diff options
author | Max Kazantsev <max.kazantsev@azul.com> | 2017-12-08 12:19:45 +0000 |
---|---|---|
committer | Max Kazantsev <max.kazantsev@azul.com> | 2017-12-08 12:19:45 +0000 |
commit | 99dd56e4a90d8abd45eaa90e506da7645286b967 (patch) | |
tree | 7a0da149a427f07ed42e644c80f83786a910b5d1 /lib/Analysis | |
parent | a72ab5b995d39c45f7f67776712d686bdb85ed00 (diff) |
[SCEV] Fix predicate usage in computeExitLimitFromICmp
In this method, we invoke `SimplifyICmpOperands` which takes the `Cond` predicate
by reference and may change it along with `LHS` and `RHS` SCEVs. But then we invoke
`computeShiftCompareExitLimit` with Values from which the SCEVs have been derived,
these Values have not been modified while `Cond` could be.
One of possible outcomes of this is that we may falsely prove that an infinite loop ends
within some finite number of iterations.
In this patch, we save the original `Cond` and pass it along with original operands.
This logic may be removed in future once `computeShiftCompareExitLimit` works
with SCEVs instead of value operands.
Reviewed By: sanjoy
Differential Revision: https://reviews.llvm.org/D40953
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320142 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/ScalarEvolution.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 9bc8f2dc83d..8001d99603a 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -7074,6 +7074,7 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L, Cond = ExitCond->getPredicate(); else Cond = ExitCond->getInversePredicate(); + const ICmpInst::Predicate OriginalCond = Cond; // Handle common loops like: for (X = "string"; *X; ++X) if (LoadInst *LI = dyn_cast<LoadInst>(ExitCond->getOperand(0))) @@ -7157,7 +7158,7 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L, return ExhaustiveCount; return computeShiftCompareExitLimit(ExitCond->getOperand(0), - ExitCond->getOperand(1), L, Cond); + ExitCond->getOperand(1), L, OriginalCond); } ScalarEvolution::ExitLimit |