guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 01/02: Improve code generation for eq? on immediates


From: Andy Wingo
Subject: [Guile-commits] 01/02: Improve code generation for eq? on immediates
Date: Thu, 30 Jul 2020 11:40:27 -0400 (EDT)

wingo pushed a commit to branch master
in repository guile.

commit f13b27a4cc6ea35e8595e7d926c5632eb797364a
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Thu Jul 30 16:30:23 2020 +0200

    Improve code generation for eq? on immediates
    
    * module/language/tree-il/compile-bytecode.scm (canonicalize):
    * module/language/tree-il/compile-cps.scm (canonicalize): Specialize
      eq-false? and similar predicates.
---
 module/language/tree-il/compile-bytecode.scm | 14 ++++++++++++++
 module/language/tree-il/compile-cps.scm      | 19 +++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/module/language/tree-il/compile-bytecode.scm 
b/module/language/tree-il/compile-bytecode.scm
index b8d432f..59bed8d 100644
--- a/module/language/tree-il/compile-bytecode.scm
+++ b/module/language/tree-il/compile-bytecode.scm
@@ -422,6 +422,20 @@
        (($ <primcall> src '>= (a b)) (reify-branch src '<= (list b a)))
        (($ <primcall> src '>  (a b)) (reify-branch src '<  (list b a)))
 
+       ;; Specialize eq?.
+       (($ <primcall> src 'eq? (a b))
+        (let ((a (if (const? b) a b))
+              (b (if (const? b) b a)))
+          (define (simplify test) (reify-branch src test (list a)))
+          (match b
+            (($ <const> _ '()) (simplify 'eq-null?))
+            (($ <const> _ #f) (simplify 'eq-false?))
+            (($ <const> _ #t) (simplify 'eq-true?))
+            (($ <const> _ #nil) (simplify 'eq-nil?))
+            (($ <const> _ (? unspecified?)) (simplify 'unspecified?))
+            (($ <const> _ (? eof-object?)) (simplify 'eof-object?))
+            (_ (reify-branch src 'eq? (list a b))))))
+
        ;; Simplify "not".
        (($ <primcall> src 'not (x))
         (finish-conditional
diff --git a/module/language/tree-il/compile-cps.scm 
b/module/language/tree-il/compile-cps.scm
index 334b4ce..9484e84 100644
--- a/module/language/tree-il/compile-cps.scm
+++ b/module/language/tree-il/compile-cps.scm
@@ -2365,6 +2365,25 @@ integer."
                           (make-const src #t)
                           (make-const src #f)))
 
+       ;; Specialize eq?.
+       (($ <primcall> src 'eq? (a b))
+        (define (reify-branch test args)
+          ;; No need to reduce as test is a branching primitive.
+          (make-conditional src (make-primcall src test args)
+                            (make-const src #t)
+                            (make-const src #f)))
+        (let ((a (if (const? b) a b))
+              (b (if (const? b) b a)))
+          (define (simplify test) (reify-branch test (list a)))
+          (match b
+            (($ <const> _ '()) (simplify 'eq-null?))
+            (($ <const> _ #f) (simplify 'eq-false?))
+            (($ <const> _ #t) (simplify 'eq-true?))
+            (($ <const> _ #nil) (simplify 'eq-nil?))
+            (($ <const> _ (? unspecified?)) (simplify 'unspecified?))
+            (($ <const> _ (? eof-object?)) (simplify 'eof-object?))
+            (_ (reify-branch 'eq? (list a b))))))
+
        (($ <primcall> src (? branching-primitive? name) args)
         ;; No need to reduce because test is not reducible: reifying
         ;; #t/#f is the right thing.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]