public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/49095] Horrible code generation for trivial decrement with test
Date: Sat, 21 May 2011 10:12:00 -0000	[thread overview]
Message-ID: <bug-49095-4-dJP519Hcn4@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-49095-4@http.gcc.gnu.org/bugzilla/>

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-*-*, i?86-*-*
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |missed-optimization
   Last reconfirmed|                            |2011.05.21 09:52:49
          Component|other                       |rtl-optimization
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-05-21 09:52:49 UTC ---
Confirmed (not using decq is because it is slower for some archs).  On the
tree level we cannot do better than

  D.2722_2 = *argv_1(D);
  D.2723_3 = D.2722_2 + -1;
  *argv_1(D) = D.2723_3;
  if (D.2723_3 == 0B)

because we lack anything like direct operations on memory (and that's good).
On the RTL side combine tries to do

Trying 7, 8 -> 9:
Failed to match this instruction:
(parallel [
        (set (mem/f:DI (reg/v/f:DI 63 [ argv ]) [2 *argv_1(D)+0 S8 A64])
            (plus:DI (mem/f:DI (reg/v/f:DI 63 [ argv ]) [2 *argv_1(D)+0 S8
A64])
                (const_int -1 [0xffffffffffffffff])))
        (set (reg/f:DI 60 [ D.2723 ])
            (plus:DI (mem/f:DI (reg/v/f:DI 63 [ argv ]) [2 *argv_1(D)+0 S8
A64])
                (const_int -1 [0xffffffffffffffff])))
    ])

because we have a use of the decrement result in the comparison.  It doesn't
try to combine this with the comparison though.

So this case is really special ;)  Without the use of the decremented
value we get the desired subq $1, (%rsi).

Manually sinking the store to *argv into the if and the else yields

        movq    (%rsi), %rbx
        subq    $1, %rbx
        je      L4
L2:
        movq    %rbx, (%rsi)
...

L4:
LCFI4:
        movq    $0, (%rsi)
        movq    %rsi, %rdi
        movq    %rsi, 8(%rsp)
        call    _fncall

so at least we then can combine the decrement with the test ...

As usual combine doesn't like stores.


  reply	other threads:[~2011-05-21 10:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-21  3:46 [Bug other/49095] New: " torvalds@linux-foundation.org
2011-05-21 10:12 ` rguenth at gcc dot gnu.org [this message]
2011-05-21 19:22 ` [Bug rtl-optimization/49095] " torvalds@linux-foundation.org
2011-05-21 21:33 ` torvalds@linux-foundation.org
2011-05-27 10:50 ` jakub at gcc dot gnu.org
2011-05-27 12:30 ` jakub at gcc dot gnu.org
2011-05-27 14:22 ` torvalds@linux-foundation.org
2011-05-27 14:55 ` jakub at gcc dot gnu.org
2011-05-27 16:02 ` torvalds@linux-foundation.org
2011-05-27 16:36 ` jakub at gcc dot gnu.org
2011-05-27 16:52 ` torvalds@linux-foundation.org
2011-05-29 18:53 ` jakub at gcc dot gnu.org
2011-05-29 18:57 ` jakub at gcc dot gnu.org
2011-05-29 19:09 ` torvalds@linux-foundation.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-49095-4-dJP519Hcn4@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).