Skip to content

Return the original signal when replicating by 1 - #689

Merged
mkorbel1 merged 1 commit into
intel:mainfrom
aishasalim:fix/replicate-by-one-returns-signal
Jul 23, 2026
Merged

Return the original signal when replicating by 1#689
mkorbel1 merged 1 commit into
intel:mainfrom
aishasalim:fix/replicate-by-one-returns-signal

Conversation

@aishasalim

Copy link
Copy Markdown
Contributor

Logic.replicate(1) built a ReplicationOp, which emits a redundant {1{...}} in the generated SystemVerilog:

assign rep1 = {1{a}};

Replicating once is a no-op, so return the signal directly instead. The generated output becomes:

assign rep1 = a;

signExtend already routes through replicate, so it inherits the same benefit: sign-extending a 1-bit signal to width 1, or any signal to its existing width, no longer emits a replication.

Validation of non-positive multipliers is unaffected; those still reach ReplicationOp and throw InvalidMultiplierException.

Adds tests for the returned signal identity and for the absence of {1{ in generated SystemVerilog. The existing "multiply by 1" test only checked simulated values, which pass either way.

Fixes #522

Description & Motivation

Related Issue(s)

Testing

Backwards-compatibility

Is this a breaking change that will not be backwards-compatible? If yes, how so?

Documentation

Does the change require any updates to documentation? If so, where? Are they included?

@mkorbel1 mkorbel1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for your contribution! A couple notes/questions

Comment thread test/replication_test.dart
Comment thread test/replication_test.dart
`Logic.replicate(1)` built a `ReplicationOp`, which emits a redundant
`{1{...}}` in the generated SystemVerilog:

    assign rep1 = {1{a}};

Replicating once is a no-op, so return the signal directly instead. The
generated output becomes:

    assign rep1 = a;

`signExtend` already routes through `replicate`, so it inherits the same
benefit: sign-extending a 1-bit signal to width 1, or any signal to its
existing width, no longer emits a replication.

Validation of non-positive multipliers is unaffected; those still reach
`ReplicationOp` and throw `InvalidMultiplierException`.

Adds tests for the returned signal identity and for the absence of `{1{`
in generated SystemVerilog. The existing "multiply by 1" test only
checked simulated values, which pass either way.

Fixes intel#522
@aishasalim
aishasalim force-pushed the fix/replicate-by-one-returns-signal branch from 8a665c4 to 5fe5200 Compare July 23, 2026 02:32

@mkorbel1 mkorbel1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great! Thank you for the contribution!

@mkorbel1
mkorbel1 merged commit 6d889fe into intel:main Jul 23, 2026
3 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.

When replicating by 1, just return the 1 signal

2 participants