Add some tests for difficult reassociation cases
[oota-llvm.git] / test / Transforms / InstCombine / add.ll
1 ; This test makes sure that add instructions are properly eliminated.
2
3 ; RUN: as < %s | opt -instcombine -die | dis | grep -v OK | not grep add
4
5 implementation
6
7 int %test1(int %A) {
8         %B = add int %A, 0
9         ret int %B
10 }
11
12 int %test2(int %A) {
13         %B = add int %A, 5
14         %C = add int %B, -5
15         ret int %C
16 }
17
18 int %test3(int %A) {
19         %B = add int %A, 5
20         %C = sub int %B, 5   ;; This should get converted to an add
21         ret int %C
22 }
23
24 int %test4(int %A, int %B) {
25         %C = sub int 0, %A
26         %D = add int %B, %C      ; D = B + -A = B - A
27         ret int %D
28 }
29
30 int %test5(int %A, int %B) {
31         %C = sub int 0, %A
32         %D = add int %C, %B      ; D = -A + B = B - A
33         ret int %D
34 }
35
36 int %test6(int %A) {
37         %B = mul int 7, %A
38         %C = add int %B, %A      ; C = 7*A+A == 8*A == A << 3
39         ret int %C
40 }
41
42 int %test7(int %A) {
43         %B = mul int 7, %A
44         %C = add int %A, %B      ; C = A+7*A == 8*A == A << 3
45         ret int %C
46 }
47
48 int %test8(int %A, int %B) {     ; (A & C1)+(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
49         %A1 = and int %A, 7
50         %B1 = and int %B, 128
51         %C = add int %A1, %B1
52         ret int %C
53 }
54
55 int %test9(int %A) {
56         %B = shl int %A, ubyte 4
57         %C = add int %B, %B      ; === shl int %A, 5
58         ret int %C
59 }
60
61 bool %test10(ubyte %A, ubyte %b) {
62         %B = add ubyte %A, %b
63         %c = setne ubyte %B, 0    ; === A != -b
64         ret bool %c
65 }
66
67 bool %test11(ubyte %A) {
68         %B = add ubyte %A, 255
69         %c = setne ubyte %B, 0    ; === A != 1
70         ret bool %c
71 }
72
73 int %test12(int %A, int %B) {
74         %C_OK = add int %B, %A       ; Should be transformed into shl A, 1
75         br label %X
76 X:
77         %D = add int %C_OK, %A 
78         ret int %D
79 }
80
81 int %test13(int %A, int %B, int %C) {
82         %D_OK = add int %A, %B
83         %E_OK = add int %D_OK, %C
84         %F = add int %E_OK, %A        ;; shl A, 1
85         ret int %F
86 }
87
88 uint %test14(uint %offset, uint %difference) {
89         %tmp.2 = and uint %difference, 3
90         %tmp.3_OK = add uint %tmp.2, %offset
91         %tmp.5.mask = and uint %difference, 4294967292
92         %tmp.8 = add uint %tmp.3_OK, %tmp.5.mask ; == add %offset, %difference
93         ret uint %tmp.8
94 }
95