Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 05ef777

Browse files
committed
Merging r310604:
------------------------------------------------------------------------ r310604 | niravd | 2017-08-10 08:12:32 -0700 (Thu, 10 Aug 2017) | 13 lines [X86] Keep dependencies when constructing loads in combineStore Summary: Preserve chain dependecies between old and new loads constructed to prevent loads from reordering below later stores. Fixes PR34088. Reviewers: craig.topper, spatel, RKSimon, efriedma Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D36528 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@310678 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d10901a commit 05ef777

File tree

4 files changed

+61
-11
lines changed

4 files changed

+61
-11
lines changed

include/llvm/CodeGen/SelectionDAG.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,8 +1220,9 @@ class SelectionDAG {
12201220
/// If an existing load has uses of its chain, create a token factor node with
12211221
/// that chain and the new memory node's chain and update users of the old
12221222
/// chain to the token factor. This ensures that the new memory node will have
1223-
/// the same relative memory dependency position as the old load.
1224-
void makeEquivalentMemoryOrdering(LoadSDNode *Old, SDValue New);
1223+
/// the same relative memory dependency position as the old load. Returns the
1224+
/// new merged load chain.
1225+
SDValue makeEquivalentMemoryOrdering(LoadSDNode *Old, SDValue New);
12251226

12261227
/// Topological-sort the AllNodes list and a
12271228
/// assign a unique node id for each node in the DAG based on their

lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7262,22 +7262,23 @@ void SelectionDAG::TransferDbgValues(SDValue From, SDValue To) {
72627262
AddDbgValue(I, ToNode, false);
72637263
}
72647264

7265-
void SelectionDAG::makeEquivalentMemoryOrdering(LoadSDNode *OldLoad,
7266-
SDValue NewMemOp) {
7265+
SDValue SelectionDAG::makeEquivalentMemoryOrdering(LoadSDNode *OldLoad,
7266+
SDValue NewMemOp) {
72677267
assert(isa<MemSDNode>(NewMemOp.getNode()) && "Expected a memop node");
7268-
if (!OldLoad->hasAnyUseOfValue(1))
7269-
return;
7270-
72717268
// The new memory operation must have the same position as the old load in
72727269
// terms of memory dependency. Create a TokenFactor for the old load and new
72737270
// memory operation and update uses of the old load's output chain to use that
72747271
// TokenFactor.
72757272
SDValue OldChain = SDValue(OldLoad, 1);
72767273
SDValue NewChain = SDValue(NewMemOp.getNode(), 1);
7274+
if (!OldLoad->hasAnyUseOfValue(1))
7275+
return NewChain;
7276+
72777277
SDValue TokenFactor =
72787278
getNode(ISD::TokenFactor, SDLoc(OldLoad), MVT::Other, OldChain, NewChain);
72797279
ReplaceAllUsesOfValueWith(OldChain, TokenFactor);
72807280
UpdateNodeOperands(TokenFactor.getNode(), OldChain, NewChain);
7281+
return TokenFactor;
72817282
}
72827283

72837284
//===----------------------------------------------------------------------===//

lib/Target/X86/X86ISelLowering.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33386,7 +33386,8 @@ static SDValue combineStore(SDNode *N, SelectionDAG &DAG,
3338633386
SDValue NewLd = DAG.getLoad(LdVT, LdDL, Ld->getChain(), Ld->getBasePtr(),
3338733387
Ld->getPointerInfo(), Ld->getAlignment(),
3338833388
Ld->getMemOperand()->getFlags());
33389-
SDValue NewChain = NewLd.getValue(1);
33389+
// Make sure new load is placed in same chain order.
33390+
SDValue NewChain = DAG.makeEquivalentMemoryOrdering(Ld, NewLd);
3339033391
if (TokenFactorIndex >= 0) {
3339133392
Ops.push_back(NewChain);
3339233393
NewChain = DAG.getNode(ISD::TokenFactor, LdDL, MVT::Other, Ops);
@@ -33407,11 +33408,12 @@ static SDValue combineStore(SDNode *N, SelectionDAG &DAG,
3340733408
Ld->getPointerInfo().getWithOffset(4),
3340833409
MinAlign(Ld->getAlignment(), 4),
3340933410
Ld->getMemOperand()->getFlags());
33411+
// Make sure new loads are placed in same chain order.
33412+
SDValue NewChain = DAG.makeEquivalentMemoryOrdering(Ld, LoLd);
33413+
NewChain = DAG.makeEquivalentMemoryOrdering(Ld, HiLd);
3341033414

33411-
SDValue NewChain = LoLd.getValue(1);
3341233415
if (TokenFactorIndex >= 0) {
33413-
Ops.push_back(LoLd);
33414-
Ops.push_back(HiLd);
33416+
Ops.push_back(NewChain);
3341533417
NewChain = DAG.getNode(ISD::TokenFactor, LdDL, MVT::Other, Ops);
3341633418
}
3341733419

test/CodeGen/X86/pr34088.ll

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=i686-unknown -mcpu=pentium4 | FileCheck %s
3+
4+
%struct.Foo = type { i32, %struct.Bar }
5+
%struct.Bar = type { i32, %struct.Buffer, i32 }
6+
%struct.Buffer = type { i8*, i32 }
7+
8+
; This test checks that the load of store %2 is not dropped.
9+
;
10+
define i32 @pr34088() local_unnamed_addr {
11+
; CHECK-LABEL: pr34088:
12+
; CHECK: # BB#0: # %entry
13+
; CHECK-NEXT: pushl %ebp
14+
; CHECK-NEXT: .Lcfi0:
15+
; CHECK-NEXT: .cfi_def_cfa_offset 8
16+
; CHECK-NEXT: .Lcfi1:
17+
; CHECK-NEXT: .cfi_offset %ebp, -8
18+
; CHECK-NEXT: movl %esp, %ebp
19+
; CHECK-NEXT: .Lcfi2:
20+
; CHECK-NEXT: .cfi_def_cfa_register %ebp
21+
; CHECK-NEXT: andl $-16, %esp
22+
; CHECK-NEXT: subl $32, %esp
23+
; CHECK-NEXT: xorps %xmm0, %xmm0
24+
; CHECK-NEXT: movaps {{.*#+}} xmm1 = [205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205]
25+
; CHECK-NEXT: xorl %eax, %eax
26+
; CHECK-NEXT: movaps %xmm0, (%esp)
27+
; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
28+
; CHECK-NEXT: movaps %xmm1, (%esp)
29+
; CHECK-NEXT: movl $-842150451, {{[0-9]+}}(%esp) # imm = 0xCDCDCDCD
30+
; CHECK-NEXT: movsd %xmm0, {{[0-9]+}}(%esp)
31+
; CHECK-NEXT: movl %ebp, %esp
32+
; CHECK-NEXT: popl %ebp
33+
; CHECK-NEXT: retl
34+
entry:
35+
%foo = alloca %struct.Foo, align 4
36+
%0 = bitcast %struct.Foo* %foo to i8*
37+
call void @llvm.memset.p0i8.i32(i8* nonnull %0, i8 0, i32 20, i32 4, i1 false)
38+
%buffer1 = getelementptr inbounds %struct.Foo, %struct.Foo* %foo, i32 0, i32 1, i32 1
39+
%1 = bitcast %struct.Buffer* %buffer1 to i64*
40+
%2 = load i64, i64* %1, align 4
41+
call void @llvm.memset.p0i8.i32(i8* nonnull %0, i8 -51, i32 20, i32 4, i1 false)
42+
store i64 %2, i64* %1, align 4
43+
ret i32 0
44+
}
45+
46+
declare void @llvm.memset.p0i8.i32(i8* nocapture writeonly, i8, i32, i32, i1)

0 commit comments

Comments
 (0)