| Message ID | 20260804003733.89961-1-kvivekananda@nvidia.com |
|---|---|
| State | New |
| Headers |
Return-Path: <gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 798D84BB1C01 for <patchwork@sourceware.org>; Tue, 4 Aug 2026 00:38:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 798D84BB1C01 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=bqkGXDKB X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013004.outbound.protection.outlook.com [40.93.196.4]) by sourceware.org (Postfix) with ESMTPS id 9310A4BA23DE for <gcc-patches@gcc.gnu.org>; Tue, 4 Aug 2026 00:38:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9310A4BA23DE Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nvidia.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9310A4BA23DE Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=40.93.196.4 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785803887; cv=pass; b=dvlY9CKi/Wi8E5Cn/YLwcTCHjhlL+56CJMNAyKz40CSA87UPtWmgchUKDF4JvYrF4fmNkMZNaLpvL2vIbuaNe8ijIxIB61Lbpy1ixbwchPhfG1JDtro7JSu+okiqJdXxhE8xAA7flop3tbocMWWbtNzMVvWqQ+Noaq8rMswZ6kA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785803887; c=relaxed/simple; bh=4d+nZDhWUXsRR6nbVV98pIe9BWgeSYQ5yUlEMcwCfIE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=v/yPMVp5VcKQEZ3yvtPdF5SLeoDlCPkb6QuxhM6tVtxVmIBI6a7HbVgsPBf5IhBmvEvgS2rLWYsSbd7K+ueNd78Porvudx0EhW6Zf8D/eIqWY8nU4v3x6Uie002hRd5qCNXrpBOKK67uSTlbLoBWP/7LQUFvI+PhMThpgZkFN7g= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=bqkGXDKB DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9310A4BA23DE ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ojO946JhNy+JPXgCJ48HBxF4rE+uVIc4oPPMA9iXyvub6LHkU6YKhsu7oPs4SkklVkBQQgWNRJf0h/34Lf+eZSdUPswR+2fB+hCrgzDaWsE2KImXdjwSO/8JrVNxAarGqpHv0zWnFDdHvmtSxi4+yqBwEEnynM4t61mgnrsPZx/POqRo/mCFDZuE49LxeRfFQG6wJYJEUaj2rgrUYmzX9FgspM2wO+Q+WI83dZgMliXCaqe1GiPfQETHqxPcjpe0EQFaU+FC2qkxpXtc5c/7jVXQAZ1CiSKScku2rNvLG5WdFAqzziguEDjkQQonsSPttD9G5HaRYywaz8MNmUn5fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=E7veROPISq8yP9qTEv3BAX+2UJ8FVM3vnF6TRZnaVa4=; b=laXIw84sg2Ija2jzhsTULrlQTfhUb1jnDATPbHR6rHOU+gjvdHELCy5rsVaakTtxGyEv/eEDSN3JKg6vT4XVkJx8Hi70ViGHyYYbqrA0VQSUXTsDjKyH9tI5VcpMUn3U9MkMmSkF2cP6+Rrvpq5v+KAC0tZ0IpSNyha5MFzktignWqJ3DRLExd8QiJ0gDWq9esy5o2XLT7F/APW2nUy45y/Zk1yI7QBY/IgT2Cw7D+Uw6bciAMArEep2x22fRdugBkk61B7ZpsPQs6ipwfQ8y5N6Zbtw22mMAszSN9lkmeJhE5KE8fQFmw6fD063gi2+iINH/iiH5wnVr2x8XEfBxQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E7veROPISq8yP9qTEv3BAX+2UJ8FVM3vnF6TRZnaVa4=; b=bqkGXDKBU3Sb6GwrGqKSMdJIvgcODjUmnNNVcrsJ4EAzrXVKwXSjBQ82UUB/CwZBPyRG8luGHtL0+vcdCTH38mWL6xLPLCoIrvUwMJvdlrtMiyKf7lf/q0sitF0ZHy3uTpaEcRRxvzg2MXOkLsH8mFPa08N9oCSu6zRqwYOpD51D3RVw03Lpuyr2aryzQenVCPb2Pz1Q8PW7X9CwanjmG2ejrwRZYXbz0AIIzG8v1XcFUrLlF2gcD8oB2OJO+slzxlWilcKybxtOLBN0ZqjesdHhjYzY705NajBTQnBaTYdZ5lNWxXX2AFz9vxmhQFJV9w0L/gT4fppwpg0pBWCR/A== Received: from MW4PR04CA0073.namprd04.prod.outlook.com (2603:10b6:303:6b::18) by DM6PR12MB4371.namprd12.prod.outlook.com (2603:10b6:5:2a3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.16; Tue, 4 Aug 2026 00:38:03 +0000 Received: from CO1PEPF00012E60.namprd05.prod.outlook.com (2603:10b6:303:6b:cafe::32) by MW4PR04CA0073.outlook.office365.com (2603:10b6:303:6b::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.17 via Frontend Transport; Tue, 4 Aug 2026 00:38:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1PEPF00012E60.mail.protection.outlook.com (10.167.249.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.8 via Frontend Transport; Tue, 4 Aug 2026 00:38:03 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Mon, 3 Aug 2026 17:37:47 -0700 Received: from nvidia.com (10.126.230.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Mon, 3 Aug 2026 17:37:44 -0700 From: Kugan Vivekanandarajah <kvivekananda@nvidia.com> To: <gcc-patches@gcc.gnu.org> CC: <honza.hubicka@gmail.com>, <kvivekananda@nvidia.com> Subject: [PATCH] [AutoFDO][IPA-CP] Handle zero-caller locals after AutoFDO early inlining Date: Tue, 4 Aug 2026 10:37:33 +1000 Message-ID: <20260804003733.89961-1-kvivekananda@nvidia.com> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.37] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF00012E60:EE_|DM6PR12MB4371:EE_ X-MS-Office365-Filtering-Correlation-Id: 04bb8c14-b560-44e2-3644-08def1c0a4cf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|82310400026|23010399003|36860700016|56012099006|11063799006|10067099003|6133799003|18002099003; X-Microsoft-Antispam-Message-Info: zuenscmcdBDN2KquWgA6Yl0XKifzlA/gzijwOTjQRIsRG8LQwcnpevoFS4rY/jN1zJv6pjaa6s46mKAzqWEWKrnBn0sgoed+ynC2xY39gvWBmWOJ4a+/AbkgD6OhsKrwMu99idni+yU5q58kh5rbFoluDa4+YogBgG/qR9Nik3UB6Kvv8rBTuxXJIIY2OwVPdWkP42Em4JKd4BAcYOSHYFy+uJz9HS8+KyZq48XNmzaR892s1EZOV+PqPnQVVFFquNQ4ovtGjl4xefhqPxeRGyi3cIQko2ZR8XraLjXl/vhgKZVX/T27Tk/DfgZZapRQgn+9Tr3qfWu1e/9NayOqBVGnFcs3vBz/k5fqALcun2GGFcICmgOa9lXg5am0GhmWG3b/9yWFO5wsm4llNdmEYpUc2wFO6n24kD/G27z7XRgb2sw2GHUVFIF6MrEpvBonLFV2XAN02Qw9LXMEi+cjTk9b1A9EyzdR+LJJfRh2ut4BIflC/YwCMUZsIgVuHrzMAofJKYBi39KHZAo1D/Kmds1/DgFn/qeJTslFU3bjQU8bgXIypODvFOwapklJ4uhz96mK4ZN3hdQq5SGt5NGO6K1kyZrKbiBpdnFJ3iGyA3qXqpeADzW4+p0QsYl7ReUgj79OAWC/KIHEVibuYwg1rbtGhxAIgjv0AkLqka0L1UB5d/powQORAa8+BRGSMAOfMBV00lQw5itlaJSYIR7veg== X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(376014)(82310400026)(23010399003)(36860700016)(56012099006)(11063799006)(10067099003)(6133799003)(18002099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UPg05mZYlWcvoxZmNLMnYJQyxgy96W9lV8Daom4iO0/g4LvrOskby5jwN55fYhAEY3SJ+hQrPJlisOXz0EP+Ti5MFAOmlB46hm2O4jWIgtciZMy9s+fGbZzUXD2lVpMJqkJ/1DC/7jZraQVcHT5U+kiE2ZIKJlI4JEe4e48RlP723bpFAt+jd9TjkVi0cEVqCK5bD7P81cdxdOY6b2hHBh2j9GOam5lmGSJib7+MEVrVbSXInTExNkTNRFbxNMTg4oay3w+b53mPQFVB8sHVpf12UvuWrYNW7MxY2HhB3ky7aPiARxaRLHxL7OMMWSdiLRHGJoUGSLFusjVjoYB0lv+/OWDivuwj+mUpbxYE8dgR3UkfMxkho7gfpUj7Lo16cxbDfVkTf54GfTee9sLGjJcOzn9xLRTfwXZu+YnE6DYQtZH7Pt2waAUrOw+lOWSy X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2026 00:38:03.2753 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 04bb8c14-b560-44e2-3644-08def1c0a4cf X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF00012E60.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4371 X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, LOCAL_AUTHENTICATION_FAIL_SPF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org |
| Series |
[AutoFDO,IPA-CP] Handle zero-caller locals after AutoFDO early inlining
|
|
Checks
| Context | Check | Description |
|---|---|---|
| linaro-tcwg-bot/tcwg_gcc_build--master-arm | success | Build passed |
| linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap | success | Build passed |
| linaro-tcwg-bot/tcwg_gcc_check--master-arm | success | Test passed |
Commit Message
Kugan Vivekanandarajah
Aug. 4, 2026, 12:37 a.m. UTC
AutoFDO early inlining can inline all direct calls to a local
function while speculative call promotion keeps the function
address-taken. The function consequently remains in the call graph
with no direct callers, triggering the -ftoplevel-reorder checking
assertion in IPA-CP.
Ordinary IPA devirtualization does not normally produce this state at
IPA-CP: it creates speculative edges before IPA-CP, but those edges are
inlined only by the later IPA inliner. IPA-CP therefore still sees a
direct caller. AutoFDO instead performs speculative inlining early, so
only its IPA_REF_ADDR may remain by the time IPA-CP runs.
When AutoFDO inlining is enabled, recognize zero-caller functions that
cannot be removed after their direct calls disappear and initialize
their lattices as variable. Preserve the assertion for removable
locals and non-AutoFDO compilation.
gcc/ChangeLog:
* ipa-cp.cc (initialize_node_lattices): Handle zero-caller local
functions left after AutoFDO early inlining.
Regression tested on aarch64-linux-gnu with no new regressions
Signed-off-by: Kugan Vivekanandarajah <kvivekananda@nvidia.com>
---
gcc/ipa-cp.cc | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
Comments
Hi, On Tue, Aug 4, 2026 at 2:38 AM Kugan Vivekanandarajah < kvivekananda@nvidia.com> wrote: > AutoFDO early inlining can inline all direct calls to a local > function while speculative call promotion keeps the function > address-taken. The function consequently remains in the call graph > with no direct callers, triggering the -ftoplevel-reorder checking > assertion in IPA-CP. > > Ordinary IPA devirtualization does not normally produce this state at > IPA-CP: it creates speculative edges before IPA-CP, but those edges are > inlined only by the later IPA inliner. IPA-CP therefore still sees a > direct caller. AutoFDO instead performs speculative inlining early, so > only its IPA_REF_ADDR may remain by the time IPA-CP runs. > > When AutoFDO inlining is enabled, recognize zero-caller functions that > cannot be removed after their direct calls disappear and initialize > their lattices as variable. Preserve the assertion for removable > locals and non-AutoFDO compilation. > > gcc/ChangeLog: > > * ipa-cp.cc (initialize_node_lattices): Handle zero-caller local > functions left after AutoFDO early inlining. > I think the problem here is earlier. If function is local, it can not be called indirectly and thus it makes no sense to add speculative call to it. I am not sure how the auto-FDO profile data got to a conclussion that the function can be called indirectly - I can see it can be triggered when source code changes between train run and compilation. Can you perhaps check what is happening and if something like this works? diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc index 6aa5166c748..63ca8938146 100644 --- a/gcc/auto-profile.cc +++ b/gcc/auto-profile.cc @@ -3326,6 +3333,14 @@ afdo_indirect_call (gcall *stmt, const icall_target_map &map, afdo_string_table->get_symbol_name (max_iter->first)); return false; } + if (direct_call->local) + { + if (dump_file) + fprintf (dump_file, "AFDO Indirect call target %s " + "is local and thus can not be called indirectly\n", + afdo_string_table->get_symbol_name (max_iter->first)); + return false; + } callee = gimple_call_fn (stmt); > > Regression tested on aarch64-linux-gnu with no new regressions > > Signed-off-by: Kugan Vivekanandarajah <kvivekananda@nvidia.com> > --- > gcc/ipa-cp.cc | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc > index c1b1f6201fd3..d68952ec8711 100644 > --- a/gcc/ipa-cp.cc > +++ b/gcc/ipa-cp.cc > @@ -1443,7 +1443,18 @@ initialize_node_lattices (struct cgraph_node *node) > NULL, true); > else if (caller_count == 0) > { > - gcc_checking_assert (!opt_for_fn (node->decl, > flag_toplevel_reorder)); > + /* With -ftoplevel-reorder, a local body with no direct callers > + should already have been removed. AutoFDO early-inline of a > + speculative call expands via gimple_ic (&target), so after all > + direct call edges are inlined the local can remain > address-taken > + with unknown indirect uses; treat that as VARIABLE. Ordinary > + IPA devirtualization does not need this exception: it creates > + speculative edges before IPA-CP, but inlines them only later, > so > + IPA-CP still sees a direct caller. */ > + if (!(flag_auto_profile && flag_auto_profile_inlining > + && !node->can_remove_if_no_direct_calls_p (false))) > + gcc_checking_assert > + (!opt_for_fn (node->decl, flag_toplevel_reorder)); > variable = true; > } > } > -- > 2.34.1 > >
diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index c1b1f6201fd3..d68952ec8711 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -1443,7 +1443,18 @@ initialize_node_lattices (struct cgraph_node *node) NULL, true); else if (caller_count == 0) { - gcc_checking_assert (!opt_for_fn (node->decl, flag_toplevel_reorder)); + /* With -ftoplevel-reorder, a local body with no direct callers + should already have been removed. AutoFDO early-inline of a + speculative call expands via gimple_ic (&target), so after all + direct call edges are inlined the local can remain address-taken + with unknown indirect uses; treat that as VARIABLE. Ordinary + IPA devirtualization does not need this exception: it creates + speculative edges before IPA-CP, but inlines them only later, so + IPA-CP still sees a direct caller. */ + if (!(flag_auto_profile && flag_auto_profile_inlining + && !node->can_remove_if_no_direct_calls_p (false))) + gcc_checking_assert + (!opt_for_fn (node->decl, flag_toplevel_reorder)); variable = true; } }