https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87540
Bug ID: 87540 Summary: Missed inner loop hoist if the loop does not depend on outer loop Product: gcc Version: 8.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: david.bolvansky at gmail dot com Target Milestone: --- Not sure how often this happens in the real world apps but anyway idea is.. int foo(void) { double *array = calloc(ARRAY_SIZE, sizeof(double)); double sum = 0; int i; for (i = 0; i < N_TIMES; i++) { // lot of code // well, this loop does not even depend on "i", hoist it? for (int j = 0; j < ARRAY_SIZE; j += 8) { sum += array[j] + array[j+1] + array[j+2] + array[j+3] + array[j+4] + array[j+5] + array[j+6] + array[j+7]; } } return sum; } Let's say we have the big outer loop with many inner loops. GCC should detect if these loops really depend on the outer loop and if not, hoist them out of this loop.