On Sat, Jun 19, 2021 at 10:51 PM apinski--- via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> From: Andrew Pinski <apin...@marvell.com>
>
> Since match and simplify does not have all of the inverted
> comparison patterns, it make sense to just have
> phi-opt try to do the inversion and try match and simplify again.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu.

OK.

Richard.

> Thanks,
> Andrew Pinski
>
> gcc/ChangeLog:
>
>         * tree-ssa-phiopt.c (match_simplify_replacement):
>         If "A ? B : C" fails to simplify, try "(!A) ? C : B".
> ---
>  gcc/tree-ssa-phiopt.c | 21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
> index feb8ca8d0d1..3b3762a668b 100644
> --- a/gcc/tree-ssa-phiopt.c
> +++ b/gcc/tree-ssa-phiopt.c
> @@ -879,7 +879,26 @@ match_simplify_replacement (basic_block cond_bb, 
> basic_block middle_bb,
>                             arg0, arg1,
>                             &seq, NULL);
>    if (!result)
> -    return false;
> +    {
> +      /* Try !A ? arg1 : arg0 instead.
> +        Not all match patterns support inverted comparisons.  */
> +      enum tree_code comp_code = gimple_cond_code (stmt);
> +      tree cmp0 = gimple_cond_lhs (stmt);
> +      tree cmp1 = gimple_cond_rhs (stmt);
> +      comp_code = invert_tree_comparison (comp_code, HONOR_NANS (cmp0));
> +      if (comp_code != ERROR_MARK)
> +       {
> +         cond = build2_loc (gimple_location (stmt),
> +                            comp_code, boolean_type_node,
> +                            cmp0, cmp1);
> +         result = gimple_simplify (COND_EXPR, type,
> +                                   cond,
> +                                   arg1, arg0,
> +                                   &seq, NULL);
> +       }
> +      if (!result)
> +       return false;
> +    }
>
>    gsi = gsi_last_bb (cond_bb);
>    if (stmt_to_move)
> --
> 2.27.0
>

Reply via email to