summaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2012-08-01 09:14:36 +0000
committerNick Lewycky <nicholas@mxc.ca>2012-08-01 09:14:36 +0000
commit6ce2471806316ae9e1c7715f703c380d4f4311b6 (patch)
tree3ebc81d806c7416849a29dad540e4ad6451e98ee /lib/Analysis
parent147d9e05116518461653695a6022f6109f0eb936 (diff)
downloadllvm-6ce2471806316ae9e1c7715f703c380d4f4311b6.tar.gz
llvm-6ce2471806316ae9e1c7715f703c380d4f4311b6.tar.bz2
llvm-6ce2471806316ae9e1c7715f703c380d4f4311b6.tar.xz
Stay rational; don't assert trying to take the square root of a negative value.
If it's negative, the loop is already proven to be infinite. Fixes PR13489! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161107 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/ScalarEvolution.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index f0f3b1cb66..a654648578 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -5370,6 +5370,12 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) {
SqrtTerm *= B;
SqrtTerm -= Four * (A * C);
+ if (SqrtTerm.isNegative()) {
+ // The loop is provably infinite.
+ const SCEV *CNC = SE.getCouldNotCompute();
+ return std::make_pair(CNC, CNC);
+ }
+
// Compute sqrt(B^2-4ac). This is guaranteed to be the nearest
// integer value or else APInt::sqrt() will assert.
APInt SqrtVal(SqrtTerm.sqrt());