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: mov z0.b, p0/z, #-1 // =0xffffffffffffffff
28 ; CHECK-NEXT: mov z1.b, p1/z, #-1 // =0xffffffffffffffff
29 ; CHECK-NEXT: ptrue p0.b
30 ; CHECK-NEXT: sabd z0.b, p0/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: mov z0.b, p0/z, #1 // =0x1
148 ; CHECK-NEXT: mov z1.b, p1/z, #1 // =0x1
149 ; CHECK-NEXT: ptrue p0.b
150 ; CHECK-NEXT: uabd z0.b, p0/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: and z0.h, z0.h, #0xff
177 ; CHECK-NEXT: and z1.h, z1.h, #0xff
178 ; CHECK-NEXT: ptrue p0.h
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: and z0.s, z0.s, #0xffff
206 ; CHECK-NEXT: and z1.s, z1.s, #0xffff
207 ; CHECK-NEXT: ptrue p0.s
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: and z0.d, z0.d, #0xffffffff
235 ; CHECK-NEXT: and z1.d, z1.d, #0xffffffff
236 ; CHECK-NEXT: ptrue p0.d
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: ptrue p0.s
253 ; CHECK-NEXT: uabd z0.s, p0/m, z0.s, z1.s
255 %a.zext = zext <vscale x 4 x i32> %a to <vscale x 4 x i64>
256 %b.zext = zext <vscale x 4 x i8> %b to <vscale x 4 x i64>
257 %sub = sub <vscale x 4 x i64> %a.zext, %b.zext
258 %abs = call <vscale x 4 x i64> @llvm.abs.nxv4i64(<vscale x 4 x i64> %sub, i1 true)
259 %trunc = trunc <vscale x 4 x i64> %abs to <vscale x 4 x i32>
260 ret <vscale x 4 x i32> %trunc
263 ; Test the situation where isLegal(ISD::ABD, typeof(%a.zext)) returns true but
264 ; %a and %b have differing types.
265 define <vscale x 4 x i32> @uabd_non_matching_promoted_ops(<vscale x 4 x i8> %a, <vscale x 4 x i16> %b) #0 {
266 ; CHECK-LABEL: uabd_non_matching_promoted_ops:
268 ; CHECK-NEXT: and z0.s, z0.s, #0xff
269 ; CHECK-NEXT: and z1.s, z1.s, #0xffff
270 ; CHECK-NEXT: ptrue p0.s
271 ; CHECK-NEXT: uabd z0.s, p0/m, z0.s, z1.s
273 %a.zext = zext <vscale x 4 x i8> %a to <vscale x 4 x i32>
274 %b.zext = zext <vscale x 4 x i16> %b to <vscale x 4 x i32>
275 %sub = sub <vscale x 4 x i32> %a.zext, %b.zext
276 %abs = call <vscale x 4 x i32> @llvm.abs.nxv4i32(<vscale x 4 x i32> %sub, i1 true)
277 ret <vscale x 4 x i32> %abs
280 ; Test the situation where isLegal(ISD::ABD, typeof(%a)) returns true but %a and
281 ; %b are promoted differently.
282 define <vscale x 4 x i32> @uabd_non_matching_promotion(<vscale x 4 x i8> %a, <vscale x 4 x i8> %b) #0 {
283 ; CHECK-LABEL: uabd_non_matching_promotion:
285 ; CHECK-NEXT: ptrue p0.s
286 ; CHECK-NEXT: and z0.s, z0.s, #0xff
287 ; CHECK-NEXT: sxtb z1.s, p0/m, z1.s
288 ; CHECK-NEXT: sub z0.s, z0.s, z1.s
289 ; CHECK-NEXT: abs z0.s, p0/m, z0.s
291 %a.zext = zext <vscale x 4 x i8> %a to <vscale x 4 x i32>
292 %b.zext = sext <vscale x 4 x i8> %b to <vscale x 4 x i32>
293 %sub = sub <vscale x 4 x i32> %a.zext, %b.zext
294 %abs = call <vscale x 4 x i32> @llvm.abs.nxv4i32(<vscale x 4 x i32> %sub, i1 true)
295 ret <vscale x 4 x i32> %abs
298 declare <vscale x 16 x i8> @llvm.abs.nxv16i8(<vscale x 16 x i8>, i1)
300 declare <vscale x 8 x i16> @llvm.abs.nxv8i16(<vscale x 8 x i16>, i1)
301 declare <vscale x 16 x i16> @llvm.abs.nxv16i16(<vscale x 16 x i16>, i1)
303 declare <vscale x 4 x i32> @llvm.abs.nxv4i32(<vscale x 4 x i32>, i1)
304 declare <vscale x 8 x i32> @llvm.abs.nxv8i32(<vscale x 8 x i32>, i1)
306 declare <vscale x 2 x i64> @llvm.abs.nxv2i64(<vscale x 2 x i64>, i1)
307 declare <vscale x 4 x i64> @llvm.abs.nxv4i64(<vscale x 4 x i64>, i1)
309 declare <vscale x 2 x i128> @llvm.abs.nxv2i128(<vscale x 2 x i128>, i1)
311 attributes #0 = { "target-features"="+neon,+sve" }