View Issue Details

IDProjectCategoryView StatusLast Update
0036542FPCCompilerpublic2020-01-09 16:34
ReporterUgochukwu Mmaduekwe Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version3.3.1 
Summary0036542: Compiler fails to inline simple code.
DescriptionCompiler fails to inline simple code even in O4 optimization

Below is a comparison of Delphi 10.2.3 x86_64 output and that of FPC 3.3.1 -r43642 [2019/12/05] for x86_64 on Windows


Delphi 10.2.3
// Main() Procedure Start
InliningDemo.dpr.14: begin
0000000000426F70 55 push rbp
0000000000426F71 4883EC30 sub rsp,$30
0000000000426F75 488BEC mov rbp,rsp
InliningDemo.dpr.15: ZeroMemory(LBuffer, System.SizeOf(LBuffer));
==================================================== ZeroMemory Function Inline Start
0000000000426F78 488D4D2B lea rcx,[rbp+$2b]
0000000000426F7C C7C205000000 mov edx,$00000005
0000000000426F82 4D33C0 xor r8,r8
0000000000426F85 E846F4FDFF call @FillChar
==================================================== ZeroMemory Function Inline End
InliningDemo.dpr.16: end;
0000000000426F8A 488D6530 lea rsp,[rbp+$30]
0000000000426F8E 5D pop rbp
0000000000426F8F C3 ret
// Main() Procedure End

=================================================================================
FPC Trunk

// Main() Procedure Start
# [14] begin
    leaq -40(%rsp),%rsp
# [15] ZeroMemory(LBuffer, System.SizeOf(LBuffer));
    leaq 32(%rsp),%rax
    movl $5,%edx
    movq %rax,%rcx
    call P$INLININGDEMO_$$_ZEROMEMORY$formal$LONGINT ==> Call instead of inline
# [16] end;
    nop
    leaq 40(%rsp),%rsp
        ret
// Main() Procedure End


Steps To Reproduce Compile InliningDemo.lpr with -al flag and examine the output assembler.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Ugochukwu Mmaduekwe

2020-01-09 13:08

reporter  

InliningDemo.lpr (422 bytes)   
program InliningDemo;

uses
  SysUtils;

procedure ZeroMemory(var ADestination; ACount: Int32); inline;
begin
  FillChar(ADestination, ACount, 0);
end;

procedure Main();
var
  LBuffer: array [0 .. 4] of Byte;
begin
  ZeroMemory(LBuffer, System.SizeOf(LBuffer));
end;

begin
  try
    Main();
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;

end.
InliningDemo.lpr (422 bytes)   

Marco van de Voort

2020-01-09 16:34

manager   ~0120292

Well, that is fairly wellknown, since compiling it gives the following note:

indemo.lpr(10,4) Note: "formal parameter" not yet supported inside inline procedure/function

Issue History

Date Modified Username Field Change
2020-01-09 13:08 Ugochukwu Mmaduekwe New Issue
2020-01-09 13:08 Ugochukwu Mmaduekwe File Added: InliningDemo.lpr
2020-01-09 16:34 Marco van de Voort Note Added: 0120292