public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tkoenig at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/42131] Weird translation of DO loops
Date: Sat, 21 Nov 2009 18:31:00 -0000	[thread overview]
Message-ID: <20091121183125.22560.qmail@sourceware.org> (raw)
In-Reply-To: <bug-42131-10053@http.gcc.gnu.org/bugzilla/>



------- 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


  parent reply	other threads:[~2009-11-21 18:31 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-21 13:58 [Bug fortran/42131] New: " rguenth at gcc dot gnu dot org
2009-11-21 16:26 ` [Bug fortran/42131] " kargl at gcc dot gnu dot org
2009-11-21 17:33 ` toon at moene dot org
2009-11-21 18:31 ` tkoenig at gcc dot gnu dot org [this message]
2009-11-21 19:24 ` rguenth at gcc dot gnu dot org
2009-11-21 21:41 ` toon at moene dot org
2009-11-21 23:07 ` tkoenig at gcc dot gnu dot org
2009-11-21 23:24 ` rguenther at suse dot de
2009-11-21 23:42 ` tkoenig at gcc dot gnu dot org
2009-11-22 10:21 ` toon at moene dot org
2009-11-22 19:04 ` burnus at gcc dot gnu dot org
2009-11-23 21:48 ` tkoenig at gcc dot gnu dot org
2009-11-24 18:04 ` toon at moene dot org
2009-11-26 21:56 ` tkoenig at gcc dot gnu dot org
2009-11-26 22:07 ` kargl at gcc dot gnu dot org
2009-11-26 23:43 ` tkoenig at gcc dot gnu dot org
2009-11-27  8:29 ` burnus at gcc dot gnu dot org
2009-11-27  9:47 ` rguenther at suse dot de
2009-11-27  9:48 ` rguenther at suse dot de
2009-11-28 15:16 ` tkoenig at gcc dot gnu dot org
2009-11-30  7:31 ` tkoenig at gcc dot gnu dot org
2009-11-30 10:10 ` rguenther at suse dot de
2009-11-30 19:16 ` tkoenig at gcc dot gnu dot org
2009-11-30 20:19 ` jvdelisle at gcc dot gnu dot org
2009-11-30 20:36 ` tkoenig at gcc dot gnu dot org
2009-11-30 21:01 ` tkoenig at gcc dot gnu dot org
2009-12-01  9:42 ` rguenther at suse dot de
2009-12-01 18:33 ` jb at gcc dot gnu dot org
2009-12-02  9:23 ` jb at gcc dot gnu dot org
2009-12-04 14:24 ` dominiq at lps dot ens dot fr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091121183125.22560.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).