On Thu, Oct 6, 2011 at 11:28 AM, Kai Tietz <kti...@redhat.com> wrote:
> Hello,
>
> Sorry attached non-updated change.  Here with proper attached patch.
> This patch improves in fold_truth_andor the generation of branch-conditions 
> for targets having LOGICAL_OP_NON_SHORT_CIRCUIT set.  If right-hand side 
> operation of a TRUTH_(OR|AND)IF_EXPR is simple operand, has no side-effects, 
> and doesn't trap, then try to convert expression to a TRUTH_(AND|OR)_EXPR, if 
> left-hand operand is a simple operand, and has no side-effects.
>
> ChangeLog
>
> 2011-10-06  Kai Tietz  <kti...@redhat.com>
>
>        * fold-const.c (fold_truth_andor): Convert TRUTH_(AND|OR)IF_EXPR
>        to TRUTH_OR_EXPR, if suitable.
>
> Bootstrapped and tested for all languages (including Ada and Obj-C++) on host 
> x86_64-unknown-linux-gnu.  Ok for apply?
>
> Regards,
> Kai
>
>
> ndex: fold-const.c
> ===================================================================
> --- fold-const.c        (revision 179592)
> +++ fold-const.c        (working copy)
> @@ -8387,6 +8387,33 @@
>   if ((tem = fold_truthop (loc, code, type, arg0, arg1)) != 0)
>     return tem;
>
> +  if ((code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
> +      && !TREE_SIDE_EFFECTS (arg1)
> +      && simple_operand_p (arg1)
> +      && LOGICAL_OP_NON_SHORT_CIRCUIT

Why only for LOGICAL_OP_NON_SHORT_CIRCUIT?  It doesn't make
a difference for !LOGICAL_OP_NON_SHORT_CIRCUIT targets, but ...

> +      && !FLOAT_TYPE_P (TREE_TYPE (arg1))

?  I hope we don't have &&|| float.

> +      && ((TREE_CODE_CLASS (TREE_CODE (arg1)) != tcc_comparison
> +          && TREE_CODE (arg1) != TRUTH_NOT_EXPR)
> +         || !FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg1, 0)))))

?  simple_operand_p would have rejected both ! and comparisons.

I miss a test for side-effects on arg0 (and probably simple_operand_p there,
as well).

> +    {
> +      if (TREE_CODE (arg0) == code
> +          && !TREE_SIDE_EFFECTS (TREE_OPERAND (arg0, 1))
> +          && simple_operand_p (TREE_OPERAND (arg0, 1)))

Err ... so why do you recurse here (and associate)?  Even with different
predicates than above ...

And similar transforms seem to happen in fold_truthop - did you
investigate why it didn't trigger there.

And I'm missing a testcase.

Richard.

> +       {
> +         tem = build2_loc (loc,
> +                           (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
> +                                                     : TRUTH_OR_EXPR),
> +                           type, TREE_OPERAND (arg0, 1), arg1);
> +       return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem);
> +      }
> +      if (!TREE_SIDE_EFFECTS (arg0)
> +          && simple_operand_p (arg0))
> +       return build2_loc (loc,
> +                          (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
> +                                                    : TRUTH_OR_EXPR),
> +                          type, arg0, arg1);
> +    }
> +
>   return NULL_TREE;
>  }
>
>

Reply via email to