From 3726fba89bb70f424ac8be4ad2d4b300c471d7e8 Mon Sep 17 00:00:00 2001 From: Albert Magyar Date: Wed, 11 Mar 2020 15:14:45 -0700 Subject: Don't const-prop a register's self-init (#1441) * Fixes #1214 Co-authored-by: Jack Koenig --- .../firrtl/transforms/ConstantPropagation.scala | 29 ++++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/main') diff --git a/src/main/scala/firrtl/transforms/ConstantPropagation.scala b/src/main/scala/firrtl/transforms/ConstantPropagation.scala index c11bc44d..18577147 100644 --- a/src/main/scala/firrtl/transforms/ConstantPropagation.scala +++ b/src/main/scala/firrtl/transforms/ConstantPropagation.scala @@ -501,17 +501,24 @@ class ConstantPropagation extends Transform with ResolvedAnnotationPaths { propagated } - def backPropStmt(stmt: Statement): Statement = stmt map backPropExpr match { - case decl: IsDeclaration if swapMap.contains(decl.name) => - val newName = swapMap(decl.name) - nPropagated += 1 - decl match { - case node: DefNode => node.copy(name = newName) - case wire: DefWire => wire.copy(name = newName) - case reg: DefRegister => reg.copy(name = newName) - case other => throwInternalError() - } - case other => other map backPropStmt + def backPropStmt(stmt: Statement): Statement = stmt match { + case reg: DefRegister if (WrappedExpression.weq(reg.init, WRef(reg))) => + // Self-init reset is an idiom for "no reset," and must be handled separately + swapMap.get(reg.name) + .map(newName => reg.copy(name = newName, init = WRef(reg).copy(name = newName))) + .getOrElse(reg) + case s => s map backPropExpr match { + case decl: IsDeclaration if swapMap.contains(decl.name) => + val newName = swapMap(decl.name) + nPropagated += 1 + decl match { + case node: DefNode => node.copy(name = newName) + case wire: DefWire => wire.copy(name = newName) + case reg: DefRegister => reg.copy(name = newName) + case other => throwInternalError() + } + case other => other map backPropStmt + } } // When propagating a reference, check if we want to keep the name that would be deleted -- cgit v1.2.3