[InstCombine] Fold IntToPtr and PtrToInt into preceding loads.
[oota-llvm.git] / test / Transforms / InstCombine / or-xor.ll
1 ; RUN: opt -S -instcombine < %s | FileCheck %s
2
3 define i32 @test1(i32 %x, i32 %y) nounwind {
4   %or = or i32 %x, %y
5   %not = xor i32 %or, -1
6   %z = or i32 %x, %not
7   ret i32 %z
8 ; CHECK-LABEL: @test1(
9 ; CHECK-NEXT: %y.not = xor i32 %y, -1
10 ; CHECK-NEXT: %z = or i32 %y.not, %x
11 ; CHECK-NEXT: ret i32 %z
12 }
13
14 define i32 @test2(i32 %x, i32 %y) nounwind {
15   %or = or i32 %x, %y
16   %not = xor i32 %or, -1
17   %z = or i32 %y, %not
18   ret i32 %z
19 ; CHECK-LABEL: @test2(
20 ; CHECK-NEXT: %x.not = xor i32 %x, -1
21 ; CHECK-NEXT: %z = or i32 %x.not, %y
22 ; CHECK-NEXT: ret i32 %z
23 }
24
25 define i32 @test3(i32 %x, i32 %y) nounwind {
26   %xor = xor i32 %x, %y
27   %not = xor i32 %xor, -1
28   %z = or i32 %x, %not
29   ret i32 %z
30 ; CHECK-LABEL: @test3(
31 ; CHECK-NEXT: %y.not = xor i32 %y, -1
32 ; CHECK-NEXT: %z = or i32 %y.not, %x
33 ; CHECK-NEXT: ret i32 %z
34 }
35
36 define i32 @test4(i32 %x, i32 %y) nounwind {
37   %xor = xor i32 %x, %y
38   %not = xor i32 %xor, -1
39   %z = or i32 %y, %not
40   ret i32 %z
41 ; CHECK-LABEL: @test4(
42 ; CHECK-NEXT: %x.not = xor i32 %x, -1
43 ; CHECK-NEXT: %z = or i32 %x.not, %y
44 ; CHECK-NEXT: ret i32 %z
45 }
46
47 define i32 @test5(i32 %x, i32 %y) nounwind {
48   %and = and i32 %x, %y
49   %not = xor i32 %and, -1
50   %z = or i32 %x, %not
51   ret i32 %z
52 ; CHECK-LABEL: @test5(
53 ; CHECK-NEXT: ret i32 -1
54 }
55
56 define i32 @test6(i32 %x, i32 %y) nounwind {
57   %and = and i32 %x, %y
58   %not = xor i32 %and, -1
59   %z = or i32 %y, %not
60   ret i32 %z
61 ; CHECK-LABEL: @test6(
62 ; CHECK-NEXT: ret i32 -1
63 }
64
65 define i32 @test7(i32 %x, i32 %y) nounwind {
66   %xor = xor i32 %x, %y
67   %z = or i32 %y, %xor
68   ret i32 %z
69 ; CHECK-LABEL: @test7(
70 ; CHECK-NEXT: %z = or i32 %x, %y
71 ; CHECK-NEXT: ret i32 %z
72 }
73
74 define i32 @test8(i32 %x, i32 %y) nounwind {
75   %not = xor i32 %y, -1
76   %xor = xor i32 %x, %not
77   %z = or i32 %y, %xor
78   ret i32 %z
79 ; CHECK-LABEL: @test8(
80 ; CHECK-NEXT: %x.not = xor i32 %x, -1
81 ; CHECK-NEXT: %z = or i32 %x.not, %y
82 ; CHECK-NEXT: ret i32 %z
83 }
84
85 define i32 @test9(i32 %x, i32 %y) nounwind {
86   %not = xor i32 %x, -1
87   %xor = xor i32 %not, %y
88   %z = or i32 %x, %xor
89   ret i32 %z
90 ; CHECK-LABEL: @test9(
91 ; CHECK-NEXT: %y.not = xor i32 %y, -1
92 ; CHECK-NEXT: %z = or i32 %y.not, %x
93 ; CHECK-NEXT: ret i32 %z
94 }
95
96 define i32 @test10(i32 %A, i32 %B) {
97   %xor1 = xor i32 %B, %A
98   %not = xor i32 %A, -1
99   %xor2 = xor i32 %not, %B
100   %or = or i32 %xor1, %xor2
101   ret i32 %or
102 ; CHECK-LABEL: @test10(
103 ; CHECK-NEXT: ret i32 -1
104 }
105
106 ; (x | y) & ((~x) ^ y) -> (x & y)
107 define i32 @test11(i32 %x, i32 %y) {
108  %or = or i32 %x, %y
109  %neg = xor i32 %x, -1
110  %xor = xor i32 %neg, %y
111  %and = and i32 %or, %xor
112  ret i32 %and
113 ; CHECK-LABEL: @test11(
114 ; CHECK-NEXT: %and = and i32 %x, %y
115 ; CHECK-NEXT: ret i32 %and
116 }
117
118 ; ((~x) ^ y) & (x | y) -> (x & y)
119 define i32 @test12(i32 %x, i32 %y) {
120  %neg = xor i32 %x, -1
121  %xor = xor i32 %neg, %y
122  %or = or i32 %x, %y
123  %and = and i32 %xor, %or
124  ret i32 %and
125 ; CHECK-LABEL: @test12(
126 ; CHECK-NEXT: %and = and i32 %x, %y
127 ; CHECK-NEXT: ret i32 %and
128 }
129
130 ; ((x | y) ^ (x ^ y)) -> (x & y)
131 define i32 @test13(i32 %x, i32 %y) {
132   %1 = xor i32 %y, %x
133   %2 = or i32 %y, %x
134   %3 = xor i32 %2, %1
135   ret i32 %3
136 ; CHECK-LABEL: @test13(
137 ; CHECK-NEXT: %1 = and i32 %y, %x
138 ; CHECK-NEXT: ret i32 %1
139 }
140
141 ; ((x | ~y) ^ (~x | y)) -> x ^ y
142 define i32 @test14(i32 %x, i32 %y) {
143   %noty = xor i32 %y, -1
144   %notx = xor i32 %x, -1
145   %or1 = or i32 %x, %noty
146   %or2 = or i32 %notx, %y
147   %xor = xor i32 %or1, %or2
148   ret i32 %xor
149 ; CHECK-LABEL: @test14(
150 ; CHECK-NEXT: %xor = xor i32 %x, %y
151 ; CHECK-NEXT: ret i32 %xor
152 }
153
154 ; ((x & ~y) ^ (~x & y)) -> x ^ y
155 define i32 @test15(i32 %x, i32 %y) {
156   %noty = xor i32 %y, -1
157   %notx = xor i32 %x, -1
158   %and1 = and i32 %x, %noty
159   %and2 = and i32 %notx, %y
160   %xor = xor i32 %and1, %and2
161   ret i32 %xor
162 ; CHECK-LABEL: @test15(
163 ; CHECK-NEXT: %xor = xor i32 %x, %y
164 ; CHECK-NEXT: ret i32 %xor
165 }
166
167 define i32 @test16(i32 %a, i32 %b) {
168   %or = xor i32 %a, %b
169   %and1 = and i32 %or, 1
170   %and2 = and i32 %b, -2
171   %xor = or i32 %and1, %and2
172   ret i32 %xor
173 ; CHECK-LABEL: @test16(
174 ; CHECK-NEXT: %1 = and i32 %a, 1
175 ; CHECK-NEXT: %xor = xor i32 %1, %b
176 ; CHECK-NEXT: ret i32 %xor
177 }