http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48885
Summary: missed optimization with restrict qualifier?
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: trivial
Priority: P3
Component: c
AssignedTo: [email protected]
ReportedBy: [email protected]
Hello,
I recently experiment the optimizations obtained by using the restrict
qualifier introduced by the C99 standard. In this purpose, I used this trivial
exemple:
#include <stdio.h>
#include <stdlib.h>
void
test (int *a, int *b, int * restrict v)
{
*a = *v;
*b = *v;
}
int
main (void)
{
int a;
int b;
int v = 10;
test (&a, &b, &v);
return EXIT_SUCCESS;
}
If i compiled it with the -S and -O2 options, I obtained for the "test"
function:
movl (%rdx), %eax
movl %eax, (%rdi)
movl (%rdx), %eax
movl %eax, (%rsi)
However, if I had correctly understand the meaning of a restrict pointer, we
can normally expect in the "test" function that the object pointed to by "v"
cannot be changed through "a" or "b"; and therefore perform only one load, like
this:
movl (%rdx), %eax
movl %eax, (%rdi)
movl %eax, (%rsi)
But, the optimization only operate if all the pointers are restrict qualified.
Why?
PS: I compile with GCC 4.6 (Debian amd64 unstable package).