-
-
Notifications
You must be signed in to change notification settings - Fork 810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Venom: Replace unconditional jump to small BBs with BB itself #4327
Comments
yea, i think this looks like a neat idea. we will need a heuristic for when to inline. maybe this can be done as part of paging @harkal, what do you think? @Philogy do you want to take a stab at this? |
fwiw, one of those jumps gets eliminated -f bb_runtime
and the corresponding assembly:
|
Simple Summary
Add an optimization pass that "inlines" small basic blocks. Similar to function inlining it allows following passes to simplify things even further and remove redundancy.
For example the following code (from snekmate):
Generates:
`_domain_separator_v4` in Venom IR
Motivation
The optimizer pass would:
jmp label %70_if_exit
in68_then
, resolving%14 = %12
jmp label %70_if_exit
in69_else
, resolving%14 = 0
Resuling in:
Theoretical Venom IR post BB inlining pass
Then it would be trivial for further optimization passes to:
70_if_exit
blockjnz label %73_if_exit, label %71_then, 0
tojmp label &71_then
in69_else
69_else
with71_then
in the function entry block (because it would be an empty BB only containing a single unconditional jump)This would lead to smaller code and remove a lot of redundant jumps and stack scheduling. Some heuristics need to be added to such a pass to avoid unsound optimization, specifically if the target basic block has any phi nodes who's lifetime extends outside of that basic block it cannot be trivially inlined. Furthermore inlining large target basic blocks could lead to code size regressions.
The
69_else
and70_if_exit
blocks are quite redundant and a common pattern arising from the short-circuiting ofor
andand
operations as well as other control-flow related to if-statements. Furthermore it would allow optimizing for loops with the rough common structure of:To:
By inlining the for-loop condition checking basic block at the end of the loop, turning the 2 branch operations per loop iteration to 1.
Copyright
Copyright and related rights waived via CC0
The text was updated successfully, but these errors were encountered: