Re: [RFC][IPA-VRP] Add support for IPA VRP in ipa-cp/ipa-prop

2016-09-02 Thread Jan Hubicka
> Hi Honza,
> 
> Here is a re-based version which also addresses the review comments.
> 
> Do you mean the following, I was following other implementations.
> 
> @@ -2264,6 +2430,11 @@ propagate_constants_accross_call (struct
> cgraph_edge *cs)
> _plats->bits_lattice);
>ret |= propagate_aggs_accross_jump_function (cs, jump_func,
> dest_plats);
> +  if (opt_for_fn (callee->decl, flag_ipa_vrp))
> +ret |= propagate_vr_accross_jump_function (cs,
> +   jump_func, dest_plats);
> +  else
> +ret |= dest_plats->m_value_range.set_to_bottom ();

yes, that looks fine.

Path is OK, thanks!

Honza


Re: [RFC][IPA-VRP] Add support for IPA VRP in ipa-cp/ipa-prop

2016-08-30 Thread kugan

Hi,


Just noticed a small nit - why not reuse ipa_vr in ipa_jump_func
instead of adding vr_known and m_vr ?


This is because we want to reuse  vrp_intersect_ranges and vrp_meet 
which are not trivial. On the other hand, in ipa_jump_func, since we 
stream the data we have a simpler data structure with wide_int.


Thanks,
Kugan


Re: [RFC][IPA-VRP] Add support for IPA VRP in ipa-cp/ipa-prop

2016-08-30 Thread Prathamesh Kulkarni
On 30 August 2016 at 10:50, Kugan Vivekanandarajah
 wrote:
> Hi Honza,
>
> Here is a re-based version which also addresses the review comments.
>
> On 21/07/16 22:54, Jan Hubicka wrote:
>>> Maybe it is better to separate value range and alignment summary
>>> writing/reading to different functions. Here is another updated
>>> version which does this.
>>
>> Makes sense to me. Note that the alignment summary propagation can be either
>> handled by doing bitwise constant propagation and/or extending our value 
>> ranges
>> by stride (as described in
>> http://www.lighterra.com/papers/valuerangeprop/Patterson1995-ValueRangeProp.pdf
>> I would like it to go eventually away in favour of more generic solution.
>>
>>> -/* If DEST_PLATS already has aggregate items, check that aggs_by_ref 
>>> matches
>>> +/* Propagate value range across jump function JFUNC that is associated with
>>> +   edge CS and update DEST_PLATS accordingly.  */
>>> +
>>> +static bool
>>> +propagate_vr_accross_jump_function (cgraph_edge *cs,
>>> +ipa_jump_func *jfunc,
>>> +struct ipcp_param_lattices *dest_plats)
>>> +{
>>> +  struct ipcp_param_lattices *src_lats;
>>> +  ipcp_vr_lattice *dest_lat = _plats->m_value_range;
>>> +
>>> +  if (dest_lat->bottom_p ())
>>> +return false;
>>> +
>>> +  if (jfunc->type == IPA_JF_PASS_THROUGH)
>>> +{
>>> +  struct ipa_node_params *caller_info = IPA_NODE_REF (cs->caller);
>>> +  int src_idx = ipa_get_jf_pass_through_formal_id (jfunc);
>>> +  src_lats = ipa_get_parm_lattices (caller_info, src_idx);
>>> +
>>> +  if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
>>> + return dest_lat->meet_with (src_lats->m_value_range);
>>
>> Clearly we can propagate thorugh expressions here (PLUS_EXPR). I have run
>> into similar issue in loop code that builds simple generic expresisons
>> (like (int)ssa_name+10) and it would be nice to have easy way to deterine
>> their value range based on the knowledge of SSA_NAME's valur range.
>>
>> Bit this is fine for initial implementaiotn for sure.
>
> Indeed. I will do this as a follow up.
>
>>>
>>> +/* Look up all VR information that we have discovered and copy it over
>>> +   to the transformation summary.  */
>>> +
>>> +static void
>>> +ipcp_store_vr_results (void)
>>> +{
>>> +  cgraph_node *node;
>>> +
>>> +  FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
>>> +  {
>>> +ipa_node_params *info = IPA_NODE_REF (node);
>>> +bool found_useful_result = false;
>>> +
>>> +if (!opt_for_fn (node->decl, flag_ipa_vrp))
>>> +  {
>>> + if (dump_file)
>>> +  fprintf (dump_file, "Not considering %s for VR discovery "
>>> +   "and propagate; -fipa-ipa-vrp: disabled.\n",
>>> +   node->name ());
>>> + continue;
>>
>> I belive you need to also prevent propagation through functions copmiled with
>> -fno-ipa-vrp, not only prevent any transformations.
>
> Do you mean the following, I was following other implementations.
>
> @@ -2264,6 +2430,11 @@ propagate_constants_accross_call (struct
> cgraph_edge *cs)
> _plats->bits_lattice);
>ret |= propagate_aggs_accross_jump_function (cs, jump_func,
> dest_plats);
> +  if (opt_for_fn (callee->decl, flag_ipa_vrp))
> +ret |= propagate_vr_accross_jump_function (cs,
> +   jump_func, dest_plats);
> +  else
> +ret |= dest_plats->m_value_range.set_to_bottom ();
>
>>> +/* Update value range of formal parameters as described in
>>> +   ipcp_transformation_summary.  */
>>> +
>>> +static void
>>> +ipcp_update_vr (struct cgraph_node *node)
>>> +{
>>> +  tree fndecl = node->decl;
>>> +  tree parm = DECL_ARGUMENTS (fndecl);
>>> +  tree next_parm = parm;
>>> +  ipcp_transformation_summary *ts = ipcp_get_transformation_summary (node);
>>> +  if (!ts || vec_safe_length (ts->m_vr) == 0)
>>> +return;
>>> +  const vec  = *ts->m_vr;
>>> +  unsigned count = vr.length ();
>>> +
>>> +  for (unsigned i = 0; i < count; ++i, parm = next_parm)
>>> +{
>>> +  if (node->clone.combined_args_to_skip
>>> +  && bitmap_bit_p (node->clone.combined_args_to_skip, i))
>>> + continue;
>>> +  gcc_checking_assert (parm);
>>> +  next_parm = DECL_CHAIN (parm);
>>> +  tree ddef = ssa_default_def (DECL_STRUCT_FUNCTION (node->decl), 
>>> parm);
>>> +
>>> +  if (!ddef || !is_gimple_reg (parm))
>>> + continue;
>>> +
>>> +  if (cgraph_local_p (node)
>> The test of cgraph_local_p seems redundant here. The analysis phase should 
>> not determine
>> anything if function is reachable non-locally.
>
> Removed it.
>
>>> +/* Info about value ranges.  */
>>> +
>>> +struct GTY(()) ipa_vr
>>> +{
>>> +  /* The data fields below are valid only if known is true.  */
>>> +  bool known;
>>> +  enum value_range_type type;
>>> +  tree min;
>>> +  tree max;
>> What is the point of representing range as trees rather than wide ints. Can 
>> they
>> be non-constant integer?
>
> Changed to wide_int after adding that support.
>
> LTO Bootstrapped and regression tested on 

Re: [RFC][IPA-VRP] Add support for IPA VRP in ipa-cp/ipa-prop

2016-08-29 Thread Kugan Vivekanandarajah
Hi Honza,

Here is a re-based version which also addresses the review comments.

On 21/07/16 22:54, Jan Hubicka wrote:
>> Maybe it is better to separate value range and alignment summary
>> writing/reading to different functions. Here is another updated
>> version which does this.
>
> Makes sense to me. Note that the alignment summary propagation can be either
> handled by doing bitwise constant propagation and/or extending our value 
> ranges
> by stride (as described in
> http://www.lighterra.com/papers/valuerangeprop/Patterson1995-ValueRangeProp.pdf
> I would like it to go eventually away in favour of more generic solution.
>
>> -/* If DEST_PLATS already has aggregate items, check that aggs_by_ref matches
>> +/* Propagate value range across jump function JFUNC that is associated with
>> +   edge CS and update DEST_PLATS accordingly.  */
>> +
>> +static bool
>> +propagate_vr_accross_jump_function (cgraph_edge *cs,
>> +ipa_jump_func *jfunc,
>> +struct ipcp_param_lattices *dest_plats)
>> +{
>> +  struct ipcp_param_lattices *src_lats;
>> +  ipcp_vr_lattice *dest_lat = _plats->m_value_range;
>> +
>> +  if (dest_lat->bottom_p ())
>> +return false;
>> +
>> +  if (jfunc->type == IPA_JF_PASS_THROUGH)
>> +{
>> +  struct ipa_node_params *caller_info = IPA_NODE_REF (cs->caller);
>> +  int src_idx = ipa_get_jf_pass_through_formal_id (jfunc);
>> +  src_lats = ipa_get_parm_lattices (caller_info, src_idx);
>> +
>> +  if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
>> + return dest_lat->meet_with (src_lats->m_value_range);
>
> Clearly we can propagate thorugh expressions here (PLUS_EXPR). I have run
> into similar issue in loop code that builds simple generic expresisons
> (like (int)ssa_name+10) and it would be nice to have easy way to deterine
> their value range based on the knowledge of SSA_NAME's valur range.
>
> Bit this is fine for initial implementaiotn for sure.

Indeed. I will do this as a follow up.

>>
>> +/* Look up all VR information that we have discovered and copy it over
>> +   to the transformation summary.  */
>> +
>> +static void
>> +ipcp_store_vr_results (void)
>> +{
>> +  cgraph_node *node;
>> +
>> +  FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
>> +  {
>> +ipa_node_params *info = IPA_NODE_REF (node);
>> +bool found_useful_result = false;
>> +
>> +if (!opt_for_fn (node->decl, flag_ipa_vrp))
>> +  {
>> + if (dump_file)
>> +  fprintf (dump_file, "Not considering %s for VR discovery "
>> +   "and propagate; -fipa-ipa-vrp: disabled.\n",
>> +   node->name ());
>> + continue;
>
> I belive you need to also prevent propagation through functions copmiled with
> -fno-ipa-vrp, not only prevent any transformations.

Do you mean the following, I was following other implementations.

@@ -2264,6 +2430,11 @@ propagate_constants_accross_call (struct
cgraph_edge *cs)
_plats->bits_lattice);
   ret |= propagate_aggs_accross_jump_function (cs, jump_func,
dest_plats);
+  if (opt_for_fn (callee->decl, flag_ipa_vrp))
+ret |= propagate_vr_accross_jump_function (cs,
+   jump_func, dest_plats);
+  else
+ret |= dest_plats->m_value_range.set_to_bottom ();

>> +/* Update value range of formal parameters as described in
>> +   ipcp_transformation_summary.  */
>> +
>> +static void
>> +ipcp_update_vr (struct cgraph_node *node)
>> +{
>> +  tree fndecl = node->decl;
>> +  tree parm = DECL_ARGUMENTS (fndecl);
>> +  tree next_parm = parm;
>> +  ipcp_transformation_summary *ts = ipcp_get_transformation_summary (node);
>> +  if (!ts || vec_safe_length (ts->m_vr) == 0)
>> +return;
>> +  const vec  = *ts->m_vr;
>> +  unsigned count = vr.length ();
>> +
>> +  for (unsigned i = 0; i < count; ++i, parm = next_parm)
>> +{
>> +  if (node->clone.combined_args_to_skip
>> +  && bitmap_bit_p (node->clone.combined_args_to_skip, i))
>> + continue;
>> +  gcc_checking_assert (parm);
>> +  next_parm = DECL_CHAIN (parm);
>> +  tree ddef = ssa_default_def (DECL_STRUCT_FUNCTION (node->decl), parm);
>> +
>> +  if (!ddef || !is_gimple_reg (parm))
>> + continue;
>> +
>> +  if (cgraph_local_p (node)
> The test of cgraph_local_p seems redundant here. The analysis phase should 
> not determine
> anything if function is reachable non-locally.

Removed it.

>> +/* Info about value ranges.  */
>> +
>> +struct GTY(()) ipa_vr
>> +{
>> +  /* The data fields below are valid only if known is true.  */
>> +  bool known;
>> +  enum value_range_type type;
>> +  tree min;
>> +  tree max;
> What is the point of representing range as trees rather than wide ints. Can 
> they
> be non-constant integer?

Changed to wide_int after adding that support.

LTO Bootstrapped and regression tested on x86_64-linux-gnu with no new
regressions, is this OK?

Thanks
Kugan
From c6687f60001695dd71316e894010a764cb15606a Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah 
Date: Tue, 23 Aug 2016 19:47:58 +1000
Subject: [PATCH 

Re: [RFC][IPA-VRP] Add support for IPA VRP in ipa-cp/ipa-prop

2016-07-21 Thread Jan Hubicka
> Maybe it is better to separate value range and alignment summary
> writing/reading to different functions. Here is another updated
> version which does this.

Makes sense to me. Note that the alignment summary propagation can be either
handled by doing bitwise constant propagation and/or extending our value ranges
by stride (as described in
http://www.lighterra.com/papers/valuerangeprop/Patterson1995-ValueRangeProp.pdf
I would like it to go eventually away in favour of more generic solution.

> -/* If DEST_PLATS already has aggregate items, check that aggs_by_ref matches
> +/* Propagate value range across jump function JFUNC that is associated with
> +   edge CS and update DEST_PLATS accordingly.  */
> +
> +static bool
> +propagate_vr_accross_jump_function (cgraph_edge *cs,
> + ipa_jump_func *jfunc,
> + struct ipcp_param_lattices *dest_plats)
> +{
> +  struct ipcp_param_lattices *src_lats;
> +  ipcp_vr_lattice *dest_lat = _plats->m_value_range;
> +
> +  if (dest_lat->bottom_p ())
> +return false;
> +
> +  if (jfunc->type == IPA_JF_PASS_THROUGH)
> +{
> +  struct ipa_node_params *caller_info = IPA_NODE_REF (cs->caller);
> +  int src_idx = ipa_get_jf_pass_through_formal_id (jfunc);
> +  src_lats = ipa_get_parm_lattices (caller_info, src_idx);
> +
> +  if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
> + return dest_lat->meet_with (src_lats->m_value_range);

Clearly we can propagate thorugh expressions here (PLUS_EXPR). I have run
into similar issue in loop code that builds simple generic expresisons
(like (int)ssa_name+10) and it would be nice to have easy way to deterine
their value range based on the knowledge of SSA_NAME's valur range.

Bit this is fine for initial implementaiotn for sure.
>  
> +/* Look up all VR information that we have discovered and copy it over
> +   to the transformation summary.  */
> +
> +static void
> +ipcp_store_vr_results (void)
> +{
> +  cgraph_node *node;
> +
> +  FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
> +  {
> +ipa_node_params *info = IPA_NODE_REF (node);
> +bool found_useful_result = false;
> +
> +if (!opt_for_fn (node->decl, flag_ipa_vrp))
> +  {
> + if (dump_file)
> +   fprintf (dump_file, "Not considering %s for VR discovery "
> +"and propagate; -fipa-ipa-vrp: disabled.\n",
> +node->name ());
> + continue;

I belive you need to also prevent propagation through functions copmiled with
-fno-ipa-vrp, not only prevent any transformations.
> +/* Update value range of formal parameters as described in
> +   ipcp_transformation_summary.  */
> +
> +static void
> +ipcp_update_vr (struct cgraph_node *node)
> +{
> +  tree fndecl = node->decl;
> +  tree parm = DECL_ARGUMENTS (fndecl);
> +  tree next_parm = parm;
> +  ipcp_transformation_summary *ts = ipcp_get_transformation_summary (node);
> +  if (!ts || vec_safe_length (ts->m_vr) == 0)
> +return;
> +  const vec  = *ts->m_vr;
> +  unsigned count = vr.length ();
> +
> +  for (unsigned i = 0; i < count; ++i, parm = next_parm)
> +{
> +  if (node->clone.combined_args_to_skip
> +   && bitmap_bit_p (node->clone.combined_args_to_skip, i))
> + continue;
> +  gcc_checking_assert (parm);
> +  next_parm = DECL_CHAIN (parm);
> +  tree ddef = ssa_default_def (DECL_STRUCT_FUNCTION (node->decl), parm);
> +
> +  if (!ddef || !is_gimple_reg (parm))
> + continue;
> +
> +  if (cgraph_local_p (node)
The test of cgraph_local_p seems redundant here. The analysis phase should not 
determine
anything if function is reachable non-locally.
> +/* Info about value ranges.  */
> +
> +struct GTY(()) ipa_vr
> +{
> +  /* The data fields below are valid only if known is true.  */
> +  bool known;
> +  enum value_range_type type;
> +  tree min;
> +  tree max;
What is the point of representing range as trees rather than wide ints. Can they
be non-constant integer?

The patch looks good to me otherwise!
Honza


Re: [RFC][IPA-VRP] Add support for IPA VRP in ipa-cp/ipa-prop

2016-07-19 Thread kugan

Hi Martin,


On 19/07/16 18:22, kugan wrote:

Hi Martin,

Thanks for the review.  I have revised the patch based on the review.
Please see the comments below.



Maybe it is better to separate value range and alignment summary 
writing/reading to different functions. Here is another updated version 
which does this.
This should be more readable and easy to maintain. Bootstrapped (LTO and 
normal) and regression tested on x86-64-linux. There are few test-case 
regressions which I am looking int:


Tests that now fail, but worked before:

27_io/basic_istream/get/char/1.cc execution test
g++.dg/ipa/pure-const-3.C  -std=gnu++11  scan-tree-dump optimized "barvar"
g++.dg/ipa/pure-const-3.C  -std=gnu++14  scan-tree-dump optimized "barvar"
g++.dg/ipa/pure-const-3.C  -std=gnu++98  scan-tree-dump optimized "barvar"
gcc.dg/guality/pr54519-1.c   -O2 -flto -fuse-linker-plugin 
-fno-fat-lto-objects  line 20 y == 25
gcc.dg/guality/pr54519-1.c   -O2 -flto -fuse-linker-plugin 
-fno-fat-lto-objects  line 23 y == 117
gcc.dg/torture/ftrapv-1.c   -O2 -flto -fuse-linker-plugin 
-fno-fat-lto-objects  execution test


New tests that FAIL:

gcc.dg/guality/pr54519-1.c   -O2 -flto -fuse-linker-plugin 
-fno-fat-lto-objects  line 20 z == 6
gcc.dg/guality/pr54519-1.c   -O2 -flto -fuse-linker-plugin 
-fno-fat-lto-objects  line 23 z == 8
gcc.dg/tree-ssa/pr22117.c scan-tree-dump-times evrp "Folding predicate 
r_.* != 0B to 0" 1


I will send the patch with testcase fix and Changelog based on the 
preference.



Thanks,
Kugan
>From 7fe2e29a6ade143c6826a5738e1430fcbe09b05e Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah 
Date: Tue, 21 Jun 2016 12:43:01 +1000
Subject: [PATCH 5/6] Add ipa vrp

---
 gcc/common.opt  |   4 +
 gcc/ipa-cp.c| 237 +++-
 gcc/ipa-prop.c  | 214 
 gcc/ipa-prop.h  |  17 +++
 gcc/testsuite/gcc.dg/ipa/vrp1.c |  32 ++
 gcc/testsuite/gcc.dg/ipa/vrp2.c |  35 ++
 gcc/testsuite/gcc.dg/ipa/vrp3.c |  30 +
 7 files changed, 548 insertions(+), 21 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp1.c
 create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp2.c
 create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp3.c

diff --git a/gcc/common.opt b/gcc/common.opt
index 29d0e4d..7e3ab5f 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2475,6 +2475,10 @@ ftree-evrp
 Common Report Var(flag_tree_early_vrp) Init(1) Optimization
 Perform Early Value Range Propagation on trees.
 
+fipa-vrp
+Common Report Var(flag_ipa_vrp) Init(1) Optimization
+Perform IPA Value Range Propagation.
+
 fsplit-paths
 Common Report Var(flag_split_paths) Init(0) Optimization
 Split paths leading to loop backedges.
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index 4b7f6bb..760e9da 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -120,6 +120,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "params.h"
 #include "ipa-inline.h"
 #include "ipa-utils.h"
+#include "tree-vrp.h"
 
 template  class ipcp_value;
 
@@ -266,6 +267,25 @@ private:
   bool meet_with_1 (unsigned new_align, unsigned new_misalign);
 };
 
+/* Lattice of value ranges.  */
+
+class ipcp_vr_lattice
+{
+public:
+  value_range m_vr;
+
+  inline bool bottom_p () const;
+  inline bool top_p () const;
+  inline bool set_to_bottom ();
+  bool meet_with (const value_range *p_vr);
+  bool meet_with (const ipcp_vr_lattice );
+  void init () { m_vr.type = VR_UNDEFINED; }
+  void print (FILE * f);
+
+private:
+  bool meet_with_1 (const value_range *other_vr);
+};
+
 /* Structure containing lattices for a parameter itself and for pieces of
aggregates that are passed in the parameter or by a reference in a parameter
plus some other useful flags.  */
@@ -281,6 +301,8 @@ public:
   ipcp_agg_lattice *aggs;
   /* Lattice describing known alignment.  */
   ipcp_alignment_lattice alignment;
+  /* Lattice describing value range.  */
+  ipcp_vr_lattice m_value_range;
   /* Number of aggregate lattices */
   int aggs_count;
   /* True if aggregate data were passed by reference (as opposed to by
@@ -348,6 +370,16 @@ ipa_get_poly_ctx_lat (struct ipa_node_params *info, int i)
   return >ctxlat;
 }
 
+/* Return the lattice corresponding to the value range of the Ith formal
+   parameter of the function described by INFO.  */
+
+static inline ipcp_vr_lattice *
+ipa_get_vr_lat (struct ipa_node_params *info, int i)
+{
+  struct ipcp_param_lattices *plats = ipa_get_parm_lattices (info, i);
+  return >m_value_range;
+}
+
 /* Return whether LAT is a lattice with a single constant and without an
undefined value.  */
 
@@ -458,6 +490,14 @@ ipcp_alignment_lattice::print (FILE * f)
 fprintf (f, " Alignment %u, misalignment %u\n", align, misalign);
 }
 
+/* Print value range lattice to F.  */
+
+void
+ipcp_vr_lattice::print (FILE * f)
+{
+  dump_value_range (f, _vr);
+}
+
 /* Print all ipcp_lattices of all 

Re: [RFC][IPA-VRP] Add support for IPA VRP in ipa-cp/ipa-prop

2016-07-19 Thread kugan

Hi Martin,

Thanks for the review.  I have revised the patch based on the review. 
Please see the comments below.


On 15/07/16 22:23, Martin Jambor wrote:

Hi,

thanks for working on extending IPA-CP in this way.  I do have a few
comments though:

On Fri, Jul 15, 2016 at 02:46:50PM +1000, kugan wrote:

Hi,

This patch extends ipa-cp/ipa-prop infrastructure to handle propagation of
VR.
Thanks,

Kugan

gcc/testsuite/ChangeLog:

2016-07-14  Kugan Vivekanandarajah  

 * gcc.dg/ipa/vrp1.c: New test.
 * gcc.dg/ipa/vrp2.c: New test.
 * gcc.dg/ipa/vrp3.c: New test.

gcc/ChangeLog:

2016-07-14  Kugan Vivekanandarajah  

 * common.opt: New option -fipa-vrp.
 * ipa-cp.c (ipa_get_vr_lat): New.
 (ipcp_vr_lattice::print): Likewise.
 (print_all_lattices): Call ipcp_vr_lattice::print.
 (ipcp_vr_lattice::meet_with): New.
 (ipcp_vr_lattice::meet_with_1): Likewise.
 (ipcp_vr_lattice::top_p): Likewise.
 (ipcp_vr_lattice::bottom_p): Likewsie.
 (ipcp_vr_lattice::set_to_bottom): Likewise.
 (set_all_contains_variable): Call VR set_to_bottom.
 (initialize_node_lattices): Init VR lattices.
 (propagate_vr_accross_jump_function): New.
 (propagate_constants_accross_call): Call
 propagate_vr_accross_jump_function.
 (ipcp_store_alignment_results): Rename to
 ipcp_store_alignment_and_vr_results and handke VR.
 * ipa-prop.c (ipa_set_jf_unknown):
 (ipa_compute_jump_functions_for_edge): Handle Value Range.
 (ipa_node_params_t::duplicate): Likewise.
 (ipa_write_jump_function): Likewise.
 (ipa_read_jump_function): Likewise.
 (write_ipcp_transformation_info): Likewise.
 (read_ipcp_transformation_info): Likewise.
 (ipcp_update_alignments): Rename to ipcp_update_vr_and_alignments
 and handle VR.




 From 092cbccd79c3859ff24846bb0e1892ef5d8086bc Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah 
Date: Tue, 21 Jun 2016 12:43:01 +1000
Subject: [PATCH 5/6] Add ipa vrp

---
  gcc/common.opt  |   4 +
  gcc/ipa-cp.c| 220 +++-
  gcc/ipa-prop.c  | 110 ++--
  gcc/ipa-prop.h  |  16 +++
  gcc/testsuite/gcc.dg/ipa/vrp1.c |  32 ++
  gcc/testsuite/gcc.dg/ipa/vrp2.c |  35 +++
  gcc/testsuite/gcc.dg/ipa/vrp3.c |  30 ++
  7 files changed, 433 insertions(+), 14 deletions(-)
  create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp1.c
  create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp2.c
  create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp3.c

diff --git a/gcc/common.opt b/gcc/common.opt
index 29d0e4d..7bf7305 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2475,6 +2475,10 @@ ftree-evrp
  Common Report Var(flag_tree_early_vrp) Init(1) Optimization
  Perform Early Value Range Propagation on trees.

+fipa-vrp
+ommon Report Var(flag_ipa_vrp) Init(1) Optimization


Common


Done.




+Perform IPA Value Range Propagation on trees.


I think that nowadays we should omit the "on trees" part, they are not
particularly useful.



Done.


+
  fsplit-paths
  Common Report Var(flag_split_paths) Init(0) Optimization
  Split paths leading to loop backedges.
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index 4b7f6bb..97cd04b 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -120,6 +120,7 @@ along with GCC; see the file COPYING3.  If not see
  #include "params.h"
  #include "ipa-inline.h"
  #include "ipa-utils.h"
+#include "tree-vrp.h"

  template  class ipcp_value;

@@ -266,6 +267,25 @@ private:
bool meet_with_1 (unsigned new_align, unsigned new_misalign);
  };

+/* Lattice of value ranges.  */
+
+class ipcp_vr_lattice
+{
+public:
+  value_range vr;
+
+  inline bool bottom_p () const;
+  inline bool top_p () const;
+  inline bool set_to_bottom ();
+  bool meet_with (const value_range *vr);


Please do not call the parameter the same name as that of a member
variable, that might become very confusing in future.


Done.


+  bool meet_with (const ipcp_vr_lattice );
+  void init () { vr.type = VR_UNDEFINED; }
+  void print (FILE * f);
+
+private:
+  bool meet_with_1 (const value_range *vr);


Likewise.

I know that no other classes in the file do, but if you want to
strictly follow the GCC coding style, member vr should be called m_vr.
Perhaps I should add the m_ prefixes to other classes as well, I am
becoming to appreciate them.



Done.


+};
+
  /* Structure containing lattices for a parameter itself and for pieces of
 aggregates that are passed in the parameter or by a reference in a 
parameter
 plus some other useful flags.  */
@@ -281,6 +301,8 @@ public:
ipcp_agg_lattice *aggs;
/* Lattice describing known alignment.  */
ipcp_alignment_lattice alignment;
+  /* Lattice describing value range.  */
+  ipcp_vr_lattice vr;
/* Number of 

Re: [RFC][IPA-VRP] Add support for IPA VRP in ipa-cp/ipa-prop

2016-07-17 Thread Prathamesh Kulkarni
On 15 July 2016 at 05:46, kugan  wrote:
> Hi,
>
>
>
> This patch extends ipa-cp/ipa-prop infrastructure to handle propagation of
> VR.
Hi Kugan,
Just a small nit - perhaps you should modify
ipa_print_node_jump_functions_for_edge () to pretty-print
value ranges associated with the jump function.

Thanks,
Prathamesh
>
>
>
> Thanks,
>
> Kugan
>
>
>
>
>
> gcc/testsuite/ChangeLog:
>
>
>
> 2016-07-14  Kugan Vivekanandarajah  
>
>
>
> * gcc.dg/ipa/vrp1.c: New test.
>
> * gcc.dg/ipa/vrp2.c: New test.
>
> * gcc.dg/ipa/vrp3.c: New test.
>
>
>
>
>
> gcc/ChangeLog:
>
>
>
> 2016-07-14  Kugan Vivekanandarajah  
>
>
>
> * common.opt: New option -fipa-vrp.
>
> * ipa-cp.c (ipa_get_vr_lat): New.
>
> (ipcp_vr_lattice::print): Likewise.
>
> (print_all_lattices): Call ipcp_vr_lattice::print.
>
> (ipcp_vr_lattice::meet_with): New.
>
> (ipcp_vr_lattice::meet_with_1): Likewise.
>
> (ipcp_vr_lattice::top_p): Likewise.
>
> (ipcp_vr_lattice::bottom_p): Likewsie.
>
> (ipcp_vr_lattice::set_to_bottom): Likewise.
>
> (set_all_contains_variable): Call VR set_to_bottom.
>
> (initialize_node_lattices): Init VR lattices.
>
> (propagate_vr_accross_jump_function): New.
>
> (propagate_constants_accross_call): Call
>
> propagate_vr_accross_jump_function.
>
> (ipcp_store_alignment_results): Rename to
>
> ipcp_store_alignment_and_vr_results and handke VR.
>
> * ipa-prop.c (ipa_set_jf_unknown):
>
> (ipa_compute_jump_functions_for_edge): Handle Value Range.
>
> (ipa_node_params_t::duplicate): Likewise.
>
> (ipa_write_jump_function): Likewise.
>
> (ipa_read_jump_function): Likewise.
>
> (write_ipcp_transformation_info): Likewise.
>
> (read_ipcp_transformation_info): Likewise.
>
> (ipcp_update_alignments): Rename to ipcp_update_vr_and_alignments
>
> and handle VR.
>
>
>
>
>


Re: [RFC][IPA-VRP] Add support for IPA VRP in ipa-cp/ipa-prop

2016-07-15 Thread Martin Jambor
Hi,

thanks for working on extending IPA-CP in this way.  I do have a few
comments though:

On Fri, Jul 15, 2016 at 02:46:50PM +1000, kugan wrote:
> Hi,
> 
> This patch extends ipa-cp/ipa-prop infrastructure to handle propagation of
> VR.
> Thanks,
> 
> Kugan
> 
> gcc/testsuite/ChangeLog:
> 
> 2016-07-14  Kugan Vivekanandarajah  
> 
> * gcc.dg/ipa/vrp1.c: New test.
> * gcc.dg/ipa/vrp2.c: New test.
> * gcc.dg/ipa/vrp3.c: New test.
> 
> gcc/ChangeLog:
> 
> 2016-07-14  Kugan Vivekanandarajah  
> 
> * common.opt: New option -fipa-vrp.
> * ipa-cp.c (ipa_get_vr_lat): New.
> (ipcp_vr_lattice::print): Likewise.
> (print_all_lattices): Call ipcp_vr_lattice::print.
> (ipcp_vr_lattice::meet_with): New.
> (ipcp_vr_lattice::meet_with_1): Likewise.
> (ipcp_vr_lattice::top_p): Likewise.
> (ipcp_vr_lattice::bottom_p): Likewsie.
> (ipcp_vr_lattice::set_to_bottom): Likewise.
> (set_all_contains_variable): Call VR set_to_bottom.
> (initialize_node_lattices): Init VR lattices.
> (propagate_vr_accross_jump_function): New.
> (propagate_constants_accross_call): Call
> propagate_vr_accross_jump_function.
> (ipcp_store_alignment_results): Rename to
> ipcp_store_alignment_and_vr_results and handke VR.
> * ipa-prop.c (ipa_set_jf_unknown):
> (ipa_compute_jump_functions_for_edge): Handle Value Range.
> (ipa_node_params_t::duplicate): Likewise.
> (ipa_write_jump_function): Likewise.
> (ipa_read_jump_function): Likewise.
> (write_ipcp_transformation_info): Likewise.
> (read_ipcp_transformation_info): Likewise.
> (ipcp_update_alignments): Rename to ipcp_update_vr_and_alignments
> and handle VR.
> 

> From 092cbccd79c3859ff24846bb0e1892ef5d8086bc Mon Sep 17 00:00:00 2001
> From: Kugan Vivekanandarajah 
> Date: Tue, 21 Jun 2016 12:43:01 +1000
> Subject: [PATCH 5/6] Add ipa vrp
> 
> ---
>  gcc/common.opt  |   4 +
>  gcc/ipa-cp.c| 220 
> +++-
>  gcc/ipa-prop.c  | 110 ++--
>  gcc/ipa-prop.h  |  16 +++
>  gcc/testsuite/gcc.dg/ipa/vrp1.c |  32 ++
>  gcc/testsuite/gcc.dg/ipa/vrp2.c |  35 +++
>  gcc/testsuite/gcc.dg/ipa/vrp3.c |  30 ++
>  7 files changed, 433 insertions(+), 14 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp1.c
>  create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp2.c
>  create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp3.c
> 
> diff --git a/gcc/common.opt b/gcc/common.opt
> index 29d0e4d..7bf7305 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -2475,6 +2475,10 @@ ftree-evrp
>  Common Report Var(flag_tree_early_vrp) Init(1) Optimization
>  Perform Early Value Range Propagation on trees.
>  
> +fipa-vrp
> +ommon Report Var(flag_ipa_vrp) Init(1) Optimization

Common

> +Perform IPA Value Range Propagation on trees.

I think that nowadays we should omit the "on trees" part, they are not
particularly useful.

> +
>  fsplit-paths
>  Common Report Var(flag_split_paths) Init(0) Optimization
>  Split paths leading to loop backedges.
> diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
> index 4b7f6bb..97cd04b 100644
> --- a/gcc/ipa-cp.c
> +++ b/gcc/ipa-cp.c
> @@ -120,6 +120,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "params.h"
>  #include "ipa-inline.h"
>  #include "ipa-utils.h"
> +#include "tree-vrp.h"
>  
>  template  class ipcp_value;
>  
> @@ -266,6 +267,25 @@ private:
>bool meet_with_1 (unsigned new_align, unsigned new_misalign);
>  };
>  
> +/* Lattice of value ranges.  */
> +
> +class ipcp_vr_lattice
> +{
> +public:
> +  value_range vr;
> +
> +  inline bool bottom_p () const;
> +  inline bool top_p () const;
> +  inline bool set_to_bottom ();
> +  bool meet_with (const value_range *vr);

Please do not call the parameter the same name as that of a member
variable, that might become very confusing in future.

> +  bool meet_with (const ipcp_vr_lattice );
> +  void init () { vr.type = VR_UNDEFINED; }
> +  void print (FILE * f);
> +
> +private:
> +  bool meet_with_1 (const value_range *vr);

Likewise.

I know that no other classes in the file do, but if you want to
strictly follow the GCC coding style, member vr should be called m_vr.
Perhaps I should add the m_ prefixes to other classes as well, I am
becoming to appreciate them.

> +};
> +
>  /* Structure containing lattices for a parameter itself and for pieces of
> aggregates that are passed in the parameter or by a reference in a 
> parameter
> plus some other useful flags.  */
> @@ -281,6 +301,8 @@ public:
>ipcp_agg_lattice *aggs;
>/* Lattice describing known alignment.  */
>ipcp_alignment_lattice alignment;
> +  /* Lattice describing value range.  */
> +  ipcp_vr_lattice vr;
>/* Number of 

[RFC][IPA-VRP] Add support for IPA VRP in ipa-cp/ipa-prop

2016-07-14 Thread kugan

Hi,



This patch extends ipa-cp/ipa-prop infrastructure to handle propagation 
of VR.




Thanks,

Kugan





gcc/testsuite/ChangeLog:



2016-07-14  Kugan Vivekanandarajah  



* gcc.dg/ipa/vrp1.c: New test.

* gcc.dg/ipa/vrp2.c: New test.

* gcc.dg/ipa/vrp3.c: New test.





gcc/ChangeLog:



2016-07-14  Kugan Vivekanandarajah  



* common.opt: New option -fipa-vrp.

* ipa-cp.c (ipa_get_vr_lat): New.

(ipcp_vr_lattice::print): Likewise.

(print_all_lattices): Call ipcp_vr_lattice::print.

(ipcp_vr_lattice::meet_with): New.

(ipcp_vr_lattice::meet_with_1): Likewise.

(ipcp_vr_lattice::top_p): Likewise.

(ipcp_vr_lattice::bottom_p): Likewsie.

(ipcp_vr_lattice::set_to_bottom): Likewise.

(set_all_contains_variable): Call VR set_to_bottom.

(initialize_node_lattices): Init VR lattices.

(propagate_vr_accross_jump_function): New.

(propagate_constants_accross_call): Call

propagate_vr_accross_jump_function.

(ipcp_store_alignment_results): Rename to

ipcp_store_alignment_and_vr_results and handke VR.

* ipa-prop.c (ipa_set_jf_unknown):

(ipa_compute_jump_functions_for_edge): Handle Value Range.

(ipa_node_params_t::duplicate): Likewise.

(ipa_write_jump_function): Likewise.

(ipa_read_jump_function): Likewise.

(write_ipcp_transformation_info): Likewise.

(read_ipcp_transformation_info): Likewise.

(ipcp_update_alignments): Rename to ipcp_update_vr_and_alignments

and handle VR.





>From 092cbccd79c3859ff24846bb0e1892ef5d8086bc Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah 
Date: Tue, 21 Jun 2016 12:43:01 +1000
Subject: [PATCH 5/6] Add ipa vrp

---
 gcc/common.opt  |   4 +
 gcc/ipa-cp.c| 220 +++-
 gcc/ipa-prop.c  | 110 ++--
 gcc/ipa-prop.h  |  16 +++
 gcc/testsuite/gcc.dg/ipa/vrp1.c |  32 ++
 gcc/testsuite/gcc.dg/ipa/vrp2.c |  35 +++
 gcc/testsuite/gcc.dg/ipa/vrp3.c |  30 ++
 7 files changed, 433 insertions(+), 14 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp1.c
 create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp2.c
 create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp3.c

diff --git a/gcc/common.opt b/gcc/common.opt
index 29d0e4d..7bf7305 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2475,6 +2475,10 @@ ftree-evrp
 Common Report Var(flag_tree_early_vrp) Init(1) Optimization
 Perform Early Value Range Propagation on trees.
 
+fipa-vrp
+ommon Report Var(flag_ipa_vrp) Init(1) Optimization
+Perform IPA Value Range Propagation on trees.
+
 fsplit-paths
 Common Report Var(flag_split_paths) Init(0) Optimization
 Split paths leading to loop backedges.
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index 4b7f6bb..97cd04b 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -120,6 +120,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "params.h"
 #include "ipa-inline.h"
 #include "ipa-utils.h"
+#include "tree-vrp.h"
 
 template  class ipcp_value;
 
@@ -266,6 +267,25 @@ private:
   bool meet_with_1 (unsigned new_align, unsigned new_misalign);
 };
 
+/* Lattice of value ranges.  */
+
+class ipcp_vr_lattice
+{
+public:
+  value_range vr;
+
+  inline bool bottom_p () const;
+  inline bool top_p () const;
+  inline bool set_to_bottom ();
+  bool meet_with (const value_range *vr);
+  bool meet_with (const ipcp_vr_lattice );
+  void init () { vr.type = VR_UNDEFINED; }
+  void print (FILE * f);
+
+private:
+  bool meet_with_1 (const value_range *vr);
+};
+
 /* Structure containing lattices for a parameter itself and for pieces of
aggregates that are passed in the parameter or by a reference in a parameter
plus some other useful flags.  */
@@ -281,6 +301,8 @@ public:
   ipcp_agg_lattice *aggs;
   /* Lattice describing known alignment.  */
   ipcp_alignment_lattice alignment;
+  /* Lattice describing value range.  */
+  ipcp_vr_lattice vr;
   /* Number of aggregate lattices */
   int aggs_count;
   /* True if aggregate data were passed by reference (as opposed to by
@@ -348,6 +370,15 @@ ipa_get_poly_ctx_lat (struct ipa_node_params *info, int i)
   return >ctxlat;
 }
 
+/* Return the lattice corresponding to the value range of the Ith formal
+   parameter of the function described by INFO.  */
+static inline ipcp_vr_lattice *
+ipa_get_vr_lat (struct ipa_node_params *info, int i)
+{
+  struct ipcp_param_lattices *plats = ipa_get_parm_lattices (info, i);
+  return >vr;
+}
+
 /* Return whether LAT is a lattice with a single constant and without an
undefined value.  */
 
@@ -458,6 +489,16 @@ ipcp_alignment_lattice::print (FILE * f)
 fprintf (f, " Alignment %u, misalignment %u\n", align, misalign);
 }
 
+/* Print vr lattice to F.  */
+
+void