-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[MIR] Consider lowering some intrinsic functions to MIR #32716
Comments
I had a branch that did exactly this a while back for transmute and a few others. https://github.com/luqmana/rust/commits/mir-intrinsics |
@luqmana I have a branch that I was experimenting with that did the lowering while building, which I think makes more sense in some situations, though an intrinsic lowering pass in other cases may also be useful. |
I would like to work on this, but don't know where to begin. Would it make sense to rebase @luqmana's branch first? |
Rebasing probably makes little sense. It’s a very old branch approaching the problem from a direction that would likely not work anymore, due to how much MIR has changed over time. IMO it would be easier to begin from scratch. |
Thanks! I took a quick look at
I have more questions, but I think I better make sure we are on the same line before I go on 😉 |
Rather than not benefiting, they inhibit them. Everything else sounds about right. |
Right, so now on with more questions. When you say that @luqmana's direction won't work anymore, do you mean that it would be a bad idea to write a MIR transformation that lowers intrinsics? I cannot imagine a different way of implementing this. |
MIR transformation will still work for most of the interesting intrinsics I think; although there may be a saner approach. What I mean is that the transformation in question was written a year ago, and MIR has changed so significantly since, that rebasing it properly would be equivalent (or even harder) than redoing it from scratch. Also: when implementing this keep in mind the eventual move to EBBs. |
Loosely based on @luqmana's code I wrote the following: https://github.com/aochagavia/rust/commit/0f9a70b3567b76b8d06ac3fd5f38426512d26128 There are a couple of FIXMEs, though. I left comments on some lines. @nagisa could you take a look at them and point me in the right direction? That would be great! |
Triage: is this bug still useful? |
Some intrinsic functions can be effectively implemented in pure MIR code. Notably, the wrapping and checked arithmetic functions, which can turn into regular
BinaryOp
andCheckedBinaryOp
(when implemented) rvalues. Similarly intrinsics likemove_val_init
can be exactly represented in the MIR.While relatively low impact right now, due to most intrinsics being used via wrapper functions, if/when we get MIR-level inlining, this would allow those intrinsics to better participate in optimisations.
The text was updated successfully, but these errors were encountered: