------- Comment #3 from tkoenig at gcc dot gnu dot org  2009-11-21 18:31 -------
(In reply to comment #2)
> Sorry, Steve - my mistake.
> 
> The original message should have been:
> 
> To illustrate this with a simple example:
> 
> DO I = M1, M2, M3
>    B(I) = A(I)
> ENDDO
> 
> would be most easily, and straightforwardly, implemented as follows:
> 
>      IF (M3 > 0 .AND. M1 > M2) GOTO 200  ! Loop executed zero times
>      IF (M3 < 0 .AND. M1 < M2) GOTO 200  ! Ditto
>      ITEMP = (M2 - M1 + M3) / M3         ! Temporary loop counter
>      I     = M1
>  100 CONTINUE
>      B(I)  = A(I)
>      ITEMP = ITEMP - 1                   ! Adjust internal loop counter
>      I     = I + M3                      ! Adjust DO loop variable
>      IF (ITEMP >= 0) GOTO 100
>  200 CONTINUE

As written, this executes the assignment one time too many.
The last but one line should read:

      IF (ITEMP > 0) GOTO 100

What we generate has the test at the bottom of the loop,
whereas 8.1.6.4.2 puts the test of the iteration count first.

What we could generate, IMHO, is

     read (*,*) m1, m2, m3
      ITEMP = (M2 - M1 + M3) / M3         ! Temporary loop counter
      print *,'itemp=',itemp
      I = M1
 100  CONTINUE
      IF (ITEMP <= 0) GOTO 200
      print *,i
      I  = I + M3                         ! Adjust DO loop variable
      ITEMP = ITEMP - 1                   ! Adjust internal loop counter
      GOTO 100
 200  CONTINUE
      print *,"final : i = ", i
      end

Does this have any drawbacks?  Would the middle end recognize this for
vectorization and loop unrolling?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42131

Reply via email to