* [PATCH][PR67666] Handle single restrict pointer in struct in create_variable_info_for_1
@ 2015-09-22 7:45 Tom de Vries
2015-09-22 8:13 ` Richard Biener
0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2015-09-22 7:45 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 467 bytes --]
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
[-- Attachment #2: 0001-Handle-single-restrict-pointer-in-struct-in-create_v.patch --]
[-- Type: text/x-patch, Size: 2584 bytes --]
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][PR67666] Handle single restrict pointer in struct in create_variable_info_for_1
2015-09-22 7:45 [PATCH][PR67666] Handle single restrict pointer in struct in create_variable_info_for_1 Tom de Vries
@ 2015-09-22 8:13 ` Richard Biener
2015-09-29 8:29 ` Tom de Vries
0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2015-09-22 8:13 UTC (permalink / raw)
To: Tom de Vries; +Cc: gcc-patches
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][PR67666] Handle single restrict pointer in struct in create_variable_info_for_1
2015-09-22 8:13 ` Richard Biener
@ 2015-09-29 8:29 ` Tom de Vries
2015-09-29 9:50 ` Richard Biener
0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2015-09-29 8:29 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
On 22/09/15 09:49, Richard Biener wrote:
> 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.
>
Hi,
I wonder if this follow-up patch is necessary.
Now that we handle structs with one field in the final loop of
create_variable_info_for_1, should we set the is_full_var field as well?
It used to be set for such structs before I committed the "Handle single
restrict pointer in struct in create_variable_info_for_1" patch.
Thanks,
- Tom
diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 8d86dcb..26d97a3 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -5720,6 +5720,8 @@ create_variable_info_for_1 (tree decl, const char
*name)
newvi->offset = fo->offset;
newvi->size = fo->size;
newvi->fullsize = vi->fullsize;
+ if (fieldstack.length () == 1)
+ newvi->is_full_var = true;
newvi->may_have_pointers = fo->may_have_pointers;
newvi->only_restrict_pointers = fo->only_restrict_pointers;
if (i + 1 < fieldstack.length ())
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][PR67666] Handle single restrict pointer in struct in create_variable_info_for_1
2015-09-29 8:29 ` Tom de Vries
@ 2015-09-29 9:50 ` Richard Biener
2015-10-23 9:59 ` Tom de Vries
0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2015-09-29 9:50 UTC (permalink / raw)
To: Tom de Vries; +Cc: gcc-patches
On Tue, 29 Sep 2015, Tom de Vries wrote:
> On 22/09/15 09:49, Richard Biener wrote:
> > 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.
> >
>
> Hi,
>
> I wonder if this follow-up patch is necessary.
>
> Now that we handle structs with one field in the final loop of
> create_variable_info_for_1, should we set the is_full_var field as well? It
> used to be set for such structs before I committed the "Handle single restrict
> pointer in struct in create_variable_info_for_1" patch.
Yeah, I suppose so. But I'd set vi->is_full_var to true when
allocating 'vi':
vi = new_var_info (decl, name);
vi->fullsize = tree_to_uhwi (declsize);
+ if (fieldstack.length () == 1)
+ vi->is_full_var = true;
Ok with that change.
Thanks,
Richard.
> Thanks,
> - Tom
>
> diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
> index 8d86dcb..26d97a3 100644
> --- a/gcc/tree-ssa-structalias.c
> +++ b/gcc/tree-ssa-structalias.c
> @@ -5720,6 +5720,8 @@ create_variable_info_for_1 (tree decl, const char *name)
> newvi->offset = fo->offset;
> newvi->size = fo->size;
> newvi->fullsize = vi->fullsize;
> + if (fieldstack.length () == 1)
> + newvi->is_full_var = true;
> newvi->may_have_pointers = fo->may_have_pointers;
> newvi->only_restrict_pointers = fo->only_restrict_pointers;
> if (i + 1 < fieldstack.length ())
>
>
--
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][PR67666] Handle single restrict pointer in struct in create_variable_info_for_1
2015-09-29 9:50 ` Richard Biener
@ 2015-10-23 9:59 ` Tom de Vries
0 siblings, 0 replies; 5+ messages in thread
From: Tom de Vries @ 2015-10-23 9:59 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1480 bytes --]
On 29/09/15 10:29, Richard Biener wrote:
> On Tue, 29 Sep 2015, Tom de Vries wrote:
>
>> On 22/09/15 09:49, Richard Biener wrote:
>>> 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.
>>>
>>
>> Hi,
>>
>> I wonder if this follow-up patch is necessary.
>>
>> Now that we handle structs with one field in the final loop of
>> create_variable_info_for_1, should we set the is_full_var field as well? It
>> used to be set for such structs before I committed the "Handle single restrict
>> pointer in struct in create_variable_info_for_1" patch.
>
> Yeah, I suppose so. But I'd set vi->is_full_var to true when
> allocating 'vi':
>
> vi = new_var_info (decl, name);
> vi->fullsize = tree_to_uhwi (declsize);
> + if (fieldstack.length () == 1)
> + vi->is_full_var = true;
>
>
> Ok with that change.
>
Committed as attached.
Thanks,
- Tom
[-- Attachment #2: 0002-Add-missing-is_full_var-setting-in-create_variable_i.patch --]
[-- Type: text/x-patch, Size: 805 bytes --]
Add missing is_full_var setting in create_variable_info_for_1
2015-10-23 Tom de Vries <tom@codesourcery.com>
* tree-ssa-structalias.c (create_variable_info_for_1): Add missing
setting of is_full_var in case of a single field.
---
gcc/tree-ssa-structalias.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 8d86dcb..db0ab1e 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -5693,6 +5693,8 @@ create_variable_info_for_1 (tree decl, const char *name)
vi = new_var_info (decl, name);
vi->fullsize = tree_to_uhwi (declsize);
+ if (fieldstack.length () == 1)
+ vi->is_full_var = true;
for (i = 0, newvi = vi;
fieldstack.iterate (i, &fo);
++i, newvi = vi_next (newvi))
--
1.9.1
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-10-23 9:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-22 7:45 [PATCH][PR67666] Handle single restrict pointer in struct in create_variable_info_for_1 Tom de Vries
2015-09-22 8:13 ` Richard Biener
2015-09-29 8:29 ` Tom de Vries
2015-09-29 9:50 ` Richard Biener
2015-10-23 9:59 ` Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).