Fix shift-right optmiization, bug763.

This commit is contained in:
Wilson Snyder 2014-05-10 16:38:20 -04:00
parent 1f56312132
commit 6ce2a52c5f
3 changed files with 15 additions and 2 deletions

View File

@ -46,6 +46,8 @@ indicates the contributor was also the author of the fix; Thanks!
**** Fix -Wno-UNOPTFLAT change detection with 64-bits, bug762. [Clifford Wolf]
**** Fix shift-right optimization, bug763. [Clifford Wolf]
**** Fix Mac OS-X test issues. [Holger Waechtler]
**** Fix C++-2011 warnings.

View File

@ -728,9 +728,15 @@ private:
AstNode* ap = lhsp->lhsp()->unlinkFrBack();
AstNode* shift1p = lhsp->rhsp()->unlinkFrBack();
AstNode* shift2p = nodep->rhsp()->unlinkFrBack();
// Shift1p and shift2p may have different sizes, both are self-determined so sum with infinite width
if (nodep->type()==lhsp->type()) {
int shift1 = shift1p->castConst()->toUInt();
int shift2 = shift2p->castConst()->toUInt();
int newshift = shift1+shift2;
shift1p->deleteTree(); shift1p=NULL;
shift2p->deleteTree(); shift2p=NULL;
nodep->lhsp(ap);
nodep->rhsp(new AstAdd(nodep->fileline(), shift1p, shift2p));
nodep->rhsp(new AstConst(nodep->fileline(), newshift));
nodep->accept(*this); // Further reduce, either node may have more reductions.
} else {
// We know shift amounts are constant, but might be a mixed left/right shift
@ -738,7 +744,7 @@ private:
int shift2 = shift2p->castConst()->toUInt(); if (nodep->castShiftR()) shift2=-shift2;
int newshift = shift1+shift2;
shift1p->deleteTree(); shift1p=NULL;
shift2p->deleteTree(); shift1p=NULL;
shift2p->deleteTree(); shift2p=NULL;
AstNode* newp;
V3Number mask1 (nodep->fileline(), nodep->width());
V3Number ones (nodep->fileline(), nodep->width());

View File

@ -111,6 +111,11 @@
w4_u = |0 != (w5_s >>> w3_u);
`checkh(w4_u, 4'b0000);
// bug763
w3_u = 2;
w4_u = (w3_u >> 2'b11) >> 1;
`checkh(w4_u, 4'b0000);
if (fail) $stop;
$write("*-* All Finished *-*\n");
$finish;