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