GVN: rangify a couple of loops.

No functionality change.
GVN: Fix non-determinism in map iteration.

Iterating over a DenseMaop is non-deterministic and results to unpredictable IR
output.

Based on a patch by Daniel Reynaud!