Jørgen Kvalsvik b1859c2a3d Improve speed of masking table algorithm for MC/DC
The masking table was computed by considering the cartesian product of
incoming edges, ordering the pairs, and doing upwards BFS searches
from the sucessors of the lower topologically index'd ones (higher in
the graph). The problem with this approach is that all the nodes we
find from the higher candidates would also be found from the lower
candidates, and since we want to collect the set intersection, any
higher candidate would be dominated by lower candidates.

We need only consider adjacent elements in the sorted set of
candidates.  This has a dramatic performance impact for large
functions.  The worst case is expressions on the form (x && y && ...)
and (x || y || ...) with up-to 64 elements. I did a wallclock
comparison of the full analysis phase (including emitting the GIMPLE):

test.c:
    int fn (int a[])
    {
      (a[0] && a[1] && ...) // 64 times
      (a[0] && a[1] && ...) // 64 times
      ...                   // 500 times
    }

    int main ()
    {
      int a[64];
      for (int i = 0; i != 10000; ++i)
        {
          for (int k = 0; k != 64; ++k)
            a[k] = i % k;
          fn1 (a);
        }
    }

Without this patch:
    fn1 instrumented in 20822.303 ms (41.645 ms per expression)

With this patch:
    fn1 instrumented in 1288.548  ms (2.577  ms per expression)

I also tried considering terms left-to-right and, whenever the search
found an already-processed expression it would stop the search and
just insert its complete table entry, but this had no measurable
impact on compile time, and the result was a slightly more complicated
function.

This inefficiency went unnoticed for a while, because these
expressions aren't very common.  The most I've seen in the wild is 27
conditions, and that involved a lot of nested expressions which aren't
impacted as much.

gcc/ChangeLog:

	* tree-profile.cc (struct conds_ctx): Add edges.
	(topological_src_cmp): New function.
	(masking_vectors): New search strategy.
2026-03-07 12:45:17 +01:00
2026-03-02 09:49:03 +00:00
2026-02-16 00:16:25 +00:00
2026-02-22 00:16:27 +00:00
2026-03-02 09:49:03 +00:00
2026-02-24 00:16:30 +00:00
2026-03-07 00:16:29 +00:00
2026-02-27 00:16:38 +00:00
2026-03-07 00:16:29 +00:00
2026-03-02 09:49:03 +00:00
2026-03-06 00:16:27 +00:00
2026-02-13 00:16:32 +00:00
2026-03-07 00:16:29 +00:00
2026-03-02 09:49:03 +00:00

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.
Description
No description provided
Readme 4.2 GiB
Languages
C++ 30.7%
C 30.2%
Ada 14.4%
D 6.1%
Go 5.7%
Other 12.4%