blob: e0c4d180e18c17101469f32a41feeaecb7f54a98 [file] [log] [blame]
Chris Lattner74e95472002-05-06 05:43:36 +00001; This test makes sure that these instructions are properly eliminated.
2;
3
Chris Lattner423909d2003-06-28 23:32:04 +00004; RUN: as < %s | opt -instcombine | 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
52 %C = cast int %B to bool
53 ret bool %C
54}
55
56bool %test9(uint %A) {
57 %B = and uint %A, 2147483648 ; Test of sign bit, convert to setle %A, 0
58 %C = cast uint %B to bool
59 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
65 %D = and uint %C, 1
66 ret uint %D
67}