From patchwork Fri Feb 23 17:53:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 1903606 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=isIwWT1l; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=isIwWT1l; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ThHgr2jGmz23f7 for ; Sat, 24 Feb 2024 04:54:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 33EB83858C66 for ; Fri, 23 Feb 2024 17:53:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2066.outbound.protection.outlook.com [40.107.21.66]) by sourceware.org (Postfix) with ESMTPS id 892A53858282 for ; Fri, 23 Feb 2024 17:53:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 892A53858282 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 892A53858282 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.21.66 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1708710815; cv=pass; b=DDY1WOSViVC+JmmEZcbG5kDKVx0WxLjaCq6tgnr15Nt3IBbWS3m0mgvVCauyGjN1uexKXYJLKemjfF5rcoKoK2F5ETGvubWNUVxZc4K1TrdHPDtsM+jhf4ky3n08xRhBGhUuydzIqQilTEZAzvxDPmVPvDpYsTBi1+SgOxaBSiw= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1708710815; c=relaxed/simple; bh=fx9XanSLSUVnMfaCaG82wInFk+PTCzV01VItBtmzguM=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=WyTzSJim0km751qjok54/CEBvUqP/GpmyxG96vi56VI2O+gH+FsPrCPDOI4UPuLemzUF3FObBpvdLV24g6VJ52nUmslF90MIsoMcQN+fGRSQUmeFo1EYmP/GODButrckn0y4ok1PVify46kcCmIoDADZaxpugUTM9UegrFTgu1E= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=RK1cN9hkGfgwYCidZxtMV7/qbsbm+IEcYXmbTR6V0V59NtmXhgjp6uaySBJSU61HTustyc5VTwpCU2N6FF40UlhCRW8cPFiJP3tmEw0y7/+JZlqkCXCXNagOCeTSovFCga55/PQhqDvWIUVhXQ1RiktJGOsxtpqhxgq1boDosdM7pSjf3uEy1cT9af9DV1EM07//Uc9qwm6XROvM8SeOvr/z4nqcthahiljpjSyGC5H8iFwDAuy/rFdaEU2flcyE41KjyG9OWpIFjlwdZFCabsTJOg5OQaWdIMCBwPA/NGazu8CL1zxKEuE46qfb5XT8Wo3WFJ1MPRSRq4Xack8OTA== 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=w5UNJGwf9Q2hMtOljQfJ8n525CxeqXPvf0o2Vkt+TnY=; b=jiOZApH4rRQfTfvDD9/FRKQh317Zf6hSoECVhd1t8LlcXVbujNV6tyv/2SGM4LGtgnx8IW/CrcVhfwrDPURU7URyX3ezPWHauY+bQFmMMdZMhFVPk0MuPoGPDz6hIoqKkJbcnzCg1jf2gWXKQWjKy7LIJXxZTUQqO1oeqKekD8foTL3tyCW0cjnYMUrJGfq1rYPYzAsBEG88BHM2IZI+YQapBNTGLWVg1fFwU8TzG7wSUxef3GZq7KKJlG0xZTQhWwMLiR0mRvYgAeVzNq9hqMSY6DSVRR/s99Ti66nOwYjtRZ7MfNNknwdKmk03wBa4A7VQA9oHJnsyOtptnKrnEg== 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]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w5UNJGwf9Q2hMtOljQfJ8n525CxeqXPvf0o2Vkt+TnY=; b=isIwWT1l2QBWbo40ipdEFSfDxbJpp7lFZCf4Bc/hzub8d7mVVsZLf4Nzn4ljn1YPzEx7JKoRA7jT7QRfywOXLiiWLkmju6el/US6DV23wVxQ9gMLBwtBlXlra01lVE4PcNtV+vuCOBwUHDQF0oaVGB2G48RgDavrqCybaiQAK4U= Received: from AS4P191CA0030.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:5d9::16) by PA6PR08MB10595.eurprd08.prod.outlook.com (2603:10a6:102:3d1::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.24; Fri, 23 Feb 2024 17:53:29 +0000 Received: from AM4PEPF00025F9A.EURPRD83.prod.outlook.com (2603:10a6:20b:5d9:cafe::db) by AS4P191CA0030.outlook.office365.com (2603:10a6:20b:5d9::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.43 via Frontend Transport; Fri, 23 Feb 2024 17:53:28 +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 AM4PEPF00025F9A.mail.protection.outlook.com (10.167.16.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.0 via Frontend Transport; Fri, 23 Feb 2024 17:53:28 +0000 Received: ("Tessian outbound 778f5fac34db:v228"); Fri, 23 Feb 2024 17:53:28 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e3c6a9f369c88b5f X-CR-MTA-TID: 64aa7808 Received: from b65f6823ba7d.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9BB0CB2C-AE86-4E0D-AEBB-EEAF75CDB711.1; Fri, 23 Feb 2024 17:53:20 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b65f6823ba7d.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 23 Feb 2024 17:53:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HLJeXrcFOQjLEWFRrXTSUiR6HDVC88HwZWVOI02rj8hRxXsvv5URdjH/z/49NdkVcwRl9rDEs4S+vqM6qN7fE8XQN4RH0cOMh/1VgSrOfznR8FWeUrgFjGxuJYLOSJi1oPtaKRzfDX8QTcZM/8GLX3qqWU+Fthf9yTN90BCiu+xyaMM2sIfXQGjelspEweig6XgOqb8Mrc8+75EWCFseNu9Hf5rYYu2Cw4Nz75592yehxDWCc79RHN2xZdTS+BRJZceUPg8NoULX2crEg07qGUesz3ZETRaDpUm9uMSmuuo/W7IMCi6LI6FP76ixJNloBv8/SQCeX7ZAWKG6+BnX3g== 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=w5UNJGwf9Q2hMtOljQfJ8n525CxeqXPvf0o2Vkt+TnY=; b=e8rrFlJwT+KfkbB3rMo00CNsxhyEouyKp1aZsg0THDonv00mnA+NF00FFWL7lJG8HcTELqk2GqNfBNICPRSVViJO0B4zk3RwZVgrmmJdAxRcZaVMfhhSB1xCYJTSe3nkIVGPF3Tvr9c7gucs3lqar3b91wloRsX2qPIbMaP8YtJUeSoPDRc9JLG+TxO3E/7zwXPaELOwuPPkC58lwb9FtTgqEx8fwQ3woIMH4lMa5YXXt42M5ShH6FqH4oBvbwqT9PtlSEaBjNH42cvictrgHTmHCbL3hCg66psZ8zctJ0t4H6JLeiqG9LJviNi0OE4giBkRSWduIgDCX4Ap9v1yHA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w5UNJGwf9Q2hMtOljQfJ8n525CxeqXPvf0o2Vkt+TnY=; b=isIwWT1l2QBWbo40ipdEFSfDxbJpp7lFZCf4Bc/hzub8d7mVVsZLf4Nzn4ljn1YPzEx7JKoRA7jT7QRfywOXLiiWLkmju6el/US6DV23wVxQ9gMLBwtBlXlra01lVE4PcNtV+vuCOBwUHDQF0oaVGB2G48RgDavrqCybaiQAK4U= 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 AM8PR08MB5571.eurprd08.prod.outlook.com (2603:10a6:20b:1d0::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.24; Fri, 23 Feb 2024 17:53:16 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::810c:8495:3f0a:ef8]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::810c:8495:3f0a:ef8%7]) with mapi id 15.20.7316.023; Fri, 23 Feb 2024 17:53:16 +0000 Date: Fri, 23 Feb 2024 17:53:12 +0000 From: Tamar Christina To: gcc-patches@gcc.gnu.org Cc: nd@arm.com, rguenther@suse.de, jlaw@ventanamicro.com Subject: [PATCH]middle-end: update vuses out of loop which use a vdef that's moved [PR114068] Message-ID: Content-Disposition: inline X-ClientProxiedBy: LO4P123CA0386.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18f::13) To VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB5325:EE_|AM8PR08MB5571:EE_|AM4PEPF00025F9A:EE_|PA6PR08MB10595:EE_ X-MS-Office365-Filtering-Correlation-Id: 8020352c-773a-4de1-30db-08dc34985762 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: v3cZr32Mpbb39L4Xc14facS95EvAzhLbgEuOu45imsksz2zGculV7a8vBkR321GgFYDt7h2Le1mqxFsXecjhfwPe3qZJm1e4n1SPZ9n8GTFD3UhjlEEdIbEFO6r6m5sKR7yNStmWrcLi9jkFJC3o+o1MwqolWFs89zTYRcmVo+jke3DicjCUWjsMmBi3X0WPPEtojVQNNOIpThJ2UEioDagvM29nAEy3dpFctQ7Fo9nDiZoeA6g/ThekFYKWODSwp693g/sjaU3K1GxrGDxmsu8DIdOo7QwaO49EzT0YrtmbI1OsxiNwdZxohgGOaC6NclYCTWbTNV7o6HXBxGfewD0QJa7mDpicDrGZ+8Kw135M8PORYc0L5dKIH/xvETV82Z1JD7I8rrKJCuYJZIexzUzWiedBSLSzH1EETDFDfMeY3rLBvMiVhtDTHCk/FFz4KTuJ86YsNROg5EbAppZ5gcFh/J7vofgh9KAfn1ikxQ4xd/XdFRjYLY3iHHDBI0rSZw+KFf0mnCdbnSTv6hJIjA== 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:(13230031); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5571 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: AM4PEPF00025F9A.EURPRD83.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: be7d89b5-8623-4a4c-5397-08dc34985043 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s5CAhSqbJjOqnq4+gaQUeZmGbp0USXSXg+AVy34JxruUjC8+gIOX7JRzWKTJ5gqdhOsI09h2Dciosu/TeoQA9uNfOJ4kiN5Zr19knsNuqYdfOrxo2f8Tv05SEneMqreV+t+1PXAJUGDxcayoNY+w9xV8DxrRdvJ9S7KAadMWRvBVrFcOL7poAB9FqIUCbkG7NjWa7KPR1UFXjgdhLz77raqbJfFFIc7/wx7wPiSv1JlusXzVE4r8fSV+vBXGYzy2GxWWq9VrGrqJmsnRn+UFsNGNuh0f6tNvGsghGnYYPm8PjDX2gWPwwoV+uKr1pJRFyKi0LSvioI4LzAJjWG2C96DHkYiTdpbvw7YJy9aVW/O5yXLkj1gq1yS7SZmgNiz+L3tZCSBTa6bVd8VhziXO9FFTJkpOm6IEwYmLrfxp6MqMC49AzrLTMfJE4zLfXovNTI4arcyK/erDmRh9aFjGWmuQ1jbPt4JNCXJsK8mO5/3JMcXCEVdfqlynRQ5Teu5iXnLSQGMehSjSEwIy2flpqzZfd6AsrIY/33tNUl9+GES7CHIOTxZSUm37QKGTjZqN46Y7JTYfhfdUWx7l6T0VgGoNNX8jjRhFoeWDmZyDtGenTxAILza9INhlj2g/JcBY5oxp8mUFixQUmNX7dZyzmw== 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:(13230031)(36860700004)(40470700004)(46966006); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Feb 2024 17:53:28.4868 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8020352c-773a-4de1-30db-08dc34985762 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: AM4PEPF00025F9A.EURPRD83.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA6PR08MB10595 X-Spam-Status: No, score=-11.9 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, T_SCC_BODY_TEXT_LINE, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi All, In certain cases we can have a situation where the merge block has a vUSE virtual PHI and the exits do not. In this case for instance the exits lead to an abort so they have no virtual PHIs. If we have a store before the first exit and we move it to a later block during vectorization we update the vUSE chain. However the merge block is not an exit and is not visited by the update code. This patch fixes it by checking during moving if there are any out of loop uses of the vDEF that is the last_seen_vuse. Normally there wouldn't be any and things are skipped, but if there is then update that to the last vDEF in the exit block. Bootstrapped Regtested on aarch64-none-linux-gnu and x86_64-pc-linux-gnu no issues. Ok for master? Thanks, Tamar gcc/ChangeLog: PR tree-optimizations/114068 * tree-vect-loop.cc (move_early_exit_stmts): Update vUSE chain in merge block. gcc/testsuite/ChangeLog: PR tree-optimizations/114068 * gcc.dg/vect/vect-early-break_118-pr114068.c: New test. * gcc.dg/vect/vect-early-break_119-pr114068.c: New test. --- inline copy of patch -- diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_118-pr114068.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_118-pr114068.c new file mode 100644 index 0000000000000000000000000000000000000000..b462a464b6603e718c5a283513ea586fc13e37ce --- diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_118-pr114068.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_118-pr114068.c new file mode 100644 index 0000000000000000000000000000000000000000..b462a464b6603e718c5a283513ea586fc13e37ce --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_118-pr114068.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-O3" } */ + +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */ + +struct h { + int b; + int f; +} k; + +void n(int m) { + struct h a = k; + for (int o = m; o; ++o) { + if (a.f) + __builtin_unreachable(); + if (o > 1) + __builtin_unreachable(); + *(&k.b + o) = 1; + } +} diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_119-pr114068.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_119-pr114068.c new file mode 100644 index 0000000000000000000000000000000000000000..a65ef7b8c4901b2ada585f38fda436dc07d1e1de --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_119-pr114068.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-O3" } */ + +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */ + +struct h { + int b; + int c; + int f; +} k; + +void n(int m) { + struct h a = k; + for (int o = m; o; ++o) { + if (a.f) + __builtin_unreachable(); + if (o > 1) + __builtin_unreachable(); + *(&k.b + o) = 1; + *(&k.c + o*m) = 2; + } +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 35f1f8c7d4245135ace7ffff40ff9be548919587..44bd8032b55b1ef84fdf4fa9d6117304b7709d6f 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -11837,6 +11837,27 @@ move_early_exit_stmts (loop_vec_info loop_vinfo) update_stmt (p); } + /* last_seen_vuse should now be the PHI in the loop header. Check for + any out of loop uses and update them to the vUSE on the loop latch. */ + auto vuse_stmt = loop_vinfo->lookup_def (last_seen_vuse); + gphi *vuse_def; + if (vuse_stmt + && (vuse_def = dyn_cast (STMT_VINFO_STMT (vuse_stmt)))) + { + imm_use_iterator iter; + use_operand_p use_p; + gimple *use_stmt; + auto loop = LOOP_VINFO_LOOP (loop_vinfo); + tree vuse = PHI_ARG_DEF_FROM_EDGE (vuse_def, loop_latch_edge (loop)); + FOR_EACH_IMM_USE_STMT (use_stmt, iter, last_seen_vuse) + { + if (flow_bb_inside_loop_p (loop, use_stmt->bb)) + continue; + FOR_EACH_IMM_USE_ON_STMT (use_p, iter) + SET_USE (use_p, vuse); + } + } + /* And update the LC PHIs on exits. */ for (edge e : get_loop_exit_edges (LOOP_VINFO_LOOP (loop_vinfo))) if (!dominated_by_p (CDI_DOMINATORS, e->src, dest_bb)) --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_118-pr114068.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-O3" } */ + +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */ + +struct h { + int b; + int f; +} k; + +void n(int m) { + struct h a = k; + for (int o = m; o; ++o) { + if (a.f) + __builtin_unreachable(); + if (o > 1) + __builtin_unreachable(); + *(&k.b + o) = 1; + } +} diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_119-pr114068.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_119-pr114068.c new file mode 100644 index 0000000000000000000000000000000000000000..a65ef7b8c4901b2ada585f38fda436dc07d1e1de --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_119-pr114068.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-O3" } */ + +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */ + +struct h { + int b; + int c; + int f; +} k; + +void n(int m) { + struct h a = k; + for (int o = m; o; ++o) { + if (a.f) + __builtin_unreachable(); + if (o > 1) + __builtin_unreachable(); + *(&k.b + o) = 1; + *(&k.c + o*m) = 2; + } +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 35f1f8c7d4245135ace7ffff40ff9be548919587..44bd8032b55b1ef84fdf4fa9d6117304b7709d6f 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -11837,6 +11837,27 @@ move_early_exit_stmts (loop_vec_info loop_vinfo) update_stmt (p); } + /* last_seen_vuse should now be the PHI in the loop header. Check for + any out of loop uses and update them to the vUSE on the loop latch. */ + auto vuse_stmt = loop_vinfo->lookup_def (last_seen_vuse); + gphi *vuse_def; + if (vuse_stmt + && (vuse_def = dyn_cast (STMT_VINFO_STMT (vuse_stmt)))) + { + imm_use_iterator iter; + use_operand_p use_p; + gimple *use_stmt; + auto loop = LOOP_VINFO_LOOP (loop_vinfo); + tree vuse = PHI_ARG_DEF_FROM_EDGE (vuse_def, loop_latch_edge (loop)); + FOR_EACH_IMM_USE_STMT (use_stmt, iter, last_seen_vuse) + { + if (flow_bb_inside_loop_p (loop, use_stmt->bb)) + continue; + FOR_EACH_IMM_USE_ON_STMT (use_p, iter) + SET_USE (use_p, vuse); + } + } + /* And update the LC PHIs on exits. */ for (edge e : get_loop_exit_edges (LOOP_VINFO_LOOP (loop_vinfo))) if (!dominated_by_p (CDI_DOMINATORS, e->src, dest_bb))