[llvm] [VPlan] Introduce ComputeReductionResult VPInstruction opcode. (PR #70253)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 18 05:08:24 PST 2023
================
@@ -7729,6 +7552,33 @@ SCEV2ValueTy LoopVectorizationPlanner::executePlan(
BestVPlan.execute(&State);
+ DenseMap<const RecurrenceDescriptor *, Value *> ReductionResumeValues;
+ BasicBlock *OrigScalarPH = OrigLoop->getLoopPreheader();
+ for (VPRecipeBase &R : *cast<VPBasicBlock>(
+ BestVPlan.getVectorLoopRegion()->getSingleSuccessor())) {
+
+ auto *Red = dyn_cast<VPInstruction>(&R);
+ if (!Red || Red->getOpcode() != VPInstruction::ComputeReductionResult)
+ continue;
+
+ Value *FinalValue = State.get(
+ Red, VPIteration(State.UF - 1, VPLane::getLastLaneForVF(State.VF)));
+ auto *PhiR = cast<VPReductionPHIRecipe>(Red->getOperand(0));
+ assert(FinalValue->hasOneUse() || PhiR->isInLoop() ||
+ PhiR->getRecurrenceDescriptor().IntermediateStore);
+
+ // Find the merge phi, which must be located in the preheader of the
+ // original scalar loop.
+ PHINode *MergePhi = nullptr;
+ for (Value *U : FinalValue->users()) {
+ auto *P = dyn_cast<PHINode>(U);
+ if (P && OrigScalarPH == P->getParent()) {
+ MergePhi = P;
+ break;
+ }
+ }
----------------
fhahn wrote:
Outlined, thanks!
https://github.com/llvm/llvm-project/pull/70253
More information about the llvm-commits
mailing list