Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1968200imu; Sat, 22 Dec 2018 09:10:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN7wBBGGpu8e3rCJ98Q/Ku27EW9rhAzQnBz2rgCOsERToCQIrBdBakmXMVLL8j1wwPJghVxU X-Received: by 2002:a17:902:2a29:: with SMTP id i38mr7216231plb.253.1545498625323; Sat, 22 Dec 2018 09:10:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545498625; cv=none; d=google.com; s=arc-20160816; b=BLVwueZwKiKylB5tm5BDG4bWkwJk1QC9ECCWmfgaRnQZKKKpGp22AxSmZihtyLhf30 oPJ3cYXbkvX+BLB5DeF9G4hViB3ZOgVMrd7wE+Ni1MxOIEVR7X/6c1KBb+YYm1H/6ZVx 3eFD8VyfDY4TyOsaBv+xeMiMovycexIvFcNz3z3TXWkyAYj8Z46aUlibx6sha7a+BNmq OyBaIEGQ1RzGxzD8eIvAqawvOa92CnL88VnSWxGQ2TxFfEhvY5ksVdP5x8Ih370zFMCq 0ywQrq9rGilbGl5Zu8yNtVztIWqQxtX8yWaF1vJeeYHktYjRxTO5LzCiQsnrJ31WrCPq ihDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date; bh=12PrgWPf/0rg6cPgnAoEdHoitkJihcXPjctesWr5bm8=; b=obtDlUQrvypPPunJMWdOWhsRNXMqQLuValix5AmdJmefO82xRexXctaJV5FRoMsmWV FTEV1QoXQtTZ8FcXybdL8Qf3l3l75vo8QUQmdcPd6zOjyAOERA0TGmonKRf0MANj4RGX BRFqGBlyNMTqSe578Ra6DhpCHGhmbugCdYgy3WTRJaWqgbm+4QzlvwpzRVnjSX3Y/RDu oNpki7U69S/DJ3g6eMc4IDJQk2QKzI8dx+9Fa2ltX6H/sn1SHcwK6HOtQEtuloUpWZOv 82rV78bFHR350PV65bVZhXNlhQN9tQTAx7SXSJDh3+DUah1Dv4QHWWExUeTKRRdY7tTT FANw== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q66si23877858pfb.231.2018.12.22.09.10.10; Sat, 22 Dec 2018 09:10:25 -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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732100AbeLUSAI (ORCPT + 99 others); Fri, 21 Dec 2018 13:00:08 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:50260 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725937AbeLUSAH (ORCPT ); Fri, 21 Dec 2018 13:00:07 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wBLHwc9W066816 for ; Fri, 21 Dec 2018 13:00:06 -0500 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ph22qgnb3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Dec 2018 13:00:05 -0500 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 21 Dec 2018 18:00:05 -0000 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 21 Dec 2018 18:00:01 -0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wBLI00IO20709428 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 21 Dec 2018 18:00:00 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8375FB2066; Fri, 21 Dec 2018 18:00:00 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 60BDEB205F; Fri, 21 Dec 2018 18:00:00 +0000 (GMT) Received: from paulmck-ThinkPad-W541 (unknown [9.85.153.1]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 21 Dec 2018 18:00:00 +0000 (GMT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 3C71216C36A7; Fri, 21 Dec 2018 10:00:07 -0800 (PST) Date: Fri, 21 Dec 2018 10:00:07 -0800 From: "Paul E. McKenney" To: Andi Kleen Cc: Peter Zijlstra , Arnd Bergmann , Nicolas Pitre , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Will Deacon , Ingo Molnar , Thomas Gleixner , hubicka@ucw.cz Subject: Re: [PATCH 0/7] ARM: hacks for link-time optimization Reply-To: paulmck@linux.ibm.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> <20181221172044.GE25620@tassilo.jf.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181221172044.GE25620@tassilo.jf.intel.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 18122118-0064-0000-0000-0000038A71D9 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010262; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000272; SDB=6.01135049; UDB=6.00590197; IPR=6.00915221; MB=3.00024789; MTD=3.00000008; XFM=3.00000015; UTC=2018-12-21 18:00:04 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18122118-0065-0000-0000-00003BC300C5 Message-Id: <20181221180007.GQ4170@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-21_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812210137 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 21, 2018 at 09:20:44AM -0800, Andi Kleen wrote: > > 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? I have not seen it myself, but I have heard others claim to. For example, if "idx & 1" had to be computed for some other reason, especially if there was a pre-exiting "if" statement with this as its condition. Or if you have hardware that has a conditional-move instruction. And so on. Do you have a way to guarantee that it never happens? Thanx, Paul > -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. >