Skip to content

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

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:computerange-calls-fromassertprop
Jun 3, 2026
Merged

Have ComputeRange call into GetRangeFromAssertions for non dependent/symbolic cases#128922
tannergooding merged 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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Wouldn’t that be handled by the cast?

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 meant I don't see what we can possibly do for a LONG that doesn't fit into INT here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's the same consideration as for TYP_INT.

Which is that the MSB is never set for this target format and so therefore shifts, mods, and various other operations can be optimized as the unsigned variants.

If we cast from TYP_LONG to TYP_INT and the value is unknown, then the cast result might be negative, in the same way that TYP_INT -> TYP_BYTE might produce a negative result, and so the same optimizations on the cast result are then not possible.

Comment thread src/coreclr/jit/rangecheck.cpp
@tannergooding tannergooding merged commit 3752108 into dotnet:main Jun 3, 2026
137 of 139 checks passed
@tannergooding tannergooding deleted the computerange-calls-fromassertprop branch June 3, 2026 13:30
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