public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/if-to-switch-v4)] Fix various issues.
@ 2020-10-09 12:41 Martin Liska
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Liska @ 2020-10-09 12:41 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:68769492b1e7999920ed2bd693ca9621da6b1eb0

commit 68769492b1e7999920ed2bd693ca9621da6b1eb0
Author: Martin Liska <mliska@suse.cz>
Date:   Fri Oct 2 15:30:03 2020 +0200

    Fix various issues.

Diff:
---
 gcc/common.opt             |  4 ----
 gcc/doc/invoke.texi        |  9 ---------
 gcc/gimple-if-to-switch.cc | 29 ++++++++++++++++-------------
 gcc/opts.c                 |  1 -
 4 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index c42f1adfffd..aa3d75c2357 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1173,10 +1173,6 @@ fconserve-stack
 Common Var(flag_conserve_stack) Optimization
 Do not perform optimizations increasing noticeably stack usage.
 
-fconvert-if-to-switch
-Common Report Var(flag_convert_if_to_switch) Optimization
-Perform conversions of if-elseif chain into a switch statement.
-
 fcprop-registers
 Common Report Var(flag_cprop_registers) Optimization
 Perform a register copy-propagation optimization pass.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index a15c4aec6f5..e5145bae08b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2654,14 +2654,6 @@ Allow conditional expressions with mismatched types in the second and
 third arguments.  The value of such an expression is void.  This option
 is not supported for C++.
 
-@item -fconvert-if-to-switch
-@opindex fconvert-if-to-switch
-Perform conversion of an if cascade into a switch statement.
-Do so if the switch can be later transformed using a jump table
-or a bit test.  The transformation can help to produce faster code for
-the switch statement.  This flag is enabled by default
-at @option{-O2} and higher.
-
 @item -flax-vector-conversions
 @opindex flax-vector-conversions
 Allow implicit conversions between vectors with differing numbers of
@@ -9765,7 +9757,6 @@ also turns on the following optimization flags:
 -falign-labels  -falign-loops @gol
 -fcaller-saves @gol
 -fcode-hoisting @gol
--fconvert-if-to-switch @gol
 -fcrossjumping @gol
 -fcse-follow-jumps  -fcse-skip-blocks @gol
 -fdelete-null-pointer-checks @gol
diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc
index d67099cd614..75388e54ce5 100644
--- a/gcc/gimple-if-to-switch.cc
+++ b/gcc/gimple-if-to-switch.cc
@@ -288,7 +288,7 @@ if_chain::record_phi_arguments (edge e)
 	  tree *v = m_phi_map.get (phi);
 	  if (v != NULL)
 	    {
-	      if (arg != *v)
+	      if (!operand_equal_p (arg, *v))
 		return false;
 	    }
 	  else
@@ -494,7 +494,7 @@ extract_case_from_stmt (tree rhs1, tree rhs2, tree_code code,
 
 static void
 find_switch_in_bb (basic_block bb, auto_vec<if_chain *> *all_candidates,
-		   auto_bitmap *visited_bbs)
+		   auto_sbitmap *visited_bbs)
 {
   if_chain *chain = new if_chain ();
   unsigned total_case_values = 0;
@@ -668,15 +668,13 @@ find_switch_in_bb (basic_block bb, auto_vec<if_chain *> *all_candidates,
       && chain->check_non_overlapping_cases ()
       && chain->is_beneficial ())
     {
-    expanded_location loc
-    = expand_location (gimple_location (chain->m_first_condition));
-      if (dump_file)
-	{
-	  fprintf (dump_file, "Condition chain (at %s:%d) with %d conditions "
-		   "(%d BBs) transformed into a switch statement.\n",
-		   loc.file, loc.line, total_case_values,
-		   chain->m_entries.length ());
-	}
+      location_t loc = gimple_location (chain->m_first_condition);
+      if (dump_enabled_p ())
+	dump_printf_loc (MSG_OPTIMIZED_LOCATIONS,
+			 dump_user_location_t::from_location_t (loc),
+			 "Condition chain with %d conditions "
+			 "(%d BBs) transformed into a switch statement.\n",
+			 total_case_values, chain->m_entries.length ());
 
       all_candidates->safe_push (chain);
     }
@@ -713,7 +711,12 @@ public:
   {}
 
   /* opt_pass methods: */
-  virtual bool gate (function *) { return flag_convert_if_to_switch != 0; }
+  virtual bool gate (function *)
+  {
+    return (jump_table_cluster::is_enabled ()
+	    || bit_test_cluster::is_enabled ());
+  }
+
   virtual unsigned int execute (function *);
 
 }; // class pass_if_to_switch
@@ -725,7 +728,7 @@ pass_if_to_switch::execute (function *fun)
 
   auto_vec<if_chain *> all_candidates;
   auto_vec<basic_block> worklist;
-  auto_bitmap visited_bbs;
+  auto_sbitmap visited_bbs (last_basic_block_for_fn (fun));
 
   worklist.safe_push (ENTRY_BLOCK_PTR_FOR_FN (fun));
   while (!worklist.is_empty ())
diff --git a/gcc/opts.c b/gcc/opts.c
index 63a50b28fce..da503c32dd0 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -510,7 +510,6 @@ static const struct default_options default_options_table[] =
     { OPT_LEVELS_2_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_CHEAP },
     { OPT_LEVELS_2_PLUS, OPT_finline_functions, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fconvert_if_to_switch, NULL, 1 },
 
     /* -O2 and above optimizations, but not -Os or -Og.  */
     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_functions, NULL, 1 },


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

* [gcc(refs/users/marxin/heads/if-to-switch-v4)] Fix various issues.
@ 2020-10-13 13:41 Martin Liska
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Liska @ 2020-10-13 13:41 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ff35e1afaed3227a8d82c3f4077d98c328db0957

commit ff35e1afaed3227a8d82c3f4077d98c328db0957
Author: Martin Liska <mliska@suse.cz>
Date:   Tue Oct 13 15:41:18 2020 +0200

    Fix various issues.

Diff:
---
 gcc/gimple-if-to-switch.cc | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc
index ba78a2c7233..8f61ba80c10 100644
--- a/gcc/gimple-if-to-switch.cc
+++ b/gcc/gimple-if-to-switch.cc
@@ -89,7 +89,7 @@ condition_info::record_phi_mapping (edge e, mapping_vec *vec)
       gphi *phi = gsi.phi ();
       if (!virtual_operand_p (gimple_phi_result (phi)))
 	{
-	  tree arg = PHI_ARG_DEF_FROM_EDGE (phi, m_true_edge);
+	  tree arg = PHI_ARG_DEF_FROM_EDGE (phi, e);
 	  vec->safe_push (std::make_pair (phi, arg));
 	}
     }
@@ -408,8 +408,15 @@ find_conditions (basic_block bb,
       info.m_true_edge = in_p ? true_edge : false_edge;
       info.m_false_edge = in_p ? false_edge : true_edge;
 
+      for (unsigned i = 0; i < info.m_ranges.length (); ++i)
+	if (info.m_ranges[i].exp == NULL_TREE
+	    || info.m_ranges[i].low == NULL_TREE
+	    || info.m_ranges[i].high == NULL_TREE)
+	  return;
+
       for (unsigned i = 1; i < info.m_ranges.length (); ++i)
-	if (info.m_ranges[i].exp != expr || info.m_ranges[i].in_p != in_p)
+	if (info.m_ranges[i].exp != expr
+	    || info.m_ranges[i].in_p != in_p)
 	  return;
 
       info.record_phi_mapping (info.m_true_edge, &info.m_true_edge_phi_mapping);
@@ -495,6 +502,7 @@ pass_if_to_switch::execute (function *fun)
 
 	  chain->m_entries.reverse ();
 	  if (chain->m_entries.length () >= 3
+	      && chain->check_non_overlapping_cases ()
 	      && chain->is_beneficial ())
 	    {
 	      expanded_location loc


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

* [gcc(refs/users/marxin/heads/if-to-switch-v4)] Fix various issues.
@ 2020-10-12 13:05 Martin Liska
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Liska @ 2020-10-12 13:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:85fb4e1dfa50b209a4da1a958f38cdd84c59ba27

commit 85fb4e1dfa50b209a4da1a958f38cdd84c59ba27
Author: Martin Liska <mliska@suse.cz>
Date:   Fri Oct 2 15:30:03 2020 +0200

    Fix various issues.

Diff:
---
 gcc/common.opt             |  4 ----
 gcc/doc/invoke.texi        |  9 ---------
 gcc/gimple-if-to-switch.cc | 29 ++++++++++++++++-------------
 gcc/opts.c                 |  1 -
 4 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index c42f1adfffd..aa3d75c2357 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1173,10 +1173,6 @@ fconserve-stack
 Common Var(flag_conserve_stack) Optimization
 Do not perform optimizations increasing noticeably stack usage.
 
-fconvert-if-to-switch
-Common Report Var(flag_convert_if_to_switch) Optimization
-Perform conversions of if-elseif chain into a switch statement.
-
 fcprop-registers
 Common Report Var(flag_cprop_registers) Optimization
 Perform a register copy-propagation optimization pass.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index a15c4aec6f5..e5145bae08b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2654,14 +2654,6 @@ Allow conditional expressions with mismatched types in the second and
 third arguments.  The value of such an expression is void.  This option
 is not supported for C++.
 
-@item -fconvert-if-to-switch
-@opindex fconvert-if-to-switch
-Perform conversion of an if cascade into a switch statement.
-Do so if the switch can be later transformed using a jump table
-or a bit test.  The transformation can help to produce faster code for
-the switch statement.  This flag is enabled by default
-at @option{-O2} and higher.
-
 @item -flax-vector-conversions
 @opindex flax-vector-conversions
 Allow implicit conversions between vectors with differing numbers of
@@ -9765,7 +9757,6 @@ also turns on the following optimization flags:
 -falign-labels  -falign-loops @gol
 -fcaller-saves @gol
 -fcode-hoisting @gol
--fconvert-if-to-switch @gol
 -fcrossjumping @gol
 -fcse-follow-jumps  -fcse-skip-blocks @gol
 -fdelete-null-pointer-checks @gol
diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc
index d67099cd614..75388e54ce5 100644
--- a/gcc/gimple-if-to-switch.cc
+++ b/gcc/gimple-if-to-switch.cc
@@ -288,7 +288,7 @@ if_chain::record_phi_arguments (edge e)
 	  tree *v = m_phi_map.get (phi);
 	  if (v != NULL)
 	    {
-	      if (arg != *v)
+	      if (!operand_equal_p (arg, *v))
 		return false;
 	    }
 	  else
@@ -494,7 +494,7 @@ extract_case_from_stmt (tree rhs1, tree rhs2, tree_code code,
 
 static void
 find_switch_in_bb (basic_block bb, auto_vec<if_chain *> *all_candidates,
-		   auto_bitmap *visited_bbs)
+		   auto_sbitmap *visited_bbs)
 {
   if_chain *chain = new if_chain ();
   unsigned total_case_values = 0;
@@ -668,15 +668,13 @@ find_switch_in_bb (basic_block bb, auto_vec<if_chain *> *all_candidates,
       && chain->check_non_overlapping_cases ()
       && chain->is_beneficial ())
     {
-    expanded_location loc
-    = expand_location (gimple_location (chain->m_first_condition));
-      if (dump_file)
-	{
-	  fprintf (dump_file, "Condition chain (at %s:%d) with %d conditions "
-		   "(%d BBs) transformed into a switch statement.\n",
-		   loc.file, loc.line, total_case_values,
-		   chain->m_entries.length ());
-	}
+      location_t loc = gimple_location (chain->m_first_condition);
+      if (dump_enabled_p ())
+	dump_printf_loc (MSG_OPTIMIZED_LOCATIONS,
+			 dump_user_location_t::from_location_t (loc),
+			 "Condition chain with %d conditions "
+			 "(%d BBs) transformed into a switch statement.\n",
+			 total_case_values, chain->m_entries.length ());
 
       all_candidates->safe_push (chain);
     }
@@ -713,7 +711,12 @@ public:
   {}
 
   /* opt_pass methods: */
-  virtual bool gate (function *) { return flag_convert_if_to_switch != 0; }
+  virtual bool gate (function *)
+  {
+    return (jump_table_cluster::is_enabled ()
+	    || bit_test_cluster::is_enabled ());
+  }
+
   virtual unsigned int execute (function *);
 
 }; // class pass_if_to_switch
@@ -725,7 +728,7 @@ pass_if_to_switch::execute (function *fun)
 
   auto_vec<if_chain *> all_candidates;
   auto_vec<basic_block> worklist;
-  auto_bitmap visited_bbs;
+  auto_sbitmap visited_bbs (last_basic_block_for_fn (fun));
 
   worklist.safe_push (ENTRY_BLOCK_PTR_FOR_FN (fun));
   while (!worklist.is_empty ())
diff --git a/gcc/opts.c b/gcc/opts.c
index 63a50b28fce..da503c32dd0 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -510,7 +510,6 @@ static const struct default_options default_options_table[] =
     { OPT_LEVELS_2_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_CHEAP },
     { OPT_LEVELS_2_PLUS, OPT_finline_functions, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fconvert_if_to_switch, NULL, 1 },
 
     /* -O2 and above optimizations, but not -Os or -Og.  */
     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_functions, NULL, 1 },


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

* [gcc(refs/users/marxin/heads/if-to-switch-v4)] Fix various issues.
@ 2020-10-06 13:49 Martin Liska
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Liska @ 2020-10-06 13:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3652bc0ebb14108321ea898d96baad6a12863176

commit 3652bc0ebb14108321ea898d96baad6a12863176
Author: Martin Liska <mliska@suse.cz>
Date:   Fri Oct 2 15:30:03 2020 +0200

    Fix various issues.

Diff:
---
 gcc/common.opt             |  4 ----
 gcc/doc/invoke.texi        |  9 ---------
 gcc/gimple-if-to-switch.cc | 29 ++++++++++++++++-------------
 gcc/opts.c                 |  1 -
 4 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 337a30cdac9..3169d71cea5 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1173,10 +1173,6 @@ fconserve-stack
 Common Var(flag_conserve_stack) Optimization
 Do not perform optimizations increasing noticeably stack usage.
 
-fconvert-if-to-switch
-Common Report Var(flag_convert_if_to_switch) Optimization
-Perform conversions of if-elseif chain into a switch statement.
-
 fcprop-registers
 Common Report Var(flag_cprop_registers) Optimization
 Perform a register copy-propagation optimization pass.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index d1536d8f533..25bddad361f 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2654,14 +2654,6 @@ Allow conditional expressions with mismatched types in the second and
 third arguments.  The value of such an expression is void.  This option
 is not supported for C++.
 
-@item -fconvert-if-to-switch
-@opindex fconvert-if-to-switch
-Perform conversion of an if cascade into a switch statement.
-Do so if the switch can be later transformed using a jump table
-or a bit test.  The transformation can help to produce faster code for
-the switch statement.  This flag is enabled by default
-at @option{-O2} and higher.
-
 @item -flax-vector-conversions
 @opindex flax-vector-conversions
 Allow implicit conversions between vectors with differing numbers of
@@ -9764,7 +9756,6 @@ also turns on the following optimization flags:
 -falign-labels  -falign-loops @gol
 -fcaller-saves @gol
 -fcode-hoisting @gol
--fconvert-if-to-switch @gol
 -fcrossjumping @gol
 -fcse-follow-jumps  -fcse-skip-blocks @gol
 -fdelete-null-pointer-checks @gol
diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc
index d67099cd614..75388e54ce5 100644
--- a/gcc/gimple-if-to-switch.cc
+++ b/gcc/gimple-if-to-switch.cc
@@ -288,7 +288,7 @@ if_chain::record_phi_arguments (edge e)
 	  tree *v = m_phi_map.get (phi);
 	  if (v != NULL)
 	    {
-	      if (arg != *v)
+	      if (!operand_equal_p (arg, *v))
 		return false;
 	    }
 	  else
@@ -494,7 +494,7 @@ extract_case_from_stmt (tree rhs1, tree rhs2, tree_code code,
 
 static void
 find_switch_in_bb (basic_block bb, auto_vec<if_chain *> *all_candidates,
-		   auto_bitmap *visited_bbs)
+		   auto_sbitmap *visited_bbs)
 {
   if_chain *chain = new if_chain ();
   unsigned total_case_values = 0;
@@ -668,15 +668,13 @@ find_switch_in_bb (basic_block bb, auto_vec<if_chain *> *all_candidates,
       && chain->check_non_overlapping_cases ()
       && chain->is_beneficial ())
     {
-    expanded_location loc
-    = expand_location (gimple_location (chain->m_first_condition));
-      if (dump_file)
-	{
-	  fprintf (dump_file, "Condition chain (at %s:%d) with %d conditions "
-		   "(%d BBs) transformed into a switch statement.\n",
-		   loc.file, loc.line, total_case_values,
-		   chain->m_entries.length ());
-	}
+      location_t loc = gimple_location (chain->m_first_condition);
+      if (dump_enabled_p ())
+	dump_printf_loc (MSG_OPTIMIZED_LOCATIONS,
+			 dump_user_location_t::from_location_t (loc),
+			 "Condition chain with %d conditions "
+			 "(%d BBs) transformed into a switch statement.\n",
+			 total_case_values, chain->m_entries.length ());
 
       all_candidates->safe_push (chain);
     }
@@ -713,7 +711,12 @@ public:
   {}
 
   /* opt_pass methods: */
-  virtual bool gate (function *) { return flag_convert_if_to_switch != 0; }
+  virtual bool gate (function *)
+  {
+    return (jump_table_cluster::is_enabled ()
+	    || bit_test_cluster::is_enabled ());
+  }
+
   virtual unsigned int execute (function *);
 
 }; // class pass_if_to_switch
@@ -725,7 +728,7 @@ pass_if_to_switch::execute (function *fun)
 
   auto_vec<if_chain *> all_candidates;
   auto_vec<basic_block> worklist;
-  auto_bitmap visited_bbs;
+  auto_sbitmap visited_bbs (last_basic_block_for_fn (fun));
 
   worklist.safe_push (ENTRY_BLOCK_PTR_FOR_FN (fun));
   while (!worklist.is_empty ())
diff --git a/gcc/opts.c b/gcc/opts.c
index 03baf758283..3bda59afced 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -510,7 +510,6 @@ static const struct default_options default_options_table[] =
     { OPT_LEVELS_2_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_CHEAP },
     { OPT_LEVELS_2_PLUS, OPT_finline_functions, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fconvert_if_to_switch, NULL, 1 },
 
     /* -O2 and above optimizations, but not -Os or -Og.  */
     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_functions, NULL, 1 },


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

end of thread, other threads:[~2020-10-13 13:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-09 12:41 [gcc(refs/users/marxin/heads/if-to-switch-v4)] Fix various issues Martin Liska
  -- strict thread matches above, loose matches on Subject: below --
2020-10-13 13:41 Martin Liska
2020-10-12 13:05 Martin Liska
2020-10-06 13:49 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).