[release/10.0] JIT: Use native sized indices in the backend for GetElement and WithElement#119172
Conversation
There was a problem hiding this comment.
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
NormalizeIndexToNativeSizedfunction to convert indices to native-sized integers - Applied index normalization in
GetElementandWithElementoperations 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 |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
jeffschwMSFT
left a comment
There was a problem hiding this comment.
approved. we can merge when ready
Backport of #118990 to release/10.0
Customer Impact
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
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