SILInliner: Critical edges have no code size impact.

I think unconditional branches should be free, period. They will
mostly be removed during LLVM code gen. However, fixing this requires
signficant adjustments to inlining heuristics to avoid microbenchmark
regressions at -Osize. So, instead I am just making this less
sensitive to critical edges for the sake of pipeline stability.
This commit is contained in:
Andrew Trick
2018-09-26 16:26:32 -07:00
parent d1bfe027c0
commit d82e0ff781
3 changed files with 31 additions and 21 deletions

View File

@@ -802,10 +802,12 @@ static int getThreadingCost(SILInstruction *I) {
return 0;
}
static int maxBranchRecursionDepth = 6;
/// couldSimplifyUsers - Check to see if any simplifications are possible if
/// "Val" is substituted for BBArg. If so, return true, if nothing obvious
/// is possible, return false.
static bool couldSimplifyEnumUsers(SILArgument *BBArg, int Budget) {
static bool couldSimplifyEnumUsers(SILArgument *BBArg, int Budget,
int recursionDepth = 0) {
SILBasicBlock *BB = BBArg->getParent();
int BudgetForBranch = 100;
@@ -833,6 +835,9 @@ static bool couldSimplifyEnumUsers(SILArgument *BBArg, int Budget) {
}
if (auto *BI = dyn_cast<BranchInst>(User)) {
if (recursionDepth >= maxBranchRecursionDepth) {
return false;
}
if (BudgetForBranch > Budget) {
BudgetForBranch = Budget;
for (SILInstruction &I : *BB) {
@@ -844,7 +849,8 @@ static bool couldSimplifyEnumUsers(SILArgument *BBArg, int Budget) {
if (BudgetForBranch > 0) {
SILBasicBlock *DestBB = BI->getDestBB();
unsigned OpIdx = UI->getOperandNumber();
if (couldSimplifyEnumUsers(DestBB->getArgument(OpIdx), BudgetForBranch))
if (couldSimplifyEnumUsers(DestBB->getArgument(OpIdx), BudgetForBranch,
recursionDepth + 1))
return true;
}
}