typedef struct {
void * field1;
} s1;
void func1(void) {
s1 my_s1;
s1 * __restrict my_s1_ptr = &my_s1;
*((int*)((char*)my_s1_ptr->field1 + 4)) = 0;
*((int*)((char*)my_s1_ptr->field1 + 8)) = 1;
*((int*)((char*)my_s1_ptr->field1 + 12)) = 2;
*((int*)((char*)my_s1_ptr->field1 + 16)) = 3;
}
It seems that for version 11.1 of the Intel compiler and version 4.6 of gcc that the compiler reloads my_s1_ptr->field1 for each of the last 4 statements. My understanding of __restrict would suggest to me that the last 3 loads should be redundant and could be eliminated. Yes, I know the code is weird but there is a reason it is structured this way. I would just like to be able to get the compiler to eliminate the redundant loads. Any idea how to convince it to do that?
__restrict
rather thanrestrict
, which is a C99 keyword? – Onagraceousrestrict
does not always optimize. It "may allow the compiler" to perform optimizations. The compiler is not required to perform those optimizations. Anyway, I find it still strange that it does not in your case. – Ezzell