3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-03-23 04:49:15 +00:00

opt_expr: Respect keep attribute for double-inverter folding

The double-inverter optimization in opt_expr folds consecutive NOT gates
without checking if the cell has the keep attribute. This causes ring
oscillator PUFs and other intentional feedback loops to be broken even
when explicitly marked for preservation.

This patch adds a has_keep_attr() check before folding double inverters,
consistent with how opt_clean handles the keep attribute.

Fixes: Ring oscillator cells marked with (* keep *) being optimized away

Signed-off-by: Sabina Sokol <Sabina.Sokol@gtri.gatech.edu>
This commit is contained in:
Sabina Sokol 2026-03-10 13:39:06 -04:00 committed by Sabina Sokol
parent de99d67bbd
commit 841a29496d

View file

@ -1056,6 +1056,7 @@ skip_fine_alu:
}
if (cell->type.in(ID($_NOT_), ID($not), ID($logic_not)) && GetSize(cell->getPort(ID::Y)) == 1 &&
!cell->has_keep_attr() &&
invert_map.count(assign_map(cell->getPort(ID::A))) != 0) {
replace_cell(assign_map, module, cell, "double_invert", ID::Y, invert_map.at(assign_map(cell->getPort(ID::A))));
goto next_cell;