blob: 28c517018e408e780f94037903ac51e554b4191d [file] [log] [blame]
Chris Lattner74e95472002-05-06 05:43:36 +00001; This test makes sure that these instructions are properly eliminated.
2;
3
Reid Spencerd0e30dc2006-12-02 04:23:10 +00004; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -disable-output &&
5; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep sh
Chris Lattner74e95472002-05-06 05:43:36 +00006
7implementation
8
Chris Lattner87301bc2003-03-10 18:20:53 +00009int %test1(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000010 %B = shl int %A, ubyte 0
11 ret int %B
12}
13
Chris Lattner87301bc2003-03-10 18:20:53 +000014int %test2(ubyte %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000015 %B = shl int 0, ubyte %A
16 ret int %B
17}
18
Chris Lattner87301bc2003-03-10 18:20:53 +000019int %test3(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000020 %B = shr int %A, ubyte 0
21 ret int %B
22}
23
Chris Lattner87301bc2003-03-10 18:20:53 +000024int %test4(ubyte %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000025 %B = shr int 0, ubyte %A
26 ret int %B
27}
28
Chris Lattner87301bc2003-03-10 18:20:53 +000029uint %test5(uint %A) {
Chris Lattnerbcb81382002-05-06 16:11:31 +000030 %B = shr uint %A, ubyte 32 ;; shift all bits out
31 ret uint %B
Chris Lattner74e95472002-05-06 05:43:36 +000032}
33
Chris Lattnerd97f0542003-03-10 19:16:20 +000034uint %test5a(uint %A) {
35 %B = shl uint %A, ubyte 32 ;; shift all bits out
36 ret uint %B
37}
38
Chris Lattner025e58d2002-09-10 23:03:10 +000039uint %test6(uint %A) {
Chris Lattnerbcbac5e2003-08-13 04:20:06 +000040 %B = shl uint %A, ubyte 1 ;; convert to an mul instruction
41 %C = mul uint %B, 3
42 ret uint %C
Chris Lattner025e58d2002-09-10 23:03:10 +000043}
Chris Lattneree5c8a92002-10-08 16:10:35 +000044
45int %test7(ubyte %A) {
46 %B = shr int -1, ubyte %A ;; Always equal to -1
47 ret int %B
48}
Chris Lattnerd97f0542003-03-10 19:16:20 +000049
50ubyte %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
56ubyte %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
62ubyte %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
Chris Lattner9e2dc892003-07-24 18:38:09 +000068ubyte %test11(ubyte %A) { ;; (A >> 3) << 4 === (A & 0x1F) << 1
Chris Lattnerbcbac5e2003-08-13 04:20:06 +000069 %a = mul ubyte %A, 3
70 %B = shr ubyte %a, ubyte 3
Chris Lattnerd97f0542003-03-10 19:16:20 +000071 %C = shl ubyte %B, ubyte 4
72 ret ubyte %C
73}
74
Chris Lattner9e2dc892003-07-24 18:38:09 +000075int %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
81sbyte %test13(sbyte %A) { ;; (A >> 3) << 4 === (A & -8) * 2
Chris Lattnerbcbac5e2003-08-13 04:20:06 +000082 %a = mul sbyte %A, 3
83 %B = shr sbyte %a, ubyte 3
Chris Lattner9e2dc892003-07-24 18:38:09 +000084 %C = shl sbyte %B, ubyte 4
85 ret sbyte %C
86}
Chris Lattner699b9522003-08-12 21:20:49 +000087
88uint %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}
Chris Lattnere8c98de2003-08-12 21:22:51 +000094uint %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
Chris Lattner699b9522003-08-12 21:20:49 +000099}
Chris Lattner24cd6b92004-04-09 23:47:24 +0000100
101int %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
107int %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
Chris Lattner6a021582004-05-25 06:30:49 +0000113bool %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}
Chris Lattnerfbfb4d42004-09-27 16:21:26 +0000119
120bool %test17(uint %A) {
121 %B = shr uint %A, ubyte 3
122 %C = seteq uint %B, 1234
123 ret bool %C
124}
125
126bool %test18(ubyte %A) {
127 %B = shr ubyte %A, ubyte 7
128 %C = seteq ubyte %B, 123 ;; false
129 ret bool %C
130}
131
132bool %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
138bool %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
144bool %test20(sbyte %A) {
145 %B = shr sbyte %A, ubyte 7
146 %C = seteq sbyte %B, 123 ;; false
147 ret bool %C
148}
Chris Lattner3dd0ae62004-09-28 18:18:35 +0000149
150bool %test21(ubyte %A) {
151 %B = shl ubyte %A, ubyte 4
152 %C = seteq ubyte %B, 128
153 ret bool %C
154}
155
156bool %test22(ubyte %A) {
157 %B = shl ubyte %A, ubyte 4
158 %C = seteq ubyte %B, 0
159 ret bool %C
160}
161
Chris Lattner1524489f2005-05-06 04:11:32 +0000162sbyte %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}
Chris Lattner5140c152005-05-08 17:31:24 +0000168
169sbyte %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
Chris Lattner1813aab2005-09-18 05:10:39 +0000176uint %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
Chris Lattner60d30022006-01-06 07:48:28 +0000184int %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