blob: 14b1a226473a043926433095ca8363bf3e90d6c7 [file] [log] [blame]
Chris Lattner74e95472002-05-06 05:43:36 +00001; This test makes sure that these instructions are properly eliminated.
2;
Reid Spencer91948d42007-04-14 20:13:02 +00003; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
4; RUN: grep -v xor | not grep {or }
Chris Lattner74e95472002-05-06 05:43:36 +00005
6implementation
7
Chris Lattner2deaf772003-02-18 18:06:44 +00008int %test1(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +00009 %B = or int %A, 0
10 ret int %B
11}
12
Chris Lattner2deaf772003-02-18 18:06:44 +000013int %test2(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000014 %B = or int %A, -1
15 ret int %B
16}
17
Chris Lattnerf67d52d2003-03-10 22:43:56 +000018ubyte %test2a(ubyte %A) {
19 %B = or ubyte %A, 255
20 ret ubyte %B
21}
22
Chris Lattner2deaf772003-02-18 18:06:44 +000023bool %test3(bool %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000024 %B = or bool %A, false
25 ret bool %B
26}
27
Chris Lattner2deaf772003-02-18 18:06:44 +000028bool %test4(bool %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000029 %B = or bool %A, true
30 ret bool %B
31}
32
Chris Lattnerfbfe8192003-07-23 21:11:56 +000033bool %test5(bool %A) {
Chris Lattner6022ad02002-05-06 05:51:26 +000034 %B = or bool %A, %A
35 ret bool %B
36}
37
Chris Lattnerfbfe8192003-07-23 21:11:56 +000038int %test6(int %A) {
Chris Lattner6022ad02002-05-06 05:51:26 +000039 %B = or int %A, %A
40 ret int %B
41}
42
Chris Lattnerfbfe8192003-07-23 21:11:56 +000043int %test7(int %A) { ; A | ~A == -1
Chris Lattnerc5fccf32003-02-18 19:28:47 +000044 %NotA = xor int -1, %A
45 %B = or int %A, %NotA
46 ret int %B
47}
Chris Lattner96c4dd92003-03-10 18:24:04 +000048
Chris Lattnerfbfe8192003-07-23 21:11:56 +000049ubyte %test8(ubyte %A) {
Chris Lattnerf67d52d2003-03-10 22:43:56 +000050 %B = or ubyte %A, 254
51 %C = or ubyte %B, 1
52 ret ubyte %C
53}
Chris Lattnerdec13672003-03-10 23:52:54 +000054
Chris Lattnerfbfe8192003-07-23 21:11:56 +000055ubyte %test9(ubyte %A, ubyte %B) { ; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2)
Chris Lattnercb269142003-03-11 00:10:59 +000056 %C = or ubyte %A, 1
57 %D = or ubyte %B, 254
58 %E = or ubyte %C, %D
59 ret ubyte %E
60}
Chris Lattnere1957a32003-06-04 04:37:46 +000061
Chris Lattnerfbfe8192003-07-23 21:11:56 +000062ubyte %test10(ubyte %A) {
Chris Lattnerd5663232003-07-23 18:28:42 +000063 %B = or ubyte %A, 1
64 %C = and ubyte %B, 254
65 %D = or ubyte %C, 254 ; (X & C1) | C2 --> (X | C2) & (C1|C2)
66 ret ubyte %D
67}
68
Chris Lattnerfbfe8192003-07-23 21:11:56 +000069ubyte %test11(ubyte %A) {
Chris Lattnerd5663232003-07-23 18:28:42 +000070 %B = or ubyte %A, 254
71 %C = xor ubyte %B, 13
72 %D = or ubyte %C, 1 ; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
73 %E = xor ubyte %D, 12
74 ret ubyte %E
75}
Chris Lattnera439aaf2003-07-23 19:05:29 +000076
Chris Lattnerfbfe8192003-07-23 21:11:56 +000077uint %test12(uint %A) {
Chris Lattnera439aaf2003-07-23 19:05:29 +000078 %B = or uint %A, 4 ; Should be eliminated
79 %C = and uint %B, 8
80 ret uint %C
81}
82
Chris Lattnerfbfe8192003-07-23 21:11:56 +000083uint %test13(uint %A) {
Chris Lattnerfcd1efb2003-07-23 19:24:34 +000084 %B = or uint %A, 12
85 %C = and uint %B, 8 ; Always equal to 8
86 ret uint %C
87}
88
Chris Lattner6dc37ab2003-07-24 19:31:08 +000089bool %test14(uint %A, uint %B) {
90 %C1 = setlt uint %A, %B
91 %C2 = setgt uint %A, %B
92 %D = or bool %C1, %C2 ; (A < B) | (A > B) === A != B
93 ret bool %D
94}
95
Chris Lattnerdaff6442003-07-24 19:44:51 +000096bool %test15(uint %A, uint %B) {
97 %C1 = setlt uint %A, %B
98 %C2 = seteq uint %A, %B
99 %D = or bool %C1, %C2 ; (A < B) | (A == B) === A <= B
100 ret bool %D
101}
102
Chris Lattner4d9385c2003-08-12 19:10:50 +0000103int %test16(int %A) {
104 %B = and int %A, 1
105 %C = and int %A, -2 ; -2 = ~1
106 %D = or int %B, %C ; %D = and int %B, -1 == %B
107 ret int %D
108}
109
110int %test17(int %A) {
111 %B = and int %A, 1
112 %C = and int %A, 4
113 %D = or int %B, %C ; %D = and int %B, 5
114 ret int %D
115}
Chris Lattnerefc06142004-09-28 22:31:49 +0000116
117bool %test18(int %A) {
118 %B = setge int %A, 100
119 %C = setlt int %A, 50
120 %D = or bool %B, %C ;; (A-50) >u 50
121 ret bool %D
122}
123
124bool %test19(int %A) {
125 %B = seteq int %A, 50
126 %C = seteq int %A, 51
127 %D = or bool %B, %C ;; (A-50) < 2
128 ret bool %D
129}
130
Chris Lattnerce8dd822005-05-06 00:58:09 +0000131int %test20(int %x) {
132 %y = and int %x, 123
133 %z = or int %y, %x
134 ret int %z
135}
Chris Lattnerc6d63a92005-09-18 03:39:02 +0000136
137uint %test21(uint %tmp.1) {
138 %tmp.1.mask1 = add uint %tmp.1, 2
139 %tmp.3 = and uint %tmp.1.mask1, 4294967294
140 %tmp.5 = and uint %tmp.1, 1
141 %tmp.6 = or uint %tmp.5, %tmp.3 ;; add tmp.1, 2
142 ret uint %tmp.6
143}
Chris Lattnere6ebe1a2006-02-12 08:01:35 +0000144
145int %test22(int %B) {
146 %ELIM41 = and int %B, 1 ; <int> [#uses=1]
147 %ELIM7 = and int %B, -2 ; <int> [#uses=1]
148 %ELIM5 = or int %ELIM41, %ELIM7 ; <int> [#uses=1]
149 ret int %ELIM5
150}
Chris Lattner69c68c32006-02-26 19:55:30 +0000151
152ushort %test23(ushort %A) {
153 %B = shr ushort %A, ubyte 1
154 %C = or ushort %B, 32768 ;; fold or into xor
155 %D = xor ushort %C, 8193
156 ret ushort %D
157}