1 ; This test makes sure that these instructions are properly eliminated.
4 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep and
10 %B = and int %A, 0 ; zero result
15 %B = and int %A, -1 ; noop
19 bool %test3(bool %A) {
20 %B = and bool %A, false ; always = false
24 bool %test4(bool %A) {
25 %B = and bool %A, true ; noop
34 bool %test6(bool %A) {
39 int %test7(int %A) { ; A & ~A == 0
40 %NotA = xor int %A, -1
41 %B = and int %A, %NotA
45 ubyte %test8(ubyte %A) { ; AND associates
52 %B = and int %A, -2147483648 ; Test of sign bit, convert to setle %A, 0
57 bool %test9(uint %A) {
58 %B = and uint %A, 2147483648 ; Test of sign bit, convert to setle %A, 0
63 uint %test10(uint %A) {
66 %D = and uint %C, 1 ; (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
70 uint %test11(uint %A, uint* %P) {
73 store uint %C, uint* %P ; additional use of C
74 %D = and uint %C, 3 ; %C = and uint %B, 3 --> 3
78 bool %test12(uint %A, uint %B) {
79 %C1 = setlt uint %A, %B
80 %C2 = setle uint %A, %B
81 %D = and bool %C1, %C2 ; (A < B) & (A <= B) === (A < B)
85 bool %test13(uint %A, uint %B) {
86 %C1 = setlt uint %A, %B
87 %C2 = setgt uint %A, %B
88 %D = and bool %C1, %C2 ; (A < B) & (A > B) === false
92 bool %test14(ubyte %A) {
93 %B = and ubyte %A, 128
94 %C = setne ubyte %B, 0
98 ubyte %test15(ubyte %A) {
99 %B = shr ubyte %A, ubyte 7
100 %C = and ubyte %B, 2 ; Always equals zero
104 ubyte %test16(ubyte %A) {
105 %B = shl ubyte %A, ubyte 2
110 sbyte %test17(sbyte %X, sbyte %Y) { ;; ~(~X & Y) --> (X | ~Y)
111 %B = xor sbyte %X, -1
112 %C = and sbyte %B, %Y
113 %D = xor sbyte %C, -1
117 bool %test18(int %A) {
118 %B = and int %A, -128
119 %C = setne int %B, 0 ;; C >= 128
123 bool %test18a(ubyte %A) {
124 %B = and ubyte %A, 254
125 %C = seteq ubyte %B, 0
129 int %test19(int %A) {
130 %B = shl int %A, ubyte 3
131 %C = and int %B, -2 ;; Clearing a zero bit
135 ubyte %test20(ubyte %A) {
136 %C = shr ubyte %A, ubyte 7
137 %D = and ubyte %C, 1 ;; Unneeded
141 bool %test22(int %A) {
144 %D = and bool %B, %C ;; False
148 bool %test23(int %A) {
151 %D = and bool %B, %C ;; A == 2
155 bool %test24(int %A) {
158 %D = and bool %B, %C ;; A > 2
162 bool %test25(int %A) {
163 %B = setge int %A, 50
164 %C = setlt int %A, 100
165 %D = and bool %B, %C ;; (A-50) <u 50
169 bool %test26(int %A) {
170 %B = setne int %A, 50
171 %C = setne int %A, 51
172 %D = and bool %B, %C ;; (A-50) > 1
176 ubyte %test27(ubyte %A) {
178 %C = sub ubyte %B, 16
179 %D = and ubyte %C, 240 ;; 0xF0
180 %E = add ubyte %D, 16
184 int %test28(int %X) { ;; This is juse a zero extending shr.
185 %Y = shr int %X, ubyte 24 ;; Sign extend
186 %Z = and int %Y, 255 ;; Mask out sign bits
190 int %test29(ubyte %X) {
191 %Y = cast ubyte %X to int
192 %Z = and int %Y, 255 ;; Zero extend makes this unneeded.
196 int %test30(bool %X) {
197 %Y = cast bool %X to int
202 uint %test31(bool %X) {
203 %Y = cast bool %X to uint
204 %Z = shl uint %Y, ubyte 4
209 uint %test32(uint %In) {
210 %Y = and uint %In, 16
211 %Z = shr uint %Y, ubyte 2
216 uint %test33(uint %b) { ;; Code corresponding to one-bit bitfield ^1.
217 %tmp.4.mask = and uint %b, 1
218 %tmp.10 = xor uint %tmp.4.mask, 1
219 %tmp.12 = and uint %b, 4294967294
220 %tmp.13 = or uint %tmp.12, %tmp.10
224 int %test34(int %A, int %B) {
225 %tmp.2 = or int %B, %A
226 %tmp.4 = and int %tmp.2, %B