master: Fix ash-modfx constant folding

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  186fa8ba9f2245fd507f97208104c71d03ce7afe (commit)
      from  df956be42674804c273fabaa4643681282fb0273 (commit)

- Log -----------------------------------------------------------------
commit 186fa8ba9f2245fd507f97208104c71d03ce7afe
Author: Stas Boukarev <[email protected]>
Date:   Thu Apr 9 04:12:08 2026 +0300

    Fix ash-modfx constant folding
---
 src/code/numbers.lisp   |  6 ++----
 tests/arith-2.pure.lisp | 10 ++++++++++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/code/numbers.lisp b/src/code/numbers.lisp
index e8f67efc6..6f8f8bc87 100644
--- a/src/code/numbers.lisp
+++ b/src/code/numbers.lisp
@@ -1983,7 +1983,7 @@ and the number of 0 bits if INTEGER is negative."
 
 #+(or x86 x86-64 arm arm64)
 (defun sb-vm::ash-left-modfx (integer amount)
-  (let ((fixnum-width (- sb-vm:n-word-bits sb-vm:n-fixnum-tag-bits)))
+  (let ((fixnum-width sb-vm:n-fixnum-bits))
     (etypecase integer
       (fixnum (sb-c::mask-signed-field fixnum-width (ash integer amount)))
       (integer (sb-c::mask-signed-field fixnum-width (ash (sb-c::mask-signed-field fixnum-width integer) amount))))))
@@ -1993,9 +1993,7 @@ and the number of 0 bits if INTEGER is negative."
     (ldb (byte 64 0) (ash integer amount)))
 
   (defun sb-vm::ash-modfx (integer amount)
-    (if (minusp integer)
-        (sb-c::mask-signed-field sb-vm:n-fixnum-bits (ash integer amount))
-        (logand most-positive-fixnum (ash integer amount)))))
+    (sb-c::mask-signed-field sb-vm:n-fixnum-bits (ash integer amount))))
 
 (defun sb-vm::truncate-mod64 (a b)
   (multiple-value-bind (q r) (truncate a b)
diff --git a/tests/arith-2.pure.lisp b/tests/arith-2.pure.lisp
index 7c6ee9bb0..ed480fac7 100644
--- a/tests/arith-2.pure.lisp
+++ b/tests/arith-2.pure.lisp
@@ -2507,3 +2507,13 @@
               (integer b))
      (truncate a b))
    (values (integer -5 5) (rational -5 4) &optional)))
+
+(with-test (:name :ash-modfx-constant-fold)
+  (checked-compile-and-assert
+      ()
+      `(lambda (b)
+         (declare (fixnum b))
+         (when (eq b (1- sb-vm:n-fixnum-bits))
+           (ldb (byte sb-vm:n-fixnum-bits 0) (ash 1 b))))
+    (((1- sb-vm:n-fixnum-bits)) (ash 1 (1- sb-vm:n-fixnum-bits)))
+    ((0) nil)))

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


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.