From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.bugs Subject: bug#39573: [3.0.0] Compiler fails to optimize out side-effect-free expression Date: Wed, 12 Feb 2020 15:57:41 +0100 Message-ID: <87lfp7am56.fsf@igalia.com> References: <87k14svxbf.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="43370"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cc: bug-Guile@gnu.org To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Wed Feb 12 15:59:13 2020 Return-path: Envelope-to: guile-bugs@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 1j1tTr-000B7R-WB for guile-bugs@m.gmane-mx.org; Wed, 12 Feb 2020 15:59:12 +0100 Original-Received: from localhost ([::1]:39130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1tTr-0007wO-1E for guile-bugs@m.gmane-mx.org; Wed, 12 Feb 2020 09:59:11 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50752) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1tTj-0007w9-BB for bug-guile@gnu.org; Wed, 12 Feb 2020 09:59:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j1tTi-0000NK-98 for bug-guile@gnu.org; Wed, 12 Feb 2020 09:59:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52953) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j1tTi-0000NE-5A for bug-guile@gnu.org; Wed, 12 Feb 2020 09:59:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j1tTi-0002Ry-5Q for bug-guile@gnu.org; Wed, 12 Feb 2020 09:59:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Andy Wingo Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 12 Feb 2020 14:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39573 X-GNU-PR-Package: guile Original-Received: via spool by submit@debbugs.gnu.org id=B.15815194969364 (code B ref -1); Wed, 12 Feb 2020 14:59:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Feb 2020 14:58:16 +0000 Original-Received: from localhost ([127.0.0.1]:58924 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j1tSy-0002Qw-AN for submit@debbugs.gnu.org; Wed, 12 Feb 2020 09:58:16 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:52461) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j1tSw-0002Qo-OB for submit@debbugs.gnu.org; Wed, 12 Feb 2020 09:58:15 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50651) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1tSv-0007FA-0O for bug-Guile@gnu.org; Wed, 12 Feb 2020 09:58:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j1tSs-00084y-Qv for bug-Guile@gnu.org; Wed, 12 Feb 2020 09:58:11 -0500 Original-Received: from fanzine.igalia.com ([178.60.130.6]:34053) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j1tSs-0007qG-8G; Wed, 12 Feb 2020 09:58:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References:Subject:Cc:To:From; bh=VCDAsNfZ5rY7jg4dIErl1pQfPDpyoVlBTRBXeSW6NTI=; b=g6SmVYbh4cpZXQSxboLd4lCbzBm0wkHclYgQUULSo8RUisRKDKkTDEX79BxcT33x6QHaFzBQrSwsaAWLpUJdlFcliKN2UdBh8bAK4DIl6qrr28S9fqRznzd73LhRaF+s9AuPwyNlFWiDwv34Hl3NX0TJDP5m7YKjIRFQofKoIbkOWFuuBpbYjGzB5BB0oJZHxKD4Yxr0s3JMzib1lzDzRVRC7JgN+4fcFBvIkQ/u3d3kjqRRpApHQ5kqF1z44nt77m6yV+AlPVzFjUemEpRAkvnFlNyhGzsjWLMvi/SL5e4fvte5fhv08aePXZtU3zrCzpJT6HY3RmpAwgOkXc2eNw==; Original-Received: from lfbn-ann-1-376-195.w86-200.abo.wanadoo.fr ([86.200.91.195] helo=milano) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1j1tSZ-0002RO-FL; Wed, 12 Feb 2020 15:57:51 +0100 In-Reply-To: <87k14svxbf.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Wed, 12 Feb 2020 12:50:44 +0100") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:9570 Archived-At: On Wed 12 Feb 2020 12:50, Ludovic Court=C3=A8s writes: > Hello! > > Consider this loop: > > (let loop ((n (expt 2 18)) > (i 1)) > (unless (zero? n) > (loop (- n 1) > (logior 0 (ash i 1))))) > > Guile 2.2 strips away the computation of =E2=80=98i=E2=80=99 (it cannot t= hrow, has no > side effects, and the result is unused): > [...] > L1: > 27 (handle-interrupts) at (unknown= file):21:11 > 28 (sub/immediate 4 4 1)=20=20=20=20=20=20=20=20=20=20=20 > 29 (br-if-u64-=3D-scm 3 4 #t -2) ;; -> L1 at (unkno= wn file):18:11 Like specifically, it removes the logior call. > However, 3.0.0 keeps the computation of =E2=80=98i=E2=80=99: > [...] > L3: > 53 (instrument-loop 139)=20=20=20=20=20=20=20=20=20=20=20 > 55 (handle-interrupts)=20=20=20=20=20=20=20=20=20=20=20=20=20 > 56 (call-scm<-scm-uimm 5 5 1 3) at (unknown= file):388:11 > 58 (call-scm<-scm-uimm 3 3 1 34) at (unknown= file):389:21 > 60 (call-scm<-scm-scm 3 4 3 10) at (unknown= file):389:11 > 62 (=3D? 5 4) at (unkno= wn file):385:11 > 63 (jne -10) ;; -> L3 Hoo, we need to fix the disassembler to output something more sensible than this :P IP 56 appears to be the 1-, 58 is the lsh/immediate, and 60 is the logior. > I=E2=80=99m not sure where the optimization should be taking place. Perh= aps > it=E2=80=99s just a matter of amount-of-work threshold somewhere? It's not an amount-of-work, that's only in peval which does nothing to either of these (though it certainly could). I took a look. I just pushed something to make (logior 0 INT) reduce to INT, but it doesn't remove the loop variable. Then I thought it was surely dead code elimination that just wasn't doing its thing. The value is unused, so it must be that it thought that the `ash' was effectful. That `ash' gets compiled to `lsh/immediate', which does indeed raise an exception if the operand isn't an int; but here we prove that it is. The problem was a missing "type checker" implementation for lsh/immediate, a problem introduced in the refactored compilation of `ash'. So, fixed in git now: L3: 45 (instrument-loop 135)=20=20=20=20=20=20=20=20=20=20=20 47 (handle-interrupts)=20=20=20=20=20=20=20=20=20=20=20=20=20 48 (call-scm<-scm-uimm 5 5 1 3) at (unknown f= ile):4:12 50 (=3D? 5 4) at (unknown= file):3:12 51 (jne -6) ;; -> L3 Cheers, Andy