public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/loop-unswitch-support-switches] Apply reviewer's comments.
@ 2022-01-06 16:30 Martin Liska
  0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2022-01-06 16:30 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:401de0fee5dfd386079caed7e8fb61e9afced477

commit 401de0fee5dfd386079caed7e8fb61e9afced477
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jan 6 17:30:08 2022 +0100

    Apply reviewer's comments.

Diff:
---
 gcc/doc/invoke.texi          |   3 -
 gcc/params.opt               |   4 --
 gcc/tree-ssa-loop-unswitch.c | 143 ++++++++++++++++++++-----------------------
 3 files changed, 66 insertions(+), 84 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 04820656ffa..98589738d62 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -13890,9 +13890,6 @@ The maximum depth of a loop nest suitable for complete peeling.
 @item max-unswitch-insns
 The maximum number of insns of an unswitched loop.
 
-@item max-unswitch-level
-The maximum number of branches unswitched in a single loop.
-
 @item lim-expensive
 The minimum cost of an expensive expression in the loop invariant motion.
 
diff --git a/gcc/params.opt b/gcc/params.opt
index 665071fbed1..91f845aaae6 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -741,10 +741,6 @@ The maximum number of instructions to consider to unroll in a loop.
 Common Joined UInteger Var(param_max_unswitch_insns) Init(50) Param Optimization
 The maximum number of insns of an unswitched loop.
 
--param=max-unswitch-level=
-Common Joined UInteger Var(param_max_unswitch_level) Init(3) Param Optimization
-The maximum number of unswitchings in a single loop.
-
 -param=max-variable-expansions-in-unroller=
 Common Joined UInteger Var(param_max_variable_expansions) Init(1) Param Optimization
 If -fvariable-expansion-in-unroller is used, the maximum number of times that an individual variable will be expanded during loop unrolling.
diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c
index b21eed5ca51..c164fe2faa0 100644
--- a/gcc/tree-ssa-loop-unswitch.c
+++ b/gcc/tree-ssa-loop-unswitch.c
@@ -448,29 +448,29 @@ find_unswitching_predicates_for_bb (basic_block bb, class loop *loop,
 		  tree lab = gimple_switch_label (stmt, i);
 		  basic_block dest = label_to_block (cfun, CASE_LABEL (lab));
 		  edge e2 = find_edge (gimple_bb (stmt), dest);
-		  if (e == e2)
+		  if (e != e2)
+		    continue;
+
+		  tree cmp;
+		  if (CASE_HIGH (lab) != NULL_TREE)
 		    {
-		      tree cmp;
-		      if (CASE_HIGH (lab) != NULL_TREE)
-			{
-			  tree cmp1 = build2 (GE_EXPR, boolean_type_node, idx,
-					      CASE_LOW (lab));
-			  tree cmp2 = build2 (LE_EXPR, boolean_type_node, idx,
-					      CASE_HIGH (lab));
-			  cmp = build2 (BIT_AND_EXPR, boolean_type_node, cmp1,
-					cmp2);
-			}
-		      else
-			cmp = build2 (EQ_EXPR, boolean_type_node, idx,
-				      CASE_LOW (lab));
-
-		      /* Combine the expression with the existing one.  */
-		      if (expr == NULL_TREE)
-			expr = cmp;
-		      else
-			expr = build2 (BIT_IOR_EXPR, boolean_type_node, expr,
-				       cmp);
+		      tree cmp1 = build2 (GE_EXPR, boolean_type_node, idx,
+					  CASE_LOW (lab));
+		      tree cmp2 = build2 (LE_EXPR, boolean_type_node, idx,
+					  CASE_HIGH (lab));
+		      cmp = fold_build2 (BIT_AND_EXPR, boolean_type_node, cmp1,
+					 cmp2);
 		    }
+		  else
+		    cmp = fold_build2 (EQ_EXPR, boolean_type_node, idx,
+				  CASE_LOW (lab));
+
+		  /* Combine the expression with the existing one.  */
+		  if (expr == NULL_TREE)
+		    expr = cmp;
+		  else
+		    expr = fold_build2 (BIT_IOR_EXPR, boolean_type_node, expr,
+					cmp);
 		}
 
 	      if (expr != NULL_TREE)
@@ -661,52 +661,52 @@ simplify_loop_version (class loop *loop, predicate_vector &predicate_path,
   for (unsigned i = 0; i != loop->num_nodes; i++)
     {
       vec<unswitch_predicate *> &predicates = get_predicates_for_bb (bbs[i]);
-      if (!predicates.is_empty ())
+      if (predicates.is_empty ())
+	continue;
+
+      hash_set<edge> ignored_edges;
+      gimple *stmt = last_stmt (bbs[i]);
+      tree folded = evaluate_control_stmt_using_entry_checks (stmt,
+							      predicate_path,
+							      ignored_edge_flag,
+							      &ignored_edges);
+
+      gcond *cond = dyn_cast<gcond *> (stmt);
+      gswitch *swtch = dyn_cast<gswitch *> (stmt);
+
+      if (cond != NULL
+	  && folded != NULL_TREE)
 	{
-	  hash_set<edge> ignored_edges;
-	  gimple *stmt = last_stmt (bbs[i]);
-	  tree folded = evaluate_control_stmt_using_entry_checks (stmt,
-								  predicate_path,
-								  ignored_edge_flag,
-								  &ignored_edges);
-
-	  gcond *cond = dyn_cast<gcond *> (stmt);
-	  gswitch *swtch = dyn_cast<gswitch *> (stmt);
-
-	  if (cond != NULL
-	      && folded != NULL_TREE)
-	    {
-	      /* Remove path.  */
-	      if (integer_nonzerop (folded))
-		gimple_cond_set_condition_from_tree (cond, boolean_true_node);
-	      else
-		gimple_cond_set_condition_from_tree (cond, boolean_false_node);
+	  /* Remove path.  */
+	  if (integer_nonzerop (folded))
+	    gimple_cond_set_condition_from_tree (cond, boolean_true_node);
+	  else
+	    gimple_cond_set_condition_from_tree (cond, boolean_false_node);
 
-	      gimple_set_uid (cond, 0);
-	      update_stmt (cond);
-	      changed = true;
-	    }
-	  else if (swtch != NULL)
-	    {
-	      edge e;
-	      edge_iterator ei;
-	      FOR_EACH_EDGE (e, ei, bbs[i]->succs)
-		if (ignored_edges.contains (e))
-		  e->flags = ignored_edge_flag;
+	  gimple_set_uid (cond, 0);
+	  update_stmt (cond);
+	  changed = true;
+	}
+      else if (swtch != NULL)
+	{
+	  edge e;
+	  edge_iterator ei;
+	  FOR_EACH_EDGE (e, ei, bbs[i]->succs)
+	    if (ignored_edges.contains (e))
+	      e->flags = ignored_edge_flag;
 
-	      for (unsigned j = 0; j < predicates.length (); j++)
-		{
-		  edge e = EDGE_SUCC (bbs[i], predicates[j]->edge_index);
-		  if (ignored_edges.contains (e))
-		    predicates[j]->handled = true;
-		}
+	  for (unsigned j = 0; j < predicates.length (); j++)
+	    {
+	      edge e = EDGE_SUCC (bbs[i], predicates[j]->edge_index);
+	      if (ignored_edges.contains (e))
+		predicates[j]->handled = true;
+	    }
 
-	      if (folded)
-		{
-		  gimple_switch_set_index (swtch, folded);
-		  update_stmt (swtch);
-		  changed = true;
-		}
+	  if (folded)
+	    {
+	      gimple_switch_set_index (swtch, folded);
+	      update_stmt (swtch);
+	      changed = true;
 	    }
 	}
     }
@@ -861,13 +861,6 @@ tree_unswitch_single_loop (class loop *loop, int num,
 
   unswitch_predicate *predicate = NULL;
   basic_block bb = NULL;
-  if (num > param_max_unswitch_level)
-    {
-      if (dump_enabled_p ())
-	dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc,
-			 "Not unswitching anymore, hit max level\n");
-      goto exit;
-    }
 
   bbs = get_loop_body (loop);
 
@@ -1473,6 +1466,8 @@ static void
 clean_up_after_unswitching (const auto_edge_flag &ignored_edge_flag)
 {
   basic_block bb;
+  edge e;
+  edge_iterator ei;
 
   FOR_EACH_BB_FN (bb, cfun)
     {
@@ -1500,14 +1495,8 @@ clean_up_after_unswitching (const auto_edge_flag &ignored_edge_flag)
 	  if (index != nlabels)
 	    gimple_switch_set_num_labels (stmt, index);
 	}
-    }
-
-  /* Clean up the ignored_edge_flag from edges.  */
-  FOR_EACH_BB_FN (bb, cfun)
-    {
-      edge e;
-      edge_iterator ei;
 
+      /* Clean up the ignored_edge_flag from edges.  */
       FOR_EACH_EDGE (e, ei, bb->succs)
 	e->flags &= ~ignored_edge_flag;
     }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-06 16:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06 16:30 [gcc/devel/loop-unswitch-support-switches] Apply reviewer's comments Martin Liska

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).