1 ; This test makes sure that these instructions are properly eliminated.
4 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep 'xor '
11 bool %test0(bool %A) {
12 %B = xor bool %A, false
21 bool %test2(bool %A) {
31 int %test4(int %A) { ; A ^ ~A == -1
32 %NotA = xor int -1, %A
33 %B = xor int %A, %NotA
37 uint %test5(uint %A) { ; (A|B)^B == A & (~B)
39 %r = xor uint %t1, 123
43 ubyte %test6(ubyte %A) {
49 ; (A & C1)^(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
50 int %test7(int %A, int %B) {
54 %C1 = xor int %A1, %B1
58 ubyte %test8(bool %c) {
59 %d = xor bool %c, true ; invert the condition
60 br bool %d, label %True, label %False
67 bool %test9(ubyte %A) {
68 %B = xor ubyte %A, 123 ; xor can be eliminated
69 %C = seteq ubyte %B, 34
73 ubyte %test10(ubyte %A) {
75 %C = xor ubyte %B, 4 ; transform into an OR
79 ubyte %test11(ubyte %A) {
81 %C = xor ubyte %B, 4 ; transform into an AND
85 bool %test12(ubyte %A) {
87 %c = setne ubyte %B, 0
91 bool %test13(ubyte %A, ubyte %B) {
92 %C = setlt ubyte %A, %B
93 %D = setgt ubyte %A, %B
94 %E = xor bool %C, %D ; E = setne %A, %B
98 bool %test14(ubyte %A, ubyte %B) {
99 %C = seteq ubyte %A, %B
100 %D = setne ubyte %B, %A
101 %E = xor bool %C, %D ; E = true
105 uint %test15(uint %A) { ; ~(X-1) == -X
106 %B = add uint %A, 4294967295
107 %C = xor uint %B, 4294967295
111 uint %test16(uint %A) { ; ~(X+c) == (-c-1)-X
112 %B = add uint %A, 123 ; A generalization of the previous case
113 %C = xor uint %B, 4294967295
117 uint %test17(uint %A) { ; ~(c-X) == X-(c-1) == X+(-c+1)
118 %B = sub uint 123, %A
119 %C = xor uint %B, 4294967295
123 uint %test18(uint %A) { ; C - ~X == X + (1+C)
124 %B = xor uint %A, 4294967295; -~X == 0 - ~X == X+1
125 %C = sub uint 123, %B
129 uint %test19(uint %A, uint %B) {
131 %D = xor uint %C, %A ; A terms cancel, D = B
135 void %test20(uint %A, uint %B) { ; The "swap idiom"
136 %tmp.2 = xor uint %B, %A
137 %tmp.5 = xor uint %tmp.2, %B
138 %tmp.8 = xor uint %tmp.5, %tmp.2
139 store uint %tmp.8, uint* %G1 ; tmp.8 = B
140 store uint %tmp.5, uint* %G2 ; tmp.5 = A