From 15b75c7c684589b77d1190dc3bbc800998bd0f67 Mon Sep 17 00:00:00 2001 From: Kornel Uriasz Date: Tue, 4 Aug 2026 07:48:15 +0200 Subject: [PATCH] Fix skipping optimization for unpacked data types (#8031) Signed-off-by: Kornel Uriasz --- src/V3Const.cpp | 1 + test_regress/t/t_opt_unpacked.py | 18 +++++++++++++++++ test_regress/t/t_opt_unpacked.v | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100755 test_regress/t/t_opt_unpacked.py create mode 100644 test_regress/t/t_opt_unpacked.v diff --git a/src/V3Const.cpp b/src/V3Const.cpp index 2c044e918..f9eac2dfe 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -438,6 +438,7 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst { // Traverse down to see AstConst or AstVarRef LeafInfo findLeaf(AstNode* nodep, bool expectConst) { + if (!nodep->dtypep()->skipRefp()->isIntegralOrPacked()) return LeafInfo{}; LeafInfo info{m_lsb}; { VL_RESTORER(m_leafp); diff --git a/test_regress/t/t_opt_unpacked.py b/test_regress/t/t_opt_unpacked.py new file mode 100755 index 000000000..8a938befd --- /dev/null +++ b/test_regress/t/t_opt_unpacked.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# 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-FileCopyrightText: 2026 Wilson Snyder +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +import vltest_bootstrap + +test.scenarios('simulator') + +test.compile() + +test.execute() + +test.passes() diff --git a/test_regress/t/t_opt_unpacked.v b/test_regress/t/t_opt_unpacked.v new file mode 100644 index 000000000..0edefd3c8 --- /dev/null +++ b/test_regress/t/t_opt_unpacked.v @@ -0,0 +1,33 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain. +// SPDX-FileCopyrightText: 2026 Antmicro +// SPDX-License-Identifier: CC0-1.0 + +// This test purpose is to make sure we do not drop if conditional +// expression when trying to optimise bit operations. +module t; + class Cls; + endclass; + + class subCls; + bit val = 1'b1; + Cls c; + + function void check_valid(); + // "c == null" shall be preserved + if (val && c == null) begin + $stop(); + end + endfunction + endclass; + + subCls sc; + + initial begin + sc = new; + sc.c = new; + sc.check_valid(); + $finish; + end +endmodule