1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S < %s -mtriple=unknown -passes=instcombine | FileCheck -check-prefixes=CHECK,CHECK32 %s
3 ; RUN: opt -S < %s -mtriple=msp430 -passes=instcombine | FileCheck -check-prefixes=CHECK,CHECK16 %s
4 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"
6 @G = constant [3 x i8] c"%s\00" ; <ptr> [#uses=1]
8 ; A 32-bit compatible sprintf is not recognized as the standard library
9 ; function on 16-bit targets.
10 declare i32 @sprintf(ptr, ptr, ...)
12 define void @foo(ptr %P, ptr %X) {
13 ; CHECK32-LABEL: @foo(
14 ; CHECK32-NEXT: [[STRCPY:%.*]] = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) [[P:%.*]], ptr noundef nonnull dereferenceable(1) [[X:%.*]])
15 ; CHECK32-NEXT: ret void
17 ; CHECK16-LABEL: @foo(
18 ; CHECK16-NEXT: [[TMP1:%.*]] = call i32 (ptr, ptr, ...) @sprintf(ptr [[P:%.*]], ptr nonnull @G, ptr [[X:%.*]])
19 ; CHECK16-NEXT: ret void
21 call i32 (ptr, ptr, ...) @sprintf( ptr %P, ptr @G, ptr %X ) ; <i32>:1 [#uses=0]
26 @str = internal constant [5 x i8] c"foog\00"
27 @str1 = internal constant [8 x i8] c"blahhh!\00"
28 @str2 = internal constant [5 x i8] c"Ponk\00"
31 ; CHECK32-LABEL: @test1(
32 ; CHECK32-NEXT: ret ptr getelementptr inbounds ([5 x i8], ptr @str, i32 0, i32 3)
34 ; CHECK16-LABEL: @test1(
35 ; CHECK16-NEXT: [[TMP3:%.*]] = tail call ptr @strchr(ptr nonnull getelementptr inbounds ([5 x i8], ptr @str, i32 0, i32 2), i32 103)
36 ; CHECK16-NEXT: ret ptr [[TMP3]]
38 %tmp3 = tail call ptr @strchr( ptr getelementptr ([5 x i8], ptr @str, i32 0, i32 2), i32 103 ) ; <ptr> [#uses=1]
42 ; A 32-bit compatible strchr is not recognized as the standard library
43 ; function on 16-bit targets.
44 declare ptr @strchr(ptr, i32)
47 ; CHECK32-LABEL: @test2(
48 ; CHECK32-NEXT: ret ptr getelementptr inbounds ([8 x i8], ptr @str1, i32 0, i32 7)
50 ; CHECK16-LABEL: @test2(
51 ; CHECK16-NEXT: [[TMP3:%.*]] = tail call ptr @strchr(ptr nonnull getelementptr inbounds ([8 x i8], ptr @str1, i32 0, i32 2), i32 0)
52 ; CHECK16-NEXT: ret ptr [[TMP3]]
54 %tmp3 = tail call ptr @strchr( ptr getelementptr ([8 x i8], ptr @str1, i32 0, i32 2), i32 0 ) ; <ptr> [#uses=1]
59 ; CHECK32-LABEL: @test3(
60 ; CHECK32-NEXT: entry:
61 ; CHECK32-NEXT: ret ptr null
63 ; CHECK16-LABEL: @test3(
64 ; CHECK16-NEXT: entry:
65 ; CHECK16-NEXT: [[TMP3:%.*]] = tail call ptr @strchr(ptr nonnull getelementptr inbounds ([5 x i8], ptr @str2, i32 0, i32 1), i32 80)
66 ; CHECK16-NEXT: ret ptr [[TMP3]]
69 %tmp3 = tail call ptr @strchr( ptr getelementptr ([5 x i8], ptr @str2, i32 0, i32 1), i32 80 ) ; <ptr> [#uses=1]
74 @_2E_str = external constant [5 x i8] ; <ptr> [#uses=1]
76 ; A 32-bit compatible memcmp is not recognized as the standard library
77 ; function on 16-bit targets.
78 declare i32 @memcmp(ptr, ptr, i32) nounwind readonly
80 define i1 @PR2341(ptr %start_addr) {
81 ; CHECK32-LABEL: @PR2341(
82 ; CHECK32-NEXT: entry:
83 ; CHECK32-NEXT: [[TMP4:%.*]] = load ptr, ptr [[START_ADDR:%.*]], align 4
84 ; CHECK32-NEXT: [[TMP5:%.*]] = call i32 @memcmp(ptr noundef nonnull dereferenceable(4) [[TMP4]], ptr noundef nonnull dereferenceable(4) @_2E_str, i32 4) #[[ATTR0:[0-9]+]]
85 ; CHECK32-NEXT: [[TMP6:%.*]] = icmp eq i32 [[TMP5]], 0
86 ; CHECK32-NEXT: ret i1 [[TMP6]]
88 ; CHECK16-LABEL: @PR2341(
89 ; CHECK16-NEXT: entry:
90 ; CHECK16-NEXT: [[TMP4:%.*]] = load ptr, ptr [[START_ADDR:%.*]], align 4
91 ; CHECK16-NEXT: [[TMP5:%.*]] = call i32 @memcmp(ptr [[TMP4]], ptr nonnull @_2E_str, i32 4) #[[ATTR0:[0-9]+]]
92 ; CHECK16-NEXT: [[TMP6:%.*]] = icmp eq i32 [[TMP5]], 0
93 ; CHECK16-NEXT: ret i1 [[TMP6]]
96 %tmp4 = load ptr, ptr %start_addr, align 4 ; <ptr> [#uses=1]
97 %tmp5 = call i32 @memcmp( ptr %tmp4, ptr @_2E_str, i32 4 ) nounwind readonly ; <i32> [#uses=1]
98 %tmp6 = icmp eq i32 %tmp5, 0 ; <i1> [#uses=1]
103 define i32 @PR4284() nounwind {
104 ; CHECK32-LABEL: @PR4284(
105 ; CHECK32-NEXT: entry:
106 ; CHECK32-NEXT: ret i32 -65
108 ; CHECK16-LABEL: @PR4284(
109 ; CHECK16-NEXT: entry:
110 ; CHECK16-NEXT: [[C0:%.*]] = alloca i8, align 1
111 ; CHECK16-NEXT: [[C2:%.*]] = alloca i8, align 1
112 ; CHECK16-NEXT: store i8 64, ptr [[C0]], align 1
113 ; CHECK16-NEXT: store i8 -127, ptr [[C2]], align 1
114 ; CHECK16-NEXT: [[CALL:%.*]] = call i32 @memcmp(ptr nonnull [[C0]], ptr nonnull [[C2]], i32 1)
115 ; CHECK16-NEXT: ret i32 [[CALL]]
118 %c0 = alloca i8, align 1 ; <ptr> [#uses=2]
119 %c2 = alloca i8, align 1 ; <ptr> [#uses=2]
121 store i8 -127, ptr %c2
122 %call = call i32 @memcmp(ptr %c0, ptr %c2, i32 1) ; <i32> [#uses=1]
127 %struct.__sFILE = type { ptr, i32, i32, i16, i16, %struct.__sbuf, i32, ptr, ptr, ptr, ptr, ptr, %struct.__sbuf, ptr, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64, ptr, ptr, i32, i32, %union.anon }
128 %struct.__sbuf = type { ptr, i32, [4 x i8] }
129 %struct.pthread = type opaque
130 %struct.pthread_mutex = type opaque
131 %union.anon = type { i64, [120 x i8] }
132 @.str13 = external constant [2 x i8] ; <ptr> [#uses=1]
133 @.str14 = external constant [2 x i8] ; <ptr> [#uses=1]
135 define i32 @PR4641(i32 %argc, ptr %argv, i1 %c1, ptr %ptr) nounwind {
136 ; CHECK-LABEL: @PR4641(
138 ; CHECK-NEXT: call void @exit(i32 0) #[[ATTR1:[0-9]+]]
139 ; CHECK-NEXT: [[COND392:%.*]] = select i1 [[C1:%.*]], ptr @.str13, ptr @.str14
140 ; CHECK-NEXT: [[CALL393:%.*]] = call ptr @fopen(ptr [[PTR:%.*]], ptr nonnull [[COND392]]) #[[ATTR1]]
141 ; CHECK-NEXT: unreachable
144 call void @exit(i32 0) nounwind
145 %cond392 = select i1 %c1, ptr @.str13, ptr @.str14 ; <ptr> [#uses=1]
146 %call393 = call ptr @fopen(ptr %ptr, ptr %cond392) nounwind ; <ptr> [#uses=0]
150 declare ptr @fopen(ptr, ptr)
152 ; A 32-bit compatible exit is not recognized as the standard library
153 ; function on 16-bit targets.
154 declare void @exit(i32)
156 define i32 @PR4645(i1 %c1) {
157 ; CHECK-LABEL: @PR4645(
159 ; CHECK-NEXT: br label [[IF_THEN:%.*]]
160 ; CHECK: lor.lhs.false:
161 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[IF_THEN]], label [[FOR_COND:%.*]]
163 ; CHECK-NEXT: call void @exit(i32 1)
164 ; CHECK-NEXT: br label [[FOR_COND]]
166 ; CHECK-NEXT: unreachable
168 ; CHECK-NEXT: br label [[FOR_COND]]
173 lor.lhs.false: ; preds = %while.body
174 br i1 %c1, label %if.then, label %for.cond
176 if.then: ; preds = %lor.lhs.false, %while.body
177 call void @exit(i32 1)
180 for.cond: ; preds = %for.end, %if.then, %lor.lhs.false
181 %j.0 = phi i32 [ %inc47, %for.end ], [ 0, %if.then ], [ 0, %lor.lhs.false ] ; <i32> [#uses=1]
184 for.end: ; preds = %for.cond20
185 %inc47 = add i32 %j.0, 1 ; <i32> [#uses=1]
189 @h = constant [2 x i8] c"h\00" ; <ptr> [#uses=1]
190 @hel = constant [4 x i8] c"hel\00" ; <ptr> [#uses=1]
191 @hello_u = constant [8 x i8] c"hello_u\00" ; <ptr> [#uses=1]
193 define i32 @MemCpy() {
194 ; CHECK-LABEL: @MemCpy(
195 ; CHECK-NEXT: ret i32 0
197 %target = alloca [1024 x i8]
198 call void @llvm.memcpy.p0.p0.i32(ptr align 2 %target, ptr align 2 @h, i32 2, i1 false)
199 call void @llvm.memcpy.p0.p0.i32(ptr align 4 %target, ptr align 4 @hel, i32 4, i1 false)
200 call void @llvm.memcpy.p0.p0.i32(ptr align 8 %target, ptr align 8 @hello_u, i32 8, i1 false)
205 declare void @llvm.memcpy.p0.p0.i32(ptr nocapture, ptr nocapture, i32, i1) nounwind
207 ; A 32-bit compatible strcmp is not recognized as the standard library
208 ; function on 16-bit targets.
209 declare i32 @strcmp(ptr, ptr) #0
211 define void @test9(ptr %x) {
212 ; CHECK32-LABEL: @test9(
213 ; CHECK32-NEXT: ret void
215 ; CHECK16-LABEL: @test9(
216 ; CHECK16-NEXT: [[Y:%.*]] = call i32 @strcmp(ptr [[X:%.*]], ptr [[X]]) #[[ATTR6:[0-9]+]]
217 ; CHECK16-NEXT: ret void
219 %y = call i32 @strcmp(ptr %x, ptr %x) #1
223 ; PR30484 - https://llvm.org/bugs/show_bug.cgi?id=30484
224 ; These aren't the library functions you're looking for...
226 declare i32 @isdigit(i8)
227 declare i32 @isascii(i8)
228 declare i32 @toascii(i8)
230 define i32 @fake_isdigit(i8 %x) {
231 ; CHECK-LABEL: @fake_isdigit(
232 ; CHECK-NEXT: [[Y:%.*]] = call i32 @isdigit(i8 [[X:%.*]])
233 ; CHECK-NEXT: ret i32 [[Y]]
235 %y = call i32 @isdigit(i8 %x)
239 define i32 @fake_isascii(i8 %x) {
240 ; CHECK-LABEL: @fake_isascii(
241 ; CHECK-NEXT: [[Y:%.*]] = call i32 @isascii(i8 [[X:%.*]])
242 ; CHECK-NEXT: ret i32 [[Y]]
244 %y = call i32 @isascii(i8 %x)
248 define i32 @fake_toascii(i8 %x) {
249 ; CHECK-LABEL: @fake_toascii(
250 ; CHECK-NEXT: [[Y:%.*]] = call i32 @toascii(i8 [[X:%.*]])
251 ; CHECK-NEXT: ret i32 [[Y]]
253 %y = call i32 @toascii(i8 %x)
257 declare double @pow(double, double)
258 declare double @exp2(double)
260 ; check to make sure only the correct libcall attributes are used
261 define double @fake_exp2(double %x) {
262 ; CHECK-LABEL: @fake_exp2(
263 ; CHECK-NEXT: [[EXP2:%.*]] = call double @exp2(double [[X:%.*]])
264 ; CHECK-NEXT: ret double [[EXP2]]
267 %y = call inreg double @pow(double inreg 2.0, double inreg %x)
270 define double @fake_ldexp(i32 %x) {
271 ; CHECK32-LABEL: @fake_ldexp(
272 ; CHECK32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[X:%.*]])
273 ; CHECK32-NEXT: ret double [[LDEXP]]
275 ; CHECK16-LABEL: @fake_ldexp(
276 ; CHECK16-NEXT: [[Y:%.*]] = sitofp i32 [[X:%.*]] to double
277 ; CHECK16-NEXT: [[Z:%.*]] = call inreg double @exp2(double [[Y]])
278 ; CHECK16-NEXT: ret double [[Z]]
282 %y = sitofp i32 %x to double
283 %z = call inreg double @exp2(double %y)
286 define double @fake_ldexp_16(i16 %x) {
287 ; CHECK32-LABEL: @fake_ldexp_16(
288 ; CHECK32-NEXT: [[TMP1:%.*]] = sext i16 [[X:%.*]] to i32
289 ; CHECK32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
290 ; CHECK32-NEXT: ret double [[LDEXP]]
292 ; CHECK16-LABEL: @fake_ldexp_16(
293 ; CHECK16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 [[X:%.*]])
294 ; CHECK16-NEXT: ret double [[LDEXP]]
298 %y = sitofp i16 %x to double
299 %z = call inreg double @exp2(double %y)
303 ; PR50885 - this would crash in ValueTracking.
305 ; A 32-bit compatible snprintf is not recognized as the standard library
306 ; function on 16-bit targets.
307 declare i32 @snprintf(ptr, double, ptr)
309 define i32 @fake_snprintf(i32 %buf, double %len, ptr %str, ptr %ptr) {
310 ; CHECK-LABEL: @fake_snprintf(
311 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @snprintf(ptr [[PTR:%.*]], double [[LEN:%.*]], ptr [[STR:%.*]])
312 ; CHECK-NEXT: ret i32 [[CALL]]
314 %call = call i32 @snprintf(ptr %ptr, double %len, ptr %str)
318 ; Wrong return type for the real strlen.
319 ; https://llvm.org/PR50836
321 define i4 @strlen(ptr %s) {
322 ; CHECK-LABEL: @strlen(
323 ; CHECK-NEXT: [[R:%.*]] = call i4 @strlen(ptr [[S:%.*]])
324 ; CHECK-NEXT: ret i4 0
326 %r = call i4 @strlen(ptr %s)
330 ; Test emission of stpncpy.
331 @a = dso_local global [4 x i8] c"123\00"
332 @b = dso_local global [5 x i8] zeroinitializer
333 declare ptr @__stpncpy_chk(ptr noundef, ptr noundef, i32 noundef, i32 noundef)
334 define signext i32 @emit_stpncpy() {
335 ; CHECK-LABEL: @emit_stpncpy(
336 ; CHECK-NEXT: [[STPNCPY:%.*]] = call ptr @stpncpy(ptr noundef nonnull dereferenceable(1) @b, ptr noundef nonnull dereferenceable(1) @a, i32 2)
337 ; CHECK-NEXT: ret i32 0
339 %call = call ptr @__stpncpy_chk(ptr noundef @b,
341 i32 noundef 2, i32 noundef 5)
345 attributes #0 = { nobuiltin }
346 attributes #1 = { builtin }