From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pip Cet Newsgroups: gmane.emacs.bugs Subject: bug#46847: 28.0.50; [native-comp] assume pseudo-insns should be verified Date: Tue, 2 Mar 2021 06:57:42 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36905"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 46847@debbugs.gnu.org To: Andrea Corallo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Mar 02 07:59:14 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lGyzy-0009Rf-Kq for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 Mar 2021 07:59:14 +0100 Original-Received: from localhost ([::1]:60920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGyzx-0003he-EN for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 Mar 2021 01:59:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGyzn-0003hR-9k for bug-gnu-emacs@gnu.org; Tue, 02 Mar 2021 01:59:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39964) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGyzm-0007MA-Cc for bug-gnu-emacs@gnu.org; Tue, 02 Mar 2021 01:59:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lGyzm-00070X-Bz for bug-gnu-emacs@gnu.org; Tue, 02 Mar 2021 01:59:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Pip Cet Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 02 Mar 2021 06:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46847 X-GNU-PR-Package: emacs Original-Received: via spool by 46847-submit@debbugs.gnu.org id=B46847.161466831126892 (code B ref 46847); Tue, 02 Mar 2021 06:59:02 +0000 Original-Received: (at 46847) by debbugs.gnu.org; 2 Mar 2021 06:58:31 +0000 Original-Received: from localhost ([127.0.0.1]:51509 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lGyzG-0006zg-RP for submit@debbugs.gnu.org; Tue, 02 Mar 2021 01:58:31 -0500 Original-Received: from mail-ot1-f49.google.com ([209.85.210.49]:35012) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lGyzB-0006zN-6q for 46847@debbugs.gnu.org; Tue, 02 Mar 2021 01:58:29 -0500 Original-Received: by mail-ot1-f49.google.com with SMTP id r19so19083933otk.2 for <46847@debbugs.gnu.org>; Mon, 01 Mar 2021 22:58:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Dnj89hy0an6V7Jp+wLTUcNQB7/8wCp+g1c1tQcAIoTA=; b=Z2RBaUk+b3rafIjzZYiU56oaK6ApDNRt81hPIQc6isKReDltobKXoTl9ugmzmp6CbX RUU0tUPB2QWKouqbroqo9T3ZR/UW9ka6dyNoKe/ALzj1yGaD9/cM007ehpIHpzYDt23A sLS2GjYV7Vvv/L3UhXu+0m/qDFM9A1V/Lo65qo0GW4EY+mCf2xXE+9sv7Z5ePeDyC/C7 IhYsSYwer3uEIZaHXG/xKxOjwpgXRUTzg3FnIjdRhc1stR51ZcmiTTVgOPclQYoDV+hh S/zuaJwhczpSO4y4qwdfFsVvHEY+gKW4RVL/Rwh5X6zpW2lbbZRQaFPN5YhHJiYacFeF 5t3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Dnj89hy0an6V7Jp+wLTUcNQB7/8wCp+g1c1tQcAIoTA=; b=nKKpX3Rbe9LB3xTILESZ6e81xTS/hg0t4qSe4104ckHHxl+WzkAN4ebeB7nTMnS2tX olj7sR5Qd+R3AuRryDYwrvhzKVWL4XaP18nzWDOGF8UTE/5+Qjn+eLSE6hhLQRJkiO4r DCRtVbAp8eEnCtDyZIsPE/JPQKzSDYIWCveVzmjRU2HLkivgQaRiQwEMuMntOIn2eWk2 JzcqEyrnTBBBaWrTbUa2IKt1EfI/mIQSFlxNyq/4ERq9Ay1VRS4VzYG4YoWltvHXtnOV dkaa2JniZPPXUKyUc6Ea5+XvR6+LN+DQUlmp2v9llL9BmA+jGZbqQnH5IN8dOnA4gAM9 XB8A== X-Gm-Message-State: AOAM531UtCnCO0RciQXupDRp7nNNHceq74FN6cWgv+uRE+p7bBpa0p26 Jgi3m8ngFG2oW4DPfVuLo5YGxlnSWls0vnraAemLuzDviaP3TQ== X-Google-Smtp-Source: ABdhPJxefPQMLycG19HhEzkFuRb5+31ezMBuqwxfkJIRwIG1AamK6pjmImLdUi4mt2Sdai6PGfq6gsRBYciKVr4toKw= X-Received: by 2002:a05:6830:1682:: with SMTP id k2mr16922857otr.154.1614668299293; Mon, 01 Mar 2021 22:58:19 -0800 (PST) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:201190 Archived-At: On Mon, Mar 1, 2021 at 8:12 PM Andrea Corallo wrote: > Pip Cet writes: > > This is a wishlist item for the native-comp branch, though I consider > > the feature in question to be so essential that its absence also > > qualifies as a bug. > > > > The native-comp branch is emitting assume pseudo-insns. Those come in > > various forms, but their interpretation is clear: they express > > conditions which are meant to hold at runtime, and which the compiler > > may use to optimize code. > > > > I would like to add an optional compiler pass which asserts that the > > conditions are actually true at runtime. This is a basic safeguard > > that any assume() mechanism should have, and it's perfectly equivalent > > to the way eassume() becomes eassert() in debug builds of Emacs. > > > > Unfortunately, it turns out that while adding the compiler pass is > > easy, there are many failures because the assume pseudo-insns emitted > > at present are inconsistent or plain wrong. Some of these wrong > > assumes result in reproducible Lisp-to-native-code bugs today; others > > will not; for still others, we're not sure. > > I think the issue might be that how assumes works has been > miss-understood here. > Assumes are working after SSA rename in the world of mvar ids, in > contrast we render code based on slot numbers. If mvars introduced in assumes don't have valid slot numbers, they shouldn't have a valid slot number in the :slot slot. But in the case of the assumes emitted so far, they do have valid slot numbers, they're just not the ones that are used. > Rendering assertions > based on assumes using the slot numbers (IIUC that's what your patch > did) I merely converted the assumes into assertions. I did not use the slot numbers there. > certainly leads to inconsistencies, but that's a fundamental > miss-interpretation of how assumes are working. If there is a consistent slot number to assign to an assume-d variable, we should use it. If there isn't, we shouldn't use a slot number at all. What we do right now is to simply use a slot number that we know to be incorrect, even though a correct one is available. Again, what we emit is (assume (mvar X :slot 1) (not (mvar Y :slot 1))) (assume (mvar Z :slot 2) (and ... (mvar X :slot 1))) what we should emit is (assume (mvar X :slot 2) (not (mvar Y :slot 1))) (assume (mvar Z :slot 2) (and ... (mvar X :slot 2))) or even (assume (mvar X :slot -1) (not (mvar Y :slot 1))) (assume (mvar Z :slot 2) (and ... (mvar X :slot -1))) or whatever mechanism you're proposing to name mvars which do not refer to variables (respectfully, but that's what a metavariable is defined to be). > This is probably also why you often suggests assumes are inconsistent. No, the seven bugs we ran into so far which were caused by inconsistent assumes are why I often suggest assumes are inconsistent. > Anyway, for the reasons above rendering 1:1 assumes into run-time checks > is not easily possible. Then we should call them something else, because that's what an "assume" is. > OTOH a possible way, and that's what I want to do, would be to verify > just before each (non pseudo) insn actually rendered that the slots in > use there are consistent with the prediction. That would catch fewer bugs, and it would catch them much later, when code which uses them has been written. > One could even control that with a parameter and have a mode where we > just inject asserts on return insns not to bloat excessively the code. That seems like an entirely arbitrary place to check our assumes, to me. > Note: I'm not aware of any compiler emitting run-time checks to verify > its compile time predictions by why not. I don't know why you're unaware Emacs (pre-native-comp) and GCC both do that, but they do. Pip