From faaca670fd56040991d8f6e0b02adebc1e71d7bc Mon Sep 17 00:00:00 2001 From: Paul Khuong Date: Wed, 22 May 2013 00:50:01 -0400 Subject: [PATCH] Optimize (- (* x constant)) into (* x (- constant)) Another marginal lvar-fun-name/splice-fun-arg hack. Closes lp#1065770. --- src/compiler/srctran.lisp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/compiler/srctran.lisp b/src/compiler/srctran.lisp index 90d1077..22d9f48 100644 --- a/src/compiler/srctran.lisp +++ b/src/compiler/srctran.lisp @@ -3429,6 +3429,20 @@ (splice-fun-args x '%negate 1) '(the rational x)) +(deftransform %negate ((x) (number)) + "Combine %negate/*" + (let ((use (lvar-uses x)) + arg) + (unless (and (combination-p use) + (eql '* (lvar-fun-name (combination-fun use))) + (constant-lvar-p (setf arg (second (combination-args use)))) + (numberp (setf arg (lvar-value arg)))) + (give-up-ir1-transform)) + (splice-fun-args x '* 2) + `(lambda (x y) + (declare (ignore y)) + (* x ,(- arg))))) + ;;; Return T if in an arithmetic op including lvars X and Y, the ;;; result type is not affected by the type of X. That is, Y is at ;;; least as contagious as X. -- 1.7.10.4