Skip to content

Commit 16a5fd3

Browse files
authored
DAG: Use flags in isLegalToCombineMinNumMaxNum (#93555)
1 parent 7bea41e commit 16a5fd3

File tree

2 files changed

+1768
-8
lines changed

2 files changed

+1768
-8
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11186,17 +11186,19 @@ SDValue DAGCombiner::visitCTPOP(SDNode *N) {
1118611186
return SDValue();
1118711187
}
1118811188

11189-
// FIXME: This should be checking for no signed zeros on individual operands, as
11190-
// well as no nans.
1119111189
static bool isLegalToCombineMinNumMaxNum(SelectionDAG &DAG, SDValue LHS,
11192-
SDValue RHS,
11190+
SDValue RHS, const SDNodeFlags Flags,
1119311191
const TargetLowering &TLI) {
11194-
const TargetOptions &Options = DAG.getTarget().Options;
1119511192
EVT VT = LHS.getValueType();
11193+
if (!VT.isFloatingPoint())
11194+
return false;
11195+
11196+
const TargetOptions &Options = DAG.getTarget().Options;
1119611197

11197-
return Options.NoSignedZerosFPMath && VT.isFloatingPoint() &&
11198+
return (Flags.hasNoSignedZeros() || Options.NoSignedZerosFPMath) &&
1119811199
TLI.isProfitableToCombineMinNumMaxNum(VT) &&
11199-
DAG.isKnownNeverNaN(LHS) && DAG.isKnownNeverNaN(RHS);
11200+
(Flags.hasNoNaNs() ||
11201+
(DAG.isKnownNeverNaN(RHS) && DAG.isKnownNeverNaN(LHS)));
1120011202
}
1120111203

1120211204
static SDValue combineMinNumMaxNumImpl(const SDLoc &DL, EVT VT, SDValue LHS,
@@ -11674,7 +11676,7 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) {
1167411676
// select (fcmp gt x, y), x, y -> fmaxnum x, y
1167511677
//
1167611678
// This is OK if we don't care what happens if either operand is a NaN.
11677-
if (N0.hasOneUse() && isLegalToCombineMinNumMaxNum(DAG, N1, N2, TLI))
11679+
if (N0.hasOneUse() && isLegalToCombineMinNumMaxNum(DAG, N1, N2, Flags, TLI))
1167811680
if (SDValue FMinMax =
1167911681
combineMinNumMaxNum(DL, VT, Cond0, Cond1, N1, N2, CC))
1168011682
return FMinMax;
@@ -12267,7 +12269,8 @@ SDValue DAGCombiner::visitVSELECT(SDNode *N) {
1226712269
// This is OK if we don't care about what happens if either operand is a
1226812270
// NaN.
1226912271
//
12270-
if (N0.hasOneUse() && isLegalToCombineMinNumMaxNum(DAG, LHS, RHS, TLI)) {
12272+
if (N0.hasOneUse() &&
12273+
isLegalToCombineMinNumMaxNum(DAG, LHS, RHS, N->getFlags(), TLI)) {
1227112274
if (SDValue FMinMax = combineMinNumMaxNum(DL, VT, LHS, RHS, N1, N2, CC))
1227212275
return FMinMax;
1227312276
}

0 commit comments

Comments
 (0)