diff options
author | Sanjay Patel <spatel@rotateright.com> | 2020-01-08 09:42:21 -0500 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2020-01-08 10:15:33 -0500 |
commit | 780ba1f22b53116918cf12decccaed7ba2292bd5 (patch) | |
tree | c846e86acc45b3659cc6beb6dbb693ffd8da575d | |
parent | c74a8adda3bc4fc5714aef14cdcfda944d3038a0 (diff) | |
download | bcm5719-llvm-780ba1f22b53116918cf12decccaed7ba2292bd5.tar.gz bcm5719-llvm-780ba1f22b53116918cf12decccaed7ba2292bd5.zip |
[DAGCombiner] clean up extract-of-concat fold; NFC
This hopes to improve readability and adds an assert.
The functional change noted by the TODO comment is
proposed in:
D72361
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index fd98b9e7b75..cfc4671eaa0 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -18566,19 +18566,27 @@ SDValue DAGCombiner::visitEXTRACT_SUBVECTOR(SDNode *N) { } } - // Combine: - // (extract_subvec (concat V1, V2, ...), i) - // Into: - // Vi if possible - // Only operand 0 is checked as 'concat' assumes all inputs of the same - // type. - if (V.getOpcode() == ISD::CONCAT_VECTORS && isa<ConstantSDNode>(Index) && - V.getOperand(0).getValueType() == NVT) { - unsigned Idx = N->getConstantOperandVal(1); - unsigned NumElems = NVT.getVectorNumElements(); - assert((Idx % NumElems) == 0 && - "IDX in concat is not a multiple of the result vector length."); - return V->getOperand(Idx / NumElems); + if (V.getOpcode() == ISD::CONCAT_VECTORS && isa<ConstantSDNode>(Index)) { + EVT ConcatSrcVT = V.getOperand(0).getValueType(); + assert(ConcatSrcVT.getVectorElementType() == NVT.getVectorElementType() && + "Concat and extract subvector do not change element type"); + + unsigned ExtIdx = N->getConstantOperandVal(1); + unsigned ExtNumElts = NVT.getVectorNumElements(); + assert(ExtIdx % ExtNumElts == 0 && + "Extract index is not a multiple of the input vector length."); + + unsigned ConcatSrcNumElts = ConcatSrcVT.getVectorNumElements(); + unsigned ConcatOpIdx = ExtIdx / ConcatSrcNumElts; + + // If the concatenated source types match this extract, it's a direct + // simplification: + // extract_subvec (concat V1, V2, ...), i --> Vi + if (ConcatSrcNumElts == ExtNumElts) + return V.getOperand(ConcatOpIdx); + + // TODO: Handle the case where the concat operands are larger than the + // result of this extract by extracting directly from a concat op. } V = peekThroughBitcasts(V); |