public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39403]  New: Excessive optimization issue
@ 2009-03-09  4:06 casmyu at gmail dot com
  2009-03-09 15:36 ` [Bug c/39403] " rguenth at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: casmyu at gmail dot com @ 2009-03-09  4:06 UTC (permalink / raw)
  To: gcc-bugs

My OS and compiler information as follows:
[root][~]# uname -a
Linux debian 2.6.26-1-686 #1 SMP Sat Jan 10 18:29:31 UTC 2009 i686 GNU/Linux
[root][~]# gcc --version
gcc (Debian 4.3.2-1.1) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.

A test C code with inline assembly language as follows:
  1 #include <stdio.h>
  2
  3 int main()
  4 {
  5     char src[30] = {"This is a test message.\n"};
  6     char dst[30];
  7     int len = 25;
  8
  9     __asm__ __volatile__(
 10         "cld\n\t"
 11         "rep movsb"
 12         :
 13         : "S"(src), "D"(dst), "c"(len)
 14         );
 15     printf("%s\t%d\n", dst, len);
 16     return 0;
 17 }

compile the code like this:
[root][~]# gcc -O2 -o bugtest bugtest.c

then run the program, this issue will be re-produced.

I disassembled the binary and found that, when add O2 switch, before the
printf() function invoked, the edi register will be push into the stack instead
of the address of output. So actually, the output of printf is part of the
dst's tail and all the src, not the dst string.
But if did not set O2 switch, this issue will be disappeared.
So I think this is an excessive optimization issue of gcc.
Thank you!


-- 
           Summary: Excessive optimization issue
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: casmyu at gmail dot com
 GCC build triplet: gcc (Debian 4.3.2-1.1) 4.3.2
  GCC host triplet: Debian 5.0
GCC target triplet: Debian 5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39403


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

* [Bug c/39403] Excessive optimization issue
  2009-03-09  4:06 [Bug c/39403] New: Excessive optimization issue casmyu at gmail dot com
@ 2009-03-09 15:36 ` rguenth at gcc dot gnu dot org
  2009-03-09 15:57   ` Andrew Thomas Pinski
  2009-03-09 15:57 ` pinskia at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-09 15:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2009-03-09 15:36 -------
You need to specify that the registers are clobbered by the asm.  The only
way to do that is to use output constraints ("+D", "+c", etc.) on proper
temporaries.

  int lent = len;
  char *dstt = dst;
  char *srct = src;
  __asm__ __volatile__(
                       "cld\n\t"
                       "rep movsb"
                       : "+c" (lent), "+D"(dstt), "+S"(src)
                      );

Otherwise GCC thinks the registers still hold the original value.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39403


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

* Re: [Bug c/39403] Excessive optimization issue
  2009-03-09 15:36 ` [Bug c/39403] " rguenth at gcc dot gnu dot org
@ 2009-03-09 15:57   ` Andrew Thomas Pinski
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Thomas Pinski @ 2009-03-09 15:57 UTC (permalink / raw)
  To: gcc-bugzilla; +Cc: gcc-bugs



Sent from my iPhone

On Mar 9, 2009, at 8:36 AM, "rguenth at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org 
 > wrote:

>
>
> ------- Comment #1 from rguenth at gcc dot gnu dot org  2009-03-09  
> 15:36 -------
> You need to specify that the registers are clobbered by the asm.   
> The only
> way to do that is to use output constraints ("+D", "+c", etc.) on  
> proper
> temporaries.
>
>  int lent = len;
>  char *dstt = dst;
>  char *srct = src;
>  __asm__ __volatile__(
>                       "cld\n\t"
>                       "rep movsb"
>                       : "+c" (lent), "+D"(dstt), "+S"(src)
>                      );
> Otherwise GCC thinks the registers still hold the original value.

Oh and mark this inline-ask as clobbering memory.

>
>
>
> -- 
>
> rguenth at gcc dot gnu dot org changed:
>
>           What    |Removed                     |Added
> --- 
> --- 
> ----------------------------------------------------------------------
>             Status|UNCONFIRMED                 |RESOLVED
>         Resolution|                            |INVALID
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39403
>


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

* [Bug c/39403] Excessive optimization issue
  2009-03-09  4:06 [Bug c/39403] New: Excessive optimization issue casmyu at gmail dot com
  2009-03-09 15:36 ` [Bug c/39403] " rguenth at gcc dot gnu dot org
@ 2009-03-09 15:57 ` pinskia at gmail dot com
  2009-03-10  1:23 ` casmyu at gmail dot com
  2009-04-16 20:32 ` [Bug target/39403] " pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gmail dot com @ 2009-03-09 15:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gmail dot com  2009-03-09 15:57 -------
Subject: Re:  Excessive optimization issue



Sent from my iPhone

On Mar 9, 2009, at 8:36 AM, "rguenth at gcc dot gnu dot org"
<gcc-bugzilla@gcc.gnu.org 
 > wrote:

>
>
> ------- Comment #1 from rguenth at gcc dot gnu dot org  2009-03-09  
> 15:36 -------
> You need to specify that the registers are clobbered by the asm.   
> The only
> way to do that is to use output constraints ("+D", "+c", etc.) on  
> proper
> temporaries.
>
>  int lent = len;
>  char *dstt = dst;
>  char *srct = src;
>  __asm__ __volatile__(
>                       "cld\n\t"
>                       "rep movsb"
>                       : "+c" (lent), "+D"(dstt), "+S"(src)
>                      );
> Otherwise GCC thinks the registers still hold the original value.

Oh and mark this inline-ask as clobbering memory.

>
>
>
> -- 
>
> rguenth at gcc dot gnu dot org changed:
>
>           What    |Removed                     |Added
> --- 
> --- 
> ----------------------------------------------------------------------
>             Status|UNCONFIRMED                 |RESOLVED
>         Resolution|                            |INVALID
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39403
>


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39403


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

* [Bug c/39403] Excessive optimization issue
  2009-03-09  4:06 [Bug c/39403] New: Excessive optimization issue casmyu at gmail dot com
  2009-03-09 15:36 ` [Bug c/39403] " rguenth at gcc dot gnu dot org
  2009-03-09 15:57 ` pinskia at gmail dot com
@ 2009-03-10  1:23 ` casmyu at gmail dot com
  2009-04-16 20:32 ` [Bug target/39403] " pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: casmyu at gmail dot com @ 2009-03-10  1:23 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2771 bytes --]



------- Comment #3 from casmyu at gmail dot com  2009-03-10 01:23 -------
Hi:
I have changed the code as you said, but it is more error now.

  1 #include <stdio.h>
  2
  3 int main()
  4 {
  5     char src[30] = {"This is a test message.\n"};
  6     char dst[30];
  7     int len = 25;
  8
  9     __asm__ __volatile__(
 10         "cld\n\t"
 11         "rep movsb"
 12         :
 13 //      : "(src), "D"(dst), "c"(len)
 14         : "+c"(len), "+D"(dst), "+S"(src)
 15         );
 16     printf("%s\t%d\n", dst, len);
 17     return 0;
 18 }

[root][~]# gcc -O2 -o bugtest bugtest.c
bugtest.c: In function ¡®main¡¯:
bugtest.c:15: error: input operand constraint contains ¡®+¡¯
bugtest.c:15: error: input operand constraint contains ¡®+¡¯
bugtest.c:15: error: input operand constraint contains ¡®+¡¯
bugtest.c:9: error: input operand constraint contains ¡®+¡¯
bugtest.c:9: error: input operand constraint contains ¡®+¡¯
bugtest.c:9: error: input operand constraint contains ¡®+¡¯

Please help to re-check this issue.
Thank you!

(In reply to comment #2)
> Subject: Re:  Excessive optimization issue
> 
> 
> 
> Sent from my iPhone
> 
> On Mar 9, 2009, at 8:36 AM, "rguenth at gcc dot gnu dot org"
> <gcc-bugzilla@gcc.gnu.org 
>  > wrote:
> 
> >
> >
> > ------- Comment #1 from rguenth at gcc dot gnu dot org  2009-03-09  
> > 15:36 -------
> > You need to specify that the registers are clobbered by the asm.   
> > The only
> > way to do that is to use output constraints ("+D", "+c", etc.) on  
> > proper
> > temporaries.
> >
> >  int lent = len;
> >  char *dstt = dst;
> >  char *srct = src;
> >  __asm__ __volatile__(
> >                       "cld\n\t"
> >                       "rep movsb"
> >                       : "+c" (lent), "+D"(dstt), "+S"(src)
> >                      );
> > Otherwise GCC thinks the registers still hold the original value.
> 
> Oh and mark this inline-ask as clobbering memory.
> 
> >
> >
> >
> > -- 
> >
> > rguenth at gcc dot gnu dot org changed:
> >
> >           What    |Removed                     |Added
> > --- 
> > --- 
> > ----------------------------------------------------------------------
> >             Status|UNCONFIRMED                 |RESOLVED
> >         Resolution|                            |INVALID
> >
> >
> > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39403
> >
> 


-- 

casmyu at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |casmyu at gmail dot com
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39403


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

* [Bug target/39403] Excessive optimization issue
  2009-03-09  4:06 [Bug c/39403] New: Excessive optimization issue casmyu at gmail dot com
                   ` (2 preceding siblings ...)
  2009-03-10  1:23 ` casmyu at gmail dot com
@ 2009-04-16 20:32 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-04-16 20:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2009-04-16 20:32 -------
You want to use the "+" constraint as output constraint.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39403


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

end of thread, other threads:[~2009-04-16 20:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-09  4:06 [Bug c/39403] New: Excessive optimization issue casmyu at gmail dot com
2009-03-09 15:36 ` [Bug c/39403] " rguenth at gcc dot gnu dot org
2009-03-09 15:57   ` Andrew Thomas Pinski
2009-03-09 15:57 ` pinskia at gmail dot com
2009-03-10  1:23 ` casmyu at gmail dot com
2009-04-16 20:32 ` [Bug target/39403] " pinskia at gcc dot gnu dot org

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