]> granicus.if.org Git - llvm/commitdiff
[InstCombine] Use APInt bit counting methods to avoid a temporary APInt. NFC
authorCraig Topper <craig.topper@gmail.com>
Thu, 27 Apr 2017 04:51:25 +0000 (04:51 +0000)
committerCraig Topper <craig.topper@gmail.com>
Thu, 27 Apr 2017 04:51:25 +0000 (04:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301516 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCalls.cpp

index 7985ec17ec9876127769cb6026a267f5eca9259a..597f1d958063ebc668f33a71c985c1c9e160a8ba 100644 (file)
@@ -1384,17 +1384,17 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombiner &IC) {
 
   // Create a mask for bits above (ctlz) or below (cttz) the first known one.
   bool IsTZ = II.getIntrinsicID() == Intrinsic::cttz;
-  unsigned NumMaskBits = IsTZ ? Known.One.countTrailingZeros()
-                              : Known.One.countLeadingZeros();
-  APInt Mask = IsTZ ? APInt::getLowBitsSet(BitWidth, NumMaskBits)
-                    : APInt::getHighBitsSet(BitWidth, NumMaskBits);
+  unsigned PossibleZeros = IsTZ ? Known.One.countTrailingZeros()
+                                : Known.One.countLeadingZeros();
+  unsigned DefiniteZeros = IsTZ ? Known.Zero.countTrailingOnes()
+                                : Known.Zero.countLeadingOnes();
 
   // If all bits above (ctlz) or below (cttz) the first known one are known
   // zero, this value is constant.
   // FIXME: This should be in InstSimplify because we're replacing an
   // instruction with a constant.
-  if (Mask.isSubsetOf(Known.Zero)) {
-    auto *C = ConstantInt::get(IT, APInt(BitWidth, NumMaskBits));
+  if (PossibleZeros == DefiniteZeros) {
+    auto *C = ConstantInt::get(IT, DefiniteZeros);
     return IC.replaceInstUsesWith(II, C);
   }