From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80074.outbound.protection.outlook.com [40.107.8.74]) by sourceware.org (Postfix) with ESMTPS id 65E833858024 for ; Thu, 3 Dec 2020 12:29:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 65E833858024 Received: from AM6P193CA0047.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:8e::24) by AM0PR08MB5362.eurprd08.prod.outlook.com (2603:10a6:208:180::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17; Thu, 3 Dec 2020 12:29:19 +0000 Received: from AM5EUR03FT041.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8e:cafe::99) by AM6P193CA0047.outlook.office365.com (2603:10a6:209:8e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Thu, 3 Dec 2020 12:29:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;gcc.gnu.org; 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT041.mail.protection.outlook.com (10.152.17.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Thu, 3 Dec 2020 12:29:18 +0000 Received: ("Tessian outbound 39646a0fd094:v71"); Thu, 03 Dec 2020 12:29:18 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d0d93fa881cb0e5a X-CR-MTA-TID: 64aa7808 Received: from b66e498277d1.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D37676DA-9F74-4D3A-ABCF-F3E5A31D8A2B.1; Thu, 03 Dec 2020 12:28:51 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b66e498277d1.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 03 Dec 2020 12:28:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b4Tq2MrQS9mi7bgHSRvFtBo9ezt+r/uDm6vUirztq8BUbTS7UanzkO+DoMocctV05z5O6GWYbNG/SZbdH1pTy5FRDNyRnOGViitOQ9H5JW5TbGMiEoV7Gzv4PUpxu9jMUh8d4Rr4dDz/qafEs3WcQYchUggwpnqk7LCiCC5d+SpH8Tbjxc1uEQuFzO40hC6nIV+cY5L96YXUAL99qcwFiaYGlhaxo4igGMrvwOpllkWUi+0TinYLaEsk3pNWPmJjCft9RFgsWP4wBunXcc4qVak4dv7qTMpmogyJrQhEbdU5C4pAV+g0Hc2c8MHPWchREwpLAMGZhJcn0mA9labzyw== 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-SenderADCheck; bh=eAfqZQAIO+zdzPEl7gYCuhpusEaPVZ55vvKxRXCpDfI=; b=O+cEwMynqfvVIszdntR6IiICMfBsSMf++oyIDrKzxq9pI8ANY0HXwSA2ddJBscSmcPtPHqepN6TIrXUiO/YibzsiXTxWUwmVDnZ1opm+J/Mu40grOgCmpICtEaNdq3VtAMEpzYmoh0T9ndeB9EKtEXYq3HwL18miXe4c46aUG8DPMBJGwrwdTaiJi0unXyaLUnCrDdz+DPKUf0/lzRR4Ml1R1xzseBrJnu+wJ9Ltk/xOv6NvexqVJ01KVuHzBDws0yiqsQtJpI0Y97/5BxeZQQYEk6xP0KmLl2Oe1ssMFYr3PIluIhfFOiCUY4MEjmU2NtM7vLM42xckF3raqskH/w== 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 Authentication-Results-Original: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB4900.eurprd08.prod.outlook.com (2603:10a6:20b:cc::10) by AM6PR08MB4673.eurprd08.prod.outlook.com (2603:10a6:20b:c4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.25; Thu, 3 Dec 2020 12:28:50 +0000 Received: from AM6PR08MB4900.eurprd08.prod.outlook.com ([fe80::5805:be9:d66d:7b65]) by AM6PR08MB4900.eurprd08.prod.outlook.com ([fe80::5805:be9:d66d:7b65%7]) with mapi id 15.20.3632.019; Thu, 3 Dec 2020 12:28:49 +0000 From: Andrea Corallo To: Richard Earnshaw Cc: gcc-help@gcc.gnu.org, nd@arm.com Subject: Re: Correct way to express to the compiler "this does not get clobbered"? References: <15f8e09a-9d21-f8f6-8611-2845bd8bc74e@foss.arm.com> Date: Thu, 03 Dec 2020 13:28:48 +0100 In-Reply-To: <15f8e09a-9d21-f8f6-8611-2845bd8bc74e@foss.arm.com> (Richard Earnshaw's message of "Thu, 3 Dec 2020 12:04:12 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Content-Type: text/plain X-Originating-IP: [217.140.106.37] X-ClientProxiedBy: LO2P265CA0017.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:62::29) To AM6PR08MB4900.eurprd08.prod.outlook.com (2603:10a6:20b:cc::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from e124257 (217.140.106.37) by LO2P265CA0017.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:62::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Thu, 3 Dec 2020 12:28:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9766f895-01b6-43f0-c169-08d897870e4c X-MS-TrafficTypeDiagnostic: AM6PR08MB4673:|AM0PR08MB5362: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:6430;OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: wx8zmtU7pxJZR5fKrhCdervYdK6JgJD2InjJgxoOL+VkCzfsvdcYqkqbGQNmwv4JzCRTwcuiXEW+s0cl6fiFxso/sxs5k6+6uHi+74NdHcGaF19qccz3Jq4/ezUpcgah4Mof2crxH9UPVAoxyEit/5EZpYVhYUAYbKcv7eeWDizNyqLOSnR48hVXFtJ0YBDwULppUMY+XhxGuyrGHdVpCE+aJyptzIkO3zKUsP1cHDlZ+YtnDBb41a3klgXxtf73T5pR0nUoHMtHDNE7si5ft+crrohHTpneJ7SHMt9V+t+ukp+fVduF+vr4vMyuLnjhpG+zJlfXaDxS8k8Rpbppp71q0bh+TZk+E/45znf3NKgMh6FhR1Us8nlEb6u0PfEf X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB4900.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(396003)(376002)(136003)(366004)(39860400002)(478600001)(53546011)(8936002)(2906002)(6496006)(44832011)(8676002)(52116002)(26005)(16526019)(186003)(316002)(4326008)(956004)(66556008)(6486002)(6862004)(86362001)(5660300002)(2616005)(66946007)(66476007)(36756003)(43043002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?AY3+oEpebUUamRHUjhX1Vd4hnOHXAO6/bj7Ecvl0pvSSHrt93wAUrp5h4Lcu?= =?us-ascii?Q?RFp8rTxVxF74rWzFKoL8iK+qXWf20ijeIVBZ8s1ayQF+11wl3jPbaBIl8Mf5?= =?us-ascii?Q?QJN5tpNjEFYOhh0pQk+WeEXqOzg5KnzKApsDBzDJTK6Kcc5DIqenFdAM16Ug?= =?us-ascii?Q?9xjJGft1TWFXnQRJFxK857zgQPBBnAIxNjHdmZi3/Oe1snIfv8eqBUGboLgT?= =?us-ascii?Q?tlXOaYdviVfKAkpOqPwKaYJhRU6A9VJ346XDI63y5zmOF64yDNqEsD1RCBF+?= =?us-ascii?Q?sKhI69IyWIYXGO2+lsjtUfuSONPwgEzSqvQkIkRe58L7d9SIKEAxwOVf2gVh?= =?us-ascii?Q?VHH/zzuokMH+STZIxR091lxH0rUA7hG8vNz5kvKingNUNliXQGl4c58guSie?= =?us-ascii?Q?sfpTOJPA5/yUDsmsZdaQA2suBg81Y6bbr8dVczIBOKQEi4MzFR9owmnZghd2?= =?us-ascii?Q?ntbECIjNwGpwtDDCDdSeYTcgMBeig1XHCXlpBrdFC1ucHl+8H0hBEryh1x2e?= =?us-ascii?Q?WjuH4KU+IVrjaEZo1NGUzgWyMHtuSvl4D1AUy1ol6t4NnCgYhu0BA425nA9Q?= =?us-ascii?Q?uJfTljovGX1RJ/nBGi/2VgA6qoAKsrzhUN9FnwUiuLdPIH8MTP4Lw0ZA4Mx/?= =?us-ascii?Q?5MupYAdSaExm2jD6dss9V2YFH040t6FzWjcWFNRImimp12mm4ut5sUHwoPGI?= =?us-ascii?Q?mpQ3byv7K4ADEfhtFIvBai2FzJlaGCY5nJgkyBWMxZQF70iNchO/U3/ISVeO?= =?us-ascii?Q?0qZUPD4MXf0ztig9pX6TxFFYxbYApv+hRP5Mb0oWmXiRwKJ8PA9VK1acmsCe?= =?us-ascii?Q?kaNNWIwzYc36i3Ly4jtE4kjCLsIwwvia5o6agttEfU2QvFW3xNereX2eSGet?= =?us-ascii?Q?FciZ8PSYA7ZlBUV8YO/xxzaZtK19RYTvc7ondlf85XlRHmi4I2EH7QrkDwbr?= =?us-ascii?Q?TWxyAzZ/Y7jqT+r2GJF2619B5yKjyHcxDol7WdkeKTrzKGZxIvF678UDtYPw?= =?us-ascii?Q?2zyv?= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4673 Original-Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT041.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 555246d7-a4d9-496a-208d-08d89786fce1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mJznkpHh/9kqXDUiA0oWRfYMv2WVTSszTUENU/ckNPJMmL1qVqobvBm6JlVTMP/wwltcQ+qL0Vkix8b+6/1AE/neCtnV7UswECme9YQ8Q6BuY0adGlqXfI8P73uPXOjK/i0YExqay+Mj1UTbTQN6rHtsXyFk2tSvSG9b49RTNIxd0e603aYtnPtesvZtxy4GaF2NW5RFy3jPE7hlczpUx67pG+DvRNxoO+o4a21t4OFjxJs8H7dQD4kAYaDuemu1QdaLA5N0Uv3y5yC7va8s/cEtCdGRWbF0uWevLHD7PbVwPlrTAhfKsHkUbGiXXAmE+AmDy06Uq9Hc0tuuMAfV+gjniVYgP+Hqm61rUxxyfyUuWhrH/ekjGBT9/giIYG3pCp0MlcFVv1FDIOOxtXucXX5gtIxLTziThTA9a/JYHoM= 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:(4636009)(136003)(39860400002)(396003)(376002)(346002)(46966005)(70586007)(2906002)(70206006)(47076004)(82740400003)(5660300002)(186003)(4326008)(16526019)(36756003)(6862004)(336012)(26005)(86362001)(8676002)(6496006)(478600001)(53546011)(36906005)(316002)(2616005)(6486002)(956004)(8936002)(44832011)(82310400003)(81166007)(356005)(43043002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2020 12:29:18.8655 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9766f895-01b6-43f0-c169-08d897870e4c 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: AM5EUR03FT041.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB5362 X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Dec 2020 12:29:23 -0000 Richard Earnshaw writes: > On 03/12/2020 11:47, Andrea Corallo via Gcc-help wrote: >> Hi all, >> >> I've a piece of code that reduced looks like this: >> >> #+begin_src C >> typedef struct { >> void (*fun_ptr)(void); >> } x_t; >> >> x_t *x; >> >> void >> f (void) >> { >> const x_t const *y = x; >> for (int i = 0; i < 1000; ++i) >> y->fun_ptr (); >> } >> #+end_src >> >> What is the correct way (if any) to express to the compiler that the >> value of y->fun_ptr does not get clobbered by the function call itself >> so the corresponding load to obtain its value can be moved out of the >> loop? >> >> My understanding is that the const qualifier is more for diagnostic >> reasons and is not sufficient for GCC to make this assumption. OTOH I >> cannot give 'fun_ptr' the attribute pure as it's not. >> >> Thanks >> >> Andrea >> > > Why not just put the function pointer in a local variable? Then the > compiler will know that the value can't change. Hi Richard, yeah that would do the job. This is generated code and changing the code generator that way might not be completely trivial (e.g. where is the best position to perform the assignments to each local variable?). Therefore before going for this solution I'd like to be convinced there's no way to express this directly to GCC. Andrea