This function previously used tail recursion as part of the use-list sorting to support round-tripping use-list orders to disk. While this is fine for small lists or when the compiler binary is itself is optimized, the combination of a debug build and a very large use list will overflow the runtime stack. Hence it is rewritten to use an explicit loop.
Due to the size of any file of this magnitude and the dependence on the runtime stack limit, no test-case is provided. This issue came up when testing a new pass on a bitcode file of most of Chromium, using a debug build of LLVM. On my machine, this crashes with something on the order of ~200,000 uses of a Value, which overflows the default Linux 8MB stack.