1 ; This test makes sure that these instructions are properly eliminated.
4 ; RUN: opt < %s -instcombine -S | not grep and
6 define i32 @test1(i32 %A) {
8 %B = and i32 %A, 0 ; <i32> [#uses=1]
12 define i32 @test2(i32 %A) {
14 %B = and i32 %A, -1 ; <i32> [#uses=1]
18 define i1 @test3(i1 %A) {
20 %B = and i1 %A, false ; <i1> [#uses=1]
24 define i1 @test4(i1 %A) {
26 %B = and i1 %A, true ; <i1> [#uses=1]
30 define i32 @test5(i32 %A) {
31 %B = and i32 %A, %A ; <i32> [#uses=1]
35 define i1 @test6(i1 %A) {
36 %B = and i1 %A, %A ; <i1> [#uses=1]
41 define i32 @test7(i32 %A) {
42 %NotA = xor i32 %A, -1 ; <i32> [#uses=1]
43 %B = and i32 %A, %NotA ; <i32> [#uses=1]
48 define i8 @test8(i8 %A) {
49 %B = and i8 %A, 3 ; <i8> [#uses=1]
50 %C = and i8 %B, 4 ; <i8> [#uses=1]
54 define i1 @test9(i32 %A) {
55 ; Test of sign bit, convert to setle %A, 0
56 %B = and i32 %A, -2147483648 ; <i32> [#uses=1]
57 %C = icmp ne i32 %B, 0 ; <i1> [#uses=1]
61 define i1 @test9a(i32 %A) {
62 ; Test of sign bit, convert to setle %A, 0
63 %B = and i32 %A, -2147483648 ; <i32> [#uses=1]
64 %C = icmp ne i32 %B, 0 ; <i1> [#uses=1]
68 define i32 @test10(i32 %A) {
69 %B = and i32 %A, 12 ; <i32> [#uses=1]
70 %C = xor i32 %B, 15 ; <i32> [#uses=1]
71 ; (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
72 %D = and i32 %C, 1 ; <i32> [#uses=1]
76 define i32 @test11(i32 %A, i32* %P) {
77 %B = or i32 %A, 3 ; <i32> [#uses=1]
78 %C = xor i32 %B, 12 ; <i32> [#uses=2]
81 ; %C = and uint %B, 3 --> 3
82 %D = and i32 %C, 3 ; <i32> [#uses=1]
86 define i1 @test12(i32 %A, i32 %B) {
87 %C1 = icmp ult i32 %A, %B ; <i1> [#uses=1]
88 %C2 = icmp ule i32 %A, %B ; <i1> [#uses=1]
89 ; (A < B) & (A <= B) === (A < B)
90 %D = and i1 %C1, %C2 ; <i1> [#uses=1]
94 define i1 @test13(i32 %A, i32 %B) {
95 %C1 = icmp ult i32 %A, %B ; <i1> [#uses=1]
96 %C2 = icmp ugt i32 %A, %B ; <i1> [#uses=1]
97 ; (A < B) & (A > B) === false
98 %D = and i1 %C1, %C2 ; <i1> [#uses=1]
102 define i1 @test14(i8 %A) {
103 %B = and i8 %A, -128 ; <i8> [#uses=1]
104 %C = icmp ne i8 %B, 0 ; <i1> [#uses=1]
108 define i8 @test15(i8 %A) {
109 %B = lshr i8 %A, 7 ; <i8> [#uses=1]
111 %C = and i8 %B, 2 ; <i8> [#uses=1]
115 define i8 @test16(i8 %A) {
116 %B = shl i8 %A, 2 ; <i8> [#uses=1]
117 %C = and i8 %B, 3 ; <i8> [#uses=1]
121 ;; ~(~X & Y) --> (X | ~Y)
122 define i8 @test17(i8 %X, i8 %Y) {
123 %B = xor i8 %X, -1 ; <i8> [#uses=1]
124 %C = and i8 %B, %Y ; <i8> [#uses=1]
125 %D = xor i8 %C, -1 ; <i8> [#uses=1]
129 define i1 @test18(i32 %A) {
130 %B = and i32 %A, -128 ; <i32> [#uses=1]
132 %C = icmp ne i32 %B, 0 ; <i1> [#uses=1]
136 define i1 @test18a(i8 %A) {
137 %B = and i8 %A, -2 ; <i8> [#uses=1]
138 %C = icmp eq i8 %B, 0 ; <i1> [#uses=1]
142 define i32 @test19(i32 %A) {
143 %B = shl i32 %A, 3 ; <i32> [#uses=1]
144 ;; Clearing a zero bit
145 %C = and i32 %B, -2 ; <i32> [#uses=1]
149 define i8 @test20(i8 %A) {
150 %C = lshr i8 %A, 7 ; <i8> [#uses=1]
152 %D = and i8 %C, 1 ; <i8> [#uses=1]
156 define i1 @test22(i32 %A) {
157 %B = icmp eq i32 %A, 1 ; <i1> [#uses=1]
158 %C = icmp sge i32 %A, 3 ; <i1> [#uses=1]
160 %D = and i1 %B, %C ; <i1> [#uses=1]
164 define i1 @test23(i32 %A) {
165 %B = icmp sgt i32 %A, 1 ; <i1> [#uses=1]
166 %C = icmp sle i32 %A, 2 ; <i1> [#uses=1]
168 %D = and i1 %B, %C ; <i1> [#uses=1]
172 define i1 @test24(i32 %A) {
173 %B = icmp sgt i32 %A, 1 ; <i1> [#uses=1]
174 %C = icmp ne i32 %A, 2 ; <i1> [#uses=1]
176 %D = and i1 %B, %C ; <i1> [#uses=1]
180 define i1 @test25(i32 %A) {
181 %B = icmp sge i32 %A, 50 ; <i1> [#uses=1]
182 %C = icmp slt i32 %A, 100 ; <i1> [#uses=1]
184 %D = and i1 %B, %C ; <i1> [#uses=1]
188 define i1 @test26(i32 %A) {
189 %B = icmp ne i32 %A, 50 ; <i1> [#uses=1]
190 %C = icmp ne i32 %A, 51 ; <i1> [#uses=1]
192 %D = and i1 %B, %C ; <i1> [#uses=1]
196 define i8 @test27(i8 %A) {
197 %B = and i8 %A, 4 ; <i8> [#uses=1]
198 %C = sub i8 %B, 16 ; <i8> [#uses=1]
200 %D = and i8 %C, -16 ; <i8> [#uses=1]
201 %E = add i8 %D, 16 ; <i8> [#uses=1]
205 ;; This is juse a zero extending shr.
206 define i32 @test28(i32 %X) {
208 %Y = ashr i32 %X, 24 ; <i32> [#uses=1]
209 ;; Mask out sign bits
210 %Z = and i32 %Y, 255 ; <i32> [#uses=1]
214 define i32 @test29(i8 %X) {
215 %Y = zext i8 %X to i32 ; <i32> [#uses=1]
216 ;; Zero extend makes this unneeded.
217 %Z = and i32 %Y, 255 ; <i32> [#uses=1]
221 define i32 @test30(i1 %X) {
222 %Y = zext i1 %X to i32 ; <i32> [#uses=1]
223 %Z = and i32 %Y, 1 ; <i32> [#uses=1]
227 define i32 @test31(i1 %X) {
228 %Y = zext i1 %X to i32 ; <i32> [#uses=1]
229 %Z = shl i32 %Y, 4 ; <i32> [#uses=1]
230 %A = and i32 %Z, 16 ; <i32> [#uses=1]
234 define i32 @test32(i32 %In) {
235 %Y = and i32 %In, 16 ; <i32> [#uses=1]
236 %Z = lshr i32 %Y, 2 ; <i32> [#uses=1]
237 %A = and i32 %Z, 1 ; <i32> [#uses=1]
241 ;; Code corresponding to one-bit bitfield ^1.
242 define i32 @test33(i32 %b) {
243 %tmp.4.mask = and i32 %b, 1 ; <i32> [#uses=1]
244 %tmp.10 = xor i32 %tmp.4.mask, 1 ; <i32> [#uses=1]
245 %tmp.12 = and i32 %b, -2 ; <i32> [#uses=1]
246 %tmp.13 = or i32 %tmp.12, %tmp.10 ; <i32> [#uses=1]
250 define i32 @test34(i32 %A, i32 %B) {
251 %tmp.2 = or i32 %B, %A ; <i32> [#uses=1]
252 %tmp.4 = and i32 %tmp.2, %B ; <i32> [#uses=1]