This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: aliasing between const and non-const objects
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Michael Matz <matz at suse dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: 29 Jul 2003 18:14:51 +0200
- Subject: Re: aliasing between const and non-const objects
- Organization: Integrable Solutions
- References: <Pine.LNX.4.44.0307291729110.17944-100000@wotan.suse.de>
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