https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87074
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- outer->header is: bb_4 (preds = {bb_3 bb_11 }, succs = {bb_5 }) { <bb 4> [local count: 118111601]: # f.10_31 = PHI <f.10_27(3), _12(11)> # .MEM_34 = PHI <.MEM_18(D)(3), .MEM_21(11)> # g_lsm.15_33 = PHI <g_lsm.15_13(3), _9(11)> _75 = (unsigned int) g_lsm.15_33; } the bb into which the inner loop exits is: bb_6 (preds = {bb_5 }, succs = {bb_11 bb_7 }) { <bb 6> [local count: 118111601]: # _11 = PHI <_8(5)> _9 = (int) _11; _12 = f.10_31 + 1; if (_12 <= 10) goto <bb 11>; [89.00%] else goto <bb 7>; [11.00%] } and outer->latch is: bb_11 (preds = {bb_6 }, succs = {bb_4 }) { <bb 11> [local count: 105119325]: goto <bb 4>; [100.00%] } >From what I can see, gimple-loop-jam.c verifies using bb_prevents_fusion_p these 3 bbs, but nothing checks the outer loop's IVs. The problem is that a value computed by the inner loop (_8) is then used inside of the outer loop and fed into the next inner loop too. So, shall we punt if there are any phis in single_exit (loop)->dest (other than virtual) (assuming here that we are in loop closed SSA form) and thus there are any SSA_NAME uses from the inner loop to next outer loop's iteration? Or are there perhaps any exceptions that can be handled, like if a value computed by the inner loop is not used only after the outer loop exits?