[llvm-branch-commits] [llvm] [LoopVectorize] Support vectorization of compressing patterns in VPlan (PR #140723)

Sergey Kachkov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 7 05:55:53 PST 2025


================
@@ -4442,6 +4495,29 @@ void VPReductionPHIRecipe::print(raw_ostream &O, const Twine &Indent,
 }
 #endif
 
+void VPMonotonicPHIRecipe::execute(VPTransformState &State) {
+  assert(getParent()->getPlan()->getUF() == 1 && "Expected unroll factor 1.");
+  Value *Start = getStartValue()->getLiveInIRValue();
+  BasicBlock *VectorPH =
+      State.CFG.VPBB2IRBB.at(getParent()->getCFGPredecessor(0));
+  PHINode *MonotonicPHI =
+      State.Builder.CreatePHI(Start->getType(), 2, "monotonic.iv");
+  MonotonicPHI->addIncoming(Start, VectorPH);
+  MonotonicPHI->setDebugLoc(getDebugLoc());
+  State.set(this, MonotonicPHI, /*IsScalar=*/true);
+}
----------------
skachkov-sc wrote:

The only rational for new recipe was to simplify "adjusting" of VPlan: we need to insert VPInstruction::ComputeMonotonicRecipe at the backedge of such phi (that will incement phi value on ctpop(mask)). This looks similar to handling of reductions: VPMonotonicPHIRecipe/VPInstruction::ComputeMonotonicResult is symmetric to VPReductionPHIRecipe/VPInstruction::ComputeReductionResult. Probably VPWidenPHI recipe can be used there, but there are some places in code when we want to distinguish "monotonic" header phis ftom the others.

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


More information about the llvm-branch-commits mailing list