Repository navigation
Fix optimizations of explicitly rounded hardware intrinsics - #133541
Merged
tannergooding merged 1 commit intoSep 10, 2026
Merged
tannergooding merged 1 commit into
tannergooding merged 1 commit into
Conversation
Co-authored-by: Copilot App <[email protected]>
|
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. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
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
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
src/tests/JIT/HardwareIntrinsics/X86_Avx512/Avx512F/EmbeddedRounding.Double.cs — Consider adding AggressiveOptimization here as well so the JIT is encouraged to apply the… |
|
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)
EgorBo
approved these changes
Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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
ToEvenarithmetic and FMA. Add focused regression coverage for both issues.Fixes #133519
Note
This PR was prepared with GitHub Copilot.