emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 254c75fc293 2/2: Better commutative binary numerical op codegen


From: Mattias Engdegård
Subject: master 254c75fc293 2/2: Better commutative binary numerical op codegen
Date: Sun, 29 Jan 2023 08:32:01 -0500 (EST)

branch: master
commit 254c75fc2935e7edef079166d90b231278115a2f
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Better commutative binary numerical op codegen
    
    * lisp/emacs-lisp/bytecomp.el (byte-compile-variadic-numeric):
    Put a constant argument last for better LAP code opportunities.
    This applies to commutative binary operations (+ and *).
    `min` and `max` are not included being not quite commutative.
---
 lisp/emacs-lisp/bytecomp.el | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index bfb9be4712b..e8a8fe37756 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -4063,9 +4063,15 @@ This function is never called when `lexical-binding' is 
nil."
      (byte-compile-constant 1)
      (byte-compile-out (get '* 'byte-opcode) 0))
     (3
-     (byte-compile-form (nth 1 form))
-     (byte-compile-form (nth 2 form))
-     (byte-compile-out (get (car form) 'byte-opcode) 0))
+     (let ((arg1 (nth 1 form))
+           (arg2 (nth 2 form)))
+       (when (and (memq (car form) '(+ *))
+                  (macroexp-const-p arg1))
+         ;; Put constant argument last for better LAP optimisation.
+         (cl-rotatef arg1 arg2))
+       (byte-compile-form arg1)
+       (byte-compile-form arg2)
+       (byte-compile-out (get (car form) 'byte-opcode) 0)))
     (_
      ;; >2 args: compile as a single function call.
      (byte-compile-normal-call form))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]