From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Corallo via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#46670: 28.0.50; [feature/native-comp] possible miscompilation affecting lsp-mode Date: Mon, 22 Feb 2021 09:37:55 +0000 Message-ID: References: <87a6ry46uc.fsf@collares.org> Reply-To: Andrea Corallo Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37413"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 46670@debbugs.gnu.org, Mauricio Collares To: Pip Cet Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 22 10:39:23 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 1lE7gY-0009do-St for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 22 Feb 2021 10:39:22 +0100 Original-Received: from localhost ([::1]:56516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lE7gX-0005pK-RR for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 22 Feb 2021 04:39:21 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lE7gE-0005nJ-10 for bug-gnu-emacs@gnu.org; Mon, 22 Feb 2021 04:39:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44113) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lE7gD-0005Wv-O2 for bug-gnu-emacs@gnu.org; Mon, 22 Feb 2021 04:39:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lE7gD-0005t3-Lc for bug-gnu-emacs@gnu.org; Mon, 22 Feb 2021 04:39:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Andrea Corallo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 22 Feb 2021 09:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46670 X-GNU-PR-Package: emacs Original-Received: via spool by 46670-submit@debbugs.gnu.org id=B46670.161398668722553 (code B ref 46670); Mon, 22 Feb 2021 09:39:01 +0000 Original-Received: (at 46670) by debbugs.gnu.org; 22 Feb 2021 09:38:07 +0000 Original-Received: from localhost ([127.0.0.1]:55655 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lE7fL-0005rh-Da for submit@debbugs.gnu.org; Mon, 22 Feb 2021 04:38:07 -0500 Original-Received: from mx.sdf.org ([205.166.94.24]:54874) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lE7fG-0005rF-Ek for 46670@debbugs.gnu.org; Mon, 22 Feb 2021 04:38:06 -0500 Original-Received: from mab (ma.sdf.org [205.166.94.33]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 11M9btdX006574 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Mon, 22 Feb 2021 09:37:57 GMT In-Reply-To: (Pip Cet's message of "Sun, 21 Feb 2021 22:46:29 +0000") 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:200551 Archived-At: Pip Cet writes: > On Sun, Feb 21, 2021 at 9:03 PM Andrea Corallo wrote: >> Pip Cet writes: >> >> > On Sun, Feb 21, 2021 at 11:51 AM Pip Cet wrote: >> >> Does the attached patch help? Andrea, is my analysis correct? >> > >> > CCing Andrea. >> > >> > In more detail, some debugging showed we were trying to intersect a >> > "nil or t" constraint with a "sequence" constraint, the result being a >> > null constraint (t is not a sequence). So if (assume (and a b)) was >> > meant to imply the intersection of a and b, we're emitting it >> > incorrectly. >> >> Hi Pip, >> >> thanks for looking into this. > > Thanks for your explanation! > >> 'and' is meant to imply intersection, so yeah... as you guess there's >> some problem in the LIMPLE we generate :) > > Thanks, I was on the wrong track there. > >> The correct fix is to have `comp-add-cond-cstrs' rewrite the comparison >> sequence as something like: >> >> (set #(mvar nil X t) #(mvar 42082358 1 t)) >> (set #(mvar 41121566 1 boolean) (call equal #(mvar 42082358 1 t) #(mvar 41665638 2 sequence))) >> (cond-jump #(mvar 41121566 1 boolean) #(mvar nil nil null) bb_2_cstrs_0 bb_1) >> >> Where X is a new slot we add to the frame. We will reference this slot >> number in the assume instead of 1 so it does not get clobbered. > > Okay, I think I understand the problem (we don't do classical SSA and > throw away the slot numbers), and your solution would avoid it, but it > seems needlessly complicated to me. Correct, ATM the assumption is that we keep LIMPLE always as "conventional SSA form". This for a number of reasons but mainly it greatly helps in maintaining the compiler simple. I've experimented investing quite some effort into removing this assumption but the result was definitely more complex and the produced code considerably harder to debug. The only advantage I could see in the end was having a simpler and more elegant `comp-cond-cstrs-target-mvar' due to the fact that was trivial to implement a copy propagation pass), so I deemed was a good move to keep always the conventional form. > Why create a new slot that isn't used anywhere? The value of the stack > slot is clobbered by the (set ...), so we cannot emit any assumptions > about that stack slot based on previous values it held. Yes but in this case (and probably others) we *have* to emit this assumption. The best option is to decide that negative slot numbers are not rendered into libgccjit IR and we consider these virtual to solve these kind of cases. IIRC we already do something similar for the -1 index so this concept has just to be generalized a bit. > In fact, all we need to do is tell comp-cond-cstrs-target-mvar to > return nil more often, isn't it? Nope, the target mvar identified is the correct one, we just have ATM no way to reference it reliably into the assume. BTW applying your patch is breaking quite some of the comp-tests-ret-type-spec-* tests :) Andrea