Skip to content

Commit

Permalink
Fix unsound fxquotient optimization.
Browse files Browse the repository at this point in the history
Closes PR13827.
(cherry picked from commit 5e30416)
  • Loading branch information
stamourv authored and rmculpepper committed Jul 8, 2013
1 parent d04ee61 commit 4e360f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Expand Up @@ -25,7 +25,7 @@ TR opt: fixnum-bounded-expr.rkt 99:5 (+ 300 301) -- fixnum bounded expr
TR opt: fixnum-bounded-expr.rkt 99:17 (+ 301 302) -- fixnum bounded expr
TR opt: fixnum-bounded-expr.rkt 99:0 (fx- (+ 300 301) (+ 301 302)) -- fixnum fx-
TR opt: fixnum-bounded-expr.rkt 102:0 (fx* 4 5) -- fixnum fx*
TR opt: fixnum-bounded-expr.rkt 105:0 (fxquotient (ann 34 Nonnegative-Fixnum) (ann -4 Fixnum)) -- fixnum fxquotient
TR opt: fixnum-bounded-expr.rkt 105:0 (fxquotient (ann 34 Nonnegative-Fixnum) (ann -4 Negative-Fixnum)) -- fixnum fxquotient
TR opt: fixnum-bounded-expr.rkt 108:0 (fxabs (ann 64235 Nonnegative-Fixnum)) -- fixnum fxabs
28
89525
Expand Down Expand Up @@ -102,7 +102,7 @@ TR opt: fixnum-bounded-expr.rkt 108:0 (fxabs (ann 64235 Nonnegative-Fixnum)) --
(fx* 4 5) ; ok, (* Byte Byte)
(fx* 300 300) ; not ok

(fxquotient (ann 34 Nonnegative-Fixnum) (ann -4 Fixnum))
(fxquotient (ann 34 Nonnegative-Fixnum) (ann -4 Negative-Fixnum))
(fxquotient -4 -5) ; not ok

(fxabs (ann 64235 Nonnegative-Fixnum)) ; ok
Expand Down
@@ -1,11 +1,14 @@
#;
(
TR missed opt: invalid-fxquotient.rkt 10:21 (quotient fixnum-min -1) -- out of fixnum range
TR missed opt: invalid-fxquotient.rkt 12:21 (quotient fixnum-min -1) -- out of fixnum range
#t
)

#lang typed/racket/base

(require racket/fixnum)

(define: fixnum-min : Nonpositive-Fixnum (assert (- (expt 2 30)) fixnum?))
(define: q : Natural (quotient fixnum-min -1)) ; this can't be optimized safely
(= 1073741824 q)
(define (bad) (fxquotient 3 0)) ; can't be optimized
5 changes: 2 additions & 3 deletions collects/typed-racket/optimizer/fixnum.rkt
Expand Up @@ -194,9 +194,8 @@
(begin (log-optimization "fixnum fx*" fixnum-opt-msg this-syntax)
(add-disappeared-use #'op)
#'(unsafe-fx* n1.opt n2.opt)))
(pattern (#%plain-app (~and op (~literal fxquotient)) n1:fixnum-expr n2:fixnum-expr)
#:when (and (subtypeof? #'n1 -NonNegFixnum)
(subtypeof? #'n2 -Fixnum))
(pattern (#%plain-app (~and op (~literal fxquotient)) n1:fixnum-expr n2:nonzero-fixnum-expr)
#:when (subtypeof? #'n1 -NonNegFixnum)
#:with opt
(begin (log-optimization "fixnum fxquotient" fixnum-opt-msg this-syntax)
(add-disappeared-use #'op)
Expand Down

0 comments on commit 4e360f8

Please sign in to comment.