Skip to content

Fix suboptimal IL for small is patterns - #84961

Open
jjonescz wants to merge 4 commits into
dotnet:mainfrom
jjonescz:80052-is-codegen
Open

Fix suboptimal IL for small is patterns#84961
jjonescz wants to merge 4 commits into
dotnet:mainfrom
jjonescz:80052-is-codegen

Conversation

@jjonescz

@jjonescz jjonescz commented Aug 19, 2026

Copy link
Copy Markdown
Member

Fixes #80052.

This PR is a refined version of #82429 (which got stale).

Benchmark: https://gist.github.com/jjonescz/4c35cef07ad198a8da9b17d480da5a99. It also tests sparse vs dense values (so it could be more efficient to consider that too when deciding the lowering strategy), but for starters I think we can simply choose between linear vs DAG lowering on a simple threshold for the number of tests.

See also dotnet/runtime#132452 and dotnet/runtime#132504.

Microsoft Reviewers: Open in CodeFlow

@jjonescz
jjonescz requested a balanced review from Copilot August 19, 2026 15:01
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Optimizes C# lowering for small disjunctive is patterns to avoid temporary booleans and inefficient branches.

Changes:

  • Uses inverted linear lowering for binding-free patterns with up to four tests.
  • Updates affected IL baselines.
  • Adds regression, threshold, binding, and async tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
LocalRewriter_IsPatternOperator.cs Adds the optimized lowering path.
PatternTests.cs Adds regression and boundary tests.
CodeGenAsyncTests.cs Covers async lowering scenarios.
PatternMatchingTests.cs Updates Span pattern IL baselines.
PatternMatchingTests5.cs Updates numeric, string, and Span IL baselines.

@jjonescz
jjonescz marked this pull request as ready for review August 20, 2026 15:18
@jjonescz
jjonescz requested a review from a team as a code owner August 20, 2026 15:18
Copilot AI review requested due to automatic review settings August 20, 2026 15:18
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suboptimal codegen for is pattern compared to .NET 6/7

2 participants