From 6ab111524c3570785641c656080c58b3637e5779 Mon Sep 17 00:00:00 2001
From: toy <toy>
Date: Sat, 10 Jan 2004 05:01:41 +0000
Subject: [PATCH] Add a deftransform for ABS so that if the arg is known to be
 non-negative we don't have to call abs at all.

---
 compiler/float-tran.lisp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/compiler/float-tran.lisp b/compiler/float-tran.lisp
index b9c2510cc..2e73790d1 100644
--- a/compiler/float-tran.lisp
+++ b/compiler/float-tran.lisp
@@ -5,7 +5,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/float-tran.lisp,v 1.96 2004/01/09 04:20:59 toy Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/float-tran.lisp,v 1.97 2004/01/10 05:01:41 toy Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -591,6 +591,15 @@
 		   (coerce (imagpart x) 'double-float))
 	  'single-float))
 
+(deftransform abs ((x) (real) real)
+  (let ((x-type (continuation-type x)))
+    ;; If the arg is known to non-negative, we can just return the
+    ;; arg.  However, (abs -0.0) is 0.0, so this transform only works
+    ;; on floats that are known not to include negative zero.
+    (if (csubtypep x-type (specifier-type '(or (rational 0) (float (0d0)) (member 0f0 0d0))))
+	'x
+	(give-up))))
+
 (deftransform phase ((x) ((complex double-float)) double-float :when :both)
   '(%atan2 (imagpart x) (realpart x)))
 
-- 
GitLab