From 1927dc6574b9eee315c8f24441df390f2ce793c7 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Thu, 23 Jul 2020 11:14:35 -0700 Subject: mask bits when propagating bitwise ops (#1745) * ConstProp: test bitwise op of signed literals * ConstProp: use bit mask for FoldOr/FoldXor * handle and also * add UIntLiteral.masked helper Co-authored-by: Jack Koenig --- .../firrtlTests/ConstantPropagationTests.scala | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/test') diff --git a/src/test/scala/firrtlTests/ConstantPropagationTests.scala b/src/test/scala/firrtlTests/ConstantPropagationTests.scala index 131f9466..d81f8687 100644 --- a/src/test/scala/firrtlTests/ConstantPropagationTests.scala +++ b/src/test/scala/firrtlTests/ConstantPropagationTests.scala @@ -1508,6 +1508,30 @@ class ConstantPropagationIntegrationSpec extends LowTransformSpec { execute(input, check, Seq.empty) } + it should "optimize bitwise operations of signed literals" in { + val input = + s"""|circuit Foo: + | module Foo: + | output out1: UInt<2> + | output out2: UInt<2> + | output out3: UInt<2> + | out1 <= xor(SInt<2>(-1), SInt<2>(1)) + | out2 <= or(SInt<2>(-1), SInt<2>(1)) + | out3 <= and(SInt<2>(-1), SInt<2>(-2)) + |""".stripMargin + val check = + s"""|circuit Foo: + | module Foo: + | output out1: UInt<2> + | output out2: UInt<2> + | output out3: UInt<2> + | out1 <= UInt<2>(2) + | out2 <= UInt<2>(3) + | out3 <= UInt<2>(2) + |""".stripMargin + execute(input, check, Seq.empty) + } + } -- cgit v1.2.3