[llvm] [VPlan] Add VPInstruction::StepVector and use it in VPWidenIntOrFpInductionRecipe (PR #129508)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed May 7 06:49:20 PDT 2025


================
@@ -1223,6 +1223,15 @@ static bool optimizeVectorInductionWidthForTCAndVFUF(VPlan &Plan,
     WideIV->setStartValue(NewStart);
     auto *NewStep = Plan.getOrAddLiveIn(ConstantInt::get(NewIVTy, 1));
     WideIV->setStepValue(NewStep);
+    // TODO: Remove once VPWidenIntOrFpInductionRecipe is fully expanded.
+    auto *OldStepVector = cast<VPInstructionWithType>(
+        WideIV->getStepVector()->getDefiningRecipe());
+    assert(OldStepVector->getOpcode() == VPInstruction::StepVector);
+    auto *NewStepVector = new VPInstructionWithType(
+        VPInstruction::StepVector, {}, NewIVTy, OldStepVector->getDebugLoc());
+    NewStepVector->insertAfter(WideIV->getStepVector()->getDefiningRecipe());
+    WideIV->setStepVector(NewStepVector);
----------------
fhahn wrote:

`StepVector` has only a single user, the wide IV, right? Can we assert that there's a single user before removing the old step vector and just use `OldStepVector->replaceAllUsesWith(NewStepVector)`, without the need for adding `setStepVector`?

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


More information about the llvm-commits mailing list