a9863db935a51f6eee6ea425a2563c2795ecb11f
[oota-llvm.git] / test / Transforms / InstCombine / or.ll
1 ; This test makes sure that these instructions are properly eliminated.
2 ;
3
4 ; RUN: as < %s | opt -instcombine | dis | grep -v '%OROK = or' | 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 = xor bool %A, false
35         ret bool %B
36 }
37
38 int %test6(int %A) {
39         %B = xor int %A, 0
40         ret int %B
41 }
42
43 bool %test7(bool %A) {
44         %B = xor bool %A, %A
45         ret bool %B
46 }
47
48 int %test8(int %A) {
49         %B = xor int %A, %A
50         ret int %B
51 }
52
53 bool %test9(bool %A) {
54         %B = or bool %A, %A
55         ret bool %B
56 }
57
58 int %test10(int %A) {
59         %B = or int %A, %A
60         ret int %B
61 }
62
63 int %test11(int %A) {    ; A ^ ~A == -1
64         %NotA = xor int -1, %A
65         %B = xor int %A, %NotA
66         ret int %B
67 }
68
69 int %test12(int %A) {    ; A | ~A == -1
70         %NotA = xor int -1, %A
71         %B = or int %A, %NotA
72         ret int %B
73 }
74
75 uint %test13(uint %A) { ; (A|B)^B == A & (~B)
76         %t1 = or uint %A, 123
77         %r  = xor uint %t1, 123
78         ret uint %r
79 }
80
81 ubyte %test14(ubyte %A) {
82         %B = or ubyte %A, 254
83         %C = or ubyte %B, 1
84         ret ubyte %C
85 }
86 ubyte %test15(ubyte %A) {
87         %B = xor ubyte %A, 17
88         %C = xor ubyte %B, 17
89         ret ubyte %C
90 }
91
92 int %test16(int %A, int %B) {     ; (A & C1)^(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
93         %A1 = and int %A, 7
94         %B1 = and int %B, 128
95         %OROK = xor int %A1, %B1
96         ret int %OROK
97 }
98
99 ubyte %test17(ubyte %A, ubyte %B) {  ; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2)
100         %C = or ubyte %A, 1
101         %D = or ubyte %B, 254
102         %E = or ubyte %C, %D
103         ret ubyte %E
104 }
105
106 ubyte %test18(bool %c) {
107         %d = xor bool %c, true    ; invert the condition
108         br bool %d, label %True, label %False
109 True:
110         ret ubyte 1
111 False:
112         ret ubyte 3
113 }
114