This addresses the ARM miscompilation issue described in PR32780.
Problem
When a constant array is promoted to a constant pool, the constant islands pass can create several constpool entries with inlined copies of that array. If the array elements are accessed via multiple pointers, it might happen that the pointers would point to different array copies, thereby making all the operations on these pointers (such as comparison, subtraction, etc) invalid.
Solution
This patch restricts promotion to arrays having one use only, which guarantees that address of a promoted array can be taken only once.
As an extra small benefit, the patch merges similar allUsersAreInFunction and allUsersAreInFunctions functions into a single function to reduce code duplication and, possibly, make it a bit faster.
IsCDAInit seems a bit dubious; for example, you could have a struct which contains an array, or use a scalar as a one-element array, or type-pun a scalar into an array. Or you could even end up comparing the address of a constant against itself.
One use in the IR could lead to more than one use in the actual generated code; for example, consider the case where the only use is a GEP, which feeds into multiple instructions. I think we can solve this, though: since ISel doesn't work across basic blocks, all the uses of the address of the global will be replaced with the return value of promoteToConstantPool. We just need to prevent later passes from trying to rematerialize it, so we have only one instruction which references the constant pool entry by the time we get to the constant islands pass.