The subject of Tapir came up in this thread a little while ago. Put simply, Tapir added 3 new instructions to LLVM's IR to make it possible to express parallelism in code such that the various optimizers in the middle/back end could do intelligent things, and it looks like they got pretty good performance improvements by doing so. Would it be worth considering adding these instructions to Cranelift's IR?
Yes, this looks very interesting. The property that most existing scalar optimizations don't need to change is a cool property. A naive optimizer thinking about detach as a conditional branch that may-or-may-not be taken happens to behave a lot like it were reasoning about code that may-happen-asynchronously, which is an interesting insight.
Glad it might work out! My hope is that rust's 'fearless concurrency' will eventually become 'the compiler has enough info to figure out what can be run concurrently, and will do a better job making that happen than you can'. Instructions like Tapir are a step in that direction. (and, yes, I know that cranelift is not rustc, but it could be a part of the collection of parts that make up rustc).
@sunfishcode Could you outline what would be needed to add these instructions to cranelift? If someone wanted to make this happen, it would be nice to know what needs to be done. If it's as simple as following the instructions at https://cranelift.readthedocs.io/en/latest/meta.html, then that would be great, but I suspect that there will be a lot more going on.
BTW, I may be able to start poking at this someday, but it won't be very soon; too much else on my plate right now. That said, I'd like to at least know what would need to be done to get this working...
@ckaran As it happens, the instructions in that meta.html page are recently obsolete, as the meta system has just been rewritten. We'll be working documenting the new system, but until that's ready, probably the way forward is to look for instructions such as brz/brnz which are similar to what you want to do, and copy them. Since Tapir is set up to appear to most of the compiler as normal conditional branches, this should be a good default for code which isn't Tapir-aware.
OK, I just started looking at this while my simulations were running... it is more complicated than I thought. I know I won't have time to really work on this any time soon, so if someone else wants to jump in, please feel free to. I will wait until the docs for new meta system are complete, and then if no-one else has picked this up, I'll start looking at it.
Most helpful comment
Glad it might work out! My hope is that rust's 'fearless concurrency' will eventually become 'the compiler has enough info to figure out what can be run concurrently, and will do a better job making that happen than you can'. Instructions like Tapir are a step in that direction. (and, yes, I know that cranelift is not rustc, but it could be a part of the collection of parts that make up rustc).