Use isInlineViable to prevent inlining of functions with non-inlinable
constructs, in case cost analysis is skipped.
Details
Diff Detail
Event Timeline
isInlineViable doesn't care whether the code is actually reachable, so you could pessimize partial inlining in certain cases, e.g. a function which calls va_start conditionally. I don't think we need fix that now, but it would be nice to at least have a testcase demonstrating the issue.
I could not find a case where not considering reachability would prevent us from partial inlining with this patch.
Currently, CodeExtractor won't extract unreachable blocks (via DT), blocks with vastart/vaend or blockaddresses in the function we use for partial inlining. That only leaves localescape which isInlineViable prevents, and those calls always have to be in the entry block, so they are always reachable. I think it would be better to avoid extracting blocks with localesacpe calls for now and just assert isInlineViable.
If we teach CodeExtractor to consider reachability beyond using the dominator tree, we should consider the same reachability in isInlineViable.
Independent of this patch, considering reachability in isInlineViable could be beneficial for alwaysinline functions, but that should be an independent patch I think. What do you think @efriedma , does this make sense?
Can you explain the difference between llvm::isInlineViable and CodeExtractor::isBlockValidForExtraction? I'm kind of confused why they're checking different things.
I think CodeExtractor is not only used to extract code for partial inlining, but also used by LoopExtractor. I suppose this is why they do not check the same thing, but I think it would make sense to check for non-inlinable blocks in CodeExtractor too. Maybe we should add an isInlineableBlock function and use them in isBlockValidForExtraction?
Update to use isInlineViable only when cost analysis is skipped.
I think CodeExtractor is not only used to extract code for partial inlining, but also used by LoopExtractor. I suppose this is why they do not check the same thing, but I think it would make sense to check for non-inlinable blocks in CodeExtractor too. Maybe we should add an isInlineableBlock function and use them in isBlockValidForExtraction?
After having another look, the difference between isBlockValidForExtraction and isInlineViable is that isBlockValidForExtraction checks loops that are going to be outlined, rather than inlined.