proc_prune: Promote partially redundant assignments.
authorJean-François Nguyen <jf@lambdaconcept.com>
Wed, 31 Jul 2019 12:26:09 +0000 (14:26 +0200)
committerJean-François Nguyen <jf@lambdaconcept.com>
Thu, 1 Aug 2019 11:09:55 +0000 (13:09 +0200)
passes/proc/proc_prune.cc

index 9e00b0a8a23e0757e0b53e59d8e30ac9b4223a68..b47ee79c2fd5136f38eb6148e981ac1e17d042a9 100644 (file)
@@ -82,14 +82,23 @@ struct PruneWorker
                                if (root) {
                                        bool promotable = true;
                                        for (auto &bit : lhs) {
-                                               if (bit.wire && affected[bit]) {
+                                               if (bit.wire && affected[bit] && !assigned[bit]) {
                                                        promotable = false;
                                                        break;
                                                }
                                        }
                                        if (promotable) {
+                                               RTLIL::SigSpec rhs = sigmap(it->second);
+                                               RTLIL::SigSig conn;
+                                               for (int i = 0; i < GetSize(lhs); i++) {
+                                                       RTLIL::SigBit lhs_bit = lhs[i];
+                                                       if (lhs_bit.wire && !assigned[lhs_bit]) {
+                                                               conn.first.append_bit(lhs_bit);
+                                                               conn.second.append(rhs.extract(i));
+                                                       }
+                                               }
                                                promoted_count++;
-                                               module->connect(*it);
+                                               module->connect(conn);
                                                remove.insert(*it);
                                        }
                                }