HPCC-12408 Various code generator optimizations

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Can you double check that this logic (OR -> AND) is correct please.