new testcase
[oota-llvm.git] / test / Transforms / InstCombine / or.ll
1 ; This test makes sure that these instructions are properly eliminated.
2 ;
3
4 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep -v xor | not grep 'or '
5
6 implementation
7
8 int %test1(int %A) {
9         %B = or int %A, 0
10         ret int %B
11 }
12
13 int %test2(int %A) {
14         %B = or int %A, -1
15         ret int %B
16 }
17
18 ubyte %test2a(ubyte %A) {
19         %B = or ubyte %A, 255
20         ret ubyte %B
21 }
22
23 bool %test3(bool %A) {
24         %B = or bool %A, false
25         ret bool %B
26 }
27
28 bool %test4(bool %A) {
29         %B = or bool %A, true
30         ret bool %B
31 }
32
33 bool %test5(bool %A) {
34         %B = or bool %A, %A
35         ret bool %B
36 }
37
38 int %test6(int %A) {
39         %B = or int %A, %A
40         ret int %B
41 }
42
43 int %test7(int %A) {    ; A | ~A == -1
44         %NotA = xor int -1, %A
45         %B = or int %A, %NotA
46         ret int %B
47 }
48
49 ubyte %test8(ubyte %A) {
50         %B = or ubyte %A, 254
51         %C = or ubyte %B, 1
52         ret ubyte %C
53 }
54
55 ubyte %test9(ubyte %A, ubyte %B) {  ; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2)
56         %C = or ubyte %A, 1
57         %D = or ubyte %B, 254
58         %E = or ubyte %C, %D
59         ret ubyte %E
60 }
61
62 ubyte %test10(ubyte %A) {
63         %B = or ubyte %A, 1
64         %C = and ubyte %B, 254
65         %D = or ubyte %C, 254  ; (X & C1) | C2 --> (X | C2) & (C1|C2)
66         ret ubyte %D
67 }
68
69 ubyte %test11(ubyte %A) {
70         %B = or ubyte %A, 254
71         %C = xor ubyte %B, 13
72         %D = or ubyte %C, 1    ; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
73         %E = xor ubyte %D, 12
74         ret ubyte %E
75 }
76
77 uint %test12(uint %A) {
78         %B = or uint %A, 4     ; Should be eliminated
79         %C = and uint %B, 8
80         ret uint %C
81 }
82
83 uint %test13(uint %A) {
84         %B = or uint %A, 12
85         %C = and uint %B, 8    ; Always equal to 8
86         ret uint %C 
87 }
88
89 bool %test14(uint %A, uint %B) {
90         %C1 = setlt uint %A, %B
91         %C2 = setgt uint %A, %B
92         %D = or bool %C1, %C2      ; (A < B) | (A > B) === A != B
93         ret bool %D
94 }
95
96 bool %test15(uint %A, uint %B) {
97         %C1 = setlt uint %A, %B
98         %C2 = seteq uint %A, %B
99         %D = or bool %C1, %C2      ; (A < B) | (A == B) === A <= B
100         ret bool %D
101 }
102
103 int %test16(int %A) {
104         %B = and int %A, 1
105         %C = and int %A, -2       ; -2 = ~1
106         %D = or int %B, %C        ; %D = and int %B, -1 == %B
107         ret int %D
108 }
109
110 int %test17(int %A) {
111         %B = and int %A, 1
112         %C = and int %A, 4
113         %D = or int %B, %C        ; %D = and int %B, 5
114         ret int %D
115 }
116
117 bool %test18(int %A) {
118         %B = setge int %A, 100
119         %C = setlt int %A, 50
120         %D = or bool %B, %C   ;; (A-50) >u 50
121         ret bool %D
122 }
123
124 bool %test19(int %A) {
125         %B = seteq int %A, 50
126         %C = seteq int %A, 51
127         %D = or bool %B, %C   ;; (A-50) < 2
128         ret bool %D
129 }
130
131 int %test20(int %x) {
132         %y = and int %x, 123
133         %z = or int %y, %x
134         ret int %z
135 }