[patch, vectorizer] Fix PR tree-optimization/38529

Ira Rosen IRAR@il.ibm.com
Mon Dec 29 20:30:00 GMT 2008



Dorit Nuzman/Haifa/IBM wrote on 28/12/2008 13:14:13:

> >
> > Hi,
> >
> > This patch fixes an ICE in the vectorizer that occurs in case that a
def is
> > in the inner loop and its use is in the outer loop (which is being
> > vectorized). The problem is that the vectorized definitions were not
> > recorded for such uses.
> >
>
> lets just check a testcase that involves a reduction - I think there
> may be some special handling required in that case.

The patch checks that it is not reduction, so it must be ok. (And also the
patch passes all the vectorizer testcases, including outer loop with
reduction).

> OK for mainline otherwise

Thanks. I am retesting it now with Daniel's comment.

I still need an OK for 4.3.

>(see minor comment below),

I added your comment to our todo list.

Thanks,
Ira


>
> thanks,
> dorit
>
> > Bootstrapped with vectorization enabled and regtested on
> > powerpc64-suse-linux.
> > O.K. for 4.3 and 4.4?
> >
> > Thanks,
> > Ira
> >
> > ChangeLog entry:
> >
> > 2008-12-16  Dorit Nuzman  <dorit@il.ibm.com>
> >             Ira Rosen  <irar@il.ibm.com>
> >
> >       PR tree-optimization/38529
> >       * tree-vect-transform (vect_transform_stmt): Handle inner-loop
stmts
> >       whose DEF is used in the loop-nest that is being vectorized, but
> > outside
> >       the immediately enclosing loop.
> >
> > testsuite/ChangeLog entry:
> >
> > 2008-12-16  Dorit Nuzman  <dorit@il.ibm.com>
> >             Ira Rosen  <irar@il.ibm.com>
> >
> >       PR tree-optimization/38529
> >       * gcc.dg/vect/pr38529.c: New.
> >
> >
> > Index: tree-vect-transform.c
> > ===================================================================
> > --- tree-vect-transform.c       (revision 142762)
> > +++ tree-vect-transform.c       (working copy)
> > @@ -7047,6 +7047,8 @@ vect_transform_stmt (gimple stmt, gimple
> >    stmt_vec_info stmt_info = vinfo_for_stmt (stmt);
> >    gimple orig_stmt_in_pattern;
> >    bool done;
> > +  loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_info);
> > +  struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
> >
> >    switch (STMT_VINFO_TYPE (stmt_info))
> >      {
> > @@ -7130,6 +7132,52 @@ vect_transform_stmt (gimple stmt, gimple;
> >         }
> >      }
> >
> > +  /* Handle inner-loop stmts whose DEF is used in the loop-nest that
> > +     is being vectorized, but outside the immediately enclosing loop.
*/
> > +  if (vec_stmt
> > +      && nested_in_vect_loop_p (loop, stmt)
> > +      && STMT_VINFO_TYPE (stmt_info) != reduc_vec_info_type
> > +      && (STMT_VINFO_RELEVANT (stmt_info) == vect_used_in_outer
> > +          || STMT_VINFO_RELEVANT (stmt_info) ==
> > vect_used_in_outer_by_reduction))
>
> (This reminds me that we still use the  "if (nested_in_vect_loop_p)"
> to distinguish between "vectorized reductions" (reductions that
> reside in the loop level that is being vectorized) and "nested
> reductions" (reductions that reside in a loop level nested within
> the loop that is being vectorized). A cleaner solution would be to
> classify these to kinds of reductions differently in the first place).
>
> > +    {
> > +      struct loop *innerloop = loop->inner;)
> > +      imm_use_iterator imm_iter;
> > +      use_operand_p use_p;
> > +      VEC(gimple,heap) *phis = NULL;>
> > +      tree scalar_dest;
> > +      gimple exit_phi;;
> > +      int i;
> > +
> > +      if (vect_print_dump_info (REPORT_DETAILS))
> > +       fprintf (vect_dump, "Record the vdef for outer-loop
> > vectorization.");
> > +
> > +      /* Find the relevant loop-exit phi-node, and reord the vec_stmt
> > there;
> > +        (to be used when vectorizing outer-loop stmts that use the DEF
of
> > +        STMT).  */
> > +      if (gimple_code (stmt) == GIMPLE_PHI)
> > +       scalar_dest = PHI_RESULT (stmt);
> > +      else
> > +        scalar_dest = gimple_assign_lhs (stmt);
> > +
> > +      phis = VEC_alloc (gimple, heap, 10);
> > +      FOR_EACH_IMM_USE_FAST (use_p, imm_iter, scalar_dest)
> > +       {
> > +         if (!flow_bb_inside_loop_p (innerloop, gimple_bb (USE_STMT
> > (use_p))))
> > +           {
> > +             exit_phi = USE_STMT (use_p);
> > +             VEC_quick_push (gimple, phis, exit_phi);
> > +           }
> > +       }
> > +
> > +      for (i = 0; VEC_iterate (gimple, phis, i, exit_phi); i++)
> > +       {
> > +         stmt_vec_info stmt_vinfo = vinfo_for_stmt (exit_phi);)
> > +         STMT_VINFO_VEC_STMT (stmt_vinfo) = vec_stmt;
> > +        }
> > +    }
> > +
> > +  /* Handle stmts whose DEF is used outside the loop-nest that is
> > +     being vectorized.  */
> >    if (STMT_VINFO_LIVE_P (stmt_info)
> >        && STMT_VINFO_TYPE (stmt_info) != reduc_vec_info_type)
> >      {
> > Index: testsuite/gcc.dg/vect/pr38529.c!
> > ===================================================================
> > --- testsuite/gcc.dg/vect/pr38529.c     (revision 0)
> > +++ testsuite/gcc.dg/vect/pr38529.c     (revision 0)
> > @@ -0,0 +1,18 @@
> > +/* { dg-do compile } */
> > +/* { dg-require-effective-target vect_float } */
> > +
> > +float a[4];
> > +
> > +void foo();
> > +{
> > +  int i, j;
> > +
> > +  for (i = 0; i < 4; ++i)
> > +    for (j = 0; j < 17; ++j)
> > +      a[i] = 0;
> > +}
> > +}
> > +/* { dg-final { scan-tree-dump-times "OUTER LOOP VECTORIZED" 1
"vect"  } }
> > */)
> > +/* { dg-final { cleanup-tree-dump "vect" } } */
> > +
> >



More information about the Gcc-patches mailing list