aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-02-03 22:00:33 +0000
committerChris Lattner <sabre@nondot.org>2004-02-03 22:00:33 +0000
commit7fecc2e5e28fa223b16280a5e434d7d0e03e9c52 (patch)
tree52fcfc9acd138d0a792acff844cd565c50dd5bb7 /lib/Transforms/Utils/PromoteMemoryToRegister.cpp
parent9f08a92e6cbe18446eb36e2dc0a41b44910e6621 (diff)
Handle extremely trivial cases extremely efficiently. This speeds up
SRoA/mem2reg from 41.2s to 27.5s on the testcase in PR209. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11099 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/PromoteMemoryToRegister.cpp')
-rw-r--r--lib/Transforms/Utils/PromoteMemoryToRegister.cpp47
1 files changed, 30 insertions, 17 deletions
diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index 0e1204f5db..c1a13a220e 100644
--- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -400,25 +400,38 @@ void PromoteMem2Reg::MarkDominatingPHILive(BasicBlock *BB, unsigned AllocaNum,
//
void PromoteMem2Reg::PromoteLocallyUsedAlloca(AllocaInst *AI) {
assert(!AI->use_empty() && "There are no uses of the alloca!");
-
- // Uses of the uninitialized memory location shall get zero...
- Value *CurVal = Constant::getNullValue(AI->getAllocatedType());
-
BasicBlock *BB = cast<Instruction>(AI->use_back())->getParent();
- for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
- Instruction *Inst = I++;
- if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
- if (LI->getOperand(0) == AI) {
- // Loads just return the "current value"...
- LI->replaceAllUsesWith(CurVal);
- BB->getInstList().erase(LI);
- }
- } else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
- if (SI->getOperand(1) == AI) {
- // Loads just update the "current value"...
- CurVal = SI->getOperand(0);
- BB->getInstList().erase(SI);
+
+ // Handle degenerate cases quickly.
+ if (AI->hasOneUse()) {
+ Instruction *U = cast<Instruction>(AI->use_back());
+ if (LoadInst *LI = dyn_cast<LoadInst>(U)) {
+ // Must be a load of uninitialized value.
+ LI->replaceAllUsesWith(Constant::getNullValue(AI->getAllocatedType()));
+ } else {
+ // Otherwise it must be a store which is never read.
+ assert(isa<StoreInst>(U));
+ }
+ BB->getInstList().erase(U);
+ } else {
+ // Uses of the uninitialized memory location shall get zero...
+ Value *CurVal = Constant::getNullValue(AI->getAllocatedType());
+
+ for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
+ Instruction *Inst = I++;
+ if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
+ if (LI->getOperand(0) == AI) {
+ // Loads just return the "current value"...
+ LI->replaceAllUsesWith(CurVal);
+ BB->getInstList().erase(LI);
+ }
+ } else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
+ if (SI->getOperand(1) == AI) {
+ // Loads just update the "current value"...
+ CurVal = SI->getOperand(0);
+ BB->getInstList().erase(SI);
+ }
}
}
}