GCC loop unswitching is very good -- handles most of the cases I tried. The
only only thing I notice is that the nested for loops in C in the example below
is not converted into a perfect loop nest:
int** p;
int** q;
void foo(int m, int n)
{
int i, j;
for (i = 0; i < m; i++)
{
for (j = 0; j < n ; j++)
{
p[i][j] += q[i][j];
q[i][j] ++;
}
}
}
It is generated into (roughly) the following code by gcc (-O3
-fno-tree-vectorize)
if (m > 0)
{
do
{
if (n > 0 )
{
do
{
p[i][j] += q[i][j];
q[i][j] += 1;
j += 1;
} while ( j < n);
}
i+=1;
} while (i < m);
}
Ideally-- it should be:
if (m > 0)
{
if (n >0)
{
do
{
do
{
....
j++;
} while(...);
i++;
}while (...);
}
// empty loop deleted
}
--
Summary: Loop unswitching to produce perfect loop nest
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: xinliangli at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35344