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

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 30 13:45:45 PST 2021


craig.topper created this revision.
craig.topper added reviewers: spatel, RKSimon.
Herald added subscribers: foad, ecnelises, hiraditya.
craig.topper requested review of this revision.
Herald added a project: LLVM.

This matches what is done in ValueTracking.cpp


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116423

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


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4294,21 +4294,7 @@
   // 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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116423.396718.patch
Type: text/x-patch
Size: 1044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211230/d544a710/attachment.bin>


More information about the llvm-commits mailing list