regno_map * analyze (basic_block bb);
void transform (regno_map *m, basic_block bb);
- bool get_si_mem_base_reg (rtx mem, rtx *addr);
+ bool get_si_mem_base_reg (rtx mem, rtx *addr, bool *extend);
}; // class pass_shorten_memrefs
bool
-pass_shorten_memrefs::get_si_mem_base_reg (rtx mem, rtx *addr)
+pass_shorten_memrefs::get_si_mem_base_reg (rtx mem, rtx *addr, bool *extend)
{
+ /* Whether it's sign/zero extended. */
+ if (GET_CODE (mem) == ZERO_EXTEND || GET_CODE (mem) == SIGN_EXTEND)
+ {
+ *extend = true;
+ mem = XEXP (mem, 0);
+ }
+
if (!MEM_P (mem) || GET_MODE (mem) != SImode)
return false;
*addr = XEXP (mem, 0);
{
rtx mem = XEXP (pat, i);
rtx addr;
- if (get_si_mem_base_reg (mem, &addr))
+ bool extend = false;
+ if (get_si_mem_base_reg (mem, &addr, &extend))
{
HOST_WIDE_INT regno = REGNO (XEXP (addr, 0));
/* Do not count store zero as these cannot be compressed. */
{
rtx mem = XEXP (pat, i);
rtx addr;
- if (get_si_mem_base_reg (mem, &addr))
+ bool extend = false;
+ if (get_si_mem_base_reg (mem, &addr, &extend))
{
HOST_WIDE_INT regno = REGNO (XEXP (addr, 0));
/* Do not transform store zero as these cannot be compressed. */
}
if (m->get_or_insert (regno) > 3)
{
- addr
- = targetm.legitimize_address (addr, addr, GET_MODE (mem));
- XEXP (pat, i) = replace_equiv_address (mem, addr);
+ if (extend)
+ {
+ addr
+ = targetm.legitimize_address (addr, addr,
+ GET_MODE (XEXP (mem, 0)));
+ XEXP (XEXP (pat, i), 0)
+ = replace_equiv_address (XEXP (mem, 0), addr);
+ }
+ else
+ {
+ addr = targetm.legitimize_address (addr, addr,
+ GET_MODE (mem));
+ XEXP (pat, i) = replace_equiv_address (mem, addr);
+ }
df_insn_rescan (insn);
}
}
bool
riscv_legitimize_move (machine_mode mode, rtx dest, rtx src)
{
+ /* Expand
+ (set (reg:QI target) (mem:QI (address)))
+ to
+ (set (reg:DI temp) (zero_extend:DI (mem:QI (address))))
+ (set (reg:QI target) (subreg:QI (reg:DI temp) 0))
+ with auto-sign/zero extend. */
+ if (GET_MODE_CLASS (mode) == MODE_INT
+ && GET_MODE_SIZE (mode) < UNITS_PER_WORD
+ && can_create_pseudo_p ()
+ && MEM_P (src))
+ {
+ rtx temp_reg;
+ int zero_extend_p;
+
+ temp_reg = gen_reg_rtx (word_mode);
+ zero_extend_p = (LOAD_EXTEND_OP (mode) == ZERO_EXTEND);
+ emit_insn (gen_extend_insn (temp_reg, src, word_mode, mode,
+ zero_extend_p));
+ riscv_emit_move (dest, gen_lowpart (mode, temp_reg));
+ return true;
+ }
+
if (!register_operand (dest, mode) && !reg_or_0_operand (src, mode))
{
rtx reg;