[AArch64][NFC] NFC for const vector as Instruction operand (#116790)
[llvm-project.git] / llvm / test / Transforms / InstCombine / simplify-libcalls-i16.ll
blob9a08b6b5cf9f70f965798cc481ec1bbd5d5a1fc7
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 16-bit compatible sprintf is not recognized as the standard library
9 ; function on 32-bit targets.
10 declare i16 @sprintf(ptr, ptr, ...)
12 define void @foo(ptr %P, ptr %X) {
13 ; CHECK32-LABEL: @foo(
14 ; CHECK32-NEXT:    [[TMP1:%.*]] = call i16 (ptr, ptr, ...) @sprintf(ptr [[P:%.*]], ptr nonnull @G, ptr [[X:%.*]])
15 ; CHECK32-NEXT:    ret void
17 ; CHECK16-LABEL: @foo(
18 ; CHECK16-NEXT:    [[STRCPY:%.*]] = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) [[P:%.*]], ptr noundef nonnull dereferenceable(1) [[X:%.*]])
19 ; CHECK16-NEXT:    ret void
21   call i16 (ptr, ptr, ...) @sprintf(ptr %P, ptr @G, ptr %X )            ; <i32>:1 [#uses=0]
22   ret void
25 ; PR1307
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"
30 define ptr @test1() {
31 ; CHECK32-LABEL: @test1(
32 ; CHECK32-NEXT:    [[TMP3:%.*]] = tail call ptr @strchr(ptr nonnull getelementptr inbounds (i8, ptr @str, i32 2), i16 103)
33 ; CHECK32-NEXT:    ret ptr [[TMP3]]
35 ; CHECK16-LABEL: @test1(
36 ; CHECK16-NEXT:    ret ptr getelementptr inbounds (i8, ptr @str, i32 3)
38   %tmp3 = tail call ptr @strchr( ptr getelementptr ([5 x i8], ptr @str, i32 0, i16 2), i16 103 )              ; <ptr> [#uses=1]
39   ret ptr %tmp3
42 ; A 16-bit compatible strchr is not recognized as the standard library
43 ; function on 32-bit targets.
44 declare ptr @strchr(ptr, i16)
46 define ptr @test2() {
47 ; CHECK32-LABEL: @test2(
48 ; CHECK32-NEXT:    [[TMP3:%.*]] = tail call ptr @strchr(ptr nonnull getelementptr inbounds (i8, ptr @str1, i32 2), i16 0)
49 ; CHECK32-NEXT:    ret ptr [[TMP3]]
51 ; CHECK16-LABEL: @test2(
52 ; CHECK16-NEXT:    ret ptr getelementptr inbounds (i8, ptr @str1, i32 7)
54   %tmp3 = tail call ptr @strchr( ptr getelementptr ([8 x i8], ptr @str1, i32 0, i32 2), i16 0 )               ; <ptr> [#uses=1]
55   ret ptr %tmp3
58 define ptr @test3() {
59 ; CHECK32-LABEL: @test3(
60 ; CHECK32-NEXT:  entry:
61 ; CHECK32-NEXT:    [[TMP3:%.*]] = tail call ptr @strchr(ptr nonnull getelementptr inbounds (i8, ptr @str2, i32 1), i16 80)
62 ; CHECK32-NEXT:    ret ptr [[TMP3]]
64 ; CHECK16-LABEL: @test3(
65 ; CHECK16-NEXT:  entry:
66 ; CHECK16-NEXT:    ret ptr null
68 entry:
69   %tmp3 = tail call ptr @strchr( ptr getelementptr ([5 x i8], ptr @str2, i32 0, i32 1), i16 80 )              ; <ptr> [#uses=1]
70   ret ptr %tmp3
74 @_2E_str = external constant [5 x i8]           ; <ptr> [#uses=1]
76 ; A 16-bit compatible memcmp is not recognized as the standard library
77 ; function on 32-bit targets.
78 declare i16 @memcmp(ptr, ptr, i16) nounwind readonly
80 define i1 @PR2341(ptr %start_addr) {
81 ; CHECK-LABEL: @PR2341(
82 ; CHECK-NEXT:  entry:
83 ; CHECK-NEXT:    [[TMP4:%.*]] = load ptr, ptr [[START_ADDR:%.*]], align 4
84 ; CHECK-NEXT:    [[TMP5:%.*]] = call i16 @memcmp(ptr [[TMP4]], ptr nonnull @_2E_str, i16 4) #[[ATTR0:[0-9]+]]
85 ; CHECK-NEXT:    [[TMP6:%.*]] = icmp eq i16 [[TMP5]], 0
86 ; CHECK-NEXT:    ret i1 [[TMP6]]
88 entry:
89   %tmp4 = load ptr, ptr %start_addr, align 4            ; <ptr> [#uses=1]
90   %tmp5 = call i16 @memcmp( ptr %tmp4, ptr @_2E_str, i16 4 ) nounwind readonly          ; <i32> [#uses=1]
91   %tmp6 = icmp eq i16 %tmp5, 0          ; <i1> [#uses=1]
92   ret i1 %tmp6
96 define i16 @PR4284() nounwind {
97 ; CHECK-LABEL: @PR4284(
98 ; CHECK-NEXT:  entry:
99 ; CHECK-NEXT:    [[C0:%.*]] = alloca i8, align 1
100 ; CHECK-NEXT:    [[C2:%.*]] = alloca i8, align 1
101 ; CHECK-NEXT:    store i8 64, ptr [[C0]], align 1
102 ; CHECK-NEXT:    store i8 -127, ptr [[C2]], align 1
103 ; CHECK-NEXT:    [[CALL:%.*]] = call i16 @memcmp(ptr nonnull [[C0]], ptr nonnull [[C2]], i16 1)
104 ; CHECK-NEXT:    ret i16 [[CALL]]
106 entry:
107   %c0 = alloca i8, align 1              ; <ptr> [#uses=2]
108   %c2 = alloca i8, align 1              ; <ptr> [#uses=2]
109   store i8 64, ptr %c0
110   store i8 -127, ptr %c2
111   %call = call i16 @memcmp(ptr %c0, ptr %c2, i16 1)             ; <i32> [#uses=1]
112   ret i16 %call
116 %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 }
117 %struct.__sbuf = type { ptr, i32, [4 x i8] }
118 %struct.pthread = type opaque
119 %struct.pthread_mutex = type opaque
120 %union.anon = type { i64, [120 x i8] }
121 @.str13 = external constant [2 x i8]            ; <ptr> [#uses=1]
122 @.str14 = external constant [2 x i8]            ; <ptr> [#uses=1]
124 define i32 @PR4641(i32 %argc, ptr %argv, i1 %c1, ptr %ptr) nounwind {
125 ; CHECK-LABEL: @PR4641(
126 ; CHECK-NEXT:  entry:
127 ; CHECK-NEXT:    call void @exit(i16 0) #[[ATTR1:[0-9]+]]
128 ; CHECK-NEXT:    [[COND392:%.*]] = select i1 [[C1:%.*]], ptr @.str13, ptr @.str14
129 ; CHECK-NEXT:    [[CALL393:%.*]] = call ptr @fopen(ptr [[PTR:%.*]], ptr nonnull [[COND392]]) #[[ATTR1]]
130 ; CHECK-NEXT:    unreachable
132 entry:
133   call void @exit(i16 0) nounwind
134   %cond392 = select i1 %c1, ptr @.str13, ptr @.str14            ; <ptr> [#uses=1]
135   %call393 = call ptr @fopen(ptr %ptr, ptr %cond392) nounwind           ; <ptr> [#uses=0]
136   unreachable
139 declare ptr @fopen(ptr, ptr)
141 ; A 16-bit compatible exit is not recognized as the standard library
142 ; function on 32-bit targets.
143 declare void @exit(i16)
145 define i32 @PR4645(i1 %c1) {
146 ; CHECK-LABEL: @PR4645(
147 ; CHECK-NEXT:  entry:
148 ; CHECK-NEXT:    br label [[IF_THEN:%.*]]
149 ; CHECK:       lor.lhs.false:
150 ; CHECK-NEXT:    br i1 [[C1:%.*]], label [[IF_THEN]], label [[FOR_COND:%.*]]
151 ; CHECK:       if.then:
152 ; CHECK-NEXT:    call void @exit(i16 1)
153 ; CHECK-NEXT:    br label [[FOR_COND]]
154 ; CHECK:       for.cond:
155 ; CHECK-NEXT:    unreachable
156 ; CHECK:       for.end:
157 ; CHECK-NEXT:    br label [[FOR_COND]]
159 entry:
160   br label %if.then
162 lor.lhs.false:          ; preds = %while.body
163   br i1 %c1, label %if.then, label %for.cond
165 if.then:                ; preds = %lor.lhs.false, %while.body
166   call void @exit(i16 1)
167   br label %for.cond
169 for.cond:               ; preds = %for.end, %if.then, %lor.lhs.false
170   %j.0 = phi i32 [ %inc47, %for.end ], [ 0, %if.then ], [ 0, %lor.lhs.false ]           ; <i32> [#uses=1]
171   unreachable
173 for.end:                ; preds = %for.cond20
174   %inc47 = add i32 %j.0, 1              ; <i32> [#uses=1]
175   br label %for.cond
178 @h = constant [2 x i8] c"h\00"          ; <ptr> [#uses=1]
179 @hel = constant [4 x i8] c"hel\00"              ; <ptr> [#uses=1]
180 @hello_u = constant [8 x i8] c"hello_u\00"              ; <ptr> [#uses=1]
182 define i32 @MemCpy() {
183 ; CHECK-LABEL: @MemCpy(
184 ; CHECK-NEXT:    ret i32 0
186   %target = alloca [1024 x i8]
187   call void @llvm.memcpy.p0.p0.i32(ptr align 2 %target, ptr align 2 @h, i16 2, i1 false)
188   call void @llvm.memcpy.p0.p0.i32(ptr align 4 %target, ptr align 4 @hel, i16 4, i1 false)
189   call void @llvm.memcpy.p0.p0.i32(ptr align 8 %target, ptr align 8 @hello_u, i16 8, i1 false)
190   ret i32 0
194 declare void @llvm.memcpy.p0.p0.i32(ptr nocapture, ptr nocapture, i16, i1)
196 ; A 16-bit compatible strcmp is not recognized as the standard library
197 ; function on 32-bit targets.
198 declare i16 @strcmp(ptr, ptr) #0
200 define void @test9(ptr %x) {
201 ; CHECK32-LABEL: @test9(
202 ; CHECK32-NEXT:    [[Y:%.*]] = call i16 @strcmp(ptr [[X:%.*]], ptr [[X]]) #[[ATTR6:[0-9]+]]
203 ; CHECK32-NEXT:    ret void
205 ; CHECK16-LABEL: @test9(
206 ; CHECK16-NEXT:    ret void
208   %y = call i16 @strcmp(ptr %x, ptr %x) #1
209   ret void
212 ; PR30484 - https://llvm.org/bugs/show_bug.cgi?id=30484
213 ; These aren't the library functions you're looking for...
215 declare i32 @isdigit(i8)
216 declare i32 @isascii(i8)
217 declare i32 @toascii(i8)
219 define i32 @fake_isdigit(i8 %x) {
220 ; CHECK-LABEL: @fake_isdigit(
221 ; CHECK-NEXT:    [[Y:%.*]] = call i32 @isdigit(i8 [[X:%.*]])
222 ; CHECK-NEXT:    ret i32 [[Y]]
224   %y = call i32 @isdigit(i8 %x)
225   ret i32 %y
228 define i32 @fake_isascii(i8 %x) {
229 ; CHECK-LABEL: @fake_isascii(
230 ; CHECK-NEXT:    [[Y:%.*]] = call i32 @isascii(i8 [[X:%.*]])
231 ; CHECK-NEXT:    ret i32 [[Y]]
233   %y = call i32 @isascii(i8 %x)
234   ret i32 %y
237 define i32 @fake_toascii(i8 %x) {
238 ; CHECK-LABEL: @fake_toascii(
239 ; CHECK-NEXT:    [[Y:%.*]] = call i32 @toascii(i8 [[X:%.*]])
240 ; CHECK-NEXT:    ret i32 [[Y]]
242   %y = call i32 @toascii(i8 %x)
243   ret i32 %y
246 declare double @pow(double, double)
247 declare double @exp2(double)
249 ; check to make sure only the correct libcall attributes are used
250 define double @fake_exp2(double %x) {
251 ; CHECK-LABEL: @fake_exp2(
252 ; CHECK-NEXT:    [[EXP2:%.*]] = call double @exp2(double [[X:%.*]])
253 ; CHECK-NEXT:    ret double [[EXP2]]
256   %y = call inreg double @pow(double inreg 2.0, double inreg %x)
257   ret double %y
259 define double @fake_ldexp(i32 %x) {
260 ; CHECK32-LABEL: @fake_ldexp(
261 ; CHECK32-NEXT:    [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[X:%.*]])
262 ; CHECK32-NEXT:    ret double [[LDEXP]]
264 ; CHECK16-LABEL: @fake_ldexp(
265 ; CHECK16-NEXT:    [[Y:%.*]] = sitofp i32 [[X:%.*]] to double
266 ; CHECK16-NEXT:    [[Z:%.*]] = call inreg double @exp2(double [[Y]])
267 ; CHECK16-NEXT:    ret double [[Z]]
271   %y = sitofp i32 %x to double
272   %z = call inreg double @exp2(double %y)
273   ret double %z
275 define double @fake_ldexp_16(i16 %x) {
276 ; CHECK32-LABEL: @fake_ldexp_16(
277 ; CHECK32-NEXT:    [[TMP1:%.*]] = sext i16 [[X:%.*]] to i32
278 ; CHECK32-NEXT:    [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
279 ; CHECK32-NEXT:    ret double [[LDEXP]]
281 ; CHECK16-LABEL: @fake_ldexp_16(
282 ; CHECK16-NEXT:    [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 [[X:%.*]])
283 ; CHECK16-NEXT:    ret double [[LDEXP]]
287   %y = sitofp i16 %x to double
288   %z = call inreg double @exp2(double %y)
289   ret double %z
292 ; PR50885 - this would crash in ValueTracking.
294 ; A 16-bit compatible snprintf is not recognized as the standard library
295 ; function on 32-bit targets.
296 declare i16 @snprintf(ptr, double, ptr)
298 define i16 @fake_snprintf(i32 %buf, double %len, ptr %str, ptr %ptr) {
299 ; CHECK-LABEL: @fake_snprintf(
300 ; CHECK-NEXT:    [[CALL:%.*]] = call i16 @snprintf(ptr [[PTR:%.*]], double [[LEN:%.*]], ptr [[STR:%.*]])
301 ; CHECK-NEXT:    ret i16 [[CALL]]
303   %call = call i16 @snprintf(ptr %ptr, double %len, ptr %str)
304   ret i16 %call
307 ; Wrong return type for the real strlen.
308 ; https://llvm.org/PR50836
310 define i4 @strlen(ptr %s) {
311 ; CHECK-LABEL: @strlen(
312 ; CHECK-NEXT:    [[R:%.*]] = call i4 @strlen(ptr [[S:%.*]])
313 ; CHECK-NEXT:    ret i4 0
315   %r = call i4 @strlen(ptr %s)
316   ret i4 0
319 ; Test emission of stpncpy, including call attributes.
320 @a = dso_local global [4 x i8] c"123\00"
321 @b = dso_local global [5 x i8] zeroinitializer
322 declare ptr @__stpncpy_chk(ptr noundef, ptr noundef, i32 noundef, i32 noundef)
323 define signext i32 @emit_stpncpy() {
324 ; CHECK-LABEL: @emit_stpncpy(
325 ; CHECK-NEXT:    [[STPNCPY:%.*]] = call ptr @stpncpy(ptr noundef nonnull dereferenceable(1) @b, ptr noundef nonnull dereferenceable(1) @a, i32 2)
326 ; CHECK-NEXT:    ret i32 0
328   %call = call ptr @__stpncpy_chk(ptr noundef @b,
329   ptr noundef @a,
330   i32 noundef 2, i32 noundef 5)
331   ret i32 0
334 attributes #0 = { nobuiltin }
335 attributes #1 = { builtin }