Repository navigation
[FIRRTL] Only narrow signed subtraction in SubOfPad canonicalizers - #11290
Merged
Merged
Conversation
SubOfPadL/R rewrite sub(pad(a, n), b) into pad(sub(a, b), n). That is only correct for signed operands. For UInt the narrower difference is zero-extended, so a negative result loses its high bits, e.g. a 9-bit zero-extended a minus c gave a 10-bit result with bit 9 always zero. Restrict both patterns to SInt and update the sub_narrow test, which was checking the wrong result. Assisted-by: Codex:gpt-6.1-sol Assisted-by: Claude Code:claude-opus-5-5
youngar
approved these changes
Oct 14, 2026
Assisted-by: Claude Code:claude-opus-5-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SubOfPadL/R currently narrow subtraction on padded UInt values, then zero-extend the result. That loses the borrow bit and makes it come out as 0.
This limits both rewrites to SInt values and corrects the existing sub_narrow test.
Checked with:
Fixes #11276
Assisted-by: Codex:gpt-6.1-sol
Assisted-by: Claude Code:claude-opus-5-5
— ChipLab