Skip to content

Fix for 127747#128962

Open
dhartglassMSFT wants to merge 4 commits into
dotnet:mainfrom
dhartglassMSFT:127747
Open

Fix for 127747#128962
dhartglassMSFT wants to merge 4 commits into
dotnet:mainfrom
dhartglassMSFT:127747

Conversation

@dhartglassMSFT
Copy link
Copy Markdown
Contributor

@dhartglassMSFT dhartglassMSFT commented Jun 3, 2026

fgOptimizeHWIntrinsic does the following transform (note V09 used before it is defined in the 'After')

Before
\--*  HWINTRINSIC simd16 16 byte Add $441
   +--*  HWINTRINSIC simd16 16 byte Negate $480
   |  \--*  HWINTRINSIC simd16 16 byte ShiftLogicalSaturate $440
   |     +--*  COMMA     simd16 $400
   |     |  +--*  STORE_LCL_VAR simd16 V09 cse1         d:1 $VN.Void
   |     |  |  \--*  CNS_VEC   simd16<0x01010101, 0x01010101, 0x01010101, 0x01010101> $400
   |     |  \--*  LCL_VAR   simd16 V09 cse1         u:1 $400
   |     \--*  CNS_VEC   simd16<0x00000000, 0x00000000, 0x00000000, 0x00000000> $401
   \--*  LCL_VAR   simd16 V09 cse1         u:1 $400
After:
\--*  HWINTRINSIC simd16 16 byte Subtract $441
   +--*  LCL_VAR   simd16 V09 cse1         u:1 $400
   \--*  HWINTRINSIC simd16 16 byte ShiftLogicalSaturate $440
      +--*  COMMA     simd16 $400
      |  +--*  STORE_LCL_VAR simd16 V09 cse1         d:1 $VN.Void
      |  |  \--*  CNS_VEC   simd16<0x01010101, 0x01010101, 0x01010101, 0x01010101> $400
      |  \--*  LCL_VAR   simd16 V09 cse1         u:1 $400
      \--*  CNS_VEC   simd16<0x00000000, 0x00000000, 0x00000000, 0x00000000> $401

fgOptimizeAddition already checks "gtCanSwapOrder" for the transform (ADD(NEG(a), b) => SUB(b, a)) - that check was missing from fgOptimizeHWIntrinsic for an identical transform

fixes #127747
"Assertion failed Write to unaliased local overlaps outstanding read during 'Rationalize IR'"

Copilot AI review requested due to automatic review settings June 3, 2026 21:04
@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 Jun 3, 2026
@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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates CoreCLR JIT morphing (fgOptimizeHWIntrinsic) to avoid performing a HWIntrinsic ADD optimization that would swap operand evaluation order when such swapping is not safe.

Changes:

  • Add a gtCanSwapOrder(op1, op2) guard before rewriting (-v1) + v2 into v2 - v1 for SIMD HWIntrinsics.
  • Bail out of that optimization when swapping could change observable behavior (e.g., due to side effects / ordering constraints).

Comment thread src/coreclr/jit/morph.cpp
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot stopped reviewing on behalf of dhartglassMSFT due to an error June 4, 2026 19:00
@dhartglassMSFT dhartglassMSFT changed the title [DRAFT] Fix for 127747 Fix for 127747 Jun 4, 2026
@dhartglassMSFT
Copy link
Copy Markdown
Contributor Author

An earlier run showed green in all the spmi asmdiff tests

Copilot AI review requested due to automatic review settings June 8, 2026 05:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment on lines +38 to +54
[Fact]
public static void TestEntryPoint()
{
if (!AdvSimd.IsSupported || !Crc32.IsSupported)
{
return;
}

try
{
M0();
}
catch (DivideByZeroException)
{
// Expected from "0 % Crc32.ComputeCrc32(0, 0)".
}
}
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: Assertion failed Write to unaliased local overlaps outstanding read during 'Rationalize IR'

3 participants