public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] tree-optimization/105142 - improve maybe_fold_comparisons_from_match_pd fix
       [not found] <20220726111853.F03813857805@sourceware.org>
@ 2022-11-11 14:04 ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2022-11-11 14:04 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Tue, Jul 26, 2022 at 1:18 PM Richard Biener via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> The following improves on the fix for PR105142 which restricted the
> expression lookup used for maybe_fold_comparisons_from_match_pd to
> avoid picking up flow-sensitive info for use in places where guarding
> conditions do not hold.  Instead of not allowing to expand SSA
> definitions there the following temporarily clears flow-sensitive
> info on the SSA names and restores it when finished matching.
>
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Better late then never - I have now pushed this after re-bootstrapping
and testing this on x86_64-unknown-linux-gnu.

Richard.

>         PR tree-optimization/105142
>         * gimple-fold.cc (fosa_unwind): New global.
>         (follow_outer_ssa_edges): When the SSA definition to follow
>         is does not dominate fosa_bb, temporarily clear flow-sensitive
>         info.
>         (maybe_fold_comparisons_from_match_pd): Set up unwind stack
>         for follow_outer_ssa_edges and unwind flow-sensitive info
>         clearing after matching.
> ---
>  gcc/gimple-fold.cc | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
> index a1704784bc9..876ef45434e 100644
> --- a/gcc/gimple-fold.cc
> +++ b/gcc/gimple-fold.cc
> @@ -6886,6 +6886,7 @@ and_comparisons_1 (tree type, enum tree_code code1, tree op1a, tree op1b,
>  }
>
>  static basic_block fosa_bb;
> +static vec<std::pair<tree, void *> > *fosa_unwind;
>  static tree
>  follow_outer_ssa_edges (tree val)
>  {
> @@ -6899,7 +6900,15 @@ follow_outer_ssa_edges (tree val)
>               && (def_bb == fosa_bb
>                   || dominated_by_p (CDI_DOMINATORS, fosa_bb, def_bb))))
>         return val;
> -      return NULL_TREE;
> +      /* If the definition does not dominate fosa_bb temporarily reset
> +        flow-sensitive info.  */
> +      if (val->ssa_name.info.range_info)
> +       {
> +         fosa_unwind->safe_push (std::make_pair
> +                                   (val, val->ssa_name.info.range_info));
> +         val->ssa_name.info.range_info = NULL;
> +       }
> +      return val;
>      }
>    return val;
>  }
> @@ -6958,9 +6967,14 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code,
>                       type, gimple_assign_lhs (stmt1),
>                       gimple_assign_lhs (stmt2));
>    fosa_bb = outer_cond_bb;
> +  auto_vec<std::pair<tree, void *>, 8> unwind_stack;
> +  fosa_unwind = &unwind_stack;
>    if (op.resimplify (NULL, (!outer_cond_bb
>                             ? follow_all_ssa_edges : follow_outer_ssa_edges)))
>      {
> +      fosa_unwind = NULL;
> +      for (auto p : unwind_stack)
> +       p.first->ssa_name.info.range_info = p.second;
>        if (gimple_simplified_result_is_gimple_val (&op))
>         {
>           tree res = op.ops[0];
> @@ -6982,6 +6996,9 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code,
>           return build2 ((enum tree_code)op.code, op.type, op0, op1);
>         }
>      }
> +  fosa_unwind = NULL;
> +  for (auto p : unwind_stack)
> +    p.first->ssa_name.info.range_info = p.second;
>
>    return NULL_TREE;
>  }
> --
> 2.35.3

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

* [PATCH] tree-optimization/105142 - improve maybe_fold_comparisons_from_match_pd fix
@ 2022-07-26 11:18 Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2022-07-26 11:18 UTC (permalink / raw)
  To: gcc-patches

The following improves on the fix for PR105142 which restricted the
expression lookup used for maybe_fold_comparisons_from_match_pd to
avoid picking up flow-sensitive info for use in places where guarding
conditions do not hold.  Instead of not allowing to expand SSA
definitions there the following temporarily clears flow-sensitive
info on the SSA names and restores it when finished matching.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

	PR tree-optimization/105142
	* gimple-fold.cc (fosa_unwind): New global.
	(follow_outer_ssa_edges): When the SSA definition to follow
	is does not dominate fosa_bb, temporarily clear flow-sensitive
	info.
	(maybe_fold_comparisons_from_match_pd): Set up unwind stack
	for follow_outer_ssa_edges and unwind flow-sensitive info
	clearing after matching.
---
 gcc/gimple-fold.cc | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index a1704784bc9..876ef45434e 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -6886,6 +6886,7 @@ and_comparisons_1 (tree type, enum tree_code code1, tree op1a, tree op1b,
 }
 
 static basic_block fosa_bb;
+static vec<std::pair<tree, void *> > *fosa_unwind;
 static tree
 follow_outer_ssa_edges (tree val)
 {
@@ -6899,7 +6900,15 @@ follow_outer_ssa_edges (tree val)
 	      && (def_bb == fosa_bb
 		  || dominated_by_p (CDI_DOMINATORS, fosa_bb, def_bb))))
 	return val;
-      return NULL_TREE;
+      /* If the definition does not dominate fosa_bb temporarily reset
+	 flow-sensitive info.  */
+      if (val->ssa_name.info.range_info)
+	{
+	  fosa_unwind->safe_push (std::make_pair
+				    (val, val->ssa_name.info.range_info));
+	  val->ssa_name.info.range_info = NULL;
+	}
+      return val;
     }
   return val;
 }
@@ -6958,9 +6967,14 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code,
 		      type, gimple_assign_lhs (stmt1),
 		      gimple_assign_lhs (stmt2));
   fosa_bb = outer_cond_bb;
+  auto_vec<std::pair<tree, void *>, 8> unwind_stack;
+  fosa_unwind = &unwind_stack;
   if (op.resimplify (NULL, (!outer_cond_bb
 			    ? follow_all_ssa_edges : follow_outer_ssa_edges)))
     {
+      fosa_unwind = NULL;
+      for (auto p : unwind_stack)
+	p.first->ssa_name.info.range_info = p.second;
       if (gimple_simplified_result_is_gimple_val (&op))
 	{
 	  tree res = op.ops[0];
@@ -6982,6 +6996,9 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code,
 	  return build2 ((enum tree_code)op.code, op.type, op0, op1);
 	}
     }
+  fosa_unwind = NULL;
+  for (auto p : unwind_stack)
+    p.first->ssa_name.info.range_info = p.second;
 
   return NULL_TREE;
 }
-- 
2.35.3

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

* [PATCH] tree-optimization/105142 - improve maybe_fold_comparisons_from_match_pd fix
@ 2022-07-26 11:18 Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2022-07-26 11:18 UTC (permalink / raw)
  To: gcc-patches

The following improves on the fix for PR105142 which restricted the
expression lookup used for maybe_fold_comparisons_from_match_pd to
avoid picking up flow-sensitive info for use in places where guarding
conditions do not hold.  Instead of not allowing to expand SSA
definitions there the following temporarily clears flow-sensitive
info on the SSA names and restores it when finished matching.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

	PR tree-optimization/105142
	* gimple-fold.cc (fosa_unwind): New global.
	(follow_outer_ssa_edges): When the SSA definition to follow
	is does not dominate fosa_bb, temporarily clear flow-sensitive
	info.
	(maybe_fold_comparisons_from_match_pd): Set up unwind stack
	for follow_outer_ssa_edges and unwind flow-sensitive info
	clearing after matching.
---
 gcc/gimple-fold.cc | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index a1704784bc9..876ef45434e 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -6886,6 +6886,7 @@ and_comparisons_1 (tree type, enum tree_code code1, tree op1a, tree op1b,
 }
 
 static basic_block fosa_bb;
+static vec<std::pair<tree, void *> > *fosa_unwind;
 static tree
 follow_outer_ssa_edges (tree val)
 {
@@ -6899,7 +6900,15 @@ follow_outer_ssa_edges (tree val)
 	      && (def_bb == fosa_bb
 		  || dominated_by_p (CDI_DOMINATORS, fosa_bb, def_bb))))
 	return val;
-      return NULL_TREE;
+      /* If the definition does not dominate fosa_bb temporarily reset
+	 flow-sensitive info.  */
+      if (val->ssa_name.info.range_info)
+	{
+	  fosa_unwind->safe_push (std::make_pair
+				    (val, val->ssa_name.info.range_info));
+	  val->ssa_name.info.range_info = NULL;
+	}
+      return val;
     }
   return val;
 }
@@ -6958,9 +6967,14 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code,
 		      type, gimple_assign_lhs (stmt1),
 		      gimple_assign_lhs (stmt2));
   fosa_bb = outer_cond_bb;
+  auto_vec<std::pair<tree, void *>, 8> unwind_stack;
+  fosa_unwind = &unwind_stack;
   if (op.resimplify (NULL, (!outer_cond_bb
 			    ? follow_all_ssa_edges : follow_outer_ssa_edges)))
     {
+      fosa_unwind = NULL;
+      for (auto p : unwind_stack)
+	p.first->ssa_name.info.range_info = p.second;
       if (gimple_simplified_result_is_gimple_val (&op))
 	{
 	  tree res = op.ops[0];
@@ -6982,6 +6996,9 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code,
 	  return build2 ((enum tree_code)op.code, op.type, op0, op1);
 	}
     }
+  fosa_unwind = NULL;
+  for (auto p : unwind_stack)
+    p.first->ssa_name.info.range_info = p.second;
 
   return NULL_TREE;
 }
-- 
2.35.3

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

* [PATCH] tree-optimization/105142 - improve maybe_fold_comparisons_from_match_pd fix
@ 2022-07-26 11:18 Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2022-07-26 11:18 UTC (permalink / raw)
  To: gcc-patches

The following improves on the fix for PR105142 which restricted the
expression lookup used for maybe_fold_comparisons_from_match_pd to
avoid picking up flow-sensitive info for use in places where guarding
conditions do not hold.  Instead of not allowing to expand SSA
definitions there the following temporarily clears flow-sensitive
info on the SSA names and restores it when finished matching.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

	PR tree-optimization/105142
	* gimple-fold.cc (fosa_unwind): New global.
	(follow_outer_ssa_edges): When the SSA definition to follow
	is does not dominate fosa_bb, temporarily clear flow-sensitive
	info.
	(maybe_fold_comparisons_from_match_pd): Set up unwind stack
	for follow_outer_ssa_edges and unwind flow-sensitive info
	clearing after matching.
---
 gcc/gimple-fold.cc | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index a1704784bc9..876ef45434e 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -6886,6 +6886,7 @@ and_comparisons_1 (tree type, enum tree_code code1, tree op1a, tree op1b,
 }
 
 static basic_block fosa_bb;
+static vec<std::pair<tree, void *> > *fosa_unwind;
 static tree
 follow_outer_ssa_edges (tree val)
 {
@@ -6899,7 +6900,15 @@ follow_outer_ssa_edges (tree val)
 	      && (def_bb == fosa_bb
 		  || dominated_by_p (CDI_DOMINATORS, fosa_bb, def_bb))))
 	return val;
-      return NULL_TREE;
+      /* If the definition does not dominate fosa_bb temporarily reset
+	 flow-sensitive info.  */
+      if (val->ssa_name.info.range_info)
+	{
+	  fosa_unwind->safe_push (std::make_pair
+				    (val, val->ssa_name.info.range_info));
+	  val->ssa_name.info.range_info = NULL;
+	}
+      return val;
     }
   return val;
 }
@@ -6958,9 +6967,14 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code,
 		      type, gimple_assign_lhs (stmt1),
 		      gimple_assign_lhs (stmt2));
   fosa_bb = outer_cond_bb;
+  auto_vec<std::pair<tree, void *>, 8> unwind_stack;
+  fosa_unwind = &unwind_stack;
   if (op.resimplify (NULL, (!outer_cond_bb
 			    ? follow_all_ssa_edges : follow_outer_ssa_edges)))
     {
+      fosa_unwind = NULL;
+      for (auto p : unwind_stack)
+	p.first->ssa_name.info.range_info = p.second;
       if (gimple_simplified_result_is_gimple_val (&op))
 	{
 	  tree res = op.ops[0];
@@ -6982,6 +6996,9 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code,
 	  return build2 ((enum tree_code)op.code, op.type, op0, op1);
 	}
     }
+  fosa_unwind = NULL;
+  for (auto p : unwind_stack)
+    p.first->ssa_name.info.range_info = p.second;
 
   return NULL_TREE;
 }
-- 
2.35.3

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

end of thread, other threads:[~2022-11-11 14:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20220726111853.F03813857805@sourceware.org>
2022-11-11 14:04 ` [PATCH] tree-optimization/105142 - improve maybe_fold_comparisons_from_match_pd fix Richard Biener
2022-07-26 11:18 Richard Biener
  -- strict thread matches above, loose matches on Subject: below --
2022-07-26 11:18 Richard Biener
2022-07-26 11:18 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).