Skip to content
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 tests for slice bounds check optimization #139129

Merged

Conversation

reez12g
Copy link
Contributor

@reez12g reez12g commented Mar 30, 2025

Closes #134466

@rustbot
Copy link
Collaborator

rustbot commented Mar 30, 2025

r? @fee1-dead

rustbot has assigned @fee1-dead.
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 30, 2025
@rust-log-analyzer

This comment has been minimized.

@reez12g reez12g force-pushed the add-tests-for-slice-bounds-check-optimization branch from f8d5a87 to 599a94d Compare March 30, 2025 10:04
@rust-log-analyzer

This comment has been minimized.

@reez12g reez12g force-pushed the add-tests-for-slice-bounds-check-optimization branch from 599a94d to f98f095 Compare March 30, 2025 10:50
@reez12g reez12g marked this pull request as ready for review March 30, 2025 12:00
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this file is needed because it doesn't test anything new. Could you remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I removed it.

Comment on lines 14 to 18
// In a suboptimal implementation this would contain a call to
// slice_start_index_len_fail that is unreachable.

// The fix exists in LLVM 20: We use this implementation with
// bounds check outside of slice operation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// In a suboptimal implementation this would contain a call to
// slice_start_index_len_fail that is unreachable.
// The fix exists in LLVM 20: We use this implementation with
// bounds check outside of slice operation.
// Previously this would generate a branch to slice_start_index_len_fail
// that is unreachable. The LLVM 20 fix should eliminate this branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly, I think it is okay to only keep the codegen test. assembly is one step further than we need since we just have to check if the LLVM IR contains the call

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to this -- assembly is annoyingly platform specific in a bunch of ways, so we should test it as little as possible in rustc. Specific assembly is almost always LLVM's problem, not our problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense — I’ve already removed the assembly test accordingly.
Only the codegen test remains now.

Comment on lines 28 to 29
// This implementation avoids the issue by moving the slice operation
// inside the conditional.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// This implementation avoids the issue by moving the slice operation
// inside the conditional.
// This version was already correctly optimized before the fix in LLVM 20.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion — I’ve applied it.

@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 Mar 30, 2025
@reez12g reez12g force-pushed the add-tests-for-slice-bounds-check-optimization branch from f98f095 to dea9472 Compare March 31, 2025 13:38
@reez12g
Copy link
Contributor Author

reez12g commented Apr 1, 2025

@rustbot ready

@rustbot rustbot 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 Apr 1, 2025
@fee1-dead
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Apr 1, 2025

📌 Commit dea9472 has been approved by fee1-dead

It is now in the queue for this repository.

@bors bors 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 Apr 1, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Apr 1, 2025
…-check-optimization, r=fee1-dead

Add tests for slice bounds check optimization

Closes rust-lang#134466
Zalathar added a commit to Zalathar/rust that referenced this pull request Apr 1, 2025
…-check-optimization, r=fee1-dead

Add tests for slice bounds check optimization

Closes rust-lang#134466
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 1, 2025
Rollup of 12 pull requests

Successful merges:

 - rust-lang#110406 (rustdoc-json: Add test for #[automatically_derived] attribute)
 - rust-lang#137738 (Make slice iterator constructors unstably const)
 - rust-lang#138492 (remove `feature(inline_const_pat)`)
 - rust-lang#138928 (Fix UWP reparse point check)
 - rust-lang#138950 (replace extra_filename with strict version hash in metrics file names)
 - rust-lang#139002 (Add release notes for 1.86.0)
 - rust-lang#139022 (increment depth of nested obligations)
 - rust-lang#139060 (replace commit placeholder in vendor status with actual commit)
 - rust-lang#139102 (coverage: Avoid splitting spans during span extraction/refinement)
 - rust-lang#139129 (Add tests for slice bounds check optimization)
 - rust-lang#139188 (PassWrapper: adapt for llvm/llvm-project@94122d58fc77079a291a3d008914…)
 - rust-lang#139193 (Feed HIR for by-move coroutine body def, since the inliner tries to read its attrs)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 1, 2025
…-check-optimization, r=fee1-dead

Add tests for slice bounds check optimization

Closes rust-lang#134466
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 1, 2025
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#110406 (rustdoc-json: Add test for #[automatically_derived] attribute)
 - rust-lang#138790 (Note potential but private items in show_candidates)
 - rust-lang#138950 (replace extra_filename with strict version hash in metrics file names)
 - rust-lang#139002 (Add release notes for 1.86.0)
 - rust-lang#139022 (increment depth of nested obligations)
 - rust-lang#139129 (Add tests for slice bounds check optimization)
 - rust-lang#139188 (PassWrapper: adapt for llvm/llvm-project@94122d58fc77079a291a3d008914…)
 - rust-lang#139193 (Feed HIR for by-move coroutine body def, since the inliner tries to read its attrs)
 - rust-lang#139202 (Improve docs of ValTreeKind)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 1, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#110406 (rustdoc-json: Add test for #[automatically_derived] attribute)
 - rust-lang#138790 (Note potential but private items in show_candidates)
 - rust-lang#139002 (Add release notes for 1.86.0)
 - rust-lang#139022 (increment depth of nested obligations)
 - rust-lang#139129 (Add tests for slice bounds check optimization)
 - rust-lang#139188 (PassWrapper: adapt for llvm/llvm-project@94122d58fc77079a291a3d008914…)
 - rust-lang#139193 (Feed HIR for by-move coroutine body def, since the inliner tries to read its attrs)
 - rust-lang#139202 (Improve docs of ValTreeKind)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a04b0e3 into rust-lang:master Apr 2, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 2, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2025
Rollup merge of rust-lang#139129 - reez12g:add-tests-for-slice-bounds-check-optimization, r=fee1-dead

Add tests for slice bounds check optimization

Closes rust-lang#134466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slice bounds check not elided in trivial case when using a local varaible outside of a branch
7 participants