Optimizer problem

General discussion on mikroC PRO for 8051.
Post Reply
Author
Message
adaniel
Posts: 28
Joined: 03 Feb 2016 15:17

Optimizer problem

#1 Post by adaniel » 17 Jul 2019 17:34

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?

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: Optimizer problem

#2 Post by jovana.medakovic » 18 Jul 2019 09:24

Hello,

Could you zip and send me your project for review?

Kind regards,
Jovana

adaniel
Posts: 28
Joined: 03 Feb 2016 15:17

Re: Optimizer problem

#3 Post by adaniel » 18 Jul 2019 11:19

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;
}

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: Optimizer problem

#4 Post by jovana.medakovic » 18 Jul 2019 15:08

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

adaniel
Posts: 28
Joined: 03 Feb 2016 15:17

Re: Optimizer problem

#5 Post by adaniel » 18 Jul 2019 16:31

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.

Post Reply

Return to “mikroC PRO for 8051 General”