-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 MIR pass to lower call to core::slice::len
into Len
operand
#86383
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Removed the heuristic part that did borrow elimination, it may be resolved (already?) in other optimizations I believe |
That is still surprising that no pass was able to eliminate
Most likely LLVM will handle it, but it should be simple to do on MIR level |
I tried to do some of those cases in #46440 , but IIRC the bigger plan was to do things with full NRVO. |
This comment has been minimized.
This comment has been minimized.
NRVO is most likely too hard for me, but I think it should not be too hard (well, except of liveness extension) to be able to make 1-2 MIR passes that will eliminate bound checks completely based on the facts from MIR statements. This pass was tested on a trivial code
Where bound checks can be obviously eliminated, but they are not. What I'd like to do is to accumulate the facts like
and be able to make judgements about them in different blocks. In my example the
So I can for sure say that This will be a good practice before full scale range analysis |
Restructured to follow lowering of intrinsics more closely, but couldn't yet understand how to make it language item. Instead interned |
@bors try @rust-timer queue let's see what perf says, too |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit bc11877830550fb9bdbf9c678d3e61b575261edd with merge 18c5138fd6998d04c4fbaeec7188078f2e8a9c7e... |
Hm, what would be the best way to structure it? There is a dependency: I need to first add new LanguageItem to be able to then modify |
Use |
☀️ Try build successful - checks-actions |
Queued 18c5138fd6998d04c4fbaeec7188078f2e8a9c7e with parent b17d9c1, future comparison URL. |
A little unrelated, but at the moment Extra info: made a dirty hack for arrays
There are fancy quircks:
|
So far I didn't set any threshold for MIR optimization level that enables this optimization other than > 0 (from mod.rs). What is a standard way to decide it? |
Since this is "just" adding another intrinsic-like lowering, we can add it directly without gating on the opt level I believe. |
Finished benchmarking try commit (18c5138fd6998d04c4fbaeec7188078f2e8a9c7e): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
📌 Commit aa53928 has been approved by |
⌛ Testing commit aa53928 with merge 7c7b6938c21b26ad34c9664813ff85689957180d... |
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
@bjorn3 Looks like random error in CI, |
@bors retry |
☀️ Test successful - checks-actions |
Just a quick heads up: I noticed this PR injected a few regressions to max-rss, up to 8.3% on incr-patched: println on inflate-debug. From skimming the results, I am not sure its worth taking any kind of corrective action to address the regressions. The max-rss results across the board are all over the place (e.g. some losses, and some wins on the order of -5%). I'm leaving the note more to remind people that when you do a perf run, its a good idea to try to double-check the (Arguably we should change the perf.rlo site to enable both |
Array `.len()` MIR optimization pass This pass kind-of works back the `[T; N].len()` call that at the moment is first coerced as `&[T; N]` -> `&[T]` and then uses `&[T].len()`. Depends on rust-lang#86383
During some larger experiment with range analysis I've found that code like
let l = slice.len()
produces different MIR then one found in bound checks. This optimization pass replaces terminators that are calls tocore::slice::len
with just a MIR operand and Goto terminator.It uses some heuristics to remove the outer borrow that is made to call
core::slice::len
, but I assume it can be eliminated, just didn't find how.Would like to express my gratitude to @oli-obk who helped me a lot on Zullip