diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h --- a/llvm/include/llvm/CodeGen/TargetLowering.h +++ b/llvm/include/llvm/CodeGen/TargetLowering.h @@ -4446,23 +4446,20 @@ /// Expand CTPOP nodes. Expands vector/scalar CTPOP nodes, /// vector nodes can only succeed if all operations are legal/custom. /// \param N Node to expand - /// \param Result output after conversion - /// \returns True, if the expansion was successful, false otherwise - bool expandCTPOP(SDNode *N, SDValue &Result, SelectionDAG &DAG) const; + /// \returns The expansion result or SDValue() if it fails. + SDValue expandCTPOP(SDNode *N, SelectionDAG &DAG) const; /// Expand CTLZ/CTLZ_ZERO_UNDEF nodes. Expands vector/scalar CTLZ nodes, /// vector nodes can only succeed if all operations are legal/custom. /// \param N Node to expand - /// \param Result output after conversion - /// \returns True, if the expansion was successful, false otherwise - bool expandCTLZ(SDNode *N, SDValue &Result, SelectionDAG &DAG) const; + /// \returns The expansion result or SDValue() if it fails. + SDValue expandCTLZ(SDNode *N, SelectionDAG &DAG) const; /// Expand CTTZ/CTTZ_ZERO_UNDEF nodes. Expands vector/scalar CTTZ nodes, /// vector nodes can only succeed if all operations are legal/custom. /// \param N Node to expand - /// \param Result output after conversion - /// \returns True, if the expansion was successful, false otherwise - bool expandCTTZ(SDNode *N, SDValue &Result, SelectionDAG &DAG) const; + /// \returns The expansion result or SDValue() if it fails. + SDValue expandCTTZ(SDNode *N, SelectionDAG &DAG) const; /// Expand ABS nodes. Expands vector/scalar ABS nodes, /// vector nodes can only succeed if all operations are legal/custom. diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -2688,17 +2688,17 @@ Results.push_back(Tmp1); break; case ISD::CTPOP: - if (TLI.expandCTPOP(Node, Tmp1, DAG)) + if ((Tmp1 = TLI.expandCTPOP(Node, DAG))) Results.push_back(Tmp1); break; case ISD::CTLZ: case ISD::CTLZ_ZERO_UNDEF: - if (TLI.expandCTLZ(Node, Tmp1, DAG)) + if ((Tmp1 = TLI.expandCTLZ(Node, DAG))) Results.push_back(Tmp1); break; case ISD::CTTZ: case ISD::CTTZ_ZERO_UNDEF: - if (TLI.expandCTTZ(Node, Tmp1, DAG)) + if ((Tmp1 = TLI.expandCTTZ(Node, DAG))) Results.push_back(Tmp1); break; case ISD::BITREVERSE: diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp @@ -783,22 +783,22 @@ ExpandBITREVERSE(Node, Results); return; case ISD::CTPOP: - if (TLI.expandCTPOP(Node, Tmp, DAG)) { - Results.push_back(Tmp); + if (SDValue Expanded = TLI.expandCTPOP(Node, DAG)) { + Results.push_back(Expanded); return; } break; case ISD::CTLZ: case ISD::CTLZ_ZERO_UNDEF: - if (TLI.expandCTLZ(Node, Tmp, DAG)) { - Results.push_back(Tmp); + if (SDValue Expanded = TLI.expandCTLZ(Node, DAG)) { + Results.push_back(Expanded); return; } break; case ISD::CTTZ: case ISD::CTTZ_ZERO_UNDEF: - if (TLI.expandCTTZ(Node, Tmp, DAG)) { - Results.push_back(Tmp); + if (SDValue Expanded = TLI.expandCTTZ(Node, DAG)) { + Results.push_back(Expanded); return; } break; diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -6991,8 +6991,7 @@ TLI.isOperationLegalOrCustomOrPromote(ISD::AND, VT); } -bool TargetLowering::expandCTPOP(SDNode *Node, SDValue &Result, - SelectionDAG &DAG) const { +SDValue TargetLowering::expandCTPOP(SDNode *Node, SelectionDAG &DAG) const { SDLoc dl(Node); EVT VT = Node->getValueType(0); EVT ShVT = getShiftAmountTy(VT, DAG.getDataLayout()); @@ -7002,11 +7001,11 @@ // TODO: Add support for irregular type lengths. if (!(Len <= 128 && Len % 8 == 0)) - return false; + return SDValue(); // Only expand vector types if we have the appropriate vector bit operations. if (VT.isVector() && !canExpandVectorCTPOP(*this, VT)) - return false; + return SDValue(); // This is the "best" algorithm from // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel @@ -7043,12 +7042,10 @@ DAG.getNode(ISD::SRL, dl, VT, DAG.getNode(ISD::MUL, dl, VT, Op, Mask01), DAG.getConstant(Len - 8, dl, ShVT)); - Result = Op; - return true; + return Op; } -bool TargetLowering::expandCTLZ(SDNode *Node, SDValue &Result, - SelectionDAG &DAG) const { +SDValue TargetLowering::expandCTLZ(SDNode *Node, SelectionDAG &DAG) const { SDLoc dl(Node); EVT VT = Node->getValueType(0); EVT ShVT = getShiftAmountTy(VT, DAG.getDataLayout()); @@ -7057,10 +7054,8 @@ // If the non-ZERO_UNDEF version is supported we can use that instead. if (Node->getOpcode() == ISD::CTLZ_ZERO_UNDEF && - isOperationLegalOrCustom(ISD::CTLZ, VT)) { - Result = DAG.getNode(ISD::CTLZ, dl, VT, Op); - return true; - } + isOperationLegalOrCustom(ISD::CTLZ, VT)) + return DAG.getNode(ISD::CTLZ, dl, VT, Op); // If the ZERO_UNDEF version is supported use that and handle the zero case. if (isOperationLegalOrCustom(ISD::CTLZ_ZERO_UNDEF, VT)) { @@ -7069,9 +7064,8 @@ SDValue CTLZ = DAG.getNode(ISD::CTLZ_ZERO_UNDEF, dl, VT, Op); SDValue Zero = DAG.getConstant(0, dl, VT); SDValue SrcIsZero = DAG.getSetCC(dl, SetCCVT, Op, Zero, ISD::SETEQ); - Result = DAG.getNode(ISD::SELECT, dl, VT, SrcIsZero, - DAG.getConstant(NumBitsPerElt, dl, VT), CTLZ); - return true; + return DAG.getNode(ISD::SELECT, dl, VT, SrcIsZero, + DAG.getConstant(NumBitsPerElt, dl, VT), CTLZ); } // Only expand vector types if we have the appropriate vector bit operations. @@ -7081,7 +7075,7 @@ !canExpandVectorCTPOP(*this, VT)) || !isOperationLegalOrCustom(ISD::SRL, VT) || !isOperationLegalOrCustomOrPromote(ISD::OR, VT))) - return false; + return SDValue(); // for now, we do this: // x = x | (x >> 1); @@ -7098,12 +7092,10 @@ DAG.getNode(ISD::SRL, dl, VT, Op, Tmp)); } Op = DAG.getNOT(dl, Op, VT); - Result = DAG.getNode(ISD::CTPOP, dl, VT, Op); - return true; + return DAG.getNode(ISD::CTPOP, dl, VT, Op); } -bool TargetLowering::expandCTTZ(SDNode *Node, SDValue &Result, - SelectionDAG &DAG) const { +SDValue TargetLowering::expandCTTZ(SDNode *Node, SelectionDAG &DAG) const { SDLoc dl(Node); EVT VT = Node->getValueType(0); SDValue Op = Node->getOperand(0); @@ -7111,10 +7103,8 @@ // If the non-ZERO_UNDEF version is supported we can use that instead. if (Node->getOpcode() == ISD::CTTZ_ZERO_UNDEF && - isOperationLegalOrCustom(ISD::CTTZ, VT)) { - Result = DAG.getNode(ISD::CTTZ, dl, VT, Op); - return true; - } + isOperationLegalOrCustom(ISD::CTTZ, VT)) + return DAG.getNode(ISD::CTTZ, dl, VT, Op); // If the ZERO_UNDEF version is supported use that and handle the zero case. if (isOperationLegalOrCustom(ISD::CTTZ_ZERO_UNDEF, VT)) { @@ -7123,9 +7113,8 @@ SDValue CTTZ = DAG.getNode(ISD::CTTZ_ZERO_UNDEF, dl, VT, Op); SDValue Zero = DAG.getConstant(0, dl, VT); SDValue SrcIsZero = DAG.getSetCC(dl, SetCCVT, Op, Zero, ISD::SETEQ); - Result = DAG.getNode(ISD::SELECT, dl, VT, SrcIsZero, - DAG.getConstant(NumBitsPerElt, dl, VT), CTTZ); - return true; + return DAG.getNode(ISD::SELECT, dl, VT, SrcIsZero, + DAG.getConstant(NumBitsPerElt, dl, VT), CTTZ); } // Only expand vector types if we have the appropriate vector bit operations. @@ -7137,7 +7126,7 @@ !isOperationLegalOrCustom(ISD::SUB, VT) || !isOperationLegalOrCustomOrPromote(ISD::AND, VT) || !isOperationLegalOrCustomOrPromote(ISD::XOR, VT))) - return false; + return SDValue(); // for now, we use: { return popcount(~x & (x - 1)); } // unless the target has ctlz but not ctpop, in which case we use: @@ -7149,14 +7138,11 @@ // If ISD::CTLZ is legal and CTPOP isn't, then do that instead. if (isOperationLegal(ISD::CTLZ, VT) && !isOperationLegal(ISD::CTPOP, VT)) { - Result = - DAG.getNode(ISD::SUB, dl, VT, DAG.getConstant(NumBitsPerElt, dl, VT), - DAG.getNode(ISD::CTLZ, dl, VT, Tmp)); - return true; + return DAG.getNode(ISD::SUB, dl, VT, DAG.getConstant(NumBitsPerElt, dl, VT), + DAG.getNode(ISD::CTLZ, dl, VT, Tmp)); } - Result = DAG.getNode(ISD::CTPOP, dl, VT, Tmp); - return true; + return DAG.getNode(ISD::CTPOP, dl, VT, Tmp); } bool TargetLowering::expandABS(SDNode *N, SDValue &Result,