Page 1 of 1

Optimizer problem

Posted: 17 Jul 2019 17:34
by adaniel
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?

Re: Optimizer problem

Posted: 18 Jul 2019 09:24
by jovana.medakovic
Hello,

Could you zip and send me your project for review?

Kind regards,
Jovana

Re: Optimizer problem

Posted: 18 Jul 2019 11:19
by adaniel
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;
}

Re: Optimizer problem

Posted: 18 Jul 2019 15:08
by jovana.medakovic
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

Re: Optimizer problem

Posted: 18 Jul 2019 16:31
by adaniel
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.