From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2043.outbound.protection.outlook.com [40.107.22.43]) by sourceware.org (Postfix) with ESMTPS id DBC9C3858C2D for ; Wed, 28 Jun 2023 13:44:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DBC9C3858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=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=gPAO0trMrLwudeRQm0bpHCv8dvDT5b4k8dM+EC9afcs=; b=dlGdQviT/MXfGI/+fE1S7iA+5Kxi6mzP0Gggcdhoy8LJXEcqsQ8bbf6z/8Gvm8iPLSCyQslvW83nfZn0QiUbP6qeUzy0vHfp/De7Bnrfp9R0VGwmovJy/PjFfn/nlniWsVnCfw2wCQkfyLc/YlBVDWHfLlNlZQflgM1VOGXdwuU= Received: from AM6PR04CA0037.eurprd04.prod.outlook.com (2603:10a6:20b:f0::14) by DB3PR08MB9898.eurprd08.prod.outlook.com (2603:10a6:10:43e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Wed, 28 Jun 2023 13:44:00 +0000 Received: from AM7EUR03FT035.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:f0:cafe::41) by AM6PR04CA0037.outlook.office365.com (2603:10a6:20b:f0::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.19 via Frontend Transport; Wed, 28 Jun 2023 13:44: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 AM7EUR03FT035.mail.protection.outlook.com (100.127.141.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.20 via Frontend Transport; Wed, 28 Jun 2023 13:44:00 +0000 Received: ("Tessian outbound 52217515e112:v142"); Wed, 28 Jun 2023 13:43:59 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 0c163df15ce77150 X-CR-MTA-TID: 64aa7808 Received: from 318ada93779d.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id DA64514C-FE22-49BF-9C9E-0875E7A4A6BE.1; Wed, 28 Jun 2023 13:43:54 +0000 Received: from EUR02-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 318ada93779d.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 28 Jun 2023 13:43:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cT3drSj6GDyHMaULlJ5YSX5xZ53vhGwpUExaw7dXCX2q3pZ2Ls9Jvryo3Q5AK+b9HTTTIGsqm2FTKXIDKcPgCqmiQ5KEsB/WSeOfGfYEe33FhZYrEcpG639DrfqlcqmWMiNrcW0+q4O9Wzdi5jscar4N8ZWuVAXvRFvME9xOrKHVO3wWgp43uxUhpzvbEscN/7UpXx45wVMy/vwN3grWQlaimouIisq7Eb/pw++oS4tpx+67Kf4OsF3rdZ0Wiz2QUPw6n2Rt93OVKHKM/4JrJHL69lviEpgukKEagm1Sdj/PaKbeGd0SBj8PYoGs9ylG0Eu70LGKDe0K+E5bDM2dpg== 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=gPAO0trMrLwudeRQm0bpHCv8dvDT5b4k8dM+EC9afcs=; b=lfuGbU0CkPe+aRe4YGVrzro/15K4yUL3hvNnjncyrRG//zkX/zK8KNofXqegZvl/sNM5dzELM6TBjsatpjrATTHfnjLMVQ7bgqEsPeFKeKL8n1q+F4xXYxMONrnr4/Pz1HOdz63EVcEv2YiQ0tMPt46kuMaaWCcYZnnf//sdPc+AXvQksXf2MDxlTprX7N9YTUVJneELHQeg8dASSH6Mqd1lImGWPTxpa3LHkHc4f32J4LJLEROCv2d7VzhBvKGTz1/poUAMsaf0SZ6Vjsx+mM/0vP5wLB7VeLiriDq3vpVbj4eLX6WQhbryNB5yV7MdpLq7bdX19GU8kVAtiSRd3Q== 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=gPAO0trMrLwudeRQm0bpHCv8dvDT5b4k8dM+EC9afcs=; b=dlGdQviT/MXfGI/+fE1S7iA+5Kxi6mzP0Gggcdhoy8LJXEcqsQ8bbf6z/8Gvm8iPLSCyQslvW83nfZn0QiUbP6qeUzy0vHfp/De7Bnrfp9R0VGwmovJy/PjFfn/nlniWsVnCfw2wCQkfyLc/YlBVDWHfLlNlZQflgM1VOGXdwuU= 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 GV2PR08MB8172.eurprd08.prod.outlook.com (2603:10a6:150:7c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Wed, 28 Jun 2023 13:43:42 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::2301:1cde:cfe7:eaf0]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::2301:1cde:cfe7:eaf0%6]) with mapi id 15.20.6521.026; Wed, 28 Jun 2023 13:43:42 +0000 Date: Wed, 28 Jun 2023 14:43:33 +0100 From: Tamar Christina To: gcc-patches@gcc.gnu.org Cc: nd@arm.com, rguenther@suse.de, jlaw@ventanamicro.com Subject: [PATCH 4/19]middle-end: Fix scale_loop_frequencies segfault on multiple-exits Message-ID: Content-Type: multipart/mixed; boundary="iwPw36o7+estmPDq" Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: DX0P273CA0105.AREP273.PROD.OUTLOOK.COM (2603:1086:300:5c::16) To VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB5325:EE_|GV2PR08MB8172:EE_|AM7EUR03FT035:EE_|DB3PR08MB9898:EE_ X-MS-Office365-Filtering-Correlation-Id: e5ba3a83-8831-4473-145e-08db77ddba5d 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: q7JfLdGkUk+IAZzdiY//hbn/E3AMxLG3BXJmG8PCxaFll9vZ4tZMEPmU5TtPbOtikRLiwV3Z8T11rWOuPCjjs/amObGV1xEoHOA9apngp3zXuy62Pa7rChN853WLh6t1fU9gEA0WFuTkhO2FseYxnmCLbX46dU3nXI+yJFP2XEmR8oNnkEsEGA0Y/3m8kfzlRycBwjlb6swuLfpy+UOUA9gtyvYNCC+oKlDlAcFEX+Ey68aabS1bBtREY704NbB349y6ccP1Dc/adjtV4lSPtsz25v/eF8f9+eAuHbBxNMfV4CKoHIiUOkTwK+E7urZfYdQDPwtLWjrPD7cB43m87xFXHU1v1BfLfoy68PumNLXZbLaK5qtXlsx0+n4JUHf8OK61M9qszfII4XWJf2XOCpvEBQ4kOMW6CTD/IuBG8KZw9sfbeely3RkuveRn77pxl3l/ev7c1TilV1VrHDG+8oTphhS+s19UCrNU/eya5tN0N51BXaRYvsjpoJy82g8h0ReKOVMYjwUyXND/I7XgmMqtUrR5Cs0JlUmT2qkaUmoxnHQGl8CdqN/C1WgV/sj3IWvPclg3ZWV3qKV73APbuxWOQx18/SlxXCf5mMnJlr3oLH1H2C+XknyU5KA/HtUM 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:(13230028)(4636009)(39860400002)(136003)(346002)(366004)(396003)(376002)(451199021)(2906002)(6486002)(33964004)(2616005)(4743002)(44144004)(6666004)(83380400001)(38100700002)(186003)(6512007)(86362001)(26005)(41300700001)(478600001)(36756003)(66556008)(66946007)(316002)(4326008)(6916009)(66476007)(6506007)(44832011)(5660300002)(235185007)(8936002)(8676002)(2700100001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB8172 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: AM7EUR03FT035.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: c257f2d8-f847-422a-ecad-08db77ddafb7 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wC2f9Ubol8eUflD273XDOM1GwpEaOqa7NAD+dURhHgrz5JbMoNIUur23aLc7rGt9HEcapP1LBl3/iRPF4DIi/nysoaRnVPxOaP/yiRUYvYIhS2POUl20W8382PRu2FKro/FSpQqUsO+KKoABOVHvLOH/w2JlH22KtisLtZZj2hZ3DsqrMsBz7uLuKlMPV4D6rgCMDMuRD8wgfe6ldQNzdFsEl76eHHEkjAIGEqqxYjwU6SUTcD+/jdnNssmY9dAJWTCFFk004Iy+mxujDywju3zficmPtj8sdp2ZCA4fPtGp/PCqS+KIvQ86MyRrVT15ZjoH1NndMHR7wx6Vjbx/CdLz410l6EtznjDhPx9R/lbXo4gaIF55OXy6SqoEPN8A6sneSSkOS08McXrNcJbFFNbRaVuG9/U6hBWPmA0OWoDhk4U76ujRgWbnI/IxJLkItsGrCEeX7LWG6wdpkGeNE7IVnUPd02dGR2QmcrVkvmeIuwgpIk6Y/azKVtVbjQFdkitB5J0ISU/5THcC1xbH5g7kG60VpzW6ckohNoL0oARzgj7RTbXbgVpdD87+t22y5GeACdGz6pCdJ1XkCFEjYztEnQrbsQFGq/N6md/MwJfqhfaKl0PzuJ9fILSf7BNwD2G2lG439XeBCm+uj5fvKselAgnDQ8seI3g6rHBmKzDBIGIbIkno4IMACwpQewK8HN4/J4AU+nthkfr3UwvWpoKOJ3Td8FGsiiNiSSjRq5L9+piZIsIw9DCRyNMCP4HHH2H+ASS5//fDjmWqivggmQ== 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:(13230028)(4636009)(346002)(136003)(396003)(376002)(39860400002)(451199021)(40470700004)(46966006)(36840700001)(82310400005)(2906002)(36860700001)(26005)(36756003)(40460700003)(70206006)(44832011)(235185007)(356005)(6916009)(4326008)(8936002)(8676002)(86362001)(316002)(81166007)(82740400003)(5660300002)(70586007)(40480700001)(41300700001)(6486002)(107886003)(47076005)(4743002)(6512007)(186003)(6506007)(33964004)(44144004)(336012)(478600001)(6666004)(83380400001)(2616005)(2700100001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2023 13:44:00.0728 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e5ba3a83-8831-4473-145e-08db77ddba5d 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: AM7EUR03FT035.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR08MB9898 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_NONE,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 List-Id: --iwPw36o7+estmPDq Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Hi All, There's an existing bug in loop frequency scaling where the if statement checks to see if there's a single exit, and records an dump file note but then continues. It then tries to access the null pointer, which of course fails. For multiple loop exists it's not really clear how to scale the exit probablities as it's really unknown which exit is most probably. For that reason I ignore the exit edges during scaling but still adjust the loop body. Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. Ok for master? Thanks, Tamar gcc/ChangeLog: * cfgloopmanip.cc (scale_loop_frequencies): Fix typo. (scale_loop_profile): Don't access null pointer. --- inline copy of patch -- diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc index 6e09dcbb0b1864bc64ffd570a4b923f50c3819b5..b10ef3d2be82902ccd74e52a4318217b2db13bcb 100644 --- a/gcc/cfgloopmanip.cc +++ b/gcc/cfgloopmanip.cc @@ -501,7 +501,7 @@ scale_loop_frequencies (class loop *loop, profile_probability p) /* Scale profile in LOOP by P. If ITERATION_BOUND is non-zero, scale even further if loop is predicted to iterate too many times. - Before caling this function, preheader block profile should be already + Before calling this function, preheader block profile should be already scaled to final count. This is necessary because loop iterations are determined by comparing header edge count to latch ege count and thus they need to be scaled synchronously. */ @@ -597,14 +597,14 @@ scale_loop_profile (class loop *loop, profile_probability p, /* If latch exists, change its count, since we changed probability of exit. Theoretically we should update everything from source of exit edge to latch, but for vectorizer this is enough. */ - if (loop->latch && loop->latch != e->src) + if (e && loop->latch && loop->latch != e->src) loop->latch->count += count_delta; /* Scale the probabilities. */ scale_loop_frequencies (loop, p); /* Change latch's count back. */ - if (loop->latch && loop->latch != e->src) + if (e && loop->latch && loop->latch != e->src) loop->latch->count -= count_delta; if (dump_file && (dump_flags & TDF_DETAILS)) -- --iwPw36o7+estmPDq Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="rb17498.patch" diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc index 6e09dcbb0b1864bc64ffd570a4b923f50c3819b5..b10ef3d2be82902ccd74e52a4318217b2db13bcb 100644 --- a/gcc/cfgloopmanip.cc +++ b/gcc/cfgloopmanip.cc @@ -501,7 +501,7 @@ scale_loop_frequencies (class loop *loop, profile_probability p) /* Scale profile in LOOP by P. If ITERATION_BOUND is non-zero, scale even further if loop is predicted to iterate too many times. - Before caling this function, preheader block profile should be already + Before calling this function, preheader block profile should be already scaled to final count. This is necessary because loop iterations are determined by comparing header edge count to latch ege count and thus they need to be scaled synchronously. */ @@ -597,14 +597,14 @@ scale_loop_profile (class loop *loop, profile_probability p, /* If latch exists, change its count, since we changed probability of exit. Theoretically we should update everything from source of exit edge to latch, but for vectorizer this is enough. */ - if (loop->latch && loop->latch != e->src) + if (e && loop->latch && loop->latch != e->src) loop->latch->count += count_delta; /* Scale the probabilities. */ scale_loop_frequencies (loop, p); /* Change latch's count back. */ - if (loop->latch && loop->latch != e->src) + if (e && loop->latch && loop->latch != e->src) loop->latch->count -= count_delta; if (dump_file && (dump_flags & TDF_DETAILS)) --iwPw36o7+estmPDq--