diff options
author | Zheng Chen <czhengsz@cn.ibm.com> | 2020-01-12 20:22:37 -0500 |
---|---|---|
committer | Zheng Chen <czhengsz@cn.ibm.com> | 2020-01-12 20:22:37 -0500 |
commit | a6342c247a17fb270e0385bd1deb463b7309a43b (patch) | |
tree | c2c4b563332cc6b078a479dc807abb450650c9e4 /llvm/lib/Analysis | |
parent | 0113cf193f0610bb1a5dfa0bcd29c41a8965938a (diff) | |
download | bcm5719-llvm-a6342c247a17fb270e0385bd1deb463b7309a43b.tar.gz bcm5719-llvm-a6342c247a17fb270e0385bd1deb463b7309a43b.zip |
[SCEV] accurate range for addrecexpr with nuw flag
If addrecexpr has nuw flag, the value should never be less than its
start value and start value does not required to be SCEVConstant.
Reviewed By: nikic, sanjoy
Differential Revision: https://reviews.llvm.org/D71690
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index f8d23c40e0c..648412a63a0 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -5672,11 +5672,12 @@ ScalarEvolution::getRangeRef(const SCEV *S, if (const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(S)) { // If there's no unsigned wrap, the value will never be less than its // initial value. - if (AddRec->hasNoUnsignedWrap()) - if (const SCEVConstant *C = dyn_cast<SCEVConstant>(AddRec->getStart())) - if (!C->getValue()->isZero()) - ConservativeResult = ConservativeResult.intersectWith( - ConstantRange(C->getAPInt(), APInt(BitWidth, 0)), RangeType); + if (AddRec->hasNoUnsignedWrap()) { + APInt UnsignedMinValue = getUnsignedRangeMin(AddRec->getStart()); + if (!UnsignedMinValue.isNullValue()) + ConservativeResult = ConservativeResult.intersectWith( + ConstantRange(UnsignedMinValue, APInt(BitWidth, 0)), RangeType); + } // If there's no signed wrap, and all the operands except initial value have // the same sign or zero, the value won't ever be: |