Fix splitting of assignments to SC variables (#6329) (#6336)

SC variables can only be assigned whole, so do not split up
concatenation assignments in V3FuncOpt.

Fixes #6329
This commit is contained in:
Geza Lore 2025-08-28 08:48:51 +01:00 committed by GitHub
parent 409e036eca
commit 1043a6c6be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 1 deletions

View File

@ -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)) {

View File

@ -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)

View File

@ -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()