[fpc-devel] Found compiler bug while working on Deep Optimiser

J. Gareth Moreton gareth at moreton-family.com
Sun May 27 16:58:56 CEST 2018


 That's some interesting insight - thanks Florian. Something that might
need rigorous timing tests in that case.  I thought about the binary
search map since the case statements jump to a procedure call, and I
wondered if I could take advantage of that homogenuity.  In the meantime,
I found a couple of peephole optimisations that don't rely on tricky code
like that in the bug report! I'll submit a patch later, just in case I find
a few more.

 Gareth aka Kit.

 On Sun 27/05/18 13:00 , Florian Klämpfl florian at freepascal.org sent:
 Am 27.05.2018 um 02:48 schrieb J. Gareth Moreton: 
 > Hi guys, 
 > 
 > So I'm still experimenting and researching with the deep optimiser, and
I'm starting to have some 
 > successes... until I found a compiler bug! 
 > 
 > https://bugs.freepascal.org/view.php?id=33794 [1] 
 > 
 > What I'm trying to do, and something which I'd like to try out with the
regular peephole optimiser 
 > at some point, is using a sorted list that maps an assembler command to
a handler procedure and 
 > using a binary search to find the correct routine.  This will speed up
the optimiser from O(n) (i.e. 
 > the speed of "case X of") to O(log n) per line of code, 

 FPC knows different means to generate code for case statements (linear
list, jump table, jump tree); 
 based on a heuristics the method is chosen. If in case of the assembler
optimizer, FPC chooses the 
 wrong approach, this heuristics should be checked, see e.g.
compiler/ncgset.pas:1170+: 

 { value has been determined on an i7-4770 using a random case with random
values 
 if more values are known, this can be handled depending on the target CPU 

 Testing on a Core 2 Duo E6850 as well as on a Raspi3 showed also, that 64
is 
 a good value } 
 else if labelcnt>=64 then 
 genjmptree(labels) 
 else 
 genlinearlist(labels); 

 The label count if a jmp tree is beneficial, is surprisingly high,
probably due to branch prediction 
 which breaks completely havoc in case of a jump tree. 
 _______________________________________________ 
 fpc-devel maillist - fpc-devel at lists.freepascal.org [2] 
 http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
[3]">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel 

 

Links:
------
[1] https://bugs.freepascal.org/view.php?id=33794
[2] mailto:fpc-devel at lists.freepascal.org
[3] 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/20180527/5616bc4e/attachment.html>


More information about the fpc-devel mailing list