aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Corallo2024-03-24 11:29:37 +0100
committerAndrea Corallo2024-03-24 12:16:11 +0100
commitc5de73a95a6ecefe46fe1ac07da8e83032be7f5b (patch)
tree32f75f1f1c54e71a1c2d009199121619e975d8c7
parent30b1b0d7cd8e4d46a601e9737350cda970f6bab0 (diff)
downloademacs-c5de73a95a6ecefe46fe1ac07da8e83032be7f5b.tar.gz
emacs-c5de73a95a6ecefe46fe1ac07da8e83032be7f5b.zip
Fix native compilation for circular immediates (bug#67883)
* test/src/comp-resources/comp-test-funcs.el (comp-test-67883-1-f): New function. * lisp/emacs-lisp/comp.el (comp--collect-rhs) (comp--ssa-rename-insn): Handle setimm aside to avoid unnecessary immediate manipulation. (comp--copy-insn-rec): Rename. (comp--copy-insn): New function. (comp--dead-assignments-func): Handle setimm aside to avoid unnecessary.
-rw-r--r--lisp/emacs-lisp/comp.el18
-rw-r--r--test/src/comp-resources/comp-test-funcs.el3
2 files changed, 18 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 1df1e3b3ddb..4ddf90349d1 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -1788,7 +1788,9 @@ into the C code forwarding the compilation unit."
1788 for insn in (comp-block-insns b) 1788 for insn in (comp-block-insns b)
1789 for (op . args) = insn 1789 for (op . args) = insn
1790 if (comp--assign-op-p op) 1790 if (comp--assign-op-p op)
1791 do (comp--collect-mvars (cdr args)) 1791 do (comp--collect-mvars (if (eq op 'setimm)
1792 (cl-first args)
1793 (cdr args)))
1792 else 1794 else
1793 do (comp--collect-mvars args)))) 1795 do (comp--collect-mvars args))))
1794 1796
@@ -2442,6 +2444,8 @@ PRE-LAMBDA and POST-LAMBDA are called in pre or post-order if non-nil."
2442 (setf (comp-vec-aref frame slot-n) mvar 2444 (setf (comp-vec-aref frame slot-n) mvar
2443 (cadr insn) mvar)))) 2445 (cadr insn) mvar))))
2444 (pcase insn 2446 (pcase insn
2447 (`(setimm ,(pred targetp) ,_imm)
2448 (new-lvalue))
2445 (`(,(pred comp--assign-op-p) ,(pred targetp) . ,_) 2449 (`(,(pred comp--assign-op-p) ,(pred targetp) . ,_)
2446 (let ((mvar (comp-vec-aref frame slot-n))) 2450 (let ((mvar (comp-vec-aref frame slot-n)))
2447 (setf (cddr insn) (cl-nsubst-if mvar #'targetp (cddr insn)))) 2451 (setf (cddr insn) (cl-nsubst-if mvar #'targetp (cddr insn))))
@@ -2545,7 +2549,7 @@ Return t when one or more block was removed, nil otherwise."
2545 ;; native compiling all Emacs code-base. 2549 ;; native compiling all Emacs code-base.
2546 "Max number of scanned insn before giving-up.") 2550 "Max number of scanned insn before giving-up.")
2547 2551
2548(defun comp--copy-insn (insn) 2552(defun comp--copy-insn-rec (insn)
2549 "Deep copy INSN." 2553 "Deep copy INSN."
2550 ;; Adapted from `copy-tree'. 2554 ;; Adapted from `copy-tree'.
2551 (if (consp insn) 2555 (if (consp insn)
@@ -2562,6 +2566,13 @@ Return t when one or more block was removed, nil otherwise."
2562 (copy-comp-mvar insn) 2566 (copy-comp-mvar insn)
2563 insn))) 2567 insn)))
2564 2568
2569(defun comp--copy-insn (insn)
2570 "Deep copy INSN."
2571 (pcase insn
2572 (`(setimm ,mvar ,imm)
2573 `(setimm ,(copy-comp-mvar mvar) ,imm))
2574 (_ (comp--copy-insn-rec insn))))
2575
2565(defmacro comp--apply-in-env (func &rest args) 2576(defmacro comp--apply-in-env (func &rest args)
2566 "Apply FUNC to ARGS in the current compilation environment." 2577 "Apply FUNC to ARGS in the current compilation environment."
2567 `(let ((env (cl-loop 2578 `(let ((env (cl-loop
@@ -2903,7 +2914,8 @@ Return the list of m-var ids nuked."
2903 for (op arg0 . rest) = insn 2914 for (op arg0 . rest) = insn
2904 if (comp--assign-op-p op) 2915 if (comp--assign-op-p op)
2905 do (push (comp-mvar-id arg0) l-vals) 2916 do (push (comp-mvar-id arg0) l-vals)
2906 (setf r-vals (nconc (comp--collect-mvar-ids rest) r-vals)) 2917 (unless (eq op 'setimm)
2918 (setf r-vals (nconc (comp--collect-mvar-ids rest) r-vals)))
2907 else 2919 else
2908 do (setf r-vals (nconc (comp--collect-mvar-ids insn) r-vals)))) 2920 do (setf r-vals (nconc (comp--collect-mvar-ids insn) r-vals))))
2909 ;; Every l-value appearing that does not appear as r-value has no right to 2921 ;; Every l-value appearing that does not appear as r-value has no right to
diff --git a/test/src/comp-resources/comp-test-funcs.el b/test/src/comp-resources/comp-test-funcs.el
index dc4abf50767..54f339f6373 100644
--- a/test/src/comp-resources/comp-test-funcs.el
+++ b/test/src/comp-resources/comp-test-funcs.el
@@ -559,6 +559,9 @@
559 (let ((time (make-comp-test-time :unix (time-convert (current-time) 'integer)))) 559 (let ((time (make-comp-test-time :unix (time-convert (current-time) 'integer))))
560 (comp-test-67239-0-f "%F" time))) 560 (comp-test-67239-0-f "%F" time)))
561 561
562(defun comp-test-67883-1-f ()
563 '#1=(1 . #1#))
564
562 565
563;;;;;;;;;;;;;;;;;;;; 566;;;;;;;;;;;;;;;;;;;;
564;; Tromey's tests ;; 567;; Tromey's tests ;;