1.0.43.42: Constant fold IFs before performing IF/IF conversion
authorPaul Khuong <pvk@pvk.ca>
Tue, 12 Oct 2010 04:41:16 +0000 (04:41 +0000)
committerPaul Khuong <pvk@pvk.ca>
Tue, 12 Oct 2010 04:41:16 +0000 (04:41 +0000)
IF/IF-conversion is somewhat similar to "the trick": when a conditional
branches on an lvar that may be written to by multiple nodes, duplicate
the conditional after each of the writers.

We used to perform that before constant-folding IFs.  We now do the
reverse: it's always better to completely flush the branch away than to
duplicate it.

src/compiler/ir1opt.lisp
version.lisp-expr

index 59b145a..bbcdc89 100644 (file)
 \f
 ;;;; IF optimization
 
-;;; If the test has multiple uses, replicate the node when possible.
-;;; Also check whether the predicate is known to be true or false,
+;;; Check whether the predicate is known to be true or false,
 ;;; deleting the IF node in favor of the appropriate branch when this
 ;;; is the case.
+;;; Also, if the test has multiple uses, replicate the node when possible.
 (defun ir1-optimize-if (node)
   (declare (type cif node))
   (let ((test (if-test node))
         (block (node-block node)))
-
-    (when (and (eq (block-start-node block) node)
-               (listp (lvar-uses test)))
-      (do-uses (use test)
-        (when (immediately-used-p test use)
-          (convert-if-if use node)
-          (when (not (listp (lvar-uses test))) (return)))))
-
     (let* ((type (lvar-type test))
            (victim
             (cond ((constant-lvar-p test)
         (when (rest (block-succ block))
           (unlink-blocks block victim))
         (setf (component-reanalyze (node-component node)) t)
-        (unlink-node node))))
+        (unlink-node node)
+        (return-from ir1-optimize-if (values))))
+
+    (when (and (eq (block-start-node block) node)
+               (listp (lvar-uses test)))
+      (do-uses (use test)
+        (when (immediately-used-p test use)
+          (convert-if-if use node)
+          (when (not (listp (lvar-uses test))) (return))))))
   (values))
 
 ;;; Create a new copy of an IF node that tests the value of the node
index eb5fa2a..8fe4b2d 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.43.41"
+"1.0.43.42"