unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-devel@gnu.org
Subject: Re: wip-cse
Date: Mon, 16 Apr 2012 23:36:27 +0200	[thread overview]
Message-ID: <874nsjuzok.fsf@gnu.org> (raw)
In-Reply-To: 87bomr30xz.fsf@pobox.com

Hi Andy,

Andy Wingo <wingo@pobox.com> skribis:

> I just finished work on the "wip-cse" branch and would like to merge it
> in sometime.  It does a form of common subexpression elimination.  It's
> a post-pass, designed to run after peval.

The examples in cse.test suggest that it does a good job.  :-)

Initially, I was expecting things like:

  (f (* a b) (* a b))
  =>
  (let ((x (* a b)))
    (f x x))

but AIUI the CSE pass here eliminates duplicate references when they are
superfluous, but not when they are needed as above, right?

> I'm attaching a log of the things that it folds in a normal Guile
> build.

I’m not sure what the messages mean.  Could you explain?

> I'm pretty happy with it, except for the speed.

What impact does it have on compilation time in module/?

> I'm reasonably confident as to its complexity, but once again we are
> seeing that lookup in vhashes is fairly slow.  Dunno.  If we can speed
> up vhashes somehow then we win in CSE, peval, and other passes, so
> probably it's best to focus there.

I think we’ll need C-level profiling to see what’s going on.  Do you
have such info already?  Otherwise I can look into it.

Also, a bit of CSE could help:  ;-)

--8<---------------cut here---------------start------------->8---
scheme@(ice-9 vlist)> ,optimize   (%vhash-assoc key vhash eq? hashq)
$3 = (begin
  (define khash
    (let ((size (vector-ref
                  (let ((s vhash))
                    (if (eq? (struct-vtable s) <vlist>)
                      (struct-ref s 0)
                      ((@@ (srfi srfi-9) throw)
                       'wrong-type-arg
                       'vlist-base
                       "Wrong type argument: ~S"
                       (list s)
                       (list s))))
                  3)))
      (and (> size 0) (hashq key size))))
  (let loop ((base (let ((s vhash))
                     (if (eq? (struct-vtable s) <vlist>)
                       (struct-ref s 0)
                       ((@@ (srfi srfi-9) throw)
                        'wrong-type-arg
                        'vlist-base
                        "Wrong type argument: ~S"
                        (list s)
                        (list s)))))
             (khash khash)
             (offset
               (and khash
                    (vector-ref
                      (vector-ref
                        (let ((s vhash))
                          (if (eq? (struct-vtable s) <vlist>)
                            (struct-ref s 0)
                            ((@@ (srfi srfi-9) throw)
                             'wrong-type-arg
                             'vlist-base
                             "Wrong type argument: ~S"
                             (list s)
                             (list s))))
                        5)
                      khash)))
             (max-offset
               (let ((s vhash))
                 (if (eq? (struct-vtable s) <vlist>)
                   (struct-ref s 1)
                   ((@@ (srfi srfi-9) throw)
                    'wrong-type-arg
                    'vlist-offset
                    "Wrong type argument: ~S"
                    (list s)
                    (list s))))))
--8<---------------cut here---------------end--------------->8---

Here (vlist-base vhash) occurs three times; this could be reduced
manually to one.  Then there’s (vlist-offset vhash), which repeats the
same struct type checking.

In the body itself I don’t see anything obvious.

Thanks,
Ludo’.




  reply	other threads:[~2012-04-16 21:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-16 19:56 wip-cse Andy Wingo
2012-04-16 21:36 ` Ludovic Courtès [this message]
2012-04-16 22:56   ` wip-cse Andy Wingo
2012-04-16 23:26     ` wip-cse Andy Wingo
2012-04-17 12:42     ` wip-cse Ludovic Courtès
2012-04-24  8:20       ` wip-cse Andy Wingo
2012-04-24 16:31         ` wip-cse Ludovic Courtès
2012-04-24 18:41           ` wip-cse Andy Wingo
2012-04-24 23:14             ` wip-cse Ludovic Courtès
2012-04-25  9:53               ` wip-cse Andy Wingo
2012-04-25 14:10                 ` wip-cse Ludovic Courtès
2012-04-25 16:42                   ` wip-cse Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874nsjuzok.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).