1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s | FileCheck %s
4 target triple = "aarch64-unknown-linux-gnu"
10 define <vscale x 16 x i8> @sabd_b(<vscale x 16 x i8> %a, <vscale x 16 x i8> %b) #0 {
11 ; CHECK-LABEL: sabd_b:
13 ; CHECK-NEXT: ptrue p0.b
14 ; CHECK-NEXT: sabd z0.b, p0/m, z0.b, z1.b
16 %a.sext = sext <vscale x 16 x i8> %a to <vscale x 16 x i16>
17 %b.sext = sext <vscale x 16 x i8> %b to <vscale x 16 x i16>
18 %sub = sub <vscale x 16 x i16> %a.sext, %b.sext
19 %abs = call <vscale x 16 x i16> @llvm.abs.nxv16i16(<vscale x 16 x i16> %sub, i1 true)
20 %trunc = trunc <vscale x 16 x i16> %abs to <vscale x 16 x i8>
21 ret <vscale x 16 x i8> %trunc
24 define <vscale x 16 x i8> @sabd_b_promoted_ops(<vscale x 16 x i1> %a, <vscale x 16 x i1> %b) #0 {
25 ; CHECK-LABEL: sabd_b_promoted_ops:
27 ; CHECK-NEXT: ptrue p2.b
28 ; CHECK-NEXT: mov z0.b, p0/z, #-1 // =0xffffffffffffffff
29 ; CHECK-NEXT: mov z1.b, p1/z, #-1 // =0xffffffffffffffff
30 ; CHECK-NEXT: sabd z0.b, p2/m, z0.b, z1.b
32 %a.sext = sext <vscale x 16 x i1> %a to <vscale x 16 x i8>
33 %b.sext = sext <vscale x 16 x i1> %b to <vscale x 16 x i8>
34 %sub = sub <vscale x 16 x i8> %a.sext, %b.sext
35 %abs = call <vscale x 16 x i8> @llvm.abs.nxv16i8(<vscale x 16 x i8> %sub, i1 true)
36 ret <vscale x 16 x i8> %abs
39 define <vscale x 8 x i16> @sabd_h(<vscale x 8 x i16> %a, <vscale x 8 x i16> %b) #0 {
40 ; CHECK-LABEL: sabd_h:
42 ; CHECK-NEXT: ptrue p0.h
43 ; CHECK-NEXT: sabd z0.h, p0/m, z0.h, z1.h
45 %a.sext = sext <vscale x 8 x i16> %a to <vscale x 8 x i32>
46 %b.sext = sext <vscale x 8 x i16> %b to <vscale x 8 x i32>
47 %sub = sub <vscale x 8 x i32> %a.sext, %b.sext
48 %abs = call <vscale x 8 x i32> @llvm.abs.nxv8i32(<vscale x 8 x i32> %sub, i1 true)
49 %trunc = trunc <vscale x 8 x i32> %abs to <vscale x 8 x i16>
50 ret <vscale x 8 x i16> %trunc
53 define <vscale x 8 x i16> @sabd_h_promoted_ops(<vscale x 8 x i8> %a, <vscale x 8 x i8> %b) #0 {
54 ; CHECK-LABEL: sabd_h_promoted_ops:
56 ; CHECK-NEXT: ptrue p0.h
57 ; CHECK-NEXT: sxtb z0.h, p0/m, z0.h
58 ; CHECK-NEXT: sxtb z1.h, p0/m, z1.h
59 ; CHECK-NEXT: sabd z0.h, p0/m, z0.h, z1.h
61 %a.sext = sext <vscale x 8 x i8> %a to <vscale x 8 x i16>
62 %b.sext = sext <vscale x 8 x i8> %b to <vscale x 8 x i16>
63 %sub = sub <vscale x 8 x i16> %a.sext, %b.sext
64 %abs = call <vscale x 8 x i16> @llvm.abs.nxv8i16(<vscale x 8 x i16> %sub, i1 true)
65 ret <vscale x 8 x i16> %abs
68 define <vscale x 4 x i32> @sabd_s(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b) #0 {
69 ; CHECK-LABEL: sabd_s:
71 ; CHECK-NEXT: ptrue p0.s
72 ; CHECK-NEXT: sabd z0.s, p0/m, z0.s, z1.s
74 %a.sext = sext <vscale x 4 x i32> %a to <vscale x 4 x i64>
75 %b.sext = sext <vscale x 4 x i32> %b to <vscale x 4 x i64>
76 %sub = sub <vscale x 4 x i64> %a.sext, %b.sext
77 %abs = call <vscale x 4 x i64> @llvm.abs.nxv4i64(<vscale x 4 x i64> %sub, i1 true)
78 %trunc = trunc <vscale x 4 x i64> %abs to <vscale x 4 x i32>
79 ret <vscale x 4 x i32> %trunc
82 define <vscale x 4 x i32> @sabd_s_promoted_ops(<vscale x 4 x i16> %a, <vscale x 4 x i16> %b) #0 {
83 ; CHECK-LABEL: sabd_s_promoted_ops:
85 ; CHECK-NEXT: ptrue p0.s
86 ; CHECK-NEXT: sxth z0.s, p0/m, z0.s
87 ; CHECK-NEXT: sxth z1.s, p0/m, z1.s
88 ; CHECK-NEXT: sabd z0.s, p0/m, z0.s, z1.s
90 %a.sext = sext <vscale x 4 x i16> %a to <vscale x 4 x i32>
91 %b.sext = sext <vscale x 4 x i16> %b to <vscale x 4 x i32>
92 %sub = sub <vscale x 4 x i32> %a.sext, %b.sext
93 %abs = call <vscale x 4 x i32> @llvm.abs.nxv4i32(<vscale x 4 x i32> %sub, i1 true)
94 ret <vscale x 4 x i32> %abs
97 define <vscale x 2 x i64> @sabd_d(<vscale x 2 x i64> %a, <vscale x 2 x i64> %b) #0 {
98 ; CHECK-LABEL: sabd_d:
100 ; CHECK-NEXT: ptrue p0.d
101 ; CHECK-NEXT: sabd z0.d, p0/m, z0.d, z1.d
103 %a.sext = sext <vscale x 2 x i64> %a to <vscale x 2 x i128>
104 %b.sext = sext <vscale x 2 x i64> %b to <vscale x 2 x i128>
105 %sub = sub <vscale x 2 x i128> %a.sext, %b.sext
106 %abs = call <vscale x 2 x i128> @llvm.abs.nxv2i128(<vscale x 2 x i128> %sub, i1 true)
107 %trunc = trunc <vscale x 2 x i128> %abs to <vscale x 2 x i64>
108 ret <vscale x 2 x i64> %trunc
111 define <vscale x 2 x i64> @sabd_d_promoted_ops(<vscale x 2 x i32> %a, <vscale x 2 x i32> %b) #0 {
112 ; CHECK-LABEL: sabd_d_promoted_ops:
114 ; CHECK-NEXT: ptrue p0.d
115 ; CHECK-NEXT: sxtw z0.d, p0/m, z0.d
116 ; CHECK-NEXT: sxtw z1.d, p0/m, z1.d
117 ; CHECK-NEXT: sabd z0.d, p0/m, z0.d, z1.d
119 %a.sext = sext <vscale x 2 x i32> %a to <vscale x 2 x i64>
120 %b.sext = sext <vscale x 2 x i32> %b to <vscale x 2 x i64>
121 %sub = sub <vscale x 2 x i64> %a.sext, %b.sext
122 %abs = call <vscale x 2 x i64> @llvm.abs.nxv2i64(<vscale x 2 x i64> %sub, i1 true)
123 ret <vscale x 2 x i64> %abs
130 define <vscale x 16 x i8> @uabd_b(<vscale x 16 x i8> %a, <vscale x 16 x i8> %b) #0 {
131 ; CHECK-LABEL: uabd_b:
133 ; CHECK-NEXT: ptrue p0.b
134 ; CHECK-NEXT: uabd z0.b, p0/m, z0.b, z1.b
136 %a.zext = zext <vscale x 16 x i8> %a to <vscale x 16 x i16>
137 %b.zext = zext <vscale x 16 x i8> %b to <vscale x 16 x i16>
138 %sub = sub <vscale x 16 x i16> %a.zext, %b.zext
139 %abs = call <vscale x 16 x i16> @llvm.abs.nxv16i16(<vscale x 16 x i16> %sub, i1 true)
140 %trunc = trunc <vscale x 16 x i16> %abs to <vscale x 16 x i8>
141 ret <vscale x 16 x i8> %trunc
144 define <vscale x 16 x i8> @uabd_b_promoted_ops(<vscale x 16 x i1> %a, <vscale x 16 x i1> %b) #0 {
145 ; CHECK-LABEL: uabd_b_promoted_ops:
147 ; CHECK-NEXT: ptrue p2.b
148 ; CHECK-NEXT: mov z0.b, p0/z, #1 // =0x1
149 ; CHECK-NEXT: mov z1.b, p1/z, #1 // =0x1
150 ; CHECK-NEXT: uabd z0.b, p2/m, z0.b, z1.b
152 %a.zext = zext <vscale x 16 x i1> %a to <vscale x 16 x i8>
153 %b.zext = zext <vscale x 16 x i1> %b to <vscale x 16 x i8>
154 %sub = sub <vscale x 16 x i8> %a.zext, %b.zext
155 %abs = call <vscale x 16 x i8> @llvm.abs.nxv16i8(<vscale x 16 x i8> %sub, i1 true)
156 ret <vscale x 16 x i8> %abs
159 define <vscale x 8 x i16> @uabd_h(<vscale x 8 x i16> %a, <vscale x 8 x i16> %b) #0 {
160 ; CHECK-LABEL: uabd_h:
162 ; CHECK-NEXT: ptrue p0.h
163 ; CHECK-NEXT: uabd z0.h, p0/m, z0.h, z1.h
165 %a.zext = zext <vscale x 8 x i16> %a to <vscale x 8 x i32>
166 %b.zext = zext <vscale x 8 x i16> %b to <vscale x 8 x i32>
167 %sub = sub <vscale x 8 x i32> %a.zext, %b.zext
168 %abs = call <vscale x 8 x i32> @llvm.abs.nxv8i32(<vscale x 8 x i32> %sub, i1 true)
169 %trunc = trunc <vscale x 8 x i32> %abs to <vscale x 8 x i16>
170 ret <vscale x 8 x i16> %trunc
173 define <vscale x 8 x i16> @uabd_h_promoted_ops(<vscale x 8 x i8> %a, <vscale x 8 x i8> %b) #0 {
174 ; CHECK-LABEL: uabd_h_promoted_ops:
176 ; CHECK-NEXT: ptrue p0.h
177 ; CHECK-NEXT: and z0.h, z0.h, #0xff
178 ; CHECK-NEXT: and z1.h, z1.h, #0xff
179 ; CHECK-NEXT: uabd z0.h, p0/m, z0.h, z1.h
181 %a.zext = zext <vscale x 8 x i8> %a to <vscale x 8 x i16>
182 %b.zext = zext <vscale x 8 x i8> %b to <vscale x 8 x i16>
183 %sub = sub <vscale x 8 x i16> %a.zext, %b.zext
184 %abs = call <vscale x 8 x i16> @llvm.abs.nxv8i16(<vscale x 8 x i16> %sub, i1 true)
185 ret <vscale x 8 x i16> %abs
188 define <vscale x 4 x i32> @uabd_s(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b) #0 {
189 ; CHECK-LABEL: uabd_s:
191 ; CHECK-NEXT: ptrue p0.s
192 ; CHECK-NEXT: uabd z0.s, p0/m, z0.s, z1.s
194 %a.zext = zext <vscale x 4 x i32> %a to <vscale x 4 x i64>
195 %b.zext = zext <vscale x 4 x i32> %b to <vscale x 4 x i64>
196 %sub = sub <vscale x 4 x i64> %a.zext, %b.zext
197 %abs = call <vscale x 4 x i64> @llvm.abs.nxv4i64(<vscale x 4 x i64> %sub, i1 true)
198 %trunc = trunc <vscale x 4 x i64> %abs to <vscale x 4 x i32>
199 ret <vscale x 4 x i32> %trunc
202 define <vscale x 4 x i32> @uabd_s_promoted_ops(<vscale x 4 x i16> %a, <vscale x 4 x i16> %b) #0 {
203 ; CHECK-LABEL: uabd_s_promoted_ops:
205 ; CHECK-NEXT: ptrue p0.s
206 ; CHECK-NEXT: and z0.s, z0.s, #0xffff
207 ; CHECK-NEXT: and z1.s, z1.s, #0xffff
208 ; CHECK-NEXT: uabd z0.s, p0/m, z0.s, z1.s
210 %a.zext = zext <vscale x 4 x i16> %a to <vscale x 4 x i32>
211 %b.zext = zext <vscale x 4 x i16> %b to <vscale x 4 x i32>
212 %sub = sub <vscale x 4 x i32> %a.zext, %b.zext
213 %abs = call <vscale x 4 x i32> @llvm.abs.nxv4i32(<vscale x 4 x i32> %sub, i1 true)
214 ret <vscale x 4 x i32> %abs
217 define <vscale x 2 x i64> @uabd_d(<vscale x 2 x i64> %a, <vscale x 2 x i64> %b) #0 {
218 ; CHECK-LABEL: uabd_d:
220 ; CHECK-NEXT: ptrue p0.d
221 ; CHECK-NEXT: uabd z0.d, p0/m, z0.d, z1.d
223 %a.zext = zext <vscale x 2 x i64> %a to <vscale x 2 x i128>
224 %b.zext = zext <vscale x 2 x i64> %b to <vscale x 2 x i128>
225 %sub = sub <vscale x 2 x i128> %a.zext, %b.zext
226 %abs = call <vscale x 2 x i128> @llvm.abs.nxv2i128(<vscale x 2 x i128> %sub, i1 true)
227 %trunc = trunc <vscale x 2 x i128> %abs to <vscale x 2 x i64>
228 ret <vscale x 2 x i64> %trunc
231 define <vscale x 2 x i64> @uabd_d_promoted_ops(<vscale x 2 x i32> %a, <vscale x 2 x i32> %b) #0 {
232 ; CHECK-LABEL: uabd_d_promoted_ops:
234 ; CHECK-NEXT: ptrue p0.d
235 ; CHECK-NEXT: and z0.d, z0.d, #0xffffffff
236 ; CHECK-NEXT: and z1.d, z1.d, #0xffffffff
237 ; CHECK-NEXT: uabd z0.d, p0/m, z0.d, z1.d
239 %a.zext = zext <vscale x 2 x i32> %a to <vscale x 2 x i64>
240 %b.zext = zext <vscale x 2 x i32> %b to <vscale x 2 x i64>
241 %sub = sub <vscale x 2 x i64> %a.zext, %b.zext
242 %abs = call <vscale x 2 x i64> @llvm.abs.nxv2i64(<vscale x 2 x i64> %sub, i1 true)
243 ret <vscale x 2 x i64> %abs
246 ; Test the situation where isLegal(ISD::ABD, typeof(%a)) returns true but %a and
247 ; %b have differing types.
248 define <vscale x 4 x i32> @uabd_non_matching_extension(<vscale x 4 x i32> %a, <vscale x 4 x i8> %b) #0 {
249 ; CHECK-LABEL: uabd_non_matching_extension:
251 ; CHECK-NEXT: and z1.s, z1.s, #0xff
252 ; CHECK-NEXT: uunpkhi z2.d, z0.s
253 ; CHECK-NEXT: uunpklo z0.d, z0.s
254 ; CHECK-NEXT: ptrue p0.d
255 ; CHECK-NEXT: uunpkhi z3.d, z1.s
256 ; CHECK-NEXT: uunpklo z1.d, z1.s
257 ; CHECK-NEXT: sub z0.d, z0.d, z1.d
258 ; CHECK-NEXT: sub z1.d, z2.d, z3.d
259 ; CHECK-NEXT: abs z1.d, p0/m, z1.d
260 ; CHECK-NEXT: abs z0.d, p0/m, z0.d
261 ; CHECK-NEXT: uzp1 z0.s, z0.s, z1.s
263 %a.zext = zext <vscale x 4 x i32> %a to <vscale x 4 x i64>
264 %b.zext = zext <vscale x 4 x i8> %b to <vscale x 4 x i64>
265 %sub = sub <vscale x 4 x i64> %a.zext, %b.zext
266 %abs = call <vscale x 4 x i64> @llvm.abs.nxv4i64(<vscale x 4 x i64> %sub, i1 true)
267 %trunc = trunc <vscale x 4 x i64> %abs to <vscale x 4 x i32>
268 ret <vscale x 4 x i32> %trunc
271 ; Test the situation where isLegal(ISD::ABD, typeof(%a.zext)) returns true but
272 ; %a and %b have differing types.
273 define <vscale x 4 x i32> @uabd_non_matching_promoted_ops(<vscale x 4 x i8> %a, <vscale x 4 x i16> %b) #0 {
274 ; CHECK-LABEL: uabd_non_matching_promoted_ops:
276 ; CHECK-NEXT: ptrue p0.s
277 ; CHECK-NEXT: and z0.s, z0.s, #0xff
278 ; CHECK-NEXT: and z1.s, z1.s, #0xffff
279 ; CHECK-NEXT: uabd z0.s, p0/m, z0.s, z1.s
281 %a.zext = zext <vscale x 4 x i8> %a to <vscale x 4 x i32>
282 %b.zext = zext <vscale x 4 x i16> %b to <vscale x 4 x i32>
283 %sub = sub <vscale x 4 x i32> %a.zext, %b.zext
284 %abs = call <vscale x 4 x i32> @llvm.abs.nxv4i32(<vscale x 4 x i32> %sub, i1 true)
285 ret <vscale x 4 x i32> %abs
288 ; Test the situation where isLegal(ISD::ABD, typeof(%a)) returns true but %a and
289 ; %b are promoted differently.
290 define <vscale x 4 x i32> @uabd_non_matching_promotion(<vscale x 4 x i8> %a, <vscale x 4 x i8> %b) #0 {
291 ; CHECK-LABEL: uabd_non_matching_promotion:
293 ; CHECK-NEXT: ptrue p0.s
294 ; CHECK-NEXT: and z0.s, z0.s, #0xff
295 ; CHECK-NEXT: sxtb z1.s, p0/m, z1.s
296 ; CHECK-NEXT: sub z0.s, z0.s, z1.s
297 ; CHECK-NEXT: abs z0.s, p0/m, z0.s
299 %a.zext = zext <vscale x 4 x i8> %a to <vscale x 4 x i32>
300 %b.zext = sext <vscale x 4 x i8> %b to <vscale x 4 x i32>
301 %sub = sub <vscale x 4 x i32> %a.zext, %b.zext
302 %abs = call <vscale x 4 x i32> @llvm.abs.nxv4i32(<vscale x 4 x i32> %sub, i1 true)
303 ret <vscale x 4 x i32> %abs
306 declare <vscale x 16 x i8> @llvm.abs.nxv16i8(<vscale x 16 x i8>, i1)
308 declare <vscale x 8 x i16> @llvm.abs.nxv8i16(<vscale x 8 x i16>, i1)
309 declare <vscale x 16 x i16> @llvm.abs.nxv16i16(<vscale x 16 x i16>, i1)
311 declare <vscale x 4 x i32> @llvm.abs.nxv4i32(<vscale x 4 x i32>, i1)
312 declare <vscale x 8 x i32> @llvm.abs.nxv8i32(<vscale x 8 x i32>, i1)
314 declare <vscale x 2 x i64> @llvm.abs.nxv2i64(<vscale x 2 x i64>, i1)
315 declare <vscale x 4 x i64> @llvm.abs.nxv4i64(<vscale x 4 x i64>, i1)
317 declare <vscale x 2 x i128> @llvm.abs.nxv2i128(<vscale x 2 x i128>, i1)
319 attributes #0 = { "target-features"="+neon,+sve" }