From patchwork Fri Oct 20 13:55:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 156115 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1072886vqb; Fri, 20 Oct 2023 06:56:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBP3swhcJuBPMCxkPWoKQd74PGidQ7gai2Cy2bdRUn3GUJ+/muIevykA8IvCLg3JvObico X-Received: by 2002:a37:e201:0:b0:76e:601d:a724 with SMTP id g1-20020a37e201000000b0076e601da724mr1913589qki.34.1697810203794; Fri, 20 Oct 2023 06:56:43 -0700 (PDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y19-20020a05620a44d300b0076efbe4639dsi1329379qkp.688.2023.10.20.06.56.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 06:56:43 -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=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=UE1QnF1l; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=UE1QnF1l; arc=fail (previous hop failed); 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D0CD3858438 for ; Fri, 20 Oct 2023 13:56:43 +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-vi1eur05on2080.outbound.protection.outlook.com [40.107.21.80]) by sourceware.org (Postfix) with ESMTPS id 2615F3858CDA for ; Fri, 20 Oct 2023 13:56:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2615F3858CDA 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 2615F3858CDA Authentication-Results: server2.sourceware.org; arc=fail smtp.remote-ip=40.107.21.80 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697810177; cv=fail; b=sh+XzNbVDKM+61cPAd+vjD4nfdIQzn7FWGV60OKecZpMFdiDZU7/+DDwsH5zhn4SkvI0BVYcXsUQE2MVPOI0wFqPPd3zExAeP50/KEph/SLmJRo8yOTIqIF+lnTZEbJJ9UrE3jhsTcJYlhy2dMY4wtWZ1LYfAe0kBGhT7fABy5I= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697810177; c=relaxed/simple; bh=7fs445YwqPG6G4x0wN+E1P6JD6nr3CMlImgU9950BRw=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=Q0fyIOSl0Ja+ZmRdpSDUqgpGh3U2nhaPZ39peaxWbShI9UlGjjbPR7iehLj7+++bl6IAttSwjgY1RITXjNeoHqLBc3PDdrLXeV/V77tT/9oUuZhV5vSyXHg7wIXv9Va12anZDgQG7wsZkQrQ1c7z3HTnQmO2OSv0dhw7nM9LCnU= ARC-Authentication-Results: i=2; server2.sourceware.org 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=YOnwUnzSMykDIxJWaNyK5Zokmgk64KiRYgUzimtHznA=; b=UE1QnF1lcFgN03oHUvfDGkKYth0oTKpE9rz35KcCFG/gYNCOpbGhKq4Pa8HKDKpfZIV1u+hZAywOn7z9k0BAw/T99zXIFHBJDq8dgZ3RYsSp5PrOfI4VsPs4Z7NiGDLpRbjqwEt8vzt621yEYtEhROJKR5qQ2/LPG0n36CM+AUg= Received: from AS8PR07CA0017.eurprd07.prod.outlook.com (2603:10a6:20b:451::26) by DBAPR08MB5638.eurprd08.prod.outlook.com (2603:10a6:10:1b2::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.26; Fri, 20 Oct 2023 13:56:11 +0000 Received: from AMS0EPF000001AF.eurprd05.prod.outlook.com (2603:10a6:20b:451:cafe::4a) by AS8PR07CA0017.outlook.office365.com (2603:10a6:20b:451::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.8 via Frontend Transport; Fri, 20 Oct 2023 13:56:10 +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 AMS0EPF000001AF.mail.protection.outlook.com (10.167.16.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.20 via Frontend Transport; Fri, 20 Oct 2023 13:56:10 +0000 Received: ("Tessian outbound 470906b1fe6c:v215"); Fri, 20 Oct 2023 13:56:10 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 1c6759539fe2674c X-CR-MTA-TID: 64aa7808 Received: from c8c19e69ca8b.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id CB5935A9-6655-4E42-9612-646B2A095F5B.1; Fri, 20 Oct 2023 13:56:03 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c8c19e69ca8b.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 20 Oct 2023 13:56:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B/B65GWaUoAbVxFkLAMei5Z5OF8w3s+tRE7E7M4iQ++pjXsCscdcsV8zrHk/TIsJKwA+2WtsOeuUd1n2JUztM1hsPx6YNOtWpmfJJdRfU84qngEhkKmFeiWcf4GpXrK8AjaTQbb3qYQCWq59SxvBAVTsfYnFRPyVIdNsSB0Z4I+WWzoOGSuUGzgxsDbHmkZmET9N4bt9sQBpixJSr6KUl1Un1EWN3PqDYQH0v/XZVdDObTUC+kpeKw3uX0bouzlU/Zucet7H+l8DJUkDKwHntUB9R4ScSeE35VNjITs8laWgr99//f97jTtCr5QMwpOTYsbVL51dksIHfOfpBjxmnA== 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=YOnwUnzSMykDIxJWaNyK5Zokmgk64KiRYgUzimtHznA=; b=ci5nuNOHalLtTBOasUevTmMCqJI1JHRrWXrceC+NeV+gmyuUckeShrLxAGVaOWxvhcJK1mBG9uN2goVuA1qz4OPbZbfUNir+AL0syZ2sTYBHSltSXwRNN1wTnPx05qxCrx0g7oSEZXVtfrgj1nttVZvwb0cwLQV9Ee0kinnZHVJgqH64/ndcAbBjm+vHdcWYD1nRn6eJ9eL4Ke0L1snafiBtCq9iGS2GJ4Ixg9l627uMwMFlQRlR8ccCcu3nLDHKpJ5s7jVNlTILgcFz9hgVA7CL0ocWWqLnENTlYQYD2QNcf+PnlAOcKhHnsTmIDmo2tLEcKoKC5MUzLLz6TWtfuQ== 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=YOnwUnzSMykDIxJWaNyK5Zokmgk64KiRYgUzimtHznA=; b=UE1QnF1lcFgN03oHUvfDGkKYth0oTKpE9rz35KcCFG/gYNCOpbGhKq4Pa8HKDKpfZIV1u+hZAywOn7z9k0BAw/T99zXIFHBJDq8dgZ3RYsSp5PrOfI4VsPs4Z7NiGDLpRbjqwEt8vzt621yEYtEhROJKR5qQ2/LPG0n36CM+AUg= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AM0PR08MB5316.eurprd08.prod.outlook.com (2603:10a6:208:185::14) by AS2PR08MB8335.eurprd08.prod.outlook.com (2603:10a6:20b:557::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Fri, 20 Oct 2023 13:56:00 +0000 Received: from AM0PR08MB5316.eurprd08.prod.outlook.com ([fe80::b979:1aa2:3557:ff30]) by AM0PR08MB5316.eurprd08.prod.outlook.com ([fe80::b979:1aa2:3557:ff30%4]) with mapi id 15.20.6907.022; Fri, 20 Oct 2023 13:55:59 +0000 Date: Fri, 20 Oct 2023 14:55:57 +0100 From: Tamar Christina To: gcc-patches@gcc.gnu.org Cc: nd@arm.com, rguenther@suse.de, jlaw@ventanamicro.com Subject: [PATCH] middle-end: don't keep .MEM guard nodes for PHI nodes who dominate loop [PR111860] Message-ID: Content-Disposition: inline X-ClientProxiedBy: LO6P265CA0009.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:339::14) To AM0PR08MB5316.eurprd08.prod.outlook.com (2603:10a6:208:185::14) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AM0PR08MB5316:EE_|AS2PR08MB8335:EE_|AMS0EPF000001AF:EE_|DBAPR08MB5638:EE_ X-MS-Office365-Filtering-Correlation-Id: 9695c931-8bec-4285-1159-08dbd1745104 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: nLpbYP9zSuz/lvoFHNeS1qis7zXd5Mksz6pW2SXG3vMN6F9eUI0UouhDMJCRUxjjlP66+qqIcG7JG1QovO4YCmDl4Oz/srQJ4nAp97JSNoJyNWgCwvSy2z3vza9estiM9ZajNZRDp0gzdW607Zm/TkIvfyxhBAssYywLZWepONygK+4CNdDYhXvnzXjsU4rMPjxv8/h4ZIA+77oToxiJWub5rW5FiOAuJ7XQW1xG5wWJL+OsZhHa8K1uLIxqM8G2tPf3TiHvjfC2raCWKabDpbtqeUYPH06q6D4/vXkh53hXglAWvUIQxpoxmZGitIdfgsOBF08FaXxPqVBSUgV6v4pBg/tA05VDsDVs7nh4mVE7LZ7h1S/yUhXmUlZJWEKLg4TT9qfS3nocUt2PEaMnKVIM3xY6m6SchgsZFRD82p+IXA8fweNl6xVhfpz7wWLCmGjejOQNbV3E1YUkbyBpTObj8ioziQaxKlFsXY+I4/FvqHo8v4Uvf4kakKYQs3NMFnYt2bnthJzEfiKm6PA5piyw8aVCnjWC+49hLEAOArW4WyqfxqeYZd78r+dtGDYj6opXSMfrLQ8/yRQVeLAAP+O6wvwi8ZJGKj879kZvBAijBVOGgKFjR/Qc1KSb5oHCNMIPpyaXhNjiDgR62k319/ccgMdSLDrVuKLAibynLwAQ0JSZaufatOh5ioXk4/xH X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR08MB5316.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(136003)(346002)(376002)(366004)(396003)(39860400002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(83380400001)(6506007)(2906002)(33964004)(5660300002)(44832011)(36756003)(26005)(44144004)(2616005)(38100700002)(86362001)(6512007)(478600001)(235185007)(316002)(66946007)(6486002)(41300700001)(6916009)(66556008)(66476007)(84970400001)(8936002)(4326008)(8676002)(4216001)(142923001)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB8335 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: AMS0EPF000001AF.eurprd05.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: c20d71f7-e8b4-421f-2c13-08dbd1744a49 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lxCnxrzWIxPIJCO0mDHTeVJLzyGdcLR4leAn7kC26Jx5zCUHnamGdM1Pt5dDwnvoqF9sRPazwd812QaMrwx8ik8gR1vhv6iABpHy/+IpApuYnztHzlVwJU4TtqeJrH2bv+4NCjmspvp8F0W2lGK4mSHY0Z7qOhMPjTT+D1Cmcv7MXf4nCakP5P05IRn2p0z7KC0tRgrkk6K/cxLXNRUqFEefQGQrzSHcK16RvSd/yka+tOkAMAHyGVFHbl9IC7nHNumC1GAYiNX9heLqyskGelJ/xj0C/IzArrrOyRvHts5V17E2AhnJuj3q7EzTsCSb+XOZ2Fb2MXO83CvReeWG3zThKgrrUkFkVn2JYLDP4naOeH/tzjAouhs8fRL4GKxbE/qY0OcE29fUm/lEQy0dvomW8O6MXist3x7GCay2gfIFH9glNtvi5q2c7P+MGOZDLXr8Ko4et4LlH5GtP4GOXj/38VA7AgfaFJFAzblAPk+W2CT9wLvjzs8BkWH+NL8d4rAuATXFbLM/kH839HLWWUxyzP316qsTcZw2qvfZ9hPqbomYTI1na1hsIWvSSQUmOvMMrpb9IP64QmUiymeDJMZ5bBIC9lDdT9C/J0wu8CVg/j7AjAn/DKb3myl3FmBUOGQLxXlyihWhXe0ZyKzo5k3NxUUX/38CDeBS5g/W/s1pLFxCKX0mpKaQX8CvAL2JovJPNmO3VAKVfUsqG7LAgYN6BXj0q8vJ1CfPFqHUfyfC3kWO+CMKjWTXJMeenNnwKumDnJzqkIAm/FDMZVoCaOphyP57pPhZ6FGF6GQr8AJCDxq490K0sbnL7kIH0JXP 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)(4636009)(39850400004)(346002)(376002)(136003)(396003)(230922051799003)(64100799003)(186009)(1800799009)(451199024)(82310400011)(36840700001)(46966006)(8936002)(8676002)(84970400001)(2906002)(235185007)(5660300002)(107886003)(26005)(4326008)(336012)(36756003)(40480700001)(41300700001)(44832011)(36860700001)(47076005)(316002)(86362001)(6916009)(478600001)(6486002)(2616005)(83380400001)(82740400003)(356005)(81166007)(70206006)(70586007)(6512007)(6506007)(44144004)(33964004)(4216001)(142923001)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2023 13:56:10.7908 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9695c931-8bec-4285-1159-08dbd1745104 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: AMS0EPF000001AF.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5638 X-Spam-Status: No, score=-12.0 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780283032231623738 X-GMAIL-MSGID: 1780283032231623738 Hi All, The previous patch tried to remove PHI nodes that dominated the first loop, however the correct fix is to only remove .MEM nodes. This patch thus makes the condition a bit stricter and only tries to remove MEM phi nodes. I couldn't figure out a way to easily determine if a particular PHI is vUSE related, so the patch does: 1. check if the definition is a vDEF and not defined in main loop. 2. check if the definition is a PHI and not defined in main loop. 3. check if the definition is a default definition. For no 2 and 3 we may misidentify the PHI, in both cases the value is defined outside of the loop version block which also makes it ok to remove. Bootstrapped Regtested on aarch64-none-linux-gnu, powerpc64le-unknown-linux-gnu, x86_64-none-linux-gnu and no issues. Tested all default testsuites. Ok for master? Thanks, Tamar gcc/ChangeLog: PR tree-optimization/111860 * tree-vect-loop-manip.cc (slpeel_tree_duplicate_loop_to_edge_cfg): Drop .MEM nodes only. gcc/testsuite/ChangeLog: PR tree-optimization/111860 * gcc.dg/vect/pr111860-2.c: New test. * gcc.dg/vect/pr111860-3.c: New test. --- inline copy of patch -- diff --git a/gcc/testsuite/gcc.dg/vect/pr111860-2.c b/gcc/testsuite/gcc.dg/vect/pr111860-2.c new file mode 100644 index 0000000000000000000000000000000000000000..07f64ffb5318c9d7817d46802d123cc9a2d65ec9 --- diff --git a/gcc/testsuite/gcc.dg/vect/pr111860-2.c b/gcc/testsuite/gcc.dg/vect/pr111860-2.c new file mode 100644 index 0000000000000000000000000000000000000000..07f64ffb5318c9d7817d46802d123cc9a2d65ec9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr111860-2.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-sink -ftree-vectorize" } */ +int buffer_ctrl_ctx_0, buffer_ctrl_p1, buffer_ctrl_cmd; + +int +buffer_ctrl (long ret, int i) +{ + switch (buffer_ctrl_cmd) + { + case 1: + buffer_ctrl_ctx_0 = 0; + for (; i; i++) + if (buffer_ctrl_p1) + ret++; + } + return ret; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr111860-3.c b/gcc/testsuite/gcc.dg/vect/pr111860-3.c new file mode 100644 index 0000000000000000000000000000000000000000..07f64ffb5318c9d7817d46802d123cc9a2d65ec9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr111860-3.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-sink -ftree-vectorize" } */ +int buffer_ctrl_ctx_0, buffer_ctrl_p1, buffer_ctrl_cmd; + +int +buffer_ctrl (long ret, int i) +{ + switch (buffer_ctrl_cmd) + { + case 1: + buffer_ctrl_ctx_0 = 0; + for (; i; i++) + if (buffer_ctrl_p1) + ret++; + } + return ret; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr111860.c b/gcc/testsuite/gcc.dg/vect/pr111860.c new file mode 100644 index 0000000000000000000000000000000000000000..36f0774601040418bc6b7f27c9425b2bf93b18cb --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr111860.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ + +int optimize_path_n, optimize_path_d; +int *optimize_path_d_0; +extern void path_threeOpt( long); +void optimize_path() { + int i; + long length; + i = 0; + for (; i <= optimize_path_n; i++) + optimize_path_d = 0; + i = 0; + for (; i < optimize_path_n; i++) + length += optimize_path_d_0[i]; + path_threeOpt(length); +} diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index 1f7779b9834c3aef3c6a993fab916224fab03147..fc55278e63f7a48943fdc32c5e207110cf14507e 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -1626,13 +1626,33 @@ slpeel_tree_duplicate_loop_to_edge_cfg (class loop *loop, edge loop_exit, edge temp_e = redirect_edge_and_branch (exit, new_preheader); flush_pending_stmts (temp_e); } - /* Record the new SSA names in the cache so that we can skip materializing them again when we fill in the rest of the LCSSA variables. */ for (auto phi : new_phis) { tree new_arg = gimple_phi_arg (phi, 0)->def; new_phi_args.put (new_arg, gimple_phi_result (phi)); + + if (!SSA_VAR_P (new_arg)) + continue; + /* If the PHI MEM node dominates the loop then we shouldn't create + a new LC-SSSA PHI for it in the intermediate block. */ + gimple *def_stmt = SSA_NAME_DEF_STMT (new_arg); + basic_block def_bb = gimple_bb (def_stmt); + /* A MEM phi that consitutes a new DEF for the vUSE chain can either + be a .VDEF or a PHI that operates on MEM. */ + if (((gimple_vdef (def_stmt) || is_a (def_stmt)) + /* And said definition must not be inside the main loop. */ + && (!def_bb || !flow_bb_inside_loop_p (loop, def_bb))) + /* Or we must be a parameter. In the last two cases we may remove + a non-MEM PHI node, but since they dominate both loops the + removal is unlikely to cause trouble as the exits must already + be using them. */ + || SSA_NAME_IS_DEFAULT_DEF (new_arg)) + { + auto gsi = gsi_for_stmt (phi); + remove_phi_node (&gsi, true); + } } /* Copy the current loop LC PHI nodes between the original loop exit --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr111860-2.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-sink -ftree-vectorize" } */ +int buffer_ctrl_ctx_0, buffer_ctrl_p1, buffer_ctrl_cmd; + +int +buffer_ctrl (long ret, int i) +{ + switch (buffer_ctrl_cmd) + { + case 1: + buffer_ctrl_ctx_0 = 0; + for (; i; i++) + if (buffer_ctrl_p1) + ret++; + } + return ret; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr111860-3.c b/gcc/testsuite/gcc.dg/vect/pr111860-3.c new file mode 100644 index 0000000000000000000000000000000000000000..07f64ffb5318c9d7817d46802d123cc9a2d65ec9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr111860-3.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-sink -ftree-vectorize" } */ +int buffer_ctrl_ctx_0, buffer_ctrl_p1, buffer_ctrl_cmd; + +int +buffer_ctrl (long ret, int i) +{ + switch (buffer_ctrl_cmd) + { + case 1: + buffer_ctrl_ctx_0 = 0; + for (; i; i++) + if (buffer_ctrl_p1) + ret++; + } + return ret; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr111860.c b/gcc/testsuite/gcc.dg/vect/pr111860.c new file mode 100644 index 0000000000000000000000000000000000000000..36f0774601040418bc6b7f27c9425b2bf93b18cb --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr111860.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ + +int optimize_path_n, optimize_path_d; +int *optimize_path_d_0; +extern void path_threeOpt( long); +void optimize_path() { + int i; + long length; + i = 0; + for (; i <= optimize_path_n; i++) + optimize_path_d = 0; + i = 0; + for (; i < optimize_path_n; i++) + length += optimize_path_d_0[i]; + path_threeOpt(length); +} diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index 1f7779b9834c3aef3c6a993fab916224fab03147..fc55278e63f7a48943fdc32c5e207110cf14507e 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -1626,13 +1626,33 @@ slpeel_tree_duplicate_loop_to_edge_cfg (class loop *loop, edge loop_exit, edge temp_e = redirect_edge_and_branch (exit, new_preheader); flush_pending_stmts (temp_e); } - /* Record the new SSA names in the cache so that we can skip materializing them again when we fill in the rest of the LCSSA variables. */ for (auto phi : new_phis) { tree new_arg = gimple_phi_arg (phi, 0)->def; new_phi_args.put (new_arg, gimple_phi_result (phi)); + + if (!SSA_VAR_P (new_arg)) + continue; + /* If the PHI MEM node dominates the loop then we shouldn't create + a new LC-SSSA PHI for it in the intermediate block. */ + gimple *def_stmt = SSA_NAME_DEF_STMT (new_arg); + basic_block def_bb = gimple_bb (def_stmt); + /* A MEM phi that consitutes a new DEF for the vUSE chain can either + be a .VDEF or a PHI that operates on MEM. */ + if (((gimple_vdef (def_stmt) || is_a (def_stmt)) + /* And said definition must not be inside the main loop. */ + && (!def_bb || !flow_bb_inside_loop_p (loop, def_bb))) + /* Or we must be a parameter. In the last two cases we may remove + a non-MEM PHI node, but since they dominate both loops the + removal is unlikely to cause trouble as the exits must already + be using them. */ + || SSA_NAME_IS_DEFAULT_DEF (new_arg)) + { + auto gsi = gsi_for_stmt (phi); + remove_phi_node (&gsi, true); + } } /* Copy the current loop LC PHI nodes between the original loop exit