Re: [patch] substitute_and_fold_engine merge with evrp domwalker

2020-06-09 Thread Jeff Law via Gcc-patches
On Mon, 2020-05-18 at 19:59 +0200, Aldy Hernandez wrote:
> Howdy.
> 
> The main evrp domwalker seems cut and pasted from the 
> substitute_and_fold_engine (or was it the other way around?).   Albeit, 
> there are a few things that evrp does, like set up ranges, but these can 
> be set up with virtuals, and thus provide a general repository to do all 
> things subst & fold, which I think was the main idea.
> 
> You will notice that the resulting evrp code becomes a handful of lines 
> calling evrp_analyze to set up ranges.
> 
> We've been playing with this approach on the ranger branch, and have 
> been able to use it to implement ranger-vrp in 24 lines, all while 
> sharing all the evrp folding code.  Granted, the ranger also needs 
> access to vr_values::simplify_using_ranges* which I have abstracted into 
> an independent class and will post as a follow-up.
> 
> Also, for future-proofing, I have added a gimple statement argument to 
> get_value().  This provides context where a future ranger (evrp, VRP, 
> ranger, whatever) can provide better values depending on the statement 
> we are processing.
> 
> OK for mainline?
> 
> Aldy

> commit f90d4a08986e98cbcb827665d91759488c714075
> Author: Aldy Hernandez 
> Date:   Tue May 5 13:45:39 2020 +0200
> 
> Merge evrp uses of substitute_and_fold_engine into the engine itself.
> 
> This patch merges the evrp uses of the substitute and fold engine into
> the engine itself, at least the parts that can be re-used by other
> engine uses.  It also adds a context parameter to get_value() for
> further use.
SO what's interesting here is originally the dominator walker had methods that
probably would have made this simpler.  We ultimately took them out because they
didn't really help all that much in the existing users of the dominator walker
and they just slowed things down with per-statement virtual calls in both the
into-ssa and DOM passes.

Anyway, this is fine with me.   I suspect there's further cleanups we can and
should do, but the removal of duplicated code along makes your patch worth it
IMHO.

jeff
> 



Fwd: [patch] substitute_and_fold_engine merge with evrp domwalker

2020-05-31 Thread Aldy Hernandez via Gcc-patches
PING

-- Forwarded message -
From: Aldy Hernandez 
Date: Mon, May 18, 2020 at 7:59 PM
Subject: [patch] substitute_and_fold_engine merge with evrp domwalker
To: Jeff Law 
Cc: gcc-patches 


Howdy.

The main evrp domwalker seems cut and pasted from the
substitute_and_fold_engine (or was it the other way around?).   Albeit,
there are a few things that evrp does, like set up ranges, but these can
be set up with virtuals, and thus provide a general repository to do all
things subst & fold, which I think was the main idea.

You will notice that the resulting evrp code becomes a handful of lines
calling evrp_analyze to set up ranges.

We've been playing with this approach on the ranger branch, and have
been able to use it to implement ranger-vrp in 24 lines, all while
sharing all the evrp folding code.  Granted, the ranger also needs
access to vr_values::simplify_using_ranges* which I have abstracted into
an independent class and will post as a follow-up.

Also, for future-proofing, I have added a gimple statement argument to
get_value().  This provides context where a future ranger (evrp, VRP,
ranger, whatever) can provide better values depending on the statement
we are processing.

OK for mainline?

Aldy
commit f90d4a08986e98cbcb827665d91759488c714075
Author: Aldy Hernandez 
Date:   Tue May 5 13:45:39 2020 +0200

Merge evrp uses of substitute_and_fold_engine into the engine itself.

This patch merges the evrp uses of the substitute and fold engine into
the engine itself, at least the parts that can be re-used by other
engine uses.  It also adds a context parameter to get_value() for
further use.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 51b5b6c908d..19e2509ab0e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,37 @@
+2020-05-18  Aldy Hernandez  
+
+	* gimple-loop-versioning.cc (loop_versioning::name_prop::get_value):
+	Add stmt parameter.
+	* gimple-ssa-evrp.c (class evrp_folder): New.
+	(class evrp_dom_walker): Remove.
+	(execute_early_vrp): Use evrp_folder instead of evrp_dom_walker.
+	* tree-ssa-ccp.c (ccp_folder::get_value): Add stmt parameter.
+	* tree-ssa-copy.c (copy_folder::get_value): Same.
+	* tree-ssa-propagate.c (substitute_and_fold_engine::replace_uses_in):
+	Pass stmt to get_value.
+	(substitute_and_fold_engine::replace_phi_args_in): Same.
+	(substitute_and_fold_dom_walker::after_dom_children): Call
+	post_fold_bb.
+	(substitute_and_fold_dom_walker::foreach_new_stmt_in_bb): New.
+	(substitute_and_fold_dom_walker::propagate_into_phi_args): New.
+	(substitute_and_fold_dom_walker::before_dom_children): Adjust to
+	call virtual functions for folding, pre_folding, and post folding.
+	Call get_value with PHI.  Tweak dump.
+	* tree-ssa-propagate.h (class substitute_and_fold_engine):
+	New argument to get_value.
+	New virtual function pre_fold_bb.
+	New virtual function post_fold_bb.
+	New virtual function pre_fold_stmt.
+	New virtual function post_new_stmt.
+	New function propagate_into_phi_args.
+	* tree-vrp.c (vrp_folder::get_value): Add stmt argument.
+	* vr-values.c (vr_values::extract_range_from_stmt): Adjust dump
+	output.
+	(vr_values::fold_cond): New.
+	(vr_values::simplify_cond_using_ranges_1): Call fold_cond.
+	* vr-values.h (class vr_values): Add
+	simplify_cond_using_ranges_when_edge_is_known.
+
 2020-05-18  Carl Love  
 
 	PR target/94833
diff --git a/gcc/gimple-loop-versioning.cc b/gcc/gimple-loop-versioning.cc
index ff6c561f9e2..002b2a68b96 100644
--- a/gcc/gimple-loop-versioning.cc
+++ b/gcc/gimple-loop-versioning.cc
@@ -277,7 +277,7 @@ private:
   {
   public:
 name_prop (loop_info ) : m_li (li) {}
-tree get_value (tree) FINAL OVERRIDE;
+tree get_value (tree, gimple *) FINAL OVERRIDE;
 
   private:
 /* Information about the versioning we've performed on the loop.  */
@@ -534,7 +534,8 @@ loop_versioning::lv_dom_walker::after_dom_children (basic_block bb)
Return the new value if so, otherwise return null.  */
 
 tree
-loop_versioning::name_prop::get_value (tree val)
+loop_versioning::name_prop::get_value (tree val,
+   gimple *stmt ATTRIBUTE_UNUSED)
 {
   if (TREE_CODE (val) == SSA_NAME
   && bitmap_bit_p (_li.unity_names, SSA_NAME_VERSION (val)))
diff --git a/gcc/gimple-ssa-evrp.c b/gcc/gimple-ssa-evrp.c
index 599e1459f00..af780fd0519 100644
--- a/gcc/gimple-ssa-evrp.c
+++ b/gcc/gimple-ssa-evrp.c
@@ -43,273 +43,68 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-ssa-evrp-analyze.h"
 
 class evrp_folder : public substitute_and_fold_engine
-{
- public:
-  tree get_value (tree) FINAL OVERRIDE;
-  evrp_folder (class vr_values *vr_values_) : vr_values (vr_values_) { }
-  bool simplify_stmt_using_ranges (gimple_stmt_iterator *gsi)
-{ return vr_values->simplify_stmt_using_ranges (gsi); }
-  class vr_values *vr_values;
-
- private:
-  DISABLE_COPY_AND_ASSIGN (evrp_folder);
-};
-
-tree
-evrp_folder::get_value (tree op)
-{
-  return vr_values->op_with_co

Re: [patch] substitute_and_fold_engine merge with evrp domwalker

2020-05-18 Thread Richard Biener via Gcc-patches
On May 18, 2020 7:59:45 PM GMT+02:00, Aldy Hernandez via Gcc-patches 
 wrote:
>Howdy.
>
>The main evrp domwalker seems cut and pasted from the 
>substitute_and_fold_engine (or was it the other way around?).   Albeit,
>
>there are a few things that evrp does, like set up ranges, but these
>can 
>be set up with virtuals, and thus provide a general repository to do
>all 
>things subst & fold, which I think was the main idea.
>
>You will notice that the resulting evrp code becomes a handful of lines
>
>calling evrp_analyze to set up ranges.
>
>We've been playing with this approach on the ranger branch, and have 
>been able to use it to implement ranger-vrp in 24 lines, all while 
>sharing all the evrp folding code.  Granted, the ranger also needs 
>access to vr_values::simplify_using_ranges* which I have abstracted
>into 
>an independent class and will post as a follow-up.
>
>Also, for future-proofing, I have added a gimple statement argument to 
>get_value().  This provides context where a future ranger (evrp, VRP, 
>ranger, whatever) can provide better values depending on the statement 
>we are processing.

Ranges before or after the stmt?  There are currently conflicting uses... (I 
did have a patch to expose non-zeroness for integer division dividend but that 
causes some code to think this holds for the stmt itself).  So this has to be 
appearant from the API. 

Richard. 

>
>OK for mainline?
>
>Aldy



[patch] substitute_and_fold_engine merge with evrp domwalker

2020-05-18 Thread Aldy Hernandez via Gcc-patches

Howdy.

The main evrp domwalker seems cut and pasted from the 
substitute_and_fold_engine (or was it the other way around?).   Albeit, 
there are a few things that evrp does, like set up ranges, but these can 
be set up with virtuals, and thus provide a general repository to do all 
things subst & fold, which I think was the main idea.


You will notice that the resulting evrp code becomes a handful of lines 
calling evrp_analyze to set up ranges.


We've been playing with this approach on the ranger branch, and have 
been able to use it to implement ranger-vrp in 24 lines, all while 
sharing all the evrp folding code.  Granted, the ranger also needs 
access to vr_values::simplify_using_ranges* which I have abstracted into 
an independent class and will post as a follow-up.


Also, for future-proofing, I have added a gimple statement argument to 
get_value().  This provides context where a future ranger (evrp, VRP, 
ranger, whatever) can provide better values depending on the statement 
we are processing.


OK for mainline?

Aldy
commit f90d4a08986e98cbcb827665d91759488c714075
Author: Aldy Hernandez 
Date:   Tue May 5 13:45:39 2020 +0200

Merge evrp uses of substitute_and_fold_engine into the engine itself.

This patch merges the evrp uses of the substitute and fold engine into
the engine itself, at least the parts that can be re-used by other
engine uses.  It also adds a context parameter to get_value() for
further use.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 51b5b6c908d..19e2509ab0e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,37 @@
+2020-05-18  Aldy Hernandez  
+
+	* gimple-loop-versioning.cc (loop_versioning::name_prop::get_value):
+	Add stmt parameter.
+	* gimple-ssa-evrp.c (class evrp_folder): New.
+	(class evrp_dom_walker): Remove.
+	(execute_early_vrp): Use evrp_folder instead of evrp_dom_walker.
+	* tree-ssa-ccp.c (ccp_folder::get_value): Add stmt parameter.
+	* tree-ssa-copy.c (copy_folder::get_value): Same.
+	* tree-ssa-propagate.c (substitute_and_fold_engine::replace_uses_in):
+	Pass stmt to get_value.
+	(substitute_and_fold_engine::replace_phi_args_in): Same.
+	(substitute_and_fold_dom_walker::after_dom_children): Call
+	post_fold_bb.
+	(substitute_and_fold_dom_walker::foreach_new_stmt_in_bb): New.
+	(substitute_and_fold_dom_walker::propagate_into_phi_args): New.
+	(substitute_and_fold_dom_walker::before_dom_children): Adjust to
+	call virtual functions for folding, pre_folding, and post folding.
+	Call get_value with PHI.  Tweak dump.
+	* tree-ssa-propagate.h (class substitute_and_fold_engine):
+	New argument to get_value.
+	New virtual function pre_fold_bb.
+	New virtual function post_fold_bb.
+	New virtual function pre_fold_stmt.
+	New virtual function post_new_stmt.
+	New function propagate_into_phi_args.
+	* tree-vrp.c (vrp_folder::get_value): Add stmt argument.
+	* vr-values.c (vr_values::extract_range_from_stmt): Adjust dump
+	output.
+	(vr_values::fold_cond): New.
+	(vr_values::simplify_cond_using_ranges_1): Call fold_cond.
+	* vr-values.h (class vr_values): Add
+	simplify_cond_using_ranges_when_edge_is_known.
+
 2020-05-18  Carl Love  
 
 	PR target/94833
diff --git a/gcc/gimple-loop-versioning.cc b/gcc/gimple-loop-versioning.cc
index ff6c561f9e2..002b2a68b96 100644
--- a/gcc/gimple-loop-versioning.cc
+++ b/gcc/gimple-loop-versioning.cc
@@ -277,7 +277,7 @@ private:
   {
   public:
 name_prop (loop_info ) : m_li (li) {}
-tree get_value (tree) FINAL OVERRIDE;
+tree get_value (tree, gimple *) FINAL OVERRIDE;
 
   private:
 /* Information about the versioning we've performed on the loop.  */
@@ -534,7 +534,8 @@ loop_versioning::lv_dom_walker::after_dom_children (basic_block bb)
Return the new value if so, otherwise return null.  */
 
 tree
-loop_versioning::name_prop::get_value (tree val)
+loop_versioning::name_prop::get_value (tree val,
+   gimple *stmt ATTRIBUTE_UNUSED)
 {
   if (TREE_CODE (val) == SSA_NAME
   && bitmap_bit_p (_li.unity_names, SSA_NAME_VERSION (val)))
diff --git a/gcc/gimple-ssa-evrp.c b/gcc/gimple-ssa-evrp.c
index 599e1459f00..af780fd0519 100644
--- a/gcc/gimple-ssa-evrp.c
+++ b/gcc/gimple-ssa-evrp.c
@@ -43,273 +43,68 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-ssa-evrp-analyze.h"
 
 class evrp_folder : public substitute_and_fold_engine
-{
- public:
-  tree get_value (tree) FINAL OVERRIDE;
-  evrp_folder (class vr_values *vr_values_) : vr_values (vr_values_) { }
-  bool simplify_stmt_using_ranges (gimple_stmt_iterator *gsi)
-{ return vr_values->simplify_stmt_using_ranges (gsi); }
-  class vr_values *vr_values;
-
- private:
-  DISABLE_COPY_AND_ASSIGN (evrp_folder);
-};
-
-tree
-evrp_folder::get_value (tree op)
-{
-  return vr_values->op_with_constant_singleton_value_range (op);
-}
-
-/* evrp_dom_walker visits the basic blocks in the dominance order and set
-   the Value Ranges (VR) for SSA_NAMEs in the scope.  Use this VR to
-   discover more VRs.  */
-