On Mon, Sep 30, 2013 at 2:29 AM, Zhenqiang Chen <zhenqiang.c...@arm.com> wrote:
> Hi,
>
> The patch enhances phiopt to handle cases like:
>
>   if (a == 0 && (...))
>     return 0;
>   return a;
>
> Boot strap and no make check regression on X86-64 and ARM.
>
> Is it OK for trunk?

>From someone who wrote lot of this code (value_replacement in fact),
this looks good, though I would pull:
+  if (TREE_CODE (gimple_assign_rhs1 (def)) == SSA_NAME)
+    {
+      gimple def1 = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (def));
+      if (is_gimple_assign (def1) && gimple_assign_rhs_code (def1) == EQ_EXPR)
+ {
+  tree op0 = gimple_assign_rhs1 (def1);
+  tree op1 = gimple_assign_rhs2 (def1);
+  if ((operand_equal_for_phi_arg_p (arg0, op0)
+       && operand_equal_for_phi_arg_p (arg1, op1))
+      || (operand_equal_for_phi_arg_p (arg0, op1)
+               && operand_equal_for_phi_arg_p (arg1, op0)))
+    {
+      *code = gimple_assign_rhs_code (def1);
+      return 1;
+    }
+ }
+    }

Out into its own function since it is repeated again for
gimple_assign_rhs2 (def).  Also what about cascading BIT_AND_EXPR
like:
if((a == 0) & (...) & (...))

I notice you don't handle that either.

Thanks,
Andrew Pinski

>
> Thanks!
> -Zhenqiang
>
> ChangeLog:
> 2013-09-30  Zhenqiang Chen  <zhenqiang.c...@linaro.org>
>
>         * tree-ssa-phiopt.c (operand_equal_for_phi_arg_p_1): New.
>         (value_replacement): Move a check to operand_equal_for_phi_arg_p_1.
>
> testsuite/ChangeLog:
> 2013-09-30  Zhenqiang Chen  <zhenqiang.c...@linaro.org>
>
>         * gcc.dg/tree-ssa/phi-opt-11.c: New test case.

Reply via email to