1//===-- X86InstrInfo.td - Main X86 Instruction Definition --*- 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 X86 instruction set, defining the instructions, and 11// properties of the instructions which are needed for code generation, machine 12// code emission, and analysis. 13// 14//===----------------------------------------------------------------------===// 15 16//===----------------------------------------------------------------------===// 17// X86 specific DAG Nodes. 18// 19 20def SDTIntShiftDOp: SDTypeProfile<1, 3, 21 [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, 22 SDTCisInt<0>, SDTCisInt<3>]>; 23 24def SDTX86CmpTest : SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisSameAs<1, 2>]>; 25 26def SDTX86Cmps : SDTypeProfile<1, 3, [SDTCisFP<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, i8>]>; 27//def SDTX86Cmpss : SDTypeProfile<1, 3, [SDTCisVT<0, f32>, SDTCisSameAs<1, 2>, SDTCisVT<3, i8>]>; 28 29def SDTX86Cmov : SDTypeProfile<1, 4, 30 [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, 31 SDTCisVT<3, i8>, SDTCisVT<4, i32>]>; 32 33// Unary and binary operator instructions that set EFLAGS as a side-effect. 34def SDTUnaryArithWithFlags : SDTypeProfile<2, 1, 35 [SDTCisSameAs<0, 2>, 36 SDTCisInt<0>, SDTCisVT<1, i32>]>; 37 38def SDTBinaryArithWithFlags : SDTypeProfile<2, 2, 39 [SDTCisSameAs<0, 2>, 40 SDTCisSameAs<0, 3>, 41 SDTCisInt<0>, SDTCisVT<1, i32>]>; 42 43// SDTBinaryArithWithFlagsInOut - RES1, EFLAGS = op LHS, RHS, EFLAGS 44def SDTBinaryArithWithFlagsInOut : SDTypeProfile<2, 3, 45 [SDTCisSameAs<0, 2>, 46 SDTCisSameAs<0, 3>, 47 SDTCisInt<0>, 48 SDTCisVT<1, i32>, 49 SDTCisVT<4, i32>]>; 50// RES1, RES2, FLAGS = op LHS, RHS 51def SDT2ResultBinaryArithWithFlags : SDTypeProfile<3, 2, 52 [SDTCisSameAs<0, 1>, 53 SDTCisSameAs<0, 2>, 54 SDTCisSameAs<0, 3>, 55 SDTCisInt<0>, SDTCisVT<1, i32>]>; 56def SDTX86BrCond : SDTypeProfile<0, 3, 57 [SDTCisVT<0, OtherVT>, 58 SDTCisVT<1, i8>, SDTCisVT<2, i32>]>; 59 60def SDTX86SetCC : SDTypeProfile<1, 2, 61 [SDTCisVT<0, i8>, 62 SDTCisVT<1, i8>, SDTCisVT<2, i32>]>; 63def SDTX86SetCC_C : SDTypeProfile<1, 2, 64 [SDTCisInt<0>, 65 SDTCisVT<1, i8>, SDTCisVT<2, i32>]>; 66 67def SDTX86sahf : SDTypeProfile<1, 1, [SDTCisVT<0, i32>, SDTCisVT<1, i8>]>; 68 69def SDTX86rdrand : SDTypeProfile<2, 0, [SDTCisInt<0>, SDTCisVT<1, i32>]>; 70 71def SDTX86cas : SDTypeProfile<0, 3, [SDTCisPtrTy<0>, SDTCisInt<1>, 72 SDTCisVT<2, i8>]>; 73def SDTX86caspair : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>; 74def SDTX86caspairSaveEbx8 : SDTypeProfile<1, 3, 75 [SDTCisVT<0, i32>, SDTCisPtrTy<1>, 76 SDTCisVT<2, i32>, SDTCisVT<3, i32>]>; 77def SDTX86caspairSaveRbx16 : SDTypeProfile<1, 3, 78 [SDTCisVT<0, i64>, SDTCisPtrTy<1>, 79 SDTCisVT<2, i64>, SDTCisVT<3, i64>]>; 80 81def SDTLockBinaryArithWithFlags : SDTypeProfile<1, 2, [SDTCisVT<0, i32>, 82 SDTCisPtrTy<1>, 83 SDTCisInt<2>]>; 84 85def SDTX86Ret : SDTypeProfile<0, -1, [SDTCisVT<0, i32>]>; 86 87def SDT_X86CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>; 88def SDT_X86CallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, 89 SDTCisVT<1, i32>]>; 90 91def SDT_X86Call : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>; 92 93def SDT_X86VASTART_SAVE_XMM_REGS : SDTypeProfile<0, -1, [SDTCisVT<0, i8>, 94 SDTCisVT<1, iPTR>, 95 SDTCisVT<2, iPTR>]>; 96 97def SDT_X86VAARG_64 : SDTypeProfile<1, -1, [SDTCisPtrTy<0>, 98 SDTCisPtrTy<1>, 99 SDTCisVT<2, i32>, 100 SDTCisVT<3, i8>, 101 SDTCisVT<4, i32>]>; 102 103def SDTX86RepStr : SDTypeProfile<0, 1, [SDTCisVT<0, OtherVT>]>; 104 105def SDTX86Void : SDTypeProfile<0, 0, []>; 106 107def SDTX86Wrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>; 108 109def SDT_X86TLSADDR : SDTypeProfile<0, 1, [SDTCisInt<0>]>; 110 111def SDT_X86TLSBASEADDR : SDTypeProfile<0, 1, [SDTCisInt<0>]>; 112 113def SDT_X86TLSCALL : SDTypeProfile<0, 1, [SDTCisInt<0>]>; 114 115def SDT_X86WIN_ALLOCA : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>; 116 117def SDT_X86SEG_ALLOCA : SDTypeProfile<1, 1, [SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>; 118 119def SDT_X86EHRET : SDTypeProfile<0, 1, [SDTCisInt<0>]>; 120 121def SDT_X86TCRET : SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisVT<1, i32>]>; 122 123def SDT_X86MEMBARRIER : SDTypeProfile<0, 0, []>; 124 125def X86MemBarrier : SDNode<"X86ISD::MEMBARRIER", SDT_X86MEMBARRIER, 126 [SDNPHasChain,SDNPSideEffect]>; 127def X86MFence : SDNode<"X86ISD::MFENCE", SDT_X86MEMBARRIER, 128 [SDNPHasChain]>; 129 130 131def X86bsf : SDNode<"X86ISD::BSF", SDTUnaryArithWithFlags>; 132def X86bsr : SDNode<"X86ISD::BSR", SDTUnaryArithWithFlags>; 133def X86shld : SDNode<"X86ISD::SHLD", SDTIntShiftDOp>; 134def X86shrd : SDNode<"X86ISD::SHRD", SDTIntShiftDOp>; 135 136def X86cmp : SDNode<"X86ISD::CMP" , SDTX86CmpTest>; 137def X86bt : SDNode<"X86ISD::BT", SDTX86CmpTest>; 138 139def X86cmov : SDNode<"X86ISD::CMOV", SDTX86Cmov>; 140def X86brcond : SDNode<"X86ISD::BRCOND", SDTX86BrCond, 141 [SDNPHasChain]>; 142def X86setcc : SDNode<"X86ISD::SETCC", SDTX86SetCC>; 143def X86setcc_c : SDNode<"X86ISD::SETCC_CARRY", SDTX86SetCC_C>; 144 145def X86sahf : SDNode<"X86ISD::SAHF", SDTX86sahf>; 146 147def X86rdrand : SDNode<"X86ISD::RDRAND", SDTX86rdrand, 148 [SDNPHasChain, SDNPSideEffect]>; 149 150def X86rdseed : SDNode<"X86ISD::RDSEED", SDTX86rdrand, 151 [SDNPHasChain, SDNPSideEffect]>; 152 153def X86cas : SDNode<"X86ISD::LCMPXCHG_DAG", SDTX86cas, 154 [SDNPHasChain, SDNPInGlue, SDNPOutGlue, SDNPMayStore, 155 SDNPMayLoad, SDNPMemOperand]>; 156def X86cas8 : SDNode<"X86ISD::LCMPXCHG8_DAG", SDTX86caspair, 157 [SDNPHasChain, SDNPInGlue, SDNPOutGlue, SDNPMayStore, 158 SDNPMayLoad, SDNPMemOperand]>; 159def X86cas16 : SDNode<"X86ISD::LCMPXCHG16_DAG", SDTX86caspair, 160 [SDNPHasChain, SDNPInGlue, SDNPOutGlue, SDNPMayStore, 161 SDNPMayLoad, SDNPMemOperand]>; 162def X86cas8save_ebx : SDNode<"X86ISD::LCMPXCHG8_SAVE_EBX_DAG", 163 SDTX86caspairSaveEbx8, 164 [SDNPHasChain, SDNPInGlue, SDNPOutGlue, 165 SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>; 166def X86cas16save_rbx : SDNode<"X86ISD::LCMPXCHG16_SAVE_RBX_DAG", 167 SDTX86caspairSaveRbx16, 168 [SDNPHasChain, SDNPInGlue, SDNPOutGlue, 169 SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>; 170 171def X86retflag : SDNode<"X86ISD::RET_FLAG", SDTX86Ret, 172 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>; 173def X86iret : SDNode<"X86ISD::IRET", SDTX86Ret, 174 [SDNPHasChain, SDNPOptInGlue]>; 175 176def X86vastart_save_xmm_regs : 177 SDNode<"X86ISD::VASTART_SAVE_XMM_REGS", 178 SDT_X86VASTART_SAVE_XMM_REGS, 179 [SDNPHasChain, SDNPVariadic]>; 180def X86vaarg64 : 181 SDNode<"X86ISD::VAARG_64", SDT_X86VAARG_64, 182 [SDNPHasChain, SDNPMayLoad, SDNPMayStore, 183 SDNPMemOperand]>; 184def X86callseq_start : 185 SDNode<"ISD::CALLSEQ_START", SDT_X86CallSeqStart, 186 [SDNPHasChain, SDNPOutGlue]>; 187def X86callseq_end : 188 SDNode<"ISD::CALLSEQ_END", SDT_X86CallSeqEnd, 189 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>; 190 191def X86call : SDNode<"X86ISD::CALL", SDT_X86Call, 192 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, 193 SDNPVariadic]>; 194 195def X86rep_stos: SDNode<"X86ISD::REP_STOS", SDTX86RepStr, 196 [SDNPHasChain, SDNPInGlue, SDNPOutGlue, SDNPMayStore]>; 197def X86rep_movs: SDNode<"X86ISD::REP_MOVS", SDTX86RepStr, 198 [SDNPHasChain, SDNPInGlue, SDNPOutGlue, SDNPMayStore, 199 SDNPMayLoad]>; 200 201def X86rdtsc : SDNode<"X86ISD::RDTSC_DAG", SDTX86Void, 202 [SDNPHasChain, SDNPOutGlue, SDNPSideEffect]>; 203def X86rdtscp : SDNode<"X86ISD::RDTSCP_DAG", SDTX86Void, 204 [SDNPHasChain, SDNPOutGlue, SDNPSideEffect]>; 205def X86rdpmc : SDNode<"X86ISD::RDPMC_DAG", SDTX86Void, 206 [SDNPHasChain, SDNPOutGlue, SDNPSideEffect]>; 207 208def X86Wrapper : SDNode<"X86ISD::Wrapper", SDTX86Wrapper>; 209def X86WrapperRIP : SDNode<"X86ISD::WrapperRIP", SDTX86Wrapper>; 210 211def X86RecoverFrameAlloc : SDNode<"ISD::LOCAL_RECOVER", 212 SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, 213 SDTCisInt<1>]>>; 214 215def X86tlsaddr : SDNode<"X86ISD::TLSADDR", SDT_X86TLSADDR, 216 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>; 217 218def X86tlsbaseaddr : SDNode<"X86ISD::TLSBASEADDR", SDT_X86TLSBASEADDR, 219 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>; 220 221def X86ehret : SDNode<"X86ISD::EH_RETURN", SDT_X86EHRET, 222 [SDNPHasChain]>; 223 224def X86eh_sjlj_setjmp : SDNode<"X86ISD::EH_SJLJ_SETJMP", 225 SDTypeProfile<1, 1, [SDTCisInt<0>, 226 SDTCisPtrTy<1>]>, 227 [SDNPHasChain, SDNPSideEffect]>; 228def X86eh_sjlj_longjmp : SDNode<"X86ISD::EH_SJLJ_LONGJMP", 229 SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>, 230 [SDNPHasChain, SDNPSideEffect]>; 231def X86eh_sjlj_setup_dispatch : SDNode<"X86ISD::EH_SJLJ_SETUP_DISPATCH", 232 SDTypeProfile<0, 0, []>, 233 [SDNPHasChain, SDNPSideEffect]>; 234 235def X86tcret : SDNode<"X86ISD::TC_RETURN", SDT_X86TCRET, 236 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>; 237 238def X86add_flag : SDNode<"X86ISD::ADD", SDTBinaryArithWithFlags, 239 [SDNPCommutative]>; 240def X86sub_flag : SDNode<"X86ISD::SUB", SDTBinaryArithWithFlags>; 241def X86smul_flag : SDNode<"X86ISD::SMUL", SDTBinaryArithWithFlags, 242 [SDNPCommutative]>; 243def X86umul_flag : SDNode<"X86ISD::UMUL", SDT2ResultBinaryArithWithFlags, 244 [SDNPCommutative]>; 245def X86adc_flag : SDNode<"X86ISD::ADC", SDTBinaryArithWithFlagsInOut>; 246def X86sbb_flag : SDNode<"X86ISD::SBB", SDTBinaryArithWithFlagsInOut>; 247 248def X86inc_flag : SDNode<"X86ISD::INC", SDTUnaryArithWithFlags>; 249def X86dec_flag : SDNode<"X86ISD::DEC", SDTUnaryArithWithFlags>; 250def X86or_flag : SDNode<"X86ISD::OR", SDTBinaryArithWithFlags, 251 [SDNPCommutative]>; 252def X86xor_flag : SDNode<"X86ISD::XOR", SDTBinaryArithWithFlags, 253 [SDNPCommutative]>; 254def X86and_flag : SDNode<"X86ISD::AND", SDTBinaryArithWithFlags, 255 [SDNPCommutative]>; 256 257def X86lock_add : SDNode<"X86ISD::LADD", SDTLockBinaryArithWithFlags, 258 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, 259 SDNPMemOperand]>; 260def X86lock_sub : SDNode<"X86ISD::LSUB", SDTLockBinaryArithWithFlags, 261 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, 262 SDNPMemOperand]>; 263def X86lock_or : SDNode<"X86ISD::LOR", SDTLockBinaryArithWithFlags, 264 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, 265 SDNPMemOperand]>; 266def X86lock_xor : SDNode<"X86ISD::LXOR", SDTLockBinaryArithWithFlags, 267 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, 268 SDNPMemOperand]>; 269def X86lock_and : SDNode<"X86ISD::LAND", SDTLockBinaryArithWithFlags, 270 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, 271 SDNPMemOperand]>; 272 273def X86bextr : SDNode<"X86ISD::BEXTR", SDTIntBinOp>; 274 275def X86mul_imm : SDNode<"X86ISD::MUL_IMM", SDTIntBinOp>; 276 277def X86WinAlloca : SDNode<"X86ISD::WIN_ALLOCA", SDT_X86WIN_ALLOCA, 278 [SDNPHasChain, SDNPOutGlue]>; 279 280def X86SegAlloca : SDNode<"X86ISD::SEG_ALLOCA", SDT_X86SEG_ALLOCA, 281 [SDNPHasChain]>; 282 283def X86TLSCall : SDNode<"X86ISD::TLSCALL", SDT_X86TLSCALL, 284 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>; 285 286//===----------------------------------------------------------------------===// 287// X86 Operand Definitions. 288// 289 290// A version of ptr_rc which excludes SP, ESP, and RSP. This is used for 291// the index operand of an address, to conform to x86 encoding restrictions. 292def ptr_rc_nosp : PointerLikeRegClass<1>; 293 294// *mem - Operand definitions for the funky X86 addressing mode operands. 295// 296def X86MemAsmOperand : AsmOperandClass { 297 let Name = "Mem"; 298} 299let RenderMethod = "addMemOperands", SuperClasses = [X86MemAsmOperand] in { 300 def X86Mem8AsmOperand : AsmOperandClass { let Name = "Mem8"; } 301 def X86Mem16AsmOperand : AsmOperandClass { let Name = "Mem16"; } 302 def X86Mem32AsmOperand : AsmOperandClass { let Name = "Mem32"; } 303 def X86Mem64AsmOperand : AsmOperandClass { let Name = "Mem64"; } 304 def X86Mem80AsmOperand : AsmOperandClass { let Name = "Mem80"; } 305 def X86Mem128AsmOperand : AsmOperandClass { let Name = "Mem128"; } 306 def X86Mem256AsmOperand : AsmOperandClass { let Name = "Mem256"; } 307 def X86Mem512AsmOperand : AsmOperandClass { let Name = "Mem512"; } 308 // Gather mem operands 309 def X86Mem64_RC128Operand : AsmOperandClass { let Name = "Mem64_RC128"; } 310 def X86Mem128_RC128Operand : AsmOperandClass { let Name = "Mem128_RC128"; } 311 def X86Mem256_RC128Operand : AsmOperandClass { let Name = "Mem256_RC128"; } 312 def X86Mem128_RC256Operand : AsmOperandClass { let Name = "Mem128_RC256"; } 313 def X86Mem256_RC256Operand : AsmOperandClass { let Name = "Mem256_RC256"; } 314 315 def X86Mem64_RC128XOperand : AsmOperandClass { let Name = "Mem64_RC128X"; } 316 def X86Mem128_RC128XOperand : AsmOperandClass { let Name = "Mem128_RC128X"; } 317 def X86Mem256_RC128XOperand : AsmOperandClass { let Name = "Mem256_RC128X"; } 318 def X86Mem128_RC256XOperand : AsmOperandClass { let Name = "Mem128_RC256X"; } 319 def X86Mem256_RC256XOperand : AsmOperandClass { let Name = "Mem256_RC256X"; } 320 def X86Mem512_RC256XOperand : AsmOperandClass { let Name = "Mem512_RC256X"; } 321 def X86Mem512_RC512Operand : AsmOperandClass { let Name = "Mem512_RC512"; } 322} 323 324def X86AbsMemAsmOperand : AsmOperandClass { 325 let Name = "AbsMem"; 326 let SuperClasses = [X86MemAsmOperand]; 327} 328 329class X86MemOperand<string printMethod, 330 AsmOperandClass parserMatchClass = X86MemAsmOperand> : Operand<iPTR> { 331 let PrintMethod = printMethod; 332 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, SEGMENT_REG); 333 let ParserMatchClass = parserMatchClass; 334 let OperandType = "OPERAND_MEMORY"; 335} 336 337// Gather mem operands 338class X86VMemOperand<RegisterClass RC, string printMethod, 339 AsmOperandClass parserMatchClass> 340 : X86MemOperand<printMethod, parserMatchClass> { 341 let MIOperandInfo = (ops ptr_rc, i8imm, RC, i32imm, SEGMENT_REG); 342} 343 344def anymem : X86MemOperand<"printanymem">; 345 346def opaque32mem : X86MemOperand<"printopaquemem">; 347def opaque48mem : X86MemOperand<"printopaquemem">; 348def opaque80mem : X86MemOperand<"printopaquemem">; 349def opaque512mem : X86MemOperand<"printopaquemem">; 350 351def i8mem : X86MemOperand<"printi8mem", X86Mem8AsmOperand>; 352def i16mem : X86MemOperand<"printi16mem", X86Mem16AsmOperand>; 353def i32mem : X86MemOperand<"printi32mem", X86Mem32AsmOperand>; 354def i64mem : X86MemOperand<"printi64mem", X86Mem64AsmOperand>; 355def i128mem : X86MemOperand<"printi128mem", X86Mem128AsmOperand>; 356def i256mem : X86MemOperand<"printi256mem", X86Mem256AsmOperand>; 357def i512mem : X86MemOperand<"printi512mem", X86Mem512AsmOperand>; 358def f32mem : X86MemOperand<"printf32mem", X86Mem32AsmOperand>; 359def f64mem : X86MemOperand<"printf64mem", X86Mem64AsmOperand>; 360def f80mem : X86MemOperand<"printf80mem", X86Mem80AsmOperand>; 361def f128mem : X86MemOperand<"printf128mem", X86Mem128AsmOperand>; 362def f256mem : X86MemOperand<"printf256mem", X86Mem256AsmOperand>; 363def f512mem : X86MemOperand<"printf512mem", X86Mem512AsmOperand>; 364 365def v512mem : X86VMemOperand<VR512, "printf512mem", X86Mem512AsmOperand>; 366 367// Gather mem operands 368def vx64mem : X86VMemOperand<VR128, "printi64mem", X86Mem64_RC128Operand>; 369def vx128mem : X86VMemOperand<VR128, "printi128mem", X86Mem128_RC128Operand>; 370def vx256mem : X86VMemOperand<VR128, "printi256mem", X86Mem256_RC128Operand>; 371def vy128mem : X86VMemOperand<VR256, "printi128mem", X86Mem128_RC256Operand>; 372def vy256mem : X86VMemOperand<VR256, "printi256mem", X86Mem256_RC256Operand>; 373 374def vx64xmem : X86VMemOperand<VR128X, "printi64mem", X86Mem64_RC128XOperand>; 375def vx128xmem : X86VMemOperand<VR128X, "printi128mem", X86Mem128_RC128XOperand>; 376def vx256xmem : X86VMemOperand<VR128X, "printi256mem", X86Mem256_RC128XOperand>; 377def vy128xmem : X86VMemOperand<VR256, "printi128mem", X86Mem128_RC256XOperand>; 378def vy256xmem : X86VMemOperand<VR256X, "printi256mem", X86Mem256_RC256XOperand>; 379def vy512mem : X86VMemOperand<VR256X, "printi512mem", X86Mem512_RC256XOperand>; 380def vz512mem : X86VMemOperand<VR512, "printi512mem", X86Mem512_RC512Operand>; 381 382// A version of i8mem for use on x86-64 and x32 that uses a NOREX GPR instead 383// of a plain GPR, so that it doesn't potentially require a REX prefix. 384def ptr_rc_norex : PointerLikeRegClass<2>; 385def ptr_rc_norex_nosp : PointerLikeRegClass<3>; 386 387def i8mem_NOREX : Operand<iPTR> { 388 let PrintMethod = "printi8mem"; 389 let MIOperandInfo = (ops ptr_rc_norex, i8imm, ptr_rc_norex_nosp, i32imm, 390 SEGMENT_REG); 391 let ParserMatchClass = X86Mem8AsmOperand; 392 let OperandType = "OPERAND_MEMORY"; 393} 394 395// GPRs available for tailcall. 396// It represents GR32_TC, GR64_TC or GR64_TCW64. 397def ptr_rc_tailcall : PointerLikeRegClass<4>; 398 399// Special i32mem for addresses of load folding tail calls. These are not 400// allowed to use callee-saved registers since they must be scheduled 401// after callee-saved register are popped. 402def i32mem_TC : Operand<i32> { 403 let PrintMethod = "printi32mem"; 404 let MIOperandInfo = (ops ptr_rc_tailcall, i8imm, ptr_rc_tailcall, 405 i32imm, SEGMENT_REG); 406 let ParserMatchClass = X86Mem32AsmOperand; 407 let OperandType = "OPERAND_MEMORY"; 408} 409 410// Special i64mem for addresses of load folding tail calls. These are not 411// allowed to use callee-saved registers since they must be scheduled 412// after callee-saved register are popped. 413def i64mem_TC : Operand<i64> { 414 let PrintMethod = "printi64mem"; 415 let MIOperandInfo = (ops ptr_rc_tailcall, i8imm, 416 ptr_rc_tailcall, i32imm, SEGMENT_REG); 417 let ParserMatchClass = X86Mem64AsmOperand; 418 let OperandType = "OPERAND_MEMORY"; 419} 420 421let OperandType = "OPERAND_PCREL", 422 ParserMatchClass = X86AbsMemAsmOperand, 423 PrintMethod = "printPCRelImm" in { 424def i32imm_pcrel : Operand<i32>; 425def i16imm_pcrel : Operand<i16>; 426 427// Branch targets have OtherVT type and print as pc-relative values. 428def brtarget : Operand<OtherVT>; 429def brtarget8 : Operand<OtherVT>; 430 431} 432 433// Special parser to detect 16-bit mode to select 16-bit displacement. 434def X86AbsMem16AsmOperand : AsmOperandClass { 435 let Name = "AbsMem16"; 436 let RenderMethod = "addAbsMemOperands"; 437 let SuperClasses = [X86AbsMemAsmOperand]; 438} 439 440// Branch targets have OtherVT type and print as pc-relative values. 441let OperandType = "OPERAND_PCREL", 442 PrintMethod = "printPCRelImm" in { 443let ParserMatchClass = X86AbsMem16AsmOperand in 444 def brtarget16 : Operand<OtherVT>; 445let ParserMatchClass = X86AbsMemAsmOperand in 446 def brtarget32 : Operand<OtherVT>; 447} 448 449let RenderMethod = "addSrcIdxOperands" in { 450 def X86SrcIdx8Operand : AsmOperandClass { 451 let Name = "SrcIdx8"; 452 let SuperClasses = [X86Mem8AsmOperand]; 453 } 454 def X86SrcIdx16Operand : AsmOperandClass { 455 let Name = "SrcIdx16"; 456 let SuperClasses = [X86Mem16AsmOperand]; 457 } 458 def X86SrcIdx32Operand : AsmOperandClass { 459 let Name = "SrcIdx32"; 460 let SuperClasses = [X86Mem32AsmOperand]; 461 } 462 def X86SrcIdx64Operand : AsmOperandClass { 463 let Name = "SrcIdx64"; 464 let SuperClasses = [X86Mem64AsmOperand]; 465 } 466} // RenderMethod = "addSrcIdxOperands" 467 468let RenderMethod = "addDstIdxOperands" in { 469 def X86DstIdx8Operand : AsmOperandClass { 470 let Name = "DstIdx8"; 471 let SuperClasses = [X86Mem8AsmOperand]; 472 } 473 def X86DstIdx16Operand : AsmOperandClass { 474 let Name = "DstIdx16"; 475 let SuperClasses = [X86Mem16AsmOperand]; 476 } 477 def X86DstIdx32Operand : AsmOperandClass { 478 let Name = "DstIdx32"; 479 let SuperClasses = [X86Mem32AsmOperand]; 480 } 481 def X86DstIdx64Operand : AsmOperandClass { 482 let Name = "DstIdx64"; 483 let SuperClasses = [X86Mem64AsmOperand]; 484 } 485} // RenderMethod = "addDstIdxOperands" 486 487let RenderMethod = "addMemOffsOperands" in { 488 def X86MemOffs16_8AsmOperand : AsmOperandClass { 489 let Name = "MemOffs16_8"; 490 let SuperClasses = [X86Mem8AsmOperand]; 491 } 492 def X86MemOffs16_16AsmOperand : AsmOperandClass { 493 let Name = "MemOffs16_16"; 494 let SuperClasses = [X86Mem16AsmOperand]; 495 } 496 def X86MemOffs16_32AsmOperand : AsmOperandClass { 497 let Name = "MemOffs16_32"; 498 let SuperClasses = [X86Mem32AsmOperand]; 499 } 500 def X86MemOffs32_8AsmOperand : AsmOperandClass { 501 let Name = "MemOffs32_8"; 502 let SuperClasses = [X86Mem8AsmOperand]; 503 } 504 def X86MemOffs32_16AsmOperand : AsmOperandClass { 505 let Name = "MemOffs32_16"; 506 let SuperClasses = [X86Mem16AsmOperand]; 507 } 508 def X86MemOffs32_32AsmOperand : AsmOperandClass { 509 let Name = "MemOffs32_32"; 510 let SuperClasses = [X86Mem32AsmOperand]; 511 } 512 def X86MemOffs32_64AsmOperand : AsmOperandClass { 513 let Name = "MemOffs32_64"; 514 let SuperClasses = [X86Mem64AsmOperand]; 515 } 516 def X86MemOffs64_8AsmOperand : AsmOperandClass { 517 let Name = "MemOffs64_8"; 518 let SuperClasses = [X86Mem8AsmOperand]; 519 } 520 def X86MemOffs64_16AsmOperand : AsmOperandClass { 521 let Name = "MemOffs64_16"; 522 let SuperClasses = [X86Mem16AsmOperand]; 523 } 524 def X86MemOffs64_32AsmOperand : AsmOperandClass { 525 let Name = "MemOffs64_32"; 526 let SuperClasses = [X86Mem32AsmOperand]; 527 } 528 def X86MemOffs64_64AsmOperand : AsmOperandClass { 529 let Name = "MemOffs64_64"; 530 let SuperClasses = [X86Mem64AsmOperand]; 531 } 532} // RenderMethod = "addMemOffsOperands" 533 534class X86SrcIdxOperand<string printMethod, AsmOperandClass parserMatchClass> 535 : X86MemOperand<printMethod, parserMatchClass> { 536 let MIOperandInfo = (ops ptr_rc, SEGMENT_REG); 537} 538 539class X86DstIdxOperand<string printMethod, AsmOperandClass parserMatchClass> 540 : X86MemOperand<printMethod, parserMatchClass> { 541 let MIOperandInfo = (ops ptr_rc); 542} 543 544def srcidx8 : X86SrcIdxOperand<"printSrcIdx8", X86SrcIdx8Operand>; 545def srcidx16 : X86SrcIdxOperand<"printSrcIdx16", X86SrcIdx16Operand>; 546def srcidx32 : X86SrcIdxOperand<"printSrcIdx32", X86SrcIdx32Operand>; 547def srcidx64 : X86SrcIdxOperand<"printSrcIdx64", X86SrcIdx64Operand>; 548def dstidx8 : X86DstIdxOperand<"printDstIdx8", X86DstIdx8Operand>; 549def dstidx16 : X86DstIdxOperand<"printDstIdx16", X86DstIdx16Operand>; 550def dstidx32 : X86DstIdxOperand<"printDstIdx32", X86DstIdx32Operand>; 551def dstidx64 : X86DstIdxOperand<"printDstIdx64", X86DstIdx64Operand>; 552 553class X86MemOffsOperand<Operand immOperand, string printMethod, 554 AsmOperandClass parserMatchClass> 555 : X86MemOperand<printMethod, parserMatchClass> { 556 let MIOperandInfo = (ops immOperand, SEGMENT_REG); 557} 558 559def offset16_8 : X86MemOffsOperand<i16imm, "printMemOffs8", 560 X86MemOffs16_8AsmOperand>; 561def offset16_16 : X86MemOffsOperand<i16imm, "printMemOffs16", 562 X86MemOffs16_16AsmOperand>; 563def offset16_32 : X86MemOffsOperand<i16imm, "printMemOffs32", 564 X86MemOffs16_32AsmOperand>; 565def offset32_8 : X86MemOffsOperand<i32imm, "printMemOffs8", 566 X86MemOffs32_8AsmOperand>; 567def offset32_16 : X86MemOffsOperand<i32imm, "printMemOffs16", 568 X86MemOffs32_16AsmOperand>; 569def offset32_32 : X86MemOffsOperand<i32imm, "printMemOffs32", 570 X86MemOffs32_32AsmOperand>; 571def offset32_64 : X86MemOffsOperand<i32imm, "printMemOffs64", 572 X86MemOffs32_64AsmOperand>; 573def offset64_8 : X86MemOffsOperand<i64imm, "printMemOffs8", 574 X86MemOffs64_8AsmOperand>; 575def offset64_16 : X86MemOffsOperand<i64imm, "printMemOffs16", 576 X86MemOffs64_16AsmOperand>; 577def offset64_32 : X86MemOffsOperand<i64imm, "printMemOffs32", 578 X86MemOffs64_32AsmOperand>; 579def offset64_64 : X86MemOffsOperand<i64imm, "printMemOffs64", 580 X86MemOffs64_64AsmOperand>; 581 582def SSECC : Operand<i8> { 583 let PrintMethod = "printSSEAVXCC"; 584 let OperandType = "OPERAND_IMMEDIATE"; 585} 586 587def i8immZExt3 : ImmLeaf<i8, [{ 588 return Imm >= 0 && Imm < 8; 589}]>; 590 591def AVXCC : Operand<i8> { 592 let PrintMethod = "printSSEAVXCC"; 593 let OperandType = "OPERAND_IMMEDIATE"; 594} 595 596def i8immZExt5 : ImmLeaf<i8, [{ 597 return Imm >= 0 && Imm < 32; 598}]>; 599 600def AVX512ICC : Operand<i8> { 601 let PrintMethod = "printSSEAVXCC"; 602 let OperandType = "OPERAND_IMMEDIATE"; 603} 604 605def XOPCC : Operand<i8> { 606 let PrintMethod = "printXOPCC"; 607 let OperandType = "OPERAND_IMMEDIATE"; 608} 609 610class ImmSExtAsmOperandClass : AsmOperandClass { 611 let SuperClasses = [ImmAsmOperand]; 612 let RenderMethod = "addImmOperands"; 613} 614 615def X86GR32orGR64AsmOperand : AsmOperandClass { 616 let Name = "GR32orGR64"; 617} 618 619def GR32orGR64 : RegisterOperand<GR32> { 620 let ParserMatchClass = X86GR32orGR64AsmOperand; 621} 622def AVX512RCOperand : AsmOperandClass { 623 let Name = "AVX512RC"; 624} 625def AVX512RC : Operand<i32> { 626 let PrintMethod = "printRoundingControl"; 627 let OperandType = "OPERAND_IMMEDIATE"; 628 let ParserMatchClass = AVX512RCOperand; 629} 630 631// Sign-extended immediate classes. We don't need to define the full lattice 632// here because there is no instruction with an ambiguity between ImmSExti64i32 633// and ImmSExti32i8. 634// 635// The strange ranges come from the fact that the assembler always works with 636// 64-bit immediates, but for a 16-bit target value we want to accept both "-1" 637// (which will be a -1ULL), and "0xFF" (-1 in 16-bits). 638 639// [0, 0x7FFFFFFF] | 640// [0xFFFFFFFF80000000, 0xFFFFFFFFFFFFFFFF] 641def ImmSExti64i32AsmOperand : ImmSExtAsmOperandClass { 642 let Name = "ImmSExti64i32"; 643} 644 645// [0, 0x0000007F] | [0x000000000000FF80, 0x000000000000FFFF] | 646// [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF] 647def ImmSExti16i8AsmOperand : ImmSExtAsmOperandClass { 648 let Name = "ImmSExti16i8"; 649 let SuperClasses = [ImmSExti64i32AsmOperand]; 650} 651 652// [0, 0x0000007F] | [0x00000000FFFFFF80, 0x00000000FFFFFFFF] | 653// [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF] 654def ImmSExti32i8AsmOperand : ImmSExtAsmOperandClass { 655 let Name = "ImmSExti32i8"; 656} 657 658// [0, 0x0000007F] | 659// [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF] 660def ImmSExti64i8AsmOperand : ImmSExtAsmOperandClass { 661 let Name = "ImmSExti64i8"; 662 let SuperClasses = [ImmSExti16i8AsmOperand, ImmSExti32i8AsmOperand, 663 ImmSExti64i32AsmOperand]; 664} 665 666// Unsigned immediate used by SSE/AVX instructions 667// [0, 0xFF] 668// [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF] 669def ImmUnsignedi8AsmOperand : AsmOperandClass { 670 let Name = "ImmUnsignedi8"; 671 let RenderMethod = "addImmOperands"; 672} 673 674// A couple of more descriptive operand definitions. 675// 16-bits but only 8 bits are significant. 676def i16i8imm : Operand<i16> { 677 let ParserMatchClass = ImmSExti16i8AsmOperand; 678 let OperandType = "OPERAND_IMMEDIATE"; 679} 680// 32-bits but only 8 bits are significant. 681def i32i8imm : Operand<i32> { 682 let ParserMatchClass = ImmSExti32i8AsmOperand; 683 let OperandType = "OPERAND_IMMEDIATE"; 684} 685 686// 64-bits but only 32 bits are significant. 687def i64i32imm : Operand<i64> { 688 let ParserMatchClass = ImmSExti64i32AsmOperand; 689 let OperandType = "OPERAND_IMMEDIATE"; 690} 691 692// 64-bits but only 8 bits are significant. 693def i64i8imm : Operand<i64> { 694 let ParserMatchClass = ImmSExti64i8AsmOperand; 695 let OperandType = "OPERAND_IMMEDIATE"; 696} 697 698// Unsigned 8-bit immediate used by SSE/AVX instructions. 699def u8imm : Operand<i8> { 700 let PrintMethod = "printU8Imm"; 701 let ParserMatchClass = ImmUnsignedi8AsmOperand; 702 let OperandType = "OPERAND_IMMEDIATE"; 703} 704 705// 32-bit immediate but only 8-bits are significant and they are unsigned. 706// Used by some SSE/AVX instructions that use intrinsics. 707def i32u8imm : Operand<i32> { 708 let PrintMethod = "printU8Imm"; 709 let ParserMatchClass = ImmUnsignedi8AsmOperand; 710 let OperandType = "OPERAND_IMMEDIATE"; 711} 712 713// 64-bits but only 32 bits are significant, and those bits are treated as being 714// pc relative. 715def i64i32imm_pcrel : Operand<i64> { 716 let PrintMethod = "printPCRelImm"; 717 let ParserMatchClass = X86AbsMemAsmOperand; 718 let OperandType = "OPERAND_PCREL"; 719} 720 721def lea64_32mem : Operand<i32> { 722 let PrintMethod = "printanymem"; 723 let MIOperandInfo = (ops GR64, i8imm, GR64_NOSP, i32imm, SEGMENT_REG); 724 let ParserMatchClass = X86MemAsmOperand; 725} 726 727// Memory operands that use 64-bit pointers in both ILP32 and LP64. 728def lea64mem : Operand<i64> { 729 let PrintMethod = "printanymem"; 730 let MIOperandInfo = (ops GR64, i8imm, GR64_NOSP, i32imm, SEGMENT_REG); 731 let ParserMatchClass = X86MemAsmOperand; 732} 733 734 735//===----------------------------------------------------------------------===// 736// X86 Complex Pattern Definitions. 737// 738 739// Define X86-specific addressing mode. 740def addr : ComplexPattern<iPTR, 5, "selectAddr", [], [SDNPWantParent]>; 741def lea32addr : ComplexPattern<i32, 5, "selectLEAAddr", 742 [add, sub, mul, X86mul_imm, shl, or, frameindex], 743 []>; 744// In 64-bit mode 32-bit LEAs can use RIP-relative addressing. 745def lea64_32addr : ComplexPattern<i32, 5, "selectLEA64_32Addr", 746 [add, sub, mul, X86mul_imm, shl, or, 747 frameindex, X86WrapperRIP], 748 []>; 749 750def tls32addr : ComplexPattern<i32, 5, "selectTLSADDRAddr", 751 [tglobaltlsaddr], []>; 752 753def tls32baseaddr : ComplexPattern<i32, 5, "selectTLSADDRAddr", 754 [tglobaltlsaddr], []>; 755 756def lea64addr : ComplexPattern<i64, 5, "selectLEAAddr", 757 [add, sub, mul, X86mul_imm, shl, or, frameindex, 758 X86WrapperRIP], []>; 759 760def tls64addr : ComplexPattern<i64, 5, "selectTLSADDRAddr", 761 [tglobaltlsaddr], []>; 762 763def tls64baseaddr : ComplexPattern<i64, 5, "selectTLSADDRAddr", 764 [tglobaltlsaddr], []>; 765 766def vectoraddr : ComplexPattern<iPTR, 5, "selectVectorAddr", [],[SDNPWantParent]>; 767 768//===----------------------------------------------------------------------===// 769// X86 Instruction Predicate Definitions. 770def TruePredicate : Predicate<"true">; 771 772def HasCMov : Predicate<"Subtarget->hasCMov()">; 773def NoCMov : Predicate<"!Subtarget->hasCMov()">; 774 775def HasMMX : Predicate<"Subtarget->hasMMX()">; 776def Has3DNow : Predicate<"Subtarget->has3DNow()">; 777def Has3DNowA : Predicate<"Subtarget->has3DNowA()">; 778def HasSSE1 : Predicate<"Subtarget->hasSSE1()">; 779def UseSSE1 : Predicate<"Subtarget->hasSSE1() && !Subtarget->hasAVX()">; 780def HasSSE2 : Predicate<"Subtarget->hasSSE2()">; 781def UseSSE2 : Predicate<"Subtarget->hasSSE2() && !Subtarget->hasAVX()">; 782def HasSSE3 : Predicate<"Subtarget->hasSSE3()">; 783def UseSSE3 : Predicate<"Subtarget->hasSSE3() && !Subtarget->hasAVX()">; 784def HasSSSE3 : Predicate<"Subtarget->hasSSSE3()">; 785def UseSSSE3 : Predicate<"Subtarget->hasSSSE3() && !Subtarget->hasAVX()">; 786def HasSSE41 : Predicate<"Subtarget->hasSSE41()">; 787def NoSSE41 : Predicate<"!Subtarget->hasSSE41()">; 788def UseSSE41 : Predicate<"Subtarget->hasSSE41() && !Subtarget->hasAVX()">; 789def HasSSE42 : Predicate<"Subtarget->hasSSE42()">; 790def UseSSE42 : Predicate<"Subtarget->hasSSE42() && !Subtarget->hasAVX()">; 791def HasSSE4A : Predicate<"Subtarget->hasSSE4A()">; 792def HasAVX : Predicate<"Subtarget->hasAVX()">; 793def HasAVX2 : Predicate<"Subtarget->hasAVX2()">; 794def HasAVX1Only : Predicate<"Subtarget->hasAVX() && !Subtarget->hasAVX2()">; 795def HasAVX512 : Predicate<"Subtarget->hasAVX512()">, 796 AssemblerPredicate<"FeatureAVX512", "AVX-512 ISA">; 797def UseAVX : Predicate<"Subtarget->hasAVX() && !Subtarget->hasAVX512()">; 798def UseAVX2 : Predicate<"Subtarget->hasAVX2() && !Subtarget->hasAVX512()">; 799def NoAVX512 : Predicate<"!Subtarget->hasAVX512()">; 800def HasCDI : Predicate<"Subtarget->hasCDI()">, 801 AssemblerPredicate<"FeatureCDI", "AVX-512 CD ISA">; 802def HasPFI : Predicate<"Subtarget->hasPFI()">, 803 AssemblerPredicate<"FeaturePFI", "AVX-512 PF ISA">; 804def HasERI : Predicate<"Subtarget->hasERI()">, 805 AssemblerPredicate<"FeatureERI", "AVX-512 ER ISA">; 806def HasDQI : Predicate<"Subtarget->hasDQI()">, 807 AssemblerPredicate<"FeatureDQI", "AVX-512 DQ ISA">; 808def NoDQI : Predicate<"!Subtarget->hasDQI()">; 809def HasBWI : Predicate<"Subtarget->hasBWI()">, 810 AssemblerPredicate<"FeatureBWI", "AVX-512 BW ISA">; 811def NoBWI : Predicate<"!Subtarget->hasBWI()">; 812def HasVLX : Predicate<"Subtarget->hasVLX()">, 813 AssemblerPredicate<"FeatureVLX", "AVX-512 VL ISA">; 814def NoVLX : Predicate<"!Subtarget->hasVLX()">; 815def NoVLX_Or_NoBWI : Predicate<"!Subtarget->hasVLX() || !Subtarget->hasBWI()">; 816def NoVLX_Or_NoDQI : Predicate<"!Subtarget->hasVLX() || !Subtarget->hasDQI()">; 817def PKU : Predicate<"Subtarget->hasPKU()">; 818 819def HasPOPCNT : Predicate<"Subtarget->hasPOPCNT()">; 820def HasAES : Predicate<"Subtarget->hasAES()">; 821def HasFXSR : Predicate<"Subtarget->hasFXSR()">; 822def HasXSAVE : Predicate<"Subtarget->hasXSAVE()">; 823def HasXSAVEOPT : Predicate<"Subtarget->hasXSAVEOPT()">; 824def HasXSAVEC : Predicate<"Subtarget->hasXSAVEC()">; 825def HasXSAVES : Predicate<"Subtarget->hasXSAVES()">; 826def HasPCLMUL : Predicate<"Subtarget->hasPCLMUL()">; 827def HasFMA : Predicate<"Subtarget->hasFMA()">; 828def UseFMAOnAVX : Predicate<"Subtarget->hasFMA() && !Subtarget->hasAVX512()">; 829def HasFMA4 : Predicate<"Subtarget->hasFMA4()">; 830def HasXOP : Predicate<"Subtarget->hasXOP()">; 831def HasTBM : Predicate<"Subtarget->hasTBM()">; 832def HasMOVBE : Predicate<"Subtarget->hasMOVBE()">; 833def HasRDRAND : Predicate<"Subtarget->hasRDRAND()">; 834def HasF16C : Predicate<"Subtarget->hasF16C()">; 835def HasFSGSBase : Predicate<"Subtarget->hasFSGSBase()">; 836def HasLZCNT : Predicate<"Subtarget->hasLZCNT()">; 837def HasBMI : Predicate<"Subtarget->hasBMI()">; 838def HasBMI2 : Predicate<"Subtarget->hasBMI2()">; 839def HasVBMI : Predicate<"Subtarget->hasVBMI()">, 840 AssemblerPredicate<"FeatureVBMI", "AVX-512 VBMI ISA">; 841def HasIFMA : Predicate<"Subtarget->hasIFMA()">, 842 AssemblerPredicate<"FeatureIFMA", "AVX-512 IFMA ISA">; 843def HasRTM : Predicate<"Subtarget->hasRTM()">; 844def HasHLE : Predicate<"Subtarget->hasHLE()">; 845def HasTSX : Predicate<"Subtarget->hasRTM() || Subtarget->hasHLE()">; 846def HasADX : Predicate<"Subtarget->hasADX()">; 847def HasSHA : Predicate<"Subtarget->hasSHA()">; 848def HasPRFCHW : Predicate<"Subtarget->hasPRFCHW()">; 849def HasRDSEED : Predicate<"Subtarget->hasRDSEED()">; 850def HasPrefetchW : Predicate<"Subtarget->hasPRFCHW()">; 851def HasLAHFSAHF : Predicate<"Subtarget->hasLAHFSAHF()">; 852def HasMWAITX : Predicate<"Subtarget->hasMWAITX()">; 853def FPStackf32 : Predicate<"!Subtarget->hasSSE1()">; 854def FPStackf64 : Predicate<"!Subtarget->hasSSE2()">; 855def HasMPX : Predicate<"Subtarget->hasMPX()">; 856def HasCmpxchg16b: Predicate<"Subtarget->hasCmpxchg16b()">; 857def Not64BitMode : Predicate<"!Subtarget->is64Bit()">, 858 AssemblerPredicate<"!Mode64Bit", "Not 64-bit mode">; 859def In64BitMode : Predicate<"Subtarget->is64Bit()">, 860 AssemblerPredicate<"Mode64Bit", "64-bit mode">; 861def IsLP64 : Predicate<"Subtarget->isTarget64BitLP64()">; 862def NotLP64 : Predicate<"!Subtarget->isTarget64BitLP64()">; 863def In16BitMode : Predicate<"Subtarget->is16Bit()">, 864 AssemblerPredicate<"Mode16Bit", "16-bit mode">; 865def Not16BitMode : Predicate<"!Subtarget->is16Bit()">, 866 AssemblerPredicate<"!Mode16Bit", "Not 16-bit mode">; 867def In32BitMode : Predicate<"Subtarget->is32Bit()">, 868 AssemblerPredicate<"Mode32Bit", "32-bit mode">; 869def IsWin64 : Predicate<"Subtarget->isTargetWin64()">; 870def NotWin64 : Predicate<"!Subtarget->isTargetWin64()">; 871def NotWin64WithoutFP : Predicate<"!Subtarget->isTargetWin64() ||" 872 "Subtarget->getFrameLowering()->hasFP(*MF)">; 873def IsPS4 : Predicate<"Subtarget->isTargetPS4()">; 874def NotPS4 : Predicate<"!Subtarget->isTargetPS4()">; 875def IsNaCl : Predicate<"Subtarget->isTargetNaCl()">; 876def NotNaCl : Predicate<"!Subtarget->isTargetNaCl()">; 877def SmallCode : Predicate<"TM.getCodeModel() == CodeModel::Small">; 878def KernelCode : Predicate<"TM.getCodeModel() == CodeModel::Kernel">; 879def FarData : Predicate<"TM.getCodeModel() != CodeModel::Small &&" 880 "TM.getCodeModel() != CodeModel::Kernel">; 881def NearData : Predicate<"TM.getCodeModel() == CodeModel::Small ||" 882 "TM.getCodeModel() == CodeModel::Kernel">; 883def IsNotPIC : Predicate<"!TM.isPositionIndependent()">; 884def OptForSize : Predicate<"OptForSize">; 885def OptForMinSize : Predicate<"OptForMinSize">; 886def OptForSpeed : Predicate<"!OptForSize">; 887def FastBTMem : Predicate<"!Subtarget->isBTMemSlow()">; 888def CallImmAddr : Predicate<"Subtarget->isLegalToCallImmediateAddr()">; 889def FavorMemIndirectCall : Predicate<"!Subtarget->callRegIndirect()">; 890def NotSlowIncDec : Predicate<"!Subtarget->slowIncDec()">; 891def HasFastMem32 : Predicate<"!Subtarget->isUnalignedMem32Slow()">; 892def HasMFence : Predicate<"Subtarget->hasMFence()">; 893 894//===----------------------------------------------------------------------===// 895// X86 Instruction Format Definitions. 896// 897 898include "X86InstrFormats.td" 899 900//===----------------------------------------------------------------------===// 901// Pattern fragments. 902// 903 904// X86 specific condition code. These correspond to CondCode in 905// X86InstrInfo.h. They must be kept in synch. 906def X86_COND_A : PatLeaf<(i8 0)>; // alt. COND_NBE 907def X86_COND_AE : PatLeaf<(i8 1)>; // alt. COND_NC 908def X86_COND_B : PatLeaf<(i8 2)>; // alt. COND_C 909def X86_COND_BE : PatLeaf<(i8 3)>; // alt. COND_NA 910def X86_COND_E : PatLeaf<(i8 4)>; // alt. COND_Z 911def X86_COND_G : PatLeaf<(i8 5)>; // alt. COND_NLE 912def X86_COND_GE : PatLeaf<(i8 6)>; // alt. COND_NL 913def X86_COND_L : PatLeaf<(i8 7)>; // alt. COND_NGE 914def X86_COND_LE : PatLeaf<(i8 8)>; // alt. COND_NG 915def X86_COND_NE : PatLeaf<(i8 9)>; // alt. COND_NZ 916def X86_COND_NO : PatLeaf<(i8 10)>; 917def X86_COND_NP : PatLeaf<(i8 11)>; // alt. COND_PO 918def X86_COND_NS : PatLeaf<(i8 12)>; 919def X86_COND_O : PatLeaf<(i8 13)>; 920def X86_COND_P : PatLeaf<(i8 14)>; // alt. COND_PE 921def X86_COND_S : PatLeaf<(i8 15)>; 922 923def i16immSExt8 : ImmLeaf<i16, [{ return isInt<8>(Imm); }]>; 924def i32immSExt8 : ImmLeaf<i32, [{ return isInt<8>(Imm); }]>; 925def i64immSExt8 : ImmLeaf<i64, [{ return isInt<8>(Imm); }]>; 926 927// If we have multiple users of an immediate, it's much smaller to reuse 928// the register, rather than encode the immediate in every instruction. 929// This has the risk of increasing register pressure from stretched live 930// ranges, however, the immediates should be trivial to rematerialize by 931// the RA in the event of high register pressure. 932// TODO : This is currently enabled for stores and binary ops. There are more 933// cases for which this can be enabled, though this catches the bulk of the 934// issues. 935// TODO2 : This should really also be enabled under O2, but there's currently 936// an issue with RA where we don't pull the constants into their users 937// when we rematerialize them. I'll follow-up on enabling O2 after we fix that 938// issue. 939// TODO3 : This is currently limited to single basic blocks (DAG creation 940// pulls block immediates to the top and merges them if necessary). 941// Eventually, it would be nice to allow ConstantHoisting to merge constants 942// globally for potentially added savings. 943// 944def imm8_su : PatLeaf<(i8 imm), [{ 945 return !shouldAvoidImmediateInstFormsForSize(N); 946}]>; 947def imm16_su : PatLeaf<(i16 imm), [{ 948 return !shouldAvoidImmediateInstFormsForSize(N); 949}]>; 950def imm32_su : PatLeaf<(i32 imm), [{ 951 return !shouldAvoidImmediateInstFormsForSize(N); 952}]>; 953 954def i16immSExt8_su : PatLeaf<(i16immSExt8), [{ 955 return !shouldAvoidImmediateInstFormsForSize(N); 956}]>; 957def i32immSExt8_su : PatLeaf<(i32immSExt8), [{ 958 return !shouldAvoidImmediateInstFormsForSize(N); 959}]>; 960 961 962def i64immSExt32 : ImmLeaf<i64, [{ return isInt<32>(Imm); }]>; 963 964 965// i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit 966// unsigned field. 967def i64immZExt32 : ImmLeaf<i64, [{ return isUInt<32>(Imm); }]>; 968 969def i64immZExt32SExt8 : ImmLeaf<i64, [{ 970 return isUInt<32>(Imm) && isInt<8>(static_cast<int32_t>(Imm)); 971}]>; 972 973// Helper fragments for loads. 974// It's always safe to treat a anyext i16 load as a i32 load if the i16 is 975// known to be 32-bit aligned or better. Ditto for i8 to i16. 976def loadi16 : PatFrag<(ops node:$ptr), (i16 (unindexedload node:$ptr)), [{ 977 LoadSDNode *LD = cast<LoadSDNode>(N); 978 ISD::LoadExtType ExtType = LD->getExtensionType(); 979 if (ExtType == ISD::NON_EXTLOAD) 980 return true; 981 if (ExtType == ISD::EXTLOAD) 982 return LD->getAlignment() >= 2 && !LD->isVolatile(); 983 return false; 984}]>; 985 986def loadi16_anyext : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)),[{ 987 LoadSDNode *LD = cast<LoadSDNode>(N); 988 ISD::LoadExtType ExtType = LD->getExtensionType(); 989 if (ExtType == ISD::EXTLOAD) 990 return LD->getAlignment() >= 2 && !LD->isVolatile(); 991 return false; 992}]>; 993 994def loadi32 : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)), [{ 995 LoadSDNode *LD = cast<LoadSDNode>(N); 996 ISD::LoadExtType ExtType = LD->getExtensionType(); 997 if (ExtType == ISD::NON_EXTLOAD) 998 return true; 999 if (ExtType == ISD::EXTLOAD) 1000 return LD->getAlignment() >= 4 && !LD->isVolatile(); 1001 return false; 1002}]>; 1003 1004def loadi8 : PatFrag<(ops node:$ptr), (i8 (load node:$ptr))>; 1005def loadi64 : PatFrag<(ops node:$ptr), (i64 (load node:$ptr))>; 1006def loadf32 : PatFrag<(ops node:$ptr), (f32 (load node:$ptr))>; 1007def loadf64 : PatFrag<(ops node:$ptr), (f64 (load node:$ptr))>; 1008def loadf80 : PatFrag<(ops node:$ptr), (f80 (load node:$ptr))>; 1009def loadf128 : PatFrag<(ops node:$ptr), (f128 (load node:$ptr))>; 1010 1011def sextloadi16i8 : PatFrag<(ops node:$ptr), (i16 (sextloadi8 node:$ptr))>; 1012def sextloadi32i8 : PatFrag<(ops node:$ptr), (i32 (sextloadi8 node:$ptr))>; 1013def sextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextloadi16 node:$ptr))>; 1014def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>; 1015def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>; 1016def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>; 1017 1018def zextloadi8i1 : PatFrag<(ops node:$ptr), (i8 (zextloadi1 node:$ptr))>; 1019def zextloadi16i1 : PatFrag<(ops node:$ptr), (i16 (zextloadi1 node:$ptr))>; 1020def zextloadi32i1 : PatFrag<(ops node:$ptr), (i32 (zextloadi1 node:$ptr))>; 1021def zextloadi16i8 : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>; 1022def zextloadi32i8 : PatFrag<(ops node:$ptr), (i32 (zextloadi8 node:$ptr))>; 1023def zextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextloadi16 node:$ptr))>; 1024def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>; 1025def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>; 1026def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>; 1027def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>; 1028 1029def extloadi8i1 : PatFrag<(ops node:$ptr), (i8 (extloadi1 node:$ptr))>; 1030def extloadi16i1 : PatFrag<(ops node:$ptr), (i16 (extloadi1 node:$ptr))>; 1031def extloadi32i1 : PatFrag<(ops node:$ptr), (i32 (extloadi1 node:$ptr))>; 1032def extloadi16i8 : PatFrag<(ops node:$ptr), (i16 (extloadi8 node:$ptr))>; 1033def extloadi32i8 : PatFrag<(ops node:$ptr), (i32 (extloadi8 node:$ptr))>; 1034def extloadi32i16 : PatFrag<(ops node:$ptr), (i32 (extloadi16 node:$ptr))>; 1035def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>; 1036def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>; 1037def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>; 1038def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>; 1039 1040 1041// An 'and' node with a single use. 1042def and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{ 1043 return N->hasOneUse(); 1044}]>; 1045// An 'srl' node with a single use. 1046def srl_su : PatFrag<(ops node:$lhs, node:$rhs), (srl node:$lhs, node:$rhs), [{ 1047 return N->hasOneUse(); 1048}]>; 1049// An 'trunc' node with a single use. 1050def trunc_su : PatFrag<(ops node:$src), (trunc node:$src), [{ 1051 return N->hasOneUse(); 1052}]>; 1053 1054//===----------------------------------------------------------------------===// 1055// Instruction list. 1056// 1057 1058// Nop 1059let hasSideEffects = 0, SchedRW = [WriteZero] in { 1060 def NOOP : I<0x90, RawFrm, (outs), (ins), "nop", [], IIC_NOP>; 1061 def NOOPW : I<0x1f, MRMXm, (outs), (ins i16mem:$zero), 1062 "nop{w}\t$zero", [], IIC_NOP>, TB, OpSize16; 1063 def NOOPL : I<0x1f, MRMXm, (outs), (ins i32mem:$zero), 1064 "nop{l}\t$zero", [], IIC_NOP>, TB, OpSize32; 1065} 1066 1067 1068// Constructing a stack frame. 1069def ENTER : Ii16<0xC8, RawFrmImm8, (outs), (ins i16imm:$len, i8imm:$lvl), 1070 "enter\t$len, $lvl", [], IIC_ENTER>, Sched<[WriteMicrocoded]>; 1071 1072let SchedRW = [WriteALU] in { 1073let Defs = [EBP, ESP], Uses = [EBP, ESP], mayLoad = 1, hasSideEffects=0 in 1074def LEAVE : I<0xC9, RawFrm, 1075 (outs), (ins), "leave", [], IIC_LEAVE>, 1076 Requires<[Not64BitMode]>; 1077 1078let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, hasSideEffects = 0 in 1079def LEAVE64 : I<0xC9, RawFrm, 1080 (outs), (ins), "leave", [], IIC_LEAVE>, 1081 Requires<[In64BitMode]>; 1082} // SchedRW 1083 1084//===----------------------------------------------------------------------===// 1085// Miscellaneous Instructions. 1086// 1087 1088let isBarrier = 1, hasSideEffects = 1, usesCustomInserter = 1 in 1089 def Int_eh_sjlj_setup_dispatch 1090 : PseudoI<(outs), (ins), [(X86eh_sjlj_setup_dispatch)]>; 1091 1092let Defs = [ESP], Uses = [ESP], hasSideEffects=0 in { 1093let mayLoad = 1, SchedRW = [WriteLoad] in { 1094def POP16r : I<0x58, AddRegFrm, (outs GR16:$reg), (ins), "pop{w}\t$reg", [], 1095 IIC_POP_REG16>, OpSize16; 1096def POP32r : I<0x58, AddRegFrm, (outs GR32:$reg), (ins), "pop{l}\t$reg", [], 1097 IIC_POP_REG>, OpSize32, Requires<[Not64BitMode]>; 1098def POP16rmr: I<0x8F, MRM0r, (outs GR16:$reg), (ins), "pop{w}\t$reg", [], 1099 IIC_POP_REG>, OpSize16; 1100def POP16rmm: I<0x8F, MRM0m, (outs), (ins i16mem:$dst), "pop{w}\t$dst", [], 1101 IIC_POP_MEM>, OpSize16; 1102def POP32rmr: I<0x8F, MRM0r, (outs GR32:$reg), (ins), "pop{l}\t$reg", [], 1103 IIC_POP_REG>, OpSize32, Requires<[Not64BitMode]>; 1104def POP32rmm: I<0x8F, MRM0m, (outs), (ins i32mem:$dst), "pop{l}\t$dst", [], 1105 IIC_POP_MEM>, OpSize32, Requires<[Not64BitMode]>; 1106} // mayLoad, SchedRW 1107 1108let mayStore = 1, SchedRW = [WriteStore] in { 1109def PUSH16r : I<0x50, AddRegFrm, (outs), (ins GR16:$reg), "push{w}\t$reg",[], 1110 IIC_PUSH_REG>, OpSize16; 1111def PUSH32r : I<0x50, AddRegFrm, (outs), (ins GR32:$reg), "push{l}\t$reg",[], 1112 IIC_PUSH_REG>, OpSize32, Requires<[Not64BitMode]>; 1113def PUSH16rmr: I<0xFF, MRM6r, (outs), (ins GR16:$reg), "push{w}\t$reg",[], 1114 IIC_PUSH_REG>, OpSize16; 1115def PUSH32rmr: I<0xFF, MRM6r, (outs), (ins GR32:$reg), "push{l}\t$reg",[], 1116 IIC_PUSH_REG>, OpSize32, Requires<[Not64BitMode]>; 1117 1118def PUSH16i8 : Ii8<0x6a, RawFrm, (outs), (ins i16i8imm:$imm), 1119 "push{w}\t$imm", [], IIC_PUSH_IMM>, OpSize16; 1120def PUSHi16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm), 1121 "push{w}\t$imm", [], IIC_PUSH_IMM>, OpSize16; 1122 1123def PUSH32i8 : Ii8<0x6a, RawFrm, (outs), (ins i32i8imm:$imm), 1124 "push{l}\t$imm", [], IIC_PUSH_IMM>, OpSize32, 1125 Requires<[Not64BitMode]>; 1126def PUSHi32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm), 1127 "push{l}\t$imm", [], IIC_PUSH_IMM>, OpSize32, 1128 Requires<[Not64BitMode]>; 1129} // mayStore, SchedRW 1130 1131let mayLoad = 1, mayStore = 1, SchedRW = [WriteRMW] in { 1132def PUSH16rmm: I<0xFF, MRM6m, (outs), (ins i16mem:$src), "push{w}\t$src",[], 1133 IIC_PUSH_MEM>, OpSize16; 1134def PUSH32rmm: I<0xFF, MRM6m, (outs), (ins i32mem:$src), "push{l}\t$src",[], 1135 IIC_PUSH_MEM>, OpSize32, Requires<[Not64BitMode]>; 1136} // mayLoad, mayStore, SchedRW 1137 1138} 1139 1140let mayLoad = 1, mayStore = 1, usesCustomInserter = 1, 1141 SchedRW = [WriteRMW], Defs = [ESP] in { 1142 let Uses = [ESP] in 1143 def RDFLAGS32 : PseudoI<(outs GR32:$dst), (ins), 1144 [(set GR32:$dst, (int_x86_flags_read_u32))]>, 1145 Requires<[Not64BitMode]>; 1146 1147 let Uses = [RSP] in 1148 def RDFLAGS64 : PseudoI<(outs GR64:$dst), (ins), 1149 [(set GR64:$dst, (int_x86_flags_read_u64))]>, 1150 Requires<[In64BitMode]>; 1151} 1152 1153let mayLoad = 1, mayStore = 1, usesCustomInserter = 1, 1154 SchedRW = [WriteRMW] in { 1155 let Defs = [ESP, EFLAGS], Uses = [ESP] in 1156 def WRFLAGS32 : PseudoI<(outs), (ins GR32:$src), 1157 [(int_x86_flags_write_u32 GR32:$src)]>, 1158 Requires<[Not64BitMode]>; 1159 1160 let Defs = [RSP, EFLAGS], Uses = [RSP] in 1161 def WRFLAGS64 : PseudoI<(outs), (ins GR64:$src), 1162 [(int_x86_flags_write_u64 GR64:$src)]>, 1163 Requires<[In64BitMode]>; 1164} 1165 1166let Defs = [ESP, EFLAGS], Uses = [ESP], mayLoad = 1, hasSideEffects=0, 1167 SchedRW = [WriteLoad] in { 1168def POPF16 : I<0x9D, RawFrm, (outs), (ins), "popf{w}", [], IIC_POP_F>, 1169 OpSize16; 1170def POPF32 : I<0x9D, RawFrm, (outs), (ins), "popf{l|d}", [], IIC_POP_FD>, 1171 OpSize32, Requires<[Not64BitMode]>; 1172} 1173 1174let Defs = [ESP], Uses = [ESP, EFLAGS], mayStore = 1, hasSideEffects=0, 1175 SchedRW = [WriteStore] in { 1176def PUSHF16 : I<0x9C, RawFrm, (outs), (ins), "pushf{w}", [], IIC_PUSH_F>, 1177 OpSize16; 1178def PUSHF32 : I<0x9C, RawFrm, (outs), (ins), "pushf{l|d}", [], IIC_PUSH_F>, 1179 OpSize32, Requires<[Not64BitMode]>; 1180} 1181 1182let Defs = [RSP], Uses = [RSP], hasSideEffects=0 in { 1183let mayLoad = 1, SchedRW = [WriteLoad] in { 1184def POP64r : I<0x58, AddRegFrm, (outs GR64:$reg), (ins), "pop{q}\t$reg", [], 1185 IIC_POP_REG>, OpSize32, Requires<[In64BitMode]>; 1186def POP64rmr: I<0x8F, MRM0r, (outs GR64:$reg), (ins), "pop{q}\t$reg", [], 1187 IIC_POP_REG>, OpSize32, Requires<[In64BitMode]>; 1188def POP64rmm: I<0x8F, MRM0m, (outs), (ins i64mem:$dst), "pop{q}\t$dst", [], 1189 IIC_POP_MEM>, OpSize32, Requires<[In64BitMode]>; 1190} // mayLoad, SchedRW 1191let mayStore = 1, SchedRW = [WriteStore] in { 1192def PUSH64r : I<0x50, AddRegFrm, (outs), (ins GR64:$reg), "push{q}\t$reg", [], 1193 IIC_PUSH_REG>, OpSize32, Requires<[In64BitMode]>; 1194def PUSH64rmr: I<0xFF, MRM6r, (outs), (ins GR64:$reg), "push{q}\t$reg", [], 1195 IIC_PUSH_REG>, OpSize32, Requires<[In64BitMode]>; 1196} // mayStore, SchedRW 1197let mayLoad = 1, mayStore = 1, SchedRW = [WriteRMW] in { 1198def PUSH64rmm: I<0xFF, MRM6m, (outs), (ins i64mem:$src), "push{q}\t$src", [], 1199 IIC_PUSH_MEM>, OpSize32, Requires<[In64BitMode]>; 1200} // mayLoad, mayStore, SchedRW 1201} 1202 1203let Defs = [RSP], Uses = [RSP], hasSideEffects = 0, mayStore = 1, 1204 SchedRW = [WriteStore] in { 1205def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i64i8imm:$imm), 1206 "push{q}\t$imm", [], IIC_PUSH_IMM>, OpSize32, 1207 Requires<[In64BitMode]>; 1208def PUSH64i32 : Ii32S<0x68, RawFrm, (outs), (ins i64i32imm:$imm), 1209 "push{q}\t$imm", [], IIC_PUSH_IMM>, OpSize32, 1210 Requires<[In64BitMode]>; 1211} 1212 1213let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1, hasSideEffects=0 in 1214def POPF64 : I<0x9D, RawFrm, (outs), (ins), "popfq", [], IIC_POP_FD>, 1215 OpSize32, Requires<[In64BitMode]>, Sched<[WriteLoad]>; 1216let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1, hasSideEffects=0 in 1217def PUSHF64 : I<0x9C, RawFrm, (outs), (ins), "pushfq", [], IIC_PUSH_F>, 1218 OpSize32, Requires<[In64BitMode]>, Sched<[WriteStore]>; 1219 1220let Defs = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP], Uses = [ESP], 1221 mayLoad = 1, hasSideEffects = 0, SchedRW = [WriteLoad] in { 1222def POPA32 : I<0x61, RawFrm, (outs), (ins), "popal", [], IIC_POP_A>, 1223 OpSize32, Requires<[Not64BitMode]>; 1224def POPA16 : I<0x61, RawFrm, (outs), (ins), "popaw", [], IIC_POP_A>, 1225 OpSize16, Requires<[Not64BitMode]>; 1226} 1227let Defs = [ESP], Uses = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP], 1228 mayStore = 1, hasSideEffects = 0, SchedRW = [WriteStore] in { 1229def PUSHA32 : I<0x60, RawFrm, (outs), (ins), "pushal", [], IIC_PUSH_A>, 1230 OpSize32, Requires<[Not64BitMode]>; 1231def PUSHA16 : I<0x60, RawFrm, (outs), (ins), "pushaw", [], IIC_PUSH_A>, 1232 OpSize16, Requires<[Not64BitMode]>; 1233} 1234 1235let Constraints = "$src = $dst", SchedRW = [WriteALU] in { 1236// GR32 = bswap GR32 1237def BSWAP32r : I<0xC8, AddRegFrm, 1238 (outs GR32:$dst), (ins GR32:$src), 1239 "bswap{l}\t$dst", 1240 [(set GR32:$dst, (bswap GR32:$src))], IIC_BSWAP>, OpSize32, TB; 1241 1242def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src), 1243 "bswap{q}\t$dst", 1244 [(set GR64:$dst, (bswap GR64:$src))], IIC_BSWAP>, TB; 1245} // Constraints = "$src = $dst", SchedRW 1246 1247// Bit scan instructions. 1248let Defs = [EFLAGS] in { 1249def BSF16rr : I<0xBC, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src), 1250 "bsf{w}\t{$src, $dst|$dst, $src}", 1251 [(set GR16:$dst, EFLAGS, (X86bsf GR16:$src))], 1252 IIC_BIT_SCAN_REG>, PS, OpSize16, Sched<[WriteShift]>; 1253def BSF16rm : I<0xBC, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src), 1254 "bsf{w}\t{$src, $dst|$dst, $src}", 1255 [(set GR16:$dst, EFLAGS, (X86bsf (loadi16 addr:$src)))], 1256 IIC_BIT_SCAN_MEM>, PS, OpSize16, Sched<[WriteShiftLd]>; 1257def BSF32rr : I<0xBC, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src), 1258 "bsf{l}\t{$src, $dst|$dst, $src}", 1259 [(set GR32:$dst, EFLAGS, (X86bsf GR32:$src))], 1260 IIC_BIT_SCAN_REG>, PS, OpSize32, Sched<[WriteShift]>; 1261def BSF32rm : I<0xBC, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src), 1262 "bsf{l}\t{$src, $dst|$dst, $src}", 1263 [(set GR32:$dst, EFLAGS, (X86bsf (loadi32 addr:$src)))], 1264 IIC_BIT_SCAN_MEM>, PS, OpSize32, Sched<[WriteShiftLd]>; 1265def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src), 1266 "bsf{q}\t{$src, $dst|$dst, $src}", 1267 [(set GR64:$dst, EFLAGS, (X86bsf GR64:$src))], 1268 IIC_BIT_SCAN_REG>, PS, Sched<[WriteShift]>; 1269def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src), 1270 "bsf{q}\t{$src, $dst|$dst, $src}", 1271 [(set GR64:$dst, EFLAGS, (X86bsf (loadi64 addr:$src)))], 1272 IIC_BIT_SCAN_MEM>, PS, Sched<[WriteShiftLd]>; 1273 1274def BSR16rr : I<0xBD, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src), 1275 "bsr{w}\t{$src, $dst|$dst, $src}", 1276 [(set GR16:$dst, EFLAGS, (X86bsr GR16:$src))], 1277 IIC_BIT_SCAN_REG>, PS, OpSize16, Sched<[WriteShift]>; 1278def BSR16rm : I<0xBD, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src), 1279 "bsr{w}\t{$src, $dst|$dst, $src}", 1280 [(set GR16:$dst, EFLAGS, (X86bsr (loadi16 addr:$src)))], 1281 IIC_BIT_SCAN_MEM>, PS, OpSize16, Sched<[WriteShiftLd]>; 1282def BSR32rr : I<0xBD, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src), 1283 "bsr{l}\t{$src, $dst|$dst, $src}", 1284 [(set GR32:$dst, EFLAGS, (X86bsr GR32:$src))], 1285 IIC_BIT_SCAN_REG>, PS, OpSize32, Sched<[WriteShift]>; 1286def BSR32rm : I<0xBD, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src), 1287 "bsr{l}\t{$src, $dst|$dst, $src}", 1288 [(set GR32:$dst, EFLAGS, (X86bsr (loadi32 addr:$src)))], 1289 IIC_BIT_SCAN_MEM>, PS, OpSize32, Sched<[WriteShiftLd]>; 1290def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src), 1291 "bsr{q}\t{$src, $dst|$dst, $src}", 1292 [(set GR64:$dst, EFLAGS, (X86bsr GR64:$src))], 1293 IIC_BIT_SCAN_REG>, PS, Sched<[WriteShift]>; 1294def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src), 1295 "bsr{q}\t{$src, $dst|$dst, $src}", 1296 [(set GR64:$dst, EFLAGS, (X86bsr (loadi64 addr:$src)))], 1297 IIC_BIT_SCAN_MEM>, PS, Sched<[WriteShiftLd]>; 1298} // Defs = [EFLAGS] 1299 1300let SchedRW = [WriteMicrocoded] in { 1301// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI 1302let Defs = [EDI,ESI], Uses = [EDI,ESI,EFLAGS] in { 1303def MOVSB : I<0xA4, RawFrmDstSrc, (outs), (ins dstidx8:$dst, srcidx8:$src), 1304 "movsb\t{$src, $dst|$dst, $src}", [], IIC_MOVS>; 1305def MOVSW : I<0xA5, RawFrmDstSrc, (outs), (ins dstidx16:$dst, srcidx16:$src), 1306 "movsw\t{$src, $dst|$dst, $src}", [], IIC_MOVS>, OpSize16; 1307def MOVSL : I<0xA5, RawFrmDstSrc, (outs), (ins dstidx32:$dst, srcidx32:$src), 1308 "movs{l|d}\t{$src, $dst|$dst, $src}", [], IIC_MOVS>, OpSize32; 1309def MOVSQ : RI<0xA5, RawFrmDstSrc, (outs), (ins dstidx64:$dst, srcidx64:$src), 1310 "movsq\t{$src, $dst|$dst, $src}", [], IIC_MOVS>; 1311} 1312 1313// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI 1314let Defs = [EDI], Uses = [AL,EDI,EFLAGS] in 1315def STOSB : I<0xAA, RawFrmDst, (outs), (ins dstidx8:$dst), 1316 "stosb\t{%al, $dst|$dst, al}", [], IIC_STOS>; 1317let Defs = [EDI], Uses = [AX,EDI,EFLAGS] in 1318def STOSW : I<0xAB, RawFrmDst, (outs), (ins dstidx16:$dst), 1319 "stosw\t{%ax, $dst|$dst, ax}", [], IIC_STOS>, OpSize16; 1320let Defs = [EDI], Uses = [EAX,EDI,EFLAGS] in 1321def STOSL : I<0xAB, RawFrmDst, (outs), (ins dstidx32:$dst), 1322 "stos{l|d}\t{%eax, $dst|$dst, eax}", [], IIC_STOS>, OpSize32; 1323let Defs = [RDI], Uses = [RAX,RDI,EFLAGS] in 1324def STOSQ : RI<0xAB, RawFrmDst, (outs), (ins dstidx64:$dst), 1325 "stosq\t{%rax, $dst|$dst, rax}", [], IIC_STOS>; 1326 1327// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI 1328let Defs = [EDI,EFLAGS], Uses = [AL,EDI,EFLAGS] in 1329def SCASB : I<0xAE, RawFrmDst, (outs), (ins dstidx8:$dst), 1330 "scasb\t{$dst, %al|al, $dst}", [], IIC_SCAS>; 1331let Defs = [EDI,EFLAGS], Uses = [AX,EDI,EFLAGS] in 1332def SCASW : I<0xAF, RawFrmDst, (outs), (ins dstidx16:$dst), 1333 "scasw\t{$dst, %ax|ax, $dst}", [], IIC_SCAS>, OpSize16; 1334let Defs = [EDI,EFLAGS], Uses = [EAX,EDI,EFLAGS] in 1335def SCASL : I<0xAF, RawFrmDst, (outs), (ins dstidx32:$dst), 1336 "scas{l|d}\t{$dst, %eax|eax, $dst}", [], IIC_SCAS>, OpSize32; 1337let Defs = [EDI,EFLAGS], Uses = [RAX,EDI,EFLAGS] in 1338def SCASQ : RI<0xAF, RawFrmDst, (outs), (ins dstidx64:$dst), 1339 "scasq\t{$dst, %rax|rax, $dst}", [], IIC_SCAS>; 1340 1341// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI 1342let Defs = [EDI,ESI,EFLAGS], Uses = [EDI,ESI,EFLAGS] in { 1343def CMPSB : I<0xA6, RawFrmDstSrc, (outs), (ins dstidx8:$dst, srcidx8:$src), 1344 "cmpsb\t{$dst, $src|$src, $dst}", [], IIC_CMPS>; 1345def CMPSW : I<0xA7, RawFrmDstSrc, (outs), (ins dstidx16:$dst, srcidx16:$src), 1346 "cmpsw\t{$dst, $src|$src, $dst}", [], IIC_CMPS>, OpSize16; 1347def CMPSL : I<0xA7, RawFrmDstSrc, (outs), (ins dstidx32:$dst, srcidx32:$src), 1348 "cmps{l|d}\t{$dst, $src|$src, $dst}", [], IIC_CMPS>, OpSize32; 1349def CMPSQ : RI<0xA7, RawFrmDstSrc, (outs), (ins dstidx64:$dst, srcidx64:$src), 1350 "cmpsq\t{$dst, $src|$src, $dst}", [], IIC_CMPS>; 1351} 1352} // SchedRW 1353 1354//===----------------------------------------------------------------------===// 1355// Move Instructions. 1356// 1357let SchedRW = [WriteMove] in { 1358let hasSideEffects = 0 in { 1359def MOV8rr : I<0x88, MRMDestReg, (outs GR8 :$dst), (ins GR8 :$src), 1360 "mov{b}\t{$src, $dst|$dst, $src}", [], IIC_MOV>; 1361def MOV16rr : I<0x89, MRMDestReg, (outs GR16:$dst), (ins GR16:$src), 1362 "mov{w}\t{$src, $dst|$dst, $src}", [], IIC_MOV>, OpSize16; 1363def MOV32rr : I<0x89, MRMDestReg, (outs GR32:$dst), (ins GR32:$src), 1364 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV>, OpSize32; 1365def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src), 1366 "mov{q}\t{$src, $dst|$dst, $src}", [], IIC_MOV>; 1367} 1368 1369let isReMaterializable = 1, isAsCheapAsAMove = 1 in { 1370def MOV8ri : Ii8 <0xB0, AddRegFrm, (outs GR8 :$dst), (ins i8imm :$src), 1371 "mov{b}\t{$src, $dst|$dst, $src}", 1372 [(set GR8:$dst, imm:$src)], IIC_MOV>; 1373def MOV16ri : Ii16<0xB8, AddRegFrm, (outs GR16:$dst), (ins i16imm:$src), 1374 "mov{w}\t{$src, $dst|$dst, $src}", 1375 [(set GR16:$dst, imm:$src)], IIC_MOV>, OpSize16; 1376def MOV32ri : Ii32<0xB8, AddRegFrm, (outs GR32:$dst), (ins i32imm:$src), 1377 "mov{l}\t{$src, $dst|$dst, $src}", 1378 [(set GR32:$dst, imm:$src)], IIC_MOV>, OpSize32; 1379def MOV64ri32 : RIi32S<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src), 1380 "mov{q}\t{$src, $dst|$dst, $src}", 1381 [(set GR64:$dst, i64immSExt32:$src)], IIC_MOV>; 1382} 1383let isReMaterializable = 1 in { 1384def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src), 1385 "movabs{q}\t{$src, $dst|$dst, $src}", 1386 [(set GR64:$dst, imm:$src)], IIC_MOV>; 1387} 1388 1389// Longer forms that use a ModR/M byte. Needed for disassembler 1390let isCodeGenOnly = 1, ForceDisassemble = 1, hasSideEffects = 0 in { 1391def MOV8ri_alt : Ii8 <0xC6, MRM0r, (outs GR8 :$dst), (ins i8imm :$src), 1392 "mov{b}\t{$src, $dst|$dst, $src}", [], IIC_MOV>; 1393def MOV16ri_alt : Ii16<0xC7, MRM0r, (outs GR16:$dst), (ins i16imm:$src), 1394 "mov{w}\t{$src, $dst|$dst, $src}", [], IIC_MOV>, OpSize16; 1395def MOV32ri_alt : Ii32<0xC7, MRM0r, (outs GR32:$dst), (ins i32imm:$src), 1396 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV>, OpSize32; 1397} 1398} // SchedRW 1399 1400let SchedRW = [WriteStore] in { 1401def MOV8mi : Ii8 <0xC6, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src), 1402 "mov{b}\t{$src, $dst|$dst, $src}", 1403 [(store (i8 imm8_su:$src), addr:$dst)], IIC_MOV_MEM>; 1404def MOV16mi : Ii16<0xC7, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src), 1405 "mov{w}\t{$src, $dst|$dst, $src}", 1406 [(store (i16 imm16_su:$src), addr:$dst)], IIC_MOV_MEM>, OpSize16; 1407def MOV32mi : Ii32<0xC7, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src), 1408 "mov{l}\t{$src, $dst|$dst, $src}", 1409 [(store (i32 imm32_su:$src), addr:$dst)], IIC_MOV_MEM>, OpSize32; 1410def MOV64mi32 : RIi32S<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src), 1411 "mov{q}\t{$src, $dst|$dst, $src}", 1412 [(store i64immSExt32:$src, addr:$dst)], IIC_MOV_MEM>; 1413} // SchedRW 1414 1415let hasSideEffects = 0 in { 1416 1417/// Memory offset versions of moves. The immediate is an address mode sized 1418/// offset from the segment base. 1419let SchedRW = [WriteALU] in { 1420let mayLoad = 1 in { 1421let Defs = [AL] in 1422def MOV8ao32 : Ii32<0xA0, RawFrmMemOffs, (outs), (ins offset32_8:$src), 1423 "mov{b}\t{$src, %al|al, $src}", [], IIC_MOV_MEM>, 1424 AdSize32; 1425let Defs = [AX] in 1426def MOV16ao32 : Ii32<0xA1, RawFrmMemOffs, (outs), (ins offset32_16:$src), 1427 "mov{w}\t{$src, %ax|ax, $src}", [], IIC_MOV_MEM>, 1428 OpSize16, AdSize32; 1429let Defs = [EAX] in 1430def MOV32ao32 : Ii32<0xA1, RawFrmMemOffs, (outs), (ins offset32_32:$src), 1431 "mov{l}\t{$src, %eax|eax, $src}", [], IIC_MOV_MEM>, 1432 OpSize32, AdSize32; 1433let Defs = [RAX] in 1434def MOV64ao32 : RIi32<0xA1, RawFrmMemOffs, (outs), (ins offset32_64:$src), 1435 "mov{q}\t{$src, %rax|rax, $src}", [], IIC_MOV_MEM>, 1436 AdSize32; 1437 1438let Defs = [AL] in 1439def MOV8ao16 : Ii16<0xA0, RawFrmMemOffs, (outs), (ins offset16_8:$src), 1440 "mov{b}\t{$src, %al|al, $src}", [], IIC_MOV_MEM>, AdSize16; 1441let Defs = [AX] in 1442def MOV16ao16 : Ii16<0xA1, RawFrmMemOffs, (outs), (ins offset16_16:$src), 1443 "mov{w}\t{$src, %ax|ax, $src}", [], IIC_MOV_MEM>, 1444 OpSize16, AdSize16; 1445let Defs = [EAX] in 1446def MOV32ao16 : Ii16<0xA1, RawFrmMemOffs, (outs), (ins offset16_32:$src), 1447 "mov{l}\t{$src, %eax|eax, $src}", [], IIC_MOV_MEM>, 1448 AdSize16, OpSize32; 1449} 1450let mayStore = 1 in { 1451let Uses = [AL] in 1452def MOV8o32a : Ii32<0xA2, RawFrmMemOffs, (outs), (ins offset32_8:$dst), 1453 "mov{b}\t{%al, $dst|$dst, al}", [], IIC_MOV_MEM>, AdSize32; 1454let Uses = [AX] in 1455def MOV16o32a : Ii32<0xA3, RawFrmMemOffs, (outs), (ins offset32_16:$dst), 1456 "mov{w}\t{%ax, $dst|$dst, ax}", [], IIC_MOV_MEM>, 1457 OpSize16, AdSize32; 1458let Uses = [EAX] in 1459def MOV32o32a : Ii32<0xA3, RawFrmMemOffs, (outs), (ins offset32_32:$dst), 1460 "mov{l}\t{%eax, $dst|$dst, eax}", [], IIC_MOV_MEM>, 1461 OpSize32, AdSize32; 1462let Uses = [RAX] in 1463def MOV64o32a : RIi32<0xA3, RawFrmMemOffs, (outs), (ins offset32_64:$dst), 1464 "mov{q}\t{%rax, $dst|$dst, rax}", [], IIC_MOV_MEM>, 1465 AdSize32; 1466 1467let Uses = [AL] in 1468def MOV8o16a : Ii16<0xA2, RawFrmMemOffs, (outs), (ins offset16_8:$dst), 1469 "mov{b}\t{%al, $dst|$dst, al}", [], IIC_MOV_MEM>, AdSize16; 1470let Uses = [AX] in 1471def MOV16o16a : Ii16<0xA3, RawFrmMemOffs, (outs), (ins offset16_16:$dst), 1472 "mov{w}\t{%ax, $dst|$dst, ax}", [], IIC_MOV_MEM>, 1473 OpSize16, AdSize16; 1474let Uses = [EAX] in 1475def MOV32o16a : Ii16<0xA3, RawFrmMemOffs, (outs), (ins offset16_32:$dst), 1476 "mov{l}\t{%eax, $dst|$dst, eax}", [], IIC_MOV_MEM>, 1477 OpSize32, AdSize16; 1478} 1479} 1480 1481// These forms all have full 64-bit absolute addresses in their instructions 1482// and use the movabs mnemonic to indicate this specific form. 1483let mayLoad = 1 in { 1484let Defs = [AL] in 1485def MOV8ao64 : RIi64_NOREX<0xA0, RawFrmMemOffs, (outs), (ins offset64_8:$src), 1486 "movabs{b}\t{$src, %al|al, $src}", []>, AdSize64; 1487let Defs = [AX] in 1488def MOV16ao64 : RIi64_NOREX<0xA1, RawFrmMemOffs, (outs), (ins offset64_16:$src), 1489 "movabs{w}\t{$src, %ax|ax, $src}", []>, OpSize16, AdSize64; 1490let Defs = [EAX] in 1491def MOV32ao64 : RIi64_NOREX<0xA1, RawFrmMemOffs, (outs), (ins offset64_32:$src), 1492 "movabs{l}\t{$src, %eax|eax, $src}", []>, OpSize32, 1493 AdSize64; 1494let Defs = [RAX] in 1495def MOV64ao64 : RIi64<0xA1, RawFrmMemOffs, (outs), (ins offset64_64:$src), 1496 "movabs{q}\t{$src, %rax|rax, $src}", []>, AdSize64; 1497} 1498 1499let mayStore = 1 in { 1500let Uses = [AL] in 1501def MOV8o64a : RIi64_NOREX<0xA2, RawFrmMemOffs, (outs), (ins offset64_8:$dst), 1502 "movabs{b}\t{%al, $dst|$dst, al}", []>, AdSize64; 1503let Uses = [AX] in 1504def MOV16o64a : RIi64_NOREX<0xA3, RawFrmMemOffs, (outs), (ins offset64_16:$dst), 1505 "movabs{w}\t{%ax, $dst|$dst, ax}", []>, OpSize16, AdSize64; 1506let Uses = [EAX] in 1507def MOV32o64a : RIi64_NOREX<0xA3, RawFrmMemOffs, (outs), (ins offset64_32:$dst), 1508 "movabs{l}\t{%eax, $dst|$dst, eax}", []>, OpSize32, 1509 AdSize64; 1510let Uses = [RAX] in 1511def MOV64o64a : RIi64<0xA3, RawFrmMemOffs, (outs), (ins offset64_64:$dst), 1512 "movabs{q}\t{%rax, $dst|$dst, rax}", []>, AdSize64; 1513} 1514} // hasSideEffects = 0 1515 1516let isCodeGenOnly = 1, ForceDisassemble = 1, hasSideEffects = 0, 1517 SchedRW = [WriteMove] in { 1518def MOV8rr_REV : I<0x8A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src), 1519 "mov{b}\t{$src, $dst|$dst, $src}", [], IIC_MOV>; 1520def MOV16rr_REV : I<0x8B, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src), 1521 "mov{w}\t{$src, $dst|$dst, $src}", [], IIC_MOV>, OpSize16; 1522def MOV32rr_REV : I<0x8B, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src), 1523 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV>, OpSize32; 1524def MOV64rr_REV : RI<0x8B, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src), 1525 "mov{q}\t{$src, $dst|$dst, $src}", [], IIC_MOV>; 1526} 1527 1528let canFoldAsLoad = 1, isReMaterializable = 1, SchedRW = [WriteLoad] in { 1529def MOV8rm : I<0x8A, MRMSrcMem, (outs GR8 :$dst), (ins i8mem :$src), 1530 "mov{b}\t{$src, $dst|$dst, $src}", 1531 [(set GR8:$dst, (loadi8 addr:$src))], IIC_MOV_MEM>; 1532def MOV16rm : I<0x8B, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src), 1533 "mov{w}\t{$src, $dst|$dst, $src}", 1534 [(set GR16:$dst, (loadi16 addr:$src))], IIC_MOV_MEM>, OpSize16; 1535def MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src), 1536 "mov{l}\t{$src, $dst|$dst, $src}", 1537 [(set GR32:$dst, (loadi32 addr:$src))], IIC_MOV_MEM>, OpSize32; 1538def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src), 1539 "mov{q}\t{$src, $dst|$dst, $src}", 1540 [(set GR64:$dst, (load addr:$src))], IIC_MOV_MEM>; 1541} 1542 1543let SchedRW = [WriteStore] in { 1544def MOV8mr : I<0x88, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src), 1545 "mov{b}\t{$src, $dst|$dst, $src}", 1546 [(store GR8:$src, addr:$dst)], IIC_MOV_MEM>; 1547def MOV16mr : I<0x89, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src), 1548 "mov{w}\t{$src, $dst|$dst, $src}", 1549 [(store GR16:$src, addr:$dst)], IIC_MOV_MEM>, OpSize16; 1550def MOV32mr : I<0x89, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src), 1551 "mov{l}\t{$src, $dst|$dst, $src}", 1552 [(store GR32:$src, addr:$dst)], IIC_MOV_MEM>, OpSize32; 1553def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src), 1554 "mov{q}\t{$src, $dst|$dst, $src}", 1555 [(store GR64:$src, addr:$dst)], IIC_MOV_MEM>; 1556} // SchedRW 1557 1558// Versions of MOV8rr, MOV8mr, and MOV8rm that use i8mem_NOREX and GR8_NOREX so 1559// that they can be used for copying and storing h registers, which can't be 1560// encoded when a REX prefix is present. 1561let isCodeGenOnly = 1 in { 1562let hasSideEffects = 0 in 1563def MOV8rr_NOREX : I<0x88, MRMDestReg, 1564 (outs GR8_NOREX:$dst), (ins GR8_NOREX:$src), 1565 "mov{b}\t{$src, $dst|$dst, $src} # NOREX", [], IIC_MOV>, 1566 Sched<[WriteMove]>; 1567let mayStore = 1, hasSideEffects = 0 in 1568def MOV8mr_NOREX : I<0x88, MRMDestMem, 1569 (outs), (ins i8mem_NOREX:$dst, GR8_NOREX:$src), 1570 "mov{b}\t{$src, $dst|$dst, $src} # NOREX", [], 1571 IIC_MOV_MEM>, Sched<[WriteStore]>; 1572let mayLoad = 1, hasSideEffects = 0, 1573 canFoldAsLoad = 1, isReMaterializable = 1 in 1574def MOV8rm_NOREX : I<0x8A, MRMSrcMem, 1575 (outs GR8_NOREX:$dst), (ins i8mem_NOREX:$src), 1576 "mov{b}\t{$src, $dst|$dst, $src} # NOREX", [], 1577 IIC_MOV_MEM>, Sched<[WriteLoad]>; 1578} 1579 1580 1581// Condition code ops, incl. set if equal/not equal/... 1582let SchedRW = [WriteALU] in { 1583let Defs = [EFLAGS], Uses = [AH] in 1584def SAHF : I<0x9E, RawFrm, (outs), (ins), "sahf", 1585 [(set EFLAGS, (X86sahf AH))], IIC_AHF>, 1586 Requires<[HasLAHFSAHF]>; 1587let Defs = [AH], Uses = [EFLAGS], hasSideEffects = 0 in 1588def LAHF : I<0x9F, RawFrm, (outs), (ins), "lahf", [], 1589 IIC_AHF>, // AH = flags 1590 Requires<[HasLAHFSAHF]>; 1591} // SchedRW 1592 1593//===----------------------------------------------------------------------===// 1594// Bit tests instructions: BT, BTS, BTR, BTC. 1595 1596let Defs = [EFLAGS] in { 1597let SchedRW = [WriteALU] in { 1598def BT16rr : I<0xA3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2), 1599 "bt{w}\t{$src2, $src1|$src1, $src2}", 1600 [(set EFLAGS, (X86bt GR16:$src1, GR16:$src2))], IIC_BT_RR>, 1601 OpSize16, TB; 1602def BT32rr : I<0xA3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2), 1603 "bt{l}\t{$src2, $src1|$src1, $src2}", 1604 [(set EFLAGS, (X86bt GR32:$src1, GR32:$src2))], IIC_BT_RR>, 1605 OpSize32, TB; 1606def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2), 1607 "bt{q}\t{$src2, $src1|$src1, $src2}", 1608 [(set EFLAGS, (X86bt GR64:$src1, GR64:$src2))], IIC_BT_RR>, TB; 1609} // SchedRW 1610 1611// Unlike with the register+register form, the memory+register form of the 1612// bt instruction does not ignore the high bits of the index. From ISel's 1613// perspective, this is pretty bizarre. Make these instructions disassembly 1614// only for now. 1615 1616let mayLoad = 1, hasSideEffects = 0, SchedRW = [WriteALULd] in { 1617 def BT16mr : I<0xA3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2), 1618 "bt{w}\t{$src2, $src1|$src1, $src2}", 1619 // [(X86bt (loadi16 addr:$src1), GR16:$src2), 1620 // (implicit EFLAGS)] 1621 [], IIC_BT_MR 1622 >, OpSize16, TB, Requires<[FastBTMem]>; 1623 def BT32mr : I<0xA3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2), 1624 "bt{l}\t{$src2, $src1|$src1, $src2}", 1625 // [(X86bt (loadi32 addr:$src1), GR32:$src2), 1626 // (implicit EFLAGS)] 1627 [], IIC_BT_MR 1628 >, OpSize32, TB, Requires<[FastBTMem]>; 1629 def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2), 1630 "bt{q}\t{$src2, $src1|$src1, $src2}", 1631 // [(X86bt (loadi64 addr:$src1), GR64:$src2), 1632 // (implicit EFLAGS)] 1633 [], IIC_BT_MR 1634 >, TB; 1635} 1636 1637let SchedRW = [WriteALU] in { 1638def BT16ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR16:$src1, i16i8imm:$src2), 1639 "bt{w}\t{$src2, $src1|$src1, $src2}", 1640 [(set EFLAGS, (X86bt GR16:$src1, i16immSExt8:$src2))], 1641 IIC_BT_RI>, OpSize16, TB; 1642def BT32ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR32:$src1, i32i8imm:$src2), 1643 "bt{l}\t{$src2, $src1|$src1, $src2}", 1644 [(set EFLAGS, (X86bt GR32:$src1, i32immSExt8:$src2))], 1645 IIC_BT_RI>, OpSize32, TB; 1646def BT64ri8 : RIi8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2), 1647 "bt{q}\t{$src2, $src1|$src1, $src2}", 1648 [(set EFLAGS, (X86bt GR64:$src1, i64immSExt8:$src2))], 1649 IIC_BT_RI>, TB; 1650} // SchedRW 1651 1652// Note that these instructions don't need FastBTMem because that 1653// only applies when the other operand is in a register. When it's 1654// an immediate, bt is still fast. 1655let SchedRW = [WriteALU] in { 1656def BT16mi8 : Ii8<0xBA, MRM4m, (outs), (ins i16mem:$src1, i16i8imm:$src2), 1657 "bt{w}\t{$src2, $src1|$src1, $src2}", 1658 [(set EFLAGS, (X86bt (loadi16 addr:$src1), i16immSExt8:$src2)) 1659 ], IIC_BT_MI>, OpSize16, TB; 1660def BT32mi8 : Ii8<0xBA, MRM4m, (outs), (ins i32mem:$src1, i32i8imm:$src2), 1661 "bt{l}\t{$src2, $src1|$src1, $src2}", 1662 [(set EFLAGS, (X86bt (loadi32 addr:$src1), i32immSExt8:$src2)) 1663 ], IIC_BT_MI>, OpSize32, TB; 1664def BT64mi8 : RIi8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2), 1665 "bt{q}\t{$src2, $src1|$src1, $src2}", 1666 [(set EFLAGS, (X86bt (loadi64 addr:$src1), 1667 i64immSExt8:$src2))], IIC_BT_MI>, TB; 1668} // SchedRW 1669 1670let hasSideEffects = 0 in { 1671let SchedRW = [WriteALU] in { 1672def BTC16rr : I<0xBB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2), 1673 "btc{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, 1674 OpSize16, TB; 1675def BTC32rr : I<0xBB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2), 1676 "btc{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, 1677 OpSize32, TB; 1678def BTC64rr : RI<0xBB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2), 1679 "btc{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, TB; 1680} // SchedRW 1681 1682let mayLoad = 1, mayStore = 1, SchedRW = [WriteALULd, WriteRMW] in { 1683def BTC16mr : I<0xBB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2), 1684 "btc{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, 1685 OpSize16, TB; 1686def BTC32mr : I<0xBB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2), 1687 "btc{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, 1688 OpSize32, TB; 1689def BTC64mr : RI<0xBB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2), 1690 "btc{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, TB; 1691} 1692 1693let SchedRW = [WriteALU] in { 1694def BTC16ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR16:$src1, i16i8imm:$src2), 1695 "btc{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, 1696 OpSize16, TB; 1697def BTC32ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR32:$src1, i32i8imm:$src2), 1698 "btc{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, 1699 OpSize32, TB; 1700def BTC64ri8 : RIi8<0xBA, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2), 1701 "btc{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, TB; 1702} // SchedRW 1703 1704let mayLoad = 1, mayStore = 1, SchedRW = [WriteALULd, WriteRMW] in { 1705def BTC16mi8 : Ii8<0xBA, MRM7m, (outs), (ins i16mem:$src1, i16i8imm:$src2), 1706 "btc{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, 1707 OpSize16, TB; 1708def BTC32mi8 : Ii8<0xBA, MRM7m, (outs), (ins i32mem:$src1, i32i8imm:$src2), 1709 "btc{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, 1710 OpSize32, TB; 1711def BTC64mi8 : RIi8<0xBA, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2), 1712 "btc{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, TB; 1713} 1714 1715let SchedRW = [WriteALU] in { 1716def BTR16rr : I<0xB3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2), 1717 "btr{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, 1718 OpSize16, TB; 1719def BTR32rr : I<0xB3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2), 1720 "btr{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, 1721 OpSize32, TB; 1722def BTR64rr : RI<0xB3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2), 1723 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB; 1724} // SchedRW 1725 1726let mayLoad = 1, mayStore = 1, SchedRW = [WriteALULd, WriteRMW] in { 1727def BTR16mr : I<0xB3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2), 1728 "btr{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, 1729 OpSize16, TB; 1730def BTR32mr : I<0xB3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2), 1731 "btr{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, 1732 OpSize32, TB; 1733def BTR64mr : RI<0xB3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2), 1734 "btr{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, TB; 1735} 1736 1737let SchedRW = [WriteALU] in { 1738def BTR16ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR16:$src1, i16i8imm:$src2), 1739 "btr{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, 1740 OpSize16, TB; 1741def BTR32ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR32:$src1, i32i8imm:$src2), 1742 "btr{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, 1743 OpSize32, TB; 1744def BTR64ri8 : RIi8<0xBA, MRM6r, (outs), (ins GR64:$src1, i64i8imm:$src2), 1745 "btr{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, TB; 1746} // SchedRW 1747 1748let mayLoad = 1, mayStore = 1, SchedRW = [WriteALULd, WriteRMW] in { 1749def BTR16mi8 : Ii8<0xBA, MRM6m, (outs), (ins i16mem:$src1, i16i8imm:$src2), 1750 "btr{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, 1751 OpSize16, TB; 1752def BTR32mi8 : Ii8<0xBA, MRM6m, (outs), (ins i32mem:$src1, i32i8imm:$src2), 1753 "btr{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, 1754 OpSize32, TB; 1755def BTR64mi8 : RIi8<0xBA, MRM6m, (outs), (ins i64mem:$src1, i64i8imm:$src2), 1756 "btr{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, TB; 1757} 1758 1759let SchedRW = [WriteALU] in { 1760def BTS16rr : I<0xAB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2), 1761 "bts{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, 1762 OpSize16, TB; 1763def BTS32rr : I<0xAB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2), 1764 "bts{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, 1765 OpSize32, TB; 1766def BTS64rr : RI<0xAB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2), 1767 "bts{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, TB; 1768} // SchedRW 1769 1770let mayLoad = 1, mayStore = 1, SchedRW = [WriteALULd, WriteRMW] in { 1771def BTS16mr : I<0xAB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2), 1772 "bts{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, 1773 OpSize16, TB; 1774def BTS32mr : I<0xAB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2), 1775 "bts{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, 1776 OpSize32, TB; 1777def BTS64mr : RI<0xAB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2), 1778 "bts{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, TB; 1779} 1780 1781let SchedRW = [WriteALU] in { 1782def BTS16ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR16:$src1, i16i8imm:$src2), 1783 "bts{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, 1784 OpSize16, TB; 1785def BTS32ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR32:$src1, i32i8imm:$src2), 1786 "bts{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, 1787 OpSize32, TB; 1788def BTS64ri8 : RIi8<0xBA, MRM5r, (outs), (ins GR64:$src1, i64i8imm:$src2), 1789 "bts{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, TB; 1790} // SchedRW 1791 1792let mayLoad = 1, mayStore = 1, SchedRW = [WriteALULd, WriteRMW] in { 1793def BTS16mi8 : Ii8<0xBA, MRM5m, (outs), (ins i16mem:$src1, i16i8imm:$src2), 1794 "bts{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, 1795 OpSize16, TB; 1796def BTS32mi8 : Ii8<0xBA, MRM5m, (outs), (ins i32mem:$src1, i32i8imm:$src2), 1797 "bts{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, 1798 OpSize32, TB; 1799def BTS64mi8 : RIi8<0xBA, MRM5m, (outs), (ins i64mem:$src1, i64i8imm:$src2), 1800 "bts{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, TB; 1801} 1802} // hasSideEffects = 0 1803} // Defs = [EFLAGS] 1804 1805 1806//===----------------------------------------------------------------------===// 1807// Atomic support 1808// 1809 1810// Atomic swap. These are just normal xchg instructions. But since a memory 1811// operand is referenced, the atomicity is ensured. 1812multiclass ATOMIC_SWAP<bits<8> opc8, bits<8> opc, string mnemonic, string frag, 1813 InstrItinClass itin> { 1814 let Constraints = "$val = $dst", SchedRW = [WriteALULd, WriteRMW] in { 1815 def NAME#8rm : I<opc8, MRMSrcMem, (outs GR8:$dst), 1816 (ins GR8:$val, i8mem:$ptr), 1817 !strconcat(mnemonic, "{b}\t{$val, $ptr|$ptr, $val}"), 1818 [(set 1819 GR8:$dst, 1820 (!cast<PatFrag>(frag # "_8") addr:$ptr, GR8:$val))], 1821 itin>; 1822 def NAME#16rm : I<opc, MRMSrcMem, (outs GR16:$dst), 1823 (ins GR16:$val, i16mem:$ptr), 1824 !strconcat(mnemonic, "{w}\t{$val, $ptr|$ptr, $val}"), 1825 [(set 1826 GR16:$dst, 1827 (!cast<PatFrag>(frag # "_16") addr:$ptr, GR16:$val))], 1828 itin>, OpSize16; 1829 def NAME#32rm : I<opc, MRMSrcMem, (outs GR32:$dst), 1830 (ins GR32:$val, i32mem:$ptr), 1831 !strconcat(mnemonic, "{l}\t{$val, $ptr|$ptr, $val}"), 1832 [(set 1833 GR32:$dst, 1834 (!cast<PatFrag>(frag # "_32") addr:$ptr, GR32:$val))], 1835 itin>, OpSize32; 1836 def NAME#64rm : RI<opc, MRMSrcMem, (outs GR64:$dst), 1837 (ins GR64:$val, i64mem:$ptr), 1838 !strconcat(mnemonic, "{q}\t{$val, $ptr|$ptr, $val}"), 1839 [(set 1840 GR64:$dst, 1841 (!cast<PatFrag>(frag # "_64") addr:$ptr, GR64:$val))], 1842 itin>; 1843 } 1844} 1845 1846defm XCHG : ATOMIC_SWAP<0x86, 0x87, "xchg", "atomic_swap", IIC_XCHG_MEM>; 1847 1848// Swap between registers. 1849let SchedRW = [WriteALU] in { 1850let Constraints = "$val = $dst" in { 1851def XCHG8rr : I<0x86, MRMSrcReg, (outs GR8:$dst), (ins GR8:$val, GR8:$src), 1852 "xchg{b}\t{$val, $src|$src, $val}", [], IIC_XCHG_REG>; 1853def XCHG16rr : I<0x87, MRMSrcReg, (outs GR16:$dst), (ins GR16:$val, GR16:$src), 1854 "xchg{w}\t{$val, $src|$src, $val}", [], IIC_XCHG_REG>, 1855 OpSize16; 1856def XCHG32rr : I<0x87, MRMSrcReg, (outs GR32:$dst), (ins GR32:$val, GR32:$src), 1857 "xchg{l}\t{$val, $src|$src, $val}", [], IIC_XCHG_REG>, 1858 OpSize32; 1859def XCHG64rr : RI<0x87, MRMSrcReg, (outs GR64:$dst), (ins GR64:$val,GR64:$src), 1860 "xchg{q}\t{$val, $src|$src, $val}", [], IIC_XCHG_REG>; 1861} 1862 1863// Swap between EAX and other registers. 1864let Uses = [AX], Defs = [AX] in 1865def XCHG16ar : I<0x90, AddRegFrm, (outs), (ins GR16:$src), 1866 "xchg{w}\t{$src, %ax|ax, $src}", [], IIC_XCHG_REG>, OpSize16; 1867let Uses = [EAX], Defs = [EAX] in 1868def XCHG32ar : I<0x90, AddRegFrm, (outs), (ins GR32:$src), 1869 "xchg{l}\t{$src, %eax|eax, $src}", [], IIC_XCHG_REG>, 1870 OpSize32, Requires<[Not64BitMode]>; 1871let Uses = [EAX], Defs = [EAX] in 1872// Uses GR32_NOAX in 64-bit mode to prevent encoding using the 0x90 NOP encoding. 1873// xchg %eax, %eax needs to clear upper 32-bits of RAX so is not a NOP. 1874def XCHG32ar64 : I<0x90, AddRegFrm, (outs), (ins GR32_NOAX:$src), 1875 "xchg{l}\t{$src, %eax|eax, $src}", [], IIC_XCHG_REG>, 1876 OpSize32, Requires<[In64BitMode]>; 1877let Uses = [RAX], Defs = [RAX] in 1878def XCHG64ar : RI<0x90, AddRegFrm, (outs), (ins GR64:$src), 1879 "xchg{q}\t{$src, %rax|rax, $src}", [], IIC_XCHG_REG>; 1880} // SchedRW 1881 1882let SchedRW = [WriteALU] in { 1883def XADD8rr : I<0xC0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src), 1884 "xadd{b}\t{$src, $dst|$dst, $src}", [], IIC_XADD_REG>, TB; 1885def XADD16rr : I<0xC1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src), 1886 "xadd{w}\t{$src, $dst|$dst, $src}", [], IIC_XADD_REG>, TB, 1887 OpSize16; 1888def XADD32rr : I<0xC1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src), 1889 "xadd{l}\t{$src, $dst|$dst, $src}", [], IIC_XADD_REG>, TB, 1890 OpSize32; 1891def XADD64rr : RI<0xC1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src), 1892 "xadd{q}\t{$src, $dst|$dst, $src}", [], IIC_XADD_REG>, TB; 1893} // SchedRW 1894 1895let mayLoad = 1, mayStore = 1, SchedRW = [WriteALULd, WriteRMW] in { 1896def XADD8rm : I<0xC0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src), 1897 "xadd{b}\t{$src, $dst|$dst, $src}", [], IIC_XADD_MEM>, TB; 1898def XADD16rm : I<0xC1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src), 1899 "xadd{w}\t{$src, $dst|$dst, $src}", [], IIC_XADD_MEM>, TB, 1900 OpSize16; 1901def XADD32rm : I<0xC1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src), 1902 "xadd{l}\t{$src, $dst|$dst, $src}", [], IIC_XADD_MEM>, TB, 1903 OpSize32; 1904def XADD64rm : RI<0xC1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src), 1905 "xadd{q}\t{$src, $dst|$dst, $src}", [], IIC_XADD_MEM>, TB; 1906 1907} 1908 1909let SchedRW = [WriteALU] in { 1910def CMPXCHG8rr : I<0xB0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src), 1911 "cmpxchg{b}\t{$src, $dst|$dst, $src}", [], 1912 IIC_CMPXCHG_REG8>, TB; 1913def CMPXCHG16rr : I<0xB1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src), 1914 "cmpxchg{w}\t{$src, $dst|$dst, $src}", [], 1915 IIC_CMPXCHG_REG>, TB, OpSize16; 1916def CMPXCHG32rr : I<0xB1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src), 1917 "cmpxchg{l}\t{$src, $dst|$dst, $src}", [], 1918 IIC_CMPXCHG_REG>, TB, OpSize32; 1919def CMPXCHG64rr : RI<0xB1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src), 1920 "cmpxchg{q}\t{$src, $dst|$dst, $src}", [], 1921 IIC_CMPXCHG_REG>, TB; 1922} // SchedRW 1923 1924let SchedRW = [WriteALULd, WriteRMW] in { 1925let mayLoad = 1, mayStore = 1 in { 1926def CMPXCHG8rm : I<0xB0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src), 1927 "cmpxchg{b}\t{$src, $dst|$dst, $src}", [], 1928 IIC_CMPXCHG_MEM8>, TB; 1929def CMPXCHG16rm : I<0xB1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src), 1930 "cmpxchg{w}\t{$src, $dst|$dst, $src}", [], 1931 IIC_CMPXCHG_MEM>, TB, OpSize16; 1932def CMPXCHG32rm : I<0xB1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src), 1933 "cmpxchg{l}\t{$src, $dst|$dst, $src}", [], 1934 IIC_CMPXCHG_MEM>, TB, OpSize32; 1935def CMPXCHG64rm : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src), 1936 "cmpxchg{q}\t{$src, $dst|$dst, $src}", [], 1937 IIC_CMPXCHG_MEM>, TB; 1938} 1939 1940let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in 1941def CMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$dst), 1942 "cmpxchg8b\t$dst", [], IIC_CMPXCHG_8B>, TB; 1943 1944let Defs = [RAX, RDX, EFLAGS], Uses = [RAX, RBX, RCX, RDX] in 1945def CMPXCHG16B : RI<0xC7, MRM1m, (outs), (ins i128mem:$dst), 1946 "cmpxchg16b\t$dst", [], IIC_CMPXCHG_16B>, 1947 TB, Requires<[HasCmpxchg16b]>; 1948} // SchedRW 1949 1950 1951// Lock instruction prefix 1952def LOCK_PREFIX : I<0xF0, RawFrm, (outs), (ins), "lock", []>; 1953 1954// Rex64 instruction prefix 1955def REX64_PREFIX : I<0x48, RawFrm, (outs), (ins), "rex64", []>, 1956 Requires<[In64BitMode]>; 1957 1958// Data16 instruction prefix 1959def DATA16_PREFIX : I<0x66, RawFrm, (outs), (ins), "data16", []>; 1960 1961// Repeat string operation instruction prefixes 1962// These uses the DF flag in the EFLAGS register to inc or dec ECX 1963let Defs = [ECX], Uses = [ECX,EFLAGS] in { 1964// Repeat (used with INS, OUTS, MOVS, LODS and STOS) 1965def REP_PREFIX : I<0xF3, RawFrm, (outs), (ins), "rep", []>; 1966// Repeat while not equal (used with CMPS and SCAS) 1967def REPNE_PREFIX : I<0xF2, RawFrm, (outs), (ins), "repne", []>; 1968} 1969 1970 1971// String manipulation instructions 1972let SchedRW = [WriteMicrocoded] in { 1973// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI 1974let Defs = [AL,ESI], Uses = [ESI,EFLAGS] in 1975def LODSB : I<0xAC, RawFrmSrc, (outs), (ins srcidx8:$src), 1976 "lodsb\t{$src, %al|al, $src}", [], IIC_LODS>; 1977let Defs = [AX,ESI], Uses = [ESI,EFLAGS] in 1978def LODSW : I<0xAD, RawFrmSrc, (outs), (ins srcidx16:$src), 1979 "lodsw\t{$src, %ax|ax, $src}", [], IIC_LODS>, OpSize16; 1980let Defs = [EAX,ESI], Uses = [ESI,EFLAGS] in 1981def LODSL : I<0xAD, RawFrmSrc, (outs), (ins srcidx32:$src), 1982 "lods{l|d}\t{$src, %eax|eax, $src}", [], IIC_LODS>, OpSize32; 1983let Defs = [RAX,ESI], Uses = [ESI,EFLAGS] in 1984def LODSQ : RI<0xAD, RawFrmSrc, (outs), (ins srcidx64:$src), 1985 "lodsq\t{$src, %rax|rax, $src}", [], IIC_LODS>; 1986} 1987 1988let SchedRW = [WriteSystem] in { 1989// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI 1990let Defs = [ESI], Uses = [DX,ESI,EFLAGS] in { 1991def OUTSB : I<0x6E, RawFrmSrc, (outs), (ins srcidx8:$src), 1992 "outsb\t{$src, %dx|dx, $src}", [], IIC_OUTS>; 1993def OUTSW : I<0x6F, RawFrmSrc, (outs), (ins srcidx16:$src), 1994 "outsw\t{$src, %dx|dx, $src}", [], IIC_OUTS>, OpSize16; 1995def OUTSL : I<0x6F, RawFrmSrc, (outs), (ins srcidx32:$src), 1996 "outs{l|d}\t{$src, %dx|dx, $src}", [], IIC_OUTS>, OpSize32; 1997} 1998 1999// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI 2000let Defs = [EDI], Uses = [DX,EDI,EFLAGS] in { 2001def INSB : I<0x6C, RawFrmDst, (outs), (ins dstidx8:$dst), 2002 "insb\t{%dx, $dst|$dst, dx}", [], IIC_INS>; 2003def INSW : I<0x6D, RawFrmDst, (outs), (ins dstidx16:$dst), 2004 "insw\t{%dx, $dst|$dst, dx}", [], IIC_INS>, OpSize16; 2005def INSL : I<0x6D, RawFrmDst, (outs), (ins dstidx32:$dst), 2006 "ins{l|d}\t{%dx, $dst|$dst, dx}", [], IIC_INS>, OpSize32; 2007} 2008} 2009 2010// Flag instructions 2011let SchedRW = [WriteALU] in { 2012def CLC : I<0xF8, RawFrm, (outs), (ins), "clc", [], IIC_CLC>; 2013def STC : I<0xF9, RawFrm, (outs), (ins), "stc", [], IIC_STC>; 2014def CLI : I<0xFA, RawFrm, (outs), (ins), "cli", [], IIC_CLI>; 2015def STI : I<0xFB, RawFrm, (outs), (ins), "sti", [], IIC_STI>; 2016def CLD : I<0xFC, RawFrm, (outs), (ins), "cld", [], IIC_CLD>; 2017def STD : I<0xFD, RawFrm, (outs), (ins), "std", [], IIC_STD>; 2018def CMC : I<0xF5, RawFrm, (outs), (ins), "cmc", [], IIC_CMC>; 2019 2020def CLTS : I<0x06, RawFrm, (outs), (ins), "clts", [], IIC_CLTS>, TB; 2021} 2022 2023// Table lookup instructions 2024let Uses = [AL,EBX], Defs = [AL], hasSideEffects = 0, mayLoad = 1 in 2025def XLAT : I<0xD7, RawFrm, (outs), (ins), "xlatb", [], IIC_XLAT>, 2026 Sched<[WriteLoad]>; 2027 2028let SchedRW = [WriteMicrocoded] in { 2029// ASCII Adjust After Addition 2030let Uses = [AL,EFLAGS], Defs = [AX,EFLAGS], hasSideEffects = 0 in 2031def AAA : I<0x37, RawFrm, (outs), (ins), "aaa", [], IIC_AAA>, 2032 Requires<[Not64BitMode]>; 2033 2034// ASCII Adjust AX Before Division 2035let Uses = [AX], Defs = [AX,EFLAGS], hasSideEffects = 0 in 2036def AAD8i8 : Ii8<0xD5, RawFrm, (outs), (ins i8imm:$src), 2037 "aad\t$src", [], IIC_AAD>, Requires<[Not64BitMode]>; 2038 2039// ASCII Adjust AX After Multiply 2040let Uses = [AL], Defs = [AX,EFLAGS], hasSideEffects = 0 in 2041def AAM8i8 : Ii8<0xD4, RawFrm, (outs), (ins i8imm:$src), 2042 "aam\t$src", [], IIC_AAM>, Requires<[Not64BitMode]>; 2043 2044// ASCII Adjust AL After Subtraction - sets 2045let Uses = [AL,EFLAGS], Defs = [AX,EFLAGS], hasSideEffects = 0 in 2046def AAS : I<0x3F, RawFrm, (outs), (ins), "aas", [], IIC_AAS>, 2047 Requires<[Not64BitMode]>; 2048 2049// Decimal Adjust AL after Addition 2050let Uses = [AL,EFLAGS], Defs = [AL,EFLAGS], hasSideEffects = 0 in 2051def DAA : I<0x27, RawFrm, (outs), (ins), "daa", [], IIC_DAA>, 2052 Requires<[Not64BitMode]>; 2053 2054// Decimal Adjust AL after Subtraction 2055let Uses = [AL,EFLAGS], Defs = [AL,EFLAGS], hasSideEffects = 0 in 2056def DAS : I<0x2F, RawFrm, (outs), (ins), "das", [], IIC_DAS>, 2057 Requires<[Not64BitMode]>; 2058} // SchedRW 2059 2060let SchedRW = [WriteSystem] in { 2061// Check Array Index Against Bounds 2062def BOUNDS16rm : I<0x62, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src), 2063 "bound\t{$src, $dst|$dst, $src}", [], IIC_BOUND>, OpSize16, 2064 Requires<[Not64BitMode]>; 2065def BOUNDS32rm : I<0x62, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src), 2066 "bound\t{$src, $dst|$dst, $src}", [], IIC_BOUND>, OpSize32, 2067 Requires<[Not64BitMode]>; 2068 2069// Adjust RPL Field of Segment Selector 2070def ARPL16rr : I<0x63, MRMDestReg, (outs GR16:$dst), (ins GR16:$src), 2071 "arpl\t{$src, $dst|$dst, $src}", [], IIC_ARPL_REG>, 2072 Requires<[Not64BitMode]>; 2073def ARPL16mr : I<0x63, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src), 2074 "arpl\t{$src, $dst|$dst, $src}", [], IIC_ARPL_MEM>, 2075 Requires<[Not64BitMode]>; 2076} // SchedRW 2077 2078//===----------------------------------------------------------------------===// 2079// MOVBE Instructions 2080// 2081let Predicates = [HasMOVBE] in { 2082 let SchedRW = [WriteALULd] in { 2083 def MOVBE16rm : I<0xF0, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src), 2084 "movbe{w}\t{$src, $dst|$dst, $src}", 2085 [(set GR16:$dst, (bswap (loadi16 addr:$src)))], IIC_MOVBE>, 2086 OpSize16, T8PS; 2087 def MOVBE32rm : I<0xF0, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src), 2088 "movbe{l}\t{$src, $dst|$dst, $src}", 2089 [(set GR32:$dst, (bswap (loadi32 addr:$src)))], IIC_MOVBE>, 2090 OpSize32, T8PS; 2091 def MOVBE64rm : RI<0xF0, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src), 2092 "movbe{q}\t{$src, $dst|$dst, $src}", 2093 [(set GR64:$dst, (bswap (loadi64 addr:$src)))], IIC_MOVBE>, 2094 T8PS; 2095 } 2096 let SchedRW = [WriteStore] in { 2097 def MOVBE16mr : I<0xF1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src), 2098 "movbe{w}\t{$src, $dst|$dst, $src}", 2099 [(store (bswap GR16:$src), addr:$dst)], IIC_MOVBE>, 2100 OpSize16, T8PS; 2101 def MOVBE32mr : I<0xF1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src), 2102 "movbe{l}\t{$src, $dst|$dst, $src}", 2103 [(store (bswap GR32:$src), addr:$dst)], IIC_MOVBE>, 2104 OpSize32, T8PS; 2105 def MOVBE64mr : RI<0xF1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src), 2106 "movbe{q}\t{$src, $dst|$dst, $src}", 2107 [(store (bswap GR64:$src), addr:$dst)], IIC_MOVBE>, 2108 T8PS; 2109 } 2110} 2111 2112//===----------------------------------------------------------------------===// 2113// RDRAND Instruction 2114// 2115let Predicates = [HasRDRAND], Defs = [EFLAGS] in { 2116 def RDRAND16r : I<0xC7, MRM6r, (outs GR16:$dst), (ins), 2117 "rdrand{w}\t$dst", 2118 [(set GR16:$dst, EFLAGS, (X86rdrand))]>, OpSize16, TB; 2119 def RDRAND32r : I<0xC7, MRM6r, (outs GR32:$dst), (ins), 2120 "rdrand{l}\t$dst", 2121 [(set GR32:$dst, EFLAGS, (X86rdrand))]>, OpSize32, TB; 2122 def RDRAND64r : RI<0xC7, MRM6r, (outs GR64:$dst), (ins), 2123 "rdrand{q}\t$dst", 2124 [(set GR64:$dst, EFLAGS, (X86rdrand))]>, TB; 2125} 2126 2127//===----------------------------------------------------------------------===// 2128// RDSEED Instruction 2129// 2130let Predicates = [HasRDSEED], Defs = [EFLAGS] in { 2131 def RDSEED16r : I<0xC7, MRM7r, (outs GR16:$dst), (ins), 2132 "rdseed{w}\t$dst", 2133 [(set GR16:$dst, EFLAGS, (X86rdseed))]>, OpSize16, TB; 2134 def RDSEED32r : I<0xC7, MRM7r, (outs GR32:$dst), (ins), 2135 "rdseed{l}\t$dst", 2136 [(set GR32:$dst, EFLAGS, (X86rdseed))]>, OpSize32, TB; 2137 def RDSEED64r : RI<0xC7, MRM7r, (outs GR64:$dst), (ins), 2138 "rdseed{q}\t$dst", 2139 [(set GR64:$dst, EFLAGS, (X86rdseed))]>, TB; 2140} 2141 2142//===----------------------------------------------------------------------===// 2143// LZCNT Instruction 2144// 2145let Predicates = [HasLZCNT], Defs = [EFLAGS] in { 2146 def LZCNT16rr : I<0xBD, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src), 2147 "lzcnt{w}\t{$src, $dst|$dst, $src}", 2148 [(set GR16:$dst, (ctlz GR16:$src)), (implicit EFLAGS)]>, XS, 2149 OpSize16; 2150 def LZCNT16rm : I<0xBD, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src), 2151 "lzcnt{w}\t{$src, $dst|$dst, $src}", 2152 [(set GR16:$dst, (ctlz (loadi16 addr:$src))), 2153 (implicit EFLAGS)]>, XS, OpSize16; 2154 2155 def LZCNT32rr : I<0xBD, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src), 2156 "lzcnt{l}\t{$src, $dst|$dst, $src}", 2157 [(set GR32:$dst, (ctlz GR32:$src)), (implicit EFLAGS)]>, XS, 2158 OpSize32; 2159 def LZCNT32rm : I<0xBD, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src), 2160 "lzcnt{l}\t{$src, $dst|$dst, $src}", 2161 [(set GR32:$dst, (ctlz (loadi32 addr:$src))), 2162 (implicit EFLAGS)]>, XS, OpSize32; 2163 2164 def LZCNT64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src), 2165 "lzcnt{q}\t{$src, $dst|$dst, $src}", 2166 [(set GR64:$dst, (ctlz GR64:$src)), (implicit EFLAGS)]>, 2167 XS; 2168 def LZCNT64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src), 2169 "lzcnt{q}\t{$src, $dst|$dst, $src}", 2170 [(set GR64:$dst, (ctlz (loadi64 addr:$src))), 2171 (implicit EFLAGS)]>, XS; 2172} 2173 2174//===----------------------------------------------------------------------===// 2175// BMI Instructions 2176// 2177let Predicates = [HasBMI], Defs = [EFLAGS] in { 2178 def TZCNT16rr : I<0xBC, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src), 2179 "tzcnt{w}\t{$src, $dst|$dst, $src}", 2180 [(set GR16:$dst, (cttz GR16:$src)), (implicit EFLAGS)]>, XS, 2181 OpSize16; 2182 def TZCNT16rm : I<0xBC, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src), 2183 "tzcnt{w}\t{$src, $dst|$dst, $src}", 2184 [(set GR16:$dst, (cttz (loadi16 addr:$src))), 2185 (implicit EFLAGS)]>, XS, OpSize16; 2186 2187 def TZCNT32rr : I<0xBC, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src), 2188 "tzcnt{l}\t{$src, $dst|$dst, $src}", 2189 [(set GR32:$dst, (cttz GR32:$src)), (implicit EFLAGS)]>, XS, 2190 OpSize32; 2191 def TZCNT32rm : I<0xBC, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src), 2192 "tzcnt{l}\t{$src, $dst|$dst, $src}", 2193 [(set GR32:$dst, (cttz (loadi32 addr:$src))), 2194 (implicit EFLAGS)]>, XS, OpSize32; 2195 2196 def TZCNT64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src), 2197 "tzcnt{q}\t{$src, $dst|$dst, $src}", 2198 [(set GR64:$dst, (cttz GR64:$src)), (implicit EFLAGS)]>, 2199 XS; 2200 def TZCNT64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src), 2201 "tzcnt{q}\t{$src, $dst|$dst, $src}", 2202 [(set GR64:$dst, (cttz (loadi64 addr:$src))), 2203 (implicit EFLAGS)]>, XS; 2204} 2205 2206multiclass bmi_bls<string mnemonic, Format RegMRM, Format MemMRM, 2207 RegisterClass RC, X86MemOperand x86memop> { 2208let hasSideEffects = 0 in { 2209 def rr : I<0xF3, RegMRM, (outs RC:$dst), (ins RC:$src), 2210 !strconcat(mnemonic, "\t{$src, $dst|$dst, $src}"), 2211 []>, T8PS, VEX_4V; 2212 let mayLoad = 1 in 2213 def rm : I<0xF3, MemMRM, (outs RC:$dst), (ins x86memop:$src), 2214 !strconcat(mnemonic, "\t{$src, $dst|$dst, $src}"), 2215 []>, T8PS, VEX_4V; 2216} 2217} 2218 2219let Predicates = [HasBMI], Defs = [EFLAGS] in { 2220 defm BLSR32 : bmi_bls<"blsr{l}", MRM1r, MRM1m, GR32, i32mem>; 2221 defm BLSR64 : bmi_bls<"blsr{q}", MRM1r, MRM1m, GR64, i64mem>, VEX_W; 2222 defm BLSMSK32 : bmi_bls<"blsmsk{l}", MRM2r, MRM2m, GR32, i32mem>; 2223 defm BLSMSK64 : bmi_bls<"blsmsk{q}", MRM2r, MRM2m, GR64, i64mem>, VEX_W; 2224 defm BLSI32 : bmi_bls<"blsi{l}", MRM3r, MRM3m, GR32, i32mem>; 2225 defm BLSI64 : bmi_bls<"blsi{q}", MRM3r, MRM3m, GR64, i64mem>, VEX_W; 2226} 2227 2228//===----------------------------------------------------------------------===// 2229// Pattern fragments to auto generate BMI instructions. 2230//===----------------------------------------------------------------------===// 2231 2232let Predicates = [HasBMI] in { 2233 // FIXME: patterns for the load versions are not implemented 2234 def : Pat<(and GR32:$src, (add GR32:$src, -1)), 2235 (BLSR32rr GR32:$src)>; 2236 def : Pat<(and GR64:$src, (add GR64:$src, -1)), 2237 (BLSR64rr GR64:$src)>; 2238 2239 def : Pat<(xor GR32:$src, (add GR32:$src, -1)), 2240 (BLSMSK32rr GR32:$src)>; 2241 def : Pat<(xor GR64:$src, (add GR64:$src, -1)), 2242 (BLSMSK64rr GR64:$src)>; 2243 2244 def : Pat<(and GR32:$src, (ineg GR32:$src)), 2245 (BLSI32rr GR32:$src)>; 2246 def : Pat<(and GR64:$src, (ineg GR64:$src)), 2247 (BLSI64rr GR64:$src)>; 2248} 2249 2250 2251multiclass bmi_bextr_bzhi<bits<8> opc, string mnemonic, RegisterClass RC, 2252 X86MemOperand x86memop, Intrinsic Int, 2253 PatFrag ld_frag> { 2254 def rr : I<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2), 2255 !strconcat(mnemonic, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"), 2256 [(set RC:$dst, (Int RC:$src1, RC:$src2)), (implicit EFLAGS)]>, 2257 T8PS, VEX_4VOp3; 2258 def rm : I<opc, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src1, RC:$src2), 2259 !strconcat(mnemonic, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"), 2260 [(set RC:$dst, (Int (ld_frag addr:$src1), RC:$src2)), 2261 (implicit EFLAGS)]>, T8PS, VEX_4VOp3; 2262} 2263 2264let Predicates = [HasBMI], Defs = [EFLAGS] in { 2265 defm BEXTR32 : bmi_bextr_bzhi<0xF7, "bextr{l}", GR32, i32mem, 2266 int_x86_bmi_bextr_32, loadi32>; 2267 defm BEXTR64 : bmi_bextr_bzhi<0xF7, "bextr{q}", GR64, i64mem, 2268 int_x86_bmi_bextr_64, loadi64>, VEX_W; 2269} 2270 2271let Predicates = [HasBMI2], Defs = [EFLAGS] in { 2272 defm BZHI32 : bmi_bextr_bzhi<0xF5, "bzhi{l}", GR32, i32mem, 2273 int_x86_bmi_bzhi_32, loadi32>; 2274 defm BZHI64 : bmi_bextr_bzhi<0xF5, "bzhi{q}", GR64, i64mem, 2275 int_x86_bmi_bzhi_64, loadi64>, VEX_W; 2276} 2277 2278 2279def CountTrailingOnes : SDNodeXForm<imm, [{ 2280 // Count the trailing ones in the immediate. 2281 return getI8Imm(countTrailingOnes(N->getZExtValue()), SDLoc(N)); 2282}]>; 2283 2284def BZHIMask : ImmLeaf<i64, [{ 2285 return isMask_64(Imm) && (countTrailingOnes<uint64_t>(Imm) > 32); 2286}]>; 2287 2288let Predicates = [HasBMI2] in { 2289 def : Pat<(and GR64:$src, BZHIMask:$mask), 2290 (BZHI64rr GR64:$src, 2291 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), 2292 (MOV8ri (CountTrailingOnes imm:$mask)), sub_8bit))>; 2293 2294 def : Pat<(and GR32:$src, (add (shl 1, GR8:$lz), -1)), 2295 (BZHI32rr GR32:$src, 2296 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$lz, sub_8bit))>; 2297 2298 def : Pat<(and (loadi32 addr:$src), (add (shl 1, GR8:$lz), -1)), 2299 (BZHI32rm addr:$src, 2300 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$lz, sub_8bit))>; 2301 2302 def : Pat<(and GR64:$src, (add (shl 1, GR8:$lz), -1)), 2303 (BZHI64rr GR64:$src, 2304 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$lz, sub_8bit))>; 2305 2306 def : Pat<(and (loadi64 addr:$src), (add (shl 1, GR8:$lz), -1)), 2307 (BZHI64rm addr:$src, 2308 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$lz, sub_8bit))>; 2309} // HasBMI2 2310 2311let Predicates = [HasBMI] in { 2312 def : Pat<(X86bextr GR32:$src1, GR32:$src2), 2313 (BEXTR32rr GR32:$src1, GR32:$src2)>; 2314 def : Pat<(X86bextr (loadi32 addr:$src1), GR32:$src2), 2315 (BEXTR32rm addr:$src1, GR32:$src2)>; 2316 def : Pat<(X86bextr GR64:$src1, GR64:$src2), 2317 (BEXTR64rr GR64:$src1, GR64:$src2)>; 2318 def : Pat<(X86bextr (loadi64 addr:$src1), GR64:$src2), 2319 (BEXTR64rm addr:$src1, GR64:$src2)>; 2320} // HasBMI 2321 2322multiclass bmi_pdep_pext<string mnemonic, RegisterClass RC, 2323 X86MemOperand x86memop, Intrinsic Int, 2324 PatFrag ld_frag> { 2325 def rr : I<0xF5, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2), 2326 !strconcat(mnemonic, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"), 2327 [(set RC:$dst, (Int RC:$src1, RC:$src2))]>, 2328 VEX_4V; 2329 def rm : I<0xF5, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2), 2330 !strconcat(mnemonic, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"), 2331 [(set RC:$dst, (Int RC:$src1, (ld_frag addr:$src2)))]>, VEX_4V; 2332} 2333 2334let Predicates = [HasBMI2] in { 2335 defm PDEP32 : bmi_pdep_pext<"pdep{l}", GR32, i32mem, 2336 int_x86_bmi_pdep_32, loadi32>, T8XD; 2337 defm PDEP64 : bmi_pdep_pext<"pdep{q}", GR64, i64mem, 2338 int_x86_bmi_pdep_64, loadi64>, T8XD, VEX_W; 2339 defm PEXT32 : bmi_pdep_pext<"pext{l}", GR32, i32mem, 2340 int_x86_bmi_pext_32, loadi32>, T8XS; 2341 defm PEXT64 : bmi_pdep_pext<"pext{q}", GR64, i64mem, 2342 int_x86_bmi_pext_64, loadi64>, T8XS, VEX_W; 2343} 2344 2345//===----------------------------------------------------------------------===// 2346// TBM Instructions 2347// 2348let Predicates = [HasTBM], Defs = [EFLAGS] in { 2349 2350multiclass tbm_ternary_imm_intr<bits<8> opc, RegisterClass RC, string OpcodeStr, 2351 X86MemOperand x86memop, PatFrag ld_frag, 2352 Intrinsic Int, Operand immtype, 2353 SDPatternOperator immoperator> { 2354 def ri : Ii32<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, immtype:$cntl), 2355 !strconcat(OpcodeStr, 2356 "\t{$cntl, $src1, $dst|$dst, $src1, $cntl}"), 2357 [(set RC:$dst, (Int RC:$src1, immoperator:$cntl))]>, 2358 XOP, XOPA; 2359 def mi : Ii32<opc, MRMSrcMem, (outs RC:$dst), 2360 (ins x86memop:$src1, immtype:$cntl), 2361 !strconcat(OpcodeStr, 2362 "\t{$cntl, $src1, $dst|$dst, $src1, $cntl}"), 2363 [(set RC:$dst, (Int (ld_frag addr:$src1), immoperator:$cntl))]>, 2364 XOP, XOPA; 2365} 2366 2367defm BEXTRI32 : tbm_ternary_imm_intr<0x10, GR32, "bextr", i32mem, loadi32, 2368 int_x86_tbm_bextri_u32, i32imm, imm>; 2369let ImmT = Imm32S in 2370defm BEXTRI64 : tbm_ternary_imm_intr<0x10, GR64, "bextr", i64mem, loadi64, 2371 int_x86_tbm_bextri_u64, i64i32imm, 2372 i64immSExt32>, VEX_W; 2373 2374multiclass tbm_binary_rm<bits<8> opc, Format FormReg, Format FormMem, 2375 RegisterClass RC, string OpcodeStr, 2376 X86MemOperand x86memop, PatFrag ld_frag> { 2377let hasSideEffects = 0 in { 2378 def rr : I<opc, FormReg, (outs RC:$dst), (ins RC:$src), 2379 !strconcat(OpcodeStr,"\t{$src, $dst|$dst, $src}"), 2380 []>, XOP_4V, XOP9; 2381 let mayLoad = 1 in 2382 def rm : I<opc, FormMem, (outs RC:$dst), (ins x86memop:$src), 2383 !strconcat(OpcodeStr,"\t{$src, $dst|$dst, $src}"), 2384 []>, XOP_4V, XOP9; 2385} 2386} 2387 2388multiclass tbm_binary_intr<bits<8> opc, string OpcodeStr, 2389 Format FormReg, Format FormMem> { 2390 defm NAME#32 : tbm_binary_rm<opc, FormReg, FormMem, GR32, OpcodeStr, i32mem, 2391 loadi32>; 2392 defm NAME#64 : tbm_binary_rm<opc, FormReg, FormMem, GR64, OpcodeStr, i64mem, 2393 loadi64>, VEX_W; 2394} 2395 2396defm BLCFILL : tbm_binary_intr<0x01, "blcfill", MRM1r, MRM1m>; 2397defm BLCI : tbm_binary_intr<0x02, "blci", MRM6r, MRM6m>; 2398defm BLCIC : tbm_binary_intr<0x01, "blcic", MRM5r, MRM5m>; 2399defm BLCMSK : tbm_binary_intr<0x02, "blcmsk", MRM1r, MRM1m>; 2400defm BLCS : tbm_binary_intr<0x01, "blcs", MRM3r, MRM3m>; 2401defm BLSFILL : tbm_binary_intr<0x01, "blsfill", MRM2r, MRM2m>; 2402defm BLSIC : tbm_binary_intr<0x01, "blsic", MRM6r, MRM6m>; 2403defm T1MSKC : tbm_binary_intr<0x01, "t1mskc", MRM7r, MRM7m>; 2404defm TZMSK : tbm_binary_intr<0x01, "tzmsk", MRM4r, MRM4m>; 2405} // HasTBM, EFLAGS 2406 2407//===----------------------------------------------------------------------===// 2408// MONITORX/MWAITX Instructions 2409// 2410let SchedRW = [ WriteSystem ] in { 2411 let usesCustomInserter = 1 in { 2412 def MONITORX : PseudoI<(outs), (ins i32mem:$src1, GR32:$src2, GR32:$src3), 2413 [(int_x86_monitorx addr:$src1, GR32:$src2, GR32:$src3)]>, 2414 Requires<[ HasMWAITX ]>; 2415 } 2416 2417 let Uses = [ EAX, ECX, EDX ] in { 2418 def MONITORXrrr : I<0x01, MRM_FA, (outs), (ins), "monitorx", [], IIC_SSE_MONITORX>, 2419 TB, Requires<[ HasMWAITX ]>; 2420 } 2421 2422 let Uses = [ ECX, EAX, EBX ] in { 2423 def MWAITXrrr : I<0x01, MRM_FB, (outs), (ins), "mwaitx", 2424 [(int_x86_mwaitx ECX, EAX, EBX)], IIC_SSE_MWAITX>, 2425 TB, Requires<[ HasMWAITX ]>; 2426 } 2427} // SchedRW 2428 2429def : InstAlias<"mwaitx\t{%eax, %ecx, %ebx|ebx, ecx, eax}", (MWAITXrrr)>, 2430 Requires<[ Not64BitMode ]>; 2431def : InstAlias<"mwaitx\t{%rax, %rcx, %rbx|rbx, rcx, rax}", (MWAITXrrr)>, 2432 Requires<[ In64BitMode ]>; 2433 2434def : InstAlias<"monitorx\t{%eax, %ecx, %edx|edx, ecx, eax}", (MONITORXrrr)>, 2435 Requires<[ Not64BitMode ]>; 2436def : InstAlias<"monitorx\t{%rax, %rcx, %rdx|rdx, rcx, rax}", (MONITORXrrr)>, 2437 Requires<[ In64BitMode ]>; 2438 2439//===----------------------------------------------------------------------===// 2440// CLZERO Instruction 2441// 2442let Uses = [EAX] in 2443def CLZEROr : I<0x01, MRM_FC, (outs), (ins), "clzero", []>, TB; 2444 2445//===----------------------------------------------------------------------===// 2446// Pattern fragments to auto generate TBM instructions. 2447//===----------------------------------------------------------------------===// 2448 2449let Predicates = [HasTBM] in { 2450 def : Pat<(X86bextr GR32:$src1, (i32 imm:$src2)), 2451 (BEXTRI32ri GR32:$src1, imm:$src2)>; 2452 def : Pat<(X86bextr (loadi32 addr:$src1), (i32 imm:$src2)), 2453 (BEXTRI32mi addr:$src1, imm:$src2)>; 2454 def : Pat<(X86bextr GR64:$src1, i64immSExt32:$src2), 2455 (BEXTRI64ri GR64:$src1, i64immSExt32:$src2)>; 2456 def : Pat<(X86bextr (loadi64 addr:$src1), i64immSExt32:$src2), 2457 (BEXTRI64mi addr:$src1, i64immSExt32:$src2)>; 2458 2459 // FIXME: patterns for the load versions are not implemented 2460 def : Pat<(and GR32:$src, (add GR32:$src, 1)), 2461 (BLCFILL32rr GR32:$src)>; 2462 def : Pat<(and GR64:$src, (add GR64:$src, 1)), 2463 (BLCFILL64rr GR64:$src)>; 2464 2465 def : Pat<(or GR32:$src, (not (add GR32:$src, 1))), 2466 (BLCI32rr GR32:$src)>; 2467 def : Pat<(or GR64:$src, (not (add GR64:$src, 1))), 2468 (BLCI64rr GR64:$src)>; 2469 2470 // Extra patterns because opt can optimize the above patterns to this. 2471 def : Pat<(or GR32:$src, (sub -2, GR32:$src)), 2472 (BLCI32rr GR32:$src)>; 2473 def : Pat<(or GR64:$src, (sub -2, GR64:$src)), 2474 (BLCI64rr GR64:$src)>; 2475 2476 def : Pat<(and (not GR32:$src), (add GR32:$src, 1)), 2477 (BLCIC32rr GR32:$src)>; 2478 def : Pat<(and (not GR64:$src), (add GR64:$src, 1)), 2479 (BLCIC64rr GR64:$src)>; 2480 2481 def : Pat<(xor GR32:$src, (add GR32:$src, 1)), 2482 (BLCMSK32rr GR32:$src)>; 2483 def : Pat<(xor GR64:$src, (add GR64:$src, 1)), 2484 (BLCMSK64rr GR64:$src)>; 2485 2486 def : Pat<(or GR32:$src, (add GR32:$src, 1)), 2487 (BLCS32rr GR32:$src)>; 2488 def : Pat<(or GR64:$src, (add GR64:$src, 1)), 2489 (BLCS64rr GR64:$src)>; 2490 2491 def : Pat<(or GR32:$src, (add GR32:$src, -1)), 2492 (BLSFILL32rr GR32:$src)>; 2493 def : Pat<(or GR64:$src, (add GR64:$src, -1)), 2494 (BLSFILL64rr GR64:$src)>; 2495 2496 def : Pat<(or (not GR32:$src), (add GR32:$src, -1)), 2497 (BLSIC32rr GR32:$src)>; 2498 def : Pat<(or (not GR64:$src), (add GR64:$src, -1)), 2499 (BLSIC64rr GR64:$src)>; 2500 2501 def : Pat<(or (not GR32:$src), (add GR32:$src, 1)), 2502 (T1MSKC32rr GR32:$src)>; 2503 def : Pat<(or (not GR64:$src), (add GR64:$src, 1)), 2504 (T1MSKC64rr GR64:$src)>; 2505 2506 def : Pat<(and (not GR32:$src), (add GR32:$src, -1)), 2507 (TZMSK32rr GR32:$src)>; 2508 def : Pat<(and (not GR64:$src), (add GR64:$src, -1)), 2509 (TZMSK64rr GR64:$src)>; 2510} // HasTBM 2511 2512//===----------------------------------------------------------------------===// 2513// Memory Instructions 2514// 2515 2516def CLFLUSHOPT : I<0xAE, MRM7m, (outs), (ins i8mem:$src), 2517 "clflushopt\t$src", [(int_x86_clflushopt addr:$src)]>, PD; 2518def CLWB : I<0xAE, MRM6m, (outs), (ins i8mem:$src), "clwb\t$src", []>, PD; 2519def PCOMMIT : I<0xAE, MRM_F8, (outs), (ins), "pcommit", []>, PD; 2520 2521 2522//===----------------------------------------------------------------------===// 2523// Subsystems. 2524//===----------------------------------------------------------------------===// 2525 2526include "X86InstrArithmetic.td" 2527include "X86InstrCMovSetCC.td" 2528include "X86InstrExtension.td" 2529include "X86InstrControl.td" 2530include "X86InstrShiftRotate.td" 2531 2532// X87 Floating Point Stack. 2533include "X86InstrFPStack.td" 2534 2535// SIMD support (SSE, MMX and AVX) 2536include "X86InstrFragmentsSIMD.td" 2537 2538// FMA - Fused Multiply-Add support (requires FMA) 2539include "X86InstrFMA.td" 2540 2541// XOP 2542include "X86InstrXOP.td" 2543 2544// SSE, MMX and 3DNow! vector support. 2545include "X86InstrSSE.td" 2546include "X86InstrAVX512.td" 2547include "X86InstrMMX.td" 2548include "X86Instr3DNow.td" 2549 2550// MPX instructions 2551include "X86InstrMPX.td" 2552 2553include "X86InstrVMX.td" 2554include "X86InstrSVM.td" 2555 2556include "X86InstrTSX.td" 2557include "X86InstrSGX.td" 2558 2559// System instructions. 2560include "X86InstrSystem.td" 2561 2562// Compiler Pseudo Instructions and Pat Patterns 2563include "X86InstrCompiler.td" 2564 2565//===----------------------------------------------------------------------===// 2566// Assembler Mnemonic Aliases 2567//===----------------------------------------------------------------------===// 2568 2569def : MnemonicAlias<"call", "callw", "att">, Requires<[In16BitMode]>; 2570def : MnemonicAlias<"call", "calll", "att">, Requires<[In32BitMode]>; 2571def : MnemonicAlias<"call", "callq", "att">, Requires<[In64BitMode]>; 2572 2573def : MnemonicAlias<"cbw", "cbtw", "att">; 2574def : MnemonicAlias<"cwde", "cwtl", "att">; 2575def : MnemonicAlias<"cwd", "cwtd", "att">; 2576def : MnemonicAlias<"cdq", "cltd", "att">; 2577def : MnemonicAlias<"cdqe", "cltq", "att">; 2578def : MnemonicAlias<"cqo", "cqto", "att">; 2579 2580// In 64-bit mode lret maps to lretl; it is not ambiguous with lretq. 2581def : MnemonicAlias<"lret", "lretw", "att">, Requires<[In16BitMode]>; 2582def : MnemonicAlias<"lret", "lretl", "att">, Requires<[Not16BitMode]>; 2583 2584def : MnemonicAlias<"leavel", "leave", "att">, Requires<[Not64BitMode]>; 2585def : MnemonicAlias<"leaveq", "leave", "att">, Requires<[In64BitMode]>; 2586 2587def : MnemonicAlias<"loopz", "loope">; 2588def : MnemonicAlias<"loopnz", "loopne">; 2589 2590def : MnemonicAlias<"pop", "popw", "att">, Requires<[In16BitMode]>; 2591def : MnemonicAlias<"pop", "popl", "att">, Requires<[In32BitMode]>; 2592def : MnemonicAlias<"pop", "popq", "att">, Requires<[In64BitMode]>; 2593def : MnemonicAlias<"popf", "popfw", "att">, Requires<[In16BitMode]>; 2594def : MnemonicAlias<"popf", "popfl", "att">, Requires<[In32BitMode]>; 2595def : MnemonicAlias<"popf", "popfq", "att">, Requires<[In64BitMode]>; 2596def : MnemonicAlias<"popfd", "popfl", "att">; 2597 2598// FIXME: This is wrong for "push reg". "push %bx" should turn into pushw in 2599// all modes. However: "push (addr)" and "push $42" should default to 2600// pushl/pushq depending on the current mode. Similar for "pop %bx" 2601def : MnemonicAlias<"push", "pushw", "att">, Requires<[In16BitMode]>; 2602def : MnemonicAlias<"push", "pushl", "att">, Requires<[In32BitMode]>; 2603def : MnemonicAlias<"push", "pushq", "att">, Requires<[In64BitMode]>; 2604def : MnemonicAlias<"pushf", "pushfw", "att">, Requires<[In16BitMode]>; 2605def : MnemonicAlias<"pushf", "pushfl", "att">, Requires<[In32BitMode]>; 2606def : MnemonicAlias<"pushf", "pushfq", "att">, Requires<[In64BitMode]>; 2607def : MnemonicAlias<"pushfd", "pushfl", "att">; 2608 2609def : MnemonicAlias<"popad", "popal", "intel">, Requires<[Not64BitMode]>; 2610def : MnemonicAlias<"pushad", "pushal", "intel">, Requires<[Not64BitMode]>; 2611def : MnemonicAlias<"popa", "popaw", "intel">, Requires<[In16BitMode]>; 2612def : MnemonicAlias<"pusha", "pushaw", "intel">, Requires<[In16BitMode]>; 2613def : MnemonicAlias<"popa", "popal", "intel">, Requires<[In32BitMode]>; 2614def : MnemonicAlias<"pusha", "pushal", "intel">, Requires<[In32BitMode]>; 2615 2616def : MnemonicAlias<"popa", "popaw", "att">, Requires<[In16BitMode]>; 2617def : MnemonicAlias<"pusha", "pushaw", "att">, Requires<[In16BitMode]>; 2618def : MnemonicAlias<"popa", "popal", "att">, Requires<[In32BitMode]>; 2619def : MnemonicAlias<"pusha", "pushal", "att">, Requires<[In32BitMode]>; 2620 2621def : MnemonicAlias<"repe", "rep">; 2622def : MnemonicAlias<"repz", "rep">; 2623def : MnemonicAlias<"repnz", "repne">; 2624 2625def : MnemonicAlias<"ret", "retw", "att">, Requires<[In16BitMode]>; 2626def : MnemonicAlias<"ret", "retl", "att">, Requires<[In32BitMode]>; 2627def : MnemonicAlias<"ret", "retq", "att">, Requires<[In64BitMode]>; 2628 2629def : MnemonicAlias<"sal", "shl", "intel">; 2630def : MnemonicAlias<"salb", "shlb", "att">; 2631def : MnemonicAlias<"salw", "shlw", "att">; 2632def : MnemonicAlias<"sall", "shll", "att">; 2633def : MnemonicAlias<"salq", "shlq", "att">; 2634 2635def : MnemonicAlias<"smovb", "movsb", "att">; 2636def : MnemonicAlias<"smovw", "movsw", "att">; 2637def : MnemonicAlias<"smovl", "movsl", "att">; 2638def : MnemonicAlias<"smovq", "movsq", "att">; 2639 2640def : MnemonicAlias<"ud2a", "ud2", "att">; 2641def : MnemonicAlias<"verrw", "verr", "att">; 2642 2643// System instruction aliases. 2644def : MnemonicAlias<"iret", "iretw", "att">, Requires<[In16BitMode]>; 2645def : MnemonicAlias<"iret", "iretl", "att">, Requires<[Not16BitMode]>; 2646def : MnemonicAlias<"sysret", "sysretl", "att">; 2647def : MnemonicAlias<"sysexit", "sysexitl", "att">; 2648 2649def : MnemonicAlias<"lgdt", "lgdtw", "att">, Requires<[In16BitMode]>; 2650def : MnemonicAlias<"lgdt", "lgdtl", "att">, Requires<[In32BitMode]>; 2651def : MnemonicAlias<"lgdt", "lgdtq", "att">, Requires<[In64BitMode]>; 2652def : MnemonicAlias<"lidt", "lidtw", "att">, Requires<[In16BitMode]>; 2653def : MnemonicAlias<"lidt", "lidtl", "att">, Requires<[In32BitMode]>; 2654def : MnemonicAlias<"lidt", "lidtq", "att">, Requires<[In64BitMode]>; 2655def : MnemonicAlias<"sgdt", "sgdtw", "att">, Requires<[In16BitMode]>; 2656def : MnemonicAlias<"sgdt", "sgdtl", "att">, Requires<[In32BitMode]>; 2657def : MnemonicAlias<"sgdt", "sgdtq", "att">, Requires<[In64BitMode]>; 2658def : MnemonicAlias<"sidt", "sidtw", "att">, Requires<[In16BitMode]>; 2659def : MnemonicAlias<"sidt", "sidtl", "att">, Requires<[In32BitMode]>; 2660def : MnemonicAlias<"sidt", "sidtq", "att">, Requires<[In64BitMode]>; 2661 2662 2663// Floating point stack aliases. 2664def : MnemonicAlias<"fcmovz", "fcmove", "att">; 2665def : MnemonicAlias<"fcmova", "fcmovnbe", "att">; 2666def : MnemonicAlias<"fcmovnae", "fcmovb", "att">; 2667def : MnemonicAlias<"fcmovna", "fcmovbe", "att">; 2668def : MnemonicAlias<"fcmovae", "fcmovnb", "att">; 2669def : MnemonicAlias<"fcomip", "fcompi">; 2670def : MnemonicAlias<"fildq", "fildll", "att">; 2671def : MnemonicAlias<"fistpq", "fistpll", "att">; 2672def : MnemonicAlias<"fisttpq", "fisttpll", "att">; 2673def : MnemonicAlias<"fldcww", "fldcw", "att">; 2674def : MnemonicAlias<"fnstcww", "fnstcw", "att">; 2675def : MnemonicAlias<"fnstsww", "fnstsw", "att">; 2676def : MnemonicAlias<"fucomip", "fucompi">; 2677def : MnemonicAlias<"fwait", "wait">; 2678 2679def : MnemonicAlias<"fxsaveq", "fxsave64", "att">; 2680def : MnemonicAlias<"fxrstorq", "fxrstor64", "att">; 2681def : MnemonicAlias<"xsaveq", "xsave64", "att">; 2682def : MnemonicAlias<"xrstorq", "xrstor64", "att">; 2683def : MnemonicAlias<"xsaveoptq", "xsaveopt64", "att">; 2684def : MnemonicAlias<"xrstorsq", "xrstors64", "att">; 2685def : MnemonicAlias<"xsavecq", "xsavec64", "att">; 2686def : MnemonicAlias<"xsavesq", "xsaves64", "att">; 2687 2688class CondCodeAlias<string Prefix,string Suffix, string OldCond, string NewCond, 2689 string VariantName> 2690 : MnemonicAlias<!strconcat(Prefix, OldCond, Suffix), 2691 !strconcat(Prefix, NewCond, Suffix), VariantName>; 2692 2693/// IntegerCondCodeMnemonicAlias - This multiclass defines a bunch of 2694/// MnemonicAlias's that canonicalize the condition code in a mnemonic, for 2695/// example "setz" -> "sete". 2696multiclass IntegerCondCodeMnemonicAlias<string Prefix, string Suffix, 2697 string V = ""> { 2698 def C : CondCodeAlias<Prefix, Suffix, "c", "b", V>; // setc -> setb 2699 def Z : CondCodeAlias<Prefix, Suffix, "z" , "e", V>; // setz -> sete 2700 def NA : CondCodeAlias<Prefix, Suffix, "na", "be", V>; // setna -> setbe 2701 def NB : CondCodeAlias<Prefix, Suffix, "nb", "ae", V>; // setnb -> setae 2702 def NC : CondCodeAlias<Prefix, Suffix, "nc", "ae", V>; // setnc -> setae 2703 def NG : CondCodeAlias<Prefix, Suffix, "ng", "le", V>; // setng -> setle 2704 def NL : CondCodeAlias<Prefix, Suffix, "nl", "ge", V>; // setnl -> setge 2705 def NZ : CondCodeAlias<Prefix, Suffix, "nz", "ne", V>; // setnz -> setne 2706 def PE : CondCodeAlias<Prefix, Suffix, "pe", "p", V>; // setpe -> setp 2707 def PO : CondCodeAlias<Prefix, Suffix, "po", "np", V>; // setpo -> setnp 2708 2709 def NAE : CondCodeAlias<Prefix, Suffix, "nae", "b", V>; // setnae -> setb 2710 def NBE : CondCodeAlias<Prefix, Suffix, "nbe", "a", V>; // setnbe -> seta 2711 def NGE : CondCodeAlias<Prefix, Suffix, "nge", "l", V>; // setnge -> setl 2712 def NLE : CondCodeAlias<Prefix, Suffix, "nle", "g", V>; // setnle -> setg 2713} 2714 2715// Aliases for set<CC> 2716defm : IntegerCondCodeMnemonicAlias<"set", "">; 2717// Aliases for j<CC> 2718defm : IntegerCondCodeMnemonicAlias<"j", "">; 2719// Aliases for cmov<CC>{w,l,q} 2720defm : IntegerCondCodeMnemonicAlias<"cmov", "w", "att">; 2721defm : IntegerCondCodeMnemonicAlias<"cmov", "l", "att">; 2722defm : IntegerCondCodeMnemonicAlias<"cmov", "q", "att">; 2723// No size suffix for intel-style asm. 2724defm : IntegerCondCodeMnemonicAlias<"cmov", "", "intel">; 2725 2726 2727//===----------------------------------------------------------------------===// 2728// Assembler Instruction Aliases 2729//===----------------------------------------------------------------------===// 2730 2731// aad/aam default to base 10 if no operand is specified. 2732def : InstAlias<"aad", (AAD8i8 10)>, Requires<[Not64BitMode]>; 2733def : InstAlias<"aam", (AAM8i8 10)>, Requires<[Not64BitMode]>; 2734 2735// Disambiguate the mem/imm form of bt-without-a-suffix as btl. 2736// Likewise for btc/btr/bts. 2737def : InstAlias<"bt\t{$imm, $mem|$mem, $imm}", 2738 (BT32mi8 i32mem:$mem, i32i8imm:$imm), 0>; 2739def : InstAlias<"btc\t{$imm, $mem|$mem, $imm}", 2740 (BTC32mi8 i32mem:$mem, i32i8imm:$imm), 0>; 2741def : InstAlias<"btr\t{$imm, $mem|$mem, $imm}", 2742 (BTR32mi8 i32mem:$mem, i32i8imm:$imm), 0>; 2743def : InstAlias<"bts\t{$imm, $mem|$mem, $imm}", 2744 (BTS32mi8 i32mem:$mem, i32i8imm:$imm), 0>; 2745 2746// clr aliases. 2747def : InstAlias<"clrb\t$reg", (XOR8rr GR8 :$reg, GR8 :$reg), 0>; 2748def : InstAlias<"clrw\t$reg", (XOR16rr GR16:$reg, GR16:$reg), 0>; 2749def : InstAlias<"clrl\t$reg", (XOR32rr GR32:$reg, GR32:$reg), 0>; 2750def : InstAlias<"clrq\t$reg", (XOR64rr GR64:$reg, GR64:$reg), 0>; 2751 2752// lods aliases. Accept the destination being omitted because it's implicit 2753// in the mnemonic, or the mnemonic suffix being omitted because it's implicit 2754// in the destination. 2755def : InstAlias<"lodsb\t$src", (LODSB srcidx8:$src), 0>; 2756def : InstAlias<"lodsw\t$src", (LODSW srcidx16:$src), 0>; 2757def : InstAlias<"lods{l|d}\t$src", (LODSL srcidx32:$src), 0>; 2758def : InstAlias<"lodsq\t$src", (LODSQ srcidx64:$src), 0>, Requires<[In64BitMode]>; 2759def : InstAlias<"lods\t{$src, %al|al, $src}", (LODSB srcidx8:$src), 0>; 2760def : InstAlias<"lods\t{$src, %ax|ax, $src}", (LODSW srcidx16:$src), 0>; 2761def : InstAlias<"lods\t{$src, %eax|eax, $src}", (LODSL srcidx32:$src), 0>; 2762def : InstAlias<"lods\t{$src, %rax|rax, $src}", (LODSQ srcidx64:$src), 0>, Requires<[In64BitMode]>; 2763def : InstAlias<"lods\t$src", (LODSB srcidx8:$src), 0>; 2764def : InstAlias<"lods\t$src", (LODSW srcidx16:$src), 0>; 2765def : InstAlias<"lods\t$src", (LODSL srcidx32:$src), 0>; 2766def : InstAlias<"lods\t$src", (LODSQ srcidx64:$src), 0>, Requires<[In64BitMode]>; 2767 2768 2769// stos aliases. Accept the source being omitted because it's implicit in 2770// the mnemonic, or the mnemonic suffix being omitted because it's implicit 2771// in the source. 2772def : InstAlias<"stosb\t$dst", (STOSB dstidx8:$dst), 0>; 2773def : InstAlias<"stosw\t$dst", (STOSW dstidx16:$dst), 0>; 2774def : InstAlias<"stos{l|d}\t$dst", (STOSL dstidx32:$dst), 0>; 2775def : InstAlias<"stosq\t$dst", (STOSQ dstidx64:$dst), 0>, Requires<[In64BitMode]>; 2776def : InstAlias<"stos\t{%al, $dst|$dst, al}", (STOSB dstidx8:$dst), 0>; 2777def : InstAlias<"stos\t{%ax, $dst|$dst, ax}", (STOSW dstidx16:$dst), 0>; 2778def : InstAlias<"stos\t{%eax, $dst|$dst, eax}", (STOSL dstidx32:$dst), 0>; 2779def : InstAlias<"stos\t{%rax, $dst|$dst, rax}", (STOSQ dstidx64:$dst), 0>, Requires<[In64BitMode]>; 2780def : InstAlias<"stos\t$dst", (STOSB dstidx8:$dst), 0>; 2781def : InstAlias<"stos\t$dst", (STOSW dstidx16:$dst), 0>; 2782def : InstAlias<"stos\t$dst", (STOSL dstidx32:$dst), 0>; 2783def : InstAlias<"stos\t$dst", (STOSQ dstidx64:$dst), 0>, Requires<[In64BitMode]>; 2784 2785 2786// scas aliases. Accept the destination being omitted because it's implicit 2787// in the mnemonic, or the mnemonic suffix being omitted because it's implicit 2788// in the destination. 2789def : InstAlias<"scasb\t$dst", (SCASB dstidx8:$dst), 0>; 2790def : InstAlias<"scasw\t$dst", (SCASW dstidx16:$dst), 0>; 2791def : InstAlias<"scas{l|d}\t$dst", (SCASL dstidx32:$dst), 0>; 2792def : InstAlias<"scasq\t$dst", (SCASQ dstidx64:$dst), 0>, Requires<[In64BitMode]>; 2793def : InstAlias<"scas\t{$dst, %al|al, $dst}", (SCASB dstidx8:$dst), 0>; 2794def : InstAlias<"scas\t{$dst, %ax|ax, $dst}", (SCASW dstidx16:$dst), 0>; 2795def : InstAlias<"scas\t{$dst, %eax|eax, $dst}", (SCASL dstidx32:$dst), 0>; 2796def : InstAlias<"scas\t{$dst, %rax|rax, $dst}", (SCASQ dstidx64:$dst), 0>, Requires<[In64BitMode]>; 2797def : InstAlias<"scas\t$dst", (SCASB dstidx8:$dst), 0>; 2798def : InstAlias<"scas\t$dst", (SCASW dstidx16:$dst), 0>; 2799def : InstAlias<"scas\t$dst", (SCASL dstidx32:$dst), 0>; 2800def : InstAlias<"scas\t$dst", (SCASQ dstidx64:$dst), 0>, Requires<[In64BitMode]>; 2801 2802// cmps aliases. Mnemonic suffix being omitted because it's implicit 2803// in the destination. 2804def : InstAlias<"cmps\t{$dst, $src|$src, $dst}", (CMPSB dstidx8:$dst, srcidx8:$src), 0>; 2805def : InstAlias<"cmps\t{$dst, $src|$src, $dst}", (CMPSW dstidx16:$dst, srcidx16:$src), 0>; 2806def : InstAlias<"cmps\t{$dst, $src|$src, $dst}", (CMPSL dstidx32:$dst, srcidx32:$src), 0>; 2807def : InstAlias<"cmps\t{$dst, $src|$src, $dst}", (CMPSQ dstidx64:$dst, srcidx64:$src), 0>, Requires<[In64BitMode]>; 2808 2809// movs aliases. Mnemonic suffix being omitted because it's implicit 2810// in the destination. 2811def : InstAlias<"movs\t{$src, $dst|$dst, $src}", (MOVSB dstidx8:$dst, srcidx8:$src), 0>; 2812def : InstAlias<"movs\t{$src, $dst|$dst, $src}", (MOVSW dstidx16:$dst, srcidx16:$src), 0>; 2813def : InstAlias<"movs\t{$src, $dst|$dst, $src}", (MOVSL dstidx32:$dst, srcidx32:$src), 0>; 2814def : InstAlias<"movs\t{$src, $dst|$dst, $src}", (MOVSQ dstidx64:$dst, srcidx64:$src), 0>, Requires<[In64BitMode]>; 2815 2816// div and idiv aliases for explicit A register. 2817def : InstAlias<"div{b}\t{$src, %al|al, $src}", (DIV8r GR8 :$src)>; 2818def : InstAlias<"div{w}\t{$src, %ax|ax, $src}", (DIV16r GR16:$src)>; 2819def : InstAlias<"div{l}\t{$src, %eax|eax, $src}", (DIV32r GR32:$src)>; 2820def : InstAlias<"div{q}\t{$src, %rax|rax, $src}", (DIV64r GR64:$src)>; 2821def : InstAlias<"div{b}\t{$src, %al|al, $src}", (DIV8m i8mem :$src)>; 2822def : InstAlias<"div{w}\t{$src, %ax|ax, $src}", (DIV16m i16mem:$src)>; 2823def : InstAlias<"div{l}\t{$src, %eax|eax, $src}", (DIV32m i32mem:$src)>; 2824def : InstAlias<"div{q}\t{$src, %rax|rax, $src}", (DIV64m i64mem:$src)>; 2825def : InstAlias<"idiv{b}\t{$src, %al|al, $src}", (IDIV8r GR8 :$src)>; 2826def : InstAlias<"idiv{w}\t{$src, %ax|ax, $src}", (IDIV16r GR16:$src)>; 2827def : InstAlias<"idiv{l}\t{$src, %eax|eax, $src}", (IDIV32r GR32:$src)>; 2828def : InstAlias<"idiv{q}\t{$src, %rax|rax, $src}", (IDIV64r GR64:$src)>; 2829def : InstAlias<"idiv{b}\t{$src, %al|al, $src}", (IDIV8m i8mem :$src)>; 2830def : InstAlias<"idiv{w}\t{$src, %ax|ax, $src}", (IDIV16m i16mem:$src)>; 2831def : InstAlias<"idiv{l}\t{$src, %eax|eax, $src}", (IDIV32m i32mem:$src)>; 2832def : InstAlias<"idiv{q}\t{$src, %rax|rax, $src}", (IDIV64m i64mem:$src)>; 2833 2834 2835 2836// Various unary fpstack operations default to operating on on ST1. 2837// For example, "fxch" -> "fxch %st(1)" 2838def : InstAlias<"faddp", (ADD_FPrST0 ST1), 0>; 2839def: InstAlias<"fadd", (ADD_FPrST0 ST1), 0>; 2840def : InstAlias<"fsub{|r}p", (SUBR_FPrST0 ST1), 0>; 2841def : InstAlias<"fsub{r|}p", (SUB_FPrST0 ST1), 0>; 2842def : InstAlias<"fmul", (MUL_FPrST0 ST1), 0>; 2843def : InstAlias<"fmulp", (MUL_FPrST0 ST1), 0>; 2844def : InstAlias<"fdiv{|r}p", (DIVR_FPrST0 ST1), 0>; 2845def : InstAlias<"fdiv{r|}p", (DIV_FPrST0 ST1), 0>; 2846def : InstAlias<"fxch", (XCH_F ST1), 0>; 2847def : InstAlias<"fcom", (COM_FST0r ST1), 0>; 2848def : InstAlias<"fcomp", (COMP_FST0r ST1), 0>; 2849def : InstAlias<"fcomi", (COM_FIr ST1), 0>; 2850def : InstAlias<"fcompi", (COM_FIPr ST1), 0>; 2851def : InstAlias<"fucom", (UCOM_Fr ST1), 0>; 2852def : InstAlias<"fucomp", (UCOM_FPr ST1), 0>; 2853def : InstAlias<"fucomi", (UCOM_FIr ST1), 0>; 2854def : InstAlias<"fucompi", (UCOM_FIPr ST1), 0>; 2855 2856// Handle fmul/fadd/fsub/fdiv instructions with explicitly written st(0) op. 2857// For example, "fadd %st(4), %st(0)" -> "fadd %st(4)". We also disambiguate 2858// instructions like "fadd %st(0), %st(0)" as "fadd %st(0)" for consistency with 2859// gas. 2860multiclass FpUnaryAlias<string Mnemonic, Instruction Inst, bit EmitAlias = 1> { 2861 def : InstAlias<!strconcat(Mnemonic, "\t{$op, %st(0)|st(0), $op}"), 2862 (Inst RST:$op), EmitAlias>; 2863 def : InstAlias<!strconcat(Mnemonic, "\t{%st(0), %st(0)|st(0), st(0)}"), 2864 (Inst ST0), EmitAlias>; 2865} 2866 2867defm : FpUnaryAlias<"fadd", ADD_FST0r>; 2868defm : FpUnaryAlias<"faddp", ADD_FPrST0, 0>; 2869defm : FpUnaryAlias<"fsub", SUB_FST0r>; 2870defm : FpUnaryAlias<"fsub{|r}p", SUBR_FPrST0>; 2871defm : FpUnaryAlias<"fsubr", SUBR_FST0r>; 2872defm : FpUnaryAlias<"fsub{r|}p", SUB_FPrST0>; 2873defm : FpUnaryAlias<"fmul", MUL_FST0r>; 2874defm : FpUnaryAlias<"fmulp", MUL_FPrST0>; 2875defm : FpUnaryAlias<"fdiv", DIV_FST0r>; 2876defm : FpUnaryAlias<"fdiv{|r}p", DIVR_FPrST0>; 2877defm : FpUnaryAlias<"fdivr", DIVR_FST0r>; 2878defm : FpUnaryAlias<"fdiv{r|}p", DIV_FPrST0>; 2879defm : FpUnaryAlias<"fcomi", COM_FIr, 0>; 2880defm : FpUnaryAlias<"fucomi", UCOM_FIr, 0>; 2881defm : FpUnaryAlias<"fcompi", COM_FIPr>; 2882defm : FpUnaryAlias<"fucompi", UCOM_FIPr>; 2883 2884 2885// Handle "f{mulp,addp} st(0), $op" the same as "f{mulp,addp} $op", since they 2886// commute. We also allow fdiv[r]p/fsubrp even though they don't commute, 2887// solely because gas supports it. 2888def : InstAlias<"faddp\t{%st(0), $op|$op, st(0)}", (ADD_FPrST0 RST:$op), 0>; 2889def : InstAlias<"fmulp\t{%st(0), $op|$op, st(0)}", (MUL_FPrST0 RST:$op)>; 2890def : InstAlias<"fsub{|r}p\t{%st(0), $op|$op, st(0)}", (SUBR_FPrST0 RST:$op)>; 2891def : InstAlias<"fsub{r|}p\t{%st(0), $op|$op, st(0)}", (SUB_FPrST0 RST:$op)>; 2892def : InstAlias<"fdiv{|r}p\t{%st(0), $op|$op, st(0)}", (DIVR_FPrST0 RST:$op)>; 2893def : InstAlias<"fdiv{r|}p\t{%st(0), $op|$op, st(0)}", (DIV_FPrST0 RST:$op)>; 2894 2895// We accept "fnstsw %eax" even though it only writes %ax. 2896def : InstAlias<"fnstsw\t{%eax|eax}", (FNSTSW16r)>; 2897def : InstAlias<"fnstsw\t{%al|al}" , (FNSTSW16r)>; 2898def : InstAlias<"fnstsw" , (FNSTSW16r)>; 2899 2900// lcall and ljmp aliases. This seems to be an odd mapping in 64-bit mode, but 2901// this is compatible with what GAS does. 2902def : InstAlias<"lcall\t$seg, $off", (FARCALL32i i32imm:$off, i16imm:$seg), 0>, Requires<[In32BitMode]>; 2903def : InstAlias<"ljmp\t$seg, $off", (FARJMP32i i32imm:$off, i16imm:$seg), 0>, Requires<[In32BitMode]>; 2904def : InstAlias<"lcall\t{*}$dst", (FARCALL32m opaque48mem:$dst), 0>, Requires<[Not16BitMode]>; 2905def : InstAlias<"ljmp\t{*}$dst", (FARJMP32m opaque48mem:$dst), 0>, Requires<[Not16BitMode]>; 2906def : InstAlias<"lcall\t$seg, $off", (FARCALL16i i16imm:$off, i16imm:$seg), 0>, Requires<[In16BitMode]>; 2907def : InstAlias<"ljmp\t$seg, $off", (FARJMP16i i16imm:$off, i16imm:$seg), 0>, Requires<[In16BitMode]>; 2908def : InstAlias<"lcall\t{*}$dst", (FARCALL16m opaque32mem:$dst), 0>, Requires<[In16BitMode]>; 2909def : InstAlias<"ljmp\t{*}$dst", (FARJMP16m opaque32mem:$dst), 0>, Requires<[In16BitMode]>; 2910 2911def : InstAlias<"call\t{*}$dst", (CALL64m i64mem:$dst), 0>, Requires<[In64BitMode]>; 2912def : InstAlias<"jmp\t{*}$dst", (JMP64m i64mem:$dst), 0>, Requires<[In64BitMode]>; 2913def : InstAlias<"call\t{*}$dst", (CALL32m i32mem:$dst), 0>, Requires<[In32BitMode]>; 2914def : InstAlias<"jmp\t{*}$dst", (JMP32m i32mem:$dst), 0>, Requires<[In32BitMode]>; 2915def : InstAlias<"call\t{*}$dst", (CALL16m i16mem:$dst), 0>, Requires<[In16BitMode]>; 2916def : InstAlias<"jmp\t{*}$dst", (JMP16m i16mem:$dst), 0>, Requires<[In16BitMode]>; 2917 2918 2919// "imul <imm>, B" is an alias for "imul <imm>, B, B". 2920def : InstAlias<"imul{w}\t{$imm, $r|$r, $imm}", (IMUL16rri GR16:$r, GR16:$r, i16imm:$imm), 0>; 2921def : InstAlias<"imul{w}\t{$imm, $r|$r, $imm}", (IMUL16rri8 GR16:$r, GR16:$r, i16i8imm:$imm), 0>; 2922def : InstAlias<"imul{l}\t{$imm, $r|$r, $imm}", (IMUL32rri GR32:$r, GR32:$r, i32imm:$imm), 0>; 2923def : InstAlias<"imul{l}\t{$imm, $r|$r, $imm}", (IMUL32rri8 GR32:$r, GR32:$r, i32i8imm:$imm), 0>; 2924def : InstAlias<"imul{q}\t{$imm, $r|$r, $imm}", (IMUL64rri32 GR64:$r, GR64:$r, i64i32imm:$imm), 0>; 2925def : InstAlias<"imul{q}\t{$imm, $r|$r, $imm}", (IMUL64rri8 GR64:$r, GR64:$r, i64i8imm:$imm), 0>; 2926 2927// ins aliases. Accept the mnemonic suffix being omitted because it's implicit 2928// in the destination. 2929def : InstAlias<"ins\t{%dx, $dst|$dst, dx}", (INSB dstidx8:$dst), 0>; 2930def : InstAlias<"ins\t{%dx, $dst|$dst, dx}", (INSW dstidx16:$dst), 0>; 2931def : InstAlias<"ins\t{%dx, $dst|$dst, dx}", (INSL dstidx32:$dst), 0>; 2932 2933// outs aliases. Accept the mnemonic suffix being omitted because it's implicit 2934// in the source. 2935def : InstAlias<"outs\t{$src, %dx|dx, $src}", (OUTSB srcidx8:$src), 0>; 2936def : InstAlias<"outs\t{$src, %dx|dx, $src}", (OUTSW srcidx16:$src), 0>; 2937def : InstAlias<"outs\t{$src, %dx|dx, $src}", (OUTSL srcidx32:$src), 0>; 2938 2939// inb %dx -> inb %al, %dx 2940def : InstAlias<"inb\t{%dx|dx}", (IN8rr), 0>; 2941def : InstAlias<"inw\t{%dx|dx}", (IN16rr), 0>; 2942def : InstAlias<"inl\t{%dx|dx}", (IN32rr), 0>; 2943def : InstAlias<"inb\t$port", (IN8ri u8imm:$port), 0>; 2944def : InstAlias<"inw\t$port", (IN16ri u8imm:$port), 0>; 2945def : InstAlias<"inl\t$port", (IN32ri u8imm:$port), 0>; 2946 2947 2948// jmp and call aliases for lcall and ljmp. jmp $42,$5 -> ljmp 2949def : InstAlias<"call\t$seg, $off", (FARCALL16i i16imm:$off, i16imm:$seg)>, Requires<[In16BitMode]>; 2950def : InstAlias<"jmp\t$seg, $off", (FARJMP16i i16imm:$off, i16imm:$seg)>, Requires<[In16BitMode]>; 2951def : InstAlias<"call\t$seg, $off", (FARCALL32i i32imm:$off, i16imm:$seg)>, Requires<[In32BitMode]>; 2952def : InstAlias<"jmp\t$seg, $off", (FARJMP32i i32imm:$off, i16imm:$seg)>, Requires<[In32BitMode]>; 2953def : InstAlias<"callw\t$seg, $off", (FARCALL16i i16imm:$off, i16imm:$seg)>, Requires<[Not64BitMode]>; 2954def : InstAlias<"jmpw\t$seg, $off", (FARJMP16i i16imm:$off, i16imm:$seg)>, Requires<[Not64BitMode]>; 2955def : InstAlias<"calll\t$seg, $off", (FARCALL32i i32imm:$off, i16imm:$seg)>, Requires<[Not64BitMode]>; 2956def : InstAlias<"jmpl\t$seg, $off", (FARJMP32i i32imm:$off, i16imm:$seg)>, Requires<[Not64BitMode]>; 2957 2958// Force mov without a suffix with a segment and mem to prefer the 'l' form of 2959// the move. All segment/mem forms are equivalent, this has the shortest 2960// encoding. 2961def : InstAlias<"mov\t{$mem, $seg|$seg, $mem}", (MOV32sm SEGMENT_REG:$seg, i32mem:$mem), 0>; 2962def : InstAlias<"mov\t{$seg, $mem|$mem, $seg}", (MOV32ms i32mem:$mem, SEGMENT_REG:$seg), 0>; 2963 2964// Match 'movq <largeimm>, <reg>' as an alias for movabsq. 2965def : InstAlias<"movq\t{$imm, $reg|$reg, $imm}", (MOV64ri GR64:$reg, i64imm:$imm), 0>; 2966 2967// Match 'movq GR64, MMX' as an alias for movd. 2968def : InstAlias<"movq\t{$src, $dst|$dst, $src}", 2969 (MMX_MOVD64to64rr VR64:$dst, GR64:$src), 0>; 2970def : InstAlias<"movq\t{$src, $dst|$dst, $src}", 2971 (MMX_MOVD64from64rr GR64:$dst, VR64:$src), 0>; 2972 2973// movsx aliases 2974def : InstAlias<"movsx\t{$src, $dst|$dst, $src}", (MOVSX16rr8 GR16:$dst, GR8:$src), 0>; 2975def : InstAlias<"movsx\t{$src, $dst|$dst, $src}", (MOVSX16rm8 GR16:$dst, i8mem:$src), 0>; 2976def : InstAlias<"movsx\t{$src, $dst|$dst, $src}", (MOVSX32rr8 GR32:$dst, GR8:$src), 0>; 2977def : InstAlias<"movsx\t{$src, $dst|$dst, $src}", (MOVSX32rr16 GR32:$dst, GR16:$src), 0>; 2978def : InstAlias<"movsx\t{$src, $dst|$dst, $src}", (MOVSX64rr8 GR64:$dst, GR8:$src), 0>; 2979def : InstAlias<"movsx\t{$src, $dst|$dst, $src}", (MOVSX64rr16 GR64:$dst, GR16:$src), 0>; 2980def : InstAlias<"movsx\t{$src, $dst|$dst, $src}", (MOVSX64rr32 GR64:$dst, GR32:$src), 0>; 2981 2982// movzx aliases 2983def : InstAlias<"movzx\t{$src, $dst|$dst, $src}", (MOVZX16rr8 GR16:$dst, GR8:$src), 0>; 2984def : InstAlias<"movzx\t{$src, $dst|$dst, $src}", (MOVZX16rm8 GR16:$dst, i8mem:$src), 0>; 2985def : InstAlias<"movzx\t{$src, $dst|$dst, $src}", (MOVZX32rr8 GR32:$dst, GR8:$src), 0>; 2986def : InstAlias<"movzx\t{$src, $dst|$dst, $src}", (MOVZX32rr16 GR32:$dst, GR16:$src), 0>; 2987def : InstAlias<"movzx\t{$src, $dst|$dst, $src}", (MOVZX64rr8 GR64:$dst, GR8:$src), 0>; 2988def : InstAlias<"movzx\t{$src, $dst|$dst, $src}", (MOVZX64rr16 GR64:$dst, GR16:$src), 0>; 2989// Note: No GR32->GR64 movzx form. 2990 2991// outb %dx -> outb %al, %dx 2992def : InstAlias<"outb\t{%dx|dx}", (OUT8rr), 0>; 2993def : InstAlias<"outw\t{%dx|dx}", (OUT16rr), 0>; 2994def : InstAlias<"outl\t{%dx|dx}", (OUT32rr), 0>; 2995def : InstAlias<"outb\t$port", (OUT8ir u8imm:$port), 0>; 2996def : InstAlias<"outw\t$port", (OUT16ir u8imm:$port), 0>; 2997def : InstAlias<"outl\t$port", (OUT32ir u8imm:$port), 0>; 2998 2999// 'sldt <mem>' can be encoded with either sldtw or sldtq with the same 3000// effect (both store to a 16-bit mem). Force to sldtw to avoid ambiguity 3001// errors, since its encoding is the most compact. 3002def : InstAlias<"sldt $mem", (SLDT16m i16mem:$mem), 0>; 3003 3004// shld/shrd op,op -> shld op, op, CL 3005def : InstAlias<"shld{w}\t{$r2, $r1|$r1, $r2}", (SHLD16rrCL GR16:$r1, GR16:$r2), 0>; 3006def : InstAlias<"shld{l}\t{$r2, $r1|$r1, $r2}", (SHLD32rrCL GR32:$r1, GR32:$r2), 0>; 3007def : InstAlias<"shld{q}\t{$r2, $r1|$r1, $r2}", (SHLD64rrCL GR64:$r1, GR64:$r2), 0>; 3008def : InstAlias<"shrd{w}\t{$r2, $r1|$r1, $r2}", (SHRD16rrCL GR16:$r1, GR16:$r2), 0>; 3009def : InstAlias<"shrd{l}\t{$r2, $r1|$r1, $r2}", (SHRD32rrCL GR32:$r1, GR32:$r2), 0>; 3010def : InstAlias<"shrd{q}\t{$r2, $r1|$r1, $r2}", (SHRD64rrCL GR64:$r1, GR64:$r2), 0>; 3011 3012def : InstAlias<"shld{w}\t{$reg, $mem|$mem, $reg}", (SHLD16mrCL i16mem:$mem, GR16:$reg), 0>; 3013def : InstAlias<"shld{l}\t{$reg, $mem|$mem, $reg}", (SHLD32mrCL i32mem:$mem, GR32:$reg), 0>; 3014def : InstAlias<"shld{q}\t{$reg, $mem|$mem, $reg}", (SHLD64mrCL i64mem:$mem, GR64:$reg), 0>; 3015def : InstAlias<"shrd{w}\t{$reg, $mem|$mem, $reg}", (SHRD16mrCL i16mem:$mem, GR16:$reg), 0>; 3016def : InstAlias<"shrd{l}\t{$reg, $mem|$mem, $reg}", (SHRD32mrCL i32mem:$mem, GR32:$reg), 0>; 3017def : InstAlias<"shrd{q}\t{$reg, $mem|$mem, $reg}", (SHRD64mrCL i64mem:$mem, GR64:$reg), 0>; 3018 3019/* FIXME: This is disabled because the asm matcher is currently incapable of 3020 * matching a fixed immediate like $1. 3021// "shl X, $1" is an alias for "shl X". 3022multiclass ShiftRotateByOneAlias<string Mnemonic, string Opc> { 3023 def : InstAlias<!strconcat(Mnemonic, "b $op, $$1"), 3024 (!cast<Instruction>(!strconcat(Opc, "8r1")) GR8:$op)>; 3025 def : InstAlias<!strconcat(Mnemonic, "w $op, $$1"), 3026 (!cast<Instruction>(!strconcat(Opc, "16r1")) GR16:$op)>; 3027 def : InstAlias<!strconcat(Mnemonic, "l $op, $$1"), 3028 (!cast<Instruction>(!strconcat(Opc, "32r1")) GR32:$op)>; 3029 def : InstAlias<!strconcat(Mnemonic, "q $op, $$1"), 3030 (!cast<Instruction>(!strconcat(Opc, "64r1")) GR64:$op)>; 3031 def : InstAlias<!strconcat(Mnemonic, "b $op, $$1"), 3032 (!cast<Instruction>(!strconcat(Opc, "8m1")) i8mem:$op)>; 3033 def : InstAlias<!strconcat(Mnemonic, "w $op, $$1"), 3034 (!cast<Instruction>(!strconcat(Opc, "16m1")) i16mem:$op)>; 3035 def : InstAlias<!strconcat(Mnemonic, "l $op, $$1"), 3036 (!cast<Instruction>(!strconcat(Opc, "32m1")) i32mem:$op)>; 3037 def : InstAlias<!strconcat(Mnemonic, "q $op, $$1"), 3038 (!cast<Instruction>(!strconcat(Opc, "64m1")) i64mem:$op)>; 3039} 3040 3041defm : ShiftRotateByOneAlias<"rcl", "RCL">; 3042defm : ShiftRotateByOneAlias<"rcr", "RCR">; 3043defm : ShiftRotateByOneAlias<"rol", "ROL">; 3044defm : ShiftRotateByOneAlias<"ror", "ROR">; 3045FIXME */ 3046 3047// test: We accept "testX <reg>, <mem>" and "testX <mem>, <reg>" as synonyms. 3048def : InstAlias<"test{b}\t{$val, $mem|$mem, $val}", 3049 (TEST8rm GR8 :$val, i8mem :$mem), 0>; 3050def : InstAlias<"test{w}\t{$val, $mem|$mem, $val}", 3051 (TEST16rm GR16:$val, i16mem:$mem), 0>; 3052def : InstAlias<"test{l}\t{$val, $mem|$mem, $val}", 3053 (TEST32rm GR32:$val, i32mem:$mem), 0>; 3054def : InstAlias<"test{q}\t{$val, $mem|$mem, $val}", 3055 (TEST64rm GR64:$val, i64mem:$mem), 0>; 3056 3057// xchg: We accept "xchgX <reg>, <mem>" and "xchgX <mem>, <reg>" as synonyms. 3058def : InstAlias<"xchg{b}\t{$mem, $val|$val, $mem}", 3059 (XCHG8rm GR8 :$val, i8mem :$mem), 0>; 3060def : InstAlias<"xchg{w}\t{$mem, $val|$val, $mem}", 3061 (XCHG16rm GR16:$val, i16mem:$mem), 0>; 3062def : InstAlias<"xchg{l}\t{$mem, $val|$val, $mem}", 3063 (XCHG32rm GR32:$val, i32mem:$mem), 0>; 3064def : InstAlias<"xchg{q}\t{$mem, $val|$val, $mem}", 3065 (XCHG64rm GR64:$val, i64mem:$mem), 0>; 3066 3067// xchg: We accept "xchgX <reg>, %eax" and "xchgX %eax, <reg>" as synonyms. 3068def : InstAlias<"xchg{w}\t{%ax, $src|$src, ax}", (XCHG16ar GR16:$src), 0>; 3069def : InstAlias<"xchg{l}\t{%eax, $src|$src, eax}", 3070 (XCHG32ar GR32:$src), 0>, Requires<[Not64BitMode]>; 3071def : InstAlias<"xchg{l}\t{%eax, $src|$src, eax}", 3072 (XCHG32ar64 GR32_NOAX:$src), 0>, Requires<[In64BitMode]>; 3073def : InstAlias<"xchg{q}\t{%rax, $src|$src, rax}", (XCHG64ar GR64:$src), 0>; 3074 3075// These aliases exist to get the parser to prioritize matching 8-bit 3076// immediate encodings over matching the implicit ax/eax/rax encodings. By 3077// explicitly mentioning the A register here, these entries will be ordered 3078// first due to the more explicit immediate type. 3079def : InstAlias<"adc{w}\t{$imm, %ax|ax, $imm}", (ADC16ri8 AX, i16i8imm:$imm), 0>; 3080def : InstAlias<"add{w}\t{$imm, %ax|ax, $imm}", (ADD16ri8 AX, i16i8imm:$imm), 0>; 3081def : InstAlias<"and{w}\t{$imm, %ax|ax, $imm}", (AND16ri8 AX, i16i8imm:$imm), 0>; 3082def : InstAlias<"cmp{w}\t{$imm, %ax|ax, $imm}", (CMP16ri8 AX, i16i8imm:$imm), 0>; 3083def : InstAlias<"or{w}\t{$imm, %ax|ax, $imm}", (OR16ri8 AX, i16i8imm:$imm), 0>; 3084def : InstAlias<"sbb{w}\t{$imm, %ax|ax, $imm}", (SBB16ri8 AX, i16i8imm:$imm), 0>; 3085def : InstAlias<"sub{w}\t{$imm, %ax|ax, $imm}", (SUB16ri8 AX, i16i8imm:$imm), 0>; 3086def : InstAlias<"xor{w}\t{$imm, %ax|ax, $imm}", (XOR16ri8 AX, i16i8imm:$imm), 0>; 3087 3088def : InstAlias<"adc{l}\t{$imm, %eax|eax, $imm}", (ADC32ri8 EAX, i32i8imm:$imm), 0>; 3089def : InstAlias<"add{l}\t{$imm, %eax|eax, $imm}", (ADD32ri8 EAX, i32i8imm:$imm), 0>; 3090def : InstAlias<"and{l}\t{$imm, %eax|eax, $imm}", (AND32ri8 EAX, i32i8imm:$imm), 0>; 3091def : InstAlias<"cmp{l}\t{$imm, %eax|eax, $imm}", (CMP32ri8 EAX, i32i8imm:$imm), 0>; 3092def : InstAlias<"or{l}\t{$imm, %eax|eax, $imm}", (OR32ri8 EAX, i32i8imm:$imm), 0>; 3093def : InstAlias<"sbb{l}\t{$imm, %eax|eax, $imm}", (SBB32ri8 EAX, i32i8imm:$imm), 0>; 3094def : InstAlias<"sub{l}\t{$imm, %eax|eax, $imm}", (SUB32ri8 EAX, i32i8imm:$imm), 0>; 3095def : InstAlias<"xor{l}\t{$imm, %eax|eax, $imm}", (XOR32ri8 EAX, i32i8imm:$imm), 0>; 3096 3097def : InstAlias<"adc{q}\t{$imm, %rax|rax, $imm}", (ADC64ri8 RAX, i64i8imm:$imm), 0>; 3098def : InstAlias<"add{q}\t{$imm, %rax|rax, $imm}", (ADD64ri8 RAX, i64i8imm:$imm), 0>; 3099def : InstAlias<"and{q}\t{$imm, %rax|rax, $imm}", (AND64ri8 RAX, i64i8imm:$imm), 0>; 3100def : InstAlias<"cmp{q}\t{$imm, %rax|rax, $imm}", (CMP64ri8 RAX, i64i8imm:$imm), 0>; 3101def : InstAlias<"or{q}\t{$imm, %rax|rax, $imm}", (OR64ri8 RAX, i64i8imm:$imm), 0>; 3102def : InstAlias<"sbb{q}\t{$imm, %rax|rax, $imm}", (SBB64ri8 RAX, i64i8imm:$imm), 0>; 3103def : InstAlias<"sub{q}\t{$imm, %rax|rax, $imm}", (SUB64ri8 RAX, i64i8imm:$imm), 0>; 3104def : InstAlias<"xor{q}\t{$imm, %rax|rax, $imm}", (XOR64ri8 RAX, i64i8imm:$imm), 0>; 3105