@@ -267,8 +267,8 @@ bool compare_signals(RTLIL::SigBit &s1, RTLIL::SigBit &s2, SigPool ®s, SigPoo
267267 return regs.check (s2);
268268 if (direct_wires.count (w1) != direct_wires.count (w2))
269269 return direct_wires.count (w2) != 0 ;
270- if (conns.check_any (s1) != conns.check_any (s2))
271- return conns.check_any (s2);
270+ if (conns.check (s1) != conns.check (s2))
271+ return conns.check (s2);
272272 }
273273
274274 if (w1->port_output != w2->port_output )
@@ -304,6 +304,7 @@ bool rmunused_module_signals(RTLIL::Module *module, bool purge_mode, bool verbos
304304 // on picking representatives out of groups of connected signals
305305 SigPool register_signals;
306306 SigPool connected_signals;
307+ std::vector<SigSpec> maybe_driven_signals;
307308 if (!purge_mode)
308309 for (auto &it : module ->cells_ ) {
309310 RTLIL::Cell *cell = it.second ;
@@ -313,12 +314,36 @@ bool rmunused_module_signals(RTLIL::Module *module, bool purge_mode, bool verbos
313314 if (clk2fflogic ? it2.first == ID::D : ct_reg.cell_output (cell->type , it2.first ))
314315 register_signals.add (it2.second );
315316 }
316- for (auto &it2 : cell->connections ())
317+ for (auto &it2 : cell->connections ()) {
317318 connected_signals.add (it2.second );
319+ if (!ct_all.cell_known (cell->type ) || ct_all.cell_output (cell->type , it2.first ))
320+ maybe_driven_signals.push_back (it2.second );
321+ }
318322 }
319323
320324 SigMap assign_map (module );
325+ SigPool maybe_driven_signals_bits;
321326
327+ for (auto sig : maybe_driven_signals) {
328+ for (auto bit : sig) {
329+ maybe_driven_signals_bits.add (assign_map (bit));
330+ }
331+ }
332+ for (auto &it : module ->wires_ ) {
333+ RTLIL::SigSpec sig = it.second ;
334+ if (it.second ->port_id != 0 ) {
335+ maybe_driven_signals_bits.add (assign_map (sig));
336+ }
337+ }
338+ for (auto &it : module ->wires_ ) {
339+ RTLIL::SigSpec sig = it.second ;
340+ for (auto bit : sig) {
341+ if (!maybe_driven_signals_bits.check (assign_map (bit))) {
342+ log (" add conn %s <-> %s to assign_map\n " , log_signal (bit), log_signal (SigBit (State::Sx)));
343+ assign_map.add (bit, SigBit (State::Sx));
344+ }
345+ }
346+ }
322347 // construct a pool of wires which are directly driven by a known celltype,
323348 // this will influence our choice of representatives
324349 pool<RTLIL::Wire*> direct_wires;
0 commit comments