This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC][patch] Fix PR tree-optimization/40801 - ICE in vectorizer


Hi,

The ICE in PR 40801 was caused by a use of incorrect vector operand in
creation of copies of vectorized calls with two arguments. The fix is to
get the correct operand from the previous copy of vector statement and to
pass valid definition type to vect_get_vec_def_for_stmt_copy().

Bootstrapped with vectorization enabled and tested on x86_64-suse-linux.

I made this change for two cases of vectorizable call: when the types are
of the same size (as in the attached testcase), and also for the "narrow"
case, i.e., the input type is bigger than the output type. The problem is,
I can't find a testcase for the later case: i.e., narrowing builtin
function with two or more arguments.

Thanks,
Ira

ChangeLog:

      PR tree-optimization/40801
      * tree-vect-stmts.c (vectorizable_call): Get previous copy
      of vector operand from the previous copy of vector statement.
      Pass the correct definition type value to
      vect_get_vec_def_for_stmt_copy().

testsuite/Changelog:

      PR tree-optimization/40801
      * gfortran.dg/vect/fast-math-real8-pr40801.f90: New test.
      * gfortran.dg/vect/vect.exp: Run tests starting with
      "fast-math-real8" with -ffast-math and -fdefault-real-8.

Index: tree-vect-stmts.c
===================================================================
--- tree-vect-stmts.c   (revision 149788)
+++ tree-vect-stmts.c   (working copy)
@@ -1227,7 +1227,7 @@ vectorizable_call (gimple stmt, gimple_s
   tree fndecl, new_temp, def, rhs_type, lhs_type;
   gimple def_stmt;
   enum vect_def_type dt[2] = {vect_unknown_def_type,
vect_unknown_def_type};
-  gimple new_stmt;
+  gimple new_stmt = NULL;
   int ncopies, j;
   VEC(tree, heap) *vargs = NULL;
   enum { NARROW, NONE, WIDEN } modifier;
@@ -1367,8 +1367,11 @@ vectorizable_call (gimple stmt, gimple_s
                vec_oprnd0
                  = vect_get_vec_def_for_operand (op, stmt, NULL);
              else
-               vec_oprnd0
-                 = vect_get_vec_def_for_stmt_copy (dt[nargs], vec_oprnd0);
+               {
+                 vec_oprnd0 = gimple_call_arg (new_stmt, i);
+                 vec_oprnd0
+                    = vect_get_vec_def_for_stmt_copy (dt[i], vec_oprnd0);
+               }

              VEC_quick_push (tree, vargs, vec_oprnd0);
            }
@@ -1406,14 +1409,15 @@ vectorizable_call (gimple stmt, gimple_s
                  vec_oprnd0
                    = vect_get_vec_def_for_operand (op, stmt, NULL);
                  vec_oprnd1
-                   = vect_get_vec_def_for_stmt_copy (dt[nargs],
vec_oprnd0);
+                   = vect_get_vec_def_for_stmt_copy (dt[i], vec_oprnd0);
                }
              else
                {
+                 vec_oprnd1 = gimple_call_arg (new_stmt, 2*i);
                  vec_oprnd0
-                   = vect_get_vec_def_for_stmt_copy (dt[nargs],
vec_oprnd1);
+                   = vect_get_vec_def_for_stmt_copy (dt[i], vec_oprnd1);
                  vec_oprnd1
-                   = vect_get_vec_def_for_stmt_copy (dt[nargs],
vec_oprnd0);
+                   = vect_get_vec_def_for_stmt_copy (dt[i], vec_oprnd0);
                }

              VEC_quick_push (tree, vargs, vec_oprnd0);
Index: testsuite/gfortran.dg/vect/vect.exp
===================================================================
--- testsuite/gfortran.dg/vect/vect.exp (revision 149788)
+++ testsuite/gfortran.dg/vect/vect.exp (working copy)
@@ -125,6 +125,12 @@ lappend DEFAULT_VECTCFLAGS "-ffast-math"
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/fast-math-*.\[fF
\]{,90,95,03,08} ]]  \
         "" $DEFAULT_VECTCFLAGS

+# -ffast-math tests
+set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS
+lappend DEFAULT_VECTCFLAGS "-ffast-math" "-fdefault-real-8"
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/fast-math-real8*.\[fF
\]{,90,95,03,08} ]]  \
+        "" $DEFAULT_VECTCFLAGS
+
 # -fvect-cost-model tests
 set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS
 lappend DEFAULT_VECTCFLAGS "-fvect-cost-model"
Index: testsuite/gfortran.dg/vect/fast-math-real8-pr40801.f90
===================================================================
--- testsuite/gfortran.dg/vect/fast-math-real8-pr40801.f90      (revision
0)
+++ testsuite/gfortran.dg/vect/fast-math-real8-pr40801.f90      (revision
0)
@@ -0,0 +1,37 @@
+! { dg-do compile }
+
+MODULE YOMPHY0
+REAL :: ECMNP
+REAL :: SCO
+REAL :: USDMLT
+END MODULE YOMPHY0
+SUBROUTINE ACCONV ( KIDIA,KFDIA,KLON,KTDIA,KLEV,&
+                    &CDLOCK)
+USE YOMPHY0  , ONLY : ECMNP    ,SCO      ,USDMLT
+REAL :: PAPHIF(KLON,KLEV),PCVGQ(KLON,KLEV)&
+    &,PFPLCL(KLON,0:KLEV),PFPLCN(KLON,0:KLEV),PSTRCU(KLON,0:KLEV)&
+    &,PSTRCV(KLON,0:KLEV)
+INTEGER :: KNLAB(KLON,KLEV),KNND(KLON)
+REAL :: ZCP(KLON,KLEV),ZLHE(KLON,KLEV),ZDSE(KLON,KLEV)&
+    &,ZPOII(KLON),ZALF(KLON),ZLN(KLON),ZUN(KLON),ZVN(KLON)&
+    &,ZPOIL(KLON)
+DO JLEV=KLEV-1,KTDIA,-1
+  DO JIT=1,NBITER
+    ZLN(JLON)=MAX(0.,ZLN(JLON)&
+     &-(ZQW(JLON,JLEV)-ZQN(JLON)&
+     &*(PQ(JLON,JLEV+1)-ZQN(JLON))))*KNLAB(JLON,JLEV)
+  ENDDO
+ENDDO
+IF (ITOP < KLEV+1) THEN
+  DO JLON=KIDIA,KFDIA
+    ZZVAL=PFPLCL(JLON,KLEV)+PFPLCN(JLON,KLEV)-SCO
+    KNND(JLON)=KNND(JLON)*MAX(0.,-SIGN(1.,0.-ZZVAL))
+  ENDDO
+  DO JLEV=ITOP,KLEV
+    DO JLON=KIDIA,KFDIA
+    ENDDO
+  ENDDO
+ENDIF
+END SUBROUTINE ACCONV
+
+! { dg-final { cleanup-tree-dump "vect" } }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]