Commit 46d7d448 authored by Mattias Engdegård's avatar Mattias Engdegård
Browse files

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.
parent 51a86b6a
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment