Skip to content

JIT: LowerHWIntrinsicCmpOp passes the wrong base type to TryInvertMask #130844

Closed

Description

@tannergooding

When lowering a vector equality/inequality comparison, LowerHWIntrinsicCmpOp calls TryInvertMask(maskNode, simdSize, simdBaseType). It passes the node's simdBaseType, but the mask's own base type (maskBaseType) can legitimately differ -- e.g. an op_Equality declared TYP_INT over a mask whose underlying element type is TYP_DOUBLE. The block comment right above already documents that these can differ.

TryInvertMask uses its base-type parameter in the constant-mask branch (node->IsCnsMsk()) to compute elemCount = simdSize / genTypeSize(base) and then GetBitMask(elemCount). When the types differ the inverted constant mask ends up with the wrong number of valid bits (e.g. GetBitMask(4) = 0xF instead of 0x3), producing spurious high bits and a wrong KORTEST result.

Every other consumer in that block uses maskBaseType (the element count, and the NotMask/ShiftLeftMask/ShiftRightMask fallback), so the TryInvertMask call should as well.

Only reachable on AVX512 (EVEX mask + KORTEST) and only in the IsCnsMsk() const-mask branch.

Note

This issue was authored with the assistance of GitHub Copilot.

Activity

  1. added
    untriaged
    on Jul 16, 2026
  2. added
    area-CodeGen-coreclr
    on Jul 16, 2026
  3. dotnet-policy-service commented on Jul 16, 2026

    @dotnet-policy-service
    Contributor

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

  4. added this to the 11.0.0 milestone on Jul 16, 2026
  5. removed
    untriaged
    on Jul 16, 2026
  6. added a commit that references this issue on Jul 20, 2026
    c74f3fb
  7. locked and limited conversation to collaborators on Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions