Skip to content

[FIRRTL] Improve canonicalization patterns for variadic cat and reduction operations #8578

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

Open
wants to merge 1 commit into
base: dev/hidetou/concat
Choose a base branch
from

Conversation

uenoku
Copy link
Member

@uenoku uenoku commented Jun 18, 2025

This commit enhances FIRRTL canonicalization for variadic cat flatten. Several canonicalizations are added to pass the existing tests.

Reduction-Cat Patterns:

  • Replace table-driven patterns for AndR/OrR/XorR with cat operands with C++
  • AndRCat: Optimizes andr(cat(...)) by handling zero constants (-> 0) and all-ones constants (identity)
  • OrRCat: Optimizes orr(cat(...)) by handling non-zero constants (-> 1) and zero constants (identity)
  • XorRCat: Optimizes xorr(cat(...)) by preserving non-zero constants and eliminating zero constants

Cat Optimization Patterns:

  • FlattenCat: Flattens nested cat operations into single cat operations for better optimization opportunities
  • CatOfConstant: Folds successive constant operands in cat operations (e.g., cat(x, 3, 5, y) -> cat(x, 29, y))
  • BitsOfCat: Optimizes bits extraction from cat operations by extracting directly from the appropriate operand when possible

The new patterns replace the previous table-driven AndRCat*, OrRCat*, and XorRCat* patterns since it's too complicated to handle the condition in tablegen

Close #8544

…ations

This commit enhances FIRRTL canonicalization with several new optimization patterns:

**Reduction-Cat Patterns:**
- Replace table-driven patterns for AndR/OrR/XorR with cat operands with C++
- AndRCat: Optimizes andr(cat(...)) by handling zero constants (-> 0) and all-ones constants (identity)
- OrRCat: Optimizes orr(cat(...)) by handling non-zero constants (-> 1) and zero constants (identity)
- XorRCat: Optimizes xorr(cat(...)) by preserving non-zero constants and eliminating zero constants

**Cat Optimization Patterns:**
- FlattenCat: Flattens nested cat operations into single cat operations for better optimization opportunities
- CatOfConstant: Folds successive constant operands in cat operations (e.g., cat(x, 3, 5, y) -> cat(x, 29, y))
- BitsOfCat: Optimizes bits extraction from cat operations by extracting directly from the appropriate operand when possible

The new patterns replace the previous table-driven AndRCat*, OrRCat*, and XorRCat* patterns since it's
too complicated to handle the condition in tablegen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant