HPCC-12408 Various code generator optimizations

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Still doesn't make sense. i.e.

should be reduced, the base cursor (which should really be) the base cursor should be reduced
should reduce the base cursor
should be reduced to the base cursor
 etc etc etc...