Skip to content

Commit 80ac32e

Browse files
committed
[VPlan] Assign custom opcodes to recipes not mapping to IR opcodes.
We can perform CSE on recipes that do not directly map to Instruction opcodes. One example is VPVectorPointerRecipe. Currently this is handled by supporting them in ::canHandle, but currently that means that we return std::nullopt from getOpcodeOrIntrinsicID() for it. This currently only works, because the only case we return std::nullopt and perform CSE is VPVectorPointerRecipe. But that does not work if we support more such recipes, like VPPredInstPHIRecipe (llvm#162110). To fix this, return a custom opcode from getOpcodeOrIntrinsicID for recipes like VPVectorPointerRecipe, using the VPDefID after all regular instruction opcodes.
1 parent b178821 commit 80ac32e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ class LLVM_ABI_FOR_TEST VPInstruction : public VPRecipeWithIRFlags,
10641064
ResumeForEpilogue,
10651065
/// Returns the value for vscale.
10661066
VScale,
1067+
OpsEnd = VScale,
10671068
};
10681069

10691070
/// Returns true if this VPInstruction generates scalar values for all lanes.

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,13 @@ struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
19821982
.Case<VPWidenIntrinsicRecipe>([](auto *I) {
19831983
return std::make_pair(true, I->getVectorIntrinsicID());
19841984
})
1985+
.Case<VPVectorPointerRecipe>([](auto *I) {
1986+
// For recipes that do not directly map to LLVM IR instructions,
1987+
// assign opcodes after the last VPInstruction opcode (which is also
1988+
// after the last IR Instruction opcode), based on the VPDefID.
1989+
return std::make_pair(false,
1990+
VPInstruction::OpsEnd + 1 + I->getVPDefID());
1991+
})
19851992
.Default([](auto *) { return std::nullopt; });
19861993
}
19871994

@@ -2005,12 +2012,9 @@ struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
20052012
static bool canHandle(const VPSingleDefRecipe *Def) {
20062013
// We can extend the list of handled recipes in the future,
20072014
// provided we account for the data embedded in them while checking for
2008-
// equality or hashing. We assign VPVectorEndPointerRecipe the GEP opcode,
2009-
// as it is essentially a GEP with different semantics.
2010-
auto C = isa<VPVectorPointerRecipe>(Def)
2011-
? std::make_pair(false, Instruction::GetElementPtr)
2012-
: getOpcodeOrIntrinsicID(Def);
2015+
// equality or hashing.
20132016

2017+
auto C = getOpcodeOrIntrinsicID(Def);
20142018
// The issue with (Insert|Extract)Value is that the index of the
20152019
// insert/extract is not a proper operand in LLVM IR, and hence also not in
20162020
// VPlan.
@@ -2048,6 +2052,8 @@ struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
20482052
vputils::isSingleScalar(L) != vputils::isSingleScalar(R) ||
20492053
!equal(L->operands(), R->operands()))
20502054
return false;
2055+
assert(getOpcodeOrIntrinsicID(L) && getOpcodeOrIntrinsicID(R) &&
2056+
"must have valid opcode info for both recipes");
20512057
if (auto *LFlags = dyn_cast<VPRecipeWithIRFlags>(L))
20522058
if (LFlags->hasPredicate() &&
20532059
LFlags->getPredicate() !=

0 commit comments

Comments
 (0)