Skip to content

Commit 6708832

Browse files
authored
[X86][APX] Distinguish REX2 PUSH/POP from PPX (#163526)
1 parent 99f02ea commit 6708832

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

llvm/include/llvm/Support/X86DisassemblerDecoderCommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ enum attributeBits {
121121
"The Dynamic Duo! Prefer over all else because this changes " \
122122
"most operands' meaning") \
123123
ENUM_ENTRY(IC_64BIT_REX2, 2, "requires a REX2 prefix") \
124+
ENUM_ENTRY(IC_64BIT_REX2_REXW, 3, "requires a REX2 and the W prefix") \
124125
ENUM_ENTRY(IC_VEX, 1, "requires a VEX prefix") \
125126
ENUM_ENTRY(IC_VEX_XS, 2, "requires VEX and the XS prefix") \
126127
ENUM_ENTRY(IC_VEX_XD, 2, "requires VEX and the XD prefix") \

llvm/test/MC/Disassembler/X86/apx/pushp-popp.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# INTEL: pushp r16
1818
0xd5,0x18,0x50
1919

20+
# ATT: pushq %r16
21+
# INTEL: push r16
22+
0xd5,0x10,0x50
23+
2024
# ATT: popp %rax
2125
# INTEL: popp rax
2226
0xd5,0x08,0x58
@@ -32,3 +36,7 @@
3236
# ATT: popp %r16
3337
# INTEL: popp r16
3438
0xd5,0x18,0x58
39+
40+
# ATT: popq %r16
41+
# INTEL: pop r16
42+
0xd5,0x10,0x58

llvm/test/MC/X86/apx/pushp-popp-att.s

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# RUN: llvm-mc -triple x86_64 -show-encoding %s | FileCheck %s
22
# RUN: not llvm-mc -triple i386 -show-encoding %s 2>&1 | FileCheck %s --check-prefix=ERROR
33

4-
# ERROR-COUNT-8: error:
4+
# ERROR-COUNT-10: error:
55
# ERROR-NOT: error:
66

77
# CHECK: pushp %rax
@@ -16,6 +16,9 @@
1616
# CHECK: pushp %r16
1717
# CHECK: encoding: [0xd5,0x18,0x50]
1818
pushp %r16
19+
# CHECK: pushq %r16
20+
# CHECK: encoding: [0xd5,0x10,0x50]
21+
pushq %r16
1922

2023
# CHECK: popp %rax
2124
# CHECK: encoding: [0xd5,0x08,0x58]
@@ -29,3 +32,6 @@
2932
# CHECK: popp %r16
3033
# CHECK: encoding: [0xd5,0x18,0x58]
3134
popp %r16
35+
# CHECK: popq %r16
36+
# CHECK: encoding: [0xd5,0x10,0x58]
37+
popq %r16

llvm/utils/TableGen/X86DisassemblerTables.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static inline bool inheritsFrom(InstructionContext child,
9999
(noPrefix && inheritsFrom(child, IC_XS, noPrefix)));
100100
case IC_64BIT:
101101
return (inheritsFrom(child, IC_64BIT_REXW) ||
102+
inheritsFrom(child, IC_64BIT_REX2) ||
102103
(noPrefix && inheritsFrom(child, IC_64BIT_OPSIZE, noPrefix)) ||
103104
(!AdSize64 && inheritsFrom(child, IC_64BIT_ADSIZE)) ||
104105
(noPrefix && inheritsFrom(child, IC_64BIT_XD, noPrefix)) ||
@@ -151,8 +152,10 @@ static inline bool inheritsFrom(InstructionContext child,
151152
case IC_64BIT_REXW_XS:
152153
case IC_64BIT_REXW_OPSIZE:
153154
case IC_64BIT_REXW_ADSIZE:
154-
case IC_64BIT_REX2:
155+
case IC_64BIT_REX2_REXW:
155156
return false;
157+
case IC_64BIT_REX2:
158+
return inheritsFrom(child, IC_64BIT_REX2_REXW);
156159
case IC_VEX:
157160
return (VEX_LIG && WIG && inheritsFrom(child, IC_VEX_L_W)) ||
158161
(WIG && inheritsFrom(child, IC_VEX_W)) ||
@@ -980,9 +983,11 @@ void DisassemblerTables::emitContextTable(raw_ostream &o, unsigned &i) const {
980983
if ((index & ATTR_EVEXB) && (index & ATTR_EVEXU))
981984
o << "_U";
982985
}
983-
} else if ((index & ATTR_64BIT) && (index & ATTR_REX2))
986+
} else if ((index & ATTR_64BIT) && (index & ATTR_REX2)) {
984987
o << "IC_64BIT_REX2";
985-
else if ((index & ATTR_64BIT) && (index & ATTR_REXW) && (index & ATTR_XS))
988+
if (index & ATTR_REXW)
989+
o << "_REXW";
990+
} else if ((index & ATTR_64BIT) && (index & ATTR_REXW) && (index & ATTR_XS))
986991
o << "IC_64BIT_REXW_XS";
987992
else if ((index & ATTR_64BIT) && (index & ATTR_REXW) && (index & ATTR_XD))
988993
o << "IC_64BIT_REXW_XD";

llvm/utils/TableGen/X86RecognizableInstr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ InstructionContext RecognizableInstr::insnContext() const {
365365
insnContext = IC_64BIT_XD;
366366
else if (OpPrefix == X86Local::XS)
367367
insnContext = IC_64BIT_XS;
368+
else if (HasREX_W && ExplicitREX2Prefix)
369+
insnContext = IC_64BIT_REX2_REXW;
368370
else if (ExplicitREX2Prefix)
369371
insnContext = IC_64BIT_REX2;
370372
else if (HasREX_W)

0 commit comments

Comments
 (0)