Hi

Here is an optimization question about gcc compiler, we wonder whether it 
is a bug or not.

A simple test program here:
===============================================
int *p;

int main(void)
{
        p++;
        __asm__ __volatile__ (""::);
        p++;
}
===============================================
And it is comiled like this:
gcc -S -O2 -o xxx.s xxx.c

Because of the '__asm__ __volatile ...' clause, the 1st 'p++' & the 2nd 
'p++' will not be merged together, so
assembly code is like: 
'addl $4, %eax'
'addl $4, %eax'


But if the program is modified as below:
===============================================
int *p;

int main(void)
{
        p++;
        __asm__ __volatile__ (""::);
        p+=8;
}
===============================================

Still, it is compiled like this:
gcc -S -O2 -o xxx.s xxx.c
According to the assembly code, we found that gcc merge the 'p++' & 'p+=8' 
and generate 'addl $36, p'

We have the intuition that if '__asm__ __volatile ...' is used, the code 
will be separated into two parts and will not be merged together for 
optimization.
Are we right?
If so, why should the second case happen? Is it a bug or something else?

gcc version is 4.1.2

Really appreciate your answer. With many thanks!


***********************************************
Beijing Sunnorth eCos Maintainer Group

Maintainers:
li...@sunnorth.com.cn
tai...@sunnorth.com.cn
yxing...@sunnorth.com.cn

Bejing Sunnorth Electronic Technology Co.,LTD
***********************************************

Reply via email to