pms <[email protected]> writes:
> My question is as follwos
>
> We've a problem here. we were trying to use cc1 with & without -O option to
> verify the optimizations happening in our sample code.
> the sample code is given below
> file name : 1.c
> #include
> int main()
> { int a=5;
> int b;
> b=a;
> printf("the number is :%d",b); }
> Here, in 1.c.026t.copyrename1, we get the following output
>
> 1.c.026t.copyrename1
> ;; Function main (main)
> main ()
> { int b; int a; : a_2 = b_1(D); return; }
> but in 1.c.027t.ccp1, the output does not contain the actual assignment
> b=a.
> ;; Function main (main)
> main ()
> { int b; int a; : return; }
> We want to know, without b=a, how is it generating the following final code
> for b=a
> pushl %ebp
>> movl %esp, %ebp
>> andl $-16, %esp
>> subl $16, %esp
>> movl $5, 4(%esp)
>> movl $.LC0, (%esp)
>> call printf
No code is generated for the statement "b=a". In effect, the program is
optimized into
printf("the number is :%d",5);
as that is equivalent to the original program.
This is a very simple compiler optimization. Please consider taking
future questions about code generation to the mailing list
[email protected]. The mailing list [email protected] is for gcc
developers. Thanks.
Ian
>> thanks, But b=a is a assignment statement. It is doing some memory
>> operations
>> isn't it. Assuming b=a is a dead statement, how r the following i386
>> assembly statements generated
>> pushl %ebp
>> movl %esp, %ebp
>> andl $-16, %esp
>> subl $16, %esp
>> movl $5, 4(%esp)
>> movl $.LC0, (%esp)
>> call printf
>
> The first four statements set up the stack. The last three do the
> printf statement.
>
> What is your real question?
>
> Ian