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

Which is a transformation of (ldb-test ...)
This commit is contained in:
Stas Boukarev 2026-08-04 17:36:24 +03:00
parent 81a76a6346
commit fa6891bcd1

View file

@ -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"