Add test for demorgans law with constants
[oota-llvm.git] / test / Transforms / InstCombine / sub.ll
1 ; This test makes sure that these instructions are properly eliminated.
2 ;
3
4 ; RUN: if as < %s | opt -instcombine -die | dis | grep sub | grep -v 'sub int %Cok, %Bok'
5 ; RUN: then exit 1
6 ; RUN: else exit 0
7 ; RUN: fi
8
9 implementation
10
11 int %test1(int %A) {
12         %B = sub int %A, %A    ; ISA constant 0
13         ret int %B
14 }
15
16 int %test2(int %A) {
17         %B = sub int %A, 0
18         ret int %B
19 }
20
21 int %test3(int %A) {
22         %B = sub int 0, %A       ; B = -A
23         %C = sub int 0, %B       ; C = -B = A
24         ret int %C
25 }
26
27 int %test4(int %A, int %x) {
28         %B = sub int 0, %A
29         %C = sub int %x, %B
30         ret int %C
31 }
32
33 int %test5(int %A, int %Bok, int %Cok) {
34         %D = sub int %Bok, %Cok
35         %E = sub int %A, %D
36         ret int %E
37 }
38
39 int %test6(int %A, int %B) {
40         %C = and int %A, %B   ; A - (A & B) => A & ~B
41         %D = sub int %A, %C
42         ret int %D
43 }
44
45 int %test7(int %A) {
46         %B = sub int -1, %A   ; B = ~A
47         ret int %B
48 }
49
50 int %test8(int %A) {
51         %B = mul int 9, %A
52         %C = sub int %B, %A      ; C = 9*A-A == A*8 == A << 3
53         ret int %C
54 }
55
56 int %test9(int %A) {
57         %B = mul int 3, %A
58         %C = sub int %A, %B      ; C = A-3*A == A*-2
59         ret int %C
60 }
61