Skip to content

Commit b035f20

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 4ce40cd commit b035f20

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
@@ -8681,6 +8681,7 @@ SDValue TargetLowering::expandFMINIMUMNUM_FMAXIMUMNUM(SDNode *Node,
86818681
RHS = DAG.getSelectCC(DL, RHS, RHS, LHS, RHS, ISD::SETUO);
86828682
}
86838683

8684+
// Please always prefer RHS if equal.
86848685
SDValue MinMax =
86858686
DAG.getSelectCC(DL, LHS, RHS, LHS, RHS, IsMax ? ISD::SETGT : ISD::SETLT);
86868687

@@ -8693,13 +8694,27 @@ SDValue TargetLowering::expandFMINIMUMNUM_FMAXIMUMNUM(SDNode *Node,
86938694
DAG.getTargetConstant(IsMax ? fcPosZero : fcNegZero, DL, MVT::i32);
86948695
SDValue IsZero = DAG.getSetCC(DL, CCVT, MinMax,
86958696
DAG.getConstantFP(0.0, DL, VT), ISD::SETEQ);
8696-
SDValue LCmp = DAG.getSelect(
8697-
DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, LHS, TestZero), LHS,
8697+
unsigned BitSize = VT.getScalarSizeInBits();
8698+
EVT IntVT = EVT::getIntegerVT(*DAG.getContext(), BitSize);
8699+
EVT FloatVT = EVT::getFloatingPointVT(32);
8700+
if (VT.isVector()) {
8701+
IntVT =
8702+
EVT::getVectorVT(*DAG.getContext(), IntVT, VT.getVectorElementCount());
8703+
FloatVT = EVT::getVectorVT(*DAG.getContext(), FloatVT,
8704+
VT.getVectorElementCount());
8705+
}
8706+
SDValue LHSTrunc = LHS;
8707+
if (!isOperationLegal(ISD::BITCAST, IntVT) &&
8708+
!isOperationLegal(ISD::IS_FPCLASS, VT)) {
8709+
LHSTrunc = DAG.getNode(ISD::FP_ROUND, DL, FloatVT, LHS,
8710+
DAG.getIntPtrConstant(0, DL, /*isTarget=*/true));
8711+
}
8712+
// It's OK to select from LHS and MinMax, with only one ISD::IS_FPCLASS, as
8713+
// we preferred RHS when generate MinMax, if the operands are equal.
8714+
SDValue RetZero = DAG.getSelect(
8715+
DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, LHSTrunc, TestZero), LHS,
86988716
MinMax, Flags);
8699-
SDValue RCmp = DAG.getSelect(
8700-
DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, RHS, TestZero), RHS, LCmp,
8701-
Flags);
8702-
return DAG.getSelect(DL, VT, IsZero, RCmp, MinMax, Flags);
8717+
return DAG.getSelect(DL, VT, IsZero, RetZero, MinMax, Flags);
87038718
}
87048719

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

0 commit comments

Comments
 (0)