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

Fix simd_bswap for i8/u8 #114266

Merged
merged 1 commit into from
Jul 31, 2023
Merged

Fix simd_bswap for i8/u8 #114266

merged 1 commit into from
Jul 31, 2023

Conversation

calebzulawski
Copy link
Member

#114156 missed this test case ☹️
cc @workingjubilee

@rustbot
Copy link
Collaborator

rustbot commented Jul 30, 2023

r? @compiler-errors

(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 Jul 30, 2023
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

Do we expect people to be calling this intrinsic on i8xN? This seems like a misuse of the intrinsic, or at least for LLVM, since llvm.bswap.* says the element needs an even number of bytes.

@workingjubilee
Copy link
Member

indeed, what are we actually trying to achieve here?

@calebzulawski
Copy link
Member Author

This mirrors the scalar bswap intrinsic:

sym::bswap => {
if width == 8 {
args[0].immediate() // byte swap a u8/i8 is just a no-op
} else {
self.call_intrinsic(
&format!("llvm.bswap.i{}", width),
&[args[0].immediate()],
)
}
}

It would be a bit of a pain to special-case i8/u8 vectors in std::simd.

@workingjubilee
Copy link
Member

or more precisely, what is the current behavior we're trying to avoid?

@calebzulawski
Copy link
Member Author

or more precisely, what is the current behavior we're trying to avoid?

I thought LLVM would handle a no-op, but instead the compiler crashes:

warning: build failed, waiting for other jobs to finish...
bswap must be an even number of bytes
  %4 = call <32 x i8> @llvm.bswap.v32i8(<32 x i8> %3), !dbg !858
in function _ZN113_$LT$core_simd..core_simd..vector..Simd$LT$i8$C$_$GT$$u20$as$u20$core_simd..core_simd..elements..int..SimdInt$GT$10swap_bytes17h00fedc46e657fc9cE
LLVM ERROR: Broken function found, compilation aborted!
error: could not compile `core_simd` (test "i8_ops")

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

I guess r=me if @workingjubilee thinks that this is worthwhile -- the fact that we're special-casing i8 in both the simd and non-simd bswap intrinsics is a tiny bit odd, but I could believe it makes sense with like... macro-generated code or something. Still kinda sus, though.

@workingjubilee
Copy link
Member

lmao llvm

@calebzulawski
Copy link
Member Author

Both scalar integers and std::simd integer vectors are macro-generated 🙃 No users should be seeing these intrinsics.

@compiler-errors
Copy link
Member

To be fair to LLVM, it says very clearly that the intrinsic is only defined when BitWidth % 16 == 0.

@workingjubilee
Copy link
Member

workingjubilee commented Jul 30, 2023

I guess r=me if @workingjubilee thinks that this is worthwhile

yeaaaaah, I guess.

but I could believe it makes sense with like... macro-generated code or something

that describes all of std's integer impls, baby!

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jul 30, 2023

📌 Commit 77ed437 has been approved by compiler-errors

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 Jul 30, 2023
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jul 31, 2023
…er-errors

Fix simd_bswap for i8/u8

rust-lang#114156 missed this test case ☹️
cc `@workingjubilee`
@workingjubilee
Copy link
Member

@bors r- rollup=iffy
cc #114270

I have no idea but I'm almost certain it's this PR.

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 31, 2023
@calebzulawski
Copy link
Member Author

The failed test is tests/ui/lint/must_not_suspend/handled.rs, I don't see any way this PR could affect that. Maybe spurious?

@workingjubilee
Copy link
Member

...hm yeah you're right, I misread the logs at-a-glance.

Probably is spurious then.

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jul 31, 2023

📌 Commit 77ed437 has been approved by compiler-errors

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 Jul 31, 2023
@bors
Copy link
Contributor

bors commented Jul 31, 2023

⌛ Testing commit 77ed437 with merge 3be07c1...

@bors
Copy link
Contributor

bors commented Jul 31, 2023

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 3be07c1 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 31, 2023
@bors bors merged commit 3be07c1 into rust-lang:master Jul 31, 2023
@rustbot rustbot added this to the 1.73.0 milestone Jul 31, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3be07c1): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

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

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

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

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.3% [2.1%, 2.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 652.418s -> 653.862s (0.22%)

@rustbot rustbot added the perf-regression Performance regression. label Jul 31, 2023
@nnethercote
Copy link
Contributor

One possible, marginal regression, nothing to worry about.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jul 31, 2023
@calebzulawski calebzulawski deleted the simd-bswap branch August 1, 2023 12:03
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants