New testcases
[oota-llvm.git] / test / Transforms / InstCombine / and.ll
1 ; This test makes sure that these instructions are properly eliminated.
2 ;
3
4 ; RUN: as < %s | opt -instcombine | 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 = cast int %B to bool
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 = cast uint %B to bool
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 }