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
