Buggy peephole prevents bootstrap (i386)

Zack Weinberg zackw@stanford.edu
Fri Oct 13 18:52:00 GMT 2000


This function is based on emit-rtl.c:gen_rtx_CONST_INT.

int foo (int x)
{
  return (x >= -64 && x <= 64);
}

Compiled with current cvs at -O2 -fno-peephole2 -fomit-frame-pointer,
we get:

foo:
        movl    4(%esp), %edx
        movl    $0, %eax
        addl    $64, %edx
        cmpl    $128, %edx
        setbe   %al
        ret


Without -fno-peephole2, we get instead:

foo:
        movl    4(%esp), %edx
        xorl    %eax, %eax
        addl    $64, %edx
*       addl    $-128, %edx
        setbe   %al
        ret

This transformation was done to save space - the add instruction is
three bytes shorter than the corresponding compare.  However, add
doesn't set the condition codes the same way cmp and sub do.  It
appears (from staring at the confusing Intel reference manual) that
add's condition codes are usable only with the signed conditional
instructions - setle in this case instead of setbe.  But we can't use
setle for the clamp operation being done here - it will get the case 
x < -64 wrong.

The bad peepholes were introduced by this patch:

Thu Oct 12 16:02:31 MET DST 2000 Jan Hubicka  <jh@suse.cz>

        * i386.md (adddi3, subdi3 splitters): Update for new pattern.
        (addsi3_cc, addqi3_cc, subsi3_cc): Remove
        (addsi3_carry): Canonicalize.
        (addqi_5): Remove '*'.
        (sbb pattern): Canonicalize.

        * i386.md (cmp to inc/add peep2): New.

At the moment, I believe this transformation is always wrong.  I could
be mistaken.

zw


More information about the Gcc-bugs mailing list