https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83234
Bug ID: 83234 Summary: Aggressive loop optim warning for loop iteration that cannot happen Product: gcc Version: 6.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: ketan.surender at gmail dot com Target Milestone: --- Created attachment 42759 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42759&action=edit Reproduction File I have an example program with the code: for (j = 0; j < 3; j++) { for (i = 1; i <= 3 - j; i++) { out8[i - 1][j] = (int8_T)(i + j); } for (i = 4 - j; i < 4; i++) { out8[i - 1][j] = in15[(i + j) - 3]; } } that produces the warning hankel_script.c: In function ‘hankel_script’: hankel_script.c:235:32: warning: iteration 2147483644 invokes undefined behavior [-Waggressive-loop-optimizations] out8[i - 1][j] = in15[(i + j) - 3]; ~~~^~~~ hankel_script.c:234:5: note: within this loop for (i = 4 - j; i < 4; i++) { The loop bounds have been defined with constants such that iteration 2147483644 cannot happen. Repro: gcc -c -O2 hankel_script.i I do not see the warning with -O3 or -O1. My gcc version is 6.3. See details below. I am able to reproduce this using x86-64 gcc 7.2 on https://gcc.godbolt.org/. COLLECT_GCC=gcc Target: x86_64-pc-linux-gnu Configured with: [SCRUB]/sources/gcc-6.3/configure --with-gmp=[SCRUB]/gcc-6.3/gmp-4.3 --with-mpfr=[SCRUB]/gcc-6.3/mpfr --with-mpc=[SCRUB]/gcc-6.3/mpc --enable-languages=c,c++,fortran --with-bugurl=[SCRUB],_Debugging --enable-shared --enable-linker-build-id --enable-plugin --enable-checking=release --enable-multiarch --enable-gold --enable-ld=default --prefix=[SCRUB]/gcc-6.3.0 --with-pkgversion='MW GCC 6.3.0-GLIBC2.11' --with-tune=generic --with-system-zlib --enable-multilib --with-multilib-list=m32,m64 --with-arch-directory=amd64 --with-arch-32=i586 --with-abi=m64 gcc version 6.3.0 (MW GCC 6.3.0-GLIBC2.11)