From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8D39CF318A for ; Tue, 1 Oct 2024 22:57:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 302DE68002E; Tue, 1 Oct 2024 18:57:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D92C68002B; Tue, 1 Oct 2024 18:57:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 154A968002E; Tue, 1 Oct 2024 18:57:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id EA2EE68002B for ; Tue, 1 Oct 2024 18:57:21 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9DA65140619 for ; Tue, 1 Oct 2024 22:57:21 +0000 (UTC) X-FDA: 82626546282.01.E1436A5 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) by imf30.hostedemail.com (Postfix) with ESMTP id BCC4780008 for ; Tue, 1 Oct 2024 22:57:19 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=rowland.harvard.edu header.s=google header.b=ANkJtuSC; dmarc=pass (policy=none) header.from=rowland.harvard.edu; spf=pass (imf30.hostedemail.com: domain of stern@g.harvard.edu designates 209.85.222.175 as permitted sender) smtp.mailfrom=stern@g.harvard.edu ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727823336; a=rsa-sha256; cv=none; b=79jM/KsCXaF7Oku6zBt2UAwhCHBRgKjZu06bmlhd+e/3gVe2MkIh6PHpJ7jeC48qkpfDHh Fe5ONVl8dG7vW1nHU9XI/cuvjbIjb4+Ytjamt3T/eBdAJUUQ3Jdg10TWlgNVj8ZKcF0r9s dS1AJPpLI4O3SwD5MsC9Gdp5rfm3ojg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=rowland.harvard.edu header.s=google header.b=ANkJtuSC; dmarc=pass (policy=none) header.from=rowland.harvard.edu; spf=pass (imf30.hostedemail.com: domain of stern@g.harvard.edu designates 209.85.222.175 as permitted sender) smtp.mailfrom=stern@g.harvard.edu ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727823336; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rspeAAc+JRCDmaTUx2qdwPB8gp+dYPhnD00JvbaW/TA=; b=SkY/4U86KPlsbBVnjsmsNYJJw7dB/7fzqNvnt/FKdhXAcUyydoPk41/GjvMTX4ab2pT5Wm Lerxd3emeA3sCBtMnFL/I10Z/IvyviFD8ak4aOxo8he3CYqaydPEgMjc8VPDxZ4iHxPsRj /Vf8H5i2QXpvQRl6cQ0207t1CENJGlw= Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-7a9ad8a7c63so610538085a.3 for ; Tue, 01 Oct 2024 15:57:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rowland.harvard.edu; s=google; t=1727823439; x=1728428239; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=rspeAAc+JRCDmaTUx2qdwPB8gp+dYPhnD00JvbaW/TA=; b=ANkJtuSCaACh+0J0V9i7kW3h1zxhpNrjFQWXafqwoPUsXzjA9Zny2bVAi0oubMFTHv B37dMFX8mYnOFpoPnEj7FIG0NVjor8Z38VLuMzPfTaU/shafvziEYsS1670bxW/ZKTSm /65NrXwUph1BznFMZ+wSlXWYiS1dR6iTEMQq4hNi0TzK2YpMB/+1de9qeGMFC49dci/I t6cKQdh7BAdPmKV91a/ZV8u85zoy3VP3lRuZY0alExiEXmdGbaZbeAp/42xH1xJ+g0x0 ujHt+8NpTx+oUbw8QEl57bxpala2VlN5nPcMQMMFpJ3146+VHwW4aBnzKURZi+2k2+jp n3Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727823439; x=1728428239; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rspeAAc+JRCDmaTUx2qdwPB8gp+dYPhnD00JvbaW/TA=; b=IASZ6Yyr4Bs32FOcvvSC02RtS9XbhjyAHUD+HqxQoU8b0MYqfaMyAk4gY8KJcxcKH8 qostU6Z5e3MbuTBXV84U1MfJkGMaOnC/gDqt6xkeB7ylCviBUVdQ0IYN3BkOPnCDCCCU Be6EQFWkeOz5Q/W/A5vRteRDIPXapYLVoZXRsYVKgGrOHrigeimOK1shbsMEMrST9yKC RvpPbKbSwPG2bFZFwTbayReT3AQfxtLffS/AfT+ViVIVn6EzYGexDAgqTVG1vU1bn1xH Nsf0xdeob+/EP/K0K5u7gJewGxddxtul3SDEJwIm++AwM/A4PxdpfyOgmvheZD6lKpU0 u0bQ== X-Forwarded-Encrypted: i=1; AJvYcCX59r2zy9j9+/JsI54Es7IHK+UaCEIQnXNyC7M9ZLvGxN0ZUkeSioZfvSGIBpcoP2tEUvgfRMYFLQ==@kvack.org X-Gm-Message-State: AOJu0YyCmB06z0TGf8tdqoh/S/SBJUNaaywQx0v1G7tzHkgUyYv6QHTg b6QhnjGhFR0ULRPvy5OcXlLcfPYE6dwcxkfUsqyeoNd5069hgkwF2MWEepB9EA== X-Google-Smtp-Source: AGHT+IGe8hLbudtLqVw4HA3bUOj2VieZ0OvJdesAxdCUKIxBnEyri8YwqF4MHDxHD5sCjFwTNkPfnQ== X-Received: by 2002:a05:620a:4490:b0:7a9:ada6:86c9 with SMTP id af79cd13be357-7ae626c541dmr193649085a.26.1727823438802; Tue, 01 Oct 2024 15:57:18 -0700 (PDT) Received: from rowland.harvard.edu ([2601:19b:681:fd10::5638]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7ae3782c6c0sm548321285a.88.2024.10.01.15.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 15:57:17 -0700 (PDT) Date: Tue, 1 Oct 2024 18:57:13 -0400 From: 'Alan Stern' To: David Laight Cc: Jonas Oberhauser , Mathieu Desnoyers , Linus Torvalds , "linux-kernel@vger.kernel.org" , Greg Kroah-Hartman , Sebastian Andrzej Siewior , "Paul E. McKenney" , Will Deacon , Peter Zijlstra , Boqun Feng , John Stultz , Neeraj Upadhyay , Frederic Weisbecker , Joel Fernandes , Josh Triplett , Uladzislau Rezki , Steven Rostedt , Lai Jiangshan , Zqiang , Ingo Molnar , Waiman Long , Mark Rutland , Thomas Gleixner , Vlastimil Babka , "maged.michael@gmail.com" , Mateusz Guzik , Gary Guo , "rcu@vger.kernel.org" , "linux-mm@kvack.org" , "lkmm@lists.linux.dev" Subject: Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency Message-ID: <2b1caba3-48fa-43b9-bd44-cf60b9a141d7@rowland.harvard.edu> References: <20240928135128.991110-1-mathieu.desnoyers@efficios.com> <20240928135128.991110-2-mathieu.desnoyers@efficios.com> <02c63e79-ec8c-4d6a-9fcf-75f0e67ea242@rowland.harvard.edu> <9539c551-5c91-42db-8ac1-cff1d6d7c293@huaweicloud.com> <2cdda043-1ad9-40cf-a157-0c16a0ffb046@rowland.harvard.edu> <5d7d8a59-57f5-4125-95bb-fda9c193b9cf@huaweicloud.com> <82e97ad5-17ad-418d-8791-22297acc7af4@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BCC4780008 X-Stat-Signature: g1qhdpu15ot8cut9xbfsy1ex6x6j3e65 X-Rspam-User: X-HE-Tag: 1727823439-338569 X-HE-Meta: U2FsdGVkX19z0SGE7UUW/edVALkLP6322Pl41nJAiuk74iEwLz64Mjk6vJSsFzJaZQXt6BAi7h8D2AQPpQlV0RBN1/pu28g52ZU/eE1o3AJxCQtRpMa1xc02EQ8lLJgvEm6qGlx/g0A5y3+zZuqL+O7z2b5/j0xYWASnY1izrKRyozjuvu+5FvsqLstR1aSLXFSFRiLlxkU0+diAcAPgayHbQjw9pxeLgNjFCL7hludc8XosHJbrGSWjc3dCHfJ+JdX5Yic18y0BLxZrZoqD+cPXO4s28Uzuz9+SW2asGr7MJCJJValGrt3At05aKskuy7N+G0olz4YwcY63+KVJBT/QG7WichXu5NCEI+dI/3VY4OPogVY9jxJw3vt/6NESJobDkPWBYuQaJQNGa308WP7cfsoa8NnLnNBXwwEQiMRWeOL/WtM3uVRLYt4/72BCTi7NnlZ1+JkjDgHA5d8rkb17JaptrDdGolE/iVBxWUPowjlO1xjOX9XJuT96InqQ8Ddt+i+1V49XzORIRrZgWiD2uG2iL2RYIWcbg32kvpzz7RZOz3MXy8/5dRji6gxtyK1XG08gA7Q+jT3NWGF1sPeKaWab8AW2EkD+IdJQUfXqpvkZGXro21JmX4H0vUqrjjDplbrrHnaS86Rtv6wFWqIJ5z7YQnJDiwZnUbxSj17O4Ejagd6dtHrqqUBk2SBJzl1KoagANFckcf5zLBKuwofP5VNWYT7Tnkfy591mhkoVYNaV/gUX0KiOghClZOMKYEzutOT9qfYjGW+2xp8qhgkdlTjTkcwKK8pUrugzMR2lnpacHbddeJPlX/6dgD+SkQDKYP35/0D09n71S7Vft1Yf/ZCjRi172iWxXV3dZgpqzRwrXMOPpbBAJqsee9TUOKzKkr6vjNPfxGrMJxFNJbjR8M6nWKaEugs2dU4/iOadLkUCQQf0vwaWwY484PuRk4mLh79CLX3EM5+hIzL TOdzZYQ0 mVOYs4L3YyB2IB5DRam1+gb7AE+VZqRlFFQyYPw+npvkfGh8yLiyUcCs2Gz4zTJQWqpbGSB5yqUfRBuicG0z3TrZCO0OtdT94jk8cZJ1eNXOCpBSCSx+rWPcRTFaLMPnYHcQ5fDS/02IcItMNxpAP15XwEALx1H/WrnN7nHoO8BiWqAEyZUGnxy/s4S1uMejY2OMusR5Nza3fzKf226JX7oCRfQoyZ8v/4YxI7KktUR/Sut+ujNF3LS/xJAnBEA+Baf0IQwbJtiGQ7u0blnjAUtSV28ITGkQ27UWn+oazmUhUGrPyxKncIb0nOA1BbLr+gm3XXQX8CfyHF40ZXMSoibH/gbx9AAGvsraU5rooeD9Z6k8gKGBDEALr++gL1RwfGVngd2TLFReBx0jOuSh15Lqileu0iMWHrxGOCBBoLnzG2u+UOC2Jw6kqbuivbccq/y+y3PXiJ5lb5tYAjXqOsTAKD+fk1TWi5sXeKrfq8k96mLCLMCU9eWck1nA34vvbKiXnKE8Dx1mQ6gGgQGeZQ1ph1uyoDjYYeVOk5Mb3GSVpBsedV9ZvJMfVbPSUTLR8xKumW9282m6PiVzh/W6xF3W66aiD6xaMPf00Tjqa6J1t86Z4wC5zyB3DQrtG5VCGSUGxdvDU5CKgcKAzuJo0VdxiwTWVCJUwP9fQ+aVJJclkarIsNSGox3r0PZS/7LNVBBYBTVLsySg01A8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Oct 01, 2024 at 05:11:05PM +0000, David Laight wrote: > From: Alan Stern > > Sent: 30 September 2024 19:53 > > > > On Mon, Sep 30, 2024 at 07:05:06PM +0200, Jonas Oberhauser wrote: > > > > > > > > > Am 9/30/2024 um 6:43 PM schrieb Alan Stern: > > > > On Mon, Sep 30, 2024 at 01:26:53PM +0200, Jonas Oberhauser wrote: > > > > > > > > > > > > > > > Am 9/28/2024 um 4:49 PM schrieb Alan Stern: > > > > > > > > > > I should also point out that it is not enough to prevent the compiler from > > > > > using @a instead of @b. > > > > > > > > > > It must also be prevented from assigning @b=@a, which it is often allowed to > > > > > do after finding @a==@b. > > > > > > > > Wouldn't that be a bug? > > > > > > That's why I said that it is often allowed to do it. In your case it > > > wouldn't, but it is often possible when a and b are non-atomic & > > > non-volatile (and haven't escaped, and I believe sometimes even then). > > > > > > It happens for example here with GCC 14.1.0 -O3: > > > > > > int fct_hide(void) > > > { > > > int *a, *b; > > > > > > do { > > > a = READ_ONCE(p); > > > asm volatile ("" : : : "memory"); > > > b = READ_ONCE(p); > > > } while (a != b); > > > OPTIMIZER_HIDE_VAR(b); > > > return *b; > > > } > > > > > > > > > > > > ldr r1, [r2] > > > ldr r3, [r2] > > > cmp r1, r3 > > > bne .L6 > > > mov r3, r1 // nay... > > > > A totally unnecessary instruction, which accomplishes nothing other than > > to waste time, space, and energy. But nonetheless, allowed -- I agree. > > > > The people in charge of GCC's optimizer might like to hear about this, > > if they're not already aware of it... > > > > > ldr r0, [r3] // yay! > > > bx lr > > > > One could argue that in this example the compiler _has_ used *a instead > > of *b. However, such an argument would have more force if we had > > described what we are talking about more precisely. > > The 'mov r3, r1' has nothing to do with 'a'. What do you mean by that? At this point in the program, a is the variable whose value is stored in r1 and b is the variable whose value is stored in r3. "mov r3, r1" copies the value from r1 into r3 and is therefore equivalent to executing "b = a". (That is why I said one could argue that the "return *b" statement uses the value of *a.) Thus it very much does have something to do with "a". > It is a more general problem that OPTIMISER_HIDE_VAR() pretty much > always ends up allocating a different internal 'register' for the > output and then allocating a separate physical rehgister. What output are you referring to? Does OPTIMISER_HIDE_VAR() have an output? If it does, the source program above ignores it, discarding any returned value. > There doesn't seem to be a later optimisation path to remove > 'pointless' register moves. That would be a good thing to add, then. Alan