-
Notifications
You must be signed in to change notification settings - Fork 237
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
Unnecessary phi instructions insert by to_ssa #318
Comments
Very broadly, unnecessary Of course, it could be cool to make a separate version that is more efficient, even at the expense of more complicated code! Here, it probably suffices to just "collapse" phi-nodes before insertion if we detect that only one of their inputs is actually defined. |
I am ok with inefficient code. It's just that it makes my BRIL-> LLVM translator hard because of
I am not very sure about this actually. I see earlier discussion about _undefined in #108, #118 and so on. I don't really understand the semantics of _undefined here. |
Another option to get around this issue seems to be using mem2reg pass as in chapter 7 of the LLVM tutorial: https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl07.html#why-is-this-a-hard-problem. Do you recommend this over 'fixing' the issue? This mem2reg thing feels a bit dirty honestly, but it seems to be what everyone is doing. |
That's what I did for |
Is this the brillvm you refer to https://github.com/sampsyo/bril/tree/main/bril-llvm? This converts to SSA at BRIL level. Would you recommend doing the same mem2reg again? Will it work fine for arrays etc as well? I am using llvmlite to generate llvm text btw. |
See https://github.com/sampsyo/bril/tree/main/bril-rs/brillvm which does not do this conversion(though should support bril code that is already in ssa form).
I think it depends on your use case. If your goal is to get to llvm ir quickly, then yes. I'm not sure in what way arrays are harder but it has been a while. |
Thanks. I will make this compromise for now. Makes my life easier.
You know arrays are also represented with |
I think that is an implementation detail/optimization. On one hand, I allocated stack space for all of my variables first since the number of variables is statically known. So any alloca after that is independent of mem2reg. I also actually malloc'ed all of my bril arrays, it's less efficient but then I somewhat trust LLVM to optimize where it is safe and avoid issues related to lifetimes and stack sizes. |
Thanks, used cc: @GlowingScrewdriver. |
Here's an example bril for interp test add-overflow
Converting this to ssa using to_ssa.py gives following output
Note how
end.0: bool = phi __undefined end.1 .b1 .body;
is inserted and it's not necessary to have done that. In fact it's not used anywhere and tdce would remove it.I will try to figure out where this issue is coming from.
The text was updated successfully, but these errors were encountered: