From 4a404bd92e0b81d1a1aaa010ab376b35243a68fd Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Sat, 6 Jun 2020 00:16:16 +0100 Subject: [PATCH] Always mask LSB in V3Merge Cond when mergin AstAnd --- src/V3MergeCond.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/V3MergeCond.cpp b/src/V3MergeCond.cpp index 30edff29c..483d32c15 100644 --- a/src/V3MergeCond.cpp +++ b/src/V3MergeCond.cpp @@ -153,17 +153,16 @@ private: return NULL; } - // Apply (_ & 1'b1), iff node is wider than 1 bit. This is necessary - // because this pass is after V3Clean, and sometimes we have an AstAnd with - // a 1-bit condition on one side, but a more than 1-bit value on the other - // side, so we need to keep only the LSB. + // Apply (_ & 1'b1). This is necessary because this pass is after V3Clean, + // and sometimes we have an AstAnd with a 1-bit condition on one side, but + // a more than 1-bit value on the other side, so we need to keep only the + // LSB. Ideally we would only do this iff the node is known not to be 1-bit + // wide, but working that out here is a bit difficult. As this masking is + // rarely required (only when trying to merge a "cond & value" with an + // earlier ternary), we will just always mask it for safety. AstNode* maskLsb(AstNode* nodep) { - if (nodep->width1()) { - return nodep; - } else { - AstNode* const maskp = new AstConst(nodep->fileline(), AstConst::LogicTrue()); - return new AstAnd(nodep->fileline(), nodep, maskp); - } + AstNode* const maskp = new AstConst(nodep->fileline(), AstConst::LogicTrue()); + return new AstAnd(nodep->fileline(), nodep, maskp); } // Fold the RHS expression assuming the given condition state. Unlink bits