We're seeing intermittent failures in upstream bots. See:
https://lab.llvm.org/buildbot/#/builders/139/builds/29185
https://lab.llvm.org/buildbot/#/builders/238/builds/295
This appears to be due to the unstable iteration order of DenseSet. Since we're trying to reduce a tree, it makes sense to attempt reductions from the top down.
This also addresses post-review comments from @MatzeB.