mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-10 02:25:47 +00:00
Two bug fixes:
1. Actually increment the Statistic for the GV elim optzn 2. When resolving undef branches, only resolve branches in executable blocks, avoiding marking a bunch of completely dead blocks live. This has a big impact on the quality of the generated code. With this patch, we positively rip up vortex, compiling Ut_MoveBytes to a single memcpy call. In vortex we get this: 12 ipsccp - Number of globals found to be constant 986 ipsccp - Number of arguments constant propagated 1378 ipsccp - Number of basic blocks unreachable 8919 ipsccp - Number of instructions removed git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18796 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -217,7 +217,11 @@ private:
|
|||||||
|
|
||||||
inline void markOverdefined(LatticeVal &IV, Value *V) {
|
inline void markOverdefined(LatticeVal &IV, Value *V) {
|
||||||
if (IV.markOverdefined()) {
|
if (IV.markOverdefined()) {
|
||||||
DEBUG(std::cerr << "markOverdefined: " << *V);
|
DEBUG(std::cerr << "markOverdefined: ";
|
||||||
|
if (Function *F = dyn_cast<Function>(V))
|
||||||
|
std::cerr << "Function '" << F->getName() << "'\n";
|
||||||
|
else
|
||||||
|
std::cerr << *V);
|
||||||
// Only instructions go on the work list
|
// Only instructions go on the work list
|
||||||
OverdefinedInstWorkList.push_back(V);
|
OverdefinedInstWorkList.push_back(V);
|
||||||
}
|
}
|
||||||
@@ -934,26 +938,29 @@ void SCCPSolver::Solve() {
|
|||||||
/// should be rerun.
|
/// should be rerun.
|
||||||
bool SCCPSolver::ResolveBranchesIn(Function &F) {
|
bool SCCPSolver::ResolveBranchesIn(Function &F) {
|
||||||
bool BranchesResolved = false;
|
bool BranchesResolved = false;
|
||||||
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
|
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
||||||
TerminatorInst *TI = BB->getTerminator();
|
if (BBExecutable.count(BB)) {
|
||||||
if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
|
TerminatorInst *TI = BB->getTerminator();
|
||||||
if (BI->isConditional()) {
|
if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
|
||||||
LatticeVal &BCValue = getValueState(BI->getCondition());
|
if (BI->isConditional()) {
|
||||||
if (BCValue.isUndefined()) {
|
LatticeVal &BCValue = getValueState(BI->getCondition());
|
||||||
BI->setCondition(ConstantBool::True);
|
if (BCValue.isUndefined()) {
|
||||||
|
BI->setCondition(ConstantBool::True);
|
||||||
|
BranchesResolved = true;
|
||||||
|
visit(BI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
|
||||||
|
LatticeVal &SCValue = getValueState(SI->getCondition());
|
||||||
|
if (SCValue.isUndefined()) {
|
||||||
|
const Type *CondTy = SI->getCondition()->getType();
|
||||||
|
SI->setCondition(Constant::getNullValue(CondTy));
|
||||||
BranchesResolved = true;
|
BranchesResolved = true;
|
||||||
visit(BI);
|
visit(SI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
|
|
||||||
LatticeVal &SCValue = getValueState(SI->getCondition());
|
|
||||||
if (SCValue.isUndefined()) {
|
|
||||||
SI->setCondition(Constant::getNullValue(SI->getCondition()->getType()));
|
|
||||||
BranchesResolved = true;
|
|
||||||
visit(SI);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return BranchesResolved;
|
return BranchesResolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1007,6 +1014,7 @@ bool SCCP::runOnFunction(Function &F) {
|
|||||||
bool ResolvedBranches = true;
|
bool ResolvedBranches = true;
|
||||||
while (ResolvedBranches) {
|
while (ResolvedBranches) {
|
||||||
Solver.Solve();
|
Solver.Solve();
|
||||||
|
DEBUG(std::cerr << "RESOLVING UNDEF BRANCHES\n");
|
||||||
ResolvedBranches = Solver.ResolveBranchesIn(F);
|
ResolvedBranches = Solver.ResolveBranchesIn(F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1146,6 +1154,7 @@ bool IPSCCP::runOnModule(Module &M) {
|
|||||||
while (ResolvedBranches) {
|
while (ResolvedBranches) {
|
||||||
Solver.Solve();
|
Solver.Solve();
|
||||||
|
|
||||||
|
DEBUG(std::cerr << "RESOLVING UNDEF BRANCHES\n");
|
||||||
ResolvedBranches = false;
|
ResolvedBranches = false;
|
||||||
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
|
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
|
||||||
ResolvedBranches |= Solver.ResolveBranchesIn(*F);
|
ResolvedBranches |= Solver.ResolveBranchesIn(*F);
|
||||||
@@ -1284,6 +1293,7 @@ bool IPSCCP::runOnModule(Module &M) {
|
|||||||
SI->eraseFromParent();
|
SI->eraseFromParent();
|
||||||
}
|
}
|
||||||
M.getGlobalList().erase(GV);
|
M.getGlobalList().erase(GV);
|
||||||
|
++IPNumGlobalConst;
|
||||||
}
|
}
|
||||||
|
|
||||||
return MadeChanges;
|
return MadeChanges;
|
||||||
|
Reference in New Issue
Block a user