[NFC][SCEV] Refactor getAbsExpr() out of createSCEV()

This commit is contained in:
Roman Lebedev 2020-10-17 20:53:11 +03:00
parent be1678bdb9
commit 130cc662b5
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
2 changed files with 10 additions and 8 deletions

View File

@ -572,6 +572,7 @@ public:
/// \p IndexExprs The expressions for the indices. /// \p IndexExprs The expressions for the indices.
const SCEV *getGEPExpr(GEPOperator *GEP, const SCEV *getGEPExpr(GEPOperator *GEP,
const SmallVectorImpl<const SCEV *> &IndexExprs); const SmallVectorImpl<const SCEV *> &IndexExprs);
const SCEV *getAbsExpr(const SCEV *Op, bool IsNSW);
const SCEV *getMinMaxExpr(unsigned Kind, const SCEV *getMinMaxExpr(unsigned Kind,
SmallVectorImpl<const SCEV *> &Operands); SmallVectorImpl<const SCEV *> &Operands);
const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS); const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS);

View File

@ -3334,6 +3334,11 @@ ScalarEvolution::findExistingSCEVInCache(int SCEVType,
UniqueSCEVs.FindNodeOrInsertPos(ID, IP), std::move(ID), IP); UniqueSCEVs.FindNodeOrInsertPos(ID, IP), std::move(ID), IP);
} }
const SCEV *ScalarEvolution::getAbsExpr(const SCEV *Op, bool IsNSW) {
SCEV::NoWrapFlags Flags = IsNSW ? SCEV::FlagNSW : SCEV::FlagAnyWrap;
return getSMaxExpr(Op, getNegativeSCEV(Op, Flags));
}
const SCEV *ScalarEvolution::getMinMaxExpr(unsigned Kind, const SCEV *ScalarEvolution::getMinMaxExpr(unsigned Kind,
SmallVectorImpl<const SCEV *> &Ops) { SmallVectorImpl<const SCEV *> &Ops) {
assert(!Ops.empty() && "Cannot get empty (u|s)(min|max)!"); assert(!Ops.empty() && "Cannot get empty (u|s)(min|max)!");
@ -6340,14 +6345,10 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
if (auto *II = dyn_cast<IntrinsicInst>(U)) { if (auto *II = dyn_cast<IntrinsicInst>(U)) {
switch (II->getIntrinsicID()) { switch (II->getIntrinsicID()) {
case Intrinsic::abs: { case Intrinsic::abs:
const SCEV *Op = getSCEV(II->getArgOperand(0)); return getAbsExpr(
SCEV::NoWrapFlags Flags = getSCEV(II->getArgOperand(0)),
cast<ConstantInt>(II->getArgOperand(1))->isOne() /*IsNSW=*/cast<ConstantInt>(II->getArgOperand(1))->isOne());
? SCEV::FlagNSW
: SCEV::FlagAnyWrap;
return getSMaxExpr(Op, getNegativeSCEV(Op, Flags));
}
case Intrinsic::umax: case Intrinsic::umax:
return getUMaxExpr(getSCEV(II->getArgOperand(0)), return getUMaxExpr(getSCEV(II->getArgOperand(0)),
getSCEV(II->getArgOperand(1))); getSCEV(II->getArgOperand(1)));