[llvm] [SelectionDAG] Add space-optimized forms of OPC_EmitCopyToReg (PR #73293)
Wang Pengcheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 23 23:55:55 PST 2023
https://github.com/wangpc-pp updated https://github.com/llvm/llvm-project/pull/73293
>From aa436c1c7d06e5f17ad33a1f30bcd23570c98617 Mon Sep 17 00:00:00 2001
From: wangpc <wangpengcheng.pp at bytedance.com>
Date: Fri, 24 Nov 2023 15:35:46 +0800
Subject: [PATCH 1/2] [SelectionDAG] Add space-optimized forms of
OPC_EmitCopyToReg
These new opcodes implicitly indicate the RecNo.
The old `OPC_EmitCopyToReg2` is renamed to `OPC_EmitCopyToRegHalf`.
Overall this reduces the llc binary size with all in-tree targets by
about 33K (most are from RISCV target).
---
llvm/include/llvm/CodeGen/SelectionDAGISel.h | 8 ++++++++
.../CodeGen/SelectionDAG/SelectionDAGISel.cpp | 17 ++++++++++++++---
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp | 14 ++++++++++----
3 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGISel.h b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
index e6513eb6abc8749..a0c590fd5269b5d 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGISel.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
@@ -192,7 +192,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_EmitCopyToRegHalf,
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 7d9bebdca127224..126f90a632ff180 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -3584,11 +3584,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_EmitCopyToRegHalf: {
+ 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_EmitCopyToRegHalf)
DestPhysReg |= MatcherTable[MatcherIndex++] << 8;
if (!InputChain.getNode())
diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
index 4a11991036efc11..e62119c1f6c3e0f 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -732,14 +732,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() << ", "
- << "TARGET_VAL(" << getQualifiedName(Reg->TheDef) << "),\n";
+ OS << "OPC_EmitCopyToRegHalf, " << 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;
>From b1e20678d2a57be8779be459e35fb4d256736bc9 Mon Sep 17 00:00:00 2001
From: wangpc <wangpengcheng.pp at bytedance.com>
Date: Fri, 24 Nov 2023 15:55:31 +0800
Subject: [PATCH 2/2] Half -> TwoByte
---
llvm/include/llvm/CodeGen/SelectionDAGISel.h | 2 +-
llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 4 ++--
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGISel.h b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
index a0c590fd5269b5d..87f5cc01a05e6b6 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGISel.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
@@ -200,7 +200,7 @@ class SelectionDAGISel : public MachineFunctionPass {
OPC_EmitCopyToReg5,
OPC_EmitCopyToReg6,
OPC_EmitCopyToReg7,
- OPC_EmitCopyToRegHalf,
+ 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 126f90a632ff180..d273ebb8025c038 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -3592,14 +3592,14 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
case OPC_EmitCopyToReg5:
case OPC_EmitCopyToReg6:
case OPC_EmitCopyToReg7:
- case OPC_EmitCopyToRegHalf: {
+ 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_EmitCopyToRegHalf)
+ 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 e62119c1f6c3e0f..8c7edd7660c9b64 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -735,7 +735,7 @@ EmitMatcher(const Matcher *N, const unsigned Indent, unsigned CurrentIdx,
unsigned Slot = C2RMatcher->getSrcSlot();
if (Reg->EnumValue > 255) {
assert(isUInt<16>(Reg->EnumValue) && "not handled");
- OS << "OPC_EmitCopyToRegHalf, " << Slot << ", " << "TARGET_VAL("
+ OS << "OPC_EmitCopyToRegTwoByte, " << Slot << ", " << "TARGET_VAL("
<< getQualifiedName(Reg->TheDef) << "),\n";
++Bytes;
} else {
More information about the llvm-commits
mailing list