https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114452

            Bug ID: 114452
           Summary: Functions invoked through compile-time table of
                    function pointers not inlined
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chfast at gmail dot com
  Target Milestone: ---

In the following example there is a compile-time table of pointers to simple
functions. When the table is used in a simple unrolled loop with constant trip
count the functions invoked by pointers are not inlined.

using F = int (*)(int) noexcept;

void test(int z[2]) noexcept {
    static constexpr F fs[]{
        [](int x) noexcept { return x; },
        [](int x) noexcept { return x; },
    };

    for (int i = 0; i < 2; ++i) {
        z[i] = fs[i](z[i]);
    }
}

Generated assembly:

test(int*)::{lambda(int)#1}::_FUN(int):
        mov     eax, edi
        ret
test(int*)::{lambda(int)#2}::_FUN(int):
        mov     eax, edi
        ret
test(int*):
        mov     rdx, rdi
        mov     edi, DWORD PTR [rdi]
        call    test(int*)::{lambda(int)#1}::_FUN(int)
        mov     edi, DWORD PTR [rdx+4]
        mov     DWORD PTR [rdx], eax
        call    test(int*)::{lambda(int)#2}::_FUN(int)
        mov     DWORD PTR [rdx+4], eax
        ret


https://godbolt.org/z/fGqPKh81j

Reply via email to