public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Steve Kargl <sgk@troutmask.apl.washington.edu>
To: fortran@gcc.gnu.org
Subject: Odd bug from Stack Overflow
Date: Sun, 18 Mar 2018 15:40:00 -0000	[thread overview]
Message-ID: <20180318153958.GB85774@troutmask.apl.washington.edu> (raw)

So, who knows how the scalarizer works?

This code

program test
   implicit none
   integer, parameter :: n = 65536
   integer, dimension(n) :: y
   integer*4 :: i
   y = (/ (1, i=1, n) /)
   if (y(2) /= 1) stop 1
end program test

generates a loops that does the right thing.

    offset.1 = 0;
    shadow_loopvar.2 = 1;
    while (1)
      {
        if (shadow_loopvar.2 > 65536) goto L.1;
        (*(integer(kind=4)[65536] * restrict) atmp.0.data)[offset.1] = 1;
        offset.1 = offset.1 + 1;
        shadow_loopvar.2 = shadow_loopvar.2 + 1;
      }
    L.1:;

Clearly, 1 is being assigned to each element of the array 'y'.  Now
change the type of 'y' to real.

    offset.1 = 0;
    (*(real(kind=4)[65536] * restrict) atmp.0.data)[offset.1] = 1.0e+0;
    offset.1 = offset.1 + 1;
    {
      integer(kind=4) S.2;

      S.2 = 0;
      while (1)
        {
          if (S.2 > 65535) goto L.1;
          y[S.2] = (*(real(kind=4)[65536] * restrict) atmp.0.data)[S.2];
          S.2 = S.2 + 1;
        }
      L.1:;
    }

The value of 1.0 is assigned to the first element of atmp, a
temporary array.  Then the loop assigns the values from
temporary array 'atmp'.  The problem is atmp(2:65536) have
never been set.  I was expecting the -fdump-tree-original for
the integer and real codes to look substantially the same.
Something has gone sideways.  Anyone have a good guess where?

-- 
Steve

             reply	other threads:[~2018-03-18 15:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-18 15:40 Steve Kargl [this message]
2018-03-18 16:03 ` Steve Kargl
2018-03-18 17:12 ` Thomas König
2018-03-18 17:19   ` Steve Kargl

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=20180318153958.GB85774@troutmask.apl.washington.edu \
    --to=sgk@troutmask.apl.washington.edu \
    --cc=fortran@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).