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

Christo Crause christo.crause at gmail.com
Wed Jul 31 21:46:02 CEST 2019


On Tue, Jul 23, 2019 at 9:49 PM Christo Crause <christo.crause at gmail.com>
wrote:

> 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?
>

After some more testing i think my approach to fixing this is completely
backwards.  The issue (of redundant code generation) is probably better
addressed upstream (at node level?) by identifying that the parameter is
unused and hence code should not be generated in the first place.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190731/24dfc387/attachment.html>


More information about the fpc-devel mailing list