[llvm] [SelectionDAG][AMDGPU] Fold mul24 with an AND operand whose low bits are zero (PR #224537)
Harrison Hao via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 05:44:05 PDT 2026
================
@@ -826,6 +826,11 @@ SDValue TargetLowering::SimplifyMultipleUseDemandedBits(
LHSKnown = DAG.computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
RHSKnown = DAG.computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
+ // If either operand is known zero for every demanded bit, the result is
+ // zero.
+ if (DemandedBits.isSubsetOf(LHSKnown.Zero | RHSKnown.Zero))
+ return DAG.getConstant(0, SDLoc(Op), VT);
----------------
harrisonGPU wrote:
Thanks @RKSimon, simplifyMul24 calls `SimplifyMultipleUseDemandedBits` first. For `x & 0xff000000`, the existing `DemandedBits.isSubsetOf(RHSKnown.Zero | LHSKnown.One)` rule returns the constant operand `0xff000000`, so simplifyMul24 rebuilds the node and returns before `SimplifyDemandedBits` is reached. That constant isn't null, so the multiply isn't folded. Checking the all-zero case first returns 0 instead, which isNullConstant then catches.
https://github.com/llvm/llvm-project/pull/224537
More information about the llvm-commits
mailing list