Skip to content

Commit 4a8e489

Browse files
committed
DAG: Preserve flags when expanding fminimum/fmaximum
The operation selection logic here doesn't really work when vector types need to be split. This was also dropping the flags, and losing nnan made the combine from select back to fmin/fmax unrecoverable. Preserve the flags to assist a future commit.
1 parent 98fa0f6 commit 4a8e489

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,11 +1241,11 @@ class SelectionDAG {
12411241
/// Helper function to make it easier to build Select's if you just have
12421242
/// operands and don't want to check for vector.
12431243
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS,
1244-
SDValue RHS) {
1244+
SDValue RHS, SDNodeFlags Flags = SDNodeFlags()) {
12451245
assert(LHS.getValueType() == VT && RHS.getValueType() == VT &&
12461246
"Cannot use select on differing types");
12471247
auto Opcode = Cond.getValueType().isVector() ? ISD::VSELECT : ISD::SELECT;
1248-
return getNode(Opcode, DL, VT, Cond, LHS, RHS);
1248+
return getNode(Opcode, DL, VT, Cond, LHS, RHS, Flags);
12491249
}
12501250

12511251
/// Helper function to make it easier to build SelectCC's if you just have an

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8428,6 +8428,7 @@ SDValue TargetLowering::expandFMINIMUM_FMAXIMUM(SDNode *N,
84288428
EVT VT = N->getValueType(0);
84298429
EVT CCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
84308430
bool IsMax = Opc == ISD::FMAXIMUM;
8431+
SDNodeFlags Flags = N->getFlags();
84318432

84328433
if (VT.isVector() &&
84338434
isOperationLegalOrCustomOrPromote(Opc, VT.getScalarType()))
@@ -8444,15 +8445,15 @@ SDValue TargetLowering::expandFMINIMUM_FMAXIMUM(SDNode *N,
84448445
bool MinMaxMustRespectOrderedZero = false;
84458446

84468447
if (isOperationLegalOrCustom(CompOpcIeee, VT)) {
8447-
MinMax = DAG.getNode(CompOpcIeee, DL, VT, LHS, RHS);
8448+
MinMax = DAG.getNode(CompOpcIeee, DL, VT, LHS, RHS, Flags);
84488449
MinMaxMustRespectOrderedZero = true;
84498450
} else if (isOperationLegalOrCustom(CompOpc, VT)) {
8450-
MinMax = DAG.getNode(CompOpc, DL, VT, LHS, RHS);
8451+
MinMax = DAG.getNode(CompOpc, DL, VT, LHS, RHS, Flags);
84518452
} else {
84528453
// NaN (if exists) will be propagated later, so orderness doesn't matter.
84538454
SDValue Compare =
84548455
DAG.getSetCC(DL, CCVT, LHS, RHS, IsMax ? ISD::SETGT : ISD::SETLT);
8455-
MinMax = DAG.getSelect(DL, VT, Compare, LHS, RHS);
8456+
MinMax = DAG.getSelect(DL, VT, Compare, LHS, RHS, Flags);
84568457
}
84578458

84588459
// Propagate any NaN of both operands
@@ -8461,7 +8462,7 @@ SDValue TargetLowering::expandFMINIMUM_FMAXIMUM(SDNode *N,
84618462
ConstantFP *FPNaN = ConstantFP::get(
84628463
*DAG.getContext(), APFloat::getNaN(DAG.EVTToAPFloatSemantics(VT)));
84638464
MinMax = DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, LHS, RHS, ISD::SETUO),
8464-
DAG.getConstantFP(*FPNaN, DL, VT), MinMax);
8465+
DAG.getConstantFP(*FPNaN, DL, VT), MinMax, Flags);
84658466
}
84668467

84678468
// fminimum/fmaximum requires -0.0 less than +0.0
@@ -8473,11 +8474,11 @@ SDValue TargetLowering::expandFMINIMUM_FMAXIMUM(SDNode *N,
84738474
DAG.getTargetConstant(IsMax ? fcPosZero : fcNegZero, DL, MVT::i32);
84748475
SDValue LCmp = DAG.getSelect(
84758476
DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, LHS, TestZero), LHS,
8476-
MinMax);
8477+
MinMax, Flags);
84778478
SDValue RCmp = DAG.getSelect(
84788479
DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, RHS, TestZero), RHS,
8479-
LCmp);
8480-
MinMax = DAG.getSelect(DL, VT, IsZero, RCmp, MinMax);
8480+
LCmp, Flags);
8481+
MinMax = DAG.getSelect(DL, VT, IsZero, RCmp, MinMax, Flags);
84818482
}
84828483

84838484
return MinMax;

0 commit comments

Comments
 (0)