From patchwork Mon Apr 24 21:30:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 87168 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3016044vqo; Mon, 24 Apr 2023 14:32:14 -0700 (PDT) X-Google-Smtp-Source: AKy350YsIc73zZbHeTY+fjFocZKkiS/k+1Yvusbfdf3lDrFz95RPUeVQVkSVePuwGspiE3ePuVA2 X-Received: by 2002:aa7:d519:0:b0:501:fe46:480b with SMTP id y25-20020aa7d519000000b00501fe46480bmr13453201edq.15.1682371933996; Mon, 24 Apr 2023 14:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682371933; cv=none; d=google.com; s=arc-20160816; b=utrGyb2JSMhST2ufjaqivvrzBzq+C6jgZN2+kh8mP4328zQ7ibDETV8e4ZPW3rgPs+ 33lJr4Twz0or+022PuTCfQbPUlkvMIUoXS7920g/3Z37J+kHptXHfw9s9nuagAwbGV7q lSx4zz7wGvnh0Ii37wXjnHHbbfBkivZqK7zfN8DZ2HoH+bKyfNP9FIDRSQcJyvgN2Ufd 31a4hIsfd8lPRtdZGQfsrJLu3E4dglc4UWZCZnbkpHST3CFdAQlh9FYQL1PzJT3RDDm5 d1ml6bHX5WtqJ+YtA8J9eSvOgMbgpVBNtT6mQXzIUg0tbK7u2WlE0M2irfXMql5dFl32 2tTw== 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=OGqr1we4K/C9CIFTaNskAIhmjFnSwYF9Hrj5NmTO44c=; b=jd2zYVjShIyGo1GCV5JA5YQvpy3elFTcMCHhE5HND7ZF4vpFXW+fxrNUqpJHpbvcA0 EQdQgy8zWHs6X5K25/o+FCgTxrR9xJ/Hh+ZblpoFYeTPpjSyxFrg2KhUkf/Nprwq8mbC GVvE0zwLmiz9LeUQpJmqhhc1ady/RCEn0ln+zoLa/aXAs+d/xXKQIsDilK8vQrU4lUZ6 DmF43CQTnokKX2uPqU9vZWFCREtK3YUIOjqrMeP+ggkVddywAJYDeXkxxYpOwY5M852T ycLCOG16E4YPsTWsP00Nxh34/ailgEMMs7HROeDdWhXyU9u/7/+osY0TGyM11tSNAsjc Dhdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OX1A56st; 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 z20-20020aa7d414000000b00506778b4f3csi8792775edq.375.2023.04.24.14.32.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 14:32:13 -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=OX1A56st; 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 44FE63853562 for ; Mon, 24 Apr 2023 21:31:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 44FE63853562 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682371875; bh=OGqr1we4K/C9CIFTaNskAIhmjFnSwYF9Hrj5NmTO44c=; 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=OX1A56stIKNKsZEp0etDbffafkBGLBo9sKQggHvP8GIpyih4ARsWfiZor0SdwVaHV txwezAtXp4iWrVpm4RgfieSqIhvAC6WiUPNI/zCxv5Cqw2NmgMm5vr3GMR6eZwqBnV ee3TeydyDpXfOYadQlg3BiANAm2UiajmoKpnwqHk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 2AF823858C50 for ; Mon, 24 Apr 2023 21:30:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2AF823858C50 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33OKnSI1010728 for ; Mon, 24 Apr 2023 14:30:23 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3q4f3p7pyj-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 24 Apr 2023 14:30:23 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 24 Apr 2023 14:30:20 -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.48 via Frontend Transport; Mon, 24 Apr 2023 14:30:20 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 312223F70B5; Mon, 24 Apr 2023 14:30:19 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 1/7] PHIOPT: Split out store elimination from phiopt Date: Mon, 24 Apr 2023 14:30:05 -0700 Message-ID: <20230424213011.528181-2-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230424213011.528181-1-apinski@marvell.com> References: <20230424213011.528181-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: w9vfLJ-NoCeWsvh-2X32o-rgn_LaUcyA X-Proofpoint-GUID: w9vfLJ-NoCeWsvh-2X32o-rgn_LaUcyA 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-24_11,2023-04-21_01,2023-02-09_01 X-Spam-Status: No, score=-14.5 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?1764094832881887146?= X-GMAIL-MSGID: =?utf-8?q?1764094832881887146?= Since the last cleanups, it made easier to see that we should split out the store elimination worker from tree_ssa_phiopt_worker function. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssa-phiopt.cc (tree_ssa_phiopt_worker): Remove do_store_elim argument and split that part out to ... (store_elim_worker): This new function. (pass_cselim::execute): Call store_elim_worker. (pass_phiopt::execute): Update call to tree_ssa_phiopt_worker. --- gcc/tree-ssa-phiopt.cc | 180 ++++++++++++++++++++++++++++------------- 1 file changed, 126 insertions(+), 54 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 4a3ab8efb71..7f47b32576b 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -104,27 +104,19 @@ single_non_singleton_phi_for_edges (gimple_seq seq, edge e0, edge e1) return phi; } -/* The core routine of conditional store replacement and normal - phi optimizations. Both share much of the infrastructure in how - to match applicable basic block patterns. DO_STORE_ELIM is true - when we want to do conditional store replacement, false otherwise. +/* The core routine of phi optimizations. DO_HOIST_LOADS is true when we want to hoist adjacent loads out of diamond control flow patterns, false otherwise. */ static unsigned int -tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) +tree_ssa_phiopt_worker (bool do_hoist_loads, bool early_p) { basic_block bb; basic_block *bb_order; unsigned n, i; bool cfgchanged = false; - hash_set *nontrap = 0; calculate_dominance_info (CDI_DOMINATORS); - if (do_store_elim) - /* Calculate the set of non-trapping memory accesses. */ - nontrap = get_non_trapping (); - /* Search every basic block for COND_EXPR we may be able to optimize. We walk the blocks in order that guarantees that a block with @@ -148,7 +140,7 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) /* Check to see if the last statement is a GIMPLE_COND. */ gcond *cond_stmt = safe_dyn_cast (*gsi_last_bb (bb)); if (!cond_stmt) - continue; + continue; e1 = EDGE_SUCC (bb, 0); bb1 = e1->dest; @@ -158,12 +150,12 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) /* We cannot do the optimization on abnormal edges. */ if ((e1->flags & EDGE_ABNORMAL) != 0 || (e2->flags & EDGE_ABNORMAL) != 0) - continue; + continue; /* If either bb1's succ or bb2 or bb2's succ is non NULL. */ if (EDGE_COUNT (bb1->succs) == 0 || EDGE_COUNT (bb2->succs) == 0) - continue; + continue; /* Find the bb which is the fall through to the other. */ if (EDGE_SUCC (bb1, 0)->dest == bb2) @@ -192,39 +184,6 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) || (e1->flags & EDGE_FALLTHRU) == 0) continue; - if (do_store_elim) - { - if (diamond_p) - { - basic_block bb3 = e1->dest; - - /* Only handle sinking of store from 2 bbs only, - The middle bbs don't need to come from the - if always since we are sinking rather than - hoisting. */ - if (EDGE_COUNT (bb3->preds) != 2) - continue; - if (cond_if_else_store_replacement (bb1, bb2, bb3)) - cfgchanged = true; - continue; - } - - /* Also make sure that bb1 only have one predecessor and that it - is bb. */ - if (!single_pred_p (bb1) - || single_pred (bb1) != bb) - continue; - - /* bb1 is the middle block, bb2 the join block, bb the split block, - e1 the fallthrough edge from bb1 to bb2. We can't do the - optimization if the join block has more than two predecessors. */ - if (EDGE_COUNT (bb2->preds) > 2) - continue; - if (cond_store_replacement (bb1, bb2, e1, e2, nontrap)) - cfgchanged = true; - continue; - } - if (diamond_p) { basic_block bb3 = e1->dest; @@ -322,18 +281,132 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) free (bb_order); - if (do_store_elim) - delete nontrap; + if (cfgchanged) + return TODO_cleanup_cfg; + return 0; +} + +/* The core routine of conditional store replacement. */ +static unsigned int +store_elim_worker (void) +{ + basic_block bb; + basic_block *bb_order; + unsigned n, i; + bool cfgchanged = false; + hash_set *nontrap = 0; + + calculate_dominance_info (CDI_DOMINATORS); + + /* Calculate the set of non-trapping memory accesses. */ + nontrap = get_non_trapping (); + + /* Search every basic block for COND_EXPR we may be able to optimize. + + We walk the blocks in order that guarantees that a block with + a single predecessor is processed before the predecessor. + This ensures that we collapse inner ifs before visiting the + outer ones, and also that we do not try to visit a removed + block. */ + bb_order = single_pred_before_succ_order (); + n = n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS; + + for (i = 0; i < n; i++) + { + basic_block bb1, bb2; + edge e1, e2; + bool diamond_p = false; + + bb = bb_order[i]; + + /* Check to see if the last statement is a GIMPLE_COND. */ + gcond *cond_stmt = safe_dyn_cast (*gsi_last_bb (bb)); + if (!cond_stmt) + continue; + + e1 = EDGE_SUCC (bb, 0); + bb1 = e1->dest; + e2 = EDGE_SUCC (bb, 1); + bb2 = e2->dest; + + /* We cannot do the optimization on abnormal edges. */ + if ((e1->flags & EDGE_ABNORMAL) != 0 + || (e2->flags & EDGE_ABNORMAL) != 0) + continue; + + /* If either bb1's succ or bb2 or bb2's succ is non NULL. */ + if (EDGE_COUNT (bb1->succs) == 0 + || EDGE_COUNT (bb2->succs) == 0) + continue; + + /* Find the bb which is the fall through to the other. */ + if (EDGE_SUCC (bb1, 0)->dest == bb2) + ; + else if (EDGE_SUCC (bb2, 0)->dest == bb1) + { + std::swap (bb1, bb2); + std::swap (e1, e2); + } + else if (EDGE_SUCC (bb1, 0)->dest == EDGE_SUCC (bb2, 0)->dest + && single_succ_p (bb2)) + { + diamond_p = true; + e2 = EDGE_SUCC (bb2, 0); + /* Make sure bb2 is just a fall through. */ + if ((e2->flags & EDGE_FALLTHRU) == 0) + continue; + } + else + continue; + + e1 = EDGE_SUCC (bb1, 0); + + /* Make sure that bb1 is just a fall through. */ + if (!single_succ_p (bb1) + || (e1->flags & EDGE_FALLTHRU) == 0) + continue; + + if (diamond_p) + { + basic_block bb3 = e1->dest; + + /* Only handle sinking of store from 2 bbs only, + The middle bbs don't need to come from the + if always since we are sinking rather than + hoisting. */ + if (EDGE_COUNT (bb3->preds) != 2) + continue; + if (cond_if_else_store_replacement (bb1, bb2, bb3)) + cfgchanged = true; + continue; + } + + /* Also make sure that bb1 only have one predecessor and that it + is bb. */ + if (!single_pred_p (bb1) + || single_pred (bb1) != bb) + continue; + + /* bb1 is the middle block, bb2 the join block, bb the split block, + e1 the fallthrough edge from bb1 to bb2. We can't do the + optimization if the join block has more than two predecessors. */ + if (EDGE_COUNT (bb2->preds) > 2) + continue; + if (cond_store_replacement (bb1, bb2, e1, e2, nontrap)) + cfgchanged = true; + } + + free (bb_order); + + delete nontrap; /* If the CFG has changed, we should cleanup the CFG. */ - if (cfgchanged && do_store_elim) + if (cfgchanged) { /* In cond-store replacement we have added some loads on edges and new VOPS (as we moved the store, and created a load). */ gsi_commit_edge_inserts (); return TODO_cleanup_cfg | TODO_update_ssa_only_virtuals; } - else if (cfgchanged) - return TODO_cleanup_cfg; return 0; } @@ -4257,8 +4330,7 @@ public: bool gate (function *) final override { return flag_ssa_phiopt; } unsigned int execute (function *) final override { - return tree_ssa_phiopt_worker (false, - !early_p ? gate_hoist_loads () : false, + return tree_ssa_phiopt_worker (!early_p ? gate_hoist_loads () : false, early_p); } @@ -4360,7 +4432,7 @@ pass_cselim::execute (function *) An interfacing issue of find_data_references_in_bb. */ loop_optimizer_init (LOOPS_NORMAL); scev_initialize (); - todo = tree_ssa_phiopt_worker (true, false, false); + todo = store_elim_worker (); scev_finalize (); loop_optimizer_finalize (); return todo; From patchwork Mon Apr 24 21:30:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 87172 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3017093vqo; Mon, 24 Apr 2023 14:34:59 -0700 (PDT) X-Google-Smtp-Source: AKy350Ypt4ipfhXQw60X2ikr/xQlA6pz+OOqbW6gf++IU5ceZc3OUbgqUYb90zwoo65m5VutWbWy X-Received: by 2002:a17:906:381:b0:94f:8605:3f30 with SMTP id b1-20020a170906038100b0094f86053f30mr10679497eja.24.1682372099261; Mon, 24 Apr 2023 14:34:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682372099; cv=none; d=google.com; s=arc-20160816; b=x5Wg5t40rr/lfA1M5CZL2YFbyhuiFE4YV8uwAlLuVVIkv5lUDHlq1/kr7qREWDt/s+ Easy5pu0LHTZtY10TnmJEiO1xF1LMDwRqoBz+zm27ALkkzfQmII4V+glPeIYLP/vCiIK MnMfx5VXX9UZU7gd+EN8SRe3yEOTi/gv4tOvCiS1zstL2mZb6Qlh+GSfssd/09+0IDGb kA9QNhjkTPZATvfvUZeWkXcU1K0iKmmUZ6aqIfs0eMgPGK6iUuBaVmdNcLG4Y30VSALe Y6bAQo4uJEGrfjjZr09vBTGWs9KzpLJ0Yr9POhdr8+03+ruxdXVMSV4xs0nSd9eu4Mix YeGQ== 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=puWAV6Qgv/yYkQvX9rBNsBTZU6qvmsvrIDWEtnRpSI4=; b=Ud4e2y6mFwLE7dEeiRwo11rLtz0jWWkRQ84dIn7hNFsFFSkN48XaSxfzyc6eZE8U3o h1L6doJc6oNfUxFSMbxi4SYsjcqalHBRP4w8adeWdMEW8AEKHXShf2V/5OqFDkne0l0T dVdrxdyV/o7syQVL/PNxYGq4QKnZB/kqjo1mm46wkjZFn6Me5Ppj74AtQHHdHzZpi1rj w0Szs3UMP/DOqf/cHN+wqzEuf8ychpLh9s+AgdLQ9G4viz3xrEKnmvg3uuXPB/qDwPr/ lmeX9exmaE+eJKdne+6lFjfbndBfwrUXYwg0UNPZhIXzY2pItNd9mmtzgdjwFONS2kZR YyYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wPpYPdJ8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id y8-20020a170906558800b00950ea4cbd1csi9573867ejp.241.2023.04.24.14.34.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 14:34:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wPpYPdJ8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 01629385B527 for ; Mon, 24 Apr 2023 21:33:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01629385B527 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682371990; bh=puWAV6Qgv/yYkQvX9rBNsBTZU6qvmsvrIDWEtnRpSI4=; 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=wPpYPdJ8ScC9/htHMT2pUO/etZ3Bb8BwmU5fX0oA4SqnAIpYhR6I5sMhVEzNS+TG2 vXsxAFgP8tSzs/u+EcxKeUq0MMwXfJlnAG00rQVbS47zm5p+lfymv7GL3H7NBgR3OT h9Pql35JlDxzV8nLCewW5jFg+oPgPzUlF5x4i0/s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id C4AF83858C5E for ; Mon, 24 Apr 2023 21:30:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4AF83858C5E Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33OKnSI2010728 for ; Mon, 24 Apr 2023 14:30:24 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3q4f3p7pyj-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 24 Apr 2023 14:30:24 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 24 Apr 2023 14:30:20 -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; Mon, 24 Apr 2023 14:30:20 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 011043F70D1; Mon, 24 Apr 2023 14:30:19 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 2/7] PHIOPT: Rename tree_ssa_phiopt_worker to pass_phiopt::execute Date: Mon, 24 Apr 2023 14:30:06 -0700 Message-ID: <20230424213011.528181-3-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230424213011.528181-1-apinski@marvell.com> References: <20230424213011.528181-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: qxIpjc4HiYjGELwSWEq24p-wpt1TZuis X-Proofpoint-GUID: qxIpjc4HiYjGELwSWEq24p-wpt1TZuis 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-24_11,2023-04-21_01,2023-02-09_01 X-Spam-Status: No, score=-14.5 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?1764095006285739750?= X-GMAIL-MSGID: =?utf-8?q?1764095006285739750?= Now that store elimination and phiopt does not share outer code, we can move tree_ssa_phiopt_worker directly into pass_phiopt::execute and remove many declarations (prototypes) from the file. gcc/ChangeLog: * tree-ssa-phiopt.cc (two_value_replacement): Remove prototype. (match_simplify_replacement): Likewise. (factor_out_conditional_conversion): Likewise. (value_replacement): Likewise. (minmax_replacement): Likewise. (spaceship_replacement): Likewise. (cond_removal_in_builtin_zero_pattern): Likewise. (hoist_adjacent_loads): Likewise. (tree_ssa_phiopt_worker): Move into ... (pass_phiopt::execute): this. --- gcc/tree-ssa-phiopt.cc | 385 +++++++++++++++++++---------------------- 1 file changed, 181 insertions(+), 204 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 7f47b32576b..d232fd9b551 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -55,27 +55,10 @@ along with GCC; see the file COPYING3. If not see #include "tree-ssa-propagate.h" #include "tree-ssa-dce.h" -static bool two_value_replacement (basic_block, basic_block, edge, gphi *, - tree, tree); -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, - edge, edge, gphi *, tree, tree); -static bool minmax_replacement (basic_block, basic_block, basic_block, - edge, edge, gphi *, tree, tree, bool); -static bool spaceship_replacement (basic_block, basic_block, - edge, edge, gphi *, tree, tree); -static bool cond_removal_in_builtin_zero_pattern (basic_block, basic_block, - edge, edge, gphi *, - tree, tree); static bool cond_store_replacement (basic_block, basic_block, edge, edge, hash_set *); static bool cond_if_else_store_replacement (basic_block, basic_block, basic_block); static hash_set * get_non_trapping (); -static void hoist_adjacent_loads (basic_block, basic_block, - basic_block, basic_block); /* Return the singleton PHI in the SEQ of PHIs for edges E0 and E1. */ @@ -104,188 +87,6 @@ single_non_singleton_phi_for_edges (gimple_seq seq, edge e0, edge e1) return phi; } -/* The core routine of phi optimizations. - DO_HOIST_LOADS is true when we want to hoist adjacent loads out - of diamond control flow patterns, false otherwise. */ -static unsigned int -tree_ssa_phiopt_worker (bool do_hoist_loads, bool early_p) -{ - basic_block bb; - basic_block *bb_order; - unsigned n, i; - bool cfgchanged = false; - - calculate_dominance_info (CDI_DOMINATORS); - - /* Search every basic block for COND_EXPR we may be able to optimize. - - We walk the blocks in order that guarantees that a block with - a single predecessor is processed before the predecessor. - This ensures that we collapse inner ifs before visiting the - outer ones, and also that we do not try to visit a removed - block. */ - bb_order = single_pred_before_succ_order (); - n = n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS; - - for (i = 0; i < n; i++) - { - gphi *phi; - basic_block bb1, bb2; - edge e1, e2; - tree arg0, arg1; - bool diamond_p = false; - - bb = bb_order[i]; - - /* Check to see if the last statement is a GIMPLE_COND. */ - gcond *cond_stmt = safe_dyn_cast (*gsi_last_bb (bb)); - if (!cond_stmt) - continue; - - e1 = EDGE_SUCC (bb, 0); - bb1 = e1->dest; - e2 = EDGE_SUCC (bb, 1); - bb2 = e2->dest; - - /* We cannot do the optimization on abnormal edges. */ - if ((e1->flags & EDGE_ABNORMAL) != 0 - || (e2->flags & EDGE_ABNORMAL) != 0) - continue; - - /* If either bb1's succ or bb2 or bb2's succ is non NULL. */ - if (EDGE_COUNT (bb1->succs) == 0 - || EDGE_COUNT (bb2->succs) == 0) - continue; - - /* Find the bb which is the fall through to the other. */ - if (EDGE_SUCC (bb1, 0)->dest == bb2) - ; - else if (EDGE_SUCC (bb2, 0)->dest == bb1) - { - std::swap (bb1, bb2); - std::swap (e1, e2); - } - else if (EDGE_SUCC (bb1, 0)->dest == EDGE_SUCC (bb2, 0)->dest - && single_succ_p (bb2)) - { - diamond_p = true; - e2 = EDGE_SUCC (bb2, 0); - /* Make sure bb2 is just a fall through. */ - if ((e2->flags & EDGE_FALLTHRU) == 0) - continue; - } - else - continue; - - e1 = EDGE_SUCC (bb1, 0); - - /* Make sure that bb1 is just a fall through. */ - if (!single_succ_p (bb1) - || (e1->flags & EDGE_FALLTHRU) == 0) - continue; - - if (diamond_p) - { - basic_block bb3 = e1->dest; - - if (!single_pred_p (bb1) - || !single_pred_p (bb2)) - continue; - - if (do_hoist_loads - && !FLOAT_TYPE_P (TREE_TYPE (gimple_cond_lhs (cond_stmt))) - && EDGE_COUNT (bb->succs) == 2 - && EDGE_COUNT (bb3->preds) == 2 - /* If one edge or the other is dominant, a conditional move - is likely to perform worse than the well-predicted branch. */ - && !predictable_edge_p (EDGE_SUCC (bb, 0)) - && !predictable_edge_p (EDGE_SUCC (bb, 1))) - hoist_adjacent_loads (bb, bb1, bb2, bb3); - } - - gimple_stmt_iterator gsi; - bool candorest = true; - - /* Check that we're looking for nested phis. */ - basic_block merge = diamond_p ? EDGE_SUCC (bb2, 0)->dest : bb2; - gimple_seq phis = phi_nodes (merge); - - /* Value replacement can work with more than one PHI - so try that first. */ - if (!early_p && !diamond_p) - for (gsi = gsi_start (phis); !gsi_end_p (gsi); gsi_next (&gsi)) - { - phi = as_a (gsi_stmt (gsi)); - arg0 = gimple_phi_arg_def (phi, e1->dest_idx); - arg1 = gimple_phi_arg_def (phi, e2->dest_idx); - if (value_replacement (bb, bb1, e1, e2, phi, arg0, arg1) == 2) - { - candorest = false; - cfgchanged = true; - break; - } - } - - if (!candorest) - continue; - - phi = single_non_singleton_phi_for_edges (phis, e1, e2); - if (!phi) - continue; - - arg0 = gimple_phi_arg_def (phi, e1->dest_idx); - arg1 = gimple_phi_arg_def (phi, e2->dest_idx); - - /* Something is wrong if we cannot find the arguments in the PHI - node. */ - gcc_assert (arg0 != NULL_TREE && arg1 != NULL_TREE); - - gphi *newphi; - if (single_pred_p (bb1) - && !diamond_p - && (newphi = factor_out_conditional_conversion (e1, e2, phi, - arg0, arg1, - cond_stmt))) - { - phi = newphi; - /* factor_out_conditional_conversion may create a new PHI in - BB2 and eliminate an existing PHI in BB2. Recompute values - that may be affected by that change. */ - arg0 = gimple_phi_arg_def (phi, e1->dest_idx); - arg1 = gimple_phi_arg_def (phi, e2->dest_idx); - gcc_assert (arg0 != NULL_TREE && arg1 != NULL_TREE); - } - - /* Do the replacement of conditional if it can be done. */ - if (!early_p - && !diamond_p - && two_value_replacement (bb, bb1, e2, phi, arg0, arg1)) - cfgchanged = true; - 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 - && single_pred_p (bb1) - && cond_removal_in_builtin_zero_pattern (bb, bb1, e1, e2, - phi, arg0, arg1)) - cfgchanged = true; - else if (minmax_replacement (bb, bb1, bb2, e1, e2, phi, arg0, arg1, - diamond_p)) - cfgchanged = true; - else if (single_pred_p (bb1) - && !diamond_p - && spaceship_replacement (bb, bb1, e1, e2, phi, arg0, arg1)) - cfgchanged = true; - } - - free (bb_order); - - if (cfgchanged) - return TODO_cleanup_cfg; - return 0; -} - /* The core routine of conditional store replacement. */ static unsigned int store_elim_worker (void) @@ -4328,11 +4129,7 @@ public: early_p = param; } bool gate (function *) final override { return flag_ssa_phiopt; } - unsigned int execute (function *) final override - { - return tree_ssa_phiopt_worker (!early_p ? gate_hoist_loads () : false, - early_p); - } + unsigned int execute (function *) final override; private: bool early_p; @@ -4346,6 +4143,186 @@ make_pass_phiopt (gcc::context *ctxt) return new pass_phiopt (ctxt); } +unsigned int +pass_phiopt::execute (function *) +{ + bool do_hoist_loads = !early_p ? gate_hoist_loads () : false; + basic_block bb; + basic_block *bb_order; + unsigned n, i; + bool cfgchanged = false; + + calculate_dominance_info (CDI_DOMINATORS); + + /* Search every basic block for COND_EXPR we may be able to optimize. + + We walk the blocks in order that guarantees that a block with + a single predecessor is processed before the predecessor. + This ensures that we collapse inner ifs before visiting the + outer ones, and also that we do not try to visit a removed + block. */ + bb_order = single_pred_before_succ_order (); + n = n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS; + + for (i = 0; i < n; i++) + { + gphi *phi; + basic_block bb1, bb2; + edge e1, e2; + tree arg0, arg1; + bool diamond_p = false; + + bb = bb_order[i]; + + /* Check to see if the last statement is a GIMPLE_COND. */ + gcond *cond_stmt = safe_dyn_cast (*gsi_last_bb (bb)); + if (!cond_stmt) + continue; + + e1 = EDGE_SUCC (bb, 0); + bb1 = e1->dest; + e2 = EDGE_SUCC (bb, 1); + bb2 = e2->dest; + + /* We cannot do the optimization on abnormal edges. */ + if ((e1->flags & EDGE_ABNORMAL) != 0 + || (e2->flags & EDGE_ABNORMAL) != 0) + continue; + + /* If either bb1's succ or bb2 or bb2's succ is non NULL. */ + if (EDGE_COUNT (bb1->succs) == 0 + || EDGE_COUNT (bb2->succs) == 0) + continue; + + /* Find the bb which is the fall through to the other. */ + if (EDGE_SUCC (bb1, 0)->dest == bb2) + ; + else if (EDGE_SUCC (bb2, 0)->dest == bb1) + { + std::swap (bb1, bb2); + std::swap (e1, e2); + } + else if (EDGE_SUCC (bb1, 0)->dest == EDGE_SUCC (bb2, 0)->dest + && single_succ_p (bb2)) + { + diamond_p = true; + e2 = EDGE_SUCC (bb2, 0); + /* Make sure bb2 is just a fall through. */ + if ((e2->flags & EDGE_FALLTHRU) == 0) + continue; + } + else + continue; + + e1 = EDGE_SUCC (bb1, 0); + + /* Make sure that bb1 is just a fall through. */ + if (!single_succ_p (bb1) + || (e1->flags & EDGE_FALLTHRU) == 0) + continue; + + if (diamond_p) + { + basic_block bb3 = e1->dest; + + if (!single_pred_p (bb1) + || !single_pred_p (bb2)) + continue; + + if (do_hoist_loads + && !FLOAT_TYPE_P (TREE_TYPE (gimple_cond_lhs (cond_stmt))) + && EDGE_COUNT (bb->succs) == 2 + && EDGE_COUNT (bb3->preds) == 2 + /* If one edge or the other is dominant, a conditional move + is likely to perform worse than the well-predicted branch. */ + && !predictable_edge_p (EDGE_SUCC (bb, 0)) + && !predictable_edge_p (EDGE_SUCC (bb, 1))) + hoist_adjacent_loads (bb, bb1, bb2, bb3); + } + + gimple_stmt_iterator gsi; + bool candorest = true; + + /* Check that we're looking for nested phis. */ + basic_block merge = diamond_p ? EDGE_SUCC (bb2, 0)->dest : bb2; + gimple_seq phis = phi_nodes (merge); + + /* Value replacement can work with more than one PHI + so try that first. */ + if (!early_p && !diamond_p) + for (gsi = gsi_start (phis); !gsi_end_p (gsi); gsi_next (&gsi)) + { + phi = as_a (gsi_stmt (gsi)); + arg0 = gimple_phi_arg_def (phi, e1->dest_idx); + arg1 = gimple_phi_arg_def (phi, e2->dest_idx); + if (value_replacement (bb, bb1, e1, e2, phi, arg0, arg1) == 2) + { + candorest = false; + cfgchanged = true; + break; + } + } + + if (!candorest) + continue; + + phi = single_non_singleton_phi_for_edges (phis, e1, e2); + if (!phi) + continue; + + arg0 = gimple_phi_arg_def (phi, e1->dest_idx); + arg1 = gimple_phi_arg_def (phi, e2->dest_idx); + + /* Something is wrong if we cannot find the arguments in the PHI + node. */ + gcc_assert (arg0 != NULL_TREE && arg1 != NULL_TREE); + + gphi *newphi; + if (single_pred_p (bb1) + && !diamond_p + && (newphi = factor_out_conditional_conversion (e1, e2, phi, + arg0, arg1, + cond_stmt))) + { + phi = newphi; + /* factor_out_conditional_conversion may create a new PHI in + BB2 and eliminate an existing PHI in BB2. Recompute values + that may be affected by that change. */ + arg0 = gimple_phi_arg_def (phi, e1->dest_idx); + arg1 = gimple_phi_arg_def (phi, e2->dest_idx); + gcc_assert (arg0 != NULL_TREE && arg1 != NULL_TREE); + } + + /* Do the replacement of conditional if it can be done. */ + if (!early_p + && !diamond_p + && two_value_replacement (bb, bb1, e2, phi, arg0, arg1)) + cfgchanged = true; + 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 + && single_pred_p (bb1) + && cond_removal_in_builtin_zero_pattern (bb, bb1, e1, e2, + phi, arg0, arg1)) + cfgchanged = true; + else if (minmax_replacement (bb, bb1, bb2, e1, e2, phi, arg0, arg1, + diamond_p)) + cfgchanged = true; + else if (single_pred_p (bb1) + && !diamond_p + && spaceship_replacement (bb, bb1, e1, e2, phi, arg0, arg1)) + cfgchanged = true; + } + + free (bb_order); + + if (cfgchanged) + return TODO_cleanup_cfg; + return 0; +} + /* This pass tries to transform conditional stores into unconditional ones, enabling further simplifications with the simpler then and else blocks. In particular it replaces this: From patchwork Mon Apr 24 21:30:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 87167 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3016030vqo; Mon, 24 Apr 2023 14:32:12 -0700 (PDT) X-Google-Smtp-Source: AKy350YL3XykQRHW58p5Vzq/NvjbYtYZCFZ9hEcw6Mm204M3NnM/dCLoxk0YAixLuynZrmwgxyZM X-Received: by 2002:a17:906:697:b0:94e:d84e:d4d0 with SMTP id u23-20020a170906069700b0094ed84ed4d0mr10565371ejb.18.1682371932235; Mon, 24 Apr 2023 14:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682371932; cv=none; d=google.com; s=arc-20160816; b=v2UcqWqnnjPPAMUkt9zhrxa2jGFX+g3R+eUtcGF0VQvqJ6Sve0dCtglcUXnDziR4dW JJ5G94/GTP2PQikJ7cRWbJ3WmDWqcFhiTLIKzQkR9ZsEApremm7KRTfESbJNIUVnROQN 6svmTnyNP0NrogG+k+d6T10BRBQhFA8s8biPjPKZoEsEcbdtbOnVUVW2A07xgd+NvMPj 13VLwZdx+Ibz1fnTe9r1c7KMt9vwyr3vlZU9x+xHsyL6BRrGkkEKSUt1ipkhcXavswWj RjFayAGK/VnCKT+I6U1j9EduUKTxxXooNWIfJshaKv0r/jVjlt23Ye2PGPHWCSsAqwyU Ld0Q== 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=1+bXVC+q09JH7oRtxE4gneL2WXBF6yEFEkOiefvsVRc=; b=aaJuvVv6UkKGneXCx78vyscxoj1tR58v5MXA14f3s3gLv7dJkKIjlZPRAj0yVD59AK UP/wO/+owzIf4haaHKnbLs0t6Fr5XpDeAsSghT3nfVTeZeZ1diT2CjUgs0vzUu0/jxfd DFAoFIhSonwGVMGjdbrjpjFea+i7hbGHPfkBBOllYxU1aw7siKqYjDcJMBIdugNXPf0+ 5W5LntUG4ggIc7TtmHHMKfixl2SA7pMTA6pXmw7IjNK4dp2zQoBmiBSMGtz9kwvBoJ77 JUCZcVXqygyc3YBX5ePjYyqPUZCphnMNIixcy5x/RwKkRDqNvAfLx5QgGX6mqwNp7dCt J6Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NlMFesg5; 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 r15-20020a170906704f00b009537a538312si8582327ejj.28.2023.04.24.14.32.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 14:32:12 -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=NlMFesg5; 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 A9FDD3856963 for ; Mon, 24 Apr 2023 21:31:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9FDD3856963 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682371874; bh=1+bXVC+q09JH7oRtxE4gneL2WXBF6yEFEkOiefvsVRc=; 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=NlMFesg544xRq0ht/D1VcvnMEsQo90gYsoDqItBWP9hFwW7o3pjS76gIwOfv4VWFT 0kW4kfV2eHarr/1XQwTPmVCOAqr17XGyjpni2T8+KzYWxUiIUVcEZlffvp28DyM4JY H53ZtTXMqTQ1E6UImUSI35aLVoeRDFn4oG4MNM4o= 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 1EF3F3858D3C for ; Mon, 24 Apr 2023 21:30:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1EF3F3858D3C 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 33OGXiZw028418 for ; Mon, 24 Apr 2023 14:30:22 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q5nfb3jvs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 24 Apr 2023 14:30:22 -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.48; Mon, 24 Apr 2023 14:30:20 -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.48 via Frontend Transport; Mon, 24 Apr 2023 14:30:20 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 81EEA3F70A2; Mon, 24 Apr 2023 14:30:20 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 3/7] PHIOPT: Move store_elim_worker into pass_cselim::execute Date: Mon, 24 Apr 2023 14:30:07 -0700 Message-ID: <20230424213011.528181-4-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230424213011.528181-1-apinski@marvell.com> References: <20230424213011.528181-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: yKxdQ0pDmcFLNS2AkAvlvQZgRvD0eNpi X-Proofpoint-GUID: yKxdQ0pDmcFLNS2AkAvlvQZgRvD0eNpi 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-24_11,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?1764094831312783847?= X-GMAIL-MSGID: =?utf-8?q?1764094831312783847?= This simple patch moves the body of store_elim_worker direclty into pass_cselim::execute. Also removes unneeded prototypes too. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssa-phiopt.cc (cond_store_replacement): Remove prototype. (cond_if_else_store_replacement): Likewise. (get_non_trapping): Likewise. (store_elim_worker): Move into ... (pass_cselim::execute): This. --- gcc/tree-ssa-phiopt.cc | 250 ++++++++++++++++++++--------------------- 1 file changed, 119 insertions(+), 131 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index d232fd9b551..fb2d2c9fc1a 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -55,11 +55,6 @@ along with GCC; see the file COPYING3. If not see #include "tree-ssa-propagate.h" #include "tree-ssa-dce.h" -static bool cond_store_replacement (basic_block, basic_block, edge, edge, - hash_set *); -static bool cond_if_else_store_replacement (basic_block, basic_block, basic_block); -static hash_set * get_non_trapping (); - /* Return the singleton PHI in the SEQ of PHIs for edges E0 and E1. */ static gphi * @@ -87,130 +82,6 @@ single_non_singleton_phi_for_edges (gimple_seq seq, edge e0, edge e1) return phi; } -/* The core routine of conditional store replacement. */ -static unsigned int -store_elim_worker (void) -{ - basic_block bb; - basic_block *bb_order; - unsigned n, i; - bool cfgchanged = false; - hash_set *nontrap = 0; - - calculate_dominance_info (CDI_DOMINATORS); - - /* Calculate the set of non-trapping memory accesses. */ - nontrap = get_non_trapping (); - - /* Search every basic block for COND_EXPR we may be able to optimize. - - We walk the blocks in order that guarantees that a block with - a single predecessor is processed before the predecessor. - This ensures that we collapse inner ifs before visiting the - outer ones, and also that we do not try to visit a removed - block. */ - bb_order = single_pred_before_succ_order (); - n = n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS; - - for (i = 0; i < n; i++) - { - basic_block bb1, bb2; - edge e1, e2; - bool diamond_p = false; - - bb = bb_order[i]; - - /* Check to see if the last statement is a GIMPLE_COND. */ - gcond *cond_stmt = safe_dyn_cast (*gsi_last_bb (bb)); - if (!cond_stmt) - continue; - - e1 = EDGE_SUCC (bb, 0); - bb1 = e1->dest; - e2 = EDGE_SUCC (bb, 1); - bb2 = e2->dest; - - /* We cannot do the optimization on abnormal edges. */ - if ((e1->flags & EDGE_ABNORMAL) != 0 - || (e2->flags & EDGE_ABNORMAL) != 0) - continue; - - /* If either bb1's succ or bb2 or bb2's succ is non NULL. */ - if (EDGE_COUNT (bb1->succs) == 0 - || EDGE_COUNT (bb2->succs) == 0) - continue; - - /* Find the bb which is the fall through to the other. */ - if (EDGE_SUCC (bb1, 0)->dest == bb2) - ; - else if (EDGE_SUCC (bb2, 0)->dest == bb1) - { - std::swap (bb1, bb2); - std::swap (e1, e2); - } - else if (EDGE_SUCC (bb1, 0)->dest == EDGE_SUCC (bb2, 0)->dest - && single_succ_p (bb2)) - { - diamond_p = true; - e2 = EDGE_SUCC (bb2, 0); - /* Make sure bb2 is just a fall through. */ - if ((e2->flags & EDGE_FALLTHRU) == 0) - continue; - } - else - continue; - - e1 = EDGE_SUCC (bb1, 0); - - /* Make sure that bb1 is just a fall through. */ - if (!single_succ_p (bb1) - || (e1->flags & EDGE_FALLTHRU) == 0) - continue; - - if (diamond_p) - { - basic_block bb3 = e1->dest; - - /* Only handle sinking of store from 2 bbs only, - The middle bbs don't need to come from the - if always since we are sinking rather than - hoisting. */ - if (EDGE_COUNT (bb3->preds) != 2) - continue; - if (cond_if_else_store_replacement (bb1, bb2, bb3)) - cfgchanged = true; - continue; - } - - /* Also make sure that bb1 only have one predecessor and that it - is bb. */ - if (!single_pred_p (bb1) - || single_pred (bb1) != bb) - continue; - - /* bb1 is the middle block, bb2 the join block, bb the split block, - e1 the fallthrough edge from bb1 to bb2. We can't do the - optimization if the join block has more than two predecessors. */ - if (EDGE_COUNT (bb2->preds) > 2) - continue; - if (cond_store_replacement (bb1, bb2, e1, e2, nontrap)) - cfgchanged = true; - } - - free (bb_order); - - delete nontrap; - /* If the CFG has changed, we should cleanup the CFG. */ - if (cfgchanged) - { - /* In cond-store replacement we have added some loads on edges - and new VOPS (as we moved the store, and created a load). */ - gsi_commit_edge_inserts (); - return TODO_cleanup_cfg | TODO_update_ssa_only_virtuals; - } - return 0; -} - /* Replace PHI node element whose edge is E in block BB with variable NEW. Remove the edge from COND_BLOCK which does not lead to BB (COND_BLOCK is known to have two edges, one of which must reach BB). */ @@ -4403,13 +4274,130 @@ make_pass_cselim (gcc::context *ctxt) unsigned int pass_cselim::execute (function *) { - unsigned todo; + basic_block bb; + basic_block *bb_order; + unsigned n, i; + bool cfgchanged = false; + hash_set *nontrap = 0; + unsigned todo = 0; + /* ??? We are not interested in loop related info, but the following will create it, ICEing as we didn't init loops with pre-headers. An interfacing issue of find_data_references_in_bb. */ loop_optimizer_init (LOOPS_NORMAL); scev_initialize (); - todo = store_elim_worker (); + + calculate_dominance_info (CDI_DOMINATORS); + + /* Calculate the set of non-trapping memory accesses. */ + nontrap = get_non_trapping (); + + /* Search every basic block for COND_EXPR we may be able to optimize. + + We walk the blocks in order that guarantees that a block with + a single predecessor is processed before the predecessor. + This ensures that we collapse inner ifs before visiting the + outer ones, and also that we do not try to visit a removed + block. */ + bb_order = single_pred_before_succ_order (); + n = n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS; + + for (i = 0; i < n; i++) + { + basic_block bb1, bb2; + edge e1, e2; + bool diamond_p = false; + + bb = bb_order[i]; + + /* Check to see if the last statement is a GIMPLE_COND. */ + gcond *cond_stmt = safe_dyn_cast (*gsi_last_bb (bb)); + if (!cond_stmt) + continue; + + e1 = EDGE_SUCC (bb, 0); + bb1 = e1->dest; + e2 = EDGE_SUCC (bb, 1); + bb2 = e2->dest; + + /* We cannot do the optimization on abnormal edges. */ + if ((e1->flags & EDGE_ABNORMAL) != 0 + || (e2->flags & EDGE_ABNORMAL) != 0) + continue; + + /* If either bb1's succ or bb2 or bb2's succ is non NULL. */ + if (EDGE_COUNT (bb1->succs) == 0 + || EDGE_COUNT (bb2->succs) == 0) + continue; + + /* Find the bb which is the fall through to the other. */ + if (EDGE_SUCC (bb1, 0)->dest == bb2) + ; + else if (EDGE_SUCC (bb2, 0)->dest == bb1) + { + std::swap (bb1, bb2); + std::swap (e1, e2); + } + else if (EDGE_SUCC (bb1, 0)->dest == EDGE_SUCC (bb2, 0)->dest + && single_succ_p (bb2)) + { + diamond_p = true; + e2 = EDGE_SUCC (bb2, 0); + /* Make sure bb2 is just a fall through. */ + if ((e2->flags & EDGE_FALLTHRU) == 0) + continue; + } + else + continue; + + e1 = EDGE_SUCC (bb1, 0); + + /* Make sure that bb1 is just a fall through. */ + if (!single_succ_p (bb1) + || (e1->flags & EDGE_FALLTHRU) == 0) + continue; + + if (diamond_p) + { + basic_block bb3 = e1->dest; + + /* Only handle sinking of store from 2 bbs only, + The middle bbs don't need to come from the + if always since we are sinking rather than + hoisting. */ + if (EDGE_COUNT (bb3->preds) != 2) + continue; + if (cond_if_else_store_replacement (bb1, bb2, bb3)) + cfgchanged = true; + continue; + } + + /* Also make sure that bb1 only have one predecessor and that it + is bb. */ + if (!single_pred_p (bb1) + || single_pred (bb1) != bb) + continue; + + /* bb1 is the middle block, bb2 the join block, bb the split block, + e1 the fallthrough edge from bb1 to bb2. We can't do the + optimization if the join block has more than two predecessors. */ + if (EDGE_COUNT (bb2->preds) > 2) + continue; + if (cond_store_replacement (bb1, bb2, e1, e2, nontrap)) + cfgchanged = true; + } + + free (bb_order); + + delete nontrap; + /* If the CFG has changed, we should cleanup the CFG. */ + if (cfgchanged) + { + /* In cond-store replacement we have added some loads on edges + and new VOPS (as we moved the store, and created a load). */ + gsi_commit_edge_inserts (); + todo = TODO_cleanup_cfg | TODO_update_ssa_only_virtuals; + } scev_finalize (); loop_optimizer_finalize (); return todo; From patchwork Mon Apr 24 21:30:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 87166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3015934vqo; Mon, 24 Apr 2023 14:31:59 -0700 (PDT) X-Google-Smtp-Source: AKy350Y6H7GwoGDgsJbd7GkzmXPOj7qXqC77FbY2qjCV7YJRh2vHgNY/uFInmZBpzvQcTJQ3N/01 X-Received: by 2002:a05:6402:1614:b0:506:82b7:10c3 with SMTP id f20-20020a056402161400b0050682b710c3mr11953863edv.41.1682371919542; Mon, 24 Apr 2023 14:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682371919; cv=none; d=google.com; s=arc-20160816; b=YV05QRso7u8Yof7vz9J+pb0T0DedoLOQUqb81mYRkcy5X5FSQgfBWn7E3yC8LoFZHd uwNnfvZS+iGoii9PIIZ2xngMP80utlLqmKL4qinqE4rI7jsbGZNZ9Mhf+uLUxMGDdmB4 QfCN3QTtOo9Jj+VCGaTGmaF3QaZj6iGWn+QQp5nJCTRNUqHSiLxHqhhIov+v4fKeARm6 EBIVHiHEGC5zDdmidoAAWWR/P1eo1szOomCaSEskDCkt52ORC73gHpF3nxhmSxwj1GdI LoL+t0/2qvZbfhNuKAWzUrKTVO7+dEF7auva2tDz1dhhgDxnXuvjAO61vGB0Oe1lB92W Nj/g== 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=94wiAQZo024aniwILV77QAcfcAeJobhoSZFvpIPegy8=; b=0dyPFkxEtnGADTcizK9V0Ddmq4r0+dx78GKEXAFvL4uHUS4BzH8wRyBscoEvK3FGoc J0QI67KJqr2XG+r0G+GrWIPV0EKXhIlid7pIvVWv2YfNIfxfvAtfbonwkoMPVDU7V/Og 46c8L+tZOAvJlrOEYbuPnL4LiW9vps69hBVqcG4LmfWa+CAyHP0rHZjZWQrYJZ+x63sN yMsT3AcjPauESQdR8TwAYHI5NHF5OQ2Vv4tUb769LKMAGEXB/JqUMDxyIxWmNKrcZZvq A/52jh29pSDjNqaoCz3mU1J7ndceMFLT9g75GUwSwh5uikVktukeCnfPf1ksIzb2HTEU 4u6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kLSQJpBR; 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 b4-20020a05640202c400b0050506788181si8932813edx.139.2023.04.24.14.31.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 14:31:59 -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=kLSQJpBR; 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 15A813856DFC for ; Mon, 24 Apr 2023 21:31:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 15A813856DFC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682371870; bh=94wiAQZo024aniwILV77QAcfcAeJobhoSZFvpIPegy8=; 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=kLSQJpBRWL09DZUJbbn6cuajD7iuBwOYVD6sv58J+TD6d52Z3Op2shHm5HmhS5q8E 3m6agO6e4mueEkHVJzbc6oMD1q2rp5SwpQlYlPtajKPBqRKxDTxhJQwzsq3To8bqMv oSwrFYsgNwLPqq8sgPSoMDnkZdHm5YYQWeC7aZ1g= 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 2705F3858C83 for ; Mon, 24 Apr 2023 21:30:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2705F3858C83 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 33OGXiZx028418 for ; Mon, 24 Apr 2023 14:30:23 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q5nfb3jvs-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 24 Apr 2023 14:30:23 -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; Mon, 24 Apr 2023 14:30:21 -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; Mon, 24 Apr 2023 14:30:21 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id E5D293F70B3; Mon, 24 Apr 2023 14:30:20 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 4/7] MIN/MAX should be treated similar as comparisons for trapping Date: Mon, 24 Apr 2023 14:30:08 -0700 Message-ID: <20230424213011.528181-5-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230424213011.528181-1-apinski@marvell.com> References: <20230424213011.528181-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: bJiRkb7_o4-akgCKuQk1SOSfslCdzXOc X-Proofpoint-GUID: bJiRkb7_o4-akgCKuQk1SOSfslCdzXOc 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-24_11,2023-04-21_01,2023-02-09_01 X-Spam-Status: No, score=-14.5 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?1764094818072075636?= X-GMAIL-MSGID: =?utf-8?q?1764094818072075636?= While looking into moving optimizations from minmax_replacement in phiopt to match.pd, I Noticed that min/max were considered trapping even if -ffinite-math-only was being used. This changes those expressions to be similar as comparisons so that they are not considered trapping if -ffinite-math-only is on. OK? Bootstrapped and tested with no regressions on x86_64-linux-gnu. gcc/ChangeLog: * rtlanal.cc (may_trap_p_1): Treat SMIN/SMAX similar as COMPARISON. * tree-eh.cc (operation_could_trap_helper_p): Treate MIN_EXPR/MAX_EXPR similar as other comparisons. --- gcc/rtlanal.cc | 3 +++ gcc/tree-eh.cc | 3 +++ 2 files changed, 6 insertions(+) diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc index c96a88cebf1..b7948ecfad1 100644 --- a/gcc/rtlanal.cc +++ b/gcc/rtlanal.cc @@ -3204,6 +3204,9 @@ may_trap_p_1 (const_rtx x, unsigned flags) case LT: case LTGT: case COMPARE: + /* Treat min/max similar as comparisons. */ + case SMIN: + case SMAX: /* Some floating point comparisons may trap. */ if (!flag_trapping_math) break; diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc index 41cf57d2b30..dbaa27d95c5 100644 --- a/gcc/tree-eh.cc +++ b/gcc/tree-eh.cc @@ -2490,6 +2490,9 @@ operation_could_trap_helper_p (enum tree_code op, case GT_EXPR: case GE_EXPR: case LTGT_EXPR: + /* MIN/MAX similar as LT/LE/GT/GE. */ + case MIN_EXPR: + case MAX_EXPR: /* Some floating point comparisons may trap. */ return honor_nans; From patchwork Mon Apr 24 21:30:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 87169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3016684vqo; Mon, 24 Apr 2023 14:33:51 -0700 (PDT) X-Google-Smtp-Source: AKy350aPmdP7lNWelm7yFX1z7oHVATXBpXEZPXtpm3jU/emIeHA2LQpDWIiO50d8mfn8NTdp3mU+ X-Received: by 2002:a17:906:2e8f:b0:94e:fd61:8482 with SMTP id o15-20020a1709062e8f00b0094efd618482mr11789740eji.35.1682372031128; Mon, 24 Apr 2023 14:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682372031; cv=none; d=google.com; s=arc-20160816; b=OC+uJZMrx8bWmu+wZBlRcwhdCq//wAoMI3BPsuYgol64/Zz8XqGxt5UOLWR/3EqMeE z2HM0dtt1gJWE+Kv0MLU1SA2o3ckfqyPqQpX9j/ozsz+Yz/IyeRrdAJhveaFOOxAt/Pb U8/sQWcgOgz8bZRY05vTcztr+pLPFW1FwXeW+qpM4mcyTArqpr84d5F3PWcivrOHfNUv F5LYkfJzyG9+9M9l6zIXFtakBJpMECpVmKdLPH1kYELt17uAAYS7MJ5z64M+HEcYLCnK pM2EPDE50N3JP3iaX24IoaPA/EwuvxBrAVpeYRSPDkgrgKjD98LkpxpdnHx0JaDV3Wx8 I7rg== 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=QfwfrWDzxGU+gKIx5vlYer0NKaxbi8iE7VhxQtfmRrQ=; b=FQh7UpkzMpmiMDm6EPAe1R6rOw22+x7UoEGJAUhJGq6RjHsIH7csLi/bvHz09GsB/I 6FJr1IY7NlWCIP7+OfvU7+lUhG2+SfIPbcakOpYgzFAJ2CX836EdJ36a1y71medjoLM3 1JsgXEdSSfQ0PKwTxvAAoPPN4nS23tKoEynncizJUwaPMERDoH2M6pXVvmmNlkhrcebL G0GCRXlQ/Uu95OoPnr8GuywnACicK3h78u66abnWbeBHBO9CgL5ME9cjdsyugPVg6bjc fcZnUshr8r1qYmHCor+DaC3Rx0ogk6SYV2Hme+p0f4gDs+Q51ed+tdUm1beu+1KS8hwN mC3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BLagoUOU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id s5-20020a170906c30500b0094f38484c95si8001048ejz.171.2023.04.24.14.33.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 14:33:51 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BLagoUOU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 00787385B518 for ; Mon, 24 Apr 2023 21:32:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00787385B518 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682371929; bh=QfwfrWDzxGU+gKIx5vlYer0NKaxbi8iE7VhxQtfmRrQ=; 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=BLagoUOUS0VLAy40BQocBbhinpxYlGXK8eFL1o+GeYCkEJiRXDYtCwvWMvU1YhcY1 HVCytrxTMXpBXk1kGcsD7CDwS0/ang2/ub525AMrbAT5yUNlhLBzjj1D8DMWxe+thN QxV/kKziViNtAot4zT5yUKq0K0onfEiC88bPW93U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id E14283858D32 for ; Mon, 24 Apr 2023 21:30:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E14283858D32 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33OKnSI4010728 for ; Mon, 24 Apr 2023 14:30:25 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3q4f3p7pyj-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 24 Apr 2023 14:30:25 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 24 Apr 2023 14:30:21 -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; Mon, 24 Apr 2023 14:30:21 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 49A263F70B6; Mon, 24 Apr 2023 14:30:21 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 5/7] PHIOPT: Allow MIN/MAX to have up to 2 MIN/MAX expressions for early phiopt Date: Mon, 24 Apr 2023 14:30:09 -0700 Message-ID: <20230424213011.528181-6-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230424213011.528181-1-apinski@marvell.com> References: <20230424213011.528181-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: JXlWfd9yETdLjgvrSB1QGGjRlnlYMU5V X-Proofpoint-GUID: JXlWfd9yETdLjgvrSB1QGGjRlnlYMU5V 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-24_11,2023-04-21_01,2023-02-09_01 X-Spam-Status: No, score=-14.5 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?1764094934982502013?= X-GMAIL-MSGID: =?utf-8?q?1764094934982502013?= In the early PHIOPT mode, the original minmax_replacement, would replace a PHI node with up to 2 min/max expressions in some cases, this allows for that too. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssa-phiopt.cc (phiopt_early_allow): Allow for up to 2 min/max expressions in the sequence/match code. --- gcc/tree-ssa-phiopt.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index fb2d2c9fc1a..de1896aa91a 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -542,9 +542,23 @@ phiopt_early_allow (gimple_seq &seq, gimple_match_op &op) return false; tree_code code = (tree_code)op.code; - /* For non-empty sequence, only allow one statement. */ + /* For non-empty sequence, only allow one statement + except for MIN/MAX, allow max 2 statements, + each with MIN/MAX. */ if (!gimple_seq_empty_p (seq)) { + if (code == MIN_EXPR || code == MAX_EXPR) + { + if (!gimple_seq_singleton_p (seq)) + return false; + + gimple *stmt = gimple_seq_first_stmt (seq); + /* Only allow assignments. */ + if (!is_gimple_assign (stmt)) + return false; + code = gimple_assign_rhs_code (stmt); + return code == MIN_EXPR || code == MAX_EXPR; + } /* Check to make sure op was already a SSA_NAME. */ if (code != SSA_NAME) return false; From patchwork Mon Apr 24 21:30:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 87171 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3016826vqo; Mon, 24 Apr 2023 14:34:15 -0700 (PDT) X-Google-Smtp-Source: AKy350ZvocbsRLuDrisJ2vsDqCPvWlt5rEiQL6RBvIDc+W4UQljqb1CE4w2W9mVLqnTGclKw9nU+ X-Received: by 2002:aa7:db85:0:b0:506:983f:1f61 with SMTP id u5-20020aa7db85000000b00506983f1f61mr11445743edt.3.1682372055065; Mon, 24 Apr 2023 14:34:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682372055; cv=none; d=google.com; s=arc-20160816; b=LOKRLDfEyVrEgFRHWzk2T7t0Ir3/zVSb9kAJvUk6ZnJbTrKjGBuGjxR7+7hHNRX96H Bk8uw41S6s5QOBVaeOyVHAiM9GAjzKwDQKvOAMKxTtkFLVqwFkPmlIUfhrgKyEq9XGkm qr0ftczQGVxKmnZ3JAjeSqmxxnx74JkckPTACY0nJAhCOmlVEnxcqZF6/z+gIT6O9BmR t3CZEiuAGwdKLw3omi3G5TCgZt82E/Adtbq+KkAL+Cy+KHVA/Qr069rAjyYlo1bLi7cL PbY1zpZGs93YM7sbMgCKsZR2Sfuh04Wo3xGxDyNVkN8B+pUi5bQOmmrgc7TNsyLJepUc 8z6w== 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=z8504nwQnTFU43pLDIaRcZ8HHbxZLfh/WpXZQd8HX1o=; b=K2o3RW5STVwfCI0ZxUFtEc3Z96pQHC/hHjiw/2CMdWRdrPPZKZAxiT1xCUGyTOn33q hJklK6UEM51UuJmxoTYu2UgCXaN86q6eB9vXUsAVJ408uc8P4CrClByLFGSVPBZO4m8n h/IoNOPWIq01bs7yHBDvYLC9uTKUU1TCRtXCFbOLg6Buk90TZUu7pjKqZi3FZgc/7tAZ DeRpCz3gDhzAeCJnPO0HvzDp7cQfpCZs5HDB12GKmO0xhZ+LYpv0ThLQ3Y9MBvvQlAII ZAwfJafYMybuEKOdohRmw80yI3Ra4lbeFS3avGc/T+1oB0SfiR2crxNFnIltFF0oJAUW +7Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VcagIox+; 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 ba12-20020a0564021acc00b004fd298d2f99si8662302edb.492.2023.04.24.14.34.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 14:34:15 -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=VcagIox+; 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 1E1CB3881D18 for ; Mon, 24 Apr 2023 21:32:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E1CB3881D18 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682371943; bh=z8504nwQnTFU43pLDIaRcZ8HHbxZLfh/WpXZQd8HX1o=; 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=VcagIox+vVA6e+8DmDP/QJslNR9x/B9GkxTEYK4W1NqlNYJysxujyPBdS1wHbnUY4 KXrUUAqMmxnprjnEb9uO5aI1DbQdIMSa8wEdPek9SCiyyz4zz68w+d31kBohoTCT3K j1XRd5UAmdfo1XSYQFDUVRyJHcjOeuRsYKsW4oSY= 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 916BA3858C53 for ; Mon, 24 Apr 2023 21:30:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 916BA3858C53 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 33OGXia0028418 for ; Mon, 24 Apr 2023 14:30:23 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q5nfb3jvs-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 24 Apr 2023 14:30:23 -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.48; Mon, 24 Apr 2023 14:30:21 -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.48 via Frontend Transport; Mon, 24 Apr 2023 14:30:21 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id A19D33F70B5; Mon, 24 Apr 2023 14:30:21 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 6/7] MATCH: Factor out code that for min max detection with constants Date: Mon, 24 Apr 2023 14:30:10 -0700 Message-ID: <20230424213011.528181-7-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230424213011.528181-1-apinski@marvell.com> References: <20230424213011.528181-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Hb50ApMdqxH0VqNvu_vZmfv_vtZCAbcJ X-Proofpoint-GUID: Hb50ApMdqxH0VqNvu_vZmfv_vtZCAbcJ 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-24_11,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?1764094960218202254?= X-GMAIL-MSGID: =?utf-8?q?1764094960218202254?= This factors out some of the code from the min/max detection from match.pd into a function so it can be reused in other places. This is mainly used to detect the conversions of >= to > which causes the integer values to be changed by one. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * match.pd: Factor out the deciding the min/max from the "(cond (cmp (convert1? x) c1) (convert2? x) c2)" pattern to ... * fold-const.cc (minmax_from_comparison): this new function. * fold-const.h (minmax_from_comparison): New prototype. --- gcc/fold-const.cc | 43 +++++++++++++++++++++++++++++++++++++++++++ gcc/fold-const.h | 3 +++ gcc/match.pd | 29 +---------------------------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 3b397ae2941..b8add24f874 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -150,6 +150,49 @@ static tree fold_convert_const (enum tree_code, tree, tree); static tree fold_view_convert_expr (tree, tree); static tree fold_negate_expr (location_t, tree); +/* This is a helper function to detect min/max for some operands of COND_EXPR. + The form is "(EXP0 CMP EXP1) ? EXP2 : EXP3". */ +tree_code +minmax_from_comparison (tree_code cmp, tree exp0, tree exp1, tree exp2, tree exp3) +{ + enum tree_code code = ERROR_MARK; + + if (HONOR_NANS (exp0) || HONOR_SIGNED_ZEROS (exp0)) + return ERROR_MARK; + + if (!operand_equal_p (exp0, exp2)) + return ERROR_MARK; + + if (TREE_CODE (exp1) == INTEGER_CST && TREE_CODE (exp1) == INTEGER_CST + && wi::to_widest (exp1) == (wi::to_widest (exp3) - 1)) + { + /* X <= Y - 1 equals to X < Y. */ + if (cmp == LE_EXPR) + code = LT_EXPR; + /* X > Y - 1 equals to X >= Y. */ + if (cmp == GT_EXPR) + code = GE_EXPR; + } + if (TREE_CODE (exp3) == INTEGER_CST && TREE_CODE (exp1) == INTEGER_CST + && wi::to_widest (exp1) == (wi::to_widest (exp3) + 1)) + { + /* X < Y + 1 equals to X <= Y. */ + if (cmp == LT_EXPR) + code = LE_EXPR; + /* X >= Y + 1 equals to X > Y. */ + if (cmp == GE_EXPR) + code = GT_EXPR; + } + if (code != ERROR_MARK + || operand_equal_p (exp1, exp3)) + { + if (cmp == LT_EXPR || cmp == LE_EXPR) + code = MIN_EXPR; + if (cmp == GT_EXPR || cmp == GE_EXPR) + code = MAX_EXPR; + } + return code; +} /* Return EXPR_LOCATION of T if it is not UNKNOWN_LOCATION. Otherwise, return LOC. */ diff --git a/gcc/fold-const.h b/gcc/fold-const.h index 56ecaa87fc6..b828badc42f 100644 --- a/gcc/fold-const.h +++ b/gcc/fold-const.h @@ -246,6 +246,9 @@ extern tree fold_build_pointer_plus_hwi_loc (location_t loc, tree ptr, HOST_WIDE #define fold_build_pointer_plus_hwi(p,o) \ fold_build_pointer_plus_hwi_loc (UNKNOWN_LOCATION, p, o) +extern tree_code minmax_from_comparison (tree_code, tree, tree, + tree, tree); + /* In gimple-fold.cc. */ extern void clear_type_padding_in_mask (tree, unsigned char *); extern bool clear_padding_type_may_have_padding_p (tree); diff --git a/gcc/match.pd b/gcc/match.pd index e89ba57e30b..6d3aaf45a93 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4677,34 +4677,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) || TYPE_SIGN (c2_type) == TYPE_SIGN (from_type))))) { if (cmp != EQ_EXPR) - { - if (wi::to_widest (@3) == (wi::to_widest (@2) - 1)) - { - /* X <= Y - 1 equals to X < Y. */ - if (cmp == LE_EXPR) - code = LT_EXPR; - /* X > Y - 1 equals to X >= Y. */ - if (cmp == GT_EXPR) - code = GE_EXPR; - } - if (wi::to_widest (@3) == (wi::to_widest (@2) + 1)) - { - /* X < Y + 1 equals to X <= Y. */ - if (cmp == LT_EXPR) - code = LE_EXPR; - /* X >= Y + 1 equals to X > Y. */ - if (cmp == GE_EXPR) - code = GT_EXPR; - } - if (code != ERROR_MARK - || wi::to_widest (@2) == wi::to_widest (@3)) - { - if (cmp == LT_EXPR || cmp == LE_EXPR) - code = MIN_EXPR; - if (cmp == GT_EXPR || cmp == GE_EXPR) - code = MAX_EXPR; - } - } + code = minmax_from_comparison (cmp, @1, @3, @1, @2); /* Can do A == C1 ? A : C2 -> A == C1 ? C1 : C2? */ else if (int_fits_type_p (@3, from_type)) code = EQ_EXPR; From patchwork Mon Apr 24 21:30:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 87170 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3016701vqo; Mon, 24 Apr 2023 14:33:53 -0700 (PDT) X-Google-Smtp-Source: AKy350b+MeASnIX/1kUgyEV0hckCeertj0wVIOYTZmrLwRM+oS8DazcxeGUZzxn/FCqcJ6GQKE3d X-Received: by 2002:a05:6402:6c7:b0:504:9345:ffa4 with SMTP id n7-20020a05640206c700b005049345ffa4mr15961879edy.21.1682372033658; Mon, 24 Apr 2023 14:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682372033; cv=none; d=google.com; s=arc-20160816; b=KUJpZRp7ksRT5D4ykGEahEMolOPyOjBXwOu//FQatXqX4O9502LEdlOyyw2B/BdUqF fLcfS7SToSz/xDSlleiBGQNDvbh8qYVKmhA+BybcWvhFoljgDtBO+VWeszsM6YBLW/aL eK6AuMTxkKw0aT7YtMPXbDBiBgVfu9VNFu4rrKMb2lNh0vhcxhOl7GjVzbDsNJDlAJRB M0v5Bxp/Yekq5otJkmWx3Td8TG6xvj42JIAfsdthylv0RLJ6a16ZxWlz4iVhnTLmIHkr vmYRFClvZSDxzE/jdPvAhEnFP9aoWPVgPE/CIHDzWwfVLdE+2/WeG9TdyontMt/Kr1j2 RxnQ== 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=ec8Qtdi03cJEnO5uQmLPjDwo9NblaKltLkFBkOukIP8=; b=0cGm5tfANa6FQUhJQUjLT4VUGIVYKhqPvumVNsLEkLBR6lFyuJg0lPegx75PG6eVTz PnEpKkNFDVDWkC6g3J3GeG8Bu22bbGbhtOAyGE99/SLzdbYHrDQqULUZeoQdDxOWRONI HzFj1D6qa/sRKZ1HbLbrWI7ZN0zcpNrrZF1T9gAA1J2YUkY+k6keq33q1T1R/yWIcdE6 dB0SHVUmyKLMBKxCN/gJs9XEdtX5Bp1nk37vYUCZ03Ttvty6tkJipB1DBe0qjYMOlXby xJARuVs6P8RkURRw5/MT4t/2h2Jitrf0n54SdppvLLycZc1eGpIa8lpsIeoXXaCSXkc6 9ZVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EgkNCRON; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k14-20020aa7c38e000000b00506921654eesi8786668edq.368.2023.04.24.14.33.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 14:33:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EgkNCRON; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 422C33853549 for ; Mon, 24 Apr 2023 21:32:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 422C33853549 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682371930; bh=ec8Qtdi03cJEnO5uQmLPjDwo9NblaKltLkFBkOukIP8=; 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=EgkNCRONHrSyEsj0f/68JMgDCtf34N6HaChhP2l8VgLBFPnqHG8BJblmJvWCOoS0s SJ4u32JtLiadFPddDWav1JlT5Vo/7P7zuFlp4p8GLYwrDtDpg+jloh+TK0w1h1lFuC nFTqryjlwcPG9Ax96qYS76sA0lirDilBfjoyPhHY= 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 F29A83858C5F for ; Mon, 24 Apr 2023 21:30:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F29A83858C5F 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 33OGXia1028418 for ; Mon, 24 Apr 2023 14:30:24 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q5nfb3jvs-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 24 Apr 2023 14:30:23 -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; Mon, 24 Apr 2023 14:30:22 -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; Mon, 24 Apr 2023 14:30:22 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 0653D3F70A2; Mon, 24 Apr 2023 14:30:21 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 7/7] MATCH: Add patterns from phiopt's minmax_replacement Date: Mon, 24 Apr 2023 14:30:11 -0700 Message-ID: <20230424213011.528181-8-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230424213011.528181-1-apinski@marvell.com> References: <20230424213011.528181-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: P0SAbgIuzRrR-NZGC93vyo5vBfxWYGQx X-Proofpoint-GUID: P0SAbgIuzRrR-NZGC93vyo5vBfxWYGQx 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-24_11,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?1764094937890563280?= X-GMAIL-MSGID: =?utf-8?q?1764094937890563280?= This adds a few patterns from phiopt's minmax_replacement for (A CMP B) ? MIN/MAX : MIN/MAX . It is progress to remove minmax_replacement from phiopt. There are still some more cases dealing with constants on the edges (0/INT_MAX) to handle in match. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * match.pd: Add patterns for "(A CMP B) ? MIN/MAX : MIN/MAX ". gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/minmax-16.c: Update testcase slightly. * gcc.dg/tree-ssa/split-path-1.c: Also disable tree-loop-if-convert as that now does the combining. --- gcc/match.pd | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c | 10 ++++++++-- gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c | 3 ++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 6d3aaf45a93..5d5aae24509 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4843,6 +4843,22 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (convert @c0)))))))) #endif +/* These was part of minmax phiopt. */ +/* Optimize (a CMP b) ? minmax : minmax + to minmax, c> */ +(for minmax (min max) + (for cmp (lt le gt ge) + (simplify + (cond (cmp @1 @3) (minmax:c @1 @4) (minmax:c @2 @4)) + (with + { + tree_code code = minmax_from_comparison (cmp, @1, @2, @1, @3); + } + (if (code == MIN_EXPR) + (minmax (min @1 @2) @4) + (if (code == MAX_EXPR) + (minmax (max @1 @2) @4))))))) + /* X != C1 ? -X : C2 simplifies to -X when -C1 == C2. */ (simplify (cond (ne @0 INTEGER_CST@1) (negate@3 @0) INTEGER_CST@2) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c index 4febd092d83..623b12b3f74 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O -fdump-tree-phiopt -g" } */ +/* { dg-options "-O -fdump-tree-phiopt -fdump-tree-optimized -g" } */ #include @@ -25,5 +25,11 @@ main (void) return 0; } -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */ +/* After phiopt1, there really should be only 3 MIN_EXPR in the IR (including debug statements). + But the way phiopt does not cleanup the CFG all the time, the PHI might still reference the + alternative bb's moved statement. + Note in the end, we do dce the statement and other debug statements to end up with only 2 MIN_EXPR. + So check that too. */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 4 "phiopt1" } } */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "optimized" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c b/gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c index 902dde44a50..b670dee8d10 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c @@ -1,5 +1,6 @@ /* { dg-do run } */ -/* { dg-options "-O2 -fsplit-paths -fdump-tree-split-paths-details --param max-jump-thread-duplication-stmts=20 -fno-ssa-phiopt" } */ +/* Note both PHI-OPT and the loop if conversion pass converts the inner if to be branchless using min/max. */ +/* { dg-options "-O2 -fsplit-paths -fdump-tree-split-paths-details --param max-jump-thread-duplication-stmts=20 -fno-ssa-phiopt -fno-tree-loop-if-convert" } */ #include #include