Skip to content

Help optimize out bounds checks in median_of_medians #144327

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kornelski
Copy link
Contributor

@kornelski kornelski commented Jul 22, 2025

LLVM can't see that assert!((v / 200) <= (v / 2)) is always true, so it couldn't remove bounds in median_of_ninthers.

.unwrap() outside of min_index() was losing bounds information. I've even tried assume(index < slice.len()); return Some(index), but it didn't help. Only moving the unwrap() to inside the function seems to keep the range information (and doesn't need assume).

Part of #144326

@rustbot
Copy link
Collaborator

rustbot commented Jul 22, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 22, 2025
@tgross35
Copy link
Contributor

tgross35 commented Jul 22, 2025

Is this something that could get a codegen test to make sure we don't have a jump to a panic? Seems easy to accidentally regress.

@kornelski
Copy link
Contributor Author

A codegen test would be valuable, but these functions are inlined into other functions that still need bounds checks fixed, so I can't realistically codegen tests until more of this work is done.

@kornelski kornelski marked this pull request as draft July 27, 2025 11:47
@rustbot rustbot 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 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant 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.

3 participants