[fpc-devel] AVR - redundant mov followed by ldi instruction

Christo Crause christo.crause at gmail.com
Tue Jul 23 21:49:18 CEST 2019


The following test code generates a redundant mov instruction which seems
to be related to a situation with an unused procedure parameter and the
inc() procedure:

program testRegAlloc;
var
  a, b: byte;
procedure testDummyParam(var x: byte);
begin
  inc(a);
end;
begin
  testDummyParam(b);
end.

The generated code for testDummyParam:
  mov r18, r24
  ldi r18, 0x00 ; 0
  ldi r19, 0x01 ; 1
  movw r30, r18
  ld r20, Z
  inc r20
  movw r30, r18
  st Z, r20
  ret

Moving r24 to r18 is redundant since it will be overwritten by the next ldi
instruction.  Attached is a patch that can identify this situation and
eliminate the redundant mov.  Is it the correct approach to fix this in the
peephole optimizer, or can it be fixed at an earlier stage?

best wishes,
Christo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190723/713c2443/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: remove-redundant-mov.patch
Type: text/x-patch
Size: 1195 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190723/713c2443/attachment.bin>


More information about the fpc-devel mailing list