diff --git a/src/V3Const.cpp b/src/V3Const.cpp index c9250a3f6..8a7670c14 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -3583,7 +3583,11 @@ public: } virtual ~ConstVisitor() override { if (m_doCpp) { - V3Stats::addStat("Optimizations, Const bit op reduction", m_statBitOpReduction); + if (m_globalPass) { + V3Stats::addStat("Optimizations, Const bit op reduction", m_statBitOpReduction); + } else { + V3Stats::addStatSum("Optimizations, Const bit op reduction", m_statBitOpReduction); + } } } @@ -3676,6 +3680,12 @@ AstNode* V3Const::constifyEdit(AstNode* nodep) { return nodep; } +AstNode* V3Const::constifyEditCpp(AstNode* nodep) { + ConstVisitor visitor{ConstVisitor::PROC_CPP, /* globalPass: */ false}; + nodep = visitor.mainAcceptEdit(nodep); + return nodep; +} + void V3Const::constifyAllLive(AstNetlist* nodep) { // Only call from Verilator.cpp, as it uses user#'s // This only pushes constants up, doesn't make any other edits diff --git a/src/V3Const.h b/src/V3Const.h index 59f5a5f76..ada396efd 100644 --- a/src/V3Const.h +++ b/src/V3Const.h @@ -39,6 +39,9 @@ public: static void constifyCpp(AstNetlist* nodep); // Only the current node and lower // Return new node that may have replaced nodep + static AstNode* constifyEditCpp(AstNode* nodep); + // Only the current node and lower + // Return new node that may have replaced nodep static AstNode* constifyEdit(AstNode* nodep); // Only the current node and lower, with special SenTree optimization // Return new node that may have replaced nodep diff --git a/src/V3Expand.cpp b/src/V3Expand.cpp index 5c341db26..c10c3c85f 100644 --- a/src/V3Expand.cpp +++ b/src/V3Expand.cpp @@ -32,6 +32,7 @@ #include "V3Expand.h" #include "V3Stats.h" #include "V3Ast.h" +#include "V3Const.h" #include @@ -160,6 +161,7 @@ private: new AstShiftL{fl, llowp, new AstConst{fl, static_cast(loffset)}, VL_EDATASIZE}}}; + newp = V3Const::constifyEditCpp(newp); } else { newp = llowp; } @@ -520,8 +522,9 @@ private: cleanmask.setMask(VL_BITBIT_E(destp->widthMin())); newp = new AstAnd{lfl, newp, new AstConst{lfl, cleanmask}}; } - - addWordAssign(nodep, w, destp, new AstOr{lfl, oldvalp, newp}); + AstNode* const orp + = V3Const::constifyEditCpp(new AstOr{lfl, oldvalp, newp}); + addWordAssign(nodep, w, destp, orp); } } VL_DO_DANGLING(rhsp->deleteTree(), rhsp); @@ -541,7 +544,8 @@ private: AstNode* const shifted = new AstShiftL{ lfl, rhsp, new AstConst{lfl, static_cast(lsb)}, destp->width()}; AstNode* const cleaned = new AstAnd{lfl, shifted, new AstConst{lfl, cleanmask}}; - AstNode* const newp = new AstAssign{nfl, destp, new AstOr{lfl, oldvalp, cleaned}}; + AstNode* const orp = V3Const::constifyEditCpp(new AstOr{lfl, oldvalp, cleaned}); + AstNode* newp = new AstAssign{nfl, destp, orp}; insertBefore(nodep, newp); } return true;