I had to optimize my C code for speed to achieve some time constraints
in my requirements.
I tried -O3 to get best results, but my code crashed. I found out
looking at the generated assembly code, that the compiler failed to
notice subroutines with a pointer to a local variable might indeed
change it.
How come such an oversight happen?
Is there a way to prevent the compiler to do such risky assumptions?
Thanks for your help,
Roland.
PS: I use GCC 4.1.1 to compile C source to PowerPC assembly.
Also, even using -O1 gave me "corrupt" code.
Aure you sure that it's not your fault? (read: Are you sure you don't
invoke undefined behaviour?) I can think of the following possibility:
The compiler rearranged some instructions in a way that you didn't
anticipate because you violated the strict aliasing rules.
Without seeing the code we can't tell for sure.
Cheers!
SG
> Hello,
>
> I had to optimize my C code for speed to achieve some time constraints
> in my requirements.
If it's C code you may be better off posting to comp.lang.c rather than
here.
> I tried -O3 to get best results, but my code crashed. I found out
> looking at the generated assembly code, that the compiler failed to
> notice subroutines with a pointer to a local variable might indeed
> change it.
Impossible to check without seeing any code.Why not post a minimal program
exhibiting the problem, then others can check your result.
If it is indeed a compiler bug then you should, of course, report it to
the developers.
> How come such an oversight happen?
If it is a bug, then the answer is: compiler writers are generally humans
> Is there a way to prevent the compiler to do such risky assumptions?
What risky assumptions exactly? In what context? We don't know without
seeing code.
> Thanks for your help,
> Roland.
>
> PS: I use GCC 4.1.1 to compile C source to PowerPC assembly. Also, even
> using -O1 gave me "corrupt" code.
So -O3 is not the problem?
--
Lionel B
Without any code, the best suggestion you can get is: usually, between
the compiler and the programmer, it's the last one that is wrong.
Best wishes,
Zeppe