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]

[Committed] Simplify (GEU x 1) as (NE x 0)


Whilst working on some optimizations for simplify_relational_operation_1
in simplify-rtx.c, the function that simplifies RTL comparisons to
expressions other than constant true/false, I noticed that it was missing
some of the "obvious" canonicalizations, and it didn't make much sense to
add my significantly more complex cases first.

This patch attempts to simplify/canonicalize comparisons against integer
constants to be simpler comparisons against the constant zero.  Many
architectures support "test" instructions in addition to "cmp", or can use
"cc0" to determine the result from a previous operation.  Even on targets,
that don't there's no harm in canonicalizing equivalent conditions to the
same RTL.

This patch implements:

(GTU x 0) -> (NE x 0)
(LEU x 0) -> (EQ x 0)
(GE  x 1) -> (GT x 0)
(GEU x 1) -> (NE x 0)
(LT  x 1) -> (LE x 0)
(LTU x 1) -> (EQ x 0)
(LE x -1) -> (LT x 0)
(GT x -1) -> (GE x 0)

A more general form of this type of canonicalization is already
implemented (by Richard G) on trees in fold-const.c.  Instrumenting this
code reveals that these transformations trigger frequently during a GCC
bootstrap.

The following patch has been tested on i686-pc-linux-gnu, with a full
"make bootstrap", all default languages including Ada, and regression
tested with a top-level "make -k check" with no new failures.

Committed to mainline as revision 121544.


2007-02-03  Roger Sayle  <roger@eyesopen.com>

        * simplify-rtx.c (simplify_relational_operation_1): Implement some
        canonicalization transformations that attempt to simplify integer
        constant comparisons to become comparisons against zero.

Roger
--

Attachment: patchc.txt
Description: Text document


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