1 ; This test makes sure that these instructions are properly eliminated.
3 ; RUN: opt < %s -instcombine -S | \
4 ; RUN: grep -v xor | not grep {or }
7 define i32 @test1(i32 %A) {
8 %B = or i32 %A, 0 ; <i32> [#uses=1]
12 define i32 @test2(i32 %A) {
13 %B = or i32 %A, -1 ; <i32> [#uses=1]
17 define i8 @test2a(i8 %A) {
18 %B = or i8 %A, -1 ; <i8> [#uses=1]
22 define i1 @test3(i1 %A) {
23 %B = or i1 %A, false ; <i1> [#uses=1]
27 define i1 @test4(i1 %A) {
28 %B = or i1 %A, true ; <i1> [#uses=1]
32 define i1 @test5(i1 %A) {
33 %B = or i1 %A, %A ; <i1> [#uses=1]
37 define i32 @test6(i32 %A) {
38 %B = or i32 %A, %A ; <i32> [#uses=1]
43 define i32 @test7(i32 %A) {
44 %NotA = xor i32 -1, %A ; <i32> [#uses=1]
45 %B = or i32 %A, %NotA ; <i32> [#uses=1]
49 define i8 @test8(i8 %A) {
50 %B = or i8 %A, -2 ; <i8> [#uses=1]
51 %C = or i8 %B, 1 ; <i8> [#uses=1]
55 ; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2)
56 define i8 @test9(i8 %A, i8 %B) {
57 %C = or i8 %A, 1 ; <i8> [#uses=1]
58 %D = or i8 %B, -2 ; <i8> [#uses=1]
59 %E = or i8 %C, %D ; <i8> [#uses=1]
63 define i8 @test10(i8 %A) {
64 %B = or i8 %A, 1 ; <i8> [#uses=1]
65 %C = and i8 %B, -2 ; <i8> [#uses=1]
66 ; (X & C1) | C2 --> (X | C2) & (C1|C2)
67 %D = or i8 %C, -2 ; <i8> [#uses=1]
71 define i8 @test11(i8 %A) {
72 %B = or i8 %A, -2 ; <i8> [#uses=1]
73 %C = xor i8 %B, 13 ; <i8> [#uses=1]
74 ; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
75 %D = or i8 %C, 1 ; <i8> [#uses=1]
76 %E = xor i8 %D, 12 ; <i8> [#uses=1]
80 define i32 @test12(i32 %A) {
81 ; Should be eliminated
82 %B = or i32 %A, 4 ; <i32> [#uses=1]
83 %C = and i32 %B, 8 ; <i32> [#uses=1]
87 define i32 @test13(i32 %A) {
88 %B = or i32 %A, 12 ; <i32> [#uses=1]
90 %C = and i32 %B, 8 ; <i32> [#uses=1]
94 define i1 @test14(i32 %A, i32 %B) {
95 %C1 = icmp ult i32 %A, %B ; <i1> [#uses=1]
96 %C2 = icmp ugt i32 %A, %B ; <i1> [#uses=1]
97 ; (A < B) | (A > B) === A != B
98 %D = or i1 %C1, %C2 ; <i1> [#uses=1]
102 define i1 @test15(i32 %A, i32 %B) {
103 %C1 = icmp ult i32 %A, %B ; <i1> [#uses=1]
104 %C2 = icmp eq i32 %A, %B ; <i1> [#uses=1]
105 ; (A < B) | (A == B) === A <= B
106 %D = or i1 %C1, %C2 ; <i1> [#uses=1]
110 define i32 @test16(i32 %A) {
111 %B = and i32 %A, 1 ; <i32> [#uses=1]
113 %C = and i32 %A, -2 ; <i32> [#uses=1]
114 ; %D = and int %B, -1 == %B
115 %D = or i32 %B, %C ; <i32> [#uses=1]
119 define i32 @test17(i32 %A) {
120 %B = and i32 %A, 1 ; <i32> [#uses=1]
121 %C = and i32 %A, 4 ; <i32> [#uses=1]
123 %D = or i32 %B, %C ; <i32> [#uses=1]
127 define i1 @test18(i32 %A) {
128 %B = icmp sge i32 %A, 100 ; <i1> [#uses=1]
129 %C = icmp slt i32 %A, 50 ; <i1> [#uses=1]
131 %D = or i1 %B, %C ; <i1> [#uses=1]
135 define i1 @test19(i32 %A) {
136 %B = icmp eq i32 %A, 50 ; <i1> [#uses=1]
137 %C = icmp eq i32 %A, 51 ; <i1> [#uses=1]
139 %D = or i1 %B, %C ; <i1> [#uses=1]
143 define i32 @test20(i32 %x) {
144 %y = and i32 %x, 123 ; <i32> [#uses=1]
145 %z = or i32 %y, %x ; <i32> [#uses=1]
149 define i32 @test21(i32 %tmp.1) {
150 %tmp.1.mask1 = add i32 %tmp.1, 2 ; <i32> [#uses=1]
151 %tmp.3 = and i32 %tmp.1.mask1, -2 ; <i32> [#uses=1]
152 %tmp.5 = and i32 %tmp.1, 1 ; <i32> [#uses=1]
154 %tmp.6 = or i32 %tmp.5, %tmp.3 ; <i32> [#uses=1]
158 define i32 @test22(i32 %B) {
159 %ELIM41 = and i32 %B, 1 ; <i32> [#uses=1]
160 %ELIM7 = and i32 %B, -2 ; <i32> [#uses=1]
161 %ELIM5 = or i32 %ELIM41, %ELIM7 ; <i32> [#uses=1]
165 define i16 @test23(i16 %A) {
166 %B = lshr i16 %A, 1 ; <i16> [#uses=1]
168 %C = or i16 %B, -32768 ; <i16> [#uses=1]
169 %D = xor i16 %C, 8193 ; <i16> [#uses=1]