[llvm] 942536a - [X86] Prefer VEX encoding in X86 assembler.
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 18 01:57:26 PDT 2021
Author: Luo, Yuanke
Date: 2021-10-18T16:54:11+08:00
New Revision: 942536ac084c2e12271140831be0c97da39cde2e
URL: https://github.com/llvm/llvm-project/commit/942536ac084c2e12271140831be0c97da39cde2e
DIFF: https://github.com/llvm/llvm-project/commit/942536ac084c2e12271140831be0c97da39cde2e.diff
LOG: [X86] Prefer VEX encoding in X86 assembler.
This patch is to order the AVX instructions ahead of AVX512 instructions
in the matching table so that the AVX instructions can be matched first.
Thanks Craig and Shengchen for the idea.
Differential Revision: https://reviews.llvm.org/D111538
Added:
Modified:
llvm/include/llvm/Target/Target.td
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
llvm/lib/Target/X86/X86InstrFormats.td
llvm/utils/TableGen/AsmMatcherEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Target/Target.td b/llvm/include/llvm/Target/Target.td
index d70df3936e9f4..36b9531a17929 100644
--- a/llvm/include/llvm/Target/Target.td
+++ b/llvm/include/llvm/Target/Target.td
@@ -653,6 +653,11 @@ class Instruction : InstructionEncoding {
/// instruction selection predicates. FastISel cannot handle such cases, but
/// SelectionDAG can.
bit FastISelShouldIgnore = false;
+
+ /// HasPositionOrder: Indicate tablegen to sort the instructions by record
+ /// ID, so that instruction that is defined earlier can be sorted earlier
+ /// in the assembly matching table.
+ bit HasPositionOrder = false;
}
/// Defines an additional encoding that disassembles to the given instruction
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 2ebe5f04d4dfa..511d263abbaab 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -4270,24 +4270,6 @@ unsigned X86AsmParser::checkTargetMatchPredicate(MCInst &Inst) {
ForcedVEXEncoding != VEXEncoding_VEX3))
return Match_Unsupported;
- // These instructions match ambiguously with their VEX encoded counterparts
- // and appear first in the matching table. Reject them unless we're forcing
- // EVEX encoding.
- // FIXME: We really need a way to break the ambiguity.
- switch (Opc) {
- case X86::VCVTSD2SIZrm_Int:
- case X86::VCVTSD2SI64Zrm_Int:
- case X86::VCVTSS2SIZrm_Int:
- case X86::VCVTSS2SI64Zrm_Int:
- case X86::VCVTTSD2SIZrm: case X86::VCVTTSD2SIZrm_Int:
- case X86::VCVTTSD2SI64Zrm: case X86::VCVTTSD2SI64Zrm_Int:
- case X86::VCVTTSS2SIZrm: case X86::VCVTTSS2SIZrm_Int:
- case X86::VCVTTSS2SI64Zrm: case X86::VCVTTSS2SI64Zrm_Int:
- if (ForcedVEXEncoding != VEXEncoding_EVEX)
- return Match_Unsupported;
- break;
- }
-
return Match_Success;
}
diff --git a/llvm/lib/Target/X86/X86InstrFormats.td b/llvm/lib/Target/X86/X86InstrFormats.td
index 4f0e0afcef8a3..0e7033fc233a0 100644
--- a/llvm/lib/Target/X86/X86InstrFormats.td
+++ b/llvm/lib/Target/X86/X86InstrFormats.td
@@ -296,6 +296,8 @@ class X86Inst<bits<8> opcod, Format f, ImmType i, dag outs, dag ins,
// If this is a pseudo instruction, mark it isCodeGenOnly.
let isCodeGenOnly = !eq(!cast<string>(f), "Pseudo");
+ let HasPositionOrder = 1;
+
//
// Attributes specific to X86 instructions...
//
diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index 00bdd127e3c28..d7b0c6db3e1f0 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -636,6 +636,15 @@ struct MatchableInfo {
if (RequiredFeatures.size() != RHS.RequiredFeatures.size())
return RequiredFeatures.size() > RHS.RequiredFeatures.size();
+ // For X86 AVX/AVX512 instructions, we prefer vex encoding because the
+ // vex encoding size is smaller. Since X86InstrSSE.td is included ahead
+ // of X86InstrAVX512.td, the AVX instruction ID is less than AVX512 ID.
+ // We use the ID to sort AVX instruction before AVX512 instruction in
+ // matching table.
+ if (TheDef->isSubClassOf("Instruction") &&
+ TheDef->getValueAsBit("HasPositionOrder"))
+ return TheDef->getID() < RHS.TheDef->getID();
+
return false;
}
More information about the llvm-commits
mailing list