[llvm] [LV] Compute value of escaped induction based on the computed end value. (PR #110576)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 22 05:52:56 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() ==
----------------
ayalz wrote:
Perhaps CreateBinOp() could be used for both integer and FP, as in something like:
```
// FP induction opcodes are inversed FAdd<->FSub,
// integer induction opcode Add is inversed -> Sub,
// otherwise zero is returned.
auto getInverseOpcode = []([BinaryOperator *BinOp) {
if (!BinOp)
return 0;
switch (BinOp->getOpcode()) {
case Instruction::Add: return Instruction::Sub;
case Instruction::FAdd: return Instruction::FSub;
case Instruction::FSub: return Instruction::FAdd;
default : return 0;
};
}
// For pointer inductions negate Step, for integer and
// FP inductions better to inverse the opcode instead.
unsigned InverseOpcode = getInverseOpcode(II.getInductionBinOp());
assert((InverseOpcode || II.getKind() == IK_PtrInduction) && "Unsupported induction opcode or type");
Value *Escape = InverseOpcode
? B.CreateBinOp(InverseOpcode, EndValue, Step)
: B.CreatePtrAdd(EndValue, B.CreateNeg(Step));
```
https://github.com/llvm/llvm-project/pull/110576
More information about the llvm-commits
mailing list