new testcase
[oota-llvm.git] / test / Transforms / InstCombine / shift.ll
1 ; This test makes sure that these instructions are properly eliminated.
2 ;
3
4 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep sh
5
6 implementation
7
8 int %test1(int %A) {
9         %B = shl int %A, ubyte 0
10         ret int %B
11 }
12
13 int %test2(ubyte %A) {
14         %B = shl int 0, ubyte %A
15         ret int %B
16 }
17
18 int %test3(int %A) {
19         %B = shr int %A, ubyte 0
20         ret int %B
21 }
22
23 int %test4(ubyte %A) {
24         %B = shr int 0, ubyte %A
25         ret int %B
26 }
27
28 uint %test5(uint %A) {
29         %B = shr uint %A, ubyte 32  ;; shift all bits out
30         ret uint %B
31 }
32
33 uint %test5a(uint %A) {
34         %B = shl uint %A, ubyte 32  ;; shift all bits out
35         ret uint %B
36 }
37
38 uint %test6(uint %A) {
39         %B = shl uint %A, ubyte 1   ;; convert to an mul instruction
40         %C = mul uint %B, 3
41         ret uint %C
42 }
43
44 int %test7(ubyte %A) {
45         %B = shr int -1, ubyte %A   ;; Always equal to -1
46         ret int %B
47 }
48
49 ubyte %test8(ubyte %A) {              ;; (A << 5) << 3 === A << 8 == 0
50         %B = shl ubyte %A, ubyte 5
51         %C = shl ubyte %B, ubyte 3
52         ret ubyte %C
53 }
54
55 ubyte %test9(ubyte %A) {              ;; (A << 7) >> 7 === A & 1
56         %B = shl ubyte %A, ubyte 7
57         %C = shr ubyte %B, ubyte 7
58         ret ubyte %C
59 }
60
61 ubyte %test10(ubyte %A) {              ;; (A >> 7) << 7 === A & 128
62         %B = shr ubyte %A, ubyte 7
63         %C = shl ubyte %B, ubyte 7
64         ret ubyte %C
65 }
66
67 ubyte %test11(ubyte %A) {              ;; (A >> 3) << 4 === (A & 0x1F) << 1
68         %a = mul ubyte %A, 3
69         %B = shr ubyte %a, ubyte 3
70         %C = shl ubyte %B, ubyte 4
71         ret ubyte %C
72 }
73
74 int %test12(int %A) {
75         %B = shr int %A, ubyte 8    ;; (A >> 8) << 8 === A & -256
76         %C = shl int %B, ubyte 8
77         ret int %C
78 }
79
80 sbyte %test13(sbyte %A) {           ;; (A >> 3) << 4 === (A & -8) * 2
81         %a = mul sbyte %A, 3
82         %B = shr sbyte %a, ubyte 3
83         %C = shl sbyte %B, ubyte 4
84         ret sbyte %C
85 }
86
87 uint %test14(uint %A) {
88         %B = shr uint %A, ubyte 4
89         %C = or uint %B, 1234
90         %D = shl uint %C, ubyte 4   ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
91         ret uint %D
92 }
93 uint %test14a(uint %A) {
94         %B = shl uint %A, ubyte 4
95         %C = and uint %B, 1234
96         %D = shr uint %C, ubyte 4   ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
97         ret uint %D
98 }