From patchwork Wed May 3 02:30:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 89541 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1030611vqo; Tue, 2 May 2023 19:31:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6kxmZcz33ktP6PB5GK5ZF0mAu4p//gH7dvFj8nkejfbmwvGdlDcziUJ1Ukw+ldd8KUvdhy X-Received: by 2002:a17:906:99c5:b0:961:be96:b0e7 with SMTP id s5-20020a17090699c500b00961be96b0e7mr2087831ejn.48.1683081117160; Tue, 02 May 2023 19:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683081117; cv=none; d=google.com; s=arc-20160816; b=cdRsv+iZ63R0NlfW2B5ZIrmwcYT+LsVC5DLBsEYt/BEtLri0rZILTH//DmE3OZoCNl YxohMKYY3X6WFAJ0kpmHnfZY2njPz7dfQu5jiv3rTGT9T/L5bMYQ2kkQJVBhtGixTmnN SKPpOI1yCUDSsodsjMKgp2Zq0FjiYGxDeSS9iRjl2NKwMSxEGcnYWIu+wWB1TjD5nt6E PLHWrxq6NJ7HuNvpBDUvRPnFyOtOHYm0jakd1p12OeZTb0X+kWsaoLQ2ZI+qOQIRd8jD g/4zNKzTjL8raZwEfxbHLTFsSgR5SEooqHa7cI0+d0VWF/mcVbiJlTX0F7o6wD2wB9XG vQyg== 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:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=O50j+TpUcaqSjs/+ri252LL/PGSyZ0ccJbN1siGLheg=; b=BOnlA2/EaX64YdSWXB4KBZwm0j72v2nKV5Ts8lIJQMP4yoH2KgO2SmljsPaAfrsv5K 82xwwfk22v3pnC0an2kcXIAhlUUNdybw+0K933d3pFfcEn15Rau5jLhLMGCgjSUqMYkJ 9gg9KGdhxdNHHjkh8YL/IGMEt6jG4tZ5gJSTzBfe4m4D7EQBVopItq/gxTRWRkx3fHVX 7T4EohfG9BEo10nC/0O4Zyc3+dXodCeBYie6BRFelrmAiHHZ9dEif17PmNV6M3H68NgL k4nyXHbyJ6cv65XB5UcyeoQp1JnKYHcLENc9BxrIInWf1UBXC7xHCOYl+K17CAClQV+8 DAWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EqcCnOsR; 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 qp23-20020a170907207700b0094f4f2ba2acsi10544569ejb.593.2023.05.02.19.31.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 19:31:57 -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=EqcCnOsR; 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 966753857723 for ; Wed, 3 May 2023 02:31:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 966753857723 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683081107; bh=O50j+TpUcaqSjs/+ri252LL/PGSyZ0ccJbN1siGLheg=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=EqcCnOsR+Hc4HI+JAiQNWK+B1IBVfj2UpsHOA5FlFU9NtrNW5QwnW7Tau/fmI5eFA 8Z6XzsOO/rfyQQUKeQoRKA90PalOsr4d3yeEmG+z0oA40EpsS0Pm9Vmcdlkk8JFgaX /vgJqUMkqUeD4Bt7dN++l3gWfw2uLRem9ulkKXs4= 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 1D5323858D1E for ; Wed, 3 May 2023 02:31:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D5323858D1E 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 342NJinw006067 for ; Tue, 2 May 2023 19:31:02 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3q92rp2wvd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 02 May 2023 19:31:02 -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; Tue, 2 May 2023 19:31:00 -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; Tue, 2 May 2023 19:30:59 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id A63563F7074; Tue, 2 May 2023 19:30:59 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 1/2] Factor out copy_phi_args from gimple_duplicate_sese_tail and remove_forwarder_block. Date: Tue, 2 May 2023 19:30:49 -0700 Message-ID: <20230503023050.880728-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 2DK_ucGBncQhj34P5GdklGLmJuvDNIyG X-Proofpoint-GUID: 2DK_ucGBncQhj34P5GdklGLmJuvDNIyG 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-05-02_14,2023-04-27_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?1764838465278318166?= X-GMAIL-MSGID: =?utf-8?q?1764838465278318166?= While improving replace_phi_edge_with_variable for the diamond formed bb case, I needed a new function, copy_phi_args and then I went to search for similar code and noticed both gimple_duplicate_sese_tail and remove_forwarder_block have the same code I need. So I decided it would be best if I factor it out into a new function into a common area and call it from those two places (and will use it for phiopt too). OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-cfg.cc (copy_phi_args): New function (gimple_duplicate_sese_tail): Use it instead of doing it inline. * tree-cfg.h (copy_phi_args): New declaration. * tree-cfgcleanup.cc (remove_forwarder_block): Use copy_phi_args instead of implementing it inline. --- gcc/tree-cfg.cc | 29 ++++++++++++++++++----------- gcc/tree-cfg.h | 1 + gcc/tree-cfgcleanup.cc | 10 +--------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index 4927fc0a8d9..3f24d9c5b1c 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -6802,6 +6802,23 @@ bb_part_of_region_p (basic_block bb, basic_block* bbs, unsigned n_region) return false; } +/* For each PHI in BB, copy the PHI argument associated with SRC_E to TGT_E. */ + +void +copy_phi_args (basic_block bb, edge src_e, edge tgt_e) +{ + gphi_iterator gsi; + int src_indx = src_e->dest_idx; + + for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gphi *phi = gsi.phi (); + tree def = gimple_phi_arg_def (phi, src_indx); + location_t locus = gimple_phi_arg_location (phi, src_indx); + add_phi_arg (phi, unshare_expr (def), tgt_e, locus); + } +} + /* Duplicates REGION consisting of N_REGION blocks. The new blocks are stored to REGION_COPY in the same order in that they appear in REGION, if REGION_COPY is not NULL. ENTRY is the entry to @@ -6847,9 +6864,6 @@ gimple_duplicate_sese_tail (edge entry, edge exit, gimple_stmt_iterator gsi; edge sorig, snew; basic_block exit_bb; - gphi_iterator psi; - gphi *phi; - tree def; class loop *target, *aloop, *cloop; gcc_assert (EDGE_COUNT (exit->src->succs) == 2); @@ -6947,14 +6961,7 @@ gimple_duplicate_sese_tail (edge entry, edge exit, gcc_assert (single_succ_edge (region_copy[i])); e = redirect_edge_and_branch (single_succ_edge (region_copy[i]), exit_bb); PENDING_STMT (e) = NULL; - for (psi = gsi_start_phis (exit_bb); - !gsi_end_p (psi); - gsi_next (&psi)) - { - phi = psi.phi (); - def = PHI_ARG_DEF (phi, nexits[0]->dest_idx); - add_phi_arg (phi, def, e, gimple_phi_arg_location_from_edge (phi, e)); - } + copy_phi_args (exit_bb, nexits[0], e); } e = redirect_edge_and_branch (nexits[1], nexits[0]->dest); PENDING_STMT (e) = NULL; diff --git a/gcc/tree-cfg.h b/gcc/tree-cfg.h index 9b56a68fe9d..7ec3f812a76 100644 --- a/gcc/tree-cfg.h +++ b/gcc/tree-cfg.h @@ -113,6 +113,7 @@ extern basic_block gimple_switch_default_bb (function *, gswitch *); extern edge gimple_switch_edge (function *, gswitch *, unsigned); extern edge gimple_switch_default_edge (function *, gswitch *); extern bool cond_only_block_p (basic_block); +extern void copy_phi_args (basic_block, edge, edge); /* Return true if the LHS of a call should be removed. */ diff --git a/gcc/tree-cfgcleanup.cc b/gcc/tree-cfgcleanup.cc index 42b25312122..f3582e5ce52 100644 --- a/gcc/tree-cfgcleanup.cc +++ b/gcc/tree-cfgcleanup.cc @@ -612,15 +612,7 @@ remove_forwarder_block (basic_block bb) { /* Create arguments for the phi nodes, since the edge was not here before. */ - for (gphi_iterator psi = gsi_start_phis (dest); - !gsi_end_p (psi); - gsi_next (&psi)) - { - gphi *phi = psi.phi (); - location_t l = gimple_phi_arg_location_from_edge (phi, succ); - tree def = gimple_phi_arg_def (phi, succ->dest_idx); - add_phi_arg (phi, unshare_expr (def), s, l); - } + copy_phi_args (dest, succ, s); } } From patchwork Wed May 3 02:30:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 89542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1030627vqo; Tue, 2 May 2023 19:31:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7K14glONpv7o6aBXeZHO4RnwCEh2JBS04D31w2ftPKradF4EiCohZgWw0UaXLjjq9NY2Qk X-Received: by 2002:a17:907:805:b0:94f:cee:56f2 with SMTP id wv5-20020a170907080500b0094f0cee56f2mr1955282ejb.4.1683081119373; Tue, 02 May 2023 19:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683081119; cv=none; d=google.com; s=arc-20160816; b=LXZl3WwA/FRLBZM2oCr0gUIB1ZldtIOvURheePHvtCurKA22odxvn4LTSp6EapdSg+ xuMbbz/xUE8arInx5GcWTxv3a+Yaf8UKo1O1KXnjttpyK81UvfgjJVrZ7/2qvClMeJQs b1OOwpK/cxpVgTymLgujdExc2LCx8d+/wAdBWkK9Mr9QfrKsyrYm281tZ1hifdqBOqCQ fs7syKz9f5DtUMNo9aRNqvvx9UqpEoNyFwjmZskEEb8U46J/uZ2bvnVPCTEi+vBZ4yz6 eoxKgUvMYJx2vPQEBjiN6sUNj1vE+M18D1WqWQvJyHWYrtlCAiufyid8Plh4gB7ogwPu o1xg== 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=TY8bTDDLqUcp9Ad6A7QQcR1NHgohdlafpqlwnxg1Wh0=; b=NxsOJ4arZGRS0rTnEuoRUfqhXSL626V8bZ1k3gdnuE4k1kIyrulJWL9OFVLMCf6/gn zDnOvOLitOpDlAAKbUNG4Ce0kh9vu5N+ePkU248P3AQ9Utkrgv6fd1POicucOKi+PjFu MJeUtP14kp+wtpeU18UOkuR9hC6D8fCLiT3GRlLDYaJUofGPScVcOv+TVQ7Rd+xnfqip exDQXsEvQtiFfzNegT4ndidP38+xgdQaSUAijoO83rKjcR427Wk72cWnmryHiiZU8/1+ 085LKpRBK/OmxA3iyO8VgRbecSb0MhutLw4Upu8MoNSPeLeIC+2dIPqaTFCLqlj3cs7J +Y+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=n0TuhycW; 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 a10-20020a170906190a00b0094f731c1015si23126220eje.34.2023.05.02.19.31.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 19: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=n0TuhycW; 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 1503A385772D for ; Wed, 3 May 2023 02:31:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1503A385772D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683081109; bh=TY8bTDDLqUcp9Ad6A7QQcR1NHgohdlafpqlwnxg1Wh0=; 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=n0TuhycWWBbTR4ZNLrdID7C28kp7lXGZmJX7Fj9NZS3877IcRCWtBbQgQQsX+891w 4V3vtTaOfOlZpY/cS3MBKrJ3DmsdyLgE4uPclLfT1HptK9JkqmIJHZEf2Z5OVfbLVo 0pkTEI2DbRzhg74ecCMqhI8NjpcRKTb2YrBuJX60= 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 1E3163858D20 for ; Wed, 3 May 2023 02:31:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E3163858D20 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 342NJMU1005889 for ; Tue, 2 May 2023 19:31:02 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3q92rp2wve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 02 May 2023 19:31:02 -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; Tue, 2 May 2023 19:31:00 -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; Tue, 2 May 2023 19:31:00 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 1F2913F7075; Tue, 2 May 2023 19:31:00 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 2/2] PHIOPT: Improve replace_phi_edge_with_variable for diamond shapped bb Date: Tue, 2 May 2023 19:30:50 -0700 Message-ID: <20230503023050.880728-2-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230503023050.880728-1-apinski@marvell.com> References: <20230503023050.880728-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: zamfrcnt0TLW_T_9pzp11AHQ9hxPZDZ1 X-Proofpoint-GUID: zamfrcnt0TLW_T_9pzp11AHQ9hxPZDZ1 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-05-02_14,2023-04-27_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?1764838468142786482?= X-GMAIL-MSGID: =?utf-8?q?1764838468142786482?= While looking at differences between what minmax_replacement and match_simplify_replacement does. I noticed that they sometimes chose different edges to remove. I decided we should be able to do better and be able to remove both empty basic blocks in the case of match_simplify_replacement as that moves the statements. This also updates the testcases as now match_simplify_replacement will remove the unused MIN/MAX_EXPR and they were checking for those. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssa-phiopt.cc (replace_phi_edge_with_variable): Handle diamond form bb with forwarder only empty blocks better. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/minmax-15.c: Update test. * gcc.dg/tree-ssa/minmax-16.c: Update test. * gcc.dg/tree-ssa/minmax-3.c: Update test. * gcc.dg/tree-ssa/minmax-4.c: Update test. * gcc.dg/tree-ssa/minmax-5.c: Update test. * gcc.dg/tree-ssa/minmax-8.c: Update test. --- gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c | 3 ++- gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c | 9 +++---- gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c | 2 +- gcc/tree-ssa-phiopt.cc | 32 ++++++++++++++++++++++- 7 files changed, 40 insertions(+), 12 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c index 8a39871c938..6731f91e6c3 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c @@ -30,5 +30,6 @@ main (void) return 0; } -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */ +/* There should only be two MIN_EXPR left, the 3rd one was removed. */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c index 623b12b3f74..094364e6424 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c @@ -25,11 +25,8 @@ main (void) return 0; } -/* 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" } } */ +/* After phiopt1, will be only 2 MIN_EXPR in the IR (including debug statements). */ +/* xk will only have the final result so the extra debug info does not change anything. */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "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/minmax-3.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c index 2af10776346..521afe3e4d9 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c @@ -25,5 +25,5 @@ main (void) return 0; } -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c index 973f39bfed3..49e27185b5e 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c @@ -26,4 +26,4 @@ main (void) } /* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "phiopt1" } } */ -/* { dg-final { scan-tree-dump-times "MAX_EXPR" 3 "phiopt1" } } */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c index 34e4e720511..194c881cc98 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c @@ -25,5 +25,5 @@ main (void) return 0; } -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c index 0160e573fef..d5cb53145ea 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c @@ -26,4 +26,4 @@ main (void) } /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ -/* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "phiopt1" } } */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 37b98ef3c52..8905e6c4d21 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -94,6 +94,7 @@ replace_phi_edge_with_variable (basic_block cond_block, basic_block bb = gimple_bb (phi); gimple_stmt_iterator gsi; tree phi_result = PHI_RESULT (phi); + bool deleteboth = false; /* Duplicate range info if they are the only things setting the target PHI. This is needed as later on, the new_tree will be replacing @@ -137,7 +138,14 @@ replace_phi_edge_with_variable (basic_block cond_block, keep_edge = EDGE_SUCC (cond_block, 1); } else if ((keep_edge = find_edge (cond_block, e->src))) - ; + { + basic_block bb1 = EDGE_SUCC (cond_block, 0)->dest; + basic_block bb2 = EDGE_SUCC (cond_block, 1)->dest; + if (single_pred_p (bb1) && single_pred_p (bb2) + && single_succ_p (bb1) && single_succ_p (bb2) + && empty_block_p (bb1) && empty_block_p (bb2)) + deleteboth = true; + } else gcc_unreachable (); @@ -148,6 +156,28 @@ replace_phi_edge_with_variable (basic_block cond_block, e->probability = profile_probability::always (); delete_basic_block (edge_to_remove->dest); + /* Eliminate the COND_EXPR at the end of COND_BLOCK. */ + gsi = gsi_last_bb (cond_block); + gsi_remove (&gsi, true); + } + else if (deleteboth) + { + basic_block bb1 = EDGE_SUCC (cond_block, 0)->dest; + basic_block bb2 = EDGE_SUCC (cond_block, 1)->dest; + + edge newedge = redirect_edge_and_branch (keep_edge, bb); + /* no new edge should be the same. */ + gcc_assert (newedge == keep_edge); + keep_edge->flags |= EDGE_FALLTHRU; + keep_edge->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE); + keep_edge->probability = profile_probability::always (); + /* Copy the edge's phi entry from the old one */ + copy_phi_args(bb, e, keep_edge); + + /* Delete the old 2 empty basic blocks */ + delete_basic_block (bb1); + delete_basic_block (bb2); + /* Eliminate the COND_EXPR at the end of COND_BLOCK. */ gsi = gsi_last_bb (cond_block); gsi_remove (&gsi, true);