-
Notifications
You must be signed in to change notification settings - Fork 13.7k
expandFMINIMUMNUM_FMAXIMUMNUM: Improve compare between zeros #140193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8690,6 +8690,7 @@ SDValue TargetLowering::expandFMINIMUMNUM_FMAXIMUMNUM(SDNode *Node, | |||||
RHS = DAG.getSelectCC(DL, RHS, RHS, LHS, RHS, ISD::SETUO); | ||||||
} | ||||||
|
||||||
// Please always prefer RHS if equal. | ||||||
SDValue MinMax = | ||||||
DAG.getSelectCC(DL, LHS, RHS, LHS, RHS, IsMax ? ISD::SETGT : ISD::SETLT); | ||||||
|
||||||
|
@@ -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()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use |
||||||
} | ||||||
SDValue LHSTrunc = LHS; | ||||||
if (!isOperationLegal(ISD::BITCAST, IntVT) && | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Would make more sense here, I think? |
||||||
!isOperationLegal(ISD::IS_FPCLASS, VT)) { | ||||||
LHSTrunc = DAG.getNode(ISD::FP_ROUND, DL, FloatVT, LHS, | ||||||
DAG.getIntPtrConstant(0, DL, /*isTarget=*/true)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this assumes that for all cases where the FP type is legal and the int type is not, that Could you please add tests for #139380, #139381 and #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. |
||||||
} | ||||||
// 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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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? |
||||||
SDValue RetZero = DAG.getSelect( | ||||||
DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, LHSTrunc, TestZero), LHS, | ||||||
MinMax, Flags); | ||||||
SDValue RCmp = DAG.getSelect( | ||||||
DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, RHS, TestZero), RHS, LCmp, | ||||||
Flags); | ||||||
return DAG.getSelect(DL, VT, IsZero, RCmp, MinMax, Flags); | ||||||
return DAG.getSelect(DL, VT, IsZero, RetZero, MinMax, Flags); | ||||||
} | ||||||
|
||||||
/// Returns a true value if if this FPClassTest can be performed with an ordered | ||||||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can directly use VT.changeTypeToInteger() to get the corresponding integer type with correct vector handling.