[fpc-devel] Debugging Loop Unroll Optimization

J. Gareth Moreton gareth at moreton-family.com
Fri May 18 15:07:12 CEST 2018


That looks sensible. Sorry to waste your time on this.  I'm glad it states
the for-loop variable will be left undefined - that's good enough
documentation for me.

I wouldn't call it a quick fix... more of fixing an oversight, since I can
see the trick of using Result as the for-counter being very easily
overlooked.  Of course, the perfect fix is only counting "exitn" if the
for-loop counter is Result.  One to test for later.

Gareth aka. Kit


 On Fri 18/05/18 14:40 , Martok listbox at martoks-place.de sent:
 > Citation: "If the loop was terminated prematurely with an exception or a

 > break statement, the loop variable retains the value it had when the 
 > loop was exited." 
 As a quick fix, not unrolling loops left with exit at least fixes this
 situation. This still leaves exceptions raised, but IIRC the handlers
 restore context anyways, we might be okay? 

 diff --git a/compiler/optloop.pas b/compiler/optloop.pas 
 index 46039ffc5a..dc714ea2cc 100644 
 --- a/compiler/optloop.pas 
 +++ b/compiler/optloop.pas 
 @@ -76,7 +76,7 @@ unit optloop; 

 function checkbreakcontinue(var n:tnode; arg: pointer): foreachnoderesult;

 - if n.nodetype in [breakn,continuen] then 
 + if n.nodetype in [breakn,continuen,exitn] then 

 I'll be running this on today's snapshot, see if anything else remains. 


 fpc-devel maillist - fpc-devel at lists.freepascal.org [1] 
 http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel [2]"


[1] mailto:fpc-devel at lists.freepascal.org
[2] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180518/db84c2b5/attachment.html>

More information about the fpc-devel mailing list