mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
[X86] Revisit the fix I made years ago to make 'xchgl %eax, %eax' not encode using the 0x90 encoding in 64-bit mode.
Prior to this we had a separate instruction and register class that excluded eax to prevent matching the instruction that would encode with 0x90. This patch changes this to just use an InstAlias to force xchgl %eax, %eax to use XCHG32rr instruction in 64-bit mode. This gets rid of the separate instruction and register class. llvm-svn: 322532
This commit is contained in:
parent
c065faaccf
commit
73a154cef6
@ -1958,13 +1958,7 @@ def XCHG16ar : I<0x90, AddRegFrm, (outs), (ins GR16:$src),
|
||||
let Uses = [EAX], Defs = [EAX] in
|
||||
def XCHG32ar : I<0x90, AddRegFrm, (outs), (ins GR32:$src),
|
||||
"xchg{l}\t{$src, %eax|eax, $src}", [], IIC_XCHG_REG>,
|
||||
OpSize32, Requires<[Not64BitMode]>;
|
||||
let Uses = [EAX], Defs = [EAX] in
|
||||
// Uses GR32_NOAX in 64-bit mode to prevent encoding using the 0x90 NOP encoding.
|
||||
// xchg %eax, %eax needs to clear upper 32-bits of RAX so is not a NOP.
|
||||
def XCHG32ar64 : I<0x90, AddRegFrm, (outs), (ins GR32_NOAX:$src),
|
||||
"xchg{l}\t{$src, %eax|eax, $src}", [], IIC_XCHG_REG>,
|
||||
OpSize32, Requires<[In64BitMode]>;
|
||||
OpSize32;
|
||||
let Uses = [RAX], Defs = [RAX] in
|
||||
def XCHG64ar : RI<0x90, AddRegFrm, (outs), (ins GR64:$src),
|
||||
"xchg{q}\t{$src, %rax|rax, $src}", [], IIC_XCHG_REG>;
|
||||
@ -3304,12 +3298,15 @@ def : InstAlias<"xchg{q}\t{$mem, $val|$val, $mem}",
|
||||
|
||||
// xchg: We accept "xchgX <reg>, %eax" and "xchgX %eax, <reg>" as synonyms.
|
||||
def : InstAlias<"xchg{w}\t{%ax, $src|$src, ax}", (XCHG16ar GR16:$src), 0>;
|
||||
def : InstAlias<"xchg{l}\t{%eax, $src|$src, eax}",
|
||||
(XCHG32ar GR32:$src), 0>, Requires<[Not64BitMode]>;
|
||||
def : InstAlias<"xchg{l}\t{%eax, $src|$src, eax}",
|
||||
(XCHG32ar64 GR32_NOAX:$src), 0>, Requires<[In64BitMode]>;
|
||||
def : InstAlias<"xchg{l}\t{%eax, $src|$src, eax}", (XCHG32ar GR32:$src), 0>;
|
||||
def : InstAlias<"xchg{q}\t{%rax, $src|$src, rax}", (XCHG64ar GR64:$src), 0>;
|
||||
|
||||
// In 64-bit mode, xchg %eax, %eax can't be encoded with the 0x90 opcode we
|
||||
// would get by default because it's defined as NOP. But xchg %eax, %eax implies
|
||||
// implicit zeroing of the upper 32 bits. So alias to the longer encoding.
|
||||
def : InstAlias<"xchg{l}\t{%eax, %eax|eax, eax}",
|
||||
(XCHG32rr EAX, EAX), 0>, Requires<[In64BitMode]>;
|
||||
|
||||
// xchg %rax, %rax is a nop in x86-64 and can be encoded as such. Without this
|
||||
// we emit an unneeded REX.w prefix.
|
||||
def : InstAlias<"xchg{q}\t{%rax, %rax|rax, rax}", (NOOP), 0>;
|
||||
|
@ -400,11 +400,6 @@ def GR32_NOREX : RegisterClass<"X86", [i32], 32,
|
||||
def GR64_NOREX : RegisterClass<"X86", [i64], 64,
|
||||
(add RAX, RCX, RDX, RSI, RDI, RBX, RBP, RSP, RIP)>;
|
||||
|
||||
// GR32_NOAX - GR32 registers except EAX. Used by AddRegFrm of XCHG32 in 64-bit
|
||||
// mode to prevent encoding using the 0x90 NOP encoding. xchg %eax, %eax needs
|
||||
// to clear upper 32-bits of RAX so is not a NOP.
|
||||
def GR32_NOAX : RegisterClass<"X86", [i32], 32, (sub GR32, EAX)>;
|
||||
|
||||
// GR32_NOSP - GR32 registers except ESP.
|
||||
def GR32_NOSP : RegisterClass<"X86", [i32], 32, (sub GR32, ESP)>;
|
||||
|
||||
|
@ -927,7 +927,6 @@ OperandType RecognizableInstr::typeFromString(const std::string &s,
|
||||
TYPE("VK32WM", TYPE_VK)
|
||||
TYPE("VK64", TYPE_VK)
|
||||
TYPE("VK64WM", TYPE_VK)
|
||||
TYPE("GR32_NOAX", TYPE_Rv)
|
||||
TYPE("vx64mem", TYPE_MVSIBX)
|
||||
TYPE("vx128mem", TYPE_MVSIBX)
|
||||
TYPE("vx256mem", TYPE_MVSIBX)
|
||||
@ -1195,7 +1194,6 @@ RecognizableInstr::opcodeModifierEncodingFromString(const std::string &s,
|
||||
ENCODING("GR64", ENCODING_RO)
|
||||
ENCODING("GR16", ENCODING_Rv)
|
||||
ENCODING("GR8", ENCODING_RB)
|
||||
ENCODING("GR32_NOAX", ENCODING_Rv)
|
||||
errs() << "Unhandled opcode modifier encoding " << s << "\n";
|
||||
llvm_unreachable("Unhandled opcode modifier encoding");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user