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

            Bug ID: 128905
           Summary: [13/14/15/16/17 Regression] compile-time hog at -O3 in
                    dom2 after loop header copying, exponential in the
                    loop trip count
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: compile-time-hog
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi,

$cat repro.c

int a;

unsigned
f (unsigned c)
{
  unsigned d = c;
  do
    {
      if (c & a)
        break;
      for (unsigned i = 0; i < 11; i++)
        for (unsigned j = 0; j < 4; j++)
          {
            d = d * d;
            d += c;
          }
    }
  while (1);
  return d;
}



$ gcc -O2 -c repro.c                          # 0.03 s (also -O1, -Os)
$ gcc -O3 -c repro.c                          # does not finish (killed after
60 s; > 5 min seen)
$ gcc -O3 -fdisable-tree-dom2 -c repro.c      # 0.04 s
$ gcc -O3 -fdisable-tree-ch2 -c repro.c       # 0.04 s   (also -fno-tree-ch,
-fno-tree-dominator-opts)


Compile time at -O3 grows explosively with the outer trip count:

| outer loop | compile time |
|---    |---    |
| i < 4 | 0.6 s |
| i < 5 | 5.7 s |
| i < 6 | > 60s |

At i < 5, -ftime-report puts all of the time essentially (6.06 s of 6.08 s) in
"dominator optimization". `-fno-thread-jumps` does not help. The code is valid,
and gcc -Wall -Wextra is clean.

## Checked Versions

- Hangs: GCC 13, 14, 15, 16 and trunk (17.0.0 20261119, --enable-checking=yes).
- Fine: GCC 11, GCC 12, and clang.

Reproduced in Godbolt: https://godbolt.org/z/WhT9YEfxM

Thanks.

Reply via email to