diff options
author | Florian Hahn <flo@fhahn.com> | 2018-12-15 00:32:38 +0000 |
---|---|---|
committer | Florian Hahn <flo@fhahn.com> | 2018-12-15 00:32:38 +0000 |
commit | c214bc2b8da91f38c4d2c060831229a17b6af816 (patch) | |
tree | f1a4f1a0c43590413a0df2f17a8ddd1049da9abc /llvm/lib/Transforms | |
parent | ae15e7232a4c12a2691c94c6585692ff6d1421e9 (diff) | |
download | bcm5719-llvm-c214bc2b8da91f38c4d2c060831229a17b6af816.tar.gz bcm5719-llvm-c214bc2b8da91f38c4d2c060831229a17b6af816.zip |
[NewGVN] Update use counts for SSA copies when replacing them by their operands.
The current code relies on LeaderUseCount to determine if we can remove
an SSA copy, but in that the LeaderUseCount does not refer to the SSA
copy. If a SSA copy is a dominating leader, we use the operand as dominating
leader instead. This means we removed a user of a ssa copy and we should
decrement its use count, so we can remove the ssa copy once it becomes dead.
Fixes PR38804.
Reviewers: efriedma, davide
Reviewed By: davide
Differential Revision: https://reviews.llvm.org/D51595
llvm-svn: 349217
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/NewGVN.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp index 6e9ab448874..7cbb0fe70f8 100644 --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -4093,10 +4093,13 @@ bool NewGVN::eliminateInstructions(Function &F) { // It's about to be alive again. if (LeaderUseCount == 0 && isa<Instruction>(DominatingLeader)) ProbablyDead.erase(cast<Instruction>(DominatingLeader)); - // Copy instructions, however, are still dead because we use their - // operand as the leader. - if (LeaderUseCount == 0 && isSSACopy) - ProbablyDead.insert(II); + // For copy instructions, we use their operand as a leader, + // which means we remove a user of the copy and it may become dead. + if (isSSACopy) { + unsigned &IIUseCount = UseCounts[II]; + if (--IIUseCount == 0) + ProbablyDead.insert(II); + } ++LeaderUseCount; AnythingReplaced = true; } |