https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99966
Andrew Macleod <amacleod at redhat dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amacleod at redhat dot com --- Comment #2 from Andrew Macleod <amacleod at redhat dot com> --- looking at VRP2: the initial assert provides: Relational : (start_4(D) < end_5(D)) Relational : (_16 > start_4(D)) Relational : (end_5(D) <= _16) unfortunately, the loop back edge is: i_12 = i_17 + 1; if (end_5(D) != i_12) goto <bb 5>; [89.00%] else goto <bb 8>; [11.00%] so it only registers what it knows from the branch: Relational : (i_12 != end_5(D)) so when it gets to the bounds check at: if (i_12 >= _16) goto <bb 6>; [0.04%] else goto <bb 10>; [99.96%] It doesn't really know the answer. If the loop branch had remained if (i_12 < end_5) instead of being changed, then we would instead get the relation: Relational : (i_12 < end_5(D)) which combined with the earlier Relational : (end_5(D) <= _16), should register the transitive relation (i_12 < _16), and enable removal of the check. This is transformed in ivopts, which runs after vrp1. A quick check shows at VRP1 time, the bounds are still using the < format... In fact... running with --param=vrp1-mode=ranger registers this exact transitive relation, and produces: Relational : (i_2 < _16) Relational : (i_2 < end_5(D)) <bb 6> [local count: 952547451]: if (0 != 0) goto <bb 7>; [0.04%] else goto <bb 8>; [99.96%] and eliminates the bounds check. So we can close this PR when we turn ranger on by default for VRP1.