[llvm-dev] Why does FPBinOp(X, undef) -> NaN?

Cameron McInally via llvm-dev llvm-dev at lists.llvm.org
Fri Feb 7 09:20:51 PST 2020

I came across this comment in SelectionDAG.cpp:

  case ISD::FADD:
  case ISD::FSUB:
  case ISD::FMUL:
  case ISD::FDIV:
  case ISD::FREM:
    // If both operands are undef, the result is undef. If 1 operand is undef,
    // the result is NaN. This should match the behavior of the IR optimizer.

That isn't intuitive to me. I would have expected a binary FP
operation with one undef operand to fold to undef. Does anyone know
the reasoning behind that decision? I don't see the value added in
returning a NaN here.


More information about the llvm-dev mailing list