master: (aref (vector a) 0) => a

stassats via Sbcl-commits <[email protected]>
Newsgroups gmane.lisp.steel-bank.cvs
Message-ID <[email protected]>
The branch "master" has been updated in SBCL:
       via  e938a68479153d11479ff77071e88e08768dfb0f (commit)
      from  d1b2b076bc95d36d046bd8cadcecc7506e4204bc (commit)

- Log -----------------------------------------------------------------
commit e938a68479153d11479ff77071e88e08768dfb0f
Author: Stas Boukarev <[email protected]>
Date:   Sun Aug 30 03:01:56 2026 +0300

    (aref (vector a) 0) => a
---
 src/compiler/generic/vm-tran.lisp | 13 +++++++++++++
 tests/compiler-ir.pure.lisp       | 11 +++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/compiler/generic/vm-tran.lisp b/src/compiler/generic/vm-tran.lisp
index 983b98ba7..1dc9ca7c8 100644
--- a/src/compiler/generic/vm-tran.lisp
+++ b/src/compiler/generic/vm-tran.lisp
@@ -328,6 +328,19 @@
                                      (%array-data array))
                           index)))))
 
+(deftransform #-(or x86 x86-64) data-vector-ref
+              #+(or x86 x86-64) data-vector-ref-with-offset
+  ((array index #+(or x86 x86-64) offset) (vector (constant-arg t) #+(or x86 x86-64) (constant-arg t)))
+  (let ((index (+ (lvar-value index)
+                  #+(or x86 x86-64) (lvar-value offset))))
+    (or (combination-case array
+          (initialize-vector *
+           (when (< index (length (cdr args)))
+             (splice-fun-args array :any (lambda (args)
+                                           (elt (cdr args) index)))
+             'array)))
+        (give-up-ir1-transform))))
+
 ;;; Transform data vector access to a form that opens up optimization
 ;;; opportunities. On platforms that support DATA-VECTOR-REF-WITH-OFFSET
 ;;; DATA-VECTOR-REF is not supported at all.
diff --git a/tests/compiler-ir.pure.lisp b/tests/compiler-ir.pure.lisp
index 628aa4c7e..51991a97f 100644
--- a/tests/compiler-ir.pure.lisp
+++ b/tests/compiler-ir.pure.lisp
@@ -9,7 +9,7 @@
 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
 ;;;; more information.
 
-(enable-test-parallelism)
+;(enable-test-parallelism)
 
 
 (import '(sb-c::combination-fun-debug-name
@@ -43,7 +43,8 @@
      (lambda (component)
        (ctu:do-blocks (block component)
          (ctu:do-nodes (node nil block)
-           (when (basic-combination-p node)
+           (when (and (basic-combination-p node)
+                      (not (eq (sb-c::basic-combination-kind node) :local)))
              (push node calls))))))
     calls))
 
@@ -919,3 +920,9 @@
     (assert (eq (funcall f  0 'whatever) 'yes))
     (assert (eq (funcall f :other 'ignore) 'yes))
     (assert (eq (funcall f 3 4) 'no))))
+
+(with-test (:name :aref-vector-fold)
+  (assert (null
+           (ir-calls
+            `(lambda (a)
+               (aref (vector a) 0))))))

-----------------------------------------------------------------------


hooks/post-receive
-- 
SBCL
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.