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

Copy 1-/2-element arrays as scalars, not vectors #116479

Closed
wants to merge 1 commit into from

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Oct 6, 2023

For [T; 1] it's silly to copy as <1 x T> when we can just copy as T.
And treat [T; 2] as a scalar pair (like (T, T)) when copying it.

Inspired by #101210 (comment), which pointed out that Option<[u8; 1]> was codegenning worse than Option<u8>.

(I'm not sure why LLVM doesn't optimize out <1 x u8>, but might as well just not emit it in the first place in this codepath.)

@rustbot
Copy link
Collaborator

rustbot commented Oct 6, 2023

r? @davidtwco

(rustbot has picked a reviewer for you, use r? to override)

@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 Oct 6, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

For `[T; 1]` it's silly to copy as `<1 x T>` when we can just copy as `T`.
And treat `[T; 2]` as a scalar pair like `(T, T)` when copying it.
@compiler-errors
Copy link
Member

@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 Oct 6, 2023
@compiler-errors compiler-errors self-assigned this Oct 6, 2023
@bors
Copy link
Contributor

bors commented Oct 6, 2023

⌛ Trying commit b5a9dd7 with merge b571f53...

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 6, 2023
Copy 1-/2-element arrays as scalars, not vectors

For `[T; 1]` it's silly to copy as `<1 x T>` when we can just copy as `T`.
And treat `[T; 2]` as a scalar pair (like `(T, T)`) when copying it.

Inspired by rust-lang#101210 (comment), which pointed out that `Option<[u8; 1]>` was codegenning worse than `Option<u8>`.

(I'm not sure *why* LLVM doesn't optimize out `<1 x u8>`, but might as well just not emit it in the first place in this codepath.)
@compiler-errors
Copy link
Member

(don't expect perf to come back up with much but we'll see what it does to rustc at least)

@bors
Copy link
Contributor

bors commented Oct 6, 2023

☀️ Try build successful - checks-actions
Build commit: b571f53 (b571f53b9ed2b2e638a502786e099948a6809c43)

@rust-timer

This comment has been minimized.

// (Having types like `<1 x u8>` is silly.)
let ety = element.llvm_type(cx);
return Some(cx.type_array(ety, *count));
} else if count.is_power_of_two() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is already inside if count.is_power_of_two(), did you mean to remove it from the outer condition?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! I think I'd intended to remove it from the outer, but with the tests not actually failing I guess I never did.

@rustbot author

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b571f53): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

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 a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.2% [0.1%, 0.2%] 8
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.1%, 0.2%] 8

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.5% [4.5%, 4.5%] 1
Regressions ❌
(secondary)
1.2% [1.2%, 1.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.0% [-3.5%, -2.4%] 2
All ❌✅ (primary) 4.5% [4.5%, 4.5%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 625.189s -> 622.203s (-0.48%)
Artifact size: 270.66 MiB -> 270.65 MiB (-0.00%)

@rustbot rustbot added perf-regression Performance regression. 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-perf Status: Waiting on a perf run to be completed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 6, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 7, 2023
Copy 1-element arrays as scalars, not vectors

For `[T; 1]` it's silly to copy as `<1 x T>` when we can just copy as `T`.

Inspired by rust-lang#101210 (comment), which pointed out that `Option<[u8; 1]>` was codegenning worse than `Option<u8>`.

(I'm not sure *why* LLVM doesn't optimize out `<1 x u8>`, but might as well just not emit it in the first place in this codepath.)

---

I think I bit off too much in rust-lang#116479; let me try just the scalar case first.

r? `@ghost`
@scottmcm scottmcm marked this pull request as draft October 8, 2023 07:07
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 12, 2023
…rors

Copy 1-element arrays as scalars, not vectors

For `[T; 1]` it's silly to copy as `<1 x T>` when we can just copy as `T`.

Inspired by rust-lang#101210 (comment), which pointed out that `Option<[u8; 1]>` was codegenning worse than `Option<u8>`.

(I'm not sure *why* LLVM doesn't optimize out `<1 x u8>`, but might as well just not emit it in the first place in this codepath.)

---

I think I bit off too much in rust-lang#116479; let me try just the scalar case first.

r? `@ghost`
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 12, 2023
…rors

Copy 1-element arrays as scalars, not vectors

For `[T; 1]` it's silly to copy as `<1 x T>` when we can just copy as `T`.

Inspired by rust-lang#101210 (comment), which pointed out that `Option<[u8; 1]>` was codegenning worse than `Option<u8>`.

(I'm not sure *why* LLVM doesn't optimize out `<1 x u8>`, but might as well just not emit it in the first place in this codepath.)

---

I think I bit off too much in rust-lang#116479; let me try just the scalar case first.

r? `@ghost`
@scottmcm
Copy link
Member Author

scottmcm commented May 4, 2024

Given #123185, I think this is no longer a good idea.

@scottmcm scottmcm closed this May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

None yet

8 participants