From 3c25a14fa1f4c7f063babed8ef0a1a5d335298c6 Mon Sep 17 00:00:00 2001 From: Paul Khuong Date: Fri, 7 Jun 2013 19:03:44 -0400 Subject: [PATCH] Enable signed modular arithmetic for LOGIOR When the result of a bitwise or is known to be negative, we don't need to compute the most significant bits (they're all ones). --- NEWS | 2 ++ src/compiler/srctran.lisp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/NEWS b/NEWS index 1f805df..b23e3ee 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,8 @@ changes relative to sbcl-1.1.8: comparison, instead of two. * optimization: enable more modular arithmetic transforms in the presence of conditionals. + * optimization: bitwise OR forms can now trigger modular arithmetic as well, + when the result is known to be negative. * bug fix: problems with NCONC type derivation (reported by Jerry James). * bug fix: EXPT type derivation no longer constructs bogus floating-point types. (reported by Vsevolod Dyomkin) diff --git a/src/compiler/srctran.lisp b/src/compiler/srctran.lisp index 713a106..c1aa106 100644 --- a/src/compiler/srctran.lisp +++ b/src/compiler/srctran.lisp @@ -3113,6 +3113,24 @@ (cut-to-width x kind w t) nil ; After fixing above, replace with T. ))))))) + +(defoptimizer (logior optimizer) ((x y) node) + (let ((result-type (single-value-type (node-derived-type node)))) + (multiple-value-bind (low high) + (integer-type-numeric-bounds result-type) + (when (and (numberp low) + (numberp high) + (<= high 0)) + (let ((width (integer-length low))) + (multiple-value-bind (w kind) + (best-modular-version (1+ width) t) + (when w + ;; FIXME: see comment in LOGAND optimizer + (let ((xact (cut-to-width x kind w t)) + (yact (cut-to-width y kind w t))) + (declare (ignore xact yact)) + nil) ; After fixing above, replace with T + ))))))) ;;; miscellanous numeric transforms -- 1.7.10.4