]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix native compilation for circular immediates (bug#67883)
authorAndrea Corallo <acorallo@gnu.org>
Sun, 24 Mar 2024 10:29:37 +0000 (11:29 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sun, 24 Mar 2024 14:22:47 +0000 (15:22 +0100)
* 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.

(cherry picked from commit c5de73a95a6ecefe46fe1ac07da8e83032be7f5b)

lisp/emacs-lisp/comp.el
test/src/comp-resources/comp-test-funcs.el

index 18e63354524b3d3f912b93e2ce5b619416c7da95..04d39967b723ffe9994c78837ee456a231d83682 100644 (file)
@@ -1788,7 +1788,9 @@ into the C code forwarding the compilation unit."
        for insn in (comp-block-insns b)
        for (op . args) = insn
        if (comp--assign-op-p op)
-         do (comp--collect-mvars (cdr args))
+         do (comp--collect-mvars (if (eq op 'setimm)
+                                     (cl-first args)
+                                   (cdr args)))
        else
          do (comp--collect-mvars args))))
 
@@ -2442,6 +2444,8 @@ PRE-LAMBDA and POST-LAMBDA are called in pre or post-order if non-nil."
                  (setf (comp-vec-aref frame slot-n) mvar
                        (cadr insn) mvar))))
      (pcase insn
+       (`(setimm ,(pred targetp) ,_imm)
+        (new-lvalue))
        (`(,(pred comp--assign-op-p) ,(pred targetp) . ,_)
         (let ((mvar (comp-vec-aref frame slot-n)))
           (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."
   ;; native compiling all Emacs code-base.
   "Max number of scanned insn before giving-up.")
 
-(defun comp--copy-insn (insn)
+(defun comp--copy-insn-rec (insn)
   "Deep copy INSN."
   ;; Adapted from `copy-tree'.
   (if (consp insn)
@@ -2562,6 +2566,13 @@ Return t when one or more block was removed, nil otherwise."
         (copy-comp-mvar insn)
       insn)))
 
+(defun comp--copy-insn (insn)
+  "Deep copy INSN."
+  (pcase insn
+    (`(setimm ,mvar ,imm)
+     `(setimm ,(copy-comp-mvar mvar) ,imm))
+    (_ (comp--copy-insn-rec insn))))
+
 (defmacro comp--apply-in-env (func &rest args)
   "Apply FUNC to ARGS in the current compilation environment."
   `(let ((env (cl-loop
@@ -2903,7 +2914,8 @@ Return the list of m-var ids nuked."
          for (op arg0 . rest) = insn
          if (comp--assign-op-p op)
            do (push (comp-mvar-id arg0) l-vals)
-              (setf r-vals (nconc (comp--collect-mvar-ids rest) r-vals))
+              (unless (eq op 'setimm)
+                (setf r-vals (nconc (comp--collect-mvar-ids rest) r-vals)))
          else
            do (setf r-vals (nconc (comp--collect-mvar-ids insn) r-vals))))
     ;; Every l-value appearing that does not appear as r-value has no right to
index dc4abf5076767078f0f49547e70ac4b95bc90970..54f339f6373d744546255e77cbf00b1a28e76420 100644 (file)
   (let ((time (make-comp-test-time :unix (time-convert (current-time) 'integer))))
     (comp-test-67239-0-f "%F" time)))
 
+(defun comp-test-67883-1-f ()
+  '#1=(1 . #1#))
+
 \f
 ;;;;;;;;;;;;;;;;;;;;
 ;; Tromey's tests ;;