This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Fold fminnum(X, NaN) to X

Authored by nikic on Sep 9 2020, 1:48 PM.



If one operand to FMINNUM and FMAXNUM is NaN, then the other operand is returned. This makes NaN a neutral element for these operations, which should improve the lowerings from D87391.

Diff Detail

Event Timeline

nikic created this revision.Sep 9 2020, 1:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2020, 1:48 PM
nikic requested review of this revision.Sep 9 2020, 1:48 PM
spatel accepted this revision.Sep 9 2020, 2:37 PM

LGTM - I'll update the other patch after this lands.


Might as well handle the other pair too (possibly in a follow-up patch)? InstSimplify has:

// If one argument is NaN, return other or NaN appropriately.
bool PropagateNaN = IID == Intrinsic::minimum || IID == Intrinsic::maximum;
if (match(Op0, m_NaN()))
  return PropagateNaN ? Op0 : Op1;
if (match(Op1, m_NaN()))
  return PropagateNaN ? Op1 : Op0;
This revision is now accepted and ready to land.Sep 9 2020, 2:37 PM
This revision was automatically updated to reflect the committed changes.
nikic marked an inline comment as done.Sep 9 2020, 2:56 PM
nikic added inline comments.

Good point! I went ahead and directly included it, together with some ARM tests (which conveniently supports both variants).