https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86889
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |missed-optimization Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org --- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> --- So the issue is that the __builtin_unreachable () elides the g >= 0 test, effectively making the loop endless. If you disable EVRP and CUNROLLI then VRP1 will do this transform. <bb 6> : # g_2 = PHI <1(2), g_7(5)> if (g_2 != -1) goto <bb 3>; [INV] else goto <bb 7>; [INV] It goes like EVRP computing the range of g_2 to [0, 1] (correctly, based on the __builtin_unreachable) and then CFG cleanup simplifying the conditional to false, removing the __builtin_unreachable () call. cunrolli then computes the loop to run twice and inserts that stray [-1] array reference, exposing it's old latent issue of sometimes emitting stray iterations as the reporter already analyzed (it can at most handle the _last_ iteration when marking blocks as never executed, but in cases where the IV increment is at unfortunate places it has to look at the previous peeled copy as well). Maybe I can get to improve this. Don't hold your breath. I think we have dups of this (but maybe closed because they no longer warn).