Skip to content

Preserve scalar negation types when folding FMA operands - #134522

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-arm64-fma-folding
Sep 24, 2026
Merged

tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-arm64-fma-folding

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Require the scalar GT_NEG type to match the FMA element type before folding it into a negated FMA variant on ARM64 and xarch.

Vector bit reinterprets can expose integer negation or a different floating-point width to these folds. Integer negation is not a floating-point sign change, and double negation does not change the sign of a float in the low 32 bits. Preserve those operations while retaining same-type fusion, without changing operand evaluation order.

Add focused regressions for both mismatch classes and the analogous xarch path, plus same-type finite and signed-zero controls.

Validation:

  • Built Checked ARM64 and x64 JITs and both regression runners. The x64 repro fails with the unfixed JIT; all three applicable cases pass with the fix and under JitStress=2.
  • ARM64 cross-codegen retains the integer neg or double fneg before fmadd for the repros. Same-type control disassembly is unchanged. Native ARM64 execution was unavailable.
  • Windows x64 JIT formatting check passed.

Resolves #134053

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:57
@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

Cross-architecture JIT lowering changes warrant final human review.

Review effort: Lite
Findings: None

What changed in this PR

Fixes incorrect FMA negation folding across scalar type reinterprets on ARM64 and xarch.

Changes:

  • Require matching scalar and FMA element types before negation folding.
  • Add regressions for mismatched, same-type, and signed-zero cases.
File Description
src/​tests/​JIT/​Regression_ro_2/​Runtime_134053.cs Adds focused regression tests and controls.
src/​coreclr/​jit/​lowerxarch.cpp Restricts scalar negation folding by type.
src/​coreclr/​jit/​lowerarmarch.cpp Applies the matching-type safeguard on ARM64.

@tannergooding
tannergooding merged commit fccfbba into dotnet:main Sep 24, 2026
143 of 146 checks passed
@tannergooding
tannergooding deleted the tannergooding-fix-arm64-fma-folding branch September 24, 2026 12:36
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 25, 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) [ARM64] FusedMultiplyAddScalar folds an unrelated GT_NEG through a bit-reinterpret, producing wrong results

3 participants