e684d31ed3efbfdb7fe26fbd5f8f1df47243d547
[oota-llvm.git] / test / Transforms / InstCombine / mul.ll
1 ; This test makes sure that mul instructions are properly eliminated.
2 ;
3
4 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep mul
5
6 implementation
7
8 int %test1(int %A) {
9         %B = mul int %A, 1
10         ret int %B
11 }
12
13 int %test2(int %A) {
14         %B = mul int %A, 2   ; Should convert to an add instruction
15         ret int %B
16 }
17
18 int %test3(int %A) {
19         %B = mul int %A, 0   ; This should disappear entirely
20         ret int %B
21 }
22
23 double %test4(double %A) {
24         %B = mul double 1.0, %A   ; This is safe for FP
25         ret double %B
26 }
27
28 int %test5(int %A) {
29         %B = mul int %A, 8
30         ret int %B
31 }
32
33 ubyte %test6(ubyte %A) {
34         %B = mul ubyte %A, 8
35         %C = mul ubyte %B, 8
36         ret ubyte %C
37 }
38
39 int %test7(int %i) {
40         %tmp = mul int %i, -1   ; %tmp = sub 0, %i
41         ret int %tmp
42 }
43
44 ulong %test8(ulong %i) {
45         %j = mul ulong %i, 18446744073709551615 ; tmp = sub 0, %i
46         ret ulong %j
47 }
48
49 uint %test9(uint %i) {
50         %j = mul uint %i, 4294967295    ; %j = sub 0, %i
51         ret uint %j
52 }
53
54 uint %test10(int %a, uint %b) {
55         %c = setlt int %a, 0
56         %d = cast bool %c to uint
57         %e = mul uint %d, %b           ; e = b & (a >> 31)
58         ret uint %e
59 }
60
61 uint %test11(int %a, uint %b) {
62         %c = setle int %a, -1
63         %d = cast bool %c to uint
64         %e = mul uint %d, %b           ; e = b & (a >> 31)
65         ret uint %e
66 }
67