Fix #3824 of wrong bit op tree optimization (#3825)

* Tests: Add a test to reproduce #3824

* Fix #3824 of wrong bitOpTree optimization. Consider constant 1 in an Or-tree made by shift-out.
This commit is contained in:
Yutetsu TAKATSUKASA
2023-01-04 23:10:55 +09:00
committed by GitHub
parent e004ea7ae2
commit 816cff009a
3 changed files with 43 additions and 6 deletions
+7 -3
View File
@@ -560,9 +560,13 @@ class ConstBitOpTreeVisitor final : public VNVisitor {
if (leafInfo.lsb() <= leafInfo.msb()) {
m_bitPolarities.emplace_back(leafInfo, isXorTree() || leafInfo.polarity(),
leafInfo.lsb());
} else if (isAndTree() && leafInfo.polarity()) {
// If there is a constant 0 term in an And tree, we must include it. Fudge
// this by adding a bit with both polarities, which will simplify to zero
} else if ((isAndTree() && leafInfo.polarity())
|| (isOrTree() && !leafInfo.polarity())) {
// If there is a constant 0 term in an And tree or 1 term in an Or tree, we
// must include it. Fudge this by adding a bit with both polarities, which
// will simplify to zero or one respectively.
// Note that Xor tree does not need this kind of care, polarity of Xor tree
// is already cared when visitin AstNot. Taking xor with 1'b0 is nop.
m_bitPolarities.emplace_back(leafInfo, true, 0);
m_bitPolarities.emplace_back(leafInfo, false, 0);
}