Fix mis-optimized identical submodule subtract, bug581. Take 2.

This commit is contained in:
Wilson Snyder 2012-11-28 20:18:41 -05:00
parent 30f6c0e105
commit c7a088faa5
3 changed files with 17 additions and 13 deletions

View File

@ -1135,10 +1135,17 @@ struct AstVarRef : public AstNodeVarRef {
ASTNODE_NODE_FUNCS(VarRef, VARREF)
virtual void dump(ostream& str);
virtual V3Hash sameHash() const { return V3Hash(V3Hash(varp()->name()),V3Hash(hiername())); }
virtual bool same(AstNode* samep) const {
if (varScopep()) return varScopep()==samep->castVarRef()->varScopep();
else return (hiername()==samep->castVarRef()->hiername()
&& varp()->name()==samep->castVarRef()->varp()->name()); }
virtual bool same(AstNode* samep) const { return same(samep->castVarRef()); }
inline bool same(AstVarRef* samep) const {
if (varScopep()) return (varScopep()==samep->varScopep()
&& lvalue()==samep->lvalue());
else return (hiername()==samep->hiername()
&& varp()->name()==samep->varp()->name()
&& lvalue()==samep->lvalue()); }
inline bool sameNoLvalue(AstVarRef* samep) const {
if (varScopep()) return (varScopep()==samep->varScopep());
else return (hiername()==samep->hiername()
&& varp()->name()==samep->varp()->name()); }
virtual int instrCount() const { return widthInstrs()*(lvalue()?1:instrCountLd()); }
virtual string emitVerilog() { V3ERROR_NA; return ""; } // Implemented specially
virtual string emitC() { V3ERROR_NA; return ""; }

View File

@ -415,9 +415,7 @@ private:
// Avoid comparing widthMin's, which results in lost optimization attempts
// If cleanup sameTree to be smarter, this can be restored.
//return node1p->sameTree(node2p);
return node1p->castVarRef()->varp() == node2p->castVarRef()->varp()
&& node1p->castVarRef()->varScopep() == node2p->castVarRef()->varScopep()
&& node1p->castVarRef()->lvalue() == node2p->castVarRef()->lvalue();
return node1p->same(node2p);
} else {
return false;
}
@ -432,7 +430,7 @@ private:
AstVarRef* elsevarp = elsep->lhsp()->castVarRef();
if (!ifvarp || !elsevarp) return false;
if (ifvarp->isWide()) return false; // Would need temporaries, so not worth it
if (ifvarp->varp() != elsevarp->varp()) return false;
if (!ifvarp->sameTree(elsevarp)) return false;
return true;
}
bool operandIfIf(AstNodeIf* nodep) {
@ -777,7 +775,7 @@ private:
AstSel* sel2p = nextp->lhsp()->castSel(); if (!sel2p) return false;
AstVarRef* varref1p = sel1p->fromp()->castVarRef(); if (!varref1p) return false;
AstVarRef* varref2p = sel2p->fromp()->castVarRef(); if (!varref2p) return false;
if (varref1p->varp() != varref2p->varp()) return false;
if (!varref1p->sameTree(varref2p)) return false;
AstConst* con1p = sel1p->lsbp()->castConst(); if (!con1p) return false;
AstConst* con2p = sel2p->lsbp()->castConst(); if (!con2p) return false;
// We need to make sure there's no self-references involved in either
@ -828,7 +826,7 @@ private:
bool replaceNodeAssign(AstNodeAssign* nodep) {
if (nodep->lhsp()->castVarRef()
&& nodep->rhsp()->castVarRef()
&& nodep->lhsp()->sameTree(nodep->rhsp())
&& nodep->lhsp()->castVarRef()->sameNoLvalue(nodep->rhsp()->castVarRef())
&& !nodep->castAssignDly()) {
// X = X. Quite pointless, though X <= X may override another earlier assignment
if (nodep->castAssignW()) {

View File

@ -55,7 +55,7 @@ module t (/*AUTOARG*/
$write("[%0t] cyc==%0d crc=%x sum=%x\n",$time, cyc, crc, sum);
if (crc !== 64'hc77bb9b3784ea091) $stop;
// What checksum will we end up with (above print should match)
`define EXPECTED_SUM 64'hf15989544a22e48a
`define EXPECTED_SUM 64'h8a78c2ec4946ac38
if (sum !== `EXPECTED_SUM) $stop;
$write("*-* All Finished *-*\n");
$finish;
@ -218,8 +218,6 @@ module clz(
reg [2:0] clz_byte2;
reg [2:0] clz_byte3;
assign out = data_i[6:0];
always @*
case (data_i)
`def_1xxx_xxxx : clz_byte0 = 3'b000;
@ -275,6 +273,7 @@ module clz(
default : clz_byte3 = 3'bxxx;
endcase
assign out = {4'b0000, clz_byte1};
endmodule // clz