From: Sanjoy Das Date: Thu, 4 Feb 2016 18:21:54 +0000 (+0000) Subject: [SCEV] Add boolean accessors for NSW, NUW and NW; NFC X-Git-Tag: llvmorg-3.9.0-rc1~15091 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=76c48e0e704ef72f37766ef12b3fa1a924c33ad8;p=platform%2Fupstream%2Fllvm.git [SCEV] Add boolean accessors for NSW, NUW and NW; NFC llvm-svn: 259809 --- diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h b/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h index ad5ee87..0fd26e3 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h +++ b/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h @@ -166,6 +166,18 @@ namespace llvm { return (NoWrapFlags)(SubclassData & Mask); } + bool hasNoUnsignedWrap() const { + return getNoWrapFlags(SCEV::FlagNUW) != SCEV::FlagAnyWrap; + } + + bool hasNoSignedWrap() const { + return getNoWrapFlags(SCEV::FlagNSW) != SCEV::FlagAnyWrap; + } + + bool hasNoSelfWrap() const { + return getNoWrapFlags(SCEV::FlagNW) != SCEV::FlagAnyWrap; + } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const SCEV *S) { return S->getSCEVType() == scAddExpr || diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index f8edbf4..32bf11a 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -166,11 +166,11 @@ void SCEV::print(raw_ostream &OS) const { for (unsigned i = 1, e = AR->getNumOperands(); i != e; ++i) OS << ",+," << *AR->getOperand(i); OS << "}<"; - if (AR->getNoWrapFlags(FlagNUW)) + if (AR->hasNoUnsignedWrap()) OS << "nuw><"; - if (AR->getNoWrapFlags(FlagNSW)) + if (AR->hasNoSignedWrap()) OS << "nsw><"; - if (AR->getNoWrapFlags(FlagNW) && + if (AR->hasNoSelfWrap() && !AR->getNoWrapFlags((NoWrapFlags)(FlagNUW | FlagNSW))) OS << "nw><"; AR->getLoop()->getHeader()->printAsOperand(OS, /*PrintType=*/false); @@ -200,9 +200,9 @@ void SCEV::print(raw_ostream &OS) const { switch (NAry->getSCEVType()) { case scAddExpr: case scMulExpr: - if (NAry->getNoWrapFlags(FlagNUW)) + if (NAry->hasNoUnsignedWrap()) OS << ""; - if (NAry->getNoWrapFlags(FlagNSW)) + if (NAry->hasNoSignedWrap()) OS << ""; } return; @@ -1456,7 +1456,7 @@ const SCEV *ScalarEvolution::getZeroExtendExpr(const SCEV *Op, // If we have special knowledge that this addrec won't overflow, // we don't need to do any further analysis. - if (AR->getNoWrapFlags(SCEV::FlagNUW)) + if (AR->hasNoUnsignedWrap()) return getAddRecExpr( getExtendAddRecStart(AR, Ty, this), getZeroExtendExpr(Step, Ty), L, AR->getNoWrapFlags()); @@ -1563,7 +1563,7 @@ const SCEV *ScalarEvolution::getZeroExtendExpr(const SCEV *Op, if (auto *SA = dyn_cast(Op)) { // zext((A + B + ...)) --> (zext(A) + zext(B) + ...) - if (SA->getNoWrapFlags(SCEV::FlagNUW)) { + if (SA->hasNoUnsignedWrap()) { // If the addition does not unsign overflow then we can, by definition, // commute the zero extension with the addition operation. SmallVector Ops; @@ -1647,7 +1647,7 @@ const SCEV *ScalarEvolution::getSignExtendExpr(const SCEV *Op, } // sext((A + B + ...)) --> (sext(A) + sext(B) + ...) - if (SA->getNoWrapFlags(SCEV::FlagNSW)) { + if (SA->hasNoSignedWrap()) { // If the addition does not sign overflow then we can, by definition, // commute the sign extension with the addition operation. SmallVector Ops; @@ -1669,7 +1669,7 @@ const SCEV *ScalarEvolution::getSignExtendExpr(const SCEV *Op, // If we have special knowledge that this addrec won't overflow, // we don't need to do any further analysis. - if (AR->getNoWrapFlags(SCEV::FlagNSW)) + if (AR->hasNoSignedWrap()) return getAddRecExpr( getExtendAddRecStart(AR, Ty, this), getSignExtendExpr(Step, Ty), L, SCEV::FlagNSW); @@ -4360,7 +4360,7 @@ ScalarEvolution::getRange(const SCEV *S, if (const SCEVAddRecExpr *AddRec = dyn_cast(S)) { // If there's no unsigned wrap, the value will never be less than its // initial value. - if (AddRec->getNoWrapFlags(SCEV::FlagNUW)) + if (AddRec->hasNoUnsignedWrap()) if (const SCEVConstant *C = dyn_cast(AddRec->getStart())) if (!C->getValue()->isZero()) ConservativeResult = ConservativeResult.intersectWith( @@ -4368,7 +4368,7 @@ ScalarEvolution::getRange(const SCEV *S, // If there's no signed wrap, and all the operands have the same sign or // zero, the value won't ever change sign. - if (AddRec->getNoWrapFlags(SCEV::FlagNSW)) { + if (AddRec->hasNoSignedWrap()) { bool AllNonNeg = true; bool AllNonPos = true; for (unsigned i = 0, e = AddRec->getNumOperands(); i != e; ++i) { @@ -6788,7 +6788,7 @@ ScalarEvolution::HowFarToZero(const SCEV *V, const Loop *L, bool ControlsExit) { // compute the backedge count. In this case, the step may not divide the // distance, but we don't care because if the condition is "missed" the loop // will have undefined behavior due to wrapping. - if (ControlsExit && AddRec->getNoWrapFlags(SCEV::FlagNW)) { + if (ControlsExit && AddRec->hasNoSelfWrap()) { const SCEV *Exact = getUDivExpr(Distance, CountDown ? getNegativeSCEV(Step) : Step); return ExitLimit(Exact, Exact); @@ -7255,7 +7255,7 @@ bool ScalarEvolution::isMonotonicPredicateImpl(const SCEVAddRecExpr *LHS, case ICmpInst::ICMP_UGE: case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_ULE: - if (!LHS->getNoWrapFlags(SCEV::FlagNUW)) + if (!LHS->hasNoUnsignedWrap()) return false; Increasing = Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_UGE; @@ -7265,7 +7265,7 @@ bool ScalarEvolution::isMonotonicPredicateImpl(const SCEVAddRecExpr *LHS, case ICmpInst::ICMP_SGE: case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_SLE: { - if (!LHS->getNoWrapFlags(SCEV::FlagNSW)) + if (!LHS->hasNoSignedWrap()) return false; const SCEV *Step = LHS->getStepRecurrence(*this);