Skip to content

Commit

Permalink
Merge pull request #4614 from georgerennie/george/opt_reduce_cell_width
Browse files Browse the repository at this point in the history
opt_reduce: keep at least one input to $reduce_or/and cells
  • Loading branch information
widlarizer authored Nov 20, 2024
2 parents 88abc4c + 0572f88 commit 18459b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions passes/opt/opt_reduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ struct OptReduceWorker
RTLIL::SigSpec new_sig_a(new_sig_a_bits);
new_sig_a.sort_and_unify();

if (GetSize(new_sig_a) == 0)
new_sig_a = (cell->type == ID($reduce_or)) ? State::S0 : State::S1;

if (new_sig_a != sig_a || sig_a.size() != cell->getPort(ID::A).size()) {
log(" New input vector for %s cell %s: %s\n", cell->type.c_str(), cell->name.c_str(), log_signal(new_sig_a));
did_something = true;
Expand Down
14 changes: 14 additions & 0 deletions tests/opt/opt_reduce_andor.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Check that opt_reduce doesn't produce zero width $reduce_or/$reduce_and,

read_verilog <<EOT
module reduce_const(output wire o, output wire a);
wire [3:0] zero = 4'b0000;
wire [3:0] ones = 4'b1111;
assign o = |zero;
assign a = &ones;
endmodule
EOT

equiv_opt -assert opt_reduce
design -load postopt
select -assert-none r:A_WIDTH=0

0 comments on commit 18459b4

Please sign in to comment.