[PATCH] D99294: [LV] Track incoming values for reductions in recipe (NFC).
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 24 12:53:29 PDT 2021
fhahn created this revision.
fhahn added reviewers: gilr, Ayal, rengolin.
Herald added subscribers: rogfer01, bollu, hiraditya.
fhahn requested review of this revision.
Herald added a subscriber: vkmr.
Herald added a project: LLVM.
This patch updates the code handling reduction recipes to also keep
track of the incoming value from the latch in the recipe. This is needed
to model the def-use chains completely in VPlan, so that it is possible
to replace the incoming value with an arbitrary VPValue.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D99294
Files:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4259,14 +4259,11 @@
// Reductions do not have to start at zero. They can start with
// any loop invariant values.
- BasicBlock *Latch = OrigLoop->getLoopLatch();
- Value *LoopVal = OrigPhi->getIncomingValueForBlock(Latch);
-
for (unsigned Part = 0; Part < UF; ++Part) {
- Value *VecRdxPhi = State.get(PhiR->getVPValue(), Part);
- Value *Val = State.get(State.Plan->getVPValue(LoopVal), Part);
- cast<PHINode>(VecRdxPhi)
- ->addIncoming(Val, LI->getLoopFor(LoopVectorBody)->getLoopLatch());
+ Value *VecRdxPhi = State.get(PhiR->getVPValue(0), Part);
+ cast<PHINode>(VecRdxPhi)->addIncoming(
+ State.get(PhiR->getOperand(1), Part),
+ LI->getLoopFor(LoopVectorBody)->getLoopLatch());
}
// Before each round, move the insertion point right between
@@ -8746,6 +8743,18 @@
RecipeBuilder.recordRecipeOf(Entry.first);
RecipeBuilder.recordRecipeOf(Entry.second);
}
+
+ SmallVector<PHINode *, 4> PhisToFix;
+ BasicBlock *OrigLatch = OrigLoop->getLoopLatch();
+ for (PHINode &Phi : OrigLoop->getHeader()->phis()) {
+ if (!Legal->isReductionVariable(&Phi))
+ continue;
+ PhisToFix.push_back(&Phi);
+ RecipeBuilder.recordRecipeOf(&Phi);
+ RecipeBuilder.recordRecipeOf(
+ cast<Instruction>(Phi.getIncomingValueForBlock(OrigLatch)));
+ }
+
for (auto &Reduction : CM.getInLoopReductionChains()) {
PHINode *Phi = Reduction.first;
RecurKind Kind = Legal->getReductionVars()[Phi].getRecurrenceKind();
@@ -8844,6 +8853,14 @@
}
}
+ for (PHINode *PN : PhisToFix) {
+ VPWidenPHIRecipe *R = cast<VPWidenPHIRecipe>(RecipeBuilder.getRecipe(PN));
+ VPRecipeBase *IncR = RecipeBuilder.getRecipe(
+ cast<Instruction>(PN->getIncomingValueForBlock(OrigLatch)));
+ assert(IncR->getNumDefinedValues() == 1);
+ R->addOperand(IncR->getVPValue(0));
+ }
+
// Discard empty dummy pre-entry VPBasicBlock. Note that other VPBasicBlocks
// may also be empty, such as the last one VPBB, reflecting original
// basic-blocks with no recipes.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99294.333096.patch
Type: text/x-patch
Size: 2278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210324/78c1a531/attachment.bin>
More information about the llvm-commits
mailing list