Skip to content

JIT: Add canonicalization to GT_EQ and GT_NE#127548

Open
BoyBaykiller wants to merge 3 commits intodotnet:mainfrom
BoyBaykiller:EQ-NE-canonicalization
Open

JIT: Add canonicalization to GT_EQ and GT_NE#127548
BoyBaykiller wants to merge 3 commits intodotnet:mainfrom
BoyBaykiller:EQ-NE-canonicalization

Conversation

@BoyBaykiller
Copy link
Copy Markdown
Contributor

@BoyBaykiller BoyBaykiller commented Apr 29, 2026

  1. 'CNS relop op2' to 'op2 relop* CNS'
  2. '(A & pow2) == pow2' to '(A & pow2) != 0'. This should help optimizeBools and consequentenly JIT: Transform arithmetic using distributive property #126852 and probably other stuff. I'd also like this for JIT: Optimize some bitwise ops in context of enum flags #125899 if I add e.g SELECT(x & 16 == 16, y | 16, y) -> y | (x & 16)

@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 Apr 29, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Apr 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.

Comment thread src/coreclr/jit/morph.cpp
}

// Canonicalize '(A & pow2) == pow2' -> '(A & pow2) != 0'
if (cmp->OperIs(GT_EQ) && op1->OperIs(GT_AND) && op1->gtGetOp2()->IsIntegralConstUnsignedPow2())
Copy link
Copy Markdown
Contributor Author

@BoyBaykiller BoyBaykiller Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IsIntegralConstUnsignedPow2 check misses 1 << 31 (or 1 << 63). I need to know if there is only a single bit set. Naturally I would do Popcount(x) == 1, but how can I get the unsigned/not-sign-extend literal? All the APIs seem to sign extend first.

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 community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant