Skip to content

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

Open
tannergooding wants to merge 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-avx-comparison-complement
Open

Fix vector complement-add folding for floating-point types#133539
tannergooding wants to merge 2 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

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: floating-point vector ~v + 1 is folded to -v

2 participants