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