IPA currently tries to manually fix up function local addresses found
in a prange in two different locations.
This patch provides a method for the range to remove such addresses, and
moves this removal to a central place (ipa_get_value_range). Then removes
the special code from the other two locations.
Bootstraps on x86_64-pc-linux-gnu with no regressions. OK?
Andrew
gcc/
* ipa-prop.cc (ipa_get_value_range_1): Rename from ipa_get_value_range.
(ipa_get_value_range): Remove any function local addresses first.
(ipa_set_jfunc_vr): Address stripping moved to ipa_get_value_range.
(ipa_record_return_value_range_1): Remove local address code.
* value-range.cc (prange::clear_function_local_addr): New.
* value-range.h (prange::clear_function_local_addr): New prototype.
gcc/testsuite/
* gcc.dg/ipa/ipa-prange-local-addr-1.c: Adjust output check.
---
gcc/ipa-prop.cc | 52 +++++++------------
.../gcc.dg/ipa/ipa-prange-local-addr-1.c | 2 +-
gcc/value-range.cc | 15 ++++++
gcc/value-range.h | 3 ++
4 files changed, 37 insertions(+), 35 deletions(-)
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 8f7cf8556ba..69628bf962a 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -2375,7 +2375,7 @@ ipa_get_callee_param_type (struct cgraph_edge *e, int i)
ipa_vr_hash_table or allocate it in GC memory. */
static ipa_vr *
-ipa_get_value_range (const vrange &tmp)
+ipa_get_value_range_1 (const vrange &tmp)
{
inchash::hash hstate;
inchash::add_vrange (tmp, hstate);
@@ -2389,11 +2389,11 @@ ipa_get_value_range (const vrange &tmp)
return vr;
}
-/* Assign to JF a pointer to a range just like TMP but either fetch a
- copy from ipa_vr_hash_table or allocate a new on in GC memory. */
+/* Wrapper around ipa_get_value_range_1 which will remove any local pointer
+ information from prange. */
-static void
-ipa_set_jfunc_vr (ipa_jump_func *jf, const vrange &tmp)
+static ipa_vr *
+ipa_get_value_range (const vrange &tmp)
{
/* A points-to that names something only invariant within the caller --
the address of one of its locals, say -- must not travel to the callee.
@@ -2402,24 +2402,27 @@ ipa_set_jfunc_vr (ipa_jump_func *jf, const vrange &tmp)
the bitmask remain valid. */
if (is_a <prange> (tmp))
{
- const prange &pr = as_a <prange> (tmp);
- tree t = pr.addr_known ();
- if (!t)
- t = pr.addr_excluded ();
- if (t && !is_gimple_ip_invariant (t))
+ prange pr = as_a <prange> (tmp);
+ if (pr.clear_function_local_addr ())
{
if (dump_file && (dump_flags & TDF_DETAILS))
{
- fprintf (dump_file, "Dropping non ipa invariant points-to from ");
+ fprintf (dump_file, "Dropping function-local address from ");
tmp.dump (dump_file);
fprintf (dump_file, "\n");
}
- prange stripped = pr;
- stripped.set_addr_unknown ();
- jf->m_vr = ipa_get_value_range (stripped);
- return;
}
+ return ipa_get_value_range_1 (pr);
}
+ return ipa_get_value_range_1 (tmp);
+}
+
+/* Assign to JF a pointer to a range just like TMP but either fetch a
+ copy from ipa_vr_hash_table or allocate a new on in GC memory. */
+
+static void
+ipa_set_jfunc_vr (ipa_jump_func *jf, const vrange &tmp)
+{
jf->m_vr = ipa_get_value_range (tmp);
}
@@ -6034,25 +6037,6 @@ ipa_prop_write_jump_functions (void)
static void
ipa_record_return_value_range_1 (cgraph_node *n, value_range val)
{
- // Remove local invariant from return values.
- if (is_a<prange> (val))
- {
- const prange &pr = as_a <prange> (val);
- tree t = pr.addr_known ();
- if (!t)
- t = pr.addr_excluded ();
- if (t && !is_gimple_ip_invariant (t))
- {
- if (dump_file && (dump_flags & TDF_DETAILS))
- {
- fprintf (dump_file, "Could not record return range of %s:",
n->dump_name ());
- val.dump (dump_file);
- fprintf (dump_file, "\n");
- fprintf (dump_file, "Because uses non ipa invariant\n");
- }
- return;
- }
- }
if (!ipa_return_value_sum)
{
if (!ipa_vr_hash_table)
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-prange-local-addr-1.c
b/gcc/testsuite/gcc.dg/ipa/ipa-prange-local-addr-1.c
index baad06d1ca7..7a2e0a16542 100644
--- a/gcc/testsuite/gcc.dg/ipa/ipa-prange-local-addr-1.c
+++ b/gcc/testsuite/gcc.dg/ipa/ipa-prange-local-addr-1.c
@@ -29,4 +29,4 @@ top (int a, int b)
return flag;
}
-/* { dg-final { scan-ipa-dump "Dropping non ipa invariant points-to" "cp" } }
*/
+/* { dg-final { scan-ipa-dump "Dropping function-local address" "cp" } } */
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 8df26d8bff3..bfc196f8ad2 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -578,6 +578,21 @@ prange::set_addr (tree expr, bool known_p)
m_kind = VR_RANGE;
}
+
+// If addr is present and is an address that is local to its function,
+// clear it and return TRUE. otherwise do nothing and retiurn false.
+
+bool
+prange::clear_function_local_addr ()
+{
+ if (m_addr && !is_gimple_ip_invariant (m_addr))
+ {
+ set_addr_unknown ();
+ return true;
+ }
+ return false;
+}
+
// Return object/allocation the pointer refers into, otherwise NULL_TREE.
tree
diff --git a/gcc/value-range.h b/gcc/value-range.h
index 6762e60a662..10fb848dd4a 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -462,6 +462,9 @@ public:
void set_addr_unknown ();
bool addr_unknown_p () const;
+ // If addr is local to a function, clear it.
+ bool clear_function_local_addr ();
+
// Return expression or NULL_TREE for known or excluded.
tree addr_known () const;
tree addr_excluded () const;
--
2.56.0