aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-08-04 02:32:22 +0000
committerChris Lattner <sabre@nondot.org>2007-08-04 02:32:22 +0000
commitec14635e603ac4554549c386f3cdc724b5b32fd5 (patch)
treeae049bd0c1c5aa3f3f4aa3f8c2d4154173d713aa /lib/Transforms/Utils/PromoteMemoryToRegister.cpp
parent043cc921d2be8c93d0269974afccb1e744836301 (diff)
downloadexternal_llvm-ec14635e603ac4554549c386f3cdc724b5b32fd5.zip
external_llvm-ec14635e603ac4554549c386f3cdc724b5b32fd5.tar.gz
external_llvm-ec14635e603ac4554549c386f3cdc724b5b32fd5.tar.bz2
Three improvements:
1. Check for revisiting a block before checking domination, which is faster. 2. If the stored value isn't an instruction, we don't have to check for domination. 3. If we have a value used in the same block more than once, make sure to remove the block from the UsingBlocks vector. Not doing so forces us to go through the slow path for the alloca. The combination of these improvements increases the number of allocas on the fastpath from 8935 to 8982 on PR1432. This speeds it up from 2.90s to 2.20s (31%) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40811 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/PromoteMemoryToRegister.cpp')
-rw-r--r--lib/Transforms/Utils/PromoteMemoryToRegister.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index 8fb9124..02eeb3c 100644
--- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -532,17 +532,26 @@ void PromoteMem2Reg::run() {
void PromoteMem2Reg::RewriteSingleStoreAlloca(AllocaInst *AI,
AllocaInfo &Info) {
StoreInst *OnlyStore = Info.OnlyStore;
+ bool StoringGlobalVal = !isa<Instruction>(OnlyStore->getOperand(0));
// Be aware of loads before the store.
SmallPtrSet<BasicBlock*, 32> 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(OnlyStore->getParent(), Info.UsingBlocks[i]))
+ BasicBlock *UseBlock = Info.UsingBlocks[i];
+
+ // If we already processed this block, don't reprocess it.
+ if (!ProcessedBlocks.insert(UseBlock)) {
+ Info.UsingBlocks[i] = Info.UsingBlocks.back();
+ Info.UsingBlocks.pop_back();
+ --i; --e;
continue;
+ }
- BasicBlock *UseBlock = Info.UsingBlocks[i];
- if (!ProcessedBlocks.insert(UseBlock))
+ // If the store dominates the block and if we haven't processed it yet,
+ // do so now. We can't handle the case where the store doesn't dominate a
+ // block because there may be a path between the store and the use, but we
+ // may need to insert phi nodes to handle dominance properly.
+ if (StoringGlobalVal || !dominates(OnlyStore->getParent(), UseBlock))
continue;
// If the use and store are in the same block, do a quick scan to
@@ -553,7 +562,8 @@ void PromoteMem2Reg::RewriteSingleStoreAlloca(AllocaInst *AI,
if (isa<LoadInst>(I) && I->getOperand(0) == AI)
break;
}
- if (&*I != OnlyStore) break; // Do not handle this case.
+ if (&*I != OnlyStore)
+ break; // Do not handle this alloca.
}
// Otherwise, if this is a different block or if all uses happen