[llvm] 243b7aa - [SelectionDAG] Use KnownBits::countMinSignBits() to simplify the end of ComputeNumSignBits.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 31 17:32:43 PST 2021


Author: Craig Topper
Date: 2021-12-31T17:29:57-08:00
New Revision: 243b7aaf51e8ad04910ea1f8779db07d6fee2481

URL: https://github.com/llvm/llvm-project/commit/243b7aaf51e8ad04910ea1f8779db07d6fee2481
DIFF: https://github.com/llvm/llvm-project/commit/243b7aaf51e8ad04910ea1f8779db07d6fee2481.diff

LOG: [SelectionDAG] Use KnownBits::countMinSignBits() to simplify the end of ComputeNumSignBits.

This matches what is done in ValueTracking.cpp

Reviewed By: RKSimon, foad

Differential Revision: https://reviews.llvm.org/D116423

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 2ae0d4df7b77..d14647d0eb0a 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4294,21 +4294,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
   // Finally, if we can prove that the top bits of the result are 0's or 1's,
   // use this information.
   KnownBits Known = computeKnownBits(Op, DemandedElts, Depth);
-
-  APInt Mask;
-  if (Known.isNonNegative()) {        // sign bit is 0
-    Mask = Known.Zero;
-  } else if (Known.isNegative()) {  // sign bit is 1;
-    Mask = Known.One;
-  } else {
-    // Nothing known.
-    return FirstAnswer;
-  }
-
-  // Okay, we know that the sign bit in Mask is set.  Use CLO to determine
-  // the number of identical bits in the top of the input value.
-  Mask <<= Mask.getBitWidth()-VTBits;
-  return std::max(FirstAnswer, Mask.countLeadingOnes());
+  return std::max(FirstAnswer, Known.countMinSignBits());
 }
 
 unsigned SelectionDAG::ComputeMinSignedBits(SDValue Op, unsigned Depth) const {


        


More information about the llvm-commits mailing list