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]

[Committed] Eliminate tree-vrp.c:opposite_comparison


This patch cleans up some functional duplication between tree-vrp.c
and fold-const.c.  An inspection of tree-vrp.c's opposite_comparison
shows that it's almost identical to swap_tree_comparison, which is used
by several source files.  The only difference is that the former also
handles the unordered floating point comparison tree codes.

The following patch enhances swap_tree_comparison, and thereby allows
opposite_comparison to be deleted and callers in tree-vrp.c to use
swap_tree_comparison instead.  Historically, I think it was reasonable
to introduce opposite_comparison whilst writing tree-vrp.c, to reduce
the diffs that were needed.  However, now that tree-vrp.c is established
as a tree-ssa optimizer, this hangover from its development can be
tidied.


The following patch has been been tested on i686-pc-linux-gnu with a
full "make bootstrap", all default languages, and regression tested
with a top-level "make -k check" with no new failures.

Committed to mainline CVS.



2005-06-19  Roger Sayle  <roger@eyesopen.com>

	* fold-const.c (swap_tree_comparison): Add support for unordered
	floating point comparisons.
	* tree-vrp.c (opposite_comparison): Delete.
	(extract_range_from_assert): Replace calls to opposite_comparison
	with calls to swap_tree_comparison.
	(register_edge_assert_for): Likewise.
	(vrp_evaluate_conditional): Likewise.


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.597
diff -c -3 -p -r1.597 fold-const.c
*** fold-const.c	18 Jun 2005 19:57:02 -0000	1.597
--- fold-const.c	19 Jun 2005 22:11:21 -0000
*************** swap_tree_comparison (enum tree_code cod
*** 2169,2174 ****
--- 2169,2178 ----
      {
      case EQ_EXPR:
      case NE_EXPR:
+     case ORDERED_EXPR:
+     case UNORDERED_EXPR:
+     case LTGT_EXPR:
+     case UNEQ_EXPR:
        return code;
      case GT_EXPR:
        return LT_EXPR;
*************** swap_tree_comparison (enum tree_code cod
*** 2178,2183 ****
--- 2182,2195 ----
        return GT_EXPR;
      case LE_EXPR:
        return GE_EXPR;
+     case UNGT_EXPR:
+       return UNLT_EXPR;
+     case UNGE_EXPR:
+       return UNLE_EXPR;
+     case UNLT_EXPR:
+       return UNGT_EXPR;
+     case UNLE_EXPR:
+       return UNGE_EXPR;
      default:
        gcc_unreachable ();
      }
Index: tree-vrp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-vrp.c,v
retrieving revision 2.30
diff -c -3 -p -r2.30 tree-vrp.c
*** tree-vrp.c	16 Jun 2005 21:25:00 -0000	2.30
--- tree-vrp.c	19 Jun 2005 22:11:22 -0000
*************** static sbitmap blocks_visited;
*** 94,139 ****
     of values that SSA name N_I may take.  */
  static value_range_t **vr_value;

- /* Given a comparison code, return its opposite.  Note that this is *not*
-    the same as inverting its truth value (invert_tree_comparison).  Here we
-    just want to literally flip the comparison around.
-
-    So, '<' gets '>', '<=' gets '>='.  Both '==' and '!=' are returned
-    unchanged.  */
-
- static enum tree_code
- opposite_comparison (enum tree_code code)
- {
-   switch (code)
-     {
-     case EQ_EXPR:
-     case NE_EXPR:
-     case ORDERED_EXPR:
-     case UNORDERED_EXPR:
-     case LTGT_EXPR:
-     case UNEQ_EXPR:
-       return code;
-     case GT_EXPR:
-       return LT_EXPR;
-     case GE_EXPR:
-       return LE_EXPR;
-     case LT_EXPR:
-       return GT_EXPR;
-     case LE_EXPR:
-       return GE_EXPR;
-     case UNGT_EXPR:
-       return UNLT_EXPR;
-     case UNGE_EXPR:
-       return UNLE_EXPR;
-     case UNLT_EXPR:
-       return UNGT_EXPR;
-     case UNLE_EXPR:
-       return UNGE_EXPR;
-     default:
-       gcc_unreachable ();
-     }
- }
-

  /* Return true if EXPR computes a non-zero value.  */

--- 94,99 ----
*************** extract_range_from_assert (value_range_t
*** 711,717 ****
  	 to flip around the comparison code to create the proper range
  	 for VAR.  */
        limit = TREE_OPERAND (cond, 0);
!       cond_code = opposite_comparison (TREE_CODE (cond));
      }

    type = TREE_TYPE (limit);
--- 671,677 ----
  	 to flip around the comparison code to create the proper range
  	 for VAR.  */
        limit = TREE_OPERAND (cond, 0);
!       cond_code = swap_tree_comparison (TREE_CODE (cond));
      }

    type = TREE_TYPE (limit);
*************** register_edge_assert_for (tree name, edg
*** 2231,2237 ****
  	      /* If the predicate is of the form VAL COMP NAME, flip
  		 COMP around because we need to register NAME as the
  		 first operand in the predicate.  */
! 	      comp_code = opposite_comparison (TREE_CODE (cond));
  	      val = TREE_OPERAND (cond, 0);
  	    }
  	  else
--- 2191,2197 ----
  	      /* If the predicate is of the form VAL COMP NAME, flip
  		 COMP around because we need to register NAME as the
  		 first operand in the predicate.  */
! 	      comp_code = swap_tree_comparison (TREE_CODE (cond));
  	      val = TREE_OPERAND (cond, 0);
  	    }
  	  else
*************** vrp_evaluate_conditional (tree cond, boo
*** 3023,3029 ****
  	    return compare_name_with_value (TREE_CODE (cond), op0, op1);
  	  else if (TREE_CODE (op1) == SSA_NAME)
  	    return compare_name_with_value (
! 		    opposite_comparison (TREE_CODE (cond)), op1, op0);
  	}
        else
  	{
--- 2983,2989 ----
  	    return compare_name_with_value (TREE_CODE (cond), op0, op1);
  	  else if (TREE_CODE (op1) == SSA_NAME)
  	    return compare_name_with_value (
! 		    swap_tree_comparison (TREE_CODE (cond)), op1, op0);
  	}
        else
  	{
*************** vrp_evaluate_conditional (tree cond, boo
*** 3038,3044 ****
  	    return compare_range_with_value (TREE_CODE (cond), vr0, op1);
  	  else if (vr0 == NULL && vr1)
  	    return compare_range_with_value (
! 		    opposite_comparison (TREE_CODE (cond)), vr1, op0);
  	}
      }

--- 2998,3004 ----
  	    return compare_range_with_value (TREE_CODE (cond), vr0, op1);
  	  else if (vr0 == NULL && vr1)
  	    return compare_range_with_value (
! 		    swap_tree_comparison (TREE_CODE (cond)), vr1, op0);
  	}
      }


Roger
--


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