Fix cut-to-width

The logand mask has to be checked to be unsigned

Fixes lp#2166725
This commit is contained in:
Stas Boukarev 2026-09-08 06:06:54 +03:00
parent d79b179ccb
commit a42c09f297
2 changed files with 11 additions and 6 deletions

View file

@ -200,12 +200,9 @@
(unless (cond ((and (vop-existsp :named sb-vm::logand-word-mask)
;; logand-word-mask works without inserting additional cuts
(combination-match2 ((lvar-dest lvar) :transform nil)
((logand a b)
(let ((other-type
(lvar-type (if (lvar-from-lvar-p b lvar)
a
b))))
(csubtypep other-type type))))))
((logand (:type unsigned-byte a) b)
(when (lvar-from-lvar-p b lvar)
(csubtypep (lvar-type a) type))))))
(t
(combination-match2 ((lvar-dest lvar) :transform nil)

View file

@ -2655,3 +2655,11 @@
((5 11) t)
((5 10) nil)
(((ash 1 (1- sb-vm:n-word-bits)) 0) (condition 'type-error))))
(with-test (:name :cut-to-width-omit-logand)
(checked-compile-and-assert
()
`(lambda (d)
(logand (lognot (logand d -3)) 1))
((-7726172277034401953) 0)
((0) 1)))