<div dir="ltr"><div>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:</div><div><br></div><div>program testRegAlloc;<br>var<br>  a, b: byte;<br>procedure testDummyParam(var x: byte);<br>begin<br>  inc(a);<br>end;<br>begin<br>  testDummyParam(b);<br>end.</div><div><br></div><div>The generated code for testDummyParam:</div><div></div><div>  mov   r18, r24<br>  ldi        r18, 0x00       ; 0<br>  ldi     r19, 0x01       ; 1<br>  movw    r30, r18<br>  ld r20, Z<br>  inc  r20<br>  movw    r30, r18<br>  st Z, r20<br>  ret</div><div><br></div><div>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?</div><div><br></div><div>best wishes,</div><div>Christo<br></div></div>