xref: /minix3/external/bsd/llvm/dist/llvm/test/Transforms/InstCombine/bit-checks.ll (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc; This test makes sure that these instructions are properly eliminated.
2*f4a2713aSLionel Sambuc;
3*f4a2713aSLionel Sambuc; RUN: opt < %s -instcombine -S | \
4*f4a2713aSLionel Sambuc; RUN:    not grep "tobool"
5*f4a2713aSLionel Sambuc; END.
6*f4a2713aSLionel Sambucdefine i32 @main(i32 %argc, i8** %argv) nounwind ssp {
7*f4a2713aSLionel Sambucentry:
8*f4a2713aSLionel Sambuc  %and = and i32 %argc, 1                         ; <i32> [#uses=1]
9*f4a2713aSLionel Sambuc  %tobool = icmp ne i32 %and, 0                   ; <i1> [#uses=1]
10*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 2                        ; <i32> [#uses=1]
11*f4a2713aSLionel Sambuc  %tobool3 = icmp ne i32 %and2, 0                 ; <i1> [#uses=1]
12*f4a2713aSLionel Sambuc  %or.cond = and i1 %tobool, %tobool3             ; <i1> [#uses=1]
13*f4a2713aSLionel Sambuc  %retval.0 = select i1 %or.cond, i32 2, i32 1    ; <i32> [#uses=1]
14*f4a2713aSLionel Sambuc  ret i32 %retval.0
15*f4a2713aSLionel Sambuc}
16*f4a2713aSLionel Sambuc
17*f4a2713aSLionel Sambucdefine i32 @main2(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
18*f4a2713aSLionel Sambucentry:
19*f4a2713aSLionel Sambuc  %and = and i32 %argc, 1                         ; <i32> [#uses=1]
20*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and, 0                   ; <i1> [#uses=1]
21*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 2                        ; <i32> [#uses=1]
22*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, 0                 ; <i1> [#uses=1]
23*f4a2713aSLionel Sambuc  %or.cond = or i1 %tobool, %tobool3              ; <i1> [#uses=1]
24*f4a2713aSLionel Sambuc  %storemerge = select i1 %or.cond, i32 0, i32 1  ; <i32> [#uses=1]
25*f4a2713aSLionel Sambuc  ret i32 %storemerge
26*f4a2713aSLionel Sambuc}
27*f4a2713aSLionel Sambuc
28*f4a2713aSLionel Sambuc; tests to check combining (icmp eq (A & B), C) & (icmp eq (A & D), E)
29*f4a2713aSLionel Sambuc; tests to check if (icmp eq (A & B), 0) is treated like (icmp eq (A & B), B)
30*f4a2713aSLionel Sambuc; if B is a single bit constant
31*f4a2713aSLionel Sambuc
32*f4a2713aSLionel Sambuc; (icmp eq (A & B), 0) & (icmp eq (A & D), 0) -> (icmp eq (A & (B|D)), 0)
33*f4a2713aSLionel Sambucdefine i32 @main3(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
34*f4a2713aSLionel Sambucentry:
35*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
36*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and, 0                   ; <i1> [#uses=1]
37*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 48                       ; <i32> [#uses=1]
38*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, 0                 ; <i1> [#uses=1]
39*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
40*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
41*f4a2713aSLionel Sambuc  ret i32 %storemerge
42*f4a2713aSLionel Sambuc}
43*f4a2713aSLionel Sambuc
44*f4a2713aSLionel Sambucdefine i32 @main3b(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
45*f4a2713aSLionel Sambucentry:
46*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
47*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and, 0                   ; <i1> [#uses=1]
48*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 16                       ; <i32> [#uses=1]
49*f4a2713aSLionel Sambuc  %tobool3 = icmp ne i32 %and2, 16                 ; <i1> [#uses=1]
50*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
51*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
52*f4a2713aSLionel Sambuc  ret i32 %storemerge
53*f4a2713aSLionel Sambuc}
54*f4a2713aSLionel Sambuc
55*f4a2713aSLionel Sambucdefine i32 @main3e_like(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
56*f4a2713aSLionel Sambuc           nounwind readnone ssp {
57*f4a2713aSLionel Sambucentry:
58*f4a2713aSLionel Sambuc  %and = and i32 %argc, %argc2                    ; <i32> [#uses=1]
59*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and, 0                   ; <i1> [#uses=1]
60*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, %argc3                   ; <i32> [#uses=1]
61*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, 0                 ; <i1> [#uses=1]
62*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
63*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
64*f4a2713aSLionel Sambuc  ret i32 %storemerge
65*f4a2713aSLionel Sambuc}
66*f4a2713aSLionel Sambuc
67*f4a2713aSLionel Sambuc; (icmp ne (A & B), 0) | (icmp ne (A & D), 0) -> (icmp ne (A & (B|D)), 0)
68*f4a2713aSLionel Sambucdefine i32 @main3c(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
69*f4a2713aSLionel Sambucentry:
70*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
71*f4a2713aSLionel Sambuc  %tobool = icmp ne i32 %and, 0                   ; <i1> [#uses=1]
72*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 48                       ; <i32> [#uses=1]
73*f4a2713aSLionel Sambuc  %tobool3 = icmp ne i32 %and2, 0                 ; <i1> [#uses=1]
74*f4a2713aSLionel Sambuc  %or.cond = or i1 %tobool, %tobool3              ; <i1> [#uses=1]
75*f4a2713aSLionel Sambuc  %storemerge = select i1 %or.cond, i32 0, i32 1  ; <i32> [#uses=1]
76*f4a2713aSLionel Sambuc  ret i32 %storemerge
77*f4a2713aSLionel Sambuc}
78*f4a2713aSLionel Sambuc
79*f4a2713aSLionel Sambucdefine i32 @main3d(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
80*f4a2713aSLionel Sambucentry:
81*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
82*f4a2713aSLionel Sambuc  %tobool = icmp ne i32 %and, 0                   ; <i1> [#uses=1]
83*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 16                       ; <i32> [#uses=1]
84*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, 16                ; <i1> [#uses=1]
85*f4a2713aSLionel Sambuc  %or.cond = or i1 %tobool, %tobool3              ; <i1> [#uses=1]
86*f4a2713aSLionel Sambuc  %storemerge = select i1 %or.cond, i32 0, i32 1  ; <i32> [#uses=1]
87*f4a2713aSLionel Sambuc  ret i32 %storemerge
88*f4a2713aSLionel Sambuc}
89*f4a2713aSLionel Sambuc
90*f4a2713aSLionel Sambucdefine i32 @main3f_like(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
91*f4a2713aSLionel Sambuc           nounwind readnone ssp {
92*f4a2713aSLionel Sambucentry:
93*f4a2713aSLionel Sambuc  %and = and i32 %argc, %argc2                    ; <i32> [#uses=1]
94*f4a2713aSLionel Sambuc  %tobool = icmp ne i32 %and, 0                   ; <i1> [#uses=1]
95*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, %argc3                   ; <i32> [#uses=1]
96*f4a2713aSLionel Sambuc  %tobool3 = icmp ne i32 %and2, 0                 ; <i1> [#uses=1]
97*f4a2713aSLionel Sambuc  %or.cond = or i1 %tobool, %tobool3              ; <i1> [#uses=1]
98*f4a2713aSLionel Sambuc  %storemerge = select i1 %or.cond, i32 0, i32 1  ; <i32> [#uses=1]
99*f4a2713aSLionel Sambuc  ret i32 %storemerge
100*f4a2713aSLionel Sambuc}
101*f4a2713aSLionel Sambuc
102*f4a2713aSLionel Sambuc; (icmp eq (A & B), B) & (icmp eq (A & D), D) -> (icmp eq (A & (B|D)), (B|D))
103*f4a2713aSLionel Sambucdefine i32 @main4(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
104*f4a2713aSLionel Sambucentry:
105*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
106*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and, 7                   ; <i1> [#uses=1]
107*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 48                       ; <i32> [#uses=1]
108*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, 48                ; <i1> [#uses=1]
109*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
110*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
111*f4a2713aSLionel Sambuc  ret i32 %storemerge
112*f4a2713aSLionel Sambuc}
113*f4a2713aSLionel Sambuc
114*f4a2713aSLionel Sambucdefine i32 @main4b(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
115*f4a2713aSLionel Sambucentry:
116*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
117*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and, 7                   ; <i1> [#uses=1]
118*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 16                       ; <i32> [#uses=1]
119*f4a2713aSLionel Sambuc  %tobool3 = icmp ne i32 %and2, 0                 ; <i1> [#uses=1]
120*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
121*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
122*f4a2713aSLionel Sambuc  ret i32 %storemerge
123*f4a2713aSLionel Sambuc}
124*f4a2713aSLionel Sambuc
125*f4a2713aSLionel Sambucdefine i32 @main4e_like(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
126*f4a2713aSLionel Sambuc           nounwind readnone ssp {
127*f4a2713aSLionel Sambucentry:
128*f4a2713aSLionel Sambuc  %and = and i32 %argc, %argc2                    ; <i32> [#uses=1]
129*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and, %argc2              ; <i1> [#uses=1]
130*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, %argc3                   ; <i32> [#uses=1]
131*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, %argc3            ; <i1> [#uses=1]
132*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
133*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
134*f4a2713aSLionel Sambuc  ret i32 %storemerge
135*f4a2713aSLionel Sambuc}
136*f4a2713aSLionel Sambuc
137*f4a2713aSLionel Sambuc; (icmp ne (A & B), B) | (icmp ne (A & D), D) -> (icmp ne (A & (B|D)), (B|D))
138*f4a2713aSLionel Sambucdefine i32 @main4c(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
139*f4a2713aSLionel Sambucentry:
140*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
141*f4a2713aSLionel Sambuc  %tobool = icmp ne i32 %and, 7                   ; <i1> [#uses=1]
142*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 48                       ; <i32> [#uses=1]
143*f4a2713aSLionel Sambuc  %tobool3 = icmp ne i32 %and2, 48                ; <i1> [#uses=1]
144*f4a2713aSLionel Sambuc  %or.cond = or i1 %tobool, %tobool3              ; <i1> [#uses=1]
145*f4a2713aSLionel Sambuc  %storemerge = select i1 %or.cond, i32 0, i32 1  ; <i32> [#uses=1]
146*f4a2713aSLionel Sambuc  ret i32 %storemerge
147*f4a2713aSLionel Sambuc}
148*f4a2713aSLionel Sambuc
149*f4a2713aSLionel Sambucdefine i32 @main4d(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
150*f4a2713aSLionel Sambucentry:
151*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
152*f4a2713aSLionel Sambuc  %tobool = icmp ne i32 %and, 7                   ; <i1> [#uses=1]
153*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 16                       ; <i32> [#uses=1]
154*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, 0                 ; <i1> [#uses=1]
155*f4a2713aSLionel Sambuc  %or.cond = or i1 %tobool, %tobool3              ; <i1> [#uses=1]
156*f4a2713aSLionel Sambuc  %storemerge = select i1 %or.cond, i32 0, i32 1  ; <i32> [#uses=1]
157*f4a2713aSLionel Sambuc  ret i32 %storemerge
158*f4a2713aSLionel Sambuc}
159*f4a2713aSLionel Sambuc
160*f4a2713aSLionel Sambucdefine i32 @main4f_like(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
161*f4a2713aSLionel Sambuc           nounwind readnone ssp {
162*f4a2713aSLionel Sambucentry:
163*f4a2713aSLionel Sambuc  %and = and i32 %argc, %argc2                    ; <i32> [#uses=1]
164*f4a2713aSLionel Sambuc  %tobool = icmp ne i32 %and, %argc2              ; <i1> [#uses=1]
165*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, %argc3                   ; <i32> [#uses=1]
166*f4a2713aSLionel Sambuc  %tobool3 = icmp ne i32 %and2, %argc3            ; <i1> [#uses=1]
167*f4a2713aSLionel Sambuc  %or.cond = or i1 %tobool, %tobool3              ; <i1> [#uses=1]
168*f4a2713aSLionel Sambuc  %storemerge = select i1 %or.cond, i32 0, i32 1  ; <i32> [#uses=1]
169*f4a2713aSLionel Sambuc  ret i32 %storemerge
170*f4a2713aSLionel Sambuc}
171*f4a2713aSLionel Sambuc
172*f4a2713aSLionel Sambuc; (icmp eq (A & B), A) & (icmp eq (A & D), A) -> (icmp eq (A & (B&D)), A)
173*f4a2713aSLionel Sambucdefine i32 @main5_like(i32 %argc, i32 %argc2, i8** nocapture %argv)
174*f4a2713aSLionel Sambuc           nounwind readnone ssp {
175*f4a2713aSLionel Sambucentry:
176*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
177*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and, 7                   ; <i1> [#uses=1]
178*f4a2713aSLionel Sambuc  %and2 = and i32 %argc2, 7                       ; <i32> [#uses=1]
179*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, 7                 ; <i1> [#uses=1]
180*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
181*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
182*f4a2713aSLionel Sambuc  ret i32 %storemerge
183*f4a2713aSLionel Sambuc}
184*f4a2713aSLionel Sambuc
185*f4a2713aSLionel Sambucdefine i32 @main5e_like(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
186*f4a2713aSLionel Sambuc           nounwind readnone ssp {
187*f4a2713aSLionel Sambucentry:
188*f4a2713aSLionel Sambuc  %and = and i32 %argc, %argc2                    ; <i32> [#uses=1]
189*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and, %argc               ; <i1> [#uses=1]
190*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, %argc3                   ; <i32> [#uses=1]
191*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, %argc             ; <i1> [#uses=1]
192*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
193*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
194*f4a2713aSLionel Sambuc  ret i32 %storemerge
195*f4a2713aSLionel Sambuc}
196*f4a2713aSLionel Sambuc
197*f4a2713aSLionel Sambuc; (icmp ne (A & B), A) | (icmp ne (A & D), A) -> (icmp ne (A & (B&D)), A)
198*f4a2713aSLionel Sambucdefine i32 @main5c_like(i32 %argc, i32 %argc2, i8** nocapture %argv)
199*f4a2713aSLionel Sambuc           nounwind readnone ssp {
200*f4a2713aSLionel Sambucentry:
201*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
202*f4a2713aSLionel Sambuc  %tobool = icmp ne i32 %and, 7                   ; <i1> [#uses=1]
203*f4a2713aSLionel Sambuc  %and2 = and i32 %argc2, 7                       ; <i32> [#uses=1]
204*f4a2713aSLionel Sambuc  %tobool3 = icmp ne i32 %and2, 7                 ; <i1> [#uses=1]
205*f4a2713aSLionel Sambuc  %or.cond = or i1 %tobool, %tobool3              ; <i1> [#uses=1]
206*f4a2713aSLionel Sambuc  %storemerge = select i1 %or.cond, i32 0, i32 1  ; <i32> [#uses=1]
207*f4a2713aSLionel Sambuc  ret i32 %storemerge
208*f4a2713aSLionel Sambuc}
209*f4a2713aSLionel Sambuc
210*f4a2713aSLionel Sambucdefine i32 @main5f_like(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
211*f4a2713aSLionel Sambuc           nounwind readnone ssp {
212*f4a2713aSLionel Sambucentry:
213*f4a2713aSLionel Sambuc  %and = and i32 %argc, %argc2                    ; <i32> [#uses=1]
214*f4a2713aSLionel Sambuc  %tobool = icmp ne i32 %and, %argc               ; <i1> [#uses=1]
215*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, %argc3                   ; <i32> [#uses=1]
216*f4a2713aSLionel Sambuc  %tobool3 = icmp ne i32 %and2, %argc             ; <i1> [#uses=1]
217*f4a2713aSLionel Sambuc  %or.cond = or i1 %tobool, %tobool3              ; <i1> [#uses=1]
218*f4a2713aSLionel Sambuc  %storemerge = select i1 %or.cond, i32 0, i32 1  ; <i32> [#uses=1]
219*f4a2713aSLionel Sambuc  ret i32 %storemerge
220*f4a2713aSLionel Sambuc}
221*f4a2713aSLionel Sambuc
222*f4a2713aSLionel Sambuc; (icmp eq (A & B), C) & (icmp eq (A & D), E) -> (icmp eq (A & (B|D)), (C|E))
223*f4a2713aSLionel Sambuc; if B, C, D, E are constant, and it's possible
224*f4a2713aSLionel Sambucdefine i32 @main6(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
225*f4a2713aSLionel Sambucentry:
226*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
227*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and, 3                   ; <i1> [#uses=1]
228*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 48                       ; <i32> [#uses=1]
229*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, 16                ; <i1> [#uses=1]
230*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
231*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
232*f4a2713aSLionel Sambuc  ret i32 %storemerge
233*f4a2713aSLionel Sambuc}
234*f4a2713aSLionel Sambuc
235*f4a2713aSLionel Sambucdefine i32 @main6b(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
236*f4a2713aSLionel Sambucentry:
237*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
238*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and, 3                   ; <i1> [#uses=1]
239*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 16                       ; <i32> [#uses=1]
240*f4a2713aSLionel Sambuc  %tobool3 = icmp ne i32 %and2, 0                 ; <i1> [#uses=1]
241*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
242*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
243*f4a2713aSLionel Sambuc  ret i32 %storemerge
244*f4a2713aSLionel Sambuc}
245*f4a2713aSLionel Sambuc
246*f4a2713aSLionel Sambuc; (icmp ne (A & B), C) | (icmp ne (A & D), E) -> (icmp ne (A & (B|D)), (C|E))
247*f4a2713aSLionel Sambuc; if B, C, D, E are constant, and it's possible
248*f4a2713aSLionel Sambucdefine i32 @main6c(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
249*f4a2713aSLionel Sambucentry:
250*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
251*f4a2713aSLionel Sambuc  %tobool = icmp ne i32 %and, 3                   ; <i1> [#uses=1]
252*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 48                       ; <i32> [#uses=1]
253*f4a2713aSLionel Sambuc  %tobool3 = icmp ne i32 %and2, 16                ; <i1> [#uses=1]
254*f4a2713aSLionel Sambuc  %or.cond = or i1 %tobool, %tobool3              ; <i1> [#uses=1]
255*f4a2713aSLionel Sambuc  %storemerge = select i1 %or.cond, i32 0, i32 1  ; <i32> [#uses=1]
256*f4a2713aSLionel Sambuc  ret i32 %storemerge
257*f4a2713aSLionel Sambuc}
258*f4a2713aSLionel Sambuc
259*f4a2713aSLionel Sambucdefine i32 @main6d(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
260*f4a2713aSLionel Sambucentry:
261*f4a2713aSLionel Sambuc  %and = and i32 %argc, 7                         ; <i32> [#uses=1]
262*f4a2713aSLionel Sambuc  %tobool = icmp ne i32 %and, 3                   ; <i1> [#uses=1]
263*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, 16                       ; <i32> [#uses=1]
264*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, 0                 ; <i1> [#uses=1]
265*f4a2713aSLionel Sambuc  %or.cond = or i1 %tobool, %tobool3              ; <i1> [#uses=1]
266*f4a2713aSLionel Sambuc  %storemerge = select i1 %or.cond, i32 0, i32 1  ; <i32> [#uses=1]
267*f4a2713aSLionel Sambuc  ret i32 %storemerge
268*f4a2713aSLionel Sambuc}
269*f4a2713aSLionel Sambuc
270*f4a2713aSLionel Sambuc; test parameter permutations
271*f4a2713aSLionel Sambuc; (B & A) == B & (D & A) == D
272*f4a2713aSLionel Sambucdefine i32 @main7a(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
273*f4a2713aSLionel Sambuc           nounwind readnone ssp {
274*f4a2713aSLionel Sambucentry:
275*f4a2713aSLionel Sambuc  %and1 = and i32 %argc2, %argc                   ; <i32> [#uses=1]
276*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and1, %argc2              ; <i1> [#uses=1]
277*f4a2713aSLionel Sambuc  %and2 = and i32 %argc3, %argc                   ; <i32> [#uses=1]
278*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, %argc3            ; <i1> [#uses=1]
279*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
280*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
281*f4a2713aSLionel Sambuc  ret i32 %storemerge
282*f4a2713aSLionel Sambuc}
283*f4a2713aSLionel Sambuc
284*f4a2713aSLionel Sambuc; B == (A & B) & D == (A & D)
285*f4a2713aSLionel Sambucdefine i32 @main7b(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
286*f4a2713aSLionel Sambuc           nounwind readnone ssp {
287*f4a2713aSLionel Sambucentry:
288*f4a2713aSLionel Sambuc  %and1 = and i32 %argc, %argc2                   ; <i32> [#uses=1]
289*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %argc2, %and1             ; <i1> [#uses=1]
290*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, %argc3                   ; <i32> [#uses=1]
291*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %argc3, %and2            ; <i1> [#uses=1]
292*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
293*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
294*f4a2713aSLionel Sambuc  ret i32 %storemerge
295*f4a2713aSLionel Sambuc}
296*f4a2713aSLionel Sambuc
297*f4a2713aSLionel Sambuc; B == (B & A) & D == (D & A)
298*f4a2713aSLionel Sambucdefine i32 @main7c(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
299*f4a2713aSLionel Sambuc           nounwind readnone ssp {
300*f4a2713aSLionel Sambucentry:
301*f4a2713aSLionel Sambuc  %and1 = and i32 %argc2, %argc                   ; <i32> [#uses=1]
302*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %argc2, %and1             ; <i1> [#uses=1]
303*f4a2713aSLionel Sambuc  %and2 = and i32 %argc3, %argc                   ; <i32> [#uses=1]
304*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %argc3, %and2            ; <i1> [#uses=1]
305*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
306*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
307*f4a2713aSLionel Sambuc  ret i32 %storemerge
308*f4a2713aSLionel Sambuc}
309*f4a2713aSLionel Sambuc
310*f4a2713aSLionel Sambuc; (A & (B & C)) == (B & C) & (A & (D & E)) == (D & E)
311*f4a2713aSLionel Sambucdefine i32 @main7d(i32 %argc, i32 %argc2, i32 %argc3,
312*f4a2713aSLionel Sambuc                   i32 %argc4, i32 %argc5, i8** nocapture %argv)
313*f4a2713aSLionel Sambuc           nounwind readnone ssp {
314*f4a2713aSLionel Sambucentry:
315*f4a2713aSLionel Sambuc  %bc = and i32 %argc2, %argc4                    ; <i32> [#uses=1]
316*f4a2713aSLionel Sambuc  %de = and i32 %argc3, %argc5                    ; <i32> [#uses=1]
317*f4a2713aSLionel Sambuc  %and1 = and i32 %argc, %bc                      ; <i32> [#uses=1]
318*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and1, %bc                ; <i1> [#uses=1]
319*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, %de                      ; <i32> [#uses=1]
320*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, %de               ; <i1> [#uses=1]
321*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
322*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
323*f4a2713aSLionel Sambuc  ret i32 %storemerge
324*f4a2713aSLionel Sambuc}
325*f4a2713aSLionel Sambuc
326*f4a2713aSLionel Sambuc; ((B & C) & A) == (B & C) & ((D & E) & A) == (D & E)
327*f4a2713aSLionel Sambucdefine i32 @main7e(i32 %argc, i32 %argc2, i32 %argc3,
328*f4a2713aSLionel Sambuc                   i32 %argc4, i32 %argc5, i8** nocapture %argv)
329*f4a2713aSLionel Sambuc           nounwind readnone ssp {
330*f4a2713aSLionel Sambucentry:
331*f4a2713aSLionel Sambuc  %bc = and i32 %argc2, %argc4                    ; <i32> [#uses=1]
332*f4a2713aSLionel Sambuc  %de = and i32 %argc3, %argc5                    ; <i32> [#uses=1]
333*f4a2713aSLionel Sambuc  %and1 = and i32 %bc, %argc                      ; <i32> [#uses=1]
334*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %and1, %bc                ; <i1> [#uses=1]
335*f4a2713aSLionel Sambuc  %and2 = and i32 %de, %argc                      ; <i32> [#uses=1]
336*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %and2, %de               ; <i1> [#uses=1]
337*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
338*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
339*f4a2713aSLionel Sambuc  ret i32 %storemerge
340*f4a2713aSLionel Sambuc}
341*f4a2713aSLionel Sambuc
342*f4a2713aSLionel Sambuc; (B & C) == (A & (B & C)) & (D & E) == (A & (D & E))
343*f4a2713aSLionel Sambucdefine i32 @main7f(i32 %argc, i32 %argc2, i32 %argc3,
344*f4a2713aSLionel Sambuc                   i32 %argc4, i32 %argc5, i8** nocapture %argv)
345*f4a2713aSLionel Sambuc           nounwind readnone ssp {
346*f4a2713aSLionel Sambucentry:
347*f4a2713aSLionel Sambuc  %bc = and i32 %argc2, %argc4                    ; <i32> [#uses=1]
348*f4a2713aSLionel Sambuc  %de = and i32 %argc3, %argc5                    ; <i32> [#uses=1]
349*f4a2713aSLionel Sambuc  %and1 = and i32 %argc, %bc                      ; <i32> [#uses=1]
350*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %bc, %and1                ; <i1> [#uses=1]
351*f4a2713aSLionel Sambuc  %and2 = and i32 %argc, %de                      ; <i32> [#uses=1]
352*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %de, %and2               ; <i1> [#uses=1]
353*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
354*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
355*f4a2713aSLionel Sambuc  ret i32 %storemerge
356*f4a2713aSLionel Sambuc}
357*f4a2713aSLionel Sambuc
358*f4a2713aSLionel Sambuc; (B & C) == ((B & C) & A) & (D & E) == ((D & E) & A)
359*f4a2713aSLionel Sambucdefine i32 @main7g(i32 %argc, i32 %argc2, i32 %argc3,
360*f4a2713aSLionel Sambuc                   i32 %argc4, i32 %argc5, i8** nocapture %argv)
361*f4a2713aSLionel Sambuc           nounwind readnone ssp {
362*f4a2713aSLionel Sambucentry:
363*f4a2713aSLionel Sambuc  %bc = and i32 %argc2, %argc4                    ; <i32> [#uses=1]
364*f4a2713aSLionel Sambuc  %de = and i32 %argc3, %argc5                    ; <i32> [#uses=1]
365*f4a2713aSLionel Sambuc  %and1 = and i32 %bc, %argc                      ; <i32> [#uses=1]
366*f4a2713aSLionel Sambuc  %tobool = icmp eq i32 %bc, %and1                ; <i1> [#uses=1]
367*f4a2713aSLionel Sambuc  %and2 = and i32 %de, %argc                      ; <i32> [#uses=1]
368*f4a2713aSLionel Sambuc  %tobool3 = icmp eq i32 %de, %and2               ; <i1> [#uses=1]
369*f4a2713aSLionel Sambuc  %and.cond = and i1 %tobool, %tobool3            ; <i1> [#uses=1]
370*f4a2713aSLionel Sambuc  %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
371*f4a2713aSLionel Sambuc  ret i32 %storemerge
372*f4a2713aSLionel Sambuc}
373