https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102981
Aldy Hernandez <aldyh at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |law at gcc dot gnu.org, | |matz at gcc dot gnu.org --- Comment #2 from Aldy Hernandez <aldyh at gcc dot gnu.org> --- I'm not sure what to do here. Perhaps one of the loop experts can opine. The threadable path starting at 2->11 could elide the call to foo(), but... <bb 2> [local count: 59046943]: goto <bb 11>; [100.00%] <bb 11> [local count: 177158542]: # c_12 = PHI <0(2), c_11(10)> # d_13 = PHI <0(2), d_18(10)> if (d_13 != 2) goto <bb 3>; [66.67%] else goto <bb 12>; [33.33%] The pre-loop threaders chose not to thread because it would destroy loop form. The late DOM pass can't even thread it, because the IL is too complex for it. The backward threader can easily see the candidate, but it has restrictions in place specifically to avoid peeling the first iteration of loops (regardless of loopdone): // This is like path_crosses_loops in profitable_path_p but more // restrictive, since profitable_path_p allows threading the // first block because it would be redirected anyhow. // // If we loosened the restriction and used profitable_path_p() // here instead, we would peel off the first iterations of loops // in places like tree-ssa/pr14341.c. I'm not sure massaging the above conditional will ultimately fix this, since the IL is sufficiently different, but that's the gist of it. This seems to be a special case where the first iteration of a loop has unreachable code, and the overly aggressives threaders in earlier GCC releases could elide it early in the pipeline. It also looks like a highly contrived testcase. Does this happen enough in real life that we should handle it? If so, should we try harder in the threader, or could another pass pick up the slack?