Skip to content

More agressively kill dead code#6803

Merged
enebo merged 4 commits intojruby:masterfrom
enebo:kill_stuff
Sep 7, 2021
Merged

More agressively kill dead code#6803
enebo merged 4 commits intojruby:masterfrom
enebo:kill_stuff

Conversation

@enebo
Copy link
Member

@enebo enebo commented Sep 2, 2021

LocalOptimizationPass will propagate values. For example:

_tmp = true
unless _tmp
 puts "Never"
end

In this case by the end of this pass we will see a BB end with a
b_false(true, some_label). This clearly cannot happen. If we eliminate
this instr then we should also be able to lop off the bb(s) representing
whatever is within the unless conditional. In this snippet the entire
snippet should be dead code except _tmp = true.

To fix this I added simplifyBranch to BranchInstr. This gives us the
ability to swap out a branch with a noop or a jump (in case where something
is unconditionally true).

After we replace the instr with a new one we need to reexamine the basicblock
it is in and correct any edge placement.

LocalOptimizationPass will propagate values.  For example:

```ruby
_tmp = true
unless _tmp
 puts "Never"
end
```

In this case by the end of this pass we will see a BB end with a
b_false(true, some_label).  This clearly cannot happen.  If we eliminate
this instr then we should also be able to lop off the bb(s) representing
whatever is within the unless conditional.  In this snippet the entire
snippet should be dead code except _tmp = true.

To fix this I added simplifyBranch to BranchInstr.  This gives us the
ability to swap out a branch with a noop or a jump (in case where something
is unconditionally true).

After we replace the instr with a new one we need to reexamine the basicblock
it is in and correct any edge placement.
@enebo enebo added this to the JRuby 9.3.0.0 milestone Sep 2, 2021
@kares
Copy link
Member

kares commented Sep 3, 2021

nice, this could also work if arg1 is simply a nil, right?

@enebo
Copy link
Member Author

enebo commented Sep 3, 2021

@kares I am in the process of simplifying all branch types.

The basic problem was I changed this branch/PR to save the original
returnBBs as a field in the CFG.  When I remove a BB I have to also
update the returnBB list as well.

Second fix was to remove incoming edges from BBs which no longer are
reachable from the BBs by using the directed graphs removeEdge method.
This is quite a bit cleaner looking as well.
@enebo enebo merged commit 97f228f into jruby:master Sep 7, 2021
@enebo enebo deleted the kill_stuff branch March 4, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants