tdk: improve to_policy for filter case

Special case to_policy when the two subdiagrams are filters. When that's
the case, the code can generate a filter as a result rather than a
policy.
tdk: fix unit tests to identify new compiler output

The fixes were mostly related to ordering of expressions, and some
additional simplification that the new compiler performs.