From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#42147: 28.0.50; pure vs side-effect-free, missing optimizations? Date: Wed, 1 Jul 2020 18:08:28 +0200 Message-ID: <0433A879-C98D-4B1A-B85C-A15DA9289099@acm.org> References: <3A9CC2A3-8307-47B2-8D80-795C0AF020E1@acm.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.14\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_95A8B98D-10E4-4DEF-8850-D010A1F1BB5D" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39397"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Paul Eggert , Stefan Monnier , 42147@debbugs.gnu.org To: Andrea Corallo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jul 01 18:11:36 2020 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 1jqfKh-000A9J-EL for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 01 Jul 2020 18:11:35 +0200 Original-Received: from localhost ([::1]:36306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqfKg-0006S7-EH for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 01 Jul 2020 12:11:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39234) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqfIE-0001lq-HL for bug-gnu-emacs@gnu.org; Wed, 01 Jul 2020 12:09:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42091) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jqfIE-0005iu-7I for bug-gnu-emacs@gnu.org; Wed, 01 Jul 2020 12:09:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jqfIE-0005ji-2J for bug-gnu-emacs@gnu.org; Wed, 01 Jul 2020 12:09:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 01 Jul 2020 16:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42147 X-GNU-PR-Package: emacs Original-Received: via spool by 42147-submit@debbugs.gnu.org id=B42147.159361973122033 (code B ref 42147); Wed, 01 Jul 2020 16:09:02 +0000 Original-Received: (at 42147) by debbugs.gnu.org; 1 Jul 2020 16:08:51 +0000 Original-Received: from localhost ([127.0.0.1]:53637 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jqfI3-0005jJ-EW for submit@debbugs.gnu.org; Wed, 01 Jul 2020 12:08:51 -0400 Original-Received: from mail1478c50.megamailservers.eu ([91.136.14.78]:49256 helo=mail118c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jqfHz-0005iw-UY for 42147@debbugs.gnu.org; Wed, 01 Jul 2020 12:08:50 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1593619713; bh=Ibe+anABKaf3S2VUi4oTGTXvcrQrZxi3VoVlJ+UCrD0=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=YTlaCd8mPqBCKH68AXnmqUYWP5jm6uwmyVSL0nzOzaIP2UoBsvhWgdgbv4h8/89DR 0H9wC8aUGNYg6QrkTVdhdb0lS+mEkeE/lcfAolOQYnY2jRy9zeBNihA6oILKuxpVNG FaiN636ouO5zG4ZYs9I877IdwV2FqpkRFBvIkuXE= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.0.4] (c188-150-171-71.bredband.comhem.se [188.150.171.71]) (authenticated bits=0) by mail118c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 061G8TMP014902; Wed, 1 Jul 2020 16:08:31 +0000 In-Reply-To: <3A9CC2A3-8307-47B2-8D80-795C0AF020E1@acm.org> X-Mailer: Apple Mail (2.3445.104.14) X-CTCH-RefID: str=0001.0A782F1F.5EFCB501.0094, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=KaGsTjQD c=1 sm=1 tr=0 a=SF+I6pRkHZhrawxbOkkvaA==:117 a=SF+I6pRkHZhrawxbOkkvaA==:17 a=M51BFTxLslgA:10 a=6tmxTm_KZLYaJ9ZbfEYA:9 a=CjuIK1q_8ugA:10 a=teqb14kzXqgVTUaVCX4A:9 a=B2y7HmGcmWMA:10 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:182615 Archived-At: --Apple-Mail=_95A8B98D-10E4-4DEF-8850-D010A1F1BB5D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Andrea, I see nothing directly wrong with your patch, but perhaps our = messages went past one another since our lists of proposed pure = functions differ. > More useful would be the ability to constant-fold ash, expt, %, mod = and abs for a subset of each respective domain. I can write a patch. Here is that patch. --Apple-Mail=_95A8B98D-10E4-4DEF-8850-D010A1F1BB5D Content-Disposition: attachment; filename=0001-Constant-fold-mod-ash-expt-and-abs-with-constant-int.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Constant-fold-mod-ash-expt-and-abs-with-constant-int.patch" Content-Transfer-Encoding: quoted-printable =46rom=20aa9ce87268365f766a0d70e6a86bf44067e86b78=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Wed,=201=20Jul=202020=2017:44:54=20+0200=0A= Subject:=20[PATCH]=20Constant-fold=20%,=20mod,=20ash,=20expt=20and=20abs=20= with=20constant=20integer=0A=20args=0A=0ATo=20ensure=20portability,=20= the=20optimisation=20is=20confined=20to=20calls=20where=20the=0Aresult=20= is=20a=20portable=20fixnum.=20(Bug#42147)=0A=0A*=20= lisp/emacs-lisp/byte-opt.el=20(byte-opt--integer-arith)=0A= (byte-optimize-binary-integer-arith,=20= byte-optimize-unary-integer-arith)=0A(byte-optimize-mod):=20New=20= functions.=0A(%,=20mod,=20ash,=20expt,=20abs):=20Set=20byte-optimizer=20= property.=0A*=20test/lisp/emacs-lisp/bytecomp-tests.el=0A= (byte-opt-testsuite-arith-data):=20Add=20test=20cases.=0A---=0A=20= lisp/emacs-lisp/byte-opt.el=20=20=20=20=20=20=20=20=20=20=20=20|=2035=20= ++++++++++++++++++++++++++=0A=20test/lisp/emacs-lisp/bytecomp-tests.el=20= |=2012=20+++++++++=0A=202=20files=20changed,=2047=20insertions(+)=0A=0A= diff=20--git=20a/lisp/emacs-lisp/byte-opt.el=20= b/lisp/emacs-lisp/byte-opt.el=0Aindex=2012bde8faf3..72c68d64b2=20100644=0A= ---=20a/lisp/emacs-lisp/byte-opt.el=0A+++=20= b/lisp/emacs-lisp/byte-opt.el=0A@@=20-801,6=20+801,34=20@@=20= byte-optimize-divide=0A=20=20=20=20=20=20=20=20=20=20=20form=0A=20=20=20=20= =20=20=20=20=20(cons=20'/=20args)))))=0A=20=0A+(defun=20= byte-opt--integer-arith=20(form)=0A+=20=20"Constant-fold=20FORM=20when=20= args=20are=20integers=20and=20the=20result=20a=20portable=20fixnum."=0A+=20= =20(let=20((args=20(cdr=20form)))=0A+=20=20=20=20(if=20(memq=20nil=20= (mapcar=20#'integerp=20args))=0A+=20=20=20=20=20=20=20=20form=0A+=20=20=20= =20=20=20(let=20((res=20(apply=20(car=20form)=20args)))=0A+=20=20=20=20=20= =20=20=20(if=20(byte-opt--portable-numberp=20res)=0A+=20=20=20=20=20=20=20= =20=20=20=20=20res=0A+=20=20=20=20=20=20=20=20=20=20form)))))=0A+=0A= +(defun=20byte-optimize-binary-integer-arith=20(form)=0A+=20=20= "Constant-fold=20the=20binary=20integer=20arithmetic=20call=20FORM."=0A+=20= =20(if=20(=3D=20(length=20form)=203)=0A+=20=20=20=20=20=20= (byte-opt--integer-arith=20form)=0A+=20=20=20=20form))=0A+=0A+(defun=20= byte-optimize-unary-integer-arith=20(form)=0A+=20=20"Constant-fold=20the=20= unary=20integer=20arithmetic=20call=20FORM."=0A+=20=20(if=20(=3D=20= (length=20form)=202)=0A+=20=20=20=20=20=20(byte-opt--integer-arith=20= form)=0A+=20=20=20=20form))=0A+=0A+(defun=20byte-optimize-mod=20(form)=0A= +=20=20"Constant-fold=20the=20mod-like=20function=20call=20FORM."=0A+=20=20= (if=20(eql=20(nth=202=20form)=200)=0A+=20=20=20=20=20=20form=0A+=20=20=20= =20(byte-optimize-binary-integer-arith=20form)))=0A+=0A=20(defun=20= byte-optimize-binary-predicate=20(form)=0A=20=20=20(cond=0A=20=20=20=20= ((or=20(not=20(macroexp-const-p=20(nth=201=20form)))=0A@@=20-918,6=20= +946,13=20@@=20byte-optimize-concat=0A=20(put=20'max=20'byte-optimizer=20= 'byte-optimize-associative-math)=0A=20(put=20'min=20'byte-optimizer=20= 'byte-optimize-associative-math)=0A=20=0A+(put=20'%=20'byte-optimizer=20= 'byte-optimize-mod)=0A+(put=20'mod=20'byte-optimizer=20= 'byte-optimize-mod)=0A+=0A+(put=20'ash=20'byte-optimizer=20= 'byte-optimize-binary-integer-arith)=0A+(put=20'expt=20'byte-optimizer=20= 'byte-optimize-binary-integer-arith)=0A+(put=20'abs=20'byte-optimizer=20= 'byte-optimize-unary-integer-arith)=0A+=0A=20(put=20'=3D=20=20=20= 'byte-optimizer=20'byte-optimize-binary-predicate)=0A=20(put=20'eq=20=20= 'byte-optimizer=20'byte-optimize-binary-predicate)=0A=20(put=20'eql=20=20= =20'byte-optimizer=20'byte-optimize-equal)=0Adiff=20--git=20= a/test/lisp/emacs-lisp/bytecomp-tests.el=20= b/test/lisp/emacs-lisp/bytecomp-tests.el=0Aindex=20= bfe2d06a61..a96a7c8368=20100644=0A---=20= a/test/lisp/emacs-lisp/bytecomp-tests.el=0A+++=20= b/test/lisp/emacs-lisp/bytecomp-tests.el=0A@@=20-69,6=20+69,18=20@@=20= byte-opt-testsuite-arith-data=0A=20=20=20=20=20(let=20((a=203)=20(b=20= 2))=09=09=09=09=20=20=20(/=20a=20b=201))=0A=20=20=20=20=20(let=20((a=20= 3)=20(b=202))=09=09=09=09=20=20=20(/=20(+=20a=20b)=201))=0A=20=0A+=20=20=20= =20;;=20More=20arithmetic=20constant-folding=20(bug#42147).=0A+=20=20=20=20= (ash=203=2010)=0A+=20=20=20=20(ash=203=2025)=0A+=20=20=20=20(abs=20-20)=0A= +=20=20=20=20(abs=20-2305843009213693952)=0A+=20=20=20=20(expt=2010=203)=0A= +=20=20=20=20(expt=2010=2020)=0A+=20=20=20=20(%=2020=203)=0A+=20=20=20=20= (%=20-20=203)=0A+=20=20=20=20(mod=2020=203)=0A+=20=20=20=20(mod=20-20=20= 3)=0A+=0A=20=20=20=20=20;;=20coverage=20test=0A=20=20=20=20=20(let=20((a=20= 3)=20(b=202)=20(c=201.0))=20(+))=0A=20=20=20=20=20(let=20((a=203)=20(b=20= 2)=20(c=201.0))=20(+=202))=0A--=20=0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_95A8B98D-10E4-4DEF-8850-D010A1F1BB5D--