public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: "Eli Zaretskii" <eliz@gnu.org>
To: gdb@sources.redhat.com, Reiner.Steib@gmx.de
Subject: Re: Variable "foo" is not available
Date: Mon, 04 Apr 2005 19:35:00 -0000	[thread overview]
Message-ID: <01c5394c$Blat.v2.4$e4580a80@zahav.net.il> (raw)
In-Reply-To: <20050404133743.GA32163@nevyn.them.org> (message from Daniel Jacobowitz on Mon, 4 Apr 2005 09:37:44 -0400)

> 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?

  reply	other threads:[~2005-04-04 19:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-01 16:40 Reiner Steib
2005-04-01 17:19 ` Daniel Jacobowitz
2005-04-02  9:49   ` Eli Zaretskii
2005-04-02 13:53     ` Reiner Steib
2005-04-02 14:27       ` Daniel Jacobowitz
2005-04-06 16:25         ` Reiner Steib
2005-04-02 14:26     ` Daniel Jacobowitz
2005-04-02 18:17       ` Eli Zaretskii
2005-04-02 18:40         ` Daniel Jacobowitz
2005-04-02 20:58           ` Eli Zaretskii
2005-04-02 21:05             ` Daniel Jacobowitz
2005-04-04  5:14               ` Eli Zaretskii
2005-04-04  6:00                 ` Mark Kettenis
2005-04-04  7:58                 ` Daniel THOMPSON
2005-04-04 19:28                   ` Eli Zaretskii
2005-04-04 13:37                 ` Daniel Jacobowitz
2005-04-04 19:35                   ` Eli Zaretskii [this message]
2005-04-04 19:41                     ` Daniel Jacobowitz
2005-04-03 18:16           ` Reiner Steib
2005-04-08 11:05       ` Eli Zaretskii
2005-04-04  9:26     ` Reiner Steib

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='01c5394c$Blat.v2.4$e4580a80@zahav.net.il' \
    --to=eliz@gnu.org \
    --cc=Reiner.Steib@gmx.de \
    --cc=gdb@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).