Skip to content

Commit eca05fd

Browse files
authored
[X86] Switch operands order for FMINIMUMNUM/FMAXIMUMNUM (#147193)
When optimizate for NaN, switch operands order for FMINIMUMNUM/FMAXIMUMNUM. Fixes #135313
1 parent dc5d353 commit eca05fd

File tree

2 files changed

+108
-158
lines changed

2 files changed

+108
-158
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29422,16 +29422,22 @@ static SDValue LowerFMINIMUM_FMAXIMUM(SDValue Op, const X86Subtarget &Subtarget,
2942229422
Op->getFlags().hasNoNaNs() || (IsXNeverNaN && IsYNeverNaN);
2942329423

2942429424
// If we did no ordering operands for signed zero handling and we need
29425-
// to process NaN and we know that the second operand is not NaN then put
29426-
// it in first operand and we will not need to post handle NaN after max/min.
29427-
if (IgnoreSignedZero && !IgnoreNaN && DAG.isKnownNeverNaN(NewY))
29425+
// to process NaN and we know that one of the operands is not NaN then:
29426+
// - For minimum/maximum, put it in the first operand,
29427+
// - For minimumnum/maximumnum, put it in the second operand,
29428+
// and we will not need to post handle NaN after max/min.
29429+
if (IgnoreSignedZero && !IgnoreNaN &&
29430+
DAG.isKnownNeverNaN(IsNum ? NewX : NewY))
2942829431
std::swap(NewX, NewY);
2942929432

2943029433
SDValue MinMax = DAG.getNode(MinMaxOp, DL, VT, NewX, NewY, Op->getFlags());
2943129434

29432-
if (IgnoreNaN || DAG.isKnownNeverNaN(NewX))
29435+
if (IgnoreNaN || DAG.isKnownNeverNaN(IsNum ? NewY : NewX))
2943329436
return MinMax;
2943429437

29438+
if (DAG.isKnownNeverNaN(NewX))
29439+
NewX = NewY;
29440+
2943529441
SDValue IsNaN =
2943629442
DAG.getSetCC(DL, SetCCType, NewX, NewX, IsNum ? ISD::SETO : ISD::SETUO);
2943729443

0 commit comments

Comments
 (0)