Skip to content

Validate store-coalescing constants before modifying IR - #133976

Open
tannergooding wants to merge 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-store-coalescing
Open

tannergooding wants to merge 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-store-coalescing

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Fixes #133746.

LowerStoreCoalescing removed the previous store and widened the current store before checking whether their constants could be combined. If constant extraction failed, lowering returned with the transformation only partially applied: the earlier bytes were lost and a narrow constant could be stored at the widened size without masking.

Move scalar constant extraction and SIMD constant validation ahead of IR mutation. Unsupported combinations retain their original stores; supported combinations retain the existing packing and atomicity handling. This fixes the rejection path rather than special-casing CreateScalar or disabling coalescing.

Add regressions for a narrow write over a Vector2 constant and signed Vector64.CreateScalar values, with normal and hardware-intrinsics-disabled configurations. On Windows x64, the Vector2 case reproduces the same invalid byte-to-long widening and fails against the baseline JIT; both variants pass with the fix. The exact reported CreateScalar failure did not reproduce on this host.

Validation: checked Windows x64 CoreCLR, fixed JIT and cross-target JIT builds; both regression variants, AVX2-disabled execution, and 16 existing struct-promotion tests. Four existing coalescing-related methods have identical normalized disassembly before and after the fix (27, 55, 19, and 21 bytes respectively). JIT formatting passed. ARM64 execution was not performed.

Note

This PR description was drafted by GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 15, 2026 18:10
@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 15, 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

🟡 Changes recommended

Add the required SDK configuration so the no-HW regression builds and runs.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Fixes JIT store-coalescing corruption by validating constants before mutating IR.

Changes:

  • Moves scalar and SIMD validation ahead of store rewriting.
  • Adds Vector2 and Vector64.CreateScalar regression coverage.
  • Adds a hardware-intrinsics-disabled test variant.
File Summary
src/​tests/​JIT/​Regression_2/​Runtime_133746/​Runtime_133746.csproj Configures the primary regression test.
src/​tests/​JIT/​Regression_2/​Runtime_133746/​Runtime_133746.cs Adds regression coverage for affected vector cases.
src/​tests/​JIT/​Regression_2/​Runtime_133746/​Runtime_133746_nohw.csproj Critical: lacks the root SDK configuration, so the no-HW regression cannot run.
src/​coreclr/​jit/​lower.cpp Validates constants before store removal and widening.

@@ -0,0 +1,6 @@
<Project>
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.

Bad lowering of CreateScalar when EnableHWIntrinsic=0

2 participants