https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104067
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |law at gcc dot gnu.org --- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> --- extern void abort (); struct S { int x; } a[10]; struct S *b; int main () { int i, j = 0; struct S *q = a; for (i = 100; --i > 0; ) { struct S *p; j++; if (j >= 10) j = 0; p = &a[j]; if (p == q) abort (); __atomic_thread_fence (__ATOMIC_SEQ_CST); q = p; } return 0; } This goes wrong in threadfull2, strlen1 looks correct to me: <bb 2> [local count: 10737416]: <bb 3> [local count: 1063004409]: # j_17 = PHI <j_2(9), 0(2)> # q_18 = PHI <prephitmp_16(9), &a(2)> # ivtmp_4 = PHI <ivtmp_3(9), 99(2)> j_8 = j_17 + 1; if (j_8 == 10) goto <bb 5>; [34.00%] else goto <bb 4>; [66.00%] <bb 4> [local count: 701582906]: _1 = (sizetype) j_8; _15 = _1 * 4; _14 = &a + _15; <bb 5> [local count: 1063004409]: # j_2 = PHI <j_8(4), 0(3)> # prephitmp_16 = PHI <_14(4), &a(3)> if (prephitmp_16 == q_18) goto <bb 6>; [0.00%] else goto <bb 7>; [100.00%] <bb 6> [count: 0]: abort (); <bb 7> [local count: 1063004409]: __atomic_thread_fence (5); ivtmp_3 = ivtmp_4 - 1; if (ivtmp_3 != 0) goto <bb 9>; [99.00%] else goto <bb 8>; [1.00%] <bb 9> [local count: 1052374367]: goto <bb 3>; [100.00%] <bb 8> [local count: 10737416]: return 0; but threadfull2 turns that into something that weirdly starts with: <bb 2> [local count: 10737416]: j_8 = 1; if (j_8 == 10) goto <bb 4>; [34.00%] else goto <bb 3>; [66.00%] <bb 3> [local count: 701582906]: # ivtmp_22 = PHI <99(2), ivtmp_12(7)> # j_24 = PHI <j_8(2), j_20(7)> # q_25 = PHI <&a(2), q_7(7)> _1 = (sizetype) j_24; _15 = _1 * 4; _14 = &a + _15; <bb 4> [local count: 705197120]: # j_2 = PHI <j_24(3), 0(2)> # prephitmp_16 = PHI <_14(3), &a(2)> # ivtmp_23 = PHI <ivtmp_22(3), 99(2)> # q_26 = PHI <q_25(3), &a(2)> if (prephitmp_16 == q_26) goto <bb 5>; [0.00%] else goto <bb 6>; [100.00%] <bb 5> [count: 0]: abort (); and for j == 10 turns it into unconditional abort: j_20 = j_21 + 1; if (j_20 == 10) goto <bb 8>; [34.00%] else goto <bb 3>; [66.00%] <bb 8> [local count: 357807289]: # j_5 = PHI <0(7)> # prephitmp_9 = PHI <&a(7)> goto <bb 5>; [100.00%]