From 20ef028b2e38e3d91874ba873be10e5dfdac4d05 Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org>
Date: Fri, 30 Sep 2016 09:00:08 +1000
Subject: [PATCH 3/5] Add nonnull to pointer from VRP
---
gcc/tree-ssa-alias.c | 4 ++--
gcc/tree-ssa-structalias.c | 6 ++++--
gcc/tree-ssanames.c | 21 +++++++++++++++++++++
gcc/tree-ssanames.h | 2 ++
gcc/tree-vrp.c | 44 +++++++++++++++++++++++++++++---------------
5 files changed, 58 insertions(+), 19 deletions(-)
@@ -515,8 +515,8 @@ dump_points_to_solution (FILE *file, struct pt_solution *pt)
if (pt->ipa_escaped)
fprintf (file, ", points-to unit escaped");
- if (pt->null)
- fprintf (file, ", points-to NULL");
+ if (!pt->null)
+ fprintf (file, ", points-to non NULL");
if (pt->vars)
{
@@ -6349,6 +6349,8 @@ find_what_var_points_to (tree fndecl, varinfo_t orig_vi)
*slot = pt = XOBNEW (&final_solutions_obstack, struct pt_solution);
memset (pt, 0, sizeof (struct pt_solution));
+ /* Conservatively set to NULL from PTA (to true). */
+ pt->null = 1;
/* Translate artificial variables into SSA_NAME_PTR_INFO
attributes. */
@@ -6359,7 +6361,7 @@ find_what_var_points_to (tree fndecl, varinfo_t orig_vi)
if (vi->is_artificial_var)
{
if (vi->id == nothing_id)
- pt->null = 1;
+ ;
else if (vi->id == escaped_id)
{
if (in_ipa_mode)
@@ -6569,7 +6571,7 @@ bool
pt_solution_singleton_p (struct pt_solution *pt, unsigned *uid)
{
if (pt->anything || pt->nonlocal || pt->escaped || pt->ipa_escaped
- || pt->null || pt->vars == NULL
+ || pt->vars == NULL
|| !bitmap_single_bit_set_p (pt->vars))
return false;
@@ -374,6 +374,27 @@ get_range_info (const_tree name, wide_int *min, wide_int *max)
return SSA_NAME_RANGE_TYPE (name);
}
+/* Set nonnull attribute to pointer NAME. */
+
+void
+set_ptr_nonnull (tree name)
+{
+ gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
+ struct ptr_info_def *pi = get_ptr_info (name);
+ pi->pt.null = 0;
+}
+
+/* Return nonnull attribute of pointer NAME. */
+bool
+get_ptr_nonnull (const_tree name)
+{
+ gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
+ struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name);
+ if (pi == NULL)
+ return false;
+ return !pi->pt.null;
+}
+
/* Change non-zero bits bitmask of NAME. */
void
@@ -88,6 +88,8 @@ extern void set_ptr_info_alignment (struct ptr_info_def *, unsigned int,
extern void adjust_ptr_info_misalignment (struct ptr_info_def *,
unsigned int);
extern struct ptr_info_def *get_ptr_info (tree);
+extern void set_ptr_nonnull (tree);
+extern bool get_ptr_nonnull (const_tree);
extern tree copy_ssa_name_fn (struct function *, tree, gimple *);
extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *);
@@ -10593,18 +10593,24 @@ vrp_finalize (bool warn_array_bounds_p)
{
tree name = ssa_name (i);
- if (!name
- || POINTER_TYPE_P (TREE_TYPE (name))
- || (vr_value[i]->type == VR_VARYING)
- || (vr_value[i]->type == VR_UNDEFINED))
- continue;
+ if (!name
+ || (vr_value[i]->type == VR_VARYING)
+ || (vr_value[i]->type == VR_UNDEFINED)
+ || (TREE_CODE (vr_value[i]->min) != INTEGER_CST)
+ || (TREE_CODE (vr_value[i]->max) != INTEGER_CST))
+ continue;
- if ((TREE_CODE (vr_value[i]->min) == INTEGER_CST)
- && (TREE_CODE (vr_value[i]->max) == INTEGER_CST)
- && (vr_value[i]->type == VR_RANGE
- || vr_value[i]->type == VR_ANTI_RANGE))
- set_range_info (name, vr_value[i]->type, vr_value[i]->min,
- vr_value[i]->max);
+ if (POINTER_TYPE_P (TREE_TYPE (name))
+ && ((vr_value[i]->type == VR_RANGE
+ && range_includes_zero_p (vr_value[i]->min,
+ vr_value[i]->max) == 0)
+ || (vr_value[i]->type == VR_ANTI_RANGE
+ && range_includes_zero_p (vr_value[i]->min,
+ vr_value[i]->max) == 1)))
+ set_ptr_nonnull (name);
+ else if (!POINTER_TYPE_P (TREE_TYPE (name)))
+ set_range_info (name, vr_value[i]->type, vr_value[i]->min,
+ vr_value[i]->max);
}
substitute_and_fold (op_with_constant_singleton_value_range,
@@ -10808,17 +10814,25 @@ evrp_dom_walker::before_dom_children (basic_block bb)
def_operand_p def_p = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_DEF);
/* Set the SSA with the value range. */
if (def_p
- && TREE_CODE (DEF_FROM_PTR (def_p)) == SSA_NAME
- && INTEGRAL_TYPE_P (TREE_TYPE (DEF_FROM_PTR (def_p))))
+ && TREE_CODE (DEF_FROM_PTR (def_p)) == SSA_NAME)
{
tree def = DEF_FROM_PTR (def_p);
value_range *vr = get_value_range (def);
- if ((vr->type == VR_RANGE
- || vr->type == VR_ANTI_RANGE)
+ if (INTEGRAL_TYPE_P (TREE_TYPE (DEF_FROM_PTR (def_p)))
+ && (vr->type == VR_RANGE
+ || vr->type == VR_ANTI_RANGE)
&& (TREE_CODE (vr->min) == INTEGER_CST)
&& (TREE_CODE (vr->max) == INTEGER_CST))
set_range_info (def, vr->type, vr->min, vr->max);
+ else if (POINTER_TYPE_P (TREE_TYPE (DEF_FROM_PTR (def_p)))
+ && ((vr->type == VR_RANGE
+ && range_includes_zero_p (vr->min,
+ vr->max) == 0)
+ || (vr->type == VR_ANTI_RANGE
+ && range_includes_zero_p (vr->min,
+ vr->max) == 1)))
+ set_ptr_nonnull (def);
}
}
else
--
2.7.4