public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bosch at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/47004] New: missed optimization in comparison
Date: Sat, 18 Dec 2010 16:11:00 -0000	[thread overview]
Message-ID: <bug-47004-4@http.gcc.gnu.org/bugzilla/> (raw)

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

           Summary: missed optimization in comparison
           Product: gcc
           Version: 4.5.4
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bosch@gcc.gnu.org


Created attachment 22811
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22811
Preprocessed source to reproduce

The attached C test case shows missed optimization, where lenzero could be
optimized to generate the same code as lenzero2. This pattern is very common in
Ada, where the 'Length attribute for arrays expands to the same code as that
for len. As this is all simple integer code without any aliasing issues, I have
some hope that GCC can do better here.

Regards,
  -Geert 

cat lenzero.c && gcc -O3 -fomit-frame-pointer -save-temps -c lenzero.c && otool
-tv lenzero.o
int len(int f, int l) {
 return l < f ? 0 : l - f + 1;
}

int lenzero(int f, int l) {
 return len(f, l) == 0;
}

int lenzero2(int f, int l) {
 return l < f;
}

lenzero.o:
(__TEXT,__text) section
_len:
0000000000000000    xorl    %eax,%eax
0000000000000002    cmpl    %edi,%esi
0000000000000004    jl    0x0000000b
0000000000000006    subl    %edi,%esi
0000000000000008    leal    0x01(%rsi),%eax
000000000000000b    repz/ret
000000000000000d    nop
000000000000000e    nop
_lenzero:
0000000000000010    cmpl    %esi,%edi
0000000000000012    movl    $0x00000001,%eax
0000000000000017    jg    0x00000023
0000000000000019    subl    %edi,%esi
000000000000001b    xorl    %eax,%eax
000000000000001d    cmpl    $0xff,%esi
0000000000000020    sete    %al
0000000000000023    repz/ret
0000000000000025    nop
0000000000000026    nopw    %cs:0x00000000(%rax,%rax)
_lenzero2:
0000000000000030    xorl    %eax,%eax
0000000000000032    cmpl    %edi,%esi
0000000000000034    setl    %al
0000000000000037    ret


             reply	other threads:[~2010-12-18 16:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-18 16:11 bosch at gcc dot gnu.org [this message]
2010-12-18 19:22 ` [Bug tree-optimization/47004] " bosch at gcc dot gnu.org
2010-12-19  8:55 ` [Bug tree-optimization/47004] missed optimization in length comparison ebotcazou at gcc dot gnu.org
2021-08-30  1:07 ` pinskia at gcc dot gnu.org
2021-08-30 23:57 ` pinskia 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=bug-47004-4@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).