llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Infinite inlining of recursive functions

Open arpilipe opened this issue 10 years ago • 0 comments

Bugzilla Link 26371
Version trunk
OS All
Attachments Reproducer
CC @chandlerc,@preames,@sanjoy

Extended Description

To prevent infinite inlining of recursive functions Inliner maintains InlineHistory structure. However in some cases we might still end up inlining recursive function chain. It happens when Inliner is executed in a CallGraphSCC pass manager iteration. CGSCC pass manager spins one more iteration of inlining if some indirect call site was devirtualized by other CGSCC passes. No InlineHistory is maintained between these inliner iterations. Small reproducer is in the attachment.

In practice it's rarely a problem because the number of iterations in CGSCC is limited by 4 by default. But theoretically it can lead to an exponential growth of code size.

The suggested fix is to mark recursive call sites encountered by Inliner with NoInline attribute, so this information will be maintained between inlining iterations.

arpilipe avatar Jan 29 '16 16:01 arpilipe