public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/47004] New: missed optimization in comparison
@ 2010-12-18 16:11 bosch at gcc dot gnu.org
  2010-12-18 19:22 ` [Bug tree-optimization/47004] " bosch at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: bosch at gcc dot gnu.org @ 2010-12-18 16:11 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-30 23:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-18 16:11 [Bug tree-optimization/47004] New: missed optimization in comparison bosch at gcc dot gnu.org
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

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