]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/87473 (ICE in create_add_on_incoming_edge, at gimpl...
authorBill Schmidt <wschmidt@linux.ibm.com>
Fri, 26 Oct 2018 19:38:45 +0000 (19:38 +0000)
committerWilliam Schmidt <wschmidt@gcc.gnu.org>
Fri, 26 Oct 2018 19:38:45 +0000 (19:38 +0000)
[gcc]

2018-10-26  Bill Schmidt  <wschmidt@linux.ibm.com>

Backport from mainline
2018-10-19  Bill Schmidt  <wschmidt@linux.ibm.com>

PR tree-optimization/87473
* gimple-ssa-strength-reduction.c (record_phi_increments): For
phi arguments identical to the base expression of the phi
candidate, record a phi-adjust increment of zero minus the index
expression of the hidden basis.
(phi_incr_cost): For phi arguments identical to the base
expression of the phi candidate, the difference to compare against
the increment is zero minus the index expression of the hidden
basis, and there is no potential savings from replacing the (phi)
statement.
(ncd_with_phi): For phi arguments identical to the base expression
of the phi candidate, the difference to compare against the
increment is zero minus the index expression of the hidden basis.
(all_phi_incrs_profitable): For phi arguments identical to the
base expression of the phi candidate, the increment to be checked
for profitability is zero minus the index expression of the hidden
basis.

[gcc/testsuite]

2018-10-26  Bill Schmidt  <wschmidt@linux.ibm.com>

Backport from mainline
2018-10-19  Bill Schmidt  <wschmidt@linux.ibm.com>

PR tree-optimization/87473
* gcc.c-torture/compile/pr87473.c: New file.

From-SVN: r265547

gcc/ChangeLog
gcc/gimple-ssa-strength-reduction.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr87473.c [new file with mode: 0644]

index 941159efb598e96664e0879082ce2db7a3cd0fd0..fbfe44a35e8f8fa31f60aced35b5f98706d2fa39 100644 (file)
@@ -1,3 +1,26 @@
+2018-10-26  Bill Schmidt  <wschmidt@linux.ibm.com>
+
+       Backport from mainline
+       2018-10-19  Bill Schmidt  <wschmidt@linux.ibm.com>
+
+       PR tree-optimization/87473
+       * gimple-ssa-strength-reduction.c (record_phi_increments): For
+       phi arguments identical to the base expression of the phi
+       candidate, record a phi-adjust increment of zero minus the index
+       expression of the hidden basis.
+       (phi_incr_cost): For phi arguments identical to the base
+       expression of the phi candidate, the difference to compare against
+       the increment is zero minus the index expression of the hidden
+       basis, and there is no potential savings from replacing the (phi)
+       statement.
+       (ncd_with_phi): For phi arguments identical to the base expression
+       of the phi candidate, the difference to compare against the
+       increment is zero minus the index expression of the hidden basis.
+       (all_phi_incrs_profitable): For phi arguments identical to the
+       base expression of the phi candidate, the increment to be checked
+       for profitability is zero minus the index expression of the hidden
+       basis.
+
 2018-10-19  Andreas Krebbel  <krebbel@linux.ibm.com>
 
        Backport from mainline
index 3e19c4b603eb8f823e3d3a6dd3ccbd8cd9d10283..ed089200e5b9e01f8b140bdd166037f12c952bff 100644 (file)
@@ -2666,17 +2666,23 @@ record_phi_increments (slsr_cand_t basis, gimple *phi)
   for (i = 0; i < gimple_phi_num_args (phi); i++)
     {
       tree arg = gimple_phi_arg_def (phi, i);
+      gimple *arg_def = SSA_NAME_DEF_STMT (arg);
 
-      if (!operand_equal_p (arg, phi_cand->base_expr, 0))
+      if (gimple_code (arg_def) == GIMPLE_PHI)
+       record_phi_increments (basis, arg_def);
+      else
        {
-         gimple *arg_def = SSA_NAME_DEF_STMT (arg);
+         widest_int diff;
 
-         if (gimple_code (arg_def) == GIMPLE_PHI)
-           record_phi_increments (basis, arg_def);
+         if (operand_equal_p (arg, phi_cand->base_expr, 0))
+           {
+             diff = -basis->index;
+             record_increment (phi_cand, diff, PHI_ADJUST);
+           }
          else
            {
              slsr_cand_t arg_cand = base_cand_from_table (arg);
-             widest_int diff = arg_cand->index - basis->index;
+             diff = arg_cand->index - basis->index;
              record_increment (arg_cand, diff, PHI_ADJUST);
            }
        }
@@ -2738,28 +2744,42 @@ phi_incr_cost (slsr_cand_t c, const widest_int &incr, gimple *phi,
   for (i = 0; i < gimple_phi_num_args (phi); i++)
     {
       tree arg = gimple_phi_arg_def (phi, i);
+      gimple *arg_def = SSA_NAME_DEF_STMT (arg);
 
-      if (!operand_equal_p (arg, phi_cand->base_expr, 0))
+      if (gimple_code (arg_def) == GIMPLE_PHI)
        {
-         gimple *arg_def = SSA_NAME_DEF_STMT (arg);
-      
-         if (gimple_code (arg_def) == GIMPLE_PHI)
+         int feeding_savings = 0;
+         cost += phi_incr_cost (c, incr, arg_def, &feeding_savings);
+         if (has_single_use (gimple_phi_result (arg_def)))
+           *savings += feeding_savings;
+       }
+      else
+       {
+         widest_int diff;
+         slsr_cand_t arg_cand;
+
+         /* When the PHI argument is just a pass-through to the base
+            expression of the hidden basis, the difference is zero minus
+            the index of the basis.  There is no potential savings by
+            eliminating a statement in this case.  */
+         if (operand_equal_p (arg, phi_cand->base_expr, 0))
            {
-             int feeding_savings = 0;
-             cost += phi_incr_cost (c, incr, arg_def, &feeding_savings);
-             if (has_single_use (gimple_phi_result (arg_def)))
-               *savings += feeding_savings;
+             arg_cand = (slsr_cand_t) NULL;
+             diff = -basis->index;
            }
          else
            {
-             slsr_cand_t arg_cand = base_cand_from_table (arg);
-             widest_int diff = arg_cand->index - basis->index;
-
-             if (incr == diff)
+             arg_cand = base_cand_from_table (arg);
+             diff = arg_cand->index - basis->index;
+           }
+         
+         if (incr == diff)
+           {
+             tree basis_lhs = gimple_assign_lhs (basis->cand_stmt);
+             cost += add_cost (true, TYPE_MODE (TREE_TYPE (basis_lhs)));
+             if (arg_cand)
                {
-                 tree basis_lhs = gimple_assign_lhs (basis->cand_stmt);
                  tree lhs = gimple_assign_lhs (arg_cand->cand_stmt);
-                 cost += add_cost (true, TYPE_MODE (TREE_TYPE (basis_lhs)));
                  if (has_single_use (lhs))
                    *savings += stmt_cost (arg_cand->cand_stmt, true);
                }
@@ -3076,23 +3096,26 @@ ncd_with_phi (slsr_cand_t c, const widest_int &incr, gphi *phi,
   for (i = 0; i < gimple_phi_num_args (phi); i++)
     {
       tree arg = gimple_phi_arg_def (phi, i);
+      gimple *arg_def = SSA_NAME_DEF_STMT (arg);
 
-      if (!operand_equal_p (arg, phi_cand->base_expr, 0))
+      if (gimple_code (arg_def) == GIMPLE_PHI)
+       ncd = ncd_with_phi (c, incr, as_a <gphi *> (arg_def), ncd, where);
+      else 
        {
-         gimple *arg_def = SSA_NAME_DEF_STMT (arg);
+         widest_int diff;
 
-         if (gimple_code (arg_def) == GIMPLE_PHI)
-           ncd = ncd_with_phi (c, incr, as_a <gphi *> (arg_def), ncd,
-                               where);
-         else 
+         if (operand_equal_p (arg, phi_cand->base_expr, 0))
+           diff = -basis->index;
+         else
            {
              slsr_cand_t arg_cand = base_cand_from_table (arg);
-             widest_int diff = arg_cand->index - basis->index;
-             basic_block pred = gimple_phi_arg_edge (phi, i)->src;
-
-             if ((incr == diff) || (!address_arithmetic_p && incr == -diff))
-               ncd = ncd_for_two_cands (ncd, pred, *where, NULL, where);
+             diff = arg_cand->index - basis->index;
            }
+         
+         basic_block pred = gimple_phi_arg_edge (phi, i)->src;
+         
+         if ((incr == diff) || (!address_arithmetic_p && incr == -diff))
+           ncd = ncd_for_two_cands (ncd, pred, *where, NULL, where);
        }
     }
 
@@ -3358,49 +3381,52 @@ all_phi_incrs_profitable (slsr_cand_t c, gphi *phi)
        return false;
 
       tree arg = gimple_phi_arg_def (phi, i);
+      gimple *arg_def = SSA_NAME_DEF_STMT (arg);
 
-      if (!operand_equal_p (arg, phi_cand->base_expr, 0))
+      if (gimple_code (arg_def) == GIMPLE_PHI)
        {
-         gimple *arg_def = SSA_NAME_DEF_STMT (arg);
+         if (!all_phi_incrs_profitable (c, as_a <gphi *> (arg_def)))
+           return false;
+       }
+      else
+       {
+         int j;
+         widest_int increment;
 
-         if (gimple_code (arg_def) == GIMPLE_PHI)
-           {
-             if (!all_phi_incrs_profitable (c, as_a <gphi *> (arg_def)))
-               return false;
-           }
+         if (operand_equal_p (arg, phi_cand->base_expr, 0))
+           increment = -basis->index;
          else
            {
-             int j;
              slsr_cand_t arg_cand = base_cand_from_table (arg);
-             widest_int increment = arg_cand->index - basis->index;
+             increment = arg_cand->index - basis->index;
+           }
 
-             if (!address_arithmetic_p && wi::neg_p (increment))
-               increment = -increment;
+         if (!address_arithmetic_p && wi::neg_p (increment))
+           increment = -increment;
 
-             j = incr_vec_index (increment);
+         j = incr_vec_index (increment);
 
-             if (dump_file && (dump_flags & TDF_DETAILS))
-               {
-                 fprintf (dump_file, "  Conditional candidate %d, phi: ",
-                          c->cand_num);
-                 print_gimple_stmt (dump_file, phi, 0, 0);
-                 fputs ("    increment: ", dump_file);
-                 print_decs (increment, dump_file);
-                 if (j < 0)
-                   fprintf (dump_file,
-                            "\n  Not replaced; incr_vec overflow.\n");
-                 else {
-                   fprintf (dump_file, "\n    cost: %d\n", incr_vec[j].cost);
-                   if (profitable_increment_p (j))
-                     fputs ("  Replacing...\n", dump_file);
-                   else
-                     fputs ("  Not replaced.\n", dump_file);
-                 }
-               }
-
-             if (j < 0 || !profitable_increment_p (j))
-               return false;
+         if (dump_file && (dump_flags & TDF_DETAILS))
+           {
+             fprintf (dump_file, "  Conditional candidate %d, phi: ",
+                      c->cand_num);
+             print_gimple_stmt (dump_file, phi, 0, 0);
+             fputs ("    increment: ", dump_file);
+             print_decs (increment, dump_file);
+             if (j < 0)
+               fprintf (dump_file,
+                        "\n  Not replaced; incr_vec overflow.\n");
+             else {
+               fprintf (dump_file, "\n    cost: %d\n", incr_vec[j].cost);
+               if (profitable_increment_p (j))
+                 fputs ("  Replacing...\n", dump_file);
+               else
+                 fputs ("  Not replaced.\n", dump_file);
+             }
            }
+
+         if (j < 0 || !profitable_increment_p (j))
+           return false;
        }
     }
 
index f4d6475be6bc37174bdcca9d388de39273225664..3fbf580f6641d5c1872792727558fb0b4b4dc6ca 100644 (file)
@@ -1,3 +1,11 @@
+2018-10-26  Bill Schmidt  <wschmidt@linux.ibm.com>
+
+       Backport from mainline
+       2018-10-19  Bill Schmidt  <wschmidt@linux.ibm.com>
+
+       PR tree-optimization/87473
+       * gcc.c-torture/compile/pr87473.c: New file.
+
 2018-10-23  Tom de Vries  <tdevries@suse.de>
 
        backport from trunk:
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr87473.c b/gcc/testsuite/gcc.c-torture/compile/pr87473.c
new file mode 100644 (file)
index 0000000..0ca5e30
--- /dev/null
@@ -0,0 +1,19 @@
+/* PR87473: SLSR ICE on hidden basis with |increment| > 1.  */
+/* { dg-additional-options "-fno-tree-ch" } */
+
+void
+t6 (int qz, int wh)
+{
+  int jl = wh;
+
+  while (1.0 / 0 < 1)
+    {
+      qz = wh * (wh + 2);
+
+      while (wh < 1)
+        jl = 0;
+    }
+
+  while (qz < 1)
+    qz = jl * wh;
+}