public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Local variables optimization
@ 2005-07-24  3:52 Hanzac Chen
  2005-07-24  5:55 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Hanzac Chen @ 2005-07-24  3:52 UTC (permalink / raw)
  To: gcc

Hi,

Some idea: Maybe local stack use in the code compiled by GCC should be
optimized 'cause some local variables are conditional. If the condition
is not satisfied, then these variables don't need to be allocated from
the stack (e.g. sub $VAR_SIZE, %esp).

For example:

int *func(unsigned int cond, unsigned i)
{
   switch (cond)
   {
	case 1:
	{  int d[0x10];
	   i = memset(d, i, 0x10);
	}
	case 2:
	{  int e[0x10];
	   i = memset(e, i, 0x10);
	}
	case 3:
	{  int f[0x10];
	   i = memset(f, i, 0x10);
	}
	default:
	  break;
   }
   return 1;
}

After compiled by GCC, you'll see GCC allocated all the local variables
in case 1/case 2/case 3, this is stupid.

Hanzac

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Local variables optimization
  2005-07-24  3:52 Local variables optimization Hanzac Chen
@ 2005-07-24  5:55 ` Ian Lance Taylor
  2005-07-24  6:50   ` Hanzac Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2005-07-24  5:55 UTC (permalink / raw)
  To: Hanzac Chen; +Cc: gcc

Hanzac Chen <hanzac@gmail.com> writes:

> Some idea: Maybe local stack use in the code compiled by GCC should be
> optimized 'cause some local variables are conditional. If the condition
> is not satisfied, then these variables don't need to be allocated from
> the stack (e.g. sub $VAR_SIZE, %esp).

You neglected to mention which version of gcc you were using, or which
target.  The description and test case sound like GCC PR 9997:
    http://gcc.gnu.org/PR9997
which was fixed for the 4.0 release.

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Local variables optimization
  2005-07-24  5:55 ` Ian Lance Taylor
@ 2005-07-24  6:50   ` Hanzac Chen
  0 siblings, 0 replies; 3+ messages in thread
From: Hanzac Chen @ 2005-07-24  6:50 UTC (permalink / raw)
  To: gcc

Ian Lance Taylor wrote:
> You neglected to mention which version of gcc you were using, or which
> target.  The description and test case sound like GCC PR 9997:
>     http://gcc.gnu.org/PR9997
> which was fixed for the 4.0 release.
Sorry, I'm using GCC 3.4.4, haven't tested on 4.0.X.
I saw the PR 9997, yes, that's it.

Thanks,
Hanzac

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-07-24  6:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-24  3:52 Local variables optimization Hanzac Chen
2005-07-24  5:55 ` Ian Lance Taylor
2005-07-24  6:50   ` Hanzac Chen

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).