re PR tree-optimization/80520 (Performance regression from missing if-conversion)
authorJeff Law <law@redhat.com>
Tue, 11 Dec 2018 04:56:54 +0000 (21:56 -0700)
committerJeff Law <law@gcc.gnu.org>
Tue, 11 Dec 2018 04:56:54 +0000 (21:56 -0700)
PR tree-optimization/80520
* gimple-ssa-split-paths.c (is_feasible_trace): Recognize half
diamonds that are likely if convertable.

* gcc.dg/tree-ssa/split-path-5.c: Update expected output.
* gcc.dg/tree-ssa/split-path-11.c: New test.

From-SVN: r266971

gcc/ChangeLog
gcc/gimple-ssa-split-paths.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/split-path-11.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/split-path-5.c

index 14c52ad64bec43ef731ec281d3aef4bf522bb70b..eddcdc3f84399132e988472d62c40f4e2b5f0c72 100644 (file)
@@ -1,3 +1,9 @@
+2018-12-10  Jeff Law  <law@redhat.com>
+
+       PR tree-optimization/80520
+       * gimple-ssa-split-paths.c (is_feasible_trace): Recognize half
+       diamonds that are likely if convertable.
+
 2018-12-10  Martin Sebor  <msebor@redhat.com>
 
        PR tree-optimization/86196
index a8515119ce58d3ff29c1a4e1bf5f003a53751b5a..915965260459e045af73ed36900f979def3fc27a 100644 (file)
@@ -203,6 +203,98 @@ is_feasible_trace (basic_block bb)
        }
     }
 
+  /* Canonicalize the form.  */
+  if (num_stmts_in_pred1 == 0 && num_stmts_in_pred2 == 1)
+    {
+      std::swap (pred1, pred2);
+      std::swap (num_stmts_in_pred1, num_stmts_in_pred2);
+    }
+
+  /* Another variant.  This one is half-diamond.  */
+  if (num_stmts_in_pred1 == 1 && num_stmts_in_pred2 == 0
+      && dominated_by_p (CDI_DOMINATORS, pred1, pred2))
+    {
+      gimple *stmt1 = last_and_only_stmt (pred1);
+
+      /* The only statement in PRED1 must be an assignment that is
+        not a good candidate for if-conversion.   This may need some
+        generalization.  */
+      if (stmt1 && gimple_code (stmt1) == GIMPLE_ASSIGN)
+       {
+         enum tree_code code1 = gimple_assign_rhs_code (stmt1);
+
+         if (!poor_ifcvt_candidate_code (code1))
+           {
+             tree lhs1 = gimple_assign_lhs (stmt1);
+             tree rhs1 = gimple_assign_rhs1 (stmt1);
+
+             gimple_stmt_iterator gsi;
+             for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+               {
+                 gimple *phi = gsi_stmt (gsi);
+                 if ((gimple_phi_arg_def (phi, 0) == lhs1
+                      && gimple_phi_arg_def (phi, 1) == rhs1)
+                     || (gimple_phi_arg_def (phi, 1) == lhs1
+                         && gimple_phi_arg_def (phi, 0) == rhs1))
+                   {
+                     if (dump_file && (dump_flags & TDF_DETAILS))
+                       fprintf (dump_file,
+                                "Block %d appears to be a join point for "
+                                "if-convertable half-diamond.\n",
+                                bb->index);
+                     return false;
+                   }
+               }
+           }
+       }
+    }
+
+  /* Canonicalize the form.  */
+  if (num_stmts_in_pred1 == 0 && num_stmts_in_pred2 == 1)
+    {
+      std::swap (pred1, pred2);
+      std::swap (num_stmts_in_pred1, num_stmts_in_pred2);
+    }
+
+  /* Another variant.  This one is half-diamond.  */
+  if (num_stmts_in_pred1 == 1 && num_stmts_in_pred2 == 0
+      && dominated_by_p (CDI_DOMINATORS, pred1, pred2))
+    {
+      gimple *stmt1 = last_and_only_stmt (pred1);
+
+      /* The only statement in PRED1 must be an assignment that is
+        not a good candidate for if-conversion.   This may need some
+        generalization.  */
+      if (stmt1 && gimple_code (stmt1) == GIMPLE_ASSIGN)
+       {
+         enum tree_code code1 = gimple_assign_rhs_code (stmt1);
+
+         if (!poor_ifcvt_candidate_code (code1))
+           {
+             tree lhs1 = gimple_assign_lhs (stmt1);
+             tree rhs1 = gimple_assign_rhs1 (stmt1);
+
+             gimple_stmt_iterator gsi;
+             for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+               {
+                 gimple *phi = gsi_stmt (gsi);
+                 if ((gimple_phi_arg_def (phi, 0) == lhs1
+                      && gimple_phi_arg_def (phi, 1) == rhs1)
+                     || (gimple_phi_arg_def (phi, 1) == lhs1
+                         && gimple_phi_arg_def (phi, 0) == rhs1))
+                   {
+                     if (dump_file && (dump_flags & TDF_DETAILS))
+                       fprintf (dump_file,
+                                "Block %d appears to be a join point for "
+                                "if-convertable half-diamond.\n",
+                                bb->index);
+                     return false;
+                   }
+               }
+           }
+       }
+    }
+
   /* If the joiner has no PHIs with useful uses there is zero chance
      of CSE/DCE/jump-threading possibilities exposed by duplicating it.  */
   bool found_useful_phi = false;
index 43675b9adb04679f9ff3c44d8d27758be8fe09d0..0fde3cb395a5cacf4bc54a1c19d846be83e80fa5 100644 (file)
@@ -1,3 +1,9 @@
+2018-12-10  Jeff Law  <law@redhat.com>
+
+       PR tree-optimization/80520
+       * gcc.dg/tree-ssa/split-path-5.c: Update expected output.
+       * gcc.dg/tree-ssa/split-path-11.c: New test.
+
 2018-12-10  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/97922
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/split-path-11.c b/gcc/testsuite/gcc.dg/tree-ssa/split-path-11.c
new file mode 100644 (file)
index 0000000..f94f1a8
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fsplit-paths -fdump-tree-split-paths-details -w" } */
+
+void foo(unsigned long *M)
+{
+  for (unsigned long k = 0; k < 227; ++k)
+    {
+      unsigned long y =
+       ((M[k] & 0xffffffff80000000) | (M[k + 1] & 0x7fffffff));
+      M[k] = (M[k + 397] ^ (y >> 1) ^ ((y & 1) ? 2567483615 : 0));
+    }
+}
+
+/* { dg-final { scan-tree-dump-times "join point for if-convertable half-diamond" 1 "split-paths" } } */
index 95aabdaf6be645c012457d1d04c732ce0ba11cda..83141a716edb5c914c3e8026da002cb20645cf7a 100644 (file)
@@ -41,4 +41,4 @@ bmhi_init (const char *pattern)
     }
 }
 
-/* { dg-final { scan-tree-dump-times "Duplicating join block" 1 "split-paths" } } */
+/* { dg-final { scan-tree-dump-times "join point for if-convertable half-diamond" 1 "split-paths" } } */