diff mbox

Fix PR tree-optimization/50178

Message ID CAKSNEw483-JewWC3j-fLxWeu3EK+cjbCrqZ9_EdZAK8U9pnWdQ@mail.gmail.com
State New
Headers show

Commit Message

Ira Rosen Sept. 1, 2011, 8:12 a.m. UTC
Hi,

When vectorizing a function call we replace the original call with a
dummy statement to ensure that DCE later removes it. We also remove
its stmt_vec_info, which causes the segfault when we try to access it
through related pattern stmt. The following patch updates related
pattern stmt to be the dummy stmt.

Bootstrapped and tested on powerpc64-suse-linux.
OK for 4.6?

Thanks,
Ira

ChangeLog:

     PR tree-optimization/50178
     * tree-vect-stmts.c (vectorizable_call): Update the related
pattern statement
     before deleting the original call.
     (vect_transform_stmt): Don't expect the related pattern statement match the
     original statement after transformation.

testsuite/ChangeLog:

     PR tree-optimization/50178
     * gfortran.dg/vect/pr50178.f90: New test.

Comments

Richard Biener Sept. 1, 2011, 8:14 a.m. UTC | #1
On Thu, Sep 1, 2011 at 10:12 AM, Ira Rosen <ira.rosen@linaro.org> wrote:
> Hi,
>
> When vectorizing a function call we replace the original call with a
> dummy statement to ensure that DCE later removes it. We also remove
> its stmt_vec_info, which causes the segfault when we try to access it
> through related pattern stmt. The following patch updates related
> pattern stmt to be the dummy stmt.
>
> Bootstrapped and tested on powerpc64-suse-linux.
> OK for 4.6?

Ok.

Thanks,
Richard.

> Thanks,
> Ira
>
> ChangeLog:
>
>     PR tree-optimization/50178
>     * tree-vect-stmts.c (vectorizable_call): Update the related
> pattern statement
>     before deleting the original call.
>     (vect_transform_stmt): Don't expect the related pattern statement match the
>     original statement after transformation.
>
> testsuite/ChangeLog:
>
>     PR tree-optimization/50178
>     * gfortran.dg/vect/pr50178.f90: New test.
>
> Index: testsuite/gfortran.dg/vect/pr50178.f90
> ===================================================================
> --- testsuite/gfortran.dg/vect/pr50178.f90      (revision 0)
> +++ testsuite/gfortran.dg/vect/pr50178.f90      (revision 0)
> @@ -0,0 +1,29 @@
> +! { dg-do compile }
> +
> +module yemdyn
> +   implicit none
> +   integer, parameter :: jpim = selected_int_kind(9)
> +   integer, parameter :: jprb = selected_real_kind(13,300)
> +   real(kind=jprb) :: elx
> +   real(kind=jprb), allocatable :: xkcoef(:)
> +   integer(kind=jpim),allocatable :: ncpln(:), npne(:)
> +end module yemdyn
> +
> +subroutine suedyn
> +
> +   use yemdyn
> +
> +   implicit none
> +
> +   integer(kind=jpim) :: jm, jn
> +   real(kind=jprb) :: zjm, zjn, zxxx
> +
> +   jn=0
> +   do jm=0,ncpln(jn)
> +      zjm=real(jm,jprb) / elx
> +      xkcoef(npne(jn)+jm) = - zxxx*(zjm**2)**0.5_jprb
> +   end do
> +
> +end subroutine suedyn
> +
> +! { dg-final { cleanup-tree-dump "vect" } }
> Index: tree-vect-stmts.c
> ===================================================================
> --- tree-vect-stmts.c   (revision 178373)
> +++ tree-vect-stmts.c   (working copy)
> @@ -1583,6 +1583,14 @@ vectorizable_call (gimple stmt, gimple_stmt_iterat
>   new_stmt = gimple_build_assign (gimple_call_lhs (stmt),
>                                  build_zero_cst (type));
>   set_vinfo_for_stmt (new_stmt, stmt_info);
> +  /* For pattern statements make the related statement to point to
> +     NEW_STMT in order to be able to retrieve the original statement
> +     information later.  */
> +  if (is_pattern_stmt_p (stmt_info))
> +    {
> +      gimple related = STMT_VINFO_RELATED_STMT (stmt_info);
> +      STMT_VINFO_RELATED_STMT (vinfo_for_stmt (related)) = new_stmt;
> +    }
>   set_vinfo_for_stmt (stmt, NULL);
>   STMT_VINFO_STMT (stmt_info) = new_stmt;
>   gsi_replace (gsi, new_stmt, false);
> @@ -4957,11 +4965,7 @@ vect_transform_stmt (gimple stmt, gimple_stmt_iter
>             the stmt_info of ORIG_STMT_IN_PATTERN.  See more details in the
>             documentation of vect_pattern_recog.  */
>          if (STMT_VINFO_IN_PATTERN_P (stmt_vinfo))
> -           {
> -             gcc_assert (STMT_VINFO_RELATED_STMT (stmt_vinfo)
> -                           == orig_scalar_stmt);
> -             STMT_VINFO_VEC_STMT (stmt_vinfo) = vec_stmt;
> -           }
> +           STMT_VINFO_VEC_STMT (stmt_vinfo) = vec_stmt;
>        }
>     }
>
Jakub Jelinek Sept. 1, 2011, 8:16 a.m. UTC | #2
On Thu, Sep 01, 2011 at 10:14:29AM +0200, Richard Guenther wrote:
> On Thu, Sep 1, 2011 at 10:12 AM, Ira Rosen <ira.rosen@linaro.org> wrote:
> > When vectorizing a function call we replace the original call with a
> > dummy statement to ensure that DCE later removes it. We also remove
> > its stmt_vec_info, which causes the segfault when we try to access it
> > through related pattern stmt. The following patch updates related
> > pattern stmt to be the dummy stmt.
> >
> > Bootstrapped and tested on powerpc64-suse-linux.
> > OK for 4.6?
> 
> Ok.

Please also commit the testcase into the trunk.

> >     PR tree-optimization/50178
> >     * tree-vect-stmts.c (vectorizable_call): Update the related
> > pattern statement
> >     before deleting the original call.
> >     (vect_transform_stmt): Don't expect the related pattern statement match the
> >     original statement after transformation.
> >
> > testsuite/ChangeLog:
> >
> >     PR tree-optimization/50178
> >     * gfortran.dg/vect/pr50178.f90: New test.

	Jakub
diff mbox

Patch

Index: testsuite/gfortran.dg/vect/pr50178.f90
===================================================================
--- testsuite/gfortran.dg/vect/pr50178.f90      (revision 0)
+++ testsuite/gfortran.dg/vect/pr50178.f90      (revision 0)
@@ -0,0 +1,29 @@ 
+! { dg-do compile }
+
+module yemdyn
+   implicit none
+   integer, parameter :: jpim = selected_int_kind(9)
+   integer, parameter :: jprb = selected_real_kind(13,300)
+   real(kind=jprb) :: elx
+   real(kind=jprb), allocatable :: xkcoef(:)
+   integer(kind=jpim),allocatable :: ncpln(:), npne(:)
+end module yemdyn
+
+subroutine suedyn
+
+   use yemdyn
+
+   implicit none
+
+   integer(kind=jpim) :: jm, jn
+   real(kind=jprb) :: zjm, zjn, zxxx
+
+   jn=0
+   do jm=0,ncpln(jn)
+      zjm=real(jm,jprb) / elx
+      xkcoef(npne(jn)+jm) = - zxxx*(zjm**2)**0.5_jprb
+   end do
+
+end subroutine suedyn
+
+! { dg-final { cleanup-tree-dump "vect" } }
Index: tree-vect-stmts.c
===================================================================
--- tree-vect-stmts.c   (revision 178373)
+++ tree-vect-stmts.c   (working copy)
@@ -1583,6 +1583,14 @@  vectorizable_call (gimple stmt, gimple_stmt_iterat
   new_stmt = gimple_build_assign (gimple_call_lhs (stmt),
                                  build_zero_cst (type));
   set_vinfo_for_stmt (new_stmt, stmt_info);
+  /* For pattern statements make the related statement to point to
+     NEW_STMT in order to be able to retrieve the original statement
+     information later.  */
+  if (is_pattern_stmt_p (stmt_info))
+    {
+      gimple related = STMT_VINFO_RELATED_STMT (stmt_info);
+      STMT_VINFO_RELATED_STMT (vinfo_for_stmt (related)) = new_stmt;
+    }
   set_vinfo_for_stmt (stmt, NULL);
   STMT_VINFO_STMT (stmt_info) = new_stmt;
   gsi_replace (gsi, new_stmt, false);
@@ -4957,11 +4965,7 @@  vect_transform_stmt (gimple stmt, gimple_stmt_iter
             the stmt_info of ORIG_STMT_IN_PATTERN.  See more details in the
             documentation of vect_pattern_recog.  */
          if (STMT_VINFO_IN_PATTERN_P (stmt_vinfo))
-           {
-             gcc_assert (STMT_VINFO_RELATED_STMT (stmt_vinfo)
-                           == orig_scalar_stmt);
-             STMT_VINFO_VEC_STMT (stmt_vinfo) = vec_stmt;
-           }
+           STMT_VINFO_VEC_STMT (stmt_vinfo) = vec_stmt;
        }
     }