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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
We have:
<bb 2>:
ubound.0_3 = 0;
size.1_4 = ubound.0_3 + 1;
size.1_5 = MAX_EXPR <size.1_4, 0>;
_6 = size.1_5 * 4;
_7 = (character(kind=4)) _6;
_8 = MAX_EXPR <_7, 1>;
sizes_9 = __builtin_malloc (_8);
size.3_10 = MAX_EXPR <ubound.0_3, 0>;
_11 = size.3_10 * 4;
_12 = (character(kind=4)) _11;
_13 = MAX_EXPR <_12, 1>;
strides_14 = __builtin_malloc (_13);
MEM[(integer(kind=4)[0:D.1906] *)sizes_9][0] = 1;
if (ubound.0_3 > 0)
  goto <bb 3>;
else
  goto <bb 6>;
<bb 3>:
idx_50 = 1;
<bb 4>:
# idx_15 = PHI <1(3), idx_25(5)>
_16 = idx_15 + -1;
_17 = array_1(D)->dim[_16].stride;
MEM[(integer(kind=4)[0:D.1900] *)strides_14][_16] = _17;
_18 = MEM[(integer(kind=4)[0:D.1906] *)sizes_9][_16];
_19 = array_1(D)->dim[_16].ubound;
_20 = array_1(D)->dim[_16].lbound;
_21 = _19 - _20;
_22 = _21 + 1;
_23 = MAX_EXPR <_22, 0>;
_24 = _18 * _23;
MEM[(integer(kind=4)[0:D.1906] *)sizes_9][idx_15] = _24;
idx_25 = idx_15 + 1;
if (ubound.0_3 == idx_15)
  goto <bb 6>;
else
  goto <bb 5>;
<bb 5>:
goto <bb 4>;

and the warning is on the header(4) latch(5) loop.  The warning is correct,
the loop would execute 0xffffffff times and _16 = idx_15 + -1 would invoke
undefined behavior on the last iteration, but still the warning is undesirable
because it is on a dead loop.  Only during IPA optimizations the original
  _15 = array_14(D)->dtype;
  ubound.0_16 = _15 & 7;
was optimized into:
  _2 = 344;
  ubound.0_3 = _2 & 7;
and only copyprop2 pass optimizes that into:
  ubound.0_3 = 0;
but nothing yet propagated it into the condition and folded the condition,
cunrolli runs simply too early.  I guess scheduling there a forwprop pass in
between copyprop2 and cunrolli would fix this, but don't know how expensive it
is.  Or we could avoid emitting the warning right away, but add there
__builtin_warning or similar into the loop, and only warn later on after some
cleanup passes that can actually figure out what code is dead.

Reply via email to