summaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar/LoopUnroll.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-03-02 23:31:34 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-03-02 23:31:34 +0000
commit4e69f48a0a6ef9b36c8f17d6ad4e3b6998c81078 (patch)
tree9b4878aed5dc4d068932f355a03ae0ded4cd9408 /lib/Transforms/Scalar/LoopUnroll.cpp
parentae6421935bd3f2e48346fd16a21297ed1a28fd32 (diff)
downloadexternal_llvm-4e69f48a0a6ef9b36c8f17d6ad4e3b6998c81078.zip
external_llvm-4e69f48a0a6ef9b36c8f17d6ad4e3b6998c81078.tar.gz
external_llvm-4e69f48a0a6ef9b36c8f17d6ad4e3b6998c81078.tar.bz2
Guard against huge loop trip counts in an APInt safe way.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34858 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopUnroll.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopUnroll.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/LoopUnroll.cpp b/lib/Transforms/Scalar/LoopUnroll.cpp
index d1770da..b0db806 100644
--- a/lib/Transforms/Scalar/LoopUnroll.cpp
+++ b/lib/Transforms/Scalar/LoopUnroll.cpp
@@ -190,10 +190,15 @@ bool LoopUnroll::visitLoop(Loop *L) {
ConstantInt *TripCountC = dyn_cast_or_null<ConstantInt>(L->getTripCount());
if (!TripCountC) return Changed; // Must have constant trip count!
- uint64_t TripCountFull = TripCountC->getZExtValue();
- if (TripCountFull != TripCountC->getZExtValue() || TripCountFull == 0)
+ // Guard against huge trip counts. This also guards against assertions in
+ // APInt from the use of getZExtValue, below.
+ if (TripCountC->getValue().getActiveBits() > 32)
return Changed; // More than 2^32 iterations???
+ uint64_t TripCountFull = TripCountC->getZExtValue();
+ if (TripCountFull == 0)
+ return Changed; // Zero iteraitons?
+
unsigned LoopSize = ApproximateLoopSize(L);
DOUT << "Loop Unroll: F[" << Header->getParent()->getName()
<< "] Loop %" << Header->getName() << " Loop Size = "