[fpc-devel] Does FPC optimize unused parameters ?

Martin lazarus at mfriebe.de
Fri Aug 24 12:33:50 CEST 2012


On 08/08/2012 15:37, Jonas Maebe wrote:
>
> Martin wrote on Wed, 08 Aug 2012:
>
>> Out of curiosity. Is there an optimization like this
> [removing calculation/load of unused parameters]
>
> No.

  Are you sure? It seems the compiler disagrees with you.

I  tested with 2.7.1 (updated yesterday):

function Foo(s:string): string;
begin
   Result := s;
   Form1.Caption := s;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   //DebugLn(['abc']);
   //DebugLn('abc');
   DebugLn(foo('abc'));
end;

The assembler for FormCreate (no optimization used). It even omits the 
call to "Foo"...

.section .text.n_unit1$_$tform1_$__$$_formcreate$tobject,"x"
     .balign 16,0x90
.globl    UNIT1$_$TFORM1_$__$$_FORMCREATE$TOBJECT
UNIT1$_$TFORM1_$__$$_FORMCREATE$TOBJECT:
.Lc6:
# Temps allocated between ebp-8 and ebp-8
     # Register ebp allocated
.Ll7:
# [42] begin
     pushl    %ebp
.Lc8:
.Lc9:
     movl    %esp,%ebp
.Lc10:
     subl    $8,%esp
# Temp -4,4 allocated
# Var Sender located at ebp-4
# Temp -8,4 allocated
# Var $self located at ebp-8
     # Register eax,edx allocated
     movl    %eax,-8(%ebp)
     # Register eax released
     movl    %edx,-4(%ebp)
     # Register edx released
# Temp -4,4 released
# Temp -8,4 released
.Ll8:
# [46] end;
     leave
     # Register ebp released
     ret
.Lc7:
.Lt2:
.Ll9:
# End asmlist al_procedures
# Begin asmlist al_globals




More information about the fpc-devel mailing list