From 48600c77b5c989d7f305e7eadefedddd323cf566 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Tue, 17 Jun 2025 15:53:47 +0100 Subject: [PATCH] Fix DFG binToOneHot table index missing driver (#6100) --- src/V3DfgPasses.cpp | 1 + test_regress/t/t_dfg_bin_to_one_hot.py | 2 +- test_regress/t/t_dfg_bin_to_one_hot.v | 138 +++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 1 deletion(-) diff --git a/src/V3DfgPasses.cpp b/src/V3DfgPasses.cpp index 6fd90bb86..1408fe40d 100644 --- a/src/V3DfgPasses.cpp +++ b/src/V3DfgPasses.cpp @@ -374,6 +374,7 @@ void V3DfgPasses::binToOneHot(DfgGraph& dfg, V3DfgBinToOneHotContext& ctx) { const std::string name = dfg.makeUniqueName("BinToOneHot_Idx", nTables); varp = dfg.makeNewVar(flp, name, idxDTypep)->as(); varp->varp()->isInternal(true); + varp->addDriver(flp, 0, srcp); } varp->setHasModRefs(); return varp; diff --git a/test_regress/t/t_dfg_bin_to_one_hot.py b/test_regress/t/t_dfg_bin_to_one_hot.py index 1612ac838..ae6ade37b 100755 --- a/test_regress/t/t_dfg_bin_to_one_hot.py +++ b/test_regress/t/t_dfg_bin_to_one_hot.py @@ -16,6 +16,6 @@ test.compile(verilator_flags2=["--stats"]) test.execute() test.file_grep(test.stats, r'Optimizations, DFG pre inline BinToOneHot, decoders created\s+(\d+)', - 2) + 3) test.passes() diff --git a/test_regress/t/t_dfg_bin_to_one_hot.v b/test_regress/t/t_dfg_bin_to_one_hot.v index 165a23f3c..2f1e3ee2b 100644 --- a/test_regress/t/t_dfg_bin_to_one_hot.v +++ b/test_regress/t/t_dfg_bin_to_one_hot.v @@ -162,6 +162,138 @@ module t (/*AUTOARG*/ cntA == 7'd0 }; + // Should create decoder - with temporary needed for index variabls + wire [127:0] notCntAOneHot = { + ~cntA == 7'd127, + ~cntA == 7'd126, + ~cntA == 7'd125, + ~cntA == 7'd124, + ~cntA == 7'd123, + ~cntA == 7'd122, + ~cntA == 7'd121, + ~cntA == 7'd120, + ~cntA == 7'd119, + ~cntA == 7'd118, + ~cntA == 7'd117, + ~cntA == 7'd116, + ~cntA == 7'd115, + ~cntA == 7'd114, + ~cntA == 7'd113, + ~cntA == 7'd112, + ~cntA == 7'd111, + ~cntA == 7'd110, + ~cntA == 7'd109, + ~cntA == 7'd108, + ~cntA == 7'd107, + ~cntA == 7'd106, + ~cntA == 7'd105, + ~cntA == 7'd104, + ~cntA == 7'd103, + ~cntA == 7'd102, + ~cntA == 7'd101, + ~cntA == 7'd100, + ~cntA == 7'd99, + ~cntA == 7'd98, + ~cntA == 7'd97, + ~cntA == 7'd96, + ~cntA == 7'd95, + ~cntA == 7'd94, + ~cntA == 7'd93, + ~cntA == 7'd92, + ~cntA == 7'd91, + ~cntA == 7'd90, + ~cntA == 7'd89, + ~cntA == 7'd88, + ~cntA == 7'd87, + ~cntA == 7'd86, + ~cntA == 7'd85, + ~cntA == 7'd84, + ~cntA == 7'd83, + ~cntA == 7'd82, + ~cntA == 7'd81, + ~cntA == 7'd80, + ~cntA == 7'd79, + ~cntA == 7'd78, + ~cntA == 7'd77, + ~cntA == 7'd76, + ~cntA == 7'd75, + ~cntA == 7'd74, + ~cntA == 7'd73, + ~cntA == 7'd72, + ~cntA == 7'd71, + ~cntA == 7'd70, + ~cntA == 7'd69, + ~cntA == 7'd68, + ~cntA == 7'd67, + ~cntA == 7'd66, + ~cntA == 7'd65, + ~cntA == 7'd64, + ~cntA == 7'd63, + ~cntA == 7'd62, + ~cntA == 7'd61, + ~cntA == 7'd60, + ~cntA == 7'd59, + ~cntA == 7'd58, + ~cntA == 7'd57, + ~cntA == 7'd56, + ~cntA == 7'd55, + ~cntA == 7'd54, + ~cntA == 7'd53, + ~cntA == 7'd52, + ~cntA == 7'd51, + ~cntA == 7'd50, + ~cntA == 7'd49, + ~cntA == 7'd48, + ~cntA == 7'd47, + ~cntA == 7'd46, + ~cntA == 7'd45, + ~cntA == 7'd44, + ~cntA == 7'd43, + ~cntA == 7'd42, + ~cntA == 7'd41, + ~cntA == 7'd40, + ~cntA == 7'd39, + ~cntA == 7'd38, + ~cntA == 7'd37, + ~cntA == 7'd36, + ~cntA == 7'd35, + ~cntA == 7'd34, + ~cntA == 7'd33, + ~cntA == 7'd32, + ~cntA == 7'd31, + ~cntA == 7'd30, + ~cntA == 7'd29, + ~cntA == 7'd28, + ~cntA == 7'd27, + ~cntA == 7'd26, + ~cntA == 7'd25, + ~cntA == 7'd24, + ~cntA == 7'd23, + ~cntA == 7'd22, + ~cntA == 7'd21, + ~cntA == 7'd20, + ~cntA == 7'd19, + ~cntA == 7'd18, + ~cntA == 7'd17, + ~cntA == 7'd16, + ~cntA == 7'd15, + ~cntA == 7'd14, + ~cntA == 7'd13, + ~cntA == 7'd12, + ~cntA == 7'd11, + ~cntA == 7'd10, + ~cntA == 7'd9, + ~cntA == 7'd8, + ~cntA == 7'd7, + ~cntA == 7'd6, + ~cntA == 7'd5, + ~cntA == 7'd4, + ~cntA == 7'd3, + ~cntA == 7'd2, + ~cntA == 7'd1, + ~cntA == 7'd0 + }; + // Should create decoder wire stupidWayToWriteConstOne = 1'b0 + (cntB == 7'd127) @@ -413,6 +545,12 @@ module t (/*AUTOARG*/ `check(cntAOneHot[i], 1'b0); end + `check(notCntAOneHot[~cntA], 1'b1); + for (int i = 0; i < $bits(notCntAOneHot); i = i + 1) begin + if (i == {25'd0, ~cntA}) continue; + `check(notCntAOneHot[i], 1'b0); + end + `check(stupidWayToWriteConstOne, 1'b1); `check(twiceCntC, cntC * 7'd2);