[fpc-devel] Debugging Loop Unroll Optimization

Marco van de Voort marcov at stack.nl
Fri May 18 17:17:51 CEST 2018


In our previous episode, Mattias Gaertner said:
> > Well, well, clearly. One could interpret it that it says that the for
> > statement terminates naturally if not forced by break or exit.  It doesn't
> > say what happens with break or exit.
> 
> If the value of counter is undefined no matter what, then you would
> not bother writing the exception in the brackets, wouldn't you?

I would not try to interpret an ambiguous line, and look for alternate
sources of info.

Seems that those are there, so that is case closed, and the only possible
outcome is to try to disable certain optimizations for FOR statements that
have multiple exit points or adapt the optimizations.
 
> > The fact that this exception is not documented with an example makes it very
> > ambiguous IMHO.
> 
> I found a dozen places in the VCL using this. 
> For Result:=...do if ... then exit;

To keep in annoying detail mode:

   for result:=0 to 3 do
     if x(result) then
       exit(result)

...is yet another case since the exit(result) could be taken as an explicit
assignment of the loopvar to an location outside the loop, after which the
loopvar scope ends.




More information about the fpc-devel mailing list