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