Skip to content

Revert "Vector128.WithElement codegen regression in .NET 9.0 #115645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 17, 2025

Conversation

jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented May 16, 2025

Fix #115532
Fix #115487
Fix #115459
Fix #115644
Unfix #108197

@Copilot Copilot AI review requested due to automatic review settings May 16, 2025 09:14
@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 May 16, 2025
Copy link
Contributor

@Copilot 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 reverts a prior change in the code generation for the Vector128.WithElement intrinsic to address several reported regressions. It enforces that the second operand is constant, removes obsolete fallback paths, and adjusts intrinsic lowering and node creation accordingly.

  • Enforces op2 to be constant in lowerings and node creation
  • Removes legacy software fallback code for non-constant index handling
  • Updates intrinsic handling for various vector sizes under different targets

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/rationalize.cpp Adds a new case for Vector*_WithElement with constant operand checks
src/coreclr/jit/lowerxarch.cpp Replaces non-constant branch with an assert to enforce op2 constant
src/coreclr/jit/hwintrinsicxarch.cpp Adds handling for non-const index in a late-stage rewriting when optimizations apply
src/coreclr/jit/hwintrinsiccodegenxarch.cpp Removes the old codegen fallback for non-constant indices
src/coreclr/jit/gentree.cpp Introduces assertions and range checks assuming op2 is a constant
Comments suppressed due to low confidence (2)

src/coreclr/jit/lowerxarch.cpp:5661

  • The assertion here enforces that op2 must be constant, which is critical for WithElement intrinsic handling. Consider adding explicit handling or validation for non-constant op2 in release builds to avoid unexpected behavior.
assert(op2->OperIsConst());

src/coreclr/jit/gentree.cpp:27870

  • This assert depends on op2 being a constant immediate value. Please verify that all upstream transformations guarantee this invariant to prevent potential issues in release builds.
assert(op2->IsCnsIntOrI());

@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib @kendall1997

Sorry @kendall1997, but I think for now it is best if we revert the change. Can you please investigate the failures and resubmit the change once fixed?

Copy link
Contributor

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

@jakobbotsch jakobbotsch requested a review from a team May 16, 2025 09:17
@tannergooding
Copy link
Member

@jakobbotsch, I'm fine with this being reverted; however, it looks like these comes down to 2 very simple issues so it might be worth just resolving them. Worst case the PR can go right back up with the fixes and additional tests

#115532 is because we're missing the equivalent to this logic from LowerHWIntrinsicGetElement: https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/lowerxarch.cpp#L5349-L5352. It should also exist in LowerHWIntrinsicWithElement here: https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/lowerxarch.cpp#L5670-L5671. The general premise is that we insert a bounds check node for anything out of range but since we now carry these nodes all the way through to codegen to support non-constants, we can encounter something which became constant but was definitely out of range and which wasn't removed as dead code. Normalizing the imm8 to always be in range in lowering then avoids this issue and won't execute due to the bounds check failing.

#115487, #115459, and #115644 are because the following logic is using ins_Move_Extend when it should be using ins_Store instead: https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/hwintrinsiccodegenxarch.cpp#L2008

@tannergooding
Copy link
Member

I have a fix up for those issues here: #115648

@jakobbotsch
Copy link
Member Author

@tannergooding It's great if you have an actual fix. I was mainly interested in resolving the blocked CI the quickest way possible.

@tannergooding
Copy link
Member

I ended up finding some issues with Mono not handling this scenario as well. Working through fixing those but going to merge this to unblock CI and will update my pr to include the WithElement improvement again

@tannergooding tannergooding merged commit 2fbc9e9 into dotnet:main May 17, 2025
110 checks passed
@jakobbotsch jakobbotsch deleted the revert-115348 branch May 17, 2025 18:07
tannergooding added a commit to tannergooding/runtime that referenced this pull request May 18, 2025
tannergooding added a commit that referenced this pull request May 19, 2025
* Reapply "Vector128.WithElement codegen regression in .NET 9.0 (#115645)"

This reverts commit 2fbc9e9.

* Ensure that WithElement always uses an in range constant during codegen

* Ensure WithElement picks a valid store instruction

* Apply suggestions from code review

* Ensure that Mono doesn't assert for bounds checked indices

* Ensure that WithElement restricts itself to allByteRegs if the base type is byte or sbyte
@github-actions github-actions bot locked and limited conversation to collaborators Jun 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.