diff options
| author | Jack Koenig | 2021-03-14 00:03:25 -0800 |
|---|---|---|
| committer | GitHub | 2021-03-14 00:03:25 -0800 |
| commit | 0eb7afd09d488507d776017c5df8f6ec56924927 (patch) | |
| tree | c8f0f82c065134fd082ddb1b803d1ac3dd1cd0c4 /src | |
| parent | fd55c51bcef01c2b2919817aa33c67e5a0849d05 (diff) | |
Fix width of constant propagation of SInt with zero (#2120)
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/firrtl/transforms/ConstantPropagation.scala | 2 | ||||
| -rw-r--r-- | src/test/scala/firrtlTests/ConstantPropagationTests.scala | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/main/scala/firrtl/transforms/ConstantPropagation.scala b/src/main/scala/firrtl/transforms/ConstantPropagation.scala index 0523082d..7106c699 100644 --- a/src/main/scala/firrtl/transforms/ConstantPropagation.scala +++ b/src/main/scala/firrtl/transforms/ConstantPropagation.scala @@ -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 } diff --git a/src/test/scala/firrtlTests/ConstantPropagationTests.scala b/src/test/scala/firrtlTests/ConstantPropagationTests.scala index 28c1d823..60cf1b8b 100644 --- a/src/test/scala/firrtlTests/ConstantPropagationTests.scala +++ b/src/test/scala/firrtlTests/ConstantPropagationTests.scala @@ -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: |
