public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/42131] New: Weird translation of DO loops Date: Sat, 21 Nov 2009 13:58:00 -0000 [thread overview] Message-ID: <bug-42131-10053@http.gcc.gnu.org/bugzilla/> (raw) Split out from PR42108. The loop is not unrolled because the frontend presents us with very funny obfuscated code: do k=i,nnd,n temp=temp+(x(k)-x(k+jmini))**2 end do gets translated to { character(kind=4) countm1.6; integer(kind=4) D.1551; integer(kind=4) D.1550; integer(kind=4) D.1549; D.1549 = i; D.1550 = *nnd; D.1551 = *n; k = D.1549; if (D.1551 > 0) { if (D.1550 < D.1549) goto L.6;, countm1.6 = (character(kind=4)) (D.1550 - D.1549) / (character(kind=4)) D.1551;; } else { if (D.1550 > D.1549) goto L.6;, countm1.6 = (character(kind=4)) (D.1549 - D.1550) / (character(kind=4)) -D.1551;; } while (1) { { real(kind=8) D.1556; real(kind=8) D.1555; D.1555 = (((*x)[(integer(kind=8)) k + -1] - (*x)[(integer(kind=8)) (k + jmini) + -1])); D.1556 = D.1555 * D.1555; temp = temp + D.1556; } L.5:; k = k + D.1551; if (countm1.6 == 0) goto L.6; countm1.6 = countm1.6 + 4294967295; } L.6:; } The funny conditional initialization of countm1.6 makes the analysis of the number of iterations of this loop impossible (not to mention the conversions to character(kind=4)). Toon suggests: The Standard doesn't prescribe the code the Frontend generates - however, to be sure one follows the Standard, it's most easy to simply implement the steps given. To illustrate this with a simple example: DO I = M1, M2, M3 B(I) = A(I) ENDDO would be most easily, and atraightforwardly, 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 count 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 That there are two induction variables in this loop is inconsequential - one of them should be eliminated by induction variable elimination (at least, that was the case with g77 and the RTL loop optimization pass). which I would agree with. I btw cannot see the difference between if (D.1551 > 0) { if (D.1550 < D.1549) goto L.6;, countm1.6 = (character(kind=4)) (D.1550 - D.1549) / (character(kind=4)) D.1551;; } else { if (D.1550 > D.1549) goto L.6;, countm1.6 = (character(kind=4)) (D.1549 - D.1550) / (character(kind=4)) -D.1551;; } and if ((D.1551 > 0 && D.1550 < D.1549) || (D.1551 < 0 && D.1550 > D.1549)) goto L.6; countm1.6 = (character(kind=4)) (D.1550 - D.1549) / (character(kind=4)) D.1551; where the unconditional initialization of countm1.6 is the important difference (I'm sure the zero-trip-count check can be done more efficiently). -- Summary: Weird translation of DO loops Product: gcc Version: 4.5.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rguenth at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42131
next reply other threads:[~2009-11-21 13:58 UTC|newest] Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top 2009-11-21 13:58 rguenth at gcc dot gnu dot org [this message] 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 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=bug-42131-10053@http.gcc.gnu.org/bugzilla/ \ --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: linkBe 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).