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

            Bug ID: 117091
           Summary: Severe Performance Regression in GCC Trunk vs GCC 6.1
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamanonymous.cs at gmail dot com
  Target Milestone: ---
            Target: x86_64

*******************************************************************************
I've encountered a significant performance regression when compiling the
following code on the GCC trunk version. The compilation process takes an
unusually long time (over 20 minutes without completion), whereas the same code
compiles quickly (in seconds) using GCC 6.1. This suggests a regression in the
trunk version of the compiler.

The code makes extensive use of macros to generate a large switch statement
with a pattern of repeated cases. The slowdown seems to be related to the
preprocessor expansion or the handling of the generated switch statement.
The issue can also be reproduced on Compiler Explorer.

*******************************************************************************
OS and Platform:
# uname -a
Linux ubuntu 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023
x86_64 x86_64 x86_64 GNU/Linux
*******************************************************************************
# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/root/gdbtest/gcc/gcc-241009/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/root/gdbtest/gcc/gcc-241009
--enable-languages=c,c++ --disable-multilib --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20241009 (experimental) (GCC) 
*******************************************************************************
Program:
# cat bugreport_0_1.c

int foo (int a, int b, int c)
{
  int d;
  switch (a)
    {
#define X(N) \
    case N ## 0: d = a + b; break; \
    case N ## 1: d = a + b; break; \
    case N ## 2: d = a + b; break; \
    case N ## 3: d = a + b; break; \
    case N ## 4: d = a + b; break; \
    case N ## 5: d = a + b; break; \
    case N ## 6: d = a + b; break; \
    case N ## 7: d = a + b; break; \
    case N ## 8: d = a + b; break; \
    case N ## 9: d = a + b; break;
#define XX(N) \
    X(N ## 0) X(N ## 1) X(N ## 2) X(N ## 3) X(N ## 4) X(N ## 5) X(N ## 6) X(N
## 7) X(N ## 8) X(N ## 9)
#define XXX(N) \
    XX(N ## 0) XX(N ## 1) XX(N ## 2) XX(N ## 3) XX(N ## 4) XX(N ## 5) XX(N ##
6) XX(N ## 7) XX(N ## 8) XX(N ## 9)
#define XXXX(N) \
    XXX(N ## 0) XXX(N ## 1) XXX(N ## 2) XXX(N ## 3) XXX(N ## 4) XXX(N ## 5)
XXX(N ## 6) XXX(N ## 7) XXX(N ## 8) XXX(N ## 9)
#define XXXXX(N) \
    XXXX(N ## 0) XXXX(N ## 1) XXXX(N ## 2) XXXX(N ## 3) XXXX(N ## 4) XXXX(N ##
5) XXXX(N ## 6) XXXX(N ## 7) XXXX(N ## 8) XXXX(N ## 9)
    XXXXX(1)
#if 0
    XXXXX(2)
    XXXXX(3)
    XXXXX(4)
    XXXXX(5)
    XXXXX(6)
    XXXXX(7)
    XXXXX(8)
    XXXXX(9)
#endif
    }
  return d;
}

*******************************************************************************
Steps to Reproduce:
1.Compile the above code using GCC trunk.
2.Observe the slow compilation time. (Even with -Os
https://godbolt.org/z/z5Wox3zTP)
3.Compile the same code using GCC 6.1 and notice the much faster compilation. (
https://godbolt.org/z/8TxehnKo7 )

Expected Behavior: The code should compile within a reasonable time frame,
similar to GCC 6.1.
Actual Behavior: The compilation on GCC trunk takes over 20 minutes and still
does not complete.

Please let me know if you need further details or if there are specific flags
to help debug this issue,thanks!
*******************************************************************************

Reply via email to