Fix a nasty bug that caused us to unroll EXTREMELY large loops due to overflow
authorChris Lattner <sabre@nondot.org>
Thu, 13 May 2004 20:43:31 +0000 (20:43 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 13 May 2004 20:43:31 +0000 (20:43 +0000)
in the size calculation.

This is not something you want to see:
Loop Unroll: F[main] Loop %no_exit Loop Size = 2 Trip Count = 2147483648 - UNROLLING!

The problem was that 2*2147483648 == 0.

Now we get:
Loop Unroll: F[main] Loop %no_exit Loop Size = 2 Trip Count = 2147483648 - TOO LARGE: 4294967296>100

Thanks to some anonymous person playing with the demo page that repeatedly
caused zion to go into swapping land.  That's one way to ensure you'll get
a quick bugfix.  :)

Testcase here: Transforms/LoopUnroll/2004-05-13-DontUnrollTooMuch.ll

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13564 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp
lib/Transforms/Scalar/LoopUnroll.cpp

index 67b99c56e7e54d6aaf32b4488dd1e65771917ff0..7ef1b5604778f2ac12d71b88c2098a3ed1cae234 100644 (file)
@@ -1475,6 +1475,13 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
   // integers at the end of their ranges...
   //
   if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
+    if (Instruction *LHSI = dyn_cast<Instruction>(Op0))
+      if (LHSI->getOpcode() == Instruction::Div && LHSI->hasOneUse() &&
+          isa<ConstantInt>(LHSI->getOperand(1))) {
+        std::cerr << "COULD FOLD: " << *LHSI;
+        std::cerr << "COULD FOLD: " << I << "\n";
+      }
+
     // Simplify seteq and setne instructions...
     if (I.getOpcode() == Instruction::SetEQ ||
         I.getOpcode() == Instruction::SetNE) {
index 33148200b46a77e6b5f53fb9464afe7b78f550c6..a9cced5ce141381186a0b219b3677371d81a66a9 100644 (file)
@@ -139,9 +139,9 @@ bool LoopUnroll::visitLoop(Loop *L) {
   DEBUG(std::cerr << "Loop Unroll: F[" << BB->getParent()->getName()
         << "] Loop %" << BB->getName() << " Loop Size = " << LoopSize
         << " Trip Count = " << TripCount << " - ");
-  if (LoopSize*TripCount > UnrollThreshold) {
-    DEBUG(std::cerr << "TOO LARGE: " << LoopSize*TripCount << ">"
-                    << UnrollThreshold << "\n");
+  uint64_t Size = (uint64_t)LoopSize*(uint64_t)TripCount;
+  if (Size > UnrollThreshold) {
+    DEBUG(std::cerr << "TOO LARGE: " << Size << ">" << UnrollThreshold << "\n");
     return Changed;
   }
   DEBUG(std::cerr << "UNROLLING!\n");