Skip to content

Commit 74275a1

Browse files
authored
[RISCV] Simplify code gen for riscv_vector_builtin_cg.inc [NFC] (#156397)
For each intrinsic with ManualCodegen block will generate something like below: ```cpp SegInstSEW = 0; ... if (SegInstSEW == (unsigned)-1) { auto PointeeType = E->getArg(4294967295)->getType()->getPointeeType(); SegInstSEW = llvm::Log2_64(getContext().getTypeSize(PointeeType)); } ``` But actually SegInstSEW is table-gen-time constant, so can remove that if-check and directly use the constant. This change reduce riscv_vector_builtin_cg.inc around 6600 lines (30913 to 24305) which is around 20% reduction, however seems this isn't impact the build time much since the redundant dead branch is almost will optimized away by compiler in early stage.
1 parent c5d7662 commit 74275a1

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

clang/utils/TableGen/RISCVVEmitter.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ static VectorTypeModifier getTupleVTM(unsigned NF) {
166166
static_cast<uint8_t>(VectorTypeModifier::Tuple2) + (NF - 2));
167167
}
168168

169+
static const unsigned UnknownIndex = (unsigned)-1;
170+
169171
static unsigned getIndexedLoadStorePtrIdx(const RVVIntrinsic *RVVI) {
170172
// We need a special rule for segment load/store since the data width is not
171173
// encoded in the intrinsic name itself.
@@ -183,7 +185,7 @@ static unsigned getIndexedLoadStorePtrIdx(const RVVIntrinsic *RVVI) {
183185
if (IRName.starts_with("vsoxseg") || IRName.starts_with("vsuxseg"))
184186
return RVVI->isMasked() ? 1 : 0;
185187

186-
return (unsigned)-1;
188+
return UnknownIndex;
187189
}
188190

189191
// This function is used to get the log2SEW of each segment load/store, this
@@ -249,19 +251,21 @@ void emitCodeGenSwitchBody(const RVVIntrinsic *RVVI, raw_ostream &OS) {
249251
OS << " ID = Intrinsic::riscv_" + RVVI->getIRName() + ";\n";
250252

251253
OS << " PolicyAttrs = " << RVVI->getPolicyAttrsBits() << ";\n";
252-
OS << " SegInstSEW = " << getSegInstLog2SEW(RVVI->getOverloadedName())
253-
<< ";\n";
254+
unsigned IndexedLoadStorePtrIdx = getIndexedLoadStorePtrIdx(RVVI);
255+
if (IndexedLoadStorePtrIdx != UnknownIndex) {
256+
OS << " {\n";
257+
OS << " auto PointeeType = E->getArg(" << IndexedLoadStorePtrIdx
258+
<< ")->getType()->getPointeeType();\n";
259+
OS << " SegInstSEW = "
260+
"llvm::Log2_64(getContext().getTypeSize(PointeeType));\n";
261+
OS << " }\n";
262+
} else {
263+
OS << " SegInstSEW = " << getSegInstLog2SEW(RVVI->getOverloadedName())
264+
<< ";\n";
265+
}
254266

255267
if (RVVI->hasManualCodegen()) {
256268
OS << "IsMasked = " << (RVVI->isMasked() ? "true" : "false") << ";\n";
257-
258-
// Skip the non-indexed load/store and compatible header load/store.
259-
OS << "if (SegInstSEW == (unsigned)-1) {\n";
260-
OS << " auto PointeeType = E->getArg(" << getIndexedLoadStorePtrIdx(RVVI)
261-
<< " )->getType()->getPointeeType();\n";
262-
OS << " SegInstSEW = "
263-
" llvm::Log2_64(getContext().getTypeSize(PointeeType));\n}\n";
264-
265269
OS << RVVI->getManualCodegen();
266270
OS << "break;\n";
267271
return;

0 commit comments

Comments
 (0)