/* Perform doloop optimizations
- Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation,
- Inc.
+ Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010
+ Free Software Foundation, Inc.
Based on code by Michael P. Hayes (m.hayes@elec.canterbury.ac.nz)
This file is part of GCC.
op0 = force_operand (op0, NULL_RTX);
op1 = force_operand (op1, NULL_RTX);
label = block_label (dest);
- do_compare_rtx_and_jump (op0, op1, code, 0, mode, NULL_RTX, NULL_RTX, label);
+ do_compare_rtx_and_jump (op0, op1, code, 0, mode, NULL_RTX,
+ NULL_RTX, label, -1);
jump = get_last_insn ();
if (!jump || !JUMP_P (jump))
redirect_edge_and_branch_force (*e, dest);
return false;
}
-
+
JUMP_LABEL (jump) = label;
/* The jump is supposed to handle an unlikely special case. */
- REG_NOTES (jump)
- = gen_rtx_EXPR_LIST (REG_BR_PROB,
- const0_rtx, REG_NOTES (jump));
+ add_reg_note (jump, REG_BR_PROB, const0_rtx);
+
LABEL_NUSES (label)++;
make_edge (bb, dest, (*e)->flags & ~EDGE_FALLTHRU);
describes the loop, DESC describes the number of iterations of the
loop, and DOLOOP_INSN is the low-overhead looping insn to emit at the
end of the loop. CONDITION is the condition separated from the
- DOLOOP_SEQ. COUNT is the number of iterations of the LOOP. */
+ DOLOOP_SEQ. COUNT is the number of iterations of the LOOP.
+ ZERO_EXTEND_P says to zero extend COUNT after the increment of it to
+ word_mode from FROM_MODE. */
static void
doloop_modify (struct loop *loop, struct niter_desc *desc,
- rtx doloop_seq, rtx condition, rtx count)
+ rtx doloop_seq, rtx condition, rtx count,
+ bool zero_extend_p, enum machine_mode from_mode)
{
rtx counter_reg;
rtx tmp, noloop = NULL_RTX;
}
if (increment_count)
- count = simplify_gen_binary (PLUS, mode, count, const1_rtx);
+ count = simplify_gen_binary (PLUS, from_mode, count, const1_rtx);
+
+ if (zero_extend_p)
+ count = simplify_gen_unary (ZERO_EXTEND, word_mode,
+ count, from_mode);
/* Insert initialization of the count register into the loop header. */
start_sequence ();
set_zero->count = preheader->count;
set_zero->frequency = preheader->frequency;
}
-
+
if (EDGE_COUNT (set_zero->preds) == 0)
{
/* All the conditions were simplified to false, remove the
sequence = get_insns ();
end_sequence ();
emit_insn_after (sequence, BB_END (set_zero));
-
+
set_immediate_dominator (CDI_DOMINATORS, set_zero,
recompute_dominator (CDI_DOMINATORS,
set_zero));
/* Add a REG_NONNEG note if the actual or estimated maximum number
of iterations is non-negative. */
if (nonneg)
- {
- REG_NOTES (jump_insn)
- = gen_rtx_EXPR_LIST (REG_NONNEG, NULL_RTX, REG_NOTES (jump_insn));
- }
+ add_reg_note (jump_insn, REG_NONNEG, NULL_RTX);
+
/* Update the REG_BR_PROB note. */
if (true_prob_val)
{
/* Seems safer to use the branch probability. */
- REG_NOTES (jump_insn) =
- gen_rtx_EXPR_LIST (REG_BR_PROB,
- GEN_INT (desc->in_edge->probability),
- REG_NOTES (jump_insn));
+ add_reg_note (jump_insn, REG_BR_PROB,
+ GEN_INT (desc->in_edge->probability));
}
}
struct niter_desc *desc;
unsigned word_mode_size;
unsigned HOST_WIDE_INT word_mode_max;
+ bool zero_extend_p = false;
if (dump_file)
fprintf (dump_file, "Doloop: Processing loop %d.\n", loop->num);
max_cost
= COSTS_N_INSNS (PARAM_VALUE (PARAM_MAX_ITERATIONS_COMPUTATION_COST));
- if (rtx_cost (desc->niter_expr, SET) > max_cost)
+ if (rtx_cost (desc->niter_expr, SET, optimize_loop_for_speed_p (loop))
+ > max_cost)
{
if (dump_file)
fprintf (dump_file,
{
if (word_mode_size > GET_MODE_BITSIZE (mode))
{
- count = simplify_gen_unary (ZERO_EXTEND, word_mode,
- count, mode);
+ zero_extend_p = true;
iterations = simplify_gen_unary (ZERO_EXTEND, word_mode,
iterations, mode);
iterations_max = simplify_gen_unary (ZERO_EXTEND, word_mode,
return false;
}
- doloop_modify (loop, desc, doloop_seq, condition, count);
+ doloop_modify (loop, desc, doloop_seq, condition, count,
+ zero_extend_p, mode);
return true;
}