Re: Questions in Optimization !!



On Feb 6, 10:31 pm, satish....@xxxxxxxxx wrote:
On Feb 6, 11:15 pm, Bill Cox <b...@xxxxxxxxxxxx> wrote:



satish....@xxxxxxxxx wrote:
My question is what is "function prolog" here?

A function prolog is code generated by the compiler to set up a
function's stack frame, make the actual parameters accessible,
and generally get ready for the first explicit source line of
the function to run. It corresponds to the function's opening
curly brace.

There's similar epilog code generated to delete the stack frame and
return to the calling function. It corresponds to the function's
closing curly brace.

2. We tried with out optimization ie."-O0" option. There it was
working even with out option " -mno-sched-prolog".- Hide quoted text -

- Show quoted text -

Hi,

But how option "-mno-sched-prolog" making my application working fine?

I would like to know the details of this option. Because in gcc
manuals, it was mentioned that the default will be taken as "-m-sched-
prolog". Is this option will be enabled only when we use optimization?

Because I tried by giving "-O0". My application was working wiht out
adding "-mno-sched-prolog" .

But the same when I tried with "-O2", it is wokring fine only If I add
option "-mno-sched-prolog".

Can you please give me detail information regarding this.?

Regards
Satish.

In my experience, there are a couple of things that could cause this
sort of problem:

1) a compiler bug
2) a bug in your code

I'm inclined to think the problem is in your code. This isn't to say
that the problem is absolutely, positively not a compiler bug, because
compiler bugs do happen. (I know: I've found a couple.) But the rule
of thumb is to assume the problem is your fault first, and then start
looking at the compiler only once you've ruled out all other
possibilities.

"But it works as long as I don't use optimization! My code must be ok,
right?"

No, wrong. It's probably just pure luck that it works without
optimization. I'll bet you a quarter that compiling the same code on
another architecture (pentium, MIPS) would result in a runtime failure
whether you used optimization or not.

I would look for two things:

- Incorrect or missing use of the volatile keyword
- Incorrect use of local variables, resulting in stack corruption

You don't specify what this code is. If it's a device driver, or code
that communicates directly with hardware, then it's important to
properly use the volatile keyword for variables that reference, say,
memory mapped hardware registers, otherwise the compiler might decide
to optimize away some code which it thinks is unnecessary. For
example:

void foo(void)
{
UINT32 * regBase = 0xfe000000; /* Address where some device is
mapped */

*regBase = 0x1234; /* Command to reset hardware */
*regBase = 0x5678; /* Command to enable hardware */
}

Here, if you compile with optimization, the compiler will say "well, I
can save some time by throwing away the first assignment of *regBase,
since I know it's just going to be overwritten anyway," so the first
write to *regBase gets lost. To correct this, you have to declare
regBase as "volatile UINT32 *" instead of "UINT32 *" to tell the
compiler not to optimize the usage of the regBase pointer.

If it's not a device driver, then I'd look at the stack usage. It's
very possible your code is corrupting the stack somehow, and it
happens that the stack usage is different when the code is compiled
with optimization vs. when it's compiled without, and in the optimized
case, the corruption is immediately fatal. (It may ultimately be fatal
in the non-optimized case too, if you let the code run long enough.)

I strongly suggest you review your code and scrutinize it carefully
for bugs. Even better, get someone else to review it: sometimes a
fresh set of eyes will spot bugs that yours will miss.

-Bill
.



Relevant Pages

  • Re: Named stack items
    ... > done by the compiler when the code is developed. ... > separate step during which optimizing can be done. ... limited scope compiler targetting a stack machine. ... or some other optimization point of your choosing. ...
    (comp.lang.forth)
  • Re: I found a FORTH stack optimzer, but could use a better version.
    ... I've got no idea what he's doing in STACK in bld.fiv... ... examples of Forth that need optimization. ... As we go from design to edit to compile to test to ... This makes the compiler work easier. ...
    (comp.lang.forth)
  • Re: I found a FORTH stack optimzer, but could use a better version.
    ... I've got no idea what he's doing in STACK in bld.fiv... ... examples of Forth that need optimization. ... As we go from design to edit to compile to test to ... This makes the compiler work easier. ...
    (comp.lang.forth)
  • Re: Translate 6809 to C code
    ... Trying to work out why the compiler did it (without access to the ... turned out to be a really clever optimization -- which no human would have ... Hand-optimised assembler is often worse. ... in registers, often consistent stack frames, etc.), whereas assembler ...
    (comp.sys.m6809)
  • Re: Weird behaviour with intent
    ... Failure to do the optimization does not constitute a ... compiler bug in terms of implementing the standard (though it might ... indicate that the compiler has room to improve its optimization). ... still like this test - not because it illustrates a bug, ...
    (comp.lang.fortran)