Skip to content

Commit 996123e

Browse files
committed
[TargetLowering] Simplify the interface for expandCTPOP/expandCTLZ/expandCTTZ.
There is no need to return a bool and have an SDValue output parameter. Just return the SDValue and let the caller check if it is null. I have another patch to add more callers of these so I thought I'd clean up the interface first. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D112267
1 parent 0bf230d commit 996123e

File tree

4 files changed

+35
-52
lines changed

4 files changed

+35
-52
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4446,23 +4446,20 @@ class TargetLowering : public TargetLoweringBase {
44464446
/// Expand CTPOP nodes. Expands vector/scalar CTPOP nodes,
44474447
/// vector nodes can only succeed if all operations are legal/custom.
44484448
/// \param N Node to expand
4449-
/// \param Result output after conversion
4450-
/// \returns True, if the expansion was successful, false otherwise
4451-
bool expandCTPOP(SDNode *N, SDValue &Result, SelectionDAG &DAG) const;
4449+
/// \returns The expansion result or SDValue() if it fails.
4450+
SDValue expandCTPOP(SDNode *N, SelectionDAG &DAG) const;
44524451

44534452
/// Expand CTLZ/CTLZ_ZERO_UNDEF nodes. Expands vector/scalar CTLZ nodes,
44544453
/// vector nodes can only succeed if all operations are legal/custom.
44554454
/// \param N Node to expand
4456-
/// \param Result output after conversion
4457-
/// \returns True, if the expansion was successful, false otherwise
4458-
bool expandCTLZ(SDNode *N, SDValue &Result, SelectionDAG &DAG) const;
4455+
/// \returns The expansion result or SDValue() if it fails.
4456+
SDValue expandCTLZ(SDNode *N, SelectionDAG &DAG) const;
44594457

44604458
/// Expand CTTZ/CTTZ_ZERO_UNDEF nodes. Expands vector/scalar CTTZ nodes,
44614459
/// vector nodes can only succeed if all operations are legal/custom.
44624460
/// \param N Node to expand
4463-
/// \param Result output after conversion
4464-
/// \returns True, if the expansion was successful, false otherwise
4465-
bool expandCTTZ(SDNode *N, SDValue &Result, SelectionDAG &DAG) const;
4461+
/// \returns The expansion result or SDValue() if it fails.
4462+
SDValue expandCTTZ(SDNode *N, SelectionDAG &DAG) const;
44664463

44674464
/// Expand ABS nodes. Expands vector/scalar ABS nodes,
44684465
/// vector nodes can only succeed if all operations are legal/custom.

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,17 +2688,17 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
26882688
Results.push_back(Tmp1);
26892689
break;
26902690
case ISD::CTPOP:
2691-
if (TLI.expandCTPOP(Node, Tmp1, DAG))
2691+
if ((Tmp1 = TLI.expandCTPOP(Node, DAG)))
26922692
Results.push_back(Tmp1);
26932693
break;
26942694
case ISD::CTLZ:
26952695
case ISD::CTLZ_ZERO_UNDEF:
2696-
if (TLI.expandCTLZ(Node, Tmp1, DAG))
2696+
if ((Tmp1 = TLI.expandCTLZ(Node, DAG)))
26972697
Results.push_back(Tmp1);
26982698
break;
26992699
case ISD::CTTZ:
27002700
case ISD::CTTZ_ZERO_UNDEF:
2701-
if (TLI.expandCTTZ(Node, Tmp1, DAG))
2701+
if ((Tmp1 = TLI.expandCTTZ(Node, DAG)))
27022702
Results.push_back(Tmp1);
27032703
break;
27042704
case ISD::BITREVERSE:

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -783,22 +783,22 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
783783
ExpandBITREVERSE(Node, Results);
784784
return;
785785
case ISD::CTPOP:
786-
if (TLI.expandCTPOP(Node, Tmp, DAG)) {
787-
Results.push_back(Tmp);
786+
if (SDValue Expanded = TLI.expandCTPOP(Node, DAG)) {
787+
Results.push_back(Expanded);
788788
return;
789789
}
790790
break;
791791
case ISD::CTLZ:
792792
case ISD::CTLZ_ZERO_UNDEF:
793-
if (TLI.expandCTLZ(Node, Tmp, DAG)) {
794-
Results.push_back(Tmp);
793+
if (SDValue Expanded = TLI.expandCTLZ(Node, DAG)) {
794+
Results.push_back(Expanded);
795795
return;
796796
}
797797
break;
798798
case ISD::CTTZ:
799799
case ISD::CTTZ_ZERO_UNDEF:
800-
if (TLI.expandCTTZ(Node, Tmp, DAG)) {
801-
Results.push_back(Tmp);
800+
if (SDValue Expanded = TLI.expandCTTZ(Node, DAG)) {
801+
Results.push_back(Expanded);
802802
return;
803803
}
804804
break;

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6991,8 +6991,7 @@ static bool canExpandVectorCTPOP(const TargetLowering &TLI, EVT VT) {
69916991
TLI.isOperationLegalOrCustomOrPromote(ISD::AND, VT);
69926992
}
69936993

6994-
bool TargetLowering::expandCTPOP(SDNode *Node, SDValue &Result,
6995-
SelectionDAG &DAG) const {
6994+
SDValue TargetLowering::expandCTPOP(SDNode *Node, SelectionDAG &DAG) const {
69966995
SDLoc dl(Node);
69976996
EVT VT = Node->getValueType(0);
69986997
EVT ShVT = getShiftAmountTy(VT, DAG.getDataLayout());
@@ -7002,11 +7001,11 @@ bool TargetLowering::expandCTPOP(SDNode *Node, SDValue &Result,
70027001

70037002
// TODO: Add support for irregular type lengths.
70047003
if (!(Len <= 128 && Len % 8 == 0))
7005-
return false;
7004+
return SDValue();
70067005

70077006
// Only expand vector types if we have the appropriate vector bit operations.
70087007
if (VT.isVector() && !canExpandVectorCTPOP(*this, VT))
7009-
return false;
7008+
return SDValue();
70107009

70117010
// This is the "best" algorithm from
70127011
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
@@ -7043,12 +7042,10 @@ bool TargetLowering::expandCTPOP(SDNode *Node, SDValue &Result,
70437042
DAG.getNode(ISD::SRL, dl, VT, DAG.getNode(ISD::MUL, dl, VT, Op, Mask01),
70447043
DAG.getConstant(Len - 8, dl, ShVT));
70457044

7046-
Result = Op;
7047-
return true;
7045+
return Op;
70487046
}
70497047

7050-
bool TargetLowering::expandCTLZ(SDNode *Node, SDValue &Result,
7051-
SelectionDAG &DAG) const {
7048+
SDValue TargetLowering::expandCTLZ(SDNode *Node, SelectionDAG &DAG) const {
70527049
SDLoc dl(Node);
70537050
EVT VT = Node->getValueType(0);
70547051
EVT ShVT = getShiftAmountTy(VT, DAG.getDataLayout());
@@ -7057,10 +7054,8 @@ bool TargetLowering::expandCTLZ(SDNode *Node, SDValue &Result,
70577054

70587055
// If the non-ZERO_UNDEF version is supported we can use that instead.
70597056
if (Node->getOpcode() == ISD::CTLZ_ZERO_UNDEF &&
7060-
isOperationLegalOrCustom(ISD::CTLZ, VT)) {
7061-
Result = DAG.getNode(ISD::CTLZ, dl, VT, Op);
7062-
return true;
7063-
}
7057+
isOperationLegalOrCustom(ISD::CTLZ, VT))
7058+
return DAG.getNode(ISD::CTLZ, dl, VT, Op);
70647059

70657060
// If the ZERO_UNDEF version is supported use that and handle the zero case.
70667061
if (isOperationLegalOrCustom(ISD::CTLZ_ZERO_UNDEF, VT)) {
@@ -7069,9 +7064,8 @@ bool TargetLowering::expandCTLZ(SDNode *Node, SDValue &Result,
70697064
SDValue CTLZ = DAG.getNode(ISD::CTLZ_ZERO_UNDEF, dl, VT, Op);
70707065
SDValue Zero = DAG.getConstant(0, dl, VT);
70717066
SDValue SrcIsZero = DAG.getSetCC(dl, SetCCVT, Op, Zero, ISD::SETEQ);
7072-
Result = DAG.getNode(ISD::SELECT, dl, VT, SrcIsZero,
7073-
DAG.getConstant(NumBitsPerElt, dl, VT), CTLZ);
7074-
return true;
7067+
return DAG.getNode(ISD::SELECT, dl, VT, SrcIsZero,
7068+
DAG.getConstant(NumBitsPerElt, dl, VT), CTLZ);
70757069
}
70767070

70777071
// Only expand vector types if we have the appropriate vector bit operations.
@@ -7081,7 +7075,7 @@ bool TargetLowering::expandCTLZ(SDNode *Node, SDValue &Result,
70817075
!canExpandVectorCTPOP(*this, VT)) ||
70827076
!isOperationLegalOrCustom(ISD::SRL, VT) ||
70837077
!isOperationLegalOrCustomOrPromote(ISD::OR, VT)))
7084-
return false;
7078+
return SDValue();
70857079

70867080
// for now, we do this:
70877081
// x = x | (x >> 1);
@@ -7098,23 +7092,19 @@ bool TargetLowering::expandCTLZ(SDNode *Node, SDValue &Result,
70987092
DAG.getNode(ISD::SRL, dl, VT, Op, Tmp));
70997093
}
71007094
Op = DAG.getNOT(dl, Op, VT);
7101-
Result = DAG.getNode(ISD::CTPOP, dl, VT, Op);
7102-
return true;
7095+
return DAG.getNode(ISD::CTPOP, dl, VT, Op);
71037096
}
71047097

7105-
bool TargetLowering::expandCTTZ(SDNode *Node, SDValue &Result,
7106-
SelectionDAG &DAG) const {
7098+
SDValue TargetLowering::expandCTTZ(SDNode *Node, SelectionDAG &DAG) const {
71077099
SDLoc dl(Node);
71087100
EVT VT = Node->getValueType(0);
71097101
SDValue Op = Node->getOperand(0);
71107102
unsigned NumBitsPerElt = VT.getScalarSizeInBits();
71117103

71127104
// If the non-ZERO_UNDEF version is supported we can use that instead.
71137105
if (Node->getOpcode() == ISD::CTTZ_ZERO_UNDEF &&
7114-
isOperationLegalOrCustom(ISD::CTTZ, VT)) {
7115-
Result = DAG.getNode(ISD::CTTZ, dl, VT, Op);
7116-
return true;
7117-
}
7106+
isOperationLegalOrCustom(ISD::CTTZ, VT))
7107+
return DAG.getNode(ISD::CTTZ, dl, VT, Op);
71187108

71197109
// If the ZERO_UNDEF version is supported use that and handle the zero case.
71207110
if (isOperationLegalOrCustom(ISD::CTTZ_ZERO_UNDEF, VT)) {
@@ -7123,9 +7113,8 @@ bool TargetLowering::expandCTTZ(SDNode *Node, SDValue &Result,
71237113
SDValue CTTZ = DAG.getNode(ISD::CTTZ_ZERO_UNDEF, dl, VT, Op);
71247114
SDValue Zero = DAG.getConstant(0, dl, VT);
71257115
SDValue SrcIsZero = DAG.getSetCC(dl, SetCCVT, Op, Zero, ISD::SETEQ);
7126-
Result = DAG.getNode(ISD::SELECT, dl, VT, SrcIsZero,
7127-
DAG.getConstant(NumBitsPerElt, dl, VT), CTTZ);
7128-
return true;
7116+
return DAG.getNode(ISD::SELECT, dl, VT, SrcIsZero,
7117+
DAG.getConstant(NumBitsPerElt, dl, VT), CTTZ);
71297118
}
71307119

71317120
// Only expand vector types if we have the appropriate vector bit operations.
@@ -7137,7 +7126,7 @@ bool TargetLowering::expandCTTZ(SDNode *Node, SDValue &Result,
71377126
!isOperationLegalOrCustom(ISD::SUB, VT) ||
71387127
!isOperationLegalOrCustomOrPromote(ISD::AND, VT) ||
71397128
!isOperationLegalOrCustomOrPromote(ISD::XOR, VT)))
7140-
return false;
7129+
return SDValue();
71417130

71427131
// for now, we use: { return popcount(~x & (x - 1)); }
71437132
// unless the target has ctlz but not ctpop, in which case we use:
@@ -7149,14 +7138,11 @@ bool TargetLowering::expandCTTZ(SDNode *Node, SDValue &Result,
71497138

71507139
// If ISD::CTLZ is legal and CTPOP isn't, then do that instead.
71517140
if (isOperationLegal(ISD::CTLZ, VT) && !isOperationLegal(ISD::CTPOP, VT)) {
7152-
Result =
7153-
DAG.getNode(ISD::SUB, dl, VT, DAG.getConstant(NumBitsPerElt, dl, VT),
7154-
DAG.getNode(ISD::CTLZ, dl, VT, Tmp));
7155-
return true;
7141+
return DAG.getNode(ISD::SUB, dl, VT, DAG.getConstant(NumBitsPerElt, dl, VT),
7142+
DAG.getNode(ISD::CTLZ, dl, VT, Tmp));
71567143
}
71577144

7158-
Result = DAG.getNode(ISD::CTPOP, dl, VT, Tmp);
7159-
return true;
7145+
return DAG.getNode(ISD::CTPOP, dl, VT, Tmp);
71607146
}
71617147

71627148
bool TargetLowering::expandABS(SDNode *N, SDValue &Result,

0 commit comments

Comments
 (0)