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