blob: 5ce807063d52842dc24a3392104a70edd62e3d55 [file] [log] [blame]
Chris Lattner74e95472002-05-06 05:43:36 +00001; This test makes sure that these instructions are properly eliminated.
2;
Reid Spencerd0e30dc2006-12-02 04:23:10 +00003; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep sh
Reid Spencer91948d42007-04-14 20:13:02 +00004; END.
Chris Lattner74e95472002-05-06 05:43:36 +00005
6implementation
7
Chris Lattner87301bc2003-03-10 18:20:53 +00008int %test1(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +00009 %B = shl int %A, ubyte 0
10 ret int %B
11}
12
Chris Lattner87301bc2003-03-10 18:20:53 +000013int %test2(ubyte %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000014 %B = shl int 0, ubyte %A
15 ret int %B
16}
17
Chris Lattner87301bc2003-03-10 18:20:53 +000018int %test3(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000019 %B = shr int %A, ubyte 0
20 ret int %B
21}
22
Chris Lattner87301bc2003-03-10 18:20:53 +000023int %test4(ubyte %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000024 %B = shr int 0, ubyte %A
25 ret int %B
26}
27
Chris Lattner87301bc2003-03-10 18:20:53 +000028uint %test5(uint %A) {
Chris Lattnerbcb81382002-05-06 16:11:31 +000029 %B = shr uint %A, ubyte 32 ;; shift all bits out
30 ret uint %B
Chris Lattner74e95472002-05-06 05:43:36 +000031}
32
Chris Lattnerd97f0542003-03-10 19:16:20 +000033uint %test5a(uint %A) {
34 %B = shl uint %A, ubyte 32 ;; shift all bits out
35 ret uint %B
36}
37
Chris Lattner025e58d2002-09-10 23:03:10 +000038uint %test6(uint %A) {
Chris Lattnerbcbac5e2003-08-13 04:20:06 +000039 %B = shl uint %A, ubyte 1 ;; convert to an mul instruction
40 %C = mul uint %B, 3
41 ret uint %C
Chris Lattner025e58d2002-09-10 23:03:10 +000042}
Chris Lattneree5c8a92002-10-08 16:10:35 +000043
44int %test7(ubyte %A) {
45 %B = shr int -1, ubyte %A ;; Always equal to -1
46 ret int %B
47}
Chris Lattnerd97f0542003-03-10 19:16:20 +000048
49ubyte %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
55ubyte %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
61ubyte %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
Chris Lattner9e2dc892003-07-24 18:38:09 +000067ubyte %test11(ubyte %A) { ;; (A >> 3) << 4 === (A & 0x1F) << 1
Chris Lattnerbcbac5e2003-08-13 04:20:06 +000068 %a = mul ubyte %A, 3
69 %B = shr ubyte %a, ubyte 3
Chris Lattnerd97f0542003-03-10 19:16:20 +000070 %C = shl ubyte %B, ubyte 4
71 ret ubyte %C
72}
73
Chris Lattner9e2dc892003-07-24 18:38:09 +000074int %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
80sbyte %test13(sbyte %A) { ;; (A >> 3) << 4 === (A & -8) * 2
Chris Lattnerbcbac5e2003-08-13 04:20:06 +000081 %a = mul sbyte %A, 3
82 %B = shr sbyte %a, ubyte 3
Chris Lattner9e2dc892003-07-24 18:38:09 +000083 %C = shl sbyte %B, ubyte 4
84 ret sbyte %C
85}
Chris Lattner699b9522003-08-12 21:20:49 +000086
87uint %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}
Chris Lattnere8c98de2003-08-12 21:22:51 +000093uint %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
Chris Lattner699b9522003-08-12 21:20:49 +000098}
Chris Lattner24cd6b92004-04-09 23:47:24 +000099
100int %test15(bool %C) {
101 %A = select bool %C, int 3, int 1
102 %V = shl int %A, ubyte 2
103 ret int %V
104}
105
106int %test15a(bool %C) {
107 %A = select bool %C, ubyte 3, ubyte 1
108 %V = shl int 64, ubyte %A
109 ret int %V
110}
111
Chris Lattner6a021582004-05-25 06:30:49 +0000112bool %test16(int %X) {
113 %tmp.3 = shr int %X, ubyte 4
114 %tmp.6 = and int %tmp.3, 1
115 %tmp.7 = setne int %tmp.6, 0 ;; X & 16 != 0
116 ret bool %tmp.7
117}
Chris Lattnerfbfb4d42004-09-27 16:21:26 +0000118
119bool %test17(uint %A) {
120 %B = shr uint %A, ubyte 3
121 %C = seteq uint %B, 1234
122 ret bool %C
123}
124
125bool %test18(ubyte %A) {
126 %B = shr ubyte %A, ubyte 7
127 %C = seteq ubyte %B, 123 ;; false
128 ret bool %C
129}
130
131bool %test19(int %A) {
132 %B = shr int %A, ubyte 2
133 %C = seteq int %B, 0 ;; (X & -4) == 0
134 ret bool %C
135}
136
137bool %test19a(int %A) {
138 %B = shr int %A, ubyte 2
139 %C = seteq int %B, -1 ;; (X & -4) == -4
140 ret bool %C
141}
142
143bool %test20(sbyte %A) {
144 %B = shr sbyte %A, ubyte 7
145 %C = seteq sbyte %B, 123 ;; false
146 ret bool %C
147}
Chris Lattner3dd0ae62004-09-28 18:18:35 +0000148
149bool %test21(ubyte %A) {
150 %B = shl ubyte %A, ubyte 4
151 %C = seteq ubyte %B, 128
152 ret bool %C
153}
154
155bool %test22(ubyte %A) {
156 %B = shl ubyte %A, ubyte 4
157 %C = seteq ubyte %B, 0
158 ret bool %C
159}
160
Chris Lattner1524489f2005-05-06 04:11:32 +0000161sbyte %test23(int %A) {
162 %B = shl int %A, ubyte 24 ;; casts not needed
163 %C = shr int %B, ubyte 24
164 %D = cast int %C to sbyte
165 ret sbyte %D
166}
Chris Lattner5140c152005-05-08 17:31:24 +0000167
168sbyte %test24(sbyte %X) {
169 %Y = and sbyte %X, -5 ; ~4
170 %Z = shl sbyte %Y, ubyte 5
171 %Q = shr sbyte %Z, ubyte 5
172 ret sbyte %Q
173}
174
Chris Lattner1813aab2005-09-18 05:10:39 +0000175uint %test25(uint %tmp.2, uint %AA) {
176 %x = shr uint %AA, ubyte 17
177 %tmp.3 = shr uint %tmp.2, ubyte 17 ; <uint> [#uses=1]
178 %tmp.5 = add uint %tmp.3, %x ; <uint> [#uses=1]
179 %tmp.6 = shl uint %tmp.5, ubyte 17 ; <uint> [#uses=1]
180 ret uint %tmp.6
181}
182
Chris Lattner60d30022006-01-06 07:48:28 +0000183int %test26(uint %A) { ;; handle casts between shifts.
184 %B = shr uint %A, ubyte 1
185 %C = cast uint %B to int
186 %D = shl int %C, ubyte 1
187 ret int %D
188}
189