From eb76d35e8030f4befb596fee6d7682d39628dc69 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcelina=20Ko=C5=9Bcielnicka?= Date: Thu, 22 Oct 2020 10:37:44 +0200 Subject: [PATCH] memory_dff: Fix needlessly duplicating enable bits. When the register being merged into the EN signal happens to be a $sdff, the current code creates a new $mux for every bit, even if they happen to be identical (as is usually the case), preventing proper grouping further down the flow. Fix this by adding a simple cache. Fixes #2409. --- passes/memory/memory_dff.cc | 8 ++++++++ tests/arch/ecp5/bug2409.ys | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/arch/ecp5/bug2409.ys diff --git a/passes/memory/memory_dff.cc b/passes/memory/memory_dff.cc index 68023fd11..4adcb462e 100644 --- a/passes/memory/memory_dff.cc +++ b/passes/memory/memory_dff.cc @@ -46,8 +46,15 @@ struct MemoryDffWorker { sigmap.apply(sig); + dict cache; + for (auto &bit : sig) { + if (cache.count(bit)) { + bit = cache[bit]; + continue; + } + if (bit.wire == NULL) continue; @@ -103,6 +110,7 @@ struct MemoryDffWorker d = module->Mux(NEW_ID, rbit, d, cell->getPort(ID::SRST)); } + cache[bit] = d; bit = d; clk = this_clk; clk_polarity = this_clk_polarity; diff --git a/tests/arch/ecp5/bug2409.ys b/tests/arch/ecp5/bug2409.ys new file mode 100644 index 000000000..5ba9cec17 --- /dev/null +++ b/tests/arch/ecp5/bug2409.ys @@ -0,0 +1,24 @@ +read_verilog <