Fix const-bit-op-tree with single-bit masks (#5993) (#5998)

This commit is contained in:
Yutetsu TAKATSUKASA
2025-05-10 06:01:15 -04:00
committed by GitHub
parent d22608a49f
commit 100e3d7702
3 changed files with 31 additions and 1 deletions
+2
View File
@@ -125,6 +125,7 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst {
void updateBitRange(const AstShiftR* shiftp) {
m_lsb += VN_AS(shiftp->rhsp(), Const)->toUInt();
}
void limitBitRangeToLsb() { m_msb = std::min(m_msb, m_lsb); }
int wordIdx() const { return m_wordIdx; }
void wordIdx(int i) { m_wordIdx = i; }
bool polarity() const { return m_polarity; }
@@ -538,6 +539,7 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst {
Restorer restorer{*this};
incrOps(nodep, __LINE__);
iterateConst(nodep->rhsp());
if (m_leafp) m_leafp->limitBitRangeToLsb();
CONST_BITOP_RETURN_IF(m_failed, nodep->rhsp());
restorer.disableRestore(); // Now all checks passed
} else if (nodep->type() == m_rootp->type()) { // And, Or, Xor