This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/24669] New: Loop index variable has offset of 1
- From: "uros at kss-loka dot si" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Nov 2005 09:05:46 -0000
- Subject: [Bug tree-optimization/24669] New: Loop index variable has offset of 1
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
A simple loop:
void foo (int *a, int *b)
{
int i;
for (i = 0; i < 4; i++)
b[i] = a[i];
}
gets compiled to (gcc -O2 -fomit-frame-pointer):
pushl %ebx
movl $1, %edx <<< index starts with 1
movl 8(%esp), %ebx
movl 12(%esp), %ecx
.p2align 4,,15
.L2:
movl -4(%ebx,%edx,4), %eax <<< it is compensated by -4 here
movl %eax, -4(%ecx,%edx,4) <<< and here
incl %edx
cmpl $5, %edx <<< compare with N+1
jne .L2
popl %ebx
ret
The problem is, that index variable has offset of 1 and it has to be
compensated by appropriate negative offset in the address.
The optimized tree dump shows:
<bb 0>:
ivtmp.33 = 1;
<L0>:;
D.1347 = (int *) ivtmp.33;
MEM[base: b, index: D.1347, step: 4B, offset: -4B] = MEM[base: a, index:
D.1347, step: 4B, offset
: -4B];
ivtmp.33 = ivtmp.33 + 1;
if (ivtmp.33 != 5) goto <L0>; else goto <L2>;
<L2>:;
return;
One would expect the index to start with 0 as this enables use of xor for
initialization. Perhaps non-zero address offset also disables some
optimizations.
--
Summary: Loop index variable has offset of 1
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: uros at kss-loka dot si
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24669