diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2021-07-20 15:46:32 +0200 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2021-07-20 19:21:00 +0200 |
commit | 46d7d44894843bf30e9bc84473195c6ab892b752 (patch) | |
tree | e47a989e772bcbadf2ce68fcd5e8ab97ff0c346b /lisp/emacs-lisp | |
parent | 51a86b6a0504d580d3e10efe41abf3ae42c90711 (diff) | |
download | emacs-46d7d44894843bf30e9bc84473195c6ab892b752.tar.gz emacs-46d7d44894843bf30e9bc84473195c6ab892b752.tar.bz2 emacs-46d7d44894843bf30e9bc84473195c6ab892b752.zip |
Strength-reduce (eq X nil) to (not X)
* lisp/emacs-lisp/byte-opt.el (byte-optimize-eq): New optimisation,
which results in better test and branch code generation where it
applies.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/byte-opt.el | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index 2fff0bd4a5f..7ed04b32e97 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el @@ -969,6 +969,12 @@ See Info node `(elisp) Integer Basics'." ;; Arity errors reported elsewhere. form))) +(defun byte-optimize-eq (form) + (byte-optimize-binary-predicate + (pcase (cdr form) + ((or `(,x nil) `(nil ,x)) `(not ,x)) + (_ form)))) + (defun byte-optimize-member (form) ;; Replace `member' or `memql' with `memq' if the first arg is a symbol, ;; or the second arg is a list of symbols. Same with fixnums. @@ -1056,7 +1062,7 @@ See Info node `(elisp) Integer Basics'." (put 'min 'byte-optimizer #'byte-optimize-min-max) (put '= 'byte-optimizer #'byte-optimize-binary-predicate) -(put 'eq 'byte-optimizer #'byte-optimize-binary-predicate) +(put 'eq 'byte-optimizer #'byte-optimize-eq) (put 'eql 'byte-optimizer #'byte-optimize-equal) (put 'equal 'byte-optimizer #'byte-optimize-equal) (put 'string= 'byte-optimizer #'byte-optimize-binary-predicate) |