diff --git a/collects/tests/typed-racket/optimizer/tests/fixnum-bounded-expr.rkt b/collects/tests/typed-racket/optimizer/tests/fixnum-bounded-expr.rkt index 58081530..271d8f81 100644 --- a/collects/tests/typed-racket/optimizer/tests/fixnum-bounded-expr.rkt +++ b/collects/tests/typed-racket/optimizer/tests/fixnum-bounded-expr.rkt @@ -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 @@ -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 diff --git a/collects/tests/typed-racket/optimizer/tests/invalid-fxquotient.rkt b/collects/tests/typed-racket/optimizer/tests/invalid-fxquotient.rkt index d2c0611a..c0f1fd69 100644 --- a/collects/tests/typed-racket/optimizer/tests/invalid-fxquotient.rkt +++ b/collects/tests/typed-racket/optimizer/tests/invalid-fxquotient.rkt @@ -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 diff --git a/collects/typed-racket/optimizer/fixnum.rkt b/collects/typed-racket/optimizer/fixnum.rkt index 4d55c5f7..585774c4 100644 --- a/collects/typed-racket/optimizer/fixnum.rkt +++ b/collects/typed-racket/optimizer/fixnum.rkt @@ -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)