-
Notifications
You must be signed in to change notification settings - Fork 94
Code size optimization (single return point) #217
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
base: main
Are you sure you want to change the base?
Conversation
Personally I think emitting a return sequence for the
This way we would be able to get both the "bloated" assembly that's easy to inspect and correlate with the B code, but also the more efficient code when optimizations are enabled. |
I don't think this makes the assembly (or ir) less readable, especially if we had custom names for labels and non-stack variables. I also wanted to introduce new before:IR:
x86_64:
after:IR:
x86_64:
After set_ret_reg:IR:
x86_64:
And with proper
Other points are valid, but implementing good enough opts is much harder, and it would certainly require |
I'm currently working on implementing some basic optimizations for the compiler, it's able to detect and remove unreachable code and pointless assigns, with very little modifications to the current IR (only added Op::Nop, no ssa). merging all returns points into one as an optimization step sounds like an interesting idea, but it's not my main focus right now. |
Yeah, I meant the "good" DCE, of course this case is eliminated even in my implementation. I should rename the issue, it is more about code size, than redundancies. |
Generate single return op for function and jump to it from return points. It simplifies control flow, removes redundant assembly, especially if function has many return points. It also fixes the issue with repeating
ret
if return is called manually.