This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR26898, folding of X +- C1 CMP Y +- C2
- From: Roger Sayle <roger at eyesopen dot com>
- To: Richard Guenther <rguenther at suse dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 30 Mar 2006 06:16:28 -0700 (MST)
- Subject: 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
--