public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "lmakhlis at bmc dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/28940]  New: Overzealous CSE with static array access
Date: Sat, 02 Sep 2006 21:14:00 -0000	[thread overview]
Message-ID: <bug-28940-10833@http.gcc.gnu.org/bugzilla/> (raw)

char a[10], b[10];

int f1(int i)
{
        return a[i+1] + b[i+1];
}

With -O1 and higher, gcc performs CSE on i+1:

        addl    $1, %edi
        movslq  %edi,%rdi
        movsbl  a(%rdi),%eax
        movsbl  b(%rdi),%edx
        addl    %edx, %eax
        ret

This doesn't happen with the equivalent
        return (&a[0])[i+1] + (&b[0])[i+1];
or
        return *(a + i + 1) + *(b + i + 1);
which both compile to
        movslq  %edi,%rdi
        movsbl  a+1(%rdi),%eax
        movsbl  b+1(%rdi),%edx
        addl    %edx, %eax
        ret


-- 
           Summary: Overzealous CSE with static array access
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: lmakhlis at bmc dot com
 GCC build triplet: x86_64-redhat-linux
  GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux


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


             reply	other threads:[~2006-09-02 21:14 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-02 21:14 lmakhlis at bmc dot com [this message]
2006-09-02 21:29 ` [Bug rtl-optimization/28940] [4.1/4.2 Regression] address selection does not work correctly pinskia at gcc dot gnu dot org
2006-09-07  1:16 ` mmitchel at gcc dot gnu dot org
2006-09-07  8:11 ` bonzini at gnu dot org
2006-09-07  8:15 ` bonzini at gnu dot org
2006-09-09  5:48 ` [Bug rtl-optimization/28940] [4.0/4.1/4.2 " pinskia at gcc dot gnu dot org
2006-09-09 13:02 ` bonzini at gnu dot org
2006-09-09 13:03 ` bonzini at gnu dot org
2006-10-11 12:23 ` [Bug c/28940] " rguenth at gcc dot gnu dot org
2006-10-11 12:30 ` rguenth at gcc dot gnu dot org
2006-10-11 12:47 ` bonzini at gnu dot org
2006-10-11 12:53 ` rguenth at gcc dot gnu dot org
2006-10-11 13:05 ` paolo dot bonzini at lu dot unisi dot ch
2007-01-15 20:21 ` [Bug rtl-optimization/28940] " pinskia at gcc dot gnu dot org
2007-02-14  9:19 ` mmitchel at gcc dot gnu dot org
2007-07-05 10:37 ` bonzini at gnu dot org
2007-07-05 10:43 ` ebotcazou at gcc dot gnu dot org
2007-07-05 10:46 ` paolo dot bonzini at lu dot unisi dot ch
2007-11-03  7:53 ` ebotcazou at gcc dot gnu dot org
2007-11-03  7:54 ` ebotcazou at gcc dot gnu dot org

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=bug-28940-10833@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).