From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22747 invoked by alias); 4 Apr 2005 19:35:03 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 22671 invoked from network); 4 Apr 2005 19:34:57 -0000 Received: from unknown (HELO legolas.inter.net.il) (192.114.186.24) by sourceware.org with SMTP; 4 Apr 2005 19:34:57 -0000 Received: from zaretski (IGLD-80-230-67-97.inter.net.il [80.230.67.97]) by legolas.inter.net.il (MOS 3.5.6-GR) with ESMTP id EBQ08468 (AUTH halo1); Mon, 4 Apr 2005 22:34:30 +0300 (IDT) Date: Mon, 04 Apr 2005 19:35:00 -0000 From: "Eli Zaretskii" To: gdb@sources.redhat.com, Reiner.Steib@gmx.de Message-ID: <01c5394c$Blat.v2.4$e4580a80@zahav.net.il> Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=ISO-8859-1 In-reply-to: <20050404133743.GA32163@nevyn.them.org> (message from Daniel Jacobowitz on Mon, 4 Apr 2005 09:37:44 -0400) Subject: Re: Variable "foo" is not available Reply-to: Eli Zaretskii References: <20050401171947.GA19058@nevyn.them.org> <01c53768$Blat.v2.4$d52008a0@zahav.net.il> <20050402142639.GA27550@nevyn.them.org> <01c537af$Blat.v2.4$c36667c0@zahav.net.il> <20050402184023.GA20247@nevyn.them.org> <01c537c6$Blat.v2.4$427763a0@zahav.net.il> <20050402210541.GA16758@nevyn.them.org> <01c538d4$Blat.v2.4$b261c020@zahav.net.il> <20050404133743.GA32163@nevyn.them.org> X-SW-Source: 2005-04/txt/msg00034.txt.bz2 > Date: Mon, 4 Apr 2005 09:37:44 -0400 > From: Daniel Jacobowitz > 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 > 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 > 1a: e8 fc ff ff ff call 1b > 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?