-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Example iterator fold vs. loop emit different code #99656
Comments
On your wasm target, this was nicely optimized in 1.33.0, 1.34.0 introduced a change, 1.56.0 made it much worse. On x86, 1.34 actually improved the results considerably over 1.33.0. 1.42.0 has nice and compact asm but 1.43.0 messed that up. We're probably dealing with multiple issues. I'd be surprised if at least one of them hasn't already been reported, but I'm not familiar enough with the backlog to be able to tell one way or the other. @rustbot label +regression-from-stable-to-stable +A-codegen +T-compiler |
probably this also needs some bisection to start narrowing down where these codegen regressions come from. I'll try to signal this by adding: @rustbot label E-needs-bisection |
Could this simply be the case for |
That sure does explain what is occurring! Yet, not why? (i.e. Wouldn't we want them both vectorised for opt-level=3?) |
If I use a while loop it works, so I guess something is preventing LLVM from optimizing the for loop |
I'll nominate for @rustbot label I-compiler-nominated |
Inclusive ranges optimize poorly. Switch to an exclusive range and the for-loop does the same unrolling as the iterator. |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-medium |
This simple example of a naive factorial (
n!
) implementation emits different code for using a range fold, and a loop over the iteration. Notably, the iterator fold emits many more instructions than the basic loop. This is unexpected, as this should be a zero-cost abstraction.https://rust.godbolt.org/z/3cMMh67rE
@rustbot label I-heavy I-slow
The text was updated successfully, but these errors were encountered: