1 ; Test that the strrchr library call simplifier works correctly.
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
6 @hello = constant [14 x i8] c"hello world\5Cn\00"
7 @null = constant [1 x i8] zeroinitializer
8 @chp = global i8* zeroinitializer
10 declare i8* @strrchr(i8*, i32)
12 define void @test_simplify1() {
13 ; CHECK: store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 6)
14 ; CHECK-NOT: call i8* @strrchr
17 %str = getelementptr [14 x i8], [14 x i8]* @hello, i32 0, i32 0
18 %dst = call i8* @strrchr(i8* %str, i32 119)
19 store i8* %dst, i8** @chp
23 define void @test_simplify2() {
24 ; CHECK: store i8* null, i8** @chp, align 4
25 ; CHECK-NOT: call i8* @strrchr
28 %str = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0
29 %dst = call i8* @strrchr(i8* %str, i32 119)
30 store i8* %dst, i8** @chp
34 define void @test_simplify3() {
35 ; CHECK: store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 13)
36 ; CHECK-NOT: call i8* @strrchr
39 %src = getelementptr [14 x i8], [14 x i8]* @hello, i32 0, i32 0
40 %dst = call i8* @strrchr(i8* %src, i32 0)
41 store i8* %dst, i8** @chp
45 define void @test_simplify4() {
46 ; CHECK: store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 13)
47 ; CHECK-NOT: call i8* @strrchr
50 %src = getelementptr [14 x i8], [14 x i8]* @hello, i32 0, i32 0
51 %dst = call i8* @strrchr(i8* %src, i32 65280)
52 store i8* %dst, i8** @chp
56 define void @test_nosimplify1(i32 %chr) {
57 ; CHECK-LABEL: @test_nosimplify1(
58 ; CHECK: call i8* @strrchr
61 %src = getelementptr [14 x i8], [14 x i8]* @hello, i32 0, i32 0
62 %dst = call i8* @strrchr(i8* %src, i32 %chr)
63 store i8* %dst, i8** @chp