[llvm] [VPlan] Introduce ComputeReductionResult VPInstruction opcode. (PR #70253)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 1 13:39:33 PST 2024


================
@@ -7585,7 +7393,36 @@ static void AddRuntimeUnrollDisableMetaData(Loop *L) {
   }
 }
 
-SCEV2ValueTy LoopVectorizationPlanner::executePlan(
+// Check if RedResult is a CompueReductionResult instruction, and if it is
+// add it to \p ReductionResumeValues with the merge phi node for it.
+static void getMergePhiForReduction(
+    VPInstruction *RedResult,
+    DenseMap<const RecurrenceDescriptor *, Value *> &ReductionResumeValues,
+    VPTransformState &State, BasicBlock *OrigScalarPH) {
+  if (!RedResult ||
+      RedResult->getOpcode() != VPInstruction::ComputeReductionResult)
+    return;
+
+  Value *FinalValue = State.get(
+      RedResult, VPIteration(State.UF - 1, VPLane::getLastLaneForVF(State.VF)));
+  auto *PhiR = cast<VPReductionPHIRecipe>(RedResult->getOperand(0));
+  const RecurrenceDescriptor &RedRdx = PhiR->getRecurrenceDescriptor();
+  assert(FinalValue->hasOneUse() || PhiR->isInLoop() ||
+         RedRdx.IntermediateStore && "unexpected final value");
+
+  // Find the merge phi, which must be located in the preheader of the
+  // original scalar loop.
+  auto It = find_if(FinalValue->users(), [OrigScalarPH](Value *U) {
----------------
fhahn wrote:

This isn't needed any longer; the merge phis are created here now, thanks! 

https://github.com/llvm/llvm-project/pull/70253


More information about the llvm-commits mailing list