Iteration of SmallPtrSet's are a cause of non-determinism in codegen because
the iteration order is not fixed. This results in different codegen from
run-to-run, release vs release+asserts and on linux vs windows.
The fix is to use SmallSetVector where the iteration order is deterministic.
This change makes this loop O(n^2), which is not acceptable.