[fpc-devel] generate assembler with no clear purpose MOV

Marģers . margers.roked at inbox.lv
Tue Feb 4 19:20:22 CET 2020


 hi 
example code:
function roo(lk:longint):byte;
var k : longint;
    bit : longint;
    num : byte;
begin
     num:=0;
     for k:=0 to 25 do
     begin
          bit:= longint(1) shl k;
          if (lk and bit) <> 0 then
          begin
               lk:=lk xor bit;
               inc(num);
          end;
     end;
     roo:=num;
end;
begin
end.

asm code 
# [109] bit:= longint(1) shl k;
    movslq    %ecx,%rdx
    # Register r8d allocated
    movl    $1,%r8d
    # Register edx,edx allocated
    shlx    %edx,%r8d,%edx
    # Register r8d released
    # Register edx allocated
    movl    %edx,%esi
# Peephole Optimization: %esi = %edx; changed to minimise pipeline stall (MovXXX2MovXXX)
# Peephole Optimization: Mov2Nop 4 done


what purpose serve: movslq    %ecx,%rdx   ?

movl    %edx,%esi seems unnecessary, 
when just enough would be
movl    $1,%esi
shlx    %ecx,%esi,%esi



More information about the fpc-devel mailing list