Skip to content

JIT: TryLowerAndOpToExtractLowestSetBit checks the wrong node for GTF_SET_FLAGS #130845

Closed

Description

@tannergooding

TryLowerAndOpToExtractLowestSetBit rewrites X & (-X) into ExtractLowestSetBit (BLSI). Before doing so it must bail if a downstream consumer relies on the CPU flags produced by the node being removed, because AND and BLSI set the flags differently.

The guard tests opNode (the surviving leaf operand) instead of andNode (the GT_AND root that is actually removed and replaced):

if (((opNode->gtFlags & GTF_SET_FLAGS) != 0) || ((negNode->gtFlags & GTF_SET_FLAGS) != 0))
    return nullptr;

opNode is a dead/irrelevant check here; the flags that matter belong to andNode. The sibling helper TryLowerAndOpToResetLowestSetBit correctly checks its removed root node. The guard should test andNode instead.

This is latent by lowering order today -- the AND's GTF_SET_FLAGS is only set later, when the consuming compare-to-zero is lowered -- but the check is still wrong and should be made consistent with the sibling helpers.

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. removed
    untriaged
    on Jul 16, 2026
  5. added this to the 11.0.0 milestone 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