From: Paul Khuong Date: Fri, 7 Jun 2013 23:06:32 +0000 (-0400) Subject: More associativity-based constant-folding X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=e4f3dfe7fefc2ab3980360ce597dc378c6b02393;p=sbcl.git More associativity-based constant-folding Detect patterns like (+ (- x k1) k2) and (* (/ x k1) k2). --- diff --git a/src/compiler/srctran.lisp b/src/compiler/srctran.lisp index c1aa106..d408fa3 100644 --- a/src/compiler/srctran.lisp +++ b/src/compiler/srctran.lisp @@ -3444,13 +3444,17 @@ (splice-fun-args x ',folded 2) `(lambda (x y z) (declare (ignore y z)) - (,',operator x ',(,folded y (lvar-value z)))))))) + ;; (operator (folded x y) z) + ;; == (operator x (folded z y)) + (,',operator x ',(,folded (lvar-value z) y))))))) (def logand) (def logior) (def logxor) (def logtest :folded logand) (def + :type rational) - (def * :type rational)) + (def + :type rational :folded -) + (def * :type rational) + (def * :type rational :folded /)) (deftransform mask-signed-field ((width x) ((constant-arg unsigned-byte) *)) "Fold mask-signed-field/mask-signed-field of constant width"