diff mbox

[PR67666] Handle single restrict pointer in struct in create_variable_info_for_1

Message ID 560A3383.3020608@mentor.com
State New
Headers show

Commit Message

Tom de Vries Sept. 29, 2015, 6:45 a.m. UTC
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

        if (i + 1 < fieldstack.length ())

Comments

Richard Biener Sept. 29, 2015, 8:29 a.m. UTC | #1
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 ())
> 
>
diff mbox

Patch

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;