blob: 70bb85a6c849c0e9514f1ef1b806accf5e25e9c1 [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