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