From bf8d455e9c2106d826d04087108b21d167e8e20b Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 21 Jul 2012 03:41:42 -0700 Subject: [PATCH] compiler: Fix /mod simplications in dead-code, add unit tests. Fixes #544 --- basis/compiler/tests/dead-code.factor | 11 +++++++++++ basis/compiler/tree/dead-code/dead-code-tests.factor | 4 ++++ basis/compiler/tree/dead-code/simple/simple.factor | 7 +++++-- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 basis/compiler/tests/dead-code.factor diff --git a/basis/compiler/tests/dead-code.factor b/basis/compiler/tests/dead-code.factor new file mode 100644 index 0000000000..293d76d2c4 --- /dev/null +++ b/basis/compiler/tests/dead-code.factor @@ -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 diff --git a/basis/compiler/tree/dead-code/dead-code-tests.factor b/basis/compiler/tree/dead-code/dead-code-tests.factor index 27840ea758..237078a159 100644 --- a/basis/compiler/tree/dead-code/dead-code-tests.factor +++ b/basis/compiler/tree/dead-code/dead-code-tests.factor @@ -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 diff --git a/basis/compiler/tree/dead-code/simple/simple.factor b/basis/compiler/tree/dead-code/simple/simple.factor index 89227a53e1..102ef1d36c 100644 --- a/basis/compiler/tree/dead-code/simple/simple.factor +++ b/basis/compiler/tree/dead-code/simple/simple.factor @@ -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* {