This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: aliasing between const and non-const objects


Michael Matz <matz@suse.de> writes:

| Hi,
| 
| Suppose you wanted to fix such testcase:
| -------
| int *t;
| const int *c;
| void f (void)
| {
|   t[0] = c[0] + c[1] + c[2];
|   t[1] = c[0] + c[1] + c[2];
| }
| -------
| 
| With fixing I mean to make CSE recognize the redundant second summation.

Given, C's notion of const and aliasing rule, I don't know how you can
decide that the second summation is redundant.  The mere fact that "c"
is declared to be "const int*" does not mean that *c is effectivelly
const.  Consider the above is completed with:

  int main(void)
  {
     int a[] = { 9, 4, 5, 9 };
     t = a;
     c = a;
     f();
  }

The above is perfectly valid and you cannot remove the second summation.


| This is possible because the write to t[0] can't alias with the values
| load from c[].

No, that does not follow from the snippet you showed.  Maybe you need
some "restrict" annotation.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]