public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "carlo at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/37810] Bad store sinking job
Date: Sun, 12 Oct 2008 15:34:00 -0000	[thread overview]
Message-ID: <20081012153257.18032.qmail@sourceware.org> (raw)
In-Reply-To: <bug-37810-7035@http.gcc.gnu.org/bugzilla/>



------- Comment #4 from carlo at gcc dot gnu dot org  2008-10-12 15:32 -------
Note that the original code was:

  A& operator++(void)
  {
    ++n;
    if (__builtin_expect(n == m, false))
      g();
    return *this;
  }

but g++ fails to optimize that by decrementing m outside
the loop (so I'm decrementing m myself now and use the
former code). The former code has as advantage, namely,
that the result of the addl $1,%eax can be used for the
conditional jump. However, gcc ALSO doesn't do that: in
the above assembly it follows the add with a redundant
testl %eax,%eax.

Anyway, using the operator++ given in this comment,
the assembly code is:

        movl    (%rdi), %eax
        jmp     .L3

.L4:
        addl    $1, %eax
        cmpl    4(%rdi), %eax
        movl    %eax, (%rdi)
        je      .L8
.L3:
        testl   %eax, %eax
        jne     .L4

which is essentially the same, except now the
testl %eax,%eax is indeed "needed" ...


-- 


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


  parent reply	other threads:[~2008-10-12 15:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-12 15:14 [Bug tree-optimization/37810] New: " carlo at gcc dot gnu dot org
2008-10-12 15:21 ` [Bug tree-optimization/37810] " rguenth at gcc dot gnu dot org
2008-10-12 15:27 ` rguenth at gcc dot gnu dot org
2008-10-12 15:30 ` rguenth at gcc dot gnu dot org
2008-10-12 15:34 ` carlo at gcc dot gnu dot org [this message]
2009-04-03 12:34 ` rguenth at gcc dot gnu dot org
     [not found] <bug-37810-4@http.gcc.gnu.org/bugzilla/>
2021-07-26  4:35 ` pinskia at gcc dot gnu.org
2021-07-27  7:03 ` rguenth at gcc dot gnu.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=20081012153257.18032.qmail@sourceware.org \
    --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).