heap-sra-2.ll and heap-sra-phi.ll test that we can perform SROA on a global
variable with only one storer (malloc).
The code does not consider that if a GEP of the storer is used, an arbitrary
element in the allocated array can be modified and we cannot correctly represent
it with a synthesized load of the global variable (some trivial usage e.g.
hasAllZeroIndices can be represented by ad-hoc code but it is clear the
optimization is worth the code complexity). For PR50027 we will get an assertion error
when creating GEP, but we could have correctness issues as well. Simply
disable the unsafe optimization.
Fix PR50027
seems like this doesn't take into account when the global variable is an array.
normally, if we just have a normal struct, the GEP's first operand is the GV, second operand is something like 0, and the third operand indexes into the struct itself, which is fine for SROA. having fewer than 3 operands can directly reference the struct
with an array, we need to account for an extra index to index into the array