Hi, For this small test case,
int a[512] ; int b[512] ; int *a_p ; int *b_p ; int i ; int k ; int f(void) { for( k = 1 ; k <= 9 ; k++) { for( i = k ; i < 512 ; i += k) { a_p = &a[i + (1<<k)] ; b_p = &b[i + (1<<k)] ; *a_p = 7 ; *b_p = 7 ; } } } Before sink pass we have, f () { int pretmp.11; int k.7; int i.6; int * b_p.3; int * a_p.2; int D.2248; int i.1; int D.2246; int k.0; <bb 2>: k = 1; <bb 3>: # k.0_9 = PHI <k.7_20(11), 1(2)> i = k.0_9; if (k.0_9 <= 511) goto <bb 7>; else goto <bb 8>; <bb 8>: Invalid sum of incoming frequencies 900, should be 81 goto <bb 5>; <bb 7>: pretmp.11_19 = 1 << k.0_9; <bb 4>: # i.1_34 = PHI <i.6_18(9), k.0_9(7)> D.2246_5 = pretmp.11_19; D.2248_7 = i.1_34 + D.2246_5; a_p.2_8 = &a[D.2248_7]; a_p = a_p.2_8; b_p.3_13 = &b[D.2248_7]; b_p = b_p.3_13; MEM[(int *)&a][D.2248_7] = 7; MEM[(int *)&b][D.2248_7] = 7; i.6_18 = k.0_9 + i.1_34; i = i.6_18; if (i.6_18 <= 511) goto <bb 9>; else goto <bb 8>; <bb 9>: goto <bb 4>; <bb 5>: Invalid sum of incoming frequencies 81, should be 900 k.7_20 = k.0_9 + 1; k = k.7_20; if (k.7_20 <= 9) goto <bb 11>; else goto <bb 6>; <bb 11>: goto <bb 3>; <bb 6>: return; } Can the following statements be sinked out of loop? I don't see this optimization happen in trunk. The consequence is register pressure increased and a spill/fill occurs in RA. a_p.2_8 = &a[D.2248_7]; a_p = a_p.2_8; b_p.3_13 = &b[D.2248_7]; b_p = b_p.3_13; I know the sink would happen in sink pass if a_p and b_p are local variables. If this is the root cause, which optimization pass in GCC take the role to sink them out of loop? How should we get it fixed? Thanks, -Jiangning