From 8e35c813992f7ccc327f09ecdcb8da19edfb8a2f Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Mon, 10 Nov 2025 17:18:33 +0000 Subject: [PATCH] Fix --expand-limit not respected for expressions (#6670) --- src/V3Expand.cpp | 5 +++++ test_regress/t/t_flag_expand_limit.py | 2 +- test_regress/t/t_flag_expand_limit.v | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/V3Expand.cpp b/src/V3Expand.cpp index f010aad3f..b3a57154a 100644 --- a/src/V3Expand.cpp +++ b/src/V3Expand.cpp @@ -907,6 +907,8 @@ class ExpandVisitor final : public VNVisitor { iterateChildren(nodep); if (nodep->lhsp()->isWide()) { if (isImpure(nodep)) return; + if (!doExpandWide(nodep->lhsp())) return; + if (!doExpandWide(nodep->rhsp())) return; UINFO(8, " Wordize EQ/NEQ " << nodep); // -> (0=={or{for each_word{WORDSEL(lhs,#)^WORDSEL(rhs,#)}}} FileLine* const fl = nodep->fileline(); @@ -933,6 +935,7 @@ class ExpandVisitor final : public VNVisitor { FileLine* const fl = nodep->fileline(); if (nodep->lhsp()->isWide()) { if (isImpure(nodep)) return; + if (!doExpandWide(nodep->lhsp())) return; UINFO(8, " Wordize REDOR " << nodep); // -> (0!={or{for each_word{WORDSEL(lhs,#)}}} AstNodeExpr* newp = nullptr; @@ -957,6 +960,7 @@ class ExpandVisitor final : public VNVisitor { FileLine* const fl = nodep->fileline(); if (nodep->lhsp()->isWide()) { if (isImpure(nodep)) return; + if (!doExpandWide(nodep->lhsp())) return; UINFO(8, " Wordize REDAND " << nodep); // -> (0!={and{for each_word{WORDSEL(lhs,#)}}} AstNodeExpr* newp = nullptr; @@ -988,6 +992,7 @@ class ExpandVisitor final : public VNVisitor { iterateChildren(nodep); if (nodep->lhsp()->isWide()) { if (isImpure(nodep)) return; + if (!doExpandWide(nodep->lhsp())) return; UINFO(8, " Wordize REDXOR " << nodep); // -> (0!={redxor{for each_word{XOR(WORDSEL(lhs,#))}}} FileLine* const fl = nodep->fileline(); diff --git a/test_regress/t/t_flag_expand_limit.py b/test_regress/t/t_flag_expand_limit.py index c5e6b9338..4e3ca445a 100755 --- a/test_regress/t/t_flag_expand_limit.py +++ b/test_regress/t/t_flag_expand_limit.py @@ -13,6 +13,6 @@ test.scenarios('vlt') test.compile(verilator_flags2=['--expand-limit 1 --stats -fno-dfg']) -test.file_grep(test.stats, r'Optimizations, expand limited\s+(\d+)', 3) +test.file_grep(test.stats, r'Optimizations, expand limited\s+(\d+)', 8) test.passes() diff --git a/test_regress/t/t_flag_expand_limit.v b/test_regress/t/t_flag_expand_limit.v index 0640ce15a..5e608ea2f 100644 --- a/test_regress/t/t_flag_expand_limit.v +++ b/test_regress/t/t_flag_expand_limit.v @@ -14,7 +14,17 @@ module t #(parameter NV = 2000) output [ 31:0] o, input [319:0] bi, - output [319:0] bo + output [319:0] bo, + + input [319:0] c_i1, + input [319:0] c_i2, + output c_eq_o, + output c_neq_o, + + input [319:0] d_red_i, + output d_red_and_o, + output d_red_or_o, + output d_red_xor_o ); // verilator lint_off WIDTH @@ -24,4 +34,11 @@ module t #(parameter NV = 2000) assign bo = ~bi; + assign c_eq_o = c_i1 == c_i2; + assign c_neq_o = c_i1 != c_i2; + + assign d_red_and_o = &d_red_i; + assign d_red_or_o = |d_red_i; + assign d_red_xor_o = ^d_red_i; + endmodule