1 ; This test makes sure that add instructions are properly eliminated.
3 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
4 ; RUN: grep -v OK | not grep add
22 %C = sub int %B, 5 ;; This should get converted to an add
26 int %test4(int %A, int %B) {
28 %D = add int %B, %C ; D = B + -A = B - A
32 int %test5(int %A, int %B) {
34 %D = add int %C, %B ; D = -A + B = B - A
40 %C = add int %B, %A ; C = 7*A+A == 8*A == A << 3
46 %C = add int %A, %B ; C = A+7*A == 8*A == A << 3
50 ; (A & C1)+(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
51 int %test8(int %A, int %B) {
59 %B = shl int %A, ubyte 4
60 %C = add int %B, %B ; === shl int %A, 5
64 bool %test10(ubyte %A, ubyte %b) {
66 %c = setne ubyte %B, 0 ; === A != -b
70 bool %test11(ubyte %A) {
71 %B = add ubyte %A, 255
72 %c = setne ubyte %B, 0 ; === A != 1
76 int %test12(int %A, int %B) {
77 %C_OK = add int %B, %A ; Should be transformed into shl A, 1
80 %D = add int %C_OK, %A
84 int %test13(int %A, int %B, int %C) {
85 %D_OK = add int %A, %B
86 %E_OK = add int %D_OK, %C
87 %F = add int %E_OK, %A ;; shl A, 1
91 uint %test14(uint %offset, uint %difference) {
92 %tmp.2 = and uint %difference, 3
93 %tmp.3_OK = add uint %tmp.2, %offset
94 %tmp.5.mask = and uint %difference, 4294967292
95 %tmp.8 = add uint %tmp.3_OK, %tmp.5.mask ; == add %offset, %difference
99 ubyte %test15(ubyte %A) {
100 %B = add ubyte %A, 192 ; Does not effect result
101 %C = and ubyte %B, 16 ; Only one bit set
105 ubyte %test16(ubyte %A) {
106 %B = add ubyte %A, 16 ; Turn this into a XOR
107 %C = and ubyte %B, 16 ; Only one bit set
111 int %test17(int %A) {
113 %C = add int %B, 1 ; == sub int 0, %A
117 ubyte %test18(ubyte %A) {
118 %B = xor ubyte %A, 255
119 %C = add ubyte %B, 17 ; == sub ubyte 16, %A
123 int %test19(bool %C) {
124 %A = select bool %C, int 1000, int 10
129 int %test20(int %x) {
130 %tmp.2 = xor int %x, -2147483648
131 ;; Add of sign bit -> xor of sign bit.
132 %tmp.4 = add int %tmp.2, -2147483648
136 bool %test21(uint %x) {
138 %y = seteq uint %t, 123
142 int %test22(uint %V) {
143 %V2 = add uint %V, 10
144 switch uint %V2, label %Default [
156 int %test23(bool %C, int %a) {
158 br bool %C, label %endif, label %else
164 %b.0 = phi int [ 0, %entry ], [ 1, %else ]
165 %tmp.4 = add int %b.0, 1
169 int %test24(int %A) {
171 %C = shl int %B, ubyte 1
176 long %test25(long %Y) {
177 %tmp.4 = shl long %Y, ubyte 2
178 %tmp.12 = shl long %Y, ubyte 2
179 %tmp.8 = add long %tmp.4, %tmp.12 ;; Y << 3
183 int %test26(int %A, int %B) {
189 int %test27(bool %C, int %X, int %Y) {
192 %C = select bool %C, int %A, int %B ;; Fold add through select.
197 int %test28(int %X) {
198 %Y = add int %X, 1234
203 uint %test29(uint %X, uint %x) {
204 %tmp.2 = sub uint %X, %x
205 %tmp.2.mask = and uint %tmp.2, 63 ; <uint> [#uses=1]
206 %tmp.6 = add uint %tmp.2.mask, %x ; <uint> [#uses=1]
207 %tmp.7 = and uint %tmp.6, 63 ; <uint> [#uses=1]
208 %tmp.9 = and uint %tmp.2, 4294967232 ; <uint> [#uses=1]
209 %tmp.10 = or uint %tmp.7, %tmp.9 ; <uint> [#uses=1]
213 long %test30(long %x) {
214 %tmp.2 = xor long %x, -9223372036854775808
215 ;; Add of sign bit -> xor of sign bit.
216 %tmp.4 = add long %tmp.2, -9223372036854775808
220 int %test31(int %A) {
227 int %test32(int %A) {
229 %C = shl int %B, ubyte 2
234 ubyte %test33(ubyte %A) { ;; OR A, 1
235 %B = and ubyte %A, 254
240 ubyte %test34(ubyte %A) {
241 %B = add ubyte %A, 64 ;; dead
242 %C = and ubyte %B, 12
246 int %test35(int %a) { ;; -> -1
247 %tmpnot = xor int %a, -1
248 %tmp2 = add int %tmpnot, %a