[llvm] expandFMINIMUMNUM_FMAXIMUMNUM: Improve compare between zeros (PR #140193)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 9 00:45:05 PDT 2025
================
@@ -8704,13 +8705,27 @@ SDValue TargetLowering::expandFMINIMUMNUM_FMAXIMUMNUM(SDNode *Node,
DAG.getTargetConstant(IsMax ? fcPosZero : fcNegZero, DL, MVT::i32);
SDValue IsZero = DAG.getSetCC(DL, CCVT, MinMax,
DAG.getConstantFP(0.0, DL, VT), ISD::SETEQ);
- SDValue LCmp = DAG.getSelect(
- DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, LHS, TestZero), LHS,
+ unsigned BitSize = VT.getScalarSizeInBits();
+ EVT IntVT = EVT::getIntegerVT(*DAG.getContext(), BitSize);
+ EVT FloatVT = EVT::getFloatingPointVT(32);
+ if (VT.isVector()) {
+ IntVT =
+ EVT::getVectorVT(*DAG.getContext(), IntVT, VT.getVectorElementCount());
+ FloatVT = EVT::getVectorVT(*DAG.getContext(), FloatVT,
+ VT.getVectorElementCount());
+ }
+ SDValue LHSTrunc = LHS;
+ if (!isOperationLegal(ISD::BITCAST, IntVT) &&
+ !isOperationLegal(ISD::IS_FPCLASS, VT)) {
+ LHSTrunc = DAG.getNode(ISD::FP_ROUND, DL, FloatVT, LHS,
+ DAG.getIntPtrConstant(0, DL, /*isTarget=*/true));
+ }
+ // It's OK to select from LHS and MinMax, with only one ISD::IS_FPCLASS, as
+ // we preferred RHS when generate MinMax, if the operands are equal.
----------------
nikic wrote:
I think this is correct for how these opcodes are legalized, but wouldn't transfer to the maximum/minimum case with the current implementation. I guess the idea is that for the legalizations through other min/max opcodes we shouldn't need the signed zero handling at all in the future, because they should now be handling it themselves?
https://github.com/llvm/llvm-project/pull/140193
More information about the llvm-commits
mailing list