Fix redundant AstExtend breaks DFG (#5112)

This commit is contained in:
Wilson Snyder 2024-05-10 18:47:58 -04:00
parent cf111d2e1f
commit d99c8f5d44
2 changed files with 20 additions and 3 deletions

View File

@ -1556,7 +1556,9 @@ class ConstVisitor final : public VNVisitor {
}
return false;
}
bool operandsSameSize(AstNode* lhsp, AstNode* rhsp) { return lhsp->width() == rhsp->width(); }
static bool operandsSameWidth(const AstNode* lhsp, const AstNode* rhsp) {
return lhsp->width() == rhsp->width();
}
//----------------------------------------
// Constant Replacement functions.
@ -3543,7 +3545,7 @@ class ConstVisitor final : public VNVisitor {
TREEOP ("AstMulS {$lhsp.isOne, $rhsp}", "replaceWRhs(nodep)");
TREEOP ("AstDiv {$lhsp, $rhsp.isOne}", "replaceWLhs(nodep)");
TREEOP ("AstDivS {$lhsp, $rhsp.isOne}", "replaceWLhs(nodep)");
TREEOP ("AstMul {operandIsPowTwo($lhsp), operandsSameSize($lhsp,,$rhsp)}", "replaceMulShift(nodep)"); // a*2^n -> a<<n
TREEOP ("AstMul {operandIsPowTwo($lhsp), operandsSameWidth($lhsp,,$rhsp)}", "replaceMulShift(nodep)"); // a*2^n -> a<<n
TREEOP ("AstDiv {$lhsp, operandIsPowTwo($rhsp)}", "replaceDivShift(nodep)"); // a/2^n -> a>>n
TREEOP ("AstModDiv{$lhsp, operandIsPowTwo($rhsp)}", "replaceModAnd(nodep)"); // a % 2^n -> a&(2^n-1)
TREEOP ("AstPow {operandIsTwo($lhsp), !$rhsp.isZero}", "replacePowShift(nodep)"); // 2**a == 1<<a
@ -3737,7 +3739,8 @@ class ConstVisitor final : public VNVisitor {
TREEOPC("AstXor {matchBitOpTree(nodep)}", "DONE");
// Note can't simplify a extend{extends}, extends{extend}, as the sign
// bits end up in the wrong places
TREEOPV("AstExtend {$lhsp.castExtend}", "replaceExtend(nodep, VN_AS(nodep->lhsp(), Extend)->lhsp())");
TREEOPV("AstExtend{operandsSameWidth(nodep,,$lhsp)}", "replaceWLhs(nodep)");
TREEOPV("AstExtend{$lhsp.castExtend}", "replaceExtend(nodep, VN_AS(nodep->lhsp(), Extend)->lhsp())");
TREEOPV("AstExtendS{$lhsp.castExtendS}", "replaceExtend(nodep, VN_AS(nodep->lhsp(), ExtendS)->lhsp())");
TREEOPV("AstReplicate{$srcp, $countp.isOne, $srcp->width()==nodep->width()}", "replaceWLhs(nodep)"); // {1{lhs}}->lhs
TREEOPV("AstReplicateN{$lhsp, $rhsp.isOne, $lhsp->width()==nodep->width()}", "replaceWLhs(nodep)"); // {1{lhs}}->lhs

View File

@ -29,6 +29,10 @@ module t(/*AUTOARG*/
.clk (clk),
.in (in[31:0]));
Test2 test2(/*AUTOINST*/
// Inputs
.clk (clk));
// Aggregate outputs into a single result vector
wire [63:0] result = {32'h0, out};
@ -96,3 +100,13 @@ module Test(/*AUTOARG*/
end
endmodule
module Test2(input wire clk);
reg [127:1][7:0] arrayu;
reg [6:0] index = 0;
wire logic [7:0] selectedu = arrayu[index];
always @(posedge clk) begin
index <= index + 1;
if (index == 2) $display(selectedu);
end
endmodule