Skip to content

JIT: INSERTPS can mark op2 both contained and reg-optional #130846

Closed

Description

@tannergooding

In ContainCheckHWIntrinsic, the NI_X86Base_Insert (INSERTPS, FLOAT) case contains op2 when it is a zero vector -- the zero is fully elided and encoded into the INSERTPS zmask bits of the immediate:

else if (op2->IsVectorZero())
{
    ...
    MakeSrcContained(node, op2);
}

TryMakeSrcContainedOrRegOptional(node, op2);   // runs unconditionally

TryMakeSrcContainedOrRegOptional then runs unconditionally. For a zero CNS_VEC, IsContainableHWIntrinsicOp returns false but first sets *supportsRegOptional = true (a non-LCL_VAR node is safe to mark reg-optional), so MakeSrcRegOptional is called and op2 ends up both contained and reg-optional -- a violated invariant.

The reg-optional flag is inert at runtime here (a contained zero CNS_VEC produces no operand uses, so no default-build assert fires and codegen is unaffected), but the invariant violation should be fixed by guarding the call on !op2->isContained(), matching the symmetric op1->IsVectorZero() branch just above which contains and never retries.

Confirmed via temporary JIT instrumentation (the "contained + reg-optional" state was observed without the guard).

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