Skip to content

Rearrange slice::split_mut to remove bounds check - #99223

Merged
bors merged 1 commit into
rust-lang:masterfrom
saethlin:panicless-split-mut
Jul 18, 2022
Merged

Rearrange slice::split_mut to remove bounds check#99223
bors merged 1 commit into
rust-lang:masterfrom
saethlin:panicless-split-mut

Conversation

@saethlin

@saethlinsaethlin commented Jul 14, 2022

Copy link
Copy Markdown
Member

Closes#86313

Turns out that all we need to do here is reorder the bounds checks to convince LLVM that all the bounds checks can be removed. It seems like LLVM just fails to propagate the original length information past the first bounds check and into the second one. With this implementation it doesn't need to, each check can be proven inbounds based on the one immediately previous.

I've gradually convinced myself that this implementation is unambiguously better based on the above logic, but maybe this is still deserving of a codegen test?

Also the mentioned borrowck limitation no longer seems to exist.

@rustbot

Copy link
Copy Markdown
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rustbotrustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jul 14, 2022
@rust-highfive

Copy link
Copy Markdown
Contributor

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 14, 2022
Comment threadlibrary/core/src/slice/iter.rs Outdated
@Mark-Simulacrum

Copy link
Copy Markdown
Member

If you feel up to writing a codegen test, I'm all for codegen tests in general. But I don't feel it's necessary here.

@Mark-SimulacrumMark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 14, 2022
@saethlin
saethlinforce-pushed the panicless-split-mut branch from d60ed7d to 82cb5d8CompareJuly 16, 2022 04:14
Comment threadlibrary/core/src/slice/iter.rs Outdated
@saethlin
saethlinforce-pushed the panicless-split-mut branch from 82cb5d8 to c937390CompareJuly 16, 2022 16:26
@saethlin

Copy link
Copy Markdown
MemberAuthor

@rustbot ready

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 16, 2022
@saethlin

Copy link
Copy Markdown
MemberAuthor

I am choosing the lazy route with no codegen test, because as mentioned I have convinced myself that this pattern is strictly easier to optimize.

@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+ rollup=never

@bors

bors commented Jul 16, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit c937390 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 16, 2022
@bors

bors commented Jul 18, 2022

Copy link
Copy Markdown
Collaborator

⌛ Testing commit c937390 with merge 9ed0bf9...

@bors

bors commented Jul 18, 2022

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing 9ed0bf9 to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label Jul 18, 2022
@bors
bors merged commit 9ed0bf9 into rust-lang:masterJul 18, 2022
@rustbotrustbot added this to the 1.64.0 milestone Jul 18, 2022
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9ed0bf9): comparison url.

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results
  • Primary benchmarks: 🎉 relevant improvements found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1maxcount2
Regressions 😿
(primary)
N/AN/A0
Regressions 😿
(secondary)
N/AN/A0
Improvements 🎉
(primary)
-1.5%-2.7%4
Improvements 🎉
(secondary)
-2.6%-2.9%3
All 😿🎉 (primary)-1.5%-2.7%4

Cycles

Results
  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: mixed results
mean1maxcount2
Regressions 😿
(primary)
2.9%3.1%2
Regressions 😿
(secondary)
4.6%4.6%1
Improvements 🎉
(primary)
N/AN/A0
Improvements 🎉
(secondary)
-2.8%-2.8%1
All 😿🎉 (primary)2.9%3.1%2

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. the arithmetic mean of the percent change2

  2. number of relevant changes2

@saethlin
saethlin deleted the panicless-split-mut branch September 3, 2022 23:26
daniel5151 added a commit to daniel5151/gdbstub that referenced this pull request Dec 29, 2022
rust-lang/rust#99223 fixes the bounds check in
split_mut and splitn_mut, so no need to carry those custom
implementations anymore.
Also tweak some of the bounds checking code in the target.xml handler,
since it re-introduced a bounds check in newer rustc versions...
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

slice::split_mut does not elide bound checks in release mode

7 participants

@saethlin@rustbot@rust-highfive@Mark-Simulacrum@bors@rust-timer@klensy