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/3508: builtin memcmp() could be optimised



>Number:         3508
>Category:       optimization
>Synopsis:       builtin memcmp() could be optimised
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 01 09:26:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     herbert@gondor.apana.org.au
>Release:        3.0 (Debian GNU/Linux) and HEAD 20010701
>Organization:
The Debian project
>Environment:
System: Debian GNU/Linux (testing/unstable)
Architecture: i686
	
host: i386-linux
build: i386-linux
target: i386-linux
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-included-gettext --disable-checking --enable-threads=posix --enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux
>Description:
[ Reported to the Debian BTS as report #85535.
  Please CC 85535-quiet@bugs.debian.org on replies.
  Log of report can be found at http://bugs.debian.org/85535 ]
 	

int main() {
	return !memcmp("abcd", "efgh", 4);
}

produces the assembly (-S -g -O2),

        movl    $.LC1, %edi
        movl    $.LC0, %esi
        movl    $4, %ecx
        cld
        repz
        cmpsb
        seta    %cl
        setb    %dl
        popl    %esi
        xorl    %eax, %eax
        popl    %edi
        cmpb    %dl, %cl
        sete    %al

which is a waste because it could've simply loaded the two objects into
registers and compared them.  The same is true on other architectures as
well.

>How-To-Repeat:
	
>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]