Skip to content

add test for codegen of SIMD vector from array repeat#151869

Open
folkertdev wants to merge 1 commit intorust-lang:mainfrom
folkertdev:simd-array-repeat
Open

add test for codegen of SIMD vector from array repeat#151869
folkertdev wants to merge 1 commit intorust-lang:mainfrom
folkertdev:simd-array-repeat

Conversation

@folkertdev
Copy link
Contributor

@folkertdev folkertdev commented Jan 30, 2026

fixes #97804

It appears that this issue was fixed silently in LLVM 19. The original codegen was terrible, but starting at LLVM 19 opt is able to generate good code.

https://llvm.godbolt.org/z/5vq8scP6q

cc @programmerjake

@folkertdev folkertdev added the A-SIMD Area: SIMD (Single Instruction Multiple Data) label Jan 30, 2026
@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 Jan 30, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 30, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@folkertdev
Copy link
Contributor Author

folkertdev commented Jan 30, 2026

Hmm, it is fixed on x86_64 and aarch64, but not for other targets where vector types require a target feature.

  • for s390x it only optimizes when the vector target feature is available
  • for wasm32 even with +simd128 it does not optimize (should just be a splat I think?)

Do we consider that fixed?

@folkertdev
Copy link
Contributor Author

I did file llvm/llvm-project#178940 for the wasm issue, cc @nikic

@workingjubilee
Copy link
Member

workingjubilee commented Jan 30, 2026

For s390x without +vector, it probably comes from type legalization: LLVM, if it can't fit a type or operation with that type to a series of machine operations, will, during... lowering to SelectionDAG, I think?... "scalarize" the operations into operations on a valid type.

@folkertdev
Copy link
Contributor Author

I'm a bit out of my depth here, but I would expect the transformation to a vector splat to happen much earlier than that. You're right that it does appear use information about what types are legal for the current target though.

@workingjubilee
Copy link
Member

I think this is fine to merge if the test gets qualified with the appropriate architectures or whatever.

@Mark-Simulacrum
Copy link
Member

@rustbot author

Yeah, with appropriate ignore-X added seems OK to approve, though we should probably leave the issue open in that case?

@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 1, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 1, 2026

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

@folkertdev folkertdev force-pushed the simd-array-repeat branch 2 times, most recently from ac7219f to 5e8a380 Compare February 3, 2026 19:37
@rustbot
Copy link
Collaborator

rustbot commented Feb 3, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

@folkertdev
Copy link
Contributor Author

I personally think the issue can be closed because we have and use simd_splat now instead of an array repeat expression. So the missed optimization caused worse code in practice before, while now for wasm that should not be the case unless you manually experiment with repr(simd) and don't use simd_splat.

@rustbot ready

@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 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-SIMD Area: SIMD (Single Instruction Multiple Data) 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array Repeat operator should not use a loop for small sizes

7 participants