Skip to content

Commit ecdf975

Browse files
committed
[IVDesc] Address review
1 parent 0a573b9 commit ecdf975

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

llvm/include/llvm/Analysis/IVDescriptors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class InductionDescriptor {
401401
InductionKind getKind() const { return IK; }
402402
const SCEV *getStep() const { return Step; }
403403
BinaryOperator *getInductionBinOp() const { return InductionBinOp; }
404-
LLVM_ABI const APInt *getStepValue() const;
404+
LLVM_ABI ConstantInt *getConstIntStepValue() const;
405405

406406
/// Returns true if \p Phi is an induction in the loop \p L. If \p Phi is an
407407
/// induction, the induction descriptor \p D will contain the data describing

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ InductionDescriptor::InductionDescriptor(Value *Start, InductionKind K,
13821382
"StartValue is not an integer for integer induction");
13831383

13841384
// Check the Step Value. It should be non-zero integer value.
1385-
assert((!getStepValue() || !getStepValue()->isZero()) &&
1385+
assert((!getConstIntStepValue() || !getConstIntStepValue()->isZero()) &&
13861386
"Step value is zero");
13871387

13881388
assert((IK == IK_FpInduction || Step->getType()->isIntegerTy()) &&
@@ -1400,11 +1400,10 @@ InductionDescriptor::InductionDescriptor(Value *Start, InductionKind K,
14001400
llvm::append_range(RedundantCasts, *Casts);
14011401
}
14021402

1403-
const APInt *InductionDescriptor::getStepValue() const {
1404-
const APInt *StepC;
1405-
if (!match(Step, m_scev_APInt(StepC)))
1406-
return nullptr;
1407-
return StepC;
1403+
ConstantInt *InductionDescriptor::getConstIntStepValue() const {
1404+
if (auto *C = dyn_cast<SCEVConstant>(Step))
1405+
return dyn_cast<ConstantInt>(C->getValue());
1406+
return nullptr;
14081407
}
14091408

14101409
bool InductionDescriptor::isFPInductionPHI(PHINode *Phi, const Loop *TheLoop,
@@ -1621,6 +1620,10 @@ bool InductionDescriptor::isInductionPHI(
16211620
// Check that the PHI is consecutive.
16221621
const SCEV *PhiScev = Expr ? Expr : SE->getSCEV(Phi);
16231622
const SCEV *Step;
1623+
1624+
// FIXME: We are currently matching the specific loop TheLoop; if it doesn't
1625+
// match, we should treat it as a uniform. Unfortunately, we don't currently
1626+
// know how to handled uniform PHIs.
16241627
if (!match(PhiScev, m_scev_AffineAddRec(m_SCEV(), m_SCEV(Step),
16251628
m_SpecificLoop(TheLoop)))) {
16261629
LLVM_DEBUG(dbgs() << "LV: PHI is not a poly recurrence.\n");

llvm/lib/Analysis/LoopInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ bool Loop::isCanonical(ScalarEvolution &SE) const {
421421
if (IndDesc.getInductionOpcode() != Instruction::Add)
422422
return false;
423423

424-
const APInt *Step = IndDesc.getStepValue();
424+
ConstantInt *Step = IndDesc.getConstIntStepValue();
425425
if (!Step || !Step->isOne())
426426
return false;
427427

llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ void LoopVectorizationLegality::addInductionPhi(
704704

705705
// Int inductions are special because we only allow one IV.
706706
if (ID.getKind() == InductionDescriptor::IK_IntInduction &&
707-
ID.getStepValue() && ID.getStepValue()->isOne() &&
707+
ID.getConstIntStepValue() && ID.getConstIntStepValue()->isOne() &&
708708
isa<Constant>(ID.getStartValue()) &&
709709
cast<Constant>(ID.getStartValue())->isNullValue()) {
710710

@@ -889,7 +889,7 @@ bool LoopVectorizationLegality::canVectorizeInstr(Instruction &I) {
889889
if (AllowStridedPointerIVs)
890890
return false;
891891
return ID.getKind() == InductionDescriptor::IK_PtrInduction &&
892-
ID.getStepValue() == nullptr;
892+
ID.getConstIntStepValue() == nullptr;
893893
};
894894

895895
// TODO: Instead of recording the AllowedExit, it would be good to

0 commit comments

Comments
 (0)