OSDN Git Service

2013-02-05 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 5 Feb 2013 12:56:51 +0000 (12:56 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 5 Feb 2013 12:56:51 +0000 (12:56 +0000)
Backport from mainline
2012-12-10  Richard Biener  <rguenther@suse.de>

PR tree-optimization/55107
* tree-ssa-pre.c (struct pre_stats): Remove constified field.
(bitmap_set_replace_value): Add gcc_unreachable.
(do_regular_insertion): Re-write all_same handling.  Insert
an assignment instead of a PHI in this case.
(execute_pre): Do not record constified events.

* gcc.dg/torture/pr55107.c: New testcase.
* gcc.dg/tree-ssa/ssa-pre-5.c: Adjust.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@195755 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr55107.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-5.c
gcc/tree-ssa-pre.c

index 820808a..8e31396 100644 (file)
@@ -1,5 +1,17 @@
 2013-02-05  Richard Biener  <rguenther@suse.de>
 
+       Backport from mainline
+       2012-12-10  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/55107
+       * tree-ssa-pre.c (struct pre_stats): Remove constified field.
+       (bitmap_set_replace_value): Add gcc_unreachable.
+       (do_regular_insertion): Re-write all_same handling.  Insert
+       an assignment instead of a PHI in this case.
+       (execute_pre): Do not record constified events.
+
+2013-02-05  Richard Biener  <rguenther@suse.de>
+
        PR tree-optimization/54767
        * tree-vrp.c (vrp_visit_phi_node): For PHI arguments coming via
        backedges drop all symbolical range information.
index c486bac..c0072f9 100644 (file)
@@ -1,3 +1,12 @@
+2013-02-05  Richard Biener  <rguenther@suse.de>
+
+       Backport from mainline
+       2012-12-10  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/55107
+       * gcc.dg/torture/pr55107.c: New testcase.
+       * gcc.dg/tree-ssa/ssa-pre-5.c: Adjust.
+
 2013-02-15  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/54767
diff --git a/gcc/testsuite/gcc.dg/torture/pr55107.c b/gcc/testsuite/gcc.dg/torture/pr55107.c
new file mode 100644 (file)
index 0000000..2402716
--- /dev/null
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+
+typedef unsigned short uint16_t;
+
+uint16_t a, b;
+
+uint16_t f(void)
+{
+  int c, **p;
+  short d = 2, e = 4;
+
+  for (;; b++)
+    {
+      int *j, k = 0;
+
+      for (; *j; j++)
+       {
+         for(; c; c++)
+           for(; k < 1; k++)
+             {
+               short *f = &d;
+
+               if(b)
+                 return *f;
+             }
+       }
+
+      if(!c)
+       d *= e;
+
+      ((a = d) ? b = 0 : (**p ? : 1) != (d != 1 ? : (a = 0))) != (k ? a : 0)
+         < (a *= c = k) && (**p = 0);
+    }
+}
index 8756944..d0e985f 100644 (file)
@@ -12,5 +12,6 @@ foo (int i)
 }
 /* We should detect that a+b is the same along both edges, and replace it with
    5  */
-/* { dg-final { scan-tree-dump-times "Constified: 1" 1 "pre"} } */
+/* { dg-final { scan-tree-dump-times "Eliminated: 1" 1 "pre"} } */
+/* { dg-final { scan-tree-dump-times "Insertions" 0 "pre"} } */
 /* { dg-final { cleanup-tree-dump "pre" } } */
index 341023d..a999668 100644 (file)
@@ -448,10 +448,6 @@ static struct
 
   /* The number of new PHI nodes added by PRE.  */
   int phis;
-
-  /* The number of values found constant.  */
-  int constified;
-
 } pre_stats;
 
 static bool do_partial_partial;
@@ -862,6 +858,8 @@ bitmap_set_replace_value (bitmap_set_t set, unsigned int lookfor,
          return;
        }
     }
+
+  gcc_unreachable ();
 }
 
 /* Return true if two bitmap sets are equal.  */
@@ -3511,7 +3509,8 @@ do_regular_insertion (basic_block block, basic_block dom)
 
   FOR_EACH_VEC_ELT (pre_expr, exprs, i, expr)
     {
-      if (expr->kind != NAME)
+      if (expr->kind == NARY
+         || expr->kind == REFERENCE)
        {
          pre_expr *avail;
          unsigned int val;
@@ -3612,36 +3611,36 @@ do_regular_insertion (basic_block block, basic_block dom)
          /* If all edges produce the same value and that value is
             an invariant, then the PHI has the same value on all
             edges.  Note this.  */
-         else if (!cant_insert && all_same && eprime
-                  && (edoubleprime->kind == CONSTANT
-                      || edoubleprime->kind == NAME)
-                  && !value_id_constant_p (val))
+         else if (!cant_insert && all_same)
            {
-             unsigned int j;
-             bitmap_iterator bi;
-             bitmap_set_t exprset = VEC_index (bitmap_set_t,
-                                               value_expressions, val);
+             tree exprtype = get_expr_type (expr);
+             tree temp;
+             gimple assign;
+             pre_expr newe;
+             gimple_stmt_iterator gsi;
 
-             unsigned int new_val = get_expr_value_id (edoubleprime);
-             FOR_EACH_EXPR_ID_IN_SET (exprset, j, bi)
-               {
-                 pre_expr expr = expression_for_id (j);
+             gcc_assert (edoubleprime->kind == CONSTANT
+                         || edoubleprime->kind == NAME);
 
-                 if (expr->kind == NAME)
-                   {
-                     vn_ssa_aux_t info = VN_INFO (PRE_EXPR_NAME (expr));
-                     /* Just reset the value id and valnum so it is
-                        the same as the constant we have discovered.  */
-                     if (edoubleprime->kind == CONSTANT)
-                       {
-                         info->valnum = PRE_EXPR_CONSTANT (edoubleprime);
-                         pre_stats.constified++;
-                       }
-                     else
-                       info->valnum = VN_INFO (PRE_EXPR_NAME (edoubleprime))->valnum;
-                     info->value_id = new_val;
-                   }
+             if (!pretemp || TREE_TYPE (pretemp) != exprtype)
+               {
+                 pretemp = create_tmp_reg (exprtype, "pretmp");
+                 add_referenced_var (pretemp);
                }
+             temp = make_ssa_name (pretemp, NULL);
+             assign = gimple_build_assign (temp,
+                                           edoubleprime->kind == CONSTANT ? PRE_EXPR_CONSTANT (edoubleprime) : PRE_EXPR_NAME (edoubleprime));
+             gsi = gsi_after_labels (block);
+             gsi_insert_before (&gsi, assign, GSI_NEW_STMT);
+
+             gimple_set_plf (assign, NECESSARY, false);
+             VN_INFO_GET (temp)->value_id = val;
+             VN_INFO (temp)->valnum = temp;
+             bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (temp));
+             newe = get_or_alloc_expr_for_name (temp);
+             add_to_value (val, newe);
+             bitmap_value_replace_in_set (AVAIL_OUT (block), newe);
+             bitmap_insert_into_set (NEW_SETS (block), newe);
            }
          free (avail);
        }
@@ -3669,7 +3668,8 @@ do_partial_partial_insertion (basic_block block, basic_block dom)
 
   FOR_EACH_VEC_ELT (pre_expr, exprs, i, expr)
     {
-      if (expr->kind != NAME)
+      if (expr->kind == NARY
+         || expr->kind == REFERENCE)
        {
          pre_expr *avail;
          unsigned int val;
@@ -4926,7 +4926,6 @@ execute_pre (bool do_fre)
   statistics_counter_event (cfun, "PA inserted", pre_stats.pa_insert);
   statistics_counter_event (cfun, "New PHIs", pre_stats.phis);
   statistics_counter_event (cfun, "Eliminated", pre_stats.eliminations);
-  statistics_counter_event (cfun, "Constified", pre_stats.constified);
 
   clear_expression_ids ();
   if (!do_fre)