public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: optimization/3640: small lost optimization of "x==0 || x==1"
@ 2002-03-29 23:59 neil
  0 siblings, 0 replies; 2+ messages in thread
From: neil @ 2002-03-29 23:59 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, user42

Synopsis: small lost optimization of "x==0 || x==1"

State-Changed-From-To: open->closed
State-Changed-By: neil
State-Changed-When: Fri Mar 29 23:59:42 2002
State-Changed-Why:
    Reported fixed by Roger Sayle.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=3640


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

* optimization/3640: small lost optimization of "x==0 || x==1"
@ 2001-07-10 16:46 Kevin Ryde
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Ryde @ 2001-07-10 16:46 UTC (permalink / raw)
  To: gcc-gnats

>Number:         3640
>Category:       optimization
>Synopsis:       small lost optimization of "x==0 || x==1"
>Confidential:   yes
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          pessimizes-code
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 10 16:46:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        3.0 (Debian) (Debian testing/unstable)
>Organization:
>Environment:
System: Linux blah 2.2.15 #1 Tue Apr 25 17:13:48 EST 2000 i586 unknown
Architecture: i586
	<machine, os, target, libraries (multiple lines)>
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,objc --prefix=/usr --infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as --with-gnu-ld --with-system-zlib --enable-long-long --enable-nls --without-x --without-included-gettext --disable-checking --enable-threads=posix --enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux
>Description:
I noticed a small case where the optimization of "x==0 || x==1" to
"(unsigned) x <= 1" seems to be lost.

>How-To-Repeat:
A file foo.c,

        int
        foo (int x, unsigned long y)
        {
          if (x == 0 || (x == 1 && y <= 0xFFFFFFFFU)
            do_something ();
        }

compiled with

        gcc-3.0 -O9 -S foo.c

comes out with the test as

        testl   %eax, %eax
        je      .L3
        decl    %eax
        je      .L3

rather than say

        cmp     $1, %eax
        jbe     .L3

That latter comes out for a plain "x==0 || x==1" test, but it seems
adding "y <= 0xFFFFFFFF" prevents that optimization, despite that
extra condition being always true (for i386).

This perhaps isn't of any great significance, but it arose in GMP when
having y as either "unsigned long" or "unsigned long long" and leaving
it to gcc to decide what CPUs do or don't need to actually do anything
for a test like "y <= UINT_MAX".

For what it's worth the same seems to occur in a debian packaged
pre-release gcc 2.95.4 too.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2002-03-30  7:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-29 23:59 optimization/3640: small lost optimization of "x==0 || x==1" neil
  -- strict thread matches above, loose matches on Subject: below --
2001-07-10 16:46 Kevin Ryde

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