Commit e50e3081 by Bernd Schmidt Committed by Bernd Schmidt

bfin.c (bfin_optimize_loop): If we need a scratch reg, scan backwards to try to…

bfin.c (bfin_optimize_loop): If we need a scratch reg, scan backwards to try to find a constant to initialize it.

	* config/bfin/bfin.c (bfin_optimize_loop): If we need a scratch reg,
	scan backwards to try to find a constant to initialize it.

From-SVN: r146974
parent 7c90021d
2009-04-29 Bernd Schmidt <bernd.schmidt@analog.com>
* config/bfin/bfin.c (bfin_optimize_loop): If we need a scratch reg,
scan backwards to try to find a constant to initialize it.
2009-04-29 Richard Guenther <rguenther@suse.de> 2009-04-29 Richard Guenther <rguenther@suse.de>
PR middle-end/39937 PR middle-end/39937
......
...@@ -3784,7 +3784,7 @@ bfin_optimize_loop (loop_info loop) ...@@ -3784,7 +3784,7 @@ bfin_optimize_loop (loop_info loop)
rtx insn, last_insn; rtx insn, last_insn;
rtx loop_init, start_label, end_label; rtx loop_init, start_label, end_label;
rtx reg_lc0, reg_lc1, reg_lt0, reg_lt1, reg_lb0, reg_lb1; rtx reg_lc0, reg_lc1, reg_lt0, reg_lt1, reg_lb0, reg_lb1;
rtx iter_reg, scratchreg; rtx iter_reg, scratchreg, scratch_init, scratch_init_insn;
rtx lc_reg, lt_reg, lb_reg; rtx lc_reg, lt_reg, lb_reg;
rtx seq, seq_end; rtx seq, seq_end;
int length; int length;
...@@ -3838,18 +3838,40 @@ bfin_optimize_loop (loop_info loop) ...@@ -3838,18 +3838,40 @@ bfin_optimize_loop (loop_info loop)
goto bad_loop; goto bad_loop;
} }
scratchreg = NULL_RTX; scratchreg = NULL_RTX;
scratch_init = iter_reg;
scratch_init_insn = NULL_RTX;
if (!PREG_P (iter_reg) && loop->incoming_src) if (!PREG_P (iter_reg) && loop->incoming_src)
{ {
basic_block bb_in = loop->incoming_src;
int i; int i;
for (i = REG_P0; i <= REG_P5; i++) for (i = REG_P0; i <= REG_P5; i++)
if ((df_regs_ever_live_p (i) if ((df_regs_ever_live_p (i)
|| (funkind (TREE_TYPE (current_function_decl)) == SUBROUTINE || (funkind (TREE_TYPE (current_function_decl)) == SUBROUTINE
&& call_used_regs[i])) && call_used_regs[i]))
&& !REGNO_REG_SET_P (df_get_live_out (loop->incoming_src), i)) && !REGNO_REG_SET_P (df_get_live_out (bb_in), i))
{ {
scratchreg = gen_rtx_REG (SImode, i); scratchreg = gen_rtx_REG (SImode, i);
break; break;
} }
for (insn = BB_END (bb_in); insn != BB_HEAD (bb_in);
insn = PREV_INSN (insn))
{
rtx set;
if (NOTE_P (insn) || BARRIER_P (insn))
continue;
set = single_set (insn);
if (set && rtx_equal_p (SET_DEST (set), iter_reg))
{
if (CONSTANT_P (SET_SRC (set)))
{
scratch_init = SET_SRC (set);
scratch_init_insn = insn;
}
break;
}
else if (reg_mentioned_p (iter_reg, PATTERN (insn)))
break;
}
} }
if (loop->incoming_src) if (loop->incoming_src)
...@@ -4092,11 +4114,13 @@ bfin_optimize_loop (loop_info loop) ...@@ -4092,11 +4114,13 @@ bfin_optimize_loop (loop_info loop)
} }
else if (scratchreg != NULL_RTX) else if (scratchreg != NULL_RTX)
{ {
emit_insn (gen_movsi (scratchreg, iter_reg)); emit_insn (gen_movsi (scratchreg, scratch_init));
loop_init = gen_lsetup_with_autoinit (lt_reg, start_label, loop_init = gen_lsetup_with_autoinit (lt_reg, start_label,
lb_reg, end_label, lb_reg, end_label,
lc_reg, scratchreg); lc_reg, scratchreg);
seq_end = emit_insn (loop_init); seq_end = emit_insn (loop_init);
if (scratch_init_insn != NULL_RTX)
delete_insn (scratch_init_insn);
} }
else else
{ {
...@@ -4106,12 +4130,14 @@ bfin_optimize_loop (loop_info loop) ...@@ -4106,12 +4130,14 @@ bfin_optimize_loop (loop_info loop)
rtx pop = gen_frame_mem (SImode, rtx pop = gen_frame_mem (SImode,
gen_rtx_POST_INC (SImode, stack_pointer_rtx)); gen_rtx_POST_INC (SImode, stack_pointer_rtx));
emit_insn (gen_movsi (push, p0reg)); emit_insn (gen_movsi (push, p0reg));
emit_insn (gen_movsi (p0reg, iter_reg)); emit_insn (gen_movsi (p0reg, scratch_init));
loop_init = gen_lsetup_with_autoinit (lt_reg, start_label, loop_init = gen_lsetup_with_autoinit (lt_reg, start_label,
lb_reg, end_label, lb_reg, end_label,
lc_reg, p0reg); lc_reg, p0reg);
emit_insn (loop_init); emit_insn (loop_init);
seq_end = emit_insn (gen_movsi (p0reg, pop)); seq_end = emit_insn (gen_movsi (p0reg, pop));
if (scratch_init_insn != NULL_RTX)
delete_insn (scratch_init_insn);
} }
if (dump_file) if (dump_file)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment