1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=aarch64-unknown-linux-gnu < %s | FileCheck %s
4 ; https://bugs.llvm.org/show_bug.cgi?id=37104
9 define i8 @out8_constmask(i8 %x, i8 %y) {
10 ; CHECK-LABEL: out8_constmask:
12 ; CHECK-NEXT: mov w8, #85
13 ; CHECK-NEXT: mov w9, #-86
14 ; CHECK-NEXT: and w8, w0, w8
15 ; CHECK-NEXT: and w9, w1, w9
16 ; CHECK-NEXT: orr w0, w8, w9
24 define i16 @out16_constmask(i16 %x, i16 %y) {
25 ; CHECK-LABEL: out16_constmask:
27 ; CHECK-NEXT: mov w8, #21845
28 ; CHECK-NEXT: mov w9, #-21846
29 ; CHECK-NEXT: and w8, w0, w8
30 ; CHECK-NEXT: and w9, w1, w9
31 ; CHECK-NEXT: orr w0, w8, w9
33 %mx = and i16 %x, 21845
34 %my = and i16 %y, -21846
39 define i32 @out32_constmask(i32 %x, i32 %y) {
40 ; CHECK-LABEL: out32_constmask:
42 ; CHECK-NEXT: and w8, w0, #0x55555555
43 ; CHECK-NEXT: and w9, w1, #0xaaaaaaaa
44 ; CHECK-NEXT: orr w0, w8, w9
46 %mx = and i32 %x, 1431655765
47 %my = and i32 %y, -1431655766
52 define i64 @out64_constmask(i64 %x, i64 %y) {
53 ; CHECK-LABEL: out64_constmask:
55 ; CHECK-NEXT: and x8, x0, #0x5555555555555555
56 ; CHECK-NEXT: and x9, x1, #0xaaaaaaaaaaaaaaaa
57 ; CHECK-NEXT: orr x0, x8, x9
59 %mx = and i64 %x, 6148914691236517205
60 %my = and i64 %y, -6148914691236517206
65 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
66 ; Should be the same as the previous one.
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
69 define i8 @in8_constmask(i8 %x, i8 %y) {
70 ; CHECK-LABEL: in8_constmask:
72 ; CHECK-NEXT: eor w8, w0, w1
73 ; CHECK-NEXT: mov w9, #85
74 ; CHECK-NEXT: and w8, w8, w9
75 ; CHECK-NEXT: eor w0, w8, w1
83 define i16 @in16_constmask(i16 %x, i16 %y) {
84 ; CHECK-LABEL: in16_constmask:
86 ; CHECK-NEXT: eor w8, w0, w1
87 ; CHECK-NEXT: mov w9, #21845
88 ; CHECK-NEXT: and w8, w8, w9
89 ; CHECK-NEXT: eor w0, w8, w1
92 %n1 = and i16 %n0, 21845
97 define i32 @in32_constmask(i32 %x, i32 %y) {
98 ; CHECK-LABEL: in32_constmask:
100 ; CHECK-NEXT: eor w8, w0, w1
101 ; CHECK-NEXT: and w8, w8, #0x55555555
102 ; CHECK-NEXT: eor w0, w8, w1
105 %n1 = and i32 %n0, 1431655765
110 define i64 @in64_constmask(i64 %x, i64 %y) {
111 ; CHECK-LABEL: in64_constmask:
113 ; CHECK-NEXT: eor x8, x0, x1
114 ; CHECK-NEXT: and x8, x8, #0x5555555555555555
115 ; CHECK-NEXT: eor x0, x8, x1
118 %n1 = and i64 %n0, 6148914691236517205
123 ; ============================================================================ ;
124 ; Constant Commutativity tests.
125 ; ============================================================================ ;
127 define i32 @in_constmask_commutativity_0_1(i32 %x, i32 %y) {
128 ; CHECK-LABEL: in_constmask_commutativity_0_1:
130 ; CHECK-NEXT: eor w8, w0, w1
131 ; CHECK-NEXT: and w8, w8, #0x55555555
132 ; CHECK-NEXT: eor w0, w1, w8
135 %n1 = and i32 %n0, 1431655765
136 %r = xor i32 %y, %n1 ; swapped
140 define i32 @in_constmask_commutativity_1_0(i32 %x, i32 %y) {
141 ; CHECK-LABEL: in_constmask_commutativity_1_0:
143 ; CHECK-NEXT: eor w8, w0, w1
144 ; CHECK-NEXT: and w8, w8, #0x55555555
145 ; CHECK-NEXT: eor w0, w8, w0
148 %n1 = and i32 %n0, 1431655765
149 %r = xor i32 %n1, %x ; %x instead of %y
153 define i32 @in_constmask_commutativity_1_1(i32 %x, i32 %y) {
154 ; CHECK-LABEL: in_constmask_commutativity_1_1:
156 ; CHECK-NEXT: eor w8, w0, w1
157 ; CHECK-NEXT: and w8, w8, #0x55555555
158 ; CHECK-NEXT: eor w0, w0, w8
161 %n1 = and i32 %n0, 1431655765
162 %r = xor i32 %x, %n1 ; swapped, %x instead of %y
166 ; ============================================================================ ;
168 ; ============================================================================ ;
170 define i32 @in_complex_y0_constmask(i32 %x, i32 %y_hi, i32 %y_low) {
171 ; CHECK-LABEL: in_complex_y0_constmask:
173 ; CHECK-NEXT: and w8, w1, w2
174 ; CHECK-NEXT: eor w9, w0, w8
175 ; CHECK-NEXT: and w9, w9, #0x55555555
176 ; CHECK-NEXT: eor w0, w9, w8
178 %y = and i32 %y_hi, %y_low
180 %n1 = and i32 %n0, 1431655765
185 define i32 @in_complex_y1_constmask(i32 %x, i32 %y_hi, i32 %y_low) {
186 ; CHECK-LABEL: in_complex_y1_constmask:
188 ; CHECK-NEXT: and w8, w1, w2
189 ; CHECK-NEXT: eor w9, w0, w8
190 ; CHECK-NEXT: and w9, w9, #0x55555555
191 ; CHECK-NEXT: eor w0, w8, w9
193 %y = and i32 %y_hi, %y_low
195 %n1 = and i32 %n0, 1431655765
200 ; ============================================================================ ;
201 ; Negative tests. Should not be folded.
202 ; ============================================================================ ;
206 declare void @use32(i32) nounwind
208 define i32 @in_multiuse_A_constmask(i32 %x, i32 %y, i32 %z) nounwind {
209 ; CHECK-LABEL: in_multiuse_A_constmask:
211 ; CHECK-NEXT: str x30, [sp, #-32]! // 8-byte Folded Spill
212 ; CHECK-NEXT: eor w8, w0, w1
213 ; CHECK-NEXT: stp x20, x19, [sp, #16] // 16-byte Folded Spill
214 ; CHECK-NEXT: and w20, w8, #0x55555555
215 ; CHECK-NEXT: mov w0, w20
216 ; CHECK-NEXT: mov w19, w1
217 ; CHECK-NEXT: bl use32
218 ; CHECK-NEXT: eor w0, w20, w19
219 ; CHECK-NEXT: ldp x20, x19, [sp, #16] // 16-byte Folded Reload
220 ; CHECK-NEXT: ldr x30, [sp], #32 // 8-byte Folded Reload
223 %n1 = and i32 %n0, 1431655765
224 call void @use32(i32 %n1)
229 define i32 @in_multiuse_B_constmask(i32 %x, i32 %y, i32 %z) nounwind {
230 ; CHECK-LABEL: in_multiuse_B_constmask:
232 ; CHECK-NEXT: str x30, [sp, #-32]! // 8-byte Folded Spill
233 ; CHECK-NEXT: eor w0, w0, w1
234 ; CHECK-NEXT: stp x20, x19, [sp, #16] // 16-byte Folded Spill
235 ; CHECK-NEXT: mov w19, w1
236 ; CHECK-NEXT: and w20, w0, #0x55555555
237 ; CHECK-NEXT: bl use32
238 ; CHECK-NEXT: eor w0, w20, w19
239 ; CHECK-NEXT: ldp x20, x19, [sp, #16] // 16-byte Folded Reload
240 ; CHECK-NEXT: ldr x30, [sp], #32 // 8-byte Folded Reload
243 %n1 = and i32 %n0, 1431655765
244 call void @use32(i32 %n0)
249 ; Various bad variants
251 define i32 @n0_badconstmask(i32 %x, i32 %y) {
252 ; CHECK-LABEL: n0_badconstmask:
254 ; CHECK-NEXT: mov w9, #43691
255 ; CHECK-NEXT: movk w9, #43690, lsl #16
256 ; CHECK-NEXT: and w8, w0, #0x55555555
257 ; CHECK-NEXT: and w9, w1, w9
258 ; CHECK-NEXT: orr w0, w8, w9
260 %mx = and i32 %x, 1431655765
261 %my = and i32 %y, -1431655765 ; instead of -1431655766
266 define i32 @n1_thirdvar_constmask(i32 %x, i32 %y, i32 %z) {
267 ; CHECK-LABEL: n1_thirdvar_constmask:
269 ; CHECK-NEXT: eor w8, w0, w1
270 ; CHECK-NEXT: and w8, w8, #0x55555555
271 ; CHECK-NEXT: eor w0, w8, w2
274 %n1 = and i32 %n0, 1431655765
275 %r = xor i32 %n1, %z ; instead of %y