summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
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
commit29fe20a98b0616be8f45c8cea2f49d096e78526d (patch)
tree4c8758b9c1c5c0beadf8f48367f465f3e648bd02 /llvm/lib/Transforms
parentdeaea25eb9813e8d0acde981758c438825aa6fbc (diff)
downloadbcm5719-llvm-29fe20a98b0616be8f45c8cea2f49d096e78526d.tar.gz
bcm5719-llvm-29fe20a98b0616be8f45c8cea2f49d096e78526d.zip
Guard against huge loop trip counts in an APInt safe way.
llvm-svn: 34858
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopUnroll.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnroll.cpp b/llvm/lib/Transforms/Scalar/LoopUnroll.cpp
index d1770da8fce..b0db806a495 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnroll.cpp
+++ b/llvm/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 = "
OpenPOWER on IntegriCloud