Hi Ludovic, > commit 2446f8e126d9a7c145c4868f2a918d2dfb226d4e > Author: Ludovic Courtès <l...@gnu.org> > Date: Sat Oct 6 01:24:46 2012 +0200 > > Simplify calls to `equal?' when one argument is a constant. > > * module/language/tree-il/primitives.scm (*primitive-expand-table*): Add > expansion rules for `equal?', when called with one constant and > another argument. > > * test-suite/tests/tree-il.test (pass-if-primitives-resolved): New > macro. > ("primitives"): New test prefix.
This commit has some problems. > diff --git a/module/language/tree-il/primitives.scm > b/module/language/tree-il/primitives.scm > index a1c5adc..dc0a145 100644 > --- a/module/language/tree-il/primitives.scm > +++ b/module/language/tree-il/primitives.scm > @@ -491,6 +491,33 @@ > (bytevector-ieee-double-native-set! vec (* i 8) x)) > > (hashq-set! *primitive-expand-table* > + 'equal? > + (case-lambda > + ((src a b) > + ;; Simplify cases where either A or B is constant. > + (define (maybe-simplify a b) > + (and (const? a) > + (let ((v (const-exp a))) > + (cond > + ((eq? #f v) > + (make-application src (make-primitive-ref #f 'not) > + (list b))) (not v) is not the same as (equal? #f v) when v is #nil. > + ((eq? '() v) > + (make-application src (make-primitive-ref #f > 'null?) > + (list b))) (null? v) is not the same as (equal? '() v) when v is #nil. > + ((or (eq? #t v) > + (eq? #nil v) > + (symbol? v) > + (and (integer? v) > + (<= v most-positive-fixnum) > + (>= v most-negative-fixnum))) > + (make-application src (make-primitive-ref #f 'eq?) > + (list a b))) 42.0 is an integer in the fixnum range, but (eq? 42.0 v) is not the same as (equal? 42.0 v). I have pushed fixes for these. Also, is there any particular reason you didn't apply the same optimizations to 'eqv?'? Mark