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

            Bug ID: 102356
           Summary: compile-time explosion at -O3
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: compile-time-hog
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi all.

It's quite weird that the following small valid program makes GCC spend too
much time on compiling at -O3 with the "-g" enabled. It seems GCC-11.x onwards
versions all suffer this issue.

$cat s.c
#include <stdint.h>
int8_t c_5 = 0x0;
uint8_t uc_9 = 0x09;
uint64_t uli_10 = 0xF1FBFC17225F7A57;
int32_t i_12 = 0x3A6667C6;
uint8_t func( uint32_t ui_14) {
    uint32_t *ptr_16 = &ui_14;
    if((uli_10 /= ((0 * (*ptr_16 *= uc_9)) <= 0))) 
        ;
    i_12 = 9;
    for ( ;i_12 > 2; i_12 -= 2 ) {
        uli_10 = -2;
        do      
            if ((*ptr_16 *= *ptr_16)){        
                c_5 = 4;        
                do{        
                    c_5 -=  3;         
                    if ((*ptr_16 *= *ptr_16))       
                        uc_9 = 9;              
                } while (c_5 > 2 );    
            }
        while ( uli_10 ++ );
    }
}

$time gcc -g -O3 -c s.c

real    10m25.417s
user    9m58.685s
sys     0m0.142s


$time gcc -g -O2 -c s.c

real    0m0.124s
user    0m0.045s
sys     0m0.011s


$gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/haoxin/haoxin-data/compilers/gcc/build/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure
--prefix=/home/haoxin/haoxin-data/compilers/gcc/build/ --enable-bootstrap
--enable-checking=release --enable-languages=c,c++ --enable-multilib :
(reconfigured) ../configure
--prefix=/home/haoxin/haoxin-data/compilers/gcc/build/ --enable-bootstrap
--enable-checking=release --enable-languages=c,c++ --enable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20210913 (experimental) (GCC) 

Reproduced in Godbolt: https://godbolt.org/z/47dqnPbad

Thanks,
Haoxin

Reply via email to