to write a 'logic optimizer'
Those fpga/cpld compilers do precisely that, and many more.
No, they optimize to minimum gate count, or at least to the specific internal architecture of a given CPLD/FPGA such as minimum usage of LUTs in FPGA or summation terms in a CPLD perhaps.
The espresso algorithm works pretty well for pure gate count optimization on this scale, I used a variant of it for programming GALs.
I want to optimize for minimum _chip_ count of a limited set of readily available chips, or find a way to implement it with a specific subset of chips. As in, answering the type of question that started this thread. Also, in addition to the one, zero, and don't care it also must understand things such as open collector, tri-state, and so forth and use resources like the 4066 switch that isn't quite a logic gate but quite handy for simplifying logic circuits.