http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52208
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-02-14 13:58:44 UTC --- The -1000 costs comes from the scan_one_insn subtracting there ira_memory_move_cost[][][] * frequency (i.e. memory_cost becomes -4000) and on the plus we add just 3000 to memory_cost. I wonder if we shouldn't limit this subtraction of mem_cost / setting of counted_mem e.g. to general_operand (SET_SRC (set), GET_MODE (SET_SRC (set))) and leave the specialized memory loads alone (I know, it would be a hack, but works for this and shouldn't pessimize the cases for which this hunk has been added). And would at least tiny bit model what reload will do with such non-standard mems - as on this testcase it doesn't use the orignal mem, but does the load, followed by store to another mem, followed by load from that mem. --- ira-costs.c.jj 2012-01-20 12:35:17.000000000 +0100 +++ ira-costs.c 2012-02-14 14:54:52.297356053 +0100 @@ -1313,7 +1313,8 @@ scan_one_insn (rtx insn) || (CONSTANT_P (XEXP (note, 0)) && targetm.legitimate_constant_p (GET_MODE (SET_DEST (set)), XEXP (note, 0)) - && REG_N_SETS (REGNO (SET_DEST (set))) == 1))) + && REG_N_SETS (REGNO (SET_DEST (set))) == 1)) + && general_operand (SET_SRC (set), GET_MODE (SET_SRC (set)))) { enum reg_class cl = GENERAL_REGS; rtx reg = SET_DEST (set);