The attached patch is a new version that fixes the iteration order by using MapVector in the two cases we were iterating over a DenseMap. I have emailed the patch implementing MapVector to llvm-commits, but I guess this review is fairly independent of the MapVector implementation itself. Cheers, Rafael