[llvm] [SelectionDAG]: Have isKnownNeverZero treat SRL like division if all else fails (PR #89523)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 20 19:08:29 PDT 2024
================
@@ -5443,10 +5443,17 @@ bool SelectionDAG::isKnownNeverZero(SDValue Op, unsigned Depth) const {
if (ValKnown.isNegative())
return true;
// If max shift cnt of known ones is non-zero, result is non-zero.
- APInt MaxCnt = computeKnownBits(Op.getOperand(1), Depth + 1).getMaxValue();
+ const KnownBits Shift = computeKnownBits(Op.getOperand(1), Depth + 1);
+ APInt MaxCnt = Shift.getMaxValue();
if (MaxCnt.ult(ValKnown.getBitWidth()) &&
!ValKnown.One.lshr(MaxCnt).isZero())
return true;
+ // We try to see if we can turn it into a division
+ const KnownBits One =
+ KnownBits::makeConstant(APInt(ValKnown.getBitWidth(), 1));
+
+ if (KnownBits::uge(ValKnown, KnownBits::lshr(One, Shift)))
----------------
topperc wrote:
Doesn't SRA reach here too? Is this also correct for SRA?
https://github.com/llvm/llvm-project/pull/89523
More information about the llvm-commits
mailing list