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

Let codegen decide when to mem::swap with immediates #122582

Merged
merged 5 commits into from
Mar 23, 2024

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Mar 16, 2024

Making libcore decide this is silly; the backend has so much better information about when it's a good idea.

Thus this PR introduces a new typed_swap intrinsic with a fallback body, and replaces that fallback implementation when swapping immediates or scalar pairs.

r? oli-obk

Replaces #111744, and means we'll never need more libs PRs like #111803 or #107140

@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 Mar 16, 2024
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm marked this pull request as draft March 16, 2024 05:45
@scottmcm scottmcm 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 16, 2024
@scottmcm scottmcm marked this pull request as ready for review March 16, 2024 09:23
@rustbot
Copy link
Collaborator

rustbot commented Mar 16, 2024

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

The Miri subtree was changed

cc @rust-lang/miri

@scottmcm scottmcm 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 Mar 16, 2024
@scottmcm
Copy link
Member Author

@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 Mar 16, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 16, 2024
Let codegen decide when to `mem::swap` with immediates

Making `libcore` decide this is silly; the backend has so much better information about when it's a good idea.

Thus this PR introduces a new `typed_swap` intrinsic with a fallback body, and replaces that fallback implementation when swapping immediates or scalar pairs.

r? oli-obk

Replaces rust-lang#111744, and means we'll never need more libs PRs like rust-lang#111803 or rust-lang#107140
@bors
Copy link
Contributor

bors commented Mar 16, 2024

⌛ Trying commit e583c57 with merge 3f68c63...

@bors
Copy link
Contributor

bors commented Mar 16, 2024

☀️ Try build successful - checks-actions
Build commit: 3f68c63 (3f68c63f114f4d57b01ae74bc549e4b68f955eee)

@rust-timer

This comment has been minimized.

@rust-timer

This comment was marked as outdated.

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 16, 2024
@@ -954,6 +954,23 @@ pub const unsafe fn swap<T>(x: *mut T, y: *mut T) {
}
}

/// Non-overlapping *typed* swap of a single value.
Copy link
Member

Choose a reason for hiding this comment

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

Should it be called typed_swap_nonoverlapping?

Copy link
Member Author

Choose a reason for hiding this comment

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

I went back and forth multiple times on this. typed_swap_nonoverlapping sounds to me like ptr::swap_nonoverlapping, just typed. So that would make this typed_swap_nonoverlapping_one or something, and now that's just seeming really long.

So since it's internal, I think I'm inclined to leave it as-is for now unless someone feels particularly strongly about it.

Copy link
Member

Choose a reason for hiding this comment

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

I feel like the "nonoverlapping" distinction is way more fundamental than the "one" distinction. And since it is internal, consistency with ptr::swap_nonoverlapping isn't very important IMO.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 23, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 23, 2024
@scottmcm
Copy link
Member Author

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Mar 23, 2024

📌 Commit 75d2e5b 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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 23, 2024
@bors
Copy link
Contributor

bors commented Mar 23, 2024

⌛ Testing commit 75d2e5b with merge ea4d0e9...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 23, 2024
Let codegen decide when to `mem::swap` with immediates

Making `libcore` decide this is silly; the backend has so much better information about when it's a good idea.

Thus this PR introduces a new `typed_swap` intrinsic with a fallback body, and replaces that fallback implementation when swapping immediates or scalar pairs.

r? oli-obk

Replaces rust-lang#111744, and means we'll never need more libs PRs like rust-lang#111803 or rust-lang#107140
@bors
Copy link
Contributor

bors commented Mar 23, 2024

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 23, 2024
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@RalfJung
Copy link
Member

@bors retry

@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 Mar 23, 2024
@bors
Copy link
Contributor

bors commented Mar 23, 2024

⌛ Testing commit 75d2e5b with merge d6eb0f5...

@bors
Copy link
Contributor

bors commented Mar 23, 2024

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 23, 2024
@bors bors merged commit d6eb0f5 into rust-lang:master Mar 23, 2024
12 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Mar 23, 2024
@scottmcm scottmcm deleted the swap-intrinsic-v2 branch March 23, 2024 16:47
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d6eb0f5): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

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

Max RSS (memory usage)

Results

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.3% [0.1%, 6.8%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-5.3% [-5.3%, -5.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.9% [-5.3%, 6.8%] 4

Cycles

Results

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)
2.5% [2.5%, 2.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

Results

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%] 27
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.2% [-1.0%, -0.0%] 10
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [-1.0%, 0.4%] 37

Bootstrap: 669.588s -> 671.198s (0.24%)
Artifact size: 315.05 MiB -> 314.95 MiB (-0.03%)

RenjiSann pushed a commit to RenjiSann/rust that referenced this pull request Mar 25, 2024
Let codegen decide when to `mem::swap` with immediates

Making `libcore` decide this is silly; the backend has so much better information about when it's a good idea.

Thus this PR introduces a new `typed_swap` intrinsic with a fallback body, and replaces that fallback implementation when swapping immediates or scalar pairs.

r? oli-obk

Replaces rust-lang#111744, and means we'll never need more libs PRs like rust-lang#111803 or rust-lang#107140
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. 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.

9 participants