From patchwork Sat Apr 22 22:09:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 86644 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1912111vqo; Sat, 22 Apr 2023 15:13:30 -0700 (PDT) X-Google-Smtp-Source: AKy350YgQcCo9q7+AUjf4rBFvf2VmGDfNWQfcfg59F9XniSra5qH1qNq7uzqNIuqZN5elPfBH2f3 X-Received: by 2002:a17:907:961d:b0:94a:653b:ba41 with SMTP id gb29-20020a170907961d00b0094a653bba41mr5980285ejc.15.1682201609979; Sat, 22 Apr 2023 15:13:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682201609; cv=none; d=google.com; s=arc-20160816; b=aBH3TRsHPzyXI14iSP9BpywoXJN3vdvaW8qLqaFN+BXRbAcPkX+mcS4bT48eQHs1Dk iT8Dvg9qcmKQI+DsLVOFp3JRa1FN7XlIQKFnE6YN/CnSXZQ4nzaGvR1SW4svX8zd11IP a2OdaMyw9sAH+dqmJ+leg7mLCde1copQ8XFVZA1DA1Cugff6Klr8CHeT4oEwf14PRQHc kGeJeHqUilvoPkZFz90eKH8C0mDs9NgrPciNaXu6exAOcD78/30g5L3lBr3Q4cBlRQyX Ylzu9NXd7YhRTfQyozin1bVzu3Smpk3ISYUBZ7hN1mgqw/E6LQFnRzKc5k3Pjci4kjMh I71g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=AHYmZ7XMm8PvDzUN0rS6zIob1x1sLFjSiveAtU8otto=; b=UOL9euebAXfe2ryz25ufBFKzcQ0qxRwvPV4WxcBa0UjzC0Iqvzvn4Iqi/Dm91T5vER alS/jUHETFpQnbmiPtMc8MQYl+xpn/ce9nCUlfUOD+yA1rv8Xkgt3Vnj0GMiRHZF+wVx Gs5yqHaKM5+tahykU1T7k/YDmC4frvRLEF7TobQq2GRHht8GHkZikWM+OWDbnk/83Yhg PytiJIqblCptgoJpzR+fHrvFtQLkAywOAraFq7Rt3mq2YpjmfBzz3jNInWYk1HeFXqzN Sv8FXkam7c7QnM1S+zDA+Sp/BDy52WLa7VgN2HUJzr9LXDpOf0fqIIFZVg3t/HlOwjB9 cRFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DppP1v5J; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l20-20020a1709065a9400b0094f9cd7adf3si2608732ejq.1008.2023.04.22.15.13.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 15:13:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DppP1v5J; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD47E3834691 for ; Sat, 22 Apr 2023 22:11:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD47E3834691 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682201496; bh=AHYmZ7XMm8PvDzUN0rS6zIob1x1sLFjSiveAtU8otto=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=DppP1v5Jvqm/YsCrKgsKUh0vXl4sgU63c2fSVeAzCFnj6vlS91Xe212ygJTor7CNg kBuCnoc07dY38ktTUVW3zvaaBHEny7ZrEQ0zFLqtzcLDGjQ2Dgbth4xsiIK9Vgtiah +wx3T/8PWAiGw9sY9Lv2YW2ocrp/puNkBA9dxBEA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 4661E3858401 for ; Sat, 22 Apr 2023 22:09:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4661E3858401 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33MLGWqC006595 for ; Sat, 22 Apr 2023 15:09:44 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q4egjhpa0-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 22 Apr 2023 15:09:44 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sat, 22 Apr 2023 15:09:32 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Sat, 22 Apr 2023 15:09:32 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 7F9613F708D; Sat, 22 Apr 2023 15:09:32 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 6/6] PHIOPT: Add support for diamond shaped bb to match_simplify_replacement Date: Sat, 22 Apr 2023 15:09:21 -0700 Message-ID: <20230422220921.452264-7-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230422220921.452264-1-apinski@marvell.com> References: <20230422220921.452264-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: zgGlF2fdLttvt9pGSku5Dk8SlJ3FKoIZ X-Proofpoint-GUID: zgGlF2fdLttvt9pGSku5Dk8SlJ3FKoIZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-22_15,2023-04-21_01,2023-02-09_01 X-Spam-Status: No, score=-14.6 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_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763916235229599012?= X-GMAIL-MSGID: =?utf-8?q?1763916235229599012?= This adds diamond shaped form of basic blocks to match_simplify_replacement. This is the patch is the start of removing/moving all of what minmax_replacement does to match.pd to reduce the code duplication. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Note phi-opt-{23,24}.c testcase had an incorrect xfail as there should have been 2 if still because f4/f5 would not be transformed as -ABS is not allowable during early phi-opt. gcc/ChangeLog: * tree-ssa-phiopt.cc (match_simplify_replacement): Add new arguments and support diamond shaped basic block form. (tree_ssa_phiopt_worker): Update call to match_simplify_replacement gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/phi-opt-23.c: Update testcase. * gcc.dg/tree-ssa/phi-opt-24.c: Likewise. --- gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c | 4 +-- gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c | 4 +-- gcc/tree-ssa-phiopt.cc | 37 ++++++++++++++++++---- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c index ff658cd16a7..86aab955d5e 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c @@ -38,7 +38,7 @@ int f5(int A) return -A; } -/* These should be optimized in phiopt1 but is confused by predicts. */ -/* { dg-final { scan-tree-dump-not "if" "phiopt1" { xfail *-*-* } } } */ +/* f4 and f5 are not allowed to be optimized in early phi-opt. */ +/* { dg-final { scan-tree-dump-times "if" 2 "phiopt1" } } */ /* { dg-final { scan-tree-dump-not "if" "phiopt2" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c index eb89decb4bf..bd8308efa0e 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c @@ -38,7 +38,7 @@ float f5(float A) return -A; } -/* These should be optimized in phiopt1 but is confused by predicts. */ -/* { dg-final { scan-tree-dump-not "if" "phiopt1" { xfail *-*-* } } } */ +/* f4 and f5 are not allowed to be optimized in early phi-opt. */ +/* { dg-final { scan-tree-dump-times "if" 2 "phiopt1" } } */ /* { dg-final { scan-tree-dump-not "if" "phiopt2" } } */ diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index ffd6a4e6f35..757e44692ed 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -57,8 +57,8 @@ along with GCC; see the file COPYING3. If not see static bool two_value_replacement (basic_block, basic_block, edge, gphi *, tree, tree); -static bool match_simplify_replacement (basic_block, basic_block, - edge, edge, gphi *, tree, tree, bool); +static bool match_simplify_replacement (basic_block, basic_block, basic_block, + edge, edge, gphi *, tree, tree, bool, bool); static gphi *factor_out_conditional_conversion (edge, edge, gphi *, tree, tree, gimple *); static int value_replacement (basic_block, basic_block, @@ -304,9 +304,8 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) && !diamond_p && two_value_replacement (bb, bb1, e2, phi, arg0, arg1)) cfgchanged = true; - else if (!diamond_p - && match_simplify_replacement (bb, bb1, e1, e2, phi, - arg0, arg1, early_p)) + else if (match_simplify_replacement (bb, bb1, bb2, e1, e2, phi, + arg0, arg1, early_p, diamond_p)) cfgchanged = true; else if (!early_p && !diamond_p @@ -1026,8 +1025,10 @@ empty_bb_or_one_feeding_into_p (basic_block bb, static bool match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, + basic_block middle_bb_alt, edge e0, edge e1, gphi *phi, - tree arg0, tree arg1, bool early_p) + tree arg0, tree arg1, bool early_p, + bool threeway_p) { gimple *stmt; gimple_stmt_iterator gsi; @@ -1035,6 +1036,7 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, gimple_seq seq = NULL; tree result; gimple *stmt_to_move = NULL; + gimple *stmt_to_move_alt = NULL; auto_bitmap inserted_exprs; /* Special case A ? B : B as this will always simplify to B. */ @@ -1046,6 +1048,12 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, if (!empty_bb_or_one_feeding_into_p (middle_bb, phi, stmt_to_move)) return false; + if (threeway_p + && middle_bb != middle_bb_alt + && !empty_bb_or_one_feeding_into_p (middle_bb_alt, phi, + stmt_to_move_alt)) + return false; + /* At this point we know we have a GIMPLE_COND with two successors. One successor is BB, the other successor is an empty block which falls through into BB. @@ -1110,6 +1118,23 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, reset_flow_sensitive_info (name); } + if (stmt_to_move_alt) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "statement un-sinked:\n"); + print_gimple_stmt (dump_file, stmt_to_move_alt, 0, + TDF_VOPS|TDF_MEMSYMS); + } + + tree name = gimple_get_lhs (stmt_to_move_alt); + // Mark the name to be renamed if there is one. + bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (name)); + gimple_stmt_iterator gsi1 = gsi_for_stmt (stmt_to_move_alt); + gsi_move_before (&gsi1, &gsi); + reset_flow_sensitive_info (name); + } + replace_phi_edge_with_variable (cond_bb, e1, phi, result, inserted_exprs); /* Add Statistic here even though replace_phi_edge_with_variable already