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]

convert combine.c



Hi
This patch converts combine.c into new infrastructure.
The combine's reversible_comparison_p is not 100% obsoletted by my function,
since it uses combine's data to search for the COMPARE expression, but in my
tests on i386 w/o REVERSIBLE_CC_MODE I didn't seen any regressions and as I've
mentioned previously I expect backends to use REVERSIBLE_CC_MODE and
REVERSE_CONDITION to eliminate need for searching backward soon, so I don't
think it worth to bother with this detail.

Even w/o this code in i386.c backend there is no case in our testsuite that
causes reversed_comparison_code to give up.

Bootstrapped and regression tested together with other my today patches
on i386 w/o regressions.

Honza 

So led  6 20:55:10 CET 2001  Jan Hubicka  <jh@suse.cz>
	* combine.c (REVERSIBLE_CC_MODE): Remove.
	(reversible_comparison_p): Remove.
	(combine_simplify_rtx): Use reversed_comparison_code instead
	of reversible_comparison_p.
	(simplify_if_then_else): Likewise.
	(simplify_set): Likewise.
	(simplify_logical): Likewise.
	(if_then_else_cond): Likewise.
	(known_cond): Likewise.
	(simplify_comparison): Likewise.

*** /p1/gcc/combine.c	Sat Jan  6 17:04:04 2001
--- combine.c	Sat Jan  6 17:15:26 2001
*************** static int combine_successes;
*** 131,142 ****
  
  static int total_attempts, total_merges, total_extras, total_successes;
  
- /* Define a default value for REVERSIBLE_CC_MODE.
-    We can never assume that a condition code mode is safe to reverse unless
-    the md tells us so.  */
- #ifndef REVERSIBLE_CC_MODE
- #define REVERSIBLE_CC_MODE(MODE) 0
- #endif
  
  /* Vector mapping INSN_UIDs to cuids.
     The cuids are like uids but increase monotonically always.
--- 131,136 ----
*************** static rtx gen_binary		PARAMS ((enum rtx
*** 414,420 ****
  static rtx gen_unary		PARAMS ((enum rtx_code, enum machine_mode,
  					 enum machine_mode, rtx));
  static enum rtx_code simplify_comparison  PARAMS ((enum rtx_code, rtx *, rtx *));
- static int reversible_comparison_p  PARAMS ((rtx));
  static void update_table_tick	PARAMS ((rtx));
  static void record_value_for_reg  PARAMS ((rtx, rtx, rtx));
  static void check_promoted_subreg PARAMS ((rtx, rtx));
--- 408,413 ----
*************** combine_simplify_rtx (x, op0_mode, last,
*** 3501,3506 ****
--- 3494,3500 ----
    enum rtx_code code = GET_CODE (x);
    enum machine_mode mode = GET_MODE (x);
    rtx temp;
+   enum rtx_code reversed_code;
    int i;
  
    /* If this is a commutative operation, put a constant last and a complex
*************** combine_simplify_rtx (x, op0_mode, last,
*** 3922,3929 ****
  	 reversing the comparison code if valid.  */
        if (STORE_FLAG_VALUE == -1
  	  && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
! 	  && reversible_comparison_p (XEXP (x, 0)))
! 	return gen_rtx_combine (reverse_condition (GET_CODE (XEXP (x, 0))),
  				mode, XEXP (XEXP (x, 0), 0),
  				XEXP (XEXP (x, 0), 1));
  
--- 3916,3923 ----
  	 reversing the comparison code if valid.  */
        if (STORE_FLAG_VALUE == -1
  	  && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
! 	  && (reversed_code = reversed_comparison_code (x, NULL)) != UNKNOWN)
! 	return gen_rtx_combine (reversed_code,
  				mode, XEXP (XEXP (x, 0), 0),
  				XEXP (XEXP (x, 0), 1));
  
*************** combine_simplify_rtx (x, op0_mode, last,
*** 4218,4229 ****
  	 is 1.  This produces better code than the alternative immediately
  	 below.  */
        if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
! 	  && reversible_comparison_p (XEXP (x, 0))
  	  && ((STORE_FLAG_VALUE == -1 && XEXP (x, 1) == const1_rtx)
  	      || (STORE_FLAG_VALUE == 1 && XEXP (x, 1) == constm1_rtx)))
  	return
  	  gen_unary (NEG, mode, mode,
! 		     gen_binary (reverse_condition (GET_CODE (XEXP (x, 0))),
  				 mode, XEXP (XEXP (x, 0), 0),
  				 XEXP (XEXP (x, 0), 1)));
  
--- 4212,4224 ----
  	 is 1.  This produces better code than the alternative immediately
  	 below.  */
        if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
! 	  && ((reversed_code = reversed_comparison_code (XEXP (x, 0), NULL))
! 	      != UNKNOWN)
  	  && ((STORE_FLAG_VALUE == -1 && XEXP (x, 1) == const1_rtx)
  	      || (STORE_FLAG_VALUE == 1 && XEXP (x, 1) == constm1_rtx)))
  	return
  	  gen_unary (NEG, mode, mode,
! 		     gen_binary (reversed_code,
  				 mode, XEXP (XEXP (x, 0), 0),
  				 XEXP (XEXP (x, 0), 1)));
  
*************** combine_simplify_rtx (x, op0_mode, last,
*** 4270,4277 ****
        if (STORE_FLAG_VALUE == 1
  	  && XEXP (x, 0) == const1_rtx
  	  && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == '<'
! 	  && reversible_comparison_p (XEXP (x, 1)))
! 	return gen_binary (reverse_condition (GET_CODE (XEXP (x, 1))), mode,
  			   XEXP (XEXP (x, 1), 0),
  			   XEXP (XEXP (x, 1), 1));
  
--- 4265,4272 ----
        if (STORE_FLAG_VALUE == 1
  	  && XEXP (x, 0) == const1_rtx
  	  && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == '<'
! 	  && (reversed_code = reversed_comparison_code (XEXP (x, 1), NULL)) != UNKNOWN)
! 	return gen_binary (reversed_code, mode,
  			   XEXP (XEXP (x, 1), 0),
  			   XEXP (XEXP (x, 1), 1));
  
*************** simplify_if_then_else (x)
*** 4622,4648 ****
    int comparison_p = GET_RTX_CLASS (true_code) == '<';
    rtx temp;
    int i;
  
    /* Simplify storing of the truth value.  */
    if (comparison_p && true == const_true_rtx && false == const0_rtx)
      return gen_binary (true_code, mode, XEXP (cond, 0), XEXP (cond, 1));
  
    /* Also when the truth value has to be reversed.  */
!   if (comparison_p && reversible_comparison_p (cond)
        && true == const0_rtx && false == const_true_rtx)
!     return gen_binary (reverse_condition (true_code),
  		       mode, XEXP (cond, 0), XEXP (cond, 1));
  
    /* Sometimes we can simplify the arm of an IF_THEN_ELSE if a register used
       in it is being compared against certain values.  Get the true and false
       comparisons and see if that says anything about the value of each arm.  */
  
!   if (comparison_p && reversible_comparison_p (cond)
        && GET_CODE (XEXP (cond, 0)) == REG)
      {
        HOST_WIDE_INT nzb;
        rtx from = XEXP (cond, 0);
-       enum rtx_code false_code = reverse_condition (true_code);
        rtx true_val = XEXP (cond, 1);
        rtx false_val = true_val;
        int swapped = 0;
--- 4620,4648 ----
    int comparison_p = GET_RTX_CLASS (true_code) == '<';
    rtx temp;
    int i;
+   enum rtx_code false_code;
  
    /* Simplify storing of the truth value.  */
    if (comparison_p && true == const_true_rtx && false == const0_rtx)
      return gen_binary (true_code, mode, XEXP (cond, 0), XEXP (cond, 1));
  
    /* Also when the truth value has to be reversed.  */
!   if (comparison_p
!       && (false_code = reversed_comparison_code (cond, NULL)) != UNKNOWN
        && true == const0_rtx && false == const_true_rtx)
!     return gen_binary (false_code,
  		       mode, XEXP (cond, 0), XEXP (cond, 1));
  
    /* Sometimes we can simplify the arm of an IF_THEN_ELSE if a register used
       in it is being compared against certain values.  Get the true and false
       comparisons and see if that says anything about the value of each arm.  */
  
!   if (comparison_p
!       && (false_code = reversed_comparison_code (cond, NULL)) != UNKNOWN
        && GET_CODE (XEXP (cond, 0)) == REG)
      {
        HOST_WIDE_INT nzb;
        rtx from = XEXP (cond, 0);
        rtx true_val = XEXP (cond, 1);
        rtx false_val = true_val;
        int swapped = 0;
*************** simplify_if_then_else (x)
*** 4691,4697 ****
       arm, the false arm is the same as the first operand of the comparison, or
       the false arm is more complicated than the true arm.  */
  
!   if (comparison_p && reversible_comparison_p (cond)
        && (true == pc_rtx
  	  || (CONSTANT_P (true)
  	      && GET_CODE (false) != CONST_INT && false != pc_rtx)
--- 4691,4698 ----
       arm, the false arm is the same as the first operand of the comparison, or
       the false arm is more complicated than the true arm.  */
  
!   if (comparison_p
!       && reversed_comparison_code (cond, NULL) != UNKNOWN
        && (true == pc_rtx
  	  || (CONSTANT_P (true)
  	      && GET_CODE (false) != CONST_INT && false != pc_rtx)
*************** simplify_if_then_else (x)
*** 4704,4710 ****
  	  || reg_mentioned_p (true, false)
  	  || rtx_equal_p (false, XEXP (cond, 0))))
      {
!       true_code = reverse_condition (true_code);
        SUBST (XEXP (x, 0),
  	     gen_binary (true_code, GET_MODE (cond), XEXP (cond, 0),
  			 XEXP (cond, 1)));
--- 4705,4711 ----
  	  || reg_mentioned_p (true, false)
  	  || rtx_equal_p (false, XEXP (cond, 0))))
      {
!       true_code = reversed_comparison_code (cond, NULL);
        SUBST (XEXP (x, 0),
  	     gen_binary (true_code, GET_MODE (cond), XEXP (cond, 0),
  			 XEXP (cond, 1)));
*************** simplify_set (x)
*** 5207,5212 ****
--- 5208,5214 ----
        rtx cond = XEXP (src, 0);
        rtx true_val = const1_rtx;
        rtx false_arm, true_arm;
+       emit rtx_code reversed_code;
  
        if (GET_CODE (cond) == MULT)
  	{
*************** simplify_set (x)
*** 5232,5245 ****
        /* Canonicalize if true_arm is the simpler one.  */
        if (GET_RTX_CLASS (GET_CODE (true_arm)) == 'o'
  	  && GET_RTX_CLASS (GET_CODE (false_arm)) != 'o'
! 	  && reversible_comparison_p (cond))
  	{
  	  rtx temp = true_arm;
  
  	  true_arm = false_arm;
  	  false_arm = temp;
  
! 	  cond = gen_rtx_combine (reverse_condition (GET_CODE (cond)),
  				  GET_MODE (cond), XEXP (cond, 0),
  				  XEXP (cond, 1));
  	}
--- 5234,5247 ----
        /* Canonicalize if true_arm is the simpler one.  */
        if (GET_RTX_CLASS (GET_CODE (true_arm)) == 'o'
  	  && GET_RTX_CLASS (GET_CODE (false_arm)) != 'o'
! 	  && (reversed_code = reversed_comparison_code (cond, NULL)) != UNKNOWN)
  	{
  	  rtx temp = true_arm;
  
  	  true_arm = false_arm;
  	  false_arm = temp;
  
! 	  cond = gen_rtx_combine (reversed_code,
  				  GET_MODE (cond), XEXP (cond, 0),
  				  XEXP (cond, 1));
  	}
*************** simplify_logical (x, last)
*** 5275,5280 ****
--- 5277,5283 ----
    enum machine_mode mode = GET_MODE (x);
    rtx op0 = XEXP (x, 0);
    rtx op1 = XEXP (x, 1);
+   enum rtx_code reversed_code;
  
    switch (GET_CODE (x))
      {
*************** simplify_logical (x, last)
*** 5526,5533 ****
        if (STORE_FLAG_VALUE == 1
  	  && op1 == const1_rtx
  	  && GET_RTX_CLASS (GET_CODE (op0)) == '<'
! 	  && reversible_comparison_p (op0))
! 	return gen_rtx_combine (reverse_condition (GET_CODE (op0)),
  				mode, XEXP (op0, 0), XEXP (op0, 1));
  
        /* (lshiftrt foo C) where C is the number of bits in FOO minus 1
--- 5529,5536 ----
        if (STORE_FLAG_VALUE == 1
  	  && op1 == const1_rtx
  	  && GET_RTX_CLASS (GET_CODE (op0)) == '<'
! 	  && (reversed_code = reversed_comparison_code (op0, NULL)) != UNKNOWN)
! 	return gen_rtx_combine (reversed_code,
  				mode, XEXP (op0, 0), XEXP (op0, 1));
  
        /* (lshiftrt foo C) where C is the number of bits in FOO minus 1
*************** simplify_logical (x, last)
*** 5548,5555 ****
  	      == (unsigned HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (mode) - 1))
  	  && op1 == const_true_rtx
  	  && GET_RTX_CLASS (GET_CODE (op0)) == '<'
! 	  && reversible_comparison_p (op0))
! 	return gen_rtx_combine (reverse_condition (GET_CODE (op0)),
  				mode, XEXP (op0, 0), XEXP (op0, 1));
  
        break;
--- 5551,5558 ----
  	      == (unsigned HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (mode) - 1))
  	  && op1 == const_true_rtx
  	  && GET_RTX_CLASS (GET_CODE (op0)) == '<'
! 	  && (reversed_code = reversed_comparison_code (op0, NULL)) != UNKNOWN)
! 	return gen_rtx_combine (reversed_code,
  				mode, XEXP (op0, 0), XEXP (op0, 1));
  
        break;
*************** if_then_else_cond (x, ptrue, pfalse)
*** 7340,7351 ****
  
  	  if (GET_RTX_CLASS (GET_CODE (cond0)) == '<'
  	      && GET_RTX_CLASS (GET_CODE (cond1)) == '<'
! 	      && reversible_comparison_p (cond1)
! 	      && ((GET_CODE (cond0) == reverse_condition (GET_CODE (cond1))
  		   && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 0))
  		   && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 1)))
  		  || ((swap_condition (GET_CODE (cond0))
! 		       == reverse_condition (GET_CODE (cond1)))
  		      && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 1))
  		      && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 0))))
  	      && ! side_effects_p (x))
--- 7343,7353 ----
  
  	  if (GET_RTX_CLASS (GET_CODE (cond0)) == '<'
  	      && GET_RTX_CLASS (GET_CODE (cond1)) == '<'
! 	      && ((GET_CODE (cond0) == reversed_comparison_code (cond1, NULL)
  		   && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 0))
  		   && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 1)))
  		  || ((swap_condition (GET_CODE (cond0))
! 		       == reversed_comparison_code (cond1, NULL))
  		      && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 1))
  		      && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 0))))
  	      && ! side_effects_p (x))
*************** if_then_else_cond (x, ptrue, pfalse)
*** 7370,7381 ****
  
  	  if (GET_RTX_CLASS (GET_CODE (cond0)) == '<'
  	      && GET_RTX_CLASS (GET_CODE (cond1)) == '<'
! 	      && reversible_comparison_p (cond1)
! 	      && ((GET_CODE (cond0) == reverse_condition (GET_CODE (cond1))
  		   && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 0))
  		   && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 1)))
  		  || ((swap_condition (GET_CODE (cond0))
! 		       == reverse_condition (GET_CODE (cond1)))
  		      && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 1))
  		      && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 0))))
  	      && ! side_effects_p (x))
--- 7372,7382 ----
  
  	  if (GET_RTX_CLASS (GET_CODE (cond0)) == '<'
  	      && GET_RTX_CLASS (GET_CODE (cond1)) == '<'
! 	      && ((GET_CODE (cond0) == reversed_comparison_code (cond1, NULL)
  		   && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 0))
  		   && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 1)))
  		  || ((swap_condition (GET_CODE (cond0))
! 		       == reversed_comparison_code (cond1, NULL))
  		      && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 1))
  		      && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 0))))
  	      && ! side_effects_p (x))
*************** known_cond (x, cond, reg, val)
*** 7521,7527 ****
  	      if (comparison_dominates_p (cond, code))
  		return const_true_rtx;
  
! 	      code = reverse_condition (code);
  	      if (code != UNKNOWN
  		  && comparison_dominates_p (cond, code))
  		return const0_rtx;
--- 7524,7530 ----
  	      if (comparison_dominates_p (cond, code))
  		return const_true_rtx;
  
! 	      code = reversed_comparison_code (x, NULL);
  	      if (code != UNKNOWN
  		  && comparison_dominates_p (cond, code))
  		return const0_rtx;
*************** simplify_comparison (code, pop0, pop1)
*** 10687,10706 ****
  
  	  /* Check for the cases where we simply want the result of the
  	     earlier test or the opposite of that result.  */
! 	  if (code == NE
! 	      || (code == EQ && reversible_comparison_p (op0))
  	      || (GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT
  		  && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
  		  && (STORE_FLAG_VALUE
  		      & (((HOST_WIDE_INT) 1
  			  << (GET_MODE_BITSIZE (GET_MODE (op0)) - 1))))
! 		  && (code == LT
! 		      || (code == GE && reversible_comparison_p (op0)))))
  	    {
  	      code = (code == LT || code == NE
! 		      ? GET_CODE (op0) : reverse_condition (GET_CODE (op0)));
! 	      op0 = tem, op1 = tem1;
! 	      continue;
  	    }
  	  break;
  
--- 10699,10719 ----
  
  	  /* Check for the cases where we simply want the result of the
  	     earlier test or the opposite of that result.  */
! 	  if (code == NE || code == EQ
  	      || (GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT
  		  && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
  		  && (STORE_FLAG_VALUE
  		      & (((HOST_WIDE_INT) 1
  			  << (GET_MODE_BITSIZE (GET_MODE (op0)) - 1))))
! 		  && (code == LT || (code == GE))))
  	    {
  	      code = (code == LT || code == NE
! 		      ? GET_CODE (op0) : reversed_comparison_code (op0, NULL));
! 	      if (code != UNKNOWN)
! 		{
! 		  op0 = tem, op1 = tem1;
! 		  continue;
! 		}
  	    }
  	  break;
  
*************** simplify_comparison (code, pop0, pop1)
*** 11101,11144 ****
    *pop1 = op1;
  
    return code;
- }
- 
- /* Return 1 if we know that X, a comparison operation, is not operating
-    on a floating-point value or is EQ or NE, meaning that we can safely
-    reverse it.  */
- 
- static int
- reversible_comparison_p (x)
-      rtx x;
- {
-   if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
-       || flag_fast_math
-       || GET_CODE (x) == NE || GET_CODE (x) == EQ
-       || GET_CODE (x) == UNORDERED || GET_CODE (x) == ORDERED)
-     return 1;
- 
-   switch (GET_MODE_CLASS (GET_MODE (XEXP (x, 0))))
-     {
-     case MODE_INT:
-     case MODE_PARTIAL_INT:
-     case MODE_COMPLEX_INT:
-       return 1;
- 
-     case MODE_CC:
-       /* If the mode of the condition codes tells us that this is safe,
- 	 we need look no further.  */
-       if (REVERSIBLE_CC_MODE (GET_MODE (XEXP (x, 0))))
- 	return 1;
- 
-       /* Otherwise try and find where the condition codes were last set and
- 	 use that.  */
-       x = get_last_value (XEXP (x, 0));
-       return (x && GET_CODE (x) == COMPARE
- 	      && ! FLOAT_MODE_P (GET_MODE (XEXP (x, 0))));
- 
-     default:
-       return 0;
-     }
  }
  
  /* Utility function for following routine.  Called when X is part of a value
--- 11114,11119 ----

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