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: bfxil w1, w0, #0, #4
13 ; CHECK-NEXT: mov w0, w1
21 define i16 @out16_constmask(i16 %x, i16 %y) {
22 ; CHECK-LABEL: out16_constmask:
24 ; CHECK-NEXT: mov w8, #3855 // =0xf0f
25 ; CHECK-NEXT: mov w9, #-3856 // =0xfffff0f0
26 ; CHECK-NEXT: and w8, w0, w8
27 ; CHECK-NEXT: and w9, w1, w9
28 ; CHECK-NEXT: orr w0, w8, w9
30 %mx = and i16 %x, 3855
31 %my = and i16 %y, -3856
36 define i32 @out32_constmask(i32 %x, i32 %y) {
37 ; CHECK-LABEL: out32_constmask:
39 ; CHECK-NEXT: and w8, w0, #0xf0f0f0f
40 ; CHECK-NEXT: and w9, w1, #0xf0f0f0f0
41 ; CHECK-NEXT: orr w0, w8, w9
43 %mx = and i32 %x, 252645135
44 %my = and i32 %y, -252645136
49 define i64 @out64_constmask(i64 %x, i64 %y) {
50 ; CHECK-LABEL: out64_constmask:
52 ; CHECK-NEXT: and x8, x0, #0xf0f0f0f0f0f0f0f
53 ; CHECK-NEXT: and x9, x1, #0xf0f0f0f0f0f0f0f0
54 ; CHECK-NEXT: orr x0, x8, x9
56 %mx = and i64 %x, 1085102592571150095
57 %my = and i64 %y, -1085102592571150096
62 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63 ; Should be the same as the previous one.
64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
66 define i8 @in8_constmask(i8 %x, i8 %y) {
67 ; CHECK-LABEL: in8_constmask:
69 ; CHECK-NEXT: eor w8, w0, w1
70 ; CHECK-NEXT: and w8, w8, #0xf
71 ; CHECK-NEXT: eor w0, w8, w1
79 define i16 @in16_constmask(i16 %x, i16 %y) {
80 ; CHECK-LABEL: in16_constmask:
82 ; CHECK-NEXT: mov w8, #3855 // =0xf0f
83 ; CHECK-NEXT: eor w9, w0, w1
84 ; CHECK-NEXT: and w8, w9, w8
85 ; CHECK-NEXT: eor w0, w8, w1
88 %n1 = and i16 %n0, 3855
93 define i32 @in32_constmask(i32 %x, i32 %y) {
94 ; CHECK-LABEL: in32_constmask:
96 ; CHECK-NEXT: eor w8, w0, w1
97 ; CHECK-NEXT: and w8, w8, #0xf0f0f0f
98 ; CHECK-NEXT: eor w0, w8, w1
101 %n1 = and i32 %n0, 252645135
106 define i64 @in64_constmask(i64 %x, i64 %y) {
107 ; CHECK-LABEL: in64_constmask:
109 ; CHECK-NEXT: eor x8, x0, x1
110 ; CHECK-NEXT: and x8, x8, #0xf0f0f0f0f0f0f0f
111 ; CHECK-NEXT: eor x0, x8, x1
114 %n1 = and i64 %n0, 1085102592571150095
119 ; ============================================================================ ;
120 ; Constant Commutativity tests.
121 ; ============================================================================ ;
123 define i32 @in_constmask_commutativity_0_1(i32 %x, i32 %y) {
124 ; CHECK-LABEL: in_constmask_commutativity_0_1:
126 ; CHECK-NEXT: eor w8, w0, w1
127 ; CHECK-NEXT: and w8, w8, #0xf0f0f0f
128 ; CHECK-NEXT: eor w0, w1, w8
131 %n1 = and i32 %n0, 252645135
132 %r = xor i32 %y, %n1 ; swapped
136 define i32 @in_constmask_commutativity_1_0(i32 %x, i32 %y) {
137 ; CHECK-LABEL: in_constmask_commutativity_1_0:
139 ; CHECK-NEXT: eor w8, w0, w1
140 ; CHECK-NEXT: and w8, w8, #0xf0f0f0f
141 ; CHECK-NEXT: eor w0, w8, w0
144 %n1 = and i32 %n0, 252645135
145 %r = xor i32 %n1, %x ; %x instead of %y
149 define i32 @in_constmask_commutativity_1_1(i32 %x, i32 %y) {
150 ; CHECK-LABEL: in_constmask_commutativity_1_1:
152 ; CHECK-NEXT: eor w8, w0, w1
153 ; CHECK-NEXT: and w8, w8, #0xf0f0f0f
154 ; CHECK-NEXT: eor w0, w0, w8
157 %n1 = and i32 %n0, 252645135
158 %r = xor i32 %x, %n1 ; swapped, %x instead of %y
162 ; ============================================================================ ;
164 ; ============================================================================ ;
166 define i32 @in_complex_y0_constmask(i32 %x, i32 %y_hi, i32 %y_low) {
167 ; CHECK-LABEL: in_complex_y0_constmask:
169 ; CHECK-NEXT: and w8, w1, w2
170 ; CHECK-NEXT: eor w9, w0, w8
171 ; CHECK-NEXT: and w9, w9, #0xf0f0f0f
172 ; CHECK-NEXT: eor w0, w9, w8
174 %y = and i32 %y_hi, %y_low
176 %n1 = and i32 %n0, 252645135
181 define i32 @in_complex_y1_constmask(i32 %x, i32 %y_hi, i32 %y_low) {
182 ; CHECK-LABEL: in_complex_y1_constmask:
184 ; CHECK-NEXT: and w8, w1, w2
185 ; CHECK-NEXT: eor w9, w0, w8
186 ; CHECK-NEXT: and w9, w9, #0xf0f0f0f
187 ; CHECK-NEXT: eor w0, w8, w9
189 %y = and i32 %y_hi, %y_low
191 %n1 = and i32 %n0, 252645135
196 ; ============================================================================ ;
197 ; Negative tests. Should not be folded.
198 ; ============================================================================ ;
202 declare void @use32(i32) nounwind
204 define i32 @in_multiuse_A_constmask(i32 %x, i32 %y, i32 %z) nounwind {
205 ; CHECK-LABEL: in_multiuse_A_constmask:
207 ; CHECK-NEXT: str x30, [sp, #-32]! // 8-byte Folded Spill
208 ; CHECK-NEXT: eor w8, w0, w1
209 ; CHECK-NEXT: stp x20, x19, [sp, #16] // 16-byte Folded Spill
210 ; CHECK-NEXT: mov w19, w1
211 ; CHECK-NEXT: and w20, w8, #0xf0f0f0f
212 ; CHECK-NEXT: mov w0, w20
213 ; CHECK-NEXT: bl use32
214 ; CHECK-NEXT: eor w0, w20, w19
215 ; CHECK-NEXT: ldp x20, x19, [sp, #16] // 16-byte Folded Reload
216 ; CHECK-NEXT: ldr x30, [sp], #32 // 8-byte Folded Reload
219 %n1 = and i32 %n0, 252645135
220 call void @use32(i32 %n1)
225 define i32 @in_multiuse_B_constmask(i32 %x, i32 %y, i32 %z) nounwind {
226 ; CHECK-LABEL: in_multiuse_B_constmask:
228 ; CHECK-NEXT: str x30, [sp, #-32]! // 8-byte Folded Spill
229 ; CHECK-NEXT: eor w0, w0, w1
230 ; CHECK-NEXT: stp x20, x19, [sp, #16] // 16-byte Folded Spill
231 ; CHECK-NEXT: mov w19, w1
232 ; CHECK-NEXT: and w20, w0, #0xf0f0f0f
233 ; CHECK-NEXT: bl use32
234 ; CHECK-NEXT: eor w0, w20, w19
235 ; CHECK-NEXT: ldp x20, x19, [sp, #16] // 16-byte Folded Reload
236 ; CHECK-NEXT: ldr x30, [sp], #32 // 8-byte Folded Reload
239 %n1 = and i32 %n0, 252645135
240 call void @use32(i32 %n0)
245 ; Various bad variants
247 define i32 @n0_badconstmask(i32 %x, i32 %y) {
248 ; CHECK-LABEL: n0_badconstmask:
250 ; CHECK-NEXT: mov w8, #61681 // =0xf0f1
251 ; CHECK-NEXT: and w9, w0, #0xf0f0f0f
252 ; CHECK-NEXT: movk w8, #61680, lsl #16
253 ; CHECK-NEXT: and w8, w1, w8
254 ; CHECK-NEXT: orr w0, w9, w8
256 %mx = and i32 %x, 252645135
257 %my = and i32 %y, -252645135 ; instead of -252645136
262 define i32 @n1_thirdvar_constmask(i32 %x, i32 %y, i32 %z) {
263 ; CHECK-LABEL: n1_thirdvar_constmask:
265 ; CHECK-NEXT: eor w8, w0, w1
266 ; CHECK-NEXT: and w8, w8, #0xf0f0f0f
267 ; CHECK-NEXT: eor w0, w8, w2
270 %n1 = and i32 %n0, 252645135
271 %r = xor i32 %n1, %z ; instead of %y