(give-up-ir1-transform
"The operands might not be the same type.")))))
-(labels ((maybe-float-lvar-p (lvar)
- (neq *empty-type* (type-intersection (specifier-type 'float)
- (lvar-type lvar))))
- (maybe-invert (op inverted x y)
- ;; Don't invert if either argument can be a float (NaNs)
- (if (or (maybe-float-lvar-p x) (maybe-float-lvar-p y))
- `(or (,op x y) (= x y))
- `(if (,inverted x y) nil t))))
+(defun maybe-float-lvar-p (lvar)
+ (neq *empty-type* (type-intersection (specifier-type 'float)
+ (lvar-type lvar))))
+
+(flet ((maybe-invert (op inverted x y)
+ ;; Don't invert if either argument can be a float (NaNs)
+ (if (or (maybe-float-lvar-p x) (maybe-float-lvar-p y))
+ `(or (,op x y) (= x y))
+ `(if (,inverted x y) nil t))))
(deftransform >= ((x y) (number number) *)
"invert or open code"
(maybe-invert '> '< x y))
(macrolet ((def (name inverse reflexive-p surely-true surely-false)
`(deftransform ,name ((x y))
"optimize using intervals"
- (if (same-leaf-ref-p x y)
+ (if (and (same-leaf-ref-p x y)
+ ;; For non-reflexive functions we don't need
+ ;; to worry about NaNs: (non-ref-op NaN NaN) => false,
+ ;; but with reflexive ones we don't know...
+ ,@(when reflexive-p
+ '((and (not (maybe-float-lvar-p x))
+ (not (maybe-float-lvar-p y))))))
,reflexive-p
(let ((ix (or (type-approximate-interval (lvar-type x))
(give-up-ir1-transform)))
(macrolet ((test (form)
(let ((nform (subst '(/ 0.0 0.0) 'nan form)))
`(progn
- (assert (not (eval ',nform)))
- (assert (not (funcall (lambda () ,nform))))))))
- ;; Source transforms for >= and <= used to be too eager about
- ;; inverting the test, causing NaN issues.
- (test (>= nan 1.0))
- (test (>= 1.0 nan))
- (test (>= 1.0 nan 0.0))
- (test (>= 1.0 0.0 nan))
- (test (>= nan 1.0 0.0))
- (test (<= nan 1.0))
- (test (<= 1.0 nan))
- (test (<= 1.0 nan 2.0))
- (test (<= 1.0 2.0 nan))
- (test (<= nan 1.0 2.0)))))
+ (assert (eval ',nform))
+ (assert (eval `(let ((nan (/ 0.0 0.0)))
+ ,',form)))
+ (assert (funcall
+ (compile nil `(lambda () ,',nform))))
+ (assert (funcall
+ (compile nil `(lambda (nan) ,',form))
+ (/ 0.0 0.0)))))))
+ (test (/= nan nan))
+ (test (/= nan nan nan))
+ (test (/= 1.0 nan 2.0 nan))
+ (test (/= nan 1.0 2.0 nan))
+ (test (not (= nan 1.0)))
+ (test (not (= nan nan)))
+ (test (not (= nan nan nan)))
+ (test (not (= 1.0 nan)))
+ (test (not (= nan 1.0)))
+ (test (not (= 1.0 1.0 nan)))
+ (test (not (= 1.0 nan 1.0)))
+ (test (not (= nan 1.0 1.0)))
+ (test (not (>= nan nan)))
+ (test (not (>= nan 1.0)))
+ (test (not (>= 1.0 nan)))
+ (test (not (>= 1.0 nan 0.0)))
+ (test (not (>= 1.0 0.0 nan)))
+ (test (not (>= nan 1.0 0.0)))
+ (test (not (<= nan nan)))
+ (test (not (<= nan 1.0)))
+ (test (not (<= 1.0 nan)))
+ (test (not (<= 1.0 nan 2.0)))
+ (test (not (<= 1.0 2.0 nan)))
+ (test (not (<= nan 1.0 2.0)))
+ (test (not (< nan nan)))
+ (test (not (< -1.0 nan)))
+ (test (not (< nan 1.0)))
+ (test (not (> nan nan)))
+ (test (not (> -1.0 nan)))
+ (test (not (> nan 1.0))))))