[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Reid Spencer reid at x10sys.com
Fri Mar 23 17:42:41 PDT 2007



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.681 -> 1.682
---
Log message:

For PR1205: http://llvm.org/PR1205 :
Convert some calls to ConstantInt::getZExtValue() into getValue() and 
use APInt facilities in the subsequent computations.


---
Diffs of the changes:  (+11 -12)

 InstructionCombining.cpp |   23 +++++++++++------------
 1 files changed, 11 insertions(+), 12 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.681 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.682
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.681	Fri Mar 23 16:24:59 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Fri Mar 23 19:42:08 2007
@@ -733,7 +733,7 @@
       assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); 
       KnownZero <<= ShiftAmt;
       KnownOne  <<= ShiftAmt;
-      KnownZero |= APInt(BitWidth, 1ULL).shl(ShiftAmt)-1;  // low bits known zero.
+      KnownZero |= APInt(BitWidth, 1ULL).shl(ShiftAmt)-1;  // low bits known 0
       return;
     }
     break;
@@ -2213,12 +2213,12 @@
       return RHS->isAllOnesValue();
     case ICmpInst::ICMP_UGE: 
       // True if LHS u>= RHS and RHS == high-bit-mask (2^7, 2^15, 2^31, etc)
-      return RHS->getZExtValue() == (1ULL << 
-        (RHS->getType()->getPrimitiveSizeInBits()-1));
+      return RHS->getValue() == 
+             APInt::getSignBit(RHS->getType()->getPrimitiveSizeInBits());
     case ICmpInst::ICMP_UGT:
       // True if LHS u> RHS and RHS == high-bit-mask - 1
-      return RHS->getZExtValue() ==
-        (1ULL << (RHS->getType()->getPrimitiveSizeInBits()-1))-1;
+      return RHS->getValue() ==
+             APInt::getSignedMaxValue(RHS->getType()->getPrimitiveSizeInBits());
     default:
       return false;
   }
@@ -2553,7 +2553,7 @@
   } else if (I->getOpcode() == Instruction::And) {
     if (ConstantInt *RHS = dyn_cast<ConstantInt>(I->getOperand(1))) {
       // X & 0xFFF0 is known to be a multiple of 16.
-      unsigned Zeros = CountTrailingZeros_64(RHS->getZExtValue());
+      uint32_t Zeros = RHS->getValue().countTrailingZeros();
       if (Zeros != V->getType()->getPrimitiveSizeInBits())
         return ConstantExpr::getShl(Result, 
                                     ConstantInt::get(Result->getType(), Zeros));
@@ -3082,18 +3082,17 @@
 // MSB, so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs.  0x0F0F0000 is
 // not, since all 1s are not contiguous.
 static bool isRunOfOnes(ConstantInt *Val, unsigned &MB, unsigned &ME) {
-  uint64_t V = Val->getZExtValue();
-  if (!isShiftedMask_64(V)) return false;
+  APInt V = Val->getValue();
+  uint32_t BitWidth = Val->getType()->getBitWidth();
+  if (!APIntOps::isShiftedMask(BitWidth, V)) return false;
 
   // look for the first zero bit after the run of ones
-  MB = 64-CountLeadingZeros_64((V - 1) ^ V);
+  MB = BitWidth - ((V - 1) ^ V).countLeadingZeros();
   // look for the first non-zero bit
-  ME = 64-CountLeadingZeros_64(V);
+  ME = V.getActiveBits(); 
   return true;
 }
 
-
-
 /// FoldLogicalPlusAnd - This is part of an expression (LHS +/- RHS) & Mask,
 /// where isSub determines whether the operator is a sub.  If we can fold one of
 /// the following xforms:






More information about the llvm-commits mailing list