diff --git a/module/language/cps/compile-bytecode.scm b/module/language/cps/compile-bytecode.scm index f7c8fbb5e..0baa30992 100644 --- a/module/language/cps/compile-bytecode.scm +++ b/module/language/cps/compile-bytecode.scm @@ -427,6 +427,8 @@ (binary op emit-je emit-jne a b)) (define (binary-< emit-) (values #t #f)) + (else (values #f #f))) + (values #f #f))) + (define-unary-branch-folder* (u64-imm-= c type min max) (cond ((= c min max) (values #t #t)) diff --git a/module/language/cps/types.scm b/module/language/cps/types.scm index dd2206b00..5c213fc5c 100644 --- a/module/language/cps/types.scm +++ b/module/language/cps/types.scm @@ -1068,6 +1068,12 @@ minimum, and maximum." (restrict! a &exact-number (max min0 min1) max0) (restrict! b &exact-number min1 (min max0 max1))))))))) +(define (infer-<= types succ param a b) + ;; Infer "(<= a b)" as "(not (< b a))", knowing that we only make + ;; inferences when NaN is impossible. + ((hashq-ref *type-inferrers* '<) types (match succ (0 1) (1 0)) param b a)) +(hashq-set! *type-inferrers* '<= infer-<=) + (define-predicate-inferrer (u64-= a b true?) (infer-= a b true?)) (define-predicate-inferrer (u64-< a b true?) diff --git a/module/language/tree-il/compile-cps.scm b/module/language/tree-il/compile-cps.scm index 49274c478..ed7ed47fc 100644 --- a/module/language/tree-il/compile-cps.scm +++ b/module/language/tree-il/compile-cps.scm @@ -1140,16 +1140,16 @@ integer." (make-const src #f))))) (($ src '<= (a b)) - ;; No need to reduce as < is a branching primitive. - (make-conditional src (make-primcall src '< (list b a)) - (make-const src #f) - (make-const src #t))) + ;; No need to reduce as <= is a branching primitive. + (make-conditional src (make-primcall src '<= (list a b)) + (make-const src #t) + (make-const src #f))) (($ src '>= (a b)) ;; No need to reduce as < is a branching primitive. - (make-conditional src (make-primcall src '< (list a b)) - (make-const src #f) - (make-const src #t))) + (make-conditional src (make-primcall src '<= (list b a)) + (make-const src #t) + (make-const src #f))) (($ src '> (a b)) ;; No need to reduce as < is a branching primitive.