public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: middle-end/5840: inline asm: register output parameter overlaps with indirect output parameter
@ 2002-04-04  3:22 rth
  0 siblings, 0 replies; 2+ messages in thread
From: rth @ 2002-04-04  3:22 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, netch, nobody

Synopsis: inline asm: register output parameter overlaps with indirect output parameter

State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Thu Apr  4 03:22:00 2002
State-Changed-Why:
    This code is incorrect.  If an output is generated
    before all inputs (including output addresses) are
    consumed, one must add an early-clobber marker: "&".
    
    The constraints for m_sbb must be written
    
      : "=&r" ( *pd ), "=&q" ( *pnc ), "=g" ( *pnf )

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5840


^ permalink raw reply	[flat|nested] 2+ messages in thread

* middle-end/5840: inline asm: register output parameter overlaps with indirect output parameter
@ 2002-03-05  9:26 Valentin Nechayev
  0 siblings, 0 replies; 2+ messages in thread
From: Valentin Nechayev @ 2002-03-05  9:26 UTC (permalink / raw)
  To: gcc-gnats


>Number:         5840
>Category:       middle-end
>Synopsis:       inline asm: register output parameter overlaps with indirect output parameter
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 05 09:26:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Valentin Nechayev
>Release:        2.95.3, 2.7.2.3
>Organization:
private
>Environment:

The problem is of inline assembler on i386 architecture.

This was reproduced on variety of 2.95.3 and 2.7.2.x packages of gcc
from a bunch of platforms. Details on this gcc packages are listed below.
2.95.3 today from GCC main ftp also shows it.

I failed to reproduce it on: 3.0.2 from FreeBSD port (ports/lang/gcc30,
PORTVERSION=3.0.2, PORTREVISION=0);
also on: 2.91.66 from RedHat 6.2;
also on: 2.96 20000731 from RedHat 7.1 (package gcc-2.96-85)

>Description:

The problem is shown on the bench-test example.

For input file sbb6.c:

=== begin sbb6.c ===
void m_sbb( int* pnc, int* pd, int* pnf, int a, int b, int c )
{
   asm(
      "mov %5,%%edi\n\t"
      "shr %%edi\n\t"
      "sbb %4,%0\n\t"
      "pushf\n\t"
      "setc %b1\n\t"
      "movzbl %b1,%1\n\t"
      "popl %2"
      : "=r" ( *pd ), "=q" ( *pnc ), "=g" ( *pnf )
      : "0" ( a ), "g" ( b ), "g" ( c ) : "cc","edi" );
}
=== end sbb6.c ===

and for gcc 2.95.3, the command `gcc -fverbose-asm -g -S sbb6.c' produces
assembly file which contains:

=== cut sbb6.s ===
#APP
        mov 28(%ebp),%edi
        shr %edi
        sbb 24(%ebp),%edx
        pushf
        setc %al
        movzbl %al,%eax
        popl (%eax)
#NO_APP
=== end cut ===

One can see that %2 is `(%eax)', %1 is `%eax', and they overlaps.
With optimization level >=1, the effect disappears. Example of correct
code, with the same options as above, but with -O added:

=== cut sbb6.s.o1 ===
#APP
        mov 28(%ebp),%edi
        shr %edi
        sbb 24(%ebp),%eax
        pushf
        setc %dl
        movzbl %dl,%edx
        popl (%ecx)
#NO_APP
=== end cut ===

These results for 2.95.3 are identical for all tested versions of it.

On the other side, with 2.7.2.3 and 2.7.2.1, the effect appears only
with non-zero optimization level with the following result:

=== cut sbb6.s ===
#APP
        mov %eax,%edi
        shr %edi
        sbb %edx,%ecx
        pushf
        setc %bl
        movzbl %bl,%ebx
        popl (%ebx)
#NO_APP
=== end cut ===

(command was: `gcc -fverbose-asm -g -S sbb6.c')

With -O0, no overlapping occurs.

>How-To-Repeat:

See source file and commands shown above.

Details on gcc versions where this occurs:

gcc 2.95.3 from GCC main ftp, compiled on FreeBSD 4.4-RELEASE
with commands:

./configure --prefix=/usr/local/gcc/2.95.3
gmake
gmake install

and called as: /usr/local/gcc/2.95.3/bin/gcc -fverbose-asm -g -S sbb6.c

for FreeBSD4 versions:

$ gcc -v
Using builtin specs.
gcc version 2.95.3 20010315 (release) [FreeBSD]

this is canonical gcc from FreeBSD installation.

For 2.95.3 from mandrake:

$ gcc -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.3/specs
gcc version 2.95.3 19991030 (prerelease)

$ rpm -qf /usr/bin/gcc-2.95.2
gcc-2.95.2-12mdk

(Sorry, but no more details for this - I'm not root on this host.)

The same `2.95.3 19991030 (prerelease)' from OpenBSD 2.8-current
shows the same result.

For 2.95.3 from OpenBSD 2.9:

$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-unknown-openbsd2.9/2.95.3/specs
gcc version 2.95.3 20010125 (prerelease)
$ uname -mrs
OpenBSD 2.9 i386

For 2.7.2.3 from FreeBSD 3.3:

$ gcc -v
gcc version 2.7.2.3

Also this is version from standard FreeBSD installation.

Also on 2.7.2.1 from unidentified Slackware, with the same results
as with 2.7.2.3.


>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-04-04 11:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-04  3:22 middle-end/5840: inline asm: register output parameter overlaps with indirect output parameter rth
  -- strict thread matches above, loose matches on Subject: below --
2002-03-05  9:26 Valentin Nechayev

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).