https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124
--- Comment #28 from Manuel López-Ibáñez <manu at gcc dot gnu.org> --- (In reply to baoshan from comment #27) > > It seems GCC at some moment unrolls the loop and creates such block with > > those ranges. Probably, the block is unreachable, but it would be better to > > not create it in the first place. Finding out where and why it is created > > would help to figure out a fix. > > > At pass "cunrolli", it would unroll the loops according the estimated > iterate times. The problem is at this time it use array > ref(infer_loop_bounds_from_ref) to infer the iterate times which is not > accurate. The inaccurate iterate times result the extra blocks. The question is why is it inaccurate? Note that cunrolli says: Statement _14 = baz[_9]; is executed at most 5 (bounded by 5) + 1 times in loop 2. Loop 2 iterates at most 6 times. Analyzing # of iterations of loop 2 exit condition [i_2 + 4294967295, + , 4294967295] != 0 bounds on difference of bases: -4294967295 ... 0 Applying pattern match.pd:71, generic-match.c:9500 result: # of iterations i_2 + 4294967295, bounded by 4294967295 Estimating sizes for loop 2 BB: 7, after_exit: 0 size: 2 if (j_3 != 0) Exit condition will be eliminated in last copy. BB: 6, after_exit: 1 size: 1 _9 = j_3 + 4294967295; size: 0 _10 = (long unsigned int) _9; Applying pattern match.pd:71, generic-match.c:9500 Applying pattern match.pd:136, generic-match.c:6019 size: 1 _11 = _10 * 4; Applying pattern match.pd:71, generic-match.c:9500 Applying pattern match.pd:136, generic-match.c:6019 size: 1 _13 = bar_12(D) + _11; size: 1 _14 = baz[_9]; size: 1 *_13 = _14; size: 7-0, last_iteration: 2-2 Loop size: 7 Estimated size after unrolling: 28 pr59124.c:8:5: note: loop turned into non-loop; it never loops. pr59124.c:8:5: note: loop with 7 iterations completely unrolled Last iteration exit edge was proved true. Forced statement unreachable: _14 = baz[_9]; However, it is clear that _14 = baz[_9] is executed only 5 times (not 5 times + 1). Why is this estimate wrong?