Zend certified PHP/Magento developer

avr-gcc optimisations are not always optimal? [migrated]

Please consider this bit of assembly code:

 924:   70 e0           ldi r23, 0x00   ; store 0 in r23
 926:   76 2f           mov r23, r22    ; copy r22's value to r23

(It was generated by avr-gcc with the (default) -Os option active.)

Why does it do this?
It makes no sense that I can fathom, to first store 0x00 in r23 and then overwrite r23 with r22.

Waste of a clock cycle, and memory space, in my humble opinion.

This is not a singular occurrence though, it happens all over the place.

Sometimes even:

eor r2, r2   ; zero r2
mov r2, r18  ; copy r18 to r2

occurs.

Why?

(Before you answer, I know that in the latter example of the “extraneous” instructions, the zero flag is set, yet is ignored or changed, by the code following it.)

Any software update, that has been compiled with a “new” and “better” compiler, eliminating the extra codes, therefore yields a speed increase, without changing the source code itself.

This stinks.

Nay, it reeks.

I’m curious if you have had the same experience, and opted to use inline assembly yourself, because the compiler just couldn’t “cut it”.

Thanks for your feedback.