[SwitchLowering] Remove quadratic vector removal.

This can be triggered with giant switches. No functionality change
intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240221 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2015-06-20 15:59:34 +00:00
parent 1e71d7421a
commit 35d21618cb

View File

@ -364,9 +364,9 @@ unsigned LowerSwitch::Clusterify(CaseVector& Cases, SwitchInst *SI) {
std::sort(Cases.begin(), Cases.end(), CaseCmp()); std::sort(Cases.begin(), Cases.end(), CaseCmp());
// Merge case into clusters // Merge case into clusters
if (Cases.size()>=2) if (Cases.size() >= 2) {
for (CaseItr I = Cases.begin(), J = std::next(Cases.begin()); CaseItr I = Cases.begin();
J != Cases.end();) { for (CaseItr J = std::next(I), E = Cases.end(); J != E; ++J) {
int64_t nextValue = J->Low->getSExtValue(); int64_t nextValue = J->Low->getSExtValue();
int64_t currentValue = I->High->getSExtValue(); int64_t currentValue = I->High->getSExtValue();
BasicBlock* nextBB = J->BB; BasicBlock* nextBB = J->BB;
@ -377,11 +377,13 @@ unsigned LowerSwitch::Clusterify(CaseVector& Cases, SwitchInst *SI) {
assert(nextValue > currentValue && "Cases should be strictly ascending"); assert(nextValue > currentValue && "Cases should be strictly ascending");
if ((nextValue == currentValue + 1) && (currentBB == nextBB)) { if ((nextValue == currentValue + 1) && (currentBB == nextBB)) {
I->High = J->High; I->High = J->High;
J = Cases.erase(J); // FIXME: Combine branch weights.
} else { } else if (++I != J) {
I = J++; *I = *J;
} }
} }
Cases.erase(std::next(I), Cases.end());
}
for (CaseItr I=Cases.begin(), E=Cases.end(); I!=E; ++I, ++numCmps) { for (CaseItr I=Cases.begin(), E=Cases.end(); I!=E; ++I, ++numCmps) {
if (I->Low != I->High) if (I->Low != I->High)
@ -477,12 +479,10 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) {
// cases. // cases.
assert(MaxPop > 0 && PopSucc); assert(MaxPop > 0 && PopSucc);
Default = PopSucc; Default = PopSucc;
for (CaseItr I = Cases.begin(); I != Cases.end();) { Cases.erase(std::remove_if(
if (I->BB == PopSucc) Cases.begin(), Cases.end(),
I = Cases.erase(I); [PopSucc](const CaseRange &R) { return R.BB == PopSucc; }),
else Cases.end());
++I;
}
// If there are no cases left, just branch. // If there are no cases left, just branch.
if (Cases.empty()) { if (Cases.empty()) {