Use the llvm-upgrade program to upgrade llvm assembly.
[oota-llvm.git] / test / Transforms / InstCombine / shift.ll
1 ; This test makes sure that these instructions are properly eliminated.
2 ;
3
4 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -disable-output &&
5 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep sh
6
7 implementation
8
9 int %test1(int %A) {
10         %B = shl int %A, ubyte 0
11         ret int %B
12 }
13
14 int %test2(ubyte %A) {
15         %B = shl int 0, ubyte %A
16         ret int %B
17 }
18
19 int %test3(int %A) {
20         %B = shr int %A, ubyte 0
21         ret int %B
22 }
23
24 int %test4(ubyte %A) {
25         %B = shr int 0, ubyte %A
26         ret int %B
27 }
28
29 uint %test5(uint %A) {
30         %B = shr uint %A, ubyte 32  ;; shift all bits out
31         ret uint %B
32 }
33
34 uint %test5a(uint %A) {
35         %B = shl uint %A, ubyte 32  ;; shift all bits out
36         ret uint %B
37 }
38
39 uint %test6(uint %A) {
40         %B = shl uint %A, ubyte 1   ;; convert to an mul instruction
41         %C = mul uint %B, 3
42         ret uint %C
43 }
44
45 int %test7(ubyte %A) {
46         %B = shr int -1, ubyte %A   ;; Always equal to -1
47         ret int %B
48 }
49
50 ubyte %test8(ubyte %A) {              ;; (A << 5) << 3 === A << 8 == 0
51         %B = shl ubyte %A, ubyte 5
52         %C = shl ubyte %B, ubyte 3
53         ret ubyte %C
54 }
55
56 ubyte %test9(ubyte %A) {              ;; (A << 7) >> 7 === A & 1
57         %B = shl ubyte %A, ubyte 7
58         %C = shr ubyte %B, ubyte 7
59         ret ubyte %C
60 }
61
62 ubyte %test10(ubyte %A) {              ;; (A >> 7) << 7 === A & 128
63         %B = shr ubyte %A, ubyte 7
64         %C = shl ubyte %B, ubyte 7
65         ret ubyte %C
66 }
67
68 ubyte %test11(ubyte %A) {              ;; (A >> 3) << 4 === (A & 0x1F) << 1
69         %a = mul ubyte %A, 3
70         %B = shr ubyte %a, ubyte 3
71         %C = shl ubyte %B, ubyte 4
72         ret ubyte %C
73 }
74
75 int %test12(int %A) {
76         %B = shr int %A, ubyte 8    ;; (A >> 8) << 8 === A & -256
77         %C = shl int %B, ubyte 8
78         ret int %C
79 }
80
81 sbyte %test13(sbyte %A) {           ;; (A >> 3) << 4 === (A & -8) * 2
82         %a = mul sbyte %A, 3
83         %B = shr sbyte %a, ubyte 3
84         %C = shl sbyte %B, ubyte 4
85         ret sbyte %C
86 }
87
88 uint %test14(uint %A) {
89         %B = shr uint %A, ubyte 4
90         %C = or uint %B, 1234
91         %D = shl uint %C, ubyte 4   ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
92         ret uint %D
93 }
94 uint %test14a(uint %A) {
95         %B = shl uint %A, ubyte 4
96         %C = and uint %B, 1234
97         %D = shr uint %C, ubyte 4   ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
98         ret uint %D
99 }
100
101 int %test15(bool %C) {
102         %A = select bool %C, int 3, int 1
103         %V = shl int %A, ubyte 2
104         ret int %V
105 }
106
107 int %test15a(bool %C) {
108         %A = select bool %C, ubyte 3, ubyte 1
109         %V = shl int 64, ubyte %A
110         ret int %V
111 }
112
113 bool %test16(int %X) {
114         %tmp.3 = shr int %X, ubyte 4
115         %tmp.6 = and int %tmp.3, 1
116         %tmp.7 = setne int %tmp.6, 0  ;; X & 16 != 0
117         ret bool %tmp.7
118 }
119
120 bool %test17(uint %A) {
121         %B = shr uint %A, ubyte 3
122         %C = seteq uint %B, 1234
123         ret bool %C
124 }
125
126 bool %test18(ubyte %A) {
127         %B = shr ubyte %A, ubyte 7
128         %C = seteq ubyte %B, 123    ;; false
129         ret bool %C
130 }
131
132 bool %test19(int %A) {
133         %B = shr int %A, ubyte 2
134         %C = seteq int %B, 0        ;; (X & -4) == 0
135         ret bool %C
136 }
137
138 bool %test19a(int %A) {
139         %B = shr int %A, ubyte 2
140         %C = seteq int %B, -1        ;; (X & -4) == -4
141         ret bool %C
142 }
143
144 bool %test20(sbyte %A) {
145         %B = shr sbyte %A, ubyte 7
146         %C = seteq sbyte %B, 123    ;; false
147         ret bool %C
148 }
149
150 bool %test21(ubyte %A) {
151         %B = shl ubyte %A, ubyte 4
152         %C = seteq ubyte %B, 128
153         ret bool %C
154 }
155
156 bool %test22(ubyte %A) {
157         %B = shl ubyte %A, ubyte 4
158         %C = seteq ubyte %B, 0
159         ret bool %C
160 }
161
162 sbyte %test23(int %A) {
163         %B = shl int %A, ubyte 24  ;; casts not needed
164         %C = shr int %B, ubyte 24
165         %D = cast int %C to sbyte
166         ret sbyte %D
167 }
168
169 sbyte %test24(sbyte %X) {
170         %Y = and sbyte %X, -5 ; ~4
171         %Z = shl sbyte %Y, ubyte 5
172         %Q = shr sbyte %Z, ubyte 5
173         ret sbyte %Q
174 }
175
176 uint %test25(uint %tmp.2, uint %AA) {
177         %x = shr uint %AA, ubyte 17
178         %tmp.3 = shr uint %tmp.2, ubyte 17              ; <uint> [#uses=1]
179         %tmp.5 = add uint %tmp.3, %x            ; <uint> [#uses=1]
180         %tmp.6 = shl uint %tmp.5, ubyte 17              ; <uint> [#uses=1]
181         ret uint %tmp.6
182 }
183
184 int %test26(uint %A) { ;; handle casts between shifts.
185         %B = shr uint %A, ubyte 1
186         %C = cast uint %B to int
187         %D = shl int %C, ubyte 1
188         ret int %D
189 }
190