Make ConstantRange::truncate a bit more efficient.
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 24 Nov 2011 17:24:33 +0000 (17:24 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 24 Nov 2011 17:24:33 +0000 (17:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145122 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/ConstantRange.cpp

index c29cb53fb9c5d738cc3c0c19324005fe3cb4ad8f..57434795070e21388705b7936bb4c7af4ddca464 100644 (file)
@@ -466,10 +466,8 @@ ConstantRange ConstantRange::signExtend(uint32_t DstTySize) const {
 /// correspond to the possible range of values as if the source range had been
 /// truncated to the specified type.
 ConstantRange ConstantRange::truncate(uint32_t DstTySize) const {
-  unsigned SrcTySize = getBitWidth();
-  assert(SrcTySize > DstTySize && "Not a value truncation");
-  APInt Size(APInt::getLowBitsSet(SrcTySize, DstTySize));
-  if (isFullSet() || getSetSize().ugt(Size))
+  assert(getBitWidth() > DstTySize && "Not a value truncation");
+  if (isFullSet() || getSetSize().getActiveBits() > DstTySize)
     return ConstantRange(DstTySize, /*isFullSet=*/true);
 
   return ConstantRange(Lower.trunc(DstTySize), Upper.trunc(DstTySize));