[x86] add test case that shows holes in LEA isel
[oota-llvm.git] / test / CodeGen / X86 / or-lea.ll
1 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s
2
3 ; InstCombine and DAGCombiner transform an 'add' into an 'or'
4 ; if there are no common bits from the incoming operands.
5 ; LEA instruction selection should be able to see through that
6 ; transform and reduce add/shift/or instruction counts.
7
8 define i32 @or_shift1_and1(i32 %x, i32 %y) {
9 ; CHECK-LABEL: or_shift1_and1:
10 ; CHECK:       # BB#0:
11 ; CHECK-NEXT:    addl %edi, %edi
12 ; CHECK-NEXT:    andl $1, %esi
13 ; CHECK-NEXT:    leal (%rsi,%rdi), %eax
14 ; CHECK-NEXT:    retq
15
16   %shl = shl i32 %x, 1
17   %and = and i32 %y, 1
18   %or = or i32 %and, %shl
19   ret i32 %or
20 }
21
22 define i32 @or_shift1_and1_swapped(i32 %x, i32 %y) {
23 ; CHECK-LABEL: or_shift1_and1_swapped:
24 ; CHECK:       # BB#0:
25 ; CHECK-NEXT:    leal (%rdi,%rdi), %eax
26 ; CHECK-NEXT:    andl $1, %esi
27 ; CHECK-NEXT:    orl %esi, %eax
28 ; CHECK-NEXT:    retq
29
30   %shl = shl i32 %x, 1
31   %and = and i32 %y, 1
32   %or = or i32 %shl, %and
33   ret i32 %or
34 }
35
36 define i32 @or_shift2_and1(i32 %x, i32 %y) {
37 ; CHECK-LABEL: or_shift2_and1:
38 ; CHECK:       # BB#0:
39 ; CHECK-NEXT:    leal (,%rdi,4), %eax
40 ; CHECK-NEXT:    andl $1, %esi
41 ; CHECK-NEXT:    orl %esi, %eax
42 ; CHECK-NEXT:    retq
43
44   %shl = shl i32 %x, 2
45   %and = and i32 %y, 1
46   %or = or i32 %shl, %and
47   ret i32 %or
48 }
49
50 define i32 @or_shift3_and1(i32 %x, i32 %y) {
51 ; CHECK-LABEL: or_shift3_and1:
52 ; CHECK:       # BB#0:
53 ; CHECK-NEXT:    leal (,%rdi,8), %eax
54 ; CHECK-NEXT:    andl $1, %esi
55 ; CHECK-NEXT:    orl %esi, %eax
56 ; CHECK-NEXT:    retq
57
58   %shl = shl i32 %x, 3
59   %and = and i32 %y, 1
60   %or = or i32 %shl, %and
61   ret i32 %or
62 }
63
64 define i32 @or_shift3_and7(i32 %x, i32 %y) {
65 ; CHECK-LABEL: or_shift3_and7:
66 ; CHECK:       # BB#0:
67 ; CHECK-NEXT:    leal (,%rdi,8), %eax
68 ; CHECK-NEXT:    andl $7, %esi
69 ; CHECK-NEXT:    orl %esi, %eax
70 ; CHECK-NEXT:    retq
71
72   %shl = shl i32 %x, 3
73   %and = and i32 %y, 7
74   %or = or i32 %shl, %and
75   ret i32 %or
76 }
77
78 ; The shift is too big for an LEA.
79
80 define i32 @or_shift4_and1(i32 %x, i32 %y) {
81 ; CHECK-LABEL: or_shift4_and1:
82 ; CHECK:       # BB#0:
83 ; CHECK-NEXT:    shll $4, %edi
84 ; CHECK-NEXT:    andl $1, %esi
85 ; CHECK-NEXT:    leal (%rsi,%rdi), %eax
86 ; CHECK-NEXT:    retq
87
88   %shl = shl i32 %x, 4
89   %and = and i32 %y, 1
90   %or = or i32 %shl, %and
91   ret i32 %or
92 }
93
94 ; The mask is too big for the shift, so the 'or' isn't equivalent to an 'add'.
95
96 define i32 @or_shift3_and8(i32 %x, i32 %y) {
97 ; CHECK-LABEL: or_shift3_and8:
98 ; CHECK:       # BB#0:
99 ; CHECK-NEXT:    leal (,%rdi,8), %eax
100 ; CHECK-NEXT:    andl $8, %esi
101 ; CHECK-NEXT:    orl %esi, %eax
102 ; CHECK-NEXT:    retq
103
104   %shl = shl i32 %x, 3
105   %and = and i32 %y, 8
106   %or = or i32 %shl, %and
107   ret i32 %or
108 }
109
110 ; 64-bit operands should work too.
111
112 define i64 @or_shift1_and1_64(i64 %x, i64 %y) {
113 ; CHECK-LABEL: or_shift1_and1_64:
114 ; CHECK:       # BB#0:
115 ; CHECK-NEXT:    addq %rdi, %rdi
116 ; CHECK-NEXT:    andl $1, %esi
117 ; CHECK-NEXT:    leaq (%rsi,%rdi), %rax
118 ; CHECK-NEXT:    retq
119
120   %shl = shl i64 %x, 1
121   %and = and i64 %y, 1
122   %or = or i64 %and, %shl
123   ret i64 %or
124 }
125