public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ubizjak at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/31248] char adding (in loops) gives an extra move or two
Date: Tue, 28 Aug 2007 12:02:00 -0000	[thread overview]
Message-ID: <20070828120213.11249.qmail@sourceware.org> (raw)
In-Reply-To: <bug-31248-1649@http.gcc.gnu.org/bugzilla/>



------- Comment #3 from ubizjak at gmail dot com  2007-08-28 12:02 -------
Current mainline [GCC: (GNU) 4.3.0 20070828] generates:

test:
.LFB2:
        xorl    %eax, %eax
        xorl    %edx, %edx
        .align 16
.L2:
        addb    table(%rdx), %al
        addq    $1, %rdx
        cmpq    $10, %rdx
        jne     .L2
        movsbl  %al,%eax
        ret

Now, there is an optimization problem in the intialization code in loop header.
To omit one iteration, it should start with:

.LFB2:
        movzbl  table(%rip), %ecx
        movl    $1, %edx
.L2:
        ...

BTW: By reversing the loop:

  for (i = 9; i; i--)
    val += table[i];

we could remove comparison from the loop, but instead we produce (x86_64):

test:
.LFB2:
        xorl    %eax, %eax
        xorl    %edx, %edx
        .align 16
.L2:
        addb    table+9(%rdx), %al
        subq    $1, %rdx
        cmpq    $-9, %rdx
        jne     .L2
        movsbl  %al,%eax
        ret

However, using -m32 we get:

test:
        xorl    %eax, %eax
        movl    $9, %edx
        .align 16
.L2:
        addb    table(%edx), %al
        subl    $1, %edx
        jne     .L2
        movsbl  %al,%eax
        ret

In reversed-loop case, we could generate:

test:
        movl    $9, %edx
        movzbl  table(%edx), %eax
        .align 16
.L2:
        addb    table(%edx), %al
        subl    $1, %edx
        jne     .L2
        movsbl  %al,%eax
        ret


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|char adding gives an extra  |char adding (in loops) gives
                   |move or two                 |an extra move or two


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


  parent reply	other threads:[~2007-08-28 12:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-17 19:09 [Bug tree-optimization/31248] New: Too much casting for char operands on tree level ubizjak at gmail dot com
2007-03-18  5:30 ` [Bug tree-optimization/31248] " pinskia at gcc dot gnu dot org
2007-03-29  6:16 ` [Bug rtl-optimization/31248] char adding gives an extra move or two pinskia at gcc dot gnu dot org
2007-08-28 12:02 ` ubizjak at gmail dot com [this message]
2008-01-09  9:29 ` [Bug rtl-optimization/31248] char adding (in loops) " ubizjak at gmail dot com
2008-01-09  9:46 ` ubizjak at gmail dot com

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