1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128-v128:128:128-n32:64"
5 target triple = "powerpc64-unknown-linux-gnu"
7 ; These tests are extracted from bitcast.ll.
8 ; Verify that they also work correctly on big-endian targets.
10 define float @test2(<2 x float> %A, <2 x i32> %B) {
11 ; CHECK-LABEL: @test2(
12 ; CHECK-NEXT: [[TMP24:%.*]] = extractelement <2 x float> [[A:%.*]], i32 1
13 ; CHECK-NEXT: [[BC:%.*]] = bitcast <2 x i32> [[B:%.*]] to <2 x float>
14 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x float> [[BC]], i32 1
15 ; CHECK-NEXT: [[ADD:%.*]] = fadd float [[TMP24]], [[TMP4]]
16 ; CHECK-NEXT: ret float [[ADD]]
18 %tmp28 = bitcast <2 x float> %A to i64
19 %tmp23 = trunc i64 %tmp28 to i32
20 %tmp24 = bitcast i32 %tmp23 to float
22 %tmp = bitcast <2 x i32> %B to i64
23 %tmp2 = trunc i64 %tmp to i32
24 %tmp4 = bitcast i32 %tmp2 to float
26 %add = fadd float %tmp24, %tmp4
30 define float @test3(<2 x float> %A, <2 x i64> %B) {
31 ; CHECK-LABEL: @test3(
32 ; CHECK-NEXT: [[TMP24:%.*]] = extractelement <2 x float> [[A:%.*]], i32 0
33 ; CHECK-NEXT: [[BC2:%.*]] = bitcast <2 x i64> [[B:%.*]] to <4 x float>
34 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[BC2]], i32 1
35 ; CHECK-NEXT: [[ADD:%.*]] = fadd float [[TMP24]], [[TMP4]]
36 ; CHECK-NEXT: ret float [[ADD]]
38 %tmp28 = bitcast <2 x float> %A to i64
39 %tmp29 = lshr i64 %tmp28, 32
40 %tmp23 = trunc i64 %tmp29 to i32
41 %tmp24 = bitcast i32 %tmp23 to float
43 %tmp = bitcast <2 x i64> %B to i128
44 %tmp1 = lshr i128 %tmp, 64
45 %tmp2 = trunc i128 %tmp1 to i32
46 %tmp4 = bitcast i32 %tmp2 to float
48 %add = fadd float %tmp24, %tmp4
52 define <2 x i32> @test4(i32 %A, i32 %B){
53 ; CHECK-LABEL: @test4(
54 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> undef, i32 [[B:%.*]], i32 0
55 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x i32> [[TMP1]], i32 [[A:%.*]], i32 1
56 ; CHECK-NEXT: ret <2 x i32> [[TMP2]]
58 %tmp38 = zext i32 %A to i64
59 %tmp32 = zext i32 %B to i64
60 %tmp33 = shl i64 %tmp32, 32
61 %ins35 = or i64 %tmp33, %tmp38
62 %tmp43 = bitcast i64 %ins35 to <2 x i32>
66 define <2 x float> @test5(float %A, float %B) {
67 ; CHECK-LABEL: @test5(
68 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x float> undef, float [[B:%.*]], i32 0
69 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x float> [[TMP1]], float [[A:%.*]], i32 1
70 ; CHECK-NEXT: ret <2 x float> [[TMP2]]
72 %tmp37 = bitcast float %A to i32
73 %tmp38 = zext i32 %tmp37 to i64
74 %tmp31 = bitcast float %B to i32
75 %tmp32 = zext i32 %tmp31 to i64
76 %tmp33 = shl i64 %tmp32, 32
77 %ins35 = or i64 %tmp33, %tmp38
78 %tmp43 = bitcast i64 %ins35 to <2 x float>
79 ret <2 x float> %tmp43
82 define <2 x float> @test6(float %A){
83 ; CHECK-LABEL: @test6(
84 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x float> <float undef, float 4.200000e+01>, float [[A:%.*]], i32 0
85 ; CHECK-NEXT: ret <2 x float> [[TMP1]]
87 %tmp23 = bitcast float %A to i32
88 %tmp24 = zext i32 %tmp23 to i64
89 %tmp25 = shl i64 %tmp24, 32
90 %mask20 = or i64 %tmp25, 1109917696
91 %tmp35 = bitcast i64 %mask20 to <2 x float>
92 ret <2 x float> %tmp35
95 ; No change. Bitcasts are canonicalized above bitwise logic.
97 define <2 x i32> @xor_bitcast_vec_to_vec(<1 x i64> %a) {
98 ; CHECK-LABEL: @xor_bitcast_vec_to_vec(
99 ; CHECK-NEXT: [[T1:%.*]] = bitcast <1 x i64> [[A:%.*]] to <2 x i32>
100 ; CHECK-NEXT: [[T2:%.*]] = xor <2 x i32> [[T1]], <i32 1, i32 2>
101 ; CHECK-NEXT: ret <2 x i32> [[T2]]
103 %t1 = bitcast <1 x i64> %a to <2 x i32>
104 %t2 = xor <2 x i32> <i32 1, i32 2>, %t1
108 ; No change. Bitcasts are canonicalized above bitwise logic.
110 define i64 @and_bitcast_vec_to_int(<2 x i32> %a) {
111 ; CHECK-LABEL: @and_bitcast_vec_to_int(
112 ; CHECK-NEXT: [[T1:%.*]] = bitcast <2 x i32> [[A:%.*]] to i64
113 ; CHECK-NEXT: [[T2:%.*]] = and i64 [[T1]], 3
114 ; CHECK-NEXT: ret i64 [[T2]]
116 %t1 = bitcast <2 x i32> %a to i64
121 ; No change. Bitcasts are canonicalized above bitwise logic.
123 define <2 x i32> @or_bitcast_int_to_vec(i64 %a) {
124 ; CHECK-LABEL: @or_bitcast_int_to_vec(
125 ; CHECK-NEXT: [[T1:%.*]] = bitcast i64 [[A:%.*]] to <2 x i32>
126 ; CHECK-NEXT: [[T2:%.*]] = or <2 x i32> [[T1]], <i32 1, i32 2>
127 ; CHECK-NEXT: ret <2 x i32> [[T2]]
129 %t1 = bitcast i64 %a to <2 x i32>
130 %t2 = or <2 x i32> %t1, <i32 1, i32 2>