1 ; Tests to make sure elimination of casts is working correctly
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
3 target datalayout = "E-p:64:64:64-p1:32:32:32-p2:64:64:64-p3:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128-n8:16:32:64"
5 @inbuf = external global [32832 x i8] ; <[32832 x i8]*> [#uses=1]
7 define i32 @test1(i32 %A) {
8 %c1 = bitcast i32 %A to i32 ; <i32> [#uses=1]
9 %c2 = bitcast i32 %c1 to i32 ; <i32> [#uses=1]
14 define i64 @test2(i8 %A) {
15 %c1 = zext i8 %A to i16 ; <i16> [#uses=1]
16 %c2 = zext i16 %c1 to i32 ; <i32> [#uses=1]
17 %Ret = zext i32 %c2 to i64 ; <i64> [#uses=1]
19 ; CHECK: %Ret = zext i8 %A to i64
23 ; This function should just use bitwise AND
24 define i64 @test3(i64 %A) {
25 %c1 = trunc i64 %A to i8 ; <i8> [#uses=1]
26 %c2 = zext i8 %c1 to i64 ; <i64> [#uses=1]
28 ; CHECK: %c2 = and i64 %A, 255
32 define i32 @test4(i32 %A, i32 %B) {
33 %COND = icmp slt i32 %A, %B ; <i1> [#uses=1]
34 ; Booleans are unsigned integrals
35 %c = zext i1 %COND to i8 ; <i8> [#uses=1]
36 ; for the cast elim purpose
37 %result = zext i8 %c to i32 ; <i32> [#uses=1]
39 ; CHECK: %COND = icmp slt i32 %A, %B
40 ; CHECK: %result = zext i1 %COND to i32
41 ; CHECK: ret i32 %result
44 define i32 @test5(i1 %B) {
45 ; This cast should get folded into
46 %c = zext i1 %B to i8 ; <i8> [#uses=1]
48 %result = zext i8 %c to i32 ; <i32> [#uses=1]
50 ; CHECK: %result = zext i1 %B to i32
51 ; CHECK: ret i32 %result
54 define i32 @test6(i64 %A) {
55 %c1 = trunc i64 %A to i32 ; <i32> [#uses=1]
56 %res = bitcast i32 %c1 to i32 ; <i32> [#uses=1]
58 ; CHECK: trunc i64 %A to i32
62 define i64 @test7(i1 %A) {
63 %c1 = zext i1 %A to i32 ; <i32> [#uses=1]
64 %res = sext i32 %c1 to i64 ; <i64> [#uses=1]
66 ; CHECK: %res = zext i1 %A to i64
70 define i64 @test8(i8 %A) {
71 %c1 = sext i8 %A to i64 ; <i64> [#uses=1]
72 %res = bitcast i64 %c1 to i64 ; <i64> [#uses=1]
74 ; CHECK: = sext i8 %A to i64
78 define i16 @test9(i16 %A) {
79 %c1 = sext i16 %A to i32 ; <i32> [#uses=1]
80 %c2 = trunc i32 %c1 to i16 ; <i16> [#uses=1]
85 define i16 @test10(i16 %A) {
86 %c1 = sext i16 %A to i32 ; <i32> [#uses=1]
87 %c2 = trunc i32 %c1 to i16 ; <i16> [#uses=1]
92 declare void @varargs(i32, ...)
94 define void @test11(i32* %P) {
95 %c = bitcast i32* %P to i16* ; <i16*> [#uses=1]
96 call void (i32, ...)* @varargs( i32 5, i16* %c )
98 ; CHECK: call void (i32, ...)* @varargs(i32 5, i32* %P)
102 define i8* @test13(i64 %A) {
103 %c = getelementptr [0 x i8]* bitcast ([32832 x i8]* @inbuf to [0 x i8]*), i64 0, i64 %A ; <i8*> [#uses=1]
105 ; CHECK: %c = getelementptr [32832 x i8]* @inbuf, i64 0, i64 %A
109 define i1 @test14(i8 %A) {
110 %c = bitcast i8 %A to i8 ; <i8> [#uses=1]
111 %X = icmp ult i8 %c, -128 ; <i1> [#uses=1]
113 ; CHECK: %X = icmp sgt i8 %A, -1
118 ; This just won't occur when there's no difference between ubyte and sbyte
119 ;bool %test15(ubyte %A) {
120 ; %c = cast ubyte %A to sbyte
121 ; %X = setlt sbyte %c, 0 ; setgt %A, 127
125 define i1 @test16(i32* %P) {
126 %c = icmp ne i32* %P, null ; <i1> [#uses=1]
128 ; CHECK: %c = icmp ne i32* %P, null
132 define i16 @test17(i1 %tmp3) {
133 %c = zext i1 %tmp3 to i32 ; <i32> [#uses=1]
134 %t86 = trunc i32 %c to i16 ; <i16> [#uses=1]
136 ; CHECK: %t86 = zext i1 %tmp3 to i16
137 ; CHECK: ret i16 %t86
140 define i16 @test18(i8 %tmp3) {
141 %c = sext i8 %tmp3 to i32 ; <i32> [#uses=1]
142 %t86 = trunc i32 %c to i16 ; <i16> [#uses=1]
144 ; CHECK: %t86 = sext i8 %tmp3 to i16
145 ; CHECK: ret i16 %t86
148 define i1 @test19(i32 %X) {
149 %c = sext i32 %X to i64 ; <i64> [#uses=1]
150 %Z = icmp slt i64 %c, 12345 ; <i1> [#uses=1]
152 ; CHECK: %Z = icmp slt i32 %X, 12345
156 define i1 @test20(i1 %B) {
157 %c = zext i1 %B to i32 ; <i32> [#uses=1]
158 %D = icmp slt i32 %c, -1 ; <i1> [#uses=1]
161 ; CHECK: ret i1 false
164 define i32 @test21(i32 %X) {
165 %c1 = trunc i32 %X to i8 ; <i8> [#uses=1]
166 ;; sext -> zext -> and -> nop
167 %c2 = sext i8 %c1 to i32 ; <i32> [#uses=1]
168 %RV = and i32 %c2, 255 ; <i32> [#uses=1]
170 ; CHECK: %c21 = and i32 %X, 255
171 ; CHECK: ret i32 %c21
174 define i32 @test22(i32 %X) {
175 %c1 = trunc i32 %X to i8 ; <i8> [#uses=1]
176 ;; sext -> zext -> and -> nop
177 %c2 = sext i8 %c1 to i32 ; <i32> [#uses=1]
178 %RV = shl i32 %c2, 24 ; <i32> [#uses=1]
180 ; CHECK: shl i32 %X, 24
181 ; CHECK-NEXT: ret i32
184 define i32 @test23(i32 %X) {
185 ;; Turn into an AND even though X
186 %c1 = trunc i32 %X to i16 ; <i16> [#uses=1]
188 %c2 = zext i16 %c1 to i32 ; <i32> [#uses=1]
190 ; CHECK: %c2 = and i32 %X, 65535
194 define i1 @test24(i1 %C) {
195 %X = select i1 %C, i32 14, i32 1234 ; <i32> [#uses=1]
196 ;; Fold cast into select
197 %c = icmp ne i32 %X, 0 ; <i1> [#uses=1]
202 define i32 @test26(float %F) {
203 ;; no need to cast from float->double.
204 %c = fpext float %F to double ; <double> [#uses=1]
205 %D = fptosi double %c to i32 ; <i32> [#uses=1]
207 ; CHECK: %D = fptosi float %F to i32
211 define [4 x float]* @test27([9 x [4 x float]]* %A) {
212 %c = bitcast [9 x [4 x float]]* %A to [4 x float]* ; <[4 x float]*> [#uses=1]
214 ; CHECK: %c = getelementptr inbounds [9 x [4 x float]]* %A, i64 0, i64 0
215 ; CHECK: ret [4 x float]* %c
218 define float* @test28([4 x float]* %A) {
219 %c = bitcast [4 x float]* %A to float* ; <float*> [#uses=1]
221 ; CHECK: %c = getelementptr inbounds [4 x float]* %A, i64 0, i64 0
222 ; CHECK: ret float* %c
225 define i32 @test29(i32 %c1, i32 %c2) {
226 %tmp1 = trunc i32 %c1 to i8 ; <i8> [#uses=1]
227 %tmp4.mask = trunc i32 %c2 to i8 ; <i8> [#uses=1]
228 %tmp = or i8 %tmp4.mask, %tmp1 ; <i8> [#uses=1]
229 %tmp10 = zext i8 %tmp to i32 ; <i32> [#uses=1]
231 ; CHECK: %tmp2 = or i32 %c2, %c1
232 ; CHECK: %tmp10 = and i32 %tmp2, 255
233 ; CHECK: ret i32 %tmp10
236 define i32 @test30(i32 %c1) {
237 %c2 = trunc i32 %c1 to i8 ; <i8> [#uses=1]
238 %c3 = xor i8 %c2, 1 ; <i8> [#uses=1]
239 %c4 = zext i8 %c3 to i32 ; <i32> [#uses=1]
241 ; CHECK: %c3 = and i32 %c1, 255
242 ; CHECK: %c4 = xor i32 %c3, 1
246 define i1 @test31(i64 %A) {
247 %B = trunc i64 %A to i32 ; <i32> [#uses=1]
248 %C = and i32 %B, 42 ; <i32> [#uses=1]
249 %D = icmp eq i32 %C, 10 ; <i1> [#uses=1]
251 ; CHECK: %C = and i64 %A, 42
252 ; CHECK: %D = icmp eq i64 %C, 10
256 define i32 @test33(i32 %c1) {
257 %x = bitcast i32 %c1 to float ; <float> [#uses=1]
258 %y = bitcast float %x to i32 ; <i32> [#uses=1]
263 define i16 @test34(i16 %a) {
264 %c1 = zext i16 %a to i32 ; <i32> [#uses=1]
265 %tmp21 = lshr i32 %c1, 8 ; <i32> [#uses=1]
266 %c2 = trunc i32 %tmp21 to i16 ; <i16> [#uses=1]
268 ; CHECK: %tmp21 = lshr i16 %a, 8
269 ; CHECK: ret i16 %tmp21
272 define i16 @test35(i16 %a) {
273 %c1 = bitcast i16 %a to i16 ; <i16> [#uses=1]
274 %tmp2 = lshr i16 %c1, 8 ; <i16> [#uses=1]
275 %c2 = bitcast i16 %tmp2 to i16 ; <i16> [#uses=1]
277 ; CHECK: %tmp2 = lshr i16 %a, 8
278 ; CHECK: ret i16 %tmp2
281 ; icmp sgt i32 %a, -1
283 define i1 @test36(i32 %a) {
285 %c = trunc i32 %b to i8
286 %d = icmp eq i8 %c, 0
288 ; CHECK: %d = icmp sgt i32 %a, -1
293 define i1 @test37(i32 %a) {
296 %d = trunc i32 %c to i8
297 %e = icmp eq i8 %d, 11
299 ; CHECK: ret i1 false
302 define i64 @test38(i32 %a) {
303 %1 = icmp eq i32 %a, -2
304 %2 = zext i1 %1 to i8
306 %4 = zext i8 %3 to i64
308 ; CHECK: %1 = icmp ne i32 %a, -2
309 ; CHECK: %2 = zext i1 %1 to i64
313 define i16 @test39(i16 %a) {
314 %tmp = zext i16 %a to i32
315 %tmp21 = lshr i32 %tmp, 8
316 %tmp5 = shl i32 %tmp, 8
317 %tmp.upgrd.32 = or i32 %tmp21, %tmp5
318 %tmp.upgrd.3 = trunc i32 %tmp.upgrd.32 to i16
320 ; CHECK-LABEL: @test39(
321 ; CHECK: %tmp.upgrd.32 = call i16 @llvm.bswap.i16(i16 %a)
322 ; CHECK: ret i16 %tmp.upgrd.32
325 define i16 @test40(i16 %a) {
326 %tmp = zext i16 %a to i32
327 %tmp21 = lshr i32 %tmp, 9
328 %tmp5 = shl i32 %tmp, 8
329 %tmp.upgrd.32 = or i32 %tmp21, %tmp5
330 %tmp.upgrd.3 = trunc i32 %tmp.upgrd.32 to i16
332 ; CHECK-LABEL: @test40(
333 ; CHECK: %tmp21 = lshr i16 %a, 9
334 ; CHECK: %tmp5 = shl i16 %a, 8
335 ; CHECK: %tmp.upgrd.32 = or i16 %tmp21, %tmp5
336 ; CHECK: ret i16 %tmp.upgrd.32
340 define i32* @test41(i32* %tmp1) {
341 %tmp64 = bitcast i32* %tmp1 to { i32 }*
342 %tmp65 = getelementptr { i32 }* %tmp64, i32 0, i32 0
344 ; CHECK-LABEL: @test41(
345 ; CHECK: ret i32* %tmp1
348 define i32 addrspace(1)* @test41_addrspacecast_smaller(i32* %tmp1) {
349 %tmp64 = addrspacecast i32* %tmp1 to { i32 } addrspace(1)*
350 %tmp65 = getelementptr { i32 } addrspace(1)* %tmp64, i32 0, i32 0
351 ret i32 addrspace(1)* %tmp65
352 ; CHECK-LABEL: @test41_addrspacecast_smaller(
353 ; CHECK: addrspacecast i32* %tmp1 to i32 addrspace(1)*
354 ; CHECK-NEXT: ret i32 addrspace(1)*
357 define i32* @test41_addrspacecast_larger(i32 addrspace(1)* %tmp1) {
358 %tmp64 = addrspacecast i32 addrspace(1)* %tmp1 to { i32 }*
359 %tmp65 = getelementptr { i32 }* %tmp64, i32 0, i32 0
361 ; CHECK-LABEL: @test41_addrspacecast_larger(
362 ; CHECK: addrspacecast i32 addrspace(1)* %tmp1 to i32*
363 ; CHECK-NEXT: ret i32*
366 define i32 @test42(i32 %X) {
367 %Y = trunc i32 %X to i8 ; <i8> [#uses=1]
368 %Z = zext i8 %Y to i32 ; <i32> [#uses=1]
370 ; CHECK-LABEL: @test42(
371 ; CHECK: %Z = and i32 %X, 255
375 define zeroext i64 @test43(i8 zeroext %on_off) nounwind readonly {
376 %A = zext i8 %on_off to i32
378 %C = sext i32 %B to i64
379 ret i64 %C ;; Should be (add (zext i8 -> i64), -1)
380 ; CHECK-LABEL: @test43(
381 ; CHECK-NEXT: %A = zext i8 %on_off to i64
382 ; CHECK-NEXT: %B = add nsw i64 %A, -1
383 ; CHECK-NEXT: ret i64 %B
386 define i64 @test44(i8 %T) {
387 %A = zext i8 %T to i16
389 %C = zext i16 %B to i64
391 ; CHECK-LABEL: @test44(
392 ; CHECK-NEXT: %A = zext i8 %T to i64
393 ; CHECK-NEXT: %B = or i64 %A, 1234
394 ; CHECK-NEXT: ret i64 %B
397 define i64 @test45(i8 %A, i64 %Q) {
398 %D = trunc i64 %Q to i32 ;; should be removed
399 %B = sext i8 %A to i32
401 %E = zext i32 %C to i64
403 ; CHECK-LABEL: @test45(
404 ; CHECK-NEXT: %B = sext i8 %A to i64
405 ; CHECK-NEXT: %C = or i64 %B, %Q
406 ; CHECK-NEXT: %E = and i64 %C, 4294967295
407 ; CHECK-NEXT: ret i64 %E
411 define i64 @test46(i64 %A) {
412 %B = trunc i64 %A to i32
415 %E = zext i32 %D to i64
417 ; CHECK-LABEL: @test46(
418 ; CHECK-NEXT: %C = shl i64 %A, 8
419 ; CHECK-NEXT: %D = and i64 %C, 10752
420 ; CHECK-NEXT: ret i64 %D
423 define i64 @test47(i8 %A) {
424 %B = sext i8 %A to i32
426 %E = zext i32 %C to i64
428 ; CHECK-LABEL: @test47(
429 ; CHECK-NEXT: %B = sext i8 %A to i64
430 ; CHECK-NEXT: %C = and i64 %B, 4294967253
431 ; CHECK-NEXT: %E = or i64 %C, 42
432 ; CHECK-NEXT: ret i64 %E
435 define i64 @test48(i8 %A, i8 %a) {
436 %b = zext i8 %a to i32
437 %B = zext i8 %A to i32
440 %E = zext i32 %D to i64
442 ; CHECK-LABEL: @test48(
443 ; CHECK-NEXT: %b = zext i8 %a to i64
444 ; CHECK-NEXT: %B = zext i8 %A to i64
445 ; CHECK-NEXT: %C = shl nuw nsw i64 %B, 8
446 ; CHECK-NEXT: %D = or i64 %C, %b
447 ; CHECK-NEXT: ret i64 %D
450 define i64 @test49(i64 %A) {
451 %B = trunc i64 %A to i32
453 %D = sext i32 %C to i64
455 ; CHECK-LABEL: @test49(
456 ; CHECK-NEXT: %C = shl i64 %A, 32
457 ; CHECK-NEXT: ashr exact i64 %C, 32
458 ; CHECK-NEXT: %D = or i64 {{.*}}, 1
459 ; CHECK-NEXT: ret i64 %D
462 define i64 @test50(i64 %A) {
464 %B = trunc i64 %a to i32
466 %E = sext i32 %D to i64
468 ; CHECK-LABEL: @test50(
469 ; lshr+shl will be handled by DAGCombine.
470 ; CHECK-NEXT: lshr i64 %A, 2
471 ; CHECK-NEXT: shl i64 %a, 32
472 ; CHECK-NEXT: add i64 {{.*}}, -4294967296
473 ; CHECK-NEXT: %E = ashr exact i64 {{.*}}, 32
474 ; CHECK-NEXT: ret i64 %E
477 define i64 @test51(i64 %A, i1 %cond) {
478 %B = trunc i64 %A to i32
481 %E = select i1 %cond, i32 %C, i32 %D
482 %F = sext i32 %E to i64
484 ; CHECK-LABEL: @test51(
485 ; CHECK-NEXT: %C = and i64 %A, 4294967294
486 ; CHECK-NEXT: %D = or i64 %A, 1
487 ; CHECK-NEXT: %E = select i1 %cond, i64 %C, i64 %D
488 ; CHECK-NEXT: %sext = shl i64 %E, 32
489 ; CHECK-NEXT: %F = ashr exact i64 %sext, 32
490 ; CHECK-NEXT: ret i64 %F
493 define i32 @test52(i64 %A) {
494 %B = trunc i64 %A to i16
495 %C = or i16 %B, -32574
496 %D = and i16 %C, -25350
497 %E = zext i16 %D to i32
499 ; CHECK-LABEL: @test52(
500 ; CHECK-NEXT: %B = trunc i64 %A to i32
501 ; CHECK-NEXT: %C = and i32 %B, 7224
502 ; CHECK-NEXT: %D = or i32 %C, 32962
503 ; CHECK-NEXT: ret i32 %D
506 define i64 @test53(i32 %A) {
507 %B = trunc i32 %A to i16
508 %C = or i16 %B, -32574
509 %D = and i16 %C, -25350
510 %E = zext i16 %D to i64
512 ; CHECK-LABEL: @test53(
513 ; CHECK-NEXT: %B = zext i32 %A to i64
514 ; CHECK-NEXT: %C = and i64 %B, 7224
515 ; CHECK-NEXT: %D = or i64 %C, 32962
516 ; CHECK-NEXT: ret i64 %D
519 define i32 @test54(i64 %A) {
520 %B = trunc i64 %A to i16
521 %C = or i16 %B, -32574
522 %D = and i16 %C, -25350
523 %E = sext i16 %D to i32
525 ; CHECK-LABEL: @test54(
526 ; CHECK-NEXT: %B = trunc i64 %A to i32
527 ; CHECK-NEXT: %C = and i32 %B, 7224
528 ; CHECK-NEXT: %D = or i32 %C, -32574
529 ; CHECK-NEXT: ret i32 %D
532 define i64 @test55(i32 %A) {
533 %B = trunc i32 %A to i16
534 %C = or i16 %B, -32574
535 %D = and i16 %C, -25350
536 %E = sext i16 %D to i64
538 ; CHECK-LABEL: @test55(
539 ; CHECK-NEXT: %B = zext i32 %A to i64
540 ; CHECK-NEXT: %C = and i64 %B, 7224
541 ; CHECK-NEXT: %D = or i64 %C, -32574
542 ; CHECK-NEXT: ret i64 %D
545 define i64 @test56(i16 %A) nounwind {
546 %tmp353 = sext i16 %A to i32
547 %tmp354 = lshr i32 %tmp353, 5
548 %tmp355 = zext i32 %tmp354 to i64
550 ; CHECK-LABEL: @test56(
551 ; CHECK-NEXT: %tmp353 = sext i16 %A to i64
552 ; CHECK-NEXT: %tmp354 = lshr i64 %tmp353, 5
553 ; CHECK-NEXT: %tmp355 = and i64 %tmp354, 134217727
554 ; CHECK-NEXT: ret i64 %tmp355
557 define i64 @test57(i64 %A) nounwind {
558 %B = trunc i64 %A to i32
560 %E = zext i32 %C to i64
562 ; CHECK-LABEL: @test57(
563 ; CHECK-NEXT: %C = lshr i64 %A, 8
564 ; CHECK-NEXT: %E = and i64 %C, 16777215
565 ; CHECK-NEXT: ret i64 %E
568 define i64 @test58(i64 %A) nounwind {
569 %B = trunc i64 %A to i32
572 %E = zext i32 %D to i64
575 ; CHECK-LABEL: @test58(
576 ; CHECK-NEXT: %C = lshr i64 %A, 8
577 ; CHECK-NEXT: %D = and i64 %C, 16777087
578 ; CHECK-NEXT: %E = or i64 %D, 128
579 ; CHECK-NEXT: ret i64 %E
582 define i64 @test59(i8 %A, i8 %B) nounwind {
583 %C = zext i8 %A to i32
586 %F = zext i8 %B to i32
589 %I = zext i32 %H to i64
591 ; CHECK-LABEL: @test59(
592 ; CHECK-NEXT: %C = zext i8 %A to i64
594 ; CHECK: %F = zext i8 %B to i64
599 define <3 x i32> @test60(<4 x i32> %call4) nounwind {
600 %tmp11 = bitcast <4 x i32> %call4 to i128
601 %tmp9 = trunc i128 %tmp11 to i96
602 %tmp10 = bitcast i96 %tmp9 to <3 x i32>
605 ; CHECK-LABEL: @test60(
606 ; CHECK-NEXT: shufflevector
610 define <4 x i32> @test61(<3 x i32> %call4) nounwind {
611 %tmp11 = bitcast <3 x i32> %call4 to i96
612 %tmp9 = zext i96 %tmp11 to i128
613 %tmp10 = bitcast i128 %tmp9 to <4 x i32>
615 ; CHECK-LABEL: @test61(
616 ; CHECK-NEXT: shufflevector
620 define <4 x i32> @test62(<3 x float> %call4) nounwind {
621 %tmp11 = bitcast <3 x float> %call4 to i96
622 %tmp9 = zext i96 %tmp11 to i128
623 %tmp10 = bitcast i128 %tmp9 to <4 x i32>
625 ; CHECK-LABEL: @test62(
626 ; CHECK-NEXT: bitcast
627 ; CHECK-NEXT: shufflevector
631 ; PR7311 - Don't create invalid IR on scalar->vector cast.
632 define <2 x float> @test63(i64 %tmp8) nounwind {
634 %a = bitcast i64 %tmp8 to <2 x i32>
635 %vcvt.i = uitofp <2 x i32> %a to <2 x float>
636 ret <2 x float> %vcvt.i
637 ; CHECK-LABEL: @test63(
642 define <4 x float> @test64(<4 x float> %c) nounwind {
643 %t0 = bitcast <4 x float> %c to <4 x i32>
644 %t1 = bitcast <4 x i32> %t0 to <4 x float>
646 ; CHECK-LABEL: @test64(
647 ; CHECK-NEXT: ret <4 x float> %c
650 define <4 x float> @test65(<4 x float> %c) nounwind {
651 %t0 = bitcast <4 x float> %c to <2 x double>
652 %t1 = bitcast <2 x double> %t0 to <4 x float>
654 ; CHECK-LABEL: @test65(
655 ; CHECK-NEXT: ret <4 x float> %c
658 define <2 x float> @test66(<2 x float> %c) nounwind {
659 %t0 = bitcast <2 x float> %c to double
660 %t1 = bitcast double %t0 to <2 x float>
662 ; CHECK-LABEL: @test66(
663 ; CHECK-NEXT: ret <2 x float> %c
666 define float @test2c() {
667 ret float extractelement (<2 x float> bitcast (double bitcast (<2 x float> <float -1.000000e+00, float -1.000000e+00> to double) to <2 x float>), i32 0)
668 ; CHECK-LABEL: @test2c(
669 ; CHECK-NOT: extractelement
672 define i64 @test_mmx(<2 x i32> %c) nounwind {
673 %A = bitcast <2 x i32> %c to x86_mmx
674 %B = bitcast x86_mmx %A to <2 x i32>
675 %C = bitcast <2 x i32> %B to i64
677 ; CHECK-LABEL: @test_mmx(
681 define i64 @test_mmx_const(<2 x i32> %c) nounwind {
682 %A = bitcast <2 x i32> zeroinitializer to x86_mmx
683 %B = bitcast x86_mmx %A to <2 x i32>
684 %C = bitcast <2 x i32> %B to i64
686 ; CHECK-LABEL: @test_mmx_const(
691 define i1 @test67(i1 %a, i32 %b) {
692 %tmp2 = zext i1 %a to i32
693 %conv6 = xor i32 %tmp2, 1
694 %and = and i32 %b, %conv6
695 %sext = shl nuw nsw i32 %and, 24
696 %neg.i = xor i32 %sext, -16777216
697 %conv.i.i = ashr exact i32 %neg.i, 24
698 %trunc = trunc i32 %conv.i.i to i8
699 %tobool.i = icmp eq i8 %trunc, 0
701 ; CHECK-LABEL: @test67(
702 ; CHECK: ret i1 false
705 %s = type { i32, i32, i32 }
707 define %s @test68(%s *%p, i64 %i) {
708 ; CHECK-LABEL: @test68(
710 %q = bitcast %s* %p to i8*
711 %pp = getelementptr inbounds i8* %q, i64 %o
712 ; CHECK-NEXT: getelementptr %s*
713 %r = bitcast i8* %pp to %s*
715 ; CHECK-NEXT: load %s*
720 ; addrspacecasts should be eliminated.
721 define %s @test68_addrspacecast(%s* %p, i64 %i) {
722 ; CHECK-LABEL: @test68_addrspacecast(
723 ; CHECK-NEXT: getelementptr %s*
724 ; CHECK-NEXT: load %s*
727 %q = addrspacecast %s* %p to i8 addrspace(2)*
728 %pp = getelementptr inbounds i8 addrspace(2)* %q, i64 %o
729 %r = addrspacecast i8 addrspace(2)* %pp to %s*
734 define %s @test68_addrspacecast_2(%s* %p, i64 %i) {
735 ; CHECK-LABEL: @test68_addrspacecast_2(
736 ; CHECK-NEXT: getelementptr %s* %p
737 ; CHECK-NEXT: addrspacecast
738 ; CHECK-NEXT: load %s addrspace(1)*
741 %q = addrspacecast %s* %p to i8 addrspace(2)*
742 %pp = getelementptr inbounds i8 addrspace(2)* %q, i64 %o
743 %r = addrspacecast i8 addrspace(2)* %pp to %s addrspace(1)*
744 %l = load %s addrspace(1)* %r
748 define %s @test68_as1(%s addrspace(1)* %p, i32 %i) {
749 ; CHECK-LABEL: @test68_as1(
751 %q = bitcast %s addrspace(1)* %p to i8 addrspace(1)*
752 %pp = getelementptr inbounds i8 addrspace(1)* %q, i32 %o
753 ; CHECK-NEXT: getelementptr %s addrspace(1)*
754 %r = bitcast i8 addrspace(1)* %pp to %s addrspace(1)*
755 %l = load %s addrspace(1)* %r
756 ; CHECK-NEXT: load %s addrspace(1)*
761 define double @test69(double *%p, i64 %i) {
762 ; CHECK-LABEL: @test69(
763 %o = shl nsw i64 %i, 3
764 %q = bitcast double* %p to i8*
765 %pp = getelementptr inbounds i8* %q, i64 %o
766 ; CHECK-NEXT: getelementptr inbounds double*
767 %r = bitcast i8* %pp to double*
769 ; CHECK-NEXT: load double*
771 ; CHECK-NEXT: ret double
774 define %s @test70(%s *%p, i64 %i) {
775 ; CHECK-LABEL: @test70(
776 %o = mul nsw i64 %i, 36
777 ; CHECK-NEXT: mul nsw i64 %i, 3
778 %q = bitcast %s* %p to i8*
779 %pp = getelementptr inbounds i8* %q, i64 %o
780 ; CHECK-NEXT: getelementptr inbounds %s*
781 %r = bitcast i8* %pp to %s*
783 ; CHECK-NEXT: load %s*
788 define double @test71(double *%p, i64 %i) {
789 ; CHECK-LABEL: @test71(
791 ; CHECK-NEXT: shl i64 %i, 2
792 %q = bitcast double* %p to i8*
793 %pp = getelementptr i8* %q, i64 %o
794 ; CHECK-NEXT: getelementptr double*
795 %r = bitcast i8* %pp to double*
797 ; CHECK-NEXT: load double*
799 ; CHECK-NEXT: ret double
802 define double @test72(double *%p, i32 %i) {
803 ; CHECK-LABEL: @test72(
804 %so = shl nsw i32 %i, 3
805 %o = sext i32 %so to i64
806 ; CHECK-NEXT: sext i32 %i to i64
807 %q = bitcast double* %p to i8*
808 %pp = getelementptr inbounds i8* %q, i64 %o
809 ; CHECK-NEXT: getelementptr inbounds double*
810 %r = bitcast i8* %pp to double*
812 ; CHECK-NEXT: load double*
814 ; CHECK-NEXT: ret double
817 define double @test73(double *%p, i128 %i) {
818 ; CHECK-LABEL: @test73(
819 %lo = shl nsw i128 %i, 3
820 %o = trunc i128 %lo to i64
821 ; CHECK-NEXT: trunc i128 %i to i64
822 %q = bitcast double* %p to i8*
823 %pp = getelementptr inbounds i8* %q, i64 %o
824 ; CHECK-NEXT: getelementptr double*
825 %r = bitcast i8* %pp to double*
827 ; CHECK-NEXT: load double*
829 ; CHECK-NEXT: ret double
832 define double @test74(double *%p, i64 %i) {
833 ; CHECK-LABEL: @test74(
834 %q = bitcast double* %p to i64*
835 %pp = getelementptr inbounds i64* %q, i64 %i
836 ; CHECK-NEXT: getelementptr inbounds double*
837 %r = bitcast i64* %pp to double*
839 ; CHECK-NEXT: load double*
841 ; CHECK-NEXT: ret double
844 define i32* @test75(i32* %p, i32 %x) {
845 ; CHECK-LABEL: @test75(
847 ; CHECK-NEXT: shl i32 %x, 3
848 %z = sext i32 %y to i64
849 ; CHECK-NEXT: sext i32 %y to i64
850 %q = bitcast i32* %p to i8*
851 %r = getelementptr i8* %q, i64 %z
852 %s = bitcast i8* %r to i32*
856 define %s @test76(%s *%p, i64 %i, i64 %j) {
857 ; CHECK-LABEL: @test76(
859 %o2 = mul nsw i64 %o, %j
860 ; CHECK-NEXT: %o2 = mul i64 %i, %j
861 %q = bitcast %s* %p to i8*
862 %pp = getelementptr inbounds i8* %q, i64 %o2
863 ; CHECK-NEXT: getelementptr %s* %p, i64 %o2
864 %r = bitcast i8* %pp to %s*
866 ; CHECK-NEXT: load %s*
871 define %s @test77(%s *%p, i64 %i, i64 %j) {
872 ; CHECK-LABEL: @test77(
873 %o = mul nsw i64 %i, 36
874 %o2 = mul nsw i64 %o, %j
875 ; CHECK-NEXT: %o = mul nsw i64 %i, 3
876 ; CHECK-NEXT: %o2 = mul nsw i64 %o, %j
877 %q = bitcast %s* %p to i8*
878 %pp = getelementptr inbounds i8* %q, i64 %o2
879 ; CHECK-NEXT: getelementptr inbounds %s* %p, i64 %o2
880 %r = bitcast i8* %pp to %s*
882 ; CHECK-NEXT: load %s*
887 define %s @test78(%s *%p, i64 %i, i64 %j, i32 %k, i32 %l, i128 %m, i128 %n) {
888 ; CHECK-LABEL: @test78(
889 %a = mul nsw i32 %k, 36
890 ; CHECK-NEXT: mul nsw i32 %k, 3
891 %b = mul nsw i32 %a, %l
892 ; CHECK-NEXT: mul nsw i32 %a, %l
893 %c = sext i32 %b to i128
894 ; CHECK-NEXT: sext i32 %b to i128
895 %d = mul nsw i128 %c, %m
896 ; CHECK-NEXT: mul nsw i128 %c, %m
898 ; CHECK-NEXT: mul i128 %d, %n
899 %f = trunc i128 %e to i64
900 ; CHECK-NEXT: trunc i128 %e to i64
901 %g = mul nsw i64 %f, %i
902 ; CHECK-NEXT: mul i64 %f, %i
903 %h = mul nsw i64 %g, %j
904 ; CHECK-NEXT: mul i64 %g, %j
905 %q = bitcast %s* %p to i8*
906 %pp = getelementptr inbounds i8* %q, i64 %h
907 ; CHECK-NEXT: getelementptr %s* %p, i64 %h
908 %r = bitcast i8* %pp to %s*
910 ; CHECK-NEXT: load %s*
915 define %s @test79(%s *%p, i64 %i, i32 %j) {
916 ; CHECK-LABEL: @test79(
917 %a = mul nsw i64 %i, 36
918 ; CHECK: mul nsw i64 %i, 36
919 %b = trunc i64 %a to i32
921 %q = bitcast %s* %p to i8*
923 %pp = getelementptr inbounds i8* %q, i32 %c
924 %r = bitcast i8* %pp to %s*
929 define double @test80([100 x double]* %p, i32 %i) {
930 ; CHECK-LABEL: @test80(
931 %tmp = shl nsw i32 %i, 3
932 ; CHECK-NEXT: sext i32 %i to i64
933 %q = bitcast [100 x double]* %p to i8*
934 %pp = getelementptr i8* %q, i32 %tmp
935 ; CHECK-NEXT: getelementptr [100 x double]*
936 %r = bitcast i8* %pp to double*
938 ; CHECK-NEXT: load double*
940 ; CHECK-NEXT: ret double
943 define double @test80_addrspacecast([100 x double] addrspace(1)* %p, i32 %i) {
944 ; CHECK-LABEL: @test80_addrspacecast(
945 ; CHECK-NEXT: getelementptr [100 x double] addrspace(1)* %p
946 ; CHECK-NEXT: load double addrspace(1)*
947 ; CHECK-NEXT: ret double
948 %tmp = shl nsw i32 %i, 3
949 %q = addrspacecast [100 x double] addrspace(1)* %p to i8 addrspace(2)*
950 %pp = getelementptr i8 addrspace(2)* %q, i32 %tmp
951 %r = addrspacecast i8 addrspace(2)* %pp to double addrspace(1)*
952 %l = load double addrspace(1)* %r
956 define double @test80_addrspacecast_2([100 x double] addrspace(1)* %p, i32 %i) {
957 ; CHECK-LABEL: @test80_addrspacecast_2(
958 ; CHECK-NEXT: getelementptr [100 x double] addrspace(1)*
959 ; CHECK-NEXT: addrspacecast double addrspace(1)*
960 ; CHECK-NEXT: load double addrspace(3)*
961 ; CHECK-NEXT: ret double
962 %tmp = shl nsw i32 %i, 3
963 %q = addrspacecast [100 x double] addrspace(1)* %p to i8 addrspace(2)*
964 %pp = getelementptr i8 addrspace(2)* %q, i32 %tmp
965 %r = addrspacecast i8 addrspace(2)* %pp to double addrspace(3)*
966 %l = load double addrspace(3)* %r
970 define double @test80_as1([100 x double] addrspace(1)* %p, i16 %i) {
971 ; CHECK-LABEL: @test80_as1(
972 %tmp = shl nsw i16 %i, 3
973 ; CHECK-NEXT: sext i16 %i to i32
974 %q = bitcast [100 x double] addrspace(1)* %p to i8 addrspace(1)*
975 %pp = getelementptr i8 addrspace(1)* %q, i16 %tmp
976 ; CHECK-NEXT: getelementptr [100 x double] addrspace(1)*
977 %r = bitcast i8 addrspace(1)* %pp to double addrspace(1)*
978 %l = load double addrspace(1)* %r
979 ; CHECK-NEXT: load double addrspace(1)*
981 ; CHECK-NEXT: ret double
984 define double @test81(double *%p, float %f) {
985 %i = fptosi float %f to i64
986 %q = bitcast double* %p to i8*
987 %pp = getelementptr i8* %q, i64 %i
988 %r = bitcast i8* %pp to double*
993 define i64 @test82(i64 %A) nounwind {
994 %B = trunc i64 %A to i32
997 %E = zext i32 %D to i64
1000 ; CHECK-LABEL: @test82(
1001 ; CHECK-NEXT: [[REG:%[0-9]*]] = shl i64 %A, 1
1002 ; CHECK-NEXT: %E = and i64 [[REG]], 4294966784
1003 ; CHECK-NEXT: ret i64 %E
1007 define i64 @test83(i16 %a, i64 %k) {
1008 %conv = sext i16 %a to i32
1009 %sub = add nsw i64 %k, -1
1010 %sh_prom = trunc i64 %sub to i32
1011 %shl = shl i32 %conv, %sh_prom
1012 %sh_prom1 = zext i32 %shl to i64
1015 ; CHECK-LABEL: @test83(
1016 ; CHECK: %sub = add i64 %k, 4294967295
1017 ; CHECK: %sh_prom = trunc i64 %sub to i32
1018 ; CHECK: %shl = shl i32 %conv, %sh_prom
1021 define i8 @test84(i32 %a) {
1022 %add = add nsw i32 %a, -16777216
1023 %shr = lshr exact i32 %add, 23
1024 %trunc = trunc i32 %shr to i8
1027 ; CHECK-LABEL: @test84(
1028 ; CHECK: [[ADD:%.*]] = add i32 %a, 2130706432
1029 ; CHECK: [[SHR:%.*]] = lshr exact i32 [[ADD]], 23
1030 ; CHECK: [[CST:%.*]] = trunc i32 [[SHR]] to i8
1033 define i8 @test85(i32 %a) {
1034 %add = add nuw i32 %a, -16777216
1035 %shr = lshr exact i32 %add, 23
1036 %trunc = trunc i32 %shr to i8
1039 ; CHECK-LABEL: @test85(
1040 ; CHECK: [[ADD:%.*]] = add i32 %a, 2130706432
1041 ; CHECK: [[SHR:%.*]] = lshr exact i32 [[ADD]], 23
1042 ; CHECK: [[CST:%.*]] = trunc i32 [[SHR]] to i8
1045 ; Overflow on a float to int or int to float conversion is undefined (PR21130).
1047 define i8 @overflow_fptosi() {
1048 %i = fptosi double 1.56e+02 to i8
1050 ; CHECK-LABEL: @overflow_fptosi(
1051 ; CHECK-NEXT: ret i8 undef
1054 define i8 @overflow_fptoui() {
1055 %i = fptoui double 2.56e+02 to i8
1057 ; CHECK-LABEL: @overflow_fptoui(
1058 ; CHECK-NEXT: ret i8 undef
1061 ; The maximum float is approximately 2 ** 128 which is 3.4E38.
1062 ; The constant below is 4E38. Use a 130 bit integer to hold that
1063 ; number; 129-bits for the value + 1 bit for the sign.
1064 define float @overflow_uitofp() {
1065 %i = uitofp i130 400000000000000000000000000000000000000 to float
1067 ; CHECK-LABEL: @overflow_uitofp(
1068 ; CHECK-NEXT: ret float undef
1071 define float @overflow_sitofp() {
1072 %i = sitofp i130 400000000000000000000000000000000000000 to float
1074 ; CHECK-LABEL: @overflow_sitofp(
1075 ; CHECK-NEXT: ret float undef
1078 define i32 @PR21388(i32* %v) {
1079 %icmp = icmp slt i32* %v, null
1080 %sext = sext i1 %icmp to i32
1082 ; CHECK-LABEL: @PR21388(
1083 ; CHECK-NEXT: %[[icmp:.*]] = icmp slt i32* %v, null
1084 ; CHECK-NEXT: %[[sext:.*]] = sext i1 %[[icmp]] to i32
1085 ; CHECK-NEXT: ret i32 %[[sext]]