The solution to that is to have two stages of compilation: the first produces a binary with a general instruction set, and the second produces a binary with an instruction set specific to the machine it's installed on. (Though even with that approach you probably still need microcode)
The Mill architecture supposedly does this; the ISA has three variants for different product lines.