https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115726
Bug ID: 115726 Summary: [avr] Wrong code with __memx and local register variables Product: gcc Version: 14.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: gjl at gcc dot gnu.org Target Milestone: --- Created attachment 58548 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58548&action=edit GNU-C99 test case When the result of a read from address-space __memx is forced into some register, wrong code might be generated. Reason is that respective insns expand with clobbers of some hard registers that they will use later on. With the attached test case for example, with avr-gcc-v14.1 -mmcu=atmega128 -Os -dp -S the generated assembly is basically like: xload8_r30: ;; mov r24,r30 ; 17 [c=4 l=1] movqi_insn/0 ret ; 20 [c=0 l=1] return xload16_r30: ;; movw r24,r30 ; 17 [c=4 l=1] *movhi/0 ret ; 20 [c=0 l=1] return xload8_r22: ;; mov r24,r22 ; 17 [c=4 l=1] movqi_insn/0 ret ; 20 [c=0 l=1] return xload16_r22: ;; movw r24,r22 ; 17 [c=4 l=1] *movhi/0 ret ; 20 [c=0 l=1] return so not a single load is present.