Skip to content

Have ComputeRange call into GetRangeFromAssertions for non dependent/symbolic cases#128922

Open
tannergooding wants to merge 1 commit into
dotnet:mainfrom
tannergooding:computerange-calls-fromassertprop
Open

Have ComputeRange call into GetRangeFromAssertions for non dependent/symbolic cases#128922
tannergooding wants to merge 1 commit into
dotnet:mainfrom
tannergooding:computerange-calls-fromassertprop

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:17
@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 analysis so RangeCheck::ComputeRange can leverage GetRangeFromAssertions for additional TYP_INT-actual expressions (i.e., cases that aren’t dependent/symbolic/explicitly handled), and improves integral-constant extraction by avoiding ssize_t truncation.

Changes:

  • Update ValueNumStore::IsVNIntegralConstant to coerce constants via int64_t (avoids truncation on 32-bit / for wider constants).
  • Rework RangeCheck::ComputeRange constant handling to use IsVNIntegralConstant.
  • Route remaining genActualType(expr) == TYP_INT cases in ComputeRange through GetRangeFromAssertions (and remove the prior small-type / cast type-based fallbacks).

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 Fix integral constant extraction to use int64_t coercion before FitsIn<T> checks.
src/coreclr/jit/rangecheck.cpp Use IsVNIntegralConstant for constants and call GetRangeFromAssertions for remaining TYP_INT-actual expressions.

Comment thread src/coreclr/jit/rangecheck.cpp
@tannergooding tannergooding force-pushed the computerange-calls-fromassertprop branch from ebb0766 to e41eb09 Compare June 3, 2026 01:14
@tannergooding
Copy link
Copy Markdown
Member Author

diffs most of the TP hit seems to be from this change, but it does get some decent wins.

@tannergooding tannergooding marked this pull request as ready for review June 3, 2026 04:04
Copilot AI review requested due to automatic review settings June 3, 2026 04:04
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

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

{
// 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.
range = Limit(Limit::keUnknown);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we can TBH, a never-negative long that doesn't fit into INT32 can be negative when casted to INT32?

// We want to handle constants first since it can avoid other more expensive work

int cns;
if (m_compiler->vnStore->IsVNIntegralConstant(vn, &cns))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: we do double lookup here: IsVNConstant and then IsVNIntegralConstant

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.

3 participants