------- Comment #1 from hutchinsonandy at aim dot com 2008-02-22 01:22 ------- This appears to be due to avr_rtx_costs not assigning same cost to SYMBOL_REF and CONST_INT. So SYMBOL_REF looks expensive - so is held in register to avoid "recalculating" it.
Quick change to make SYMBOL_REF same cost as CONST_INT in both avr_rtx_cost and avr_operand_rtx_cost gave the desired result 22 /* prologue: function */ 23 /* frame size = 0 */ 24 .LM2: 25 0000 E091 0000 lds r30,a 26 0004 F091 0000 lds r31,(a)+1 27 0008 EE0F lsl r30 28 000a FF1F rol r31 29 000c E050 subi r30,lo8(-(data)) 30 000e F040 sbci r31,hi8(-(data)) 31 0010 8081 ld r24,Z 32 0012 9181 ldd r25,Z+1 33 0014 0E94 0000 call foo 34 .LM3: 35 0018 FC01 movw r30,r24 36 001a EE0F lsl r30 37 001c FF1F rol r31 38 001e E050 subi r30,lo8(-(data)) 39 0020 F040 sbci r31,hi8(-(data)) 40 0022 8081 ld r24,Z 41 0024 9181 ldd r25,Z+1 42 0026 0E94 0000 call foo 43 /* epilogue start */ 44 .LM4: 45 002a 0895 ret CONST and LABEL_REF might also have same problem as they cost same as MEM. But note, if SYMBOL_REF were part of memory address, then it might be better held in register (like Y or Z) - this should be done by checking outer code. With outer code of "MEM" SYMBOL_REF would be more expensive than register. (which might same a few LDS/STS that appear in code) Avr_rtx_cost needs some serious work done to correct these are other anomalies in cost assumptions and the recursion on operand costs. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34789