public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2510] Abstract out conditional simplification out of execute_vrp.
@ 2021-07-26 11:42 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2021-07-26 11:42 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:32f7506bdc3956762bcc7dc84133fd7c3a00bb7b

commit r12-2510-g32f7506bdc3956762bcc7dc84133fd7c3a00bb7b
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Jul 26 11:53:41 2021 +0200

    Abstract out conditional simplification out of execute_vrp.
    
    VRP simplifies conditionals involving casted values outside of the main
    folding mechanism, because this optimization inhibits the VRP jump
    threader from threading through the comparison.
    
    As part of replacing VRP with an evrp instance, I am making sure we do
    everything VRP does.  Hence, I am abstracting this functionality out so
    we can call it from from elsewhere.
    
    ISTM that when the proposed ranger-based jump threader can handle
    everything the forward threader does, there will be no need for this
    optimization to be done outside of the evrp folder.  Perhaps we can fold
    this into the substitute_using_ranges class.  But that's further down
    the line.
    
    Also, there is no need to pass a vr_values around, when the base
    range_query class will do.  I fixed this, at it makes it trivial to pass
    down a ranger or evrp instance.
    
    Tested on x86-64 Linux.
    
    gcc/ChangeLog:
    
            * tree-vrp.c (vrp_simplify_cond_using_ranges): Rename vr_values
            with range_query.
            (execute_vrp): Abstract out simplification of conditionals...
            (simplify_casted_conds): ...here.

Diff:
---
 gcc/tree-vrp.c | 39 +++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index a9c31bcedb5..58111f83183 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4359,7 +4359,7 @@ vrp_jump_threader::after_dom_children (basic_block bb)
    subsequent passes.  */
 
 static void
-vrp_simplify_cond_using_ranges (vr_values *query, gcond *stmt)
+vrp_simplify_cond_using_ranges (range_query *query, gcond *stmt)
 {
   tree op0 = gimple_cond_lhs (stmt);
   tree op1 = gimple_cond_rhs (stmt);
@@ -4423,6 +4423,27 @@ vrp_simplify_cond_using_ranges (vr_values *query, gcond *stmt)
     }
 }
 
+/* A comparison of an SSA_NAME against a constant where the SSA_NAME
+   was set by a type conversion can often be rewritten to use the RHS
+   of the type conversion.  Do this optimization for all conditionals
+   in FUN.
+
+   However, doing so inhibits jump threading through the comparison.
+   So that transformation is not performed until after jump threading
+   is complete.  */
+
+static void
+simplify_casted_conds (function *fun, range_query *query)
+{
+  basic_block bb;
+  FOR_EACH_BB_FN (bb, fun)
+    {
+      gimple *last = last_stmt (bb);
+      if (last && gimple_code (last) == GIMPLE_COND)
+	vrp_simplify_cond_using_ranges (query, as_a <gcond *> (last));
+    }
+}
+
 /* Main entry point to VRP (Value Range Propagation).  This pass is
    loosely based on J. R. C. Patterson, ``Accurate Static Branch
    Prediction by Value Range Propagation,'' in SIGPLAN Conference on
@@ -4519,21 +4540,7 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
   vrp_jump_threader threader (fun, &vrp_vr_values);
   threader.thread_jumps ();
 
-  /* A comparison of an SSA_NAME against a constant where the SSA_NAME
-     was set by a type conversion can often be rewritten to use the
-     RHS of the type conversion.
-
-     However, doing so inhibits jump threading through the comparison.
-     So that transformation is not performed until after jump threading
-     is complete.  */
-  basic_block bb;
-  FOR_EACH_BB_FN (bb, fun)
-    {
-      gimple *last = last_stmt (bb);
-      if (last && gimple_code (last) == GIMPLE_COND)
-	vrp_simplify_cond_using_ranges (&vrp_vr_values,
-					as_a <gcond *> (last));
-    }
+  simplify_casted_conds (fun, &vrp_vr_values);
 
   free_numbers_of_iterations_estimates (fun);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-26 11:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-26 11:42 [gcc r12-2510] Abstract out conditional simplification out of execute_vrp Aldy Hernandez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).