OSDN Git Service

Fix PR42681.
authorspop <spop@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 14 Jan 2010 08:37:26 +0000 (08:37 +0000)
committerspop <spop@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 14 Jan 2010 08:37:26 +0000 (08:37 +0000)
2010-01-14  Sebastian Pop  <sebastian.pop@amd.com>

PR middle-end/42681
* graphite-clast-to-gimple.c (gloog_error): New static variable.
(clast_to_gcc_expression): Do not build MULT_EXPR of POINTER_TYPE_P.
Set gloog_error when such an expression failed to be built.
(translate_clast): Early return when gloog_error is set.
(gloog): Clear gloog_error.  When gloog_error is set, call
set_ifsese_condition to enable the original code.  Return the status
of the code generation based on gloog_error.
* sese.c (set_ifsese_condition): New.
* sese.h (set_ifsese_condition): Declared.

* testsuite/g++.dg/graphite/pr42681.C: New.

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

gcc/ChangeLog.graphite
gcc/graphite-clast-to-gimple.c
gcc/sese.c
gcc/sese.h
gcc/testsuite/g++.dg/graphite/pr42681.C [new file with mode: 0644]

index fe3598c..c2bb01e 100644 (file)
@@ -1,5 +1,20 @@
 2010-01-14  Sebastian Pop  <sebastian.pop@amd.com>
 
+       PR middle-end/42681
+       * graphite-clast-to-gimple.c (gloog_error): New static variable.
+       (clast_to_gcc_expression): Do not build MULT_EXPR of POINTER_TYPE_P.
+       Set gloog_error when such an expression failed to be built.
+       (translate_clast): Early return when gloog_error is set.
+       (gloog): Clear gloog_error.  When gloog_error is set, call
+       set_ifsese_condition to enable the original code.  Return the status
+       of the code generation based on gloog_error.
+       * sese.c (set_ifsese_condition): New.
+       * sese.h (set_ifsese_condition): Declared.
+
+       * testsuite/g++.dg/graphite/pr42681.C: New.
+
+2010-01-14  Sebastian Pop  <sebastian.pop@amd.com>
+
        PR middle-end/42732
        * graphite-clast-to-gimple.c (gloog): Call scev_reset_htab and
        rename_nb_iterations.
index be16807..6651e95 100644 (file)
@@ -52,6 +52,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "graphite-clast-to-gimple.h"
 #include "graphite-dependences.h"
 
+/* This flag is set when an error occurred during the translation of
+   CLAST to Gimple.  */
+static bool gloog_error;
+
 /* Verifies properties that GRAPHITE should maintain during translation.  */
 
 static inline void
@@ -294,7 +298,11 @@ clast_to_gcc_expression (tree type, struct clast_expr *e,
                                               newivs_index, params_index);
                tree cst = gmp_cst_to_tree (type, t->val);
                name = fold_convert (type, name);
-               return fold_build2 (MULT_EXPR, type, cst, name);
+               if (!POINTER_TYPE_P (type))
+                 return fold_build2 (MULT_EXPR, type, cst, name);
+
+               gloog_error = true;
+               return cst;
              }
          }
        else
@@ -944,7 +952,7 @@ translate_clast (sese region, loop_p context_loop, struct clast_stmt *stmt,
                 htab_t newivs_index, htab_t bb_pbb_mapping, int level,
                 htab_t params_index)
 {
-  if (!stmt)
+  if (!stmt || gloog_error)
     return next_e;
 
   if (CLAST_STMT_IS_A (stmt, stmt_root))
@@ -1431,6 +1439,7 @@ gloog (scop_p scop, htab_t bb_pbb_mapping)
   cloog_prog_clast pc;
 
   timevar_push (TV_GRAPHITE_CODE_GEN);
+  gloog_error = false;
 
   pc = scop_to_clast (scop);
 
@@ -1476,6 +1485,9 @@ gloog (scop_p scop, htab_t bb_pbb_mapping)
   recompute_all_dominators ();
   graphite_verify ();
 
+  if (gloog_error)
+    set_ifsese_condition (if_region, integer_zero_node);
+
   free (if_region->true_region);
   free (if_region->region);
   free (if_region);
@@ -1502,7 +1514,7 @@ gloog (scop_p scop, htab_t bb_pbb_mapping)
               num_no_dependency);
     }
 
-  return true;
+  return !gloog_error;
 }
 
 #endif
index 1c4686d..f959bdb 100644 (file)
@@ -1558,6 +1558,34 @@ move_sese_in_condition (sese region)
   return if_region;
 }
 
+/* Replaces the condition of the IF_REGION with CONDITION:
+   | if (CONDITION)
+   |   true_region;
+   | else
+   |   false_region;
+*/
+
+void
+set_ifsese_condition (ifsese if_region, tree condition)
+{
+  sese region = if_region->region;
+  edge entry = region->entry;
+  basic_block bb = entry->dest;
+  gimple last = last_stmt (bb);
+  gimple_stmt_iterator gsi = gsi_last_bb (bb);
+  gimple cond_stmt;
+
+  gcc_assert (gimple_code (last) == GIMPLE_COND);
+
+  gsi_remove (&gsi, true);
+  gsi = gsi_last_bb (bb);
+  condition = force_gimple_operand_gsi (&gsi, condition, true, NULL,
+                                       false, GSI_NEW_STMT);
+  cond_stmt = gimple_build_cond_from_tree (condition, NULL_TREE, NULL_TREE);
+  gsi = gsi_last_bb (bb);
+  gsi_insert_after (&gsi, cond_stmt, GSI_NEW_STMT);
+}
+
 /* Returns the scalar evolution of T in REGION.  Every variable that
    is not defined in the REGION is considered a parameter.  */
 
index 350ae48..a54854a 100644 (file)
@@ -229,6 +229,7 @@ extern ifsese create_if_region_on_edge (edge, tree);
 extern ifsese move_sese_in_condition (sese);
 extern edge get_true_edge_from_guard_bb (basic_block);
 extern edge get_false_edge_from_guard_bb (basic_block);
+extern void set_ifsese_condition (ifsese, tree);
 
 static inline edge
 if_region_entry (ifsese if_region)
diff --git a/gcc/testsuite/g++.dg/graphite/pr42681.C b/gcc/testsuite/g++.dg/graphite/pr42681.C
new file mode 100644 (file)
index 0000000..4593e1b
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-options "-O1 -fgraphite-identity -fno-loop-block -fno-loop-interchange -fno-loop-strip-mine" } */
+
+typedef long unsigned int size_t;
+inline void* operator new(size_t, void* __p) throw() { return __p; }
+
+struct A {
+  int i, j;
+  A() : i(0) {}
+};
+
+void Init(A *a)
+{
+  for (int i = 0; i < 20; i++) {
+    new (&a[i]) A;
+    a[i].j = 0;
+  }
+}