Better type derivation for APPEND, NCONC, LIST.
[sbcl.git] / src / compiler / generic / vm-ir2tran.lisp
index dae68f9..dd820f6 100644 (file)
            nil)
 
 #!+stack-allocatable-fixed-objects
-(defoptimizer (%make-structure-instance stack-allocate-result) ((&rest args) node dx)
+(defoptimizer (%make-structure-instance stack-allocate-result) ((defstruct-description &rest args) node dx)
+  (aver (constant-lvar-p defstruct-description))
+  ;; A structure instance can be stack-allocated if it has no raw
+  ;; slots, or if we're on a target with a conservatively-scavenged
+  ;; stack.  We have no reader conditional for stack conservation, but
+  ;; it turns out that the only time stack conservation is in play is
+  ;; when we're on GENCGC (since CHENEYGC doesn't have conservation)
+  ;; and C-STACK-IS-CONTROL-STACK (otherwise, the C stack is the
+  ;; number stack, and we precisely-scavenge the control stack).
+  #!-(and :gencgc :c-stack-is-control-stack)
+  (zerop (sb!kernel::dd-raw-length (lvar-value defstruct-description)))
+  #!+(and :gencgc :c-stack-is-control-stack)
   t)
 
 (defoptimizer ir2-convert-reffer ((object) node block name offset lowtag)
 (progn
   (defoptimizer (allocate-vector stack-allocate-result)
       ((type length words) node dx)
-    (or (eq dx :always-dynamic)
-        (zerop (policy node safety))
-        ;; a vector object should fit in one page -- otherwise it might go past
-        ;; stack guard pages.
-        (values-subtypep (lvar-derived-type words)
-                         (load-time-value
-                          (specifier-type `(integer 0 ,(- (/ sb!vm::*backend-page-bytes*
-                                                             sb!vm:n-word-bytes)
-                                                          sb!vm:vector-data-offset)))))))
+    (and
+     ;; Can't put unboxed data on the stack unless we scavenge it
+     ;; conservatively.
+     #!-c-stack-is-control-stack
+     (constant-lvar-p type)
+     #!-c-stack-is-control-stack
+     (member (lvar-value type)
+             '#.(list (sb!vm:saetp-typecode (find-saetp 't))
+                      (sb!vm:saetp-typecode (find-saetp 'fixnum))))
+     (or (eq dx :always-dynamic)
+         (zerop (policy node safety))
+         ;; a vector object should fit in one page -- otherwise it might go past
+         ;; stack guard pages.
+         (values-subtypep (lvar-derived-type words)
+                          (load-time-value
+                           (specifier-type `(integer 0 ,(- (/ sb!vm::*backend-page-bytes*
+                                                              sb!vm:n-word-bytes)
+                                                           sb!vm:vector-data-offset))))))))
 
   (defoptimizer (allocate-vector ltn-annotate) ((type length words) call ltn-policy)
     (let ((args (basic-combination-args call))
 #!+stack-allocatable-lists
 (progn
   (defoptimizer (list stack-allocate-result) ((&rest args) node dx)
-    (declare (ignore node dx))
     (not (null args)))
   (defoptimizer (list* stack-allocate-result) ((&rest args) node dx)
-    (declare (ignore node dx))
     (not (null (rest args))))
   (defoptimizer (%listify-rest-args stack-allocate-result) ((&rest args) node dx)
-    (declare (ignore node dx))
     t))
 
 ;;; ...conses