Add some more tests for: (A <setcc1> B) logicalop (A <setcc2> B)
[oota-llvm.git] / test / Transforms / InstCombine / xor.ll
1 ; This test makes sure that these instructions are properly eliminated.
2 ;
3
4 ; RUN: as < %s | opt -instcombine | dis | not grep 'xor '
5
6 implementation
7
8 bool %test0(bool %A) {
9         %B = xor bool %A, false
10         ret bool %B
11 }
12
13 int %test1(int %A) {
14         %B = xor int %A, 0
15         ret int %B
16 }
17
18 bool %test2(bool %A) {
19         %B = xor bool %A, %A
20         ret bool %B
21 }
22
23 int %test3(int %A) {
24         %B = xor int %A, %A
25         ret int %B
26 }
27
28 int %test4(int %A) {    ; A ^ ~A == -1
29         %NotA = xor int -1, %A
30         %B = xor int %A, %NotA
31         ret int %B
32 }
33
34 uint %test5(uint %A) { ; (A|B)^B == A & (~B)
35         %t1 = or uint %A, 123
36         %r  = xor uint %t1, 123
37         ret uint %r
38 }
39
40 ubyte %test6(ubyte %A) {
41         %B = xor ubyte %A, 17
42         %C = xor ubyte %B, 17
43         ret ubyte %C
44 }
45
46 ; (A & C1)^(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
47 int %test7(int %A, int %B) {
48
49         %A1 = and int %A, 7
50         %B1 = and int %B, 128
51         %C1 = xor int %A1, %B1
52         ret int %C1
53 }
54
55 ubyte %test8(bool %c) {
56         %d = xor bool %c, true    ; invert the condition
57         br bool %d, label %True, label %False
58 True:
59         ret ubyte 1
60 False:
61         ret ubyte 3
62 }
63
64 bool %test9(ubyte %A) {
65         %B = xor ubyte %A, 123      ; xor can be eliminated
66         %C = seteq ubyte %B, 34
67         ret bool %C
68 }
69
70 ubyte %test10(ubyte %A) {
71         %B = and ubyte %A, 3
72         %C = xor ubyte %B, 4        ; transform into an OR
73         ret ubyte %C
74 }
75
76 ubyte %test11(ubyte %A) {
77         %B = or ubyte %A, 12
78         %C = xor ubyte %B, 4        ; transform into an AND
79         ret ubyte %C
80 }
81
82 bool %test12(ubyte %A) {
83         %B = xor ubyte %A, 4
84         %c = setne ubyte %B, 0
85         ret bool %c
86 }
87
88 bool %test13(ubyte %A, ubyte %B) {
89         %C = setlt ubyte %A, %B
90         %D = setgt ubyte %A, %B
91         %E = xor bool %C, %D        ; E = setne %A, %B
92         ret bool %E
93 }
94
95 bool %test14(ubyte %A, ubyte %B) {
96         %C = seteq ubyte %A, %B
97         %D = setne ubyte %B, %A
98         %E = xor bool %C, %D        ; E = true
99         ret bool %E
100 }