re PR middle-end/71062 (r235622 and restrict pointers)
authorRichard Biener <rguenther@suse.de>
Thu, 12 May 2016 13:05:13 +0000 (13:05 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 12 May 2016 13:05:13 +0000 (13:05 +0000)
2016-05-12  Richard Biener  <rguenther@suse.de>

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

gcc/ChangeLog
gcc/gimple-pretty-print.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr71062.c [new file with mode: 0644]
gcc/tree-ssa-alias.c
gcc/tree-ssa-alias.h
gcc/tree-ssa-structalias.c

index 40f1b6680e0e612467babaa451069e21f3ea7175..ddea24baf0d2b3d2aaf6f2fa40f05e8a7e4cf062 100644 (file)
@@ -1,3 +1,16 @@
+2016-05-12  Richard Biener  <rguenther@suse.de>
+
+       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  <mliska@suse.cz>
 
        * doc/invoke.texi: Explain connection between -fsanitize-recover=address
index e27214fd1a812f0f5a7feba93a2b64d39a8996a3..4b0dc7c9a986bac37928a6992837c32ba0bbae75 100644 (file)
@@ -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, ")");
+       }
+
     }
 }
 
index d61bb26799dbe8ed0a672dd973f0bf95d884eee3..6dca22fd18259ef3732f5fc20ebde0bd95c3b20b 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-12  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/71062
+       * gcc.dg/torture/pr71062.c: New testcase.
+
 2016-05-12  Ilya Enkovich  <ilya.enkovich@intel.com>
 
        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 (file)
index 0000000..cc01dda
--- /dev/null
@@ -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;
+}
index 58920e0d5b4d113133094cbac22bd2767ef4b30b..b663ddfb0d5097b34d58cd14dba8e9a4bce4d24a 100644 (file)
@@ -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, ")");
+       }
     }
 }
 
index 0593b05a7bcf321712d3b70b56b17f891d2a663b..6680cc0a1eb674979794dda411638d7ffd67d8d8 100644 (file)
@@ -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;
index 3956efd476661f9f3028f7f63dc1500a2343e80f..5e3c7d094b58a4296eae879a9c43a5b373a717ee 100644 (file)
@@ -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.  */