This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Variable "foo" is not available


> Date: Mon, 4 Apr 2005 09:37:44 -0400
> From: Daniel Jacobowitz <drow@false.org>
> Cc: gdb@sources.redhat.com, Reiner.Steib@gmx.de
> 
> int foo();
> int foo2 (int *);
> int bar(int a)
> {
>   foo ();
>   a += 3;
>   foo2 (&a);
>   return a + foo();
> }
> 
>    0:   55                      push   %ebp
>    1:   89 e5                   mov    %esp,%ebp
>    3:   83 ec 08                sub    $0x8,%esp
>    6:   e8 fc ff ff ff          call   7 <bar+0x7>
>    b:   83 45 08 03             addl   $0x3,0x8(%ebp)
>    f:   8d 45 08                lea    0x8(%ebp),%eax
>   12:   89 04 24                mov    %eax,(%esp)
>   15:   e8 fc ff ff ff          call   16 <bar+0x16>
>   1a:   e8 fc ff ff ff          call   1b <bar+0x1b>
>   1f:   8b 55 08                mov    0x8(%ebp),%edx
>   22:   89 ec                   mov    %ebp,%esp
>   24:   5d                      pop    %ebp
>   25:   01 d0                   add    %edx,%eax
>   27:   c3                      ret
> 
> See the instruction at 0xb?

But this kind of code is only possible if the compiler examines all
the callers of `bar' and finds that none of them uses the value of
`bar's argument after `bar' returns.  So such code is probably only
possible in practice with static functions, right?  Or am I missing
something?

Also, is such optimizations really worth it?  I mean, the more
traditional code will mov the argument into a register and do the math
there; is adding to a memory location really faster than a mov and a
register-based add?

> GCC won't reuse the slot for an unrelated variable at present. 
> However, in the future, it would be a valid optimization.

Again, only if the compiler has enough information about the callers,
right?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]