diff mbox

[PR67666] Handle single restrict pointer in struct in create_variable_info_for_1

Message ID 5600FBFA.2090300@mentor.com
State New
Headers show

Commit Message

Tom de Vries Sept. 22, 2015, 6:58 a.m. UTC
Hi,

Consider this test-case:

struct ps
{
   int *__restrict__ p;
};

void
f (struct ps &__restrict__ ps1)
{
   *(ps1.p) = 1;
}


Atm, the restrict on p has no effect. Now, say we add a field to the struct:

struct ps
{
   int *__restrict__ p;
   int a;
};


Then the restrict on p does have the desired effect.


This patch fixes the handling of structs with a single field in alias 
analysis.

Bootstrapped and reg-tested on x86_64.

OK for trunk?

Thanks,
- Tom

Comments

Richard Biener Sept. 22, 2015, 7:49 a.m. UTC | #1
On Tue, 22 Sep 2015, Tom de Vries wrote:

> Hi,
> 
> Consider this test-case:
> 
> struct ps
> {
>   int *__restrict__ p;
> };
> 
> void
> f (struct ps &__restrict__ ps1)
> {
>   *(ps1.p) = 1;
> }
> 
> 
> Atm, the restrict on p has no effect. Now, say we add a field to the struct:
> 
> struct ps
> {
>   int *__restrict__ p;
>   int a;
> };
> 
> 
> Then the restrict on p does have the desired effect.
> 
> 
> This patch fixes the handling of structs with a single field in alias
> analysis.
> 
> Bootstrapped and reg-tested on x86_64.
> 
> OK for trunk?

Ok.

Thanks,
Richard.
diff mbox

Patch

Handle single restrict pointer in struct in create_variable_info_for_1

2015-09-22  Tom de Vries  <tom@codesourcery.com>

	PR tree-optimization/67666
	* tree-ssa-structalias.c (create_variable_info_for_1): Handle struct
	with single field non-conservative.

	* g++.dg/pr67666.C: New test.
---
 gcc/testsuite/g++.dg/pr67666.C | 17 +++++++++++++++++
 gcc/tree-ssa-structalias.c     | 25 ++++++++++++++++---------
 2 files changed, 33 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr67666.C

diff --git a/gcc/testsuite/g++.dg/pr67666.C b/gcc/testsuite/g++.dg/pr67666.C
new file mode 100644
index 0000000..ad162f4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr67666.C
@@ -0,0 +1,17 @@ 
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-ealias-all" }
+
+struct ps
+{
+  int *__restrict__ p;
+};
+
+void
+f (struct ps &__restrict__ ps1)
+{
+  *(ps1.p) = 1;
+}
+
+// { dg-final { scan-tree-dump-times "clique 1 base 1" 1 "ealias" } }
+// { dg-final { scan-tree-dump-times "clique 1 base 2" 1 "ealias" } }
+// { dg-final { scan-tree-dump-times "(?n)clique .* base .*" 2 "ealias" } }
diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index b5b9d0a..94016b9 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -5675,7 +5675,7 @@  create_variable_info_for_1 (tree decl, const char *name)
 
   /* If we didn't end up collecting sub-variables create a full
      variable for the decl.  */
-  if (fieldstack.length () <= 1
+  if (fieldstack.length () == 0
       || fieldstack.length () > MAX_FIELDS_FOR_FIELD_SENSITIVE)
     {
       vi = new_var_info (decl, name);
@@ -5694,19 +5694,26 @@  create_variable_info_for_1 (tree decl, const char *name)
        fieldstack.iterate (i, &fo);
        ++i, newvi = vi_next (newvi))
     {
-      const char *newname = "NULL";
+      const char *newname = NULL;
       char *tempname;
 
       if (dump_file)
 	{
-	  tempname
-	    = xasprintf ("%s." HOST_WIDE_INT_PRINT_DEC
-			 "+" HOST_WIDE_INT_PRINT_DEC, name,
-			 fo->offset, fo->size);
-	  newname = ggc_strdup (tempname);
-	  free (tempname);
+	  if (fieldstack.length () != 1)
+	    {
+	      tempname
+		= xasprintf ("%s." HOST_WIDE_INT_PRINT_DEC
+			     "+" HOST_WIDE_INT_PRINT_DEC, name,
+			     fo->offset, fo->size);
+	      newname = ggc_strdup (tempname);
+	      free (tempname);
+	    }
 	}
-      newvi->name = newname;
+      else
+	newname = "NULL";
+
+      if (newname)
+	  newvi->name = newname;
       newvi->offset = fo->offset;
       newvi->size = fo->size;
       newvi->fullsize = vi->fullsize;
-- 
1.9.1