Skip to content

Fix optimizations of explicitly rounded hardware intrinsics - #133541

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-rounded-simd-negation
Sep 10, 2026
Merged

tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-rounded-simd-negation

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Skip morph simplifications that move negation through an explicitly rounded multiply/divide or replace a rounded multiply with an operation that drops its rounding mode.

Also keep explicit-rounding nodes out of ordinary lowering and containment, which expect no rounding operand. This fixes operand-count assertions for ToEven arithmetic and FMA. Add focused regression coverage for both issues.

Fixes #133519

Note

This PR was prepared with GitHub Copilot.

Copilot AI lite review requested due to automatic review settings September 9, 2026 22:13
@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.

@tannergooding
tannergooding requested a review from EgorBo September 9, 2026 22:15

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 morph/lowering semantics for hardware intrinsics, so a human review is needed to validate correctness and any potential codegen/perf side effects across the full intrinsic set.

Review tier: Lite
Findings: 2 Medium severity

New issues introduced by this change (2)
Severity Finding
Medium severity src/​tests/​JIT/​HardwareIntrinsics/​X86_Avx512/​Avx512F/​EmbeddedRounding.Double.cs — Consider adding AggressiveOptimization here as well so the JIT is encouraged to apply the…
Medium severity src/​tests/​JIT/​HardwareIntrinsics/​X86_Avx512/​Avx512F/​EmbeddedRounding.Single.cs — These new regression tests rely on JIT morph optimizations (e.g., moving negation / multiply-to-add…
What changed in this PR

This PR adjusts CoreCLR JIT optimization and lowering behavior for AVX-512 embedded-rounding intrinsics so that explicitly specified rounding modes aren’t lost or mis-handled by generic SIMD transforms, and adds regression coverage for the affected scenarios.

Changes:

  • Prevent certain morph simplifications (e.g., multiply-to-add and pushing negation through mul/div) from applying when the HWIntrinsic has an explicit rounding operand.
  • Ensure embedded-rounding intrinsics bypass ordinary lowering/containment paths that assume the “normal” operand count.
  • Add focused AVX-512F embedded-rounding tests for negation, constant-multiply rewrite, and ToEven/FMA paths.
File Description
src/​tests/​JIT/​HardwareIntrinsics/​X86_Avx512/​Avx512F/​EmbeddedRounding.Single.cs Adds Single-precision regression tests covering negation + explicit rounding, multiply-by-2 rewrite with explicit rounding, and ToEven/FMA operand-count paths.
src/​tests/​JIT/​HardwareIntrinsics/​X86_Avx512/​Avx512F/​EmbeddedRounding.Double.cs Adds Double-precision regression test covering negation + explicit rounding.
src/​coreclr/​jit/​morph.cpp Gates constant-multiply and negation-through-mul/div simplifications on the intrinsic having the ordinary operand count (avoids dropping explicit rounding).
src/​coreclr/​jit/​lowerxarch.cpp Ensures embedded-rounding intrinsics skip regular lowering/containment that assumes no rounding-mode operand.
Suppressed comments (1)

src/tests/JIT/HardwareIntrinsics/X86_Avx512/Avx512F/EmbeddedRounding.Single.cs:30

  • Same as above: this test is intended to catch a multiply-to-add rewrite that would drop the explicit rounding mode. Adding AggressiveOptimization makes it more likely the relevant optimization runs in all expected test configurations.
        [ConditionalTheory(typeof(Avx512F), nameof(Avx512F.IsSupported))]
        [InlineData(float.MaxValue)]
        [MethodImpl(MethodImplOptions.NoInlining)]
        public static void MultiplyConstantEmbeddedRounding_Single(float scalar)

@tannergooding
tannergooding merged commit fb99e10 into dotnet:main Sep 10, 2026
143 of 144 checks passed
@tannergooding
tannergooding deleted the tannergooding-fix-rounded-simd-negation branch September 10, 2026 15:09
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 14, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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) negating an AVX-512 multiply changes its explicit rounding mode

3 participants