blob: 4d128c666d38089c01cbb7368cb73e82f07976ed [file] [log] [blame]
Chris Lattner2cc064c2003-07-23 21:10:55 +00001; This test makes sure that these instructions are properly eliminated.
2;
3
Reid Spencerd0e30dc2006-12-02 04:23:10 +00004; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -disable-output &&
5; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep 'xor '
Chris Lattner2cc064c2003-07-23 21:10:55 +00006
Chris Lattner98c26a72004-02-16 03:53:44 +00007%G1 = global uint 0
8%G2 = global uint 0
9
Chris Lattner2cc064c2003-07-23 21:10:55 +000010implementation
11
Chris Lattnerfbfe8192003-07-23 21:11:56 +000012bool %test0(bool %A) {
Chris Lattner2cc064c2003-07-23 21:10:55 +000013 %B = xor bool %A, false
14 ret bool %B
15}
16
Chris Lattnerfbfe8192003-07-23 21:11:56 +000017int %test1(int %A) {
Chris Lattner2cc064c2003-07-23 21:10:55 +000018 %B = xor int %A, 0
19 ret int %B
20}
21
Chris Lattnerfbfe8192003-07-23 21:11:56 +000022bool %test2(bool %A) {
Chris Lattner2cc064c2003-07-23 21:10:55 +000023 %B = xor bool %A, %A
24 ret bool %B
25}
26
Chris Lattnerfbfe8192003-07-23 21:11:56 +000027int %test3(int %A) {
Chris Lattner2cc064c2003-07-23 21:10:55 +000028 %B = xor int %A, %A
29 ret int %B
30}
31
Chris Lattnerfbfe8192003-07-23 21:11:56 +000032int %test4(int %A) { ; A ^ ~A == -1
Chris Lattner2cc064c2003-07-23 21:10:55 +000033 %NotA = xor int -1, %A
34 %B = xor int %A, %NotA
35 ret int %B
36}
37
Chris Lattnerfbfe8192003-07-23 21:11:56 +000038uint %test5(uint %A) { ; (A|B)^B == A & (~B)
Chris Lattner2cc064c2003-07-23 21:10:55 +000039 %t1 = or uint %A, 123
40 %r = xor uint %t1, 123
41 ret uint %r
42}
43
Chris Lattnerfbfe8192003-07-23 21:11:56 +000044ubyte %test6(ubyte %A) {
Chris Lattner2cc064c2003-07-23 21:10:55 +000045 %B = xor ubyte %A, 17
46 %C = xor ubyte %B, 17
47 ret ubyte %C
48}
49
Chris Lattnerfbfe8192003-07-23 21:11:56 +000050; (A & C1)^(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
51int %test7(int %A, int %B) {
52
Chris Lattner2cc064c2003-07-23 21:10:55 +000053 %A1 = and int %A, 7
54 %B1 = and int %B, 128
Chris Lattner2326ef62003-07-23 21:36:01 +000055 %C1 = xor int %A1, %B1
56 ret int %C1
Chris Lattner2cc064c2003-07-23 21:10:55 +000057}
58
Chris Lattnerfbfe8192003-07-23 21:11:56 +000059ubyte %test8(bool %c) {
Chris Lattner2cc064c2003-07-23 21:10:55 +000060 %d = xor bool %c, true ; invert the condition
61 br bool %d, label %True, label %False
62True:
63 ret ubyte 1
64False:
65 ret ubyte 3
66}
67
Chris Lattnerfbfe8192003-07-23 21:11:56 +000068bool %test9(ubyte %A) {
Chris Lattner2cc064c2003-07-23 21:10:55 +000069 %B = xor ubyte %A, 123 ; xor can be eliminated
70 %C = seteq ubyte %B, 34
71 ret bool %C
72}
Chris Lattner2326ef62003-07-23 21:36:01 +000073
74ubyte %test10(ubyte %A) {
75 %B = and ubyte %A, 3
76 %C = xor ubyte %B, 4 ; transform into an OR
77 ret ubyte %C
78}
79
80ubyte %test11(ubyte %A) {
81 %B = or ubyte %A, 12
82 %C = xor ubyte %B, 4 ; transform into an AND
83 ret ubyte %C
84}
Chris Lattner9b741f12003-08-13 05:27:57 +000085
86bool %test12(ubyte %A) {
87 %B = xor ubyte %A, 4
88 %c = setne ubyte %B, 0
89 ret bool %c
90}
Chris Lattnerfaedc5e2003-08-13 20:13:15 +000091
92bool %test13(ubyte %A, ubyte %B) {
93 %C = setlt ubyte %A, %B
94 %D = setgt ubyte %A, %B
95 %E = xor bool %C, %D ; E = setne %A, %B
96 ret bool %E
97}
98
99bool %test14(ubyte %A, ubyte %B) {
100 %C = seteq ubyte %A, %B
101 %D = setne ubyte %B, %A
102 %E = xor bool %C, %D ; E = true
103 ret bool %E
104}
Chris Lattnerf622d7c2003-11-04 23:21:22 +0000105
106uint %test15(uint %A) { ; ~(X-1) == -X
107 %B = add uint %A, 4294967295
108 %C = xor uint %B, 4294967295
109 ret uint %C
110}
Chris Lattnere3a932c2003-11-04 23:36:50 +0000111
112uint %test16(uint %A) { ; ~(X+c) == (-c-1)-X
113 %B = add uint %A, 123 ; A generalization of the previous case
114 %C = xor uint %B, 4294967295
115 ret uint %C
116}
Chris Lattnerf6368c82003-11-04 23:49:53 +0000117
118uint %test17(uint %A) { ; ~(c-X) == X-(c-1) == X+(-c+1)
119 %B = sub uint 123, %A
120 %C = xor uint %B, 4294967295
121 ret uint %C
122}
Chris Lattnerb6ca46e02003-11-05 01:05:22 +0000123
124uint %test18(uint %A) { ; C - ~X == X + (1+C)
125 %B = xor uint %A, 4294967295; -~X == 0 - ~X == X+1
126 %C = sub uint 123, %B
127 ret uint %C
128}
Chris Lattner5c063c92004-02-16 01:19:52 +0000129
130uint %test19(uint %A, uint %B) {
131 %C = xor uint %A, %B
132 %D = xor uint %C, %A ; A terms cancel, D = B
133 ret uint %D
134}
Chris Lattner98c26a72004-02-16 03:53:44 +0000135
136void %test20(uint %A, uint %B) { ; The "swap idiom"
137 %tmp.2 = xor uint %B, %A
138 %tmp.5 = xor uint %tmp.2, %B
139 %tmp.8 = xor uint %tmp.5, %tmp.2
140 store uint %tmp.8, uint* %G1 ; tmp.8 = B
141 store uint %tmp.5, uint* %G2 ; tmp.5 = A
142 ret void
143}
144
Chris Lattnerb57d0402005-04-24 07:28:53 +0000145int %test21(bool %C, int %A, int %B) {
146 %C2 = xor bool %C, true
147 %D = select bool %C2, int %A, int %B
148 ret int %D
149}
Chris Lattner1524489f2005-05-06 04:11:32 +0000150
151int %test22(bool %X) {
152 %Y = xor bool %X, true
153 %Z = cast bool %Y to int
154 %Q = xor int %Z, 1
155 ret int %Q
156}
157
Chris Lattner7422e472006-02-27 01:43:02 +0000158bool %test23(int %a, int %b) {
159 %tmp.2 = xor int %b, %a
160 %tmp.4 = seteq int %tmp.2, %a
161 ret bool %tmp.4
162}
163
164bool %test24(int %c, int %d) {
165 %tmp.2 = xor int %d, %c
166 %tmp.4 = setne int %tmp.2, %c
167 ret bool %tmp.4
168}
Chris Lattner2b11adc2006-04-01 08:02:51 +0000169
170int %test25(int %g, int %h) {
171 %h2 = xor int %h, -1
172 %tmp2 = and int %h2, %g
173 %tmp4 = xor int %tmp2, %g ; (h2&g)^g -> ~h2 & g -> h & g
174 ret int %tmp4
175}
176
177int %test26(int %a, int %b) {
178 %b2 = xor int %b, -1
179 %tmp2 = xor int %a, %b2
180 %tmp4 = and int %tmp2, %a ; (a^b2)&a -> ~b2 & a -> b & a
181 ret int %tmp4
182}
183
Chris Lattner130fff02007-01-05 03:03:51 +0000184
Reid Spencerce380562007-01-26 08:25:06 +0000185int %test27(int %b, int %c, int %d) {
186 %tmp2 = xor int %d, %b
187 %tmp5 = xor int %d, %c
188 %tmp = icmp eq int %tmp2, %tmp5
189 %tmp6 = zext bool %tmp to int
190 ret int %tmp6
Chris Lattner130fff02007-01-05 03:03:51 +0000191}
192
Chris Lattner2d81c6d2007-04-02 05:35:08 +0000193int %test28(int %indvar) {
194 %tmp7 = add int %indvar, -2147483647
195 %tmp214 = xor int %tmp7, -2147483648
196 ret int %tmp214
197}
198