Skip to content

Commit

Permalink
DAG: Avoid breaking legal vector_shuffle with multiple uses (llvm#123712
Browse files Browse the repository at this point in the history
)

Previously this combine would undo AMDGPU's new custom legalization of
wide vector shuffles into 2 element pieces. The comment also
states that this combine is only done before legalization,
but the case with a build_vector source was unconditional.

We probably don't want to do this if the multiple uses are full
scalarization of the vector, but this seems to work well enough.
Scalarizing extracts should have folded out pre-legalize.
  • Loading branch information
arsenm authored Jan 30, 2025
1 parent edb7f6c commit 97a1f49
Show file tree
Hide file tree
Showing 10 changed files with 1,763 additions and 2,325 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23186,6 +23186,11 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR_ELT(SDNode *N) {
}

if (SVInVec.getOpcode() == ISD::BUILD_VECTOR) {
// TODO: Check if shuffle mask is legal?
if (LegalOperations && TLI.isOperationLegal(ISD::VECTOR_SHUFFLE, VecVT) &&
!VecOp.hasOneUse())
return SDValue();

SDValue InOp = SVInVec.getOperand(OrigElt);
if (InOp.getValueType() != ScalarVT) {
assert(InOp.getValueType().isInteger() && ScalarVT.isInteger());
Expand Down
280 changes: 114 additions & 166 deletions llvm/test/CodeGen/AMDGPU/shufflevector.v4f32.v2f32.ll

Large diffs are not rendered by default.

272 changes: 129 additions & 143 deletions llvm/test/CodeGen/AMDGPU/shufflevector.v4f32.v3f32.ll

Large diffs are not rendered by default.

809 changes: 343 additions & 466 deletions llvm/test/CodeGen/AMDGPU/shufflevector.v4f32.v4f32.ll

Large diffs are not rendered by default.

280 changes: 114 additions & 166 deletions llvm/test/CodeGen/AMDGPU/shufflevector.v4i32.v2i32.ll

Large diffs are not rendered by default.

272 changes: 129 additions & 143 deletions llvm/test/CodeGen/AMDGPU/shufflevector.v4i32.v3i32.ll

Large diffs are not rendered by default.

809 changes: 343 additions & 466 deletions llvm/test/CodeGen/AMDGPU/shufflevector.v4i32.v4i32.ll

Large diffs are not rendered by default.

280 changes: 114 additions & 166 deletions llvm/test/CodeGen/AMDGPU/shufflevector.v4p3.v2p3.ll

Large diffs are not rendered by default.

272 changes: 129 additions & 143 deletions llvm/test/CodeGen/AMDGPU/shufflevector.v4p3.v3p3.ll

Large diffs are not rendered by default.

809 changes: 343 additions & 466 deletions llvm/test/CodeGen/AMDGPU/shufflevector.v4p3.v4p3.ll

Large diffs are not rendered by default.

0 comments on commit 97a1f49

Please sign in to comment.