From: Richard Biener Date: Thu, 12 May 2016 13:05:13 +0000 (+0000) Subject: re PR middle-end/71062 (r235622 and restrict pointers) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=763baff6f54ec6070e0ec6497363f5116ab4c874;p=gcc.git re PR middle-end/71062 (r235622 and restrict pointers) 2016-05-12 Richard Biener PR tree-optimization/71062 * tree-ssa-alias.h (struct pt_solution): Add vars_contains_restrict field. * tree-ssa-structalias.c (set_uids_in_ptset): Set vars_contains_restrict if the var is a restrict tag. * tree-ssa-alias.c (ptrs_compare_unequal): If vars_contains_restrict do not disambiguate pointers against it. (dump_points_to_solution): Re-structure and adjust for new vars_contains_restrict flag. * gimple-pretty-print.c (pp_points_to_solution): Likewise. * gcc.dg/torture/pr71062.c: New testcase. From-SVN: r236174 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 40f1b6680e0..ddea24baf0d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2016-05-12 Richard Biener + + PR tree-optimization/71062 + * tree-ssa-alias.h (struct pt_solution): Add vars_contains_restrict + field. + * tree-ssa-structalias.c (set_uids_in_ptset): Set vars_contains_restrict + if the var is a restrict tag. + * tree-ssa-alias.c (ptrs_compare_unequal): If vars_contains_restrict + do not disambiguate pointers against it. + (dump_points_to_solution): Re-structure and adjust for new + vars_contains_restrict flag. + * gimple-pretty-print.c (pp_points_to_solution): Likewise. + 2016-05-12 Martin Liska * doc/invoke.texi: Explain connection between -fsanitize-recover=address diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index e27214fd1a8..4b0dc7c9a98 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -632,17 +632,37 @@ pp_points_to_solution (pretty_printer *buffer, struct pt_solution *pt) } pp_right_brace (buffer); if (pt->vars_contains_nonlocal - && pt->vars_contains_escaped_heap) - pp_string (buffer, " (nonlocal, escaped heap)"); - else if (pt->vars_contains_nonlocal - && pt->vars_contains_escaped) - pp_string (buffer, " (nonlocal, escaped)"); - else if (pt->vars_contains_nonlocal) - pp_string (buffer, " (nonlocal)"); - else if (pt->vars_contains_escaped_heap) - pp_string (buffer, " (escaped heap)"); - else if (pt->vars_contains_escaped) - pp_string (buffer, " (escaped)"); + || pt->vars_contains_escaped + || pt->vars_contains_escaped_heap + || pt->vars_contains_restrict) + { + const char *comma = ""; + pp_string (buffer, " ("); + if (pt->vars_contains_nonlocal) + { + pp_string (buffer, "nonlocal"); + comma = ", "; + } + if (pt->vars_contains_escaped) + { + pp_string (buffer, comma); + pp_string (buffer, "escaped"); + comma = ", "; + } + if (pt->vars_contains_escaped_heap) + { + pp_string (buffer, comma); + pp_string (buffer, "escaped heap"); + comma = ", "; + } + if (pt->vars_contains_restrict) + { + pp_string (buffer, comma); + pp_string (buffer, "restrict"); + } + pp_string (buffer, ")"); + } + } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d61bb26799d..6dca22fd182 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-12 Richard Biener + + PR tree-optimization/71062 + * gcc.dg/torture/pr71062.c: New testcase. + 2016-05-12 Ilya Enkovich PR tree-optimization/71006 diff --git a/gcc/testsuite/gcc.dg/torture/pr71062.c b/gcc/testsuite/gcc.dg/torture/pr71062.c new file mode 100644 index 00000000000..cc01dda2de4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr71062.c @@ -0,0 +1,20 @@ +/* { dg-do run } */ + +extern void abort (void); + +char bar; + +int __attribute__((noinline,noclone)) +foo (char *__restrict p) +{ + if (p == &bar) + return 1; + return 0; +} + +int main() +{ + if (foo (&bar) != 1) + abort (); + return 0; +} diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index 58920e0d5b4..b663ddfb0d5 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -363,14 +363,17 @@ ptrs_compare_unequal (tree ptr1, tree ptr2) else if (obj1 && TREE_CODE (ptr2) == SSA_NAME) { struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr2); - if (!pi) + /* We may not use restrict to optimize pointer comparisons. + See PR71062. So we have to assume that restrict-pointed-to + may be in fact obj1. */ + if (!pi || pi->pt.vars_contains_restrict) 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) + if (!pi || pi->pt.vars_contains_restrict) return false; return !pt_solution_includes (&pi->pt, obj2); } @@ -521,17 +524,31 @@ dump_points_to_solution (FILE *file, struct pt_solution *pt) fprintf (file, ", points-to vars: "); dump_decl_set (file, pt->vars); if (pt->vars_contains_nonlocal - && pt->vars_contains_escaped_heap) - fprintf (file, " (nonlocal, escaped heap)"); - else if (pt->vars_contains_nonlocal - && pt->vars_contains_escaped) - fprintf (file, " (nonlocal, escaped)"); - else if (pt->vars_contains_nonlocal) - fprintf (file, " (nonlocal)"); - else if (pt->vars_contains_escaped_heap) - fprintf (file, " (escaped heap)"); - else if (pt->vars_contains_escaped) - fprintf (file, " (escaped)"); + || pt->vars_contains_escaped + || pt->vars_contains_escaped_heap + || pt->vars_contains_restrict) + { + const char *comma = ""; + fprintf (file, " ("); + if (pt->vars_contains_nonlocal) + { + fprintf (file, "nonlocal"); + comma = ", "; + } + if (pt->vars_contains_escaped) + { + fprintf (file, "%sescaped", comma); + comma = ", "; + } + if (pt->vars_contains_escaped_heap) + { + fprintf (file, "%sescaped heap", comma); + comma = ", "; + } + if (pt->vars_contains_restrict) + fprintf (file, "%srestrict", comma); + fprintf (file, ")"); + } } } diff --git a/gcc/tree-ssa-alias.h b/gcc/tree-ssa-alias.h index 0593b05a7bc..6680cc0a1eb 100644 --- a/gcc/tree-ssa-alias.h +++ b/gcc/tree-ssa-alias.h @@ -47,7 +47,6 @@ struct GTY(()) pt_solution includes memory at address NULL. */ unsigned int null : 1; - /* Nonzero if the vars bitmap includes a variable included in 'nonlocal'. */ unsigned int vars_contains_nonlocal : 1; /* Nonzero if the vars bitmap includes a variable included in 'escaped'. */ @@ -55,6 +54,9 @@ struct GTY(()) pt_solution /* Nonzero if the vars bitmap includes a anonymous heap variable that escaped the function and thus became global. */ unsigned int vars_contains_escaped_heap : 1; + /* Nonzero if the vars bitmap includes a anonymous variable used to + represent storage pointed to by a restrict qualified pointer. */ + unsigned int vars_contains_restrict : 1; /* Set of variables that this pointer may point to. */ bitmap vars; diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index 3956efd4766..5e3c7d094b5 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -6254,6 +6254,9 @@ set_uids_in_ptset (bitmap into, bitmap from, struct pt_solution *pt, pt->vars_contains_escaped_heap = vi->is_heap_var; } + if (vi->is_restrict_var) + pt->vars_contains_restrict = true; + if (TREE_CODE (vi->decl) == VAR_DECL || TREE_CODE (vi->decl) == PARM_DECL || TREE_CODE (vi->decl) == RESULT_DECL) @@ -7505,7 +7508,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, false, false, NULL }; + = { true, false, false, false, false, false, false, false, false, NULL }; /* Associate node with varinfo DATA. Worker for cgraph_for_symbol_thunks_and_aliases. */