Add hasSideEffects=0 to some shift and rotate instructions. None of which are current...
[oota-llvm.git] / lib / Target / X86 / X86InstrShiftRotate.td
1 //===-- X86InstrShiftRotate.td - Shift and Rotate Instrs ---*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the shift and rotate instructions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 // FIXME: Someone needs to smear multipattern goodness all over this file.
15
16 let Defs = [EFLAGS] in {
17
18 let Constraints = "$src1 = $dst" in {
19 let Uses = [CL] in {
20 def SHL8rCL  : I<0xD2, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1),
21                  "shl{b}\t{%cl, $dst|$dst, CL}",
22                  [(set GR8:$dst, (shl GR8:$src1, CL))], IIC_SR>;
23 def SHL16rCL : I<0xD3, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
24                  "shl{w}\t{%cl, $dst|$dst, CL}",
25                  [(set GR16:$dst, (shl GR16:$src1, CL))], IIC_SR>, OpSize;
26 def SHL32rCL : I<0xD3, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
27                  "shl{l}\t{%cl, $dst|$dst, CL}",
28                  [(set GR32:$dst, (shl GR32:$src1, CL))], IIC_SR>;
29 def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
30                   "shl{q}\t{%cl, $dst|$dst, CL}",
31                   [(set GR64:$dst, (shl GR64:$src1, CL))], IIC_SR>;
32 } // Uses = [CL]
33
34 def SHL8ri   : Ii8<0xC0, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
35                    "shl{b}\t{$src2, $dst|$dst, $src2}",
36                    [(set GR8:$dst, (shl GR8:$src1, (i8 imm:$src2)))], IIC_SR>;
37                    
38 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
39 def SHL16ri  : Ii8<0xC1, MRM4r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
40                    "shl{w}\t{$src2, $dst|$dst, $src2}",
41                    [(set GR16:$dst, (shl GR16:$src1, (i8 imm:$src2)))], IIC_SR>,
42                    OpSize;
43 def SHL32ri  : Ii8<0xC1, MRM4r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
44                    "shl{l}\t{$src2, $dst|$dst, $src2}",
45                    [(set GR32:$dst, (shl GR32:$src1, (i8 imm:$src2)))], IIC_SR>;
46 def SHL64ri  : RIi8<0xC1, MRM4r, (outs GR64:$dst), 
47                     (ins GR64:$src1, i8imm:$src2),
48                     "shl{q}\t{$src2, $dst|$dst, $src2}",
49                     [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))],
50                     IIC_SR>;
51
52 // NOTE: We don't include patterns for shifts of a register by one, because
53 // 'add reg,reg' is cheaper (and we have a Pat pattern for shift-by-one).
54 let hasSideEffects = 0 in {
55 def SHL8r1   : I<0xD0, MRM4r, (outs GR8:$dst), (ins GR8:$src1),
56                  "shl{b}\t$dst", [], IIC_SR>;
57 def SHL16r1  : I<0xD1, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
58                  "shl{w}\t$dst", [], IIC_SR>, OpSize;
59 def SHL32r1  : I<0xD1, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
60                  "shl{l}\t$dst", [], IIC_SR>;
61 def SHL64r1  : RI<0xD1, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
62                  "shl{q}\t$dst", [], IIC_SR>;
63 } // hasSideEffects = 0
64 } // isConvertibleToThreeAddress = 1
65 } // Constraints = "$src = $dst"
66
67
68 // FIXME: Why do we need an explicit "Uses = [CL]" when the instr has a pattern
69 // using CL?
70 let Uses = [CL] in {
71 def SHL8mCL  : I<0xD2, MRM4m, (outs), (ins i8mem :$dst),
72                  "shl{b}\t{%cl, $dst|$dst, CL}",
73                  [(store (shl (loadi8 addr:$dst), CL), addr:$dst)], IIC_SR>;
74 def SHL16mCL : I<0xD3, MRM4m, (outs), (ins i16mem:$dst),
75                  "shl{w}\t{%cl, $dst|$dst, CL}",
76                  [(store (shl (loadi16 addr:$dst), CL), addr:$dst)], IIC_SR>,
77                  OpSize;
78 def SHL32mCL : I<0xD3, MRM4m, (outs), (ins i32mem:$dst),
79                  "shl{l}\t{%cl, $dst|$dst, CL}",
80                  [(store (shl (loadi32 addr:$dst), CL), addr:$dst)], IIC_SR>;
81 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
82                   "shl{q}\t{%cl, $dst|$dst, CL}",
83                   [(store (shl (loadi64 addr:$dst), CL), addr:$dst)], IIC_SR>;
84 }
85 def SHL8mi   : Ii8<0xC0, MRM4m, (outs), (ins i8mem :$dst, i8imm:$src),
86                    "shl{b}\t{$src, $dst|$dst, $src}",
87                 [(store (shl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)],
88                 IIC_SR>;
89 def SHL16mi  : Ii8<0xC1, MRM4m, (outs), (ins i16mem:$dst, i8imm:$src),
90                    "shl{w}\t{$src, $dst|$dst, $src}",
91                [(store (shl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)],
92                IIC_SR>,
93                    OpSize;
94 def SHL32mi  : Ii8<0xC1, MRM4m, (outs), (ins i32mem:$dst, i8imm:$src),
95                    "shl{l}\t{$src, $dst|$dst, $src}",
96                [(store (shl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)],
97                IIC_SR>;
98 def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
99                   "shl{q}\t{$src, $dst|$dst, $src}",
100                  [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)],
101                  IIC_SR>;
102
103 // Shift by 1
104 def SHL8m1   : I<0xD0, MRM4m, (outs), (ins i8mem :$dst),
105                  "shl{b}\t$dst",
106                 [(store (shl (loadi8 addr:$dst), (i8 1)), addr:$dst)],
107                 IIC_SR>;
108 def SHL16m1  : I<0xD1, MRM4m, (outs), (ins i16mem:$dst),
109                  "shl{w}\t$dst",
110                [(store (shl (loadi16 addr:$dst), (i8 1)), addr:$dst)],
111                IIC_SR>,
112                    OpSize;
113 def SHL32m1  : I<0xD1, MRM4m, (outs), (ins i32mem:$dst),
114                  "shl{l}\t$dst",
115                [(store (shl (loadi32 addr:$dst), (i8 1)), addr:$dst)],
116                IIC_SR>;
117 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
118                   "shl{q}\t$dst",
119                  [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)],
120                  IIC_SR>;
121
122 let Constraints = "$src1 = $dst" in {
123 let Uses = [CL] in {
124 def SHR8rCL  : I<0xD2, MRM5r, (outs GR8 :$dst), (ins GR8 :$src1),
125                  "shr{b}\t{%cl, $dst|$dst, CL}",
126                  [(set GR8:$dst, (srl GR8:$src1, CL))], IIC_SR>;
127 def SHR16rCL : I<0xD3, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
128                  "shr{w}\t{%cl, $dst|$dst, CL}",
129                  [(set GR16:$dst, (srl GR16:$src1, CL))], IIC_SR>, OpSize;
130 def SHR32rCL : I<0xD3, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
131                  "shr{l}\t{%cl, $dst|$dst, CL}",
132                  [(set GR32:$dst, (srl GR32:$src1, CL))], IIC_SR>;
133 def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
134                   "shr{q}\t{%cl, $dst|$dst, CL}",
135                   [(set GR64:$dst, (srl GR64:$src1, CL))], IIC_SR>;
136 }
137
138 def SHR8ri   : Ii8<0xC0, MRM5r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
139                    "shr{b}\t{$src2, $dst|$dst, $src2}",
140                    [(set GR8:$dst, (srl GR8:$src1, (i8 imm:$src2)))], IIC_SR>;
141 def SHR16ri  : Ii8<0xC1, MRM5r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
142                    "shr{w}\t{$src2, $dst|$dst, $src2}",
143                    [(set GR16:$dst, (srl GR16:$src1, (i8 imm:$src2)))],
144                    IIC_SR>, OpSize;
145 def SHR32ri  : Ii8<0xC1, MRM5r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
146                    "shr{l}\t{$src2, $dst|$dst, $src2}",
147                    [(set GR32:$dst, (srl GR32:$src1, (i8 imm:$src2)))],
148                    IIC_SR>;
149 def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
150                   "shr{q}\t{$src2, $dst|$dst, $src2}",
151                   [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))], IIC_SR>;
152
153 // Shift right by 1
154 def SHR8r1   : I<0xD0, MRM5r, (outs GR8:$dst), (ins GR8:$src1),
155                  "shr{b}\t$dst",
156                  [(set GR8:$dst, (srl GR8:$src1, (i8 1)))], IIC_SR>;
157 def SHR16r1  : I<0xD1, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
158                  "shr{w}\t$dst",
159                  [(set GR16:$dst, (srl GR16:$src1, (i8 1)))], IIC_SR>, OpSize;
160 def SHR32r1  : I<0xD1, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
161                  "shr{l}\t$dst",
162                  [(set GR32:$dst, (srl GR32:$src1, (i8 1)))], IIC_SR>;
163 def SHR64r1  : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
164                  "shr{q}\t$dst",
165                  [(set GR64:$dst, (srl GR64:$src1, (i8 1)))], IIC_SR>;
166 } // Constraints = "$src = $dst"
167
168
169 let Uses = [CL] in {
170 def SHR8mCL  : I<0xD2, MRM5m, (outs), (ins i8mem :$dst),
171                  "shr{b}\t{%cl, $dst|$dst, CL}",
172                  [(store (srl (loadi8 addr:$dst), CL), addr:$dst)], IIC_SR>;
173 def SHR16mCL : I<0xD3, MRM5m, (outs), (ins i16mem:$dst),
174                  "shr{w}\t{%cl, $dst|$dst, CL}",
175                  [(store (srl (loadi16 addr:$dst), CL), addr:$dst)], IIC_SR>,
176                  OpSize;
177 def SHR32mCL : I<0xD3, MRM5m, (outs), (ins i32mem:$dst),
178                  "shr{l}\t{%cl, $dst|$dst, CL}",
179                  [(store (srl (loadi32 addr:$dst), CL), addr:$dst)], IIC_SR>;
180 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
181                   "shr{q}\t{%cl, $dst|$dst, CL}",
182                   [(store (srl (loadi64 addr:$dst), CL), addr:$dst)], IIC_SR>;
183 }
184 def SHR8mi   : Ii8<0xC0, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src),
185                    "shr{b}\t{$src, $dst|$dst, $src}",
186                 [(store (srl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)],
187                 IIC_SR>;
188 def SHR16mi  : Ii8<0xC1, MRM5m, (outs), (ins i16mem:$dst, i8imm:$src),
189                    "shr{w}\t{$src, $dst|$dst, $src}",
190                [(store (srl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)],
191                IIC_SR>,
192                    OpSize;
193 def SHR32mi  : Ii8<0xC1, MRM5m, (outs), (ins i32mem:$dst, i8imm:$src),
194                    "shr{l}\t{$src, $dst|$dst, $src}",
195                [(store (srl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)],
196                IIC_SR>;
197 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
198                   "shr{q}\t{$src, $dst|$dst, $src}",
199                  [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)],
200                  IIC_SR>;
201
202 // Shift by 1
203 def SHR8m1   : I<0xD0, MRM5m, (outs), (ins i8mem :$dst),
204                  "shr{b}\t$dst",
205                 [(store (srl (loadi8 addr:$dst), (i8 1)), addr:$dst)],
206                 IIC_SR>;
207 def SHR16m1  : I<0xD1, MRM5m, (outs), (ins i16mem:$dst),
208                  "shr{w}\t$dst",
209                [(store (srl (loadi16 addr:$dst), (i8 1)), addr:$dst)],
210                IIC_SR>,OpSize;
211 def SHR32m1  : I<0xD1, MRM5m, (outs), (ins i32mem:$dst),
212                  "shr{l}\t$dst",
213                [(store (srl (loadi32 addr:$dst), (i8 1)), addr:$dst)],
214                IIC_SR>;
215 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
216                   "shr{q}\t$dst",
217                  [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)],
218                  IIC_SR>;
219
220 let Constraints = "$src1 = $dst" in {
221 let Uses = [CL] in {
222 def SAR8rCL  : I<0xD2, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
223                  "sar{b}\t{%cl, $dst|$dst, CL}",
224                  [(set GR8:$dst, (sra GR8:$src1, CL))],
225                  IIC_SR>;
226 def SAR16rCL : I<0xD3, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
227                  "sar{w}\t{%cl, $dst|$dst, CL}",
228                  [(set GR16:$dst, (sra GR16:$src1, CL))],
229                  IIC_SR>, OpSize;
230 def SAR32rCL : I<0xD3, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
231                  "sar{l}\t{%cl, $dst|$dst, CL}",
232                  [(set GR32:$dst, (sra GR32:$src1, CL))],
233                  IIC_SR>;
234 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
235                  "sar{q}\t{%cl, $dst|$dst, CL}",
236                  [(set GR64:$dst, (sra GR64:$src1, CL))],
237                  IIC_SR>;
238 }
239
240 def SAR8ri   : Ii8<0xC0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
241                    "sar{b}\t{$src2, $dst|$dst, $src2}",
242                    [(set GR8:$dst, (sra GR8:$src1, (i8 imm:$src2)))],
243                    IIC_SR>;
244 def SAR16ri  : Ii8<0xC1, MRM7r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
245                    "sar{w}\t{$src2, $dst|$dst, $src2}",
246                    [(set GR16:$dst, (sra GR16:$src1, (i8 imm:$src2)))],
247                    IIC_SR>,
248                    OpSize;
249 def SAR32ri  : Ii8<0xC1, MRM7r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
250                    "sar{l}\t{$src2, $dst|$dst, $src2}",
251                    [(set GR32:$dst, (sra GR32:$src1, (i8 imm:$src2)))],
252                    IIC_SR>;
253 def SAR64ri  : RIi8<0xC1, MRM7r, (outs GR64:$dst),
254                     (ins GR64:$src1, i8imm:$src2),
255                     "sar{q}\t{$src2, $dst|$dst, $src2}",
256                     [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))],
257                     IIC_SR>;
258
259 // Shift by 1
260 def SAR8r1   : I<0xD0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
261                  "sar{b}\t$dst",
262                  [(set GR8:$dst, (sra GR8:$src1, (i8 1)))],
263                  IIC_SR>;
264 def SAR16r1  : I<0xD1, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
265                  "sar{w}\t$dst",
266                  [(set GR16:$dst, (sra GR16:$src1, (i8 1)))],
267                  IIC_SR>, OpSize;
268 def SAR32r1  : I<0xD1, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
269                  "sar{l}\t$dst",
270                  [(set GR32:$dst, (sra GR32:$src1, (i8 1)))],
271                  IIC_SR>;
272 def SAR64r1  : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
273                  "sar{q}\t$dst",
274                  [(set GR64:$dst, (sra GR64:$src1, (i8 1)))],
275                  IIC_SR>;
276 } // Constraints = "$src = $dst"
277
278
279 let Uses = [CL] in {
280 def SAR8mCL  : I<0xD2, MRM7m, (outs), (ins i8mem :$dst),
281                  "sar{b}\t{%cl, $dst|$dst, CL}",
282                  [(store (sra (loadi8 addr:$dst), CL), addr:$dst)],
283                  IIC_SR>;
284 def SAR16mCL : I<0xD3, MRM7m, (outs), (ins i16mem:$dst),
285                  "sar{w}\t{%cl, $dst|$dst, CL}",
286                  [(store (sra (loadi16 addr:$dst), CL), addr:$dst)],
287                  IIC_SR>, OpSize;
288 def SAR32mCL : I<0xD3, MRM7m, (outs), (ins i32mem:$dst), 
289                  "sar{l}\t{%cl, $dst|$dst, CL}",
290                  [(store (sra (loadi32 addr:$dst), CL), addr:$dst)],
291                  IIC_SR>;
292 def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst), 
293                  "sar{q}\t{%cl, $dst|$dst, CL}",
294                  [(store (sra (loadi64 addr:$dst), CL), addr:$dst)],
295                  IIC_SR>;
296 }
297 def SAR8mi   : Ii8<0xC0, MRM7m, (outs), (ins i8mem :$dst, i8imm:$src),
298                    "sar{b}\t{$src, $dst|$dst, $src}",
299                 [(store (sra (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)],
300                 IIC_SR>;
301 def SAR16mi  : Ii8<0xC1, MRM7m, (outs), (ins i16mem:$dst, i8imm:$src),
302                    "sar{w}\t{$src, $dst|$dst, $src}",
303                [(store (sra (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)],
304                IIC_SR>,
305                    OpSize;
306 def SAR32mi  : Ii8<0xC1, MRM7m, (outs), (ins i32mem:$dst, i8imm:$src),
307                    "sar{l}\t{$src, $dst|$dst, $src}",
308                [(store (sra (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)],
309                IIC_SR>;
310 def SAR64mi  : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
311                     "sar{q}\t{$src, $dst|$dst, $src}",
312                  [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)],
313                  IIC_SR>;
314
315 // Shift by 1
316 def SAR8m1   : I<0xD0, MRM7m, (outs), (ins i8mem :$dst),
317                  "sar{b}\t$dst",
318                 [(store (sra (loadi8 addr:$dst), (i8 1)), addr:$dst)],
319                 IIC_SR>;
320 def SAR16m1  : I<0xD1, MRM7m, (outs), (ins i16mem:$dst),
321                  "sar{w}\t$dst",
322                [(store (sra (loadi16 addr:$dst), (i8 1)), addr:$dst)],
323                IIC_SR>,
324                    OpSize;
325 def SAR32m1  : I<0xD1, MRM7m, (outs), (ins i32mem:$dst),
326                  "sar{l}\t$dst",
327                [(store (sra (loadi32 addr:$dst), (i8 1)), addr:$dst)],
328                IIC_SR>;
329 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
330                   "sar{q}\t$dst",
331                  [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)],
332                  IIC_SR>;
333
334 //===----------------------------------------------------------------------===//
335 // Rotate instructions
336 //===----------------------------------------------------------------------===//
337
338 let hasSideEffects = 0 in {
339 let Constraints = "$src1 = $dst" in {
340 def RCL8r1 : I<0xD0, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
341                "rcl{b}\t$dst", [], IIC_SR>;
342 def RCL8ri : Ii8<0xC0, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$cnt),
343                  "rcl{b}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>;
344 let Uses = [CL] in
345 def RCL8rCL : I<0xD2, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
346                 "rcl{b}\t{%cl, $dst|$dst, CL}", [], IIC_SR>;
347   
348 def RCL16r1 : I<0xD1, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
349                 "rcl{w}\t$dst", [], IIC_SR>, OpSize;
350 def RCL16ri : Ii8<0xC1, MRM2r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$cnt),
351                   "rcl{w}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>, OpSize;
352 let Uses = [CL] in
353 def RCL16rCL : I<0xD3, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
354                  "rcl{w}\t{%cl, $dst|$dst, CL}", [], IIC_SR>, OpSize;
355
356 def RCL32r1 : I<0xD1, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
357                 "rcl{l}\t$dst", [], IIC_SR>;
358 def RCL32ri : Ii8<0xC1, MRM2r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$cnt),
359                   "rcl{l}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>;
360 let Uses = [CL] in
361 def RCL32rCL : I<0xD3, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
362                  "rcl{l}\t{%cl, $dst|$dst, CL}", [], IIC_SR>;
363
364
365 def RCL64r1 : RI<0xD1, MRM2r, (outs GR64:$dst), (ins GR64:$src1),
366                  "rcl{q}\t$dst", [], IIC_SR>;
367 def RCL64ri : RIi8<0xC1, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$cnt),
368                    "rcl{q}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>;
369 let Uses = [CL] in
370 def RCL64rCL : RI<0xD3, MRM2r, (outs GR64:$dst), (ins GR64:$src1),
371                   "rcl{q}\t{%cl, $dst|$dst, CL}", [], IIC_SR>;
372
373
374 def RCR8r1 : I<0xD0, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
375                "rcr{b}\t$dst", [], IIC_SR>;
376 def RCR8ri : Ii8<0xC0, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$cnt),
377                  "rcr{b}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>;
378 let Uses = [CL] in
379 def RCR8rCL : I<0xD2, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
380                 "rcr{b}\t{%cl, $dst|$dst, CL}", [], IIC_SR>;
381   
382 def RCR16r1 : I<0xD1, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
383                 "rcr{w}\t$dst", [], IIC_SR>, OpSize;
384 def RCR16ri : Ii8<0xC1, MRM3r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$cnt),
385                   "rcr{w}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>, OpSize;
386 let Uses = [CL] in
387 def RCR16rCL : I<0xD3, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
388                  "rcr{w}\t{%cl, $dst|$dst, CL}", [], IIC_SR>, OpSize;
389
390 def RCR32r1 : I<0xD1, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
391                 "rcr{l}\t$dst", [], IIC_SR>;
392 def RCR32ri : Ii8<0xC1, MRM3r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$cnt),
393                   "rcr{l}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>;
394 let Uses = [CL] in
395 def RCR32rCL : I<0xD3, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
396                  "rcr{l}\t{%cl, $dst|$dst, CL}", [], IIC_SR>;
397                  
398 def RCR64r1 : RI<0xD1, MRM3r, (outs GR64:$dst), (ins GR64:$src1),
399                  "rcr{q}\t$dst", [], IIC_SR>;
400 def RCR64ri : RIi8<0xC1, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$cnt),
401                    "rcr{q}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>;
402 let Uses = [CL] in
403 def RCR64rCL : RI<0xD3, MRM3r, (outs GR64:$dst), (ins GR64:$src1),
404                   "rcr{q}\t{%cl, $dst|$dst, CL}", [], IIC_SR>;
405
406 } // Constraints = "$src = $dst"
407
408 def RCL8m1 : I<0xD0, MRM2m, (outs), (ins i8mem:$dst),
409                "rcl{b}\t$dst", [], IIC_SR>;
410 def RCL8mi : Ii8<0xC0, MRM2m, (outs), (ins i8mem:$dst, i8imm:$cnt),
411                  "rcl{b}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>;
412 def RCL16m1 : I<0xD1, MRM2m, (outs), (ins i16mem:$dst),
413                 "rcl{w}\t$dst", [], IIC_SR>, OpSize;
414 def RCL16mi : Ii8<0xC1, MRM2m, (outs), (ins i16mem:$dst, i8imm:$cnt),
415                   "rcl{w}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>, OpSize;
416 def RCL32m1 : I<0xD1, MRM2m, (outs), (ins i32mem:$dst),
417                 "rcl{l}\t$dst", [], IIC_SR>;
418 def RCL32mi : Ii8<0xC1, MRM2m, (outs), (ins i32mem:$dst, i8imm:$cnt),
419                   "rcl{l}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>;
420 def RCL64m1 : RI<0xD1, MRM2m, (outs), (ins i64mem:$dst),
421                  "rcl{q}\t$dst", [], IIC_SR>;
422 def RCL64mi : RIi8<0xC1, MRM2m, (outs), (ins i64mem:$dst, i8imm:$cnt),
423                    "rcl{q}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>;
424
425 def RCR8m1 : I<0xD0, MRM3m, (outs), (ins i8mem:$dst),
426                "rcr{b}\t$dst", [], IIC_SR>;
427 def RCR8mi : Ii8<0xC0, MRM3m, (outs), (ins i8mem:$dst, i8imm:$cnt),
428                  "rcr{b}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>;
429 def RCR16m1 : I<0xD1, MRM3m, (outs), (ins i16mem:$dst),
430                 "rcr{w}\t$dst", [], IIC_SR>, OpSize;
431 def RCR16mi : Ii8<0xC1, MRM3m, (outs), (ins i16mem:$dst, i8imm:$cnt),
432                   "rcr{w}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>, OpSize;
433 def RCR32m1 : I<0xD1, MRM3m, (outs), (ins i32mem:$dst),
434                 "rcr{l}\t$dst", [], IIC_SR>;
435 def RCR32mi : Ii8<0xC1, MRM3m, (outs), (ins i32mem:$dst, i8imm:$cnt),
436                   "rcr{l}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>;
437 def RCR64m1 : RI<0xD1, MRM3m, (outs), (ins i64mem:$dst),
438                  "rcr{q}\t$dst", [], IIC_SR>;
439 def RCR64mi : RIi8<0xC1, MRM3m, (outs), (ins i64mem:$dst, i8imm:$cnt),
440                    "rcr{q}\t{$cnt, $dst|$dst, $cnt}", [], IIC_SR>;
441
442 let Uses = [CL] in {
443 def RCL8mCL : I<0xD2, MRM2m, (outs), (ins i8mem:$dst),
444                 "rcl{b}\t{%cl, $dst|$dst, CL}", [], IIC_SR>;
445 def RCL16mCL : I<0xD3, MRM2m, (outs), (ins i16mem:$dst),
446                  "rcl{w}\t{%cl, $dst|$dst, CL}", [], IIC_SR>, OpSize;
447 def RCL32mCL : I<0xD3, MRM2m, (outs), (ins i32mem:$dst),
448                  "rcl{l}\t{%cl, $dst|$dst, CL}", [], IIC_SR>;
449 def RCL64mCL : RI<0xD3, MRM2m, (outs), (ins i64mem:$dst),
450                   "rcl{q}\t{%cl, $dst|$dst, CL}", [], IIC_SR>;
451
452 def RCR8mCL : I<0xD2, MRM3m, (outs), (ins i8mem:$dst),
453                 "rcr{b}\t{%cl, $dst|$dst, CL}", [], IIC_SR>;
454 def RCR16mCL : I<0xD3, MRM3m, (outs), (ins i16mem:$dst),
455                  "rcr{w}\t{%cl, $dst|$dst, CL}", [], IIC_SR>, OpSize;
456 def RCR32mCL : I<0xD3, MRM3m, (outs), (ins i32mem:$dst),
457                  "rcr{l}\t{%cl, $dst|$dst, CL}", [], IIC_SR>;
458 def RCR64mCL : RI<0xD3, MRM3m, (outs), (ins i64mem:$dst),
459                   "rcr{q}\t{%cl, $dst|$dst, CL}", [], IIC_SR>;
460 }
461 } // hasSideEffects = 0
462
463 let Constraints = "$src1 = $dst" in {
464 // FIXME: provide shorter instructions when imm8 == 1
465 let Uses = [CL] in {
466 def ROL8rCL  : I<0xD2, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
467                  "rol{b}\t{%cl, $dst|$dst, CL}",
468                  [(set GR8:$dst, (rotl GR8:$src1, CL))], IIC_SR>;
469 def ROL16rCL : I<0xD3, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
470                  "rol{w}\t{%cl, $dst|$dst, CL}",
471                  [(set GR16:$dst, (rotl GR16:$src1, CL))], IIC_SR>, OpSize;
472 def ROL32rCL : I<0xD3, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
473                  "rol{l}\t{%cl, $dst|$dst, CL}",
474                  [(set GR32:$dst, (rotl GR32:$src1, CL))], IIC_SR>;
475 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
476                   "rol{q}\t{%cl, $dst|$dst, CL}",
477                   [(set GR64:$dst, (rotl GR64:$src1, CL))], IIC_SR>;
478 }
479
480 def ROL8ri   : Ii8<0xC0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
481                    "rol{b}\t{$src2, $dst|$dst, $src2}",
482                    [(set GR8:$dst, (rotl GR8:$src1, (i8 imm:$src2)))], IIC_SR>;
483 def ROL16ri  : Ii8<0xC1, MRM0r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
484                    "rol{w}\t{$src2, $dst|$dst, $src2}",
485                    [(set GR16:$dst, (rotl GR16:$src1, (i8 imm:$src2)))],
486                    IIC_SR>, 
487                    OpSize;
488 def ROL32ri  : Ii8<0xC1, MRM0r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
489                    "rol{l}\t{$src2, $dst|$dst, $src2}",
490                    [(set GR32:$dst, (rotl GR32:$src1, (i8 imm:$src2)))],
491                    IIC_SR>;
492 def ROL64ri  : RIi8<0xC1, MRM0r, (outs GR64:$dst), 
493                     (ins GR64:$src1, i8imm:$src2),
494                     "rol{q}\t{$src2, $dst|$dst, $src2}",
495                     [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))],
496                     IIC_SR>;
497
498 // Rotate by 1
499 def ROL8r1   : I<0xD0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
500                  "rol{b}\t$dst",
501                  [(set GR8:$dst, (rotl GR8:$src1, (i8 1)))],
502                  IIC_SR>;
503 def ROL16r1  : I<0xD1, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
504                  "rol{w}\t$dst",
505                  [(set GR16:$dst, (rotl GR16:$src1, (i8 1)))],
506                  IIC_SR>, OpSize;
507 def ROL32r1  : I<0xD1, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
508                  "rol{l}\t$dst",
509                  [(set GR32:$dst, (rotl GR32:$src1, (i8 1)))],
510                  IIC_SR>;
511 def ROL64r1  : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
512                   "rol{q}\t$dst",
513                   [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))],
514                   IIC_SR>;
515 } // Constraints = "$src = $dst"
516
517 let Uses = [CL] in {
518 def ROL8mCL  : I<0xD2, MRM0m, (outs), (ins i8mem :$dst),
519                  "rol{b}\t{%cl, $dst|$dst, CL}",
520                  [(store (rotl (loadi8 addr:$dst), CL), addr:$dst)],
521                  IIC_SR>;
522 def ROL16mCL : I<0xD3, MRM0m, (outs), (ins i16mem:$dst),
523                  "rol{w}\t{%cl, $dst|$dst, CL}",
524                  [(store (rotl (loadi16 addr:$dst), CL), addr:$dst)],
525                  IIC_SR>, OpSize;
526 def ROL32mCL : I<0xD3, MRM0m, (outs), (ins i32mem:$dst),
527                  "rol{l}\t{%cl, $dst|$dst, CL}",
528                  [(store (rotl (loadi32 addr:$dst), CL), addr:$dst)],
529                  IIC_SR>;
530 def ROL64mCL :  RI<0xD3, MRM0m, (outs), (ins i64mem:$dst),
531                    "rol{q}\t{%cl, $dst|$dst, %cl}",
532                    [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)],
533                    IIC_SR>;
534 }
535 def ROL8mi   : Ii8<0xC0, MRM0m, (outs), (ins i8mem :$dst, i8imm:$src1),
536                    "rol{b}\t{$src1, $dst|$dst, $src1}",
537                [(store (rotl (loadi8 addr:$dst), (i8 imm:$src1)), addr:$dst)],
538                IIC_SR>;
539 def ROL16mi  : Ii8<0xC1, MRM0m, (outs), (ins i16mem:$dst, i8imm:$src1),
540                    "rol{w}\t{$src1, $dst|$dst, $src1}",
541               [(store (rotl (loadi16 addr:$dst), (i8 imm:$src1)), addr:$dst)],
542               IIC_SR>,
543                    OpSize;
544 def ROL32mi  : Ii8<0xC1, MRM0m, (outs), (ins i32mem:$dst, i8imm:$src1),
545                    "rol{l}\t{$src1, $dst|$dst, $src1}",
546               [(store (rotl (loadi32 addr:$dst), (i8 imm:$src1)), addr:$dst)],
547               IIC_SR>;
548 def ROL64mi  : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src1),
549                     "rol{q}\t{$src1, $dst|$dst, $src1}",
550                 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src1)), addr:$dst)],
551                 IIC_SR>;
552
553 // Rotate by 1
554 def ROL8m1   : I<0xD0, MRM0m, (outs), (ins i8mem :$dst),
555                  "rol{b}\t$dst",
556                [(store (rotl (loadi8 addr:$dst), (i8 1)), addr:$dst)],
557                IIC_SR>;
558 def ROL16m1  : I<0xD1, MRM0m, (outs), (ins i16mem:$dst),
559                  "rol{w}\t$dst",
560               [(store (rotl (loadi16 addr:$dst), (i8 1)), addr:$dst)],
561               IIC_SR>,
562                    OpSize;
563 def ROL32m1  : I<0xD1, MRM0m, (outs), (ins i32mem:$dst),
564                  "rol{l}\t$dst",
565               [(store (rotl (loadi32 addr:$dst), (i8 1)), addr:$dst)],
566               IIC_SR>;
567 def ROL64m1  : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
568                  "rol{q}\t$dst",
569                [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)],
570                IIC_SR>;
571
572 let Constraints = "$src1 = $dst" in {
573 let Uses = [CL] in {
574 def ROR8rCL  : I<0xD2, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
575                  "ror{b}\t{%cl, $dst|$dst, CL}",
576                  [(set GR8:$dst, (rotr GR8:$src1, CL))], IIC_SR>;
577 def ROR16rCL : I<0xD3, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
578                  "ror{w}\t{%cl, $dst|$dst, CL}",
579                  [(set GR16:$dst, (rotr GR16:$src1, CL))], IIC_SR>, OpSize;
580 def ROR32rCL : I<0xD3, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
581                  "ror{l}\t{%cl, $dst|$dst, CL}",
582                  [(set GR32:$dst, (rotr GR32:$src1, CL))], IIC_SR>;
583 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
584                   "ror{q}\t{%cl, $dst|$dst, CL}",
585                   [(set GR64:$dst, (rotr GR64:$src1, CL))], IIC_SR>;
586 }
587
588 def ROR8ri   : Ii8<0xC0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
589                    "ror{b}\t{$src2, $dst|$dst, $src2}",
590                    [(set GR8:$dst, (rotr GR8:$src1, (i8 imm:$src2)))], IIC_SR>;
591 def ROR16ri  : Ii8<0xC1, MRM1r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
592                    "ror{w}\t{$src2, $dst|$dst, $src2}",
593                    [(set GR16:$dst, (rotr GR16:$src1, (i8 imm:$src2)))],
594                    IIC_SR>, 
595                    OpSize;
596 def ROR32ri  : Ii8<0xC1, MRM1r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
597                    "ror{l}\t{$src2, $dst|$dst, $src2}",
598                    [(set GR32:$dst, (rotr GR32:$src1, (i8 imm:$src2)))],
599                    IIC_SR>;
600 def ROR64ri  : RIi8<0xC1, MRM1r, (outs GR64:$dst), 
601                     (ins GR64:$src1, i8imm:$src2),
602                     "ror{q}\t{$src2, $dst|$dst, $src2}",
603                     [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))],
604                     IIC_SR>;
605
606 // Rotate by 1
607 def ROR8r1   : I<0xD0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
608                  "ror{b}\t$dst",
609                  [(set GR8:$dst, (rotr GR8:$src1, (i8 1)))],
610                  IIC_SR>;
611 def ROR16r1  : I<0xD1, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
612                  "ror{w}\t$dst",
613                  [(set GR16:$dst, (rotr GR16:$src1, (i8 1)))],
614                  IIC_SR>, OpSize;
615 def ROR32r1  : I<0xD1, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
616                  "ror{l}\t$dst",
617                  [(set GR32:$dst, (rotr GR32:$src1, (i8 1)))],
618                  IIC_SR>;
619 def ROR64r1  : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
620                   "ror{q}\t$dst",
621                   [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))],
622                   IIC_SR>;
623 } // Constraints = "$src = $dst"
624
625 let Uses = [CL] in {
626 def ROR8mCL  : I<0xD2, MRM1m, (outs), (ins i8mem :$dst),
627                  "ror{b}\t{%cl, $dst|$dst, CL}",
628                  [(store (rotr (loadi8 addr:$dst), CL), addr:$dst)],
629                  IIC_SR>;
630 def ROR16mCL : I<0xD3, MRM1m, (outs), (ins i16mem:$dst),
631                  "ror{w}\t{%cl, $dst|$dst, CL}",
632                  [(store (rotr (loadi16 addr:$dst), CL), addr:$dst)],
633                  IIC_SR>, OpSize;
634 def ROR32mCL : I<0xD3, MRM1m, (outs), (ins i32mem:$dst), 
635                  "ror{l}\t{%cl, $dst|$dst, CL}",
636                  [(store (rotr (loadi32 addr:$dst), CL), addr:$dst)],
637                  IIC_SR>;
638 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst), 
639                   "ror{q}\t{%cl, $dst|$dst, CL}",
640                   [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)],
641                   IIC_SR>;
642 }
643 def ROR8mi   : Ii8<0xC0, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
644                    "ror{b}\t{$src, $dst|$dst, $src}",
645                [(store (rotr (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)],
646                IIC_SR>;
647 def ROR16mi  : Ii8<0xC1, MRM1m, (outs), (ins i16mem:$dst, i8imm:$src),
648                    "ror{w}\t{$src, $dst|$dst, $src}",
649               [(store (rotr (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)],
650               IIC_SR>,
651                    OpSize;
652 def ROR32mi  : Ii8<0xC1, MRM1m, (outs), (ins i32mem:$dst, i8imm:$src),
653                    "ror{l}\t{$src, $dst|$dst, $src}",
654               [(store (rotr (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)],
655               IIC_SR>;
656 def ROR64mi  : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
657                     "ror{q}\t{$src, $dst|$dst, $src}",
658                 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)],
659                 IIC_SR>;
660
661 // Rotate by 1
662 def ROR8m1   : I<0xD0, MRM1m, (outs), (ins i8mem :$dst),
663                  "ror{b}\t$dst",
664                [(store (rotr (loadi8 addr:$dst), (i8 1)), addr:$dst)],
665                IIC_SR>;
666 def ROR16m1  : I<0xD1, MRM1m, (outs), (ins i16mem:$dst),
667                  "ror{w}\t$dst",
668               [(store (rotr (loadi16 addr:$dst), (i8 1)), addr:$dst)],
669               IIC_SR>,
670                    OpSize;
671 def ROR32m1  : I<0xD1, MRM1m, (outs), (ins i32mem:$dst),
672                  "ror{l}\t$dst",
673               [(store (rotr (loadi32 addr:$dst), (i8 1)), addr:$dst)],
674               IIC_SR>;
675 def ROR64m1  : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
676                  "ror{q}\t$dst",
677                [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)],
678                IIC_SR>;
679
680
681 //===----------------------------------------------------------------------===//
682 // Double shift instructions (generalizations of rotate)
683 //===----------------------------------------------------------------------===//
684
685 let Constraints = "$src1 = $dst" in {
686
687 let Uses = [CL] in {
688 def SHLD16rrCL : I<0xA5, MRMDestReg, (outs GR16:$dst), 
689                    (ins GR16:$src1, GR16:$src2),
690                    "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
691                    [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2, CL))],
692                     IIC_SHD16_REG_CL>,
693                    TB, OpSize;
694 def SHRD16rrCL : I<0xAD, MRMDestReg, (outs GR16:$dst), 
695                    (ins GR16:$src1, GR16:$src2),
696                    "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
697                    [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2, CL))],
698                     IIC_SHD16_REG_CL>,
699                    TB, OpSize;
700 def SHLD32rrCL : I<0xA5, MRMDestReg, (outs GR32:$dst), 
701                    (ins GR32:$src1, GR32:$src2),
702                    "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
703                    [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2, CL))],
704                     IIC_SHD32_REG_CL>, TB;
705 def SHRD32rrCL : I<0xAD, MRMDestReg, (outs GR32:$dst),
706                    (ins GR32:$src1, GR32:$src2),
707                    "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
708                    [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2, CL))],
709                    IIC_SHD32_REG_CL>, TB;
710 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), 
711                     (ins GR64:$src1, GR64:$src2),
712                     "shld{q}\t{%cl, $src2, $dst|$dst, $src2, CL}",
713                     [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))],
714                     IIC_SHD64_REG_CL>, 
715                     TB;
716 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), 
717                     (ins GR64:$src1, GR64:$src2),
718                     "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, CL}",
719                     [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))],
720                     IIC_SHD64_REG_CL>, 
721                     TB;
722 }
723
724 let isCommutable = 1 in {  // These instructions commute to each other.
725 def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
726                      (outs GR16:$dst), 
727                      (ins GR16:$src1, GR16:$src2, i8imm:$src3),
728                      "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
729                      [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2,
730                                       (i8 imm:$src3)))], IIC_SHD16_REG_IM>,
731                      TB, OpSize;
732 def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
733                      (outs GR16:$dst), 
734                      (ins GR16:$src1, GR16:$src2, i8imm:$src3),
735                      "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
736                      [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2,
737                                       (i8 imm:$src3)))], IIC_SHD16_REG_IM>,
738                      TB, OpSize;
739 def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
740                      (outs GR32:$dst), 
741                      (ins GR32:$src1, GR32:$src2, i8imm:$src3),
742                      "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
743                      [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2,
744                                       (i8 imm:$src3)))], IIC_SHD32_REG_IM>,
745                  TB;
746 def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
747                      (outs GR32:$dst), 
748                      (ins GR32:$src1, GR32:$src2, i8imm:$src3),
749                      "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
750                      [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2,
751                                       (i8 imm:$src3)))], IIC_SHD32_REG_IM>,
752                  TB;
753 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
754                       (outs GR64:$dst), 
755                       (ins GR64:$src1, GR64:$src2, i8imm:$src3),
756                       "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
757                       [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
758                                        (i8 imm:$src3)))], IIC_SHD64_REG_IM>,
759                  TB;
760 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
761                       (outs GR64:$dst), 
762                       (ins GR64:$src1, GR64:$src2, i8imm:$src3),
763                       "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
764                       [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
765                                        (i8 imm:$src3)))], IIC_SHD64_REG_IM>,
766                  TB;
767 }
768 } // Constraints = "$src = $dst"
769
770 let Uses = [CL] in {
771 def SHLD16mrCL : I<0xA5, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
772                    "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
773                    [(store (X86shld (loadi16 addr:$dst), GR16:$src2, CL),
774                      addr:$dst)], IIC_SHD16_MEM_CL>, TB, OpSize;
775 def SHRD16mrCL : I<0xAD, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
776                   "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
777                   [(store (X86shrd (loadi16 addr:$dst), GR16:$src2, CL),
778                     addr:$dst)], IIC_SHD16_MEM_CL>, TB, OpSize;
779
780 def SHLD32mrCL : I<0xA5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
781                    "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
782                    [(store (X86shld (loadi32 addr:$dst), GR32:$src2, CL),
783                      addr:$dst)], IIC_SHD32_MEM_CL>, TB;
784 def SHRD32mrCL : I<0xAD, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
785                   "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
786                   [(store (X86shrd (loadi32 addr:$dst), GR32:$src2, CL),
787                     addr:$dst)], IIC_SHD32_MEM_CL>, TB;
788                     
789 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
790                     "shld{q}\t{%cl, $src2, $dst|$dst, $src2, CL}",
791                     [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
792                       addr:$dst)], IIC_SHD64_MEM_CL>, TB;
793 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
794                     "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, CL}",
795                     [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
796                       addr:$dst)], IIC_SHD64_MEM_CL>, TB;
797 }
798
799 def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
800                     (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
801                     "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
802                     [(store (X86shld (loadi16 addr:$dst), GR16:$src2,
803                                       (i8 imm:$src3)), addr:$dst)],
804                                       IIC_SHD16_MEM_IM>,
805                     TB, OpSize;
806 def SHRD16mri8 : Ii8<0xAC, MRMDestMem, 
807                      (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
808                      "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
809                     [(store (X86shrd (loadi16 addr:$dst), GR16:$src2,
810                                       (i8 imm:$src3)), addr:$dst)],
811                                       IIC_SHD16_MEM_IM>,
812                      TB, OpSize;
813
814 def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
815                     (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
816                     "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
817                     [(store (X86shld (loadi32 addr:$dst), GR32:$src2,
818                                       (i8 imm:$src3)), addr:$dst)],
819                                       IIC_SHD32_MEM_IM>,
820                     TB;
821 def SHRD32mri8 : Ii8<0xAC, MRMDestMem, 
822                      (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
823                      "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
824                      [(store (X86shrd (loadi32 addr:$dst), GR32:$src2,
825                                        (i8 imm:$src3)), addr:$dst)],
826                                        IIC_SHD32_MEM_IM>,
827                      TB;
828
829 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
830                       (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
831                       "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
832                       [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
833                                        (i8 imm:$src3)), addr:$dst)],
834                                        IIC_SHD64_MEM_IM>,
835                  TB;
836 def SHRD64mri8 : RIi8<0xAC, MRMDestMem, 
837                       (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
838                       "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
839                       [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
840                                        (i8 imm:$src3)), addr:$dst)],
841                                        IIC_SHD64_MEM_IM>,
842                  TB;
843
844 } // Defs = [EFLAGS]
845
846 def ROT32L2R_imm8  : SDNodeXForm<imm, [{
847   // Convert a ROTL shamt to a ROTR shamt on 32-bit integer.
848   return getI8Imm(32 - N->getZExtValue());
849 }]>;
850
851 def ROT64L2R_imm8  : SDNodeXForm<imm, [{
852   // Convert a ROTL shamt to a ROTR shamt on 64-bit integer.
853   return getI8Imm(64 - N->getZExtValue());
854 }]>;
855
856 multiclass bmi_rotate<string asm, RegisterClass RC, X86MemOperand x86memop> {
857 let neverHasSideEffects = 1 in {
858   def ri : Ii8<0xF0, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, i8imm:$src2),
859                !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
860                []>, TAXD, VEX;
861   let mayLoad = 1 in
862   def mi : Ii8<0xF0, MRMSrcMem, (outs RC:$dst),
863                (ins x86memop:$src1, i8imm:$src2),
864                !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
865                []>, TAXD, VEX;
866 }
867 }
868
869 multiclass bmi_shift<string asm, RegisterClass RC, X86MemOperand x86memop> {
870 let neverHasSideEffects = 1 in {
871   def rr : I<0xF7, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
872              !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>,
873              VEX_4VOp3;
874   let mayLoad = 1 in
875   def rm : I<0xF7, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src1, RC:$src2),
876              !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>,
877              VEX_4VOp3;
878 }
879 }
880
881 let Predicates = [HasBMI2] in {
882   defm RORX32 : bmi_rotate<"rorx{l}", GR32, i32mem>;
883   defm RORX64 : bmi_rotate<"rorx{q}", GR64, i64mem>, VEX_W;
884   defm SARX32 : bmi_shift<"sarx{l}", GR32, i32mem>, T8XS;
885   defm SARX64 : bmi_shift<"sarx{q}", GR64, i64mem>, T8XS, VEX_W;
886   defm SHRX32 : bmi_shift<"shrx{l}", GR32, i32mem>, T8XD;
887   defm SHRX64 : bmi_shift<"shrx{q}", GR64, i64mem>, T8XD, VEX_W;
888   defm SHLX32 : bmi_shift<"shlx{l}", GR32, i32mem>, T8, OpSize;
889   defm SHLX64 : bmi_shift<"shlx{q}", GR64, i64mem>, T8, OpSize, VEX_W;
890
891   // Prefer RORX which is non-destructive and doesn't update EFLAGS.
892   let AddedComplexity = 10 in {
893     def : Pat<(rotl GR32:$src, (i8 imm:$shamt)),
894               (RORX32ri GR32:$src, (ROT32L2R_imm8 imm:$shamt))>;
895     def : Pat<(rotl GR64:$src, (i8 imm:$shamt)),
896               (RORX64ri GR64:$src, (ROT64L2R_imm8 imm:$shamt))>;
897   }
898
899   def : Pat<(rotl (loadi32 addr:$src), (i8 imm:$shamt)),
900             (RORX32mi addr:$src, (ROT32L2R_imm8 imm:$shamt))>;
901   def : Pat<(rotl (loadi64 addr:$src), (i8 imm:$shamt)),
902             (RORX64mi addr:$src, (ROT64L2R_imm8 imm:$shamt))>;
903
904   // Prefer SARX/SHRX/SHLX over SAR/SHR/SHL with variable shift BUT not
905   // immedidate shift, i.e. the following code is considered better
906   //
907   //  mov %edi, %esi
908   //  shl $imm, %esi
909   //  ... %edi, ...
910   //
911   // than
912   //
913   //  movb $imm, %sil
914   //  shlx %sil, %edi, %esi
915   //  ... %edi, ...
916   //
917   let AddedComplexity = 1 in {
918     def : Pat<(sra GR32:$src1, GR8:$src2),
919               (SARX32rr GR32:$src1,
920                         (INSERT_SUBREG
921                           (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
922     def : Pat<(sra GR64:$src1, GR8:$src2),
923               (SARX64rr GR64:$src1,
924                         (INSERT_SUBREG
925                           (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
926
927     def : Pat<(srl GR32:$src1, GR8:$src2),
928               (SHRX32rr GR32:$src1,
929                         (INSERT_SUBREG
930                           (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
931     def : Pat<(srl GR64:$src1, GR8:$src2),
932               (SHRX64rr GR64:$src1,
933                         (INSERT_SUBREG
934                           (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
935
936     def : Pat<(shl GR32:$src1, GR8:$src2),
937               (SHLX32rr GR32:$src1,
938                         (INSERT_SUBREG
939                           (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
940     def : Pat<(shl GR64:$src1, GR8:$src2),
941               (SHLX64rr GR64:$src1,
942                         (INSERT_SUBREG
943                           (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
944   }
945
946   // Patterns on SARXrm/SHRXrm/SHLXrm are explicitly omitted to favor
947   //
948   //  mov (%ecx), %esi
949   //  shl $imm, $esi
950   //
951   // over
952   //
953   //  movb $imm %al
954   //  shlx %al, (%ecx), %esi
955   //
956   // As SARXrr/SHRXrr/SHLXrr is favored on variable shift, the peephole
957   // optimization will fold them into SARXrm/SHRXrm/SHLXrm if possible.
958 }