Bug 65330 - restrict should be considered when folding through references from global vars
Summary: restrict should be considered when folding through references from global vars
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 5.0
: P3 enhancement
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords: missed-optimization
Depends on: 65270
Blocks: restrict
  Show dependency treegraph
 
Reported: 2015-03-05 19:56 UTC by Jan Hubicka
Modified: 2016-08-18 12:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-03-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Hubicka 2015-03-05 19:56:21 UTC
In the following testcase the restrict should be taken into account when folding testrestrict.

const int *varptr=&var;
const int *__restrict__ varptr2=&var;

 int *__restrict__ varptr3 = &var;
 int *__restrict__ varptr4 = &var;

int *
return_valptr(int i)
{
  return varptr[i];
}
int * __restrict__
return_valptr2(int i)
{
  return varptr2[i];
}
int
testrestrict ()
{
  int *ptr = return_valptr (0);
  *ptr = 0;
  *varptr3 = 1;
  return *ptr;
}
int
testrestrict2 ()
{
  int *ptr = return_valptr2 (0);
  *ptr = 0;
  *varptr3 = 1;
  return *ptr;
}
int
testrestrict4 ()
{
  *varptr4 = 0;
  *varptr3 = 1;
  return *varptr4;
}
Comment 1 Jan Hubicka 2015-03-05 20:29:52 UTC
To make this work, ICF most probably must not merge variables with mismatching restrict qualifiers.
Comment 2 Richard Biener 2015-03-06 10:06:52 UTC
I was thinking of sth else first - make sure that points-to analysis processes
initializers of readonly globals (when they bind to the current def).  In
your testcase the globals are not readonly - or did you mean to write

int * const varptr = &var;
int * const __restrict__ varptr2 = &var;

?  Your testcase also misses a declaration of 'var'.
Comment 3 Jan Hubicka 2015-03-07 00:08:49 UTC
> I was thinking of sth else first - make sure that points-to analysis processes
> initializers of readonly globals (when they bind to the current def).  In
when ctor_for_folding returns non-NULL;
> your testcase the globals are not readonly - or did you mean to write
> 
> int * const varptr = &var;
> int * const __restrict__ varptr2 = &var;
> 
> ?  Your testcase also misses a declaration of 'var'.

I did not quite finish the testcase because the restrict qualifier I was
interested in was ignored.  Yes, they would need to be declared either const or
static (so the DECL_READONLY is derived by IPA code).

This should be full testcase (-fmerge-all-constants is needed to get merging
done, but to expose any problems testrestrict/testrestrict2 codegen would need
to differ):

int var;
static const int *varptr=&var;
static const int *__restrict__ varptr2=&var;
static int *__restrict__ varptr3 = &var;
static int *__restrict__ varptr4 = &var;
int *
return_valptr(int i)
{
  return varptr[i];
}
int * __restrict__
return_valptr2(int i)
{
  return varptr2[i];
}
int
testrestrict ()
{
  int *ptr = return_valptr (0);
  *ptr = 0;
  *varptr3 = 1;
  return *ptr;
}
int
testrestrict2 ()
{
  int *ptr = return_valptr2 (0);
  *ptr = 0;
  *varptr3 = 1;
  return *ptr;
}
int
testrestrict4 ()
{
  *varptr4 = 0;
  *varptr3 = 1;
  return *varptr4;
}