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

Use unchecked_sub in split_at #124699

Merged

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented May 4, 2024

LLVM currently isn't figuring it out on its own, even in the checked version where it hypothetically could.

Before: https://rust.godbolt.org/z/PEY38YrKs

bb1:                                              ; preds = %start
  %4 = getelementptr inbounds float, ptr %x.0, i64 %n
  %5 = sub i64 %x.1, %n

After:

bb1:                                              ; preds = %start
  %4 = getelementptr inbounds float, ptr %x.0, i64 %n
  %5 = sub nuw i64 %x.1, %n

This is not using the wrapper because there's already a ubcheck covering it, so I don't want this to get a second one once #121571 lands.


This is basically the same as #108763, since split_at is essentially doing two get_uncheckeds.

@rustbot
Copy link
Collaborator

rustbot commented May 4, 2024

r? @m-ou-se

rustbot has assigned @m-ou-se.
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 May 4, 2024
@@ -2035,7 +2035,12 @@ impl<T> [T] {
//
// `[ptr; mid]` and `[mid; len]` are not overlapping, so returning a mutable reference
// is fine.
unsafe { (from_raw_parts_mut(ptr, mid), from_raw_parts_mut(ptr.add(mid), len - mid)) }
unsafe {
Copy link
Member

Choose a reason for hiding this comment

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

two local variables for the left and right sides would have been nice here to reduce the lines from 6 to 3 :3, things like this are certainly formative of your opinions about rustfmt 😆 (though i can't really complain, it's doing its best)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, my preferred philosophical underpinnings for a formatter are pretty different from those that rustfmt picked :(

@Noratrieb
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 4, 2024

📌 Commit f1de4c1 has been approved by Nilstrieb

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 May 4, 2024
@Noratrieb
Copy link
Member

r? Nilstrieb

@rustbot rustbot assigned Noratrieb and unassigned m-ou-se May 4, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 4, 2024
…_use_unchecked, r=Nilstrieb

Use `unchecked_sub` in `split_at`

LLVM currently isn't figuring it out on its own, even in the checked version where it hypothetically could.

Before: <https://rust.godbolt.org/z/PEY38YrKs>
```llvm
bb1:                                              ; preds = %start
  %4 = getelementptr inbounds float, ptr %x.0, i64 %n
  %5 = sub i64 %x.1, %n
```

After:
```llvm
bb1:                                              ; preds = %start
  %4 = getelementptr inbounds float, ptr %x.0, i64 %n
  %5 = sub nuw i64 %x.1, %n
```

This is not using the wrapper because there's already a ubcheck covering it, so I don't want this to get a second one once rust-lang#121571 lands.

---

This is basically the same as rust-lang#108763, since `split_at` is essentially doing two `get_unchecked`s.
bors added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#122441 (Improve several `Read` implementations)
 - rust-lang#124584 (Various improvements to entrypoint code)
 - rust-lang#124699 (Use `unchecked_sub` in `split_at`)
 - rust-lang#124704 (Fix ignored tests for formatting)
 - rust-lang#124709 (Miri subtree update)

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

Rollup of 5 pull requests

Successful merges:

 - rust-lang#122441 (Improve several `Read` implementations)
 - rust-lang#124584 (Various improvements to entrypoint code)
 - rust-lang#124699 (Use `unchecked_sub` in `split_at`)
 - rust-lang#124704 (Fix ignored tests for formatting)
 - rust-lang#124709 (Miri subtree update)

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

Rollup of 4 pull requests

Successful merges:

 - rust-lang#122441 (Improve several `Read` implementations)
 - rust-lang#124584 (Various improvements to entrypoint code)
 - rust-lang#124699 (Use `unchecked_sub` in `split_at`)
 - rust-lang#124715 (interpret, miri: uniform treatments of intrinsics/functions with and without return block)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a5cc1f6 into rust-lang:master May 4, 2024
6 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 4, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2024
Rollup merge of rust-lang#124699 - scottmcm:split_at_unchecked_should_use_unchecked, r=Nilstrieb

Use `unchecked_sub` in `split_at`

LLVM currently isn't figuring it out on its own, even in the checked version where it hypothetically could.

Before: <https://rust.godbolt.org/z/PEY38YrKs>
```llvm
bb1:                                              ; preds = %start
  %4 = getelementptr inbounds float, ptr %x.0, i64 %n
  %5 = sub i64 %x.1, %n
```

After:
```llvm
bb1:                                              ; preds = %start
  %4 = getelementptr inbounds float, ptr %x.0, i64 %n
  %5 = sub nuw i64 %x.1, %n
```

This is not using the wrapper because there's already a ubcheck covering it, so I don't want this to get a second one once rust-lang#121571 lands.

---

This is basically the same as rust-lang#108763, since `split_at` is essentially doing two `get_unchecked`s.
@scottmcm scottmcm deleted the split_at_unchecked_should_use_unchecked branch May 4, 2024 20:25
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-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.

5 participants