]> gcc.gnu.org Git - gcc.git/commitdiff
tree-optimization/13962 - handle ptr-ptr compares in ptrs_compare_unequal
authorRichard Biener <rguenther@suse.de>
Mon, 11 Mar 2024 10:17:32 +0000 (11:17 +0100)
committerRichard Biener <rguenther@suse.de>
Thu, 16 May 2024 12:44:17 +0000 (14:44 +0200)
Now that we handle pt.null conservatively we can implement the missing
tracking of constant pool entries (aka STRING_CST) and handle
ptr-ptr compares using points-to info in ptrs_compare_unequal.

PR tree-optimization/13962
PR tree-optimization/96564
* tree-ssa-alias.h (pt_solution::const_pool): New flag.
* tree-ssa-alias.cc (ptrs_compare_unequal): Handle pointer-pointer
compares.
(dump_points_to_solution): Dump the const_pool flag, fix guard
of flag dumping.
* gimple-pretty-print.cc (pp_points_to_solution): Likewise.
* tree-ssa-structalias.cc (find_what_var_points_to): Set
the const_pool flag for STRING.
(pt_solution_ior_into): Handle the const_pool flag.
(ipa_escaped_pt): Initialize it.

* gcc.dg/tree-ssa/alias-39.c: New testcase.
* g++.dg/vect/pr68145.cc: Use -fno-tree-pta to avoid UB
to manifest in transforms no longer vectorizing this testcase
for an ICE.

gcc/gimple-pretty-print.cc
gcc/testsuite/g++.dg/vect/pr68145.cc
gcc/testsuite/gcc.dg/tree-ssa/alias-39.c [new file with mode: 0644]
gcc/tree-ssa-alias.cc
gcc/tree-ssa-alias.h
gcc/tree-ssa-structalias.cc

index abda8871f97fea6d18e18fe76245434097b23530..a71e1e0efc77ec8f425cc1579bad8045beb01d4b 100644 (file)
@@ -822,6 +822,8 @@ pp_points_to_solution (pretty_printer *buffer, const pt_solution *pt)
     pp_string (buffer, "unit-escaped ");
   if (pt->null)
     pp_string (buffer, "null ");
+  if (pt->const_pool)
+    pp_string (buffer, "const-pool ");
   if (pt->vars
       && !bitmap_empty_p (pt->vars))
     {
@@ -838,7 +840,8 @@ pp_points_to_solution (pretty_printer *buffer, const pt_solution *pt)
       if (pt->vars_contains_nonlocal
          || pt->vars_contains_escaped
          || pt->vars_contains_escaped_heap
-         || pt->vars_contains_restrict)
+         || pt->vars_contains_restrict
+         || pt->vars_contains_interposable)
        {
          const char *comma = "";
          pp_string (buffer, " (");
index 8a1e10ee7833937d1440a3393df513235be85bd1..8d3502b0bf4ec2805c0f173d2638093757b0980f 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-additional-options "-Wno-return-type" } */
+/* { dg-additional-options "-fno-tree-pta -Wno-return-type" } */
 
 struct A {
   bool operator()(int p1, int p2) { return p1 && p2; }
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alias-39.c b/gcc/testsuite/gcc.dg/tree-ssa/alias-39.c
new file mode 100644 (file)
index 0000000..3b45289
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-forwprop3" } */
+
+static int a, b;
+int foo (int n, int which)
+{
+  void *p = __builtin_malloc (n);
+  void *q = which ? &a : &b;
+  return p == q;
+}
+
+/* { dg-final { scan-tree-dump "return 0;" "forwprop3" } } */
index 96301bbde7fa1af65712bd91ab0e7f6800fbcdd1..6d31fc836917259a2627b55ee994884c163d3d8c 100644 (file)
@@ -484,9 +484,27 @@ ptrs_compare_unequal (tree ptr1, tree ptr2)
        }
       return !pt_solution_includes (&pi->pt, obj1);
     }
-
-  /* ???  We'd like to handle ptr1 != NULL and ptr1 != ptr2
-     but those require pt.null to be conservatively correct.  */
+  else if (TREE_CODE (ptr1) == SSA_NAME)
+    {
+      struct ptr_info_def *pi1 = SSA_NAME_PTR_INFO (ptr1);
+      if (!pi1
+         || pi1->pt.vars_contains_restrict
+         || pi1->pt.vars_contains_interposable)
+       return false;
+      if (integer_zerop (ptr2) && !pi1->pt.null)
+       return true;
+      if (TREE_CODE (ptr2) == SSA_NAME)
+       {
+         struct ptr_info_def *pi2 = SSA_NAME_PTR_INFO (ptr2);
+         if (!pi2
+             || pi2->pt.vars_contains_restrict
+             || pi2->pt.vars_contains_interposable)
+           return false;
+         if ((!pi1->pt.null || !pi2->pt.null)
+             && (!pi1->pt.const_pool || !pi2->pt.const_pool))
+           return !pt_solutions_intersect (&pi1->pt, &pi2->pt);
+       }
+    }
 
   return false;
 }
@@ -636,6 +654,9 @@ dump_points_to_solution (FILE *file, struct pt_solution *pt)
   if (pt->null)
     fprintf (file, ", points-to NULL");
 
+  if (pt->const_pool)
+    fprintf (file, ", points-to const-pool");
+
   if (pt->vars)
     {
       fprintf (file, ", points-to vars: ");
@@ -643,7 +664,8 @@ dump_points_to_solution (FILE *file, struct pt_solution *pt)
       if (pt->vars_contains_nonlocal
          || pt->vars_contains_escaped
          || pt->vars_contains_escaped_heap
-         || pt->vars_contains_restrict)
+         || pt->vars_contains_restrict
+         || pt->vars_contains_interposable)
        {
          const char *comma = "";
          fprintf (file, " (");
index b26fffeeb2df7d513ccf1a9c61cde15496bf98d3..e29dff5837503e764976af061405635ccbadd092 100644 (file)
@@ -47,6 +47,11 @@ struct GTY(()) pt_solution
      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.  */
+  unsigned int const_pool : 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'.  */
index 0bac1a1f045ac34be259bdeb5bc64abc30b5168f..0c6085b17662a7a8dabc6d0e8265ca5a70cb0753 100644 (file)
@@ -6799,8 +6799,7 @@ find_what_var_points_to (tree fndecl, varinfo_t orig_vi)
          else if (vi->id == nonlocal_id)
            pt->nonlocal = 1;
          else if (vi->id == string_id)
-           /* Nobody cares - STRING_CSTs are read-only entities.  */
-           ;
+           pt->const_pool = 1;
          else if (vi->id == anything_id
                   || vi->id == integer_id)
            pt->anything = 1;
@@ -6956,6 +6955,7 @@ pt_solution_ior_into (struct pt_solution *dest, struct pt_solution *src)
   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;
   dest->vars_contains_escaped_heap |= src->vars_contains_escaped_heap;
@@ -8128,7 +8128,7 @@ make_pass_build_ealias (gcc::context *ctxt)
 
 /* IPA PTA solutions for ESCAPED.  */
 struct pt_solution ipa_escaped_pt
-  = { true, false, false, false, false,
+  = { true, false, false, false, false, false,
       false, false, false, false, false, NULL };
 
 /* Associate node with varinfo DATA. Worker for
This page took 0.096924 seconds and 5 git commands to generate.