[llvm] [LV] Compute value of escaped induction based on the computed end value. (PR #110576)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 21 21:51:42 PDT 2024
================
@@ -2747,17 +2747,24 @@ void InnerLoopVectorizer::fixupIVUsers(PHINode *OrigPhi,
if (isa_and_nonnull<FPMathOperator>(II.getInductionBinOp()))
B.setFastMathFlags(II.getInductionBinOp()->getFastMathFlags());
- Value *CountMinusOne = B.CreateSub(
- VectorTripCount, ConstantInt::get(VectorTripCount->getType(), 1));
- CountMinusOne->setName("cmo");
-
VPValue *StepVPV = Plan.getSCEVExpansion(II.getStep());
assert(StepVPV && "step must have been expanded during VPlan execution");
Value *Step = StepVPV->isLiveIn() ? StepVPV->getLiveInIRValue()
: State.get(StepVPV, VPLane(0));
- Value *Escape =
- emitTransformedIndex(B, CountMinusOne, II.getStartValue(), Step,
- II.getKind(), II.getInductionBinOp());
+ Value *Escape = nullptr;
+ if (EndValue->getType()->isIntegerTy())
+ Escape = B.CreateSub(EndValue, Step);
+ else if (EndValue->getType()->isPointerTy())
+ Escape = B.CreatePtrAdd(EndValue, B.CreateNeg(Step));
+ else if (EndValue->getType()->isFloatingPointTy()) {
+ Escape = B.CreateBinOp(II.getInductionBinOp()->getOpcode() ==
----------------
fhahn wrote:
Unfortunately I am not sure there's a way to do this more concisely overall. Negating the step would work for both integer and pointers, but then we still would need to select between Add/PtrAdd. And add(neg()) requires an additional instructions for integers.
For floating points, perhaps it might be possible to normalize the representation of currently `fsub step` to `fadd -step` in general, but we would still need to handle FP values separately. I left things as is for now
https://github.com/llvm/llvm-project/pull/110576
More information about the llvm-commits
mailing list