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 {
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))]>;
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
68 let SchedRW = [WriteShiftLd, WriteRMW] in {
69 // FIXME: Why do we need an explicit "Uses = [CL]" when the instr has a pattern
72 def SHL8mCL : I<0xD2, MRM4m, (outs), (ins i8mem :$dst),
73 "shl{b}\t{%cl, $dst|$dst, cl}",
74 [(store (shl (loadi8 addr:$dst), CL), addr:$dst)]>;
75 def SHL16mCL : I<0xD3, MRM4m, (outs), (ins i16mem:$dst),
76 "shl{w}\t{%cl, $dst|$dst, cl}",
77 [(store (shl (loadi16 addr:$dst), CL), addr:$dst)]>,
79 def SHL32mCL : I<0xD3, MRM4m, (outs), (ins i32mem:$dst),
80 "shl{l}\t{%cl, $dst|$dst, cl}",
81 [(store (shl (loadi32 addr:$dst), CL), addr:$dst)]>,
83 def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
84 "shl{q}\t{%cl, $dst|$dst, cl}",
85 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>,
86 Requires<[In64BitMode]>;
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 {
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 SchedRW = [WriteShiftLd, WriteRMW] in {
171 def SHR8mCL : I<0xD2, MRM5m, (outs), (ins i8mem :$dst),
172 "shr{b}\t{%cl, $dst|$dst, cl}",
173 [(store (srl (loadi8 addr:$dst), CL), addr:$dst)]>;
174 def SHR16mCL : I<0xD3, MRM5m, (outs), (ins i16mem:$dst),
175 "shr{w}\t{%cl, $dst|$dst, cl}",
176 [(store (srl (loadi16 addr:$dst), CL), addr:$dst)]>,
178 def SHR32mCL : I<0xD3, MRM5m, (outs), (ins i32mem:$dst),
179 "shr{l}\t{%cl, $dst|$dst, cl}",
180 [(store (srl (loadi32 addr:$dst), CL), addr:$dst)]>,
182 def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
183 "shr{q}\t{%cl, $dst|$dst, cl}",
184 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>,
185 Requires<[In64BitMode]>;
187 def SHR8mi : Ii8<0xC0, MRM5m, (outs), (ins i8mem :$dst, u8imm:$src),
188 "shr{b}\t{$src, $dst|$dst, $src}",
189 [(store (srl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
190 def SHR16mi : Ii8<0xC1, MRM5m, (outs), (ins i16mem:$dst, u8imm:$src),
191 "shr{w}\t{$src, $dst|$dst, $src}",
192 [(store (srl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
194 def SHR32mi : Ii8<0xC1, MRM5m, (outs), (ins i32mem:$dst, u8imm:$src),
195 "shr{l}\t{$src, $dst|$dst, $src}",
196 [(store (srl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
198 def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, u8imm:$src),
199 "shr{q}\t{$src, $dst|$dst, $src}",
200 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
201 Requires<[In64BitMode]>;
204 def SHR8m1 : I<0xD0, MRM5m, (outs), (ins i8mem :$dst),
206 [(store (srl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
207 def SHR16m1 : I<0xD1, MRM5m, (outs), (ins i16mem:$dst),
209 [(store (srl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
211 def SHR32m1 : I<0xD1, MRM5m, (outs), (ins i32mem:$dst),
213 [(store (srl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>,
215 def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
217 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>,
218 Requires<[In64BitMode]>;
221 let Constraints = "$src1 = $dst", SchedRW = [WriteShift] in {
223 def SAR8rCL : I<0xD2, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
224 "sar{b}\t{%cl, $dst|$dst, cl}",
225 [(set GR8:$dst, (sra GR8:$src1, CL))]>;
226 def SAR16rCL : I<0xD3, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
227 "sar{w}\t{%cl, $dst|$dst, cl}",
228 [(set GR16:$dst, (sra GR16:$src1, CL))]>,
230 def SAR32rCL : I<0xD3, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
231 "sar{l}\t{%cl, $dst|$dst, cl}",
232 [(set GR32:$dst, (sra GR32:$src1, CL))]>,
234 def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
235 "sar{q}\t{%cl, $dst|$dst, cl}",
236 [(set GR64:$dst, (sra GR64:$src1, CL))]>;
239 def SAR8ri : Ii8<0xC0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1, u8imm:$src2),
240 "sar{b}\t{$src2, $dst|$dst, $src2}",
241 [(set GR8:$dst, (sra GR8:$src1, (i8 imm:$src2)))]>;
242 def SAR16ri : Ii8<0xC1, MRM7r, (outs GR16:$dst), (ins GR16:$src1, u8imm:$src2),
243 "sar{w}\t{$src2, $dst|$dst, $src2}",
244 [(set GR16:$dst, (sra GR16:$src1, (i8 imm:$src2)))]>,
246 def SAR32ri : Ii8<0xC1, MRM7r, (outs GR32:$dst), (ins GR32:$src1, u8imm:$src2),
247 "sar{l}\t{$src2, $dst|$dst, $src2}",
248 [(set GR32:$dst, (sra GR32:$src1, (i8 imm:$src2)))]>,
250 def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst),
251 (ins GR64:$src1, u8imm:$src2),
252 "sar{q}\t{$src2, $dst|$dst, $src2}",
253 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
256 def SAR8r1 : I<0xD0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
258 [(set GR8:$dst, (sra GR8:$src1, (i8 1)))]>;
259 def SAR16r1 : I<0xD1, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
261 [(set GR16:$dst, (sra GR16:$src1, (i8 1)))]>, OpSize16;
262 def SAR32r1 : I<0xD1, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
264 [(set GR32:$dst, (sra GR32:$src1, (i8 1)))]>, OpSize32;
265 def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
267 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
268 } // Constraints = "$src = $dst", SchedRW
271 let SchedRW = [WriteShiftLd, 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]>;
289 def SAR8mi : Ii8<0xC0, MRM7m, (outs), (ins i8mem :$dst, u8imm:$src),
290 "sar{b}\t{$src, $dst|$dst, $src}",
291 [(store (sra (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
292 def SAR16mi : Ii8<0xC1, MRM7m, (outs), (ins i16mem:$dst, u8imm:$src),
293 "sar{w}\t{$src, $dst|$dst, $src}",
294 [(store (sra (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
296 def SAR32mi : Ii8<0xC1, MRM7m, (outs), (ins i32mem:$dst, u8imm:$src),
297 "sar{l}\t{$src, $dst|$dst, $src}",
298 [(store (sra (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
300 def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, u8imm:$src),
301 "sar{q}\t{$src, $dst|$dst, $src}",
302 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
303 Requires<[In64BitMode]>;
306 def SAR8m1 : I<0xD0, MRM7m, (outs), (ins i8mem :$dst),
308 [(store (sra (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
309 def SAR16m1 : I<0xD1, MRM7m, (outs), (ins i16mem:$dst),
311 [(store (sra (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
313 def SAR32m1 : I<0xD1, MRM7m, (outs), (ins i32mem:$dst),
315 [(store (sra (loadi32 addr:$dst), (i8 1)), addr:$dst)]>,
317 def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
319 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>,
320 Requires<[In64BitMode]>;
323 //===----------------------------------------------------------------------===//
324 // Rotate instructions
325 //===----------------------------------------------------------------------===//
327 let hasSideEffects = 0 in {
328 let Constraints = "$src1 = $dst", SchedRW = [WriteShift] in {
330 let Uses = [CL, EFLAGS] in {
331 def RCL8rCL : I<0xD2, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
332 "rcl{b}\t{%cl, $dst|$dst, cl}", []>;
333 def RCL16rCL : I<0xD3, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
334 "rcl{w}\t{%cl, $dst|$dst, cl}", []>, OpSize16;
335 def RCL32rCL : I<0xD3, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
336 "rcl{l}\t{%cl, $dst|$dst, cl}", []>, OpSize32;
337 def RCL64rCL : RI<0xD3, MRM2r, (outs GR64:$dst), (ins GR64:$src1),
338 "rcl{q}\t{%cl, $dst|$dst, cl}", []>;
339 } // Uses = [CL, EFLAGS]
341 let Uses = [EFLAGS] in {
342 def RCL8r1 : I<0xD0, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
344 def RCL8ri : Ii8<0xC0, MRM2r, (outs GR8:$dst), (ins GR8:$src1, u8imm:$cnt),
345 "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
346 def RCL16r1 : I<0xD1, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
347 "rcl{w}\t$dst", []>, OpSize16;
348 def RCL16ri : Ii8<0xC1, MRM2r, (outs GR16:$dst), (ins GR16:$src1, u8imm:$cnt),
349 "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize16;
350 def RCL32r1 : I<0xD1, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
351 "rcl{l}\t$dst", []>, OpSize32;
352 def RCL32ri : Ii8<0xC1, MRM2r, (outs GR32:$dst), (ins GR32:$src1, u8imm:$cnt),
353 "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize32;
354 def RCL64r1 : RI<0xD1, MRM2r, (outs GR64:$dst), (ins GR64:$src1),
356 def RCL64ri : RIi8<0xC1, MRM2r, (outs GR64:$dst), (ins GR64:$src1, u8imm:$cnt),
357 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
360 let Uses = [CL, EFLAGS] in {
361 def RCR8rCL : I<0xD2, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
362 "rcr{b}\t{%cl, $dst|$dst, cl}", []>;
363 def RCR16rCL : I<0xD3, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
364 "rcr{w}\t{%cl, $dst|$dst, cl}", []>, OpSize16;
365 def RCR32rCL : I<0xD3, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
366 "rcr{l}\t{%cl, $dst|$dst, cl}", []>, OpSize32;
367 def RCR64rCL : RI<0xD3, MRM3r, (outs GR64:$dst), (ins GR64:$src1),
368 "rcr{q}\t{%cl, $dst|$dst, cl}", []>;
369 } // Uses = [CL, EFLAGS]
371 let Uses = [EFLAGS] in {
372 def RCR8r1 : I<0xD0, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
374 def RCR8ri : Ii8<0xC0, MRM3r, (outs GR8:$dst), (ins GR8:$src1, u8imm:$cnt),
375 "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
376 def RCR16r1 : I<0xD1, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
377 "rcr{w}\t$dst", []>, OpSize16;
378 def RCR16ri : Ii8<0xC1, MRM3r, (outs GR16:$dst), (ins GR16:$src1, u8imm:$cnt),
379 "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize16;
380 def RCR32r1 : I<0xD1, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
381 "rcr{l}\t$dst", []>, OpSize32;
382 def RCR32ri : Ii8<0xC1, MRM3r, (outs GR32:$dst), (ins GR32:$src1, u8imm:$cnt),
383 "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize32;
384 def RCR64r1 : RI<0xD1, MRM3r, (outs GR64:$dst), (ins GR64:$src1),
386 def RCR64ri : RIi8<0xC1, MRM3r, (outs GR64:$dst), (ins GR64:$src1, u8imm:$cnt),
387 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
390 } // Constraints = "$src = $dst"
392 let SchedRW = [WriteShiftLd, WriteRMW], mayStore = 1 in {
393 let Uses = [EFLAGS] in {
394 def RCL8m1 : I<0xD0, MRM2m, (outs), (ins i8mem:$dst),
396 def RCL8mi : Ii8<0xC0, MRM2m, (outs), (ins i8mem:$dst, u8imm:$cnt),
397 "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
398 def RCL16m1 : I<0xD1, MRM2m, (outs), (ins i16mem:$dst),
399 "rcl{w}\t$dst", []>, OpSize16;
400 def RCL16mi : Ii8<0xC1, MRM2m, (outs), (ins i16mem:$dst, u8imm:$cnt),
401 "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize16;
402 def RCL32m1 : I<0xD1, MRM2m, (outs), (ins i32mem:$dst),
403 "rcl{l}\t$dst", []>, OpSize32;
404 def RCL32mi : Ii8<0xC1, MRM2m, (outs), (ins i32mem:$dst, u8imm:$cnt),
405 "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize32;
406 def RCL64m1 : RI<0xD1, MRM2m, (outs), (ins i64mem:$dst),
407 "rcl{q}\t$dst", []>, Requires<[In64BitMode]>;
408 def RCL64mi : RIi8<0xC1, MRM2m, (outs), (ins i64mem:$dst, u8imm:$cnt),
409 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>,
410 Requires<[In64BitMode]>;
412 def RCR8m1 : I<0xD0, MRM3m, (outs), (ins i8mem:$dst),
414 def RCR8mi : Ii8<0xC0, MRM3m, (outs), (ins i8mem:$dst, u8imm:$cnt),
415 "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
416 def RCR16m1 : I<0xD1, MRM3m, (outs), (ins i16mem:$dst),
417 "rcr{w}\t$dst", []>, OpSize16;
418 def RCR16mi : Ii8<0xC1, MRM3m, (outs), (ins i16mem:$dst, u8imm:$cnt),
419 "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize16;
420 def RCR32m1 : I<0xD1, MRM3m, (outs), (ins i32mem:$dst),
421 "rcr{l}\t$dst", []>, OpSize32;
422 def RCR32mi : Ii8<0xC1, MRM3m, (outs), (ins i32mem:$dst, u8imm:$cnt),
423 "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize32;
424 def RCR64m1 : RI<0xD1, MRM3m, (outs), (ins i64mem:$dst),
425 "rcr{q}\t$dst", []>, Requires<[In64BitMode]>;
426 def RCR64mi : RIi8<0xC1, MRM3m, (outs), (ins i64mem:$dst, u8imm:$cnt),
427 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>,
428 Requires<[In64BitMode]>;
431 let Uses = [CL, EFLAGS] in {
432 def RCL8mCL : I<0xD2, MRM2m, (outs), (ins i8mem:$dst),
433 "rcl{b}\t{%cl, $dst|$dst, cl}", []>;
434 def RCL16mCL : I<0xD3, MRM2m, (outs), (ins i16mem:$dst),
435 "rcl{w}\t{%cl, $dst|$dst, cl}", []>, OpSize16;
436 def RCL32mCL : I<0xD3, MRM2m, (outs), (ins i32mem:$dst),
437 "rcl{l}\t{%cl, $dst|$dst, cl}", []>, OpSize32;
438 def RCL64mCL : RI<0xD3, MRM2m, (outs), (ins i64mem:$dst),
439 "rcl{q}\t{%cl, $dst|$dst, cl}", []>,
440 Requires<[In64BitMode]>;
442 def RCR8mCL : I<0xD2, MRM3m, (outs), (ins i8mem:$dst),
443 "rcr{b}\t{%cl, $dst|$dst, cl}", []>;
444 def RCR16mCL : I<0xD3, MRM3m, (outs), (ins i16mem:$dst),
445 "rcr{w}\t{%cl, $dst|$dst, cl}", []>, OpSize16;
446 def RCR32mCL : I<0xD3, MRM3m, (outs), (ins i32mem:$dst),
447 "rcr{l}\t{%cl, $dst|$dst, cl}", []>, OpSize32;
448 def RCR64mCL : RI<0xD3, MRM3m, (outs), (ins i64mem:$dst),
449 "rcr{q}\t{%cl, $dst|$dst, cl}", []>,
450 Requires<[In64BitMode]>;
451 } // Uses = [CL, EFLAGS]
453 } // hasSideEffects = 0
455 let Constraints = "$src1 = $dst", SchedRW = [WriteShift] in {
456 // FIXME: provide shorter instructions when imm8 == 1
458 def ROL8rCL : I<0xD2, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
459 "rol{b}\t{%cl, $dst|$dst, cl}",
460 [(set GR8:$dst, (rotl GR8:$src1, CL))]>;
461 def ROL16rCL : I<0xD3, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
462 "rol{w}\t{%cl, $dst|$dst, cl}",
463 [(set GR16:$dst, (rotl GR16:$src1, CL))]>, OpSize16;
464 def ROL32rCL : I<0xD3, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
465 "rol{l}\t{%cl, $dst|$dst, cl}",
466 [(set GR32:$dst, (rotl GR32:$src1, CL))]>, OpSize32;
467 def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
468 "rol{q}\t{%cl, $dst|$dst, cl}",
469 [(set GR64:$dst, (rotl GR64:$src1, CL))]>;
472 def ROL8ri : Ii8<0xC0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1, u8imm:$src2),
473 "rol{b}\t{$src2, $dst|$dst, $src2}",
474 [(set GR8:$dst, (rotl GR8:$src1, (i8 imm:$src2)))]>;
475 def ROL16ri : Ii8<0xC1, MRM0r, (outs GR16:$dst), (ins GR16:$src1, u8imm:$src2),
476 "rol{w}\t{$src2, $dst|$dst, $src2}",
477 [(set GR16:$dst, (rotl GR16:$src1, (i8 imm:$src2)))]>, OpSize16;
478 def ROL32ri : Ii8<0xC1, MRM0r, (outs GR32:$dst), (ins GR32:$src1, u8imm:$src2),
479 "rol{l}\t{$src2, $dst|$dst, $src2}",
480 [(set GR32:$dst, (rotl GR32:$src1, (i8 imm:$src2)))]>, OpSize32;
481 def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst),
482 (ins GR64:$src1, u8imm:$src2),
483 "rol{q}\t{$src2, $dst|$dst, $src2}",
484 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
487 def ROL8r1 : I<0xD0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
489 [(set GR8:$dst, (rotl GR8:$src1, (i8 1)))]>;
490 def ROL16r1 : I<0xD1, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
492 [(set GR16:$dst, (rotl GR16:$src1, (i8 1)))]>, OpSize16;
493 def ROL32r1 : I<0xD1, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
495 [(set GR32:$dst, (rotl GR32:$src1, (i8 1)))]>, OpSize32;
496 def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
498 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
499 } // Constraints = "$src = $dst", SchedRW
501 let SchedRW = [WriteShiftLd, WriteRMW] in {
503 def ROL8mCL : I<0xD2, MRM0m, (outs), (ins i8mem :$dst),
504 "rol{b}\t{%cl, $dst|$dst, cl}",
505 [(store (rotl (loadi8 addr:$dst), CL), addr:$dst)]>;
506 def ROL16mCL : I<0xD3, MRM0m, (outs), (ins i16mem:$dst),
507 "rol{w}\t{%cl, $dst|$dst, cl}",
508 [(store (rotl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize16;
509 def ROL32mCL : I<0xD3, MRM0m, (outs), (ins i32mem:$dst),
510 "rol{l}\t{%cl, $dst|$dst, cl}",
511 [(store (rotl (loadi32 addr:$dst), CL), addr:$dst)]>, OpSize32;
512 def ROL64mCL : RI<0xD3, MRM0m, (outs), (ins i64mem:$dst),
513 "rol{q}\t{%cl, $dst|$dst, cl}",
514 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>,
515 Requires<[In64BitMode]>;
517 def ROL8mi : Ii8<0xC0, MRM0m, (outs), (ins i8mem :$dst, u8imm:$src1),
518 "rol{b}\t{$src1, $dst|$dst, $src1}",
519 [(store (rotl (loadi8 addr:$dst), (i8 imm:$src1)), addr:$dst)]>;
520 def ROL16mi : Ii8<0xC1, MRM0m, (outs), (ins i16mem:$dst, u8imm:$src1),
521 "rol{w}\t{$src1, $dst|$dst, $src1}",
522 [(store (rotl (loadi16 addr:$dst), (i8 imm:$src1)), addr:$dst)]>,
524 def ROL32mi : Ii8<0xC1, MRM0m, (outs), (ins i32mem:$dst, u8imm:$src1),
525 "rol{l}\t{$src1, $dst|$dst, $src1}",
526 [(store (rotl (loadi32 addr:$dst), (i8 imm:$src1)), addr:$dst)]>,
528 def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, u8imm:$src1),
529 "rol{q}\t{$src1, $dst|$dst, $src1}",
530 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src1)), addr:$dst)]>,
531 Requires<[In64BitMode]>;
534 def ROL8m1 : I<0xD0, MRM0m, (outs), (ins i8mem :$dst),
536 [(store (rotl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
537 def ROL16m1 : I<0xD1, MRM0m, (outs), (ins i16mem:$dst),
539 [(store (rotl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
541 def ROL32m1 : I<0xD1, MRM0m, (outs), (ins i32mem:$dst),
543 [(store (rotl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>,
545 def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
547 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>,
548 Requires<[In64BitMode]>;
551 let Constraints = "$src1 = $dst", SchedRW = [WriteShift] in {
553 def ROR8rCL : I<0xD2, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
554 "ror{b}\t{%cl, $dst|$dst, cl}",
555 [(set GR8:$dst, (rotr GR8:$src1, CL))]>;
556 def ROR16rCL : I<0xD3, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
557 "ror{w}\t{%cl, $dst|$dst, cl}",
558 [(set GR16:$dst, (rotr GR16:$src1, CL))]>, OpSize16;
559 def ROR32rCL : I<0xD3, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
560 "ror{l}\t{%cl, $dst|$dst, cl}",
561 [(set GR32:$dst, (rotr GR32:$src1, CL))]>, OpSize32;
562 def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
563 "ror{q}\t{%cl, $dst|$dst, cl}",
564 [(set GR64:$dst, (rotr GR64:$src1, CL))]>;
567 def ROR8ri : Ii8<0xC0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1, u8imm:$src2),
568 "ror{b}\t{$src2, $dst|$dst, $src2}",
569 [(set GR8:$dst, (rotr GR8:$src1, (i8 relocImm:$src2)))]>;
570 def ROR16ri : Ii8<0xC1, MRM1r, (outs GR16:$dst), (ins GR16:$src1, u8imm:$src2),
571 "ror{w}\t{$src2, $dst|$dst, $src2}",
572 [(set GR16:$dst, (rotr GR16:$src1, (i8 relocImm:$src2)))]>,
574 def ROR32ri : Ii8<0xC1, MRM1r, (outs GR32:$dst), (ins GR32:$src1, u8imm:$src2),
575 "ror{l}\t{$src2, $dst|$dst, $src2}",
576 [(set GR32:$dst, (rotr GR32:$src1, (i8 relocImm:$src2)))]>,
578 def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst),
579 (ins GR64:$src1, u8imm:$src2),
580 "ror{q}\t{$src2, $dst|$dst, $src2}",
581 [(set GR64:$dst, (rotr GR64:$src1, (i8 relocImm:$src2)))]>;
584 def ROR8r1 : I<0xD0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
586 [(set GR8:$dst, (rotl GR8:$src1, (i8 7)))]>;
587 def ROR16r1 : I<0xD1, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
589 [(set GR16:$dst, (rotl GR16:$src1, (i8 15)))]>, OpSize16;
590 def ROR32r1 : I<0xD1, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
592 [(set GR32:$dst, (rotl GR32:$src1, (i8 31)))]>, OpSize32;
593 def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
595 [(set GR64:$dst, (rotl GR64:$src1, (i8 63)))]>;
596 } // Constraints = "$src = $dst", SchedRW
598 let SchedRW = [WriteShiftLd, WriteRMW] in {
600 def ROR8mCL : I<0xD2, MRM1m, (outs), (ins i8mem :$dst),
601 "ror{b}\t{%cl, $dst|$dst, cl}",
602 [(store (rotr (loadi8 addr:$dst), CL), addr:$dst)]>;
603 def ROR16mCL : I<0xD3, MRM1m, (outs), (ins i16mem:$dst),
604 "ror{w}\t{%cl, $dst|$dst, cl}",
605 [(store (rotr (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize16;
606 def ROR32mCL : I<0xD3, MRM1m, (outs), (ins i32mem:$dst),
607 "ror{l}\t{%cl, $dst|$dst, cl}",
608 [(store (rotr (loadi32 addr:$dst), CL), addr:$dst)]>, OpSize32;
609 def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
610 "ror{q}\t{%cl, $dst|$dst, cl}",
611 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>,
612 Requires<[In64BitMode]>;
614 def ROR8mi : Ii8<0xC0, MRM1m, (outs), (ins i8mem :$dst, u8imm:$src),
615 "ror{b}\t{$src, $dst|$dst, $src}",
616 [(store (rotr (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
617 def ROR16mi : Ii8<0xC1, MRM1m, (outs), (ins i16mem:$dst, u8imm:$src),
618 "ror{w}\t{$src, $dst|$dst, $src}",
619 [(store (rotr (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
621 def ROR32mi : Ii8<0xC1, MRM1m, (outs), (ins i32mem:$dst, u8imm:$src),
622 "ror{l}\t{$src, $dst|$dst, $src}",
623 [(store (rotr (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
625 def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, u8imm:$src),
626 "ror{q}\t{$src, $dst|$dst, $src}",
627 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
628 Requires<[In64BitMode]>;
631 def ROR8m1 : I<0xD0, MRM1m, (outs), (ins i8mem :$dst),
633 [(store (rotl (loadi8 addr:$dst), (i8 7)), addr:$dst)]>;
634 def ROR16m1 : I<0xD1, MRM1m, (outs), (ins i16mem:$dst),
636 [(store (rotl (loadi16 addr:$dst), (i8 15)), addr:$dst)]>,
638 def ROR32m1 : I<0xD1, MRM1m, (outs), (ins i32mem:$dst),
640 [(store (rotl (loadi32 addr:$dst), (i8 31)), addr:$dst)]>,
642 def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
644 [(store (rotl (loadi64 addr:$dst), (i8 63)), addr:$dst)]>,
645 Requires<[In64BitMode]>;
649 //===----------------------------------------------------------------------===//
650 // Double shift instructions (generalizations of rotate)
651 //===----------------------------------------------------------------------===//
653 let Constraints = "$src1 = $dst" in {
655 let Uses = [CL], SchedRW = [WriteSHDrrcl] in {
656 def SHLD16rrCL : I<0xA5, MRMDestReg, (outs GR16:$dst),
657 (ins GR16:$src1, GR16:$src2),
658 "shld{w}\t{%cl, $src2, $dst|$dst, $src2, cl}",
659 [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2, CL))]>,
661 def SHRD16rrCL : I<0xAD, MRMDestReg, (outs GR16:$dst),
662 (ins GR16:$src1, GR16:$src2),
663 "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, cl}",
664 [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2, CL))]>,
666 def SHLD32rrCL : I<0xA5, MRMDestReg, (outs GR32:$dst),
667 (ins GR32:$src1, GR32:$src2),
668 "shld{l}\t{%cl, $src2, $dst|$dst, $src2, cl}",
669 [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2, CL))]>,
671 def SHRD32rrCL : I<0xAD, MRMDestReg, (outs GR32:$dst),
672 (ins GR32:$src1, GR32:$src2),
673 "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, cl}",
674 [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2, CL))]>,
676 def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst),
677 (ins GR64:$src1, GR64:$src2),
678 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, cl}",
679 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>,
681 def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst),
682 (ins GR64:$src1, GR64:$src2),
683 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, cl}",
684 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>,
688 let isCommutable = 1, SchedRW = [WriteSHDrri] in { // These instructions commute to each other.
689 def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
691 (ins GR16:$src1, GR16:$src2, u8imm:$src3),
692 "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
693 [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2,
696 def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
698 (ins GR16:$src1, GR16:$src2, u8imm:$src3),
699 "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
700 [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2,
703 def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
705 (ins GR32:$src1, GR32:$src2, u8imm:$src3),
706 "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
707 [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2,
710 def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
712 (ins GR32:$src1, GR32:$src2, u8imm:$src3),
713 "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
714 [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2,
717 def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
719 (ins GR64:$src1, GR64:$src2, u8imm:$src3),
720 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
721 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
724 def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
726 (ins GR64:$src1, GR64:$src2, u8imm:$src3),
727 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
728 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
732 } // Constraints = "$src = $dst"
734 let Uses = [CL], SchedRW = [WriteSHDmrcl] in {
735 def SHLD16mrCL : I<0xA5, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
736 "shld{w}\t{%cl, $src2, $dst|$dst, $src2, cl}",
737 [(store (X86shld (loadi16 addr:$dst), GR16:$src2, CL),
738 addr:$dst)]>, TB, OpSize16;
739 def SHRD16mrCL : I<0xAD, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
740 "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, cl}",
741 [(store (X86shrd (loadi16 addr:$dst), GR16:$src2, CL),
742 addr:$dst)]>, TB, OpSize16;
744 def SHLD32mrCL : I<0xA5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
745 "shld{l}\t{%cl, $src2, $dst|$dst, $src2, cl}",
746 [(store (X86shld (loadi32 addr:$dst), GR32:$src2, CL),
747 addr:$dst)]>, TB, OpSize32;
748 def SHRD32mrCL : I<0xAD, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
749 "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, cl}",
750 [(store (X86shrd (loadi32 addr:$dst), GR32:$src2, CL),
751 addr:$dst)]>, TB, OpSize32;
753 def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
754 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, cl}",
755 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
757 def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
758 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, cl}",
759 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
763 let SchedRW = [WriteSHDmri] in {
764 def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
765 (outs), (ins i16mem:$dst, GR16:$src2, u8imm:$src3),
766 "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
767 [(store (X86shld (loadi16 addr:$dst), GR16:$src2,
768 (i8 imm:$src3)), addr:$dst)]>,
770 def SHRD16mri8 : Ii8<0xAC, MRMDestMem,
771 (outs), (ins i16mem:$dst, GR16:$src2, u8imm:$src3),
772 "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
773 [(store (X86shrd (loadi16 addr:$dst), GR16:$src2,
774 (i8 imm:$src3)), addr:$dst)]>,
777 def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
778 (outs), (ins i32mem:$dst, GR32:$src2, u8imm:$src3),
779 "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
780 [(store (X86shld (loadi32 addr:$dst), GR32:$src2,
781 (i8 imm:$src3)), addr:$dst)]>,
783 def SHRD32mri8 : Ii8<0xAC, MRMDestMem,
784 (outs), (ins i32mem:$dst, GR32:$src2, u8imm:$src3),
785 "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
786 [(store (X86shrd (loadi32 addr:$dst), GR32:$src2,
787 (i8 imm:$src3)), addr:$dst)]>,
790 def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
791 (outs), (ins i64mem:$dst, GR64:$src2, u8imm:$src3),
792 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
793 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
794 (i8 imm:$src3)), addr:$dst)]>,
796 def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
797 (outs), (ins i64mem:$dst, GR64:$src2, u8imm:$src3),
798 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
799 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
800 (i8 imm:$src3)), addr:$dst)]>,
806 // Sandy Bridge and newer Intel processors support faster rotates using
807 // SHLD to avoid a partial flag update on the normal rotate instructions.
808 let Predicates = [HasFastSHLDRotate], AddedComplexity = 5 in {
809 def : Pat<(rotl GR32:$src, (i8 imm:$shamt)),
810 (SHLD32rri8 GR32:$src, GR32:$src, imm:$shamt)>;
811 def : Pat<(rotl GR64:$src, (i8 imm:$shamt)),
812 (SHLD64rri8 GR64:$src, GR64:$src, imm:$shamt)>;
815 def ROT32L2R_imm8 : SDNodeXForm<imm, [{
816 // Convert a ROTL shamt to a ROTR shamt on 32-bit integer.
817 return getI8Imm(32 - N->getZExtValue(), SDLoc(N));
820 def ROT64L2R_imm8 : SDNodeXForm<imm, [{
821 // Convert a ROTL shamt to a ROTR shamt on 64-bit integer.
822 return getI8Imm(64 - N->getZExtValue(), SDLoc(N));
825 multiclass bmi_rotate<string asm, RegisterClass RC, X86MemOperand x86memop> {
826 let hasSideEffects = 0 in {
827 def ri : Ii8<0xF0, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, u8imm:$src2),
828 !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
829 []>, TAXD, VEX, Sched<[WriteShift]>;
831 def mi : Ii8<0xF0, MRMSrcMem, (outs RC:$dst),
832 (ins x86memop:$src1, u8imm:$src2),
833 !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
834 []>, TAXD, VEX, Sched<[WriteShiftLd]>;
838 multiclass bmi_shift<string asm, RegisterClass RC, X86MemOperand x86memop> {
839 let hasSideEffects = 0 in {
840 def rr : I<0xF7, MRMSrcReg4VOp3, (outs RC:$dst), (ins RC:$src1, RC:$src2),
841 !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>,
842 VEX, Sched<[WriteShift]>;
844 def rm : I<0xF7, MRMSrcMem4VOp3,
845 (outs RC:$dst), (ins x86memop:$src1, RC:$src2),
846 !strconcat(asm, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"), []>,
847 VEX, Sched<[WriteShiftLd,
849 ReadDefault, ReadDefault, ReadDefault, ReadDefault,
856 let Predicates = [HasBMI2] in {
857 defm RORX32 : bmi_rotate<"rorx{l}", GR32, i32mem>;
858 defm RORX64 : bmi_rotate<"rorx{q}", GR64, i64mem>, VEX_W;
859 defm SARX32 : bmi_shift<"sarx{l}", GR32, i32mem>, T8XS;
860 defm SARX64 : bmi_shift<"sarx{q}", GR64, i64mem>, T8XS, VEX_W;
861 defm SHRX32 : bmi_shift<"shrx{l}", GR32, i32mem>, T8XD;
862 defm SHRX64 : bmi_shift<"shrx{q}", GR64, i64mem>, T8XD, VEX_W;
863 defm SHLX32 : bmi_shift<"shlx{l}", GR32, i32mem>, T8PD;
864 defm SHLX64 : bmi_shift<"shlx{q}", GR64, i64mem>, T8PD, VEX_W;
866 // Prefer RORX which is non-destructive and doesn't update EFLAGS.
867 let AddedComplexity = 10 in {
868 def : Pat<(rotl GR32:$src, (i8 imm:$shamt)),
869 (RORX32ri GR32:$src, (ROT32L2R_imm8 imm:$shamt))>;
870 def : Pat<(rotl GR64:$src, (i8 imm:$shamt)),
871 (RORX64ri GR64:$src, (ROT64L2R_imm8 imm:$shamt))>;
874 def : Pat<(rotl (loadi32 addr:$src), (i8 imm:$shamt)),
875 (RORX32mi addr:$src, (ROT32L2R_imm8 imm:$shamt))>;
876 def : Pat<(rotl (loadi64 addr:$src), (i8 imm:$shamt)),
877 (RORX64mi addr:$src, (ROT64L2R_imm8 imm:$shamt))>;
879 // Prefer SARX/SHRX/SHLX over SAR/SHR/SHL with variable shift BUT not
880 // immedidate shift, i.e. the following code is considered better
889 // shlx %sil, %edi, %esi
892 let AddedComplexity = 1 in {
893 def : Pat<(sra GR32:$src1, GR8:$src2),
894 (SARX32rr GR32:$src1,
896 (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
897 def : Pat<(sra GR64:$src1, GR8:$src2),
898 (SARX64rr GR64:$src1,
900 (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
902 def : Pat<(srl GR32:$src1, GR8:$src2),
903 (SHRX32rr GR32:$src1,
905 (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
906 def : Pat<(srl GR64:$src1, GR8:$src2),
907 (SHRX64rr GR64:$src1,
909 (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
911 def : Pat<(shl GR32:$src1, GR8:$src2),
912 (SHLX32rr GR32:$src1,
914 (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
915 def : Pat<(shl GR64:$src1, GR8:$src2),
916 (SHLX64rr GR64:$src1,
918 (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
928 // shlx %al, (%ecx), %esi
930 // This priority is enforced by IsProfitableToFoldLoad.
931 def : Pat<(sra (loadi32 addr:$src1), GR8:$src2),
932 (SARX32rm addr:$src1,
934 (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
935 def : Pat<(sra (loadi64 addr:$src1), GR8:$src2),
936 (SARX64rm addr:$src1,
938 (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
940 def : Pat<(srl (loadi32 addr:$src1), GR8:$src2),
941 (SHRX32rm addr:$src1,
943 (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
944 def : Pat<(srl (loadi64 addr:$src1), GR8:$src2),
945 (SHRX64rm addr:$src1,
947 (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
949 def : Pat<(shl (loadi32 addr:$src1), GR8:$src2),
950 (SHLX32rm addr:$src1,
952 (i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
953 def : Pat<(shl (loadi64 addr:$src1), GR8:$src2),
954 (SHLX64rm addr:$src1,
956 (i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;