loop.c (check_dbra_loop): Try swapping the comparison operands of the loop condition...
authorRoger Sayle <roger@eyesopen.com>
Sun, 9 Nov 2003 14:33:20 +0000 (14:33 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Sun, 9 Nov 2003 14:33:20 +0000 (14:33 +0000)
* 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
gcc/loop.c
gcc/unroll.c

index a050922..8603eb5 100644 (file)
@@ -1,3 +1,9 @@
+2003-11-09  Roger Sayle  <roger@eyesopen.com>
+
+       * 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  <ghazi@caip.rutgers.edu>
 
        * config/sparc/sparc.h (TARGET_CPU_CPP_BUILTINS): Fix sparc vs
index 667833d..159906d 100644 (file)
@@ -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;
 
index 38659d4..cc415a7 100644 (file)
@@ -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 ();