Skip to content

Track bool-returning and scalar-T-returning HW intrinsics via flags#128848

Open
Copilot wants to merge 5 commits into
mainfrom
copilot/track-bool-returning-intrinsics
Open

Track bool-returning and scalar-T-returning HW intrinsics via flags#128848
Copilot wants to merge 5 commits into
mainfrom
copilot/track-bool-returning-intrinsics

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 1, 2026

Several hardware intrinsics are known to return bool or a scalar T, but consumers (assertionprop, rangecheck, valuenum) tracked them via long ID switches that had to be kept in sync. Replace those with flags on the intrinsic table queryable through HWIntrinsicInfo.

hwintrinsic.h

  • Widen HWIntrinsicFlag to uint64_t (arm64 was out of bits in the 32-bit space).
  • Add HW_Flag_ReturnsBoolean and HW_Flag_ReturnsScalarT as common flags.
  • Add HWIntrinsicInfo::ReturnsBoolean / ReturnsScalarT static APIs, grouped after ReturnsPerElementMask.

hwintrinsiclist*.h

Tag the entries previously enumerated in the consumer switches (skipping HW_Flag_InvalidNodeId entries per the issue):

  • xarch: 24 ReturnsBoolean (Vector{128,256,512}_op_{Equality,Inequality}, X86Base.CompareScalar{Ordered,Unordered}*, X86Base/AVX Test{C,Z,NotZAndNotC}) and 8 ReturnsScalarT (Vector{128,256,512}.{GetElement,ToScalar}, X86Base[_X64].Extract).
  • arm64: 4 ReturnsBoolean (Vector{64,128}_op_{Equality,Inequality}) and 5 ReturnsScalarT (Vector{64,128}.{GetElement,ToScalar}, AdvSimd.Extract).

Consumer refactors

assertionprop.cpp, rangecheck.cpp, and valuenum.cpp no longer enumerate intrinsic IDs in their GT_HWINTRINSIC / VNF_HWI_* switches. A flag check runs before the remaining switch and preserves prior semantics, e.g.:

if (HWIntrinsicInfo::ReturnsBoolean(id))
{
    rangeType = TYP_INT;
    range     = Range(Limit(Limit::keConstant, 0), Limit(Limit::keConstant, 1));
    break;
}
if (HWIntrinsicInfo::ReturnsScalarT(id) && varTypeIsSmall(simdBaseType))
{
    rangeType = simdBaseType;
    break;
}

For IsVNNeverNegative the scalar-T path keeps its base-type guard (only TYP_UBYTE/TYP_USHORT continue), matching the previous case-by-case behavior. The HW intrinsic checks in IsVNNeverNegative and rangecheck.cpp now use IsVNHWIntrinsicFunc, eliminating the manual VNF_HWI_FIRST/VNF_HWI_LAST range check, the explicit NamedIntrinsic cast, the separate GetVNHWIntrinsicSizeAndBaseType call. Both IsVNHWIntrinsicFunc blocks are correctly wrapped in #if defined(FEATURE_HW_INTRINSICS) / #endif guards.

SVE bool/scalar-T intrinsics are intentionally not tagged here — they were never in the original switches and remain covered by the existing TODO-SVE notes.

Copilot AI review requested due to automatic review settings June 1, 2026 14:08
Copilot AI review requested due to automatic review settings June 1, 2026 14:08
Copilot AI linked an issue Jun 1, 2026 that may be closed by this pull request
Co-authored-by: tannergooding <10487869+tannergooding@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 1, 2026 14:25
@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 1, 2026
Copilot AI changed the title [WIP] Add HWIntrinsicFlags for bool and scalar T tracking Track bool-returning and scalar-T-returning HW intrinsics via flags Jun 1, 2026
Copilot AI requested a review from tannergooding June 1, 2026 14:30
@tannergooding tannergooding marked this pull request as ready for review June 1, 2026 14:41
Copilot AI review requested due to automatic review settings June 1, 2026 14:41
@tannergooding
Copy link
Copy Markdown
Member

CC. @EgorBo, the downside of this is that we were out of flag space and so it extends it up to uint64_t.

I think there's likely cleanup possible and we can free up space, but I expect that's more involved and requires careful thought.

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 centralizes knowledge about certain hardware intrinsics that return either a boolean (conceptually TYP_INT in range [0, 1]) or a scalar of the SIMD base type, by encoding that information as flags in the HW intrinsic table and switching consumers over to flag queries.

Changes:

  • Widen HWIntrinsicFlag to uint64_t and add common flags for ReturnsBoolean and ReturnsScalarT, exposed via HWIntrinsicInfo.
  • Tag relevant xarch/arm64 intrinsic table entries with the new return-shape flags.
  • Refactor assertionprop.cpp, rangecheck.cpp, and valuenum.cpp to query HWIntrinsicInfo::{ReturnsBoolean,ReturnsScalarT} instead of maintaining long intrinsic-ID switches.

Reviewed changes

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

Show a summary per file
File Description
src/coreclr/jit/valuenum.cpp Uses HW intrinsic return-shape flags to simplify IsVNNeverNegative handling for HWI VNs.
src/coreclr/jit/rangecheck.cpp Uses HW intrinsic return-shape flags to derive ranges for HWI VNs without ID enumeration.
src/coreclr/jit/assertionprop.cpp Uses HW intrinsic return-shape flags to derive symbolic integer ranges for GT_HWINTRINSIC.
src/coreclr/jit/hwintrinsiclistxarch.h Tags xarch intrinsics (equality/test/compare, GetElement/ToScalar/Extract) with new return-shape flags.
src/coreclr/jit/hwintrinsiclistarm64.h Tags arm64 intrinsics (equality, GetElement/ToScalar/Extract) with new return-shape flags.
src/coreclr/jit/hwintrinsic.h Widens flag type and adds ReturnsBoolean / ReturnsScalarT APIs on HWIntrinsicInfo.

Comment thread src/coreclr/jit/valuenum.cpp Outdated
Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Copilot finished work on behalf of EgorBo June 1, 2026 19:10
Copilot AI requested a review from EgorBo June 1, 2026 19:10
Comment thread src/coreclr/jit/rangecheck.cpp Outdated
…heck

Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 1, 2026 19:29
Copilot finished work on behalf of EgorBo June 1, 2026 19:30
Copilot AI requested a review from EgorBo June 1, 2026 19:30
}

#if defined(TARGET_XARCH)
case VNF_HWI_AVX2_LeadingZeroCount:
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.

@EgorBo do you think it's worth handling these other VNF_HWI_* cases under the IsVNHWIntrinsicFunc path, seeing as they can only trigger for that anyways?

Probably doesn't make a big difference here, but at least keeps the hwintrinsic code grouped and the main switch case smaller?

No strong opinion, just something that is possible now that we have such an explicit check for the other hwintrinsic handling.

Comment thread src/coreclr/jit/rangecheck.cpp
…unc blocks

Co-authored-by: tannergooding <10487869+tannergooding@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 2, 2026 00:07
Copilot AI requested a review from tannergooding June 2, 2026 00:08
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.

Track bool returning intrinsics via a flag

4 participants