diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2025-03-29 17:55:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-29 17:55:38 +0000 |
commit | 666faa7fd98b7a58e089a38083f33c067ed5b955 (patch) | |
tree | ccd7e593436fe7c9e406e47c3c03398b8be11e9d /llvm/lib/CodeGen | |
parent | 3db5be79d24bb48a38e844fafc3db054f8d8cc58 (diff) | |
download | llvm-666faa7fd98b7a58e089a38083f33c067ed5b955.zip llvm-666faa7fd98b7a58e089a38083f33c067ed5b955.tar.gz llvm-666faa7fd98b7a58e089a38083f33c067ed5b955.tar.bz2 |
[DAG] visitEXTRACT_SUBVECTOR - accumulate SimplifyDemandedVectorElts demanded elts across all EXTRACT_SUBVECTOR uses (REAPPLIED) (#133401)
Similar to what is done for visitEXTRACT_VECTOR_ELT - if all uses of a vector are EXTRACT_SUBVECTOR, then determine the accumulated demanded elts across all users and call SimplifyDemandedVectorElts in "AssumeSingleUse" use.
Second try after #133130 was reverted by #133331 due to it affecting reverted test files
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 2fd7443..4487b9d 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -25557,8 +25557,31 @@ SDValue DAGCombiner::visitEXTRACT_SUBVECTOR(SDNode *N) { if (SDValue NarrowBOp = narrowExtractedVectorBinOp(N, DAG, LegalOperations)) return NarrowBOp; - if (SimplifyDemandedVectorElts(SDValue(N, 0))) - return SDValue(N, 0); + // If only EXTRACT_SUBVECTOR nodes use the source vector we can + // simplify it based on the (valid) extractions. + if (!V.getValueType().isScalableVector() && + llvm::all_of(V->users(), [&](SDNode *Use) { + return Use->getOpcode() == ISD::EXTRACT_SUBVECTOR && + Use->getOperand(0) == V; + })) { + unsigned NumElts = V.getValueType().getVectorNumElements(); + APInt DemandedElts = APInt::getZero(NumElts); + for (SDNode *User : V->users()) { + unsigned ExtIdx = User->getConstantOperandVal(1); + unsigned NumSubElts = User->getValueType(0).getVectorNumElements(); + DemandedElts.setBits(ExtIdx, ExtIdx + NumSubElts); + } + if (SimplifyDemandedVectorElts(V, DemandedElts, /*AssumeSingleUse=*/true)) { + // We simplified the vector operand of this extract subvector. If this + // extract is not dead, visit it again so it is folded properly. + if (N->getOpcode() != ISD::DELETED_NODE) + AddToWorklist(N); + return SDValue(N, 0); + } + } else { + if (SimplifyDemandedVectorElts(SDValue(N, 0))) + return SDValue(N, 0); + } return SDValue(); } |