Skip to content

[Mosaic] NFC: Refactor Mosaic canonicalization pass to use RewritePattern. #28250

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: main
Choose a base branch
from

Conversation

copybara-service[bot]
Copy link

[Mosaic] NFC: Refactor Mosaic canonicalization pass to use RewritePattern.

Right now, we're manually canonicalizing ops generated in the pattern (See arith::FPToSIOp and vector::ContractionOp). Also we might have an op that has both standalone and elementwise canonicalization pattern (e.g., arith::Select is suitable for elementwise upcast), and the current approach is bug-prone because each rule invalidates op.

RewritePattern infra seems a good-fit here. One caveat is that we're also doing (pre-infer) verification in the canonicalization pass while RewritePattern uses mlir::failure() to identify whether the transformation converges. I make it a tri-state instead:

  • If op is rewritten, return success().
  • If op is not matched and just passes through, return silent failure()
    without any diagnostic messages.
  • If op is invalid, return failure() with a meaningful diagnostic message.

But, we should consider separating verification from canonicalization too.

@copybara-service copybara-service bot force-pushed the test_751146100 branch 2 times, most recently from 4c08ef8 to dce0393 Compare April 25, 2025 00:38
…tern.

Right now, we're manually canonicalizing ops generated in the pattern (See arith::FPToSIOp and vector::ContractionOp). Also we might have an op that has both standalone and elementwise canonicalization pattern (e.g., arith::Select is suitable for elementwise upcast), and the current approach is bug-prone because each rule invalidates op.

RewritePattern infra seems a good-fit here. One caveat is that we're also doing (pre-infer) verification in the canonicalization pass while RewritePattern uses mlir::failure() to identify whether the transformation converges. I make it a tri-state instead:

- If op is rewritten, return `success()`.
- If op is not matched and just passes through, return silent `failure()`
  without any diagnostic messages.
- If op is invalid, return `failure()` with a meaningful diagnostic message.

But, we should consider separating verification from canonicalization too.

PiperOrigin-RevId: 751146100
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