[llvm] c7209cb - [LV] Assert that there's a resume phi for epilogue loops (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu May 2 11:20:54 PDT 2024
Author: Florian Hahn
Date: 2024-05-02T19:20:28+01:00
New Revision: c7209cbb8be7a3c658137679d760ce9d70baded8
URL: https://github.com/llvm/llvm-project/commit/c7209cbb8be7a3c658137679d760ce9d70baded8
DIFF: https://github.com/llvm/llvm-project/commit/c7209cbb8be7a3c658137679d760ce9d70baded8.diff
LOG: [LV] Assert that there's a resume phi for epilogue loops (NFC).
This patch adds an assert to createAndCollectMergePhiForReduction to
make sure there is a resume phi when vectorizing the epilogue loop. This
is needed to set the resume value from the main vector loop.
This assertion guards against the issue caused the revert of
https://github.com/llvm/llvm-project/pull/78304.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index d1c54b928f9fa2..95209e015a0511 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7450,7 +7450,8 @@ static void AddRuntimeUnrollDisableMetaData(Loop *L) {
static void createAndCollectMergePhiForReduction(
VPInstruction *RedResult,
DenseMap<const RecurrenceDescriptor *, Value *> &ReductionResumeValues,
- VPTransformState &State, Loop *OrigLoop, BasicBlock *LoopMiddleBlock) {
+ VPTransformState &State, Loop *OrigLoop, BasicBlock *LoopMiddleBlock,
+ bool VectorizingEpilogue) {
if (!RedResult ||
RedResult->getOpcode() != VPInstruction::ComputeReductionResult)
return;
@@ -7463,6 +7464,9 @@ static void createAndCollectMergePhiForReduction(
State.get(RedResult, VPIteration(State.UF - 1, VPLane::getFirstLane()));
auto *ResumePhi =
dyn_cast<PHINode>(PhiR->getStartValue()->getUnderlyingValue());
+ assert((!VectorizingEpilogue || ResumePhi) &&
+ "when vectorizing the epilogue loop, we need a resume phi from main "
+ "vector loop");
// TODO: bc.merge.rdx should not be created here, instead it should be
// modeled in VPlan.
@@ -7588,9 +7592,9 @@ LoopVectorizationPlanner::executePlan(
auto *ExitVPBB =
cast<VPBasicBlock>(BestVPlan.getVectorLoopRegion()->getSingleSuccessor());
for (VPRecipeBase &R : *ExitVPBB) {
- createAndCollectMergePhiForReduction(dyn_cast<VPInstruction>(&R),
- ReductionResumeValues, State, OrigLoop,
- State.CFG.VPBB2IRBB[ExitVPBB]);
+ createAndCollectMergePhiForReduction(
+ dyn_cast<VPInstruction>(&R), ReductionResumeValues, State, OrigLoop,
+ State.CFG.VPBB2IRBB[ExitVPBB], ExpandedSCEVs);
}
// 2.6. Maintain Loop Hints
More information about the llvm-commits
mailing list