This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/47186] New: -O2 moves invariant address load INTO loop
- From: "gcc.hall at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 6 Jan 2011 09:33:09 +0000
- Subject: [Bug target/47186] New: -O2 moves invariant address load INTO loop
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47186
Summary: -O2 moves invariant address load INTO loop
Product: gcc
Version: 4.5.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: gcc.hall@gmail.com
Host: Fedora 14
Target: i?86-*-*
Build: 4.5.1 20100924 (Red Hat 4.5.1-4)
gcc -O1 try.c -S -masm=intel -o try.s
In the example below, the address load to esi for the movsd is moved into the
loop when -O2 is used. With -O1 its outside the loop.
Perhaps this is something to do with scheduling? I tried with various x86
targets and it always happened, although the position of the address load
within the loop changed between atom and core2 for example.
--------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int mike[100], joe[100];
int main( int argc, char *argv[] )
{
int i;
for( i = 0; i < 100; ++i )
mike[i] = rand();
memcpy( joe, mike, sizeof(joe) );
}
--------------------------------------
Compile with -O1 produces ...
.L2:
call rand
mov DWORD PTR mike[0+ebx*4], eax
add ebx, 1
cmp ebx, 100
jne .L2
mov edi, OFFSET FLAT:joe
mov esi, OFFSET FLAT:mike
mov ecx, 100
rep movsd
Now repeat with -O2, and esi is loaded within the loop
.L2:
call rand
mov esi, OFFSET FLAT:mike
mov DWORD PTR mike[0+ebx*4], eax
add ebx, 1
cmp ebx, 100
jne .L2
mov ecx, ebx
mov edi, OFFSET FLAT:joe
rep movsd