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