This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

dbra loop reversal for unsigned


gcc does not reverse a loop of the form

	unsigned max = ...; 
	int count; 
	for (count = 0; count < max; count++) {
		/* count not used */
	} 

to count downwards. When max is an int it works as expected and
generates efficient downward counting code. The reason is that
check_dbra_loop does check for LT, but not for LTU in the loop
condition. I verified that the correct code for unsigned comparisons
is generated in the initial test. 

Survives a bootstrap on x86-64. I don't have CVS access.

2003-07-14  Andi Kleen  <ak@muc.de>

	* loop.c (check_dbra_loop): Allow LTU in the loop condition.

Index: gcc/loop.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/loop.c,v
retrieving revision 1.463
diff -u -u -r1.463 loop.c
--- gcc/loop.c	11 Jul 2003 06:44:40 -0000	1.463
+++ gcc/loop.c	14 Jul 2003 00:10:00 -0000
@@ -8021,7 +8021,8 @@
 	  before_comparison = get_condition_for_loop (loop, p);
 	  if (before_comparison
 	      && XEXP (before_comparison, 0) == bl->biv->dest_reg
-	      && GET_CODE (before_comparison) == LT
+	      && (GET_CODE (before_comparison) == LT || 
+		  GET_CODE (before_comparison) == LTU)
 	      && XEXP (before_comparison, 1) == const0_rtx
 	      && ! reg_set_between_p (bl->biv->dest_reg, p, loop_start)
 	      && INTVAL (bl->biv->add_val) == -1)
@@ -8192,7 +8193,8 @@
 	      /* for constants, LE gets turned into LT */
 	      && (GET_CODE (comparison) == LT
 		  || (GET_CODE (comparison) == LE
-		      && no_use_except_counting)))
+		      && no_use_except_counting) 
+		  || GET_CODE (comparison) == LTU))
 	    {
 	      HOST_WIDE_INT add_val, add_adjust, comparison_val = 0;
 	      rtx initial_value, comparison_value;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]