mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
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
This commit is contained in:
parent
9f08a92e6c
commit
7fecc2e5e2
@ -400,25 +400,38 @@ void PromoteMem2Reg::MarkDominatingPHILive(BasicBlock *BB, unsigned AllocaNum,
|
|||||||
//
|
//
|
||||||
void PromoteMem2Reg::PromoteLocallyUsedAlloca(AllocaInst *AI) {
|
void PromoteMem2Reg::PromoteLocallyUsedAlloca(AllocaInst *AI) {
|
||||||
assert(!AI->use_empty() && "There are no uses of the alloca!");
|
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();
|
BasicBlock *BB = cast<Instruction>(AI->use_back())->getParent();
|
||||||
|
|
||||||
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
|
|
||||||
Instruction *Inst = I++;
|
// Handle degenerate cases quickly.
|
||||||
if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
|
if (AI->hasOneUse()) {
|
||||||
if (LI->getOperand(0) == AI) {
|
Instruction *U = cast<Instruction>(AI->use_back());
|
||||||
// Loads just return the "current value"...
|
if (LoadInst *LI = dyn_cast<LoadInst>(U)) {
|
||||||
LI->replaceAllUsesWith(CurVal);
|
// Must be a load of uninitialized value.
|
||||||
BB->getInstList().erase(LI);
|
LI->replaceAllUsesWith(Constant::getNullValue(AI->getAllocatedType()));
|
||||||
}
|
} else {
|
||||||
} else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
|
// Otherwise it must be a store which is never read.
|
||||||
if (SI->getOperand(1) == AI) {
|
assert(isa<StoreInst>(U));
|
||||||
// Loads just update the "current value"...
|
}
|
||||||
CurVal = SI->getOperand(0);
|
BB->getInstList().erase(U);
|
||||||
BB->getInstList().erase(SI);
|
} 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user