[llvm] [VPlan] Compute induction end values in VPlan. (PR #112145)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 20 05:57:19 PST 2024


================
@@ -9718,13 +9711,14 @@ void VPDerivedIVRecipe::execute(VPTransformState &State) {
     State.Builder.setFastMathFlags(FPBinOp->getFastMathFlags());
 
   Value *Step = State.get(getStepValue(), VPLane(0));
-  Value *CanonicalIV = State.get(getOperand(1), VPLane(0));
+  Value *Index = State.get(getOperand(1), VPLane(0));
   Value *DerivedIV = emitTransformedIndex(
-      State.Builder, CanonicalIV, getStartValue()->getLiveInIRValue(), Step,
-      Kind, cast_if_present<BinaryOperator>(FPBinOp));
+      State.Builder, Index, getStartValue()->getLiveInIRValue(), Step, Kind,
+      cast_if_present<BinaryOperator>(FPBinOp));
   DerivedIV->setName(Name);
-  assert(DerivedIV != CanonicalIV && "IV didn't need transforming?");
-
+  // Index may only be set to constant 0 in prepareToExecute.
----------------
fhahn wrote:

Yes that is the issue; VectorTripCountV is only created during skeleton creation and set as underlying value here, so we miss this opportunity to fold. I adjusted the assert to check if the index is the vector trip count instead and expanded the comment.

Added a TODO to remove this once we construct VTC in VPlan, and can use it for simplifications. 

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


More information about the llvm-commits mailing list