From ce4191eed16e15397cc09bba95d8ef603ba05359 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Sun, 9 Nov 2003 14:33:20 +0000 Subject: [PATCH] loop.c (check_dbra_loop): Try swapping the comparison operands of the loop condition to identify a... * loop.c (check_dbra_loop): Try swapping the comparison operands of the loop condition to identify a suitable induction variable. * unroll.c (loop_iterations): Likewise. From-SVN: r73391 --- gcc/ChangeLog | 6 ++++++ gcc/loop.c | 16 ++++++++++++++++ gcc/unroll.c | 15 ++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a050922f7aa..8603eb5aeb6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2003-11-09 Roger Sayle + + * loop.c (check_dbra_loop): Try swapping the comparison operands + of the loop condition to identify a suitable induction variable. + * unroll.c (loop_iterations): Likewise. + 2003-11-09 Kaveh R. Ghazi * config/sparc/sparc.h (TARGET_CPU_CPP_BUILTINS): Fix sparc vs diff --git a/gcc/loop.c b/gcc/loop.c index 667833d64a5..159906d3747 100644 --- a/gcc/loop.c +++ b/gcc/loop.c @@ -8017,6 +8017,22 @@ check_dbra_loop (struct loop *loop, int insn_count) break; } + /* Try swapping the comparison to identify a suitable biv. */ + if (!bl) + for (bl = ivs->list; bl; bl = bl->next) + if (bl->biv_count == 1 + && ! bl->biv->maybe_multiple + && bl->biv->dest_reg == XEXP (comparison, 1) + && ! reg_used_between_p (regno_reg_rtx[bl->regno], bl->biv->insn, + first_compare)) + { + comparison = gen_rtx_fmt_ee (swap_condition (GET_CODE (comparison)), + VOIDmode, + XEXP (comparison, 1), + XEXP (comparison, 0)); + break; + } + if (! bl) return 0; diff --git a/gcc/unroll.c b/gcc/unroll.c index 38659d461cb..cc415a795b6 100644 --- a/gcc/unroll.c +++ b/gcc/unroll.c @@ -3421,7 +3421,20 @@ loop_iterations (struct loop *loop) "Loop iterations: Iteration var not an integer.\n"); return 0; } - else if (REG_IV_TYPE (ivs, REGNO (iteration_var)) == BASIC_INDUCT) + + /* Try swapping the comparison to identify a suitable iv. */ + if (REG_IV_TYPE (ivs, REGNO (iteration_var)) != BASIC_INDUCT + && REG_IV_TYPE (ivs, REGNO (iteration_var)) != GENERAL_INDUCT + && GET_CODE (comparison_value) == REG + && REGNO (comparison_value) < ivs->n_regs) + { + rtx temp = comparison_value; + comparison_code = swap_condition (comparison_code); + comparison_value = iteration_var; + iteration_var = temp; + } + + if (REG_IV_TYPE (ivs, REGNO (iteration_var)) == BASIC_INDUCT) { if (REGNO (iteration_var) >= ivs->n_regs) abort ();