From e504e9aced15a3aeedc983b24d56e7ed552ec66e Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Thu, 27 Oct 2022 18:32:10 +0100 Subject: [PATCH] Optimize clocked processes to comb when referencing const variables In V3Active, we try hard to turn `always @(a or b or c)` into an `always_comb` if the only variables read in the block are also in the sensitivity list. In addition, also allow this optimization when reading variables that are not in the sensitivity list, but are known to be constant/never changing after initialization. In particular lookup tables introduced by V3Table are covered by this. This can have a significant impact on designs that use the `always @(a or b or c)` style for combinational logic. --- src/V3Active.cpp | 7 ++++--- test_regress/t/t_case_huge.pl | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/V3Active.cpp b/src/V3Active.cpp index 06a1d7f51..0350609cc 100644 --- a/src/V3Active.cpp +++ b/src/V3Active.cpp @@ -571,10 +571,11 @@ private: if (nodep->access().isWriteOnly()) { vscp->user2(true); } else { - // If the variable is read before it is written, and is not in the sensitivity list, - // then this cannot be optimized into a combinational process + // If the variable is read before it is written (and is not a never-changing value), + // and is not in the sensitivity list, then this cannot be optimized into a + // combinational process // TODO: live variable analysis would be more precise - if (!vscp->user2() && !vscp->user1()) m_canBeComb = false; + if (!vscp->user2() && !vscp->varp()->valuep() && !vscp->user1()) m_canBeComb = false; } } void visit(AstAssignDly* nodep) override { diff --git a/test_regress/t/t_case_huge.pl b/test_regress/t/t_case_huge.pl index 79a6a7976..c8266ccbc 100755 --- a/test_regress/t/t_case_huge.pl +++ b/test_regress/t/t_case_huge.pl @@ -14,9 +14,12 @@ compile( verilator_flags2 => ["--stats"], ); -if ($Self->{vlt_all}) { +if ($Self->{vlt}) { file_grep($Self->{stats}, qr/Optimizations, Tables created\s+(\d+)/i, 10); - file_grep($Self->{stats}, qr/Optimizations, Combined CFuncs\s+(\d+)/i, 0); + file_grep($Self->{stats}, qr/Optimizations, Combined CFuncs\s+(\d+)/i, 8); +} elsif ($Self->{vltmt}) { + file_grep($Self->{stats}, qr/Optimizations, Tables created\s+(\d+)/i, 10); + file_grep($Self->{stats}, qr/Optimizations, Combined CFuncs\s+(\d+)/i, 9); } execute(