aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-08-04 02:15:24 +0000
committerChris Lattner <sabre@nondot.org>2007-08-04 02:15:24 +0000
commitb776a335b1a3260c27555db31f7ea0bee605de04 (patch)
treedd86d1763f91d73e61b190aa646faf2e6a547bc0 /lib/Transforms/Utils/PromoteMemoryToRegister.cpp
parent022021951ba28914e7ab917c10e3aff8b018b80b (diff)
In mem2reg, when handling the single-store case, make sure to remove
a using block from the list if we handle it. Not doing this caused us to not be able to promote (with the fast path) allocas which have uses (whoops). This increases the # allocas hitting this fastpath from 4042 to 8935 on the testcase in PR1432, speeding up mem2reg by 2.6x git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40809 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/PromoteMemoryToRegister.cpp')
-rw-r--r--lib/Transforms/Utils/PromoteMemoryToRegister.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index 6be25d6dfe..5ec5d182c7 100644
--- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -531,28 +531,29 @@ void PromoteMem2Reg::run() {
/// the value stored.
void PromoteMem2Reg::RewriteSingleStoreAlloca(AllocaInst *AI,
AllocaInfo &Info) {
+ StoreInst *OnlyStore = Info.OnlyStore;
+
// Be aware of loads before the store.
std::set<BasicBlock*> ProcessedBlocks;
for (unsigned i = 0, e = Info.UsingBlocks.size(); i != e; ++i) {
// If the store dominates the block and if we haven't processed it yet,
// do so now.
- if (!dominates(Info.OnlyStore->getParent(), Info.UsingBlocks[i]))
- continue;
-
- if (!ProcessedBlocks.insert(Info.UsingBlocks[i]).second)
+ if (!dominates(OnlyStore->getParent(), Info.UsingBlocks[i]))
continue;
BasicBlock *UseBlock = Info.UsingBlocks[i];
+ if (!ProcessedBlocks.insert(UseBlock).second)
+ continue;
// If the use and store are in the same block, do a quick scan to
// verify that there are no uses before the store.
- if (UseBlock == Info.OnlyStore->getParent()) {
+ if (UseBlock == OnlyStore->getParent()) {
BasicBlock::iterator I = UseBlock->begin();
- for (; &*I != Info.OnlyStore; ++I) { // scan block for store.
+ for (; &*I != OnlyStore; ++I) { // scan block for store.
if (isa<LoadInst>(I) && I->getOperand(0) == AI)
break;
}
- if (&*I != Info.OnlyStore) break; // Do not handle this case.
+ if (&*I != OnlyStore) break; // Do not handle this case.
}
// Otherwise, if this is a different block or if all uses happen
@@ -562,7 +563,7 @@ void PromoteMem2Reg::RewriteSingleStoreAlloca(AllocaInst *AI,
I != E; ) {
if (LoadInst *LI = dyn_cast<LoadInst>(I++)) {
if (LI->getOperand(0) == AI) {
- LI->replaceAllUsesWith(Info.OnlyStore->getOperand(0));
+ LI->replaceAllUsesWith(OnlyStore->getOperand(0));
if (AST && isa<PointerType>(LI->getType()))
AST->deleteValue(LI);
LI->eraseFromParent();
@@ -572,6 +573,7 @@ void PromoteMem2Reg::RewriteSingleStoreAlloca(AllocaInst *AI,
// Finally, remove this block from the UsingBlock set.
Info.UsingBlocks[i] = Info.UsingBlocks.back();
+ Info.UsingBlocks.pop_back();
--i; --e;
}
}