From e1392b81c7da370bc34935ba643792df83e9d655 Mon Sep 17 00:00:00 2001 From: Charitha-Jeewanka Date: Sat, 14 Feb 2026 02:22:07 -0500 Subject: [PATCH 1/2] Fix wrong runtime result when using -fno-gate (#6952) Signed-off-by: Charitha-Jeewanka --- src/V3Gate.cpp | 35 +++++++++++++++++++++-------------- src/Verilator.cpp | 13 +++++++------ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/V3Gate.cpp b/src/V3Gate.cpp index ed078eee6..fbc38ff84 100644 --- a/src/V3Gate.cpp +++ b/src/V3Gate.cpp @@ -1284,26 +1284,33 @@ void V3Gate::gateAll(AstNetlist* netlistp) { graphp->removeRedundantEdgesSum(&V3GraphEdge::followAlwaysTrue); if (dumpGraphLevel() >= 6) graphp->dumpDotFilePrefixed("gate_simp"); - // Inline variables + // Inline variables (CRITICAL for downstream scheduling) GateInline::apply(*graphp); if (dumpGraphLevel() >= 6) graphp->dumpDotFilePrefixed("gate_inline"); - // Remove redundant logic - if (v3Global.opt.fDedupe()) { - GateDedupe::apply(*graphp); - if (dumpGraphLevel() >= 6) graphp->dumpDotFilePrefixed("gate_dedup"); - } + // --- NON-CRITICAL OPTIMIZATIONS --- + // Only run these aggressive logic reducers if gate optimization is enabled + if (v3Global.opt.fGate()) { + + // Remove redundant logic + if (v3Global.opt.fDedupe()) { + GateDedupe::apply(*graphp); + if (dumpGraphLevel() >= 6) graphp->dumpDotFilePrefixed("gate_dedup"); + } - // Merge assignments - if (v3Global.opt.fAssemble()) { - GateMergeAssignments::apply(*graphp); - if (dumpGraphLevel() >= 6) graphp->dumpDotFilePrefixed("gate_merge"); - } + // Merge assignments + if (v3Global.opt.fAssemble()) { + GateMergeAssignments::apply(*graphp); + if (dumpGraphLevel() >= 6) graphp->dumpDotFilePrefixed("gate_merge"); + } - // Remove unused logic - GateUnused::apply(*graphp); - if (dumpGraphLevel() >= 3) graphp->dumpDotFilePrefixed("gate_final"); + // Remove unused logic + GateUnused::apply(*graphp); + if (dumpGraphLevel() >= 3) graphp->dumpDotFilePrefixed("gate_final"); + + } // End of fGate() check } V3Global::dumpCheckGlobalTree("gate", 0, dumpTreeEitherLevel() >= 3); } + diff --git a/src/Verilator.cpp b/src/Verilator.cpp index 50a4dcf0f..c4fbeb1fc 100644 --- a/src/Verilator.cpp +++ b/src/Verilator.cpp @@ -420,12 +420,13 @@ static void process() { // Gate-based logic elimination; eliminate signals and push constant across cell // boundaries Instant propagation makes lots-o-constant reduction possibilities. - if (v3Global.opt.fGate()) { - V3Gate::gateAll(v3Global.rootp()); - // V3Gate calls constant propagation itself. - } else { - v3info("Command Line disabled gate optimization with -fno-gate. " - "This may cause ordering problems."); + // Always run gateAll to perform critical downstream normalizations + // (like GateInline) even if fGate is false. + V3Gate::gateAll(v3Global.rootp()); + + if (!v3Global.opt.fGate()) { + v3info("Command Line disabled gate optimization with -fno-gate. " + "Only critical normalizations will be performed."); } // Combine COVERINCs with duplicate terms From 60e06ddcc39486effe6b7781a7539b3d1e189eb8 Mon Sep 17 00:00:00 2001 From: Charitha-Jeewanka Date: Sat, 14 Feb 2026 03:40:40 -0500 Subject: [PATCH 2/2] Add name to CONTRIBUTORS to certify DCO Signed-off-by: Charitha-Jeewanka --- docs/CONTRIBUTORS | 1 + src/V3Gate.cpp | 4 ++-- src/Verilator.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index c652b4f39..96811c86e 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -30,6 +30,7 @@ Bartłomiej Chmiel Brian Li Cameron Kirk Cameron Waite +Charitha Jeewanka Chih-Mao Chen Chris Bachhuber Chris Randall diff --git a/src/V3Gate.cpp b/src/V3Gate.cpp index fbc38ff84..6f53bd90b 100644 --- a/src/V3Gate.cpp +++ b/src/V3Gate.cpp @@ -1291,7 +1291,7 @@ void V3Gate::gateAll(AstNetlist* netlistp) { // --- NON-CRITICAL OPTIMIZATIONS --- // Only run these aggressive logic reducers if gate optimization is enabled if (v3Global.opt.fGate()) { - + // Remove redundant logic if (v3Global.opt.fDedupe()) { GateDedupe::apply(*graphp); @@ -1307,7 +1307,7 @@ void V3Gate::gateAll(AstNetlist* netlistp) { // Remove unused logic GateUnused::apply(*graphp); if (dumpGraphLevel() >= 3) graphp->dumpDotFilePrefixed("gate_final"); - + } // End of fGate() check } diff --git a/src/Verilator.cpp b/src/Verilator.cpp index c4fbeb1fc..41bad8111 100644 --- a/src/Verilator.cpp +++ b/src/Verilator.cpp @@ -423,7 +423,7 @@ static void process() { // Always run gateAll to perform critical downstream normalizations // (like GateInline) even if fGate is false. V3Gate::gateAll(v3Global.rootp()); - + if (!v3Global.opt.fGate()) { v3info("Command Line disabled gate optimization with -fno-gate. " "Only critical normalizations will be performed.");