diff --git a/src/V3FuncOpt.cpp b/src/V3FuncOpt.cpp index 7b79c7309..67af6296f 100644 --- a/src/V3FuncOpt.cpp +++ b/src/V3FuncOpt.cpp @@ -228,6 +228,8 @@ class FuncOptVisitor final : public VNVisitor { UASSERT_OBJ(lhsp->width() == rhsp->width(), nodep, "Inconsistent assignment"); // Only consider pure assignments. Nodes inserted below are safe. if (!nodep->user1() && (!lhsp->isPure() || !rhsp->isPure())) return false; + // Do not split assignments to SC variables, they cannot be assigned in parts + if (lhsp->exists([](AstVarRef* refp) { return refp->varp()->isSc(); })) return false; // Check for a Sel on the LHS if present, and skip over it uint32_t lsb = 0; if (AstSel* const selp = VN_CAST(lhsp, Sel)) { diff --git a/test_regress/t/t_balance_cats.py b/test_regress/t/t_balance_cats.py index b3cdbade4..b4c1671aa 100755 --- a/test_regress/t/t_balance_cats.py +++ b/test_regress/t/t_balance_cats.py @@ -11,7 +11,8 @@ import vltest_bootstrap test.scenarios('vlt') -test.compile(verilator_flags2=["--stats"]) +test.compile( + verilator_flags2=["--stats", "--build", "--gate-stmts", "10000", "--expand-limit", "128"]) test.file_grep(test.stats, r'Optimizations, FuncOpt concat trees balanced\s+(\d+)', 1) test.file_grep(test.stats, r'Optimizations, FuncOpt concat splits\s+(\d+)', 62) diff --git a/test_regress/t/t_balance_cats_sc.py b/test_regress/t/t_balance_cats_sc.py new file mode 100755 index 000000000..4bf066c4e --- /dev/null +++ b/test_regress/t/t_balance_cats_sc.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2024 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +import vltest_bootstrap + +test.scenarios('vlt') + +test.top_filename = "t/t_balance_cats.v" + +test.compile(verilator_flags2=[ + "--stats", "--build", "--gate-stmts", "10000", "--expand-limit", "128", "--sc" +]) + +test.file_grep(test.stats, r'Optimizations, FuncOpt concat trees balanced\s+(\d+)', 1) +test.file_grep(test.stats, r'Optimizations, FuncOpt concat splits\s+(\d+)', 0) + +test.passes()