Add --param max-unswitch-depth
authorRichard Biener <rguenther@suse.de>
Thu, 1 Dec 2022 15:14:14 +0000 (16:14 +0100)
committerRichard Biener <rguenther@suse.de>
Fri, 2 Dec 2022 07:04:11 +0000 (08:04 +0100)
The following adds a --param to limit the depth of unswitched loop
nests.  One can use --param max-unswitch-depth=1 to disable unswitching
of outer loops (the innermost loop will then be unswitched).

PR tree-optimization/107946
* params.opt (-param=max-unswitch-depth=): New.
* doc/invoke.texi (--param=max-unswitch-depth): Document.
* tree-ssa-loop-unswitch.cc (init_loop_unswitch_info): Honor
--param=max-unswitch-depth

gcc/doc/invoke.texi
gcc/params.opt
gcc/tree-ssa-loop-unswitch.cc

index 56e5e87..277ac35 100644 (file)
@@ -14963,6 +14963,9 @@ 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-depth
+The maximum depth of a loop nest to be unswitched.
+
 @item lim-expensive
 The minimum cost of an expensive expression in the loop invariant motion.
 
index c1dcb7e..397ec0b 100644 (file)
@@ -726,6 +726,10 @@ 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-depth=
+Common Joined UInteger Var(param_max_unswitch_depth) Init(50) IntegerRange(1, 50) Param Optimization
+The maximum depth of a loop nest to be unswitched.
+
 -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.
index e8c9bd6..df7a201 100644 (file)
@@ -263,8 +263,10 @@ init_loop_unswitch_info (class loop *&loop, unswitch_predicate *&hottest,
 
   /* Unswitch only nests with no sibling loops.  */
   class loop *outer_loop = loop;
+  unsigned max_depth = param_max_unswitch_depth;
   while (loop_outer (outer_loop)->num != 0
-        && !loop_outer (outer_loop)->inner->next)
+        && !loop_outer (outer_loop)->inner->next
+        && --max_depth != 0)
     outer_loop = loop_outer (outer_loop);
   hottest = NULL;
   hottest_bb = NULL;