This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Improve when TRUTH_AND_EXPR is created from TRUTH_ANDIF_EXPR
- From: Roger Sayle <roger at eyesopen dot com>
- To: Andrew Pinski <pinskia at physics dot uc dot edu>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 19 May 2005 08:47:41 -0600 (MDT)
- Subject: Re: [PATCH] Improve when TRUTH_AND_EXPR is created from TRUTH_ANDIF_EXPR
On Thu, 19 May 2005, Andrew Pinski wrote:
> * fold-const.c (fold_truthop): Simplify LHS ANDIF_EXPR RHS for simple
> RHS and LHS.
Hmm. There are two potential issues here.
Firstly, could you check with your patch that long sequences of
ANDIF_EXPRs aren't blindly converted into AND_EXPRs? I think this
is safe because gimplification should lower ANDIF_EXPR before the
constant folder sees all operands as SSA_NAMEs and therefore
bool a, b, c, d, e, f, g;
return a && b && c && d && e && f && g;
should only turn one ANDIF_EXPR at the leaf, into an AND_EXPR.
The other minor issue is that LOGICAL_OP_NON_SHORT_CIRCUIT could be
tested earlier, and we want to avoid (re)constructing trees if there is
no change. As written your patch will transform TRUTH_AND_EXPR into
TRUTH_AND_EXPR, return a different tree from fold(t) even if t is
the same. Thiscan create more tree nodes than necessar. It also
disables the following optimizations for TRUTH_AND_EXPR when both
operands are simple.
I'm thinking an improved version would look something like:
+ /* Simplify LHS ANDIF_EXPR RHS to LHS AND_EXPR RHS for simple RHS and
+ LHS. Likewise for ORIF_EXPR. */
+ if (LOGICAL_OP_NON_SHORT_CIRCUIT
+ && simple_operand_p (lhs)
+ && simple_operand_p (rhs))
+ if (code == TRUTH_ANDIF_EXPR)
+ return fold_build2 (TRUTH_AND_EXPR, truth_type, lhs, rhs);
+ if (code == TRUTH_ORIF_EXPR)
+ return fold_build2 (TRUTH_OR_EXPR, truth_type, lhs, rhs);
If you can confirm that we still have conditional branches in the
test case above, the revised patch is OK for mainline after the
usual bootstrap and regression test.