This is the mail archive of the 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]

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;

bool foo()
  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.  */
+      && 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.



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