-
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
Weird codegen / constant folding with iterators of length > 101 #112169
Comments
I expect that select peeling in LLVM 17 will fix this. |
Fixed in 1.73, presumably due to the LLVM 17 upgrade (#114048): https://godbolt.org/z/eWYs5YvKK @rustbot label +E-needs-test |
(Keeping this open until a codegen test has been added for it -- these kinds of optimizations have an annoying habit of regressing without that.) |
My bad, I just looked at the number of opened issues and thought I'd better close mine to reduce the "noise" since it seemed to be fixed. |
If you're interested, what we need it basically a test like this: https://github.com/rust-lang/rust/blob/master/tests/codegen/issues/issue-101082.rs That just takes the test function checks it compiles down to a single ret. |
Ok, I'm looking at the filecheck documentation, I will inform you if I manage to implement the codegen test ^^ |
…lacrum Add codegen test for 112169 Add codegen test for rust-lang#112169. The test passes but it's my first time using FileCheck, don't hesitate to tell me if this can be improved ^^
As @nikic said in the linked PR, this still isn't completely fixed, using a length of 801 and above still results in the loop not being optimized away (see https://godbolt.org/z/48594oGn5) |
fun note: adding |
Hi,
When playing with some of my code on compiler explorer, I found a case where rust would not compute the result of some functions at compile time. I managed to reduce the code to the following:
compiler explorer link
Both
test2
andtest3
are completely optimized and are compiled down to a singled "mov constant + ret" combo. But thetest
function generates something quite convoluted: the compiler loads the result (102
) and removes6
from it until it reaches0
, at which point it returns the value of another register to which6
s have been added at each step.I tried a few versions of rustc but couldn't find any which completely optimized away the first function. Using
mir-opt-level
didn't help.The text was updated successfully, but these errors were encountered: