2002-04-18 17:35:39 +00:00
|
|
|
; This test makes sure that add instructions are properly eliminated.
|
|
|
|
;
|
|
|
|
; This also tests that a subtract with a constant is properly converted
|
|
|
|
; to a add w/negative constant
|
|
|
|
|
2003-06-28 23:32:04 +00:00
|
|
|
; RUN: as < %s | opt -instcombine -die | dis | not grep add
|
2002-04-18 17:35:39 +00:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2003-02-18 19:43:53 +00:00
|
|
|
int %test1(int %A) {
|
2002-04-18 17:35:39 +00:00
|
|
|
%B = add int %A, 0
|
|
|
|
ret int %B
|
2003-02-18 19:43:53 +00:00
|
|
|
}
|
2002-04-18 17:35:39 +00:00
|
|
|
|
2003-02-18 19:43:53 +00:00
|
|
|
int %test2(int %A) {
|
2002-04-18 17:35:39 +00:00
|
|
|
%B = add int %A, 5
|
|
|
|
%C = add int %B, -5
|
|
|
|
ret int %C
|
2003-02-18 19:43:53 +00:00
|
|
|
}
|
2002-04-18 17:35:39 +00:00
|
|
|
|
2003-02-18 19:43:53 +00:00
|
|
|
int %test3(int %A) {
|
2002-04-18 17:35:39 +00:00
|
|
|
%B = add int %A, 5
|
|
|
|
%C = sub int %B, 5 ;; This should get converted to an add
|
|
|
|
ret int %C
|
2003-02-18 19:43:53 +00:00
|
|
|
}
|
2002-04-18 17:35:39 +00:00
|
|
|
|
2003-02-18 19:43:21 +00:00
|
|
|
int %test4(int %A, int %B) {
|
2002-05-06 16:44:53 +00:00
|
|
|
%C = sub int 0, %A
|
|
|
|
%D = add int %B, %C ; D = B + -A = B - A
|
|
|
|
ret int %D
|
|
|
|
}
|
|
|
|
|
2003-02-18 19:43:21 +00:00
|
|
|
int %test5(int %A, int %B) {
|
2002-05-06 16:44:53 +00:00
|
|
|
%C = sub int 0, %A
|
|
|
|
%D = add int %C, %B ; D = -A + B = B - A
|
|
|
|
ret int %D
|
|
|
|
}
|
|
|
|
|
2003-02-18 19:55:31 +00:00
|
|
|
int %test6(int %A) {
|
|
|
|
%B = mul int 7, %A
|
|
|
|
%C = add int %B, %A ; C = 7*A+A == 8*A == A << 3
|
|
|
|
ret int %C
|
|
|
|
}
|
|
|
|
|
|
|
|
int %test7(int %A) {
|
|
|
|
%B = mul int 7, %A
|
|
|
|
%C = add int %A, %B ; C = A+7*A == 8*A == A << 3
|
|
|
|
ret int %C
|
|
|
|
}
|
|
|
|
|
2003-03-10 23:52:54 +00:00
|
|
|
int %test8(int %A, int %B) { ; (A & C1)+(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
|
|
|
|
%A1 = and int %A, 7
|
|
|
|
%B1 = and int %B, 128
|
|
|
|
%C = add int %A1, %B1
|
|
|
|
ret int %C
|
|
|
|
}
|
2003-03-11 00:10:59 +00:00
|
|
|
|