Skip to content

auto-inline: any function annotation (even [sideeffects] or a tagging macro) blocks it; an over-budget callee is declined silently #94

Backlog

Description

@lookibed

Checked on b7d8f6f (not on master: the recent inliner PRs GaijinEntertainment#4804/GaijinEntertainment#4808/GaijinEntertainment#4810 are not in that commit, so this may already differ there).

Summary

Two things keep the interpreter's auto-inliner (options auto_inline_functions) away from small, pure functions in generated code:

  1. Any function annotation blocks auto-inlining, except export and unused_argument (ast_inline.cpp, isAnnotated). That includes [sideeffects] and any user function macro that only tags the function (a marker with no call-site semantics). In a C-to-daslang conversion, every converted function carries such a marker, so no converted function is ever auto-inlined, however small. Declines of this kind are logged.
  2. A callee over the node budget (auto_inline_cost, default 32) is declined silently: log_optimization prints nothing for it, so a function that "should" inline gives no hint why it did not.

Repro

options gen2
require math
options auto_inline_functions = true
options log_optimization = true

def plain_mul(a, b : int) : int {
    return (a * b) >> 16
}

[sideeffects]
def marked_mul(a, b : int) : int {
    return (a * b) >> 16
}

def big_div(a, b : int) : int {
    if ((abs(a) >> 14) >= abs(b)) {
        return (a ^ b) < 0 ? -2147483647 : 2147483647
    }
    let c = (int64(a) << 16l) / int64(b)
    let d = c + int64(a) - int64(b) + c * 2l - c / 3l
    return int(c) + int(d - d)
}

[export]
def main {
    var s = 0
    for (i in range(1, 10)) {
        s += plain_mul(i, 3)
        s += marked_mul(i, 3)
        s += big_div(i, 3)
    }
    print("{s}\n")
}

Actual (log_optimization)

AUTO-INLINE plain_mul into main at ann.das:28:13
AUTO-INLINE DECLINED at ann.das:29:13: marked_mul: annotated function [sideeffects]
INLINE: 0 must + 1 auto + 0 invoke-block site(s), 1 declined in module

No line at all for big_div (line 30).

Expected

  1. marked_mul inlines like plain_mul. Splicing a body keeps its effects, so [sideeffects] (which only keeps the call from being dropped or folded) has no call-site semantics the splice would bypass. More generally, a way for a function macro to declare itself inert for inlining, e.g. a flag on AstFunctionAnnotation or a list beside export/unused_argument, so tagging macros do not disable the optimization.
  2. big_div gets a line such as AUTO-INLINE DECLINED at ann.das:30:13: big_div: N nodes over the budget 32 (auto_inline_cost).

Effect seen

In a converted Doom (PureDOOM), 615 of 799 functions carry a tagging function macro, so the fixed-point helpers are never inlined into the renderer loops; the fixed-point division is over the 32-node budget with no log line. Hand-edited copies without the markers moved interpreter fps within run-to-run noise (rough, not an isolated measurement), so this is a report of the mechanism, not of a measured speedup.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions