cse: expressions evaluated for effect do not provide predicates
authorAndy Wingo <wingo@pobox.com>
Fri, 22 Jun 2012 10:25:34 +0000 (12:25 +0200)
committerAndy Wingo <wingo@pobox.com>
Fri, 22 Jun 2012 10:33:20 +0000 (12:33 +0200)
* module/language/tree-il/cse.scm (cse): When trying to fold
  conditionals, only look at entries in the database that were added in
  test context.

* test-suite/tests/cse.test ("cse"): Add a test case.

module/language/tree-il/cse.scm
test-suite/tests/cse.test

index ceef15f..b8e7229 100644 (file)
            #f)))
        (_
         (cond
-         ((find-dominating-expression exp effects #f db)
+         ((find-dominating-expression exp effects 'test db)
           ;; We have an EXP fact, so we infer #t.
           (log 'inferring exp #t)
           (make-const (tree-il-src exp) #t))
-         ((find-dominating-expression (negate exp 'test) effects #f db)
+         ((find-dominating-expression (negate exp 'test) effects 'test db)
           ;; We have a (not EXP) fact, so we infer #f.
           (log 'inferring exp #f)
           (make-const (tree-il-src exp) #f))
index ee31285..d01d318 100644 (file)
    (let ((x (car y)))
      (cons x (car y)))
    (let (x) (_) ((apply (primitive car) (toplevel y)))
-        (apply (primitive cons) (lexical x _) (lexical x _)))))
+        (apply (primitive cons) (lexical x _) (lexical x _))))
+
+  ;; Dominating expressions only provide predicates when evaluated in
+  ;; test context.
+  (pass-if-cse
+   (let ((t (car x)))
+     (if (car x)
+         'one
+         'two))
+   ;; Actually this one should reduce in other ways, but this is the
+   ;; current reduction:
+   (begin
+     (apply (primitive car) (toplevel x))
+     (if (apply (primitive car) (toplevel x))
+         (const one)
+         (const two)))))