aliasing between const and non-const objects
Gabriel Dos Reis
gdr@integrable-solutions.net
Tue Jul 29 16:50:00 GMT 2003
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
More information about the Gcc
mailing list