--- /dev/null
+
+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
[ [ 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
: define-simplifications ( word seq -- )
"simplifications" set-word-prop ;
+! true if dead
\ /mod {
{ { f t } /i }
{ { t f } mod }
} 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
: simplify-call ( #call -- nodes )
dup (simplify-call) [
>>word [ filter-live ] change-out-d
- ] when* ;
+ ] [
+ maybe-drop-dead-outputs
+ ] if* ;
M: #call remove-dead-code*
{