I vaguely recall from when I first started with gcc in the early '90s
that the gcc developers disavowed correctness for unoptimized code,
saying they always used -O.  That may be apocryphal, and is certainly
not true for the msp430 back end while I'm responsible for it.

However, gcc's internals are significantly simplified by generating
the most obvious code possible from what the front-end requires.
Without -O, that's what you're going to get, even if it involves
moving a value from one location to another six times before returning
it.

It's not being stupid; it's just doing what you told it to do.

Peter

int retval (int v)
{
  int t1 = v;
  int t2 = t1;
  int t3 = t2;
  int t4 = t3;
  int t5 = t4;
  return t5;
}


On Mon, Apr 18, 2011 at 9:27 AM, JMGross <msp...@grossibaer.de> wrote:
> It compiles well with or without optimization and is always inlined.
> It still lets the compiler decide where to put the result (memory, register, 
> whatever) and
> without optimization generates still some unnecessary stuff, but less that 
> the original version.
> And it works.
> With optimization, the result is identical to the original.

------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload 
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve 
application availability and disaster protection. Learn more about boosting 
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to