Skip to content

Conversation

@scottmcm
Copy link
Member

@scottmcm scottmcm commented Feb 8, 2025

Previously it only did integer-ABI things, but this way it does data pointers too. That gives more information in general to the backend, and allows slightly simplifying one of the helpers in slice iterators.

@rustbot
Copy link
Collaborator

rustbot commented Feb 8, 2025

r? @oli-obk

rustbot has assigned @oli-obk.
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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 8, 2025
// CHECK: %[[A:.+]] = load ptr
// CHECK-SAME: !nonnull
// CHECK: %[[B:.+]] = load ptr
// CHECK-SAME: !nonnull
Copy link
Member Author

Choose a reason for hiding this comment

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

annot: this now goes through the transmute instead of the load-as-nonnull, but still ends up getting the !nonnull on the load as desired. (And all the https://github.com/rust-lang/rust/blob/master/tests/codegen/slice-iter-nonnull.rs tests still pass as well, no updates needed.)

@rust-log-analyzer

This comment has been minimized.

Comment on lines -7 to +8
let mut _2: *const *const T;
let mut _3: *const std::ptr::NonNull<T>;
let mut _8: *const T;
let mut _2: *const T;
let mut _7: *const T;
Copy link
Member Author

Choose a reason for hiding this comment

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

Really not that substantial a difference, but saved a local and means it no longer has the pointer-to-pointer types.

@scottmcm
Copy link
Member Author

scottmcm commented Feb 8, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 8, 2025
@bors
Copy link
Collaborator

bors commented Feb 8, 2025

⌛ Trying commit 48c0083 with merge 6ae82df...

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 8, 2025
`transmute` should also assume non-null pointers

Previously it only did integer-ABI things, but this way it does data pointers too.  That gives more information in general to the backend, and allows slightly simplifying one of the helpers in slice iterators.
/// [`iter_mut`]: slice::iter_mut
/// [slices]: slice
#[stable(feature = "rust1", since = "1.0.0")]
#[repr(C)] // *Not* a guarantee, but keeps the codegen tests consistent
Copy link
Member

Choose a reason for hiding this comment

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

Is this about layout randomization? If so then using the //@ needs-deterministic-layouts test annotation should be better, that way people can still get randomized iters.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, that does sound better.

@rustbot author

Copy link
Member

Choose a reason for hiding this comment

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

#[cfg_attr(not(doc), repr(C))] is also used in some places.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, the test annotation worked to keep it passing.

@rustbot ready

@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 Feb 8, 2025
@bors
Copy link
Collaborator

bors commented Feb 8, 2025

☀️ Try build successful - checks-actions
Build commit: 6ae82df (6ae82df21229ba9bca0dd9144cc5781c1875c6df)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6ae82df): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
1.2% [0.2%, 3.1%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.4% [-0.9%, -0.1%] 12
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.0% [-0.9%, 3.1%] 16

Max RSS (memory usage)

Results (primary -0.4%, secondary 2.4%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.0% [2.1%, 4.3%] 3
Regressions ❌
(secondary)
2.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
-3.9% [-6.6%, -2.1%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.4% [-6.6%, 4.3%] 6

Cycles

Results (primary 0.9%, secondary 2.8%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.7% [2.7%, 2.7%] 1
Regressions ❌
(secondary)
2.8% [2.8%, 2.8%] 1
Improvements ✅
(primary)
-0.9% [-0.9%, -0.9%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.9% [-0.9%, 2.7%] 2

Binary size

Results (primary -0.2%, secondary -0.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.4%] 16
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 34
Improvements ✅
(primary)
-0.3% [-1.8%, -0.0%] 48
Improvements ✅
(secondary)
-0.2% [-0.5%, -0.1%] 8
All ❌✅ (primary) -0.2% [-1.8%, 0.4%] 64

Bootstrap: 781.002s -> 777.406s (-0.46%)
Artifact size: 329.08 MiB -> 328.44 MiB (-0.19%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 8, 2025
@lqd
Copy link
Member

lqd commented Feb 8, 2025

(syn is currently being noisy)

@scottmcm
Copy link
Member Author

scottmcm commented Feb 9, 2025

Interesting, saved 630K off librustc_driver.so somehow, and a nice improvement in bootstrap time.

@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 Feb 9, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 9, 2025
Simplify `slice::Iter::next` enough that it inlines

Inspired by this zulip conversation: <https://rust-lang.zulipchat.com/#narrow/channel/189540-t-compiler.2Fwg-mir-opt/topic/Feedback.20on.20a.20MIR.20optimization.20idea/near/498579990>

Draft for now because it needs rust-lang#136735 to get the codegen tests to pass.
} else {
// SAFETY: for non-ZSTs, the type invariant ensures it cannot be null
let $end = unsafe { *(&raw const $this.end_or_len).cast::<NonNull<T>>() };
let $end = unsafe { mem::transmute::<*const T, NonNull<T>>($this.end_or_len) };
Copy link
Contributor

@oli-obk oli-obk Feb 11, 2025

Choose a reason for hiding this comment

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

Would it make sense/work to use NonNull::new_unchecked here and make the body of that use a transmute instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

In general I would like to move NonNull to using transmutes.

But in this specific case I really don't want to do that, because it adds a UbCheck which would then have major impact on perf because of just how critical next is.

(Though maybe after #136771, once the super-critical methods aren't using this helper macro any more, it could be worth trying.)

@scottmcm
Copy link
Member Author

Rebased to fix the conflict with the //@ compile-flags change.

@bors r=oli-obk

@bors
Copy link
Collaborator

bors commented Feb 13, 2025

📌 Commit 083672b has been approved by oli-obk

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 13, 2025
@rust-log-analyzer

This comment has been minimized.

Previously it only did integer-ABI things, but this way it does data pointers too.  That gives more information in general to the backend, and allows slightly simplifying one of the helpers in slice iterators.
@scottmcm
Copy link
Member Author

scottmcm commented Feb 13, 2025

Weird, somehow the rebase got the indent wrong and broke tidy. Well, fixed 🤷

@bors r=oli-obk

@bors
Copy link
Collaborator

bors commented Feb 13, 2025

📌 Commit 0cc14b6 has been approved by oli-obk

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Feb 14, 2025

⌛ Testing commit 0cc14b6 with merge d88ffcd...

@bors
Copy link
Collaborator

bors commented Feb 14, 2025

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing d88ffcd to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 14, 2025
@bors bors merged commit d88ffcd into rust-lang:master Feb 14, 2025
7 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Feb 14, 2025
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d88ffcd): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.5% [0.3%, 0.8%] 4
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
-0.5% [-1.0%, -0.2%] 7
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 2
All ❌✅ (primary) -0.2% [-1.0%, 0.8%] 11

Max RSS (memory usage)

Results (primary -0.5%, secondary -0.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
4.9% [4.9%, 4.9%] 1
Regressions ❌
(secondary)
2.4% [2.4%, 2.5%] 3
Improvements ✅
(primary)
-3.2% [-3.7%, -2.7%] 2
Improvements ✅
(secondary)
-3.7% [-4.0%, -3.3%] 2
All ❌✅ (primary) -0.5% [-3.7%, 4.9%] 3

Cycles

Results (primary -1.3%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.3% [-1.3%, -1.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.3% [-1.3%, -1.3%] 1

Binary size

Results (primary -0.2%, secondary -0.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.3%] 21
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 34
Improvements ✅
(primary)
-0.3% [-1.8%, -0.0%] 43
Improvements ✅
(secondary)
-0.2% [-0.5%, -0.1%] 8
All ❌✅ (primary) -0.2% [-1.8%, 0.3%] 64

Bootstrap: 787.772s -> 789.359s (0.20%)
Artifact size: 348.36 MiB -> 347.77 MiB (-0.17%)

@Kobzol
Copy link
Member

Kobzol commented Feb 18, 2025

Performance is a wash.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Feb 18, 2025
@scottmcm scottmcm deleted the transmute-nonnull branch February 19, 2025 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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. 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.

10 participants