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]: Transform builtin ascii and toascii


On Wed, 7 Apr 2004, Kaveh R. Ghazi wrote:
> 2004-04-05  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
>
> 	* builtins.c (fold_builtin_isascii, fold_builtin_toascii): New.
> 	(fold_builtin): Handle BUILT_IN_ISASCII and BUILT_IN_TOASCII.
>
> testsuite:
> 	* gcc.dg/torture/builtin-ctype-2.c: New test.

This is OK for mainline with the tweaks below.


> +      return fold (build (EQ_EXPR, integer_type_node, integer_zero_node,
> +			  build (BIT_AND_EXPR, integer_type_node, arg,
> +				 fold (build1 (BIT_NOT_EXPR,
> +					       integer_type_node,
> +					       build_int_2 (0x7f, 0))))));

This bit could be done more efficiently as

	tree tem = build_int_2 (~ (unsigned HOST_WIDE_INT) 0x7f,
				~ (HOST_WIDE_INT) 0);
	... build (BIT_AND_EXPR, integer_type_node, arg, tem);

This saves building a tree node for the BIT_NOT_EXPR and passing it to
fold just to calculate the immediate constant ~ 0x7f at compile-time.
You should also place the integer_zero_node as the second operand of
the EQ_EXPR, as this will save "fold" the trouble of swapping it around
during its canonicalization.

Ok with those changes (after the usual testing).  Many thanks.

Roger
--


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