This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/57186] New: implement load sinking in loops
- From: "ebotcazou at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 06 May 2013 14:50:44 +0000
- Subject: [Bug tree-optimization/57186] New: implement load sinking in loops
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57186
Bug #: 57186
Summary: implement load sinking in loops
Classification: Unclassified
Product: gcc
Version: 4.9.0
URL: http://gcc.gnu.org/ml/gcc-patches/2012-10/msg00742.htm
l
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: ebotcazou@gcc.gnu.org
Created attachment 30040
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30040
Original implementation
Even at -O3, the compiler doesn't figure out that the following loop is dumb:
#define SIZE 64
int foo (int v[])
{
int r;
for (i = 0; i < SIZE; i++)
r = v[i];
return r;
}
This isn't entirely unexpected, as it probably matters only for (slightly)
pathological cases. The attached patch nevertheless implements a form of load
sinking in loops so as to optimize these cases. It's combined with invariant
motion to optimize:
int foo (int v[], int a)
{
int r, i;
for (i = 0; i < SIZE; i++)
r = v[i] + a;
return r;
}
and with store sinking to optimize:
int foo (int v1[], int v2[])
{
int r[SIZE];
int i, j;
for (j = 0; j < SIZE; j++)
for (i = 0; i < SIZE; i++)
r[j] = v1[j] + v2[i];
return r[SIZE - 1];
}
The optimization is enabled at -O2 in the patch for measurement purposes but,
given how rarely it triggers (e.g. exactly 10 occurrences in a GCC bootstrap,
compiler-only, all languages except Go), it's probably best suited to -O3.
It also comes with 3 testcases.