[llvm] [SelectionDAG] Second SimplifyDemandedBits pass for AND RHS using LHS known zeros (scalar only) (PR #185235)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 9 10:24:12 PDT 2026
================
@@ -1513,6 +1513,19 @@ bool TargetLowering::SimplifyDemandedBits(
Known2, TLO, Depth + 1))
return true;
+ // FIXME: Op1Opc checks are to avoid regressions in
+ // x86 codegen.
+ unsigned Op1Opc = Op1.getOpcode();
+ if (!VT.isVector() &&
+ (Op1Opc == ISD::ZERO_EXTEND || Op1Opc == ISD::SIGN_EXTEND ||
+ Op1Opc == ISD::ANY_EXTEND || Op1Opc == ISD::TRUNCATE) &&
+ (~Known2.Zero & DemandedBits) != DemandedBits) {
+ Known2 = TLO.DAG.computeKnownBits(Op0, DemandedElts, Depth + 1);
+ if (SimplifyDemandedBits(Op1, ~Known2.Zero & DemandedBits, DemandedElts,
+ Known, TLO, Depth + 1))
+ return true;
+ }
+
----------------
jayfoad wrote:
In this whole block we now have three recursive calls to SimplifyDemandedBits plus one call to computeKnownBits. Would it make sense to refactor it like:
```
Known = TLO.DAG.computeKnownBits(Op1, DemandedElts, Depth + 1);
if (SimplifyDemandedBits(Op0, ~Known.Zero & DemandedBits, DemandedElts, Dummy, TLO, Depth + 1))
return true;
Known2 = TLO.DAG.computeKnownBits(Op0, DemandedElts, Depth + 1);
if (SimplifyDemandedBits(Op1, ~Known2.Zero & DemandedBits, DemandedElts, Dummy, TLO, Depth + 1))
return true;
```
https://github.com/llvm/llvm-project/pull/185235
More information about the llvm-commits
mailing list