]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/gimple-if-to-switch.cc
Update copyright years.
[thirdparty/gcc.git] / gcc / gimple-if-to-switch.cc
index f39662be3e698f96a11f1e59e1bfee212c959640..8b3a499ac2120bf963c0d058d00c858745ccd910 100644 (file)
@@ -1,5 +1,5 @@
 /* If-elseif-else to switch conversion pass
-   Copyright (C) 2020-2021 Free Software Foundation, Inc.
+   Copyright (C) 2020-2024 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -61,9 +61,11 @@ struct condition_info
 {
   typedef auto_vec<std::pair<gphi *, tree>> mapping_vec;
 
-  condition_info (gcond *cond): m_cond (cond), m_bb (gimple_bb (cond)),
-    m_forwarder_bb (NULL), m_ranges (), m_true_edge (NULL), m_false_edge (NULL),
-    m_true_edge_phi_mapping (), m_false_edge_phi_mapping ()
+  condition_info (gcond *cond, bool has_side_effect): m_cond (cond),
+    m_bb (gimple_bb (cond)), m_forwarder_bb (NULL), m_ranges (),
+    m_true_edge (NULL), m_false_edge (NULL),
+    m_true_edge_phi_mapping (), m_false_edge_phi_mapping (),
+    m_has_side_effect (has_side_effect)
   {
     m_ranges.create (0);
   }
@@ -80,6 +82,7 @@ struct condition_info
   edge m_false_edge;
   mapping_vec m_true_edge_phi_mapping;
   mapping_vec m_false_edge_phi_mapping;
+  bool m_has_side_effect;
 };
 
 /* Recond PHI mapping for an original edge E and save these into vector VEC.  */
@@ -227,6 +230,7 @@ if_chain::is_beneficial ()
                        (left->get_high ()), wi::one (TYPE_PRECISION (type))))
            {
              left->set_high (right->get_high ());
+             delete right;
              continue;
            }
        }
@@ -241,20 +245,20 @@ if_chain::is_beneficial ()
     = jump_table_cluster::find_jump_tables (filtered_clusters);
   bool r = output.length () < filtered_clusters.length ();
   if (r)
-    dump_clusters (&output, "JT can be built");
-  output.release ();
-  if (r)
-    return true;
+    {
+      dump_clusters (&output, "JT can be built");
+      release_clusters (output);
+      return true;
+    }
+  else
+    output.release ();
 
   output = bit_test_cluster::find_bit_tests (filtered_clusters);
   r = output.length () < filtered_clusters.length ();
   if (r)
     dump_clusters (&output, "BT can be built");
 
-  for (unsigned i = 0; i < output.length (); i++)
-    delete output[i];
-
-  output.release ();
+  release_clusters (output);
   return r;
 }
 
@@ -388,14 +392,11 @@ find_conditions (basic_block bb,
   if (cond == NULL)
     return;
 
-  if (!no_side_effect_bb (bb))
-    return;
-
   tree lhs = gimple_cond_lhs (cond);
   tree rhs = gimple_cond_rhs (cond);
   tree_code code = gimple_cond_code (cond);
 
-  condition_info *info = new condition_info (cond);
+  condition_info *info = new condition_info (cond, !no_side_effect_bb (bb));
 
   gassign *def;
   if (code == NE_EXPR
@@ -477,13 +478,13 @@ public:
   {}
 
   /* opt_pass methods: */
-  virtual bool gate (function *)
+  bool gate (function *) final override
   {
     return (jump_table_cluster::is_enabled ()
            || bit_test_cluster::is_enabled ());
   }
 
-  virtual unsigned int execute (function *);
+  unsigned int execute (function *) final override;
 
 }; // class pass_if_to_switch
 
@@ -533,6 +534,10 @@ pass_if_to_switch::execute (function *fun)
              if ((*info2)->m_false_edge != e)
                break;
 
+             /* Only the first BB in a chain can have a side effect.  */
+             if (info->m_has_side_effect)
+               break;
+
              chain->m_entries.safe_push (*info2);
              bitmap_set_bit (seen_bbs, e->src->index);
              info = *info2;