summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
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
commitfb78083b1cf696dd3e9264dfe89e99451c62c60d (patch)
tree5e4745f95b0c1f704c794e776c3e90c5fc9c6655 /llvm/lib/Analysis/ScalarEvolution.cpp
parent8c9a6bcae6114a4682ea90fedb87397fa08ea0f4 (diff)
downloadbcm5719-llvm-fb78083b1cf696dd3e9264dfe89e99451c62c60d.tar.gz
bcm5719-llvm-fb78083b1cf696dd3e9264dfe89e99451c62c60d.zip
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! llvm-svn: 161107
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index f0f3b1cb66e..a654648578b 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/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());
OpenPOWER on IntegriCloud