Skip to content

Conversation

jakobbotsch
Copy link
Member

Fix #118566

@Copilot Copilot AI review requested due to automatic review settings August 11, 2025 16:50
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 fixes a bug in the JIT's optimization of integral casts for returned fields by adding an additional constraint to ensure the source type is also an integral register type.

  • Adds a check to verify that the cast source type (CastFromType()) uses an integral register before optimizing out the cast
  • This prevents incorrect optimization when casting from non-integral types (like floating-point) to integral types
Comments suppressed due to low confidence (1)

src/coreclr/jit/lower.cpp:5323

  • [nitpick] The fix appears correct but the condition order could be more efficient. Consider moving varTypeUsesIntReg(node->CastFromType()) before the size comparison since type checks are typically faster than size calculations and can short-circuit the evaluation earlier.
                   varTypeUsesIntReg(node->CastFromType()) && (genTypeSize(regType) <= genTypeSize(node->CastToType())))

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Aug 11, 2025

cc @dotnet/jit-contrib PTAL @EgorBo

Regression introduced by #118345.

@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 11, 2025
@jakobbotsch jakobbotsch requested a review from EgorBo August 11, 2025 16:50
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

@EgorBo EgorBo left a comment

Choose a reason for hiding this comment

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

Just curious - is this some recent regression? Ah, I see the link

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test failure: JIT/Directed/callconv/ThisCall/ThisCallTest/ThisCallTest.cmd
2 participants