Thread overview
[Issue 23857] backend inliner takes too long on recursive function call
Apr 24, 2023
Dennis
May 03, 2023
Dlang Bot
Jul 21, 2023
Dlang Bot
Jul 23, 2023
Walter Bright
Jul 23, 2023
Walter Bright
Jul 23, 2023
Dlang Bot
Jul 23, 2023
Dlang Bot
April 24, 2023
https://issues.dlang.org/show_bug.cgi?id=23857

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |backend
                 CC|                            |dkorpel@live.nl
           Hardware|x86_64                      |All
            Summary|Compilation of certain      |backend inliner takes too
                   |recursion takes too long    |long on recursive function
                   |                            |call
                 OS|Linux                       |All

--- Comment #1 from Dennis <dkorpel@live.nl> ---
This is a problem with the dmd's backend inliner recursively trying to inline f. `-release` is needed to remove bounds checks, otherwise it doesn't inline it. By using .ptr on a, the -release switch is not needed. Reduced a bit further:

```D
int f(int[] a, int u)
{
    return (a.ptr[u] < 0) ? u : (a.ptr[u] = f(a, a.ptr[u]));
}

void main()
{
    f([], 0);
    f([], 0);
}
```

--
May 03, 2023
https://issues.dlang.org/show_bug.cgi?id=23857

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright created dlang/dmd pull request #15172 "fix Issue 23857 and fix Issue 23880" fixing this issue:

- fix Issue 23857 and fix Issue 23880

https://github.com/dlang/dmd/pull/15172

--
July 21, 2023
https://issues.dlang.org/show_bug.cgi?id=23857

--- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> ---
@dkorpel created dlang/dmd pull request #15437 "Fix 23857 - backend inliner takes too long on recursive function call" fixing this issue:

- Fix 23857 - backend inliner takes too long on recursive function call

https://github.com/dlang/dmd/pull/15437

--
July 23, 2023
https://issues.dlang.org/show_bug.cgi?id=23857

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
> It takes ~26 seconds on my PC (WSL2, DMD64 D Compiler v2.103.0).

Notice "30" in this line in backend/go.d:

        if (!(go.changes && go.mfoptim & MFloop && (clock() - starttime) < 30 *
CLOCKS_PER_SEC))

It's there to prevent infinite loop if the optimizer cannot find a stable state.

--
July 23, 2023
https://issues.dlang.org/show_bug.cgi?id=23857

--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> ---
The inliner itself prevents recursive inlining by setting the Finlinenest flag. But that flag is turned off when scanForInlines() returns. And then the optimizer calls scanForInlines() again, it inlines again, opening up more opportunities for other optimizations, and then the optimizer calls it again.

The easy way to fix this is to only call scanForInlines() once per function.

--
July 23, 2023
https://issues.dlang.org/show_bug.cgi?id=23857

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright created dlang/dmd pull request #15447 "fix Issue 23857 - backend inliner takes too long on recursive functio…" fixing this issue:

- fix Issue 23857 - backend inliner takes too long on recursive function call

https://github.com/dlang/dmd/pull/15447

--
July 23, 2023
https://issues.dlang.org/show_bug.cgi?id=23857

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #15447 "fix Issue 23857 - backend inliner takes too long on recursive functio…" was merged into stable:

- cead34eb03273dd4b9a00856a08a598f93b86fdb by Walter Bright:
  fix Issue 23857 - backend inliner takes too long on recursive function call

https://github.com/dlang/dmd/pull/15447

--