blob: e8558f7d907e777b6523be3971e5e6bc6b9ddf9b [file] [log] [blame]
Chris Lattner74e95472002-05-06 05:43:36 +00001; This test makes sure that these instructions are properly eliminated.
2;
3
Misha Brukmanedf4bab2003-09-16 15:29:54 +00004; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep and
Chris Lattner74e95472002-05-06 05:43:36 +00005
6implementation
7
Chris Lattner2deaf772003-02-18 18:06:44 +00008int %test1(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +00009 %B = and int %A, 0 ; zero result
10 ret int %B
11}
12
Chris Lattner2deaf772003-02-18 18:06:44 +000013int %test2(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000014 %B = and int %A, -1 ; noop
15 ret int %B
16}
17
Chris Lattner2deaf772003-02-18 18:06:44 +000018bool %test3(bool %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000019 %B = and bool %A, false ; always = false
20 ret bool %B
21}
22
Chris Lattner2deaf772003-02-18 18:06:44 +000023bool %test4(bool %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000024 %B = and bool %A, true ; noop
25 ret bool %B
26}
27
Chris Lattner2deaf772003-02-18 18:06:44 +000028int %test5(int %A) {
Chris Lattner6022ad02002-05-06 05:51:26 +000029 %B = and int %A, %A
30 ret int %B
31}
32
Chris Lattner2deaf772003-02-18 18:06:44 +000033bool %test6(bool %A) {
Chris Lattner6022ad02002-05-06 05:51:26 +000034 %B = and bool %A, %A
35 ret bool %B
36}
Chris Lattner74e95472002-05-06 05:43:36 +000037
Chris Lattnerc5fccf32003-02-18 19:28:47 +000038int %test7(int %A) { ; A & ~A == 0
39 %NotA = xor int %A, -1
40 %B = and int %A, %NotA
41 ret int %B
Chris Lattnerf67d52d2003-03-10 22:43:56 +000042}
43
44ubyte %test8(ubyte %A) { ; AND associates
45 %B = and ubyte %A, 3
46 %C = and ubyte %B, 4
47 ret ubyte %C
48}
Chris Lattnerdec13672003-03-10 23:52:54 +000049
Chris Lattner9af98802003-07-22 21:44:06 +000050bool %test9(int %A) {
51 %B = and int %A, -2147483648 ; Test of sign bit, convert to setle %A, 0
Chris Lattnerdad4e272003-08-13 20:17:41 +000052 %C = setne int %B, 0
Chris Lattner9af98802003-07-22 21:44:06 +000053 ret bool %C
54}
55
56bool %test9(uint %A) {
57 %B = and uint %A, 2147483648 ; Test of sign bit, convert to setle %A, 0
Chris Lattnerdad4e272003-08-13 20:17:41 +000058 %C = setne uint %B, 0
Chris Lattner9af98802003-07-22 21:44:06 +000059 ret bool %C
60}
Chris Lattneraeef93c2003-07-23 17:56:34 +000061
62uint %test10(uint %A) {
63 %B = and uint %A, 12
64 %C = xor uint %B, 15
Chris Lattnerd5663232003-07-23 18:28:42 +000065 %D = and uint %C, 1 ; (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
Chris Lattneraeef93c2003-07-23 17:56:34 +000066 ret uint %D
67}
Chris Lattnerb69f30c2003-07-23 19:35:51 +000068
69uint %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
Chris Lattnerdaff6442003-07-24 19:44:51 +000077bool %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
84bool %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}
Chris Lattnerb69f30c2003-07-23 19:35:51 +000090
Chris Lattner9b741f12003-08-13 05:27:57 +000091bool %test14(ubyte %A) {
92 %B = and ubyte %A, 128
93 %C = setne ubyte %B, 0
94 ret bool %C
95}
Chris Lattnerd441d402003-09-19 19:04:43 +000096
97ubyte %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
103ubyte %test16(ubyte %A) {
104 %B = shl ubyte %A, ubyte 2
105 %C = and ubyte %B, 3
106 ret ubyte %C
107}
Chris Lattnerd5829aa2004-06-18 06:07:17 +0000108
109sbyte %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
Chris Lattner45a5ace2004-09-23 21:42:49 +0000116bool %test18(int %A) {
117 %B = and int %A, -128
118 %C = setne int %B, 0 ;; C >= 128
119 ret bool %C
120}
121
Chris Lattner5f9319a2004-09-27 19:25:20 +0000122bool %test18a(ubyte %A) {
123 %B = and ubyte %A, 254
124 %C = seteq ubyte %B, 0
125 ret bool %C
126}
127
Chris Lattner8c1c6912004-09-24 15:18:43 +0000128int %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
134ubyte %test20(ubyte %A) {
135 %C = shr ubyte %A, ubyte 7
136 %D = and ubyte %C, 1 ;; Unneeded
137 ret ubyte %D
138}
139
Chris Lattner3cbcd252004-09-28 21:39:35 +0000140bool %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
147bool %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
154bool %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
161bool %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
168bool %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
Chris Lattner94670622004-10-08 05:03:25 +0000175ubyte %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}
Chris Lattner329d0252005-01-01 16:13:19 +0000182
183int %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
189int %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
Chris Lattner8169e162005-05-06 01:52:52 +0000195int %test30(bool %X) {
196 %Y = cast bool %X to int
197 %Z = and int %Y, 1
198 ret int %Z
199}