This is the mail archive of the gcc@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]

Re: Re-run of loop pass


Mark Mitchell writes:
 > Or the second pass could learn to recongize some of these idioms.
 > For example, you seem to imply that if I write:
 > 
 >   int* i;
 >   int* j;
 >   for (i = j ; i < j + 4; ++j)
 >     ;
 > 
 > say, that loop can't figure out the number of iterations.  A little
 > algebra might be helpful here, since this is a reasonably common
 > idiom, especially in C++ using STL, and especially where `4' is
 > replaced by `k'.  So much so that if no-one else does this, I'll
 > probably get around to it.

OK, this patch (with maybe a little strengthening) should handle the 
very simple case.

Index: unroll.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/unroll.c,v
retrieving revision 1.32
diff -c -3 -p -r1.32 unroll.c
*** unroll.c	1998/10/14 09:02:52	1.32
--- unroll.c	1998/10/18 22:02:59
*************** loop_iterations (loop_start, loop_end)
*** 3499,3504 ****
--- 3499,3508 ----
  		  if (note && GET_CODE (XEXP (note, 0)) != EXPR_LIST
  		      && CONSTANT_P (XEXP (note, 0)))
  		    comparison_value = XEXP (note, 0);
+ 		  /* May have to check that we have the sum of a register
+ 		     and a constant.  */
+ 		  else if (GET_CODE (SET_SRC (set)) == PLUS)
+ 		    comparison_value = SET_SRC (set);
  		}
  	      break;
  	    }
*************** loop_iterations (loop_start, loop_end)
*** 3535,3544 ****
      }
    else if (GET_CODE (initial_value) != CONST_INT)
      {
!       if (loop_dump_stream)
! 	fprintf (loop_dump_stream,
! 		 "Loop unrolling: Initial value not constant.\n");
!       return 0;
      }
    else if (final_value == 0)
      {
--- 3539,3559 ----
      }
    else if (GET_CODE (initial_value) != CONST_INT)
      {
!       if (REG_P (initial_value)
! 	  && GET_CODE (final_value) == PLUS
! 	  && XEXP (final_value, 0) == initial_value
! 	  && CONSTANT_P (XEXP (final_value, 1)))
! 	{
! 	  initial_value = const0_rtx;
! 	  final_value = XEXP (final_value, 1);
! 	}
!       else
! 	{
! 	  if (loop_dump_stream)
! 	    fprintf (loop_dump_stream,
! 		     "Loop unrolling: Initial value not constant.\n");
! 	  return 0;
! 	}
      }
    else if (final_value == 0)
      {


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