Optimiser destroys loop! 
Author Message
 Optimiser destroys loop!

The following fragment has always looped times 256 until it
met VC5's optimiser, when it compiled just a single pass!!

Anyone met this?

Bill

unsigned char byte = 0;
do {
   ...
   byte++;

Quote:
} while (byte !=0)



Sat, 29 Jun 2002 03:00:00 GMT  
 Optimiser destroys loop!
Have you installed Service Pack 3 for VC5?  There were a number of
Optimizer bugs fixed in it.


Quote:
> The following fragment has always looped times 256 until it
> met VC5's optimiser, when it compiled just a single pass!!

> Anyone met this?

> Bill

> unsigned char byte = 0;
> do {
>    ...
>    byte++;
> } while (byte !=0)



Sat, 29 Jun 2002 03:00:00 GMT  
 Optimiser destroys loop!
Before the loop, byte was zero. After the loop byte was zero (and nothing
else had changed). So why bother doing the loop? At least that _may_ be what
the optimiser thinks...

NeilB

Quote:
> The following fragment has always looped times 256 until it
> met VC5's optimiser, when it compiled just a single pass!!

> Anyone met this?

> Bill

> unsigned char byte = 0;
> do {
>    ...
>    byte++;
> } while (byte !=0)



Sat, 29 Jun 2002 03:00:00 GMT  
 Optimiser destroys loop!
That's basically why it is called an optimizer, if you put a loop that has
no effect (like a delay loop, the loop compiles to:

    byte=0;

All depends on what kind of code was in the "..." part of your snipet. If
there is anything that uses the current value of byte then the optimzer
cannot get rid of the loop and you'll keep your 256 iterations.

Hope it helped

Stephane


Quote:
> The following fragment has always looped times 256 until it
> met VC5's optimiser, when it compiled just a single pass!!

> Anyone met this?

> Bill

> unsigned char byte = 0;
> do {
>    ...
>    byte++;
> } while (byte !=0)



Sat, 29 Jun 2002 03:00:00 GMT  
 Optimiser destroys loop!
William,

Erik and others already answered most of the question. Just one final
comment: as an [at least iterim] fix, you can use the #pragma optimize
directive to turn off optimizations for the problematic function.

--
Tomas Restrepo
http://members.xoom.com/trestrep/

Quote:
> The following fragment has always looped times 256 until it
> met VC5's optimiser, when it compiled just a single pass!!

> Anyone met this?

> Bill

> unsigned char byte = 0;
> do {
>    ...
>    byte++;
> } while (byte !=0)



Sat, 29 Jun 2002 03:00:00 GMT  
 Optimiser destroys loop!

Quote:

> The following fragment has always looped times 256 until it
> met VC5's optimiser, when it compiled just a single pass!!
> Anyone met this?
> Bill

> unsigned char byte = 0;
> do {
>    ...
>    byte++;
> } while (byte !=0)

Try this:
======================
#pragma optimize("",off)
unsigned volatile char byte = 0;
do
{
        ....
        byte++;
Quote:
} while (byte != 0)

#pragma optimize("",on)
======================

--
Anton N. Breusov 'Antonz'.



Sun, 30 Jun 2002 03:00:00 GMT  
 Optimiser destroys loop!


Quote:
> The following fragment has always looped times 256 until it
> met VC5's optimiser, when it compiled just a single pass!!

> Anyone met this?

> Bill

> unsigned char byte = 0;
> do {
>    ...
>    byte++;
> } while (byte !=0)

Thanks for all the prompt replies! I am assured that we have
SP3 of Dev Studio in place (C1.dll version 11.00.7113, C2.exe
version 11.00.7303?). There is lots of code in the loop
employing byte to set a static array of structures. If you
initialise byte=1, then you get the expected effect. VC6 does
not exhibit the problem, but we can't use that yet. Looks
like a #pragma or a for loop! Microsoft have been informed...

Bill

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 30 Jun 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. C source code optimisers?

2. Binary code optimiser

3. OPTIMISERS in C for SUN PLATFORMS

4. GLOBAL OPTIMISER FOR UNIX PLATFORMS

5. For loops into for loops

6. Loop or Loops in "C"

7. (Newbie) My Loop Isn't Looping - Aargh!

8. SEMA - WHILE loop in a FOR loop !

9. For loops into for loops

10. wanted - C and/or Fortran source for 24-loop Livermore Loops

11. vector<CMyClass> push_back() loops on destroy because of incorrect element size. OK in VC6

12. char *pmychar; destroys when out of scope, or destroy it explicitly?

 

 
Powered by phpBB® Forum Software