Skip to content

Commit 3668de5

Browse files
committed
Merging r167912: into the 3.2 release branch.
Handle DAG CSE adding new uses during ReplaceAllUsesWith. Fixes PR14333. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_32@168596 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent bc69dc1 commit 3668de5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7728,7 +7728,18 @@ bool DAGCombiner::MergeConsecutiveStores(StoreSDNode* St) {
77287728
if (StoreNodes[i].MemNode == EarliestOp)
77297729
continue;
77307730
StoreSDNode *St = cast<StoreSDNode>(StoreNodes[i].MemNode);
7731-
DAG.ReplaceAllUsesOfValueWith(SDValue(St, 0), St->getChain());
7731+
// ReplaceAllUsesWith will replace all uses that existed when it was
7732+
// called, but graph optimizations may cause new ones to appear. For
7733+
// example, the case in pr14333 looks like
7734+
//
7735+
// St's chain -> St -> another store -> X
7736+
//
7737+
// And the only difference from St to the other store is the chain.
7738+
// When we change it's chain to be St's chain they become identical,
7739+
// get CSEed and the net result is that X is now a use of St.
7740+
// Since we know that St is redundant, just iterate.
7741+
while (!St->use_empty())
7742+
DAG.ReplaceAllUsesWith(SDValue(St, 0), St->getChain());
77327743
removeFromWorkList(St);
77337744
DAG.DeleteNode(St);
77347745
}

test/CodeGen/X86/pr14333.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: llc -mtriple=x86_64-unknown-unknown < %s
2+
%foo = type { i64, i64 }
3+
define void @bar(%foo* %zed) {
4+
%tmp = getelementptr inbounds %foo* %zed, i64 0, i32 0
5+
store i64 0, i64* %tmp, align 8
6+
%tmp2 = getelementptr inbounds %foo* %zed, i64 0, i32 1
7+
store i64 0, i64* %tmp2, align 8
8+
%tmp3 = bitcast %foo* %zed to i8*
9+
call void @llvm.memset.p0i8.i64(i8* %tmp3, i8 0, i64 16, i32 8, i1 false)
10+
ret void
11+
}
12+
declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind

0 commit comments

Comments
 (0)