1 ; This test makes sure that add instructions are properly eliminated.
3 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep -v OK | not grep add
20 %C = sub int %B, 5 ;; This should get converted to an add
24 int %test4(int %A, int %B) {
26 %D = add int %B, %C ; D = B + -A = B - A
30 int %test5(int %A, int %B) {
32 %D = add int %C, %B ; D = -A + B = B - A
38 %C = add int %B, %A ; C = 7*A+A == 8*A == A << 3
44 %C = add int %A, %B ; C = A+7*A == 8*A == A << 3
48 int %test8(int %A, int %B) { ; (A & C1)+(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
56 %B = shl int %A, ubyte 4
57 %C = add int %B, %B ; === shl int %A, 5
61 bool %test10(ubyte %A, ubyte %b) {
63 %c = setne ubyte %B, 0 ; === A != -b
67 bool %test11(ubyte %A) {
68 %B = add ubyte %A, 255
69 %c = setne ubyte %B, 0 ; === A != 1
73 int %test12(int %A, int %B) {
74 %C_OK = add int %B, %A ; Should be transformed into shl A, 1
77 %D = add int %C_OK, %A
81 int %test13(int %A, int %B, int %C) {
82 %D_OK = add int %A, %B
83 %E_OK = add int %D_OK, %C
84 %F = add int %E_OK, %A ;; shl A, 1
88 uint %test14(uint %offset, uint %difference) {
89 %tmp.2 = and uint %difference, 3
90 %tmp.3_OK = add uint %tmp.2, %offset
91 %tmp.5.mask = and uint %difference, 4294967292
92 %tmp.8 = add uint %tmp.3_OK, %tmp.5.mask ; == add %offset, %difference
96 ubyte %test15(ubyte %A) {
97 %B = add ubyte %A, 192 ; Does not effect result
98 %C = and ubyte %B, 16 ; Only one bit set
102 ubyte %test16(ubyte %A) {
103 %B = add ubyte %A, 16 ; Turn this into a XOR
104 %C = and ubyte %B, 16 ; Only one bit set
108 int %test17(int %A) {
110 %C = add int %B, 1 ; == sub int 0, %A
114 ubyte %test18(ubyte %A) {
115 %B = xor ubyte %A, 255
116 %C = add ubyte %B, 17 ; == sub ubyte 16, %A
120 int %test19(bool %C) {
121 %A = select bool %C, int 1000, int 10
126 int %test20(int %x) {
127 %tmp.2 = xor int %x, -2147483648
128 ;; Add of sign bit -> xor of sign bit.
129 %tmp.4 = add int %tmp.2, -2147483648
133 bool %test21(uint %x) {
135 %y = seteq uint %t, 123
139 int %test22(uint %V) {
140 %V2 = add uint %V, 10
141 switch uint %V2, label %Default [
153 int %test23(bool %C, int %a) {
155 br bool %C, label %endif, label %else
161 %b.0 = phi int [ 0, %entry ], [ 1, %else ]
162 %tmp.4 = add int %b.0, 1
166 int %test24(int %A) {
168 %C = shl int %B, ubyte 1
173 long %test25(long %Y) {
174 %tmp.4 = shl long %Y, ubyte 2
175 %tmp.12 = shl long %Y, ubyte 2
176 %tmp.8 = add long %tmp.4, %tmp.12 ;; Y << 3
180 int %test26(int %A, int %B) {
186 int %test27(bool %C, int %X, int %Y) {
189 %C = select bool %C, int %A, int %B ;; Fold add through select.
194 int %test28(int %X) {
195 %Y = add int %X, 1234
200 uint %test29(uint %X, uint %x) {
201 %tmp.2 = sub uint %X, %x
202 %tmp.2.mask = and uint %tmp.2, 63 ; <uint> [#uses=1]
203 %tmp.6 = add uint %tmp.2.mask, %x ; <uint> [#uses=1]
204 %tmp.7 = and uint %tmp.6, 63 ; <uint> [#uses=1]
205 %tmp.9 = and uint %tmp.2, 4294967232 ; <uint> [#uses=1]
206 %tmp.10 = or uint %tmp.7, %tmp.9 ; <uint> [#uses=1]
210 long %test30(long %x) {
211 %tmp.2 = xor long %x, -9223372036854775808
212 ;; Add of sign bit -> xor of sign bit.
213 %tmp.4 = add long %tmp.2, -9223372036854775808