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* %source to i32*
97 ; CHECK: bitcast i32 %call to float
98 %tmp = load float* %source, align 8
99 %call = call float @alias_i32_to_f32(float %tmp) nounwind
100 store float %call, float* %dest, align 8
104 ; Sizes match, should only bitcast
105 define void @bitcast_alias_vector(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
107 ; CHECK-LABEL: @bitcast_alias_vector
108 ; CHECK: bitcast <2 x float>* %source to <2 x i32>*
109 ; CHECK: load <2 x i32>*
112 ; CHECK: bitcast <2 x i32> %call to <2 x float>
113 %tmp = load <2 x float>* %source, align 8
114 %call = call <2 x float> @alias_v2i32_to_v2f32(<2 x float> %tmp) nounwind
115 store <2 x float> %call, <2 x float>* %dest, align 8
119 ; Sizes match, should only bitcast
120 define void @bitcast_alias_vector_scalar_same_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
122 ; CHECK-LABEL: @bitcast_alias_vector_scalar_same_size
123 ; CHECK: bitcast <2 x float>* %source to i64*
125 ; CHECK: %call = call i64 @func_i64
126 ; CHECK: bitcast i64 %call to <2 x float>
127 %tmp = load <2 x float>* %source, align 8
128 %call = call <2 x float> @alias_v2f32_to_i64(<2 x float> %tmp) nounwind
129 store <2 x float> %call, <2 x float>* %dest, align 8
133 define void @bitcast_alias_scalar_vector_same_size(i64* noalias %source, i64* noalias %dest) nounwind {
135 ; CHECK-LABEL: @bitcast_alias_scalar_vector_same_size
136 ; CHECK: bitcast i64* %source to <2 x float>*
137 ; CHECK: load <2 x float>*
138 ; CHECK: call <2 x float> @func_v2f32
139 ; CHECK: bitcast <2 x float> %call to i64
140 %tmp = load i64* %source, align 8
141 %call = call i64 @alias_i64_to_v2f32(i64 %tmp) nounwind
142 store i64 %call, i64* %dest, align 8
146 define void @bitcast_alias_vector_ptrs_same_size(<2 x i64*>* noalias %source, <2 x i64*>* noalias %dest) nounwind {
148 ; CHECK-LABEL: @bitcast_alias_vector_ptrs_same_size
149 ; CHECK: bitcast <2 x i64*>* %source to <2 x i32*>*
150 ; CHECK: load <2 x i32*>*
151 ; CHECK: call <2 x i32*> @func_v2i32p
152 ; CHECK: bitcast <2 x i32*> %call to <2 x i64*>
153 %tmp = load <2 x i64*>* %source, align 8
154 %call = call <2 x i64*> @alias_v2i32p_to_v2i64p(<2 x i64*> %tmp) nounwind
155 store <2 x i64*> %call, <2 x i64*>* %dest, align 8
161 define void @bitcast_alias_mismatch_scalar_size(float* noalias %source, float* noalias %dest) nounwind {
163 ; CHECK-LABEL: @bitcast_alias_mismatch_scalar_size
165 ; CHECK: @alias_i64_to_f32
167 %tmp = load float* %source, align 8
168 %call = call float @alias_i64_to_f32(float %tmp) nounwind
169 store float %call, float* %dest, align 8
173 define void @bitcast_alias_mismatch_vector_element_and_bit_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
175 ; CHECK-LABEL: @bitcast_alias_mismatch_vector_element_and_bit_size
176 ; CHECK-NOT: fptoui <2 x float> %tmp to <2 x i64>
177 ; CHECK: @alias_v2i64_to_v2f32
178 ; CHECK-NOT: uitofp <2 x i64> %call to <2 x float>
179 %tmp = load <2 x float>* %source, align 8
180 %call = call <2 x float> @alias_v2i64_to_v2f32(<2 x float> %tmp) nounwind
181 store <2 x float> %call, <2 x float>* %dest, align 8
185 define void @bitcast_alias_vector_mismatched_number_elements(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind {
187 ; CHECK-LABEL: @bitcast_alias_vector_mismatched_number_elements
188 ; CHECK: %call = call <4 x float> @alias_v2i32_to_v4f32
189 %tmp = load <4 x float>* %source, align 8
190 %call = call <4 x float> @alias_v2i32_to_v4f32(<4 x float> %tmp) nounwind
191 store <4 x float> %call, <4 x float>* %dest, align 8
195 define void @bitcast_alias_vector_scalar_mismatched_bit_size(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind {
197 ; CHECK-LABEL: @bitcast_alias_vector_scalar_mismatched_bit_size
198 ; CHECK: %call = call <4 x float> @alias_v4f32_to_i64
199 %tmp = load <4 x float>* %source, align 8
200 %call = call <4 x float> @alias_v4f32_to_i64(<4 x float> %tmp) nounwind
201 store <4 x float> %call, <4 x float>* %dest, align 8
205 define void @bitcast_alias_vector_ptrs_scalar_mismatched_bit_size(<4 x i32*>* noalias %source, <4 x i32*>* noalias %dest) nounwind {
207 ; CHECK-LABEL: @bitcast_alias_vector_ptrs_scalar_mismatched_bit_size
208 ; CHECK: @alias_v4i32p_to_i64
209 %tmp = load <4 x i32*>* %source, align 8
210 %call = call <4 x i32*> @alias_v4i32p_to_i64(<4 x i32*> %tmp) nounwind
211 store <4 x i32*> %call, <4 x i32*>* %dest, align 8
215 define void @bitcast_alias_scalar_vector_ptrs_same_size(i64* noalias %source, i64* noalias %dest) nounwind {
217 ; CHECK-LABEL: @bitcast_alias_scalar_vector_ptrs_same_size
218 ; CHECK: @alias_i64_to_v2i32p
219 %tmp = load i64* %source, align 8
220 %call = call i64 @alias_i64_to_v2i32p(i64 %tmp) nounwind
221 store i64 %call, i64* %dest, align 8
225 define void @bitcast_alias_scalar_vector_mismatched_bit_size(i64* noalias %source, i64* noalias %dest) nounwind {
227 ; CHECK-LABEL: @bitcast_alias_scalar_vector_mismatched_bit_size
228 ; CHECK: call i64 @alias_i64_to_v4f32
229 %tmp = load i64* %source, align 8
230 %call = call i64 @alias_i64_to_v4f32(i64 %tmp) nounwind
231 store i64 %call, i64* %dest, align 8