Skip to content

Preserve element types when folding SIMD Dot broadcasts - #134521

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-simd-dot-folding
Sep 23, 2026
Merged

tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-simd-dot-folding

Conversation

@tannergooding

Copy link
Copy Markdown
Member

The Vector.Create(ToScalar(Dot(...))) fold checked the vector size but not the element type. Reusing a short-lane Dot result as an int broadcast therefore produced 0x00080008 (524296) instead of 8 for the reported all-one inputs.

Require compatible SIMD base types as well as matching vector sizes before folding. Normalize signedness so same-width signed/unsigned broadcasts remain eligible; incompatible types retain the scalar extraction and broadcast. The check runs before rewriting the operands.

Add data-driven regressions for signed and unsigned widening at 128-bit and 64-bit widths, including truncation cases, plus same-type and signedness-only controls.

Validation on Windows x64: Checked JIT and test builds, JIT formatting, and all eight regression cases passed. The same cases passed with AVX2 disabled, hardware intrinsics disabled, and JIT stress 2. Three cases fail against the unfixed JIT. ARM64 execution was not available locally.

Resolves #134479

Note

This PR description was drafted with GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 23, 2026 13:36
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Sep 23, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

JIT and architecture-sensitive changes warrant final human review.

Review effort: Lite
Findings: None

What changed in this PR

Fixes SIMD Dot broadcast folding to preserve element-type compatibility and prevent incorrect lane reinterpretation.

Changes:

  • Validates vector width and compatible SIMD element types before folding.
  • Adds signed/unsigned widening, truncation, and control regressions.
File Summary
src/​tests/​JIT/​Regression_ro_2/​Runtime_134479.cs Adds data-driven regression coverage.
src/​coreclr/​jit/​morph.cpp Validates SIMD element compatibility before folding.

@tannergooding

Copy link
Copy Markdown
Member Author

/ba-g unrelated failures

@tannergooding
tannergooding merged commit be8eaf9 into dotnet:main Sep 23, 2026
144 of 146 checks passed
@tannergooding
tannergooding deleted the tannergooding-fix-simd-dot-folding branch September 23, 2026 19:34
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: (bug) Vector128.Create((int)Vector128.Dot(shortVec, shortVec)) returns the Dot result broadcast as shorts

3 participants