diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -743,14 +743,21 @@ SimplifiedValues.lookup(BI->getCondition()))) { CurrentSavings += InlineConstants::InstrCost; } + } else if (SwitchInst *SI = dyn_cast(&I)) { + // Count a switch statement as savings if we can fold it. + if (dyn_cast_or_null( + SimplifiedValues.lookup(SI->getCondition()))) { + CurrentSavings += InlineConstants::InstrCost; + } } else if (Value *V = dyn_cast(&I)) { - // Count an instruction as savings if we can fold it. - if (SimplifiedValues.count(V)) { + // Count an instruction as savings if we can fold it + // or it could be simplified through SROA. + if (SimplifiedValues.count(V) || SROAArgValues.count(V)) { CurrentSavings += InlineConstants::InstrCost; } } - // TODO: Consider other forms of savings like switch statements, - // indirect calls becoming direct, SROACostSavings, LoadEliminationCost, + // TODO: Consider other forms of savings like + // indirect calls becoming direct, LoadEliminationCost, // etc. }