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 | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc
index 5e35a59fcd1..f27a9e5cd11 100644
--- a/gcc/tree-ssa-loop-niter.cc
+++ b/gcc/tree-ssa-loop-niter.cc
@@ -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
-- 
2.51.0

Reply via email to