https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69526
--- Comment #4 from amker at gcc dot gnu.org --- (In reply to rdapp from comment #2) > Ok, that's sensible but why is the - 1 necessary in the first place? > > n_5 - 1 can only underflow if n_5 == 0 which is checked by > > testl %edx, %edx > > before. This is in a previous basic block, unfortunately, and will not be > regarded by ivopts then (because strictly speaking, it has no influence on > the induction variable)? Actually ivopts does take preheader costs into consideration. Just the cost needs to be amortized over number of loop iterations when compiling for speed. After that, the cost gets more inaccurate. For example, instruction cost is generally 4, while average loop niters is 5, the cost becomes 0 in this way.