https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118527
--- Comment #1 from Di Zhao <dizhao at os dot amperecomputing.com> --- The change below can fix the problem. But it appears not quite efficient. (I tried to do this in cfg cleanup stage, but haven't succeeded with that.) How do you think of this? diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 6d0202ad436..ceb093c608a 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -8849,6 +8849,27 @@ do_rpo_vn_1 (function *fn, edge entry, bitmap exit_bbs, todo |= avail.eliminate_cleanup (do_region); } + /* If the back-edge of a loop is marked as unexecutable, then the loop will be + unlooped. Update the profile counts accordingly. */ + if (iterate && (todo | TODO_cleanup_cfg)) + { + for (loop_p loop : *get_loops (cfun)) + { + if (!(loop && loop->header && loop->latch)) + continue; + if (!(loop->header->flags & BB_EXECUTABLE)) + continue; + edge e = loop_latch_edge (loop); + if (!(e->flags & EDGE_EXECUTABLE) + && loop->header->count.initialized_p ()) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "Loop %d won't iterate\n", loop->num); + scale_loop_profile (loop, profile_probability::always (), 0); + } + } + } + vn_valueize = NULL; rpo_avail = NULL;