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 declare i32 @__gxx_personality_v0(...)
103 define void @test_invoke_vararg_cast(i32* %a, i32* %b) {
105 %0 = bitcast i32* %b to i8*
106 %1 = bitcast i32* %a to i64*
107 invoke void (i32, ...)* @varargs(i32 1, i8* %0, i64* %1)
108 to label %invoke.cont unwind label %lpad
110 invoke.cont: ; preds = %entry
113 lpad: ; preds = %entry
114 %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
117 ; CHECK-LABEL: test_invoke_vararg_cast
118 ; CHECK-LABEL: entry:
119 ; CHECK: invoke void (i32, ...)* @varargs(i32 1, i32* %b, i32* %a)
122 define i8* @test13(i64 %A) {
123 %c = getelementptr [0 x i8], [0 x i8]* bitcast ([32832 x i8]* @inbuf to [0 x i8]*), i64 0, i64 %A ; <i8*> [#uses=1]
125 ; CHECK: %c = getelementptr [32832 x i8], [32832 x i8]* @inbuf, i64 0, i64 %A
129 define i1 @test14(i8 %A) {
130 %c = bitcast i8 %A to i8 ; <i8> [#uses=1]
131 %X = icmp ult i8 %c, -128 ; <i1> [#uses=1]
133 ; CHECK: %X = icmp sgt i8 %A, -1
138 ; This just won't occur when there's no difference between ubyte and sbyte
139 ;bool %test15(ubyte %A) {
140 ; %c = cast ubyte %A to sbyte
141 ; %X = setlt sbyte %c, 0 ; setgt %A, 127
145 define i1 @test16(i32* %P) {
146 %c = icmp ne i32* %P, null ; <i1> [#uses=1]
148 ; CHECK: %c = icmp ne i32* %P, null
152 define i16 @test17(i1 %tmp3) {
153 %c = zext i1 %tmp3 to i32 ; <i32> [#uses=1]
154 %t86 = trunc i32 %c to i16 ; <i16> [#uses=1]
156 ; CHECK: %t86 = zext i1 %tmp3 to i16
157 ; CHECK: ret i16 %t86
160 define i16 @test18(i8 %tmp3) {
161 %c = sext i8 %tmp3 to i32 ; <i32> [#uses=1]
162 %t86 = trunc i32 %c to i16 ; <i16> [#uses=1]
164 ; CHECK: %t86 = sext i8 %tmp3 to i16
165 ; CHECK: ret i16 %t86
168 define i1 @test19(i32 %X) {
169 %c = sext i32 %X to i64 ; <i64> [#uses=1]
170 %Z = icmp slt i64 %c, 12345 ; <i1> [#uses=1]
172 ; CHECK: %Z = icmp slt i32 %X, 12345
176 define i1 @test20(i1 %B) {
177 %c = zext i1 %B to i32 ; <i32> [#uses=1]
178 %D = icmp slt i32 %c, -1 ; <i1> [#uses=1]
181 ; CHECK: ret i1 false
184 define i32 @test21(i32 %X) {
185 %c1 = trunc i32 %X to i8 ; <i8> [#uses=1]
186 ;; sext -> zext -> and -> nop
187 %c2 = sext i8 %c1 to i32 ; <i32> [#uses=1]
188 %RV = and i32 %c2, 255 ; <i32> [#uses=1]
190 ; CHECK: %c21 = and i32 %X, 255
191 ; CHECK: ret i32 %c21
194 define i32 @test22(i32 %X) {
195 %c1 = trunc i32 %X to i8 ; <i8> [#uses=1]
196 ;; sext -> zext -> and -> nop
197 %c2 = sext i8 %c1 to i32 ; <i32> [#uses=1]
198 %RV = shl i32 %c2, 24 ; <i32> [#uses=1]
200 ; CHECK: shl i32 %X, 24
201 ; CHECK-NEXT: ret i32
204 define i32 @test23(i32 %X) {
205 ;; Turn into an AND even though X
206 %c1 = trunc i32 %X to i16 ; <i16> [#uses=1]
208 %c2 = zext i16 %c1 to i32 ; <i32> [#uses=1]
210 ; CHECK: %c2 = and i32 %X, 65535
214 define i1 @test24(i1 %C) {
215 %X = select i1 %C, i32 14, i32 1234 ; <i32> [#uses=1]
216 ;; Fold cast into select
217 %c = icmp ne i32 %X, 0 ; <i1> [#uses=1]
222 define i32 @test26(float %F) {
223 ;; no need to cast from float->double.
224 %c = fpext float %F to double ; <double> [#uses=1]
225 %D = fptosi double %c to i32 ; <i32> [#uses=1]
227 ; CHECK: %D = fptosi float %F to i32
231 define [4 x float]* @test27([9 x [4 x float]]* %A) {
232 %c = bitcast [9 x [4 x float]]* %A to [4 x float]* ; <[4 x float]*> [#uses=1]
234 ; CHECK: %c = getelementptr inbounds [9 x [4 x float]], [9 x [4 x float]]* %A, i64 0, i64 0
235 ; CHECK: ret [4 x float]* %c
238 define float* @test28([4 x float]* %A) {
239 %c = bitcast [4 x float]* %A to float* ; <float*> [#uses=1]
241 ; CHECK: %c = getelementptr inbounds [4 x float], [4 x float]* %A, i64 0, i64 0
242 ; CHECK: ret float* %c
245 define i32 @test29(i32 %c1, i32 %c2) {
246 %tmp1 = trunc i32 %c1 to i8 ; <i8> [#uses=1]
247 %tmp4.mask = trunc i32 %c2 to i8 ; <i8> [#uses=1]
248 %tmp = or i8 %tmp4.mask, %tmp1 ; <i8> [#uses=1]
249 %tmp10 = zext i8 %tmp to i32 ; <i32> [#uses=1]
251 ; CHECK: %tmp2 = or i32 %c2, %c1
252 ; CHECK: %tmp10 = and i32 %tmp2, 255
253 ; CHECK: ret i32 %tmp10
256 define i32 @test30(i32 %c1) {
257 %c2 = trunc i32 %c1 to i8 ; <i8> [#uses=1]
258 %c3 = xor i8 %c2, 1 ; <i8> [#uses=1]
259 %c4 = zext i8 %c3 to i32 ; <i32> [#uses=1]
261 ; CHECK: %c3 = and i32 %c1, 255
262 ; CHECK: %c4 = xor i32 %c3, 1
266 define i1 @test31(i64 %A) {
267 %B = trunc i64 %A to i32 ; <i32> [#uses=1]
268 %C = and i32 %B, 42 ; <i32> [#uses=1]
269 %D = icmp eq i32 %C, 10 ; <i1> [#uses=1]
271 ; CHECK: %C = and i64 %A, 42
272 ; CHECK: %D = icmp eq i64 %C, 10
276 define i32 @test33(i32 %c1) {
277 %x = bitcast i32 %c1 to float ; <float> [#uses=1]
278 %y = bitcast float %x to i32 ; <i32> [#uses=1]
283 define i16 @test34(i16 %a) {
284 %c1 = zext i16 %a to i32 ; <i32> [#uses=1]
285 %tmp21 = lshr i32 %c1, 8 ; <i32> [#uses=1]
286 %c2 = trunc i32 %tmp21 to i16 ; <i16> [#uses=1]
288 ; CHECK: %tmp21 = lshr i16 %a, 8
289 ; CHECK: ret i16 %tmp21
292 define i16 @test35(i16 %a) {
293 %c1 = bitcast i16 %a to i16 ; <i16> [#uses=1]
294 %tmp2 = lshr i16 %c1, 8 ; <i16> [#uses=1]
295 %c2 = bitcast i16 %tmp2 to i16 ; <i16> [#uses=1]
297 ; CHECK: %tmp2 = lshr i16 %a, 8
298 ; CHECK: ret i16 %tmp2
301 ; icmp sgt i32 %a, -1
303 define i1 @test36(i32 %a) {
305 %c = trunc i32 %b to i8
306 %d = icmp eq i8 %c, 0
308 ; CHECK: %d = icmp sgt i32 %a, -1
313 define i1 @test37(i32 %a) {
316 %d = trunc i32 %c to i8
317 %e = icmp eq i8 %d, 11
319 ; CHECK: ret i1 false
322 define i64 @test38(i32 %a) {
323 %1 = icmp eq i32 %a, -2
324 %2 = zext i1 %1 to i8
326 %4 = zext i8 %3 to i64
328 ; CHECK: %1 = icmp ne i32 %a, -2
329 ; CHECK: %2 = zext i1 %1 to i64
333 define i16 @test39(i16 %a) {
334 %tmp = zext i16 %a to i32
335 %tmp21 = lshr i32 %tmp, 8
336 %tmp5 = shl i32 %tmp, 8
337 %tmp.upgrd.32 = or i32 %tmp21, %tmp5
338 %tmp.upgrd.3 = trunc i32 %tmp.upgrd.32 to i16
340 ; CHECK-LABEL: @test39(
341 ; CHECK: %tmp.upgrd.32 = call i16 @llvm.bswap.i16(i16 %a)
342 ; CHECK: ret i16 %tmp.upgrd.32
345 define i16 @test40(i16 %a) {
346 %tmp = zext i16 %a to i32
347 %tmp21 = lshr i32 %tmp, 9
348 %tmp5 = shl i32 %tmp, 8
349 %tmp.upgrd.32 = or i32 %tmp21, %tmp5
350 %tmp.upgrd.3 = trunc i32 %tmp.upgrd.32 to i16
352 ; CHECK-LABEL: @test40(
353 ; CHECK: %tmp21 = lshr i16 %a, 9
354 ; CHECK: %tmp5 = shl i16 %a, 8
355 ; CHECK: %tmp.upgrd.32 = or i16 %tmp21, %tmp5
356 ; CHECK: ret i16 %tmp.upgrd.32
360 define i32* @test41(i32* %tmp1) {
361 %tmp64 = bitcast i32* %tmp1 to { i32 }*
362 %tmp65 = getelementptr { i32 }, { i32 }* %tmp64, i32 0, i32 0
364 ; CHECK-LABEL: @test41(
365 ; CHECK: ret i32* %tmp1
368 define i32 addrspace(1)* @test41_addrspacecast_smaller(i32* %tmp1) {
369 %tmp64 = addrspacecast i32* %tmp1 to { i32 } addrspace(1)*
370 %tmp65 = getelementptr { i32 }, { i32 } addrspace(1)* %tmp64, i32 0, i32 0
371 ret i32 addrspace(1)* %tmp65
372 ; CHECK-LABEL: @test41_addrspacecast_smaller(
373 ; CHECK: addrspacecast i32* %tmp1 to i32 addrspace(1)*
374 ; CHECK-NEXT: ret i32 addrspace(1)*
377 define i32* @test41_addrspacecast_larger(i32 addrspace(1)* %tmp1) {
378 %tmp64 = addrspacecast i32 addrspace(1)* %tmp1 to { i32 }*
379 %tmp65 = getelementptr { i32 }, { i32 }* %tmp64, i32 0, i32 0
381 ; CHECK-LABEL: @test41_addrspacecast_larger(
382 ; CHECK: addrspacecast i32 addrspace(1)* %tmp1 to i32*
383 ; CHECK-NEXT: ret i32*
386 define i32 @test42(i32 %X) {
387 %Y = trunc i32 %X to i8 ; <i8> [#uses=1]
388 %Z = zext i8 %Y to i32 ; <i32> [#uses=1]
390 ; CHECK-LABEL: @test42(
391 ; CHECK: %Z = and i32 %X, 255
395 define zeroext i64 @test43(i8 zeroext %on_off) nounwind readonly {
396 %A = zext i8 %on_off to i32
398 %C = sext i32 %B to i64
399 ret i64 %C ;; Should be (add (zext i8 -> i64), -1)
400 ; CHECK-LABEL: @test43(
401 ; CHECK-NEXT: %A = zext i8 %on_off to i64
402 ; CHECK-NEXT: %B = add nsw i64 %A, -1
403 ; CHECK-NEXT: ret i64 %B
406 define i64 @test44(i8 %T) {
407 %A = zext i8 %T to i16
409 %C = zext i16 %B to i64
411 ; CHECK-LABEL: @test44(
412 ; CHECK-NEXT: %A = zext i8 %T to i64
413 ; CHECK-NEXT: %B = or i64 %A, 1234
414 ; CHECK-NEXT: ret i64 %B
417 define i64 @test45(i8 %A, i64 %Q) {
418 %D = trunc i64 %Q to i32 ;; should be removed
419 %B = sext i8 %A to i32
421 %E = zext i32 %C to i64
423 ; CHECK-LABEL: @test45(
424 ; CHECK-NEXT: %B = sext i8 %A to i64
425 ; CHECK-NEXT: %C = or i64 %B, %Q
426 ; CHECK-NEXT: %E = and i64 %C, 4294967295
427 ; CHECK-NEXT: ret i64 %E
431 define i64 @test46(i64 %A) {
432 %B = trunc i64 %A to i32
435 %E = zext i32 %D to i64
437 ; CHECK-LABEL: @test46(
438 ; CHECK-NEXT: %C = shl i64 %A, 8
439 ; CHECK-NEXT: %D = and i64 %C, 10752
440 ; CHECK-NEXT: ret i64 %D
443 define i64 @test47(i8 %A) {
444 %B = sext i8 %A to i32
446 %E = zext i32 %C to i64
448 ; CHECK-LABEL: @test47(
449 ; CHECK-NEXT: %B = sext i8 %A to i64
450 ; CHECK-NEXT: %C = and i64 %B, 4294967253
451 ; CHECK-NEXT: %E = or i64 %C, 42
452 ; CHECK-NEXT: ret i64 %E
455 define i64 @test48(i8 %A, i8 %a) {
456 %b = zext i8 %a to i32
457 %B = zext i8 %A to i32
460 %E = zext i32 %D to i64
462 ; CHECK-LABEL: @test48(
463 ; CHECK-NEXT: %b = zext i8 %a to i64
464 ; CHECK-NEXT: %B = zext i8 %A to i64
465 ; CHECK-NEXT: %C = shl nuw nsw i64 %B, 8
466 ; CHECK-NEXT: %D = or i64 %C, %b
467 ; CHECK-NEXT: ret i64 %D
470 define i64 @test49(i64 %A) {
471 %B = trunc i64 %A to i32
473 %D = sext i32 %C to i64
475 ; CHECK-LABEL: @test49(
476 ; CHECK-NEXT: %C = shl i64 %A, 32
477 ; CHECK-NEXT: ashr exact i64 %C, 32
478 ; CHECK-NEXT: %D = or i64 {{.*}}, 1
479 ; CHECK-NEXT: ret i64 %D
482 define i64 @test50(i64 %A) {
484 %B = trunc i64 %a to i32
486 %E = sext i32 %D to i64
488 ; CHECK-LABEL: @test50(
489 ; lshr+shl will be handled by DAGCombine.
490 ; CHECK-NEXT: lshr i64 %A, 2
491 ; CHECK-NEXT: shl i64 %a, 32
492 ; CHECK-NEXT: add i64 {{.*}}, -4294967296
493 ; CHECK-NEXT: %E = ashr exact i64 {{.*}}, 32
494 ; CHECK-NEXT: ret i64 %E
497 define i64 @test51(i64 %A, i1 %cond) {
498 %B = trunc i64 %A to i32
501 %E = select i1 %cond, i32 %C, i32 %D
502 %F = sext i32 %E to i64
504 ; CHECK-LABEL: @test51(
505 ; CHECK-NEXT: %C = and i64 %A, 4294967294
506 ; CHECK-NEXT: %D = or i64 %A, 1
507 ; CHECK-NEXT: %E = select i1 %cond, i64 %C, i64 %D
508 ; CHECK-NEXT: %sext = shl i64 %E, 32
509 ; CHECK-NEXT: %F = ashr exact i64 %sext, 32
510 ; CHECK-NEXT: ret i64 %F
513 define i32 @test52(i64 %A) {
514 %B = trunc i64 %A to i16
515 %C = or i16 %B, -32574
516 %D = and i16 %C, -25350
517 %E = zext i16 %D to i32
519 ; CHECK-LABEL: @test52(
520 ; CHECK-NEXT: %B = trunc i64 %A to i32
521 ; CHECK-NEXT: %C = and i32 %B, 7224
522 ; CHECK-NEXT: %D = or i32 %C, 32962
523 ; CHECK-NEXT: ret i32 %D
526 define i64 @test53(i32 %A) {
527 %B = trunc i32 %A to i16
528 %C = or i16 %B, -32574
529 %D = and i16 %C, -25350
530 %E = zext i16 %D to i64
532 ; CHECK-LABEL: @test53(
533 ; CHECK-NEXT: %B = zext i32 %A to i64
534 ; CHECK-NEXT: %C = and i64 %B, 7224
535 ; CHECK-NEXT: %D = or i64 %C, 32962
536 ; CHECK-NEXT: ret i64 %D
539 define i32 @test54(i64 %A) {
540 %B = trunc i64 %A to i16
541 %C = or i16 %B, -32574
542 %D = and i16 %C, -25350
543 %E = sext i16 %D to i32
545 ; CHECK-LABEL: @test54(
546 ; CHECK-NEXT: %B = trunc i64 %A to i32
547 ; CHECK-NEXT: %C = and i32 %B, 7224
548 ; CHECK-NEXT: %D = or i32 %C, -32574
549 ; CHECK-NEXT: ret i32 %D
552 define i64 @test55(i32 %A) {
553 %B = trunc i32 %A to i16
554 %C = or i16 %B, -32574
555 %D = and i16 %C, -25350
556 %E = sext i16 %D to i64
558 ; CHECK-LABEL: @test55(
559 ; CHECK-NEXT: %B = zext i32 %A to i64
560 ; CHECK-NEXT: %C = and i64 %B, 7224
561 ; CHECK-NEXT: %D = or i64 %C, -32574
562 ; CHECK-NEXT: ret i64 %D
565 define i64 @test56(i16 %A) nounwind {
566 %tmp353 = sext i16 %A to i32
567 %tmp354 = lshr i32 %tmp353, 5
568 %tmp355 = zext i32 %tmp354 to i64
570 ; CHECK-LABEL: @test56(
571 ; CHECK-NEXT: %tmp353 = sext i16 %A to i64
572 ; CHECK-NEXT: %tmp354 = lshr i64 %tmp353, 5
573 ; CHECK-NEXT: %tmp355 = and i64 %tmp354, 134217727
574 ; CHECK-NEXT: ret i64 %tmp355
577 define i64 @test57(i64 %A) nounwind {
578 %B = trunc i64 %A to i32
580 %E = zext i32 %C to i64
582 ; CHECK-LABEL: @test57(
583 ; CHECK-NEXT: %C = lshr i64 %A, 8
584 ; CHECK-NEXT: %E = and i64 %C, 16777215
585 ; CHECK-NEXT: ret i64 %E
588 define i64 @test58(i64 %A) nounwind {
589 %B = trunc i64 %A to i32
592 %E = zext i32 %D to i64
595 ; CHECK-LABEL: @test58(
596 ; CHECK-NEXT: %C = lshr i64 %A, 8
597 ; CHECK-NEXT: %D = and i64 %C, 16777087
598 ; CHECK-NEXT: %E = or i64 %D, 128
599 ; CHECK-NEXT: ret i64 %E
602 define i64 @test59(i8 %A, i8 %B) nounwind {
603 %C = zext i8 %A to i32
606 %F = zext i8 %B to i32
609 %I = zext i32 %H to i64
611 ; CHECK-LABEL: @test59(
612 ; CHECK-NEXT: %C = zext i8 %A to i64
614 ; CHECK: %F = zext i8 %B to i64
619 define <3 x i32> @test60(<4 x i32> %call4) nounwind {
620 %tmp11 = bitcast <4 x i32> %call4 to i128
621 %tmp9 = trunc i128 %tmp11 to i96
622 %tmp10 = bitcast i96 %tmp9 to <3 x i32>
625 ; CHECK-LABEL: @test60(
626 ; CHECK-NEXT: shufflevector
630 define <4 x i32> @test61(<3 x i32> %call4) nounwind {
631 %tmp11 = bitcast <3 x i32> %call4 to i96
632 %tmp9 = zext i96 %tmp11 to i128
633 %tmp10 = bitcast i128 %tmp9 to <4 x i32>
635 ; CHECK-LABEL: @test61(
636 ; CHECK-NEXT: shufflevector
640 define <4 x i32> @test62(<3 x float> %call4) nounwind {
641 %tmp11 = bitcast <3 x float> %call4 to i96
642 %tmp9 = zext i96 %tmp11 to i128
643 %tmp10 = bitcast i128 %tmp9 to <4 x i32>
645 ; CHECK-LABEL: @test62(
646 ; CHECK-NEXT: bitcast
647 ; CHECK-NEXT: shufflevector
651 ; PR7311 - Don't create invalid IR on scalar->vector cast.
652 define <2 x float> @test63(i64 %tmp8) nounwind {
654 %a = bitcast i64 %tmp8 to <2 x i32>
655 %vcvt.i = uitofp <2 x i32> %a to <2 x float>
656 ret <2 x float> %vcvt.i
657 ; CHECK-LABEL: @test63(
662 define <4 x float> @test64(<4 x float> %c) nounwind {
663 %t0 = bitcast <4 x float> %c to <4 x i32>
664 %t1 = bitcast <4 x i32> %t0 to <4 x float>
666 ; CHECK-LABEL: @test64(
667 ; CHECK-NEXT: ret <4 x float> %c
670 define <4 x float> @test65(<4 x float> %c) nounwind {
671 %t0 = bitcast <4 x float> %c to <2 x double>
672 %t1 = bitcast <2 x double> %t0 to <4 x float>
674 ; CHECK-LABEL: @test65(
675 ; CHECK-NEXT: ret <4 x float> %c
678 define <2 x float> @test66(<2 x float> %c) nounwind {
679 %t0 = bitcast <2 x float> %c to double
680 %t1 = bitcast double %t0 to <2 x float>
682 ; CHECK-LABEL: @test66(
683 ; CHECK-NEXT: ret <2 x float> %c
686 define float @test2c() {
687 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)
688 ; CHECK-LABEL: @test2c(
689 ; CHECK-NOT: extractelement
692 define i64 @test_mmx(<2 x i32> %c) nounwind {
693 %A = bitcast <2 x i32> %c to x86_mmx
694 %B = bitcast x86_mmx %A to <2 x i32>
695 %C = bitcast <2 x i32> %B to i64
697 ; CHECK-LABEL: @test_mmx(
701 define i64 @test_mmx_const(<2 x i32> %c) nounwind {
702 %A = bitcast <2 x i32> zeroinitializer to x86_mmx
703 %B = bitcast x86_mmx %A to <2 x i32>
704 %C = bitcast <2 x i32> %B to i64
706 ; CHECK-LABEL: @test_mmx_const(
711 define i1 @test67(i1 %a, i32 %b) {
712 %tmp2 = zext i1 %a to i32
713 %conv6 = xor i32 %tmp2, 1
714 %and = and i32 %b, %conv6
715 %sext = shl nuw nsw i32 %and, 24
716 %neg.i = xor i32 %sext, -16777216
717 %conv.i.i = ashr exact i32 %neg.i, 24
718 %trunc = trunc i32 %conv.i.i to i8
719 %tobool.i = icmp eq i8 %trunc, 0
721 ; CHECK-LABEL: @test67(
722 ; CHECK: ret i1 false
725 %s = type { i32, i32, i32 }
727 define %s @test68(%s *%p, i64 %i) {
728 ; CHECK-LABEL: @test68(
730 %q = bitcast %s* %p to i8*
731 %pp = getelementptr inbounds i8, i8* %q, i64 %o
732 ; CHECK-NEXT: getelementptr %s, %s*
733 %r = bitcast i8* %pp to %s*
735 ; CHECK-NEXT: load %s, %s*
740 ; addrspacecasts should be eliminated.
741 define %s @test68_addrspacecast(%s* %p, i64 %i) {
742 ; CHECK-LABEL: @test68_addrspacecast(
743 ; CHECK-NEXT: getelementptr %s, %s*
744 ; CHECK-NEXT: load %s, %s*
747 %q = addrspacecast %s* %p to i8 addrspace(2)*
748 %pp = getelementptr inbounds i8, i8 addrspace(2)* %q, i64 %o
749 %r = addrspacecast i8 addrspace(2)* %pp to %s*
754 define %s @test68_addrspacecast_2(%s* %p, i64 %i) {
755 ; CHECK-LABEL: @test68_addrspacecast_2(
756 ; CHECK-NEXT: getelementptr %s, %s* %p
757 ; CHECK-NEXT: addrspacecast
758 ; CHECK-NEXT: load %s, %s addrspace(1)*
761 %q = addrspacecast %s* %p to i8 addrspace(2)*
762 %pp = getelementptr inbounds i8, i8 addrspace(2)* %q, i64 %o
763 %r = addrspacecast i8 addrspace(2)* %pp to %s addrspace(1)*
764 %l = load %s, %s addrspace(1)* %r
768 define %s @test68_as1(%s addrspace(1)* %p, i32 %i) {
769 ; CHECK-LABEL: @test68_as1(
771 %q = bitcast %s addrspace(1)* %p to i8 addrspace(1)*
772 %pp = getelementptr inbounds i8, i8 addrspace(1)* %q, i32 %o
773 ; CHECK-NEXT: getelementptr %s, %s addrspace(1)*
774 %r = bitcast i8 addrspace(1)* %pp to %s addrspace(1)*
775 %l = load %s, %s addrspace(1)* %r
776 ; CHECK-NEXT: load %s, %s addrspace(1)*
781 define double @test69(double *%p, i64 %i) {
782 ; CHECK-LABEL: @test69(
783 %o = shl nsw i64 %i, 3
784 %q = bitcast double* %p to i8*
785 %pp = getelementptr inbounds i8, i8* %q, i64 %o
786 ; CHECK-NEXT: getelementptr inbounds double, double*
787 %r = bitcast i8* %pp to double*
788 %l = load double, double* %r
789 ; CHECK-NEXT: load double, double*
791 ; CHECK-NEXT: ret double
794 define %s @test70(%s *%p, i64 %i) {
795 ; CHECK-LABEL: @test70(
796 %o = mul nsw i64 %i, 36
797 ; CHECK-NEXT: mul nsw i64 %i, 3
798 %q = bitcast %s* %p to i8*
799 %pp = getelementptr inbounds i8, i8* %q, i64 %o
800 ; CHECK-NEXT: getelementptr inbounds %s, %s*
801 %r = bitcast i8* %pp to %s*
803 ; CHECK-NEXT: load %s, %s*
808 define double @test71(double *%p, i64 %i) {
809 ; CHECK-LABEL: @test71(
811 ; CHECK-NEXT: shl i64 %i, 2
812 %q = bitcast double* %p to i8*
813 %pp = getelementptr i8, i8* %q, i64 %o
814 ; CHECK-NEXT: getelementptr double, double*
815 %r = bitcast i8* %pp to double*
816 %l = load double, double* %r
817 ; CHECK-NEXT: load double, double*
819 ; CHECK-NEXT: ret double
822 define double @test72(double *%p, i32 %i) {
823 ; CHECK-LABEL: @test72(
824 %so = shl nsw i32 %i, 3
825 %o = sext i32 %so to i64
826 ; CHECK-NEXT: sext i32 %i to i64
827 %q = bitcast double* %p to i8*
828 %pp = getelementptr inbounds i8, i8* %q, i64 %o
829 ; CHECK-NEXT: getelementptr inbounds double, double*
830 %r = bitcast i8* %pp to double*
831 %l = load double, double* %r
832 ; CHECK-NEXT: load double, double*
834 ; CHECK-NEXT: ret double
837 define double @test73(double *%p, i128 %i) {
838 ; CHECK-LABEL: @test73(
839 %lo = shl nsw i128 %i, 3
840 %o = trunc i128 %lo to i64
841 ; CHECK-NEXT: trunc i128 %i to i64
842 %q = bitcast double* %p to i8*
843 %pp = getelementptr inbounds i8, i8* %q, i64 %o
844 ; CHECK-NEXT: getelementptr double, double*
845 %r = bitcast i8* %pp to double*
846 %l = load double, double* %r
847 ; CHECK-NEXT: load double, double*
849 ; CHECK-NEXT: ret double
852 define double @test74(double *%p, i64 %i) {
853 ; CHECK-LABEL: @test74(
854 %q = bitcast double* %p to i64*
855 %pp = getelementptr inbounds i64, i64* %q, i64 %i
856 ; CHECK-NEXT: getelementptr inbounds double, double*
857 %r = bitcast i64* %pp to double*
858 %l = load double, double* %r
859 ; CHECK-NEXT: load double, double*
861 ; CHECK-NEXT: ret double
864 define i32* @test75(i32* %p, i32 %x) {
865 ; CHECK-LABEL: @test75(
867 ; CHECK-NEXT: shl i32 %x, 3
868 %z = sext i32 %y to i64
869 ; CHECK-NEXT: sext i32 %y to i64
870 %q = bitcast i32* %p to i8*
871 %r = getelementptr i8, i8* %q, i64 %z
872 %s = bitcast i8* %r to i32*
876 define %s @test76(%s *%p, i64 %i, i64 %j) {
877 ; CHECK-LABEL: @test76(
879 %o2 = mul nsw i64 %o, %j
880 ; CHECK-NEXT: %o2 = mul i64 %i, %j
881 %q = bitcast %s* %p to i8*
882 %pp = getelementptr inbounds i8, i8* %q, i64 %o2
883 ; CHECK-NEXT: getelementptr %s, %s* %p, i64 %o2
884 %r = bitcast i8* %pp to %s*
886 ; CHECK-NEXT: load %s, %s*
891 define %s @test77(%s *%p, i64 %i, i64 %j) {
892 ; CHECK-LABEL: @test77(
893 %o = mul nsw i64 %i, 36
894 %o2 = mul nsw i64 %o, %j
895 ; CHECK-NEXT: %o = mul nsw i64 %i, 3
896 ; CHECK-NEXT: %o2 = mul nsw i64 %o, %j
897 %q = bitcast %s* %p to i8*
898 %pp = getelementptr inbounds i8, i8* %q, i64 %o2
899 ; CHECK-NEXT: getelementptr inbounds %s, %s* %p, i64 %o2
900 %r = bitcast i8* %pp to %s*
902 ; CHECK-NEXT: load %s, %s*
907 define %s @test78(%s *%p, i64 %i, i64 %j, i32 %k, i32 %l, i128 %m, i128 %n) {
908 ; CHECK-LABEL: @test78(
909 %a = mul nsw i32 %k, 36
910 ; CHECK-NEXT: mul nsw i32 %k, 3
911 %b = mul nsw i32 %a, %l
912 ; CHECK-NEXT: mul nsw i32 %a, %l
913 %c = sext i32 %b to i128
914 ; CHECK-NEXT: sext i32 %b to i128
915 %d = mul nsw i128 %c, %m
916 ; CHECK-NEXT: mul nsw i128 %c, %m
918 ; CHECK-NEXT: mul i128 %d, %n
919 %f = trunc i128 %e to i64
920 ; CHECK-NEXT: trunc i128 %e to i64
921 %g = mul nsw i64 %f, %i
922 ; CHECK-NEXT: mul i64 %f, %i
923 %h = mul nsw i64 %g, %j
924 ; CHECK-NEXT: mul i64 %g, %j
925 %q = bitcast %s* %p to i8*
926 %pp = getelementptr inbounds i8, i8* %q, i64 %h
927 ; CHECK-NEXT: getelementptr %s, %s* %p, i64 %h
928 %r = bitcast i8* %pp to %s*
929 %load = load %s, %s* %r
930 ; CHECK-NEXT: load %s, %s*
935 define %s @test79(%s *%p, i64 %i, i32 %j) {
936 ; CHECK-LABEL: @test79(
937 %a = mul nsw i64 %i, 36
938 ; CHECK: mul nsw i64 %i, 36
939 %b = trunc i64 %a to i32
941 %q = bitcast %s* %p to i8*
943 %pp = getelementptr inbounds i8, i8* %q, i32 %c
944 %r = bitcast i8* %pp to %s*
949 define double @test80([100 x double]* %p, i32 %i) {
950 ; CHECK-LABEL: @test80(
951 %tmp = shl nsw i32 %i, 3
952 ; CHECK-NEXT: sext i32 %i to i64
953 %q = bitcast [100 x double]* %p to i8*
954 %pp = getelementptr i8, i8* %q, i32 %tmp
955 ; CHECK-NEXT: getelementptr [100 x double], [100 x double]*
956 %r = bitcast i8* %pp to double*
957 %l = load double, double* %r
958 ; CHECK-NEXT: load double, double*
960 ; CHECK-NEXT: ret double
963 define double @test80_addrspacecast([100 x double] addrspace(1)* %p, i32 %i) {
964 ; CHECK-LABEL: @test80_addrspacecast(
965 ; CHECK-NEXT: getelementptr [100 x double], [100 x double] addrspace(1)* %p
966 ; CHECK-NEXT: load double, double addrspace(1)*
967 ; CHECK-NEXT: ret double
968 %tmp = shl nsw i32 %i, 3
969 %q = addrspacecast [100 x double] addrspace(1)* %p to i8 addrspace(2)*
970 %pp = getelementptr i8, i8 addrspace(2)* %q, i32 %tmp
971 %r = addrspacecast i8 addrspace(2)* %pp to double addrspace(1)*
972 %l = load double, double addrspace(1)* %r
976 define double @test80_addrspacecast_2([100 x double] addrspace(1)* %p, i32 %i) {
977 ; CHECK-LABEL: @test80_addrspacecast_2(
978 ; CHECK-NEXT: getelementptr [100 x double], [100 x double] addrspace(1)*
979 ; CHECK-NEXT: addrspacecast double addrspace(1)*
980 ; CHECK-NEXT: load double, double addrspace(3)*
981 ; CHECK-NEXT: ret double
982 %tmp = shl nsw i32 %i, 3
983 %q = addrspacecast [100 x double] addrspace(1)* %p to i8 addrspace(2)*
984 %pp = getelementptr i8, i8 addrspace(2)* %q, i32 %tmp
985 %r = addrspacecast i8 addrspace(2)* %pp to double addrspace(3)*
986 %l = load double, double addrspace(3)* %r
990 define double @test80_as1([100 x double] addrspace(1)* %p, i16 %i) {
991 ; CHECK-LABEL: @test80_as1(
992 %tmp = shl nsw i16 %i, 3
993 ; CHECK-NEXT: sext i16 %i to i32
994 %q = bitcast [100 x double] addrspace(1)* %p to i8 addrspace(1)*
995 %pp = getelementptr i8, i8 addrspace(1)* %q, i16 %tmp
996 ; CHECK-NEXT: getelementptr [100 x double], [100 x double] addrspace(1)*
997 %r = bitcast i8 addrspace(1)* %pp to double addrspace(1)*
998 %l = load double, double addrspace(1)* %r
999 ; CHECK-NEXT: load double, double addrspace(1)*
1001 ; CHECK-NEXT: ret double
1004 define double @test81(double *%p, float %f) {
1005 %i = fptosi float %f to i64
1006 %q = bitcast double* %p to i8*
1007 %pp = getelementptr i8, i8* %q, i64 %i
1008 %r = bitcast i8* %pp to double*
1009 %l = load double, double* %r
1013 define i64 @test82(i64 %A) nounwind {
1014 %B = trunc i64 %A to i32
1017 %E = zext i32 %D to i64
1020 ; CHECK-LABEL: @test82(
1021 ; CHECK-NEXT: [[REG:%[0-9]*]] = shl i64 %A, 1
1022 ; CHECK-NEXT: %E = and i64 [[REG]], 4294966784
1023 ; CHECK-NEXT: ret i64 %E
1027 define i64 @test83(i16 %a, i64 %k) {
1028 %conv = sext i16 %a to i32
1029 %sub = add nsw i64 %k, -1
1030 %sh_prom = trunc i64 %sub to i32
1031 %shl = shl i32 %conv, %sh_prom
1032 %sh_prom1 = zext i32 %shl to i64
1035 ; CHECK-LABEL: @test83(
1036 ; CHECK: %sub = add i64 %k, 4294967295
1037 ; CHECK: %sh_prom = trunc i64 %sub to i32
1038 ; CHECK: %shl = shl i32 %conv, %sh_prom
1041 define i8 @test84(i32 %a) {
1042 %add = add nsw i32 %a, -16777216
1043 %shr = lshr exact i32 %add, 23
1044 %trunc = trunc i32 %shr to i8
1047 ; CHECK-LABEL: @test84(
1048 ; CHECK: [[ADD:%.*]] = add i32 %a, 2130706432
1049 ; CHECK: [[SHR:%.*]] = lshr exact i32 [[ADD]], 23
1050 ; CHECK: [[CST:%.*]] = trunc i32 [[SHR]] to i8
1053 define i8 @test85(i32 %a) {
1054 %add = add nuw i32 %a, -16777216
1055 %shr = lshr exact i32 %add, 23
1056 %trunc = trunc i32 %shr to i8
1059 ; CHECK-LABEL: @test85(
1060 ; CHECK: [[ADD:%.*]] = add i32 %a, 2130706432
1061 ; CHECK: [[SHR:%.*]] = lshr exact i32 [[ADD]], 23
1062 ; CHECK: [[CST:%.*]] = trunc i32 [[SHR]] to i8
1065 ; Overflow on a float to int or int to float conversion is undefined (PR21130).
1067 define i8 @overflow_fptosi() {
1068 %i = fptosi double 1.56e+02 to i8
1070 ; CHECK-LABEL: @overflow_fptosi(
1071 ; CHECK-NEXT: ret i8 undef
1074 define i8 @overflow_fptoui() {
1075 %i = fptoui double 2.56e+02 to i8
1077 ; CHECK-LABEL: @overflow_fptoui(
1078 ; CHECK-NEXT: ret i8 undef
1081 ; The maximum float is approximately 2 ** 128 which is 3.4E38.
1082 ; The constant below is 4E38. Use a 130 bit integer to hold that
1083 ; number; 129-bits for the value + 1 bit for the sign.
1084 define float @overflow_uitofp() {
1085 %i = uitofp i130 400000000000000000000000000000000000000 to float
1087 ; CHECK-LABEL: @overflow_uitofp(
1088 ; CHECK-NEXT: ret float undef
1091 define float @overflow_sitofp() {
1092 %i = sitofp i130 400000000000000000000000000000000000000 to float
1094 ; CHECK-LABEL: @overflow_sitofp(
1095 ; CHECK-NEXT: ret float undef
1098 define i32 @PR21388(i32* %v) {
1099 %icmp = icmp slt i32* %v, null
1100 %sext = sext i1 %icmp to i32
1102 ; CHECK-LABEL: @PR21388(
1103 ; CHECK-NEXT: %[[icmp:.*]] = icmp slt i32* %v, null
1104 ; CHECK-NEXT: %[[sext:.*]] = sext i1 %[[icmp]] to i32
1105 ; CHECK-NEXT: ret i32 %[[sext]]
1108 define float @sitofp_zext(i16 %a) {
1109 ; CHECK-LABEL: @sitofp_zext(
1110 ; CHECK-NEXT: %[[sitofp:.*]] = uitofp i16 %a to float
1111 ; CHECK-NEXT: ret float %[[sitofp]]
1112 %zext = zext i16 %a to i32
1113 %sitofp = sitofp i32 %zext to float
1117 define i1 @PR23309(i32 %A, i32 %B) {
1118 ; CHECK-LABEL: @PR23309(
1119 ; CHECK-NEXT: %[[sub:.*]] = sub i32 %A, %B
1120 ; CHECK-NEXT: %[[and:.*]] = and i32 %[[sub]], 1
1121 ; CHECK-NEXT: %[[cmp:.*]] = icmp ne i32 %[[and]], 0
1122 ; CHECK-NEXT: ret i1 %[[cmp]]
1123 %add = add i32 %A, -4
1124 %sub = sub nsw i32 %add, %B
1125 %trunc = trunc i32 %sub to i1
1129 define i1 @PR23309v2(i32 %A, i32 %B) {
1130 ; CHECK-LABEL: @PR23309v2(
1131 ; CHECK-NEXT: %[[sub:.*]] = add i32 %A, %B
1132 ; CHECK-NEXT: %[[and:.*]] = and i32 %[[sub]], 1
1133 ; CHECK-NEXT: %[[cmp:.*]] = icmp ne i32 %[[and]], 0
1134 ; CHECK-NEXT: ret i1 %[[cmp]]
1135 %add = add i32 %A, -4
1136 %sub = add nuw i32 %add, %B
1137 %trunc = trunc i32 %sub to i1