https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115579
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2024-06-21 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Confirmed. LIM is doing it wrong: ``` <bb 2> [local count: 118111600]: a.0_1 = a; ... b_lsm.10_17 = _16(D); goto <bb 4>; [100.00%] ... <bb 4> [local count: 1073741824]: # d_I_lsm.9_13 = PHI <d_I_lsm.9_15(2), d_I_lsm.9_18(3)> # b_lsm.10_14 = PHI <b_lsm.10_17(2), b_lsm.10_19(3)> if (a.0_1 != 0) goto <bb 3>; [89.00%] else goto <bb 5>; [11.00%] <bb 5> [local count: 118111600]: # d_I_lsm.9_23 = PHI <d_I_lsm.9_13(4)> # b_lsm.10_24 = PHI <b_lsm.10_14(4)> d[1] = d_I_lsm.9_23; b = b_lsm.10_24; ... ``` Why was the store to b an unconditional one here? Before LIM: ``` <bb 2> [local count: 118111600]: goto <bb 4>; [100.00%] <bb 3> [local count: 955630224]: d[1] = 0; b = 0; <bb 4> [local count: 1073741824]: a.0_1 = a; if (a.0_1 != 0) goto <bb 3>; [89.00%] else goto <bb 5>; [11.00%] ``` It looks like it is pulling out d[1] of the loop unconditionally and that also causes b to be done unconditionally ... So -Os is needed because we can't see the loop is an infinite one too ...