[gcc(refs/users/marxin/heads/loop-unswitch-improvement-v7)] Fix switch bug!

Martin Liska marxin@gcc.gnu.org
Wed Dec 8 11:14:50 GMT 2021


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

commit a3ba6f3bb9dff3289345e7b84642c76350502bb9
Author: Martin Liska <mliska@suse.cz>
Date:   Wed Dec 8 12:14:27 2021 +0100

    Fix switch bug!
    
    And add comments.

Diff:
---
 gcc/tree-ssa-loop-unswitch.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c
index 811f0cad343..d80b34db861 100644
--- a/gcc/tree-ssa-loop-unswitch.c
+++ b/gcc/tree-ssa-loop-unswitch.c
@@ -90,6 +90,8 @@ struct unswitch_predicate
     edge_index (edge_index_), handled (false)
   {}
 
+  /* Based on true_range, compute inverted range.  */
+
   inline void
   init_false_edge (void)
   {
@@ -100,6 +102,8 @@ struct unswitch_predicate
       false_range.invert ();
   }
 
+  /* Copy ranges for purpose of usage in predicate path.  */
+
   inline void
   copy_merged_ranges ()
   {
@@ -107,11 +111,22 @@ struct unswitch_predicate
     merged_false_range = false_range;
   }
 
+  /* Unswitching expression.  */
   tree condition;
+
+  /* LHS of the expression.  */
   tree lhs;
+
+  /* Initial ranges (when the expression is true/false) for the expression.  */
   int_range_max true_range, false_range;
+
+  /* Modified range that is part of a predicate path.  */
   int_range_max merged_true_range, merged_false_range;
+
+  /* For switch predicates, index of the edge the predicate belongs to.  */
   int edge_index;
+
+  /* True if the predicate was already used for unswitching.  */
   bool handled;
 };
 
@@ -451,6 +466,12 @@ find_unswitching_predicates_for_bb (basic_block bb, class loop *loop,
 		  unswitch_predicate *predicate = new unswitch_predicate (expr, idx, edge_index);
 		  ranger->gori().outgoing_edge_range_p (predicate->true_range, e,
 							idx, *get_global_range_query  ());
+		  /* Huge switches are not supported by Ranger.  */
+		  if (predicate->true_range.undefined_p ())
+		    {
+		      delete predicate;
+		      return;
+		    }
 		  predicate->init_false_edge ();
 
 		  candidates.safe_push (predicate);


More information about the Gcc-cvs mailing list