Use ScalarEvolution's new GetMinSignBits and GetMinLeadingZeros
authorDan Gohman <gohman@apple.com>
Sat, 20 Jun 2009 00:32:22 +0000 (00:32 +0000)
committerDan Gohman <gohman@apple.com>
Sat, 20 Jun 2009 00:32:22 +0000 (00:32 +0000)
in the loop backedge-taken count computation of the maximum
possible trip count.

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

lib/Analysis/ScalarEvolution.cpp

index 2dab2f367de26ee730606e98fd1e1852fe1fbc8d..465807ecacb4e47a3a6a3a699ee3b7f2ffdb909d 100644 (file)
@@ -3836,9 +3836,12 @@ HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
                      : getUMaxExpr(RHS, Start);
 
     // Determine the maximum constant end value.
-    SCEVHandle MaxEnd = isa<SCEVConstant>(End) ? End :
-      getConstant(isSigned ? APInt::getSignedMaxValue(BitWidth) :
-                             APInt::getMaxValue(BitWidth));
+    SCEVHandle MaxEnd =
+      isa<SCEVConstant>(End) ? End :
+      getConstant(isSigned ? APInt::getSignedMaxValue(BitWidth)
+                               .ashr(GetMinSignBits(End) - 1) :
+                             APInt::getMaxValue(BitWidth)
+                               .lshr(GetMinLeadingZeros(End)));
 
     // Finally, we subtract these two values and divide, rounding up, to get
     // the number of times the backedge is executed.