[llvm] Provide intrinsics for speculative loads (PR #179642)

Ralf Jung via llvm-commits llvm-commits at lists.llvm.org
Wed May 13 07:47:01 PDT 2026


================
@@ -28184,6 +28184,139 @@ Semantics:
 
 Follows the same semantics as :ref:`srem <i_srem>` with the exception that disabled lanes cannot produce undefined behaviour and always result in poison.
 
+Speculative Load Intrinsics
+---------------------------
+
+LLVM provides intrinsics for speculatively loading memory that may be
+out-of-bounds. These intrinsics enable optimizations like early-exit loop
+vectorization where the vectorized loop may read beyond the end of an array,
+provided the access is guaranteed to be valid by target-specific checks.
+
+.. _int_speculative_load:
+
+'``llvm.speculative.load``' Intrinsic
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+This is an overloaded intrinsic.
+
+::
+
+      ; Direct form: number of accessible bytes given as i64
+      declare <4 x float>  @llvm.speculative.load.v4f32.p0(ptr <ptr>, i1 <from_end>, i64 <num_accessible_bytes>)
+      declare <8 x i32>    @llvm.speculative.load.v8i32.p0(ptr <ptr>, i1 <from_end>, i64 <num_accessible_bytes>)
+
+      ; Oracle form: accessible bytes computed by calling oracle_fn(args...)
+      declare <4 x float>  @llvm.speculative.load.v4f32.p0(ptr <ptr>, i1 <from_end>, ptr <oracle_fn>, ...)
+
+Overview:
+"""""""""
+
+The '``llvm.speculative.load``' intrinsic loads a value from memory. Unlike a
+regular load, the memory access may extend beyond the bounds of the allocated
+object, provided the pointer has been verified by
+:ref:`llvm.can.load.speculatively <int_can_load_speculatively>` to ensure the
+access is valid.
+
+Arguments:
+""""""""""
+
+The first argument is a pointer to the memory location to load from. The return
+type must be a vector type with a power-of-2 size in bytes. The second argument
----------------
RalfJung wrote:

Or we make it return a byte typed value, so the user can then deal with partial poison in whatever way fits their needs?

https://github.com/llvm/llvm-project/pull/179642


More information about the llvm-commits mailing list