Skip to content

Commit cd71163

Browse files
committed
expandFMINIMUMNUM_FMAXIMUMNUM: Improve compare between zeros
1. On GPR32 platform, expandIS_FPCLASS may fail due to ISD::BITCAST double to int64 may fail. Let's FP_ROUND double to float first. Since we use it if MinMax is zero only, so the flushing won't break anything. 2. Only one IS_FPCLASS is needed. MinMax will always be RHS if equal. So we can select between LHS and MinMax. It will even safe if FP_ROUND flush a small LHS, as if LHS is not zero then, MinMax won't be Zero, so we will always use MinMax.
1 parent 63861d6 commit cd71163

File tree

2 files changed

+745
-45
lines changed

2 files changed

+745
-45
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8690,6 +8690,7 @@ SDValue TargetLowering::expandFMINIMUMNUM_FMAXIMUMNUM(SDNode *Node,
86908690
RHS = DAG.getSelectCC(DL, RHS, RHS, LHS, RHS, ISD::SETUO);
86918691
}
86928692

8693+
// Please always prefer RHS if equal.
86938694
SDValue MinMax =
86948695
DAG.getSelectCC(DL, LHS, RHS, LHS, RHS, IsMax ? ISD::SETGT : ISD::SETLT);
86958696

@@ -8704,13 +8705,27 @@ SDValue TargetLowering::expandFMINIMUMNUM_FMAXIMUMNUM(SDNode *Node,
87048705
DAG.getTargetConstant(IsMax ? fcPosZero : fcNegZero, DL, MVT::i32);
87058706
SDValue IsZero = DAG.getSetCC(DL, CCVT, MinMax,
87068707
DAG.getConstantFP(0.0, DL, VT), ISD::SETEQ);
8707-
SDValue LCmp = DAG.getSelect(
8708-
DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, LHS, TestZero), LHS,
8708+
unsigned BitSize = VT.getScalarSizeInBits();
8709+
EVT IntVT = EVT::getIntegerVT(*DAG.getContext(), BitSize);
8710+
EVT FloatVT = EVT::getFloatingPointVT(32);
8711+
if (VT.isVector()) {
8712+
IntVT =
8713+
EVT::getVectorVT(*DAG.getContext(), IntVT, VT.getVectorElementCount());
8714+
FloatVT = EVT::getVectorVT(*DAG.getContext(), FloatVT,
8715+
VT.getVectorElementCount());
8716+
}
8717+
SDValue LHSTrunc = LHS;
8718+
if (!isOperationLegal(ISD::BITCAST, IntVT) &&
8719+
!isOperationLegal(ISD::IS_FPCLASS, VT)) {
8720+
LHSTrunc = DAG.getNode(ISD::FP_ROUND, DL, FloatVT, LHS,
8721+
DAG.getIntPtrConstant(0, DL, /*isTarget=*/true));
8722+
}
8723+
// It's OK to select from LHS and MinMax, with only one ISD::IS_FPCLASS, as
8724+
// we preferred RHS when generate MinMax, if the operands are equal.
8725+
SDValue RetZero = DAG.getSelect(
8726+
DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, LHSTrunc, TestZero), LHS,
87098727
MinMax, Flags);
8710-
SDValue RCmp = DAG.getSelect(
8711-
DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, RHS, TestZero), RHS, LCmp,
8712-
Flags);
8713-
return DAG.getSelect(DL, VT, IsZero, RCmp, MinMax, Flags);
8728+
return DAG.getSelect(DL, VT, IsZero, RetZero, MinMax, Flags);
87148729
}
87158730

87168731
/// Returns a true value if if this FPClassTest can be performed with an ordered

0 commit comments

Comments
 (0)