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

[idea] For exhaustive matches, should we expose the construct to the IR? #1920

Open
cdleary opened this issue Feb 9, 2025 · 1 comment
Open
Labels
ir long-term-enhancement Issues that are sensible enhancements but XLS devs expect may not be addressed in the near-term optimizer Related to IR optimization or analysis

Comments

@cdleary
Copy link
Collaborator

cdleary commented Feb 9, 2025

Filing for discussion -- I was thinking that for the match construct in DSLX -- e.g. imagine one that doesn't have a trailing wildcard arm -- we know that the coverage of arms is exhaustive because we've done a small proof of it in the type system. Following that, we place the last arm's expression in the "default value" position for a select op during IR conversion, while the other arms have equality/range tests (or compound equality/range tests) that guide whether they're selected.

The fact that the earlier arms have equality/range tests and the last arm doesn't need to compute any associated predicate seems gives an opportunity to reorder the arms so that the most costly predicate is the one that we don't need to compute. e.g. imagine one arm that had lots of range comparisons which are effectively comparisons, you may want to place the costliest one in the "default" position if the patterns for the arms were disjoint. Both proving disjointness of the arms and swizzling the arms around based on cost seems like potential opportunities for the IR if we kept the match-like construct in tact somehow.

Not very crisp in identifying the potential opportunity I know, but wanted to jot it down. Relates to recent discussion in #1913 cc @meheff

@cdleary cdleary added ir long-term-enhancement Issues that are sensible enhancements but XLS devs expect may not be addressed in the near-term optimizer Related to IR optimization or analysis labels Feb 9, 2025
@cdleary
Copy link
Collaborator Author

cdleary commented Feb 9, 2025

Thinking about it more, maybe priority sel already is the representation and we just need some kind of "condition A implies condition B" or "condition A is disjoint from condition B" within the stacked conditions that make up the selector bits to swap around the bits correctly in the selector (and associated case values come along for the ride). Disjointness makes the ability to commute the case values around arbitrary. Don't know that we do that optimization yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ir long-term-enhancement Issues that are sensible enhancements but XLS devs expect may not be addressed in the near-term optimizer Related to IR optimization or analysis
Projects
None yet
Development

No branches or pull requests

1 participant