Skip to content

[X86][Combine] Ensure single use chain in extract-load combine #136520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46258,7 +46258,8 @@ static SDValue combineExtractWithShuffle(SDNode *N, SelectionDAG &DAG,

// If we're extracting a single element from a broadcast load and there are
// no other users, just create a single load.
if (SrcBC.getOpcode() == X86ISD::VBROADCAST_LOAD && SrcBC.hasOneUse()) {
if (peekThroughOneUseBitcasts(Src).getOpcode() == X86ISD::VBROADCAST_LOAD &&
SrcBC.hasOneUse()) {
auto *MemIntr = cast<MemIntrinsicSDNode>(SrcBC);
unsigned SrcBCWidth = SrcBC.getScalarValueSizeInBits();
if (MemIntr->getMemoryVT().getSizeInBits() == SrcBCWidth &&
Expand Down
9 changes: 6 additions & 3 deletions llvm/test/CodeGen/X86/extractelement-load.ll
Original file line number Diff line number Diff line change
Expand Up @@ -573,14 +573,17 @@ define dso_local <2 x float> @multiuse_of_single_value_from_vbroadcast_load(ptr
; X64-AVX-LABEL: multiuse_of_single_value_from_vbroadcast_load:
; X64-AVX: # %bb.0:
; X64-AVX-NEXT: pushq %rbx
; X64-AVX-NEXT: subq $16, %rsp
; X64-AVX-NEXT: movq %rsi, %rbx
; X64-AVX-NEXT: vmovsd 32(%rsi), %xmm0 # xmm0 = mem[0],zero
; X64-AVX-NEXT: vmovsd %xmm0, (%rdi)
; X64-AVX-NEXT: vmovddup {{.*#+}} xmm0 = mem[0,0]
; X64-AVX-NEXT: vmovaps %xmm0, (%rsp) # 16-byte Spill
; X64-AVX-NEXT: vmovlps %xmm0, (%rdi)
; X64-AVX-NEXT: vmovaps 32(%rsi), %xmm0
; X64-AVX-NEXT: callq ccosf@PLT
; X64-AVX-NEXT: vmovlps %xmm0, 32(%rbx)
; X64-AVX-NEXT: vmovddup 32(%rbx), %xmm0 # xmm0 = mem[0,0]
; X64-AVX-NEXT: vmovaps (%rsp), %xmm0 # 16-byte Reload
; X64-AVX-NEXT: callq ccosf@PLT
; X64-AVX-NEXT: addq $16, %rsp
; X64-AVX-NEXT: popq %rbx
; X64-AVX-NEXT: retq
%p1 = getelementptr [5 x <2 x float>], ptr %arr, i64 0, i64 3
Expand Down
Loading