https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70491
Bug ID: 70491 Summary: slow compilation initializing a VLA Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- Compiling a program that initializes a VLA is several times slower that compiling the same program that initializes an ordinary array. The following scripts create a pair of programs, the first initializes 100 arrays, and the second initializes 100 VLAs. The output shows the difference between the two using an unoptimized GCC build on powerpc64le. The difference between the two with an optimized GCC is less dramatic but the VLA case is still 3 times slower on x86_64. While compiling the VLA program is expected to take more cycles it shouldn't take several times as long as the equivalent program with ordinary arrays. $ (i=0; init=""; echo > z.cpp; while [ $i -lt 100 ]; do echo "int f$i (int n) { int a [$i] = { $init }; return a [0]; }" >> z.cpp; init="$init $i,"; i=$((i+1)); done && time /build/gcc-trunk/gcc/xgcc -B /build/gcc-trunk/gcc -S -Wall -xc++ z.cpp) real 0m0.545s user 0m0.543s sys 0m0.002s tmp$ (i=0; init=""; echo > z.cpp; while [ $i -lt 100 ]; do echo "int f$i (int n) { int a [n] = { $init }; return a [0]; }" >> z.cpp; init="$init $i,"; i=$((i+1)); done && time /build/gcc-trunk/gcc/xgcc -B /build/gcc-trunk/gcc -S -Wall -xc++ z.cpp) real 0m6.415s user 0m6.393s sys 0m0.022s