[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));
----------------
nikic wrote:
So this assumes that for all cases where the FP type is legal and the int type is not, that `float` is a legal type and that it either has legal IS_FPCLASS or i32 is also legal. Do these assumptions hold in practice? I think it's reasonable to expect float to be a legal type if there are any legal FP types, but I'm less sure about the rest. I think we have targets where f32 is legal but i32 is not.
Could you please add tests for https://github.com/llvm/llvm-project/issues/139380, https://github.com/llvm/llvm-project/issues/139381 and https://github.com/llvm/llvm-project/issues/140445 (just for minimumnum instead of minimum)? I *think* all of those are going to be fine with this patch, but I'd like to be sure.
https://github.com/llvm/llvm-project/pull/140193
More information about the llvm-commits
mailing list