[Bug fortran/30404] Wrong FORALL result

pault at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Mon Jan 8 12:23:00 GMT 2007



------- Comment #2 from pault at gcc dot gnu dot org  2007-01-08 12:23 -------
  logical :: l1(2,2) = reshape ((/.false.,.true.,.true.,.false./), (/2,2/))
  integer :: it(2,2) = reshape ((/1,2,3,4/), (/2,2/))
  forall (i = 1:2, i < 3)
    forall (j = 1:2, l1(i,j))
      it(i, j) = 0
    end forall
  end forall
!  print *, l1
!  print '(4i2)', it
end

gfortran gives:
 F T T F
 0 0 0 0

the correct result is, of course:
 F T T F
 1 0 0 4

The (annotated) code is:

MAIN__ ()
{
  int4 j;
  static int4 it[4] = {1, 2, 3, 4};
  int4 i;
  static logical4 l1[4] = {0, 1, 1, 0};

  _gfortran_set_std (70, 127, 0);
  {
    int4 mi.2;
    int4 count.3;
    logical1 temp.1[2];
    int4 i.0;

    mi.2 = 0;
    i.0 = 1;
    count.3 = 2;
    while (1)
      {
        if (count.3 <= 0) goto L.1;
        temp.1[mi.2] = i.0 <= 2;
        mi.2 = mi.2 + 1;
        i.0 = i.0 + 1;
        count.3 = count.3 - 1;
      }
    L.1:;
    {
      int4 mi.6;
      int4 count.9;
      int4 count.8;
      int4 count.7;
      logical1 temp.5[2];
      int4 j.4;

      mi.6 = 0;
      j.4 = 1;
      count.7 = 2;
      while (1)                 /* i.0 is now 3 */
        {
          if (count.7 <= 0) goto L.2;
          temp.5[mi.6] = (logical1) l1[j.4 * 2 + NON_LVALUE_EXPR <i.0> + -3];
          mi.6 = mi.6 + 1;
          j.4 = j.4 + 1;
          count.7 = count.7 - 1;
        }
      L.2:;                    /* temp.5 = {1, ?} */
      i.0 = 1;
      mi.2 = 0;
      count.9 = 2;
      while (1)
        {
          if (count.9 <= 0) goto L.4;
          if (temp.1[mi.2])
            {
              j.4 = 1;
              mi.6 = 0;
              count.8 = 2;
              while (1)
                {
                  if (count.8 <= 0) goto L.3;
                  if (temp.5[mi.6])       /* {1, ?} */
                    {
                      it[j.4 * 2 + NON_LVALUE_EXPR <i.0> + -3] = 0;
                    }
                  j.4 = j.4 + 1;
                  mi.6 = mi.6 + 1;
                  count.8 = count.8 - 1;
                }                         /* Since ? probably != 0 => it = 0 */
              L.3:;
            }
          i.0 = i.0 + 1;
          mi.2 = mi.2 + 1;
          count.9 = count.9 - 1;
        }
      L.4:;
    }
  }
}

>From which we see that nested masks, with dependencies on the outer indices,
are not being evaluated with anything other than out of range values for the
outer indices.  In fact the mask is either not being given the correct rank or
the nesting of each block should include evaluation of the mask within the
outer loops.  I have not thought through if the last is consistent with
dependency analysis.

Paul


-- 


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



More information about the Gcc-bugs mailing list