Small strength_reduce cleanup

Jan Hubicka hubicka@atrey.karlin.mff.cuni.cz
Fri Apr 14 06:18:00 GMT 2000


Hi
This patch breaks giv detection code out of strength_reduce.  I would
like to reuse it in my prefetching patch.

Honza 

Fri Apr 14 15:16:41 MET DST 2000  Jan Hubicka  <jh@suse.cz>
	* loop.c (check_insn_for_givs): Break out from ...
	(strength_reduce): ... Here.
Index: egcs/gcc/loop.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/loop.c,v
retrieving revision 1.233
diff -c -3 -p -r1.233 loop.c
*** loop.c	2000/03/25 18:34:03	1.233
--- loop.c	2000/04/14 13:15:11
*************** static int replace_loop_reg PARAMS ((rtx
*** 308,313 ****
--- 308,314 ----
  static void note_reg_stored PARAMS ((rtx, rtx, void *));
  static void try_copy_prop PARAMS ((const struct loop *, rtx, unsigned int));
  static int replace_label PARAMS ((rtx *, void *));
+ static void check_insn_for_givs PARAMS((struct loop *, rtx, int, int));
  
  typedef struct rtx_and_int {
    rtx r;
*************** strength_reduce (loop, insn_count, unrol
*** 4452,4530 ****
  	    break;
  	  if (p == loop_scan_start)
  	    break;
- 	}
- 
-       /* Look for a general induction variable in a register.  */
-       if (GET_CODE (p) == INSN
- 	  && (set = single_set (p))
- 	  && GET_CODE (SET_DEST (set)) == REG
- 	  && ! VARRAY_CHAR (may_not_optimize, REGNO (SET_DEST (set))))
- 	{
- 	  rtx src_reg;
- 	  rtx add_val;
- 	  rtx mult_val;
- 	  int benefit;
- 	  rtx regnote = 0;
- 	  rtx last_consec_insn;
- 
- 	  dest_reg = SET_DEST (set);
- 	  if (REGNO (dest_reg) < FIRST_PSEUDO_REGISTER)
- 	    continue;
- 
- 	  if (/* SET_SRC is a giv.  */
- 	      (general_induction_var (loop, SET_SRC (set), &src_reg, &add_val,
- 				      &mult_val, 0, &benefit)
- 	       /* Equivalent expression is a giv.  */
- 	       || ((regnote = find_reg_note (p, REG_EQUAL, NULL_RTX))
- 		   && general_induction_var (loop, XEXP (regnote, 0), &src_reg,
- 					     &add_val, &mult_val, 0,
- 					     &benefit)))
- 	      /* Don't try to handle any regs made by loop optimization.
- 		 We have nothing on them in regno_first_uid, etc.  */
- 	      && REGNO (dest_reg) < max_reg_before_loop
- 	      /* Don't recognize a BASIC_INDUCT_VAR here.  */
- 	      && dest_reg != src_reg
- 	      /* This must be the only place where the register is set.  */
- 	      && (VARRAY_INT (n_times_set, REGNO (dest_reg)) == 1
- 		  /* or all sets must be consecutive and make a giv.  */
- 		  || (benefit = consec_sets_giv (loop, benefit, p,
- 						 src_reg, dest_reg,
- 						 &add_val, &mult_val,
- 						 &last_consec_insn))))
- 	    {
- 	      struct induction *v
- 		= (struct induction *) alloca (sizeof (struct induction));
- 
- 	      /* If this is a library call, increase benefit.  */
- 	      if (find_reg_note (p, REG_RETVAL, NULL_RTX))
- 		benefit += libcall_benefit (p);
- 
- 	      /* Skip the consecutive insns, if there are any.  */
- 	      if (VARRAY_INT (n_times_set, REGNO (dest_reg)) != 1)
- 		p = last_consec_insn;
- 
- 	      record_giv (loop, v, p, src_reg, dest_reg, mult_val, add_val,
- 			  benefit, DEST_REG, not_every_iteration,
- 			  maybe_multiple, NULL_PTR);
- 
- 	    }
  	}
  
- #ifndef DONT_REDUCE_ADDR
-       /* Look for givs which are memory addresses.  */
-       /* This resulted in worse code on a VAX 8600.  I wonder if it
- 	 still does.  */
-       if (GET_CODE (p) == INSN)
- 	find_mem_givs (loop, PATTERN (p), p, not_every_iteration,
- 		       maybe_multiple);
- #endif
- 
-       /* Update the status of whether giv can derive other givs.  This can
- 	 change when we pass a label or an insn that updates a biv.  */
-       if (GET_CODE (p) == INSN || GET_CODE (p) == JUMP_INSN
- 	|| GET_CODE (p) == CODE_LABEL)
- 	update_giv_derive (loop, p);
- 
        /* Past CODE_LABEL, we get to insns that may be executed multiple
  	 times.  The only way we can be sure that they can't is if every
  	 every jump insn between here and the end of the loop either
--- 4760,4768 ----
  	    break;
  	  if (p == loop_scan_start)
  	    break;
  	}
+       check_insn_for_givs (loop, p, not_every_iteration, maybe_multiple);
  
        /* Past CODE_LABEL, we get to insns that may be executed multiple
  	 times.  The only way we can be sure that they can't is if every
  	 every jump insn between here and the end of the loop either
*************** egress:
*** 5282,5287 ****
--- 5523,5611 ----
      free (reg_map);
  }
  
+ /* Record all givs calculated in the insn.  */
+ static void
+ check_insn_for_givs (loop, p, not_every_iteration, maybe_multiple)
+      struct loop *loop;
+      rtx p;
+      int not_every_iteration;
+      int maybe_multiple;
+ {
+   rtx set;
+   /* Look for a general induction variable in a register.  */
+   if (GET_CODE (p) == INSN
+       && (set = single_set (p))
+       && GET_CODE (SET_DEST (set)) == REG
+       && ! VARRAY_CHAR (may_not_optimize, REGNO (SET_DEST (set))))
+     {
+       rtx src_reg;
+       rtx dest_reg;
+       rtx add_val;
+       rtx mult_val;
+       int benefit;
+       rtx regnote = 0;
+       rtx last_consec_insn;
+ 
+       dest_reg = SET_DEST (set);
+       if (REGNO (dest_reg) < FIRST_PSEUDO_REGISTER)
+ 	return;
+ 
+       if (/* SET_SRC is a giv.  */
+ 	  (general_induction_var (loop, SET_SRC (set), &src_reg, &add_val,
+ 				  &mult_val, 0, &benefit)
+ 	   /* Equivalent expression is a giv.  */
+ 	   || ((regnote = find_reg_note (p, REG_EQUAL, NULL_RTX))
+ 	       && general_induction_var (loop, XEXP (regnote, 0), &src_reg,
+ 					 &add_val, &mult_val, 0,
+ 					 &benefit)))
+ 	  /* Don't try to handle any regs made by loop optimization.
+ 	     We have nothing on them in regno_first_uid, etc.  */
+ 	  && REGNO (dest_reg) < max_reg_before_loop
+ 	  /* Don't recognize a BASIC_INDUCT_VAR here.  */
+ 	  && dest_reg != src_reg
+ 	  /* This must be the only place where the register is set.  */
+ 	  && (VARRAY_INT (n_times_set, REGNO (dest_reg)) == 1
+ 	      /* or all sets must be consecutive and make a giv.  */
+ 	      || (benefit = consec_sets_giv (loop, benefit, p,
+ 					     src_reg, dest_reg,
+ 					     &add_val, &mult_val,
+ 					     &last_consec_insn))))
+ 	{
+ 	  struct induction *v
+ 	    = (struct induction *) oballoc (sizeof (struct induction));
+ 
+ 	  /* If this is a library call, increase benefit.  */
+ 	  if (find_reg_note (p, REG_RETVAL, NULL_RTX))
+ 	    benefit += libcall_benefit (p);
+ 
+ 	  /* Skip the consecutive insns, if there are any.  */
+ 	  if (VARRAY_INT (n_times_set, REGNO (dest_reg)) != 1)
+ 	    p = last_consec_insn;
+ 
+ 	  record_giv (loop, v, p, src_reg, dest_reg, mult_val, add_val,
+ 		      benefit, DEST_REG, not_every_iteration,
+ 		      maybe_multiple, NULL_PTR);
+ 
+ 	}
+     }
+ 
+ #ifndef DONT_REDUCE_ADDR
+   /* Look for givs which are memory addresses.  */
+   /* This resulted in worse code on a VAX 8600.  I wonder if it
+      still does.  */
+   if (GET_CODE (p) == INSN)
+     find_mem_givs (loop, PATTERN (p), p, not_every_iteration,
+ 		   maybe_multiple);
+ #endif
+ 
+   /* Update the status of whether giv can derive other givs.  This can
+      change when we pass a label or an insn that updates a biv.  */
+   if (GET_CODE (p) == INSN || GET_CODE (p) == JUMP_INSN
+     || GET_CODE (p) == CODE_LABEL)
+     update_giv_derive (loop, p);
+ 
+ }
+ 
  /* Return 1 if X is a valid source for an initial value (or as value being
     compared against in an initial test).
  


More information about the Gcc-patches mailing list