mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-27 14:24:40 +00:00
Be more aggressive in pruning unnecessary PHI nodes when doing PHI construction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41080 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -749,40 +749,59 @@ Value *GVN::GetValueForBlock(BasicBlock *BB, LoadInst* orig,
|
|||||||
if (Phis.count(BB) == 0)
|
if (Phis.count(BB) == 0)
|
||||||
Phis.insert(std::make_pair(BB, PN));
|
Phis.insert(std::make_pair(BB, PN));
|
||||||
|
|
||||||
bool all_same = true;
|
|
||||||
Value* first = 0;
|
|
||||||
|
|
||||||
// Fill in the incoming values for the block.
|
// Fill in the incoming values for the block.
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
||||||
Value* val = GetValueForBlock(*PI, orig, Phis);
|
Value* val = GetValueForBlock(*PI, orig, Phis);
|
||||||
if (first == 0)
|
|
||||||
first = val;
|
|
||||||
else if (all_same && first != val)
|
|
||||||
all_same = false;
|
|
||||||
|
|
||||||
PN->addIncoming(val, *PI);
|
PN->addIncoming(val, *PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (all_same) {
|
Value* v = PN->hasConstantValue();
|
||||||
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
|
if (v) {
|
||||||
|
if (Instruction* inst = dyn_cast<Instruction>(v)) {
|
||||||
MD.removeInstruction(PN);
|
DominatorTree &DT = getAnalysis<DominatorTree>();
|
||||||
PN->replaceAllUsesWith(first);
|
if (DT.dominates(inst, PN)) {
|
||||||
|
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
|
||||||
SmallVector<BasicBlock*, 4> toRemove;
|
|
||||||
for (DenseMap<BasicBlock*, Value*>::iterator I = Phis.begin(),
|
MD.removeInstruction(PN);
|
||||||
E = Phis.end(); I != E; ++I)
|
PN->replaceAllUsesWith(inst);
|
||||||
if (I->second == PN)
|
|
||||||
toRemove.push_back(I->first);
|
SmallVector<BasicBlock*, 4> toRemove;
|
||||||
for (SmallVector<BasicBlock*, 4>::iterator I = toRemove.begin(),
|
for (DenseMap<BasicBlock*, Value*>::iterator I = Phis.begin(),
|
||||||
E= toRemove.end(); I != E; ++I)
|
E = Phis.end(); I != E; ++I)
|
||||||
Phis[*I] = first;
|
if (I->second == PN)
|
||||||
|
toRemove.push_back(I->first);
|
||||||
PN->eraseFromParent();
|
for (SmallVector<BasicBlock*, 4>::iterator I = toRemove.begin(),
|
||||||
|
E= toRemove.end(); I != E; ++I)
|
||||||
Phis[BB] = first;
|
Phis[*I] = inst;
|
||||||
|
|
||||||
return first;
|
PN->eraseFromParent();
|
||||||
|
|
||||||
|
Phis[BB] = inst;
|
||||||
|
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
|
||||||
|
|
||||||
|
MD.removeInstruction(PN);
|
||||||
|
PN->replaceAllUsesWith(v);
|
||||||
|
|
||||||
|
SmallVector<BasicBlock*, 4> toRemove;
|
||||||
|
for (DenseMap<BasicBlock*, Value*>::iterator I = Phis.begin(),
|
||||||
|
E = Phis.end(); I != E; ++I)
|
||||||
|
if (I->second == PN)
|
||||||
|
toRemove.push_back(I->first);
|
||||||
|
for (SmallVector<BasicBlock*, 4>::iterator I = toRemove.begin(),
|
||||||
|
E= toRemove.end(); I != E; ++I)
|
||||||
|
Phis[*I] = v;
|
||||||
|
|
||||||
|
PN->eraseFromParent();
|
||||||
|
|
||||||
|
Phis[BB] = v;
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
phiMap[orig->getPointerOperand()].insert(PN);
|
phiMap[orig->getPointerOperand()].insert(PN);
|
||||||
@ -915,7 +934,7 @@ bool GVN::processLoad(LoadInst* L,
|
|||||||
return deletedLoad;
|
return deletedLoad;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// buildsets_availout - When calculating availability, handle an instruction
|
/// processInstruction - When calculating availability, handle an instruction
|
||||||
/// by inserting it into the appropriate sets
|
/// by inserting it into the appropriate sets
|
||||||
bool GVN::processInstruction(Instruction* I,
|
bool GVN::processInstruction(Instruction* I,
|
||||||
ValueNumberedSet& currAvail,
|
ValueNumberedSet& currAvail,
|
||||||
|
Reference in New Issue
Block a user