https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92839
Bug ID: 92839 Summary: Normalize memory address to same base in non-loop code Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: fxue at os dot amperecomputing.com Target Milestone: --- If possible, IVOPTs can transform memory accesses to make them use same base, which can decrease register pressure in loop. But it does not handle memory address that is not an iv, or in a pure non-loop code. Consider the following example, compile with -O3, we can find that data[b + ?] will use same base register. But if we remove the line "for (i = 0; i < n; i++, b++)" to make it be non-loop code, data[b + ?] will use different bases, with result that we have to consume 10 register as bases, which is a much higher register pressure. And since live ranges of these base registers cross function call, most of them will be spilled to memory. int data[100]; int fn(); void foo(int b, int n) { int i; for (i = 0; i < n; i++, b++) // remove the statement to be non-loop { data[b + 1] += 1; data[b + 3] += 3; data[b + 5] += 5; data[b + 7] += 7; data[b + 9] += 9; data[b + 11] += 11; data[b + 13] += 13; data[b + 15] += 15; data[b + 17] += 17; data[b + 19] += 19; fn (); data[b + 1] -= 1; data[b + 3] -= 3; data[b + 5] -= 5; data[b + 7] -= 7; data[b + 9] -= 9; data[b + 11] -= 11; data[b + 15] -= 13; data[b + 17] -= 15; data[b + 19] -= 19; } }