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]

Re: [PATCH] Optimize ((c>=1)&&(c<=127)) into ((signed char)c>0)


On Thu, May 09, 2002 at 06:46:30AM -0600, Roger Sayle wrote:
> !       unsigned HOST_WIDE_INT lo;
> !       HOST_WIDE_INT hi;
> !       int prec;
> !
> !       prec = TYPE_PRECISION (etype);
> !       if (prec <= HOST_BITS_PER_WIDE_INT)
> !         {
> !           hi = 0;
> !           lo = ((unsigned HOST_WIDE_INT) 1 << (prec - 1)) - 1;
> !         }
> !       else
> !         {
> !           hi = ((HOST_WIDE_INT) 1 << (prec - HOST_BITS_PER_WIDE_INT - 1)) - 1;
> !           lo = (unsigned HOST_WIDE_INT) -1;
> !         }
> !
> !       if (TREE_INT_CST_HIGH (high) == hi && TREE_INT_CST_LOW (high) == lo)

This is the second time you've had to write this sequence
recently.  You might consider pulling it out to a predicate
beside integer_onep, et al.

> !           if (! TREE_UNSIGNED (etype))
> !             return fold (build (GT_EXPR, type, exp,
> !                                 convert (etype, integer_zero_node)));
> !           stype = (*lang_hooks.types.signed_type) (etype);
> !           return fold (build (GT_EXPR, type, convert (stype, exp),
> !                               convert (stype, integer_zero_node)));

Better

	if (TREE_UNSIGNED (etype))
	  {
	    etype = (*lang_hooks.types.signed_type) (etype);
	    exp = convert (etype, exp);
	  }
	return fold (build (GT_EXPR, type, exp,
			    convert (etype, integer_zero_node)));

Otherwise it looks good.


r~


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