Skip to content

[FIRRTL] Eliminate Implicit Truncation#10294

Open
darthscsi wants to merge 2 commits intomainfrom
dev/darthscsi/connectTruncKill2
Open

[FIRRTL] Eliminate Implicit Truncation#10294
darthscsi wants to merge 2 commits intomainfrom
dev/darthscsi/connectTruncKill2

Conversation

@darthscsi
Copy link
Copy Markdown
Contributor

Eliminate implicit truncations from FIRRTL. This changes connects, InferWidths, and parsing.

Assisted-by: Augment:Sonet-4.5

Eliminate implicit truncations from FIRRTL.  This changes connects, InferWidths, and parsing.
@darthscsi darthscsi requested a review from seldridge as a code owner April 21, 2026 22:29
@darthscsi
Copy link
Copy Markdown
Contributor Author

This version is more aggressive with simplifying more locations in the code. Especially watching emitConnect changes in large design testing.

@fabianschuiki
Copy link
Copy Markdown
Contributor

Results of circt-tests run for 777abb2 compared to results for 2aefae7: no change to test results.

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.

Parser rejections are great as the errors are better. However, this should also have verifiers do the rejection, too, right?

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.

This NFC change that was really a test mistake (a FIRRTL or MLIR file relying on implicit truncation that didn't need to and wasn't testing implicit truncation) could be broken out and landed directly. I'm thinking about this as I'd like to keep this change out of the 1.145.0 release as I am pretty sure this is going to need Chisel and internal codebase coordination to not break a ton of stuff.

However, it would be great to start prepping CIRCT for this change.

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.

Can be landed separately.

Comment thread test/firtool/connect.fir
Comment on lines -8 to +6
FIRRTL version 4.0.0
FIRRTL version 4.0.0
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.

Nit: unnecessary change.

Comment thread test/firtool/firtool.fir
Comment on lines -221 to +169
input inp_1: UInt<5>
input inp_2: UInt<5>
input inp_3: UInt<5>
output out1: UInt<10>
output out2: UInt<10>
input inp_1: UInt<6>
input inp_2: UInt<6>
input inp_3: UInt<6>
output out1: UInt<12>
output out2: UInt<12>
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.

This could be factored out.

Comment on lines +202 to +211
// Issue #1088 - Implicit truncation is not allowed.
firrtl.circuit "Issue1088" {
firrtl.module @Issue1088(out %y: !firrtl.sint<4>) {
%x = firrtl.wire : !firrtl.sint
%c200_si = firrtl.constant 200 : !firrtl.sint
// expected-error @+1 {{destination '!firrtl.sint<4>' is not as wide as the source '!firrtl.sint<9>'}}
firrtl.connect %y, %x : !firrtl.sint<4>, !firrtl.sint
firrtl.connect %x, %c200_si : !firrtl.sint, !firrtl.sint
}
}
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.

This looks like LLM slop.

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.

Can be landed separately.

Comment on lines +166 to +168
// The source can be extended if needed, but truncation is not allowed.
assert(dstWidth >= srcWidth &&
"implicit truncation is not allowed in connect operations");
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.

The addition of these asserts likely means that emitConnect needs to return a LogicalResult for better handling of this. I'm worried that this will be brittle in release builds unless we can guarantee that this is never going to ever occur.

Alternatively, if there is a ConnectOp verifier, that would be entirely fine. (That is probably the right thing to do here and then maybe leave the asserts so that this errors faster in debug/relwithdebinfo builds.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Was looking at that. This is more a thing to see how often this triggers and under what conditions.

Comment on lines +381 to +384
// If there's no access operation, skip this port
if (!cmemoryPortAccess) {
continue;
}
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.

This looks unrelated.

Also, nit:

Suggested change
// If there's no access operation, skip this port
if (!cmemoryPortAccess) {
continue;
}
// If there's no access operation, skip this port
if (!cmemoryPortAccess)
continue;

Comment on lines +409 to +413
if (addrWidth >= 0 && indexWidth >= 0 && indexWidth > addrWidth) {
indexValue =
TailPrimOp::create(portBuilder, indexValue, indexWidth - addrWidth)
.getResult();
}
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.

Suggested change
if (addrWidth >= 0 && indexWidth >= 0 && indexWidth > addrWidth) {
indexValue =
TailPrimOp::create(portBuilder, indexValue, indexWidth - addrWidth)
.getResult();
}
if (addrWidth >= 0 && indexWidth >= 0 && indexWidth > addrWidth)
indexValue =
TailPrimOp::create(portBuilder, indexValue, indexWidth - addrWidth)
.getResult();

@uenoku uenoku changed the title Eliminate Implicit Truncation [FIRRTL] Eliminate Implicit Truncation Apr 22, 2026
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.

3 participants