[Bug rtl-optimization/56124] Redundant reload for loading from memory

amker.cheng at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Jan 28 02:43:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56124

--- Comment #1 from bin.cheng <amker.cheng at gmail dot com> 2013-01-28 02:43:10 UTC ---
The root cause is in ira:scan_one_insn function.

It decrease cost of memory for pseudo which are target of loading from memory:

  if (set != 0 && REG_P (SET_DEST (set)) && MEM_P (SET_SRC (set))
      && (note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != NULL_RTX
      && ((MEM_P (XEXP (note, 0)))
      || (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))
      && general_operand (SET_SRC (set), GET_MODE (SET_SRC (set))))
    {
      enum reg_class cl = GENERAL_REGS;
      rtx reg = SET_DEST (set);
      int num = COST_INDEX (REGNO (reg));

      COSTS (costs, num)->mem_cost
    -= ira_memory_move_cost[GET_MODE (reg)][cl][1] * frequency;
      record_address_regs (GET_MODE (SET_SRC (set)),
               MEM_ADDR_SPACE (SET_SRC (set)),
               XEXP (SET_SRC (set), 0), 0, MEM, SCRATCH,
               frequency * 2);
      counted_mem = true;
    }

The problem is if the src memory rtx (like in insn 2) has side effect, the orig
load insn won't be eliminated and causes redundant reload.

Patch will be sent for review.



More information about the Gcc-bugs mailing list