We should produce the same code in the two loops
unsigned short *q;
#define NOSB 10
int last;
void h1()
{
int i;
for (i=0;i<last+NOSB;i++)
{
q[i] = 0;
}
}
-----
unsigned short q[100];
#define NOSB 10
int last;
void h1()
{
int i;
for (i=0;i<last+NOSB;i++)
{
q[i] = 0;
}
}
For the array one we produce:
L4:
sth r0,0(r2)
addi r2,r2,2
bdnz L4
which is optimial but for the pointer one we produce:
L4:
slwi r2,r9,1
addi r9,r9,1
sthx r0,r2,r11
bdnz L4
which sucks as we have tree instructions in the loop instead of two.
I think this is a place where IV-OPTS is failing.
--
Summary: Code for arrays and pointers are not the same
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P2
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: pinskia at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18431