public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* Odd bug from Stack Overflow
@ 2018-03-18 15:40 Steve Kargl
  2018-03-18 16:03 ` Steve Kargl
  2018-03-18 17:12 ` Thomas König
  0 siblings, 2 replies; 4+ messages in thread
From: Steve Kargl @ 2018-03-18 15:40 UTC (permalink / raw)
  To: fortran

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-03-18 17:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-18 15:40 Odd bug from Stack Overflow Steve Kargl
2018-03-18 16:03 ` Steve Kargl
2018-03-18 17:12 ` Thomas König
2018-03-18 17:19   ` Steve Kargl

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