Skip to content

Fix vector complement-add folding for floating-point types - #133539

Merged
tannergooding merged 5 commits into
dotnet:mainfrom
tannergooding:tannergooding-avx-comparison-complement
Sep 11, 2026
Merged

tannergooding merged 5 commits into
dotnet:mainfrom
tannergooding:tannergooding-avx-comparison-complement

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Restrict (~v) + 1 folding to integral SIMD base types. The guard was inverted, incorrectly replacing floating-point complement-and-add with negation while excluding the valid integer transform.

Add a focused regression covering Vector128<float>, Vector128<double>, and Vector128<int>.

Fixes #133522.

Note

This PR was prepared 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 9, 2026 22:08
@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 9, 2026
@tannergooding
tannergooding requested a review from EgorBo September 9, 2026 22:09
@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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

🟢 Approval recommended

The fix is a small, well-scoped correctness change in the JIT morph optimization and is backed by a targeted regression that reproduces the reported incorrect floating-point folding.

Review tier: Lite
Findings: None

What changed in this PR

This PR fixes a JIT HWIntrinsic morph optimization that was incorrectly folding (~v) + 1 into -v for floating-point SIMD vectors (and skipping the intended integral-only transform). It updates the guard to only apply the fold for integral SIMD base types and adds a regression test that validates the floating-point behavior.

Changes:

  • Restrict the (~v) + 1-v folding in fgOptimizeHWIntrinsic to integral SIMD base types.
  • Simplify xarch SetMorphed handling for the newly created negation node in the integral-only path.
  • Add a focused JIT regression test covering Vector128<float>, Vector128<double>, and Vector128<int>.
File Description
src/​coreclr/​jit/​morph.cpp Fixes the folding guard so (~v) + 1 is only rewritten for integral SIMD base types.
src/​tests/​JIT/​Regression/​JitBlue/​Runtime_133522/​Runtime_133522.cs Adds a regression asserting correct floating-point ~v + 1 semantics and a basic integer check.
src/​tests/​JIT/​Regression/​Regression_ro_2.csproj Includes the new regression test in the merged regression project.

Copilot AI review requested due to automatic review settings September 9, 2026 22:17

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

🟢 Approval recommended

The JIT fix is narrowly scoped to the documented invalid fold for floating-point SIMD and is backed by a focused regression test that would fail on the buggy behavior.

Review tier: Lite
Findings: None

tannergooding and others added 2 commits September 10, 2026 08:36
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ions

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 10, 2026 16:10

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

🟢 Approval recommended

The fix is a small, well-scoped correctness change with a targeted regression that matches the reported repro/expected behavior.

Review tier: Lite
Findings: None

…nner

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 11, 2026 02:35
@tannergooding

Copy link
Copy Markdown
Member Author

@EgorBo, same here, resolved merge conflict now that the regression_ro_2.csproj has been fixed to avoid future conflicts. Need reapproval

@tannergooding
tannergooding enabled auto-merge (squash) September 11, 2026 02:38

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

🟢 Approval recommended

The requested fix and regression coverage are complete with no unresolved review issues.

Review tier: Lite
Findings: None

@tannergooding

Copy link
Copy Markdown
Member Author

/ba-g unrelated failures that are also on main

@tannergooding
tannergooding merged commit 05d1319 into dotnet:main Sep 11, 2026
141 of 143 checks passed
@tannergooding
tannergooding deleted the tannergooding-avx-comparison-complement branch September 11, 2026 14:17
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 14, 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) floating-point vector ~v + 1 is folded to -v

3 participants