blob: 19fa6261cdd51a71f95a94e334a065ef2c11ee79 [file] [log] [blame]
Chris Lattner7bfa8b62002-04-18 17:35:39 +00001; This test makes sure that add instructions are properly eliminated.
2;
3; This also tests that a subtract with a constant is properly converted
4; to a add w/negative constant
5
Chris Lattnerf6f95d02002-08-02 19:27:58 +00006; RUN: if as < %s | opt -instcombine -die | dis | grep add
Chris Lattner7bfa8b62002-04-18 17:35:39 +00007; RUN: then exit 1
8; RUN: else exit 0
9; RUN: fi
10
11implementation
12
Chris Lattnerde293ee2003-02-18 19:43:53 +000013int %test1(int %A) {
Chris Lattner7bfa8b62002-04-18 17:35:39 +000014 %B = add int %A, 0
15 ret int %B
Chris Lattnerde293ee2003-02-18 19:43:53 +000016}
Chris Lattner7bfa8b62002-04-18 17:35:39 +000017
Chris Lattnerde293ee2003-02-18 19:43:53 +000018int %test2(int %A) {
Chris Lattner7bfa8b62002-04-18 17:35:39 +000019 %B = add int %A, 5
20 %C = add int %B, -5
21 ret int %C
Chris Lattnerde293ee2003-02-18 19:43:53 +000022}
Chris Lattner7bfa8b62002-04-18 17:35:39 +000023
Chris Lattnerde293ee2003-02-18 19:43:53 +000024int %test3(int %A) {
Chris Lattner7bfa8b62002-04-18 17:35:39 +000025 %B = add int %A, 5
26 %C = sub int %B, 5 ;; This should get converted to an add
27 ret int %C
Chris Lattnerde293ee2003-02-18 19:43:53 +000028}
Chris Lattner7bfa8b62002-04-18 17:35:39 +000029
Chris Lattner2ae37b02003-02-18 19:43:21 +000030int %test4(int %A, int %B) {
Chris Lattnere0c3fbb2002-05-06 16:44:53 +000031 %C = sub int 0, %A
32 %D = add int %B, %C ; D = B + -A = B - A
33 ret int %D
34}
35
Chris Lattner2ae37b02003-02-18 19:43:21 +000036int %test5(int %A, int %B) {
Chris Lattnere0c3fbb2002-05-06 16:44:53 +000037 %C = sub int 0, %A
38 %D = add int %C, %B ; D = -A + B = B - A
39 ret int %D
40}
41
Chris Lattner39593402003-02-18 19:55:31 +000042int %test6(int %A) {
43 %B = mul int 7, %A
44 %C = add int %B, %A ; C = 7*A+A == 8*A == A << 3
45 ret int %C
46}
47
48int %test7(int %A) {
49 %B = mul int 7, %A
50 %C = add int %A, %B ; C = A+7*A == 8*A == A << 3
51 ret int %C
52}
53