You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Clang] Allow non-constant sizes for __builtin_assume_dereferenceable. (#156929)
Update Clang's __builtin_assume_dereferenceable to support non-constant
lengths. The corresponding assume bundle has been updated to support
non-constant sizes in cad62df.
The current docs for the builtin don't mention the constant requirement
for the size argument, so don't need to be updated:
https://clang.llvm.org/docs/LanguageExtensions.html#builtin-assume-dereferenceable
A number of patches landed recently to make the optimizer make better
use of the dereferenceable assumptions, and once
#156730 lands, it can be used
to vectorize some early-exit loops, for example std::find with
std::vector::iterator: https://godbolt.org/z/qo58PKG37
```
#include <algorithm>
#include <cstddef>
#include <vector>
auto find(std::vector<short>::iterator first, short s, unsigned size) {
auto Addr = __builtin_assume_aligned(std::to_address(first), 2);
__builtin_assume_dereferenceable(std::to_address(first), size * sizeof(short));
return std::find(first, first + size, s);
}
```
PR: #156929
__builtin_assume_dereferenceable(a, a); // expected-error {{cannot initialize a parameter of type '__size_t' (aka 'unsigned long') with an lvalue of type 'int *'}}
0 commit comments