[llvm] [VPlan] Use ExitingIVValue for pointer inductions as well. (PR #180925)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 12 05:28:12 PST 2026


================
@@ -624,9 +624,37 @@ createWidenInductionRecipe(PHINode *Phi, VPPhi *PhiR, VPIRValue *Start,
   VPValue *Step =
       vputils::getOrCreateVPValueForSCEVExpr(Plan, IndDesc.getStep());
 
-  if (IndDesc.getKind() == InductionDescriptor::IK_PtrInduction)
-    return new VPWidenPointerInductionRecipe(Phi, Start, Step, &Plan.getVFxUF(),
-                                             IndDesc, DL);
+  VPValue *BackedgeVal = PhiR->getOperand(1);
+  // Replace live-out extracts of WideIV's backedge value by ExitingIVValue
+  // recipes. optimizeInductionExitUsers will later compute the proper
+  // DerivedIV.
+  auto ReplaceExtractsWithExitingIVValue = [&](VPHeaderPHIRecipe *WideIV) {
+    for (VPUser *U : to_vector(BackedgeVal->users())) {
+      if (!match(U, m_ExtractLastPart(m_VPValue())))
+        continue;
+      auto *ExtractLastPart = cast<VPInstruction>(U);
+      if (!match(ExtractLastPart->getSingleUser(),
----------------
david-arm wrote:

Is this safe? What if `getSingleUser` returns nullptr? It feels like we're expecting there to be only a single user, and if so perhaps we should assert this?

Alternatively, if you expect there to be more than one user, you could do something like:

```
  VPValue *ExtractLastPart;
  if (!match(U, m_OneUse(m_ExtractLastPart(ExtractLastPart))))
    continue;
  VPInstruction * ExtractLastLane;
  if (!match(ExtractLastPart, m_ExtractLastLane(ExtractLastLane)))
    continue
```

?

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


More information about the llvm-commits mailing list