Skip to content

[FIRRTL] Replace remove-unused-ports with port-only IMDCE mode#10575

Merged
uenoku merged 4 commits into
llvm:mainfrom
uenoku:dev/hidetou/remove-unused-ports
Jun 6, 2026
Merged

[FIRRTL] Replace remove-unused-ports with port-only IMDCE mode#10575
uenoku merged 4 commits into
llvm:mainfrom
uenoku:dev/hidetou/remove-unused-ports

Conversation

@uenoku
Copy link
Copy Markdown
Member

@uenoku uenoku commented Jun 2, 2026

This PR replaces RemoveUnusedPorts with IMDCE by adding a new mode to IMDCE as mentioned in #10501.

To mimic the old RemoveUnusedPorts behavior, this PR adds two options (1) dropping donttouch (2) remove only ports. Maybe it might be better to move (1) to reduction pattern instead of implementing in IMDCE pass, though.

Invalid value propagation is added as well to pass the old test.

This PR fixes crashes in #10501 and #10504. IMDCE doesn't eliminate property/instance choices at this point though.

Close #3377.

Assisted-by: claude code: sonnet 4.6

@uenoku uenoku force-pushed the dev/hidetou/remove-unused-ports branch from df39e83 to 85c55f9 Compare June 2, 2026 00:16
@circt-bot
Copy link
Copy Markdown

circt-bot Bot commented Jun 2, 2026

Results of circt-tests run for 85c55f9 compared to results for a8e5943: no change to test results.

@@ -10,11 +10,11 @@ firrtl.circuit "Foo" {
// CHECK-NOT: %bar_e
// CHECK: %bar_b, %bar_d = firrtl.instance bar @Bar
%bar_a, %bar_b, %bar_c, %bar_d, %bar_e = firrtl.instance bar @Bar (in a: !firrtl.uint<1>, in b: !firrtl.uint<1>, out c: !firrtl.uint<1>, out d: !firrtl.uint<1>, out e: !firrtl.uint<1>)
firrtl.connect %bar_a, %x : !firrtl.uint<1>, !firrtl.uint<1>
Copy link
Copy Markdown
Member Author

@uenoku uenoku Jun 2, 2026

Choose a reason for hiding this comment

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

connect was replaced with matching connect since IMDCE doesn't handle normal connect for the simplicity (IMDCE relies on getSingleConnectUserOf. OTOH RemoveUnusedPorts manually inspected use-def connection). I don't expect this restriction reduces capability of reducer.

@circt-bot
Copy link
Copy Markdown

circt-bot Bot commented Jun 2, 2026

Results of circt-tests run for 7466173 compared to results for a8e5943: no change to test results.

Copy link
Copy Markdown
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

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

Awesome. Thank you for picking this up! I'm happy to see RemoveUnusedPorts getting dropped.

Comment thread lib/Dialect/FIRRTL/Transforms/IMDeadCodeElim.cpp
Comment thread lib/Dialect/FIRRTL/Transforms/IMDeadCodeElim.cpp Outdated
Comment thread include/circt/Dialect/FIRRTL/Passes.td Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider a file rename or moving this out of the reduction and into the main test/Dialect/FIRRTL/imdce-* suite of tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I consider this as a test for --include firrtl-imdeadcodeelim-remove-ports so I'd like to keep under reduction. Fair point for file name.

Comment on lines 13 to +38
@@ -33,8 +33,8 @@ firrtl.circuit "Foo" {
) {
%invalid_ui1 = firrtl.invalidvalue : !firrtl.uint<1>
%0 = firrtl.not %b : (!firrtl.uint<1>) -> !firrtl.uint<1>
firrtl.connect %c, %invalid_ui1 : !firrtl.uint<1>, !firrtl.uint<1>
firrtl.connect %d, %0 : !firrtl.uint<1>, !firrtl.uint<1>
firrtl.connect %e, %invalid_ui1 : !firrtl.uint<1>, !firrtl.uint<1>
firrtl.matchingconnect %c, %invalid_ui1 : !firrtl.uint<1>
firrtl.matchingconnect %d, %0 : !firrtl.uint<1>
firrtl.matchingconnect %e, %invalid_ui1 : !firrtl.uint<1>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are these changes required?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. #10575 (comment) for more info.

Comment thread test/Dialect/FIRRTL/imdce-remove-ports.mlir
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same question about connect vs. matchingconnect.

Comment thread test/Dialect/FIRRTL/imdce-remove-ports.mlir
@uenoku uenoku force-pushed the dev/hidetou/remove-unused-ports branch from 7466173 to f95cda8 Compare June 3, 2026 00:40
@uenoku uenoku force-pushed the dev/hidetou/remove-unused-ports branch from f95cda8 to 4988f5a Compare June 3, 2026 00:43
@circt-bot
Copy link
Copy Markdown

circt-bot Bot commented Jun 3, 2026

Results of circt-tests run for c594fd8 compared to results for a8e5943: no change to test results.

@uenoku uenoku requested a review from seldridge June 4, 2026 23:02
Copy link
Copy Markdown
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread test/Dialect/FIRRTL/imdce-remove-ports.mlir Outdated
Co-authored-by: Schuyler Eldridge <schuyler.eldridge@gmail.com>
@circt-bot
Copy link
Copy Markdown

circt-bot Bot commented Jun 5, 2026

Results of circt-tests run for 398c99e compared to results for a8e5943: no change to test results.

@uenoku uenoku merged commit 86a6966 into llvm:main Jun 6, 2026
6 checks passed
@uenoku uenoku deleted the dev/hidetou/remove-unused-ports branch June 6, 2026 03:52
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.

[FIRRTL] Remove RemoveUnusedPorts pass

2 participants