maybe_eliminate_biv_1 fix

Jan Hubicka hubicka@atrey.karlin.mff.cuni.cz
Mon Apr 17 14:34:00 GMT 2000


Hi
Maybe_eliminate_biv_1 on some places test mult_val for CONSTANT_P, but then
takes INTVAL of it.  This seems to be bug, only it didn't show so far, since
multval usualy isn't some other constant than INTVAL.

I've also cleaned up a bit how the changes are applied (i.e one is applied by
hand, wile the second using validate_change)

Tue Apr 11 21:02:13 CEST 2000  Jan Hubicka  <jh@suse.cz>
	* loop.c (maybe_eliminate_biv_1): Use GET_CODE (x) == CONST_INT instead
	of CONSTANT_P for mult_val; always use validate_change to update insn.

*** /usr/src/egcs-20000306.orig1/gcc/loop.c	Sun Apr  9 11:41:05 2000
--- loop.c	Tue Apr 11 20:54:26 2000
*************** maybe_eliminate_biv_1 (loop, x, insn, bl
*** 8975,8981 ****
  	     overflows.  */
  
  	  for (v = bl->giv; v; v = v->next_iv)
! 	    if (CONSTANT_P (v->mult_val) && v->mult_val != const0_rtx
  		&& v->add_val == const0_rtx
  		&& ! v->ignore && ! v->maybe_dead && v->always_computable
  		&& v->mode == mode
--- 9042,9048 ----
  	     overflows.  */
  
  	  for (v = bl->giv; v; v = v->next_iv)
! 	    if (GET_CODE (v->mult_val) == CONST_INT && v->mult_val != const0_rtx
  		&& v->add_val == const0_rtx
  		&& ! v->ignore && ! v->maybe_dead && v->always_computable
  		&& v->mode == mode
*************** maybe_eliminate_biv_1 (loop, x, insn, bl
*** 9007,9013 ****
  	     overflow problem.  */
  
  	  for (v = bl->giv; v; v = v->next_iv)
! 	    if (CONSTANT_P (v->mult_val) && v->mult_val != const0_rtx
  		&& ! v->ignore && ! v->maybe_dead && v->always_computable
  		&& v->mode == mode
  		&& (GET_CODE (v->add_val) == SYMBOL_REF
--- 9074,9080 ----
  	     overflow problem.  */
  
  	  for (v = bl->giv; v; v = v->next_iv)
! 	    if (GET_CODE (v->mult_val) == CONST_INT && v->mult_val != const0_rtx
  		&& ! v->ignore && ! v->maybe_dead && v->always_computable
  		&& v->mode == mode
  		&& (GET_CODE (v->add_val) == SYMBOL_REF
*************** maybe_eliminate_biv_1 (loop, x, insn, bl
*** 9072,9078 ****
  	     negative mult_val, but it seems complex to do it in general.  */
  
  	  for (v = bl->giv; v; v = v->next_iv)
! 	    if (CONSTANT_P (v->mult_val) && INTVAL (v->mult_val) > 0
  		&& (GET_CODE (v->add_val) == SYMBOL_REF
  		    || GET_CODE (v->add_val) == LABEL_REF
  		    || GET_CODE (v->add_val) == CONST
--- 9139,9145 ----
  	     negative mult_val, but it seems complex to do it in general.  */
  
  	  for (v = bl->giv; v; v = v->next_iv)
! 	    if (GET_CODE (v->mult_val) == CONST_INT && INTVAL (v->mult_val) > 0
  		&& (GET_CODE (v->add_val) == SYMBOL_REF
  		    || GET_CODE (v->add_val) == LABEL_REF
  		    || GET_CODE (v->add_val) == CONST
*************** maybe_eliminate_biv_1 (loop, x, insn, bl
*** 9088,9115 ****
  		  return 1;
  
  		/* Replace biv with the giv's reduced reg.  */
! 		XEXP (x, 1-arg_operand) = v->new_reg;
  
  		/* If all constants are actually constant integers and
  		   the derived constant can be directly placed in the COMPARE,
  		   do so.  */
  		if (GET_CODE (arg) == CONST_INT
  		    && GET_CODE (v->mult_val) == CONST_INT
! 		    && GET_CODE (v->add_val) == CONST_INT
! 		    && validate_change (insn, &XEXP (x, arg_operand),
! 					GEN_INT (INTVAL (arg)
! 						 * INTVAL (v->mult_val)
! 						 + INTVAL (v->add_val)), 0))
! 		  return 1;
! 
! 		/* Otherwise, load it into a register.  */
! 		tem = gen_reg_rtx (mode);
! 		emit_iv_add_mult (arg, v->mult_val, v->add_val, tem, where);
! 		if (validate_change (insn, &XEXP (x, arg_operand), tem, 0))
  		  return 1;
- 
- 		/* If that failed, put back the change we made above.  */
- 		XEXP (x, 1-arg_operand) = reg;
  	      }
  	  
  	  /* Look for giv with positive constant mult_val and nonconst add_val.
--- 9155,9183 ----
  		  return 1;
  
  		/* Replace biv with the giv's reduced reg.  */
! 		validate_change (insn, &XEXP (x, 1-arg_operand), v->new_reg, 1);
  
  		/* If all constants are actually constant integers and
  		   the derived constant can be directly placed in the COMPARE,
  		   do so.  */
  		if (GET_CODE (arg) == CONST_INT
  		    && GET_CODE (v->mult_val) == CONST_INT
! 		    && GET_CODE (v->add_val) == CONST_INT)
! 		  {
! 		    validate_change (insn, &XEXP (x, arg_operand),
! 				     GEN_INT (INTVAL (arg)
! 					     * INTVAL (v->mult_val)
! 					     + INTVAL (v->add_val)), 1);
! 		  }
! 		else
! 		  {
! 		    /* Otherwise, load it into a register.  */
! 		    tem = gen_reg_rtx (mode);
! 		    emit_iv_add_mult (arg, v->mult_val, v->add_val, tem, where);
! 		    validate_change (insn, &XEXP (x, arg_operand), tem, 1);
! 		  }
! 		if (apply_change_group ())
  		  return 1;
  	      }
  	  
  	  /* Look for giv with positive constant mult_val and nonconst add_val.
*************** maybe_eliminate_biv_1 (loop, x, insn, bl
*** 9117,9123 ****
  	     ??? Turn this off due to possible overflow.  */
  
  	  for (v = bl->giv; v; v = v->next_iv)
! 	    if (CONSTANT_P (v->mult_val) && INTVAL (v->mult_val) > 0
  		&& ! v->ignore && ! v->maybe_dead && v->always_computable
  		&& v->mode == mode
  		&& 0)
--- 9185,9191 ----
  	     ??? Turn this off due to possible overflow.  */
  
  	  for (v = bl->giv; v; v = v->next_iv)
! 	    if (GET_CODE (v->mult_val) == CONST_INT && INTVAL (v->mult_val) > 0
  		&& ! v->ignore && ! v->maybe_dead && v->always_computable
  		&& v->mode == mode
  		&& 0)
*************** maybe_eliminate_biv_1 (loop, x, insn, bl
*** 9153,9159 ****
  		 ??? Turn this off due to possible overflow.  */
  
  	      for (v = bl->giv; v; v = v->next_iv)
! 		if (CONSTANT_P (v->mult_val) && INTVAL (v->mult_val) > 0
  		    && ! v->ignore && ! v->maybe_dead && v->always_computable
  		    && v->mode == mode
  		    && 0)
--- 9221,9227 ----
  		 ??? Turn this off due to possible overflow.  */
  
  	      for (v = bl->giv; v; v = v->next_iv)
! 		if (GET_CODE (v->mult_val) == CONST_INT && INTVAL (v->mult_val) > 0
  		    && ! v->ignore && ! v->maybe_dead && v->always_computable
  		    && v->mode == mode
  		    && 0)


More information about the Gcc-patches mailing list