Fix === with some tristate constants (#3551).

This commit is contained in:
Ryszard Rozak 2022-08-18 13:03:05 +02:00 committed by GitHub
parent 951cd73fe0
commit db5fdfb0ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 100 additions and 1 deletions

View File

@ -99,6 +99,7 @@ Rafal Kapuscik
Raynard Qiao Raynard Qiao
Richard Myers Richard Myers
Rupert Swarbrick Rupert Swarbrick
Ryszard Rozak
Samuel Riedel Samuel Riedel
Sean Cross Sean Cross
Sebastien Van Cauwenberghe Sebastien Van Cauwenberghe

View File

@ -937,7 +937,7 @@ class TristateVisitor final : public TristateBaseVisitor {
iterateChildren(nodep); iterateChildren(nodep);
UINFO(9, dbgState() << nodep << endl); UINFO(9, dbgState() << nodep << endl);
// Constification always moves const to LHS // Constification always moves const to LHS
const AstConst* const constp = VN_CAST(nodep->lhsp(), Const); AstConst* const constp = VN_CAST(nodep->lhsp(), Const);
AstVarRef* const varrefp = VN_CAST(nodep->rhsp(), VarRef); // Input variable AstVarRef* const varrefp = VN_CAST(nodep->rhsp(), VarRef); // Input variable
if (constp && constp->user1p() && varrefp) { if (constp && constp->user1p() && varrefp) {
// 3'b1z0 -> ((3'b101 == in__en) && (3'b100 == in)) // 3'b1z0 -> ((3'b101 == in__en) && (3'b100 == in))
@ -960,6 +960,21 @@ class TristateVisitor final : public TristateBaseVisitor {
if (debug() >= 9) newp->dumpTree(cout, "-caseeq-new: "); if (debug() >= 9) newp->dumpTree(cout, "-caseeq-new: ");
nodep->replaceWith(newp); nodep->replaceWith(newp);
VL_DO_DANGLING(pushDeletep(nodep), nodep); VL_DO_DANGLING(pushDeletep(nodep), nodep);
} else if (constp && nodep->rhsp()->user1p()) {
FileLine* const fl = nodep->fileline();
constp->unlinkFrBack();
AstNode* const rhsp = nodep->rhsp()->unlinkFrBack();
AstNode* newp = new AstLogAnd{
fl, new AstEq{fl, newAllZerosOrOnes(constp, false), rhsp->user1p()},
// Keep the caseeq if there are X's present
new AstEqCase{fl, constp, rhsp}};
if (neq) newp = new AstLogNot{fl, newp};
rhsp->user1p(nullptr);
UINFO(9, " newceq " << newp << endl);
if (debug() >= 9) nodep->dumpTree(cout, "-caseeq-old: ");
if (debug() >= 9) newp->dumpTree(cout, "-caseeq-new: ");
nodep->replaceWith(newp);
VL_DO_DANGLING(pushDeletep(nodep), nodep);
} else { } else {
checkUnhandled(nodep); checkUnhandled(nodep);
} }

View File

@ -0,0 +1,21 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2022 by Antmicro Ltd. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
scenarios(simulator => 1);
compile(
);
execute(
check_finished => 1,
);
ok(1);
1;

View File

@ -0,0 +1,21 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2022 by Antmicro Ltd.
// SPDX-License-Identifier: CC0-1.0
module t (/*AUTOARG*/
// Inputs
clk
);
input clk;
wire a;
assign a = 1 === (clk ? 1 : 1'bz);
always begin
if (!a) begin
$write("*-* All Finished *-*\n");
$finish;
end
end
endmodule

View File

@ -0,0 +1,21 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2022 by Antmicro Ltd. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
scenarios(simulator => 1);
compile(
);
execute(
check_finished => 1,
);
ok(1);
1;

View File

@ -0,0 +1,20 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2022 by Antmicro Ltd.
// SPDX-License-Identifier: CC0-1.0
module t (/*AUTOARG*/
// Inputs
clk
);
input clk;
wire a = 1'bz === clk;
always begin
if (a) begin
$write("*-* All Finished *-*\n");
$finish;
end
end
endmodule