From 40b8428e2e586d89cce4fbafb8ef333a062a53f8 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 20 Oct 2016 14:14:47 +0000 Subject: [PATCH] tree-ssa-alias.c (ptrs_compare_unequal): Remove code duplication. 2016-10-20 Richard Biener * tree-ssa-alias.c (ptrs_compare_unequal): Remove code duplication. Handle decls possibly not bound. * tree-ssa-structalias.c (get_constraint_for_ssa_var): Add nothing_id for decls that might not be bound if we are interested for the address. (get_constraint_for_component_ref): Deal with that. From-SVN: r241378 --- gcc/ChangeLog | 9 +++++++++ gcc/tree-ssa-alias.c | 22 +++++++++++++++------- gcc/tree-ssa-structalias.c | 16 ++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4265d087107..2c770c240ec 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2016-10-20 Richard Biener + + * tree-ssa-alias.c (ptrs_compare_unequal): Remove code duplication. + Handle decls possibly not bound. + * tree-ssa-structalias.c (get_constraint_for_ssa_var): Add + nothing_id for decls that might not be bound if we are interested + for the address. + (get_constraint_for_component_ref): Deal with that. + 2016-10-20 Michael Matz Loop splitting. diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index 01bef17cbfb..26c9f9e894b 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -358,6 +358,13 @@ ptrs_compare_unequal (tree ptr1, tree ptr2) ptr2 = TREE_OPERAND (tem, 0); } + /* Canonicalize ptr vs. object. */ + if (TREE_CODE (ptr1) == SSA_NAME && obj2) + { + std::swap (ptr1, ptr2); + std::swap (obj1, obj2); + } + if (obj1 && obj2) /* Other code handles this correctly, no need to duplicate it here. */; else if (obj1 && TREE_CODE (ptr2) == SSA_NAME) @@ -368,15 +375,16 @@ ptrs_compare_unequal (tree ptr1, tree ptr2) may be in fact obj1. */ if (!pi || pi->pt.vars_contains_restrict) return false; + if (VAR_P (obj1) + && (TREE_STATIC (obj1) || DECL_EXTERNAL (obj1))) + { + varpool_node *node = varpool_node::get (obj1); + /* If obj1 may bind to NULL give up (see below). */ + if (! node || ! node->nonzero_address ()) + return false; + } return !pt_solution_includes (&pi->pt, obj1); } - else if (TREE_CODE (ptr1) == SSA_NAME && obj2) - { - struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr1); - if (!pi || pi->pt.vars_contains_restrict) - return false; - return !pt_solution_includes (&pi->pt, obj2); - } /* ??? We'd like to handle ptr1 != NULL and ptr1 != ptr2 but those require pt.null to be conservatively correct. */ diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index 78f45334785..fb364f1319d 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -2944,6 +2944,16 @@ get_constraint_for_ssa_var (tree t, vec *results, bool address_p) DECL_PT_UID (t) = DECL_UID (node->decl); t = node->decl; } + + /* If this is decl may bind to NULL note that. */ + if (address_p + && (! node || ! node->nonzero_address ())) + { + cexpr.var = nothing_id; + cexpr.type = SCALAR; + cexpr.offset = 0; + results->safe_push (cexpr); + } } vi = get_vi_for_tree (t); @@ -3213,6 +3223,12 @@ get_constraint_for_component_ref (tree t, vec *results, /* Pretend to take the address of the base, we'll take care of adding the required subset of sub-fields below. */ get_constraint_for_1 (t, results, true, lhs_p); + /* Strip off nothing_id. */ + if (results->length () == 2) + { + gcc_assert ((*results)[0].var == nothing_id); + results->unordered_remove (0); + } gcc_assert (results->length () == 1); struct constraint_expr &result = results->last (); -- 2.30.2