Optimize fx->fl when safe.
original commit: a21caa361cd31fa3b6d553d8f7126aa503e6a015
This commit is contained in:
parent
56beba63d3
commit
58b694fff1
|
@ -62,6 +62,8 @@
|
|||
(define-bitwise-syntax-class (and ior xor not))
|
||||
|
||||
(define-unsafe-syntax-class exact->inexact^ (exact->inexact) unsafe-fx->fl)
|
||||
(define-unsafe-syntax-class fx->fl^ (fx->fl) unsafe-fx->fl)
|
||||
(define-merged-syntax-class fixnum-coercion-op (exact->inexact^ fx->fl^))
|
||||
(define-literal-syntax-class add1)
|
||||
(define-literal-syntax-class sub1)
|
||||
(define-literal-syntax-class zero?)
|
||||
|
@ -158,7 +160,7 @@
|
|||
#:do [(log-fx-opt "unary fixnum")]
|
||||
#:with opt #'(op.unsafe 0 f.opt))
|
||||
|
||||
(pattern (op:exact->inexact^ n:fixnum-expr)
|
||||
(pattern (op:fixnum-coercion-op n:fixnum-expr)
|
||||
#:do [(log-fx-opt "fixnum to float")]
|
||||
#:with opt #'(op.unsafe n.opt))
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#;#;
|
||||
#<<END
|
||||
TR missed opt: fx2fl.rkt 15:40 (* 1024 i) -- out of fixnum range
|
||||
TR opt: fx2fl.rkt 10:20 (+ s (/ 1.0 (fx->fl i))) -- binary float
|
||||
TR opt: fx2fl.rkt 10:25 (/ 1.0 (fx->fl i)) -- binary float
|
||||
TR opt: fx2fl.rkt 10:32 (fx->fl i) -- fixnum to float
|
||||
TR opt: fx2fl.rkt 12:9 (for/fold: : Float ((s : Float 0.0)) ((i : Fixnum (in-range 1 100000001))) (+ s (/ 1.0 (fx->fl (* 1024 i))))) -- dead else branch
|
||||
TR opt: fx2fl.rkt 12:9 (for/fold: : Float ((s : Float 0.0)) ((i : Fixnum (in-range 1 100000001))) (+ s (/ 1.0 (fx->fl (* 1024 i))))) -- dead else branch
|
||||
TR opt: fx2fl.rkt 12:9 (for/fold: : Float ((s : Float 0.0)) ((i : Fixnum (in-range 1 100000001))) (+ s (/ 1.0 (fx->fl (* 1024 i))))) -- dead else branch
|
||||
TR opt: fx2fl.rkt 13:22 s -- dead else branch
|
||||
TR opt: fx2fl.rkt 13:22 s -- dead else branch
|
||||
TR opt: fx2fl.rkt 15:20 (+ s (/ 1.0 (fx->fl (* 1024 i)))) -- binary float
|
||||
TR opt: fx2fl.rkt 15:25 (/ 1.0 (fx->fl (* 1024 i))) -- binary float
|
||||
TR opt: fx2fl.rkt 7:9 (for/fold: : Float ((s : Float 0.0)) ((i : Fixnum (in-range 1 100000001))) (+ s (/ 1.0 (fx->fl i)))) -- dead else branch
|
||||
TR opt: fx2fl.rkt 7:9 (for/fold: : Float ((s : Float 0.0)) ((i : Fixnum (in-range 1 100000001))) (+ s (/ 1.0 (fx->fl i)))) -- dead else branch
|
||||
TR opt: fx2fl.rkt 7:9 (for/fold: : Float ((s : Float 0.0)) ((i : Fixnum (in-range 1 100000001))) (+ s (/ 1.0 (fx->fl i)))) -- dead else branch
|
||||
TR opt: fx2fl.rkt 8:22 s -- dead else branch
|
||||
TR opt: fx2fl.rkt 8:22 s -- dead else branch
|
||||
END
|
||||
""
|
||||
#lang typed/racket
|
||||
#:optimize
|
||||
#reader tests/typed-racket/optimizer/reset-port
|
||||
|
||||
(require racket/fixnum)
|
||||
|
||||
;; from http://stackoverflow.com/questions/22868795/how-to-optimize-this-piece-of-racket-code
|
||||
|
||||
(define: (test) : Float
|
||||
(for/fold: : Float
|
||||
([s : Float 0.0])
|
||||
([i : Fixnum (in-range 1 100000001)])
|
||||
(+ s (/ 1.0 (fx->fl i))))) ; should be optimized
|
||||
(define: (test2) : Float
|
||||
(for/fold: : Float
|
||||
([s : Float 0.0])
|
||||
([i : Fixnum (in-range 1 100000001)])
|
||||
(+ s (/ 1.0 (fx->fl (* 1024 i)))))) ; should not
|
Loading…
Reference in New Issue
Block a user