Miscellaneous updates from keithp
Found these in an old branch, reordered them into a vaguely coherent sequence but otherwise these are all @keithp's work. This fixes a few behavioural issues, tweaks some tests to defeat some driver optimizations, and adds a few tests.