1 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
2 // RUN: -disable-O0-optnone -ffp-contract=fast -emit-llvm -o - %s | opt -S -mem2reg \
3 // RUN:  | FileCheck %s
4 
5 // REQUIRES: aarch64-registered-target
6 
7 // Test new aarch64 intrinsics with poly128
8 // FIXME: Currently, poly128_t equals to uint128, which will be spilt into
9 // two 64-bit GPR(eg X0, X1). Now moving data from X0, X1 to FPR128 will
10 // introduce 2 store and 1 load instructions(store X0, X1 to memory and
11 // then load back to Q0). If target has NEON, this is better replaced by
12 // FMOV or INS.
13 
14 #include <arm_neon.h>
15 
16 // CHECK-LABEL: define{{.*}} void @test_vstrq_p128(i128* noundef %ptr, i128 noundef %val) #0 {
17 // CHECK:   [[TMP0:%.*]] = bitcast i128* %ptr to i8*
18 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to i128*
19 // CHECK:   store i128 %val, i128* [[TMP1]]
20 // CHECK:   ret void
21 void test_vstrq_p128(poly128_t * ptr, poly128_t val) {
22   vstrq_p128(ptr, val);
23 
24 }
25 
26 // CHECK-LABEL: define{{.*}} i128 @test_vldrq_p128(i128* noundef %ptr) #0 {
27 // CHECK:   [[TMP0:%.*]] = bitcast i128* %ptr to i8*
28 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to i128*
29 // CHECK:   [[TMP2:%.*]] = load i128, i128* [[TMP1]]
30 // CHECK:   ret i128 [[TMP2]]
31 poly128_t test_vldrq_p128(poly128_t * ptr) {
32   return vldrq_p128(ptr);
33 
34 }
35 
36 // CHECK-LABEL: define{{.*}} void @test_ld_st_p128(i128* noundef %ptr) #0 {
37 // CHECK:   [[TMP0:%.*]] = bitcast i128* %ptr to i8*
38 // CHECK:   [[TMP1:%.*]] = bitcast i8* [[TMP0]] to i128*
39 // CHECK:   [[TMP2:%.*]] = load i128, i128* [[TMP1]]
40 // CHECK:   [[ADD_PTR:%.*]] = getelementptr inbounds i128, i128* %ptr, i64 1
41 // CHECK:   [[TMP3:%.*]] = bitcast i128* [[ADD_PTR]] to i8*
42 // CHECK:   [[TMP4:%.*]] = bitcast i8* [[TMP3]] to i128*
43 // CHECK:   store i128 [[TMP2]], i128* [[TMP4]]
44 // CHECK:   ret void
45 void test_ld_st_p128(poly128_t * ptr) {
46    vstrq_p128(ptr+1, vldrq_p128(ptr));
47 
48 }
49 
50 // CHECK-LABEL: define{{.*}} i128 @test_vmull_p64(i64 noundef %a, i64 noundef %b) #0 {
51 // CHECK:   [[VMULL_P64_I:%.*]] = call <16 x i8> @llvm.aarch64.neon.pmull64(i64 %a, i64 %b) #3
52 // CHECK:   [[VMULL_P641_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I]] to i128
53 // CHECK:   ret i128 [[VMULL_P641_I]]
54 poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
55   return vmull_p64(a, b);
56 }
57 
58 // CHECK-LABEL: define{{.*}} i128 @test_vmull_high_p64(<2 x i64> noundef %a, <2 x i64> noundef %b) #1 {
59 // CHECK:   [[SHUFFLE_I_I:%.*]] = shufflevector <2 x i64> %a, <2 x i64> %a, <1 x i32> <i32 1>
60 // CHECK:   [[TMP0:%.*]] = bitcast <1 x i64> [[SHUFFLE_I_I]] to i64
61 // CHECK:   [[SHUFFLE_I7_I:%.*]] = shufflevector <2 x i64> %b, <2 x i64> %b, <1 x i32> <i32 1>
62 // CHECK:   [[TMP1:%.*]] = bitcast <1 x i64> [[SHUFFLE_I7_I]] to i64
63 // CHECK:   [[VMULL_P64_I_I:%.*]] = call <16 x i8> @llvm.aarch64.neon.pmull64(i64 [[TMP0]], i64 [[TMP1]]) #3
64 // CHECK:   [[VMULL_P641_I_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I_I]] to i128
65 // CHECK:   ret i128 [[VMULL_P641_I_I]]
66 poly128_t test_vmull_high_p64(poly64x2_t a, poly64x2_t b) {
67   return vmull_high_p64(a, b);
68 }
69 
70 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_s8(<16 x i8> noundef %a) #1 {
71 // CHECK:   [[TMP0:%.*]] = bitcast <16 x i8> %a to i128
72 // CHECK:   ret i128 [[TMP0]]
73 poly128_t test_vreinterpretq_p128_s8(int8x16_t a) {
74   return vreinterpretq_p128_s8(a);
75 }
76 
77 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_s16(<8 x i16> noundef %a) #1 {
78 // CHECK:   [[TMP0:%.*]] = bitcast <8 x i16> %a to i128
79 // CHECK:   ret i128 [[TMP0]]
80 poly128_t test_vreinterpretq_p128_s16(int16x8_t a) {
81   return vreinterpretq_p128_s16(a);
82 }
83 
84 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_s32(<4 x i32> noundef %a) #1 {
85 // CHECK:   [[TMP0:%.*]] = bitcast <4 x i32> %a to i128
86 // CHECK:   ret i128 [[TMP0]]
87 poly128_t test_vreinterpretq_p128_s32(int32x4_t a) {
88   return vreinterpretq_p128_s32(a);
89 }
90 
91 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_s64(<2 x i64> noundef %a) #1 {
92 // CHECK:   [[TMP0:%.*]] = bitcast <2 x i64> %a to i128
93 // CHECK:   ret i128 [[TMP0]]
94 poly128_t test_vreinterpretq_p128_s64(int64x2_t a) {
95   return vreinterpretq_p128_s64(a);
96 }
97 
98 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_u8(<16 x i8> noundef %a) #1 {
99 // CHECK:   [[TMP0:%.*]] = bitcast <16 x i8> %a to i128
100 // CHECK:   ret i128 [[TMP0]]
101 poly128_t test_vreinterpretq_p128_u8(uint8x16_t a) {
102   return vreinterpretq_p128_u8(a);
103 }
104 
105 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_u16(<8 x i16> noundef %a) #1 {
106 // CHECK:   [[TMP0:%.*]] = bitcast <8 x i16> %a to i128
107 // CHECK:   ret i128 [[TMP0]]
108 poly128_t test_vreinterpretq_p128_u16(uint16x8_t a) {
109   return vreinterpretq_p128_u16(a);
110 }
111 
112 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_u32(<4 x i32> noundef %a) #1 {
113 // CHECK:   [[TMP0:%.*]] = bitcast <4 x i32> %a to i128
114 // CHECK:   ret i128 [[TMP0]]
115 poly128_t test_vreinterpretq_p128_u32(uint32x4_t a) {
116   return vreinterpretq_p128_u32(a);
117 }
118 
119 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_u64(<2 x i64> noundef %a) #1 {
120 // CHECK:   [[TMP0:%.*]] = bitcast <2 x i64> %a to i128
121 // CHECK:   ret i128 [[TMP0]]
122 poly128_t test_vreinterpretq_p128_u64(uint64x2_t a) {
123   return vreinterpretq_p128_u64(a);
124 }
125 
126 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_f32(<4 x float> noundef %a) #1 {
127 // CHECK:   [[TMP0:%.*]] = bitcast <4 x float> %a to i128
128 // CHECK:   ret i128 [[TMP0]]
129 poly128_t test_vreinterpretq_p128_f32(float32x4_t a) {
130   return vreinterpretq_p128_f32(a);
131 }
132 
133 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_f64(<2 x double> noundef %a) #1 {
134 // CHECK:   [[TMP0:%.*]] = bitcast <2 x double> %a to i128
135 // CHECK:   ret i128 [[TMP0]]
136 poly128_t test_vreinterpretq_p128_f64(float64x2_t a) {
137   return vreinterpretq_p128_f64(a);
138 }
139 
140 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_p8(<16 x i8> noundef %a) #1 {
141 // CHECK:   [[TMP0:%.*]] = bitcast <16 x i8> %a to i128
142 // CHECK:   ret i128 [[TMP0]]
143 poly128_t test_vreinterpretq_p128_p8(poly8x16_t a) {
144   return vreinterpretq_p128_p8(a);
145 }
146 
147 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_p16(<8 x i16> noundef %a) #1 {
148 // CHECK:   [[TMP0:%.*]] = bitcast <8 x i16> %a to i128
149 // CHECK:   ret i128 [[TMP0]]
150 poly128_t test_vreinterpretq_p128_p16(poly16x8_t a) {
151   return vreinterpretq_p128_p16(a);
152 }
153 
154 // CHECK-LABEL: define{{.*}} i128 @test_vreinterpretq_p128_p64(<2 x i64> noundef %a) #1 {
155 // CHECK:   [[TMP0:%.*]] = bitcast <2 x i64> %a to i128
156 // CHECK:   ret i128 [[TMP0]]
157 poly128_t test_vreinterpretq_p128_p64(poly64x2_t a) {
158   return vreinterpretq_p128_p64(a);
159 }
160 
161 // CHECK-LABEL: define{{.*}} <16 x i8> @test_vreinterpretq_s8_p128(i128 noundef %a) #1 {
162 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <16 x i8>
163 // CHECK:   ret <16 x i8> [[TMP0]]
164 int8x16_t test_vreinterpretq_s8_p128(poly128_t a) {
165   return vreinterpretq_s8_p128(a);
166 }
167 
168 // CHECK-LABEL: define{{.*}} <8 x i16> @test_vreinterpretq_s16_p128(i128 noundef %a) #1 {
169 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <8 x i16>
170 // CHECK:   ret <8 x i16> [[TMP0]]
171 int16x8_t test_vreinterpretq_s16_p128(poly128_t  a) {
172   return vreinterpretq_s16_p128(a);
173 }
174 
175 // CHECK-LABEL: define{{.*}} <4 x i32> @test_vreinterpretq_s32_p128(i128 noundef %a) #1 {
176 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <4 x i32>
177 // CHECK:   ret <4 x i32> [[TMP0]]
178 int32x4_t test_vreinterpretq_s32_p128(poly128_t a) {
179   return vreinterpretq_s32_p128(a);
180 }
181 
182 // CHECK-LABEL: define{{.*}} <2 x i64> @test_vreinterpretq_s64_p128(i128 noundef %a) #1 {
183 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <2 x i64>
184 // CHECK:   ret <2 x i64> [[TMP0]]
185 int64x2_t test_vreinterpretq_s64_p128(poly128_t  a) {
186   return vreinterpretq_s64_p128(a);
187 }
188 
189 // CHECK-LABEL: define{{.*}} <16 x i8> @test_vreinterpretq_u8_p128(i128 noundef %a) #1 {
190 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <16 x i8>
191 // CHECK:   ret <16 x i8> [[TMP0]]
192 uint8x16_t test_vreinterpretq_u8_p128(poly128_t  a) {
193   return vreinterpretq_u8_p128(a);
194 }
195 
196 // CHECK-LABEL: define{{.*}} <8 x i16> @test_vreinterpretq_u16_p128(i128 noundef %a) #1 {
197 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <8 x i16>
198 // CHECK:   ret <8 x i16> [[TMP0]]
199 uint16x8_t test_vreinterpretq_u16_p128(poly128_t  a) {
200   return vreinterpretq_u16_p128(a);
201 }
202 
203 // CHECK-LABEL: define{{.*}} <4 x i32> @test_vreinterpretq_u32_p128(i128 noundef %a) #1 {
204 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <4 x i32>
205 // CHECK:   ret <4 x i32> [[TMP0]]
206 uint32x4_t test_vreinterpretq_u32_p128(poly128_t  a) {
207   return vreinterpretq_u32_p128(a);
208 }
209 
210 // CHECK-LABEL: define{{.*}} <2 x i64> @test_vreinterpretq_u64_p128(i128 noundef %a) #1 {
211 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <2 x i64>
212 // CHECK:   ret <2 x i64> [[TMP0]]
213 uint64x2_t test_vreinterpretq_u64_p128(poly128_t  a) {
214   return vreinterpretq_u64_p128(a);
215 }
216 
217 // CHECK-LABEL: define{{.*}} <4 x float> @test_vreinterpretq_f32_p128(i128 noundef %a) #1 {
218 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <4 x float>
219 // CHECK:   ret <4 x float> [[TMP0]]
220 float32x4_t test_vreinterpretq_f32_p128(poly128_t  a) {
221   return vreinterpretq_f32_p128(a);
222 }
223 
224 // CHECK-LABEL: define{{.*}} <2 x double> @test_vreinterpretq_f64_p128(i128 noundef %a) #1 {
225 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <2 x double>
226 // CHECK:   ret <2 x double> [[TMP0]]
227 float64x2_t test_vreinterpretq_f64_p128(poly128_t  a) {
228   return vreinterpretq_f64_p128(a);
229 }
230 
231 // CHECK-LABEL: define{{.*}} <16 x i8> @test_vreinterpretq_p8_p128(i128 noundef %a) #1 {
232 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <16 x i8>
233 // CHECK:   ret <16 x i8> [[TMP0]]
234 poly8x16_t test_vreinterpretq_p8_p128(poly128_t  a) {
235   return vreinterpretq_p8_p128(a);
236 }
237 
238 // CHECK-LABEL: define{{.*}} <8 x i16> @test_vreinterpretq_p16_p128(i128 noundef %a) #1 {
239 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <8 x i16>
240 // CHECK:   ret <8 x i16> [[TMP0]]
241 poly16x8_t test_vreinterpretq_p16_p128(poly128_t  a) {
242   return vreinterpretq_p16_p128(a);
243 }
244 
245 // CHECK-LABEL: define{{.*}} <2 x i64> @test_vreinterpretq_p64_p128(i128 noundef %a) #1 {
246 // CHECK:   [[TMP0:%.*]] = bitcast i128 %a to <2 x i64>
247 // CHECK:   ret <2 x i64> [[TMP0]]
248 poly64x2_t test_vreinterpretq_p64_p128(poly128_t  a) {
249   return vreinterpretq_p64_p128(a);
250 }
251 
252 
253