[llvm] [TableGen] Add OPC_EmitIntegerByHwMode0 and OPC_CheckChildXTypeByHwMode0. NFC (PR #182686)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 21 09:28:39 PST 2026
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/182686
Add versions of these opcodes that implicitly call getValueTypeForHwMode with index 0.
This reduces llc size by ~100K.
>From b572cb5181227d21d92c5a50e3958292ba141713 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Fri, 20 Feb 2026 22:01:49 -0800
Subject: [PATCH] [TableGen] Add OPC_EmitIntegerByHwMode0 and
OPC_CheckChildXTypeByHwMode0. NFC
Add versions of these opcodes that implicitly call getValueTypeForHwMode
with index 0.
This reduces llc size by ~100K.
---
llvm/include/llvm/CodeGen/SelectionDAGISel.h | 10 ++++
.../CodeGen/SelectionDAG/SelectionDAGISel.cpp | 42 +++++++++++--
llvm/test/TableGen/RegClassByHwMode.td | 4 +-
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp | 59 ++++++++++++-------
4 files changed, 88 insertions(+), 27 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGISel.h b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
index 826e0472310d5..58f141bbc4862 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGISel.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
@@ -249,6 +249,15 @@ class SelectionDAGISel {
OPC_CheckChild6TypeByHwMode,
OPC_CheckChild7TypeByHwMode,
+ OPC_CheckChild0TypeByHwMode0,
+ OPC_CheckChild1TypeByHwMode0,
+ OPC_CheckChild2TypeByHwMode0,
+ OPC_CheckChild3TypeByHwMode0,
+ OPC_CheckChild4TypeByHwMode0,
+ OPC_CheckChild5TypeByHwMode0,
+ OPC_CheckChild6TypeByHwMode0,
+ OPC_CheckChild7TypeByHwMode0,
+
OPC_CheckInteger,
OPC_CheckChild0Integer,
OPC_CheckChild1Integer,
@@ -280,6 +289,7 @@ class SelectionDAGISel {
OPC_EmitIntegerI32,
OPC_EmitIntegerI64,
OPC_EmitIntegerByHwMode,
+ OPC_EmitIntegerByHwMode0,
OPC_EmitRegister,
OPC_EmitRegisterI32,
OPC_EmitRegisterI64,
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index a0cdc5148d0b8..02c2444fc9d9e 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -3233,7 +3233,15 @@ static size_t IsPredicateKnownToFail(
case SelectionDAGISel::OPC_CheckChild4TypeByHwMode:
case SelectionDAGISel::OPC_CheckChild5TypeByHwMode:
case SelectionDAGISel::OPC_CheckChild6TypeByHwMode:
- case SelectionDAGISel::OPC_CheckChild7TypeByHwMode: {
+ case SelectionDAGISel::OPC_CheckChild7TypeByHwMode:
+ case SelectionDAGISel::OPC_CheckChild0TypeByHwMode0:
+ case SelectionDAGISel::OPC_CheckChild1TypeByHwMode0:
+ case SelectionDAGISel::OPC_CheckChild2TypeByHwMode0:
+ case SelectionDAGISel::OPC_CheckChild3TypeByHwMode0:
+ case SelectionDAGISel::OPC_CheckChild4TypeByHwMode0:
+ case SelectionDAGISel::OPC_CheckChild5TypeByHwMode0:
+ case SelectionDAGISel::OPC_CheckChild6TypeByHwMode0:
+ case SelectionDAGISel::OPC_CheckChild7TypeByHwMode0: {
MVT VT;
unsigned ChildNo;
if (Opcode >= SelectionDAGISel::OPC_CheckChild0TypeI32 &&
@@ -3248,6 +3256,10 @@ static size_t IsPredicateKnownToFail(
Opcode <= SelectionDAGISel::OPC_CheckChild7TypeByHwMode) {
VT = getHwModeVT(Table, Index, SDISel);
ChildNo = Opcode - SelectionDAGISel::OPC_CheckChild0TypeByHwMode;
+ } else if (Opcode >= SelectionDAGISel::OPC_CheckChild0TypeByHwMode0 &&
+ Opcode <= SelectionDAGISel::OPC_CheckChild7TypeByHwMode0) {
+ VT = SDISel.getValueTypeForHwMode(0);
+ ChildNo = Opcode - SelectionDAGISel::OPC_CheckChild0TypeByHwMode0;
} else {
VT = getSimpleVT(Table, Index);
ChildNo = Opcode - SelectionDAGISel::OPC_CheckChild0Type;
@@ -3909,9 +3921,25 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
case OPC_CheckChild4TypeByHwMode:
case OPC_CheckChild5TypeByHwMode:
case OPC_CheckChild6TypeByHwMode:
- case OPC_CheckChild7TypeByHwMode: {
- MVT VT = getHwModeVT(MatcherTable, MatcherIndex, *this);
- unsigned ChildNo = Opcode - OPC_CheckChild0TypeByHwMode;
+ case OPC_CheckChild7TypeByHwMode:
+ case OPC_CheckChild0TypeByHwMode0:
+ case OPC_CheckChild1TypeByHwMode0:
+ case OPC_CheckChild2TypeByHwMode0:
+ case OPC_CheckChild3TypeByHwMode0:
+ case OPC_CheckChild4TypeByHwMode0:
+ case OPC_CheckChild5TypeByHwMode0:
+ case OPC_CheckChild6TypeByHwMode0:
+ case OPC_CheckChild7TypeByHwMode0: {
+ MVT VT;
+ unsigned ChildNo;
+ if (Opcode >= OPC_CheckChild0TypeByHwMode0 &&
+ Opcode <= OPC_CheckChild7TypeByHwMode0) {
+ VT = getValueTypeForHwMode(0);
+ ChildNo = Opcode - OPC_CheckChild0TypeByHwMode0;
+ } else {
+ VT = getHwModeVT(MatcherTable, MatcherIndex, *this);
+ ChildNo = Opcode - OPC_CheckChild0TypeByHwMode;
+ }
if (!::CheckChildType(VT.SimpleTy, N, TLI, CurDAG->getDataLayout(),
ChildNo))
break;
@@ -3986,7 +4014,8 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
case OPC_EmitIntegerI16:
case OPC_EmitIntegerI32:
case OPC_EmitIntegerI64:
- case OPC_EmitIntegerByHwMode: {
+ case OPC_EmitIntegerByHwMode:
+ case OPC_EmitIntegerByHwMode0: {
MVT VT;
switch (Opcode) {
case OPC_EmitIntegerI8:
@@ -4004,6 +4033,9 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
case OPC_EmitIntegerByHwMode:
VT = getHwModeVT(MatcherTable, MatcherIndex, *this);
break;
+ case OPC_EmitIntegerByHwMode0:
+ VT = getValueTypeForHwMode(0);
+ break;
default:
VT = getSimpleVT(MatcherTable, MatcherIndex);
break;
diff --git a/llvm/test/TableGen/RegClassByHwMode.td b/llvm/test/TableGen/RegClassByHwMode.td
index 0a06b8991b590..4f0a71e8bbf71 100644
--- a/llvm/test/TableGen/RegClassByHwMode.td
+++ b/llvm/test/TableGen/RegClassByHwMode.td
@@ -207,7 +207,7 @@ include "Common/RegClassByHwModeCommon.td"
// ISEL-SDAG-NEXT: OPC_RecordChild1, // #1 = $val
// ISEL-SDAG-NEXT: OPC_CheckChild1TypeByHwMode, /*{(*:i64),(m1:i64),(m2:i64)}*/1,
// ISEL-SDAG-NEXT: OPC_RecordChild2, // #2 = $src
-// ISEL-SDAG-NEXT: OPC_CheckChild2TypeByHwMode, /*{(*:i32),(m3:i64)}*/0,
+// ISEL-SDAG-NEXT: OPC_CheckChild2TypeByHwMode0/*{(*:i32),(m3:i64)}*/,
// ISEL-SDAG-NEXT: OPC_CheckPredicate0, // Predicate_unindexedstore
// ISEL-SDAG-NEXT: OPC_CheckPredicate1, // Predicate_store
// ISEL-SDAG-NEXT: OPC_EmitMergeInputChains1_0,
@@ -218,7 +218,7 @@ include "Common/RegClassByHwModeCommon.td"
// ISEL-SDAG-NEXT: OPC_RecordMemRef,
// ISEL-SDAG-NEXT: OPC_RecordNode, // #0 = 'ld' chained node
// ISEL-SDAG-NEXT: OPC_RecordChild1, // #1 = $src
-// ISEL-SDAG-NEXT: OPC_CheckChild1TypeByHwMode, /*{(*:i32),(m3:i64)}*/0,
+// ISEL-SDAG-NEXT: OPC_CheckChild1TypeByHwMode0/*{(*:i32),(m3:i64)}*/,
// ISEL-SDAG-NEXT: OPC_CheckPredicate2, // Predicate_unindexedload
// ISEL-SDAG-NEXT: OPC_CheckPredicate3, // Predicate_load
// ISEL-SDAG-NEXT: OPC_CheckTypeI64,
diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
index c08d0668380a7..3d69c96ebd900 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -289,7 +289,7 @@ class MatcherTableEmitter {
return Idx - 1;
}
- unsigned emitValueTypeByHwMode(const ValueTypeByHwMode &VTBH,
+ unsigned emitValueTypeByHwMode(const ValueTypeByHwMode &VTBH, unsigned Index,
raw_ostream &OS);
};
} // end anonymous namespace.
@@ -515,10 +515,10 @@ static unsigned emitMVT(MVT VT, raw_ostream &OS) {
unsigned
MatcherTableEmitter::emitValueTypeByHwMode(const ValueTypeByHwMode &VTBH,
- raw_ostream &OS) {
+ unsigned Index, raw_ostream &OS) {
if (!OmitComments)
OS << "/*" << VTBH << "*/";
- OS << getValueTypeID(VTBH) << ',';
+ OS << Index << ',';
return 1;
}
/// EmitMatcher - Emit bytes for the specified matcher and return
@@ -778,23 +778,24 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
return NumBytes + 2;
}
- unsigned Idx = getValueTypeID(VTBH);
unsigned OpSize;
if (cast<CheckTypeMatcher>(N)->getResNo() == 0) {
- if (Idx == 0) {
- OS << "OPC_CheckTypeByHwMode0,";
+ unsigned Index = getValueTypeID(VTBH);
+ if (Index == 0) {
+ OS << "OPC_CheckTypeByHwMode0";
+ if (!OmitComments)
+ OS << "/*" << VTBH << "*/";
+ OS << ',';
OpSize = 1;
} else {
- OS << "OPC_CheckTypeByHwMode, " << Idx << ",";
- OpSize = 2;
+ OS << "OPC_CheckTypeByHwMode, ";
+ OpSize = 1 + emitValueTypeByHwMode(VTBH, Index, OS);
}
} else {
OS << "OPC_CheckTypeResByHwMode, "
- << cast<CheckTypeMatcher>(N)->getResNo() << ", " << Idx << ",";
- OpSize = 3;
+ << cast<CheckTypeMatcher>(N)->getResNo() << ", ";
+ OpSize = 2 + emitValueTypeByHwMode(VTBH, getValueTypeID(VTBH), OS);
}
- if (!OmitComments)
- OS << "/*" << VTBH << "*/";
OS << '\n';
return OpSize;
}
@@ -807,7 +808,7 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
case MVT::i32:
case MVT::i64:
OS << "OPC_CheckChild" << cast<CheckChildTypeMatcher>(N)->getChildNo()
- << "TypeI" << MVT(VT).getSizeInBits() << ",\n";
+ << "TypeI" << VT.getSizeInBits() << ",\n";
return 1;
default:
OS << "OPC_CheckChild" << cast<CheckChildTypeMatcher>(N)->getChildNo()
@@ -817,9 +818,18 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
return NumBytes + 1;
}
} else {
+ unsigned Index = getValueTypeID(VTBH);
+ if (Index == 0) {
+ OS << "OPC_CheckChild" << cast<CheckChildTypeMatcher>(N)->getChildNo()
+ << "TypeByHwMode0";
+ if (!OmitComments)
+ OS << "/*" << VTBH << "*/";
+ OS << ",\n";
+ return 1;
+ }
OS << "OPC_CheckChild" << cast<CheckChildTypeMatcher>(N)->getChildNo()
<< "TypeByHwMode, ";
- unsigned NumBytes = emitValueTypeByHwMode(VTBH, OS);
+ unsigned NumBytes = emitValueTypeByHwMode(VTBH, Index, OS);
OS << '\n';
return NumBytes + 1;
}
@@ -931,9 +941,18 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
break;
}
} else {
- OS << "OPC_EmitIntegerByHwMode, ";
- TypeBytes = emitValueTypeByHwMode(VTBH, OS);
- OS << ' ';
+ unsigned Index = getValueTypeID(VTBH);
+ if (Index == 0) {
+ OS << "OPC_EmitIntegerByHwMode0";
+ if (!OmitComments)
+ OS << "/*" << VTBH << "*/";
+ OS << ", ";
+ TypeBytes = 0;
+ } else {
+ OS << "OPC_EmitIntegerByHwMode, ";
+ TypeBytes = emitValueTypeByHwMode(VTBH, Index, OS);
+ OS << ' ';
+ }
}
// If the value is 63 or smaller, use the string directly. Otherwise, use
// a VBR.
@@ -983,13 +1002,13 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
} else {
if (Reg && Reg->EnumValue > 255) {
OS << "OPC_EmitRegisterByHwMode2, ";
- OpBytes = emitValueTypeByHwMode(VTBH, OS);
+ OpBytes = emitValueTypeByHwMode(VTBH, getValueTypeID(VTBH), OS);
OS << " TARGET_VAL(" << getQualifiedName(Reg->TheDef) << "),\n";
return OpBytes + 3;
}
OS << "OPC_EmitRegisterByHwMode, ";
- OpBytes = emitValueTypeByHwMode(VTBH, OS) + 1;
+ OpBytes = emitValueTypeByHwMode(VTBH, getValueTypeID(VTBH), OS) + 1;
OS << ' ';
}
if (Reg)
@@ -1169,7 +1188,7 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
for (unsigned i = 0, e = EN->getNumVTs(); i != e; ++i) {
OS << ' ';
const ValueTypeByHwMode &VTBH = EN->getVT(i);
- NumTypeBytes += emitValueTypeByHwMode(VTBH, OS);
+ NumTypeBytes += emitValueTypeByHwMode(VTBH, getValueTypeID(VTBH), OS);
}
} else {
for (unsigned i = 0, e = EN->getNumVTs(); i != e; ++i) {
More information about the llvm-commits
mailing list