[llvm] 8d2efd7 - [DAG] Avoid ComputeNumSignBits call when we know the result is unsigned

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 29 10:35:47 PDT 2023


Author: Simon Pilgrim
Date: 2023-10-29T17:35:24Z
New Revision: 8d2efd7427ff01277f68a95ec27b83193c1c15fb

URL: https://github.com/llvm/llvm-project/commit/8d2efd7427ff01277f68a95ec27b83193c1c15fb
DIFF: https://github.com/llvm/llvm-project/commit/8d2efd7427ff01277f68a95ec27b83193c1c15fb.diff

LOG: [DAG] Avoid ComputeNumSignBits call when we know the result is unsigned

D146121 needs to set the NSW flag, but given the result is NUW then we know that the result has leading zeros, so we don't need to call ComputeNumSignBits - just reuse the existing KnownBits value instead.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index a7e8d6f8cc8e2bf..de4a3098c935142 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -1834,8 +1834,7 @@ bool TargetLowering::SimplifyDemandedBits(
           // that the upper bits of the shift result are known to be zero,
           // which is equivalent to the narrow shift being NUW.
           if (bool IsNUW = (Known.countMinLeadingZeros() >= HalfWidth)) {
-            unsigned NumSignBits = TLO.DAG.ComputeNumSignBits(Op0, Depth + 1);
-            bool IsNSW = NumSignBits > (ShAmt + HalfWidth);
+            bool IsNSW = Known.countMinSignBits() > HalfWidth;
             SDNodeFlags Flags;
             Flags.setNoSignedWrap(IsNSW);
             Flags.setNoUnsignedWrap(IsNUW);


        


More information about the llvm-commits mailing list