xref: /aosp_15_r20/external/llvm/test/Transforms/InstCombine/bitcast-alias-function.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt -S -instcombine -o - %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-p:32:32:32-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v64:64:64-v128:128:128-a0:0:64"
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Worker; Cases that should be bitcast
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Worker; Test cast between scalars with same bit sizes
9*9880d681SAndroid Build Coastguard Worker@alias_i32_to_f32 = alias float (float), bitcast (i32 (i32)* @func_i32 to float (float)*)
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker; Test cast between vectors with same number of elements and bit sizes
12*9880d681SAndroid Build Coastguard Worker@alias_v2i32_to_v2f32 = alias <2 x float> (<2 x float>), bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <2 x float> (<2 x float>)*)
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Worker; Test cast from vector to scalar with same number of bits
15*9880d681SAndroid Build Coastguard Worker@alias_v2f32_to_i64 = alias <2 x float> (<2 x float>), bitcast (i64 (i64)* @func_i64 to <2 x float> (<2 x float>)*)
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker; Test cast from scalar to vector with same number of bits
18*9880d681SAndroid Build Coastguard Worker@alias_i64_to_v2f32 = alias i64 (i64), bitcast (<2 x float> (<2 x float>)* @func_v2f32 to i64 (i64)*)
19*9880d681SAndroid Build Coastguard Worker
20*9880d681SAndroid Build Coastguard Worker; Test cast between vectors of pointers
21*9880d681SAndroid Build Coastguard Worker@alias_v2i32p_to_v2i64p = alias <2 x i64*> (<2 x i64*>), bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to <2 x i64*> (<2 x i64*>)*)
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker; Cases that should be invalid and unchanged
25*9880d681SAndroid Build Coastguard Worker
26*9880d681SAndroid Build Coastguard Worker; Test cast between scalars with different bit sizes
27*9880d681SAndroid Build Coastguard Worker@alias_i64_to_f32 = alias float (float), bitcast (i64 (i64)* @func_i64 to float (float)*)
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Worker; Test cast between vectors with different bit sizes but the
30*9880d681SAndroid Build Coastguard Worker; same number of elements
31*9880d681SAndroid Build Coastguard Worker@alias_v2i64_to_v2f32 = alias <2 x float> (<2 x float>), bitcast (<2 x i64> (<2 x i64>)* @func_v2i64 to <2 x float> (<2 x float>)*)
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Worker; Test cast between vectors with same number of bits and different
34*9880d681SAndroid Build Coastguard Worker; numbers of elements
35*9880d681SAndroid Build Coastguard Worker@alias_v2i32_to_v4f32 = alias <4 x float> (<4 x float>), bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <4 x float> (<4 x float>)*)
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Worker; Test cast between scalar and vector with different number of bits
38*9880d681SAndroid Build Coastguard Worker@alias_i64_to_v4f32 = alias i64 (i64), bitcast (<4 x float> (<4 x float>)* @func_v4f32 to i64 (i64)*)
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard Worker; Test cast between vector and scalar with different number of bits
41*9880d681SAndroid Build Coastguard Worker@alias_v4f32_to_i64 = alias <4 x float> (<4 x float>), bitcast (i64 (i64)* @func_i64 to <4 x float> (<4 x float>)*)
42*9880d681SAndroid Build Coastguard Worker
43*9880d681SAndroid Build Coastguard Worker; Test cast from scalar to vector of pointers with same number of bits
44*9880d681SAndroid Build Coastguard Worker; We don't know the pointer size at this point, so this can't be done
45*9880d681SAndroid Build Coastguard Worker@alias_i64_to_v2i32p = alias i64 (i64), bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to i64 (i64)*)
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Worker; Test cast between vector of pointers and scalar with different number of bits
48*9880d681SAndroid Build Coastguard Worker@alias_v4i32p_to_i64 = alias <4 x i32*> (<4 x i32*>), bitcast (i64 (i64)* @func_i64 to <4 x i32*> (<4 x i32*>)*)
49*9880d681SAndroid Build Coastguard Worker
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Workerdefine internal <2 x i32> @func_v2i32(<2 x i32> %v) noinline nounwind {
53*9880d681SAndroid Build Coastguard Workerentry:
54*9880d681SAndroid Build Coastguard Worker  ret <2 x i32> %v
55*9880d681SAndroid Build Coastguard Worker}
56*9880d681SAndroid Build Coastguard Worker
57*9880d681SAndroid Build Coastguard Workerdefine internal <2 x float> @func_v2f32(<2 x float> %v) noinline nounwind {
58*9880d681SAndroid Build Coastguard Workerentry:
59*9880d681SAndroid Build Coastguard Worker  ret <2 x float> %v
60*9880d681SAndroid Build Coastguard Worker}
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Workerdefine internal <4 x float> @func_v4f32(<4 x float> %v) noinline nounwind {
63*9880d681SAndroid Build Coastguard Workerentry:
64*9880d681SAndroid Build Coastguard Worker  ret <4 x float> %v
65*9880d681SAndroid Build Coastguard Worker}
66*9880d681SAndroid Build Coastguard Worker
67*9880d681SAndroid Build Coastguard Workerdefine internal i32 @func_i32(i32 %v) noinline nounwind {
68*9880d681SAndroid Build Coastguard Workerentry:
69*9880d681SAndroid Build Coastguard Worker  ret i32 %v
70*9880d681SAndroid Build Coastguard Worker}
71*9880d681SAndroid Build Coastguard Worker
72*9880d681SAndroid Build Coastguard Workerdefine internal i64 @func_i64(i64 %v) noinline nounwind {
73*9880d681SAndroid Build Coastguard Workerentry:
74*9880d681SAndroid Build Coastguard Worker  ret i64 %v
75*9880d681SAndroid Build Coastguard Worker}
76*9880d681SAndroid Build Coastguard Worker
77*9880d681SAndroid Build Coastguard Workerdefine internal <2 x i64> @func_v2i64(<2 x i64> %v) noinline nounwind {
78*9880d681SAndroid Build Coastguard Workerentry:
79*9880d681SAndroid Build Coastguard Worker  ret <2 x i64> %v
80*9880d681SAndroid Build Coastguard Worker}
81*9880d681SAndroid Build Coastguard Worker
82*9880d681SAndroid Build Coastguard Workerdefine internal <2 x i32*> @func_v2i32p(<2 x i32*> %v) noinline nounwind {
83*9880d681SAndroid Build Coastguard Workerentry:
84*9880d681SAndroid Build Coastguard Worker  ret <2 x i32*> %v
85*9880d681SAndroid Build Coastguard Worker}
86*9880d681SAndroid Build Coastguard Worker
87*9880d681SAndroid Build Coastguard Worker; Valid cases, only bitcast for argument / return type and call underlying function
88*9880d681SAndroid Build Coastguard Worker
89*9880d681SAndroid Build Coastguard Worker; Sizes match, should only bitcast
90*9880d681SAndroid Build Coastguard Workerdefine void @bitcast_alias_scalar(float* noalias %source, float* noalias %dest) nounwind {
91*9880d681SAndroid Build Coastguard Workerentry:
92*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @bitcast_alias_scalar
93*9880d681SAndroid Build Coastguard Worker; CHECK: bitcast float* %source to i32*
94*9880d681SAndroid Build Coastguard Worker; CHECK: load i32, i32*
95*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: fptoui
96*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: uitofp
97*9880d681SAndroid Build Coastguard Worker; CHECK: bitcast float* %dest to i32*
98*9880d681SAndroid Build Coastguard Worker; CHECK: store i32
99*9880d681SAndroid Build Coastguard Worker  %tmp = load float, float* %source, align 8
100*9880d681SAndroid Build Coastguard Worker  %call = call float @alias_i32_to_f32(float %tmp) nounwind
101*9880d681SAndroid Build Coastguard Worker  store float %call, float* %dest, align 8
102*9880d681SAndroid Build Coastguard Worker  ret void
103*9880d681SAndroid Build Coastguard Worker}
104*9880d681SAndroid Build Coastguard Worker
105*9880d681SAndroid Build Coastguard Worker; Sizes match, should only bitcast
106*9880d681SAndroid Build Coastguard Workerdefine void @bitcast_alias_vector(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
107*9880d681SAndroid Build Coastguard Workerentry:
108*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @bitcast_alias_vector
109*9880d681SAndroid Build Coastguard Worker; CHECK: bitcast <2 x float>* %source to <2 x i32>*
110*9880d681SAndroid Build Coastguard Worker; CHECK: load <2 x i32>, <2 x i32>*
111*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: fptoui
112*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: uitofp
113*9880d681SAndroid Build Coastguard Worker; CHECK: bitcast <2 x float>* %dest to <2 x i32>*
114*9880d681SAndroid Build Coastguard Worker; CHECK: store <2 x i32>
115*9880d681SAndroid Build Coastguard Worker  %tmp = load <2 x float>, <2 x float>* %source, align 8
116*9880d681SAndroid Build Coastguard Worker  %call = call <2 x float> @alias_v2i32_to_v2f32(<2 x float> %tmp) nounwind
117*9880d681SAndroid Build Coastguard Worker  store <2 x float> %call, <2 x float>* %dest, align 8
118*9880d681SAndroid Build Coastguard Worker  ret void
119*9880d681SAndroid Build Coastguard Worker}
120*9880d681SAndroid Build Coastguard Worker
121*9880d681SAndroid Build Coastguard Worker; Sizes match, should only bitcast
122*9880d681SAndroid Build Coastguard Workerdefine void @bitcast_alias_vector_scalar_same_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
123*9880d681SAndroid Build Coastguard Workerentry:
124*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @bitcast_alias_vector_scalar_same_size
125*9880d681SAndroid Build Coastguard Worker; CHECK: bitcast <2 x float>* %source to i64*
126*9880d681SAndroid Build Coastguard Worker; CHECK: load i64, i64*
127*9880d681SAndroid Build Coastguard Worker; CHECK: %call = call i64 @func_i64
128*9880d681SAndroid Build Coastguard Worker; CHECK: bitcast <2 x float>* %dest to i64*
129*9880d681SAndroid Build Coastguard Worker; CHECK: store i64
130*9880d681SAndroid Build Coastguard Worker  %tmp = load <2 x float>, <2 x float>* %source, align 8
131*9880d681SAndroid Build Coastguard Worker  %call = call <2 x float> @alias_v2f32_to_i64(<2 x float> %tmp) nounwind
132*9880d681SAndroid Build Coastguard Worker  store <2 x float> %call, <2 x float>* %dest, align 8
133*9880d681SAndroid Build Coastguard Worker  ret void
134*9880d681SAndroid Build Coastguard Worker}
135*9880d681SAndroid Build Coastguard Worker
136*9880d681SAndroid Build Coastguard Workerdefine void @bitcast_alias_scalar_vector_same_size(i64* noalias %source, i64* noalias %dest) nounwind {
137*9880d681SAndroid Build Coastguard Workerentry:
138*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @bitcast_alias_scalar_vector_same_size
139*9880d681SAndroid Build Coastguard Worker; CHECK: bitcast i64* %source to <2 x float>*
140*9880d681SAndroid Build Coastguard Worker; CHECK: load <2 x float>, <2 x float>*
141*9880d681SAndroid Build Coastguard Worker; CHECK: call <2 x float> @func_v2f32
142*9880d681SAndroid Build Coastguard Worker; CHECK: bitcast i64* %dest to <2 x float>*
143*9880d681SAndroid Build Coastguard Worker; CHECK: store <2 x float>
144*9880d681SAndroid Build Coastguard Worker  %tmp = load i64, i64* %source, align 8
145*9880d681SAndroid Build Coastguard Worker  %call = call i64 @alias_i64_to_v2f32(i64 %tmp) nounwind
146*9880d681SAndroid Build Coastguard Worker  store i64 %call, i64* %dest, align 8
147*9880d681SAndroid Build Coastguard Worker  ret void
148*9880d681SAndroid Build Coastguard Worker}
149*9880d681SAndroid Build Coastguard Worker
150*9880d681SAndroid Build Coastguard Workerdefine void @bitcast_alias_vector_ptrs_same_size(<2 x i64*>* noalias %source, <2 x i64*>* noalias %dest) nounwind {
151*9880d681SAndroid Build Coastguard Workerentry:
152*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @bitcast_alias_vector_ptrs_same_size
153*9880d681SAndroid Build Coastguard Worker; CHECK: bitcast <2 x i64*>* %source to <2 x i32*>*
154*9880d681SAndroid Build Coastguard Worker; CHECK: load <2 x i32*>, <2 x i32*>*
155*9880d681SAndroid Build Coastguard Worker; CHECK: call <2 x i32*> @func_v2i32p
156*9880d681SAndroid Build Coastguard Worker; CHECK: bitcast <2 x i64*>* %dest to <2 x i32*>*
157*9880d681SAndroid Build Coastguard Worker; CHECK: store <2 x i32*>
158*9880d681SAndroid Build Coastguard Worker  %tmp = load <2 x i64*>, <2 x i64*>* %source, align 8
159*9880d681SAndroid Build Coastguard Worker  %call = call <2 x i64*> @alias_v2i32p_to_v2i64p(<2 x i64*> %tmp) nounwind
160*9880d681SAndroid Build Coastguard Worker  store <2 x i64*> %call, <2 x i64*>* %dest, align 8
161*9880d681SAndroid Build Coastguard Worker  ret void
162*9880d681SAndroid Build Coastguard Worker}
163*9880d681SAndroid Build Coastguard Worker
164*9880d681SAndroid Build Coastguard Worker; Invalid cases:
165*9880d681SAndroid Build Coastguard Worker
166*9880d681SAndroid Build Coastguard Workerdefine void @bitcast_alias_mismatch_scalar_size(float* noalias %source, float* noalias %dest) nounwind {
167*9880d681SAndroid Build Coastguard Workerentry:
168*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @bitcast_alias_mismatch_scalar_size
169*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: fptoui
170*9880d681SAndroid Build Coastguard Worker; CHECK: @alias_i64_to_f32
171*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: uitofp
172*9880d681SAndroid Build Coastguard Worker  %tmp = load float, float* %source, align 8
173*9880d681SAndroid Build Coastguard Worker  %call = call float @alias_i64_to_f32(float %tmp) nounwind
174*9880d681SAndroid Build Coastguard Worker  store float %call, float* %dest, align 8
175*9880d681SAndroid Build Coastguard Worker  ret void
176*9880d681SAndroid Build Coastguard Worker}
177*9880d681SAndroid Build Coastguard Worker
178*9880d681SAndroid Build Coastguard Workerdefine void @bitcast_alias_mismatch_vector_element_and_bit_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
179*9880d681SAndroid Build Coastguard Workerentry:
180*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @bitcast_alias_mismatch_vector_element_and_bit_size
181*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: fptoui <2 x float> %tmp to <2 x i64>
182*9880d681SAndroid Build Coastguard Worker; CHECK: @alias_v2i64_to_v2f32
183*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: uitofp <2 x i64> %call to <2 x float>
184*9880d681SAndroid Build Coastguard Worker  %tmp = load <2 x float>, <2 x float>* %source, align 8
185*9880d681SAndroid Build Coastguard Worker  %call = call <2 x float> @alias_v2i64_to_v2f32(<2 x float> %tmp) nounwind
186*9880d681SAndroid Build Coastguard Worker  store <2 x float> %call, <2 x float>* %dest, align 8
187*9880d681SAndroid Build Coastguard Worker  ret void
188*9880d681SAndroid Build Coastguard Worker}
189*9880d681SAndroid Build Coastguard Worker
190*9880d681SAndroid Build Coastguard Workerdefine void @bitcast_alias_vector_mismatched_number_elements(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind {
191*9880d681SAndroid Build Coastguard Workerentry:
192*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @bitcast_alias_vector_mismatched_number_elements
193*9880d681SAndroid Build Coastguard Worker; CHECK:  %call = call <4 x float> @alias_v2i32_to_v4f32
194*9880d681SAndroid Build Coastguard Worker  %tmp = load <4 x float>, <4 x float>* %source, align 8
195*9880d681SAndroid Build Coastguard Worker  %call = call <4 x float> @alias_v2i32_to_v4f32(<4 x float> %tmp) nounwind
196*9880d681SAndroid Build Coastguard Worker  store <4 x float> %call, <4 x float>* %dest, align 8
197*9880d681SAndroid Build Coastguard Worker  ret void
198*9880d681SAndroid Build Coastguard Worker}
199*9880d681SAndroid Build Coastguard Worker
200*9880d681SAndroid Build Coastguard Workerdefine void @bitcast_alias_vector_scalar_mismatched_bit_size(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind {
201*9880d681SAndroid Build Coastguard Workerentry:
202*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @bitcast_alias_vector_scalar_mismatched_bit_size
203*9880d681SAndroid Build Coastguard Worker; CHECK:  %call = call <4 x float> @alias_v4f32_to_i64
204*9880d681SAndroid Build Coastguard Worker  %tmp = load <4 x float>, <4 x float>* %source, align 8
205*9880d681SAndroid Build Coastguard Worker  %call = call <4 x float> @alias_v4f32_to_i64(<4 x float> %tmp) nounwind
206*9880d681SAndroid Build Coastguard Worker  store <4 x float> %call, <4 x float>* %dest, align 8
207*9880d681SAndroid Build Coastguard Worker  ret void
208*9880d681SAndroid Build Coastguard Worker}
209*9880d681SAndroid Build Coastguard Worker
210*9880d681SAndroid Build Coastguard Workerdefine void @bitcast_alias_vector_ptrs_scalar_mismatched_bit_size(<4 x i32*>* noalias %source, <4 x i32*>* noalias %dest) nounwind {
211*9880d681SAndroid Build Coastguard Workerentry:
212*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @bitcast_alias_vector_ptrs_scalar_mismatched_bit_size
213*9880d681SAndroid Build Coastguard Worker; CHECK: @alias_v4i32p_to_i64
214*9880d681SAndroid Build Coastguard Worker  %tmp = load <4 x i32*>, <4 x i32*>* %source, align 8
215*9880d681SAndroid Build Coastguard Worker  %call = call <4 x i32*> @alias_v4i32p_to_i64(<4 x i32*> %tmp) nounwind
216*9880d681SAndroid Build Coastguard Worker  store <4 x i32*> %call, <4 x i32*>* %dest, align 8
217*9880d681SAndroid Build Coastguard Worker  ret void
218*9880d681SAndroid Build Coastguard Worker}
219*9880d681SAndroid Build Coastguard Worker
220*9880d681SAndroid Build Coastguard Workerdefine void @bitcast_alias_scalar_vector_ptrs_same_size(i64* noalias %source, i64* noalias %dest) nounwind {
221*9880d681SAndroid Build Coastguard Workerentry:
222*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @bitcast_alias_scalar_vector_ptrs_same_size
223*9880d681SAndroid Build Coastguard Worker; CHECK: @alias_i64_to_v2i32p
224*9880d681SAndroid Build Coastguard Worker  %tmp = load i64, i64* %source, align 8
225*9880d681SAndroid Build Coastguard Worker  %call = call i64 @alias_i64_to_v2i32p(i64 %tmp) nounwind
226*9880d681SAndroid Build Coastguard Worker  store i64 %call, i64* %dest, align 8
227*9880d681SAndroid Build Coastguard Worker  ret void
228*9880d681SAndroid Build Coastguard Worker}
229*9880d681SAndroid Build Coastguard Worker
230*9880d681SAndroid Build Coastguard Workerdefine void @bitcast_alias_scalar_vector_mismatched_bit_size(i64* noalias %source, i64* noalias %dest) nounwind {
231*9880d681SAndroid Build Coastguard Workerentry:
232*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @bitcast_alias_scalar_vector_mismatched_bit_size
233*9880d681SAndroid Build Coastguard Worker; CHECK: call i64 @alias_i64_to_v4f32
234*9880d681SAndroid Build Coastguard Worker  %tmp = load i64, i64* %source, align 8
235*9880d681SAndroid Build Coastguard Worker  %call = call i64 @alias_i64_to_v4f32(i64 %tmp) nounwind
236*9880d681SAndroid Build Coastguard Worker  store i64 %call, i64* %dest, align 8
237*9880d681SAndroid Build Coastguard Worker  ret void
238*9880d681SAndroid Build Coastguard Worker}
239*9880d681SAndroid Build Coastguard Worker
240