Skip to content

[FIRRTL] Only narrow signed subtraction in SubOfPad canonicalizers - #11290

Merged
youngar merged 2 commits into
llvm:mainfrom
vera-rubin:fix/subofpad-uint-sub
Oct 14, 2026
Merged

youngar merged 2 commits into
llvm:mainfrom
vera-rubin:fix/subofpad-uint-sub

Conversation

@vera-rubin

@vera-rubin vera-rubin commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Updated test: fails before the fix, passes after
  • Issue reproducer: 154 mismatches before, 0 after, in both Icarus and Verilator
  • FIRRTL, firtool and FIRRTLToHW test suites: 331 passed, 5 expected failures

Fixes #11276

Assisted-by: Codex:gpt-6.1-sol
Assisted-by: Claude Code:claude-opus-5-5

— ChipLab

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 youngar left a comment

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.

LGTM

@circt-bot

circt-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown

Results of circt-tests run for 1bb8b99 compared to results for a034e7d: no change to test results.

Assisted-by: Claude Code:claude-opus-5-5
@circt-bot

circt-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown

Results of circt-tests run for 1e5d87b compared to results for a034e7d: no change to test results.

@youngar
youngar merged commit b905f70 into llvm:main Oct 14, 2026
6 checks passed
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] SubOfPad drops the high bit of UInt subtraction

2 participants