1 ; RUN: opt -S -instcombine -o - %s | FileCheck %s
2 target 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"
6 ; Cases that should be bitcast
8 ; Test cast between scalars with same bit sizes
9 @alias_i32_to_f32 = alias bitcast (i32 (i32)* @func_i32 to float (float)*)
11 ; Test cast between vectors with same number of elements and bit sizes
12 @alias_v2i32_to_v2f32 = alias bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <2 x float> (<2 x float>)*)
14 ; Test cast from vector to scalar with same number of bits
15 @alias_v2f32_to_i64 = alias bitcast (i64 (i64)* @func_i64 to <2 x float> (<2 x float>)*)
17 ; Test cast from scalar to vector with same number of bits
18 @alias_i64_to_v2f32 = alias bitcast (<2 x float> (<2 x float>)* @func_v2f32 to i64 (i64)*)
20 ; Test cast between vectors of pointers
21 @alias_v2i32p_to_v2i64p = alias bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to <2 x i64*> (<2 x i64*>)*)
24 ; Cases that should be invalid and unchanged
26 ; Test cast between scalars with different bit sizes
27 @alias_i64_to_f32 = alias bitcast (i64 (i64)* @func_i64 to float (float)*)
29 ; Test cast between vectors with different bit sizes but the
30 ; same number of elements
31 @alias_v2i64_to_v2f32 = alias bitcast (<2 x i64> (<2 x i64>)* @func_v2i64 to <2 x float> (<2 x float>)*)
33 ; Test cast between vectors with same number of bits and different
35 @alias_v2i32_to_v4f32 = alias bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <4 x float> (<4 x float>)*)
37 ; Test cast between scalar and vector with different number of bits
38 @alias_i64_to_v4f32 = alias bitcast (<4 x float> (<4 x float>)* @func_v4f32 to i64 (i64)*)
40 ; Test cast between vector and scalar with different number of bits
41 @alias_v4f32_to_i64 = alias bitcast (i64 (i64)* @func_i64 to <4 x float> (<4 x float>)*)
43 ; Test cast from scalar to vector of pointers with same number of bits
44 ; We don't know the pointer size at this point, so this can't be done
45 @alias_i64_to_v2i32p = alias bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to i64 (i64)*)
47 ; Test cast between vector of pointers and scalar with different number of bits
48 @alias_v4i32p_to_i64 = alias bitcast (i64 (i64)* @func_i64 to <4 x i32*> (<4 x i32*>)*)
52 define internal <2 x i32> @func_v2i32(<2 x i32> %v) noinline nounwind {
57 define internal <2 x float> @func_v2f32(<2 x float> %v) noinline nounwind {
62 define internal <4 x float> @func_v4f32(<4 x float> %v) noinline nounwind {
67 define internal i32 @func_i32(i32 %v) noinline nounwind {
72 define internal i64 @func_i64(i64 %v) noinline nounwind {
77 define internal <2 x i64> @func_v2i64(<2 x i64> %v) noinline nounwind {
82 define internal <2 x i32*> @func_v2i32p(<2 x i32*> %v) noinline nounwind {
87 ; Valid cases, only bitcast for argument / return type and call underlying function
89 ; Sizes match, should only bitcast
90 define void @bitcast_alias_scalar(float* noalias %source, float* noalias %dest) nounwind {
92 ; CHECK-LABEL: @bitcast_alias_scalar
93 ; CHECK: bitcast float %tmp to i32
96 ; CHECK: bitcast i32 %call to float
97 %tmp = load float* %source, align 8
98 %call = call float @alias_i32_to_f32(float %tmp) nounwind
99 store float %call, float* %dest, align 8
103 ; Sizes match, should only bitcast
104 define void @bitcast_alias_vector(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
106 ; CHECK-LABEL: @bitcast_alias_vector
107 ; CHECK: bitcast <2 x float> %tmp to <2 x i32>
110 ; CHECK: bitcast <2 x i32> %call to <2 x float>
111 %tmp = load <2 x float>* %source, align 8
112 %call = call <2 x float> @alias_v2i32_to_v2f32(<2 x float> %tmp) nounwind
113 store <2 x float> %call, <2 x float>* %dest, align 8
117 ; Sizes match, should only bitcast
118 define void @bitcast_alias_vector_scalar_same_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
120 ; CHECK-LABEL: @bitcast_alias_vector_scalar_same_size
121 ; CHECK: bitcast <2 x float> %tmp to i64
122 ; CHECK: %call = call i64 @func_i64
123 ; CHECK: bitcast i64 %call to <2 x float>
124 %tmp = load <2 x float>* %source, align 8
125 %call = call <2 x float> @alias_v2f32_to_i64(<2 x float> %tmp) nounwind
126 store <2 x float> %call, <2 x float>* %dest, align 8
130 define void @bitcast_alias_scalar_vector_same_size(i64* noalias %source, i64* noalias %dest) nounwind {
132 ; CHECK-LABEL: @bitcast_alias_scalar_vector_same_size
133 ; CHECK: bitcast i64 %tmp to <2 x float>
134 ; CHECK: call <2 x float> @func_v2f32
135 ; CHECK: bitcast <2 x float> %call to i64
136 %tmp = load i64* %source, align 8
137 %call = call i64 @alias_i64_to_v2f32(i64 %tmp) nounwind
138 store i64 %call, i64* %dest, align 8
142 define void @bitcast_alias_vector_ptrs_same_size(<2 x i64*>* noalias %source, <2 x i64*>* noalias %dest) nounwind {
144 ; CHECK-LABEL: @bitcast_alias_vector_ptrs_same_size
145 ; CHECK: bitcast <2 x i64*> %tmp to <2 x i32*>
146 ; CHECK: call <2 x i32*> @func_v2i32p
147 ; CHECK: bitcast <2 x i32*> %call to <2 x i64*>
148 %tmp = load <2 x i64*>* %source, align 8
149 %call = call <2 x i64*> @alias_v2i32p_to_v2i64p(<2 x i64*> %tmp) nounwind
150 store <2 x i64*> %call, <2 x i64*>* %dest, align 8
156 define void @bitcast_alias_mismatch_scalar_size(float* noalias %source, float* noalias %dest) nounwind {
158 ; CHECK-LABEL: @bitcast_alias_mismatch_scalar_size
160 ; CHECK: @alias_i64_to_f32
162 %tmp = load float* %source, align 8
163 %call = call float @alias_i64_to_f32(float %tmp) nounwind
164 store float %call, float* %dest, align 8
168 define void @bitcast_alias_mismatch_vector_element_and_bit_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
170 ; CHECK-LABEL: @bitcast_alias_mismatch_vector_element_and_bit_size
171 ; CHECK-NOT: fptoui <2 x float> %tmp to <2 x i64>
172 ; CHECK: @alias_v2i64_to_v2f32
173 ; CHECK-NOT: uitofp <2 x i64> %call to <2 x float>
174 %tmp = load <2 x float>* %source, align 8
175 %call = call <2 x float> @alias_v2i64_to_v2f32(<2 x float> %tmp) nounwind
176 store <2 x float> %call, <2 x float>* %dest, align 8
180 define void @bitcast_alias_vector_mismatched_number_elements(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind {
182 ; CHECK-LABEL: @bitcast_alias_vector_mismatched_number_elements
183 ; CHECK: %call = call <4 x float> @alias_v2i32_to_v4f32
184 %tmp = load <4 x float>* %source, align 8
185 %call = call <4 x float> @alias_v2i32_to_v4f32(<4 x float> %tmp) nounwind
186 store <4 x float> %call, <4 x float>* %dest, align 8
190 define void @bitcast_alias_vector_scalar_mismatched_bit_size(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind {
192 ; CHECK-LABEL: @bitcast_alias_vector_scalar_mismatched_bit_size
193 ; CHECK: %call = call <4 x float> @alias_v4f32_to_i64
194 %tmp = load <4 x float>* %source, align 8
195 %call = call <4 x float> @alias_v4f32_to_i64(<4 x float> %tmp) nounwind
196 store <4 x float> %call, <4 x float>* %dest, align 8
200 define void @bitcast_alias_vector_ptrs_scalar_mismatched_bit_size(<4 x i32*>* noalias %source, <4 x i32*>* noalias %dest) nounwind {
202 ; CHECK-LABEL: @bitcast_alias_vector_ptrs_scalar_mismatched_bit_size
203 ; CHECK: @alias_v4i32p_to_i64
204 %tmp = load <4 x i32*>* %source, align 8
205 %call = call <4 x i32*> @alias_v4i32p_to_i64(<4 x i32*> %tmp) nounwind
206 store <4 x i32*> %call, <4 x i32*>* %dest, align 8
210 define void @bitcast_alias_scalar_vector_ptrs_same_size(i64* noalias %source, i64* noalias %dest) nounwind {
212 ; CHECK-LABEL: @bitcast_alias_scalar_vector_ptrs_same_size
213 ; CHECK: @alias_i64_to_v2i32p
214 %tmp = load i64* %source, align 8
215 %call = call i64 @alias_i64_to_v2i32p(i64 %tmp) nounwind
216 store i64 %call, i64* %dest, align 8
220 define void @bitcast_alias_scalar_vector_mismatched_bit_size(i64* noalias %source, i64* noalias %dest) nounwind {
222 ; CHECK-LABEL: @bitcast_alias_scalar_vector_mismatched_bit_size
223 ; CHECK: call i64 @alias_i64_to_v4f32
224 %tmp = load i64* %source, align 8
225 %call = call i64 @alias_i64_to_v4f32(i64 %tmp) nounwind
226 store i64 %call, i64* %dest, align 8