From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 59F723886C44 for ; Sun, 27 Jun 2021 23:25:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 59F723886C44 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15RNL7iw028199 for ; Sun, 27 Jun 2021 16:25:07 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com with ESMTP id 39f11y086j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 27 Jun 2021 16:25:07 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 27 Jun 2021 16:25:06 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 27 Jun 2021 16:25:06 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.197]) by maili.marvell.com (Postfix) with ESMTP id 0EB353F704B; Sun, 27 Jun 2021 16:25:06 -0700 (PDT) From: To: CC: Andrew Pinski Subject: [PATCH 3/4] Try inverted comparison for match_simplify in phiopt Date: Sun, 27 Jun 2021 16:24:59 -0700 Message-ID: <1624836300-23553-4-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1624836300-23553-1-git-send-email-apinski@marvell.com> References: <1624836300-23553-1-git-send-email-apinski@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-GUID: gIbjuSA0Nc7fuJL_d1HNv4SSkMwJljpP X-Proofpoint-ORIG-GUID: gIbjuSA0Nc7fuJL_d1HNv4SSkMwJljpP X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-06-27_04:2021-06-25, 2021-06-27 signatures=0 X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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: Sun, 27 Jun 2021 23:25:09 -0000 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. 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