diff options
author | Owen Anderson <resistor@mac.com> | 2008-05-13 23:18:30 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2008-05-13 23:18:30 +0000 |
commit | c4f406e736d2cb5f313eef50abe1c0c935c4090e (patch) | |
tree | 087daa1519a1a1a961b621668f0715a4e13b0fec | |
parent | 94fb68ba217975d2d99ae86d15993402158ac655 (diff) | |
download | external_llvm-c4f406e736d2cb5f313eef50abe1c0c935c4090e.zip external_llvm-c4f406e736d2cb5f313eef50abe1c0c935c4090e.tar.gz external_llvm-c4f406e736d2cb5f313eef50abe1c0c935c4090e.tar.bz2 |
Fix Analysis/BasicAA/pure-const-dce.ll. This turned out to be a correctness
bug as well as a missed optimization. We weren't properly checking for local
dependencies before moving on to non-local ones when doing non-local read-only
call CSE.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51082 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/GVN.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 3333ecd..c671078 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -441,6 +441,43 @@ uint32_t ValueTable::lookup_or_add(Value* V) { return nextValueNumber++; } + Instruction* local_dep = MD->getDependency(C); + + if (local_dep == MemoryDependenceAnalysis::None) { + valueNumbering.insert(std::make_pair(V, nextValueNumber)); + return nextValueNumber++; + } else if (local_dep != MemoryDependenceAnalysis::NonLocal) { + if (!isa<CallInst>(local_dep)) { + valueNumbering.insert(std::make_pair(V, nextValueNumber)); + return nextValueNumber++; + } + + CallInst* local_cdep = cast<CallInst>(local_dep); + + if (local_cdep->getCalledFunction() != C->getCalledFunction() || + local_cdep->getNumOperands() != C->getNumOperands()) { + valueNumbering.insert(std::make_pair(V, nextValueNumber)); + return nextValueNumber++; + } else if (!C->getCalledFunction()) { + valueNumbering.insert(std::make_pair(V, nextValueNumber)); + return nextValueNumber++; + } else { + for (unsigned i = 1; i < C->getNumOperands(); ++i) { + uint32_t c_vn = lookup_or_add(C->getOperand(i)); + uint32_t cd_vn = lookup_or_add(local_cdep->getOperand(i)); + if (c_vn != cd_vn) { + valueNumbering.insert(std::make_pair(V, nextValueNumber)); + return nextValueNumber++; + } + } + + uint32_t v = lookup_or_add(local_cdep); + valueNumbering.insert(std::make_pair(V, v)); + return v; + } + } + + DenseMap<BasicBlock*, Value*> deps; MD->getNonLocalDependency(C, deps); CallInst* cdep = 0; @@ -488,7 +525,7 @@ uint32_t ValueTable::lookup_or_add(Value* V) { } } - uint32_t v = valueNumbering[cdep]; + uint32_t v = lookup_or_add(cdep); valueNumbering.insert(std::make_pair(V, v)); return v; } |