New testcase for instcombine
[oota-llvm.git] / test / Transforms / InstCombine / add.ll
1 ; 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
6 ; RUN: if as < %s | opt -instcombine -die | dis | grep add
7 ; RUN: then exit 1
8 ; RUN: else exit 0
9 ; RUN: fi
10
11 implementation
12
13 int "test1"(int %A)
14 begin
15         %B = add int %A, 0
16         ret int %B
17 end
18
19 int "test2"(int %A)
20 begin
21         %B = add int %A, 5
22         %C = add int %B, -5
23         ret int %C
24 end
25
26 int "test3"(int %A)
27 begin
28         %B = add int %A, 5
29         %C = sub int %B, 5   ;; This should get converted to an add
30         ret int %C
31 end
32
33 int "test4"(int %A, int %B) {
34         %C = sub int 0, %A
35         %D = add int %B, %C      ; D = B + -A = B - A
36         ret int %D
37 }
38
39 int "test5"(int %A, int %B) {
40         %C = sub int 0, %A
41         %D = add int %C, %B      ; D = -A + B = B - A
42         ret int %D
43 }
44