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