https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118294
Bug ID: 118294 Summary: GCC doesn't unroll the outer loop of a nest where the outer body trivially only runs once Product: gcc Version: 15.0 URL: https://godbolt.org/z/G7WfxM3e7 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: tiborgyri at gmail dot com Target Milestone: --- In this example: https://godbolt.org/z/G7WfxM3e7 the outer loop "for (TT j=0; j<Nperm; j++)" trivially never loops, since Nperm=1 and the loop body does not modify j. This means there is no point in not unrolling it trivially (trip count of 1), which is what clang does. For some reason GCC gets confused by this loop nest and writes messages into the optimization log like: "not vectorized: could not determine main exit from loop with multiple exits" I do not see any multiple exits. Also, there is this message in stdout which I find slightly suspicious: "hotter_than_inner_loop is NULL". hotter_than_inner_loop sounds like something that should be a bool, so it being NULL is a bit funky, but I do not know GCC's internals enough to tell if that indicates a bug. Note that increasing Nperm to 2 results in the outer loop being correctly unrolled, so only the edge case of the loop body getting executed only once is mishandled. I am not sure which component is responsible for this, as other unroll related bugs seem to be spread across middle-end/rtl/tree, so I am filing this for tree-optimization as a guess.