<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body smarttemplateinserted="true" text="#000000" bgcolor="#FFFFFF">
    Hi,<br>
    <br>
    why does fpc not remove the calculation of the return value of
    inline functions, when the return value is unused?<br>
    <br>
    For example<br>
    <br>
    type TUtility = class<br>
      function doSomething: TUtility; inline;<br>
    end;<br>
    <br>
    function TUtility.dosomething: TUtility;<br>
    begin<br>
       writeln();<br>
       result := self;<br>
    end;<br>
    <br>
    adds a mov    rax,rdi in the caller function, even if rax is then
    never used.<br>
    <br>
    {<br>
    26      begin<br>
       0x00000000004001c0 <+0>:     push   rbx<br>
    <br>
    27        ut := TUtility.Create;<br>
       0x00000000004001c1 <+1>:     movabs rsi,0x1<br>
       0x00000000004001cb <+11>:    lea   
    rdi,[rip+0x2b2fde]        # 0x6b31b0
    <VMT_$WTFINLINE_$$_TUTILITY><br>
       0x00000000004001d2 <+18>:    call   0x411b60
    <SYSTEM$_$TOBJECT_$__$$_CREATE$$TOBJECT><br>
       0x00000000004001d7 <+23>:    mov    rbx,rax<br>
    <br>
    28        ut.dosomething;<br>
       0x00000000004001da <+26>:    call   0x41bf20
    <fpc_get_output><br>
       0x00000000004001df <+31>:    mov    rdi,rax<br>
       0x00000000004001e2 <+34>:    call   0x41c100
    <fpc_writeln_end><br>
       0x00000000004001e7 <+39>:    call   0x416170
    <fpc_iocheck><br>
       0x00000000004001ec <+44>:    mov    rdi,rbx<br>
       0x00000000004001ef <+47>:    mov    rax,rdi           
    //<----------------------------------------------- here<br>
    <br>
    29        ut.free;<br>
       0x00000000004001f2 <+50>:    call   0x411cd0
    <SYSTEM$_$TOBJECT_$__$$_FREE><br>
    <br>
    30      end;<br>
       0x00000000004001f7 <+55>:    pop    rbx<br>
       0x00000000004001f8 <+56>:    ret    <br>
    }    <br>
    <br>
    <div id="smartTemplate4-template"><br>
      It is a popular pattern to add result := self; to _every_ method
      (or result := @self in objects/records), so it can be chained as
      dosomething().dosomething().dosomething(),.....<br>
      but one cannot use it with fpc efficiently, when it inserts too
      many unnecessary instructions<br>
      <br>
      <br>
      <br>
      Best,<br>
      <p>Benito </p>
    </div>
    <br>
  </body>
</html>