This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

optimization/3640: small lost optimization of "x==0 || x==1"



>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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]