public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tkoenig at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/55806] New: Missed optimization with ANY or ALL
Date: Tue, 25 Dec 2012 15:39:00 -0000	[thread overview]
Message-ID: <bug-55806-4@http.gcc.gnu.org/bugzilla/> (raw)


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

             Bug #: 55806
           Summary: Missed optimization with ANY or ALL
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tkoenig@gcc.gnu.org


Mike Metcalf complains (correctly) in
<44daf54c-3de5-4b1c-a1f7-cb7bf0d496b0@googlegroups.com>
that using ANY as an idiom instead of .or. for a small number of conditions.



Look at this:

module mymod
contains
  subroutine bar(a,b,c)
    integer, dimension(3,3), intent(in) :: a,b
    integer, intent(out) :: c
    real, parameter :: acc = 1e-4
    integer :: i

    c = 0
    do i=1,3
       if (any([abs(a(i,1) - b(i,1)) > acc,  &
            abs(a(i,2) - b(i,2)) > acc, &
            abs(a(i,3) - b(i,3)) > acc])) cycle
       c = c + 1
    end do
  end subroutine bar
end module mymod

This generates a logical array, assigns the values to them,
and then loops over the array to generate the values:


              atmp.1.dtype = 273;
              atmp.1.dim[0].stride = 1;
              atmp.1.dim[0].lbound = 0;
              atmp.1.dim[0].ubound = 2;
              atmp.1.data = (void * restrict) &A.2;
              atmp.1.offset = 0;
              (*(logical(kind=4)[3] * restrict) atmp.1.data)[0] =
(real(kind=4)) ABS_EXPR <(*a)[(integer(kind=8)) i + -1] -
(*b)[(integer(kind=8)) i + -1]> > 9.99999974737875163555145263671875e-5;
              (*(logical(kind=4)[3] * restrict) atmp.1.data)[1] =
(real(kind=4)) ABS_EXPR <(*a)[(integer(kind=8)) i + 2] - (*b)[(integer(kind=8))
i + 2]> > 9.99999974737875163555145263671875e-5;
              (*(logical(kind=4)[3] * restrict) atmp.1.data)[2] =
(real(kind=4)) ABS_EXPR <(*a)[(integer(kind=8)) i + 5] - (*b)[(integer(kind=8))
i + 5]> > 9.99999974737875163555145263671875e-5;
              {
                integer(kind=8) S.4;

                S.4 = 0;
                while (1)
                  {
                    if (S.4 > 2) goto L.5;
                    if (NON_LVALUE_EXPR <(*(logical(kind=4)[3] * restrict)
atmp.1.data)[S.4]>)
                      {
                        test.0 = 1;
                        goto L.4;
                      }
                    S.4 = S.4 + 1;
                  }
                L.5:;
              }
              L.4:;
              if (test.0) goto L.1;
            }
            L.3:;
            *c = *c + 1;
            L.1:;
            D.1907 = i == 3;
            i = i + 1;
            if (D.1907) goto L.2;
          }

The middle-end then fails to remove this array.

Compare this to the result of

module mymod
contains
  subroutine bar(a,b,c)
    real, dimension(3,3), intent(in) :: a,b
    integer, intent(out) :: c
    real, parameter :: acc = 1e-4
    integer :: i

    c = 0.
    do i=1,3
       if (abs(a(i,1) - b(i,1)) > acc .or. &
            abs(a(i,2) - b(i,2)) > acc .or. &
            abs(a(i,3) - b(i,3)) > acc) cycle
       c = c + 1
    end do
  end subroutine bar
end module mymod

What the Fortran FE generates here isn't very idiomatic when you
write in a language like C.  Should we tackle this in the middle
end, or would issuing the version with .or instead of the ANY
to the middle end be preferred?


             reply	other threads:[~2012-12-25 15:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-25 15:39 tkoenig at gcc dot gnu.org [this message]
2012-12-25 18:39 ` [Bug fortran/55806] " burnus at gcc dot gnu.org
2013-01-14 21:50 ` tkoenig at gcc dot gnu.org
2013-01-14 22:30 ` tkoenig at gcc dot gnu.org
2013-01-19 21:33 ` tkoenig at gcc dot gnu.org
2013-01-20 14:56 ` tkoenig at gcc dot gnu.org
2013-01-31 19:48 ` tkoenig at gcc dot gnu.org
2013-01-31 21:02 ` tkoenig at gcc dot gnu.org
2013-03-28 23:25 ` tkoenig at gcc dot gnu.org

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-55806-4@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: 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).