The utility validate_tree (and related validate_tree_filter) were added for future use, but have immediate use in the optimization of T9460, as a solution for the problem raised in T6543. The fixes here allow that application and provide a welcome sanity check.