From e4f3dfe7fefc2ab3980360ce597dc378c6b02393 Mon Sep 17 00:00:00 2001 From: Paul Khuong Date: Fri, 7 Jun 2013 19:06:32 -0400 Subject: [PATCH] More associativity-based constant-folding Detect patterns like (+ (- x k1) k2) and (* (/ x k1) k2). --- src/compiler/srctran.lisp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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" -- 1.7.10.4