Skip to content

Concrete SIMD.init(repeating:) and SIMD.init(lowHalf:highHalf:) optimizations #81766

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

Merged
merged 5 commits into from
May 27, 2025

Conversation

stephentyrone
Copy link
Contributor

@stephentyrone stephentyrone commented May 25, 2025

WIP to add more overloads to optimize SIMD codegen on concrete types. Here we do:

  • init(repeating:)
  • init(lowHalf:highHalf:)

These are always inlined, even in debug, since LLVM knows how to lower them to one or two instructions on the targets that we care about.

@stephentyrone stephentyrone requested a review from a team as a code owner May 25, 2025 00:57
@stephentyrone
Copy link
Contributor Author

@swift-ci test

@stephentyrone
Copy link
Contributor Author

@swift-ci benchmark

@stephentyrone
Copy link
Contributor Author

(I don't think that this will move much in the benchmark suite, but we have determined that it's a significant win via inspection of the generated assembly for newly added test cases)

@stephentyrone stephentyrone requested review from Azoy and drexin May 25, 2025 00:59
Split these out into separate files for Mask, Integer, Float, since each has a somewhat different set of operations.
Previously these were not transparent, and so were not generally inlined in debug; that's basically always a win because LLVM knows how to optimize them to single instructions + some debugging bookkeeping (which we should also figure out how to eliminate). Add FileCheck tests that ensure that we get optimal -O codegen and near-optimal -Onone codegen.
I had hoped that swiftlang#54445 would unblock these, but it doesn't seem to quite be the complete story yet (or at least, these were still failing as implemented).
@stephentyrone stephentyrone force-pushed the expand-concrete-simd branch from 0cf3d34 to 7a00619 Compare May 25, 2025 20:08
@stephentyrone
Copy link
Contributor Author

@swift-ci test

We drop the _ on Linux, so keep just the Swift mangling part.
@stephentyrone
Copy link
Contributor Author

@swift-ci smoke test

@stephentyrone
Copy link
Contributor Author

@swift-ci smoke test

Copy link
Member

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

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

build system changes look good to me.

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

Build changes LGTM too

@stephentyrone stephentyrone merged commit 592d72b into swiftlang:main May 27, 2025
3 checks passed
kovdan01 added a commit to kovdan01/swift that referenced this pull request May 30, 2025
The PR swiftlang#81766 introduced some concrete SIMD operations, but
`init(repeating:)` was temporarily disabled due to differentiation
testing break. See:

stephentyrone@7a00619

This PR contains two changes:

1. Define custom derivatives for concrete `init(repeating:)` so we do
   not fall into non-differentiability error diagnostic.

2. Add a fix to SIL linker so differentiability witness lookup is done
   when the original function has both `@_alwaysEmitIntoClient` and
   `@_transparent`. Similar changes were introduced previously in
   swiftlang#78908, but they only handled `@_alwaysEmitIntoClient` without
   `@_transparent`.
kovdan01 added a commit to kovdan01/swift that referenced this pull request May 30, 2025
The PR swiftlang#81766 introduced some concrete SIMD operations, but
`init(repeating:)` was temporarily disabled due to differentiation
testing break. See:

stephentyrone@7a00619

This PR contains two changes:

1. Define custom derivatives for concrete `init(repeating:)` so we do
   not fall into non-differentiability error diagnostic.

2. Add a fix to SIL linker so differentiability witness lookup is done
   when the original function has both `@_alwaysEmitIntoClient` and
   `@_transparent`. Similar changes were introduced previously in
   swiftlang#78908, but they only handled `@_alwaysEmitIntoClient` without
   `@_transparent`.
stephentyrone pushed a commit that referenced this pull request May 31, 2025
The PR #81766 introduced some concrete SIMD operations, but
`init(repeating:)` was temporarily disabled due to differentiation
testing break. See:


stephentyrone@7a00619

This PR contains two changes:

1. Define custom derivatives for concrete `init(repeating:)` so we do
not fall into non-differentiability error diagnostic.

2. Add a fix to SIL linker so differentiability witness lookup is done
when the original function has both `@_alwaysEmitIntoClient` and
`@_transparent`. Similar changes were introduced previously in #78908,
but they only handled `@_alwaysEmitIntoClient` without `@_transparent`.

<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants