[llvm] [LoopVectorizer] Add support for partial reductions (PR #92418)
Sam Tebbs via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 8 02:01:22 PDT 2024
================
@@ -7031,6 +7221,23 @@ void LoopVectorizationPlanner::plan(ElementCount UserVF, unsigned UserIC) {
if (CM.foldTailByMasking())
Legal->prepareToFoldTailByMasking();
+ for (auto Pair : CM.getPartialReductionChains()) {
+ // TODO: Allow creating partial reductions when predicating. The select at
+ // the end of the loop chooses between the phi value and most recent partial
+ // reduction result, both of which have different VFs to the active lane
+ // mask.
+ Instruction *Instr = Pair.first;
+ if (CM.blockNeedsPredicationForAnyReason(Instr->getParent())) {
+ LLVM_DEBUG(dbgs() << "LV: Removing the partial reduction for an "
+ "instruction in a predicated block: "
+ << *Instr << "\n");
+ PartialReductionsToRemove.insert(Instr);
+ }
+ }
----------------
SamTebbs33 wrote:
Currently, `collectValuesToIgnore` needs the partial reductions to exist, so we have to add them before that function is called. When we're able to remove the changes to `collectValuesToIgnore` I can remove this and only add the partial reductions if the block doesn't need predication. Unfortunately that predication information is only known after `collectValuesToIgnore` and `computeMaxVF` is called.
https://github.com/llvm/llvm-project/pull/92418
More information about the llvm-commits
mailing list