From: Jan Hubicka Date: Wed, 18 Dec 2019 13:21:51 +0000 (+0100) Subject: ipa-param-manipulation.h (get_original_index): Declare. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c7ac9a0c7e3916f192ad41227e16238fd1fa2fbf;p=gcc.git ipa-param-manipulation.h (get_original_index): Declare. * ipa-param-manipulation.h (get_original_index): Declare. * ipa-param-manipulation.c (ipa_param_adjustments::get_original_index): New member function. * ipa-prop.c (ipcp_get_parm_bits): New function. * ipa-prop.h (ipcp_get_parm_bits): Declare. * tree-ssa-ccp.c: Include cgraph.h, alloc-pool.h, symbol-summary.h, ipa-utils.h and ipa-prop.h (get_default_value): Use ipcp_get_parm_bits. * gcc.dg/ipa/ipa-bit-cp.c: New testcase. * gcc.dg/ipa/ipa-bit-cp-1.c: New testcase. * gcc.dg/ipa/ipa-bit-cp-2.c: New testcase. Co-Authored-By: Martin Jambor From-SVN: r279523 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index eb5264dcc37..198aa78fd17 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2019-12-17 Jan Hubicka + Martin Jambor + + * ipa-param-manipulation.h (get_original_index): Declare. + * ipa-param-manipulation.c (ipa_param_adjustments::get_original_index): + New member function. + * ipa-prop.c (ipcp_get_parm_bits): New function. + * ipa-prop.h (ipcp_get_parm_bits): Declare. + * tree-ssa-ccp.c: Include cgraph.h, alloc-pool.h, symbol-summary.h, + ipa-utils.h and ipa-prop.h + (get_default_value): Use ipcp_get_parm_bits. + 2019-12-18 Jakub Jelinek PR lto/92972 diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c index 28ac2b8ad6e..b756b5d2281 100644 --- a/gcc/ipa-param-manipulation.c +++ b/gcc/ipa-param-manipulation.c @@ -324,6 +324,18 @@ ipa_param_adjustments::get_updated_indices (vec *new_indices) } } +/* Return the original index for the given new parameter index. Return a + negative number if not available. */ + +int +ipa_param_adjustments::get_original_index (int newidx) +{ + const ipa_adjusted_param *adj = &(*m_adj_params)[newidx]; + if (adj->op != IPA_PARAM_OP_COPY) + return -1; + return adj->base_index; +} + /* Return true if the first parameter (assuming there was one) survives the transformation intact and remains the first one. */ diff --git a/gcc/ipa-param-manipulation.h b/gcc/ipa-param-manipulation.h index 8e9554563e4..5d7278e0d1b 100644 --- a/gcc/ipa-param-manipulation.h +++ b/gcc/ipa-param-manipulation.h @@ -258,6 +258,9 @@ public: void get_surviving_params (vec *surviving_params); /* Fill a vector with new indices of surviving original parameters. */ void get_updated_indices (vec *new_indices); + /* Return the original index for the given new parameter index. Return a + negative number if not available. */ + int get_original_index (int newidx); void dump (FILE *f); void debug (); diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 1a59c3554f5..c9c6a827d08 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -5480,6 +5480,43 @@ ipcp_modif_dom_walker::before_dom_children (basic_block bb) return NULL; } +/* Return true if we have recorded VALUE and MASK about PARM. + Set VALUE and MASk accordingly. */ + +bool +ipcp_get_parm_bits (tree parm, tree *value, widest_int *mask) +{ + cgraph_node *cnode = cgraph_node::get (current_function_decl); + ipcp_transformation *ts = ipcp_get_transformation_summary (cnode); + if (!ts || vec_safe_length (ts->bits) == 0) + return false; + + int i = 0; + for (tree p = DECL_ARGUMENTS (current_function_decl); + p != parm; p = DECL_CHAIN (p)) + { + i++; + /* Ignore static chain. */ + if (!p) + return false; + } + + if (cnode->clone.param_adjustments) + { + i = cnode->clone.param_adjustments->get_original_index (i); + if (i < 0) + return false; + } + + vec &bits = *ts->bits; + if (!bits[i]) + return false; + *mask = bits[i]->mask; + *value = wide_int_to_tree (TREE_TYPE (parm), bits[i]->value); + return true; +} + + /* Update bits info of formal parameters as described in ipcp_transformation. */ diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index 1958e1ee9cc..4ce367a23ab 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -1041,6 +1041,7 @@ ipa_agg_value_set ipa_agg_value_set_from_jfunc (ipa_node_params *, void ipa_dump_param (FILE *, class ipa_node_params *info, int i); void ipa_release_body_info (struct ipa_func_body_info *); tree ipa_get_callee_param_type (struct cgraph_edge *e, int i); +bool ipcp_get_parm_bits (tree, tree *, widest_int *); /* From tree-sra.c: */ tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5dcd460deab..bcdfaa89c90 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-12-17 Jan Hubicka + Martin Jambor + + * gcc.dg/ipa/ipa-bit-cp.c: New testcase. + * gcc.dg/ipa/ipa-bit-cp-1.c: New testcase. + * gcc.dg/ipa/ipa-bit-cp-2.c: New testcase. + 2019-12-18 Andrew Stubbs * gcc.dg/vect/pr65947-8.c: Change pass conditions for amdgcn. diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-bit-cp-1.c b/gcc/testsuite/gcc.dg/ipa/ipa-bit-cp-1.c new file mode 100644 index 00000000000..2ec5fe54f55 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-bit-cp-1.c @@ -0,0 +1,16 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -w -fipa-bit-cp" } */ +static int +__attribute__ ((noinline)) +test (int a) +{ + if (!(a&2)) + link_error (); +} +main() +{ + test (2); + test (3); + test (6); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-bit-cp-2.c b/gcc/testsuite/gcc.dg/ipa/ipa-bit-cp-2.c new file mode 100644 index 00000000000..42ce346948c --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-bit-cp-2.c @@ -0,0 +1,19 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -w -fipa-bit-cp" } */ +static int +__attribute__ ((noinline)) +test (int __attribute__((unused)) b, int a) +{ + if (!(a&2)) + link_error (); +} + +extern int __attribute__((const)) getint (); + +main() +{ + test (getint(), 2); + test (getint(), 3); + test (getint(), 6); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-bit-cp.c b/gcc/testsuite/gcc.dg/ipa/ipa-bit-cp.c new file mode 100644 index 00000000000..2ec5fe54f55 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-bit-cp.c @@ -0,0 +1,16 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -w -fipa-bit-cp" } */ +static int +__attribute__ ((noinline)) +test (int a) +{ + if (!(a&2)) + link_error (); +} +main() +{ + test (2); + test (3); + test (6); + return 0; +} diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index 72e15b1c99e..a77c03625ed 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -146,6 +146,11 @@ along with GCC; see the file COPYING3. If not see #include "stringpool.h" #include "attribs.h" #include "tree-vector-builder.h" +#include "cgraph.h" +#include "alloc-pool.h" +#include "symbol-summary.h" +#include "ipa-utils.h" +#include "ipa-prop.h" /* Possible lattice values. */ typedef enum @@ -292,11 +297,26 @@ get_default_value (tree var) if (flag_tree_bit_ccp) { wide_int nonzero_bits = get_nonzero_bits (var); - if (nonzero_bits != -1) + tree value; + widest_int mask; + + if (SSA_NAME_VAR (var) + && TREE_CODE (SSA_NAME_VAR (var)) == PARM_DECL + && ipcp_get_parm_bits (SSA_NAME_VAR (var), &value, &mask)) + { + val.lattice_val = CONSTANT; + val.value = value; + val.mask = mask; + if (nonzero_bits != -1) + val.mask &= extend_mask (nonzero_bits, + TYPE_SIGN (TREE_TYPE (var))); + } + else if (nonzero_bits != -1) { val.lattice_val = CONSTANT; val.value = build_zero_cst (TREE_TYPE (var)); - val.mask = extend_mask (nonzero_bits, TYPE_SIGN (TREE_TYPE (var))); + val.mask = extend_mask (nonzero_bits, + TYPE_SIGN (TREE_TYPE (var))); } } }