public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/27055] New: Structures are copied byte by byte into function arguments
@ 2006-04-06 11:46 guillaume dot melquiond at ens-lyon dot fr
2006-04-06 12:03 ` [Bug c/27055] " gdr at integrable-solutions dot net
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: guillaume dot melquiond at ens-lyon dot fr @ 2006-04-06 11:46 UTC (permalink / raw)
To: gcc-bugs
I tried the following testcase with various GCC versions available as Debian
packages. With 3.3.5, the copy from *a to the stack frame of g is done
word-by-word with rep movsl. With 3.4.4, it is done by memcpy. Both previous
methods are fine. With 3.4.6, the copy is done byte-by-byte without string
opcodes. With 4.0.3 and 4.1.0, it is done byte-by-byte and out-of-line: there
are two jumps for each copied byte! So argument copy got broken for x86 during
GCC 3.4 cycle and it did not get any better with GCC 4.
typedef struct A { int a[1000]; } A;
void g(A);
void f(A *a) { g(*a); }
Assembly output with GCC4 and -O3 optimization:
pushl %ebp
xorl %edx, %edx
movl %esp, %ebp
subl $4008, %esp
movl 8(%ebp), %ecx
.L3:
cmpl $4000, %edx
jb .L2
call g
leave
ret
.p2align 4,,7
.L2:
movzbl (%ecx,%edx), %eax
movb %al, (%esp,%edx)
incl %edx
.p2align 4,,3
jmp .L3
$ LANG=C gcc-3.4 -v
Reading specs from /usr/lib/gcc/i486-linux-gnu/3.4.6/specs
Configured with: ../src/configure -v --enable-languages=c,c++,f77,pascal
--prefix=/usr --libexecdir=/usr/lib --with-gxx-include-dir=/usr/include/c++/3.4
--enable-shared --with-system-zlib --enable-nls --without-included-gettext
--program-suffix=-3.4 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --with-tune=i686 i486-linux-gnu
Thread model: posix
gcc version 3.4.6 (Debian 3.4.6-1)
$ LANG=C gcc-4.1 -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,fortran,objc,obj-c++,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.1-1.4.2.0/jre --enable-mpfr
--with-tune=i686 --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.0 (Debian 4.1.0-1)
--
Summary: Structures are copied byte by byte into function
arguments
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: guillaume dot melquiond at ens-lyon dot fr
GCC target triplet: i486-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27055
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/27055] Structures are copied byte by byte into function arguments
2006-04-06 11:46 [Bug c/27055] New: Structures are copied byte by byte into function arguments guillaume dot melquiond at ens-lyon dot fr
@ 2006-04-06 12:03 ` gdr at integrable-solutions dot net
2006-04-06 12:49 ` pluto at agmk dot net
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: gdr at integrable-solutions dot net @ 2006-04-06 12:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from gdr at integrable-solutions dot net 2006-04-06 12:03 -------
Subject: Re: New: Structures are copied byte by byte into function arguments
"guillaume dot melquiond at ens-lyon dot fr" <gcc-bugzilla@gcc.gnu.org> writes:
[...]
| With 3.4.6, the copy is done byte-by-byte without string
| opcodes. With 4.0.3 and 4.1.0, it is done byte-by-byte and
| out-of-line: there are two jumps for each copied byte! So argument
| copy got broken for x86 during GCC 3.4 cycle and it did not get any
| better with GCC 4.
That is insane, if I may.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27055
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/27055] Structures are copied byte by byte into function arguments
2006-04-06 11:46 [Bug c/27055] New: Structures are copied byte by byte into function arguments guillaume dot melquiond at ens-lyon dot fr
2006-04-06 12:03 ` [Bug c/27055] " gdr at integrable-solutions dot net
@ 2006-04-06 12:49 ` pluto at agmk dot net
2006-04-06 13:05 ` guillaume dot melquiond at ens-lyon dot fr
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pluto at agmk dot net @ 2006-04-06 12:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pluto at agmk dot net 2006-04-06 12:49 -------
for -march=i{345}86 I get:
f:
pushl %ebp
movl %esp, %ebp
subl $4008, %esp
movl %esp, %eax
pushl %edx
pushl $4000
pushl 8(%ebp)
pushl %eax
call memcpy
addl $16, %esp
call g
addl $4000, %esp
leave
ret
for -march=i686,pentium2,... I get:
f:
pushl %ebp
xorl %edx, %edx
movl %esp, %ebp
subl $4008, %esp
movl 8(%ebp), %ecx
.L3:
cmpl $4000, %edx
jb .L2
call g
leave
ret
.p2align 4,,7
.L2:
movzbl (%ecx,%edx), %eax
movb %al, (%esp,%edx)
incl %edx
.p2align 4,,3
jmp .L3
$ gcc version 4.1.1 20060405 (prerelease) (PLD-Linux)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27055
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/27055] Structures are copied byte by byte into function arguments
2006-04-06 11:46 [Bug c/27055] New: Structures are copied byte by byte into function arguments guillaume dot melquiond at ens-lyon dot fr
2006-04-06 12:03 ` [Bug c/27055] " gdr at integrable-solutions dot net
2006-04-06 12:49 ` pluto at agmk dot net
@ 2006-04-06 13:05 ` guillaume dot melquiond at ens-lyon dot fr
2006-04-13 1:52 ` [Bug target/27055] " pinskia at gcc dot gnu dot org
2006-04-16 18:16 ` guillaume dot melquiond at ens-lyon dot fr
4 siblings, 0 replies; 6+ messages in thread
From: guillaume dot melquiond at ens-lyon dot fr @ 2006-04-06 13:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from guillaume dot melquiond at ens-lyon dot fr 2006-04-06 13:05 -------
> for -march=i{345}86 I get
> for -march=i686,pentium2,... I get
Thanks to your tests, I noticed that the change of behavior between GCC 3.4
versions was actually caused by the addition of --with-tune=686 in Debian
packages. In fact, even older versions of GCC 3.4 are doing byte-by-byte copies
once you change the -march target to at least i686. GCC 3.3 is fine though.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27055
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/27055] Structures are copied byte by byte into function arguments
2006-04-06 11:46 [Bug c/27055] New: Structures are copied byte by byte into function arguments guillaume dot melquiond at ens-lyon dot fr
` (2 preceding siblings ...)
2006-04-06 13:05 ` guillaume dot melquiond at ens-lyon dot fr
@ 2006-04-13 1:52 ` pinskia at gcc dot gnu dot org
2006-04-16 18:16 ` guillaume dot melquiond at ens-lyon dot fr
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-13 1:52 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from pinskia at gcc dot gnu dot org 2006-04-13 01:52 -------
This works on most targets I tried, ppc-linux-gnu and x86_64-linux-gnu both
work, only i?86-linux-gnu (32bit) did not.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Component|middle-end |target
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2006-04-13 01:52:19
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27055
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/27055] Structures are copied byte by byte into function arguments
2006-04-06 11:46 [Bug c/27055] New: Structures are copied byte by byte into function arguments guillaume dot melquiond at ens-lyon dot fr
` (3 preceding siblings ...)
2006-04-13 1:52 ` [Bug target/27055] " pinskia at gcc dot gnu dot org
@ 2006-04-16 18:16 ` guillaume dot melquiond at ens-lyon dot fr
4 siblings, 0 replies; 6+ messages in thread
From: guillaume dot melquiond at ens-lyon dot fr @ 2006-04-16 18:16 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from guillaume dot melquiond at ens-lyon dot fr 2006-04-16 18:15 -------
I have tried to look at why it fails. Here are my observations. The function
gcc/expr.c:emit_block_move tries to expand a movmem pattern. The backend
refuses, since a call to memcpy would be a lot more efficient. So
emit_block_move tries to generate memcpy but
block_move_libcall_safe_for_call_parm says this is not safe. The only thing
left is calling emit_block_move_via_loop, and it generates some really dumb
code.
Whenever there is -Os or -mtune=i386 or -mregparm=3, the function
block_move_libcall_safe_for_call_parm says memcpy is safe. Otherwise it fails
because arguments are neither pushed nor passed through registers but stored at
the top of the stack. Failing then seems to be the right thing to do, since the
call to memcpy will otherwise overwrite its own argument stack.
Assuming memcpy is the right thing to do, emit_block_move should allocate a bit
of stack space for memcpy instead of refusing to call it (and hence falling
back to a loop move).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27055
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-04-16 18:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-06 11:46 [Bug c/27055] New: Structures are copied byte by byte into function arguments guillaume dot melquiond at ens-lyon dot fr
2006-04-06 12:03 ` [Bug c/27055] " gdr at integrable-solutions dot net
2006-04-06 12:49 ` pluto at agmk dot net
2006-04-06 13:05 ` guillaume dot melquiond at ens-lyon dot fr
2006-04-13 1:52 ` [Bug target/27055] " pinskia at gcc dot gnu dot org
2006-04-16 18:16 ` guillaume dot melquiond at ens-lyon dot fr
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).