Skip to content

Conversation

sayantn
Copy link
Contributor

@sayantn sayantn commented Sep 28, 2025

While testing out some intrinsic-based implementation in stdarch, I noticed that LLVM can't optimize it well if we use simple bitcast and truncs to get the actual i1xNs from the bitmasks. LLVM actually seems to like it better if we use shufflevectors, and for autoupgraded intrinsics that used integer returns, but were migrated to use i1xN returns, LLVM actually use this exact form (https://godbolt.org/z/YT99Phzj5)

This doesn't affect any codegen that uses vectors that are multiples-of-8-length. This is mostly targeted towards 2- and 4-width vectors

@rustbot A-LLVM A-codegen T-compiler

r? codegen

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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 Sep 28, 2025
@saethlin
Copy link
Member

saethlin commented Oct 2, 2025

Can you add a codegen test that demonstrates a case where this actually helps? I feel like the fact that a shufflevector leads to better codegen than bitcast + trunc is at the very least unintuitive. Is this recognized as an upstream bug?

r? author

@rustbot
Copy link
Collaborator

rustbot commented Oct 2, 2025

Failed to set assignee to author: cannot assign: response: {"message":"Not Found","documentation_url":"https://docs.github.com/rest/issues/assignees#add-assignees-to-an-issue","status":"404"}

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@sayantn
Copy link
Contributor Author

sayantn commented Oct 2, 2025

@rustbot author

I did observe some improved codegen with this, but unfortunately I forgot which example it was. I will try to find it out and add a test/example

@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 Oct 2, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 2, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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.

3 participants