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] Fix PR26898, folding of X +- C1 CMP Y +- C2


On Thu, 30 Mar 2006, Richard Guenther wrote:
> 2006-03-29  Richard Guenther  <rguenther@suse.de>
>
> 	PR middle-end/26898
> 	* fold-const.c (fold_comparison): Fold signed comparisons
> 	of the form X +- C1 CMP Y +- C2.
>
> 	* gcc.dg/pr26898.c: New testcase.

This is OK for mainline, with one minor tweak:

> +       tree lhs;
> +       int lhs_add;
> +       lhs_add = TREE_CODE (arg0) != PLUS_EXPR;
> +       lhs = fold_build2 (lhs_add ? PLUS_EXPR : MINUS_EXPR,
> + 			 TREE_TYPE (arg0), arg1, const1);

You should use bool instead of int, and you can avoid the extra
lines by reordering the declarations with the appropriate initializers.

Something like:

	bool lhs_add = TREE_CODE (arg0) != PLUS_EXPR;
	tree lhs = fold_build2 (lhs_add ? PLUS_EXPR : MINUS_EXPR,
				TREE_TYPE (arg0), arg1, const1);

Thanks for implementing this.

Roger
--


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