1 ; This test makes sure that add instructions are properly eliminated.
3 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -disable-output &&
4 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep -v OK | not grep add
21 %C = sub int %B, 5 ;; This should get converted to an add
25 int %test4(int %A, int %B) {
27 %D = add int %B, %C ; D = B + -A = B - A
31 int %test5(int %A, int %B) {
33 %D = add int %C, %B ; D = -A + B = B - A
39 %C = add int %B, %A ; C = 7*A+A == 8*A == A << 3
45 %C = add int %A, %B ; C = A+7*A == 8*A == A << 3
49 int %test8(int %A, int %B) { ; (A & C1)+(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
57 %B = shl int %A, ubyte 4
58 %C = add int %B, %B ; === shl int %A, 5
62 bool %test10(ubyte %A, ubyte %b) {
64 %c = setne ubyte %B, 0 ; === A != -b
68 bool %test11(ubyte %A) {
69 %B = add ubyte %A, 255
70 %c = setne ubyte %B, 0 ; === A != 1
74 int %test12(int %A, int %B) {
75 %C_OK = add int %B, %A ; Should be transformed into shl A, 1
78 %D = add int %C_OK, %A
82 int %test13(int %A, int %B, int %C) {
83 %D_OK = add int %A, %B
84 %E_OK = add int %D_OK, %C
85 %F = add int %E_OK, %A ;; shl A, 1
89 uint %test14(uint %offset, uint %difference) {
90 %tmp.2 = and uint %difference, 3
91 %tmp.3_OK = add uint %tmp.2, %offset
92 %tmp.5.mask = and uint %difference, 4294967292
93 %tmp.8 = add uint %tmp.3_OK, %tmp.5.mask ; == add %offset, %difference
97 ubyte %test15(ubyte %A) {
98 %B = add ubyte %A, 192 ; Does not effect result
99 %C = and ubyte %B, 16 ; Only one bit set
103 ubyte %test16(ubyte %A) {
104 %B = add ubyte %A, 16 ; Turn this into a XOR
105 %C = and ubyte %B, 16 ; Only one bit set
109 int %test17(int %A) {
111 %C = add int %B, 1 ; == sub int 0, %A
115 ubyte %test18(ubyte %A) {
116 %B = xor ubyte %A, 255
117 %C = add ubyte %B, 17 ; == sub ubyte 16, %A
121 int %test19(bool %C) {
122 %A = select bool %C, int 1000, int 10
127 int %test20(int %x) {
128 %tmp.2 = xor int %x, -2147483648
129 ;; Add of sign bit -> xor of sign bit.
130 %tmp.4 = add int %tmp.2, -2147483648
134 bool %test21(uint %x) {
136 %y = seteq uint %t, 123
140 int %test22(uint %V) {
141 %V2 = add uint %V, 10
142 switch uint %V2, label %Default [
154 int %test23(bool %C, int %a) {
156 br bool %C, label %endif, label %else
162 %b.0 = phi int [ 0, %entry ], [ 1, %else ]
163 %tmp.4 = add int %b.0, 1
167 int %test24(int %A) {
169 %C = shl int %B, ubyte 1
174 long %test25(long %Y) {
175 %tmp.4 = shl long %Y, ubyte 2
176 %tmp.12 = shl long %Y, ubyte 2
177 %tmp.8 = add long %tmp.4, %tmp.12 ;; Y << 3
181 int %test26(int %A, int %B) {
187 int %test27(bool %C, int %X, int %Y) {
190 %C = select bool %C, int %A, int %B ;; Fold add through select.
195 int %test28(int %X) {
196 %Y = add int %X, 1234
201 uint %test29(uint %X, uint %x) {
202 %tmp.2 = sub uint %X, %x
203 %tmp.2.mask = and uint %tmp.2, 63 ; <uint> [#uses=1]
204 %tmp.6 = add uint %tmp.2.mask, %x ; <uint> [#uses=1]
205 %tmp.7 = and uint %tmp.6, 63 ; <uint> [#uses=1]
206 %tmp.9 = and uint %tmp.2, 4294967232 ; <uint> [#uses=1]
207 %tmp.10 = or uint %tmp.7, %tmp.9 ; <uint> [#uses=1]
211 long %test30(long %x) {
212 %tmp.2 = xor long %x, -9223372036854775808
213 ;; Add of sign bit -> xor of sign bit.
214 %tmp.4 = add long %tmp.2, -9223372036854775808
218 int %test31(int %A) {
225 int %test32(int %A) {
227 %C = shl int %B, ubyte 2
232 ubyte %test33(ubyte %A) { ;; OR A, 1
233 %B = and ubyte %A, 254
238 ubyte %test34(ubyte %A) {
239 %B = add ubyte %A, 64 ;; dead
240 %C = and ubyte %B, 12
244 i32 %test34(i32 %a) { ;; -> -1
245 %tmpnot = xor i32 %a, -1
246 %tmp2 = add i32 %tmpnot, %a