-
Notifications
You must be signed in to change notification settings - Fork 13k
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
included range in for loop gives more assembly code than excluded range #102462
Comments
@rustbot label -A-diagnostics +A-codegen +I-heavy |
This regressed between 1.42 and 1.43: Godbolt link related: #45222 |
(If you have two nested loop, the code is bad even in older compilers). |
The 1.42 codegen is tricky, as it seems at first that it doesn't account for the case where |
Simpler example without the unnecessary memory indirections: https://rust.godbolt.org/z/GPvrbvbYY External iteration over inclusive ranges is well known to optimize badly. Optimization may be viable in this particular case though. |
This is the fold we'd need: https://alive2.llvm.org/ce/z/JsWRvT |
how is the problem right now guys? |
Came across this weirdness today; it's still a problem in December 2023: pub fn inclusive() -> usize {
(2..=100).step_by(2).sum::<usize>()
}
pub fn exclusive() -> usize {
(2..101).step_by(2).sum::<usize>()
} produces assembly with 46 lines and 3 lines, respectively. Was going to create a new bug for it, but I'm pretty sure it's just another version of this one. |
@rustbot claim |
Given the following code where source will be excluded
The assembly output is:
if source will be included the assembly code will increase more than
The assembly output is:
I tested on rustc 1.64.0 with -C opt-level=3
The text was updated successfully, but these errors were encountered: