public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Glen Nakamura <glen@imodulo.com>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: optimization/8613: [3.2/3.3/3.4 regression] -O2 optimization generates wrong code
Date: Wed, 19 Feb 2003 09:16:00 -0000	[thread overview]
Message-ID: <20030219091601.6838.qmail@sources.redhat.com> (raw)

The following reply was made to PR optimization/8613; it has been noted by GNATS.

From: Glen Nakamura <glen@imodulo.com>
To: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
	mark.odonohue@cytopia.com.au
Cc:  
Subject: Re: optimization/8613: [3.2/3.3/3.4 regression] -O2 optimization generates wrong code
Date: Tue, 18 Feb 2003 23:10:09 -1000

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8613
 
 I've tracked this bug down to a problem with postincrements and the strlen
 builtin function.  What happens is that the postincrement code isn't emitted
 before the builtin strlen function is expanded and gets emitted within the
 loop created by ix86_expand_strlensi_unroll_1.  This causes the postincrement
 code to be executed multiple times when calculating the string length.
 The fix is to call emit_queue before expanding the strlen builtin so the
 postincrement code is emitted outside of the loop.
 
 I'm not exactly sure where the emit_queue call should be placed.  Although
 adding emit_queue to expand_builtin_strlen would work, I added it to
 expand_builtin instead, because other builtins may have the same problem.
 It passed regression testing on i686-pc-linux-gnu for the 3.3 branch,
 but a more experienced developer should decide where the best place is.
 
 Here is a reduced testcase:
 
 extern void abort (void);
 
 int
 main ()
 {
   char buf[16] = "1234567890";
   char *p = buf;
   *p++ = (char) __builtin_strlen (buf);
   if ((buf[0] != 10) || (p - buf != 1))
     abort ();
 }
 
 And here is the patch:
 
 2003-02-19  Glen Nakamura  <glen@imodulo.com>
 
 	* builtins.c (expand_builtin): Emit postincrements before expanding
 	builtin functions.
 
 diff -Nru3p gcc-3.3.orig/gcc/builtins.c gcc-3.3/gcc/builtins.c
 --- gcc-3.3.orig/gcc/builtins.c	2002-12-01 17:51:43.000000000 +0000
 +++ gcc-3.3/gcc/builtins.c	2002-12-01 17:51:43.000000000 +0000
 @@ -3691,6 +3691,9 @@ expand_builtin (exp, target, subtarget, 
    tree arglist = TREE_OPERAND (exp, 1);
    enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
  
 +  /* Perform postincrements before expanding builtin functions.  */
 +  emit_queue ();
 +
    if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
      return (*targetm.expand_builtin) (exp, target, subtarget, mode, ignore);
  


             reply	other threads:[~2003-02-19  9:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-19  9:16 Glen Nakamura [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-02-21  8:34 ebotcazou
2003-02-20 20:06 Eric Botcazou
2003-02-20 19:46 Glen Nakamura
2003-02-18 14:35 ebotcazou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030219091601.6838.qmail@sources.redhat.com \
    --to=glen@imodulo.com \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).