[llvm] ed866d9 - [X86][Combine] Ensure single use chain in extract-load combine (#136520)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 24 07:16:54 PDT 2025
Author: Evgenii Kudriashov
Date: 2025-04-24T16:16:50+02:00
New Revision: ed866d994c3b074cb1b7a380b1ce9169dde3362c
URL: https://github.com/llvm/llvm-project/commit/ed866d994c3b074cb1b7a380b1ce9169dde3362c
DIFF: https://github.com/llvm/llvm-project/commit/ed866d994c3b074cb1b7a380b1ce9169dde3362c.diff
LOG: [X86][Combine] Ensure single use chain in extract-load combine (#136520)
The problem is that `SrcBC = peekThroughBitcasts(Src)` doesn't ensure
single use chain. It results in the situation when a cast may have
multiple users and instead of replacing a load we introduce a new one.
The situation is worsened by the fact that we've replaced the token from
the original load and its correct memory order now is not guaranteed.
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/extractelement-load.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 4a9121baba7db..0fc50dc1a87b6 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -46268,7 +46268,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 &&
diff --git a/llvm/test/CodeGen/X86/extractelement-load.ll b/llvm/test/CodeGen/X86/extractelement-load.ll
index c251f2a22f83a..ce68eebd5b752 100644
--- a/llvm/test/CodeGen/X86/extractelement-load.ll
+++ b/llvm/test/CodeGen/X86/extractelement-load.ll
@@ -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 at 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 at 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
More information about the llvm-commits
mailing list