OSDN Git Service

Do not use a data ref with indices invalid in the loop of the close_phi.
authorspop <spop@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 25 Jan 2011 06:48:52 +0000 (06:48 +0000)
committerspop <spop@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 25 Jan 2011 06:48:52 +0000 (06:48 +0000)
2011-01-25  Sebastian Pop  <sebastian.pop@amd.com>

* graphite-sese-to-poly.c (dr_indices_valid_in_loop): New.
(close_phi_written_to_memory): Call for_each_index with
dr_indices_valid_in_loop.

* gfortran.dg/graphite/id-24.f: New.
* gfortran.dg/graphite/id-25.f: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@169220 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/ChangeLog.graphite
gcc/graphite-sese-to-poly.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/graphite/id-24.f [new file with mode: 0644]
gcc/testsuite/gfortran.dg/graphite/id-25.f [new file with mode: 0644]

index 599ee15..25e2bc4 100644 (file)
@@ -1,5 +1,11 @@
 2011-01-25  Sebastian Pop  <sebastian.pop@amd.com>
 
+       * graphite-sese-to-poly.c (dr_indices_valid_in_loop): New.
+       (close_phi_written_to_memory): Call for_each_index with
+       dr_indices_valid_in_loop.
+
+2011-01-25  Sebastian Pop  <sebastian.pop@amd.com>
+
        * graphite-sese-to-poly.c (new_pbb_from_pbb): Only copy PBB_DOMAIN
        when it is initialized.
 
index 8855606..7fc8402 100644 (file)
@@ -1,3 +1,12 @@
+2011-01-20  Sebastian Pop  <sebastian.pop@amd.com>
+
+       * graphite-sese-to-poly.c (dr_indices_valid_in_loop): New.
+       (close_phi_written_to_memory): Call for_each_index with
+       dr_indices_valid_in_loop.
+
+       * gfortran.dg/graphite/id-24.f: New.
+       * gfortran.dg/graphite/id-25.f: New.
+
 2011-01-19  Sebastian Pop  <sebastian.pop@amd.com>
 
        * graphite-sese-to-poly.c (new_pbb_from_pbb): Only copy PBB_DOMAIN
index c6b4385..11a73b3 100644 (file)
@@ -2999,6 +2999,35 @@ remove_phi (gimple phi)
   remove_phi_node (&gsi, false);
 }
 
+/* Helper function for for_each_index.  For each INDEX of the data
+   reference REF, returns true when its indices are valid in the loop
+   nest LOOP passed in as DATA.  */
+
+static bool
+dr_indices_valid_in_loop (tree ref ATTRIBUTE_UNUSED, tree *index, void *data)
+{
+  loop_p loop;
+  basic_block header, def_bb;
+  gimple stmt;
+
+  if (TREE_CODE (*index) != SSA_NAME)
+    return true;
+
+  loop = *((loop_p *) data);
+  header = loop->header;
+  stmt = SSA_NAME_DEF_STMT (*index);
+
+  if (!stmt)
+    return true;
+
+  def_bb = gimple_bb (stmt);
+
+  if (!def_bb)
+    return true;
+
+  return dominated_by_p (CDI_DOMINATORS, header, def_bb);
+}
+
 /* When the result of a CLOSE_PHI is written to a memory location,
    return a pointer to that memory reference, otherwise return
    NULL_TREE.  */
@@ -3007,21 +3036,40 @@ static tree
 close_phi_written_to_memory (gimple close_phi)
 {
   imm_use_iterator imm_iter;
-  tree res, def = gimple_phi_result (close_phi);
   use_operand_p use_p;
   gimple stmt;
+  tree res, def = gimple_phi_result (close_phi);
 
   FOR_EACH_IMM_USE_FAST (use_p, imm_iter, def)
     if ((stmt = USE_STMT (use_p))
        && gimple_code (stmt) == GIMPLE_ASSIGN
-       && (res = gimple_assign_lhs (stmt))
-       && (TREE_CODE (res) == ARRAY_REF
-           || TREE_CODE (res) == MEM_REF
-           || TREE_CODE (res) == VAR_DECL
-           || TREE_CODE (res) == PARM_DECL
-           || TREE_CODE (res) == RESULT_DECL))
-      return res;
+       && (res = gimple_assign_lhs (stmt)))
+      {
+       switch (TREE_CODE (res))
+         {
+         case VAR_DECL:
+         case PARM_DECL:
+         case RESULT_DECL:
+           return res;
+
+         case ARRAY_REF:
+         case MEM_REF:
+           {
+             tree arg = gimple_phi_arg_def (close_phi, 0);
+             loop_p nest = loop_containing_stmt (SSA_NAME_DEF_STMT (arg));
+
+             /* FIXME: this restriction is for id-{24,25}.f and
+                could be handled by duplicating the computation of
+                array indices before the loop of the close_phi.  */
+             if (for_each_index (&res, dr_indices_valid_in_loop, &nest))
+               return res;
+           }
+           /* Fallthru.  */
 
+         default:
+           continue;
+         }
+      }
   return NULL_TREE;
 }
 
index a03e7d9..1b26d4a 100644 (file)
@@ -1,5 +1,10 @@
 2011-01-25  Sebastian Pop  <sebastian.pop@amd.com>
 
+       * gfortran.dg/graphite/id-24.f: New.
+       * gfortran.dg/graphite/id-25.f: New.
+
+2011-01-25  Sebastian Pop  <sebastian.pop@amd.com>
+
        * gfortran.dg/graphite/id-23.f: New.
 
 2011-01-25  Sebastian Pop  <sebastian.pop@amd.com>
diff --git a/gcc/testsuite/gfortran.dg/graphite/id-24.f b/gcc/testsuite/gfortran.dg/graphite/id-24.f
new file mode 100644 (file)
index 0000000..20c40ee
--- /dev/null
@@ -0,0 +1,9 @@
+      SUBROUTINE TFTRAB(A,NA)
+      DIMENSION A(NA,NA)
+      DO 160 K=1,NA
+         DUM = DUM + A(K,I)
+ 160  CONTINUE
+      DO 180 I=1,NA
+         A(I,J) = DUM
+ 180  CONTINUE
+      END
diff --git a/gcc/testsuite/gfortran.dg/graphite/id-25.f b/gcc/testsuite/gfortran.dg/graphite/id-25.f
new file mode 100644 (file)
index 0000000..642ed6d
--- /dev/null
@@ -0,0 +1,10 @@
+      SUBROUTINE TFTRAB(NA,NC,D,WRK)
+      DIMENSION D(NA,NC), WRK(NA)
+      DO 160 K=1,NA
+         DUM = DUM + D(K,J)
+ 160  CONTINUE
+      WRK(I) = DUM
+      DO 180 I=1,NA
+         D(I,J) = WRK(I)
+ 180  CONTINUE
+      END