master: Transform floor/ceiling to truncate when used as a divisibility test

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  3eb58efbbe070e67ad7968f36e8d9c59b2e81e1f (commit)
      from  914726b494c081ae0a4cfe5e21c92f7532ff7f98 (commit)

- Log -----------------------------------------------------------------
commit 3eb58efbbe070e67ad7968f36e8d9c59b2e81e1f
Author: Stas Boukarev <[email protected]>
Date:   Mon Apr 20 04:26:35 2026 +0300

    Transform floor/ceiling to truncate when used as a divisibility test
---
 src/compiler/srctran.lisp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/compiler/srctran.lisp b/src/compiler/srctran.lisp
index d48a4d38c..1af378318 100644
--- a/src/compiler/srctran.lisp
+++ b/src/compiler/srctran.lisp
@@ -4653,6 +4653,16 @@
                          (truly-the ,rem-type rem)))))
         (give-up-ir1-transform))))
 
+;;; (zerop (mod x y)) => (zerop (rem x y))
+(deftransforms (floor ceiling) ((number divisor) (rational rational) * :result result :node node)
+  (let ((rem (and (mv-bind-unused-p result 0)
+                  (mv-bind-dest result 1 t))))
+    (cond ((combination-matches 'eq '(* 0) rem)
+           (erase-node-type node (values-specifier-type '(values integer rational &optional)))
+           `(truncate number divisor))
+          (t
+           (give-up-ir1-transform)))))
+
 (deftransform ceiling ((number divisor) ((and unsigned-byte fixnum) (and unsigned-byte fixnum)) * :result result)
   (if (and result
            (lvar-single-value-p result))

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


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.