Most floating point tests fail when GDB is built with GCC trunk for mips-linux.
 I assume it shows up on all targets.  The miscompiled function is
doublest.c:put_field.  Here is a reduced test case:

int put_field (unsigned int start, unsigned int len)
{
  int cur_bitshift = ((start + len) % 8) - 8;

  if (cur_bitshift > -8)
    not_removed ();
}

When compiled with -O2, the resulting assembly file does not include a call to
not_removed.  But in fact it should be called in seven out of eight cases. 
((start + len) % 8) is an unsigned int in [0, 7].  "((start + len) % 8) - 8" is
an unsigned int in [UINT_MAX - 8, UINT_MAX].  cur_bitshift is an int, which can
not represent UINT_MAX; this is an implementation defined conversion, and the
GCC manual says that the value is reduced modulo (UINT_MAX+1) until it fits in
the range of int.  So the defined result of the conversion is in [-8, -1].

But VRP says:

Value ranges after VRP:

start_1(D): VARYING
len_2(D): VARYING
D.1559_3: [0, +INF]  EQUIVALENCES: { } (0 elements)
D.1560_4: [0, 7]  EQUIVALENCES: { } (0 elements)
D.1561_5: [4294967288, +INF]  EQUIVALENCES: { } (0 elements)
cur_bitshift_6: [-INF(OVF), -2147483648]  EQUIVALENCES: { } (0 elements)


Folding predicate cur_bitshift_6 >= -7 to 0
Removing basic block 3
Merging blocks 2 and 4
put_field (start, len)
{
  int cur_bitshift;
  unsigned int D.1561;
  unsigned int D.1560;
  unsigned int D.1559;

<bb 2>:
  D.1559_3 = start_1(D) + len_2(D);
  D.1560_4 = D.1559_3 & 7;
  D.1561_5 = D.1560_4 + 4294967288;
  cur_bitshift_6 = (int) D.1561_5;
  return;

}


-- 
           Summary: VRP eliminates a useful test due to overflow
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: drow at gcc dot gnu dot org
GCC target triplet: mips-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31605

Reply via email to