1 ; RUN: opt -S < %s -instcombine | FileCheck %s
2 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32"
4 @G = constant [3 x i8] c"%s\00" ; <[3 x i8]*> [#uses=1]
6 declare i32 @sprintf(i8*, i8*, ...)
8 define void @foo(i8* %P, i32* %X) {
9 call i32 (i8*, i8*, ...) @sprintf( i8* %P, i8* getelementptr ([3 x i8], [3 x i8]* @G, i32 0, i32 0), i32* %X ) ; <i32>:1 [#uses=0]
14 @str = internal constant [5 x i8] c"foog\00"
15 @str1 = internal constant [8 x i8] c"blahhh!\00"
16 @str2 = internal constant [5 x i8] c"Ponk\00"
19 %tmp3 = tail call i8* @strchr( i8* getelementptr ([5 x i8], [5 x i8]* @str, i32 0, i32 2), i32 103 ) ; <i8*> [#uses=1]
22 ; CHECK-LABEL: @test1(
23 ; CHECK: ret i8* getelementptr inbounds ([5 x i8], [5 x i8]* @str, i32 0, i32 3)
26 declare i8* @strchr(i8*, i32)
29 %tmp3 = tail call i8* @strchr( i8* getelementptr ([8 x i8], [8 x i8]* @str1, i32 0, i32 2), i32 0 ) ; <i8*> [#uses=1]
32 ; CHECK-LABEL: @test2(
33 ; CHECK: ret i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str1, i32 0, i32 7)
38 %tmp3 = tail call i8* @strchr( i8* getelementptr ([5 x i8], [5 x i8]* @str2, i32 0, i32 1), i32 80 ) ; <i8*> [#uses=1]
41 ; CHECK-LABEL: @test3(
45 @_2E_str = external constant [5 x i8] ; <[5 x i8]*> [#uses=1]
47 declare i32 @memcmp(i8*, i8*, i32) nounwind readonly
49 define i1 @PR2341(i8** %start_addr) {
51 %tmp4 = load i8*, i8** %start_addr, align 4 ; <i8*> [#uses=1]
52 %tmp5 = call i32 @memcmp( i8* %tmp4, i8* getelementptr ([5 x i8], [5 x i8]* @_2E_str, i32 0, i32 0), i32 4 ) nounwind readonly ; <i32> [#uses=1]
53 %tmp6 = icmp eq i32 %tmp5, 0 ; <i1> [#uses=1]
56 ; CHECK-LABEL: @PR2341(
60 define i32 @PR4284() nounwind {
62 %c0 = alloca i8, align 1 ; <i8*> [#uses=2]
63 %c2 = alloca i8, align 1 ; <i8*> [#uses=2]
65 store i8 -127, i8* %c2
66 %call = call i32 @memcmp(i8* %c0, i8* %c2, i32 1) ; <i32> [#uses=1]
69 ; CHECK-LABEL: @PR4284(
73 %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 }
74 %struct.__sbuf = type { i8*, i32, [4 x i8] }
75 %struct.pthread = type opaque
76 %struct.pthread_mutex = type opaque
77 %union.anon = type { i64, [120 x i8] }
78 @.str13 = external constant [2 x i8] ; <[2 x i8]*> [#uses=1]
79 @.str14 = external constant [2 x i8] ; <[2 x i8]*> [#uses=1]
81 define i32 @PR4641(i32 %argc, i8** %argv) nounwind {
83 call void @exit(i32 0) nounwind
84 %cond392 = select i1 undef, i8* getelementptr ([2 x i8], [2 x i8]* @.str13, i32 0, i32 0), i8* getelementptr ([2 x i8], [2 x i8]* @.str14, i32 0, i32 0) ; <i8*> [#uses=1]
85 %call393 = call %struct.__sFILE* @fopen(i8* undef, i8* %cond392) nounwind ; <%struct.__sFILE*> [#uses=0]
89 declare %struct.__sFILE* @fopen(i8*, i8*)
91 declare void @exit(i32)
93 define i32 @PR4645() {
97 lor.lhs.false: ; preds = %while.body
98 br i1 undef, label %if.then, label %for.cond
100 if.then: ; preds = %lor.lhs.false, %while.body
101 call void @exit(i32 1)
104 for.cond: ; preds = %for.end, %if.then, %lor.lhs.false
105 %j.0 = phi i32 [ %inc47, %for.end ], [ 0, %if.then ], [ 0, %lor.lhs.false ] ; <i32> [#uses=1]
108 for.end: ; preds = %for.cond20
109 %inc47 = add i32 %j.0, 1 ; <i32> [#uses=1]
113 @h = constant [2 x i8] c"h\00" ; <[2 x i8]*> [#uses=1]
114 @hel = constant [4 x i8] c"hel\00" ; <[4 x i8]*> [#uses=1]
115 @hello_u = constant [8 x i8] c"hello_u\00" ; <[8 x i8]*> [#uses=1]
117 define i32 @MemCpy() {
118 %h_p = getelementptr [2 x i8], [2 x i8]* @h, i32 0, i32 0
119 %hel_p = getelementptr [4 x i8], [4 x i8]* @hel, i32 0, i32 0
120 %hello_u_p = getelementptr [8 x i8], [8 x i8]* @hello_u, i32 0, i32 0
121 %target = alloca [1024 x i8]
122 %target_p = getelementptr [1024 x i8], [1024 x i8]* %target, i32 0, i32 0
123 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 2 %target_p, i8* align 2 %h_p, i32 2, i1 false)
124 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %target_p, i8* align 4 %hel_p, i32 4, i1 false)
125 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 8 %target_p, i8* align 8 %hello_u_p, i32 8, i1 false)
128 ; CHECK-LABEL: @MemCpy(
129 ; CHECK-NOT: llvm.memcpy
133 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) nounwind
135 declare i32 @strcmp(i8*, i8*) #0
137 define void @test9(i8* %x) {
138 ; CHECK-LABEL: @test9(
140 %y = call i32 @strcmp(i8* %x, i8* %x) #1
144 ; PR30484 - https://llvm.org/bugs/show_bug.cgi?id=30484
145 ; These aren't the library functions you're looking for...
147 declare i32 @isdigit(i8)
148 declare i32 @isascii(i8)
149 declare i32 @toascii(i8)
151 define i32 @fake_isdigit(i8 %x) {
152 ; CHECK-LABEL: @fake_isdigit(
153 ; CHECK-NEXT: [[Y:%.*]] = call i32 @isdigit(i8 %x)
154 ; CHECK-NEXT: ret i32 [[Y]]
156 %y = call i32 @isdigit(i8 %x)
160 define i32 @fake_isascii(i8 %x) {
161 ; CHECK-LABEL: @fake_isascii(
162 ; CHECK-NEXT: [[Y:%.*]] = call i32 @isascii(i8 %x)
163 ; CHECK-NEXT: ret i32 [[Y]]
165 %y = call i32 @isascii(i8 %x)
169 define i32 @fake_toascii(i8 %x) {
170 ; CHECK-LABEL: @fake_toascii(
171 ; CHECK-NEXT: [[Y:%.*]] = call i32 @toascii(i8 %x)
172 ; CHECK-NEXT: ret i32 [[Y]]
174 %y = call i32 @toascii(i8 %x)
179 attributes #0 = { nobuiltin }
180 attributes #1 = { builtin }