Move broken float optimizations out of main syntax class.
Introduces slight regression in already broken checks. original commit: 4fb96bdfa52657bf7596291658e9f7f877258fa6
This commit is contained in:
parent
e2d6458f3e
commit
fcc8ef6eb4
|
@ -30,7 +30,6 @@
|
|||
(define-merged-syntax-class projection^ (real-part^ imag-part^))
|
||||
|
||||
(define-merged-syntax-class float-complex-op (+^ -^ *^ conjugate^ exp^))
|
||||
(define-merged-syntax-class float-complex->float-op (magnitude^ projection^))
|
||||
|
||||
(define-syntax-class/specialize float-expr (subtyped-expr -Flonum))
|
||||
(define-syntax-class/specialize float-complex-expr (subtyped-expr -FloatComplex))
|
||||
|
@ -270,16 +269,6 @@
|
|||
#`(c.bindings ...
|
||||
((imag-binding) (unsafe-fl* -1.0 c.imag-binding))))
|
||||
|
||||
(pattern (#%plain-app op:magnitude^ c:unboxed-float-complex-opt-expr)
|
||||
#:with real-binding (generate-temporary "unboxed-real-")
|
||||
#:with imag-binding #'0.0
|
||||
#:do [(log-unboxing-opt "unboxed unary float complex")]
|
||||
#:with (bindings ...)
|
||||
#`(c.bindings ...
|
||||
((real-binding)
|
||||
(unsafe-flsqrt
|
||||
(unsafe-fl+ (unsafe-fl* c.real-binding c.real-binding)
|
||||
(unsafe-fl* c.imag-binding c.imag-binding))))))
|
||||
|
||||
(pattern (#%plain-app op:exp^ c:unboxed-float-complex-opt-expr)
|
||||
#:when (or (subtypeof? this-syntax -FloatComplex)
|
||||
|
@ -293,25 +282,6 @@
|
|||
((real-binding) (unsafe-fl* (unsafe-flcos c.imag-binding) scaling-factor))
|
||||
((imag-binding) (unsafe-fl* (unsafe-flsin c.imag-binding) scaling-factor))))
|
||||
|
||||
(pattern (#%plain-app op:real-part^ c:unboxed-float-complex-opt-expr)
|
||||
#:with real-binding #'c.real-binding
|
||||
#:with imag-binding #'0.0
|
||||
#:do [(log-unboxing-opt "unboxed unary float complex")]
|
||||
#:with (bindings ...) #'(c.bindings ...))
|
||||
(pattern (#%plain-app op:imag-part^ c:unboxed-float-complex-opt-expr)
|
||||
#:with real-binding #'c.imag-binding
|
||||
#:with imag-binding #'0.0
|
||||
#:do [(log-unboxing-opt "unboxed unary float complex")]
|
||||
#:with (bindings ...) #'(c.bindings ...))
|
||||
|
||||
;; special handling of reals inside complex operations
|
||||
;; must be after any cases that we are supposed to handle
|
||||
(pattern e:float-arg-expr
|
||||
#:with real-binding (generate-temporary 'unboxed-float-)
|
||||
#:with imag-binding #'0.0
|
||||
#:do [(log-unboxing-opt "float-arg-expr in complex ops")]
|
||||
#:with (bindings ...) #`(((real-binding) e.opt)))
|
||||
|
||||
|
||||
;; we can eliminate boxing that was introduced by the user
|
||||
(pattern (#%plain-app op:make-rectangular^ real:float-arg-expr imag:float-arg-expr)
|
||||
|
@ -351,14 +321,6 @@
|
|||
#:with (bindings ...)
|
||||
#`(((real-binding) '#,(real->double-flonum (real-part n)))
|
||||
((imag-binding) '#,(real->double-flonum (imag-part n)))))
|
||||
(pattern (quote n*:number)
|
||||
#:do [(define n (syntax->datum #'n*))]
|
||||
#:when (real? n)
|
||||
#:with real-binding (generate-temporary "unboxed-real-")
|
||||
#:with imag-binding #'0.0
|
||||
#:do [(log-unboxing-opt "unboxed literal")]
|
||||
#:with (bindings ...)
|
||||
#`(((real-binding) '#,(real->double-flonum n))))
|
||||
|
||||
(pattern e:float-complex-expr
|
||||
#:with e* (generate-temporary)
|
||||
|
@ -368,6 +330,14 @@
|
|||
#`(((e*) e.opt)
|
||||
((real-binding) (unsafe-flreal-part e*))
|
||||
((imag-binding) (unsafe-flimag-part e*))))
|
||||
|
||||
;; The following optimizations are incorrect and cause bugs because they turn exact numbers into inexact
|
||||
(pattern e:float-arg-expr
|
||||
#:with real-binding (generate-temporary 'unboxed-float-)
|
||||
#:with imag-binding #'0.0
|
||||
#:do [(log-unboxing-opt "float-arg-expr in complex ops")]
|
||||
#:with (bindings ...) #`(((real-binding) e.opt)))
|
||||
|
||||
(pattern e:opt-expr
|
||||
#:when (subtypeof? #'e -Number) ; complex, maybe exact, maybe not
|
||||
#:with e* (generate-temporary)
|
||||
|
@ -420,17 +390,6 @@
|
|||
;; required, otherwise syntax/parse is not happy
|
||||
#:with opt #'#f)
|
||||
|
||||
;; we can optimize taking the real of imag part of an unboxed complex
|
||||
;; hopefully, the compiler can eliminate unused bindings for the other part if it's not used
|
||||
(pattern (#%plain-app op:projection^ c:float-complex-expr)
|
||||
#:with c*:unboxed-float-complex-opt-expr #'c
|
||||
#:do [(log-unboxing-opt "complex accessor elimination")]
|
||||
#:with opt #`(let*-values (c*.bindings ...)
|
||||
#,(if (or (free-identifier=? #'op #'real-part)
|
||||
(free-identifier=? #'op #'flreal-part)
|
||||
(free-identifier=? #'op #'unsafe-flreal-part))
|
||||
#'c*.real-binding
|
||||
#'c*.imag-binding)))
|
||||
|
||||
(pattern (#%plain-app op:make-polar^ r theta)
|
||||
#:when (subtypeof? this-syntax -FloatComplex)
|
||||
|
@ -453,13 +412,32 @@
|
|||
#:commit
|
||||
#:attributes (opt)
|
||||
|
||||
(pattern (#%plain-app op:float-complex->float-op e:expr ...)
|
||||
#:when (subtypeof? this-syntax -Flonum)
|
||||
;; we can optimize taking the real of imag part of an unboxed complex
|
||||
;; hopefully, the compiler can eliminate unused bindings for the other part if it's not used
|
||||
(pattern (#%plain-app _:projection^ _:float-complex-expr)
|
||||
#:attr opt
|
||||
(delay
|
||||
(syntax-parse this-syntax
|
||||
(exp:unboxed-float-complex-opt-expr
|
||||
#'(let*-values (exp.bindings ...) exp.real-binding)))))
|
||||
[(#%plain-app op:projection^ c:unboxed-float-complex-opt-expr)
|
||||
(log-unboxing-opt "complex accessor elimination")
|
||||
#`(let*-values (c.bindings ...)
|
||||
#,(if (or (free-identifier=? #'op #'real-part)
|
||||
(free-identifier=? #'op #'flreal-part)
|
||||
(free-identifier=? #'op #'unsafe-flreal-part))
|
||||
#'c.real-binding
|
||||
#'c.imag-binding))])))
|
||||
|
||||
(pattern (#%plain-app _:magnitude^ _:float-complex-expr)
|
||||
#:attr opt
|
||||
(delay
|
||||
(syntax-parse this-syntax
|
||||
[(#%plain-app op:magnitude^ c:unboxed-float-complex-opt-expr)
|
||||
(log-unboxing-opt "unboxed unary float complex")
|
||||
#`(let*-values (c.bindings ...)
|
||||
(unsafe-flsqrt
|
||||
(unsafe-fl+ (unsafe-fl* c.real-binding c.real-binding)
|
||||
(unsafe-fl* c.imag-binding c.imag-binding))))])))
|
||||
|
||||
|
||||
(pattern (#%plain-app op:float-complex-op e:expr ...)
|
||||
#:when (subtypeof? this-syntax -FloatComplex)
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
(test-suite "Known bugs"
|
||||
|
||||
;; Arguments are converted to inexact too early
|
||||
(good-opt (* (make-rectangular -inf.0 1) (* 1 1)))
|
||||
(bad-opt (* (make-rectangular -inf.0 1) (* 1 1)))
|
||||
(bad-opt (/ -inf.0-inf.0i 8))
|
||||
(good-opt (- (* -1 1 +nan.0) 1.0+1.0i))
|
||||
(good-opt (- (* (/ 6 11) (/ 1.2345678f0 123456.7f0)) (make-rectangular 0.0 0.3)))
|
||||
|
|
|
@ -1,29 +1,33 @@
|
|||
#;#;
|
||||
#<<END
|
||||
TR opt: float-complex-parts3.rkt 41:0 (+ 1.0+2.0i (real-part (+ 2.0+4.0i 3.0+6.0i))) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 41:12 (real-part (+ 2.0+4.0i 3.0+6.0i)) -- unboxed unary float complex
|
||||
TR opt: float-complex-parts3.rkt 41:23 (+ 2.0+4.0i 3.0+6.0i) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 41:26 2.0+4.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 41:3 1.0+2.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 41:35 3.0+6.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 42:0 (+ 1.0+2.0i (unsafe-flreal-part (+ 2.0+4.0i 3.0+6.0i))) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 42:12 (unsafe-flreal-part (+ 2.0+4.0i 3.0+6.0i)) -- unboxed unary float complex
|
||||
TR opt: float-complex-parts3.rkt 42:3 1.0+2.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 42:32 (+ 2.0+4.0i 3.0+6.0i) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 42:35 2.0+4.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 42:44 3.0+6.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 43:0 (+ 1.0+2.0i (imag-part (+ 2.0+4.0i 3.0+6.0i))) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 43:12 (imag-part (+ 2.0+4.0i 3.0+6.0i)) -- unboxed unary float complex
|
||||
TR opt: float-complex-parts3.rkt 43:23 (+ 2.0+4.0i 3.0+6.0i) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 43:26 2.0+4.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 43:3 1.0+2.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 43:35 3.0+6.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 44:0 (+ 1.0+2.0i (unsafe-flimag-part (+ 2.0+4.0i 3.0+6.0i))) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 44:12 (unsafe-flimag-part (+ 2.0+4.0i 3.0+6.0i)) -- unboxed unary float complex
|
||||
TR opt: float-complex-parts3.rkt 44:3 1.0+2.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 44:32 (+ 2.0+4.0i 3.0+6.0i) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 44:35 2.0+4.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 44:44 3.0+6.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 45:0 (+ 1.0+2.0i (real-part (+ 2.0+4.0i 3.0+6.0i))) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 45:12 (real-part (+ 2.0+4.0i 3.0+6.0i)) -- complex accessor elimination
|
||||
TR opt: float-complex-parts3.rkt 45:12 (real-part (+ 2.0+4.0i 3.0+6.0i)) -- float-arg-expr in complex ops
|
||||
TR opt: float-complex-parts3.rkt 45:23 (+ 2.0+4.0i 3.0+6.0i) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 45:26 2.0+4.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 45:3 1.0+2.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 45:35 3.0+6.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 46:0 (+ 1.0+2.0i (unsafe-flreal-part (+ 2.0+4.0i 3.0+6.0i))) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 46:12 (unsafe-flreal-part (+ 2.0+4.0i 3.0+6.0i)) -- complex accessor elimination
|
||||
TR opt: float-complex-parts3.rkt 46:12 (unsafe-flreal-part (+ 2.0+4.0i 3.0+6.0i)) -- float-arg-expr in complex ops
|
||||
TR opt: float-complex-parts3.rkt 46:3 1.0+2.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 46:32 (+ 2.0+4.0i 3.0+6.0i) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 46:35 2.0+4.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 46:44 3.0+6.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 47:0 (+ 1.0+2.0i (imag-part (+ 2.0+4.0i 3.0+6.0i))) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 47:12 (imag-part (+ 2.0+4.0i 3.0+6.0i)) -- complex accessor elimination
|
||||
TR opt: float-complex-parts3.rkt 47:12 (imag-part (+ 2.0+4.0i 3.0+6.0i)) -- float-arg-expr in complex ops
|
||||
TR opt: float-complex-parts3.rkt 47:23 (+ 2.0+4.0i 3.0+6.0i) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 47:26 2.0+4.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 47:3 1.0+2.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 47:35 3.0+6.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 48:0 (+ 1.0+2.0i (unsafe-flimag-part (+ 2.0+4.0i 3.0+6.0i))) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 48:12 (unsafe-flimag-part (+ 2.0+4.0i 3.0+6.0i)) -- complex accessor elimination
|
||||
TR opt: float-complex-parts3.rkt 48:12 (unsafe-flimag-part (+ 2.0+4.0i 3.0+6.0i)) -- float-arg-expr in complex ops
|
||||
TR opt: float-complex-parts3.rkt 48:3 1.0+2.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 48:32 (+ 2.0+4.0i 3.0+6.0i) -- unboxed binary float complex
|
||||
TR opt: float-complex-parts3.rkt 48:35 2.0+4.0i -- unboxed literal
|
||||
TR opt: float-complex-parts3.rkt 48:44 3.0+6.0i -- unboxed literal
|
||||
END
|
||||
#<<END
|
||||
6.0+2.0i
|
||||
|
|
|
@ -1,37 +1,13 @@
|
|||
#;#;
|
||||
#<<END
|
||||
TR missed opt: pr13468.rkt 92:5 (/ (ann 0.0+0.0i Float-Complex) (ann 1 Number)) -- Float-Complex division, potential exact 0s on the rhss -- caused by: 92:42 1
|
||||
TR missed opt: pr13468.rkt 95:5 (expt (ann -5.0 Flonum) (ann 2.0 Flonum)) -- unexpected complex type
|
||||
TR opt: pr13468.rkt 116:21 0.0 -- float-arg-expr in complex ops
|
||||
TR opt: pr13468.rkt 116:5 (magnitude (ann 0.0 Flonum-Zero)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 117:21 6.0 -- float-arg-expr in complex ops
|
||||
TR opt: pr13468.rkt 117:5 (magnitude (ann 6.0 Positive-Flonum)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 118:21 6.0 -- float-arg-expr in complex ops
|
||||
TR opt: pr13468.rkt 118:5 (magnitude (ann 6.0 Nonnegative-Flonum)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 119:21 -6.0 -- float-arg-expr in complex ops
|
||||
TR opt: pr13468.rkt 119:5 (magnitude (ann -6.0 Nonpositive-Flonum)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 120:21 -6.0 -- float-arg-expr in complex ops
|
||||
TR opt: pr13468.rkt 120:5 (magnitude (ann -6.0 Negative-Flonum)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 121:21 6.0 -- float-arg-expr in complex ops
|
||||
TR opt: pr13468.rkt 121:5 (magnitude (ann 6.0 Flonum)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 142:21 0.0 -- float-arg-expr in complex ops
|
||||
TR opt: pr13468.rkt 142:5 (real-part (ann 0.0 Flonum-Zero)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 143:21 6.0 -- float-arg-expr in complex ops
|
||||
TR opt: pr13468.rkt 143:5 (real-part (ann 6.0 Positive-Flonum)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 144:21 6.0 -- float-arg-expr in complex ops
|
||||
TR opt: pr13468.rkt 144:5 (real-part (ann 6.0 Nonnegative-Flonum)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 145:21 -6.0 -- float-arg-expr in complex ops
|
||||
TR opt: pr13468.rkt 145:5 (real-part (ann -6.0 Nonpositive-Flonum)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 146:21 -6.0 -- float-arg-expr in complex ops
|
||||
TR opt: pr13468.rkt 146:5 (real-part (ann -6.0 Negative-Flonum)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 147:21 6.0 -- float-arg-expr in complex ops
|
||||
TR opt: pr13468.rkt 147:5 (real-part (ann 6.0 Flonum)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 90:13 6.0+2.3i -- unboxed literal
|
||||
TR opt: pr13468.rkt 90:13 6.0+2.3i -- unboxed literal
|
||||
TR opt: pr13468.rkt 90:5 (- (ann 6.0+2.3i Float-Complex)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 91:13 6.0+2.3i -- unboxed literal
|
||||
TR opt: pr13468.rkt 91:13 6.0+2.3i -- unboxed literal
|
||||
TR opt: pr13468.rkt 91:5 (/ (ann 6.0+2.3i Float-Complex)) -- unboxed unary float complex
|
||||
TR missed opt: pr13468.rkt 68:5 (/ (ann 0.0+0.0i Float-Complex) (ann 1 Number)) -- Float-Complex division, potential exact 0s on the rhss -- caused by: 68:42 1
|
||||
TR missed opt: pr13468.rkt 71:5 (expt (ann -5.0 Flonum) (ann 2.0 Flonum)) -- unexpected complex type
|
||||
TR opt: pr13468.rkt 66:13 6.0+2.3i -- unboxed literal
|
||||
TR opt: pr13468.rkt 66:13 6.0+2.3i -- unboxed literal
|
||||
TR opt: pr13468.rkt 66:5 (- (ann 6.0+2.3i Float-Complex)) -- unboxed unary float complex
|
||||
TR opt: pr13468.rkt 67:13 6.0+2.3i -- unboxed literal
|
||||
TR opt: pr13468.rkt 67:13 6.0+2.3i -- unboxed literal
|
||||
TR opt: pr13468.rkt 67:5 (/ (ann 6.0+2.3i Float-Complex)) -- unboxed unary float complex
|
||||
END
|
||||
#<<END
|
||||
-6.0-2.3i
|
||||
|
|
Loading…
Reference in New Issue
Block a user