Skip to content

Improve handling of VNF_Cast in GetRangeFromAssertionsWorker#128923

Draft
tannergooding wants to merge 1 commit into
dotnet:mainfrom
tannergooding:better-castcheck
Draft

Improve handling of VNF_Cast in GetRangeFromAssertionsWorker#128923
tannergooding wants to merge 1 commit into
dotnet:mainfrom
tannergooding:better-castcheck

Conversation

@tannergooding
Copy link
Copy Markdown
Member

This is a smaller change from #128906 that doesn't involve more complex handling around TYP_LONG

Copilot AI review requested due to automatic review settings June 2, 2026 23:32
@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 Jun 2, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
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 adjusts JIT range inference to better reason about VNF_Cast in RangeCheck::GetRangeFromAssertionsWorker, and updates value-number constant extraction to use a 64-bit intermediate when checking whether an integral VN constant fits in a requested target type.

Changes:

  • ValueNumStore::IsVNIntegralConstant now coerces constants to int64_t before applying FitsIn<T>, avoiding width-related truncation issues.
  • GetRangeFromAssertionsWorker refines how it selects an initial range for VNF_Cast by distinguishing widening vs. narrowing/same-size casts.
  • GetRangeFromAssertionsWorker adds an IsVNConstant fast-path for constants (but currently risks returning a non-constant range in a code path that is expected to produce constant ranges).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/valuenum.h Uses a 64-bit coerced constant (int64_t) when probing whether an integral VN constant fits in a requested type.
src/coreclr/jit/rangecheck.cpp Improves VNF_Cast range selection (widening vs. narrowing) and adjusts constant handling in GetRangeFromAssertionsWorker.

Comment thread src/coreclr/jit/rangecheck.cpp Outdated
Comment on lines +713 to +726
// If it's a constant, it's already as tight as it can get.
int cns;
if (comp->vnStore->IsVNIntegralConstant(num, &cns))
if (comp->vnStore->IsVNConstant(num))
{
return Range(Limit(Limit::keConstant, cns));
int cns;
if (comp->vnStore->IsVNIntegralConstant(num, &cns))
{
return Range(Limit(Limit::keConstant, cns));
}
else
{
// TODO: We could return `0, keUnknown` if the constant is known positive
// but this would require more handling in other places to take advantage of.
return Limit(Limit::keUnknown);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

2 participants