Comp: Fix limplification pass (bug#62537)

* test/src/comp-resources/comp-test-funcs.el (comp-test-62537-1-f)
(comp-test-62537-2-f): New functions.

* lisp/emacs-lisp/comp.el (comp-jump-table-optimizable): Make it
stricter add a comment.
This commit is contained in:
Andrea Corallo 2023-04-05 18:17:58 +02:00
parent a42f4a775b
commit fa669c4b17
2 changed files with 21 additions and 1 deletions

View file

@ -1712,6 +1712,10 @@ Return value is the fall-through block name."
(defun comp-jump-table-optimizable (jmp-table)
"Return t if JMP-TABLE can be optimized out."
;; Identify LAP sequences like:
;; (byte-constant #s(hash-table size 3 test eq rehash-size 1.5 rehash-threshold 0.8125 purecopy t data (created 126 deleted 126 changed 126)) . 24)
;; (byte-switch)
;; (TAG 126 . 10)
(cl-loop
with labels = (cl-loop for target-label being each hash-value of jmp-table
collect target-label)
@ -1719,7 +1723,10 @@ Return value is the fall-through block name."
for l in (cdr-safe labels)
unless (= l x)
return nil
finally return t))
finally return (pcase (nth (1+ (comp-limplify-pc comp-pass))
(comp-func-lap comp-func))
(`(TAG ,label . ,_label-sp)
(= label l)))))
(defun comp-emit-switch (var last-insn)
"Emit a Limple for a lap jump table given VAR and LAST-INSN."

View file

@ -518,6 +518,19 @@
(defun comp-test-48029-nonascii-žžž-f (arg)
(when arg t))
(defun comp-test-62537-1-f ())
(defun comp-test-62537-2-f ()
(when (let ((val (comp-test-62537-1-f)))
(cond
((eq val 'x)
t)
((eq val 'y)
'y)))
(comp-test-62537-1-f))
t)
;;;;;;;;;;;;;;;;;;;;
;; Tromey's tests ;;