-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Offer attributes for controlling loop optimizations #2219
Comments
Previous discussion: https://internals.rust-lang.org/t/loop-unrolling-on-request/3091 (pointed out in #rust-internals by lqd) |
In that discussion, the possibility of a (likely procedural) macro for unrolling specifically was brought up. That would be a rather blunt tool, as it wouldn't integrate with the optimizer. It would also not cover use cases for limiting in the optimizer (i.e., preventing unrolling that would normally occur). It also doesn't address knobs related to other optimization than loop unrolling. |
My proposal was meant to integrate with the optimizer. In that proposal
Regarding the knobs for other optimizations, my proposal doesn't prevent them. If you want later you can add other attributes:
And: |
The I.e, something like,
So, for example:
|
I believe this is potentially something for @rust-lang/wg-codegen to weigh in on? |
(small nit) In Rust we'd probably use |
Personally, I think |
The unroll crate only supports unrolling literal constant loops, like: ``` for 0..10 { // body } ``` I spent some time looking into adding constant-generic unroll support, since the bounds will still be constant at compile time, but proc macros operate over source tokens (i.e. before monomorphization when the const generic would be a known value). There was some light discussion about offering compiler-level tools for better control of more kinds of loop unrolling in: rust-lang/rfcs#2219 But, that seems to have stalled out for now. The suggestion from [1] to use a proc macro to unroll the const generic loop into a series of const branches that can be pruned after monomorphization seems promising, but as no such macro yet exists I did it manually. [1]: 0xPolygonZero/plonky#80 (comment)
I would really love to see this implemented |
So, is there any roadmap already for loop unrolling being supported? At least a compiler hint like inline |
For example, Clang has
#pragma loop
which allow the programmer to guide loop unrolling, vectorization, and other optimizations. This is useful in high performance code because heuristics are often fallible and nudging the optimizer in the right direction can sometimes squeeze out some more performance (for a particular optimizer version, of course).In Rust, the natural replacement for a pragma would probably be an attribute.
The text was updated successfully, but these errors were encountered: