Uh oh!
There was an error while loading. Please reload this page.
Add MIR pass to lower call to core::slice::len into Len operand - #86383
Conversation
rust-highfive
commented
Jun 16, 2021
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 |
shamatar
commented
Jun 16, 2021
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 |
scottmcm
commented
Jun 16, 2021
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.
shamatar
commented
Jun 16, 2021
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 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
shamatar
commented
Jun 17, 2021
Restructured to follow lowering of intrinsics more closely, but couldn't yet understand how to make it language item. Instead interned |
oli-obk
commented
Jun 17, 2021
@bors try @rust-timer queue let's see what perf says, too |
rust-timer
commented
Jun 17, 2021
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
bors
commented
Jun 17, 2021
⌛ Trying commit bc11877830550fb9bdbf9c678d3e61b575261edd with merge 18c5138fd6998d04c4fbaeec7188078f2e8a9c7e... |
shamatar
commented
Jun 17, 2021
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 |
bjorn3
commented
Jun 17, 2021
Use |
bors
commented
Jun 17, 2021
☀️ Try build successful - checks-actions |
rust-timer
commented
Jun 17, 2021
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:
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
shamatar
commented
Jun 17, 2021
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? |
oli-obk
commented
Jun 17, 2021
Since this is "just" adding another intrinsic-like lowering, we can add it directly without gating on the opt level I believe. |
rust-timer
commented
Jun 17, 2021
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 |
bors
commented
Jun 21, 2021
📌 Commit aa53928 has been approved by |
bors
commented
Jun 21, 2021
⌛ Testing commit aa53928 with merge 7c7b6938c21b26ad34c9664813ff85689957180d... |
rust-log-analyzer
commented
Jun 21, 2021
The job Click to see the possible cause of the failure (guessed by this bot) |
bors
commented
Jun 21, 2021
💔 Test failed - checks-actions |
shamatar
commented
Jun 21, 2021
@bjorn3 Looks like random error in CI, |
bjorn3
commented
Jun 21, 2021
@bors retry |
bors
commented
Jun 21, 2021
bors
commented
Jun 22, 2021
☀️ 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::lenwith 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