opt_share: Fix X and CO signal width for shifted $alu in opt_share.
authorMarcelina Kościelnicka <mwk@0x04.net>
Thu, 14 Jan 2021 08:58:33 +0000 (09:58 +0100)
committerMarcelina Kościelnicka <mwk@0x04.net>
Thu, 14 Jan 2021 13:54:08 +0000 (14:54 +0100)
These need to be the same length as actual Y, not visible part of Y.

Fixes #2538.

passes/opt/opt_share.cc
tests/opt/opt_share_bug2538.ys [new file with mode: 0644]

index 53296699c931234b6ad761ae5ab65a3843398ac5..62a478673cb45b1a4d18213d0b634ea2deb59346 100644 (file)
@@ -244,8 +244,8 @@ void merge_operators(RTLIL::Module *module, RTLIL::Cell *mux, const std::vector<
        }
 
        if (shared_op->type.in(ID($alu))) {
-               shared_op->setPort(ID::X, module->addWire(NEW_ID, GetSize(new_sig_out)));
-               shared_op->setPort(ID::CO, module->addWire(NEW_ID, GetSize(new_sig_out)));
+               shared_op->setPort(ID::X, module->addWire(NEW_ID, GetSize(new_out)));
+               shared_op->setPort(ID::CO, module->addWire(NEW_ID, GetSize(new_out)));
        }
 
        bool is_fine = shared_op->type.in(FINE_BITWISE_OPS);
diff --git a/tests/opt/opt_share_bug2538.ys b/tests/opt/opt_share_bug2538.ys
new file mode 100644 (file)
index 0000000..7261c66
--- /dev/null
@@ -0,0 +1,20 @@
+read_verilog <<EOT
+
+module top(...);
+
+input [3:0] A;
+input S;
+output [1:0] Y;
+
+wire [3:0] A1 = A + 1;
+wire [3:0] A2 = A + 2;
+assign Y = S ? A1[3:2] : A2[3:2];
+
+endmodule
+
+EOT
+
+proc
+alumacc
+equiv_opt -assert opt_share
+