Compiler: MikroC Pro for 8051
Version: 3.6.0
Chip: C8051F350
" 'n' has been eliminated by optimizer"
This is a warning which I get many times, despite the fact that the "eliminated" variables are in use. The program works well, so I guess that this is a false warning which can be ignored?
Is there a way to avoid it?
Optimizer problem
- jovana.medakovic
- mikroElektronika team
- Posts: 986
- Joined: 18 Dec 2018 10:36
Re: Optimizer problem
Hello,
Could you zip and send me your project for review?
Kind regards,
Jovana
Could you zip and send me your project for review?
Kind regards,
Jovana
Re: Optimizer problem
Thanks for your attention. Here is a piece of code which triggers the optimizer problem.
void alpha(void);
void main()
{
alpha();
while (1) {
}
}
void alpha()
{
char n;
long w;
w = 245000000;
n = (char) w;
TL1 = n;
}
void alpha(void);
void main()
{
alpha();
while (1) {
}
}
void alpha()
{
char n;
long w;
w = 245000000;
n = (char) w;
TL1 = n;
}
- jovana.medakovic
- mikroElektronika team
- Posts: 986
- Joined: 18 Dec 2018 10:36
Re: Optimizer problem
Hello,
Because this code is so simple, in which one value is being moved from a variable to a variable and then into a register, compiler takes the opportunity and speeds this up by simply writing the value into the register right away, leaving the variables you defined unused, hence the "has been eliminated" message. This you can see by opening assembly code.
You can go to Tools -> Options -> Output Settings and set Optimisation level to zero and then you will not get this warning.
Kind regards,
Jovana
Because this code is so simple, in which one value is being moved from a variable to a variable and then into a register, compiler takes the opportunity and speeds this up by simply writing the value into the register right away, leaving the variables you defined unused, hence the "has been eliminated" message. This you can see by opening assembly code.
You can go to Tools -> Options -> Output Settings and set Optimisation level to zero and then you will not get this warning.
Kind regards,
Jovana
Re: Optimizer problem
Thanks Jovana for your explanation. Without inhibiting the optimizer by setting its level to zero, I understand that this warning simply means that the compiler is able to bypass intermediary assignments and doesn't need temporary variables. So, I can remove them myself.