summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorSimon Dardis <simon.dardis@mips.com>2017-11-13 11:47:21 +0000
committerSimon Dardis <simon.dardis@mips.com>2017-11-13 11:47:21 +0000
commit8e2a5bd235a0e08b5a7d1a621aaaaabedb2bcbbe (patch)
treef88b58fd61595497f0d9fe927d6433cf5344acfb /llvm/lib/CodeGen/CodeGenPrepare.cpp
parentaecd4f5f9dbe6f4ba2c5ed322d73eae83df6f66a (diff)
downloadbcm5719-llvm-8e2a5bd235a0e08b5a7d1a621aaaaabedb2bcbbe.tar.gz
bcm5719-llvm-8e2a5bd235a0e08b5a7d1a621aaaaabedb2bcbbe.zip
[CodeGenPrepare] Check that erased sunken address are not reused
CodeGenPrepare sinks address computations from one basic block to another and attempts to reuse address computations that have already been sunk. If the same address computation appears twice with the first instance as an operand of a load whose result is an operand to a simplifable select, CodeGenPrepare simplifies the select and recursively erases the now dead instructions. CodeGenPrepare then attempts to use the erased address computation for the second load. Fix this by erasing the cached address value if it has zero uses before looking for the address value in the sunken address map. This partially resolves PR35209. Thanks to Alexander Richardson for reporting the issue! Reviewers: john.brawn Differential Revision: https://reviews.llvm.org/D39841 llvm-svn: 318032
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index d6633a508f5..96b7704a765 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -4358,7 +4358,12 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
// Now that we determined the addressing expression we want to use and know
// that we have to sink it into this block. Check to see if we have already
// done this for some other load/store instr in this block. If so, reuse the
- // computation.
+ // computation. Before attempting reuse, check if the address is valid as it
+ // may have been erased.
+ auto I = SunkAddrs.find(Addr);
+ if (I != SunkAddrs.end() && I->second && I->second->user_empty())
+ SunkAddrs.erase(I);
+
Value *&SunkAddr = SunkAddrs[Addr];
if (SunkAddr) {
DEBUG(dbgs() << "CGP: Reusing nonlocal addrmode: " << AddrMode << " for "
OpenPOWER on IntegriCloud