[Bug fortran/42131] Weird translation of DO loops
toon at moene dot org
gcc-bugzilla@gcc.gnu.org
Sat Nov 21 21:41:00 GMT 2009
------- Comment #5 from toon at moene dot org 2009-11-21 21:40 -------
> The middle-end prefers do { } while () loop style so it knows the loop is
> always executed.
And the Fortran Standard describes the loops being built (by compilers) just
so:
1. First you determine what is m1, m2, m3
2. Then you initialize the do loop counter with m1
3. Then you determine the loop count (m2 - m1 + m3) / m3
4. If the loop count is zero or negative, you skip the loop
5. Otherwise, you traverse the loop body at least once.
Or, to return to our example (and fix the mistake Thomas Koenig noted):
DO I = M1, M2, M3
B(I) = A(I)
ENDDO
turns into
ITEMP = (M2 - M1 + M3) / M3 ! The iteration count
IF (ITEMP <= 0) GOTO 200 ! Past this point, the loop is executed
I = M1 ! at least once.
100 CONTINUE
B(I) = A(I)
ITEMP = ITEMP - 1
I = I + M3
IF (ITEMP > 0) GOTO 100
200 CONTINUE
therewith following the (normative) text of the Standard.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42131
More information about the Gcc-bugs
mailing list