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

via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 24 13:35:08 PST 2023


================
@@ -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) {
----------------
ayalz wrote:

Perhaps there's a better way to collect these merge phi's per RdxDesc than to lookup ComputeReductionResult's first operand along with first user in OrigScalarPH, see below.

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


More information about the llvm-commits mailing list