[llvm] cbf1d58 - [SelectionDAG] Add space-optimized forms of OPC_EmitCopyToReg (#73293)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 12 01:25:37 PST 2023
Author: Wang Pengcheng
Date: 2023-12-12T17:25:33+08:00
New Revision: cbf1d58820877b06a379005c155bf354cece57ff
URL: https://github.com/llvm/llvm-project/commit/cbf1d58820877b06a379005c155bf354cece57ff
DIFF: https://github.com/llvm/llvm-project/commit/cbf1d58820877b06a379005c155bf354cece57ff.diff
LOG: [SelectionDAG] Add space-optimized forms of OPC_EmitCopyToReg (#73293)
These new opcodes implicitly indicate the RecNo.
The old `OPC_EmitCopyToReg2` is renamed to `OPC_EmitCopyToRegTwoByte`.
Overall this reduces the llc binary size with all in-tree targets by
about 33K (most are from RISCV target).
Added:
Modified:
llvm/include/llvm/CodeGen/SelectionDAGISel.h
llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGISel.h b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
index 8a0e790bd170b..ca3d034086290 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGISel.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
@@ -210,7 +210,15 @@ class SelectionDAGISel : public MachineFunctionPass {
OPC_EmitMergeInputChains1_1,
OPC_EmitMergeInputChains1_2,
OPC_EmitCopyToReg,
+ OPC_EmitCopyToReg0,
+ OPC_EmitCopyToReg1,
OPC_EmitCopyToReg2,
+ OPC_EmitCopyToReg3,
+ OPC_EmitCopyToReg4,
+ OPC_EmitCopyToReg5,
+ OPC_EmitCopyToReg6,
+ OPC_EmitCopyToReg7,
+ OPC_EmitCopyToRegTwoByte,
OPC_EmitNodeXForm,
OPC_EmitNode,
// Space-optimized forms that implicitly encode number of result VTs.
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 09d5a74688e43..9c423dba7d2c2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -3649,11 +3649,22 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
}
case OPC_EmitCopyToReg:
- case OPC_EmitCopyToReg2: {
- unsigned RecNo = MatcherTable[MatcherIndex++];
+ case OPC_EmitCopyToReg0:
+ case OPC_EmitCopyToReg1:
+ case OPC_EmitCopyToReg2:
+ case OPC_EmitCopyToReg3:
+ case OPC_EmitCopyToReg4:
+ case OPC_EmitCopyToReg5:
+ case OPC_EmitCopyToReg6:
+ case OPC_EmitCopyToReg7:
+ case OPC_EmitCopyToRegTwoByte: {
+ unsigned RecNo =
+ Opcode >= OPC_EmitCopyToReg0 && Opcode <= OPC_EmitCopyToReg7
+ ? Opcode - OPC_EmitCopyToReg0
+ : MatcherTable[MatcherIndex++];
assert(RecNo < RecordedNodes.size() && "Invalid EmitCopyToReg");
unsigned DestPhysReg = MatcherTable[MatcherIndex++];
- if (Opcode == OPC_EmitCopyToReg2)
+ if (Opcode == OPC_EmitCopyToRegTwoByte)
DestPhysReg |= MatcherTable[MatcherIndex++] << 8;
if (!InputChain.getNode())
diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
index c9ee071fd8d35..22bf5926966da 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -767,14 +767,20 @@ EmitMatcher(const Matcher *N, const unsigned Indent, unsigned CurrentIdx,
const auto *C2RMatcher = cast<EmitCopyToRegMatcher>(N);
int Bytes = 3;
const CodeGenRegister *Reg = C2RMatcher->getDestPhysReg();
+ unsigned Slot = C2RMatcher->getSrcSlot();
if (Reg->EnumValue > 255) {
assert(isUInt<16>(Reg->EnumValue) && "not handled");
- OS << "OPC_EmitCopyToReg2, " << C2RMatcher->getSrcSlot() << ", "
+ OS << "OPC_EmitCopyToRegTwoByte, " << Slot << ", "
<< "TARGET_VAL(" << getQualifiedName(Reg->TheDef) << "),\n";
++Bytes;
} else {
- OS << "OPC_EmitCopyToReg, " << C2RMatcher->getSrcSlot() << ", "
- << getQualifiedName(Reg->TheDef) << ",\n";
+ if (Slot < 8) {
+ OS << "OPC_EmitCopyToReg" << Slot << ", "
+ << getQualifiedName(Reg->TheDef) << ",\n";
+ --Bytes;
+ } else
+ OS << "OPC_EmitCopyToReg, " << Slot << ", "
+ << getQualifiedName(Reg->TheDef) << ",\n";
}
return Bytes;
More information about the llvm-commits
mailing list