Fix SIMD primitive zero initialization - #133100
Conversation
Ensure block morphing replaces the integer zero source with the newly created SIMD zero node. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
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. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The fix is a minimal, localized correctness change (updating the store operand to match the new SIMD zero node) with targeted regression coverage added.
Review tier: Lite
Findings: None
What changed in this PR
This PR fixes a CoreCLR JIT morphing bug where TryPrimitiveInit could retarget an init-block into a SIMD-typed store but leave the store’s Data() operand pointing at the original integer zero constant, producing an invalid SIMD store source and causing Tier0/FullOpts failures. The change updates the rationalized store node to use the newly created SIMD zero constant and adds a JIT regression test covering Vector128 and Vector256 under both Tier0 and FullOpts behavior.
Changes:
- Fix
MorphInitBlockHelper::TryPrimitiveInitto replace the store’sData()operand when creating a SIMD zero source. - Mark the newly created SIMD zero node as morphed to match surrounding morph-phase conventions.
- Add a JitBlue regression test project validating
Vector128<ulong>andVector256<ulong>zero-init throughUnsafe.As<,>()under tiered compilation.
| File | Description |
|---|---|
| src/coreclr/jit/morphblock.cpp | Updates primitive-init morphing to keep store Data() consistent with a newly created SIMD zero node. |
| src/tests/JIT/Regression/JitBlue/Runtime_133085/Runtime_133085.csproj | Adds a new isolated JIT regression test project with tiered compilation enabled. |
| src/tests/JIT/Regression/JitBlue/Runtime_133085/Runtime_133085.cs | Adds regression coverage for SIMD local zero-init via initobj-equivalent patterns for Vector128/256. |
|
CC. @EgorBo, @jakobbotsch for review. This will need backport to .NET 11 and 10 Fairly old issue and it likely hasn't been hit before due to the exact pattern required to trigger it being a bit unlikely. |
|
/ba-g unrelated quic failure |
|
/backport to release/11.0 |
|
/backport to release/10.0 |
|
Started backporting to |
|
Started backporting to |
|
@tannergooding backporting to git am output$ git cherry-pick f0b01ad7f0e01b4ac9f731eefe61213ec0278533
Auto-merging src/coreclr/jit/morphblock.cpp
CONFLICT (content): Merge conflict in src/coreclr/jit/morphblock.cpp
error: could not apply f0b01ad7f0e... Fix SIMD primitive zero initialization (#133100)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix SIMD primitive zero initialization
Using index info to reconstruct a base tree...
M src/coreclr/jit/morphblock.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/jit/morphblock.cpp
CONFLICT (content): Merge conflict in src/coreclr/jit/morphblock.cpp
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fix SIMD primitive zero initialization
Error: The process '/usr/bin/git' failed with exit code 128 |
Backport of #133100 to release/10.0 /cc @tannergooding ## Customer Impact - [x] Customer reported - [ ] Found internally Reported in #133085. Zero-initializing a struct through a byref that the JIT can see is the address of a `Vector128<T>`/`Vector256<T>` local (`Unsafe.As<Vector256<ulong>, S>(ref v) = default;`) produces a SIMD store whose source is an integer zero constant. With optimizations that lowers to `vmovq ymm0, rax` (`C4 E1 FD 6E C0`), which has no valid VEX.256 encoding, so the process dies with `ExecutionEngineException: Illegal instruction`; at Tier0 the same method fails to compile and throws `InvalidProgramException`. Expected behavior is a SIMD zero (`vxorps`) in both modes. The pattern shows up in code that reinterprets vector locals as multi-limb structs, and there is no compile-time diagnostic — it fails at runtime on any AVX-capable x64 machine. ## Regression - [ ] Yes - [x] No Not a regression in 10.0 — .NET 9 fails the same way. The bad tree dates to the assignment rationalization work in #85585 (`53b4cd0912d`), where the legacy `GT_ASG` path updated `gtOp2` but the rationalized store path never updated `Data()`. ## Testing New regression test `src/tests/JIT/Regression/JitBlue/Runtime_133085`, covering `Vector128<ulong>` and `Vector256<ulong>` in both FullOpts (`AggressiveOptimization`) and Tier0. It reproduces the illegal encoding / `InvalidProgramException` without the fix and passes with it. Missed previously because `TryPrimitiveInit` looked correct in isolation — it built the SIMD zero node and assigned it to `m_src` — and no existing test zero-initialized a SIMD local through a reinterpreted struct view, so nothing exercised the path where the store's data operand still had to be replaced. ## Risk Low. Two lines in `TryPrimitiveInit`, reached only when a block zero-init of a SIMD-typed local is converted into a primitive store. It makes the store's data node match the store's type, which is what the transform already intended; every other case was already consistent. This is a manual backport: the cherry-pick conflicted only because the member is named `m_comp` on release/10.0 rather than `m_compiler`. The change is otherwise identical to #133100. > [!NOTE] > This pull request description was generated with GitHub Copilot. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Backport of #133100 to release/11.0 /cc @tannergooding ## Customer Impact - [x] Customer reported - [ ] Found internally Reported in #133085. Zero-initializing a struct through a byref that the JIT can see is the address of a `Vector128<T>`/`Vector256<T>` local (`Unsafe.As<Vector256<ulong>, S>(ref v) = default;`) produces a SIMD store whose source is an integer zero constant. With optimizations that lowers to `vmovq ymm0, rax` (`C4 E1 FD 6E C0`), which has no valid VEX.256 encoding, so the process dies with `ExecutionEngineException: Illegal instruction`; at Tier0 the same method fails to compile and throws `InvalidProgramException`. Expected behavior is a SIMD zero (`vxorps`) in both modes. The pattern shows up in code that reinterprets vector locals as multi-limb structs, and there is no compile-time diagnostic — it fails at runtime on any AVX-capable x64 machine. ## Regression - [ ] Yes - [x] No Not a regression in 10.0 or 11.0 — .NET 9 fails the same way. The bad tree dates to the assignment rationalization work in #85585 (`53b4cd0912d`), where the legacy `GT_ASG` path updated `gtOp2` but the rationalized store path never updated `Data()`. ## Testing New regression test `src/tests/JIT/Regression/JitBlue/Runtime_133085`, covering `Vector128<ulong>` and `Vector256<ulong>` in both FullOpts (`AggressiveOptimization`) and Tier0. It reproduces the illegal encoding / `InvalidProgramException` without the fix and passes with it. Missed previously because `TryPrimitiveInit` looked correct in isolation — it built the SIMD zero node and assigned it to `m_src` — and no existing test zero-initialized a SIMD local through a reinterpreted struct view, so nothing exercised the path where the store's data operand still had to be replaced. ## Risk Low. Two lines in `TryPrimitiveInit`, reached only when a block zero-init of a SIMD-typed local is converted into a primitive store. It makes the store's data node match the store's type, which is what the transform already intended; every other case was already consistent. > [!NOTE] > This pull request description was generated with GitHub Copilot. Co-authored-by: Tanner Gooding <tagoo@outlook.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
TryPrimitiveInitcreated a SIMD zero node when converting a zero block initialization into a primitive local store, but the rationalized store retained its original integer-zero data node. This produced a SIMD store with an integer source, leading to invalid codegen and Tier0 compilation failures.The missing source replacement was introduced by the assignment rationalization changes in #85585 (
53b4cd0912d), where the legacyGT_ASGpath updatedgtOp2but the rationalized store path did not updateData().Before the fix, the
Vector256case encodedC4 E1 FD 6E C0(vmovqwithVEX.L=1). The corrected tree emits a SIMD zero (vxorps) in both FullOpts and Tier0. Regression coverage includesVector128andVector256in both modes.Fixes #133085
Note
This pull request description was generated with GitHub Copilot.