This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Fix another testsuite failure on i586-pc-linux-gnu


Hello,

The following test fails on i586-pc-linux-gnu:
FAIL: gcc.c-torture/execute/loop-3c.c execution,  -Os

The failure is caused by a mis-optimization of the loop:

  int i;
  i = m;

  do
    {
      a[sh >>= 1] = ((unsigned)i << 3)  + (char*)a;
      i += 4;
    }
  while (i < INT_MAX/2 + 1 + 4 * 4);


The loop optimizer replaces the biv i by the giv i*8 (i<<3).
Therefore the loop comparison becomes:

  while (j < (INT_MAX/2 + 1 + 4 * 4) * 8)

which of course badly overflows when folding. Then for some well-chosen
values of m (e.g INT_MAX/2 + INT_MAX/4 + 2), the loop is executed several
times while it shouldn't.

The proposed fix is to explicitly check for the overflow in that case.
Bootstrapped/regtested (C/C++) on i586-pc-linux-gnu (gcc-3_1-branch),
the aforementioned failure being fixed.


2002-05-16  Eric Botcazou  <ebotcazou@multimania.com>

 * expmed.c (const_mult_add_overflow_p): New.
 * loop.c (maybe_eliminate_biv_1) [COMPARE]: Use it.
 Don't eliminate the biv if the giv has a constant
 multiplier and the rhs argument of the comparison
 does satisfy the predicate. Use expand_mult_add
 to compute the replacement constant.


--
Eric Botcazou
ebotcazou@multimania.com

Attachment: loop-opt.diff
Description: Binary data


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