Add test for demorgans law with constants
[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         %B = add int %A, 0
15         ret int %B
16 }
17
18 int %test2(int %A) {
19         %B = add int %A, 5
20         %C = add int %B, -5
21         ret int %C
22 }
23
24 int %test3(int %A) {
25         %B = add int %A, 5
26         %C = sub int %B, 5   ;; This should get converted to an add
27         ret int %C
28 }
29
30 int %test4(int %A, int %B) {
31         %C = sub int 0, %A
32         %D = add int %B, %C      ; D = B + -A = B - A
33         ret int %D
34 }
35
36 int %test5(int %A, int %B) {
37         %C = sub int 0, %A
38         %D = add int %C, %B      ; D = -A + B = B - A
39         ret int %D
40 }
41
42 int %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
48 int %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