1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=aarch64-- | FileCheck %s
4 declare i8 @llvm.fshl.i8(i8, i8, i8)
5 declare i16 @llvm.fshl.i16(i16, i16, i16)
6 declare i32 @llvm.fshl.i32(i32, i32, i32)
7 declare i64 @llvm.fshl.i64(i64, i64, i64)
8 declare <4 x i32> @llvm.fshl.v4i32(<4 x i32>, <4 x i32>, <4 x i32>)
10 declare i8 @llvm.fshr.i8(i8, i8, i8)
11 declare i16 @llvm.fshr.i16(i16, i16, i16)
12 declare i32 @llvm.fshr.i32(i32, i32, i32)
13 declare i64 @llvm.fshr.i64(i64, i64, i64)
14 declare <4 x i32> @llvm.fshr.v4i32(<4 x i32>, <4 x i32>, <4 x i32>)
16 ; General case - all operands can be variables.
18 define i32 @fshl_i32(i32 %x, i32 %y, i32 %z) {
19 ; CHECK-LABEL: fshl_i32:
21 ; CHECK-NEXT: and w9, w2, #0x1f
22 ; CHECK-NEXT: neg w9, w9
23 ; CHECK-NEXT: lsl w8, w0, w2
24 ; CHECK-NEXT: lsr w9, w1, w9
25 ; CHECK-NEXT: orr w8, w8, w9
26 ; CHECK-NEXT: tst w2, #0x1f
27 ; CHECK-NEXT: csel w0, w0, w8, eq
29 %f = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 %z)
33 ; Verify that weird types are minimally supported.
34 declare i37 @llvm.fshl.i37(i37, i37, i37)
35 define i37 @fshl_i37(i37 %x, i37 %y, i37 %z) {
36 ; CHECK-LABEL: fshl_i37:
38 ; CHECK-NEXT: mov x10, #31883
39 ; CHECK-NEXT: movk x10, #3542, lsl #16
40 ; CHECK-NEXT: movk x10, #51366, lsl #32
41 ; CHECK-NEXT: and x9, x2, #0x1fffffffff
42 ; CHECK-NEXT: movk x10, #56679, lsl #48
43 ; CHECK-NEXT: umulh x10, x9, x10
44 ; CHECK-NEXT: mov w11, #37
45 ; CHECK-NEXT: lsr x10, x10, #5
46 ; CHECK-NEXT: msub x9, x10, x11, x9
47 ; CHECK-NEXT: and x8, x1, #0x1fffffffff
48 ; CHECK-NEXT: sub x11, x11, x9
49 ; CHECK-NEXT: lsl x10, x0, x9
50 ; CHECK-NEXT: lsr x8, x8, x11
51 ; CHECK-NEXT: orr x8, x10, x8
52 ; CHECK-NEXT: cmp x9, #0 // =0
53 ; CHECK-NEXT: csel x0, x0, x8, eq
55 %f = call i37 @llvm.fshl.i37(i37 %x, i37 %y, i37 %z)
59 ; extract(concat(0b1110000, 0b1111111) << 2) = 0b1000011
61 declare i7 @llvm.fshl.i7(i7, i7, i7)
62 define i7 @fshl_i7_const_fold() {
63 ; CHECK-LABEL: fshl_i7_const_fold:
65 ; CHECK-NEXT: mov w0, #67
67 %f = call i7 @llvm.fshl.i7(i7 112, i7 127, i7 2)
71 define i8 @fshl_i8_const_fold_overshift_1() {
72 ; CHECK-LABEL: fshl_i8_const_fold_overshift_1:
74 ; CHECK-NEXT: mov w0, #128
76 %f = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15)
80 define i8 @fshl_i8_const_fold_overshift_2() {
81 ; CHECK-LABEL: fshl_i8_const_fold_overshift_2:
83 ; CHECK-NEXT: mov w0, #120
85 %f = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11)
89 define i8 @fshl_i8_const_fold_overshift_3() {
90 ; CHECK-LABEL: fshl_i8_const_fold_overshift_3:
92 ; CHECK-NEXT: mov w0, wzr
94 %f = call i8 @llvm.fshl.i8(i8 0, i8 225, i8 8)
98 ; With constant shift amount, this is 'extr'.
100 define i32 @fshl_i32_const_shift(i32 %x, i32 %y) {
101 ; CHECK-LABEL: fshl_i32_const_shift:
103 ; CHECK-NEXT: extr w0, w0, w1, #23
105 %f = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 9)
109 ; Check modulo math on shift amount.
111 define i32 @fshl_i32_const_overshift(i32 %x, i32 %y) {
112 ; CHECK-LABEL: fshl_i32_const_overshift:
114 ; CHECK-NEXT: extr w0, w0, w1, #23
116 %f = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 41)
120 ; 64-bit should also work.
122 define i64 @fshl_i64_const_overshift(i64 %x, i64 %y) {
123 ; CHECK-LABEL: fshl_i64_const_overshift:
125 ; CHECK-NEXT: extr x0, x0, x1, #23
127 %f = call i64 @llvm.fshl.i64(i64 %x, i64 %y, i64 105)
131 ; This should work without any node-specific logic.
133 define i8 @fshl_i8_const_fold() {
134 ; CHECK-LABEL: fshl_i8_const_fold:
136 ; CHECK-NEXT: mov w0, #128
138 %f = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 7)
142 ; Repeat everything for funnel shift right.
144 ; General case - all operands can be variables.
146 define i32 @fshr_i32(i32 %x, i32 %y, i32 %z) {
147 ; CHECK-LABEL: fshr_i32:
149 ; CHECK-NEXT: and w9, w2, #0x1f
150 ; CHECK-NEXT: neg w9, w9
151 ; CHECK-NEXT: lsr w8, w1, w2
152 ; CHECK-NEXT: lsl w9, w0, w9
153 ; CHECK-NEXT: orr w8, w9, w8
154 ; CHECK-NEXT: tst w2, #0x1f
155 ; CHECK-NEXT: csel w0, w1, w8, eq
157 %f = call i32 @llvm.fshr.i32(i32 %x, i32 %y, i32 %z)
161 ; Verify that weird types are minimally supported.
162 declare i37 @llvm.fshr.i37(i37, i37, i37)
163 define i37 @fshr_i37(i37 %x, i37 %y, i37 %z) {
164 ; CHECK-LABEL: fshr_i37:
166 ; CHECK-NEXT: mov x10, #31883
167 ; CHECK-NEXT: movk x10, #3542, lsl #16
168 ; CHECK-NEXT: movk x10, #51366, lsl #32
169 ; CHECK-NEXT: and x9, x2, #0x1fffffffff
170 ; CHECK-NEXT: movk x10, #56679, lsl #48
171 ; CHECK-NEXT: umulh x10, x9, x10
172 ; CHECK-NEXT: mov w11, #37
173 ; CHECK-NEXT: lsr x10, x10, #5
174 ; CHECK-NEXT: msub x9, x10, x11, x9
175 ; CHECK-NEXT: and x8, x1, #0x1fffffffff
176 ; CHECK-NEXT: sub x10, x11, x9
177 ; CHECK-NEXT: lsr x8, x8, x9
178 ; CHECK-NEXT: lsl x10, x0, x10
179 ; CHECK-NEXT: orr x8, x10, x8
180 ; CHECK-NEXT: cmp x9, #0 // =0
181 ; CHECK-NEXT: csel x0, x1, x8, eq
183 %f = call i37 @llvm.fshr.i37(i37 %x, i37 %y, i37 %z)
187 ; extract(concat(0b1110000, 0b1111111) >> 2) = 0b0011111
189 declare i7 @llvm.fshr.i7(i7, i7, i7)
190 define i7 @fshr_i7_const_fold() {
191 ; CHECK-LABEL: fshr_i7_const_fold:
193 ; CHECK-NEXT: mov w0, #31
195 %f = call i7 @llvm.fshr.i7(i7 112, i7 127, i7 2)
199 define i8 @fshr_i8_const_fold_overshift_1() {
200 ; CHECK-LABEL: fshr_i8_const_fold_overshift_1:
202 ; CHECK-NEXT: mov w0, #254
204 %f = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15)
208 define i8 @fshr_i8_const_fold_overshift_2() {
209 ; CHECK-LABEL: fshr_i8_const_fold_overshift_2:
211 ; CHECK-NEXT: mov w0, #225
213 %f = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11)
217 define i8 @fshr_i8_const_fold_overshift_3() {
218 ; CHECK-LABEL: fshr_i8_const_fold_overshift_3:
220 ; CHECK-NEXT: mov w0, #255
222 %f = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8)
226 ; With constant shift amount, this is 'extr'.
228 define i32 @fshr_i32_const_shift(i32 %x, i32 %y) {
229 ; CHECK-LABEL: fshr_i32_const_shift:
231 ; CHECK-NEXT: extr w0, w0, w1, #9
233 %f = call i32 @llvm.fshr.i32(i32 %x, i32 %y, i32 9)
237 ; Check modulo math on shift amount. 41-32=9.
239 define i32 @fshr_i32_const_overshift(i32 %x, i32 %y) {
240 ; CHECK-LABEL: fshr_i32_const_overshift:
242 ; CHECK-NEXT: extr w0, w0, w1, #9
244 %f = call i32 @llvm.fshr.i32(i32 %x, i32 %y, i32 41)
248 ; 64-bit should also work. 105-64 = 41.
250 define i64 @fshr_i64_const_overshift(i64 %x, i64 %y) {
251 ; CHECK-LABEL: fshr_i64_const_overshift:
253 ; CHECK-NEXT: extr x0, x0, x1, #41
255 %f = call i64 @llvm.fshr.i64(i64 %x, i64 %y, i64 105)
259 ; This should work without any node-specific logic.
261 define i8 @fshr_i8_const_fold() {
262 ; CHECK-LABEL: fshr_i8_const_fold:
264 ; CHECK-NEXT: mov w0, #254
266 %f = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 7)
270 define i32 @fshl_i32_shift_by_bitwidth(i32 %x, i32 %y) {
271 ; CHECK-LABEL: fshl_i32_shift_by_bitwidth:
274 %f = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 32)
278 define i32 @fshr_i32_shift_by_bitwidth(i32 %x, i32 %y) {
279 ; CHECK-LABEL: fshr_i32_shift_by_bitwidth:
281 ; CHECK-NEXT: mov w0, w1
283 %f = call i32 @llvm.fshr.i32(i32 %x, i32 %y, i32 32)
287 define <4 x i32> @fshl_v4i32_shift_by_bitwidth(<4 x i32> %x, <4 x i32> %y) {
288 ; CHECK-LABEL: fshl_v4i32_shift_by_bitwidth:
291 %f = call <4 x i32> @llvm.fshl.v4i32(<4 x i32> %x, <4 x i32> %y, <4 x i32> <i32 32, i32 32, i32 32, i32 32>)
295 define <4 x i32> @fshr_v4i32_shift_by_bitwidth(<4 x i32> %x, <4 x i32> %y) {
296 ; CHECK-LABEL: fshr_v4i32_shift_by_bitwidth:
298 ; CHECK-NEXT: mov v0.16b, v1.16b
300 %f = call <4 x i32> @llvm.fshr.v4i32(<4 x i32> %x, <4 x i32> %y, <4 x i32> <i32 32, i32 32, i32 32, i32 32>)