Skip to content

Commit

Permalink
[DAG] Avoid ComputeNumSignBits call when we know the result is unsigned
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RKSimon committed Oct 29, 2023
1 parent a65070a commit 8d2efd7
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 8d2efd7

Please sign in to comment.