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