new testcase
[oota-llvm.git] / test / Transforms / InstCombine / xor.ll
1 ; This test makes sure that these instructions are properly eliminated.
2 ;
3
4 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep 'xor '
5
6 %G1 = global uint 0
7 %G2 = global uint 0
8
9 implementation
10
11 bool %test0(bool %A) {
12         %B = xor bool %A, false
13         ret bool %B
14 }
15
16 int %test1(int %A) {
17         %B = xor int %A, 0
18         ret int %B
19 }
20
21 bool %test2(bool %A) {
22         %B = xor bool %A, %A
23         ret bool %B
24 }
25
26 int %test3(int %A) {
27         %B = xor int %A, %A
28         ret int %B
29 }
30
31 int %test4(int %A) {    ; A ^ ~A == -1
32         %NotA = xor int -1, %A
33         %B = xor int %A, %NotA
34         ret int %B
35 }
36
37 uint %test5(uint %A) { ; (A|B)^B == A & (~B)
38         %t1 = or uint %A, 123
39         %r  = xor uint %t1, 123
40         ret uint %r
41 }
42
43 ubyte %test6(ubyte %A) {
44         %B = xor ubyte %A, 17
45         %C = xor ubyte %B, 17
46         ret ubyte %C
47 }
48
49 ; (A & C1)^(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
50 int %test7(int %A, int %B) {
51
52         %A1 = and int %A, 7
53         %B1 = and int %B, 128
54         %C1 = xor int %A1, %B1
55         ret int %C1
56 }
57
58 ubyte %test8(bool %c) {
59         %d = xor bool %c, true    ; invert the condition
60         br bool %d, label %True, label %False
61 True:
62         ret ubyte 1
63 False:
64         ret ubyte 3
65 }
66
67 bool %test9(ubyte %A) {
68         %B = xor ubyte %A, 123      ; xor can be eliminated
69         %C = seteq ubyte %B, 34
70         ret bool %C
71 }
72
73 ubyte %test10(ubyte %A) {
74         %B = and ubyte %A, 3
75         %C = xor ubyte %B, 4        ; transform into an OR
76         ret ubyte %C
77 }
78
79 ubyte %test11(ubyte %A) {
80         %B = or ubyte %A, 12
81         %C = xor ubyte %B, 4        ; transform into an AND
82         ret ubyte %C
83 }
84
85 bool %test12(ubyte %A) {
86         %B = xor ubyte %A, 4
87         %c = setne ubyte %B, 0
88         ret bool %c
89 }
90
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
95         ret bool %E
96 }
97
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
102         ret bool %E
103 }
104
105 uint %test15(uint %A) {             ; ~(X-1) == -X
106         %B = add uint %A, 4294967295
107         %C = xor uint %B, 4294967295
108         ret uint %C
109 }
110
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
114         ret uint %C
115 }
116
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
120         ret uint %C
121 }
122
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
126         ret uint %C
127 }
128
129 uint %test19(uint %A, uint %B) {
130         %C = xor uint %A, %B
131         %D = xor uint %C, %A  ; A terms cancel, D = B
132         ret uint %D
133 }
134
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
141         ret void
142 }
143
144 int %test21(bool %C, int %A, int %B) {
145         %C2 = xor bool %C, true
146         %D = select bool %C2, int %A, int %B
147         ret int %D
148 }
149
150 int %test22(bool %X) {
151         %Y = xor bool %X, true
152         %Z = cast bool %Y to int
153         %Q = xor int %Z, 1
154         ret int %Q
155 }
156