On 11/12/26 8:34 AM, [email protected] wrote:
From: Kyrylo Tkachov <[email protected]>

Each copy of a dispatch made by pass_duplicate_computed_gotos gets an edge
to every target of the original.  The number of new edges is therefore the
product of the number of copies and the number of targets, which is
quadratic in the size of an interpreter.  The instruction budget does not
bound this, since a copy of a shared-table dispatch is only a few insns.

Since -fduplicate-switch-dispatch became the default at -O2, compiling
POVRay fnpovfpu.cpp copies a 971-target dispatch 830 times and adds about
660000 edges.  Compared with -fno-duplicate-switch-dispatch, compile time
grows by a factor of 8.5 and peak memory by a factor of 5.6, mostly in
RTL-SSA construction for fold-mem-offsets and the AArch64 reorg pass.

Add --param=max-goto-duplication-edges, the number of edges that the
copies in one function may add.  Charge each copy for its edges, and stop
copying once the budget cannot cover another copy.  The limit applies to
computed gotos and to switch dispatches alike.

The default of 131072 leaves the dispatch copies of CPython, QuickJS, Lua
and mawk unchanged, the largest of which adds about 93000 edges.  On
fnpovfpu.cpp it keeps 165 of the 830 copies.  At -O2 this reduces the
compile time of that file by 77% and its peak memory by 67%, and the
compile time of the whole of 511.povray_r by 12%.  Duplication does not
change the runtime of 511.povray_r, as the interpreter does not run in the
benchmark.

Bootstrapped and tested on aarch64-none-linux-gnu.
Ok for trunk?
Thanks,
Kyrill

Cc: Jeff Law <[email protected]>

gcc/ChangeLog:

        PR target/128512
        * params.opt (--param=max-goto-duplication-edges=): New param.
        * doc/params.texi (max-goto-duplication-edges): Document.
        * bb-reorder.cc (maybe_duplicate_dispatch): Add EDGE_BUDGET
        parameter.  Stop copying once it cannot cover the edges of a copy.
        (duplicate_computed_gotos): Initialize it from the param.

gcc/testsuite/ChangeLog:

        PR target/128512
        * gcc.dg/duplicate-computed-goto-3.c: New test.
        * gcc.dg/switch-dispatch-6.c: New test.

Signed-off-by: Kyrylo Tkachov <[email protected]>
LGTM and Sashiko clean.  OK for the trunk.

jeff

Reply via email to