[llvm] [DAG] visitTRUNCATE - early out from computeKnownBits/ComputeNumSignBits failures. NFC. (PR #154111)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 18 06:19:32 PDT 2025
================
@@ -16332,25 +16332,22 @@ SDValue DAGCombiner::visitTRUNCATE(SDNode *N) {
// (trunc (abdu/abds a, b)) -> (abdu/abds (trunc a), (trunc b))
if ((!LegalOperations || N0.hasOneUse()) &&
TLI.isOperationLegal(N0.getOpcode(), VT)) {
- EVT SrcVT = N0.getValueType();
EVT TruncVT = VT;
unsigned SrcBits = SrcVT.getScalarSizeInBits();
unsigned TruncBits = TruncVT.getScalarSizeInBits();
- unsigned NeededBits = SrcBits - TruncBits;
SDValue A = N0.getOperand(0);
SDValue B = N0.getOperand(1);
bool CanFold = false;
if (N0.getOpcode() == ISD::ABDU) {
- KnownBits KnownA = DAG.computeKnownBits(A);
- KnownBits KnownB = DAG.computeKnownBits(B);
- CanFold = KnownA.countMinLeadingZeros() >= NeededBits &&
- KnownB.countMinLeadingZeros() >= NeededBits;
+ APInt UpperBits = APInt::getBitsSetFrom(SrcBits, TruncBits);
+ CanFold = DAG.MaskedValueIsZero(A, UpperBits) &&
+ DAG.MaskedValueIsZero(B, UpperBits);
----------------
woruyu wrote:
why to check the second oprand for ABDU/ABDS firstly, in my understadning, the second is smaller, the possibility of MaskedValueIsZero will be bigger.
https://github.com/llvm/llvm-project/pull/154111
More information about the llvm-commits
mailing list