Fix optimization of entry slices
Periodic entry selections are compacted into a slice, but that slice cannot actually be carried through the optimizer. This MR fixes this by actually encoding them, allowing their optimization across trains as a side product.
There are also two further small fixes for said compacted slices from selections missing their last element, as well as very few instructions (less than the minimal compaction amount) being dropped entirely.