On Tue, Oct 19, 2021 at 7:30 PM Jiufu Guo via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> In tree_simplify_using_condition_1, there is code which should be logic:
> "op0 || op1"/"op0 && op1".  When creating expression for TRUTH_OR_EXPR
> and TRUTH_AND_EXPR, fold_build2 would be used instead fold_binary which
> always return NULL_TREE for this kind of expr.
>
> Bootstrap and regtest pass on ppc and ppc64le.  Is this ok for trunk?

No, because I think it is the wrong thing to do as we will be throwing
away the result if the fold_binary is not an integer cst anyways so
creating an extra tree is a waste.

>
> BR,
> Jiufu
>
> gcc/ChangeLog:
>
>         * tree-ssa-loop-niter.c (tree_simplify_using_condition_1): Replace
>         fold_binary with fold_build2 fir logical OR/AND.
>
> ---
>  gcc/tree-ssa-loop-niter.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
> index 75109407124..27e11a29707 100644
> --- a/gcc/tree-ssa-loop-niter.c
> +++ b/gcc/tree-ssa-loop-niter.c
> @@ -2290,12 +2290,12 @@ tree_simplify_using_condition_1 (tree cond, tree expr)
>
>    /* Check whether COND ==> EXPR.  */
>    notcond = invert_truthvalue (cond);
> -  e = fold_binary (TRUTH_OR_EXPR, boolean_type_node, notcond, expr);
> +  e = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, notcond, expr);
>    if (e && integer_nonzerop (e))
>      return e;

We already check for non-nullness and we also check to see it is an
integer which is nonzero. So building a tree which will be thrown away
is just a waste and all.

>
>    /* Check whether COND ==> not EXPR.  */
> -  e = fold_binary (TRUTH_AND_EXPR, boolean_type_node, cond, expr);
> +  e = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, cond, expr);
>    if (e && integer_zerop (e))
>      return e;

Likewise.

Thanks,
Andrew Pinski

>
> --
> 2.17.1
>

Reply via email to