master: Avoid creating bignums for (zerop (mask-field ...))

stassats via Sbcl-commits <[email protected]> Tue, 04 Aug 2026 14:39:12 +0000
Newsgroups gmane.lisp.steel-bank.cvs
Message-ID <[email protected]>
The branch "master" has been updated in SBCL:
       via  fa6891bcd19066601d081010e747ecd2df9ecbdd (commit)
      from  81a76a6346c84b70318f4554b470705b31d0550b (commit)

- Log -----------------------------------------------------------------
commit fa6891bcd19066601d081010e747ecd2df9ecbdd
Author: Stas Boukarev <[email protected]>
Date:   Tue Aug 4 17:36:24 2026 +0300

    Avoid creating bignums for (zerop (mask-field ...))
    
    Which is a transformation of (ldb-test ...)
---
 src/compiler/srctran.lisp | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/compiler/srctran.lisp b/src/compiler/srctran.lisp
index 373f1ef51..9eeef6208 100644
--- a/src/compiler/srctran.lisp
+++ b/src/compiler/srctran.lisp
@@ -3618,13 +3618,22 @@
   (let* ((size (lvar-value size))
          (posn (lvar-value posn))
          (mask (mask-field (byte size posn) -1)))
-    (if (and (<= mask most-positive-word)
-             (or (combination-matches '= '(* 0) (node-dest node))
-                 (combination-matches '> '(* 0) (node-dest node))))
-        (progn
-          (erase-node-type node (specifier-type 'word))
-          `(logand integer ,mask))
-        (give-up-ir1-transform))))
+    (cond ((and (<= mask most-positive-word)
+                (or (combination-matches '= '(* 0) (node-dest node))
+                    (combination-matches '> '(* 0) (node-dest node))))
+           (erase-node-type node (specifier-type 'word))
+           `(logand integer ,mask))
+          (t
+           (give-up-ir1-transform)))))
+
+;;; Avoid creating bignums
+(deftransform %mask-field ((size posn int) * * :node node)
+  (cond ((or (combination-matches '= '(* 0) (node-dest node))
+             (combination-matches '> '(* 0) (node-dest node)))
+         (erase-node-type node (specifier-type 'unsigned-byte))
+         `(%ldb size posn int))
+        (t
+         (give-up-ir1-transform))))
 
 (deftransform %mask-field ((size posn int) ((integer 0 #.sb-vm:n-word-bits) fixnum integer) word)
   "convert to inline logical operations"

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


hooks/post-receive
-- 
SBCL