]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ipa-param-manipulation.h (get_original_index): Declare.
authorJan Hubicka <hubicka@ucw.cz>
Wed, 18 Dec 2019 13:21:51 +0000 (14:21 +0100)
committerJan Hubicka <hubicka@gcc.gnu.org>
Wed, 18 Dec 2019 13:21:51 +0000 (13:21 +0000)
* 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 <mjambor@suse.cz>
From-SVN: r279523

gcc/ChangeLog
gcc/ipa-param-manipulation.c
gcc/ipa-param-manipulation.h
gcc/ipa-prop.c
gcc/ipa-prop.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/ipa/ipa-bit-cp-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/ipa/ipa-bit-cp-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/ipa/ipa-bit-cp.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c

index eb5264dcc379a11fa638b7a51d5c2a47c671de9c..198aa78fd170c522ef707d2e7a77e621b0501f1a 100644 (file)
@@ -1,3 +1,15 @@
+2019-12-17  Jan Hubicka  <hubicka@ucw.cz>
+           Martin Jambor  <mjambor@suse.cz>
+
+       * 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  <jakub@redhat.com>
 
        PR lto/92972
index 28ac2b8ad6e7fba2599d76e08bfb4e1a4875cca6..b756b5d2281bc768dcdc606dd4dd9605cccde8e7 100644 (file)
@@ -324,6 +324,18 @@ ipa_param_adjustments::get_updated_indices (vec<int> *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.  */
 
index 8e9554563e4e4f49f41be17bc08310bf9443c322..5d7278e0d1b745393d08316b97827964393a8ff5 100644 (file)
@@ -258,6 +258,9 @@ public:
   void get_surviving_params (vec<bool> *surviving_params);
   /* Fill a vector with new indices of surviving original parameters.  */
   void get_updated_indices (vec<int> *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 ();
index 1a59c3554f521d9349da5dec2e44caf14812225e..c9c6a827d0828b2b75390e80c64fc49e90e9a74f 100644 (file)
@@ -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<ipa_bits *, va_gc> &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.  */
 
index 1958e1ee9cc37490f4871802ca6aff5846be2624..4ce367a23ab06c1b30a97fd38ae543c62d0b5ab1 100644 (file)
@@ -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,
index 5dcd460deabada8f22567f8cc7cdc68f71d1a651..bcdfaa89c903f070c9fe14cabec073ee29870c8c 100644 (file)
@@ -1,3 +1,10 @@
+2019-12-17  Jan Hubicka  <hubicka@ucw.cz>
+           Martin Jambor  <mjambor@suse.cz>
+
+       * 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  <ams@codesourcery.com>
 
        * 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 (file)
index 0000000..2ec5fe5
--- /dev/null
@@ -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 (file)
index 0000000..42ce346
--- /dev/null
@@ -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 (file)
index 0000000..2ec5fe5
--- /dev/null
@@ -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;
+}
index 72e15b1c99eaf89d4952fd56b06e8b1faf51b530..a77c03625ed80b341f4c9cebfb6c62142d98d537 100644 (file)
@@ -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)));
                }
            }
        }