Make the range calculations for addrecs to be more conservative,
authorDan Gohman <gohman@apple.com>
Tue, 21 Jul 2009 00:42:47 +0000 (00:42 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 21 Jul 2009 00:42:47 +0000 (00:42 +0000)
as they aren't currently prepared to handle complicated overflow
cases.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76524 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolution.cpp

index 13c734027c786bfc3905f63ea93171d64275f1f6..20b2aa48c12fc92075ca85489a786cbe1602ec9b 100644 (file)
@@ -2619,10 +2619,15 @@ ScalarEvolution::getUnsignedRange(const SCEV *S) {
         MaxBECount = getNoopOrZeroExtend(MaxBECount, Ty);
 
         const SCEV *Start = AddRec->getStart();
+        const SCEV *Step = AddRec->getStepRecurrence(*this);
         const SCEV *End = AddRec->evaluateAtIteration(MaxBECount, *this);
 
         // Check for overflow.
-        if (!isKnownPredicate(ICmpInst::ICMP_ULE, Start, End))
+        // TODO: This is very conservative.
+        if (!(Step->isOne() &&
+              isKnownPredicate(ICmpInst::ICMP_ULT, Start, End)) &&
+            !(Step->isAllOnesValue() &&
+              isKnownPredicate(ICmpInst::ICMP_UGT, Start, End)))
           return FullSet;
 
         ConstantRange StartRange = getUnsignedRange(Start);
@@ -2728,9 +2733,10 @@ ScalarEvolution::getSignedRange(const SCEV *S) {
         const SCEV *End = AddRec->evaluateAtIteration(MaxBECount, *this);
 
         // Check for overflow.
-        if (!(isKnownPositive(Step) &&
+        // TODO: This is very conservative.
+        if (!(Step->isOne() &&
               isKnownPredicate(ICmpInst::ICMP_SLT, Start, End)) &&
-            !(isKnownNegative(Step) &&
+            !(Step->isAllOnesValue() &&
               isKnownPredicate(ICmpInst::ICMP_SGT, Start, End)))
           return FullSet;