[llvm] [IR] Add llvm.structured.gep instruction (PR #167883)
Nathan Gauër via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 18 08:18:38 PST 2025
================
@@ -14841,6 +14841,180 @@ Semantics:
See the description for :ref:`llvm.stacksave <int_stacksave>`.
+.. _i_structured_gep:
+
+'``llvm.structured.gep``' Intrinsic
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+
+::
+
+ <result> = call ptr llvm.structured.gep <basetype> poison, ptr <source>, {, [i32/i64] <index> }*
+
+Overview:
+"""""""""
+
+The '``llvm.structured.gep``' intrinsic (structured **G**\ et\ **E**\ lement\ **P**\ tr) computes a new pointer address
+resulting of a logical indexing into the ``<source>`` pointer. The returned
+address depends on the indices and may depend on the layout of %basetype at
+runtime.
+
+Arguments:
+""""""""""
+
+``<ty> basetype``:
+The type of the element pointed by the pointer source. This type will be
+used along with the provided indices and source operands to compute a new
+pointer representing the result of a logical indexing into a basetype
+pointed by source.
+The actual value passed is ignored, and should be ``poison``.
+
+``ptr <source>``:
+A pointer to a valid memory location assumed to be large enough to hold a
+completely laid out value with the same type as ``basetype``. The physical
+layout of ``basetype`` is target dependent, and is not always known at
+compile time.
+
+``[i32/i64] index, ...``:
+Indices used to traverse into the basetype and determine the target element
+this instruction computes an offset for. Indices can be 32-bit or 64-bit
+unsigned integers. Indices being handled one by one, both sizes can be mixed
+in the same instruction. The precision used to compute the resulting pointer
+is target-dependent.
----------------
Keenuts wrote:
I'll add the note about constant indices on structs (it's there, but burried in the semantic section).
For the signedness, I'm not sure:
For SPIR-V, OpAccessChain indices are indeed signed, but only positive values are used for logical AFAIK.
> We can be explicit and make only the first index into runtime arrays signed
This assumes you can get a pointer to an element in the middle of a runtime array and still derive a pointer from the wider array using this element address. Not sure if that's something we **need**, and it opens a bunch of complications.
What would that be useful for when doing logical accesses? (That cannot be done with positive indices only)
https://github.com/llvm/llvm-project/pull/167883
More information about the llvm-commits
mailing list