diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-10-12 14:45:57 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-10-12 14:45:57 +0000 |
commit | b8339c0167e6329c8b0ebf3fd8359e8cd817a74e (patch) | |
tree | e13648b4152b6375e89831eee938e0eb2e3f6062 /llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp | |
parent | 78b5a3c3ef120e51e31a592ec98b2f0558f2f284 (diff) | |
download | bcm5719-llvm-b8339c0167e6329c8b0ebf3fd8359e8cd817a74e.tar.gz bcm5719-llvm-b8339c0167e6329c8b0ebf3fd8359e8cd817a74e.zip |
[SelectionDAG] Move VectorLegalizer::ExpandCTLZ codegen into SelectionDAGLegalize
Generalize SelectionDAGLegalize's CTLZ expansion to handle vectors - lets VectorLegalizer::ExpandCTLZ to just pass the expansion on instead of repeating the same codegen.
llvm-svn: 344349
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp index 3f38ed8a03c..852415647b1 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp @@ -1082,32 +1082,13 @@ SDValue VectorLegalizer::ExpandCTLZ(SDValue Op) { return DAG.getNode(ISD::CTLZ, DL, Op.getValueType(), Op.getOperand(0)); } - // If CTPOP is available we can lower with a CTPOP based method: - // u16 ctlz(u16 x) { - // x |= (x >> 1); - // x |= (x >> 2); - // x |= (x >> 4); - // x |= (x >> 8); - // return ctpop(~x); - // } - // Ref: "Hacker's Delight" by Henry Warren + // If we have the appropriate vector bit operations, it is better to use them + // than unrolling and expanding each component. if (isPowerOf2_32(NumBitsPerElt) && TLI.isOperationLegalOrCustom(ISD::CTPOP, VT) && TLI.isOperationLegalOrCustom(ISD::SRL, VT) && - TLI.isOperationLegalOrCustomOrPromote(ISD::OR, VT) && - TLI.isOperationLegalOrCustomOrPromote(ISD::XOR, VT)) { - SDLoc DL(Op); - SDValue Res = Op.getOperand(0); - EVT ShiftTy = TLI.getShiftAmountTy(VT, DAG.getDataLayout()); - - for (unsigned i = 1; i != NumBitsPerElt; i *= 2) - Res = DAG.getNode( - ISD::OR, DL, VT, Res, - DAG.getNode(ISD::SRL, DL, VT, Res, DAG.getConstant(i, DL, ShiftTy))); - - Res = DAG.getNOT(DL, Res, VT); - return DAG.getNode(ISD::CTPOP, DL, VT, Res); - } + TLI.isOperationLegalOrCustomOrPromote(ISD::OR, VT)) + return Op; // Otherwise go ahead and unroll. return DAG.UnrollVectorOp(Op.getNode()); |