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