https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/242576
This patch implements a clang builtin exposign LLVM's llvm.speculative.load intrinsic, which allows for performing potentially OOB memory accesses, assuming the load will not trap on the underlying hardware and that the program doesn't use the OOB parts of the load. The intrinsic here is set to return a vector. We cannot use the overload that returns a byte value given there is no type in clang currently that lowers to the byte type, and the primary use case for __builtin_speculative_load requires wide types whereas the byte type will most likely only be used for char/std::byte. We can get the same poison spreading semantics as the byte type by using clang-native vectors with 8-bit wide lanes (e.g., char). This is primarily intended to allow for a formally correct implementation of LLVM libc's strlen, which needs speculative loads for a fast implementation. The current implementation already does this, but just does wide loads. Inlining such a strlen implementation (e.g., in (Thin)LTO scenarios) causes problems as the compiler observes that the load accesses memory that is potentially OOB and treats the entire load as UB. _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
