https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93042
Bug ID: 93042 Summary: bit-field optimizations get in the way of interchange Product: gcc Version: 10.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: #define N 100 #define M 1111 struct S { int a : 3; int b : 17; int c : 12; }; struct S A[N][M]; int __attribute__((noinline)) foo (void) { int i, j; for( i = 0; i < M; i++) for( j = 0; j < N; j++) { int t = 0; struct S s1 = A[j][i]; if (s1.b) t++; A[j][i].a = t; } return A[0][0].a + A[N-1][M-1].a; } ----- CUT ---- If we change the loop slightly, to not to use a temp struct or even add a temp var to hold s1.b, the loop can be interchanged. That is: int __attribute__((noinline)) foo1 (void) { int i, j; for( i = 0; i < M; i++) for( j = 0; j < N; j++) { int t = 0; if (A[j][i].b) t++; A[j][i].a = t; } return A[0][0].a + A[N-1][M-1].a; } int __attribute__((noinline)) foo2 (void) { int i, j; for( i = 0; i < M; i++) for( j = 0; j < N; j++) { int t = 0; struct S s1 = A[j][i]; int t1 = s1.b; if (t1) t++; A[j][i].a = t; } return A[0][0].a + A[N-1][M-1].a; } ----- CUT ---- This shows up slightly different when I add lowering of bit-field accesses but in a different way.