https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78725
--- Comment #4 from Michael Matz <matz at gcc dot gnu.org> --- Thanks for the second testcase as well. It's not quite the same miscompilation (the induction vars don't overflow), but a related one (the value of d considered in the conditional statement is the final one after the d-loop finishes, not the value at the use itself). Fixed with v2 of the patch, at https://gcc.gnu.org/ml/gcc-patches/2016-12/msg01035.html .