Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize const pattern guards for StructuralEq types #138664

Open
TimNN opened this issue Mar 18, 2025 · 0 comments
Open

Optimize const pattern guards for StructuralEq types #138664

TimNN opened this issue Mar 18, 2025 · 0 comments
Labels
A-patterns Relating to patterns and pattern matching C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@TimNN
Copy link
Contributor

TimNN commented Mar 18, 2025

With inline_const_pat being removed in #138492, it might be nice to optimize codegen of pat if pat == const { .. }.

Right now

match a {
  1 => 42,
  b if b == 7 => 100,
  _ => 99,
}

Produces a SwitchInt and then a separate equality check.

Changing the second pattern to 7 => 100 produces a single SwitchInt.

I assume that the optimizer can recover this (at least for simpler cases), but it might be nice for the compiler to generate the simplified MIR directly (especially with inline_const_pat gone).

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 18, 2025
@fmease fmease added the C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such label Mar 18, 2025
@lolbinarycat lolbinarycat added A-patterns Relating to patterns and pattern matching T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-patterns Relating to patterns and pattern matching C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants