https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66875
Bug ID: 66875 Summary: entire for loop got eliminated at cddce2 tree-opt stage Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: patricksung at gmail dot com Target Milestone: --- Created attachment 35985 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35985&action=edit Intermediate of the C source Hi the attached code in the parse_peppi_protocol() (which got inline into parse()) with the for loop (and nearby code) from line 10821 to line 10995 got eliminated. We found out this problem starting with GCC version 4.9.2 and subsequently also tested with GCC 4.9.3 and 5.1 also having this problem. One of the following two ways will work around this problem, 1) -fno-aggressive-loop-optimizations (obvious?) 2) change the for loop code from "for (...; i++)" to "for (...; --i)", i.e. the loop search backwards. We also found that the code elimination was happening at the "cddce2" stage of the tree optimization. Here is the command line used with the -v output (with compiler warnings removed that I believe is irrelevant to this problem to make the output a little bit cleaner here) x86_64-peplink-linux-gnu-gcc -D_LARGEFILE_SOURCE=1 -D_LARGE_FILES -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DXTABLES_LIBDIR=\"/usr/lib/xtables\" -DXTABLES_INTERNAL -I../include -I.. -I../include -I/home/psung/tmp/fw.63.ndpi-test/staging/usr/include -I/home/psung/tmp/fw.63.ndpi-test/staging/usr/include -Wp,-MMD,./.libxt_peppi.oo.d,-MT,libxt_peppi.oo -Wall -Waggregate-return -Wmissing-declarations -Wmissing-prototypes -Wredundant-decls -Wshadow -Wstrict-prototypes -Winline -pipe -D_INIT=libxt_peppi_init -DPIC -fPIC -Wextra -g -O3 -o libxt_peppi.oo -c libxt_peppi.c -dp -save-temps -fdump-tree-cddce2-details-stats -fno-strict-aliasing -fwrapv -v x86_64-peplink-linux-gnu-gcc: warning: -pipe ignored because -save-temps specified Using built-in specs. COLLECT_GCC=x86_64-peplink-linux-gnu-gcc Target: x86_64-peplink-linux-gnu Configured with: /home/psung/toolchains-2015/x64-4.9.3/.build/src/gcc-4.9.3/configure --build=x86_64-build_unknown-linux-gnu --host=x86_64-build_unknown-linux-gnu --target=x86_64-peplink-linux-gnu --prefix=/home/psung/x-tools-2015/x86_64-peplink-linux-gnu --with-sysroot=/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot --enable-languages=c,c++,go --with-pkgversion='crosstool-NG crosstool-ng-1.21.0-50-g488f7a8' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --with-gmp=/home/psung/toolchains-2015/x64-4.9.3/.build/x86_64-peplink-linux-gnu/buildtools --with-mpfr=/home/psung/toolchains-2015/x64-4.9.3/.build/x86_64-peplink-linux-gnu/buildtools --with-mpc=/home/psung/toolchains-2015/x64-4.9.3/.build/x86_64-peplink-linux-gnu/buildtools --with-ppl=no --with-isl=no --with-cloog=no --with-libelf=/home/psung/toolchains-2015/x64-4.9.3/.build/x86_64-peplink-linux-gnu/buildtools --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-gold --disable-nls --disable-multilib --with-local-prefix=/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot --enable-long-long Thread model: posix gcc version 4.9.3 (crosstool-NG crosstool-ng-1.21.0-50-g488f7a8) COLLECT_GCC_OPTIONS='-D' '_LARGEFILE_SOURCE=1' '-D' '_LARGE_FILES' '-D' '_FILE_OFFSET_BITS=64' '-D' '_REENTRANT' '-D' 'XTABLES_LIBDIR="/usr/lib/xtables"' '-D' 'XTABLES_INTERNAL' '-I' '../include' '-I' '..' '-I' '../include' '-I' '/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-I' '/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-Wall' '-Waggregate-return' '-Wmissing-declarations' '-Wmissing-prototypes' '-Wredundant-decls' '-Wshadow' '-Wstrict-prototypes' '-Winline' '-pipe' '-D' '_INIT=libxt_peppi_init' '-D' 'PIC' '-fPIC' '-Wextra' '-g' '-O3' '-o' 'libxt_peppi.oo' '-c' '-dp' '-save-temps' '-fdump-tree-cddce2-details-stats' '-fno-strict-aliasing' '-fwrapv' '-v' '-mtune=generic' '-march=x86-64' /home/psung/x-tools-2015/x86_64-peplink-linux-gnu/libexec/gcc/x86_64-peplink-linux-gnu/4.9.3/cc1 -E -quiet -v -I ../include -I .. -I ../include -I /home/psung/tmp/fw.63.ndpi-test/staging/usr/include -I /home/psung/tmp/fw.63.ndpi-test/staging/usr/include -D _LARGEFILE_SOURCE=1 -D _LARGE_FILES -D _FILE_OFFSET_BITS=64 -D _REENTRANT -D XTABLES_LIBDIR="/usr/lib/xtables" -D XTABLES_INTERNAL -D _INIT=libxt_peppi_init -D PIC -MMD ./.libxt_peppi.oo.d -MT libxt_peppi.oo libxt_peppi.c -mtune=generic -march=x86-64 -Wall -Waggregate-return -Wmissing-declarations -Wmissing-prototypes -Wredundant-decls -Wshadow -Wstrict-prototypes -Winline -Wextra -fPIC -fdump-tree-cddce2-details-stats -fno-strict-aliasing -fwrapv -g -fworking-directory -O3 -fpch-preprocess -o libxt_peppi.i ignoring nonexistent directory "/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/include" ignoring duplicate directory "../include" ignoring duplicate directory "/home/psung/tmp/fw.63.ndpi-test/staging/usr/include" #include "..." search starts here: #include <...> search starts here: ../include .. /home/psung/tmp/fw.63.ndpi-test/staging/usr/include /home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/include /home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/include-fixed /home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/../../../../x86_64-peplink-linux-gnu/include /home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/usr/include End of search list. COLLECT_GCC_OPTIONS='-D' '_LARGEFILE_SOURCE=1' '-D' '_LARGE_FILES' '-D' '_FILE_OFFSET_BITS=64' '-D' '_REENTRANT' '-D' 'XTABLES_LIBDIR="/usr/lib/xtables"' '-D' 'XTABLES_INTERNAL' '-I' '../include' '-I' '..' '-I' '../include' '-I' '/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-I' '/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-Wall' '-Waggregate-return' '-Wmissing-declarations' '-Wmissing-prototypes' '-Wredundant-decls' '-Wshadow' '-Wstrict-prototypes' '-Winline' '-pipe' '-D' '_INIT=libxt_peppi_init' '-D' 'PIC' '-fPIC' '-Wextra' '-g' '-O3' '-o' 'libxt_peppi.oo' '-c' '-dp' '-save-temps' '-fdump-tree-cddce2-details-stats' '-fno-strict-aliasing' '-fwrapv' '-v' '-mtune=generic' '-march=x86-64' /home/psung/x-tools-2015/x86_64-peplink-linux-gnu/libexec/gcc/x86_64-peplink-linux-gnu/4.9.3/cc1 -fpreprocessed libxt_peppi.i -quiet -dumpbase libxt_peppi.c -dp -mtune=generic -march=x86-64 -auxbase-strip libxt_peppi.oo -g -O3 -Wall -Waggregate-return -Wmissing-declarations -Wmissing-prototypes -Wredundant-decls -Wshadow -Wstrict-prototypes -Winline -Wextra -version -fPIC -fdump-tree-cddce2-details-stats -fno-strict-aliasing -fwrapv -o libxt_peppi.s GNU C (crosstool-NG crosstool-ng-1.21.0-50-g488f7a8) version 4.9.3 (x86_64-peplink-linux-gnu) compiled by GNU C version 4.7.3, GMP version 6.0.0, MPFR version 3.1.2, MPC version 1.0.2 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C (crosstool-NG crosstool-ng-1.21.0-50-g488f7a8) version 4.9.3 (x86_64-peplink-linux-gnu) compiled by GNU C version 4.7.3, GMP version 6.0.0, MPFR version 3.1.2, MPC version 1.0.2 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: a9b782f9952f9abb8547d3239b6bb751 ^ COLLECT_GCC_OPTIONS='-D' '_LARGEFILE_SOURCE=1' '-D' '_LARGE_FILES' '-D' '_FILE_OFFSET_BITS=64' '-D' '_REENTRANT' '-D' 'XTABLES_LIBDIR="/usr/lib/xtables"' '-D' 'XTABLES_INTERNAL' '-I' '../include' '-I' '..' '-I' '../include' '-I' '/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-I' '/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-Wall' '-Waggregate-return' '-Wmissing-declarations' '-Wmissing-prototypes' '-Wredundant-decls' '-Wshadow' '-Wstrict-prototypes' '-Winline' '-pipe' '-D' '_INIT=libxt_peppi_init' '-D' 'PIC' '-fPIC' '-Wextra' '-g' '-O3' '-o' 'libxt_peppi.oo' '-c' '-dp' '-save-temps' '-fdump-tree-cddce2-details-stats' '-fno-strict-aliasing' '-fwrapv' '-v' '-mtune=generic' '-march=x86-64' /home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/../../../../x86_64-peplink-linux-gnu/bin/as -v -I ../include -I .. -I ../include -I /home/psung/tmp/fw.63.ndpi-test/staging/usr/include -I /home/psung/tmp/fw.63.ndpi-test/staging/usr/include --64 -o libxt_peppi.oo libxt_peppi.s GNU assembler version 2.24 (x86_64-peplink-linux-gnu) using BFD version (crosstool-NG crosstool-ng-1.21.0-50-g488f7a8) 2.24 COMPILER_PATH=/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/libexec/gcc/x86_64-peplink-linux-gnu/4.9.3/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/libexec/gcc/x86_64-peplink-linux-gnu/4.9.3/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/libexec/gcc/x86_64-peplink-linux-gnu/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/../../../../x86_64-peplink-linux-gnu/bin/ LIBRARY_PATH=/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/../../../../x86_64-peplink-linux-gnu/lib/../lib64/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/lib/../lib64/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/usr/lib/../lib64/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/lib/gcc/x86_64-peplink-linux-gnu/4.9.3/../../../../x86_64-peplink-linux-gnu/lib/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/lib/:/home/psung/x-tools-2015/x86_64-peplink-linux-gnu/x86_64-peplink-linux-gnu/sysroot/usr/lib/ COLLECT_GCC_OPTIONS='-D' '_LARGEFILE_SOURCE=1' '-D' '_LARGE_FILES' '-D' '_FILE_OFFSET_BITS=64' '-D' '_REENTRANT' '-D' 'XTABLES_LIBDIR="/usr/lib/xtables"' '-D' 'XTABLES_INTERNAL' '-I' '../include' '-I' '..' '-I' '../include' '-I' '/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-I' '/home/psung/tmp/fw.63.ndpi-test/staging/usr/include' '-Wall' '-Waggregate-return' '-Wmissing-declarations' '-Wmissing-prototypes' '-Wredundant-decls' '-Wshadow' '-Wstrict-prototypes' '-Winline' '-pipe' '-D' '_INIT=libxt_peppi_init' '-D' 'PIC' '-fPIC' '-Wextra' '-g' '-O3' '-o' 'libxt_peppi.oo' '-c' '-dp' '-save-temps' '-fdump-tree-cddce2-details-stats' '-fno-strict-aliasing' '-fwrapv' '-v' '-mtune=generic' '-march=x86-64'