diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2018-08-24 21:24:18 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2018-08-24 21:24:18 +0000 |
commit | 5b9ef39bdd3d78af62a18bac578b0b0795feeb68 (patch) | |
tree | f80d52e96b6fccde3442a0da6222aeea31b509d0 /llvm/lib | |
parent | 96cbeffa7be529a16b90362f705ff7fae8db7fee (diff) | |
download | bcm5719-llvm-5b9ef39bdd3d78af62a18bac578b0b0795feeb68.tar.gz bcm5719-llvm-5b9ef39bdd3d78af62a18bac578b0b0795feeb68.zip |
DAG: Allow matching fminnum/fmaxnum from vselect
llvm-svn: 340655
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 71621b1b324..3df040459ed 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -7031,6 +7031,16 @@ SDValue DAGCombiner::visitCTPOP(SDNode *N) { return SDValue(); } +// FIXME: This should be checking for no signed zeros on individual operands, as +// well as no nans. +static bool isLegalToCombineMinNumMaxNum(SelectionDAG &DAG, SDValue LHS, SDValue RHS) { + const TargetOptions &Options = DAG.getTarget().Options; + EVT VT = LHS.getValueType(); + + return Options.NoSignedZerosFPMath && VT.isFloatingPoint() && + DAG.isKnownNeverNaN(LHS) && DAG.isKnownNeverNaN(RHS); +} + /// Generate Min/Max node static SDValue combineMinNumMaxNum(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, SDValue True, SDValue False, @@ -7047,7 +7057,7 @@ static SDValue combineMinNumMaxNum(const SDLoc &DL, EVT VT, SDValue LHS, case ISD::SETULT: case ISD::SETULE: { unsigned Opcode = (LHS == True) ? ISD::FMINNUM : ISD::FMAXNUM; - if (TLI.isOperationLegal(Opcode, VT)) + if (TLI.isOperationLegalOrCustom(Opcode, VT)) return DAG.getNode(Opcode, DL, VT, LHS, RHS); return SDValue(); } @@ -7058,7 +7068,7 @@ static SDValue combineMinNumMaxNum(const SDLoc &DL, EVT VT, SDValue LHS, case ISD::SETUGT: case ISD::SETUGE: { unsigned Opcode = (LHS == True) ? ISD::FMAXNUM : ISD::FMINNUM; - if (TLI.isOperationLegal(Opcode, VT)) + if (TLI.isOperationLegalOrCustom(Opcode, VT)) return DAG.getNode(Opcode, DL, VT, LHS, RHS); return SDValue(); } @@ -7291,12 +7301,7 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) { // This is OK if we don't care about what happens if either operand is a // NaN. // - - // FIXME: This should be checking for no signed zeros on individual - // operands, as well as no nans. - const TargetOptions &Options = DAG.getTarget().Options; - if (Options.NoSignedZerosFPMath && VT.isFloatingPoint() && N0.hasOneUse() && - DAG.isKnownNeverNaN(N1) && DAG.isKnownNeverNaN(N2)) { + if (N0.hasOneUse() && isLegalToCombineMinNumMaxNum(DAG, N1, N2)) { ISD::CondCode CC = cast<CondCodeSDNode>(N0.getOperand(2))->get(); if (SDValue FMinMax = combineMinNumMaxNum( @@ -7771,6 +7776,20 @@ SDValue DAGCombiner::visitVSELECT(SDNode *N) { return DAG.getNode(ISD::XOR, DL, VT, Add, Shift); } + // vselect x, y (fcmp lt x, y) -> fminnum x, y + // vselect x, y (fcmp gt x, y) -> fmaxnum x, y + // + // This is OK if we don't care about what happens if either operand is a + // NaN. + // + EVT VT = N->getValueType(0); + if (N0.hasOneUse() && isLegalToCombineMinNumMaxNum(DAG, N0.getOperand(0), N0.getOperand(1))) { + ISD::CondCode CC = cast<CondCodeSDNode>(N0.getOperand(2))->get(); + if (SDValue FMinMax = combineMinNumMaxNum( + DL, VT, N0.getOperand(0), N0.getOperand(1), N1, N2, CC, TLI, DAG)) + return FMinMax; + } + // If this select has a condition (setcc) with narrower operands than the // select, try to widen the compare to match the select width. // TODO: This should be extended to handle any constant. |