Skip to content

Fix SIMD complement and scalar FMA folding - #133542

Open
tannergooding wants to merge 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-scalar-simd-complement
Open

Fix SIMD complement and scalar FMA folding#133542
tannergooding wants to merge 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-scalar-simd-complement

Conversation

@tannergooding

@tannergooding tannergooding commented Sep 9, 2026

Copy link
Copy Markdown
Member

Preserve upper lanes when folding scalar SIMD operations: reversing a scalar comparison cannot replace a full-vector complement, and folding a vector negation from scalar FMA's first operand changes its copied upper lanes.

Also use the inverted immediate predicate when folding packed AVX comparison complements. Includes focused regression coverage for both comparison paths and scalar FMA variants.

Fixes #133521
Fixes #133518
Fixes #133553

Note

This PR was prepared with GitHub Copilot.

tannergooding and others added 2 commits September 9, 2026 15:04
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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:14
@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
@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

It changes CoreCLR JIT optimization behavior for SIMD intrinsics, where subtle codegen/semantics regressions are high-impact and should get final human validation across relevant xarch paths.

Review tier: Lite
Findings: None

What changed in this PR

This PR adjusts CoreCLR JIT optimization/folding around SIMD bitwise-complement patterns to preserve scalar-intrinsic upper-lane semantics, and fixes predicate folding for packed AVX comparisons so the complement is not dropped. It adds focused JIT regression tests to lock in the corrected behavior.

Changes:

  • Prevent ~(scalar-compare) from being folded via comparison reversal (since scalar compares copy upper lanes from the first operand).
  • When folding ~Avx.Compare(..., imm8), invert the immediate predicate (and update VN) instead of dropping the NOT without changing the mode.
  • Avoid folding vector-negation from the first operand of scalar FMA (since scalar FMA copies upper lanes from operand 1).
File Description
src/​coreclr/​jit/​morph.cpp Fixes NOT-folding for SIMD compares: blocks scalar-compare reversal and correctly inverts AVX/AVX512 compare immediates.
src/​coreclr/​jit/​lowerxarch.cpp Prevents scalar FMA folding from losing upper-lane negation on operand 1.
src/​tests/​JIT/​Regression/​Regression_ro_2.csproj Adds the new regression test sources to the merged JIT regression project.
src/​tests/​JIT/​Regression/​JitBlue/​Runtime_133518/​Runtime_133518.cs Regression coverage for packed AVX/AVX512 compare complement folding with inverted predicates.
src/​tests/​JIT/​Regression/​JitBlue/​Runtime_133521/​Runtime_133521.cs Regression coverage for scalar compare complement upper-lane preservation and scalar FMA operand-1 negation semantics.

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

2 participants