Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2110778imu; Sat, 22 Dec 2018 12:28:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vg68e5pyp1j6I5OpEKpuMF29mlAT9h/YEeEX3ZEIzTFjNMx6al+Km2gK/AM7+91U9rGFRA X-Received: by 2002:a62:5a03:: with SMTP id o3mr7646455pfb.19.1545510531123; Sat, 22 Dec 2018 12:28:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545510531; cv=none; d=google.com; s=arc-20160816; b=zSiAMUYNmCVNGYd1DjxupDI3gXHuzq9XXbC5UUr9HOSXxKbYAyx1B3rmOx1y9AqDhu JpaLwqaydhmAmHrk+6aSf0la0hHkdtEitoWVhO8u/Co/1+lZ9gs1vJCn2Hjvdw9lQvpE RFSZS+B6/A2ac0CrDUKA1Qvbx2L9T7+By4x/7aKbPMzc2oC66Iopn2WDvFGgmnSMjhhU 1GLjZj3RUnkk/la0LbKiKy+dX4UZrTyUesCWNUHVRwLVJlt2wsB36w8SPUc15RIHXH+L 2FrWLFlNH+VYxhWSetVX/XPKatwLXQc6081vqm9qTzw5GTnTDk1Vwi4fZMlxg/RI8IX6 Fzlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=j9jXT0l41b6dC5FPey51ZzmQvMqx7keU3HGzws5IUI0=; b=TtC+SOuyV4IUM+vQOJE3MYds1XrOD7odu2ZxieYTtvShXi9Sqls00qqxn1U8KYLcWY JtHtrJm0ZHECe8s9CpWk91O+6U1UyZ6qNF4eTd3cGduvRKVKouCYmmKHxbM6bJuYdHsH vIEKoXQGJeTcsdbdDuJXXo2mc1mZ4OEIOPNV/x04K34M0nqESSlIO1GVHVvr5ULdQ3k/ FunhQy2NDcVQxU2DcvEZG5n+awrk4DeTX008TPxUBJCPpgeu6e3tlAcvJWG+y930LLtB 8K1+rpgT2AH0FCeHK3JqmXseAZbora4FNI4g/Dh/0FcSnstmxElfDS5o510oB9iYfd3i IGfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i63si23417869pge.515.2018.12.22.12.28.24; Sat, 22 Dec 2018 12:28:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732728AbeLURUq (ORCPT + 99 others); Fri, 21 Dec 2018 12:20:46 -0500 Received: from mga11.intel.com ([192.55.52.93]:54995 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731600AbeLURUp (ORCPT ); Fri, 21 Dec 2018 12:20:45 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Dec 2018 09:20:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,382,1539673200"; d="scan'208";a="305773566" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.137]) by fmsmga005.fm.intel.com with ESMTP; 21 Dec 2018 09:20:44 -0800 Received: by tassilo.localdomain (Postfix, from userid 1000) id 69927301036; Fri, 21 Dec 2018 09:20:44 -0800 (PST) Date: Fri, 21 Dec 2018 09:20:44 -0800 From: Andi Kleen To: Peter Zijlstra Cc: Arnd Bergmann , Nicolas Pitre , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Paul McKenney , Will Deacon , Ingo Molnar , Thomas Gleixner , hubicka@ucw.cz Subject: Re: [PATCH 0/7] ARM: hacks for link-time optimization Message-ID: <20181221172044.GE25620@tassilo.jf.intel.com> References: <20180220215954.4092811-1-arnd@arndb.de> <20181217225020.GA16520@hirez.programming.kicks-ass.net> <20181218000800.GB25620@tassilo.jf.intel.com> <20181218091824.GI2218@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181218091824.GI2218@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > In particular turning an address-dependency into a control-dependency, > which is something allowed by the C language, since it doesn't recognise > these concepts as such. > > The 'optimization' is allowed currently, but LTO will make it much more > likely since it will have a much wider view of things. Esp. when combined > with PGO. > > Specifically; if you have something like: > > int idx; > struct object objs[2]; > > the statement: > > val = objs[idx & 1].ponies; > > which you 'need' to be translated like: > > struct object *obj = objs; > obj += (idx & 1); > val = obj->ponies; > > Such that the load of obj->ponies depends on the load of idx. However > our dear compiler is allowed to make it: > > if (idx & 1) > obj = &objs[1]; > else > obj = &objs[0]; > > val = obj->ponies; I don't see why a compiler would do such an optimization. Clearly the second variant is worse than the first, bigger and needs branch prediction resources. In fact compilers usually try hard to go into the other direction and apply if conversion. Has anyone seen real world examples of such changes being done, or is this all language lawyering theory? -Andi > > Because C doesn't recognise this as being different. However this is > utterly broken, because in this translation we can speculate the load > of obj->ponies such that it no longer depends on the load of idx, which > breaks RCU. > > Note that further 'optimization' is possible and the compiler could even > make it: > > if (idx & 1) > val = objs[1].ponies; > else > val = objs[0].ponies; > > Now, granted, this is a fairly artificial example, but it does > illustrate the exact problem. > > The more the compiler can see of the complete program, the more likely > it can make inferrences like this, esp. when coupled with PGO. > > Now, we're (usually) very careful to wrap things in READ_ONCE() and > rcu_dereference() and the like, which makes it harder on the compiler > (because 'volatile' is special), but nothing really stops it from doing > this. > > Paul has been trying to beat clue into the language people, but given > he's been at it for 10 years now, and there's no resolution, I figure we > ought to get compiler implementations to give us a knob.