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