[llvm] Intrinsic: introduce minimumnum and maximumnum for IR and SelectionDAG (PR #96649)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 25 01:54:32 PDT 2024
================
@@ -8531,6 +8531,94 @@ SDValue TargetLowering::expandFMINIMUM_FMAXIMUM(SDNode *N,
return MinMax;
}
+SDValue TargetLowering::expandFMINIMUMNUM_FMAXIMUMNUM(SDNode *Node,
+ SelectionDAG &DAG) const {
+ SDLoc DL(Node);
+ SDValue LHS = Node->getOperand(0);
+ SDValue RHS = Node->getOperand(1);
+ unsigned Opc = Node->getOpcode();
+ EVT VT = Node->getValueType(0);
+ EVT CCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
+ bool IsMax = Opc == ISD::FMAXIMUMNUM;
+ SDNodeFlags Flags = Node->getFlags();
+
+ unsigned NewOp =
+ Opc == ISD::FMINIMUMNUM ? ISD::FMINNUM_IEEE : ISD::FMAXNUM_IEEE;
+
+ if (isOperationLegalOrCustom(NewOp, VT)) {
+ if (!Flags.hasNoNaNs()) {
+ // Insert canonicalizes if it's possible we need to quiet to get correct
+ // sNaN behavior.
+ if (!DAG.isKnownNeverSNaN(LHS)) {
+ LHS = DAG.getNode(ISD::FCANONICALIZE, DL, VT, LHS, Node->getFlags());
+ }
+ if (!DAG.isKnownNeverSNaN(RHS)) {
+ RHS = DAG.getNode(ISD::FCANONICALIZE, DL, VT, RHS, Node->getFlags());
+ }
----------------
arsenm wrote:
```suggestion
if (!DAG.isKnownNeverSNaN(LHS))
LHS = DAG.getNode(ISD::FCANONICALIZE, DL, VT, LHS, Flags);
if (!DAG.isKnownNeverSNaN(RHS))
RHS = DAG.getNode(ISD::FCANONICALIZE, DL, VT, RHS, Flags);
```
https://github.com/llvm/llvm-project/pull/96649
More information about the llvm-commits
mailing list