diff --git a/src/V3Cast.cpp b/src/V3Cast.cpp index 0406149c8..de912c72e 100644 --- a/src/V3Cast.cpp +++ b/src/V3Cast.cpp @@ -155,9 +155,10 @@ private: } } virtual void visit(AstVarRef* nodep) override { - if (nodep->access().isReadOnly() && !VN_IS(nodep->backp(), CCast) - && VN_IS(nodep->backp(), NodeMath) && !VN_IS(nodep->backp(), ArraySel) - && nodep->backp()->width() && castSize(nodep) != castSize(nodep->varp())) { + AstNode* const backp = nodep->backp(); + if (nodep->access().isReadOnly() && !VN_IS(backp, CCast) && VN_IS(backp, NodeMath) + && !VN_IS(backp, ArraySel) && !VN_IS(backp, RedXor) && backp->width() + && castSize(nodep) != castSize(nodep->varp())) { // Cast vars to IData first, else below has upper bits wrongly set // CData x=3; out = (QData)(x<<30); insertCast(nodep, castSize(nodep)); diff --git a/src/V3EmitCFunc.h b/src/V3EmitCFunc.h index 03c2b30b7..144307b88 100644 --- a/src/V3EmitCFunc.h +++ b/src/V3EmitCFunc.h @@ -975,8 +975,13 @@ public: if (nodep->lhsp()->isWide()) { visit(VN_CAST(nodep, NodeUniop)); } else { + AstVarRef* const vrefp = VN_CAST(nodep->lhsp(), VarRef); + const int widthPow2 = vrefp ? vrefp->varp()->dtypep()->widthPow2() + : nodep->lhsp()->dtypep()->widthPow2(); + UASSERT_OBJ(widthPow2 > 1, nodep, + "Reduction over single bit value should have been folded"); putbs("VL_REDXOR_"); - puts(cvtToStr(nodep->lhsp()->dtypep()->widthPow2())); + puts(cvtToStr(widthPow2)); puts("("); iterateAndNextNull(nodep->lhsp()); puts(")");