https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103300
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |matz at gcc dot gnu.org
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> (In reply to hubicka from comment #2)
> > Needs -O2 -floop-unroll-and-jam --param early-inlining-insns=14
> > to fail, so I guess it may be issue with unrol-and-jam.
>
> The major difference I see between GCC 11 and GCC 12 is how tree-loop-im
> handles the load/store of a and c. In GCC 11, it was an unconditional move
> of the store of a and c while in GCC 12 we get some interesting branches:
> <bb 9> [local count: 35059055]:
> # a_lsm.21_25 = PHI <_20(D)(6), _15(8)>
> # a_lsm_flag.22_8 = PHI <0(6), 1(8)>
> # c_lsm.23_22 = PHI <0(6), _5(8)>
> if (c_lsm.23_22 <= 2)
> goto <bb 17>; [94.50%]
> else
> goto <bb 10>; [5.50%]
>
> <bb 10> [local count: 1928248]:
> # a_lsm_flag.22_14 = PHI <a_lsm_flag.22_8(9)>
> # a_lsm.21_28 = PHI <a_lsm.21_25(9)>
> c_lsm.23_27 = 3;
> if (a_lsm_flag.22_14 != 0)
> goto <bb 11>; [66.67%]
> else
> goto <bb 12>; [33.33%]
>
> <bb 11> [local count: 1285499]:
> c = c_lsm.23_27;
>
> <bb 12> [local count: 1285499]:
> if (a_lsm_flag.22_14 != 0)
> goto <bb 13>; [66.67%]
> else
> goto <bb 14>; [33.33%]
>
> <bb 13> [local count: 856999]:
> a = a_lsm.21_28;
>
> <bb 14> [local count: 1928248]:
That's likely a missed threading / header copying, the stores are conditional
now and thus need protecting against store data races.
What unroll-and-jam does is make the inner loop enter always, only considering
the loop header check for the second iteration and also fails to include the
increment. That's likely a latent issue, maybe because the latch of the
outer loop is not empty?
Testcase that fails with -O2 -floop-unroll-and-jam:
int a, b[2], c, d, e, f;
int g(int h, int i) { return !i || h && i == 1 ? 0 : h % i; }
static void j() {
while (1)
while (1) {
if (d)
L:
if (f)
break;
if (e)
goto L;
return;
}
}
int main() {
j();
for (c = 0; c < 3; c++)
for (a = 0; a < 2; a++)
if (g(0, b[a]++))
while (1)
;
if (b[1] != 3)
__builtin_abort();
return 0;
}
Micha?