blob: 7b08975877fc9207d7497c9644b724b49d78f132 [file] [log] [blame]
Chris Lattner74e95472002-05-06 05:43:36 +00001; This test makes sure that these instructions are properly eliminated.
2;
3
Reid Spencerd0e30dc2006-12-02 04:23:10 +00004; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep and
Reid Spencerede8c3b2007-04-15 07:38:21 +00005; END.
Chris Lattner74e95472002-05-06 05:43:36 +00006
7implementation
8
Chris Lattner2deaf772003-02-18 18:06:44 +00009int %test1(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000010 %B = and int %A, 0 ; zero result
11 ret int %B
12}
13
Chris Lattner2deaf772003-02-18 18:06:44 +000014int %test2(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000015 %B = and int %A, -1 ; noop
16 ret int %B
17}
18
Chris Lattner2deaf772003-02-18 18:06:44 +000019bool %test3(bool %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000020 %B = and bool %A, false ; always = false
21 ret bool %B
22}
23
Chris Lattner2deaf772003-02-18 18:06:44 +000024bool %test4(bool %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000025 %B = and bool %A, true ; noop
26 ret bool %B
27}
28
Chris Lattner2deaf772003-02-18 18:06:44 +000029int %test5(int %A) {
Chris Lattner6022ad02002-05-06 05:51:26 +000030 %B = and int %A, %A
31 ret int %B
32}
33
Chris Lattner2deaf772003-02-18 18:06:44 +000034bool %test6(bool %A) {
Chris Lattner6022ad02002-05-06 05:51:26 +000035 %B = and bool %A, %A
36 ret bool %B
37}
Chris Lattner74e95472002-05-06 05:43:36 +000038
Chris Lattnerc5fccf32003-02-18 19:28:47 +000039int %test7(int %A) { ; A & ~A == 0
40 %NotA = xor int %A, -1
41 %B = and int %A, %NotA
42 ret int %B
Chris Lattnerf67d52d2003-03-10 22:43:56 +000043}
44
45ubyte %test8(ubyte %A) { ; AND associates
46 %B = and ubyte %A, 3
47 %C = and ubyte %B, 4
48 ret ubyte %C
49}
Chris Lattnerdec13672003-03-10 23:52:54 +000050
Chris Lattner9af98802003-07-22 21:44:06 +000051bool %test9(int %A) {
52 %B = and int %A, -2147483648 ; Test of sign bit, convert to setle %A, 0
Chris Lattnerdad4e272003-08-13 20:17:41 +000053 %C = setne int %B, 0
Chris Lattner9af98802003-07-22 21:44:06 +000054 ret bool %C
55}
56
57bool %test9(uint %A) {
58 %B = and uint %A, 2147483648 ; Test of sign bit, convert to setle %A, 0
Chris Lattnerdad4e272003-08-13 20:17:41 +000059 %C = setne uint %B, 0
Chris Lattner9af98802003-07-22 21:44:06 +000060 ret bool %C
61}
Chris Lattneraeef93c2003-07-23 17:56:34 +000062
63uint %test10(uint %A) {
64 %B = and uint %A, 12
65 %C = xor uint %B, 15
Chris Lattnerd5663232003-07-23 18:28:42 +000066 %D = and uint %C, 1 ; (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
Chris Lattneraeef93c2003-07-23 17:56:34 +000067 ret uint %D
68}
Chris Lattnerb69f30c2003-07-23 19:35:51 +000069
70uint %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
Chris Lattnerdaff6442003-07-24 19:44:51 +000078bool %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
85bool %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}
Chris Lattnerb69f30c2003-07-23 19:35:51 +000091
Chris Lattner9b741f12003-08-13 05:27:57 +000092bool %test14(ubyte %A) {
93 %B = and ubyte %A, 128
94 %C = setne ubyte %B, 0
95 ret bool %C
96}
Chris Lattnerd441d402003-09-19 19:04:43 +000097
98ubyte %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
104ubyte %test16(ubyte %A) {
105 %B = shl ubyte %A, ubyte 2
106 %C = and ubyte %B, 3
107 ret ubyte %C
108}
Chris Lattnerd5829aa2004-06-18 06:07:17 +0000109
110sbyte %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
Chris Lattner45a5ace2004-09-23 21:42:49 +0000117bool %test18(int %A) {
118 %B = and int %A, -128
119 %C = setne int %B, 0 ;; C >= 128
120 ret bool %C
121}
122
Chris Lattner5f9319a2004-09-27 19:25:20 +0000123bool %test18a(ubyte %A) {
124 %B = and ubyte %A, 254
125 %C = seteq ubyte %B, 0
126 ret bool %C
127}
128
Chris Lattner8c1c6912004-09-24 15:18:43 +0000129int %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
135ubyte %test20(ubyte %A) {
136 %C = shr ubyte %A, ubyte 7
137 %D = and ubyte %C, 1 ;; Unneeded
138 ret ubyte %D
139}
140
Chris Lattner3cbcd252004-09-28 21:39:35 +0000141bool %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
148bool %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
155bool %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
162bool %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
169bool %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
Chris Lattner94670622004-10-08 05:03:25 +0000176ubyte %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}
Chris Lattner329d0252005-01-01 16:13:19 +0000183
184int %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
190int %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
Chris Lattner8169e162005-05-06 01:52:52 +0000196int %test30(bool %X) {
197 %Y = cast bool %X to int
198 %Z = and int %Y, 1
199 ret int %Z
200}
Chris Lattner8d83be22005-05-06 04:52:46 +0000201
202uint %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
209uint %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}
Chris Lattner19519b32005-05-09 04:54:18 +0000215
216uint %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
Chris Lattner8081f402006-02-13 23:07:02 +0000224int %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