From patchwork Thu Jan 11 13:33:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 83889 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 225493857704 for ; Thu, 11 Jan 2024 13:34:35 +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-vi1eur05on2056.outbound.protection.outlook.com [40.107.21.56]) by sourceware.org (Postfix) with ESMTPS id AD5B5385800A for ; Thu, 11 Jan 2024 13:34:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD5B5385800A 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 AD5B5385800A Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.21.56 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1704980048; cv=pass; b=GlNiIy+w4Uqobu+16ZMt9pdSLJzzYiGAoxIOiqBHyjAIKTgMSIgmPPJFj9iyjv2r4hTK/Xay6v0doIg9X1CPt4I3pVR+T90rZvFc1yx7V0GQpCniDLSewwXUYkOAjvEUjC85gSppuk6lBMMHZrI5cF/DL0PaMjrjeMP1hN7DrOc= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1704980048; c=relaxed/simple; bh=/afVeFTZIPZntqoXUl9Lq00pTzCdYpcBogy1151OOhQ=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=kHP6HyKBv5SsM7UGmnRS4xjSrOm8MUWRI7oIxJeBXZSoeWHb0Y9LLELReQu8gyvE9zVfZ+21b4nO4fnd44mGmDp3xoM4GRjRvSKey19jtzJO0LJ6qPsDfqzWaqZehgFkyL5rqEZYtJ64zRLySJboW0tAWp0DFDG/vSxTyVebMZI= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=axV8I7a9XUq6iUxzVNUebIMGa1gwSQq1+CbLUh7qyWPAWJP53CLjPItS7fMGGSZMgDZFaolYCq7yM5JnSShf6SMRPROy6br3XcofojM0oNWCnRphAs/Y0Sq6KlwYShUk2Pxc5ndzsFNZ1jYlDbTrg4bsjVnnBb3lmBkmefYmr1jSnDIw+LuMFrAf3FFUcJpxFJ+viVVhGQy7tjbdC29Z+ZLg9Ij5aP3mUBqGXW3PGyUv2IoWrgz5BlelcVcik6FvZ13whedTt8lkoymMZEfYAkm3raWLGaZYz4BxCuqnN7spL9L24R+s/hwkelHpVKEVPGJsorZR7sRdZNGtq0h8SA== 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=bqH7E+QQKTWDHMfxypZrHyQcEjTSLCB3c7om65Bh5U4=; b=nHy1/wlKvAkY8mUMMcWKyxwnIF8nCVZ5fPBfSGBs3tWGWs1LixMoD40ZzV4lekKO3t5EKI2dVMkiRyIPP3XhA5FSflRuBDneEW/6cLmaAKNVENJGYDiglvPDeSk260V92N1pbkKFUBn+YwPEot0ZmbilmBFjA/3gkjMjYOTdR6BJleRijdgHnMLThrTlbdjjBs6Dw5dHOxiUBlSrDhw1vgbOaaXsIXi4rvXkqdNBYGwM/pldE95Vg9VNi6gjeKyGa7TuYUKbWlHEY8cAX2qAr2Yr2MC6Vuyhtwh+SM5IdPP6sdGN7f/M0e+nKLMZdBAll6n4lsnkbMeDKWjFNLjO8A== 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=bqH7E+QQKTWDHMfxypZrHyQcEjTSLCB3c7om65Bh5U4=; b=f7IghXINQuuk7QR/MCA5kYRTWJHwJrnZw3ymNuWdBijCOJTPQFEaMV1wG8e9zv98ne9qNpoBpuovXvCRjvDALpR6InRF7L0Ao45EP707lJ9BdMZePOnGCPHW9FBOR1poPTbi9P2Pb5Eych5PJvMLVMeVtkMdzwCXYwO7AimL3Gg= Received: from AM6P193CA0088.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::29) by GV1PR08MB8642.eurprd08.prod.outlook.com (2603:10a6:150:83::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.26; Thu, 11 Jan 2024 13:34:00 +0000 Received: from AM3PEPF00009BA2.eurprd04.prod.outlook.com (2603:10a6:209:88:cafe::77) by AM6P193CA0088.outlook.office365.com (2603:10a6:209:88::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.19 via Frontend Transport; Thu, 11 Jan 2024 13:34:00 +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 AM3PEPF00009BA2.mail.protection.outlook.com (10.167.16.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.14 via Frontend Transport; Thu, 11 Jan 2024 13:34:00 +0000 Received: ("Tessian outbound c87008563c51:v228"); Thu, 11 Jan 2024 13:34:00 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 5a4f714436e6fc2e X-CR-MTA-TID: 64aa7808 Received: from f7f22ddc7ae5.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 587DDF84-641E-4800-9D74-955096814CF1.1; Thu, 11 Jan 2024 13:33:53 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f7f22ddc7ae5.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 11 Jan 2024 13:33:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F5qFTmoS6HJzZ+lKbb3EOXkbd6BrrOyBUe2n0YJ2mw23ns9tizvAaQ3Zb+JoqFAoRjhky54emWPXMa6KuEIBVUAbstLVDK2T/8nKkJr0HmaRsAr5rJk426Vph4mAYLTL/f1DQfiyMCFXOpT25CTgFNc6tHkCZQqR7d91LCwuWVKu5jdY+sKBd3rXgU9LQmw23nIrqt6FV33YmZ5o1CujCYWYz+XtTbxI646YfaxI3DP8JD3+uzkJH+r6GVhc2LxoxvyDU/yK0HlRixuIWyU/FCG4X6K1LOeuD76eifml0f0kK8bSMfbhyPU9/DWcC8W00WP1hlUzxxsGUNkbJqFaBg== 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=bqH7E+QQKTWDHMfxypZrHyQcEjTSLCB3c7om65Bh5U4=; b=ZhL8n5uKADFLRj1k+sJS0GSADFOPEJa08GkcvYJIgSGMy79CG47V/hPO5jUR/+EKvZ8mIKoFLW8veuyeAFWyyXUh14QDkou94EFpELFf5gLDFqiZ6xnS2TFf0dzQ/AVFHQGVUAhgWLy20Xu7KPlZUGFtLxb38WNH6bsPXA1x4V/KPTgTXVlu1zDKlwnoDPFnu70IIyT/IKk8QMJ76J6lLrC0N4+ZaMB9su3zvBn+aV8PV1RgMSpKHMeJ2t8Tv7C7nh6n5rhyWrauuDvOvpK/eOfhku0jVwY3ZV77MR4cDwpl411vstCqDsVoZKcLDhdF1JOIX5iX+f71aSpsHx/HQQ== 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=bqH7E+QQKTWDHMfxypZrHyQcEjTSLCB3c7om65Bh5U4=; b=f7IghXINQuuk7QR/MCA5kYRTWJHwJrnZw3ymNuWdBijCOJTPQFEaMV1wG8e9zv98ne9qNpoBpuovXvCRjvDALpR6InRF7L0Ao45EP707lJ9BdMZePOnGCPHW9FBOR1poPTbi9P2Pb5Eych5PJvMLVMeVtkMdzwCXYwO7AimL3Gg= 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 PAWPR08MB9122.eurprd08.prod.outlook.com (2603:10a6:102:342::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.19; Thu, 11 Jan 2024 13:33:51 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::810c:8495:3f0a:ef8]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::810c:8495:3f0a:ef8%6]) with mapi id 15.20.7181.015; Thu, 11 Jan 2024 13:33:51 +0000 Date: Thu, 11 Jan 2024 13:33:48 +0000 From: Tamar Christina To: gcc-patches@gcc.gnu.org Cc: nd@arm.com, rguenther@suse.de, jlaw@ventanamicro.com Subject: [PATCH]middle-end: make memory analysis for early break more deterministic [PR113135] Message-ID: Content-Disposition: inline X-ClientProxiedBy: LO4P265CA0216.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:33a::8) To VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB5325:EE_|PAWPR08MB9122:EE_|AM3PEPF00009BA2:EE_|GV1PR08MB8642:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ae4c093-525c-48aa-202c-08dc12a9f866 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: fq3o6ZzSpBeEi1bTXHeLJxIf9eDhtdyvfpP0joLNQQzdSfrvDVVXcD2B8SWYif/64ZJjKfSJFVJbZhblwLstOhKTYfWw69HQKu/W/X9bibyp1EukcGI/FnzJwEFdmMwxkamznE37ygCNZuzRVh5zOixk44nOzhofIDDizM7vqD1HnnyFwz/00dcQTT/LkJt/SQQY61hSPpocOV+yE4Y0SjgWCaMpMZrPJ0zkogYlPq6noJDsQ+8WIUA+QDlLQrsmztpYaVF7ib+Mj4348Qnw1m6HeNRQoi9edhlQoHoyiaknJbIkb+Nw7VOJ/k9tBN3Ckty+VZbdCJK+kYGk+IhQ8xe250q4qQewHGN4F/dEL2fByv6nyh5e6HWBfxF5O8ns/AIxSFjz9yb22iLROKITTNkKjbgIm+g6O99dT111rJkHgl382P2bKRpdAwE8hdBRtVxYkvWiCfoHaV0xYTW4fpb1ZO0hwCVmIvD22tgbnBbrfCizoNVRp3MR1XAfOEkVQyTBN0Pvs5C09tszipXIFrnrpHG4T3fDK5La6faIoyIUemRY7SIiX4kbreqvbT109btTT27ABI7Jr9VrEHsVIxFn+zQmq9FBlLam1l0p8yoSsP32U83ox7dwpASJPEaA 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)(366004)(39860400002)(396003)(376002)(136003)(346002)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(38100700002)(66476007)(66556008)(66946007)(316002)(84970400001)(6916009)(6506007)(478600001)(6512007)(44144004)(33964004)(41300700001)(8676002)(8936002)(4326008)(6486002)(44832011)(83380400001)(2616005)(26005)(6666004)(86362001)(4743002)(5660300002)(235185007)(2906002)(36756003)(4216001)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB9122 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: AM3PEPF00009BA2.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 7c72db18-4d71-4711-122f-08dc12a9f2eb X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oJ+wCzl8Zyq6DCFxQd/InAVMQtX2O6RmshMF+dHA6jUBl/JpduUnuNH9UKPDi+uD4WP+o4Ttom84rI4YkG7dbRgU/tiu2UCDTBj7ZwbMubvOhTPDILk6QUgwNnv9h6pTf4KSanKwrGOXgE/vkIsaS+96dWmPPIS0vnwgzO99LDc/OWEz01ugT8hMjclaZKVLxAeqDfFsduHczDTINoNpdLmhd9qCSLJMEn81QI3s/Qernhf9KXl9bSbLjpla5AR+KrOeBMFvxn2wUYExzYtOFliTEfzD5vxsrSzPZZQDjGQU+PRz1mEh0g2Px6TtnYls5XmNIY9l5vN+Cx1JbvTyv6xhw4TNJgSK05phQ3NBo+0D4e4YUpYXUXtXhFeUBCZ46kQ196dj7eVux+Q6ocvHsOJ72aAIrY5F8mXX6UuckGyVwWHWUmsad1Hll6Xw8T9YlOP3HCq/7x2g6MQpK6ZuRhhZQ2p1yNaNT7qPcaILx4pPAAN8PyGviof0evmgy8YyjvS+0eP1AQ2+P+Yc1ibp3QEWI4TKjJzg/GSXgNrRQjcTtoCIlYH/aMIJMfiXllvUDlEjbSGrTnXlNjpscZBfsrf4u+MFIjBL2hbG5Up0W2mw8qRQrzeFs/M5LA4WZljHB9HToL8XLm7TkaKeL/f26lVMlY0TzVUZ1JoHIp6gpuykTk+MqvN7mXJPrTy1HncEYdNhCWPfF7KGlZyOGHS61eJosJrdNxPk0Np2HvzDOuQ7BmWku1Dz2swm+CUnvO7FZH7Wnw5RYwBpwVBrBqfo1A== 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)(396003)(39860400002)(346002)(136003)(376002)(230922051799003)(451199024)(1800799012)(82310400011)(186009)(64100799003)(36840700001)(40470700004)(46966006)(2616005)(356005)(26005)(107886003)(478600001)(336012)(6666004)(6506007)(6512007)(33964004)(44144004)(83380400001)(36860700001)(235185007)(4743002)(2906002)(5660300002)(44832011)(41300700001)(47076005)(70586007)(70206006)(6486002)(4326008)(8936002)(8676002)(6916009)(316002)(81166007)(86362001)(82740400003)(36756003)(84970400001)(40460700003)(40480700001)(4216001)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2024 13:34:00.5358 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ae4c093-525c-48aa-202c-08dc12a9f866 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: AM3PEPF00009BA2.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB8642 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+patchwork=sourceware.org@gcc.gnu.org Hi All, Instead of searching for where to move stores to, they should always be in exit belonging to the latch. We can only ever delay stores and even if we pick a different exit than the latch one as the main one, effects still happen in program order when vectorized. If we don't move the stores to the latch exit but instead to whever we pick as the "main" exit then we can perform incorrect memory accesses (luckily these are trapped by verify_ssa). We used to iterate over the conds and check the loads and stores inside them. However this relies on the conds being ordered in program order. Additionally if there is a basic block between two conds we would not have analyzed it. Instead this now walks from the preds of the destination basic block up to the loop header and analyzes every block along the way. As a later optimization we could stop as soon as we've seen all the BBs we have conds for. For now the header will always contain the first cond, but this can change when we support arbitrary control flow. Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu and no issues normally and with --enable-checking=release --enable-lto --with-build-config=bootstrap-O3 --enable-checking=yes,rtl,extra. Ok for master? Thanks, Tamar gcc/ChangeLog: PR tree-optimization/113135 * tree-vect-data-refs.cc (vect_analyze_early_break_dependences): Rework dependency analysis. gcc/testsuite/ChangeLog: PR tree-optimization/113135 * gcc.dg/vect/vect-early-break_103-pr113135.c: New test. --- inline copy of patch -- diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_103-pr113135.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_103-pr113135.c new file mode 100644 index 0000000000000000000000000000000000000000..bbad7ee2cb18086e470f4a2a2dc0a2b345bbdd71 --- diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_103-pr113135.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_103-pr113135.c new file mode 100644 index 0000000000000000000000000000000000000000..bbad7ee2cb18086e470f4a2a2dc0a2b345bbdd71 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_103-pr113135.c @@ -0,0 +1,14 @@ +/* { 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 "-w" } */ + +char UnpackReadTables_BitLength[20]; +int UnpackReadTables_ZeroCount; +void UnpackReadTables() { + for (unsigned I = 0; I < 20;) + while (UnpackReadTables_ZeroCount-- && + I < sizeof(UnpackReadTables_BitLength)) + UnpackReadTables_BitLength[I++] = 0; +} diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index 3d9673fb0b580ff21ff151dc5c199840df41a1cd..6b76eee72cb7d09de5f443589b4fc3a0e8c2584f 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -671,13 +671,18 @@ vect_analyze_early_break_dependences (loop_vec_info loop_vinfo) "loop contains multiple exits, analyzing" " statement dependencies.\n"); - for (gimple *c : LOOP_VINFO_LOOP_CONDS (loop_vinfo)) - { - stmt_vec_info loop_cond_info = loop_vinfo->lookup_stmt (c); - if (STMT_VINFO_TYPE (loop_cond_info) != loop_exit_ctrl_vec_info_type) - continue; + /* Since we don't support general control flow, the location we'll move the + side-effects to is always the latch connected exit. When we support + general control flow we can do better but for now this is fine. */ + dest_bb = single_pred (loop->latch); + auto_vec workset; + for (auto e: dest_bb->preds) + workset.safe_push (e); - gimple_stmt_iterator gsi = gsi_for_stmt (c); + while (!workset.is_empty ()) + { + basic_block bb = workset.pop ()->src; + gimple_stmt_iterator gsi = gsi_last_bb (bb); /* Now analyze all the remaining statements and try to determine which instructions are allowed/needed to be moved. */ @@ -705,10 +710,10 @@ vect_analyze_early_break_dependences (loop_vec_info loop_vinfo) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "early breaks only supported on statically" " allocated objects.\n"); - return opt_result::failure_at (c, + return opt_result::failure_at (stmt, "can't safely apply code motion to " "dependencies of %G to vectorize " - "the early exit.\n", c); + "the early exit.\n", stmt); } tree refop = TREE_OPERAND (obj, 0); @@ -720,10 +725,10 @@ vect_analyze_early_break_dependences (loop_vec_info loop_vinfo) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "early breaks only supported on" " statically allocated objects.\n"); - return opt_result::failure_at (c, + return opt_result::failure_at (stmt, "can't safely apply code motion to " "dependencies of %G to vectorize " - "the early exit.\n", c); + "the early exit.\n", stmt); } /* Check if vector accesses to the object will be within bounds. @@ -736,10 +741,10 @@ vect_analyze_early_break_dependences (loop_vec_info loop_vinfo) "early breaks not supported: vectorization " "would %s beyond size of obj.", DR_IS_READ (dr_ref) ? "read" : "write"); - return opt_result::failure_at (c, + return opt_result::failure_at (stmt, "can't safely apply code motion to " "dependencies of %G to vectorize " - "the early exit.\n", c); + "the early exit.\n", stmt); } if (DR_IS_READ (dr_ref)) @@ -802,26 +807,15 @@ vect_analyze_early_break_dependences (loop_vec_info loop_vinfo) } } - /* Save destination as we go, BB are visited in order and the last one - is where statements should be moved to. */ - if (!dest_bb) - dest_bb = gimple_bb (c); - else - { - basic_block curr_bb = gimple_bb (c); - if (dominated_by_p (CDI_DOMINATORS, curr_bb, dest_bb)) - dest_bb = curr_bb; - } + if (bb != loop->header) + for (auto e: bb->preds) + workset.safe_push (e); } - basic_block dest_bb0 = EDGE_SUCC (dest_bb, 0)->dest; - basic_block dest_bb1 = EDGE_SUCC (dest_bb, 1)->dest; - dest_bb = flow_bb_inside_loop_p (loop, dest_bb0) ? dest_bb0 : dest_bb1; /* We don't allow outer -> inner loop transitions which should have been trapped already during loop form analysis. */ gcc_assert (dest_bb->loop_father == loop); - gcc_assert (dest_bb); LOOP_VINFO_EARLY_BRK_DEST_BB (loop_vinfo) = dest_bb; if (!LOOP_VINFO_EARLY_BRK_VUSES (loop_vinfo).is_empty ()) --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_103-pr113135.c @@ -0,0 +1,14 @@ +/* { 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 "-w" } */ + +char UnpackReadTables_BitLength[20]; +int UnpackReadTables_ZeroCount; +void UnpackReadTables() { + for (unsigned I = 0; I < 20;) + while (UnpackReadTables_ZeroCount-- && + I < sizeof(UnpackReadTables_BitLength)) + UnpackReadTables_BitLength[I++] = 0; +} diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index 3d9673fb0b580ff21ff151dc5c199840df41a1cd..6b76eee72cb7d09de5f443589b4fc3a0e8c2584f 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -671,13 +671,18 @@ vect_analyze_early_break_dependences (loop_vec_info loop_vinfo) "loop contains multiple exits, analyzing" " statement dependencies.\n"); - for (gimple *c : LOOP_VINFO_LOOP_CONDS (loop_vinfo)) - { - stmt_vec_info loop_cond_info = loop_vinfo->lookup_stmt (c); - if (STMT_VINFO_TYPE (loop_cond_info) != loop_exit_ctrl_vec_info_type) - continue; + /* Since we don't support general control flow, the location we'll move the + side-effects to is always the latch connected exit. When we support + general control flow we can do better but for now this is fine. */ + dest_bb = single_pred (loop->latch); + auto_vec workset; + for (auto e: dest_bb->preds) + workset.safe_push (e); - gimple_stmt_iterator gsi = gsi_for_stmt (c); + while (!workset.is_empty ()) + { + basic_block bb = workset.pop ()->src; + gimple_stmt_iterator gsi = gsi_last_bb (bb); /* Now analyze all the remaining statements and try to determine which instructions are allowed/needed to be moved. */ @@ -705,10 +710,10 @@ vect_analyze_early_break_dependences (loop_vec_info loop_vinfo) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "early breaks only supported on statically" " allocated objects.\n"); - return opt_result::failure_at (c, + return opt_result::failure_at (stmt, "can't safely apply code motion to " "dependencies of %G to vectorize " - "the early exit.\n", c); + "the early exit.\n", stmt); } tree refop = TREE_OPERAND (obj, 0); @@ -720,10 +725,10 @@ vect_analyze_early_break_dependences (loop_vec_info loop_vinfo) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "early breaks only supported on" " statically allocated objects.\n"); - return opt_result::failure_at (c, + return opt_result::failure_at (stmt, "can't safely apply code motion to " "dependencies of %G to vectorize " - "the early exit.\n", c); + "the early exit.\n", stmt); } /* Check if vector accesses to the object will be within bounds. @@ -736,10 +741,10 @@ vect_analyze_early_break_dependences (loop_vec_info loop_vinfo) "early breaks not supported: vectorization " "would %s beyond size of obj.", DR_IS_READ (dr_ref) ? "read" : "write"); - return opt_result::failure_at (c, + return opt_result::failure_at (stmt, "can't safely apply code motion to " "dependencies of %G to vectorize " - "the early exit.\n", c); + "the early exit.\n", stmt); } if (DR_IS_READ (dr_ref)) @@ -802,26 +807,15 @@ vect_analyze_early_break_dependences (loop_vec_info loop_vinfo) } } - /* Save destination as we go, BB are visited in order and the last one - is where statements should be moved to. */ - if (!dest_bb) - dest_bb = gimple_bb (c); - else - { - basic_block curr_bb = gimple_bb (c); - if (dominated_by_p (CDI_DOMINATORS, curr_bb, dest_bb)) - dest_bb = curr_bb; - } + if (bb != loop->header) + for (auto e: bb->preds) + workset.safe_push (e); } - basic_block dest_bb0 = EDGE_SUCC (dest_bb, 0)->dest; - basic_block dest_bb1 = EDGE_SUCC (dest_bb, 1)->dest; - dest_bb = flow_bb_inside_loop_p (loop, dest_bb0) ? dest_bb0 : dest_bb1; /* We don't allow outer -> inner loop transitions which should have been trapped already during loop form analysis. */ gcc_assert (dest_bb->loop_father == loop); - gcc_assert (dest_bb); LOOP_VINFO_EARLY_BRK_DEST_BB (loop_vinfo) = dest_bb; if (!LOOP_VINFO_EARLY_BRK_VUSES (loop_vinfo).is_empty ())