Local variables optimization

Hanzac Chen hanzac@gmail.com
Sun Jul 24 03:52:00 GMT 2005


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



More information about the Gcc mailing list