This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] for PR18942
- From: Roger Sayle <roger at eyesopen dot com>
- To: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sun, 19 Dec 2004 10:14:41 -0700 (MST)
- Subject: Re: [patch] for PR18942
On Sun, 19 Dec 2004, Zdenek Dvorak wrote:
> PR rtl-optimization/18942
> * simplify-rtx.c (simplify_relational_operation_1): Simplify
> x + cst1 == cst2 to x == cst2 - cst1.
This is OK for mainline. Thanks.
However, I do have some optional suggestions for improvements. The
first is that you could take this opportunity to fix the declaration
of simplify_relational_operation_1 to make it "static" to match it's
prototype.
The next is just a very minor style issue.
> + /* (eq/ne (plus x cst1) cst2) simplifies to (eq/ne x (cst2 - cst1)) */
> + if ((code == EQ || code == NE)
> + && CONSTANT_P (op1)
> + && GET_CODE (op0) == PLUS)
> + {
> + rtx x = XEXP (op0, 0);
> + rtx c = XEXP (op0, 1);
> +
> + if (CONSTANT_P (c))
> + {
> + c = simplify_gen_binary (MINUS, cmp_mode, op1, c);
> +
> + return simplify_gen_relational (code, mode, cmp_mode, x, c);
> + }
> + }
My personal preference would be to avoid the nested conditional and
instead write this as
/* (eq/ne (plus x c1) c2) simplifies to (eq/ne x (c2 - c1)). */
if ((code == EQ || code == NE)
&& CONSTANT_P (op1)
&& GET_CODE (op0) == PLUS
&& CONSTANT_P (XEXP (op0, 1)))
{
rtx c = XEXP (op0, 1);
...
Then finally this transformation can also be generalized to handle the
MINUS case as well, i.e. "(x - C1) == C2" -> "x == (C2 + C1)".
These aren't requirements on committing your patch, but enhancements
that are eligible under the regression status PR 18942.
Thanks in advance,
Roger
--