public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PHIOPT: small refactoring of match_simplify_replacement.
@ 2023-04-30 21:13 Andrew Pinski
  2023-05-02 12:21 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Pinski @ 2023-04-30 21:13 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

When I added diamond shaped form bb to match_simplify_replacement,
I copied the code to move the statement rather than factoring it
out to a new function. This does the refactoring to a new function
to avoid the duplicated code. It will make adding support for having
two statements to move easier (the second statement will only be a
conversion).

OK? Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-phiopt.cc (move_stmt): New function.
	(match_simplify_replacement): Use move_stmt instead
	of the inlined version.
---
 gcc/tree-ssa-phiopt.cc | 57 ++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 33 deletions(-)

diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 024a4362093..65b3deea34a 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -643,6 +643,28 @@ empty_bb_or_one_feeding_into_p (basic_block bb,
   return true;
 }
 
+/* Move STMT to before GSI and insert its defining
+   name into INSERTED_EXPRS bitmap. */
+static void
+move_stmt (gimple *stmt, gimple_stmt_iterator *gsi, auto_bitmap &inserted_exprs)
+{
+  if (!stmt)
+    return;
+  if (dump_file && (dump_flags & TDF_DETAILS))
+    {
+      fprintf (dump_file, "statement un-sinked:\n");
+      print_gimple_stmt (dump_file, stmt, 0,
+			 TDF_VOPS|TDF_MEMSYMS);
+    }
+
+  tree name = gimple_get_lhs (stmt);
+  // Mark the name to be renamed if there is one.
+  bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (name));
+  gimple_stmt_iterator gsi1 = gsi_for_stmt (stmt);
+  gsi_move_before (&gsi1, gsi);
+  reset_flow_sensitive_info (name);
+}
+
 /*  The function match_simplify_replacement does the main work of doing the
     replacement using match and simplify.  Return true if the replacement is done.
     Otherwise return false.
@@ -727,39 +749,8 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb,
 
   /* If there was a statement to move, move it to right before
      the original conditional.  */
-  if (stmt_to_move)
-    {
-      if (dump_file && (dump_flags & TDF_DETAILS))
-	{
-	  fprintf (dump_file, "statement un-sinked:\n");
-	  print_gimple_stmt (dump_file, stmt_to_move, 0,
-			   TDF_VOPS|TDF_MEMSYMS);
-	}
-
-      tree name = gimple_get_lhs (stmt_to_move);
-      // Mark the name to be renamed if there is one.
-      bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (name));
-      gimple_stmt_iterator gsi1 = gsi_for_stmt (stmt_to_move);
-      gsi_move_before (&gsi1, &gsi);
-      reset_flow_sensitive_info (name);
-    }
-
-  if (stmt_to_move_alt)
-    {
-      if (dump_file && (dump_flags & TDF_DETAILS))
-	{
-	  fprintf (dump_file, "statement un-sinked:\n");
-	  print_gimple_stmt (dump_file, stmt_to_move_alt, 0,
-			   TDF_VOPS|TDF_MEMSYMS);
-	}
-
-      tree name = gimple_get_lhs (stmt_to_move_alt);
-      // Mark the name to be renamed if there is one.
-      bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (name));
-      gimple_stmt_iterator gsi1 = gsi_for_stmt (stmt_to_move_alt);
-      gsi_move_before (&gsi1, &gsi);
-      reset_flow_sensitive_info (name);
-    }
+  move_stmt (stmt_to_move, &gsi, inserted_exprs);
+  move_stmt (stmt_to_move_alt, &gsi, inserted_exprs);
 
   replace_phi_edge_with_variable (cond_bb, e1, phi, result, inserted_exprs);
 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] PHIOPT: small refactoring of match_simplify_replacement.
  2023-04-30 21:13 [PATCH] PHIOPT: small refactoring of match_simplify_replacement Andrew Pinski
@ 2023-05-02 12:21 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-05-02 12:21 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches

On Sun, Apr 30, 2023 at 11:14 PM Andrew Pinski via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> When I added diamond shaped form bb to match_simplify_replacement,
> I copied the code to move the statement rather than factoring it
> out to a new function. This does the refactoring to a new function
> to avoid the duplicated code. It will make adding support for having
> two statements to move easier (the second statement will only be a
> conversion).
>
> OK? Bootstrapped and tested on x86_64-linux-gnu.

OK.

> gcc/ChangeLog:
>
>         * tree-ssa-phiopt.cc (move_stmt): New function.
>         (match_simplify_replacement): Use move_stmt instead
>         of the inlined version.
> ---
>  gcc/tree-ssa-phiopt.cc | 57 ++++++++++++++++++------------------------
>  1 file changed, 24 insertions(+), 33 deletions(-)
>
> diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
> index 024a4362093..65b3deea34a 100644
> --- a/gcc/tree-ssa-phiopt.cc
> +++ b/gcc/tree-ssa-phiopt.cc
> @@ -643,6 +643,28 @@ empty_bb_or_one_feeding_into_p (basic_block bb,
>    return true;
>  }
>
> +/* Move STMT to before GSI and insert its defining
> +   name into INSERTED_EXPRS bitmap. */
> +static void
> +move_stmt (gimple *stmt, gimple_stmt_iterator *gsi, auto_bitmap &inserted_exprs)
> +{
> +  if (!stmt)
> +    return;
> +  if (dump_file && (dump_flags & TDF_DETAILS))
> +    {
> +      fprintf (dump_file, "statement un-sinked:\n");
> +      print_gimple_stmt (dump_file, stmt, 0,
> +                        TDF_VOPS|TDF_MEMSYMS);
> +    }
> +
> +  tree name = gimple_get_lhs (stmt);
> +  // Mark the name to be renamed if there is one.
> +  bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (name));
> +  gimple_stmt_iterator gsi1 = gsi_for_stmt (stmt);
> +  gsi_move_before (&gsi1, gsi);
> +  reset_flow_sensitive_info (name);
> +}
> +
>  /*  The function match_simplify_replacement does the main work of doing the
>      replacement using match and simplify.  Return true if the replacement is done.
>      Otherwise return false.
> @@ -727,39 +749,8 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb,
>
>    /* If there was a statement to move, move it to right before
>       the original conditional.  */
> -  if (stmt_to_move)
> -    {
> -      if (dump_file && (dump_flags & TDF_DETAILS))
> -       {
> -         fprintf (dump_file, "statement un-sinked:\n");
> -         print_gimple_stmt (dump_file, stmt_to_move, 0,
> -                          TDF_VOPS|TDF_MEMSYMS);
> -       }
> -
> -      tree name = gimple_get_lhs (stmt_to_move);
> -      // Mark the name to be renamed if there is one.
> -      bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (name));
> -      gimple_stmt_iterator gsi1 = gsi_for_stmt (stmt_to_move);
> -      gsi_move_before (&gsi1, &gsi);
> -      reset_flow_sensitive_info (name);
> -    }
> -
> -  if (stmt_to_move_alt)
> -    {
> -      if (dump_file && (dump_flags & TDF_DETAILS))
> -       {
> -         fprintf (dump_file, "statement un-sinked:\n");
> -         print_gimple_stmt (dump_file, stmt_to_move_alt, 0,
> -                          TDF_VOPS|TDF_MEMSYMS);
> -       }
> -
> -      tree name = gimple_get_lhs (stmt_to_move_alt);
> -      // Mark the name to be renamed if there is one.
> -      bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (name));
> -      gimple_stmt_iterator gsi1 = gsi_for_stmt (stmt_to_move_alt);
> -      gsi_move_before (&gsi1, &gsi);
> -      reset_flow_sensitive_info (name);
> -    }
> +  move_stmt (stmt_to_move, &gsi, inserted_exprs);
> +  move_stmt (stmt_to_move_alt, &gsi, inserted_exprs);
>
>    replace_phi_edge_with_variable (cond_bb, e1, phi, result, inserted_exprs);
>
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-02 12:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-30 21:13 [PATCH] PHIOPT: small refactoring of match_simplify_replacement Andrew Pinski
2023-05-02 12:21 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).