1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-bmi < %s | FileCheck %s --check-prefix=CHECK-NOBMI
3; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi < %s | FileCheck %s --check-prefix=CHECK-BMI
4
5; https://bugs.llvm.org/show_bug.cgi?id=37104
6
7; X:           [bit 3210]
8; Y: [bit 7654]
9
10define i8 @out8_constmask(i8 %x, i8 %y) {
11; CHECK-NOBMI-LABEL: out8_constmask:
12; CHECK-NOBMI:       # %bb.0:
13; CHECK-NOBMI-NEXT:    andb $15, %dil
14; CHECK-NOBMI-NEXT:    andb $-16, %sil
15; CHECK-NOBMI-NEXT:    orb %dil, %sil
16; CHECK-NOBMI-NEXT:    movl %esi, %eax
17; CHECK-NOBMI-NEXT:    retq
18;
19; CHECK-BMI-LABEL: out8_constmask:
20; CHECK-BMI:       # %bb.0:
21; CHECK-BMI-NEXT:    andb $15, %dil
22; CHECK-BMI-NEXT:    andb $-16, %sil
23; CHECK-BMI-NEXT:    orb %dil, %sil
24; CHECK-BMI-NEXT:    movl %esi, %eax
25; CHECK-BMI-NEXT:    retq
26  %mx = and i8 %x, 15
27  %my = and i8 %y, -16
28  %r = or i8 %mx, %my
29  ret i8 %r
30}
31
32define i16 @out16_constmask(i16 %x, i16 %y) {
33; CHECK-NOBMI-LABEL: out16_constmask:
34; CHECK-NOBMI:       # %bb.0:
35; CHECK-NOBMI-NEXT:    # kill: def $esi killed $esi def $rsi
36; CHECK-NOBMI-NEXT:    # kill: def $edi killed $edi def $rdi
37; CHECK-NOBMI-NEXT:    andl $3855, %edi # imm = 0xF0F
38; CHECK-NOBMI-NEXT:    andl $-3856, %esi # imm = 0xF0F0
39; CHECK-NOBMI-NEXT:    leal (%rsi,%rdi), %eax
40; CHECK-NOBMI-NEXT:    # kill: def $ax killed $ax killed $eax
41; CHECK-NOBMI-NEXT:    retq
42;
43; CHECK-BMI-LABEL: out16_constmask:
44; CHECK-BMI:       # %bb.0:
45; CHECK-BMI-NEXT:    # kill: def $esi killed $esi def $rsi
46; CHECK-BMI-NEXT:    # kill: def $edi killed $edi def $rdi
47; CHECK-BMI-NEXT:    andl $3855, %edi # imm = 0xF0F
48; CHECK-BMI-NEXT:    andl $-3856, %esi # imm = 0xF0F0
49; CHECK-BMI-NEXT:    leal (%rsi,%rdi), %eax
50; CHECK-BMI-NEXT:    # kill: def $ax killed $ax killed $eax
51; CHECK-BMI-NEXT:    retq
52  %mx = and i16 %x, 3855
53  %my = and i16 %y, -3856
54  %r = or i16 %mx, %my
55  ret i16 %r
56}
57
58define i32 @out32_constmask(i32 %x, i32 %y) {
59; CHECK-NOBMI-LABEL: out32_constmask:
60; CHECK-NOBMI:       # %bb.0:
61; CHECK-NOBMI-NEXT:    # kill: def $esi killed $esi def $rsi
62; CHECK-NOBMI-NEXT:    # kill: def $edi killed $edi def $rdi
63; CHECK-NOBMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
64; CHECK-NOBMI-NEXT:    andl $-252645136, %esi # imm = 0xF0F0F0F0
65; CHECK-NOBMI-NEXT:    leal (%rsi,%rdi), %eax
66; CHECK-NOBMI-NEXT:    retq
67;
68; CHECK-BMI-LABEL: out32_constmask:
69; CHECK-BMI:       # %bb.0:
70; CHECK-BMI-NEXT:    # kill: def $esi killed $esi def $rsi
71; CHECK-BMI-NEXT:    # kill: def $edi killed $edi def $rdi
72; CHECK-BMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
73; CHECK-BMI-NEXT:    andl $-252645136, %esi # imm = 0xF0F0F0F0
74; CHECK-BMI-NEXT:    leal (%rsi,%rdi), %eax
75; CHECK-BMI-NEXT:    retq
76  %mx = and i32 %x, 252645135
77  %my = and i32 %y, -252645136
78  %r = or i32 %mx, %my
79  ret i32 %r
80}
81
82define i64 @out64_constmask(i64 %x, i64 %y) {
83; CHECK-NOBMI-LABEL: out64_constmask:
84; CHECK-NOBMI:       # %bb.0:
85; CHECK-NOBMI-NEXT:    movabsq $1085102592571150095, %rcx # imm = 0xF0F0F0F0F0F0F0F
86; CHECK-NOBMI-NEXT:    andq %rdi, %rcx
87; CHECK-NOBMI-NEXT:    movabsq $-1085102592571150096, %rax # imm = 0xF0F0F0F0F0F0F0F0
88; CHECK-NOBMI-NEXT:    andq %rsi, %rax
89; CHECK-NOBMI-NEXT:    orq %rcx, %rax
90; CHECK-NOBMI-NEXT:    retq
91;
92; CHECK-BMI-LABEL: out64_constmask:
93; CHECK-BMI:       # %bb.0:
94; CHECK-BMI-NEXT:    movabsq $1085102592571150095, %rcx # imm = 0xF0F0F0F0F0F0F0F
95; CHECK-BMI-NEXT:    andq %rdi, %rcx
96; CHECK-BMI-NEXT:    movabsq $-1085102592571150096, %rax # imm = 0xF0F0F0F0F0F0F0F0
97; CHECK-BMI-NEXT:    andq %rsi, %rax
98; CHECK-BMI-NEXT:    orq %rcx, %rax
99; CHECK-BMI-NEXT:    retq
100  %mx = and i64 %x, 1085102592571150095
101  %my = and i64 %y, -1085102592571150096
102  %r = or i64 %mx, %my
103  ret i64 %r
104}
105
106;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107; Should be the same as the previous one.
108;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109
110define i8 @in8_constmask(i8 %x, i8 %y) {
111; CHECK-NOBMI-LABEL: in8_constmask:
112; CHECK-NOBMI:       # %bb.0:
113; CHECK-NOBMI-NEXT:    xorl %esi, %edi
114; CHECK-NOBMI-NEXT:    andb $15, %dil
115; CHECK-NOBMI-NEXT:    xorb %dil, %sil
116; CHECK-NOBMI-NEXT:    movl %esi, %eax
117; CHECK-NOBMI-NEXT:    retq
118;
119; CHECK-BMI-LABEL: in8_constmask:
120; CHECK-BMI:       # %bb.0:
121; CHECK-BMI-NEXT:    xorl %esi, %edi
122; CHECK-BMI-NEXT:    andb $15, %dil
123; CHECK-BMI-NEXT:    xorb %dil, %sil
124; CHECK-BMI-NEXT:    movl %esi, %eax
125; CHECK-BMI-NEXT:    retq
126  %n0 = xor i8 %x, %y
127  %n1 = and i8 %n0, 15
128  %r = xor i8 %n1, %y
129  ret i8 %r
130}
131
132define i16 @in16_constmask(i16 %x, i16 %y) {
133; CHECK-NOBMI-LABEL: in16_constmask:
134; CHECK-NOBMI:       # %bb.0:
135; CHECK-NOBMI-NEXT:    xorl %esi, %edi
136; CHECK-NOBMI-NEXT:    andl $3855, %edi # imm = 0xF0F
137; CHECK-NOBMI-NEXT:    xorl %esi, %edi
138; CHECK-NOBMI-NEXT:    movl %edi, %eax
139; CHECK-NOBMI-NEXT:    retq
140;
141; CHECK-BMI-LABEL: in16_constmask:
142; CHECK-BMI:       # %bb.0:
143; CHECK-BMI-NEXT:    xorl %esi, %edi
144; CHECK-BMI-NEXT:    andl $3855, %edi # imm = 0xF0F
145; CHECK-BMI-NEXT:    xorl %esi, %edi
146; CHECK-BMI-NEXT:    movl %edi, %eax
147; CHECK-BMI-NEXT:    retq
148  %n0 = xor i16 %x, %y
149  %n1 = and i16 %n0, 3855
150  %r = xor i16 %n1, %y
151  ret i16 %r
152}
153
154define i32 @in32_constmask(i32 %x, i32 %y) {
155; CHECK-NOBMI-LABEL: in32_constmask:
156; CHECK-NOBMI:       # %bb.0:
157; CHECK-NOBMI-NEXT:    xorl %esi, %edi
158; CHECK-NOBMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
159; CHECK-NOBMI-NEXT:    xorl %esi, %edi
160; CHECK-NOBMI-NEXT:    movl %edi, %eax
161; CHECK-NOBMI-NEXT:    retq
162;
163; CHECK-BMI-LABEL: in32_constmask:
164; CHECK-BMI:       # %bb.0:
165; CHECK-BMI-NEXT:    xorl %esi, %edi
166; CHECK-BMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
167; CHECK-BMI-NEXT:    xorl %esi, %edi
168; CHECK-BMI-NEXT:    movl %edi, %eax
169; CHECK-BMI-NEXT:    retq
170  %n0 = xor i32 %x, %y
171  %n1 = and i32 %n0, 252645135
172  %r = xor i32 %n1, %y
173  ret i32 %r
174}
175
176define i64 @in64_constmask(i64 %x, i64 %y) {
177; CHECK-NOBMI-LABEL: in64_constmask:
178; CHECK-NOBMI:       # %bb.0:
179; CHECK-NOBMI-NEXT:    xorq %rsi, %rdi
180; CHECK-NOBMI-NEXT:    movabsq $1085102592571150095, %rax # imm = 0xF0F0F0F0F0F0F0F
181; CHECK-NOBMI-NEXT:    andq %rdi, %rax
182; CHECK-NOBMI-NEXT:    xorq %rsi, %rax
183; CHECK-NOBMI-NEXT:    retq
184;
185; CHECK-BMI-LABEL: in64_constmask:
186; CHECK-BMI:       # %bb.0:
187; CHECK-BMI-NEXT:    xorq %rsi, %rdi
188; CHECK-BMI-NEXT:    movabsq $1085102592571150095, %rax # imm = 0xF0F0F0F0F0F0F0F
189; CHECK-BMI-NEXT:    andq %rdi, %rax
190; CHECK-BMI-NEXT:    xorq %rsi, %rax
191; CHECK-BMI-NEXT:    retq
192  %n0 = xor i64 %x, %y
193  %n1 = and i64 %n0, 1085102592571150095
194  %r = xor i64 %n1, %y
195  ret i64 %r
196}
197
198; ============================================================================ ;
199; Constant Commutativity tests.
200; ============================================================================ ;
201
202define i32 @in_constmask_commutativity_0_1(i32 %x, i32 %y) {
203; CHECK-NOBMI-LABEL: in_constmask_commutativity_0_1:
204; CHECK-NOBMI:       # %bb.0:
205; CHECK-NOBMI-NEXT:    xorl %esi, %edi
206; CHECK-NOBMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
207; CHECK-NOBMI-NEXT:    xorl %esi, %edi
208; CHECK-NOBMI-NEXT:    movl %edi, %eax
209; CHECK-NOBMI-NEXT:    retq
210;
211; CHECK-BMI-LABEL: in_constmask_commutativity_0_1:
212; CHECK-BMI:       # %bb.0:
213; CHECK-BMI-NEXT:    xorl %esi, %edi
214; CHECK-BMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
215; CHECK-BMI-NEXT:    xorl %esi, %edi
216; CHECK-BMI-NEXT:    movl %edi, %eax
217; CHECK-BMI-NEXT:    retq
218  %n0 = xor i32 %x, %y
219  %n1 = and i32 %n0, 252645135
220  %r = xor i32 %y, %n1 ; swapped
221  ret i32 %r
222}
223
224define i32 @in_constmask_commutativity_1_0(i32 %x, i32 %y) {
225; CHECK-NOBMI-LABEL: in_constmask_commutativity_1_0:
226; CHECK-NOBMI:       # %bb.0:
227; CHECK-NOBMI-NEXT:    xorl %edi, %esi
228; CHECK-NOBMI-NEXT:    andl $252645135, %esi # imm = 0xF0F0F0F
229; CHECK-NOBMI-NEXT:    xorl %edi, %esi
230; CHECK-NOBMI-NEXT:    movl %esi, %eax
231; CHECK-NOBMI-NEXT:    retq
232;
233; CHECK-BMI-LABEL: in_constmask_commutativity_1_0:
234; CHECK-BMI:       # %bb.0:
235; CHECK-BMI-NEXT:    xorl %edi, %esi
236; CHECK-BMI-NEXT:    andl $252645135, %esi # imm = 0xF0F0F0F
237; CHECK-BMI-NEXT:    xorl %edi, %esi
238; CHECK-BMI-NEXT:    movl %esi, %eax
239; CHECK-BMI-NEXT:    retq
240  %n0 = xor i32 %x, %y
241  %n1 = and i32 %n0, 252645135
242  %r = xor i32 %n1, %x ; %x instead of %y
243  ret i32 %r
244}
245
246define i32 @in_constmask_commutativity_1_1(i32 %x, i32 %y) {
247; CHECK-NOBMI-LABEL: in_constmask_commutativity_1_1:
248; CHECK-NOBMI:       # %bb.0:
249; CHECK-NOBMI-NEXT:    xorl %edi, %esi
250; CHECK-NOBMI-NEXT:    andl $252645135, %esi # imm = 0xF0F0F0F
251; CHECK-NOBMI-NEXT:    xorl %edi, %esi
252; CHECK-NOBMI-NEXT:    movl %esi, %eax
253; CHECK-NOBMI-NEXT:    retq
254;
255; CHECK-BMI-LABEL: in_constmask_commutativity_1_1:
256; CHECK-BMI:       # %bb.0:
257; CHECK-BMI-NEXT:    xorl %edi, %esi
258; CHECK-BMI-NEXT:    andl $252645135, %esi # imm = 0xF0F0F0F
259; CHECK-BMI-NEXT:    xorl %edi, %esi
260; CHECK-BMI-NEXT:    movl %esi, %eax
261; CHECK-BMI-NEXT:    retq
262  %n0 = xor i32 %x, %y
263  %n1 = and i32 %n0, 252645135
264  %r = xor i32 %x, %n1 ; swapped, %x instead of %y
265  ret i32 %r
266}
267
268; ============================================================================ ;
269; Y is an 'and' too.
270; ============================================================================ ;
271
272define i32 @in_complex_y0_constmask(i32 %x, i32 %y_hi, i32 %y_low) {
273; CHECK-NOBMI-LABEL: in_complex_y0_constmask:
274; CHECK-NOBMI:       # %bb.0:
275; CHECK-NOBMI-NEXT:    andl %edx, %esi
276; CHECK-NOBMI-NEXT:    xorl %esi, %edi
277; CHECK-NOBMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
278; CHECK-NOBMI-NEXT:    xorl %esi, %edi
279; CHECK-NOBMI-NEXT:    movl %edi, %eax
280; CHECK-NOBMI-NEXT:    retq
281;
282; CHECK-BMI-LABEL: in_complex_y0_constmask:
283; CHECK-BMI:       # %bb.0:
284; CHECK-BMI-NEXT:    andl %edx, %esi
285; CHECK-BMI-NEXT:    xorl %esi, %edi
286; CHECK-BMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
287; CHECK-BMI-NEXT:    xorl %esi, %edi
288; CHECK-BMI-NEXT:    movl %edi, %eax
289; CHECK-BMI-NEXT:    retq
290  %y = and i32 %y_hi, %y_low
291  %n0 = xor i32 %x, %y
292  %n1 = and i32 %n0, 252645135
293  %r = xor i32 %n1, %y
294  ret i32 %r
295}
296
297define i32 @in_complex_y1_constmask(i32 %x, i32 %y_hi, i32 %y_low) {
298; CHECK-NOBMI-LABEL: in_complex_y1_constmask:
299; CHECK-NOBMI:       # %bb.0:
300; CHECK-NOBMI-NEXT:    andl %edx, %esi
301; CHECK-NOBMI-NEXT:    xorl %esi, %edi
302; CHECK-NOBMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
303; CHECK-NOBMI-NEXT:    xorl %esi, %edi
304; CHECK-NOBMI-NEXT:    movl %edi, %eax
305; CHECK-NOBMI-NEXT:    retq
306;
307; CHECK-BMI-LABEL: in_complex_y1_constmask:
308; CHECK-BMI:       # %bb.0:
309; CHECK-BMI-NEXT:    andl %edx, %esi
310; CHECK-BMI-NEXT:    xorl %esi, %edi
311; CHECK-BMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
312; CHECK-BMI-NEXT:    xorl %esi, %edi
313; CHECK-BMI-NEXT:    movl %edi, %eax
314; CHECK-BMI-NEXT:    retq
315  %y = and i32 %y_hi, %y_low
316  %n0 = xor i32 %x, %y
317  %n1 = and i32 %n0, 252645135
318  %r = xor i32 %y, %n1
319  ret i32 %r
320}
321
322; ============================================================================ ;
323; Negative tests. Should not be folded.
324; ============================================================================ ;
325
326; Multi-use tests.
327
328declare void @use32(i32) nounwind
329
330define i32 @in_multiuse_A_constmask(i32 %x, i32 %y, i32 %z) nounwind {
331; CHECK-NOBMI-LABEL: in_multiuse_A_constmask:
332; CHECK-NOBMI:       # %bb.0:
333; CHECK-NOBMI-NEXT:    pushq %rbp
334; CHECK-NOBMI-NEXT:    pushq %rbx
335; CHECK-NOBMI-NEXT:    pushq %rax
336; CHECK-NOBMI-NEXT:    movl %esi, %ebx
337; CHECK-NOBMI-NEXT:    movl %edi, %ebp
338; CHECK-NOBMI-NEXT:    xorl %esi, %ebp
339; CHECK-NOBMI-NEXT:    andl $252645135, %ebp # imm = 0xF0F0F0F
340; CHECK-NOBMI-NEXT:    movl %ebp, %edi
341; CHECK-NOBMI-NEXT:    callq use32
342; CHECK-NOBMI-NEXT:    xorl %ebx, %ebp
343; CHECK-NOBMI-NEXT:    movl %ebp, %eax
344; CHECK-NOBMI-NEXT:    addq $8, %rsp
345; CHECK-NOBMI-NEXT:    popq %rbx
346; CHECK-NOBMI-NEXT:    popq %rbp
347; CHECK-NOBMI-NEXT:    retq
348;
349; CHECK-BMI-LABEL: in_multiuse_A_constmask:
350; CHECK-BMI:       # %bb.0:
351; CHECK-BMI-NEXT:    pushq %rbp
352; CHECK-BMI-NEXT:    pushq %rbx
353; CHECK-BMI-NEXT:    pushq %rax
354; CHECK-BMI-NEXT:    movl %esi, %ebx
355; CHECK-BMI-NEXT:    movl %edi, %ebp
356; CHECK-BMI-NEXT:    xorl %esi, %ebp
357; CHECK-BMI-NEXT:    andl $252645135, %ebp # imm = 0xF0F0F0F
358; CHECK-BMI-NEXT:    movl %ebp, %edi
359; CHECK-BMI-NEXT:    callq use32
360; CHECK-BMI-NEXT:    xorl %ebx, %ebp
361; CHECK-BMI-NEXT:    movl %ebp, %eax
362; CHECK-BMI-NEXT:    addq $8, %rsp
363; CHECK-BMI-NEXT:    popq %rbx
364; CHECK-BMI-NEXT:    popq %rbp
365; CHECK-BMI-NEXT:    retq
366  %n0 = xor i32 %x, %y
367  %n1 = and i32 %n0, 252645135
368  call void @use32(i32 %n1)
369  %r = xor i32 %n1, %y
370  ret i32 %r
371}
372
373define i32 @in_multiuse_B_constmask(i32 %x, i32 %y, i32 %z) nounwind {
374; CHECK-NOBMI-LABEL: in_multiuse_B_constmask:
375; CHECK-NOBMI:       # %bb.0:
376; CHECK-NOBMI-NEXT:    pushq %rbp
377; CHECK-NOBMI-NEXT:    pushq %rbx
378; CHECK-NOBMI-NEXT:    pushq %rax
379; CHECK-NOBMI-NEXT:    movl %esi, %ebx
380; CHECK-NOBMI-NEXT:    xorl %esi, %edi
381; CHECK-NOBMI-NEXT:    movl %edi, %ebp
382; CHECK-NOBMI-NEXT:    andl $252645135, %ebp # imm = 0xF0F0F0F
383; CHECK-NOBMI-NEXT:    callq use32
384; CHECK-NOBMI-NEXT:    xorl %ebx, %ebp
385; CHECK-NOBMI-NEXT:    movl %ebp, %eax
386; CHECK-NOBMI-NEXT:    addq $8, %rsp
387; CHECK-NOBMI-NEXT:    popq %rbx
388; CHECK-NOBMI-NEXT:    popq %rbp
389; CHECK-NOBMI-NEXT:    retq
390;
391; CHECK-BMI-LABEL: in_multiuse_B_constmask:
392; CHECK-BMI:       # %bb.0:
393; CHECK-BMI-NEXT:    pushq %rbp
394; CHECK-BMI-NEXT:    pushq %rbx
395; CHECK-BMI-NEXT:    pushq %rax
396; CHECK-BMI-NEXT:    movl %esi, %ebx
397; CHECK-BMI-NEXT:    xorl %esi, %edi
398; CHECK-BMI-NEXT:    movl %edi, %ebp
399; CHECK-BMI-NEXT:    andl $252645135, %ebp # imm = 0xF0F0F0F
400; CHECK-BMI-NEXT:    callq use32
401; CHECK-BMI-NEXT:    xorl %ebx, %ebp
402; CHECK-BMI-NEXT:    movl %ebp, %eax
403; CHECK-BMI-NEXT:    addq $8, %rsp
404; CHECK-BMI-NEXT:    popq %rbx
405; CHECK-BMI-NEXT:    popq %rbp
406; CHECK-BMI-NEXT:    retq
407  %n0 = xor i32 %x, %y
408  %n1 = and i32 %n0, 252645135
409  call void @use32(i32 %n0)
410  %r = xor i32 %n1, %y
411  ret i32 %r
412}
413
414; Various bad variants
415
416define i32 @n0_badconstmask(i32 %x, i32 %y) {
417; CHECK-NOBMI-LABEL: n0_badconstmask:
418; CHECK-NOBMI:       # %bb.0:
419; CHECK-NOBMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
420; CHECK-NOBMI-NEXT:    andl $-252645135, %esi # imm = 0xF0F0F0F1
421; CHECK-NOBMI-NEXT:    orl %edi, %esi
422; CHECK-NOBMI-NEXT:    movl %esi, %eax
423; CHECK-NOBMI-NEXT:    retq
424;
425; CHECK-BMI-LABEL: n0_badconstmask:
426; CHECK-BMI:       # %bb.0:
427; CHECK-BMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
428; CHECK-BMI-NEXT:    andl $-252645135, %esi # imm = 0xF0F0F0F1
429; CHECK-BMI-NEXT:    orl %edi, %esi
430; CHECK-BMI-NEXT:    movl %esi, %eax
431; CHECK-BMI-NEXT:    retq
432  %mx = and i32 %x, 252645135
433  %my = and i32 %y, -252645135 ; instead of -252645136
434  %r = or i32 %mx, %my
435  ret i32 %r
436}
437
438define i32 @n1_thirdvar_constmask(i32 %x, i32 %y, i32 %z) {
439; CHECK-NOBMI-LABEL: n1_thirdvar_constmask:
440; CHECK-NOBMI:       # %bb.0:
441; CHECK-NOBMI-NEXT:    xorl %esi, %edi
442; CHECK-NOBMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
443; CHECK-NOBMI-NEXT:    xorl %edx, %edi
444; CHECK-NOBMI-NEXT:    movl %edi, %eax
445; CHECK-NOBMI-NEXT:    retq
446;
447; CHECK-BMI-LABEL: n1_thirdvar_constmask:
448; CHECK-BMI:       # %bb.0:
449; CHECK-BMI-NEXT:    xorl %esi, %edi
450; CHECK-BMI-NEXT:    andl $252645135, %edi # imm = 0xF0F0F0F
451; CHECK-BMI-NEXT:    xorl %edx, %edi
452; CHECK-BMI-NEXT:    movl %edi, %eax
453; CHECK-BMI-NEXT:    retq
454  %n0 = xor i32 %x, %y
455  %n1 = and i32 %n0, 252645135
456  %r = xor i32 %n1, %z ; instead of %y
457  ret i32 %r
458}
459