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