[llvm] [SelectionDAG] Fix isKnownNeverNaN OR-logic for FMINNUM/FMAXNUM with SNaN (PR #204736)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 1 01:50:25 PDT 2026
================
@@ -6423,10 +6423,20 @@ bool SelectionDAG::isKnownNeverNaN(SDValue Op, const APInt &DemandedElts,
case ISD::FMAXNUM:
case ISD::FMINIMUMNUM:
case ISD::FMAXIMUMNUM: {
- // Only one needs to be known not-nan, since it will be returned if the
- // other ends up being one.
- return isKnownNeverNaN(Op.getOperand(0), DemandedElts, SNaN, Depth + 1) ||
- isKnownNeverNaN(Op.getOperand(1), DemandedElts, SNaN, Depth + 1);
+ // The result is a NaN only if both operands are NaN, so it is never NaN
+ // (and hence never a signaling NaN) if either operand is known to never be
+ // NaN.
+ if (isKnownNeverNaN(Op.getOperand(0), DemandedElts, false, Depth + 1) ||
+ isKnownNeverNaN(Op.getOperand(1), DemandedElts, false, Depth + 1))
+ return true;
+ // Otherwise, for the signaling-NaN query, these do not quiet a signaling
+ // NaN: an input signaling NaN may be returned unchanged, so the result is
+ // never a signaling NaN only if both operands are known to never be one.
+ if (SNaN &&
+ isKnownNeverNaN(Op.getOperand(0), DemandedElts, true, Depth + 1) &&
----------------
ayrai-gb wrote:
Thanks for the review!
I took a look at `computeKnownFPClass` and the DAG-level `SelectionDAG::computeKnownFPClass` doesn't currently handle `FMINNUM` / `FMAXNUM` / `FMINIMUMNUM` / `FMAXIMUMNUM`. Its switch only covers a small set of opcodes and otherwise falls back to the target hook, so min/max nodes currently come back as unknown there. Only the IR-level implementation (`minMaxLike` in `ValueTracking`) seems to handle them today.
Is there a plan to add similar min/max handling to the DAG-level `computeKnownFPClass`, or am I missing an existing path?
https://github.com/llvm/llvm-project/pull/204736
More information about the llvm-commits
mailing list