-
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
Add unreachable hints for length getters? #106737
Comments
In many cases it would be much better to do this by emitting range metadata info in the compiler -- https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Range.20metadata.20for.20.60size_of_val.60.20and.20other.20isize.3A.3AMAX.20limits is a conversation about it (for In general My hunch is that it's unlikely that we'll be able to accept the impact of doing this as a library change on slices. |
@thomcc In the linked discussion @erikdesjardins has expressed concern about range metadata getting eliminated too early to positively impact optimization passes. I guess using |
Not really, because I don't know that there's a good way to anything like this to libraries. The closest would be the niche RFC. But the concerns of the standard library here are very different than for other library code, and really this is probably not an issue that should be used for discussion of new language features like that anyway. |
IIUC it happens only after the method gets inlined. Otherwise, it's a simple method to which we can add whatever we want, be it P.S.: Feel free to close this issue, if you think that the |
The problem is, there often isn't a load, e.g. whenever a slice is passed directly as an argument: https://godbolt.org/z/z6ocsEfzx. Even if it were temporarily spilled to an alloca, that load would get optimized out by SROA early in the pipeline, dropping the metadata. (If the slice is behind another layer of indirection, e.g. in This is not to say that we shouldn't add range metadata, just that I think it won't help that much. I agree that adding metadata has a much better cost/benefit tradeoff vs. adding assumes. What would really help is range attributes on arguments. If LLVM had that, we could codegen |
That'd be a big help for |
Cross-linking to a recent Zulip conversation: https://rust-lang.zulipchat.com/#narrow/stream/247081-t-compiler.2Fperformance/topic/range.20metadata.20for.20slice.20len/near/395449552 |
As discussed in this thread, Rust does not provide LLVM any information about possible lengths of slices, vectors, and other types. In some cases it prevents LLVM from applying optimizations since it has to account for invalid lengths.
I suggest updating length getters of slice-like types to something like this:
The text was updated successfully, but these errors were encountered: