mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 06:29:05 +00:00
GVN: Fix quadratic runtime on the number of switch cases.
No intended behavior change. This was introduced in r162023. With the fixed algorithm a Release build of ARMInstPrinter.cpp goes from 16s to 10s on a 2011 MBP. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162559 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -2231,13 +2231,21 @@ bool GVN::processInstruction(Instruction *I) {
|
|||||||
Value *SwitchCond = SI->getCondition();
|
Value *SwitchCond = SI->getCondition();
|
||||||
BasicBlock *Parent = SI->getParent();
|
BasicBlock *Parent = SI->getParent();
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
|
|
||||||
|
// Remember how many outgoing edges there are to every successor.
|
||||||
|
SmallDenseMap<BasicBlock *, unsigned, 16> SwitchEdges;
|
||||||
|
for (unsigned i = 0, n = SI->getNumSuccessors(); i != n; ++i)
|
||||||
|
++SwitchEdges[SI->getSuccessor(i)];
|
||||||
|
|
||||||
for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end();
|
for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end();
|
||||||
i != e; ++i) {
|
i != e; ++i) {
|
||||||
BasicBlock *Dst = i.getCaseSuccessor();
|
BasicBlock *Dst = i.getCaseSuccessor();
|
||||||
|
// If there is only a single edge, propagate the case value into it.
|
||||||
|
if (SwitchEdges.lookup(Dst) == 1) {
|
||||||
BasicBlockEdge E(Parent, Dst);
|
BasicBlockEdge E(Parent, Dst);
|
||||||
if (E.isSingleEdge())
|
|
||||||
Changed |= propagateEquality(SwitchCond, i.getCaseValue(), E);
|
Changed |= propagateEquality(SwitchCond, i.getCaseValue(), E);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user