From patchwork Thu Aug 4 12:17:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 56538 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 153683857364 for ; Thu, 4 Aug 2022 12:18:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 153683857364 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1659615508; bh=Zb1K4SR/QK0Ooa1lLgeJzJ3FqCgQna6YzFOGtUBZwpo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=asXdX6/7J334mQFZLf9X+aV3+z7cYq1jT5aMsaVDbU8Fa6xiXNw/QDjBsRNO9iwRY 6AsAkbbjJozv1xgcu3IwgFU4BEgkYVm3upwtcTqaAJbrQgG2YuwK3HIIEsHKQsGhNT GWjtvWOVi1v7FinsDNolcyIkaBKj2uF9oJUy1zoA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00079.outbound.protection.outlook.com [40.107.0.79]) by sourceware.org (Postfix) with ESMTPS id 712323858407 for ; Thu, 4 Aug 2022 12:17:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 712323858407 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=ECSrXICW4h/95ob+zkWvC19Mgh1jSUAxq7sOpJLjvH7xvXYF+bL+P6YOGa0ESbbPp1ncV4Gpi2kyFX+Su/EuLWX/kCLGS2x37FGslNpWNllUx1GvgYREz2d0Xc8mxE91dOQ5CZ6ej6/+3Y5Frj040JCQDq9uVBvov3CdCNSZCr3YzNDqCXChiqlnz1XgNWsW3ZHPkz6AcSrD8MLe7LcXB3y7ImI4o+89s7s5ubdbXQkgrV5jegj+i5WdYdsAK5mMs4kg52l/nc0NnYRJ5noYsUNFjd8/3WYKkjrFawcOlFxynHQTlWtZBBmQyuLDp6VGhu9+W4ZJS5FUjEY8VrlLVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Zb1K4SR/QK0Ooa1lLgeJzJ3FqCgQna6YzFOGtUBZwpo=; b=gzzM/JN4+TKCMrtYNdmRvISmrfn9DWLR9McABCCJBpRE3xKn8d7J7aKEFUmma52NVThInVNzF134RI4/4kVD2pFJ0Tt6JfWPlHGP7ZzY9Bcm+kqWIZbhN8wWCBiyQA29svEHBh+N11Wk68zM1JOCZa/9w2HmlKr4/rdVjuThZADKY9WmwG2D+dN/M7vPFzGIUqSRL41Xmc5wWmzG+xHs8Pyaclj14CzBin2L0ihcqoXZ/nCcRVNEG9gaiR0MtFgQr0ktqrmPL6EZTg5H37z/Tgmqxxgaa3EJyXgplfiKGRNX7zLY/3hPfFCOeGxZCDD2LeuGk6wrmYQ80KN4w8cRMQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from FR0P281CA0008.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::13) by PAXPR08MB6864.eurprd08.prod.outlook.com (2603:10a6:102:132::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.14; Thu, 4 Aug 2022 12:17:49 +0000 Received: from VE1EUR03FT013.eop-EUR03.prod.protection.outlook.com (2603:10a6:d10:15:cafe::39) by FR0P281CA0008.outlook.office365.com (2603:10a6:d10:15::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.15 via Frontend Transport; Thu, 4 Aug 2022 12:17:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT013.mail.protection.outlook.com (10.152.19.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.12 via Frontend Transport; Thu, 4 Aug 2022 12:17:49 +0000 Received: ("Tessian outbound fa99bf31ee7d:v123"); Thu, 04 Aug 2022 12:17:48 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: dc3a8d664e7c586d X-CR-MTA-TID: 64aa7808 Received: from e78c2ee55c99.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F38C394E-5D6D-4132-A3BD-A6949CFE540F.1; Thu, 04 Aug 2022 12:17:42 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e78c2ee55c99.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 04 Aug 2022 12:17:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g34eyELkTZQAkj6vFgVJeTXKzOv1pIt8GjCM0HZ/vKPUSjAFBIK23YnsLTeSGxTu6I8Ep6MR5xFZdPikI2VLAvbFZZIKZz0mUHY/RugsNoGV9z+Xwq61OyA/MglComcQIpY8j/8EFOHWeXepwcub9Yxyxi7Z7i0VZhxKU6dv9VBuMZaZgGCEYX+hrRwjNXTv9I6mWlZ78v8NNfISf0yf567eS14JV66FyS7cfSQmVtdIiIg3Kx415+0KPxg4XTQcTOZV9DYgeqryPLZYuVBDmlPEjVtX50eMWrOvsNiGStqDcbSj8G+w+b+zwchT1y8rUK9rjnIAaPBrxsC8rigdvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Zb1K4SR/QK0Ooa1lLgeJzJ3FqCgQna6YzFOGtUBZwpo=; b=CHyy+mjE2KK5GTG5QJZPSNu+z6p6q6rKV8k6wwv+CMBiCBhmk134dyLXsxGBYbBoAziuAZwTvhoDHs2OZYiTsgcQaJsjppLbuFMdbrjTfNRO6qzRnOAlHvuPD9LWaid2R99VuO/Eth0tW2a1C0cTxlMw6CrF4imTa35f40db4KEWWgMEc5B0vOz4M/byMamw3GOJBZVyW3cjAsLKWcmLZqcftZmIFlQqIa89WpSZukv+4VvYhjTzi76DumHh1684vED1M5yWE55vcUXfWMlxE7tG2t5wPg0jXOJ6iPk5365tK4UbgNp34tAqS/9y6Ut4OJgaUrPP6776d/Ccp6d6Rw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) by DBAPR08MB5655.eurprd08.prod.outlook.com (2603:10a6:10:1ab::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.13; Thu, 4 Aug 2022 12:17:40 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::3858:80b1:39b:1584]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::3858:80b1:39b:1584%7]) with mapi id 15.20.5504.014; Thu, 4 Aug 2022 12:17:39 +0000 Date: Thu, 4 Aug 2022 13:17:32 +0100 To: gcc-patches@gcc.gnu.org Subject: [PATCH]middle-end: Fix phi-ssa assertion triggers. [PR106519] Message-ID: Content-Disposition: inline X-ClientProxiedBy: SN7P222CA0008.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::12) To VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 22bf97de-c2a1-4046-29a0-08da761358e7 X-MS-TrafficTypeDiagnostic: DBAPR08MB5655:EE_|VE1EUR03FT013:EE_|PAXPR08MB6864:EE_ x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: m/a5dtar/BADr3INUvA8GmL0AqnYbv4Zd4UrTblyHasnJHbAzlz/NYkHoZShpOMb09QPDyr7qvmr7B3LMpSf43z/7cktEaF91ckeRULmmkUka1xcgby6UXqEFAtm55uExhyJKQOXWUvzhBA/FfRneg9lrvXXALW1h8mCGZzD0MBWBudJt1PupJsse3yI9lELhsaWE47bJL4tJ1b7gqAAoSNzL5Ns+R2nmvFWyB6nn5KLg2+HRpmXYIwWo4xqGgRW957IzJNYCTTQRl8bZAErpD7rIV11b7metvwnQRQTOlXuK/oAF9Bo74EhtyIsjtVJ6LiOEP3jjfmiXEy6tdxfulSyb69C65yV7nh/9PMLA5e1q+YD72grYNfTfPZ4+Xqp7GH2SJAwRbfjOvzZ6QFTwAWGHYeyNoxD0u6S72o2eDisFKbxOYft3IPk/zEBZVWOwk7cwTFSIBtz8WWHYC6MUhjBwaqIIa+Bv6M+3FAdYPPlD73RTaqkF2qZyMc9QVRZFQyvc4t2gGsZnKMj9bXBIUqnEhFBkrg2AUSls7RHndmArnzNKYLh1MGQl6USmAdqicMoqnPoP5O/EcflHo3bESueJRCcslFOklxPZZlq5CRb50uOhykyNuWRiowl7AJcPMS4yGdV5dDF5lcVKxBSYQ9G8NuPfhdsRtPUmrZnbOQ2SVSvP5K5DujiWa3M3GQG02VAiSzW1pw0pbl9UylwZ+4W2Tkx8urZcRgza1PbR8hDxUmqNKJZMpIl8ZT7ypE+QK5la0M1lC/wKpOcXaF/impgu9dTDpMGIUVyDVM0d3VQAiStIHsKZfD0+chrVOgp6mutLUM5R2udxbKhckJRRQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB5325.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(39860400002)(396003)(136003)(346002)(366004)(376002)(6916009)(36756003)(83380400001)(38100700002)(316002)(8936002)(41300700001)(478600001)(6486002)(2906002)(6666004)(186003)(84970400001)(2616005)(66946007)(66556008)(4326008)(66476007)(8676002)(33964004)(6506007)(44144004)(6512007)(235185007)(44832011)(26005)(86362001)(5660300002)(4216001)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5655 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT013.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 4048465b-8d2a-4367-a156-08da76135316 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5mrF/D5OrfnXJFG7HGcKpg35D0T8wzMmmQtBxlnJTalqx0rvEetj05YQTLq0I541T1TDXi5fBmvZIyx9pWm6Ix6HMzzLM+5se1e6qrcn5IjNwK15rCpia1KqlZuYpWg4msooVpP71+xwsY19GpanFa4M+oNn6gEolbXPOW8UUEzQE7NJvJRg2433OymdEIzLsgrPTvOETNsqEpg+l08D60/cjqFvL3qoNVTwV8wgF4T/tk67p+0yjuowx3XPQGu5SNbH2ceNv6dwzgAPWRy35KAS7QhpjbRifTQ7cIc3oFu5BSLhc6cgfrsJhPS2eKtJCEodt2WEI7w7y72olL1Mkxk/nI2D+r0WPgpFsU06Ykdew9YUBwINfTCGWIg5A0Mv5tGPg/9E/QIQCykzXqvMBD/yyyNUoHUmStNr2eR4bu965haCftDoZsb2g6joeHTwYUCbmpUbxZc6Y6dIX5/lrrM65CsKW4n6ty4CvDUBJ5cUpluqofHiFhgtZp1/iLmB52/KeDPqUBe6uYlZuKB2cAnqJbR/Tu+eyCm6kGoI1V+mONvVTnU7fYW8Fby3E/VH5kfm34MgywonntrDrW/iImStwAiWVrEc298tnRj80UwwNfuSp++B8L48a02tFs1BwIULnn8t+Uf7oOkJm6hVdsikm1/kYi+U67nGmhvL8Jj7GLEmpWK1TDxAj6ZYsRlWhBIYS6prVtTb04tJ7U3Yh+EcEicrPDVOfYCKctl18KlTXAVZZIKM39vA2XV4qg6osIl+SbJyv1kW83js/LFl7ySEL9cj3k8jKO6D/6yV/N9+78tzhPsyfedVqI7qF/Op760SDwNgv33qF9KjPy9ajpJAeYeKTtDvCXo04r7B4/D8rNE7HqrdFNPRcJxymQ+M X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230016)(4636009)(136003)(346002)(396003)(39860400002)(376002)(40470700004)(36840700001)(46966006)(36756003)(235185007)(82310400005)(36860700001)(86362001)(44832011)(316002)(6916009)(6486002)(5660300002)(70586007)(8676002)(4326008)(478600001)(70206006)(8936002)(107886003)(33964004)(44144004)(2616005)(6506007)(2906002)(186003)(84970400001)(41300700001)(47076005)(40460700003)(26005)(336012)(6666004)(356005)(81166007)(40480700001)(83380400001)(82740400003)(6512007)(4216001)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2022 12:17:49.2784 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22bf97de-c2a1-4046-29a0-08da761358e7 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT013.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6864 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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: Tamar Christina via Gcc-patches From: Tamar Christina Reply-To: Tamar Christina Cc: nd@arm.com, rguenther@suse.de Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi All, The failures on -m32 on x86 show that the checks at the top level in tree_ssa_phiopt_worker aren't enough for diamond_p. In minmax_replacement we perform the additional validation of the shape but by then it's too late to catch these case. This patch changes it so we check that for a diamond shape we check that the edges we're operation on must result in the same destination BB. We also enforce that for a diamond the middle BBs must have a single successor, this is because the remainder of the code always follows EDGE_SUCC 0. If there are more than 1 successor then the edge we follow could be not part of the diamond so just reject it early on. I also remove the assert after the use of gimple_phi_arg_def as this function can't return NULL. if the index is out of range it already breaks on an assert inside the gimple_phi_arg_def, so we never hit this assert. Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu and no issues. Ok for master? Thanks, Tamar gcc/ChangeLog: PR middle-end/106519 * tree-ssa-phiopt.cc (tree_ssa_phiopt_worker): Check final phi edge for diamond shapes. gcc/testsuite/ChangeLog: PR middle-end/106519 * gcc.dg/pr106519.c: New test. --- inline copy of patch -- diff --git a/gcc/testsuite/gcc.dg/pr106519.c b/gcc/testsuite/gcc.dg/pr106519.c new file mode 100644 index 0000000000000000000000000000000000000000..3d4662d8a02c6501560abb71ac53320f093620d8 --- diff --git a/gcc/testsuite/gcc.dg/pr106519.c b/gcc/testsuite/gcc.dg/pr106519.c new file mode 100644 index 0000000000000000000000000000000000000000..3d4662d8a02c6501560abb71ac53320f093620d8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr106519.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ + +int bytestart, bytemem_0_0, modlookup_l_p; + +void +modlookup_l() { + long j; + while (modlookup_l_p) + while (bytestart && j && bytemem_0_0) + j = j + 1; +} diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index a8e55e040649e17f83a2fc3340e368cf9c4c5e70..1c4942b5b5c18732a8b18789c04e2685437404dd 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -268,7 +268,8 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) continue; } else if (EDGE_SUCC (bb1, 0)->dest == EDGE_SUCC (bb2, 0)->dest - && !empty_block_p (bb1)) + && !empty_block_p (bb1) + && single_succ_p (bb1) && single_succ_p (bb2)) diamond_p = true; else continue; @@ -311,6 +312,12 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) for (gsi = gsi_start (phis); !gsi_end_p (gsi); gsi_next (&gsi)) { phi = as_a (gsi_stmt (gsi)); + + /* A diamond must continue to the same destination node, otherwise + by definition it's not a diamond. */ + if (diamond_p && e1->dest != e2->dest) + continue; + 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) @@ -329,12 +336,15 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) if (!phi) continue; - arg0 = gimple_phi_arg_def (phi, e1->dest_idx); - arg1 = gimple_phi_arg_def (phi, e2->dest_idx); + /* A diamond must continue to the same destination node, otherwise + by definition it's not a diamond. */ + if (diamond_p && e1->dest != e2->dest) + continue; /* Something is wrong if we cannot find the arguments in the PHI node. */ - gcc_assert (arg0 != NULL_TREE && arg1 != NULL_TREE); + arg0 = gimple_phi_arg_def (phi, e1->dest_idx); + arg1 = gimple_phi_arg_def (phi, e2->dest_idx); gphi *newphi; if (single_pred_p (bb1) --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr106519.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ + +int bytestart, bytemem_0_0, modlookup_l_p; + +void +modlookup_l() { + long j; + while (modlookup_l_p) + while (bytestart && j && bytemem_0_0) + j = j + 1; +} diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index a8e55e040649e17f83a2fc3340e368cf9c4c5e70..1c4942b5b5c18732a8b18789c04e2685437404dd 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -268,7 +268,8 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) continue; } else if (EDGE_SUCC (bb1, 0)->dest == EDGE_SUCC (bb2, 0)->dest - && !empty_block_p (bb1)) + && !empty_block_p (bb1) + && single_succ_p (bb1) && single_succ_p (bb2)) diamond_p = true; else continue; @@ -311,6 +312,12 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) for (gsi = gsi_start (phis); !gsi_end_p (gsi); gsi_next (&gsi)) { phi = as_a (gsi_stmt (gsi)); + + /* A diamond must continue to the same destination node, otherwise + by definition it's not a diamond. */ + if (diamond_p && e1->dest != e2->dest) + continue; + 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) @@ -329,12 +336,15 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) if (!phi) continue; - arg0 = gimple_phi_arg_def (phi, e1->dest_idx); - arg1 = gimple_phi_arg_def (phi, e2->dest_idx); + /* A diamond must continue to the same destination node, otherwise + by definition it's not a diamond. */ + if (diamond_p && e1->dest != e2->dest) + continue; /* Something is wrong if we cannot find the arguments in the PHI node. */ - gcc_assert (arg0 != NULL_TREE && arg1 != NULL_TREE); + arg0 = gimple_phi_arg_def (phi, e1->dest_idx); + arg1 = gimple_phi_arg_def (phi, e2->dest_idx); gphi *newphi; if (single_pred_p (bb1)