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

Florian Klämpfl florian at freepascal.org
Sun May 27 14:00:14 CEST 2018


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
> 
> 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.



More information about the fpc-devel mailing list