1 //===-- X86InstrShiftRotate.td - Shift and Rotate Instrs ---*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the shift and rotate instructions.
12 //===----------------------------------------------------------------------===//
14 // FIXME: Someone needs to smear multipattern goodness all over this file.
16 let Defs = [EFLAGS] in {
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
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)))]>;
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)))]>,
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)))]>,
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
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),
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),
64 } // hasSideEffects = 0
65 } // Constraints = "$src = $dst", SchedRW
67 // FIXME: Why do we need an explicit "Uses = [CL]" when the instr has a pattern
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)]>,
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)]>,
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]>;
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)]>,
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)]>,
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]>;
105 def SHL8m1 : I<0xD0, MRM4m, (outs), (ins i8mem :$dst),
107 [(store (shl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
108 def SHL16m1 : I<0xD1, MRM4m, (outs), (ins i16mem:$dst),
110 [(store (shl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
112 def SHL32m1 : I<0xD1, MRM4m, (outs), (ins i32mem:$dst),
114 [(store (shl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>,
116 def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
118 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>,
119 Requires<[In64BitMode]>;
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))]>;
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)))]>,
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)))]>,
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)))]>;
154 def SHR8r1 : I<0xD0, MRM5r, (outs GR8:$dst), (ins GR8:$src1),
156 [(set GR8:$dst, (srl GR8:$src1, (i8 1)))]>;
157 def SHR16r1 : I<0xD1, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
159 [(set GR16:$dst, (srl GR16:$src1, (i8 1)))]>, OpSize16;
160 def SHR32r1 : I<0xD1, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
162 [(set GR32:$dst, (srl GR32:$src1, (i8 1)))]>, OpSize32;
163 def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
165 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
166 } // Constraints = "$src = $dst", SchedRW
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)]>,
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)]>,
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]>;
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)]>,
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)]>,
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]>;
205 def SHR8m1 : I<0xD0, MRM5m, (outs), (ins i8mem :$dst),
207 [(store (srl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
208 def SHR16m1 : I<0xD1, MRM5m, (outs), (ins i16mem:$dst),
210 [(store (srl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
212 def SHR32m1 : I<0xD1, MRM5m, (outs), (ins i32mem:$dst),
214 [(store (srl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>,
216 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
218 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>,
219 Requires<[In64BitMode]>;
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))]>,
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))]>,
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))]>;
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)))]>,
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)))]>,
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)))]>;
257 def SAR8r1 : I<0xD0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
259 [(set GR8:$dst, (sra GR8:$src1, (i8 1)))]>;
260 def SAR16r1 : I<0xD1, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
262 [(set GR16:$dst, (sra GR16:$src1, (i8 1)))]>, OpSize16;
263 def SAR32r1 : I<0xD1, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
265 [(set GR32:$dst, (sra GR32:$src1, (i8 1)))]>, OpSize32;
266 def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
268 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
269 } // Constraints = "$src = $dst", SchedRW
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)]>,
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)]>,
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]>;
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)]>,
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)]>,
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]>;
308 def SAR8m1 : I<0xD0, MRM7m, (outs), (ins i8mem :$dst),
310 [(store (sra (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
311 def SAR16m1 : I<0xD1, MRM7m, (outs), (ins i16mem:$dst),
313 [(store (sra (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
315 def SAR32m1 : I<0xD1, MRM7m, (outs), (ins i32mem:$dst),
317 [(store (sra (loadi32 addr:$dst), (i8 1)), addr:$dst)]>,
319 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
321 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>,
322 Requires<[In64BitMode]>;
325 //===----------------------------------------------------------------------===//
326 // Rotate instructions
327 //===----------------------------------------------------------------------===//
329 let hasSideEffects = 0 in {
330 let Constraints = "$src1 = $dst", SchedRW = [WriteRotate] in {
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]
343 let Uses = [EFLAGS] in {
344 def RCL8r1 : I<0xD0, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
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),
358 def RCL64ri : RIi8<0xC1, MRM2r, (outs GR64:$dst), (ins GR64:$src1, u8imm:$cnt),
359 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
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]
373 let Uses = [EFLAGS] in {
374 def RCR8r1 : I<0xD0, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
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),
388 def RCR64ri : RIi8<0xC1, MRM3r, (outs GR64:$dst), (ins GR64:$src1, u8imm:$cnt),
389 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
392 } // Constraints = "$src = $dst"
394 let SchedRW = [WriteRotateLd, WriteRMW], mayStore = 1 in {
395 let Uses = [EFLAGS] in {
396 def RCL8m1 : I<0xD0, MRM2m, (outs), (ins i8mem:$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]>;
414 def RCR8m1 : I<0xD0, MRM3m, (outs), (ins i8mem:$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]>;
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]>;
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]
455 } // hasSideEffects = 0
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))]>;
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)))]>;
489 def ROL8r1 : I<0xD0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
491 [(set GR8:$dst, (rotl GR8:$src1, (i8 1)))]>;
492 def ROL16r1 : I<0xD1, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
494 [(set GR16:$dst, (rotl GR16:$src1, (i8 1)))]>, OpSize16;
495 def ROL32r1 : I<0xD1, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
497 [(set GR32:$dst, (rotl GR32:$src1, (i8 1)))]>, OpSize32;
498 def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
500 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
501 } // Constraints = "$src = $dst", SchedRW
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]>;
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)]>,
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)]>,
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]>;
537 def ROL8m1 : I<0xD0, MRM0m, (outs), (ins i8mem :$dst),
539 [(store (rotl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
540 def ROL16m1 : I<0xD1, MRM0m, (outs), (ins i16mem:$dst),
542 [(store (rotl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
544 def ROL32m1 : I<0xD1, MRM0m, (outs), (ins i32mem:$dst),
546 [(store (rotl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>,
548 def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
550 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>,
551 Requires<[In64BitMode]>;
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))]>;
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)))]>,
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)))]>,
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)))]>;
587 def ROR8r1 : I<0xD0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
589 [(set GR8:$dst, (rotl GR8:$src1, (i8 7)))]>;
590 def ROR16r1 : I<0xD1, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
592 [(set GR16:$dst, (rotl GR16:$src1, (i8 15)))]>, OpSize16;
593 def ROR32r1 : I<0xD1, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
595 [(set GR32:$dst, (rotl GR32:$src1, (i8 31)))]>, OpSize32;
596 def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
598 [(set GR64:$dst, (rotl GR64:$src1, (i8 63)))]>;
599 } // Constraints = "$src = $dst", SchedRW
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]>;
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)]>,
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)]>,
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]>;
635 def ROR8m1 : I<0xD0, MRM1m, (outs), (ins i8mem :$dst),
637 [(store (rotl (loadi8 addr:$dst), (i8 7)), addr:$dst)]>;
638 def ROR16m1 : I<0xD1, MRM1m, (outs), (ins i16mem:$dst),
640 [(store (rotl (loadi16 addr:$dst), (i8 15)), addr:$dst)]>,
642 def ROR32m1 : I<0xD1, MRM1m, (outs), (ins i32mem:$dst),
644 [(store (rotl (loadi32 addr:$dst), (i8 31)), addr:$dst)]>,
646 def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
648 [(store (rotl (loadi64 addr:$dst), (i8 63)), addr:$dst)]>,
649 Requires<[In64BitMode]>;
653 //===----------------------------------------------------------------------===//
654 // Double shift instructions (generalizations of rotate)
655 //===----------------------------------------------------------------------===//
657 let Constraints = "$src1 = $dst" in {
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))]>,
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))]>,
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))]>,
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))]>,
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))]>,
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))]>,
692 let isCommutable = 1, SchedRW = [WriteSHDrri] in { // These instructions commute to each other.
693 def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
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,
700 def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
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,
707 def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
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,
714 def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
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,
721 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
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,
728 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
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,
736 } // Constraints = "$src = $dst"
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;
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;
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),
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),
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)]>,
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)]>,
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)]>,
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)]>,
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)]>,
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)]>,
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)>;
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));
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));
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]>;
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]>;
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]>;
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,
855 ReadDefault, ReadDefault, ReadDefault, ReadDefault,
858 WriteShift.ReadAfterFold]>;
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;
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))>;
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))>;
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
895 // shlx %sil, %edi, %esi
898 let AddedComplexity = 1 in {
899 def : Pat<(sra GR32:$src1, GR8:$src2),
900 (SARX32rr GR32:$src1,
902 (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
903 def : Pat<(sra GR64:$src1, GR8:$src2),
904 (SARX64rr GR64:$src1,
906 (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
908 def : Pat<(srl GR32:$src1, GR8:$src2),
909 (SHRX32rr GR32:$src1,
911 (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
912 def : Pat<(srl GR64:$src1, GR8:$src2),
913 (SHRX64rr GR64:$src1,
915 (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
917 def : Pat<(shl GR32:$src1, GR8:$src2),
918 (SHLX32rr GR32:$src1,
920 (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
921 def : Pat<(shl GR64:$src1, GR8:$src2),
922 (SHLX64rr GR64:$src1,
924 (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
934 // shlx %al, (%ecx), %esi
936 // This priority is enforced by IsProfitableToFoldLoad.
937 def : Pat<(sra (loadi32 addr:$src1), GR8:$src2),
938 (SARX32rm addr:$src1,
940 (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
941 def : Pat<(sra (loadi64 addr:$src1), GR8:$src2),
942 (SARX64rm addr:$src1,
944 (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
946 def : Pat<(srl (loadi32 addr:$src1), GR8:$src2),
947 (SHRX32rm addr:$src1,
949 (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
950 def : Pat<(srl (loadi64 addr:$src1), GR8:$src2),
951 (SHRX64rm addr:$src1,
953 (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
955 def : Pat<(shl (loadi32 addr:$src1), GR8:$src2),
956 (SHLX32rm addr:$src1,
958 (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
959 def : Pat<(shl (loadi64 addr:$src1), GR8:$src2),
960 (SHLX64rm addr:$src1,
962 (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;