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] Finish off PR15784


ja2morri@csclub.uwaterloo.ca (James A. Morrison) writes:

PING: http://gcc.gnu.org/ml/gcc-patches/2005-02/msg00905.html

>  Hi,
> 
>   This patch adds the last bit of folding that pr15784 was actually
> looking for.  This has been bootstrapped and regtested on powerpc-linux,
> all languages except ada and java.  Ok for mainline?
> 
> -- 
> Thanks,
> Jim
> 
> http://www.student.cs.uwaterloo.ca/~ja2morri/
> http://phython.blogspot.com
> http://open.nit.ca/wiki/?page=jim
> 
> 
> 
> 2005-02-16  James A. Morrison  <phython@gcc.gnu.org>
> 
> 	* fold-const.c (fold): Fold ~A + 1 to -1.  Fold -A - 1
> 	and -1 - A to ~A.
> 
> Index: fold-const.c
> ===================================================================
> RCS file: /cvsroot/gcc/gcc/gcc/fold-const.c,v
> retrieving revision 1.512
> diff -u -p -r1.512 fold-const.c
> --- fold-const.c	15 Feb 2005 21:58:10 -0000	1.512
> +++ fold-const.c	16 Feb 2005 05:08:38 -0000
> @@ -7010,6 +7009,11 @@ fold (tree expr)
>        if (TREE_CODE (arg0) == NEGATE_EXPR
>  	  && reorder_operands_p (TREE_OPERAND (arg0, 0), arg1))
>  	return fold (build2 (MINUS_EXPR, type, arg1, TREE_OPERAND (arg0, 0)));
> +      /* Convert ~A + 1 to -A.  */
> +      if (INTEGRAL_TYPE_P (type)
> +	  && TREE_CODE (arg0) == BIT_NOT_EXPR
> +	  && integer_onep (arg1))
> +	return fold (build1 (NEGATE_EXPR, type, TREE_OPERAND (arg0, 0)));
>  
>        if (TREE_CODE (type) == COMPLEX_TYPE)
>  	{
> @@ -7448,6 +7452,16 @@ fold (tree expr)
>  	  && reorder_operands_p (arg0, arg1))
>  	return fold (build2 (MINUS_EXPR, type, negate_expr (arg1),
>  			     TREE_OPERAND (arg0, 0)));
> +      /* Convert -A - 1 to ~A.  */
> +      if (INTEGRAL_TYPE_P (type)
> +	  && TREE_CODE (arg0) == NEGATE_EXPR
> +	  && integer_onep (arg1))
> +	return fold (build1 (BIT_NOT_EXPR, type, TREE_OPERAND (arg0, 0)));
> +
> +      /* Convert -1 - A to ~A.  */
> +      if (INTEGRAL_TYPE_P (type)
> +	  && integer_all_onesp (arg0))
> +	return fold (build1 (BIT_NOT_EXPR, type, arg1));
>  
>        if (TREE_CODE (type) == COMPLEX_TYPE)
>  	{

-- 
Thanks,
Jim

http://www.student.cs.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim


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