Skip to content

Fix incorrect CoercedConstantValue usage in IsVNIntegralConstant#128770

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-coerced-constant-value-usages
Open

Fix incorrect CoercedConstantValue usage in IsVNIntegralConstant#128770
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-coerced-constant-value-usages

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 29, 2026

On 32-bit targets ssize_t is effectively int32_t, so CoercedConstantValue<ssize_t> truncates TYP_LONG values. In IsVNIntegralConstant, this truncation occurs before the FitsIn<T> check, causing arbitrary TYP_LONG constants to be incorrectly reported as fitting into smaller integral types (e.g. int32).

Changes

  • src/coreclr/jit/valuenum.h: read the constant as int64_t instead of ssize_t in IsVNIntegralConstant, preserving the full 64-bit value before the FitsIn<T> check.
// before
ssize_t val = CoercedConstantValue<ssize_t>(vn);
// after
int64_t val = CoercedConstantValue<int64_t>(vn);

TYP_INT constants are sign-extended to int64_t and TYP_LONG constants are preserved without truncation, so FitsIn<T> now evaluates the true value on all architectures.

Copilot AI review requested due to automatic review settings May 29, 2026 14:05
Copilot AI review requested due to automatic review settings May 29, 2026 14:05
Copilot AI linked an issue May 29, 2026 that may be closed by this pull request
Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 29, 2026 14:09
Copilot AI changed the title [WIP] Fix incorrect CoercedConstantValue<ssize_t> usages Fix incorrect CoercedConstantValue usage in IsVNIntegralConstant May 29, 2026
Copilot finished work on behalf of EgorBo May 29, 2026 14:11
Copilot AI requested a review from EgorBo May 29, 2026 14:11
Comment thread src/coreclr/jit/valuenum.h
@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 29, 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.

@EgorBo EgorBo marked this pull request as ready for review May 29, 2026 15:39
Copilot AI review requested due to automatic review settings May 29, 2026 15:39
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 fixes IsVNIntegralConstant so JIT value-number constants are checked for integral fit after preserving the full 64-bit value, avoiding 32-bit host truncation of TYP_LONG constants.

Changes:

  • Reads VN integral constants as int64_t before applying FitsIn<T>.
  • Preserves existing behavior for TYP_INT while correctly rejecting oversized TYP_LONG values.

Comment thread src/coreclr/jit/valuenum.h
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.

Fix incorrect CoercedConstantValue<ssize_t> usages

4 participants