I was planning to keep pt.null and non-zero ranges in sync with each
other for a while, but it turns out that isn't necessary.
Thre is only one place (!!!!) that actually sets pt.null to 0 (meaning
the range is nonnull) It is in tree-ssa-structalias.cc
find_what_p_points_to() and it determines nonnullness based on :
get_range_query (DECL_STRUCT_FUNCTION (fndecl))->range_of_expr (vr, p);
bool nonnull = !vr.contains_zero_p ();
<..>
if (nonnull)
set_ptr_nonnull (p);
So it is only setting nonnull in pt_solution if the range is already
nonzero. It might be possible we dont even need to do this now... but
its unclear to me whether that query may sometimes pick up information
from the pass and transferring it to the global range that might not
have been there before. I expect we can remove it and I'll try a run
with an assert... but that can be a follow on.
Therefore, this patch removes null from the pt_solution and adjusts
callers and utilities, leaving that single set_ptr_nonnull call.
Queries that use to use !pt.null are now replaced with
ptr_nonnull_p (name).
This also means pt_solution no longer contains any flow sensitive range
information, so there are numerous cleanup/adjustments for that.
Bootstraps on x86_64-pc-linux-gnu with no regressions. OK?
Andrew
The null field in pt_solution is a remnant from when no range
for a pointer was stored, and an extra bit in the alias structure
was ultized to communicate non-nullness. This is now fully tracked
by a prange, and is no longer needed.
Add a couple of helpers as well to prange_storage and ptr_nonnull_p ()
now replaces !pt.null as a query.
This also means that a pt_solution no longer has any flow sensitive
information in it, and that pointers are no longer "special" from that
perspective.
gcc/
* gimple-pretty-print.cc (pp_points_to_solution): Do not print
null field.
* tree-ssa-alias.cc (ptrs_compare_unequal): Use ptr_nonnull_p.
(dump_points_to_solution): Don't print null field.
(same_addr_size_stores_p): Use ptr_nonnull_p.
* tree-ssa-alias.h (pt_solution::null): Remove bit member.
* tree-ssa-structalias.cc (find_what_var_points_to): Ignore null.
(find_what_p_points_to): Likewise.
(pt_solution_reset): Likewise.
(pt_solution_ior_into): Likewise.
(ipa_escaped_pt): Don't set null field.
* tree-ssanames.cc (set_range_info): Do not check pt_solution
for the null field.
(ptr_nonnull_p): New.
(set_ptr_nonnull): Update to Remove 0 from the range.
(reset_flow_sensitive_info): No need to clear the null field
in pt_solution.
(flow_sensitive_info_storage::save): Move to header.
(flow_sensitive_info_storage::restore): Move to header.
(flow_sensitive_info_storage::ave_and_clear: Move to header.
(flow_sensitive_info_storage::clear_storage: Move to header.
* tree-ssanames.h (ptr_nonnull_p): New prototype.
(flow_sensitive_info_storage::save): Simplify and inline.
(flow_sensitive_info_storage::restore): Likewise.
(flow_sensitive_info_storage::ave_and_clear): Likewise.
(flow_sensitive_info_storage::clear_storage): Likewise.
(flow_sensitive_info_storage::null): Remove member.
* value-query.cc (get_ssa_name_ptr_info_nonnull): Delete.
(gimple_range_global): Do not check pt_solution null field.
* value-range-storage.cc (prange_storage::set_nonnull): New.
* value-range-storage.h (prange_storage::nonnull_p): New.
(prange_storage::set_nonnull): New prototype.
gcc/testsuite/
* gcc.dg/torture/pr39074-2.c: Remove NULL from pt output.
* gcc.dg/torture/pr39074.c: Likewise.
---
gcc/gimple-pretty-print.cc | 2 -
gcc/testsuite/gcc.dg/torture/pr39074-2.c | 2 +-
gcc/testsuite/gcc.dg/torture/pr39074.c | 2 +-
gcc/tree-ssa-alias.cc | 9 +--
gcc/tree-ssa-alias.h | 4 -
gcc/tree-ssa-structalias.cc | 12 +--
gcc/tree-ssanames.cc | 93 +++++-------------------
gcc/tree-ssanames.h | 39 +++++++---
gcc/value-query.cc | 40 ++--------
gcc/value-range-storage.cc | 46 ++++++++++++
gcc/value-range-storage.h | 24 ++++++
11 files changed, 131 insertions(+), 142 deletions(-)
diff --git a/gcc/gimple-pretty-print.cc b/gcc/gimple-pretty-print.cc
index 69148dd5cbd..1af0910f148 100644
--- a/gcc/gimple-pretty-print.cc
+++ b/gcc/gimple-pretty-print.cc
@@ -822,8 +822,6 @@ pp_points_to_solution (pretty_printer *pp, const
pt_solution *pt)
pp_string (pp, "escaped ");
if (pt->ipa_escaped)
pp_string (pp, "unit-escaped ");
- if (pt->null)
- pp_string (pp, "null ");
if (pt->const_pool)
pp_string (pp, "const-pool ");
if (pt->vars
diff --git a/gcc/testsuite/gcc.dg/torture/pr39074-2.c
b/gcc/testsuite/gcc.dg/torture/pr39074-2.c
index 16c10e88277..ea9c0d3e9d2 100644
--- a/gcc/testsuite/gcc.dg/torture/pr39074-2.c
+++ b/gcc/testsuite/gcc.dg/torture/pr39074-2.c
@@ -31,4 +31,4 @@ int main()
}
/* { dg-final { scan-tree-dump "y.\?.._. = { i }" "alias" } } */
-/* { dg-final { scan-tree-dump "y.\?.._., points-to NULL, points-to
vars: { D..... }" "alias" } } */
+/* { dg-final { scan-tree-dump "y.\?.._., points-to vars: { D..... }"
"alias" } } */
diff --git a/gcc/testsuite/gcc.dg/torture/pr39074.c
b/gcc/testsuite/gcc.dg/torture/pr39074.c
index eec4873405d..d28b35e118e 100644
--- a/gcc/testsuite/gcc.dg/torture/pr39074.c
+++ b/gcc/testsuite/gcc.dg/torture/pr39074.c
@@ -30,4 +30,4 @@ int main()
}
/* { dg-final { scan-tree-dump "y.\?.._. = { i }" "alias" } } */
-/* { dg-final { scan-tree-dump "y.\?.._., points-to NULL, points-to
vars: { D..... }" "alias" } } */
+/* { dg-final { scan-tree-dump "y.\?.._., points-to vars: { D..... }"
"alias" } } */
diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index 23490c07ecd..41072b4d5d9 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -516,7 +516,7 @@ ptrs_compare_unequal (tree ptr1, tree ptr2)
|| pt1->vars_contains_restrict
|| pt1->vars_contains_interposable)
return false;
- if (integer_zerop (ptr2) && !pt1->null)
+ if (integer_zerop (ptr2) && ptr_nonnull_p (ptr1))
return true;
if (TREE_CODE (ptr2) == SSA_NAME)
{
@@ -525,7 +525,7 @@ ptrs_compare_unequal (tree ptr1, tree ptr2)
|| pt2->vars_contains_restrict
|| pt2->vars_contains_interposable)
return false;
- if ((!pt1->null || !pt2->null)
+ if ((ptr_nonnull_p (ptr1) || ptr_nonnull_p (ptr2))
/* ??? We do not represent FUNCTION_DECL and LABEL_DECL
in pt.vars but only set pt.vars_contains_nonlocal. This
makes compares involving those and other nonlocals
@@ -683,9 +683,6 @@ dump_points_to_solution (FILE *file, const
pt_solution *pt)
if (pt->ipa_escaped)
fprintf (file, ", points-to unit escaped");
- if (pt->null)
- fprintf (file, ", points-to NULL");
-
if (pt->const_pool)
fprintf (file, ", points-to const-pool");
@@ -3399,7 +3396,7 @@ same_addr_size_stores_p (tree base1, poly_int64
offset1, poly_int64 size1,
/* Be conservative with non-call exceptions when the address might
be NULL. */
- if (cfun->can_throw_non_call_exceptions && pt->null)
+ if (cfun->can_throw_non_call_exceptions && !ptr_nonnull_p (ptr))
return false;
/* Check that ptr points relative to obj. */
diff --git a/gcc/tree-ssa-alias.h b/gcc/tree-ssa-alias.h
index 2e6344a0b6e..a67293ae4ae 100644
--- a/gcc/tree-ssa-alias.h
+++ b/gcc/tree-ssa-alias.h
@@ -43,10 +43,6 @@ struct GTY(()) pt_solution
reference. */
unsigned int ipa_escaped : 1;
- /* Nonzero if the points-to set includes 'nothing', the points-to set
- includes memory at address NULL. */
- unsigned int null : 1;
-
/* Nonzero if the points-to set includes a readonly object like a
STRING_CST that does not have an underlying declaration but will
end up in the constant pool. */
diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc
index 1db7c69be65..af8100d49a5 100644
--- a/gcc/tree-ssa-structalias.cc
+++ b/gcc/tree-ssa-structalias.cc
@@ -874,11 +874,9 @@ find_what_var_points_to (tree fndecl, varinfo_t
orig_vi)
{
varinfo_t vi = get_varinfo (i);
- if (vi->is_artificial_var)
+ if (vi->is_artificial_var && vi->id != nothing_id)
{
- if (vi->id == nothing_id)
- pt->null = 1;
- else if (vi->id == escaped_id)
+ if (vi->id == escaped_id)
{
if (in_ipa_mode)
pt->ipa_escaped = 1;
@@ -948,8 +946,6 @@ find_what_p_points_to (tree fndecl, tree p)
return;
pt_solution pt = find_what_var_points_to (fndecl, vi);
- /* Conservatively set to NULL from PTA (to true). */
- pt.null = 1;
set_ssa_name_pt_solution (p, pt);
/* Preserve pointer nonnull globally computed. */
if (nonnull)
@@ -993,7 +989,6 @@ pt_solution_reset (struct pt_solution *pt)
{
memset (pt, 0, sizeof (struct pt_solution));
pt->anything = true;
- pt->null = true;
}
/* Set the points-to solution *PT to point only to the variables
@@ -1046,7 +1041,6 @@ pt_solution_ior_into (struct pt_solution *dest,
struct pt_solution *src)
dest->nonlocal |= src->nonlocal;
dest->escaped |= src->escaped;
dest->ipa_escaped |= src->ipa_escaped;
- dest->null |= src->null;
dest->const_pool |= src->const_pool ;
dest->vars_contains_nonlocal |= src->vars_contains_nonlocal;
dest->vars_contains_escaped |= src->vars_contains_escaped;
@@ -1834,7 +1828,7 @@ make_pass_build_ealias (gcc::context *ctxt)
/* IPA PTA solutions for ESCAPED. */
struct pt_solution ipa_escaped_pt
- = { true, false, false, false, false, false,
+ = { true, false, false, false, false,
false, false, false, false, false, false, NULL };
diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index 680f795f4ff..827aed0ab80 100644
--- a/gcc/tree-ssanames.cc
+++ b/gcc/tree-ssanames.cc
@@ -497,14 +497,6 @@ set_range_info (tree name, const vrange &r)
if (!tmp.intersect (r) || tmp.undefined_p ())
return false;
- if (POINTER_TYPE_P (type))
- {
- // Preserve nonnullness in the points-to solution as well.
- pt_solution *pt = get_pt_solution (name);
- if (!tmp.contains_zero_p () && pt->null)
- set_ptr_nonnull (name);
- }
-
if (!range_info_set_range (name, tmp))
return false;
@@ -523,13 +515,31 @@ set_range_info (tree name, const vrange &r)
return true;
}
+/* query nonnull attribute for pointer NAME. */
+
+bool
+ptr_nonnull_p (tree name)
+{
+ gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
+ prange_storage *ps = ssa_name_prange_storage (name);
+ return ps ? ps->nonnull_p (TREE_TYPE (name)) : false;
+}
+
/* Set nonnull attribute to pointer NAME. */
void
set_ptr_nonnull (tree name)
{
gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
- get_pt_solution (name)->null = 0;
+ prange_storage *ps = ssa_name_prange_storage (name);
+ if (ps)
+ {
+ ps->set_nonnull (TREE_TYPE (name));
+ return;
+ }
+ prange pr;
+ pr.set_nonzero (TREE_TYPE (name));
+ range_info_set_range (name, pr);
}
/* Update the non-zero bits bitmask of NAME. */
@@ -1038,13 +1048,7 @@ reset_flow_sensitive_info (tree name)
pt_solution *pt = s ? s->pt : NULL;
SSA_NAME_RANGE_INFO (name) = NULL;
if (pt)
- {
- set_pt_solution (name, pt);
- /* [E]VRP can derive context sensitive alignment info and
- non-nullness properties. We must reset both. The alignment went
- with the range storage above; only the nullness is left. */
- pt->null = 1;
- }
+ set_pt_solution (name, pt);
// Clear range info in the current range query.
get_range_query (cfun)->reset_range_info (name);
@@ -1178,60 +1182,3 @@ make_pass_release_ssa_names (gcc::context *ctxt)
{
return new pass_release_ssa_names (ctxt);
}
-
-/* Save and restore of flow sensitive information. */
-
-/* Save off the flow sensitive info from NAME. */
-
-void
-flow_sensitive_info_storage::save (tree name)
-{
- gcc_assert (state == 0);
- range_info = SSA_NAME_RANGE_INFO (name);
- if (!POINTER_TYPE_P (TREE_TYPE (name)))
- {
- state = 1;
- return;
- }
- state = -1;
- const pt_solution *pt = ssa_name_pt_solution (name);
- null = pt ? pt->null : true;
-}
-
-/* Restore the flow sensitive info from NAME. */
-
-void
-flow_sensitive_info_storage::restore (tree name)
-{
- gcc_assert (state != 0);
- /* The storage carries the range, its bitmask and -- for now -- the
- alignment, so reinstating it restores all three. Only the nullness
- lives outside it. */
- SSA_NAME_RANGE_INFO (name) = range_info;
- if (!POINTER_TYPE_P (TREE_TYPE (name)))
- {
- gcc_assert (state == 1);
- return;
- }
- gcc_assert (state == -1);
- prange_storage *s = ssa_name_prange_storage (name);
- if (s && s->pt)
- s->pt->null = null;
-}
-
-/* Save off the flow sensitive info from NAME.
- And reset the flow sensitive info of NAME. */
-
-void
-flow_sensitive_info_storage::save_and_clear (tree name)
-{
- save (name);
- reset_flow_sensitive_info (name);
-}
-
-/* Clear the storage. */
-void
-flow_sensitive_info_storage::clear_storage (void)
-{
- state = 0;
-}
diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h
index bbd5890c4ff..6ddf5d1fca5 100644
--- a/gcc/tree-ssanames.h
+++ b/gcc/tree-ssanames.h
@@ -56,6 +56,7 @@ extern bool get_ptr_info_alignment (const_tree,
unsigned int *,
extern void mark_ptr_info_alignment_unknown (tree);
extern void set_ptr_info_alignment (tree, unsigned int, unsigned int);
extern void set_ptr_nonnull (tree);
+extern bool ptr_nonnull_p (tree);
extern tree copy_ssa_name_fn (struct function *, tree, gimple *);
extern tree duplicate_ssa_name_fn (struct function *, tree, gimple *);
@@ -122,21 +123,35 @@ make_temp_ssa_name (tree type, gimple *stmt, const
char *name)
class flow_sensitive_info_storage
{
public:
- void save (tree);
- void save_and_clear (tree);
- void restore (tree);
- void clear_storage ();
+ /* Save the flow sensitive info from NAME. */
+ inline void save (tree name)
+ {
+ gcc_checking_assert (state == 0);
+ range_info = SSA_NAME_RANGE_INFO (name);
+ state = 1;
+ }
+
+ /* Restore the flow sensitive info from NAME. */
+ inline void restore (tree name) const
+ {
+ gcc_checking_assert (state == 1);
+ SSA_NAME_RANGE_INFO (name) = range_info;
+ }
+
+ /* Save the flow sensitive info from NAME and reset that info. */
+ inline void save_and_clear (tree name)
+ {
+ save (name);
+ reset_flow_sensitive_info (name);
+ }
+
+ /* Clear the storage. */
+ inline void clear_storage () { state = 0; }
private:
- /* 0 means there is nothing saved.
- 1 means non pointer is saved.
- -1 means a pointer type is saved.
- -2 means a pointer type is saved but no information was saved. */
+ /* 0 means there is nothing saved. 1 means something is saved. */
int state = 0;
- /* The range info, which for a pointer also carries the bitmask and the
- alignment, so those need no separate slot here. */
+ /* The range info contains all flow sensitive information now. */
vrange_storage *range_info = nullptr;
- /* Flow sensitive pointer information not held in the range. */
- bool null = true;
};
#endif /* GCC_TREE_SSANAMES_H */
diff --git a/gcc/value-query.cc b/gcc/value-query.cc
index e5290075243..a35029237ec 100644
--- a/gcc/value-query.cc
+++ b/gcc/value-query.cc
@@ -592,26 +592,6 @@ get_ssa_name_range_info (vrange &r, const_tree name)
r.set_varying (type);
}
-// Return nonnull attribute of pointer NAME from its points-to solution.
-
-static inline bool
-get_ssa_name_ptr_info_nonnull (const_tree name)
-{
- gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
- const pt_solution *pt = ssa_name_pt_solution (name);
- if (pt == NULL)
- return false;
- /* TODO Now pt->null is conservatively set to true in PTA
- analysis. vrp is the only pass (including ipa-vrp)
- that clears pt.null via set_ptr_nonnull when it knows
- for sure. PTA will preserves the pt.null value set by VRP.
-
- When PTA analysis is improved, pt.anything, pt.nonlocal
- and pt.escaped may also has to be considered before
- deciding that pointer cannot point to NULL. */
- return !pt->null;
-}
-
// Update the global range for NAME into the SSA_RANGE_NAME_INFO and
// Return the legacy global range for NAME if it has one, otherwise
// return VARYING.
@@ -639,13 +619,12 @@ gimple_range_global (vrange &r, tree name, struct
function *fun)
// ~[0, 0]. Note that this is only valid with default definitions
// of PARM_DECLs
if (POINTER_TYPE_P (type)
- && ((cfun && fun == cfun && nonnull_arg_p (sym))
- || get_ssa_name_ptr_info_nonnull (name)))
- {
- prange nz (type);
- nz.set_nonzero (type);
- r.intersect (nz);
- }
+ && ((cfun && fun == cfun && nonnull_arg_p (sym))))
+ {
+ prange nz (type);
+ nz.set_nonzero (type);
+ r.intersect (nz);
+ }
}
// If this is a local automatic with no definition, use undefined.
else if (TREE_CODE (sym) != RESULT_DECL)
@@ -658,13 +637,6 @@ gimple_range_global (vrange &r, tree name, struct
function *fun)
get_ssa_name_range_info (r, name);
if (r.undefined_p ())
r.set_varying (type);
- // pt.null may still carry non-nullness the stored range does not.
- if (POINTER_TYPE_P (type) && get_ssa_name_ptr_info_nonnull (name))
- {
- prange nz (type);
- nz.set_nonzero (type);
- r.intersect (nz);
- }
}
else
r.set_varying (type);
diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc
index 62879585b6d..bb2a58788b3 100644
--- a/gcc/value-range-storage.cc
+++ b/gcc/value-range-storage.cc
@@ -883,6 +883,52 @@ prange_storage::fits_p (const prange &r) const
return num_words <= m_trailing_ints.num_elements ();
}
+// Ensure this range of type TYPE does not contain zero.
+
+void
+prange_storage::set_nonnull (tree type)
+{
+ gcc_checking_assert (m_kind != PR_UNDEFINED);
+ switch (m_kind)
+ {
+ case PR_VARYING:
+ case PR_FULL:
+ m_kind = PR_NONZERO;
+ return;
+
+ case PR_NONZERO:
+ return;
+
+ case PR_ZERO:
+ m_kind = PR_UNDEFINED;
+ return;
+
+ case PR_OTHER:
+ if (get_word (0, type) != 0)
+ return;
+ // [0,1] -> [1,1] is a special case and requires adjustments.
+ // otherwise we can simply set the lower bound to 1.
+ if (get_word (1, type) != 1)
+ set_word (0, wi::one (TYPE_PRECISION (type)), type);
+ else
+ {
+ // This is very uncoomon, and rather than trying to cover
+ // the edge cases (ie, bitmask present, points to)
+ // simply load the range, remove zero, and resave it.
+ prange pr;
+ this->get_vrange (pr, type);
+ prange nz;
+ nz.set_nonzero (type);
+ if (pr.intersect (nz))
+ this->set_prange (pr);
+ }
+ return;
+
+ default:
+ gcc_unreachable ();
+ }
+}
+
irange_bitmask
prange_storage::get_bitmask (tree type) const
{
diff --git a/gcc/value-range-storage.h b/gcc/value-range-storage.h
index a3a2821a445..b58a2f23bd3 100644
--- a/gcc/value-range-storage.h
+++ b/gcc/value-range-storage.h
@@ -132,6 +132,8 @@ public:
bool equal_p (const prange &r) const;
bool fits_p (const prange &r) const;
irange_bitmask get_bitmask (tree type) const;
+ bool nonnull_p (tree type) const;
+ void set_nonnull (tree type);
void dump () const;
// The points-to solution for the SSA name is flow insensitive and is
@@ -162,6 +164,28 @@ private:
trailing_wide_ints<PRANGE_STORAGE_NINTS> m_trailing_ints;
};
+// Return TRUE if this range of type TYPE does not contain zero.
+
+inline bool
+prange_storage::nonnull_p (tree type) const
+{
+ switch (m_kind)
+ {
+ case PR_UNDEFINED:
+ case PR_VARYING:
+ case PR_ZERO:
+ case PR_FULL:
+ return false;
+ case PR_NONZERO:
+ return true;
+ case PR_OTHER:
+ return (get_word (0, type) != 0);
+ default:
+ gcc_unreachable ();
+ }
+}
+
+
// Efficient memory storage for an frange.
class GTY((tag ("VR_FRANGE"))) frange_storage : public vrange_storage
--
2.56.0