]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler: Fix /mod simplications in dead-code, add unit tests. Fixes #544
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 21 Jul 2012 10:41:42 +0000 (03:41 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 21 Jul 2012 10:41:42 +0000 (03:41 -0700)
basis/compiler/tests/dead-code.factor [new file with mode: 0644]
basis/compiler/tree/dead-code/dead-code-tests.factor
basis/compiler/tree/dead-code/simple/simple.factor

diff --git a/basis/compiler/tests/dead-code.factor b/basis/compiler/tests/dead-code.factor
new file mode 100644 (file)
index 0000000..293d76d
--- /dev/null
@@ -0,0 +1,11 @@
+
+USING: kernel math tools.test ;
+IN: compiler.tests.dead-code
+
+: test-outputs0 ( a b -- ) /mod 2drop ;
+: test-outputs1 ( a b -- ) /i drop ;
+: test-outputs2 ( a b -- ) mod drop ;
+
+[ ] [ 10 3 test-outputs0 ] unit-test
+[ ] [ 10 3 test-outputs1 ] unit-test
+[ ] [ 10 3 test-outputs2 ] unit-test
index 27840ea758ca4efb4b83f26448fd9a4f6da1f000..237078a159eab53f6af62ec4784f47301dde9b91 100644 (file)
@@ -200,3 +200,7 @@ IN: compiler.tree.dead-code.tests
 [ [ bignum/i ] ] [ [ { bignum bignum } declare /mod drop ] optimize-quot ] unit-test
 
 [ [ bignum-mod ] ] [ [ { bignum bignum } declare /mod nip ] optimize-quot ] unit-test
+
+[ [ /i ] ] [ [ /mod drop ] optimize-quot ] unit-test
+
+[ [ mod ] ] [ [ /mod nip ] optimize-quot ] unit-test
index 89227a53e13de8915ef70cd14c76c74fdec79c64..102ef1d36c2b27141388fd0179484103dd13463c 100644 (file)
@@ -98,6 +98,7 @@ M: #push remove-dead-code*
 : define-simplifications ( word seq -- )
     "simplifications" set-word-prop ;
 
+! true if dead
 \ /mod {
     { { f t } /i }
     { { t f } mod }
@@ -114,7 +115,7 @@ M: #push remove-dead-code*
 } define-simplifications
 
 : out-d-matches? ( out-d seq -- ? )
-    [ [ live-value? ] [ drop t ] if ] 2all? not ;
+    [ swap live-value? xor ] 2all? ;
 
 : (simplify-call) ( #call -- new-word/f )
     [ out-d>> ] [ word>> "simplifications" word-prop ] bi
@@ -123,7 +124,9 @@ M: #push remove-dead-code*
 : simplify-call ( #call -- nodes )
     dup (simplify-call) [
         >>word [ filter-live ] change-out-d
-    ] when* ;
+    ] [
+        maybe-drop-dead-outputs
+    ] if* ;
 
 M: #call remove-dead-code*
     {