1 ; This test makes sure that these instructions are properly eliminated.
4 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep and
9 %B = and int %A, 0 ; zero result
14 %B = and int %A, -1 ; noop
18 bool %test3(bool %A) {
19 %B = and bool %A, false ; always = false
23 bool %test4(bool %A) {
24 %B = and bool %A, true ; noop
33 bool %test6(bool %A) {
38 int %test7(int %A) { ; A & ~A == 0
39 %NotA = xor int %A, -1
40 %B = and int %A, %NotA
44 ubyte %test8(ubyte %A) { ; AND associates
51 %B = and int %A, -2147483648 ; Test of sign bit, convert to setle %A, 0
56 bool %test9(uint %A) {
57 %B = and uint %A, 2147483648 ; Test of sign bit, convert to setle %A, 0
62 uint %test10(uint %A) {
65 %D = and uint %C, 1 ; (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
69 uint %test11(uint %A, uint* %P) {
72 store uint %C, uint* %P ; additional use of C
73 %D = and uint %C, 3 ; %C = and uint %B, 3 --> 3
77 bool %test12(uint %A, uint %B) {
78 %C1 = setlt uint %A, %B
79 %C2 = setle uint %A, %B
80 %D = and bool %C1, %C2 ; (A < B) & (A <= B) === (A < B)
84 bool %test13(uint %A, uint %B) {
85 %C1 = setlt uint %A, %B
86 %C2 = setgt uint %A, %B
87 %D = and bool %C1, %C2 ; (A < B) & (A > B) === false
91 bool %test14(ubyte %A) {
92 %B = and ubyte %A, 128
93 %C = setne ubyte %B, 0
97 ubyte %test15(ubyte %A) {
98 %B = shr ubyte %A, ubyte 7
99 %C = and ubyte %B, 2 ; Always equals zero
103 ubyte %test16(ubyte %A) {
104 %B = shl ubyte %A, ubyte 2
109 sbyte %test17(sbyte %X, sbyte %Y) { ;; ~(~X & Y) --> (X | ~Y)
110 %B = xor sbyte %X, -1
111 %C = and sbyte %B, %Y
112 %D = xor sbyte %C, -1
116 bool %test18(int %A) {
117 %B = and int %A, -128
118 %C = setne int %B, 0 ;; C >= 128
122 bool %test18a(ubyte %A) {
123 %B = and ubyte %A, 254
124 %C = seteq ubyte %B, 0
128 int %test19(int %A) {
129 %B = shl int %A, ubyte 3
130 %C = and int %B, -2 ;; Clearing a zero bit
134 ubyte %test20(ubyte %A) {
135 %C = shr ubyte %A, ubyte 7
136 %D = and ubyte %C, 1 ;; Unneeded
140 bool %test22(int %A) {
143 %D = and bool %B, %C ;; False
147 bool %test23(int %A) {
150 %D = and bool %B, %C ;; A == 2
154 bool %test24(int %A) {
157 %D = and bool %B, %C ;; A > 2
161 bool %test25(int %A) {
162 %B = setge int %A, 50
163 %C = setlt int %A, 100
164 %D = and bool %B, %C ;; (A-50) <u 50
168 bool %test26(int %A) {
169 %B = setne int %A, 50
170 %C = setne int %A, 51
171 %D = and bool %B, %C ;; (A-50) > 1
175 ubyte %test27(ubyte %A) {
177 %C = sub ubyte %B, 16
178 %D = and ubyte %C, 240 ;; 0xF0
179 %E = add ubyte %D, 16