I can't see any difference of code by gcc for restrict pointers.
file1
void test (int *a, int *b, int *c)
{
while (*a)
{
*c++ = *a++ + *b++;
}
}
file2
void test (int *restrict a, int *restrict b, int *restrict c)
{
while (*a)
{
*c++ = *a++ + *b++;
}
}
compile with
gcc -S -std=c99 -masm=intel file1.c
gcc -S -std=c99 -masm=intel file2.c
file1.s and file2.s both are same, except the .file
line, which tells the filename:
.file "file1.c"
.text
.globl test
.type test, @function
test:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movq %rdi, -8(%rbp)
movq %rsi, -16(%rbp)
movq %rdx, -24(%rbp)
jmp .L2
.L3:
movq -8(%rbp), %rax
movl (%rax), %edx
movq -16(%rbp), %rax
movl (%rax), %eax
addl %eax, %edx
movq -24(%rbp), %rax
movl %edx, (%rax)
addq $4, -24(%rbp)
addq $4, -8(%rbp)
addq $4, -16(%rbp)
.L2:
movq -8(%rbp), %rax
movl (%rax), %eax
testl %eax, %eax
jne .L3
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size test, .-test
.ident "GCC: (GNU) 4.6.3 20120306 (Red Hat 4.6.3-2)"
.section .note.GNU-stack,"",@progbits
Both of these code read from the memory and then assign the memory location pointed to by a
to b
. Where i expected the restrict
version will not re-read the addresses of a
and b
, and the addresses of a
and b
will be incremented in-register and at the end written to memory.
Is there anything wrong i am doing? Or is the selection of the example okay?
I have tried with different switches -O0
, -O1
, -O2
, -O3
, -Ofast
, and -fstrict-aliasing
with the same identical results for both of the files.
Note: gcc --version = gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2)
EDIT Code changed.