This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] fold-const trick for gzip
- From: Roger Sayle <roger at eyesopen dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 10 Dec 2003 21:11:44 -0700 (MST)
- Subject: Re: [tree-ssa] fold-const trick for gzip
On Wed, 10 Dec 2003, Richard Henderson wrote:
> Well, aside from the obvious ones, (p ? 1 : 0) -> (p != 0) and
> (true/false ? a : b), what do you hope to gain at the tree level?
Listing the many COND_EXPR transformations in fold-const.c, such as
ABS, MIN and MAX induction etc... would be too easy.
One could even argue that new additional optimizations such as
A & C1 ? B op C2 : B => B op ((A & C1) << C3)
or B op ((A & C1) >> C4)
where C1 and C2 are powers of two.
or
A ? (B ? X : Y) : Y => (A && B) ? X : Y
A ? (B ? X : Y) : X => (!A || B) ? X : Y
could equally well be performed at the RTL-level.
But the killer application for COND_EXPR optimization at the
tree-ssa level is switch statement induction. Conversion of
A == C1 ? X1 :
A == C2 ? X2 :
(A == C3 || A == C4) ? X3 :
A == C5 ? X4 : X5;
into a switch statment that can be evaluated as either a table-jump,
a balanced binary-tree of comparisons, bit tests or even a look-up table
is something that can't be performed once we've lowered to RTL.
To take a random example consider i386.h's REG_CLASS_FROM_LETTER:
#define REG_CLASS_FROM_LETTER(C) \
((C) == 'r' ? GENERAL_REGS : \
(C) == 'R' ? LEGACY_REGS : \
(C) == 'q' ? TARGET_64BIT ? GENERAL_REGS : Q_REGS : \
(C) == 'Q' ? Q_REGS : \
(C) == 'f' ? (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387 \
? FLOAT_REGS \
: NO_REGS) : \
(C) == 't' ? (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387 \
? FP_TOP_REG \
: NO_REGS) : \
(C) == 'u' ? (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387 \
? FP_SECOND_REG \
: NO_REGS) : \
(C) == 'a' ? AREG : \
(C) == 'b' ? BREG : \
(C) == 'c' ? CREG : \
(C) == 'd' ? DREG : \
(C) == 'x' ? TARGET_SSE ? SSE_REGS : NO_REGS : \
(C) == 'Y' ? TARGET_SSE2? SSE_REGS : NO_REGS : \
(C) == 'y' ? TARGET_MMX ? MMX_REGS : NO_REGS : \
(C) == 'A' ? AD_REGS : \
(C) == 'D' ? DIREG : \
(C) == 'S' ? SIREG : NO_REGS)
Roger
--