]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use ranger when simplifying conditions during niter analysis
authorRichard Biener <rguenther@suse.de>
Fri, 7 Nov 2025 12:52:09 +0000 (13:52 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 11 Nov 2025 14:36:04 +0000 (15:36 +0100)
The following uses ranger to try to simplify boolean expressions
in simplify_using_initial_conditions as used by niter analysis.
We also try to simplify niter expressions themselves, but we cannot
use ranger directly for this.

* tree-ssa-loop-niter.cc (simplify_using_initial_conditions):
Use the active ranger to simplify boolean expressions.

gcc/tree-ssa-loop-niter.cc

index 5e35a59fcd10afd76c1d1e181d5fcd6ee0847195..f27a9e5cd1132513b1adf194a1552adecac2b863 100644 (file)
@@ -3085,6 +3085,15 @@ simplify_using_initial_conditions (class loop *loop, tree expr)
   if (TREE_CODE (expr) == INTEGER_CST)
     return expr;
 
+  value_range expr_range (TREE_TYPE (expr));
+  if (TREE_TYPE (expr) == boolean_type_node
+      && get_range_query (cfun)->range_on_edge (expr_range,
+                                               loop_preheader_edge (loop),
+                                               expr)
+      && !expr_range.undefined_p ()
+      && !expr_range.varying_p ())
+    return expr_range.nonzero_p () ? boolean_true_node : boolean_false_node;
+
   backup = expanded = expand_simple_operations (expr);
 
   /* Limit walking the dominators to avoid quadraticness in