compiler: Fix /mod simplications in dead-code, add unit tests. Fixes #544

db4
Doug Coleman 2012-07-21 03:41:42 -07:00
parent 4fe25c8fd2
commit bf8d455e9c
3 changed files with 20 additions and 2 deletions

View File

@ -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

View 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

View 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*
{