1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

[InstCombine] Remove unreachable blocks before DCE

Dropping unreachable code may reduce use counts on other instructions,
so it's better to do this earlier rather than later.

NFC-ish, may only impact worklist order.
This commit is contained in:
Nikita Popov 2020-03-28 21:16:48 +01:00
parent 798e241738
commit 74ebf8606d

View File

@ -3685,6 +3685,18 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
Worklist.push_back(SuccBB);
} while (!Worklist.empty());
// Remove instructions inside unreachable blocks. This prevents the
// instcombine code from having to deal with some bad special cases, and
// reduces use counts of instructions.
for (BasicBlock &BB : F) {
if (Visited.count(&BB))
continue;
unsigned NumDeadInstInBB = removeAllNonTerminatorAndEHPadInstructions(&BB);
MadeIRChange |= NumDeadInstInBB > 0;
NumDeadInst += NumDeadInstInBB;
}
// Once we've found all of the instructions to add to instcombine's worklist,
// add them in reverse order. This way instcombine will visit from the top
// of the function down. This jives well with the way that it adds all uses
@ -3706,18 +3718,6 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
ICWorklist.push(Inst);
}
// Do a quick scan over the function. If we find any blocks that are
// unreachable, remove any instructions inside of them. This prevents
// the instcombine code from having to deal with some bad special cases.
for (BasicBlock &BB : F) {
if (Visited.count(&BB))
continue;
unsigned NumDeadInstInBB = removeAllNonTerminatorAndEHPadInstructions(&BB);
MadeIRChange |= NumDeadInstInBB > 0;
NumDeadInst += NumDeadInstInBB;
}
return MadeIRChange;
}