[fpc-devel] Progress of pure function research

Martok listbox at martoks-place.de
Mon Jul 16 12:43:58 CEST 2018


Am 16.07.2018 um 07:01 schrieb J. Gareth Moreton:
> As stated in the Wiki page, my first test case is the Max function.  Since it
> works both as an inline and a pure function, I can easily change the directive to
> analyse the code flow in the compiler.
I may have missed this in the discussion before. But isn't that a prime example
for "simple" const propagation?

==========================================
function Max(a, b: integer): integer; inline;
begin
  if a > b then
    Result:= a
  else
    Result:= b;
end;

  z:= Max(1, 2);
==========================================
That already gets optimized to `z:= 2;` on -O1, while the following needs -O2,
but gets to the same result:
==========================================
  x:= 1;
  y:= 2;
  z:= Max(x, y);
==========================================

Tail recursion expansion could do the same for certain recursive functions.


-- 
Regards,
Martok





More information about the fpc-devel mailing list