This patch adds a dereferencable attribute. In some sense, this is a companion to the nonnull attribute, but specifies that the pointer is known to be dereferencable in the same sense as a pointer generated by alloca is known to be dereferencable.
My primary use case for this is C++ references that are passes as function parameters and used in loops. For example,
void foo(int * restrict a, int * restrict b, int &c, int n) {
for (int i = 0; i < n; ++i) if (a[i] > 0) a[i] = c*b[i];
}
Currently, we generate a load of 'c' in every loop iteration because we can't prove that there is no control dependence on the dereferencability of 'c' from the if condition. But because 'c' is a reference, we know it must point to something, and since nothing else in the loop can alias it, it is safe to load it in the preheader.
(there is a simple companion Clang patch, which I'll also post.)
The obvious question left by the documentation is what's the difference between 'nonnull' and 'dereferencable'? Spelling this out explicitly would be helpful.