This is a follow-up for D22793, and the [llvm-dev] [RFC] Adding range metadata to array subscripts.: https://groups.google.com/g/llvm-dev/c/T9o51zB1JHY
As per C 6.5.6p9 / http://eel.is/c++draft/expr.add#4, given
struct S { int a[3]; int b[3]; int c[3]; }; void bar(int*); void foo(S* s) { bar(&s.b[1]); }
even though the pointer the bar receives has 4 ints to the left of it and 4 to the right of it,
the only ints it can access are one to the left and one to the right.
I.e. it can not go outside of the S::b.
But, there is currently no way to represent this in LLVM IR,
and this makes some optimizations impossible.
In my case, i'd like to improve alloca splitting,
but this also affects alias analysis.
While that RFC proposed a number of implementation variants,
i think it is obvious that the inrange approach is superiour,
because constant expr GEP's already support that,
and because encoding such knowledge via assumes will make it impossible to make use of it.
Now, GEP's can have a large number of indices,
so even though we have (7-1)+(16-1)=21 vacant bits total in SubclassOptionalData and SubclassData,
we have to support storing the arbitary number of is index inrange bits,
so we have to allocate additional trailing objects.
(I suspect there are bugs in this logic, will add better tests.)
I will add clang support in later changes.