1 ; RUN: opt -S < %s -instcombine | FileCheck %s 2 3 @G = constant [3 x i8] c"%s\00" ; <[3 x i8]*> [#uses=1] 4 5 declare i32 @sprintf(i8*, i8*, ...) 6 7 define void @foo(i8* %P, i32* %X) { 8 call i32 (i8*, i8*, ...)* @sprintf( i8* %P, i8* getelementptr ([3 x i8]* @G, i32 0, i32 0), i32* %X ) ; <i32>:1 [#uses=0] 9 ret void 10 } 11 12 ; PR1307 13 @str = internal constant [5 x i8] c"foog\00" 14 @str1 = internal constant [8 x i8] c"blahhh!\00" 15 @str2 = internal constant [5 x i8] c"Ponk\00" 16 17 define i8* @test1() { 18 %tmp3 = tail call i8* @strchr( i8* getelementptr ([5 x i8]* @str, i32 0, i32 2), i32 103 ) ; <i8*> [#uses=1] 19 ret i8* %tmp3 20 21 ; CHECK-LABEL: @test1( 22 ; CHECK: ret i8* getelementptr inbounds ([5 x i8]* @str, i32 0, i64 3) 23 } 24 25 declare i8* @strchr(i8*, i32) 26 27 define i8* @test2() { 28 %tmp3 = tail call i8* @strchr( i8* getelementptr ([8 x i8]* @str1, i32 0, i32 2), i32 0 ) ; <i8*> [#uses=1] 29 ret i8* %tmp3 30 31 ; CHECK-LABEL: @test2( 32 ; CHECK: ret i8* getelementptr inbounds ([8 x i8]* @str1, i32 0, i64 7) 33 } 34 35 define i8* @test3() { 36 entry: 37 %tmp3 = tail call i8* @strchr( i8* getelementptr ([5 x i8]* @str2, i32 0, i32 1), i32 80 ) ; <i8*> [#uses=1] 38 ret i8* %tmp3 39 40 ; CHECK-LABEL: @test3( 41 ; CHECK: ret i8* null 42 } 43 44 @_2E_str = external constant [5 x i8] ; <[5 x i8]*> [#uses=1] 45 46 declare i32 @memcmp(i8*, i8*, i32) nounwind readonly 47 48 define i1 @PR2341(i8** %start_addr) { 49 entry: 50 %tmp4 = load i8** %start_addr, align 4 ; <i8*> [#uses=1] 51 %tmp5 = call i32 @memcmp( i8* %tmp4, i8* getelementptr ([5 x i8]* @_2E_str, i32 0, i32 0), i32 4 ) nounwind readonly ; <i32> [#uses=1] 52 %tmp6 = icmp eq i32 %tmp5, 0 ; <i1> [#uses=1] 53 ret i1 %tmp6 54 55 ; CHECK-LABEL: @PR2341( 56 ; CHECK: i32 57 } 58 59 define i32 @PR4284() nounwind { 60 entry: 61 %c0 = alloca i8, align 1 ; <i8*> [#uses=2] 62 %c2 = alloca i8, align 1 ; <i8*> [#uses=2] 63 store i8 64, i8* %c0 64 store i8 -127, i8* %c2 65 %call = call i32 @memcmp(i8* %c0, i8* %c2, i32 1) ; <i32> [#uses=1] 66 ret i32 %call 67 68 ; CHECK-LABEL: @PR4284( 69 ; CHECK: ret i32 -65 70 } 71 72 %struct.__sFILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, i8*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64, %struct.pthread_mutex*, %struct.pthread*, i32, i32, %union.anon } 73 %struct.__sbuf = type { i8*, i32, [4 x i8] } 74 %struct.pthread = type opaque 75 %struct.pthread_mutex = type opaque 76 %union.anon = type { i64, [120 x i8] } 77 @.str13 = external constant [2 x i8] ; <[2 x i8]*> [#uses=1] 78 @.str14 = external constant [2 x i8] ; <[2 x i8]*> [#uses=1] 79 80 define i32 @PR4641(i32 %argc, i8** %argv) nounwind { 81 entry: 82 call void @exit(i32 0) nounwind 83 %cond392 = select i1 undef, i8* getelementptr ([2 x i8]* @.str13, i32 0, i32 0), i8* getelementptr ([2 x i8]* @.str14, i32 0, i32 0) ; <i8*> [#uses=1] 84 %call393 = call %struct.__sFILE* @fopen(i8* undef, i8* %cond392) nounwind ; <%struct.__sFILE*> [#uses=0] 85 unreachable 86 } 87 88 declare %struct.__sFILE* @fopen(i8*, i8*) 89 90 declare void @exit(i32) 91 92 define i32 @PR4645() { 93 entry: 94 br label %if.then 95 96 lor.lhs.false: ; preds = %while.body 97 br i1 undef, label %if.then, label %for.cond 98 99 if.then: ; preds = %lor.lhs.false, %while.body 100 call void @exit(i32 1) 101 br label %for.cond 102 103 for.cond: ; preds = %for.end, %if.then, %lor.lhs.false 104 %j.0 = phi i32 [ %inc47, %for.end ], [ 0, %if.then ], [ 0, %lor.lhs.false ] ; <i32> [#uses=1] 105 unreachable 106 107 for.end: ; preds = %for.cond20 108 %inc47 = add i32 %j.0, 1 ; <i32> [#uses=1] 109 br label %for.cond 110 } 111 112 @h = constant [2 x i8] c"h\00" ; <[2 x i8]*> [#uses=1] 113 @hel = constant [4 x i8] c"hel\00" ; <[4 x i8]*> [#uses=1] 114 @hello_u = constant [8 x i8] c"hello_u\00" ; <[8 x i8]*> [#uses=1] 115 116 define i32 @MemCpy() { 117 %h_p = getelementptr [2 x i8]* @h, i32 0, i32 0 118 %hel_p = getelementptr [4 x i8]* @hel, i32 0, i32 0 119 %hello_u_p = getelementptr [8 x i8]* @hello_u, i32 0, i32 0 120 %target = alloca [1024 x i8] 121 %target_p = getelementptr [1024 x i8]* %target, i32 0, i32 0 122 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %target_p, i8* %h_p, i32 2, i32 2, i1 false) 123 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %target_p, i8* %hel_p, i32 4, i32 4, i1 false) 124 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %target_p, i8* %hello_u_p, i32 8, i32 8, i1 false) 125 ret i32 0 126 127 ; CHECK-LABEL: @MemCpy( 128 ; CHECK-NOT: llvm.memcpy 129 ; CHECK: ret i32 0 130 } 131 132 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind 133 134 declare i32 @strcmp(i8*, i8*) #0 135 136 define void @test9(i8* %x) { 137 ; CHECK-LABEL: @test9( 138 ; CHECK-NOT: strcmp 139 %y = call i32 @strcmp(i8* %x, i8* %x) #1 140 ret void 141 } 142 143 attributes #0 = { nobuiltin } 144 attributes #1 = { builtin } 145