[cmucl-cvs] CMUCL commit: src/compiler (srctran.lisp)
Raymond Toy
rtoy at common-lisp.net
Wed Jan 12 00:41:34 UTC 2011
Date: Tuesday, January 11, 2011 @ 19:41:34
Author: rtoy
Path: /project/cmucl/cvsroot/src/compiler
Modified: srctran.lisp
Transform (EQ foo NIL) to the equivalent (IF foo NIL T). Optimization
suggested by Helmut Eller on cmucl-imp, 2011-01-08.
--------------+
srctran.lisp | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
Index: src/compiler/srctran.lisp
diff -u src/compiler/srctran.lisp:1.173 src/compiler/srctran.lisp:1.174
--- src/compiler/srctran.lisp:1.173 Tue Apr 20 13:57:46 2010
+++ src/compiler/srctran.lisp Tue Jan 11 19:41:34 2011
@@ -5,7 +5,7 @@
;;; Carnegie Mellon University, and has been placed in the public domain.
;;;
(ext:file-comment
- "$Header: /project/cmucl/cvsroot/src/compiler/srctran.lisp,v 1.173 2010-04-20 17:57:46 rtoy Rel $")
+ "$Header: /project/cmucl/cvsroot/src/compiler/srctran.lisp,v 1.174 2011-01-12 00:41:34 rtoy Exp $")
;;;
;;; **********************************************************************
;;;
@@ -2945,6 +2945,29 @@
(%deftransform x '(function * *) #'commutative-arg-swap
"place constant arg last."))
+;;; Convert (EQ foo NIL) and (EQ NIL foo) into the equivalent (if foo
+;;; nil t), like we do for NULL and NOT so that IF optimizations will
+;;; eliminate redundant negations.
+(deftransform eq ((x y) (t t) * :when :both)
+ ;; It would be nice to use commutative-arg-swap above for this.
+ ;; Then we only need to handle one case. But if we do that
+ ;; commutative-arg-swap converts (eq 'declare x) to (eq x declare),
+ ;; losing the quote on declare. I'm too lazy to fix that in
+ ;; commutative-arg-swap, so we do everything here.
+ (cond ((and (constant-continuation-p x)
+ (not (constant-continuation-p y))
+ (eq nil (continuation-value x)))
+ ;; (EQ NIL foo) case
+ `(if y nil t))
+ ((and (constant-continuation-p y)
+ (not (constant-continuation-p x))
+ (eq nil (continuation-value y)))
+ ;; (EQ foo NIL) case
+ `(if x nil t))
+ (t
+ ;; Give up on all others.
+ (give-up))))
+
;;; Handle the case of a constant boole-code.
;;;
(deftransform boole ((op x y) * * :when :both)
More information about the cmucl-cvs
mailing list