Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Fix width of constant propagation of SInt with zero #2120

Merged
merged 1 commit into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/firrtl/transforms/ConstantPropagation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class ConstantPropagation extends Transform with DependencyAPIMigration {
}
def simplify(e: Expression, lhs: Literal, rhs: Expression) = lhs match {
case UIntLiteral(v, _) if v == BigInt(0) => rhs
case SIntLiteral(v, _) if v == BigInt(0) => asUInt(rhs, e.tpe)
case SIntLiteral(v, _) if v == BigInt(0) => asUInt(pad(rhs, e.tpe), e.tpe)
case UIntLiteral(v, IntWidth(w)) if v == (BigInt(1) << bitWidth(rhs.tpe).toInt) - 1 => lhs
case _ => e
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/scala/firrtlTests/ConstantPropagationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,20 @@ class ConstantPropagationEquivalenceSpec extends FirrtlFlatSpec {
firrtlEquivalenceTest(input, transforms)
}

// https://github.com/chipsalliance/firrtl/issues/2034
"SInt OR with constant zero" should "have the correct widths" in {
val input =
s"""circuit WidthsOrSInt :
| module WidthsOrSInt :
| input in : SInt<1>
| input in2 : SInt<4>
| output out : UInt<8>
| output out2 : UInt<8>
| out <= or(in, SInt<8>(0))
| out2 <= or(in2, SInt<8>(0))""".stripMargin
firrtlEquivalenceTest(input, transforms)
}

"addition by zero width wires" should "have the correct widths" in {
val input =
s"""circuit ZeroWidthAdd:
Expand Down