https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66158
Bug ID: 66158 Summary: Use DO loop constraints for optimizing bounds checking Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: tkoenig at gcc dot gnu.org Target Milestone: --- For the code real, dimension(10) :: a ... do i=1,10 a(i) = a(i) + 3. end do we can prove that there is no possible bounds checking violation, and the compiler should not insert code to do so. It is more tricky with do i=1,10 a(i) = a(i) + 3. call foo(i) end do Sure, it is illegal to change i, but the whole point of bounds checking is to catch buggy programs, so we should not eliminate the checks there. Also, the code we generate ourselves, such as for inline matmul, we can easily prove that no bounds check occurs. If somebody does strange things like equivalencing a DO loop variable, we should also be prepared for the worst.