dc30c564d028d23e2c6165fd6d5f597d48c96d56
[oota-llvm.git] / test / Transforms / InstCombine / and.ll
1 ; This test makes sure that these instructions are properly eliminated.
2 ;
3
4 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep and
5
6 implementation
7
8 int %test1(int %A) {
9         %B = and int %A, 0     ; zero result
10         ret int %B
11 }
12
13 int %test2(int %A) {
14         %B = and int %A, -1    ; noop
15         ret int %B
16 }
17
18 bool %test3(bool %A) {
19         %B = and bool %A, false  ; always = false
20         ret bool %B
21 }
22
23 bool %test4(bool %A) {
24         %B = and bool %A, true  ; noop
25         ret bool %B
26 }
27
28 int %test5(int %A) {
29         %B = and int %A, %A
30         ret int %B
31 }
32
33 bool %test6(bool %A) {
34         %B = and bool %A, %A
35         ret bool %B
36 }
37
38 int %test7(int %A) {         ; A & ~A == 0
39         %NotA = xor int %A, -1
40         %B = and int %A, %NotA
41         ret int %B
42 }
43
44 ubyte %test8(ubyte %A) {    ; AND associates
45         %B = and ubyte %A, 3
46         %C = and ubyte %B, 4
47         ret ubyte %C
48 }
49
50 bool %test9(int %A) {
51         %B = and int %A, -2147483648   ; Test of sign bit, convert to setle %A, 0 
52         %C = setne int %B, 0
53         ret bool %C
54 }
55
56 bool %test9(uint %A) {
57         %B = and uint %A, 2147483648   ; Test of sign bit, convert to setle %A, 0 
58         %C = setne uint %B, 0
59         ret bool %C
60 }
61
62 uint %test10(uint %A) {
63         %B = and uint %A, 12
64         %C = xor uint %B, 15
65         %D = and uint %C, 1   ; (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
66         ret uint %D
67 }
68
69 uint %test11(uint %A, uint* %P) {
70         %B = or uint %A, 3
71         %C = xor uint %B, 12
72         store uint %C, uint* %P    ; additional use of C
73         %D = and uint %C, 3        ; %C = and uint %B, 3 --> 3
74         ret uint %D
75 }
76
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)
81         ret bool %D
82 }
83
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
88         ret bool %D
89 }
90
91 bool %test14(ubyte %A) {
92         %B = and ubyte %A, 128
93         %C = setne ubyte %B, 0
94         ret bool %C
95 }
96
97 ubyte %test15(ubyte %A) {
98         %B = shr ubyte %A, ubyte 7
99         %C = and ubyte %B, 2        ; Always equals zero
100         ret ubyte %C
101 }
102
103 ubyte %test16(ubyte %A) {
104         %B = shl ubyte %A, ubyte 2
105         %C = and ubyte %B, 3
106         ret ubyte %C
107 }
108
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
113         ret sbyte %D
114 }
115
116 bool %test18(int %A) {
117         %B = and int %A, -128
118         %C = setne int %B, 0   ;; C >= 128
119         ret bool %C
120 }
121
122 bool %test18a(ubyte %A) {
123         %B = and ubyte %A, 254
124         %C = seteq ubyte %B, 0
125         ret bool %C
126 }
127
128 int %test19(int %A) {
129         %B = shl int %A, ubyte 3
130         %C = and int %B, -2    ;; Clearing a zero bit
131         ret int %C
132 }
133
134 ubyte %test20(ubyte %A) {
135         %C = shr ubyte %A, ubyte 7 
136         %D = and ubyte %C, 1            ;; Unneeded
137         ret ubyte %D
138 }
139
140 bool %test22(int %A) {
141         %B = seteq int %A, 1
142         %C = setge int %A, 3
143         %D = and bool %B, %C   ;; False
144         ret bool %D
145 }
146
147 bool %test23(int %A) {
148         %B = setgt int %A, 1
149         %C = setle int %A, 2
150         %D = and bool %B, %C   ;; A == 2
151         ret bool %D
152 }
153
154 bool %test24(int %A) {
155         %B = setgt int %A, 1
156         %C = setne int %A, 2
157         %D = and bool %B, %C   ;; A > 2
158         ret bool %D
159 }
160
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
165         ret bool %D
166 }
167
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
172         ret bool %D
173 }
174
175 ubyte %test27(ubyte %A) {
176         %B = and ubyte %A, 4
177         %C = sub ubyte %B, 16
178         %D = and ubyte %C, 240   ;; 0xF0
179         %E = add ubyte %D, 16
180         ret ubyte %E
181 }
182
183 int %test28(int %X) {       ;; This is juse a zero extending shr.
184         %Y = shr int %X, ubyte 24  ;; Sign extend
185         %Z = and int %Y, 255       ;; Mask out sign bits
186         ret int %Z
187 }
188
189 int %test29(ubyte %X) {
190         %Y = cast ubyte %X to int
191         %Z = and int %Y, 255       ;; Zero extend makes this unneeded.
192         ret int %Z
193 }
194
195 int %test30(bool %X) {
196         %Y = cast bool %X to int
197         %Z = and int %Y, 1
198         ret int %Z
199 }
200
201 uint %test31(bool %X) {
202         %Y = cast bool %X to uint
203         %Z = shl uint %Y, ubyte 4
204         %A = and uint %Z, 16
205         ret uint %A
206 }
207
208 uint %test32(uint %In) {
209         %Y = and uint %In, 16
210         %Z = shr uint %Y, ubyte 2
211         %A = and uint %Z, 1
212         ret uint %A
213 }
214
215 uint %test33(uint %b) {   ;; Code corresponding to one-bit bitfield ^1.
216         %tmp.4.mask = and uint %b, 1
217         %tmp.10 = xor uint %tmp.4.mask, 1
218         %tmp.12 = and uint %b, 4294967294
219         %tmp.13 = or uint %tmp.12, %tmp.10
220         ret uint %tmp.13
221 }
222
223 int %test34(int %A, int %B) {
224         %tmp.2 = or int %B, %A
225         %tmp.4 = and int %tmp.2, %B
226         ret int %tmp.4
227 }
228