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]

[patch] adjust make_range


In looking at a missed optimization from a customer request:

unsigned char cond;
 
foo (void)
{
   
   if (cond <= 2 || (cond-2) > 100)
        return 7;
   return 0;
}

We were turning it into a pair of branches and failing to merge the
ranges of the comparison. After this patch it completes and breaks the
previous 11 instruction two branch sequence into a 5 instruction no
branch sequence. Muuuch better.

With this small change we actually complete the merge of the ranges
since we're in the range at the time of the call, and then we should
adjust afterwards, I think. I also believe we should be using orig_type
instead of the long expansion in the type precision check.

Bootstrapped and regression tested on x86-linux. Tested on
mipsisa64-elf. No regressions.

OK?

-eric

-- 
Eric Christopher <echristo@redhat.com>

2004-06-09  Eric Christopher  <echristo@redhat.com>

	* fold-const.c (make_range): Use orig_type in type precision.
	Use 1 for in_p in calls to merge_ranges.

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.390
diff -u -p -w -r1.390 fold-const.c
--- fold-const.c	9 Jun 2004 15:32:33 -0000	1.390
+++ fold-const.c	9 Jun 2004 23:10:33 -0000
@@ -3680,7 +3680,7 @@ make_range (tree exp, int *pin_p, tree *
 
 	     So we have to make sure that the original unsigned value will
 	     be interpreted as positive.  */
-	  if (TYPE_UNSIGNED (type) && ! TYPE_UNSIGNED (TREE_TYPE (exp)))
+	  if (TYPE_UNSIGNED (type) && ! TYPE_UNSIGNED (orig_type))
 	    {
 	      tree equiv_type = lang_hooks.types.type_for_mode
 		(TYPE_MODE (type), 1);
@@ -3693,7 +3693,7 @@ make_range (tree exp, int *pin_p, tree *
 		= TYPE_MAX_VALUE (equiv_type) ? TYPE_MAX_VALUE (equiv_type)
 		  : TYPE_MAX_VALUE (type);
 
-	      if (TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (exp)))
+	      if (TYPE_PRECISION (type) == TYPE_PRECISION (orig_type))
 	        high_positive = fold (build2 (RSHIFT_EXPR, type,
 					      fold_convert (type,
 							    high_positive),
@@ -3718,7 +3718,7 @@ make_range (tree exp, int *pin_p, tree *
 		  /* Otherwise, "or" the range with the range of the input
 		     that will be interpreted as negative.  */
 		  if (! merge_ranges (&n_in_p, &n_low, &n_high,
-				      0, n_low, n_high, 1,
+				      1, n_low, n_high, 1,
 				      fold_convert (type, integer_zero_node),
 				      high_positive))
 		    break;



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