public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aldyh/heads/ranger-relational)] Enable evrp passes before each VRP pass.
@ 2021-04-25 11:25 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2021-04-25 11:25 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:433113cf36ad86decfcfd4e940f781269e2188ed

commit 433113cf36ad86decfcfd4e940f781269e2188ed
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Apr 21 17:03:24 2021 +0200

    Enable evrp passes before each VRP pass.
    
    Late evrp passes are disabled by default and must be explicitly enabled
    with -fenable-tree-late-evrp[12] that match their vrp[12] conterparts.

Diff:
---
 gcc/gimple-ssa-evrp.c | 57 +++++++++++++++++++++++++++++++++++++++++++++-
 gcc/passes.def        |  2 ++
 gcc/tree-pass.h       |  1 +
 gcc/tree-vrp.c        | 62 +++++++++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 119 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-ssa-evrp.c b/gcc/gimple-ssa-evrp.c
index cfd1ee74c5f..c3966f74720 100644
--- a/gcc/gimple-ssa-evrp.c
+++ b/gcc/gimple-ssa-evrp.c
@@ -474,7 +474,15 @@ public:
 
   bool fold_stmt (gimple_stmt_iterator *gsi) OVERRIDE
   {
-    return m_simplifier.simplify (gsi);
+    bool ret = m_simplifier.simplify (gsi);
+    if (dump_file && ret)
+      {
+	extern bool folded_cond_p (gimple *);
+	gimple *stmt = gsi_stmt (*gsi);
+	if (folded_cond_p (stmt))
+	  fprintf (dump_file, "XXFOLDED CONDITIONAL\n");
+      }
+    return ret;
   }
 
 private:
@@ -742,6 +750,19 @@ const pass_data pass_data_early_vrp =
   ( TODO_cleanup_cfg | TODO_update_ssa | TODO_verify_all ),
 };
 
+const pass_data pass_data_late_evrp =
+{
+  GIMPLE_PASS, /* type */
+  "late-evrp", /* name */
+  OPTGROUP_NONE, /* optinfo_flags */
+  TV_TREE_EARLY_VRP, /* tv_id */
+  PROP_ssa, /* properties_required */
+  0, /* properties_provided */
+  0, /* properties_destroyed */
+  0, /* todo_flags_start */
+  ( TODO_cleanup_cfg | TODO_update_ssa | TODO_verify_all ),
+};
+
 class pass_early_vrp : public gimple_opt_pass
 {
 public:
@@ -759,6 +780,34 @@ public:
     { return execute_early_vrp (); }
 
 }; // class pass_vrp
+
+// This is a different class than pass_late_evrp so -fdisable-tree-evrp works in
+// tests, instead of having to specify -fdisable-tree-evrp1.
+//
+// These passes are disabled by default and must be explicitly enabled with
+// -fenable-tree-late-evrp[12] that match their -ftree-vrp[12] counterparts.
+class pass_late_evrp : public gimple_opt_pass
+{
+public:
+  pass_late_evrp (gcc::context *ctxt)
+    : gimple_opt_pass (pass_data_late_evrp, ctxt)
+    {}
+
+  virtual opt_pass * clone () OVERRIDE
+  {
+    return new pass_late_evrp (m_ctxt);
+  }
+  virtual bool gate (function *) OVERRIDE
+    {
+      // Must be explicitly enabled with -fenable-tree-late-evrp[12].
+      return 0;
+    }
+  virtual unsigned int execute (function *) OVERRIDE
+    {
+      return execute_early_vrp ();
+    }
+};
+
 } // anon namespace
 
 gimple_opt_pass *
@@ -766,3 +815,9 @@ make_pass_early_vrp (gcc::context *ctxt)
 {
   return new pass_early_vrp (ctxt);
 }
+
+gimple_opt_pass *
+make_pass_late_evrp (gcc::context *ctxt)
+{
+  return new pass_late_evrp (ctxt);
+}
diff --git a/gcc/passes.def b/gcc/passes.def
index e9ed3c7bc57..78d6278053e 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -209,6 +209,7 @@ along with GCC; see the file COPYING3.  If not see
       NEXT_PASS (pass_fre, true /* may_iterate */);
       NEXT_PASS (pass_merge_phi);
       NEXT_PASS (pass_thread_jumps);
+      NEXT_PASS (pass_late_evrp);
       NEXT_PASS (pass_vrp, true /* warn_array_bounds_p */);
       NEXT_PASS (pass_dce);
       NEXT_PASS (pass_stdarg);
@@ -330,6 +331,7 @@ along with GCC; see the file COPYING3.  If not see
       NEXT_PASS (pass_dominator, false /* may_peel_loop_headers_p */);
       NEXT_PASS (pass_strlen);
       NEXT_PASS (pass_thread_jumps);
+      NEXT_PASS (pass_late_evrp);
       NEXT_PASS (pass_vrp, false /* warn_array_bounds_p */);
       /* Threading can leave many const/copy propagations in the IL.
 	 Clean them up.  */
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index 15693fee150..5acefbe4edc 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -454,6 +454,7 @@ extern gimple_opt_pass *make_pass_check_data_deps (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_copy_prop (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_isolate_erroneous_paths (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_early_vrp (gcc::context *ctxt);
+extern gimple_opt_pass *make_pass_late_evrp (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_vrp (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_uncprop (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_return_slot (gcc::context *ctxt);
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 4818497353e..b67fcc78526 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4142,15 +4142,73 @@ vrp_folder::fold_predicate_in (gimple_stmt_iterator *si)
   return false;
 }
 
+static void
+dump_folded_conditional_context (gimple *stmt,
+				 tree lhs, irange &lhs_range,
+				 tree rhs, irange &rhs_range)
+{
+  if (cfun && cfun->decl)
+    {
+      fprintf (dump_file, "\nFUNCTION: ");
+      print_generic_expr (dump_file, cfun->decl);
+      fprintf (dump_file, "\n");
+    }
+
+  basic_block bb = gimple_bb (stmt);
+  dump_bb (dump_file, bb, 0, TDF_DETAILS);
+
+  fprintf (dump_file, "\tlhs = ");
+  print_generic_expr (dump_file, lhs);
+  fprintf (dump_file, ": ");
+  lhs_range.dump (dump_file);
+  fprintf (dump_file, "\n");
+
+  fprintf (dump_file, "\trhs = ");
+  print_generic_expr (dump_file, rhs);
+  fprintf (dump_file, ": ");
+  rhs_range.dump (dump_file);
+  fprintf (dump_file, "\n");
+}
+
+bool
+folded_cond_p (gimple *stmt)
+{
+  if (is_a<gcond *> (stmt))
+    return (TREE_CODE (gimple_cond_lhs (stmt)) == INTEGER_CST
+	    && TREE_CODE (gimple_cond_rhs (stmt)) == INTEGER_CST);
+  return false;
+}
+
 /* Callback for substitute_and_fold folding the stmt at *SI.  */
 
 bool
 vrp_folder::fold_stmt (gimple_stmt_iterator *si)
 {
+  gimple *stmt = gsi_stmt (*si);
+  tree lhs = NULL, rhs = NULL;
+  value_range lhs_range, rhs_range;
+
+  if (dump_file && is_a<gcond *> (stmt))
+    {
+      lhs = gimple_cond_lhs (stmt);
+      rhs = gimple_cond_rhs (stmt);
+      m_vr_values->range_of_expr (lhs_range, lhs, NULL);
+      m_vr_values->range_of_expr (rhs_range, rhs, NULL);
+    }
+
+  bool ret = false;
   if (fold_predicate_in (si))
-    return true;
+    ret = true;
+  else
+    ret = simplifier.simplify (si);
 
-  return simplifier.simplify (si);
+  if (dump_file && ret && folded_cond_p (stmt))
+    {
+      if (param_evrp_mode == EVRP_MODE_RVRP_ONLY)
+	dump_folded_conditional_context (stmt, lhs, lhs_range, rhs, rhs_range);
+      fprintf (dump_file, "XXFOLDED CONDITIONAL\n");
+    }
+  return ret;
 }
 
 class vrp_jump_threader_simplifier : public jump_threader_simplifier


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

only message in thread, other threads:[~2021-04-25 11:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-25 11:25 [gcc(refs/users/aldyh/heads/ranger-relational)] Enable evrp passes before each VRP pass 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).