Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 538282c

Browse files
committed
Revert "[SDAG] Relax conditions under stores of loaded values can be merged"
This reverts r302712. The change fails with ASAN enabled: ERROR: AddressSanitizer: use-after-poison on address ... at ... READ of size 2 at ... thread T0 #0 ... in llvm::SDNode::getNumValues() const <snip>/include/llvm/CodeGen/SelectionDAGNodes.h:855:42 #1 ... in llvm::SDNode::hasAnyUseOfValue(unsigned int) const <snip>/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:7270:3 #2 ... in llvm::SDValue::use_empty() const <snip> include/llvm/CodeGen/SelectionDAGNodes.h:1042:17 #3 ... in (anonymous namespace)::DAGCombiner::MergeConsecutiveStores(llvm::StoreSDNode*) <snip>/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:12944:7 Reviewers: niravd Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33081 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302746 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3358093 commit 538282c

File tree

3 files changed

+28
-36
lines changed

3 files changed

+28
-36
lines changed

include/llvm/CodeGen/ISDOpcodes.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ namespace ISD {
4444
/// EntryToken - This is the marker used to indicate the start of a region.
4545
EntryToken,
4646

47-
/// DummyNode - Temporary node for node replacement. These nodes
48-
/// should not persist beyond their introduction.
49-
DummyNode,
50-
5147
/// TokenFactor - This node takes multiple tokens as input and produces a
5248
/// single token result. This is used to represent the fact that the operand
5349
/// operators are independent of each other.

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12783,6 +12783,10 @@ bool DAGCombiner::MergeConsecutiveStores(StoreSDNode *St) {
1278312783
LoadSDNode *Ld = dyn_cast<LoadSDNode>(St->getValue());
1278412784
if (!Ld) break;
1278512785

12786+
// Loads must only have one use.
12787+
if (!Ld->hasNUsesOfValue(1, 0))
12788+
break;
12789+
1278612790
// The memory operands must not be volatile.
1278712791
if (Ld->isVolatile() || Ld->isIndexed())
1278812792
break;
@@ -12791,6 +12795,10 @@ bool DAGCombiner::MergeConsecutiveStores(StoreSDNode *St) {
1279112795
if (Ld->getExtensionType() != ISD::NON_EXTLOAD)
1279212796
break;
1279312797

12798+
// The stored memory type must be the same.
12799+
if (Ld->getMemoryVT() != MemVT)
12800+
break;
12801+
1279412802
BaseIndexOffset LdPtr = BaseIndexOffset::match(Ld->getBasePtr(), DAG);
1279512803
// If this is not the first ptr that we check.
1279612804
if (LdBasePtr.Base.getNode()) {
@@ -12922,28 +12930,8 @@ bool DAGCombiner::MergeConsecutiveStores(StoreSDNode *St) {
1292212930
// Transfer chain users from old loads to the new load.
1292312931
for (unsigned i = 0; i < NumElem; ++i) {
1292412932
LoadSDNode *Ld = cast<LoadSDNode>(LoadNodes[i].MemNode);
12925-
if (SDValue(Ld, 0).hasOneUse()) {
12926-
// Only the original store used value so just replace chain.
12927-
DAG.ReplaceAllUsesOfValueWith(SDValue(Ld, 1),
12928-
SDValue(NewLoad.getNode(), 1));
12929-
} else {
12930-
// Multiple uses exist. Keep the old load in line with the new
12931-
// load, i.e. Replace chains using Ld's chain with a
12932-
// TokenFactor. Create a temporary node to serve as a placer so
12933-
// we do not replace the reference to original Load's chain in
12934-
// the TokenFactor.
12935-
SDValue TokenDummy = DAG.getNode(ISD::DummyNode, SDLoc(Ld), MVT::Other);
12936-
12937-
// Replace all references to Load's output chain to TokenDummy
12938-
CombineTo(Ld, SDValue(Ld, 0), TokenDummy, false);
12939-
SDValue Token =
12940-
DAG.getNode(ISD::TokenFactor, SDLoc(Ld), MVT::Other, SDValue(Ld, 1),
12941-
SDValue(NewLoad.getNode(), 1));
12942-
// Replace all uses of TokenDummy from itself to Ld's output chain.
12943-
CombineTo(TokenDummy.getNode(), Token);
12944-
assert(TokenDummy.use_empty() && "TokenDummy should be unused");
12945-
AddToWorklist(Ld);
12946-
}
12933+
DAG.ReplaceAllUsesOfValueWith(SDValue(Ld, 1),
12934+
SDValue(NewLoad.getNode(), 1));
1294712935
}
1294812936

1294912937
// Replace the all stores with the new store.

test/CodeGen/X86/merge_store_duplicated_loads.ll

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc %s -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -o - | FileCheck %s
33

4-
; PR32086
4+
55
target triple = "x86_64-unknown-linux-gnu"
66

77
define void @merge_double(double* noalias nocapture %st, double* noalias nocapture readonly %ld) #0 {
88
; CHECK-LABEL: merge_double:
99
; CHECK: # BB#0:
10-
; CHECK-NEXT: movups (%rsi), %xmm0
11-
; CHECK-NEXT: movups %xmm0, (%rdi)
12-
; CHECK-NEXT: movups %xmm0, 16(%rdi)
10+
; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
11+
; CHECK-NEXT: movsd {{.*#+}} xmm1 = mem[0],zero
12+
; CHECK-NEXT: movsd %xmm0, (%rdi)
13+
; CHECK-NEXT: movsd %xmm1, 8(%rdi)
14+
; CHECK-NEXT: movsd %xmm0, 16(%rdi)
15+
; CHECK-NEXT: movsd %xmm1, 24(%rdi)
1316
; CHECK-NEXT: retq
1417
%ld_idx1 = getelementptr inbounds double, double* %ld, i64 1
1518
%ld0 = load double, double* %ld, align 8, !tbaa !2
@@ -29,9 +32,12 @@ define void @merge_double(double* noalias nocapture %st, double* noalias nocaptu
2932
define void @merge_loadstore_int(i64* noalias nocapture readonly %p, i64* noalias nocapture %q) local_unnamed_addr #0 {
3033
; CHECK-LABEL: merge_loadstore_int:
3134
; CHECK: # BB#0: # %entry
32-
; CHECK-NEXT: movups (%rdi), %xmm0
33-
; CHECK-NEXT: movups %xmm0, (%rsi)
34-
; CHECK-NEXT: movups %xmm0, 16(%rsi)
35+
; CHECK-NEXT: movq (%rdi), %rax
36+
; CHECK-NEXT: movq 8(%rdi), %rcx
37+
; CHECK-NEXT: movq %rax, (%rsi)
38+
; CHECK-NEXT: movq %rcx, 8(%rsi)
39+
; CHECK-NEXT: movq %rax, 16(%rsi)
40+
; CHECK-NEXT: movq %rcx, 24(%rsi)
3541
; CHECK-NEXT: retq
3642
entry:
3743
%0 = load i64, i64* %p, align 8, !tbaa !1
@@ -51,9 +57,11 @@ define i64 @merge_loadstore_int_with_extra_use(i64* noalias nocapture readonly %
5157
; CHECK-LABEL: merge_loadstore_int_with_extra_use:
5258
; CHECK: # BB#0: # %entry
5359
; CHECK-NEXT: movq (%rdi), %rax
54-
; CHECK-NEXT: movups (%rdi), %xmm0
55-
; CHECK-NEXT: movups %xmm0, (%rsi)
56-
; CHECK-NEXT: movups %xmm0, 16(%rsi)
60+
; CHECK-NEXT: movq 8(%rdi), %rcx
61+
; CHECK-NEXT: movq %rax, (%rsi)
62+
; CHECK-NEXT: movq %rcx, 8(%rsi)
63+
; CHECK-NEXT: movq %rax, 16(%rsi)
64+
; CHECK-NEXT: movq %rcx, 24(%rsi)
5765
; CHECK-NEXT: retq
5866
entry:
5967
%0 = load i64, i64* %p, align 8, !tbaa !1

0 commit comments

Comments
 (0)