https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104543
--- Comment #11 from Michael Matz <matz at gcc dot gnu.org> --- (In reply to Richard Biener from comment #5) > in particular the comment in bb_prevents_fusion_p saying > > /* BB is duplicated by outer unrolling and then all N-1 first copies > move into the body of the fused inner loop. If BB exits the outer loop > the last copy still does so, and the first N-1 copies are cancelled > by loop unrolling, so also after fusion it's the exit block. > > looks wrong. Yes, the first is cancelled but the remaining is not the > exit block. I think your patch is fine and fixes the bug. We can possibly do better also for head-controlled loops by just reversing the above: the _first_ of the N exit-bb copies needs to remain (and stay in front of the inner loop), and the last N-1 copies need to be cancelled. Needs to be carefully thought through, but something like that should be possible.