Skip to content

Conversation

@jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Aug 28, 2025

Backport of #118990 to release/10.0

Customer Impact

  • Customer reported
  • Found internally

Potential bad codegen for methods that involve indexing SIMD vectors with non-constant indices. The JIT backend assumes a 64-bit normalized index while the JIT frontend leaves a 32-bit index. If the upper bits of the register containing the index end up being non-zero, then memory corruption or segfaults/AVs can occur.

Regression

  • Yes
  • No

Testing

Manual inspection of codegen of the method reported in #118974. Automatic testing of this problem is hard as the register containing the index almost always ends up normalized on x64 and arm64.

Risk

Low

Copilot AI review requested due to automatic review settings August 28, 2025 10:59
Copy link
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 backports a fix from #118990 to ensure that SIMD vector indices are properly normalized to native-sized integers in the JIT backend. The issue occurs when the JIT frontend leaves 32-bit indices while the backend assumes 64-bit normalized indices, potentially causing memory corruption or segfaults if the upper bits of the index register are non-zero.

Key changes:

  • Added NormalizeIndexToNativeSized function to convert indices to native-sized integers
  • Applied index normalization in GetElement and WithElement operations across x86/x64 and ARM architectures
  • Added assertions to verify proper index types in code generation

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/coreclr/jit/lower.h Added declaration for NormalizeIndexToNativeSized function
src/coreclr/jit/lower.cpp Implemented NormalizeIndexToNativeSized function to cast or convert indices to native size
src/coreclr/jit/lowerxarch.cpp Applied index normalization in x86/x64 GetElement and WithElement intrinsics
src/coreclr/jit/lowerarmarch.cpp Applied index normalization in ARM GetElement intrinsic
src/coreclr/jit/hwintrinsiccodegenxarch.cpp Added assertions to verify indices are native-sized during code generation

@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 Aug 28, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@jeffschwMSFT jeffschwMSFT left a comment

Choose a reason for hiding this comment

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

approved. we can merge when ready

@jeffschwMSFT jeffschwMSFT added the Servicing-approved Approved for servicing release label Aug 28, 2025
@jeffschwMSFT jeffschwMSFT added this to the 10.0.0 milestone Aug 28, 2025
@jeffschwMSFT jeffschwMSFT merged commit 1151a7b into dotnet:release/10.0 Aug 28, 2025
102 of 104 checks passed
@jakobbotsch jakobbotsch deleted the fix-118974-10.0 branch August 28, 2025 14:53
@github-actions github-actions bot locked and limited conversation to collaborators Sep 28, 2025
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 Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants