unfold-masked-merge-scalar-constmask-interleavedbytehalves.ll
7.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=aarch64-unknown-linux-gnu < %s | FileCheck %s
; https://bugs.llvm.org/show_bug.cgi?id=37104
; X: [bit 3210]
; Y: [bit 7654]
define i8 @out8_constmask(i8 %x, i8 %y) {
; CHECK-LABEL: out8_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: bfxil w1, w0, #0, #4
; CHECK-NEXT: mov w0, w1
; CHECK-NEXT: ret
%mx = and i8 %x, 15
%my = and i8 %y, -16
%r = or i8 %mx, %my
ret i8 %r
}
define i16 @out16_constmask(i16 %x, i16 %y) {
; CHECK-LABEL: out16_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: mov w8, #3855
; CHECK-NEXT: mov w9, #-3856
; CHECK-NEXT: and w8, w0, w8
; CHECK-NEXT: and w9, w1, w9
; CHECK-NEXT: orr w0, w8, w9
; CHECK-NEXT: ret
%mx = and i16 %x, 3855
%my = and i16 %y, -3856
%r = or i16 %mx, %my
ret i16 %r
}
define i32 @out32_constmask(i32 %x, i32 %y) {
; CHECK-LABEL: out32_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: and w8, w0, #0xf0f0f0f
; CHECK-NEXT: and w9, w1, #0xf0f0f0f0
; CHECK-NEXT: orr w0, w8, w9
; CHECK-NEXT: ret
%mx = and i32 %x, 252645135
%my = and i32 %y, -252645136
%r = or i32 %mx, %my
ret i32 %r
}
define i64 @out64_constmask(i64 %x, i64 %y) {
; CHECK-LABEL: out64_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: and x8, x0, #0xf0f0f0f0f0f0f0f
; CHECK-NEXT: and x9, x1, #0xf0f0f0f0f0f0f0f0
; CHECK-NEXT: orr x0, x8, x9
; CHECK-NEXT: ret
%mx = and i64 %x, 1085102592571150095
%my = and i64 %y, -1085102592571150096
%r = or i64 %mx, %my
ret i64 %r
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Should be the same as the previous one.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
define i8 @in8_constmask(i8 %x, i8 %y) {
; CHECK-LABEL: in8_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: eor w8, w0, w1
; CHECK-NEXT: and w8, w8, #0xf
; CHECK-NEXT: eor w0, w8, w1
; CHECK-NEXT: ret
%n0 = xor i8 %x, %y
%n1 = and i8 %n0, 15
%r = xor i8 %n1, %y
ret i8 %r
}
define i16 @in16_constmask(i16 %x, i16 %y) {
; CHECK-LABEL: in16_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: eor w8, w0, w1
; CHECK-NEXT: mov w9, #3855
; CHECK-NEXT: and w8, w8, w9
; CHECK-NEXT: eor w0, w8, w1
; CHECK-NEXT: ret
%n0 = xor i16 %x, %y
%n1 = and i16 %n0, 3855
%r = xor i16 %n1, %y
ret i16 %r
}
define i32 @in32_constmask(i32 %x, i32 %y) {
; CHECK-LABEL: in32_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: eor w8, w0, w1
; CHECK-NEXT: and w8, w8, #0xf0f0f0f
; CHECK-NEXT: eor w0, w8, w1
; CHECK-NEXT: ret
%n0 = xor i32 %x, %y
%n1 = and i32 %n0, 252645135
%r = xor i32 %n1, %y
ret i32 %r
}
define i64 @in64_constmask(i64 %x, i64 %y) {
; CHECK-LABEL: in64_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: eor x8, x0, x1
; CHECK-NEXT: and x8, x8, #0xf0f0f0f0f0f0f0f
; CHECK-NEXT: eor x0, x8, x1
; CHECK-NEXT: ret
%n0 = xor i64 %x, %y
%n1 = and i64 %n0, 1085102592571150095
%r = xor i64 %n1, %y
ret i64 %r
}
; ============================================================================ ;
; Constant Commutativity tests.
; ============================================================================ ;
define i32 @in_constmask_commutativity_0_1(i32 %x, i32 %y) {
; CHECK-LABEL: in_constmask_commutativity_0_1:
; CHECK: // %bb.0:
; CHECK-NEXT: eor w8, w0, w1
; CHECK-NEXT: and w8, w8, #0xf0f0f0f
; CHECK-NEXT: eor w0, w1, w8
; CHECK-NEXT: ret
%n0 = xor i32 %x, %y
%n1 = and i32 %n0, 252645135
%r = xor i32 %y, %n1 ; swapped
ret i32 %r
}
define i32 @in_constmask_commutativity_1_0(i32 %x, i32 %y) {
; CHECK-LABEL: in_constmask_commutativity_1_0:
; CHECK: // %bb.0:
; CHECK-NEXT: eor w8, w0, w1
; CHECK-NEXT: and w8, w8, #0xf0f0f0f
; CHECK-NEXT: eor w0, w8, w0
; CHECK-NEXT: ret
%n0 = xor i32 %x, %y
%n1 = and i32 %n0, 252645135
%r = xor i32 %n1, %x ; %x instead of %y
ret i32 %r
}
define i32 @in_constmask_commutativity_1_1(i32 %x, i32 %y) {
; CHECK-LABEL: in_constmask_commutativity_1_1:
; CHECK: // %bb.0:
; CHECK-NEXT: eor w8, w0, w1
; CHECK-NEXT: and w8, w8, #0xf0f0f0f
; CHECK-NEXT: eor w0, w0, w8
; CHECK-NEXT: ret
%n0 = xor i32 %x, %y
%n1 = and i32 %n0, 252645135
%r = xor i32 %x, %n1 ; swapped, %x instead of %y
ret i32 %r
}
; ============================================================================ ;
; Y is an 'and' too.
; ============================================================================ ;
define i32 @in_complex_y0_constmask(i32 %x, i32 %y_hi, i32 %y_low) {
; CHECK-LABEL: in_complex_y0_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: and w8, w1, w2
; CHECK-NEXT: eor w9, w0, w8
; CHECK-NEXT: and w9, w9, #0xf0f0f0f
; CHECK-NEXT: eor w0, w9, w8
; CHECK-NEXT: ret
%y = and i32 %y_hi, %y_low
%n0 = xor i32 %x, %y
%n1 = and i32 %n0, 252645135
%r = xor i32 %n1, %y
ret i32 %r
}
define i32 @in_complex_y1_constmask(i32 %x, i32 %y_hi, i32 %y_low) {
; CHECK-LABEL: in_complex_y1_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: and w8, w1, w2
; CHECK-NEXT: eor w9, w0, w8
; CHECK-NEXT: and w9, w9, #0xf0f0f0f
; CHECK-NEXT: eor w0, w8, w9
; CHECK-NEXT: ret
%y = and i32 %y_hi, %y_low
%n0 = xor i32 %x, %y
%n1 = and i32 %n0, 252645135
%r = xor i32 %y, %n1
ret i32 %r
}
; ============================================================================ ;
; Negative tests. Should not be folded.
; ============================================================================ ;
; Multi-use tests.
declare void @use32(i32) nounwind
define i32 @in_multiuse_A_constmask(i32 %x, i32 %y, i32 %z) nounwind {
; CHECK-LABEL: in_multiuse_A_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: str x30, [sp, #-32]! // 8-byte Folded Spill
; CHECK-NEXT: eor w8, w0, w1
; CHECK-NEXT: stp x20, x19, [sp, #16] // 16-byte Folded Spill
; CHECK-NEXT: and w20, w8, #0xf0f0f0f
; CHECK-NEXT: mov w0, w20
; CHECK-NEXT: mov w19, w1
; CHECK-NEXT: bl use32
; CHECK-NEXT: eor w0, w20, w19
; CHECK-NEXT: ldp x20, x19, [sp, #16] // 16-byte Folded Reload
; CHECK-NEXT: ldr x30, [sp], #32 // 8-byte Folded Reload
; CHECK-NEXT: ret
%n0 = xor i32 %x, %y
%n1 = and i32 %n0, 252645135
call void @use32(i32 %n1)
%r = xor i32 %n1, %y
ret i32 %r
}
define i32 @in_multiuse_B_constmask(i32 %x, i32 %y, i32 %z) nounwind {
; CHECK-LABEL: in_multiuse_B_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: str x30, [sp, #-32]! // 8-byte Folded Spill
; CHECK-NEXT: eor w0, w0, w1
; CHECK-NEXT: stp x20, x19, [sp, #16] // 16-byte Folded Spill
; CHECK-NEXT: mov w19, w1
; CHECK-NEXT: and w20, w0, #0xf0f0f0f
; CHECK-NEXT: bl use32
; CHECK-NEXT: eor w0, w20, w19
; CHECK-NEXT: ldp x20, x19, [sp, #16] // 16-byte Folded Reload
; CHECK-NEXT: ldr x30, [sp], #32 // 8-byte Folded Reload
; CHECK-NEXT: ret
%n0 = xor i32 %x, %y
%n1 = and i32 %n0, 252645135
call void @use32(i32 %n0)
%r = xor i32 %n1, %y
ret i32 %r
}
; Various bad variants
define i32 @n0_badconstmask(i32 %x, i32 %y) {
; CHECK-LABEL: n0_badconstmask:
; CHECK: // %bb.0:
; CHECK-NEXT: mov w9, #61681
; CHECK-NEXT: movk w9, #61680, lsl #16
; CHECK-NEXT: and w8, w0, #0xf0f0f0f
; CHECK-NEXT: and w9, w1, w9
; CHECK-NEXT: orr w0, w8, w9
; CHECK-NEXT: ret
%mx = and i32 %x, 252645135
%my = and i32 %y, -252645135 ; instead of -252645136
%r = or i32 %mx, %my
ret i32 %r
}
define i32 @n1_thirdvar_constmask(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: n1_thirdvar_constmask:
; CHECK: // %bb.0:
; CHECK-NEXT: eor w8, w0, w1
; CHECK-NEXT: and w8, w8, #0xf0f0f0f
; CHECK-NEXT: eor w0, w8, w2
; CHECK-NEXT: ret
%n0 = xor i32 %x, %y
%n1 = and i32 %n0, 252645135
%r = xor i32 %n1, %z ; instead of %y
ret i32 %r
}