[PATCH] D147944: [LV][NFC] Improve complexity of fixing users of reductions
Michael Maitland via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 10 07:53:52 PDT 2023
michaelmaitland created this revision.
michaelmaitland added reviewers: fhahn, Ayal, ABataev.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
michaelmaitland requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead.
Herald added a project: LLVM.
The original loop is O(MxN) since is_contained iterates over
all incoming values. This change makes it so only the phis
which use the value as an incoming value are iterated over so
it is now O(M).
This patch is analogous to D146999 <https://reviews.llvm.org/D146999>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147944
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
@@ -4100,12 +4100,17 @@
// We know that the loop is in LCSSA form. We need to update the PHI nodes
// in the exit blocks. See comment on analogous loop in
// fixFixedOrderRecurrence for a more complete explaination of the logic.
- if (!Cost->requiresScalarEpilogue(VF))
- for (PHINode &LCSSAPhi : LoopExitBlock->phis())
- if (llvm::is_contained(LCSSAPhi.incoming_values(), LoopExitInst)) {
- LCSSAPhi.addIncoming(ReducedPartRdx, LoopMiddleBlock);
- State.Plan->removeLiveOut(&LCSSAPhi);
- }
+ if (!Cost->requiresScalarEpilogue(VF)) {
+ SmallPtrSet<PHINode *, 2> ToFix;
+ PHINode *Phi = cast<PHINode>(PhiR->getUnderlyingValue());
+ for (User *U : Phi->users())
+ if (isa<PHINode>(U) && cast<Instruction>(U)->getParent() == LoopExitBlock)
+ ToFix.insert(cast<PHINode>(U));
+ for (PHINode *LCSSAPhi : ToFix) {
+ LCSSAPhi->addIncoming(ReducedPartRdx, LoopMiddleBlock);
+ State.Plan->removeLiveOut(LCSSAPhi);
+ }
+ }
// Fix the scalar loop reduction variable with the incoming reduction sum
// from the vector body and from the backedge value.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147944.512147.patch
Type: text/x-patch
Size: 1351 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230410/97f81893/attachment.bin>
More information about the llvm-commits
mailing list