From cc80c631e2a6a259f33d1d583107d5add05aaf12 Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Thu, 26 Aug 2021 13:40:59 -0400 Subject: Fix dshl zero-width shift behavior (#2339) * Fix dshl zero-width shift behavior Add a special case for dshl handling in the ZeroWidths pass. If one expression is shifted by a second, zero-width expression, just return the first expression. This prevents a bug where the width will incorrectly expand due to zero-widths introducing a 1-bit zero expression. Signed-off-by: Schuyler Eldridge * fixup! Fix dshl zero-width shift behavior--- src/main/scala/firrtl/passes/ZeroWidth.scala | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/main') diff --git a/src/main/scala/firrtl/passes/ZeroWidth.scala b/src/main/scala/firrtl/passes/ZeroWidth.scala index 003ab3c9..80eeab12 100644 --- a/src/main/scala/firrtl/passes/ZeroWidth.scala +++ b/src/main/scala/firrtl/passes/ZeroWidth.scala @@ -132,6 +132,10 @@ object ZeroWidth extends Transform with DependencyAPIMigration { case seq => DoPrim(Cat, seq, consts, tpe).map(onExp) } case DoPrim(Andr, Seq(x), _, _) if (bitWidth(x.tpe) == 0) => UIntLiteral(1) // nothing false + // The width of the result type of dshl is a function of the width of the shift. This has to be special cased for + // the zero-width shift case to prevent increasing the result width. Canonicalize a dshl by a zero-width element as + // just returning the unshifted expression. + case DoPrim(Dshl, Seq(x, a), _, _) if (bitWidth(a.tpe) == 0) => x case other => other.tpe match { case UIntType(IntWidth(ZERO)) => UIntLiteral(ZERO, IntWidth(BigInt(1))) -- cgit v1.2.3