From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id EB9CC394FC1B for ; Mon, 28 Jun 2021 08:44:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EB9CC394FC1B Received: by mail-ej1-x629.google.com with SMTP id o5so3594675ejy.7 for ; Mon, 28 Jun 2021 01:44:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EZLOiogR6bxr3810L2celgxRiESBQCzzDLZ7N+ME7nA=; b=GnIClMWt3WayL4htLtuDteu5He4ouXgj7OvEeu4qsFpG79CjH8ecEqII9yA8MmeuBX 69jYB6FjYENY0yj4sfvr7UZY/HCwbGjYrIu2NF2v33+FBzQCMezNC2lw+HtnSHfHn28B HUWx8pbRaGcXPFelaQJi15Tbs0AlLOunkQgIwl0LKn9YHpcXsrGDtduAe9QqTqAuWjht aNT0XzoGRoX5iaEH9Z+P23AiXYSeMhmzCJYJP+WBzwQ6ZHmBUINg1/HVNb/gxUDEYNC5 KYv/xQmxLA3NEW5+4Sc7n9zBoyWJMGBb6ehvd5Bw9uVAOE3obZyX0bYgH1A7O709ovi4 2reQ== X-Gm-Message-State: AOAM531UMTFZ1lPz2kvhjIB9M+FMOdWGZmjuTCojxZTBnuWlhzbPFCte V9IqHngOXl52kywqp2uPUhNsdSA9heHmCmDgDt0= X-Google-Smtp-Source: ABdhPJyIb0Z2k3yzcP8l6Jk55rz+cyo7o5andELa/tG98xgOkljPcXCGfLs3NEBzsrQblEUuSW1SNRI0ljEQ622KVao= X-Received: by 2002:a17:906:52d9:: with SMTP id w25mr15069224ejn.138.1624869868978; Mon, 28 Jun 2021 01:44:28 -0700 (PDT) MIME-Version: 1.0 References: <1624836300-23553-1-git-send-email-apinski@marvell.com> <1624836300-23553-4-git-send-email-apinski@marvell.com> In-Reply-To: <1624836300-23553-4-git-send-email-apinski@marvell.com> From: Richard Biener Date: Mon, 28 Jun 2021 10:44:18 +0200 Message-ID: Subject: Re: [PATCH 3/4] Try inverted comparison for match_simplify in phiopt To: Andrew Pinski Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jun 2021 08:44:31 -0000 On Mon, Jun 28, 2021 at 1:28 AM apinski--- via Gcc-patches wrote: > > From: Andrew Pinski > > 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 with the comment fix suggested by Bernhard. I think if the match fails you have to somewhere discard the sequence, since it can still end up with partly pushed stmts - otherwise you'll slowly leak SSA names. Theres gimple_seq_discard () for this. It's probably best to do it in gimple_simplify_phiopt after each failed try. Richard. > Thanks, > Andrew Pinski > > gcc/ChangeLog: > > * tree-ssa-phiopt.c (gimple_simplify_phiopt): > If "A ? B : C" fails to simplify, try "(!A) ? C : B". > --- > gcc/tree-ssa-phiopt.c | 27 ++++++++++++++++++++++++++- > 1 file changed, 26 insertions(+), 1 deletion(-) > > diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c > index 17bc597851b..9bda1b2a397 100644 > --- a/gcc/tree-ssa-phiopt.c > +++ b/gcc/tree-ssa-phiopt.c > @@ -836,7 +836,8 @@ phiopt_early_allow (enum tree_code code) > with parts pushed if EARLY_P was true. Also rejects non allowed tree code > if EARLY_P is set. > Takes the comparison from COMP_STMT and two args, ARG0 and ARG1 and tries > - to simplify CMP ? ARG0 : ARG1. */ > + to simplify CMP ? ARG0 : ARG1. > + Also try to simplify (!CMP) ? ARG0 : ARG1 if the non-inverse failed. */ > static tree > gimple_simplify_phiopt (bool early_p, tree type, gimple *comp_stmt, > tree arg0, tree arg1, > @@ -869,6 +870,30 @@ gimple_simplify_phiopt (bool early_p, tree type, gimple *comp_stmt, > return result; > } > } > + /* Try the inverted comparison, that is !COMP ? ARG1 : ARG0. */ > + comp_code = invert_tree_comparison (comp_code, HONOR_NANS (cmp0)); > + > + if (comp_code == ERROR_MARK) > + return NULL; > + > + cond = build2_loc (loc, > + comp_code, boolean_type_node, > + cmp0, cmp1); > + gimple_match_op op1 (gimple_match_cond::UNCOND, > + COND_EXPR, type, cond, arg1, arg0); > + > + if (op1.resimplify (early_p ? NULL : seq, follow_all_ssa_edges)) > + { > + /* Early we want only to allow some generated tree codes. */ > + if (!early_p > + || op1.code.is_tree_code () > + || phiopt_early_allow ((tree_code)op1.code)) > + { > + result = maybe_push_res_to_seq (&op1, seq); > + if (result) > + return result; > + } > + } > > return NULL; > } > -- > 2.27.0 >