xref: /llvm-project-15.0.7/llvm/docs/LangRef.rst (revision 77b72fbc)
1==============================
2LLVM Language Reference Manual
3==============================
4
5.. contents::
6   :local:
7   :depth: 4
8
9Abstract
10========
11
12This document is a reference manual for the LLVM assembly language. LLVM
13is a Static Single Assignment (SSA) based representation that provides
14type safety, low-level operations, flexibility, and the capability of
15representing 'all' high-level languages cleanly. It is the common code
16representation used throughout all phases of the LLVM compilation
17strategy.
18
19Introduction
20============
21
22The LLVM code representation is designed to be used in three different
23forms: as an in-memory compiler IR, as an on-disk bitcode representation
24(suitable for fast loading by a Just-In-Time compiler), and as a human
25readable assembly language representation. This allows LLVM to provide a
26powerful intermediate representation for efficient compiler
27transformations and analysis, while providing a natural means to debug
28and visualize the transformations. The three different forms of LLVM are
29all equivalent. This document describes the human readable
30representation and notation.
31
32The LLVM representation aims to be light-weight and low-level while
33being expressive, typed, and extensible at the same time. It aims to be
34a "universal IR" of sorts, by being at a low enough level that
35high-level ideas may be cleanly mapped to it (similar to how
36microprocessors are "universal IR's", allowing many source languages to
37be mapped to them). By providing type information, LLVM can be used as
38the target of optimizations: for example, through pointer analysis, it
39can be proven that a C automatic variable is never accessed outside of
40the current function, allowing it to be promoted to a simple SSA value
41instead of a memory location.
42
43.. _wellformed:
44
45Well-Formedness
46---------------
47
48It is important to note that this document describes 'well formed' LLVM
49assembly language. There is a difference between what the parser accepts
50and what is considered 'well formed'. For example, the following
51instruction is syntactically okay, but not well formed:
52
53.. code-block:: llvm
54
55    %x = add i32 1, %x
56
57because the definition of ``%x`` does not dominate all of its uses. The
58LLVM infrastructure provides a verification pass that may be used to
59verify that an LLVM module is well formed. This pass is automatically
60run by the parser after parsing input assembly and by the optimizer
61before it outputs bitcode. The violations pointed out by the verifier
62pass indicate bugs in transformation passes or input to the parser.
63
64.. _identifiers:
65
66Identifiers
67===========
68
69LLVM identifiers come in two basic types: global and local. Global
70identifiers (functions, global variables) begin with the ``'@'``
71character. Local identifiers (register names, types) begin with the
72``'%'`` character. Additionally, there are three different formats for
73identifiers, for different purposes:
74
75#. Named values are represented as a string of characters with their
76   prefix. For example, ``%foo``, ``@DivisionByZero``,
77   ``%a.really.long.identifier``. The actual regular expression used is
78   '``[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*``'. Identifiers that require other
79   characters in their names can be surrounded with quotes. Special
80   characters may be escaped using ``"\xx"`` where ``xx`` is the ASCII
81   code for the character in hexadecimal. In this way, any character can
82   be used in a name value, even quotes themselves. The ``"\01"`` prefix
83   can be used on global values to suppress mangling.
84#. Unnamed values are represented as an unsigned numeric value with
85   their prefix. For example, ``%12``, ``@2``, ``%44``.
86#. Constants, which are described in the section Constants_ below.
87
88LLVM requires that values start with a prefix for two reasons: Compilers
89don't need to worry about name clashes with reserved words, and the set
90of reserved words may be expanded in the future without penalty.
91Additionally, unnamed identifiers allow a compiler to quickly come up
92with a temporary variable without having to avoid symbol table
93conflicts.
94
95Reserved words in LLVM are very similar to reserved words in other
96languages. There are keywords for different opcodes ('``add``',
97'``bitcast``', '``ret``', etc...), for primitive type names ('``void``',
98'``i32``', etc...), and others. These reserved words cannot conflict
99with variable names, because none of them start with a prefix character
100(``'%'`` or ``'@'``).
101
102Here is an example of LLVM code to multiply the integer variable
103'``%X``' by 8:
104
105The easy way:
106
107.. code-block:: llvm
108
109    %result = mul i32 %X, 8
110
111After strength reduction:
112
113.. code-block:: llvm
114
115    %result = shl i32 %X, 3
116
117And the hard way:
118
119.. code-block:: llvm
120
121    %0 = add i32 %X, %X           ; yields i32:%0
122    %1 = add i32 %0, %0           ; yields i32:%1
123    %result = add i32 %1, %1
124
125This last way of multiplying ``%X`` by 8 illustrates several important
126lexical features of LLVM:
127
128#. Comments are delimited with a '``;``' and go until the end of line.
129#. Unnamed temporaries are created when the result of a computation is
130   not assigned to a named value.
131#. Unnamed temporaries are numbered sequentially (using a per-function
132   incrementing counter, starting with 0). Note that basic blocks and unnamed
133   function parameters are included in this numbering. For example, if the
134   entry basic block is not given a label name and all function parameters are
135   named, then it will get number 0.
136
137It also shows a convention that we follow in this document. When
138demonstrating instructions, we will follow an instruction with a comment
139that defines the type and name of value produced.
140
141High Level Structure
142====================
143
144Module Structure
145----------------
146
147LLVM programs are composed of ``Module``'s, each of which is a
148translation unit of the input programs. Each module consists of
149functions, global variables, and symbol table entries. Modules may be
150combined together with the LLVM linker, which merges function (and
151global variable) definitions, resolves forward declarations, and merges
152symbol table entries. Here is an example of the "hello world" module:
153
154.. code-block:: llvm
155
156    ; Declare the string constant as a global constant.
157    @.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
158
159    ; External declaration of the puts function
160    declare i32 @puts(i8* nocapture) nounwind
161
162    ; Definition of main function
163    define i32 @main() {   ; i32()*
164      ; Convert [13 x i8]* to i8*...
165      %cast210 = getelementptr [13 x i8], [13 x i8]* @.str, i64 0, i64 0
166
167      ; Call puts function to write out the string to stdout.
168      call i32 @puts(i8* %cast210)
169      ret i32 0
170    }
171
172    ; Named metadata
173    !0 = !{i32 42, null, !"string"}
174    !foo = !{!0}
175
176This example is made up of a :ref:`global variable <globalvars>` named
177"``.str``", an external declaration of the "``puts``" function, a
178:ref:`function definition <functionstructure>` for "``main``" and
179:ref:`named metadata <namedmetadatastructure>` "``foo``".
180
181In general, a module is made up of a list of global values (where both
182functions and global variables are global values). Global values are
183represented by a pointer to a memory location (in this case, a pointer
184to an array of char, and a pointer to a function), and have one of the
185following :ref:`linkage types <linkage>`.
186
187.. _linkage:
188
189Linkage Types
190-------------
191
192All Global Variables and Functions have one of the following types of
193linkage:
194
195``private``
196    Global values with "``private``" linkage are only directly
197    accessible by objects in the current module. In particular, linking
198    code into a module with a private global value may cause the
199    private to be renamed as necessary to avoid collisions. Because the
200    symbol is private to the module, all references can be updated. This
201    doesn't show up in any symbol table in the object file.
202``internal``
203    Similar to private, but the value shows as a local symbol
204    (``STB_LOCAL`` in the case of ELF) in the object file. This
205    corresponds to the notion of the '``static``' keyword in C.
206``available_externally``
207    Globals with "``available_externally``" linkage are never emitted into
208    the object file corresponding to the LLVM module. From the linker's
209    perspective, an ``available_externally`` global is equivalent to
210    an external declaration. They exist to allow inlining and other
211    optimizations to take place given knowledge of the definition of the
212    global, which is known to be somewhere outside the module. Globals
213    with ``available_externally`` linkage are allowed to be discarded at
214    will, and allow inlining and other optimizations. This linkage type is
215    only allowed on definitions, not declarations.
216``linkonce``
217    Globals with "``linkonce``" linkage are merged with other globals of
218    the same name when linkage occurs. This can be used to implement
219    some forms of inline functions, templates, or other code which must
220    be generated in each translation unit that uses it, but where the
221    body may be overridden with a more definitive definition later.
222    Unreferenced ``linkonce`` globals are allowed to be discarded. Note
223    that ``linkonce`` linkage does not actually allow the optimizer to
224    inline the body of this function into callers because it doesn't
225    know if this definition of the function is the definitive definition
226    within the program or whether it will be overridden by a stronger
227    definition. To enable inlining and other optimizations, use
228    "``linkonce_odr``" linkage.
229``weak``
230    "``weak``" linkage has the same merging semantics as ``linkonce``
231    linkage, except that unreferenced globals with ``weak`` linkage may
232    not be discarded. This is used for globals that are declared "weak"
233    in C source code.
234``common``
235    "``common``" linkage is most similar to "``weak``" linkage, but they
236    are used for tentative definitions in C, such as "``int X;``" at
237    global scope. Symbols with "``common``" linkage are merged in the
238    same way as ``weak symbols``, and they may not be deleted if
239    unreferenced. ``common`` symbols may not have an explicit section,
240    must have a zero initializer, and may not be marked
241    ':ref:`constant <globalvars>`'. Functions and aliases may not have
242    common linkage.
243
244.. _linkage_appending:
245
246``appending``
247    "``appending``" linkage may only be applied to global variables of
248    pointer to array type. When two global variables with appending
249    linkage are linked together, the two global arrays are appended
250    together. This is the LLVM, typesafe, equivalent of having the
251    system linker append together "sections" with identical names when
252    .o files are linked.
253
254    Unfortunately this doesn't correspond to any feature in .o files, so it
255    can only be used for variables like ``llvm.global_ctors`` which llvm
256    interprets specially.
257
258``extern_weak``
259    The semantics of this linkage follow the ELF object file model: the
260    symbol is weak until linked, if not linked, the symbol becomes null
261    instead of being an undefined reference.
262``linkonce_odr``, ``weak_odr``
263    Some languages allow differing globals to be merged, such as two
264    functions with different semantics. Other languages, such as
265    ``C++``, ensure that only equivalent globals are ever merged (the
266    "one definition rule" --- "ODR"). Such languages can use the
267    ``linkonce_odr`` and ``weak_odr`` linkage types to indicate that the
268    global will only be merged with equivalent globals. These linkage
269    types are otherwise the same as their non-``odr`` versions.
270``external``
271    If none of the above identifiers are used, the global is externally
272    visible, meaning that it participates in linkage and can be used to
273    resolve external symbol references.
274
275It is illegal for a global variable or function *declaration* to have any
276linkage type other than ``external`` or ``extern_weak``.
277
278.. _callingconv:
279
280Calling Conventions
281-------------------
282
283LLVM :ref:`functions <functionstructure>`, :ref:`calls <i_call>` and
284:ref:`invokes <i_invoke>` can all have an optional calling convention
285specified for the call. The calling convention of any pair of dynamic
286caller/callee must match, or the behavior of the program is undefined.
287The following calling conventions are supported by LLVM, and more may be
288added in the future:
289
290"``ccc``" - The C calling convention
291    This calling convention (the default if no other calling convention
292    is specified) matches the target C calling conventions. This calling
293    convention supports varargs function calls and tolerates some
294    mismatch in the declared prototype and implemented declaration of
295    the function (as does normal C).
296"``fastcc``" - The fast calling convention
297    This calling convention attempts to make calls as fast as possible
298    (e.g. by passing things in registers). This calling convention
299    allows the target to use whatever tricks it wants to produce fast
300    code for the target, without having to conform to an externally
301    specified ABI (Application Binary Interface). `Tail calls can only
302    be optimized when this, the tailcc, the GHC or the HiPE convention is
303    used. <CodeGenerator.html#tail-call-optimization>`_ This calling
304    convention does not support varargs and requires the prototype of all
305    callees to exactly match the prototype of the function definition.
306"``coldcc``" - The cold calling convention
307    This calling convention attempts to make code in the caller as
308    efficient as possible under the assumption that the call is not
309    commonly executed. As such, these calls often preserve all registers
310    so that the call does not break any live ranges in the caller side.
311    This calling convention does not support varargs and requires the
312    prototype of all callees to exactly match the prototype of the
313    function definition. Furthermore the inliner doesn't consider such function
314    calls for inlining.
315"``cc 10``" - GHC convention
316    This calling convention has been implemented specifically for use by
317    the `Glasgow Haskell Compiler (GHC) <http://www.haskell.org/ghc>`_.
318    It passes everything in registers, going to extremes to achieve this
319    by disabling callee save registers. This calling convention should
320    not be used lightly but only for specific situations such as an
321    alternative to the *register pinning* performance technique often
322    used when implementing functional programming languages. At the
323    moment only X86 supports this convention and it has the following
324    limitations:
325
326    -  On *X86-32* only supports up to 4 bit type parameters. No
327       floating-point types are supported.
328    -  On *X86-64* only supports up to 10 bit type parameters and 6
329       floating-point parameters.
330
331    This calling convention supports `tail call
332    optimization <CodeGenerator.html#tail-call-optimization>`_ but requires
333    both the caller and callee are using it.
334"``cc 11``" - The HiPE calling convention
335    This calling convention has been implemented specifically for use by
336    the `High-Performance Erlang
337    (HiPE) <http://www.it.uu.se/research/group/hipe/>`_ compiler, *the*
338    native code compiler of the `Ericsson's Open Source Erlang/OTP
339    system <http://www.erlang.org/download.shtml>`_. It uses more
340    registers for argument passing than the ordinary C calling
341    convention and defines no callee-saved registers. The calling
342    convention properly supports `tail call
343    optimization <CodeGenerator.html#tail-call-optimization>`_ but requires
344    that both the caller and the callee use it. It uses a *register pinning*
345    mechanism, similar to GHC's convention, for keeping frequently
346    accessed runtime components pinned to specific hardware registers.
347    At the moment only X86 supports this convention (both 32 and 64
348    bit).
349"``webkit_jscc``" - WebKit's JavaScript calling convention
350    This calling convention has been implemented for `WebKit FTL JIT
351    <https://trac.webkit.org/wiki/FTLJIT>`_. It passes arguments on the
352    stack right to left (as cdecl does), and returns a value in the
353    platform's customary return register.
354"``anyregcc``" - Dynamic calling convention for code patching
355    This is a special convention that supports patching an arbitrary code
356    sequence in place of a call site. This convention forces the call
357    arguments into registers but allows them to be dynamically
358    allocated. This can currently only be used with calls to
359    llvm.experimental.patchpoint because only this intrinsic records
360    the location of its arguments in a side table. See :doc:`StackMaps`.
361"``preserve_mostcc``" - The `PreserveMost` calling convention
362    This calling convention attempts to make the code in the caller as
363    unintrusive as possible. This convention behaves identically to the `C`
364    calling convention on how arguments and return values are passed, but it
365    uses a different set of caller/callee-saved registers. This alleviates the
366    burden of saving and recovering a large register set before and after the
367    call in the caller. If the arguments are passed in callee-saved registers,
368    then they will be preserved by the callee across the call. This doesn't
369    apply for values returned in callee-saved registers.
370
371    - On X86-64 the callee preserves all general purpose registers, except for
372      R11. R11 can be used as a scratch register. Floating-point registers
373      (XMMs/YMMs) are not preserved and need to be saved by the caller.
374
375    The idea behind this convention is to support calls to runtime functions
376    that have a hot path and a cold path. The hot path is usually a small piece
377    of code that doesn't use many registers. The cold path might need to call out to
378    another function and therefore only needs to preserve the caller-saved
379    registers, which haven't already been saved by the caller. The
380    `PreserveMost` calling convention is very similar to the `cold` calling
381    convention in terms of caller/callee-saved registers, but they are used for
382    different types of function calls. `coldcc` is for function calls that are
383    rarely executed, whereas `preserve_mostcc` function calls are intended to be
384    on the hot path and definitely executed a lot. Furthermore `preserve_mostcc`
385    doesn't prevent the inliner from inlining the function call.
386
387    This calling convention will be used by a future version of the ObjectiveC
388    runtime and should therefore still be considered experimental at this time.
389    Although this convention was created to optimize certain runtime calls to
390    the ObjectiveC runtime, it is not limited to this runtime and might be used
391    by other runtimes in the future too. The current implementation only
392    supports X86-64, but the intention is to support more architectures in the
393    future.
394"``preserve_allcc``" - The `PreserveAll` calling convention
395    This calling convention attempts to make the code in the caller even less
396    intrusive than the `PreserveMost` calling convention. This calling
397    convention also behaves identical to the `C` calling convention on how
398    arguments and return values are passed, but it uses a different set of
399    caller/callee-saved registers. This removes the burden of saving and
400    recovering a large register set before and after the call in the caller. If
401    the arguments are passed in callee-saved registers, then they will be
402    preserved by the callee across the call. This doesn't apply for values
403    returned in callee-saved registers.
404
405    - On X86-64 the callee preserves all general purpose registers, except for
406      R11. R11 can be used as a scratch register. Furthermore it also preserves
407      all floating-point registers (XMMs/YMMs).
408
409    The idea behind this convention is to support calls to runtime functions
410    that don't need to call out to any other functions.
411
412    This calling convention, like the `PreserveMost` calling convention, will be
413    used by a future version of the ObjectiveC runtime and should be considered
414    experimental at this time.
415"``cxx_fast_tlscc``" - The `CXX_FAST_TLS` calling convention for access functions
416    Clang generates an access function to access C++-style TLS. The access
417    function generally has an entry block, an exit block and an initialization
418    block that is run at the first time. The entry and exit blocks can access
419    a few TLS IR variables, each access will be lowered to a platform-specific
420    sequence.
421
422    This calling convention aims to minimize overhead in the caller by
423    preserving as many registers as possible (all the registers that are
424    preserved on the fast path, composed of the entry and exit blocks).
425
426    This calling convention behaves identical to the `C` calling convention on
427    how arguments and return values are passed, but it uses a different set of
428    caller/callee-saved registers.
429
430    Given that each platform has its own lowering sequence, hence its own set
431    of preserved registers, we can't use the existing `PreserveMost`.
432
433    - On X86-64 the callee preserves all general purpose registers, except for
434      RDI and RAX.
435"``tailcc``" - Tail callable calling convention
436    This calling convention ensures that calls in tail position will always be
437    tail call optimized. This calling convention is equivalent to fastcc,
438    except for an additional guarantee that tail calls will be produced
439    whenever possible. `Tail calls can only be optimized when this, the fastcc,
440    the GHC or the HiPE convention is used. <CodeGenerator.html#tail-call-optimization>`_
441    This calling convention does not support varargs and requires the prototype of
442    all callees to exactly match the prototype of the function definition.
443"``swiftcc``" - This calling convention is used for Swift language.
444    - On X86-64 RCX and R8 are available for additional integer returns, and
445      XMM2 and XMM3 are available for additional FP/vector returns.
446    - On iOS platforms, we use AAPCS-VFP calling convention.
447"``swifttailcc``"
448    This calling convention is like ``swiftcc`` in most respects, but also the
449    callee pops the argument area of the stack so that mandatory tail calls are
450    possible as in ``tailcc``.
451"``cfguard_checkcc``" - Windows Control Flow Guard (Check mechanism)
452    This calling convention is used for the Control Flow Guard check function,
453    calls to which can be inserted before indirect calls to check that the call
454    target is a valid function address. The check function has no return value,
455    but it will trigger an OS-level error if the address is not a valid target.
456    The set of registers preserved by the check function, and the register
457    containing the target address are architecture-specific.
458
459    - On X86 the target address is passed in ECX.
460    - On ARM the target address is passed in R0.
461    - On AArch64 the target address is passed in X15.
462"``cc <n>``" - Numbered convention
463    Any calling convention may be specified by number, allowing
464    target-specific calling conventions to be used. Target specific
465    calling conventions start at 64.
466
467More calling conventions can be added/defined on an as-needed basis, to
468support Pascal conventions or any other well-known target-independent
469convention.
470
471.. _visibilitystyles:
472
473Visibility Styles
474-----------------
475
476All Global Variables and Functions have one of the following visibility
477styles:
478
479"``default``" - Default style
480    On targets that use the ELF object file format, default visibility
481    means that the declaration is visible to other modules and, in
482    shared libraries, means that the declared entity may be overridden.
483    On Darwin, default visibility means that the declaration is visible
484    to other modules. On XCOFF, default visibility means no explicit
485    visibility bit will be set and whether the symbol is visible
486    (i.e "exported") to other modules depends primarily on export lists
487    provided to the linker. Default visibility corresponds to "external
488    linkage" in the language.
489"``hidden``" - Hidden style
490    Two declarations of an object with hidden visibility refer to the
491    same object if they are in the same shared object. Usually, hidden
492    visibility indicates that the symbol will not be placed into the
493    dynamic symbol table, so no other module (executable or shared
494    library) can reference it directly.
495"``protected``" - Protected style
496    On ELF, protected visibility indicates that the symbol will be
497    placed in the dynamic symbol table, but that references within the
498    defining module will bind to the local symbol. That is, the symbol
499    cannot be overridden by another module.
500
501A symbol with ``internal`` or ``private`` linkage must have ``default``
502visibility.
503
504.. _dllstorageclass:
505
506DLL Storage Classes
507-------------------
508
509All Global Variables, Functions and Aliases can have one of the following
510DLL storage class:
511
512``dllimport``
513    "``dllimport``" causes the compiler to reference a function or variable via
514    a global pointer to a pointer that is set up by the DLL exporting the
515    symbol. On Microsoft Windows targets, the pointer name is formed by
516    combining ``__imp_`` and the function or variable name.
517``dllexport``
518    On Microsoft Windows targets, "``dllexport``" causes the compiler to provide
519    a global pointer to a pointer in a DLL, so that it can be referenced with the
520    ``dllimport`` attribute. the pointer name is formed by combining ``__imp_``
521    and the function or variable name. On XCOFF targets, ``dllexport`` indicates
522    that the symbol will be made visible to other modules using "exported"
523    visibility and thus placed by the linker in the loader section symbol table.
524    Since this storage class exists for defining a dll interface, the compiler,
525    assembler and linker know it is externally referenced and must refrain from
526    deleting the symbol.
527
528.. _tls_model:
529
530Thread Local Storage Models
531---------------------------
532
533A variable may be defined as ``thread_local``, which means that it will
534not be shared by threads (each thread will have a separated copy of the
535variable). Not all targets support thread-local variables. Optionally, a
536TLS model may be specified:
537
538``localdynamic``
539    For variables that are only used within the current shared library.
540``initialexec``
541    For variables in modules that will not be loaded dynamically.
542``localexec``
543    For variables defined in the executable and only used within it.
544
545If no explicit model is given, the "general dynamic" model is used.
546
547The models correspond to the ELF TLS models; see `ELF Handling For
548Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for
549more information on under which circumstances the different models may
550be used. The target may choose a different TLS model if the specified
551model is not supported, or if a better choice of model can be made.
552
553A model can also be specified in an alias, but then it only governs how
554the alias is accessed. It will not have any effect in the aliasee.
555
556For platforms without linker support of ELF TLS model, the -femulated-tls
557flag can be used to generate GCC compatible emulated TLS code.
558
559.. _runtime_preemption_model:
560
561Runtime Preemption Specifiers
562-----------------------------
563
564Global variables, functions and aliases may have an optional runtime preemption
565specifier. If a preemption specifier isn't given explicitly, then a
566symbol is assumed to be ``dso_preemptable``.
567
568``dso_preemptable``
569    Indicates that the function or variable may be replaced by a symbol from
570    outside the linkage unit at runtime.
571
572``dso_local``
573    The compiler may assume that a function or variable marked as ``dso_local``
574    will resolve to a symbol within the same linkage unit. Direct access will
575    be generated even if the definition is not within this compilation unit.
576
577.. _namedtypes:
578
579Structure Types
580---------------
581
582LLVM IR allows you to specify both "identified" and "literal" :ref:`structure
583types <t_struct>`. Literal types are uniqued structurally, but identified types
584are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used
585to forward declare a type that is not yet available.
586
587An example of an identified structure specification is:
588
589.. code-block:: llvm
590
591    %mytype = type { %mytype*, i32 }
592
593Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only
594literal types are uniqued in recent versions of LLVM.
595
596.. _nointptrtype:
597
598Non-Integral Pointer Type
599-------------------------
600
601Note: non-integral pointer types are a work in progress, and they should be
602considered experimental at this time.
603
604LLVM IR optionally allows the frontend to denote pointers in certain address
605spaces as "non-integral" via the :ref:`datalayout string<langref_datalayout>`.
606Non-integral pointer types represent pointers that have an *unspecified* bitwise
607representation; that is, the integral representation may be target dependent or
608unstable (not backed by a fixed integer).
609
610``inttoptr`` and ``ptrtoint`` instructions have the same semantics as for
611integral (i.e. normal) pointers in that they convert integers to and from
612corresponding pointer types, but there are additional implications to be
613aware of.  Because the bit-representation of a non-integral pointer may
614not be stable, two identical casts of the same operand may or may not
615return the same value.  Said differently, the conversion to or from the
616non-integral type depends on environmental state in an implementation
617defined manner.
618
619If the frontend wishes to observe a *particular* value following a cast, the
620generated IR must fence with the underlying environment in an implementation
621defined manner. (In practice, this tends to require ``noinline`` routines for
622such operations.)
623
624From the perspective of the optimizer, ``inttoptr`` and ``ptrtoint`` for
625non-integral types are analogous to ones on integral types with one
626key exception: the optimizer may not, in general, insert new dynamic
627occurrences of such casts.  If a new cast is inserted, the optimizer would
628need to either ensure that a) all possible values are valid, or b)
629appropriate fencing is inserted.  Since the appropriate fencing is
630implementation defined, the optimizer can't do the latter.  The former is
631challenging as many commonly expected properties, such as
632``ptrtoint(v)-ptrtoint(v) == 0``, don't hold for non-integral types.
633
634.. _globalvars:
635
636Global Variables
637----------------
638
639Global variables define regions of memory allocated at compilation time
640instead of run-time.
641
642Global variable definitions must be initialized.
643
644Global variables in other translation units can also be declared, in which
645case they don't have an initializer.
646
647Global variables can optionally specify a :ref:`linkage type <linkage>`.
648
649Either global variable definitions or declarations may have an explicit section
650to be placed in and may have an optional explicit alignment specified. If there
651is a mismatch between the explicit or inferred section information for the
652variable declaration and its definition the resulting behavior is undefined.
653
654A variable may be defined as a global ``constant``, which indicates that
655the contents of the variable will **never** be modified (enabling better
656optimization, allowing the global data to be placed in the read-only
657section of an executable, etc). Note that variables that need runtime
658initialization cannot be marked ``constant`` as there is a store to the
659variable.
660
661LLVM explicitly allows *declarations* of global variables to be marked
662constant, even if the final definition of the global is not. This
663capability can be used to enable slightly better optimization of the
664program, but requires the language definition to guarantee that
665optimizations based on the 'constantness' are valid for the translation
666units that do not include the definition.
667
668As SSA values, global variables define pointer values that are in scope
669(i.e. they dominate) all basic blocks in the program. Global variables
670always define a pointer to their "content" type because they describe a
671region of memory, and all memory objects in LLVM are accessed through
672pointers.
673
674Global variables can be marked with ``unnamed_addr`` which indicates
675that the address is not significant, only the content. Constants marked
676like this can be merged with other constants if they have the same
677initializer. Note that a constant with significant address *can* be
678merged with a ``unnamed_addr`` constant, the result being a constant
679whose address is significant.
680
681If the ``local_unnamed_addr`` attribute is given, the address is known to
682not be significant within the module.
683
684A global variable may be declared to reside in a target-specific
685numbered address space. For targets that support them, address spaces
686may affect how optimizations are performed and/or what target
687instructions are used to access the variable. The default address space
688is zero. The address space qualifier must precede any other attributes.
689
690LLVM allows an explicit section to be specified for globals. If the
691target supports it, it will emit globals to the section specified.
692Additionally, the global can placed in a comdat if the target has the necessary
693support.
694
695External declarations may have an explicit section specified. Section
696information is retained in LLVM IR for targets that make use of this
697information. Attaching section information to an external declaration is an
698assertion that its definition is located in the specified section. If the
699definition is located in a different section, the behavior is undefined.
700
701By default, global initializers are optimized by assuming that global
702variables defined within the module are not modified from their
703initial values before the start of the global initializer. This is
704true even for variables potentially accessible from outside the
705module, including those with external linkage or appearing in
706``@llvm.used`` or dllexported variables. This assumption may be suppressed
707by marking the variable with ``externally_initialized``.
708
709An explicit alignment may be specified for a global, which must be a
710power of 2. If not present, or if the alignment is set to zero, the
711alignment of the global is set by the target to whatever it feels
712convenient. If an explicit alignment is specified, the global is forced
713to have exactly that alignment. Targets and optimizers are not allowed
714to over-align the global if the global has an assigned section. In this
715case, the extra alignment could be observable: for example, code could
716assume that the globals are densely packed in their section and try to
717iterate over them as an array, alignment padding would break this
718iteration. The maximum alignment is ``1 << 32``.
719
720For global variables declarations, as well as definitions that may be
721replaced at link time (``linkonce``, ``weak``, ``extern_weak`` and ``common``
722linkage types), LLVM makes no assumptions about the allocation size of the
723variables, except that they may not overlap. The alignment of a global variable
724declaration or replaceable definition must not be greater than the alignment of
725the definition it resolves to.
726
727Globals can also have a :ref:`DLL storage class <dllstorageclass>`,
728an optional :ref:`runtime preemption specifier <runtime_preemption_model>`,
729an optional :ref:`global attributes <glattrs>` and
730an optional list of attached :ref:`metadata <metadata>`.
731
732Variables and aliases can have a
733:ref:`Thread Local Storage Model <tls_model>`.
734
735:ref:`Scalable vectors <t_vector>` cannot be global variables or members of
736arrays because their size is unknown at compile time. They are allowed in
737structs to facilitate intrinsics returning multiple values. Structs containing
738scalable vectors cannot be used in loads, stores, allocas, or GEPs.
739
740Syntax::
741
742      @<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility]
743                         [DLLStorageClass] [ThreadLocal]
744                         [(unnamed_addr|local_unnamed_addr)] [AddrSpace]
745                         [ExternallyInitialized]
746                         <global | constant> <Type> [<InitializerConstant>]
747                         [, section "name"] [, partition "name"]
748                         [, comdat [($name)]] [, align <Alignment>]
749                         [, no_sanitize_address] [, no_sanitize_hwaddress]
750                         [, sanitize_address_dyninit] [, sanitize_memtag]
751                         (, !name !N)*
752
753For example, the following defines a global in a numbered address space
754with an initializer, section, and alignment:
755
756.. code-block:: llvm
757
758    @G = addrspace(5) constant float 1.0, section "foo", align 4
759
760The following example just declares a global variable
761
762.. code-block:: llvm
763
764   @G = external global i32
765
766The following example defines a thread-local global with the
767``initialexec`` TLS model:
768
769.. code-block:: llvm
770
771    @G = thread_local(initialexec) global i32 0, align 4
772
773.. _functionstructure:
774
775Functions
776---------
777
778LLVM function definitions consist of the "``define``" keyword, an
779optional :ref:`linkage type <linkage>`, an optional :ref:`runtime preemption
780specifier <runtime_preemption_model>`,  an optional :ref:`visibility
781style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`,
782an optional :ref:`calling convention <callingconv>`,
783an optional ``unnamed_addr`` attribute, a return type, an optional
784:ref:`parameter attribute <paramattrs>` for the return type, a function
785name, a (possibly empty) argument list (each with optional :ref:`parameter
786attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`,
787an optional address space, an optional section, an optional partition,
788an optional alignment, an optional :ref:`comdat <langref_comdats>`,
789an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`,
790an optional :ref:`prologue <prologuedata>`,
791an optional :ref:`personality <personalityfn>`,
792an optional list of attached :ref:`metadata <metadata>`,
793an opening curly brace, a list of basic blocks, and a closing curly brace.
794
795Syntax::
796
797    define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass]
798           [cconv] [ret attrs]
799           <ResultType> @<FunctionName> ([argument list])
800           [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs]
801           [section "name"] [partition "name"] [comdat [($name)]] [align N]
802           [gc] [prefix Constant] [prologue Constant] [personality Constant]
803           (!name !N)* { ... }
804
805The argument list is a comma separated sequence of arguments where each
806argument is of the following form:
807
808Syntax::
809
810   <type> [parameter Attrs] [name]
811
812LLVM function declarations consist of the "``declare``" keyword, an
813optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style
814<visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an
815optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr``
816or ``local_unnamed_addr`` attribute, an optional address space, a return type,
817an optional :ref:`parameter attribute <paramattrs>` for the return type, a function name, a possibly
818empty list of arguments, an optional alignment, an optional :ref:`garbage
819collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional
820:ref:`prologue <prologuedata>`.
821
822Syntax::
823
824    declare [linkage] [visibility] [DLLStorageClass]
825            [cconv] [ret attrs]
826            <ResultType> @<FunctionName> ([argument list])
827            [(unnamed_addr|local_unnamed_addr)] [align N] [gc]
828            [prefix Constant] [prologue Constant]
829
830A function definition contains a list of basic blocks, forming the CFG (Control
831Flow Graph) for the function. Each basic block may optionally start with a label
832(giving the basic block a symbol table entry), contains a list of instructions,
833and ends with a :ref:`terminator <terminators>` instruction (such as a branch or
834function return). If an explicit label name is not provided, a block is assigned
835an implicit numbered label, using the next value from the same counter as used
836for unnamed temporaries (:ref:`see above<identifiers>`). For example, if a
837function entry block does not have an explicit label, it will be assigned label
838"%0", then the first unnamed temporary in that block will be "%1", etc. If a
839numeric label is explicitly specified, it must match the numeric label that
840would be used implicitly.
841
842The first basic block in a function is special in two ways: it is
843immediately executed on entrance to the function, and it is not allowed
844to have predecessor basic blocks (i.e. there can not be any branches to
845the entry block of a function). Because the block can have no
846predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`.
847
848LLVM allows an explicit section to be specified for functions. If the
849target supports it, it will emit functions to the section specified.
850Additionally, the function can be placed in a COMDAT.
851
852An explicit alignment may be specified for a function. If not present,
853or if the alignment is set to zero, the alignment of the function is set
854by the target to whatever it feels convenient. If an explicit alignment
855is specified, the function is forced to have at least that much
856alignment. All alignments must be a power of 2.
857
858If the ``unnamed_addr`` attribute is given, the address is known to not
859be significant and two identical functions can be merged.
860
861If the ``local_unnamed_addr`` attribute is given, the address is known to
862not be significant within the module.
863
864If an explicit address space is not given, it will default to the program
865address space from the :ref:`datalayout string<langref_datalayout>`.
866
867.. _langref_aliases:
868
869Aliases
870-------
871
872Aliases, unlike function or variables, don't create any new data. They
873are just a new symbol and metadata for an existing position.
874
875Aliases have a name and an aliasee that is either a global value or a
876constant expression.
877
878Aliases may have an optional :ref:`linkage type <linkage>`, an optional
879:ref:`runtime preemption specifier <runtime_preemption_model>`, an optional
880:ref:`visibility style <visibility>`, an optional :ref:`DLL storage class
881<dllstorageclass>` and an optional :ref:`tls model <tls_model>`.
882
883Syntax::
884
885    @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee>
886              [, partition "name"]
887
888The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
889``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
890might not correctly handle dropping a weak symbol that is aliased.
891
892Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
893the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
894to the same content.
895
896If the ``local_unnamed_addr`` attribute is given, the address is known to
897not be significant within the module.
898
899Since aliases are only a second name, some restrictions apply, of which
900some can only be checked when producing an object file:
901
902* The expression defining the aliasee must be computable at assembly
903  time. Since it is just a name, no relocations can be used.
904
905* No alias in the expression can be weak as the possibility of the
906  intermediate alias being overridden cannot be represented in an
907  object file.
908
909* No global value in the expression can be a declaration, since that
910  would require a relocation, which is not possible.
911
912* If either the alias or the aliasee may be replaced by a symbol outside the
913  module at link time or runtime, any optimization cannot replace the alias with
914  the aliasee, since the behavior may be different. The alias may be used as a
915  name guaranteed to point to the content in the current module.
916
917.. _langref_ifunc:
918
919IFuncs
920-------
921
922IFuncs, like as aliases, don't create any new data or func. They are just a new
923symbol that dynamic linker resolves at runtime by calling a resolver function.
924
925IFuncs have a name and a resolver that is a function called by dynamic linker
926that returns address of another function associated with the name.
927
928IFunc may have an optional :ref:`linkage type <linkage>` and an optional
929:ref:`visibility style <visibility>`.
930
931Syntax::
932
933    @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver>
934              [, partition "name"]
935
936
937.. _langref_comdats:
938
939Comdats
940-------
941
942Comdat IR provides access to object file COMDAT/section group functionality
943which represents interrelated sections.
944
945Comdats have a name which represents the COMDAT key and a selection kind to
946provide input on how the linker deduplicates comdats with the same key in two
947different object files. A comdat must be included or omitted as a unit.
948Discarding the whole comdat is allowed but discarding a subset is not.
949
950A global object may be a member of at most one comdat. Aliases are placed in the
951same COMDAT that their aliasee computes to, if any.
952
953Syntax::
954
955    $<Name> = comdat SelectionKind
956
957For selection kinds other than ``nodeduplicate``, only one of the duplicate
958comdats may be retained by the linker and the members of the remaining comdats
959must be discarded. The following selection kinds are supported:
960
961``any``
962    The linker may choose any COMDAT key, the choice is arbitrary.
963``exactmatch``
964    The linker may choose any COMDAT key but the sections must contain the
965    same data.
966``largest``
967    The linker will choose the section containing the largest COMDAT key.
968``nodeduplicate``
969    No deduplication is performed.
970``samesize``
971    The linker may choose any COMDAT key but the sections must contain the
972    same amount of data.
973
974- XCOFF and Mach-O don't support COMDATs.
975- COFF supports all selection kinds. Non-``nodeduplicate`` selection kinds need
976  a non-local linkage COMDAT symbol.
977- ELF supports ``any`` and ``nodeduplicate``.
978- WebAssembly only supports ``any``.
979
980Here is an example of a COFF COMDAT where a function will only be selected if
981the COMDAT key's section is the largest:
982
983.. code-block:: text
984
985   $foo = comdat largest
986   @foo = global i32 2, comdat($foo)
987
988   define void @bar() comdat($foo) {
989     ret void
990   }
991
992In a COFF object file, this will create a COMDAT section with selection kind
993``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol
994and another COMDAT section with selection kind
995``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT
996section and contains the contents of the ``@bar`` symbol.
997
998As a syntactic sugar the ``$name`` can be omitted if the name is the same as
999the global name:
1000
1001.. code-block:: llvm
1002
1003  $foo = comdat any
1004  @foo = global i32 2, comdat
1005  @bar = global i32 3, comdat($foo)
1006
1007There are some restrictions on the properties of the global object.
1008It, or an alias to it, must have the same name as the COMDAT group when
1009targeting COFF.
1010The contents and size of this object may be used during link-time to determine
1011which COMDAT groups get selected depending on the selection kind.
1012Because the name of the object must match the name of the COMDAT group, the
1013linkage of the global object must not be local; local symbols can get renamed
1014if a collision occurs in the symbol table.
1015
1016The combined use of COMDATS and section attributes may yield surprising results.
1017For example:
1018
1019.. code-block:: llvm
1020
1021   $foo = comdat any
1022   $bar = comdat any
1023   @g1 = global i32 42, section "sec", comdat($foo)
1024   @g2 = global i32 42, section "sec", comdat($bar)
1025
1026From the object file perspective, this requires the creation of two sections
1027with the same name. This is necessary because both globals belong to different
1028COMDAT groups and COMDATs, at the object file level, are represented by
1029sections.
1030
1031Note that certain IR constructs like global variables and functions may
1032create COMDATs in the object file in addition to any which are specified using
1033COMDAT IR. This arises when the code generator is configured to emit globals
1034in individual sections (e.g. when `-data-sections` or `-function-sections`
1035is supplied to `llc`).
1036
1037.. _namedmetadatastructure:
1038
1039Named Metadata
1040--------------
1041
1042Named metadata is a collection of metadata. :ref:`Metadata
1043nodes <metadata>` (but not metadata strings) are the only valid
1044operands for a named metadata.
1045
1046#. Named metadata are represented as a string of characters with the
1047   metadata prefix. The rules for metadata names are the same as for
1048   identifiers, but quoted names are not allowed. ``"\xx"`` type escapes
1049   are still valid, which allows any character to be part of a name.
1050
1051Syntax::
1052
1053    ; Some unnamed metadata nodes, which are referenced by the named metadata.
1054    !0 = !{!"zero"}
1055    !1 = !{!"one"}
1056    !2 = !{!"two"}
1057    ; A named metadata.
1058    !name = !{!0, !1, !2}
1059
1060.. _paramattrs:
1061
1062Parameter Attributes
1063--------------------
1064
1065The return type and each parameter of a function type may have a set of
1066*parameter attributes* associated with them. Parameter attributes are
1067used to communicate additional information about the result or
1068parameters of a function. Parameter attributes are considered to be part
1069of the function, not of the function type, so functions with different
1070parameter attributes can have the same function type.
1071
1072Parameter attributes are simple keywords that follow the type specified.
1073If multiple parameter attributes are needed, they are space separated.
1074For example:
1075
1076.. code-block:: llvm
1077
1078    declare i32 @printf(i8* noalias nocapture, ...)
1079    declare i32 @atoi(i8 zeroext)
1080    declare signext i8 @returns_signed_char()
1081
1082Note that any attributes for the function result (``nounwind``,
1083``readonly``) come immediately after the argument list.
1084
1085Currently, only the following parameter attributes are defined:
1086
1087``zeroext``
1088    This indicates to the code generator that the parameter or return
1089    value should be zero-extended to the extent required by the target's
1090    ABI by the caller (for a parameter) or the callee (for a return value).
1091``signext``
1092    This indicates to the code generator that the parameter or return
1093    value should be sign-extended to the extent required by the target's
1094    ABI (which is usually 32-bits) by the caller (for a parameter) or
1095    the callee (for a return value).
1096``inreg``
1097    This indicates that this parameter or return value should be treated
1098    in a special target-dependent fashion while emitting code for
1099    a function call or return (usually, by putting it in a register as
1100    opposed to memory, though some targets use it to distinguish between
1101    two different kinds of registers). Use of this attribute is
1102    target-specific.
1103``byval(<ty>)``
1104    This indicates that the pointer parameter should really be passed by
1105    value to the function. The attribute implies that a hidden copy of
1106    the pointee is made between the caller and the callee, so the callee
1107    is unable to modify the value in the caller. This attribute is only
1108    valid on LLVM pointer arguments. It is generally used to pass
1109    structs and arrays by value, but is also valid on pointers to
1110    scalars. The copy is considered to belong to the caller not the
1111    callee (for example, ``readonly`` functions should not write to
1112    ``byval`` parameters). This is not a valid attribute for return
1113    values.
1114
1115    The byval type argument indicates the in-memory value type, and
1116    must be the same as the pointee type of the argument.
1117
1118    The byval attribute also supports specifying an alignment with the
1119    align attribute. It indicates the alignment of the stack slot to
1120    form and the known alignment of the pointer specified to the call
1121    site. If the alignment is not specified, then the code generator
1122    makes a target-specific assumption.
1123
1124.. _attr_byref:
1125
1126``byref(<ty>)``
1127
1128    The ``byref`` argument attribute allows specifying the pointee
1129    memory type of an argument. This is similar to ``byval``, but does
1130    not imply a copy is made anywhere, or that the argument is passed
1131    on the stack. This implies the pointer is dereferenceable up to
1132    the storage size of the type.
1133
1134    It is not generally permissible to introduce a write to an
1135    ``byref`` pointer. The pointer may have any address space and may
1136    be read only.
1137
1138    This is not a valid attribute for return values.
1139
1140    The alignment for an ``byref`` parameter can be explicitly
1141    specified by combining it with the ``align`` attribute, similar to
1142    ``byval``. If the alignment is not specified, then the code generator
1143    makes a target-specific assumption.
1144
1145    This is intended for representing ABI constraints, and is not
1146    intended to be inferred for optimization use.
1147
1148.. _attr_preallocated:
1149
1150``preallocated(<ty>)``
1151    This indicates that the pointer parameter should really be passed by
1152    value to the function, and that the pointer parameter's pointee has
1153    already been initialized before the call instruction. This attribute
1154    is only valid on LLVM pointer arguments. The argument must be the value
1155    returned by the appropriate
1156    :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` on non
1157    ``musttail`` calls, or the corresponding caller parameter in ``musttail``
1158    calls, although it is ignored during codegen.
1159
1160    A non ``musttail`` function call with a ``preallocated`` attribute in
1161    any parameter must have a ``"preallocated"`` operand bundle. A ``musttail``
1162    function call cannot have a ``"preallocated"`` operand bundle.
1163
1164    The preallocated attribute requires a type argument, which must be
1165    the same as the pointee type of the argument.
1166
1167    The preallocated attribute also supports specifying an alignment with the
1168    align attribute. It indicates the alignment of the stack slot to
1169    form and the known alignment of the pointer specified to the call
1170    site. If the alignment is not specified, then the code generator
1171    makes a target-specific assumption.
1172
1173.. _attr_inalloca:
1174
1175``inalloca(<ty>)``
1176
1177    The ``inalloca`` argument attribute allows the caller to take the
1178    address of outgoing stack arguments. An ``inalloca`` argument must
1179    be a pointer to stack memory produced by an ``alloca`` instruction.
1180    The alloca, or argument allocation, must also be tagged with the
1181    inalloca keyword. Only the last argument may have the ``inalloca``
1182    attribute, and that argument is guaranteed to be passed in memory.
1183
1184    An argument allocation may be used by a call at most once because
1185    the call may deallocate it. The ``inalloca`` attribute cannot be
1186    used in conjunction with other attributes that affect argument
1187    storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The
1188    ``inalloca`` attribute also disables LLVM's implicit lowering of
1189    large aggregate return values, which means that frontend authors
1190    must lower them with ``sret`` pointers.
1191
1192    When the call site is reached, the argument allocation must have
1193    been the most recent stack allocation that is still live, or the
1194    behavior is undefined. It is possible to allocate additional stack
1195    space after an argument allocation and before its call site, but it
1196    must be cleared off with :ref:`llvm.stackrestore
1197    <int_stackrestore>`.
1198
1199    The inalloca attribute requires a type argument, which must be the
1200    same as the pointee type of the argument.
1201
1202    See :doc:`InAlloca` for more information on how to use this
1203    attribute.
1204
1205``sret(<ty>)``
1206    This indicates that the pointer parameter specifies the address of a
1207    structure that is the return value of the function in the source
1208    program. This pointer must be guaranteed by the caller to be valid:
1209    loads and stores to the structure may be assumed by the callee not
1210    to trap and to be properly aligned. This is not a valid attribute
1211    for return values.
1212
1213    The sret type argument specifies the in memory type, which must be
1214    the same as the pointee type of the argument.
1215
1216.. _attr_elementtype:
1217
1218``elementtype(<ty>)``
1219
1220    The ``elementtype`` argument attribute can be used to specify a pointer
1221    element type in a way that is compatible with `opaque pointers
1222    <OpaquePointers.html>`__.
1223
1224    The ``elementtype`` attribute by itself does not carry any specific
1225    semantics. However, certain intrinsics may require this attribute to be
1226    present and assign it particular semantics. This will be documented on
1227    individual intrinsics.
1228
1229    The attribute may only be applied to pointer typed arguments of intrinsic
1230    calls. It cannot be applied to non-intrinsic calls, and cannot be applied
1231    to parameters on function declarations. For non-opaque pointers, the type
1232    passed to ``elementtype`` must match the pointer element type.
1233
1234.. _attr_align:
1235
1236``align <n>`` or ``align(<n>)``
1237    This indicates that the pointer value or vector of pointers has the
1238    specified alignment. If applied to a vector of pointers, *all* pointers
1239    (elements) have the specified alignment. If the pointer value does not have
1240    the specified alignment, :ref:`poison value <poisonvalues>` is returned or
1241    passed instead.  The ``align`` attribute should be combined with the
1242    ``noundef`` attribute to ensure a pointer is aligned, or otherwise the
1243    behavior is undefined. Note that ``align 1`` has no effect on non-byval,
1244    non-preallocated arguments.
1245
1246    Note that this attribute has additional semantics when combined with the
1247    ``byval`` or ``preallocated`` attribute, which are documented there.
1248
1249.. _noalias:
1250
1251``noalias``
1252    This indicates that memory locations accessed via pointer values
1253    :ref:`based <pointeraliasing>` on the argument or return value are not also
1254    accessed, during the execution of the function, via pointer values not
1255    *based* on the argument or return value. This guarantee only holds for
1256    memory locations that are *modified*, by any means, during the execution of
1257    the function. The attribute on a return value also has additional semantics
1258    described below. The caller shares the responsibility with the callee for
1259    ensuring that these requirements are met.  For further details, please see
1260    the discussion of the NoAlias response in :ref:`alias analysis <Must, May,
1261    or No>`.
1262
1263    Note that this definition of ``noalias`` is intentionally similar
1264    to the definition of ``restrict`` in C99 for function arguments.
1265
1266    For function return values, C99's ``restrict`` is not meaningful,
1267    while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias``
1268    attribute on return values are stronger than the semantics of the attribute
1269    when used on function arguments. On function return values, the ``noalias``
1270    attribute indicates that the function acts like a system memory allocation
1271    function, returning a pointer to allocated storage disjoint from the
1272    storage for any other object accessible to the caller.
1273
1274.. _nocapture:
1275
1276``nocapture``
1277    This indicates that the callee does not :ref:`capture <pointercapture>` the
1278    pointer. This is not a valid attribute for return values.
1279    This attribute applies only to the particular copy of the pointer passed in
1280    this argument. A caller could pass two copies of the same pointer with one
1281    being annotated nocapture and the other not, and the callee could validly
1282    capture through the non annotated parameter.
1283
1284.. code-block:: llvm
1285
1286    define void @f(i8* nocapture %a, i8* %b) {
1287      ; (capture %b)
1288    }
1289
1290    call void @f(i8* @glb, i8* @glb) ; well-defined
1291
1292``nofree``
1293    This indicates that callee does not free the pointer argument. This is not
1294    a valid attribute for return values.
1295
1296.. _nest:
1297
1298``nest``
1299    This indicates that the pointer parameter can be excised using the
1300    :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid
1301    attribute for return values and can only be applied to one parameter.
1302
1303``returned``
1304    This indicates that the function always returns the argument as its return
1305    value. This is a hint to the optimizer and code generator used when
1306    generating the caller, allowing value propagation, tail call optimization,
1307    and omission of register saves and restores in some cases; it is not
1308    checked or enforced when generating the callee. The parameter and the
1309    function return type must be valid operands for the
1310    :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for
1311    return values and can only be applied to one parameter.
1312
1313``nonnull``
1314    This indicates that the parameter or return pointer is not null. This
1315    attribute may only be applied to pointer typed parameters. This is not
1316    checked or enforced by LLVM; if the parameter or return pointer is null,
1317    :ref:`poison value <poisonvalues>` is returned or passed instead.
1318    The ``nonnull`` attribute should be combined with the ``noundef`` attribute
1319    to ensure a pointer is not null or otherwise the behavior is undefined.
1320
1321``dereferenceable(<n>)``
1322    This indicates that the parameter or return pointer is dereferenceable. This
1323    attribute may only be applied to pointer typed parameters. A pointer that
1324    is dereferenceable can be loaded from speculatively without a risk of
1325    trapping. The number of bytes known to be dereferenceable must be provided
1326    in parentheses. It is legal for the number of bytes to be less than the
1327    size of the pointee type. The ``nonnull`` attribute does not imply
1328    dereferenceability (consider a pointer to one element past the end of an
1329    array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in
1330    ``addrspace(0)`` (which is the default address space), except if the
1331    ``null_pointer_is_valid`` function attribute is present.
1332    ``n`` should be a positive number. The pointer should be well defined,
1333    otherwise it is undefined behavior. This means ``dereferenceable(<n>)``
1334    implies ``noundef``.
1335
1336``dereferenceable_or_null(<n>)``
1337    This indicates that the parameter or return value isn't both
1338    non-null and non-dereferenceable (up to ``<n>`` bytes) at the same
1339    time. All non-null pointers tagged with
1340    ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``.
1341    For address space 0 ``dereferenceable_or_null(<n>)`` implies that
1342    a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``,
1343    and in other address spaces ``dereferenceable_or_null(<n>)``
1344    implies that a pointer is at least one of ``dereferenceable(<n>)``
1345    or ``null`` (i.e. it may be both ``null`` and
1346    ``dereferenceable(<n>)``). This attribute may only be applied to
1347    pointer typed parameters.
1348
1349``swiftself``
1350    This indicates that the parameter is the self/context parameter. This is not
1351    a valid attribute for return values and can only be applied to one
1352    parameter.
1353
1354``swiftasync``
1355    This indicates that the parameter is the asynchronous context parameter and
1356    triggers the creation of a target-specific extended frame record to store
1357    this pointer. This is not a valid attribute for return values and can only
1358    be applied to one parameter.
1359
1360``swifterror``
1361    This attribute is motivated to model and optimize Swift error handling. It
1362    can be applied to a parameter with pointer to pointer type or a
1363    pointer-sized alloca. At the call site, the actual argument that corresponds
1364    to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or
1365    the ``swifterror`` parameter of the caller. A ``swifterror`` value (either
1366    the parameter or the alloca) can only be loaded and stored from, or used as
1367    a ``swifterror`` argument. This is not a valid attribute for return values
1368    and can only be applied to one parameter.
1369
1370    These constraints allow the calling convention to optimize access to
1371    ``swifterror`` variables by associating them with a specific register at
1372    call boundaries rather than placing them in memory. Since this does change
1373    the calling convention, a function which uses the ``swifterror`` attribute
1374    on a parameter is not ABI-compatible with one which does not.
1375
1376    These constraints also allow LLVM to assume that a ``swifterror`` argument
1377    does not alias any other memory visible within a function and that a
1378    ``swifterror`` alloca passed as an argument does not escape.
1379
1380``immarg``
1381    This indicates the parameter is required to be an immediate
1382    value. This must be a trivial immediate integer or floating-point
1383    constant. Undef or constant expressions are not valid. This is
1384    only valid on intrinsic declarations and cannot be applied to a
1385    call site or arbitrary function.
1386
1387``noundef``
1388    This attribute applies to parameters and return values. If the value
1389    representation contains any undefined or poison bits, the behavior is
1390    undefined. Note that this does not refer to padding introduced by the
1391    type's storage representation.
1392
1393``alignstack(<n>)``
1394    This indicates the alignment that should be considered by the backend when
1395    assigning this parameter to a stack slot during calling convention
1396    lowering. The enforcement of the specified alignment is target-dependent,
1397    as target-specific calling convention rules may override this value. This
1398    attribute serves the purpose of carrying language specific alignment
1399    information that is not mapped to base types in the backend (for example,
1400    over-alignment specification through language attributes).
1401
1402``allocalign``
1403    The function parameter marked with this attribute is is the alignment in bytes of the
1404    newly allocated block returned by this function. The returned value must either have
1405    the specified alignment or be the null pointer. The return value MAY be more aligned
1406    than the requested alignment, but not less aligned.  Invalid (e.g. non-power-of-2)
1407    alignments are permitted for the allocalign parameter, so long as the returned pointer
1408    is null. This attribute may only be applied to integer parameters.
1409
1410``allocptr``
1411    The function parameter marked with this attribute is the pointer
1412    that will be manipulated by the allocator. For a realloc-like
1413    function the pointer will be invalidated upon success (but the
1414    same address may be returned), for a free-like function the
1415    pointer will always be invalidated.
1416
1417.. _gc:
1418
1419Garbage Collector Strategy Names
1420--------------------------------
1421
1422Each function may specify a garbage collector strategy name, which is simply a
1423string:
1424
1425.. code-block:: llvm
1426
1427    define void @f() gc "name" { ... }
1428
1429The supported values of *name* includes those :ref:`built in to LLVM
1430<builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC
1431strategy will cause the compiler to alter its output in order to support the
1432named garbage collection algorithm. Note that LLVM itself does not contain a
1433garbage collector, this functionality is restricted to generating machine code
1434which can interoperate with a collector provided externally.
1435
1436.. _prefixdata:
1437
1438Prefix Data
1439-----------
1440
1441Prefix data is data associated with a function which the code
1442generator will emit immediately before the function's entrypoint.
1443The purpose of this feature is to allow frontends to associate
1444language-specific runtime metadata with specific functions and make it
1445available through the function pointer while still allowing the
1446function pointer to be called.
1447
1448To access the data for a given function, a program may bitcast the
1449function pointer to a pointer to the constant's type and dereference
1450index -1. This implies that the IR symbol points just past the end of
1451the prefix data. For instance, take the example of a function annotated
1452with a single ``i32``,
1453
1454.. code-block:: llvm
1455
1456    define void @f() prefix i32 123 { ... }
1457
1458The prefix data can be referenced as,
1459
1460.. code-block:: llvm
1461
1462    %0 = bitcast void* () @f to i32*
1463    %a = getelementptr inbounds i32, i32* %0, i32 -1
1464    %b = load i32, i32* %a
1465
1466Prefix data is laid out as if it were an initializer for a global variable
1467of the prefix data's type. The function will be placed such that the
1468beginning of the prefix data is aligned. This means that if the size
1469of the prefix data is not a multiple of the alignment size, the
1470function's entrypoint will not be aligned. If alignment of the
1471function's entrypoint is desired, padding must be added to the prefix
1472data.
1473
1474A function may have prefix data but no body. This has similar semantics
1475to the ``available_externally`` linkage in that the data may be used by the
1476optimizers but will not be emitted in the object file.
1477
1478.. _prologuedata:
1479
1480Prologue Data
1481-------------
1482
1483The ``prologue`` attribute allows arbitrary code (encoded as bytes) to
1484be inserted prior to the function body. This can be used for enabling
1485function hot-patching and instrumentation.
1486
1487To maintain the semantics of ordinary function calls, the prologue data must
1488have a particular format. Specifically, it must begin with a sequence of
1489bytes which decode to a sequence of machine instructions, valid for the
1490module's target, which transfer control to the point immediately succeeding
1491the prologue data, without performing any other visible action. This allows
1492the inliner and other passes to reason about the semantics of the function
1493definition without needing to reason about the prologue data. Obviously this
1494makes the format of the prologue data highly target dependent.
1495
1496A trivial example of valid prologue data for the x86 architecture is ``i8 144``,
1497which encodes the ``nop`` instruction:
1498
1499.. code-block:: text
1500
1501    define void @f() prologue i8 144 { ... }
1502
1503Generally prologue data can be formed by encoding a relative branch instruction
1504which skips the metadata, as in this example of valid prologue data for the
1505x86_64 architecture, where the first two bytes encode ``jmp .+10``:
1506
1507.. code-block:: text
1508
1509    %0 = type <{ i8, i8, i8* }>
1510
1511    define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... }
1512
1513A function may have prologue data but no body. This has similar semantics
1514to the ``available_externally`` linkage in that the data may be used by the
1515optimizers but will not be emitted in the object file.
1516
1517.. _personalityfn:
1518
1519Personality Function
1520--------------------
1521
1522The ``personality`` attribute permits functions to specify what function
1523to use for exception handling.
1524
1525.. _attrgrp:
1526
1527Attribute Groups
1528----------------
1529
1530Attribute groups are groups of attributes that are referenced by objects within
1531the IR. They are important for keeping ``.ll`` files readable, because a lot of
1532functions will use the same set of attributes. In the degenerative case of a
1533``.ll`` file that corresponds to a single ``.c`` file, the single attribute
1534group will capture the important command line flags used to build that file.
1535
1536An attribute group is a module-level object. To use an attribute group, an
1537object references the attribute group's ID (e.g. ``#37``). An object may refer
1538to more than one attribute group. In that situation, the attributes from the
1539different groups are merged.
1540
1541Here is an example of attribute groups for a function that should always be
1542inlined, has a stack alignment of 4, and which shouldn't use SSE instructions:
1543
1544.. code-block:: llvm
1545
1546   ; Target-independent attributes:
1547   attributes #0 = { alwaysinline alignstack=4 }
1548
1549   ; Target-dependent attributes:
1550   attributes #1 = { "no-sse" }
1551
1552   ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse".
1553   define void @f() #0 #1 { ... }
1554
1555.. _fnattrs:
1556
1557Function Attributes
1558-------------------
1559
1560Function attributes are set to communicate additional information about
1561a function. Function attributes are considered to be part of the
1562function, not of the function type, so functions with different function
1563attributes can have the same function type.
1564
1565Function attributes are simple keywords that follow the type specified.
1566If multiple attributes are needed, they are space separated. For
1567example:
1568
1569.. code-block:: llvm
1570
1571    define void @f() noinline { ... }
1572    define void @f() alwaysinline { ... }
1573    define void @f() alwaysinline optsize { ... }
1574    define void @f() optsize { ... }
1575
1576``alignstack(<n>)``
1577    This attribute indicates that, when emitting the prologue and
1578    epilogue, the backend should forcibly align the stack pointer.
1579    Specify the desired alignment, which must be a power of two, in
1580    parentheses.
1581``"alloc-family"="FAMILY"``
1582    This indicates which "family" an allocator function is part of. To avoid
1583    collisions, the family name should match the mangled name of the primary
1584    allocator function, that is "malloc" for malloc/calloc/realloc/free,
1585    "_Znwm" for ``::operator::new`` and ``::operator::delete``, and
1586    "_ZnwmSt11align_val_t" for aligned ``::operator::new`` and
1587    ``::operator::delete``. Matching malloc/realloc/free calls within a family
1588    can be optimized, but mismatched ones will be left alone.
1589``allockind("KIND")``
1590    Describes the behavior of an allocation function. The KIND string contains comma
1591    separated entries from the following options:
1592
1593    * "alloc": the function returns a new block of memory or null.
1594    * "realloc": the function returns a new block of memory or null. If the
1595      result is non-null the memory contents from the start of the block up to
1596      the smaller of the original allocation size and the new allocation size
1597      will match that of the ``allocptr`` argument and the ``allocptr``
1598      argument is invalidated, even if the function returns the same address.
1599    * "free": the function frees the block of memory specified by ``allocptr``.
1600    * "uninitialized": Any newly-allocated memory (either a new block from
1601      a "alloc" function or the enlarged capacity from a "realloc" function)
1602      will be uninitialized.
1603    * "zeroed": Any newly-allocated memory (either a new block from a "alloc"
1604      function or the enlarged capacity from a "realloc" function) will be
1605      zeroed.
1606    * "aligned": the function returns memory aligned according to the
1607      ``allocalign`` parameter.
1608
1609    The first three options are mutually exclusive, and the remaining options
1610    describe more details of how the function behaves. The remaining options
1611    are invalid for "free"-type functions.
1612``allocsize(<EltSizeParam>[, <NumEltsParam>])``
1613    This attribute indicates that the annotated function will always return at
1614    least a given number of bytes (or null). Its arguments are zero-indexed
1615    parameter numbers; if one argument is provided, then it's assumed that at
1616    least ``CallSite.Args[EltSizeParam]`` bytes will be available at the
1617    returned pointer. If two are provided, then it's assumed that
1618    ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are
1619    available. The referenced parameters must be integer types. No assumptions
1620    are made about the contents of the returned block of memory.
1621``alwaysinline``
1622    This attribute indicates that the inliner should attempt to inline
1623    this function into callers whenever possible, ignoring any active
1624    inlining size threshold for this caller.
1625``builtin``
1626    This indicates that the callee function at a call site should be
1627    recognized as a built-in function, even though the function's declaration
1628    uses the ``nobuiltin`` attribute. This is only valid at call sites for
1629    direct calls to functions that are declared with the ``nobuiltin``
1630    attribute.
1631``cold``
1632    This attribute indicates that this function is rarely called. When
1633    computing edge weights, basic blocks post-dominated by a cold
1634    function call are also considered to be cold; and, thus, given low
1635    weight.
1636``convergent``
1637    In some parallel execution models, there exist operations that cannot be
1638    made control-dependent on any additional values.  We call such operations
1639    ``convergent``, and mark them with this attribute.
1640
1641    The ``convergent`` attribute may appear on functions or call/invoke
1642    instructions.  When it appears on a function, it indicates that calls to
1643    this function should not be made control-dependent on additional values.
1644    For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so
1645    calls to this intrinsic cannot be made control-dependent on additional
1646    values.
1647
1648    When it appears on a call/invoke, the ``convergent`` attribute indicates
1649    that we should treat the call as though we're calling a convergent
1650    function.  This is particularly useful on indirect calls; without this we
1651    may treat such calls as though the target is non-convergent.
1652
1653    The optimizer may remove the ``convergent`` attribute on functions when it
1654    can prove that the function does not execute any convergent operations.
1655    Similarly, the optimizer may remove ``convergent`` on calls/invokes when it
1656    can prove that the call/invoke cannot call a convergent function.
1657``disable_sanitizer_instrumentation``
1658    When instrumenting code with sanitizers, it can be important to skip certain
1659    functions to ensure no instrumentation is applied to them.
1660
1661    This attribute is not always similar to absent ``sanitize_<name>``
1662    attributes: depending on the specific sanitizer, code can be inserted into
1663    functions regardless of the ``sanitize_<name>`` attribute to prevent false
1664    positive reports.
1665
1666    ``disable_sanitizer_instrumentation`` disables all kinds of instrumentation,
1667    taking precedence over the ``sanitize_<name>`` attributes and other compiler
1668    flags.
1669``"dontcall-error"``
1670    This attribute denotes that an error diagnostic should be emitted when a
1671    call of a function with this attribute is not eliminated via optimization.
1672    Front ends can provide optional ``srcloc`` metadata nodes on call sites of
1673    such callees to attach information about where in the source language such a
1674    call came from. A string value can be provided as a note.
1675``"dontcall-warn"``
1676    This attribute denotes that a warning diagnostic should be emitted when a
1677    call of a function with this attribute is not eliminated via optimization.
1678    Front ends can provide optional ``srcloc`` metadata nodes on call sites of
1679    such callees to attach information about where in the source language such a
1680    call came from. A string value can be provided as a note.
1681``fn_ret_thunk_extern``
1682    This attribute tells the code generator that returns from functions should
1683    be replaced with jumps to externally-defined architecture-specific symbols.
1684    For X86, this symbol's identifier is ``__x86_return_thunk``.
1685``"frame-pointer"``
1686    This attribute tells the code generator whether the function
1687    should keep the frame pointer. The code generator may emit the frame pointer
1688    even if this attribute says the frame pointer can be eliminated.
1689    The allowed string values are:
1690
1691     * ``"none"`` (default) - the frame pointer can be eliminated.
1692     * ``"non-leaf"`` - the frame pointer should be kept if the function calls
1693       other functions.
1694     * ``"all"`` - the frame pointer should be kept.
1695``hot``
1696    This attribute indicates that this function is a hot spot of the program
1697    execution. The function will be optimized more aggressively and will be
1698    placed into special subsection of the text section to improving locality.
1699
1700    When profile feedback is enabled, this attribute has the precedence over
1701    the profile information. By marking a function ``hot``, users can work
1702    around the cases where the training input does not have good coverage
1703    on all the hot functions.
1704``inaccessiblememonly``
1705    This attribute indicates that the function may only access memory that
1706    is not accessible by the module being compiled before return from the
1707    function. This is a weaker form of ``readnone``. If the function reads
1708    or writes other memory, the behavior is undefined.
1709
1710    For clarity, note that such functions are allowed to return new memory
1711    which is ``noalias`` with respect to memory already accessible from
1712    the module.  That is, a function can be both ``inaccessiblememonly`` and
1713    have a ``noalias`` return which introduces a new, potentially initialized,
1714    allocation.
1715``inaccessiblemem_or_argmemonly``
1716    This attribute indicates that the function may only access memory that is
1717    either not accessible by the module being compiled, or is pointed to
1718    by its pointer arguments. This is a weaker form of  ``argmemonly``. If the
1719    function reads or writes other memory, the behavior is undefined.
1720``inlinehint``
1721    This attribute indicates that the source code contained a hint that
1722    inlining this function is desirable (such as the "inline" keyword in
1723    C/C++). It is just a hint; it imposes no requirements on the
1724    inliner.
1725``jumptable``
1726    This attribute indicates that the function should be added to a
1727    jump-instruction table at code-generation time, and that all address-taken
1728    references to this function should be replaced with a reference to the
1729    appropriate jump-instruction-table function pointer. Note that this creates
1730    a new pointer for the original function, which means that code that depends
1731    on function-pointer identity can break. So, any function annotated with
1732    ``jumptable`` must also be ``unnamed_addr``.
1733``minsize``
1734    This attribute suggests that optimization passes and code generator
1735    passes make choices that keep the code size of this function as small
1736    as possible and perform optimizations that may sacrifice runtime
1737    performance in order to minimize the size of the generated code.
1738``naked``
1739    This attribute disables prologue / epilogue emission for the
1740    function. This can have very system-specific consequences.
1741``"no-inline-line-tables"``
1742    When this attribute is set to true, the inliner discards source locations
1743    when inlining code and instead uses the source location of the call site.
1744    Breakpoints set on code that was inlined into the current function will
1745    not fire during the execution of the inlined call sites. If the debugger
1746    stops inside an inlined call site, it will appear to be stopped at the
1747    outermost inlined call site.
1748``no-jump-tables``
1749    When this attribute is set to true, the jump tables and lookup tables that
1750    can be generated from a switch case lowering are disabled.
1751``nobuiltin``
1752    This indicates that the callee function at a call site is not recognized as
1753    a built-in function. LLVM will retain the original call and not replace it
1754    with equivalent code based on the semantics of the built-in function, unless
1755    the call site uses the ``builtin`` attribute. This is valid at call sites
1756    and on function declarations and definitions.
1757``noduplicate``
1758    This attribute indicates that calls to the function cannot be
1759    duplicated. A call to a ``noduplicate`` function may be moved
1760    within its parent function, but may not be duplicated within
1761    its parent function.
1762
1763    A function containing a ``noduplicate`` call may still
1764    be an inlining candidate, provided that the call is not
1765    duplicated by inlining. That implies that the function has
1766    internal linkage and only has one call site, so the original
1767    call is dead after inlining.
1768``nofree``
1769    This function attribute indicates that the function does not, directly or
1770    transitively, call a memory-deallocation function (``free``, for example)
1771    on a memory allocation which existed before the call.
1772
1773    As a result, uncaptured pointers that are known to be dereferenceable
1774    prior to a call to a function with the ``nofree`` attribute are still
1775    known to be dereferenceable after the call. The capturing condition is
1776    necessary in environments where the function might communicate the
1777    pointer to another thread which then deallocates the memory.  Alternatively,
1778    ``nosync`` would ensure such communication cannot happen and even captured
1779    pointers cannot be freed by the function.
1780
1781    A ``nofree`` function is explicitly allowed to free memory which it
1782    allocated or (if not ``nosync``) arrange for another thread to free
1783    memory on it's behalf.  As a result, perhaps surprisingly, a ``nofree``
1784    function can return a pointer to a previously deallocated memory object.
1785``noimplicitfloat``
1786    Disallows implicit floating-point code. This inhibits optimizations that
1787    use floating-point code and floating-point/SIMD/vector registers for
1788    operations that are not nominally floating-point. LLVM instructions that
1789    perform floating-point operations or require access to floating-point
1790    registers may still cause floating-point code to be generated.
1791``noinline``
1792    This attribute indicates that the inliner should never inline this
1793    function in any situation. This attribute may not be used together
1794    with the ``alwaysinline`` attribute.
1795``nomerge``
1796    This attribute indicates that calls to this function should never be merged
1797    during optimization. For example, it will prevent tail merging otherwise
1798    identical code sequences that raise an exception or terminate the program.
1799    Tail merging normally reduces the precision of source location information,
1800    making stack traces less useful for debugging. This attribute gives the
1801    user control over the tradeoff between code size and debug information
1802    precision.
1803``nonlazybind``
1804    This attribute suppresses lazy symbol binding for the function. This
1805    may make calls to the function faster, at the cost of extra program
1806    startup time if the function is not called during program startup.
1807``noprofile``
1808    This function attribute prevents instrumentation based profiling, used for
1809    coverage or profile based optimization, from being added to a function,
1810    even when inlined.
1811``noredzone``
1812    This attribute indicates that the code generator should not use a
1813    red zone, even if the target-specific ABI normally permits it.
1814``indirect-tls-seg-refs``
1815    This attribute indicates that the code generator should not use
1816    direct TLS access through segment registers, even if the
1817    target-specific ABI normally permits it.
1818``noreturn``
1819    This function attribute indicates that the function never returns
1820    normally, hence through a return instruction. This produces undefined
1821    behavior at runtime if the function ever does dynamically return. Annotated
1822    functions may still raise an exception, i.a., ``nounwind`` is not implied.
1823``norecurse``
1824    This function attribute indicates that the function does not call itself
1825    either directly or indirectly down any possible call path. This produces
1826    undefined behavior at runtime if the function ever does recurse.
1827
1828.. _langref_willreturn:
1829
1830``willreturn``
1831    This function attribute indicates that a call of this function will
1832    either exhibit undefined behavior or comes back and continues execution
1833    at a point in the existing call stack that includes the current invocation.
1834    Annotated functions may still raise an exception, i.a., ``nounwind`` is not implied.
1835    If an invocation of an annotated function does not return control back
1836    to a point in the call stack, the behavior is undefined.
1837``nosync``
1838    This function attribute indicates that the function does not communicate
1839    (synchronize) with another thread through memory or other well-defined means.
1840    Synchronization is considered possible in the presence of `atomic` accesses
1841    that enforce an order, thus not "unordered" and "monotonic", `volatile` accesses,
1842    as well as `convergent` function calls. Note that through `convergent` function calls
1843    non-memory communication, e.g., cross-lane operations, are possible and are also
1844    considered synchronization. However `convergent` does not contradict `nosync`.
1845    If an annotated function does ever synchronize with another thread,
1846    the behavior is undefined.
1847``nounwind``
1848    This function attribute indicates that the function never raises an
1849    exception. If the function does raise an exception, its runtime
1850    behavior is undefined. However, functions marked nounwind may still
1851    trap or generate asynchronous exceptions. Exception handling schemes
1852    that are recognized by LLVM to handle asynchronous exceptions, such
1853    as SEH, will still provide their implementation defined semantics.
1854``nosanitize_bounds``
1855    This attribute indicates that bounds checking sanitizer instrumentation
1856    is disabled for this function.
1857``nosanitize_coverage``
1858    This attribute indicates that SanitizerCoverage instrumentation is disabled
1859    for this function.
1860``null_pointer_is_valid``
1861   If ``null_pointer_is_valid`` is set, then the ``null`` address
1862   in address-space 0 is considered to be a valid address for memory loads and
1863   stores. Any analysis or optimization should not treat dereferencing a
1864   pointer to ``null`` as undefined behavior in this function.
1865   Note: Comparing address of a global variable to ``null`` may still
1866   evaluate to false because of a limitation in querying this attribute inside
1867   constant expressions.
1868``optforfuzzing``
1869    This attribute indicates that this function should be optimized
1870    for maximum fuzzing signal.
1871``optnone``
1872    This function attribute indicates that most optimization passes will skip
1873    this function, with the exception of interprocedural optimization passes.
1874    Code generation defaults to the "fast" instruction selector.
1875    This attribute cannot be used together with the ``alwaysinline``
1876    attribute; this attribute is also incompatible
1877    with the ``minsize`` attribute and the ``optsize`` attribute.
1878
1879    This attribute requires the ``noinline`` attribute to be specified on
1880    the function as well, so the function is never inlined into any caller.
1881    Only functions with the ``alwaysinline`` attribute are valid
1882    candidates for inlining into the body of this function.
1883``optsize``
1884    This attribute suggests that optimization passes and code generator
1885    passes make choices that keep the code size of this function low,
1886    and otherwise do optimizations specifically to reduce code size as
1887    long as they do not significantly impact runtime performance.
1888``"patchable-function"``
1889    This attribute tells the code generator that the code
1890    generated for this function needs to follow certain conventions that
1891    make it possible for a runtime function to patch over it later.
1892    The exact effect of this attribute depends on its string value,
1893    for which there currently is one legal possibility:
1894
1895     * ``"prologue-short-redirect"`` - This style of patchable
1896       function is intended to support patching a function prologue to
1897       redirect control away from the function in a thread safe
1898       manner.  It guarantees that the first instruction of the
1899       function will be large enough to accommodate a short jump
1900       instruction, and will be sufficiently aligned to allow being
1901       fully changed via an atomic compare-and-swap instruction.
1902       While the first requirement can be satisfied by inserting large
1903       enough NOP, LLVM can and will try to re-purpose an existing
1904       instruction (i.e. one that would have to be emitted anyway) as
1905       the patchable instruction larger than a short jump.
1906
1907       ``"prologue-short-redirect"`` is currently only supported on
1908       x86-64.
1909
1910    This attribute by itself does not imply restrictions on
1911    inter-procedural optimizations.  All of the semantic effects the
1912    patching may have to be separately conveyed via the linkage type.
1913``"probe-stack"``
1914    This attribute indicates that the function will trigger a guard region
1915    in the end of the stack. It ensures that accesses to the stack must be
1916    no further apart than the size of the guard region to a previous
1917    access of the stack. It takes one required string value, the name of
1918    the stack probing function that will be called.
1919
1920    If a function that has a ``"probe-stack"`` attribute is inlined into
1921    a function with another ``"probe-stack"`` attribute, the resulting
1922    function has the ``"probe-stack"`` attribute of the caller. If a
1923    function that has a ``"probe-stack"`` attribute is inlined into a
1924    function that has no ``"probe-stack"`` attribute at all, the resulting
1925    function has the ``"probe-stack"`` attribute of the callee.
1926``readnone``
1927    On a function, this attribute indicates that the function computes its
1928    result (or decides to unwind an exception) based strictly on its arguments,
1929    without dereferencing any pointer arguments or otherwise accessing
1930    any mutable state (e.g. memory, control registers, etc) visible outside the
1931    ``readnone`` function. It does not write through any pointer arguments
1932    (including ``byval`` arguments) and never changes any state visible to
1933    callers. This means while it cannot unwind exceptions by calling the ``C++``
1934    exception throwing methods (since they write to memory), there may be
1935    non-``C++`` mechanisms that throw exceptions without writing to LLVM visible
1936    memory.
1937
1938    On an argument, this attribute indicates that the function does not
1939    dereference that pointer argument, even though it may read or write the
1940    memory that the pointer points to if accessed through other pointers.
1941
1942    If a readnone function reads or writes memory visible outside the function,
1943    or has other side-effects, the behavior is undefined. If a
1944    function reads from or writes to a readnone pointer argument, the behavior
1945    is undefined.
1946``readonly``
1947    On a function, this attribute indicates that the function does not write
1948    through any pointer arguments (including ``byval`` arguments) or otherwise
1949    modify any state (e.g. memory, control registers, etc) visible outside the
1950    ``readonly`` function. It may dereference pointer arguments and read
1951    state that may be set in the caller. A readonly function always
1952    returns the same value (or unwinds an exception identically) when
1953    called with the same set of arguments and global state.  This means while it
1954    cannot unwind exceptions by calling the ``C++`` exception throwing methods
1955    (since they write to memory), there may be non-``C++`` mechanisms that throw
1956    exceptions without writing to LLVM visible memory.
1957
1958    On an argument, this attribute indicates that the function does not write
1959    through this pointer argument, even though it may write to the memory that
1960    the pointer points to.
1961
1962    If a readonly function writes memory visible outside the function, or has
1963    other side-effects, the behavior is undefined. If a function writes to a
1964    readonly pointer argument, the behavior is undefined.
1965``"stack-probe-size"``
1966    This attribute controls the behavior of stack probes: either
1967    the ``"probe-stack"`` attribute, or ABI-required stack probes, if any.
1968    It defines the size of the guard region. It ensures that if the function
1969    may use more stack space than the size of the guard region, stack probing
1970    sequence will be emitted. It takes one required integer value, which
1971    is 4096 by default.
1972
1973    If a function that has a ``"stack-probe-size"`` attribute is inlined into
1974    a function with another ``"stack-probe-size"`` attribute, the resulting
1975    function has the ``"stack-probe-size"`` attribute that has the lower
1976    numeric value. If a function that has a ``"stack-probe-size"`` attribute is
1977    inlined into a function that has no ``"stack-probe-size"`` attribute
1978    at all, the resulting function has the ``"stack-probe-size"`` attribute
1979    of the callee.
1980``"no-stack-arg-probe"``
1981    This attribute disables ABI-required stack probes, if any.
1982``writeonly``
1983    On a function, this attribute indicates that the function may write to but
1984    does not read from memory visible outside the ``writeonly`` function.
1985
1986    On an argument, this attribute indicates that the function may write to but
1987    does not read through this pointer argument (even though it may read from
1988    the memory that the pointer points to).
1989
1990    If a writeonly function reads memory visible outside the function or has
1991    other side-effects, the behavior is undefined. If a function reads
1992    from a writeonly pointer argument, the behavior is undefined.
1993``argmemonly``
1994    This attribute indicates that the only memory accesses inside function are
1995    loads and stores from objects pointed to by its pointer-typed arguments,
1996    with arbitrary offsets. Or in other words, all memory operations in the
1997    function can refer to memory only using pointers based on its function
1998    arguments.
1999
2000    Note that ``argmemonly`` can be used together with ``readonly`` attribute
2001    in order to specify that function reads only from its arguments.
2002
2003    If an argmemonly function reads or writes memory other than the pointer
2004    arguments, or has other side-effects, the behavior is undefined.
2005``returns_twice``
2006    This attribute indicates that this function can return twice. The C
2007    ``setjmp`` is an example of such a function. The compiler disables
2008    some optimizations (like tail calls) in the caller of these
2009    functions.
2010``safestack``
2011    This attribute indicates that
2012    `SafeStack <https://clang.llvm.org/docs/SafeStack.html>`_
2013    protection is enabled for this function.
2014
2015    If a function that has a ``safestack`` attribute is inlined into a
2016    function that doesn't have a ``safestack`` attribute or which has an
2017    ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting
2018    function will have a ``safestack`` attribute.
2019``sanitize_address``
2020    This attribute indicates that AddressSanitizer checks
2021    (dynamic address safety analysis) are enabled for this function.
2022``sanitize_memory``
2023    This attribute indicates that MemorySanitizer checks (dynamic detection
2024    of accesses to uninitialized memory) are enabled for this function.
2025``sanitize_thread``
2026    This attribute indicates that ThreadSanitizer checks
2027    (dynamic thread safety analysis) are enabled for this function.
2028``sanitize_hwaddress``
2029    This attribute indicates that HWAddressSanitizer checks
2030    (dynamic address safety analysis based on tagged pointers) are enabled for
2031    this function.
2032``sanitize_memtag``
2033    This attribute indicates that MemTagSanitizer checks
2034    (dynamic address safety analysis based on Armv8 MTE) are enabled for
2035    this function.
2036``speculative_load_hardening``
2037    This attribute indicates that
2038    `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_
2039    should be enabled for the function body.
2040
2041    Speculative Load Hardening is a best-effort mitigation against
2042    information leak attacks that make use of control flow
2043    miss-speculation - specifically miss-speculation of whether a branch
2044    is taken or not. Typically vulnerabilities enabling such attacks are
2045    classified as "Spectre variant #1". Notably, this does not attempt to
2046    mitigate against miss-speculation of branch target, classified as
2047    "Spectre variant #2" vulnerabilities.
2048
2049    When inlining, the attribute is sticky. Inlining a function that carries
2050    this attribute will cause the caller to gain the attribute. This is intended
2051    to provide a maximally conservative model where the code in a function
2052    annotated with this attribute will always (even after inlining) end up
2053    hardened.
2054``speculatable``
2055    This function attribute indicates that the function does not have any
2056    effects besides calculating its result and does not have undefined behavior.
2057    Note that ``speculatable`` is not enough to conclude that along any
2058    particular execution path the number of calls to this function will not be
2059    externally observable. This attribute is only valid on functions
2060    and declarations, not on individual call sites. If a function is
2061    incorrectly marked as speculatable and really does exhibit
2062    undefined behavior, the undefined behavior may be observed even
2063    if the call site is dead code.
2064
2065``ssp``
2066    This attribute indicates that the function should emit a stack
2067    smashing protector. It is in the form of a "canary" --- a random value
2068    placed on the stack before the local variables that's checked upon
2069    return from the function to see if it has been overwritten. A
2070    heuristic is used to determine if a function needs stack protectors
2071    or not. The heuristic used will enable protectors for functions with:
2072
2073    - Character arrays larger than ``ssp-buffer-size`` (default 8).
2074    - Aggregates containing character arrays larger than ``ssp-buffer-size``.
2075    - Calls to alloca() with variable sizes or constant sizes greater than
2076      ``ssp-buffer-size``.
2077
2078    Variables that are identified as requiring a protector will be arranged
2079    on the stack such that they are adjacent to the stack protector guard.
2080
2081    If a function with an ``ssp`` attribute is inlined into a calling function,
2082    the attribute is not carried over to the calling function.
2083
2084``sspstrong``
2085    This attribute indicates that the function should emit a stack smashing
2086    protector. This attribute causes a strong heuristic to be used when
2087    determining if a function needs stack protectors. The strong heuristic
2088    will enable protectors for functions with:
2089
2090    - Arrays of any size and type
2091    - Aggregates containing an array of any size and type.
2092    - Calls to alloca().
2093    - Local variables that have had their address taken.
2094
2095    Variables that are identified as requiring a protector will be arranged
2096    on the stack such that they are adjacent to the stack protector guard.
2097    The specific layout rules are:
2098
2099    #. Large arrays and structures containing large arrays
2100       (``>= ssp-buffer-size``) are closest to the stack protector.
2101    #. Small arrays and structures containing small arrays
2102       (``< ssp-buffer-size``) are 2nd closest to the protector.
2103    #. Variables that have had their address taken are 3rd closest to the
2104       protector.
2105
2106    This overrides the ``ssp`` function attribute.
2107
2108    If a function with an ``sspstrong`` attribute is inlined into a calling
2109    function which has an ``ssp`` attribute, the calling function's attribute
2110    will be upgraded to ``sspstrong``.
2111
2112``sspreq``
2113    This attribute indicates that the function should *always* emit a stack
2114    smashing protector. This overrides the ``ssp`` and ``sspstrong`` function
2115    attributes.
2116
2117    Variables that are identified as requiring a protector will be arranged
2118    on the stack such that they are adjacent to the stack protector guard.
2119    The specific layout rules are:
2120
2121    #. Large arrays and structures containing large arrays
2122       (``>= ssp-buffer-size``) are closest to the stack protector.
2123    #. Small arrays and structures containing small arrays
2124       (``< ssp-buffer-size``) are 2nd closest to the protector.
2125    #. Variables that have had their address taken are 3rd closest to the
2126       protector.
2127
2128    If a function with an ``sspreq`` attribute is inlined into a calling
2129    function which has an ``ssp`` or ``sspstrong`` attribute, the calling
2130    function's attribute will be upgraded to ``sspreq``.
2131
2132``strictfp``
2133    This attribute indicates that the function was called from a scope that
2134    requires strict floating-point semantics.  LLVM will not attempt any
2135    optimizations that require assumptions about the floating-point rounding
2136    mode or that might alter the state of floating-point status flags that
2137    might otherwise be set or cleared by calling this function. LLVM will
2138    not introduce any new floating-point instructions that may trap.
2139
2140``"denormal-fp-math"``
2141    This indicates the denormal (subnormal) handling that may be
2142    assumed for the default floating-point environment. This is a
2143    comma separated pair. The elements may be one of ``"ieee"``,
2144    ``"preserve-sign"``, or ``"positive-zero"``. The first entry
2145    indicates the flushing mode for the result of floating point
2146    operations. The second indicates the handling of denormal inputs
2147    to floating point instructions. For compatibility with older
2148    bitcode, if the second value is omitted, both input and output
2149    modes will assume the same mode.
2150
2151    If this is attribute is not specified, the default is
2152    ``"ieee,ieee"``.
2153
2154    If the output mode is ``"preserve-sign"``, or ``"positive-zero"``,
2155    denormal outputs may be flushed to zero by standard floating-point
2156    operations. It is not mandated that flushing to zero occurs, but if
2157    a denormal output is flushed to zero, it must respect the sign
2158    mode. Not all targets support all modes. While this indicates the
2159    expected floating point mode the function will be executed with,
2160    this does not make any attempt to ensure the mode is
2161    consistent. User or platform code is expected to set the floating
2162    point mode appropriately before function entry.
2163
2164   If the input mode is ``"preserve-sign"``, or ``"positive-zero"``, a
2165   floating-point operation must treat any input denormal value as
2166   zero. In some situations, if an instruction does not respect this
2167   mode, the input may need to be converted to 0 as if by
2168   ``@llvm.canonicalize`` during lowering for correctness.
2169
2170``"denormal-fp-math-f32"``
2171    Same as ``"denormal-fp-math"``, but only controls the behavior of
2172    the 32-bit float type (or vectors of 32-bit floats). If both are
2173    are present, this overrides ``"denormal-fp-math"``. Not all targets
2174    support separately setting the denormal mode per type, and no
2175    attempt is made to diagnose unsupported uses. Currently this
2176    attribute is respected by the AMDGPU and NVPTX backends.
2177
2178``"thunk"``
2179    This attribute indicates that the function will delegate to some other
2180    function with a tail call. The prototype of a thunk should not be used for
2181    optimization purposes. The caller is expected to cast the thunk prototype to
2182    match the thunk target prototype.
2183
2184``"tls-load-hoist"``
2185    This attribute indicates that the function will try to reduce redundant
2186    tls address calculation by hoisting tls variable.
2187
2188``uwtable[(sync|async)]``
2189    This attribute indicates that the ABI being targeted requires that
2190    an unwind table entry be produced for this function even if we can
2191    show that no exceptions passes by it. This is normally the case for
2192    the ELF x86-64 abi, but it can be disabled for some compilation
2193    units. The optional parameter describes what kind of unwind tables
2194    to generate: ``sync`` for normal unwind tables, ``async`` for asynchronous
2195    (instruction precise) unwind tables. Without the parameter, the attribute
2196    ``uwtable`` is equivalent to ``uwtable(async)``.
2197``nocf_check``
2198    This attribute indicates that no control-flow check will be performed on
2199    the attributed entity. It disables -fcf-protection=<> for a specific
2200    entity to fine grain the HW control flow protection mechanism. The flag
2201    is target independent and currently appertains to a function or function
2202    pointer.
2203``shadowcallstack``
2204    This attribute indicates that the ShadowCallStack checks are enabled for
2205    the function. The instrumentation checks that the return address for the
2206    function has not changed between the function prolog and epilog. It is
2207    currently x86_64-specific.
2208
2209.. _langref_mustprogress:
2210
2211``mustprogress``
2212    This attribute indicates that the function is required to return, unwind,
2213    or interact with the environment in an observable way e.g. via a volatile
2214    memory access, I/O, or other synchronization.  The ``mustprogress``
2215    attribute is intended to model the requirements of the first section of
2216    [intro.progress] of the C++ Standard. As a consequence, a loop in a
2217    function with the `mustprogress` attribute can be assumed to terminate if
2218    it does not interact with the environment in an observable way, and
2219    terminating loops without side-effects can be removed. If a `mustprogress`
2220    function does not satisfy this contract, the behavior is undefined.  This
2221    attribute does not apply transitively to callees, but does apply to call
2222    sites within the function. Note that `willreturn` implies `mustprogress`.
2223``"warn-stack-size"="<threshold>"``
2224    This attribute sets a threshold to emit diagnostics once the frame size is
2225    known should the frame size exceed the specified value.  It takes one
2226    required integer value, which should be a non-negative integer, and less
2227    than `UINT_MAX`.  It's unspecified which threshold will be used when
2228    duplicate definitions are linked together with differing values.
2229``vscale_range(<min>[, <max>])``
2230    This attribute indicates the minimum and maximum vscale value for the given
2231    function. The min must be greater than 0. A maximum value of 0 means
2232    unbounded. If the optional max value is omitted then max is set to the
2233    value of min. If the attribute is not present, no assumptions are made
2234    about the range of vscale.
2235``"min-legal-vector-width"="<size>"``
2236    This attribute indicates the minimum legal vector width required by the
2237    calling conversion. It is the maximum width of vector arguments and
2238    returnings in the function and functions called by this function. Because
2239    all the vectors are supposed to be legal type for compatibility.
2240    Backends are free to ignore the attribute if they don't need to support
2241    different maximum legal vector types or such information can be inferred by
2242    other attributes.
2243
2244Call Site Attributes
2245----------------------
2246
2247In addition to function attributes the following call site only
2248attributes are supported:
2249
2250``vector-function-abi-variant``
2251    This attribute can be attached to a :ref:`call <i_call>` to list
2252    the vector functions associated to the function. Notice that the
2253    attribute cannot be attached to a :ref:`invoke <i_invoke>` or a
2254    :ref:`callbr <i_callbr>` instruction. The attribute consists of a
2255    comma separated list of mangled names. The order of the list does
2256    not imply preference (it is logically a set). The compiler is free
2257    to pick any listed vector function of its choosing.
2258
2259    The syntax for the mangled names is as follows:::
2260
2261        _ZGV<isa><mask><vlen><parameters>_<scalar_name>[(<vector_redirection>)]
2262
2263    When present, the attribute informs the compiler that the function
2264    ``<scalar_name>`` has a corresponding vector variant that can be
2265    used to perform the concurrent invocation of ``<scalar_name>`` on
2266    vectors. The shape of the vector function is described by the
2267    tokens between the prefix ``_ZGV`` and the ``<scalar_name>``
2268    token. The standard name of the vector function is
2269    ``_ZGV<isa><mask><vlen><parameters>_<scalar_name>``. When present,
2270    the optional token ``(<vector_redirection>)`` informs the compiler
2271    that a custom name is provided in addition to the standard one
2272    (custom names can be provided for example via the use of ``declare
2273    variant`` in OpenMP 5.0). The declaration of the variant must be
2274    present in the IR Module. The signature of the vector variant is
2275    determined by the rules of the Vector Function ABI (VFABI)
2276    specifications of the target. For Arm and X86, the VFABI can be
2277    found at https://github.com/ARM-software/abi-aa and
2278    https://software.intel.com/content/www/us/en/develop/download/vector-simd-function-abi.html,
2279    respectively.
2280
2281    For X86 and Arm targets, the values of the tokens in the standard
2282    name are those that are defined in the VFABI. LLVM has an internal
2283    ``<isa>`` token that can be used to create scalar-to-vector
2284    mappings for functions that are not directly associated to any of
2285    the target ISAs (for example, some of the mappings stored in the
2286    TargetLibraryInfo). Valid values for the ``<isa>`` token are:::
2287
2288        <isa>:= b | c | d | e  -> X86 SSE, AVX, AVX2, AVX512
2289              | n | s          -> Armv8 Advanced SIMD, SVE
2290              | __LLVM__       -> Internal LLVM Vector ISA
2291
2292    For all targets currently supported (x86, Arm and Internal LLVM),
2293    the remaining tokens can have the following values:::
2294
2295        <mask>:= M | N         -> mask | no mask
2296
2297        <vlen>:= number        -> number of lanes
2298               | x             -> VLA (Vector Length Agnostic)
2299
2300        <parameters>:= v              -> vector
2301                     | l | l <number> -> linear
2302                     | R | R <number> -> linear with ref modifier
2303                     | L | L <number> -> linear with val modifier
2304                     | U | U <number> -> linear with uval modifier
2305                     | ls <pos>       -> runtime linear
2306                     | Rs <pos>       -> runtime linear with ref modifier
2307                     | Ls <pos>       -> runtime linear with val modifier
2308                     | Us <pos>       -> runtime linear with uval modifier
2309                     | u              -> uniform
2310
2311        <scalar_name>:= name of the scalar function
2312
2313        <vector_redirection>:= optional, custom name of the vector function
2314
2315``preallocated(<ty>)``
2316    This attribute is required on calls to ``llvm.call.preallocated.arg``
2317    and cannot be used on any other call. See
2318    :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` for more
2319    details.
2320
2321.. _glattrs:
2322
2323Global Attributes
2324-----------------
2325
2326Attributes may be set to communicate additional information about a global variable.
2327Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable
2328are grouped into a single :ref:`attribute group <attrgrp>`.
2329
2330``no_sanitize_address``
2331    This attribute indicates that the global variable should not have
2332    AddressSanitizer instrumentation applied to it, because it was annotated
2333    with `__attribute__((no_sanitize("address")))`,
2334    `__attribute__((disable_sanitizer_instrumentation))`, or included in the
2335    `-fsanitize-ignorelist` file.
2336``no_sanitize_hwaddress``
2337    This attribute indicates that the global variable should not have
2338    HWAddressSanitizer instrumentation applied to it, because it was annotated
2339    with `__attribute__((no_sanitize("hwaddress")))`,
2340    `__attribute__((disable_sanitizer_instrumentation))`, or included in the
2341    `-fsanitize-ignorelist` file.
2342``sanitize_memtag``
2343    This attribute indicates that the global variable should have AArch64 memory
2344    tags (MTE) instrumentation applied to it. This attribute causes the
2345    suppression of certain optimisations, like GlobalMerge, as well as ensuring
2346    extra directives are emitted in the assembly and extra bits of metadata are
2347    placed in the object file so that the linker can ensure the accesses are
2348    protected by MTE. This attribute is added by clang when
2349    `-fsanitize=memtag-globals` is provided, as long as the global is not marked
2350    with `__attribute__((no_sanitize("memtag")))`,
2351    `__attribute__((disable_sanitizer_instrumentation))`, or included in the
2352    `-fsanitize-ignorelist` file. The AArch64 Globals Tagging pass may remove
2353    this attribute when it's not possible to tag the global (e.g. it's a TLS
2354    variable).
2355``sanitize_address_dyninit``
2356    This attribute indicates that the global variable, when instrumented with
2357    AddressSanitizer, should be checked for ODR violations. This attribute is
2358    applied to global variables that are dynamically initialized according to
2359    C++ rules.
2360
2361.. _opbundles:
2362
2363Operand Bundles
2364---------------
2365
2366Operand bundles are tagged sets of SSA values that can be associated
2367with certain LLVM instructions (currently only ``call`` s and
2368``invoke`` s).  In a way they are like metadata, but dropping them is
2369incorrect and will change program semantics.
2370
2371Syntax::
2372
2373    operand bundle set ::= '[' operand bundle (, operand bundle )* ']'
2374    operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')'
2375    bundle operand ::= SSA value
2376    tag ::= string constant
2377
2378Operand bundles are **not** part of a function's signature, and a
2379given function may be called from multiple places with different kinds
2380of operand bundles.  This reflects the fact that the operand bundles
2381are conceptually a part of the ``call`` (or ``invoke``), not the
2382callee being dispatched to.
2383
2384Operand bundles are a generic mechanism intended to support
2385runtime-introspection-like functionality for managed languages.  While
2386the exact semantics of an operand bundle depend on the bundle tag,
2387there are certain limitations to how much the presence of an operand
2388bundle can influence the semantics of a program.  These restrictions
2389are described as the semantics of an "unknown" operand bundle.  As
2390long as the behavior of an operand bundle is describable within these
2391restrictions, LLVM does not need to have special knowledge of the
2392operand bundle to not miscompile programs containing it.
2393
2394- The bundle operands for an unknown operand bundle escape in unknown
2395  ways before control is transferred to the callee or invokee.
2396- Calls and invokes with operand bundles have unknown read / write
2397  effect on the heap on entry and exit (even if the call target is
2398  ``readnone`` or ``readonly``), unless they're overridden with
2399  callsite specific attributes.
2400- An operand bundle at a call site cannot change the implementation
2401  of the called function.  Inter-procedural optimizations work as
2402  usual as long as they take into account the first two properties.
2403
2404More specific types of operand bundles are described below.
2405
2406.. _deopt_opbundles:
2407
2408Deoptimization Operand Bundles
2409^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2410
2411Deoptimization operand bundles are characterized by the ``"deopt"``
2412operand bundle tag.  These operand bundles represent an alternate
2413"safe" continuation for the call site they're attached to, and can be
2414used by a suitable runtime to deoptimize the compiled frame at the
2415specified call site.  There can be at most one ``"deopt"`` operand
2416bundle attached to a call site.  Exact details of deoptimization is
2417out of scope for the language reference, but it usually involves
2418rewriting a compiled frame into a set of interpreted frames.
2419
2420From the compiler's perspective, deoptimization operand bundles make
2421the call sites they're attached to at least ``readonly``.  They read
2422through all of their pointer typed operands (even if they're not
2423otherwise escaped) and the entire visible heap.  Deoptimization
2424operand bundles do not capture their operands except during
2425deoptimization, in which case control will not be returned to the
2426compiled frame.
2427
2428The inliner knows how to inline through calls that have deoptimization
2429operand bundles.  Just like inlining through a normal call site
2430involves composing the normal and exceptional continuations, inlining
2431through a call site with a deoptimization operand bundle needs to
2432appropriately compose the "safe" deoptimization continuation.  The
2433inliner does this by prepending the parent's deoptimization
2434continuation to every deoptimization continuation in the inlined body.
2435E.g. inlining ``@f`` into ``@g`` in the following example
2436
2437.. code-block:: llvm
2438
2439    define void @f() {
2440      call void @x()  ;; no deopt state
2441      call void @y() [ "deopt"(i32 10) ]
2442      call void @y() [ "deopt"(i32 10), "unknown"(i8* null) ]
2443      ret void
2444    }
2445
2446    define void @g() {
2447      call void @f() [ "deopt"(i32 20) ]
2448      ret void
2449    }
2450
2451will result in
2452
2453.. code-block:: llvm
2454
2455    define void @g() {
2456      call void @x()  ;; still no deopt state
2457      call void @y() [ "deopt"(i32 20, i32 10) ]
2458      call void @y() [ "deopt"(i32 20, i32 10), "unknown"(i8* null) ]
2459      ret void
2460    }
2461
2462It is the frontend's responsibility to structure or encode the
2463deoptimization state in a way that syntactically prepending the
2464caller's deoptimization state to the callee's deoptimization state is
2465semantically equivalent to composing the caller's deoptimization
2466continuation after the callee's deoptimization continuation.
2467
2468.. _ob_funclet:
2469
2470Funclet Operand Bundles
2471^^^^^^^^^^^^^^^^^^^^^^^
2472
2473Funclet operand bundles are characterized by the ``"funclet"``
2474operand bundle tag.  These operand bundles indicate that a call site
2475is within a particular funclet.  There can be at most one
2476``"funclet"`` operand bundle attached to a call site and it must have
2477exactly one bundle operand.
2478
2479If any funclet EH pads have been "entered" but not "exited" (per the
2480`description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_),
2481it is undefined behavior to execute a ``call`` or ``invoke`` which:
2482
2483* does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind
2484  intrinsic, or
2485* has a ``"funclet"`` bundle whose operand is not the most-recently-entered
2486  not-yet-exited funclet EH pad.
2487
2488Similarly, if no funclet EH pads have been entered-but-not-yet-exited,
2489executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior.
2490
2491GC Transition Operand Bundles
2492^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2493
2494GC transition operand bundles are characterized by the
2495``"gc-transition"`` operand bundle tag. These operand bundles mark a
2496call as a transition between a function with one GC strategy to a
2497function with a different GC strategy. If coordinating the transition
2498between GC strategies requires additional code generation at the call
2499site, these bundles may contain any values that are needed by the
2500generated code.  For more details, see :ref:`GC Transitions
2501<gc_transition_args>`.
2502
2503The bundle contain an arbitrary list of Values which need to be passed
2504to GC transition code. They will be lowered and passed as operands to
2505the appropriate GC_TRANSITION nodes in the selection DAG. It is assumed
2506that these arguments must be available before and after (but not
2507necessarily during) the execution of the callee.
2508
2509.. _assume_opbundles:
2510
2511Assume Operand Bundles
2512^^^^^^^^^^^^^^^^^^^^^^
2513
2514Operand bundles on an :ref:`llvm.assume <int_assume>` allows representing
2515assumptions that a :ref:`parameter attribute <paramattrs>` or a
2516:ref:`function attribute <fnattrs>` holds for a certain value at a certain
2517location. Operand bundles enable assumptions that are either hard or impossible
2518to represent as a boolean argument of an :ref:`llvm.assume <int_assume>`.
2519
2520An assume operand bundle has the form:
2521
2522::
2523
2524      "<tag>"([ <holds for value> [, <attribute argument>] ])
2525
2526* The tag of the operand bundle is usually the name of attribute that can be
2527  assumed to hold. It can also be `ignore`, this tag doesn't contain any
2528  information and should be ignored.
2529* The first argument if present is the value for which the attribute hold.
2530* The second argument if present is an argument of the attribute.
2531
2532If there are no arguments the attribute is a property of the call location.
2533
2534For example:
2535
2536.. code-block:: llvm
2537
2538      call void @llvm.assume(i1 true) ["align"(i32* %val, i32 8)]
2539
2540allows the optimizer to assume that at location of call to
2541:ref:`llvm.assume <int_assume>` ``%val`` has an alignment of at least 8.
2542
2543.. code-block:: llvm
2544
2545      call void @llvm.assume(i1 %cond) ["cold"(), "nonnull"(i64* %val)]
2546
2547allows the optimizer to assume that the :ref:`llvm.assume <int_assume>`
2548call location is cold and that ``%val`` may not be null.
2549
2550Just like for the argument of :ref:`llvm.assume <int_assume>`, if any of the
2551provided guarantees are violated at runtime the behavior is undefined.
2552
2553While attributes expect constant arguments, assume operand bundles may be
2554provided a dynamic value, for example:
2555
2556.. code-block:: llvm
2557
2558      call void @llvm.assume(i1 true) ["align"(i32* %val, i32 %align)]
2559
2560If the operand bundle value violates any requirements on the attribute value,
2561the behavior is undefined, unless one of the following exceptions applies:
2562
2563* ``"assume"`` operand bundles may specify a non-power-of-two alignment
2564  (including a zero alignment). If this is the case, then the pointer value
2565  must be a null pointer, otherwise the behavior is undefined.
2566
2567Even if the assumed property can be encoded as a boolean value, like
2568``nonnull``, using operand bundles to express the property can still have
2569benefits:
2570
2571* Attributes that can be expressed via operand bundles are directly the
2572  property that the optimizer uses and cares about. Encoding attributes as
2573  operand bundles removes the need for an instruction sequence that represents
2574  the property (e.g., `icmp ne i32* %p, null` for `nonnull`) and for the
2575  optimizer to deduce the property from that instruction sequence.
2576* Expressing the property using operand bundles makes it easy to identify the
2577  use of the value as a use in an :ref:`llvm.assume <int_assume>`. This then
2578  simplifies and improves heuristics, e.g., for use "use-sensitive"
2579  optimizations.
2580
2581.. _ob_preallocated:
2582
2583Preallocated Operand Bundles
2584^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2585
2586Preallocated operand bundles are characterized by the ``"preallocated"``
2587operand bundle tag.  These operand bundles allow separation of the allocation
2588of the call argument memory from the call site.  This is necessary to pass
2589non-trivially copyable objects by value in a way that is compatible with MSVC
2590on some targets.  There can be at most one ``"preallocated"`` operand bundle
2591attached to a call site and it must have exactly one bundle operand, which is
2592a token generated by ``@llvm.call.preallocated.setup``.  A call with this
2593operand bundle should not adjust the stack before entering the function, as
2594that will have been done by one of the ``@llvm.call.preallocated.*`` intrinsics.
2595
2596.. code-block:: llvm
2597
2598      %foo = type { i64, i32 }
2599
2600      ...
2601
2602      %t = call token @llvm.call.preallocated.setup(i32 1)
2603      %a = call i8* @llvm.call.preallocated.arg(token %t, i32 0) preallocated(%foo)
2604      %b = bitcast i8* %a to %foo*
2605      ; initialize %b
2606      call void @bar(i32 42, %foo* preallocated(%foo) %b) ["preallocated"(token %t)]
2607
2608.. _ob_gc_live:
2609
2610GC Live Operand Bundles
2611^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2612
2613A "gc-live" operand bundle is only valid on a :ref:`gc.statepoint <gc_statepoint>`
2614intrinsic. The operand bundle must contain every pointer to a garbage collected
2615object which potentially needs to be updated by the garbage collector.
2616
2617When lowered, any relocated value will be recorded in the corresponding
2618:ref:`stackmap entry <statepoint-stackmap-format>`.  See the intrinsic description
2619for further details.
2620
2621ObjC ARC Attached Call Operand Bundles
2622^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2623
2624A ``"clang.arc.attachedcall"`` operand bundle on a call indicates the call is
2625implicitly followed by a marker instruction and a call to an ObjC runtime
2626function that uses the result of the call. The operand bundle takes a mandatory
2627pointer to the runtime function (``@objc_retainAutoreleasedReturnValue`` or
2628``@objc_unsafeClaimAutoreleasedReturnValue``).
2629The return value of a call with this bundle is used by a call to
2630``@llvm.objc.clang.arc.noop.use`` unless the called function's return type is
2631void, in which case the operand bundle is ignored.
2632
2633.. code-block:: llvm
2634
2635   ; The marker instruction and a runtime function call are inserted after the call
2636   ; to @foo.
2637   call i8* @foo() [ "clang.arc.attachedcall"(i8* (i8*)* @objc_retainAutoreleasedReturnValue) ]
2638   call i8* @foo() [ "clang.arc.attachedcall"(i8* (i8*)* @objc_unsafeClaimAutoreleasedReturnValue) ]
2639
2640The operand bundle is needed to ensure the call is immediately followed by the
2641marker instruction and the ObjC runtime call in the final output.
2642
2643.. _ob_ptrauth:
2644
2645Pointer Authentication Operand Bundles
2646^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2647
2648Pointer Authentication operand bundles are characterized by the
2649``"ptrauth"`` operand bundle tag.  They are described in the
2650`Pointer Authentication <PointerAuth.html#operand-bundle>`__ document.
2651
2652.. _moduleasm:
2653
2654Module-Level Inline Assembly
2655----------------------------
2656
2657Modules may contain "module-level inline asm" blocks, which corresponds
2658to the GCC "file scope inline asm" blocks. These blocks are internally
2659concatenated by LLVM and treated as a single unit, but may be separated
2660in the ``.ll`` file if desired. The syntax is very simple:
2661
2662.. code-block:: llvm
2663
2664    module asm "inline asm code goes here"
2665    module asm "more can go here"
2666
2667The strings can contain any character by escaping non-printable
2668characters. The escape sequence used is simply "\\xx" where "xx" is the
2669two digit hex code for the number.
2670
2671Note that the assembly string *must* be parseable by LLVM's integrated assembler
2672(unless it is disabled), even when emitting a ``.s`` file.
2673
2674.. _langref_datalayout:
2675
2676Data Layout
2677-----------
2678
2679A module may specify a target specific data layout string that specifies
2680how data is to be laid out in memory. The syntax for the data layout is
2681simply:
2682
2683.. code-block:: llvm
2684
2685    target datalayout = "layout specification"
2686
2687The *layout specification* consists of a list of specifications
2688separated by the minus sign character ('-'). Each specification starts
2689with a letter and may include other information after the letter to
2690define some aspect of the data layout. The specifications accepted are
2691as follows:
2692
2693``E``
2694    Specifies that the target lays out data in big-endian form. That is,
2695    the bits with the most significance have the lowest address
2696    location.
2697``e``
2698    Specifies that the target lays out data in little-endian form. That
2699    is, the bits with the least significance have the lowest address
2700    location.
2701``S<size>``
2702    Specifies the natural alignment of the stack in bits. Alignment
2703    promotion of stack variables is limited to the natural stack
2704    alignment to avoid dynamic stack realignment. The stack alignment
2705    must be a multiple of 8-bits. If omitted, the natural stack
2706    alignment defaults to "unspecified", which does not prevent any
2707    alignment promotions.
2708``P<address space>``
2709    Specifies the address space that corresponds to program memory.
2710    Harvard architectures can use this to specify what space LLVM
2711    should place things such as functions into. If omitted, the
2712    program memory space defaults to the default address space of 0,
2713    which corresponds to a Von Neumann architecture that has code
2714    and data in the same space.
2715``G<address space>``
2716    Specifies the address space to be used by default when creating global
2717    variables. If omitted, the globals address space defaults to the default
2718    address space 0.
2719    Note: variable declarations without an address space are always created in
2720    address space 0, this property only affects the default value to be used
2721    when creating globals without additional contextual information (e.g. in
2722    LLVM passes).
2723``A<address space>``
2724    Specifies the address space of objects created by '``alloca``'.
2725    Defaults to the default address space of 0.
2726``p[n]:<size>:<abi>[:<pref>][:<idx>]``
2727    This specifies the *size* of a pointer and its ``<abi>`` and
2728    ``<pref>``\erred alignments for address space ``n``. ``<pref>`` is optional
2729    and defaults to ``<abi>``. The fourth parameter ``<idx>`` is the size of the
2730    index that used for address calculation. If not
2731    specified, the default index size is equal to the pointer size. All sizes
2732    are in bits. The address space, ``n``, is optional, and if not specified,
2733    denotes the default address space 0. The value of ``n`` must be
2734    in the range [1,2^23).
2735``i<size>:<abi>[:<pref>]``
2736    This specifies the alignment for an integer type of a given bit
2737    ``<size>``. The value of ``<size>`` must be in the range [1,2^23).
2738    ``<pref>`` is optional and defaults to ``<abi>``.
2739``v<size>:<abi>[:<pref>]``
2740    This specifies the alignment for a vector type of a given bit
2741    ``<size>``. The value of ``<size>`` must be in the range [1,2^23).
2742    ``<pref>`` is optional and defaults to ``<abi>``.
2743``f<size>:<abi>[:<pref>]``
2744    This specifies the alignment for a floating-point type of a given bit
2745    ``<size>``. Only values of ``<size>`` that are supported by the target
2746    will work. 32 (float) and 64 (double) are supported on all targets; 80
2747    or 128 (different flavors of long double) are also supported on some
2748    targets. The value of ``<size>`` must be in the range [1,2^23).
2749    ``<pref>`` is optional and defaults to ``<abi>``.
2750``a:<abi>[:<pref>]``
2751    This specifies the alignment for an object of aggregate type.
2752    ``<pref>`` is optional and defaults to ``<abi>``.
2753``F<type><abi>``
2754    This specifies the alignment for function pointers.
2755    The options for ``<type>`` are:
2756
2757    * ``i``: The alignment of function pointers is independent of the alignment
2758      of functions, and is a multiple of ``<abi>``.
2759    * ``n``: The alignment of function pointers is a multiple of the explicit
2760      alignment specified on the function, and is a multiple of ``<abi>``.
2761``m:<mangling>``
2762    If present, specifies that llvm names are mangled in the output. Symbols
2763    prefixed with the mangling escape character ``\01`` are passed through
2764    directly to the assembler without the escape character. The mangling style
2765    options are
2766
2767    * ``e``: ELF mangling: Private symbols get a ``.L`` prefix.
2768    * ``l``: GOFF mangling: Private symbols get a ``@`` prefix.
2769    * ``m``: Mips mangling: Private symbols get a ``$`` prefix.
2770    * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other
2771      symbols get a ``_`` prefix.
2772    * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix.
2773      Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``,
2774      ``__fastcall``, and ``__vectorcall`` have custom mangling that appends
2775      ``@N`` where N is the number of bytes used to pass parameters. C++ symbols
2776      starting with ``?`` are not mangled in any way.
2777    * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C
2778      symbols do not receive a ``_`` prefix.
2779    * ``a``: XCOFF mangling: Private symbols get a ``L..`` prefix.
2780``n<size1>:<size2>:<size3>...``
2781    This specifies a set of native integer widths for the target CPU in
2782    bits. For example, it might contain ``n32`` for 32-bit PowerPC,
2783    ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of
2784    this set are considered to support most general arithmetic operations
2785    efficiently.
2786``ni:<address space0>:<address space1>:<address space2>...``
2787    This specifies pointer types with the specified address spaces
2788    as :ref:`Non-Integral Pointer Type <nointptrtype>` s.  The ``0``
2789    address space cannot be specified as non-integral.
2790
2791On every specification that takes a ``<abi>:<pref>``, specifying the
2792``<pref>`` alignment is optional. If omitted, the preceding ``:``
2793should be omitted too and ``<pref>`` will be equal to ``<abi>``.
2794
2795When constructing the data layout for a given target, LLVM starts with a
2796default set of specifications which are then (possibly) overridden by
2797the specifications in the ``datalayout`` keyword. The default
2798specifications are given in this list:
2799
2800-  ``e`` - little endian
2801-  ``p:64:64:64`` - 64-bit pointers with 64-bit alignment.
2802-  ``p[n]:64:64:64`` - Other address spaces are assumed to be the
2803   same as the default address space.
2804-  ``S0`` - natural stack alignment is unspecified
2805-  ``i1:8:8`` - i1 is 8-bit (byte) aligned
2806-  ``i8:8:8`` - i8 is 8-bit (byte) aligned
2807-  ``i16:16:16`` - i16 is 16-bit aligned
2808-  ``i32:32:32`` - i32 is 32-bit aligned
2809-  ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred
2810   alignment of 64-bits
2811-  ``f16:16:16`` - half is 16-bit aligned
2812-  ``f32:32:32`` - float is 32-bit aligned
2813-  ``f64:64:64`` - double is 64-bit aligned
2814-  ``f128:128:128`` - quad is 128-bit aligned
2815-  ``v64:64:64`` - 64-bit vector is 64-bit aligned
2816-  ``v128:128:128`` - 128-bit vector is 128-bit aligned
2817-  ``a:0:64`` - aggregates are 64-bit aligned
2818
2819When LLVM is determining the alignment for a given type, it uses the
2820following rules:
2821
2822#. If the type sought is an exact match for one of the specifications,
2823   that specification is used.
2824#. If no match is found, and the type sought is an integer type, then
2825   the smallest integer type that is larger than the bitwidth of the
2826   sought type is used. If none of the specifications are larger than
2827   the bitwidth then the largest integer type is used. For example,
2828   given the default specifications above, the i7 type will use the
2829   alignment of i8 (next largest) while both i65 and i256 will use the
2830   alignment of i64 (largest specified).
2831
2832The function of the data layout string may not be what you expect.
2833Notably, this is not a specification from the frontend of what alignment
2834the code generator should use.
2835
2836Instead, if specified, the target data layout is required to match what
2837the ultimate *code generator* expects. This string is used by the
2838mid-level optimizers to improve code, and this only works if it matches
2839what the ultimate code generator uses. There is no way to generate IR
2840that does not embed this target-specific detail into the IR. If you
2841don't specify the string, the default specifications will be used to
2842generate a Data Layout and the optimization phases will operate
2843accordingly and introduce target specificity into the IR with respect to
2844these default specifications.
2845
2846.. _langref_triple:
2847
2848Target Triple
2849-------------
2850
2851A module may specify a target triple string that describes the target
2852host. The syntax for the target triple is simply:
2853
2854.. code-block:: llvm
2855
2856    target triple = "x86_64-apple-macosx10.7.0"
2857
2858The *target triple* string consists of a series of identifiers delimited
2859by the minus sign character ('-'). The canonical forms are:
2860
2861::
2862
2863    ARCHITECTURE-VENDOR-OPERATING_SYSTEM
2864    ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
2865
2866This information is passed along to the backend so that it generates
2867code for the proper architecture. It's possible to override this on the
2868command line with the ``-mtriple`` command line option.
2869
2870.. _objectlifetime:
2871
2872Object Lifetime
2873----------------------
2874
2875A memory object, or simply object, is a region of a memory space that is
2876reserved by a memory allocation such as :ref:`alloca <i_alloca>`, heap
2877allocation calls, and global variable definitions.
2878Once it is allocated, the bytes stored in the region can only be read or written
2879through a pointer that is :ref:`based on <pointeraliasing>` the allocation
2880value.
2881If a pointer that is not based on the object tries to read or write to the
2882object, it is undefined behavior.
2883
2884A lifetime of a memory object is a property that decides its accessibility.
2885Unless stated otherwise, a memory object is alive since its allocation, and
2886dead after its deallocation.
2887It is undefined behavior to access a memory object that isn't alive, but
2888operations that don't dereference it such as
2889:ref:`getelementptr <i_getelementptr>`, :ref:`ptrtoint <i_ptrtoint>` and
2890:ref:`icmp <i_icmp>` return a valid result.
2891This explains code motion of these instructions across operations that
2892impact the object's lifetime.
2893A stack object's lifetime can be explicitly specified using
2894:ref:`llvm.lifetime.start <int_lifestart>` and
2895:ref:`llvm.lifetime.end <int_lifeend>` intrinsic function calls.
2896
2897.. _pointeraliasing:
2898
2899Pointer Aliasing Rules
2900----------------------
2901
2902Any memory access must be done through a pointer value associated with
2903an address range of the memory access, otherwise the behavior is
2904undefined. Pointer values are associated with address ranges according
2905to the following rules:
2906
2907-  A pointer value is associated with the addresses associated with any
2908   value it is *based* on.
2909-  An address of a global variable is associated with the address range
2910   of the variable's storage.
2911-  The result value of an allocation instruction is associated with the
2912   address range of the allocated storage.
2913-  A null pointer in the default address-space is associated with no
2914   address.
2915-  An :ref:`undef value <undefvalues>` in *any* address-space is
2916   associated with no address.
2917-  An integer constant other than zero or a pointer value returned from
2918   a function not defined within LLVM may be associated with address
2919   ranges allocated through mechanisms other than those provided by
2920   LLVM. Such ranges shall not overlap with any ranges of addresses
2921   allocated by mechanisms provided by LLVM.
2922
2923A pointer value is *based* on another pointer value according to the
2924following rules:
2925
2926-  A pointer value formed from a scalar ``getelementptr`` operation is *based* on
2927   the pointer-typed operand of the ``getelementptr``.
2928-  The pointer in lane *l* of the result of a vector ``getelementptr`` operation
2929   is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand
2930   of the ``getelementptr``.
2931-  The result value of a ``bitcast`` is *based* on the operand of the
2932   ``bitcast``.
2933-  A pointer value formed by an ``inttoptr`` is *based* on all pointer
2934   values that contribute (directly or indirectly) to the computation of
2935   the pointer's value.
2936-  The "*based* on" relationship is transitive.
2937
2938Note that this definition of *"based"* is intentionally similar to the
2939definition of *"based"* in C99, though it is slightly weaker.
2940
2941LLVM IR does not associate types with memory. The result type of a
2942``load`` merely indicates the size and alignment of the memory from
2943which to load, as well as the interpretation of the value. The first
2944operand type of a ``store`` similarly only indicates the size and
2945alignment of the store.
2946
2947Consequently, type-based alias analysis, aka TBAA, aka
2948``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR.
2949:ref:`Metadata <metadata>` may be used to encode additional information
2950which specialized optimization passes may use to implement type-based
2951alias analysis.
2952
2953.. _pointercapture:
2954
2955Pointer Capture
2956---------------
2957
2958Given a function call and a pointer that is passed as an argument or stored in
2959the memory before the call, a pointer is *captured* by the call if it makes a
2960copy of any part of the pointer that outlives the call.
2961To be precise, a pointer is captured if one or more of the following conditions
2962hold:
2963
29641. The call stores any bit of the pointer carrying information into a place,
2965   and the stored bits can be read from the place by the caller after this call
2966   exits.
2967
2968.. code-block:: llvm
2969
2970    @glb  = global i8* null
2971    @glb2 = global i8* null
2972    @glb3 = global i8* null
2973    @glbi = global i32 0
2974
2975    define i8* @f(i8* %a, i8* %b, i8* %c, i8* %d, i8* %e) {
2976      store i8* %a, i8** @glb ; %a is captured by this call
2977
2978      store i8* %b,   i8** @glb2 ; %b isn't captured because the stored value is overwritten by the store below
2979      store i8* null, i8** @glb2
2980
2981      store i8* %c,   i8** @glb3
2982      call void @g() ; If @g makes a copy of %c that outlives this call (@f), %c is captured
2983      store i8* null, i8** @glb3
2984
2985      %i = ptrtoint i8* %d to i64
2986      %j = trunc i64 %i to i32
2987      store i32 %j, i32* @glbi ; %d is captured
2988
2989      ret i8* %e ; %e is captured
2990    }
2991
29922. The call stores any bit of the pointer carrying information into a place,
2993   and the stored bits can be safely read from the place by another thread via
2994   synchronization.
2995
2996.. code-block:: llvm
2997
2998    @lock = global i1 true
2999
3000    define void @f(i8* %a) {
3001      store i8* %a, i8** @glb
3002      store atomic i1 false, i1* @lock release ; %a is captured because another thread can safely read @glb
3003      store i8* null, i8** @glb
3004      ret void
3005    }
3006
30073. The call's behavior depends on any bit of the pointer carrying information.
3008
3009.. code-block:: llvm
3010
3011    @glb = global i8 0
3012
3013    define void @f(i8* %a) {
3014      %c = icmp eq i8* %a, @glb
3015      br i1 %c, label %BB_EXIT, label %BB_CONTINUE ; escapes %a
3016    BB_EXIT:
3017      call void @exit()
3018      unreachable
3019    BB_CONTINUE:
3020      ret void
3021    }
3022
30234. The pointer is used in a volatile access as its address.
3024
3025
3026.. _volatile:
3027
3028Volatile Memory Accesses
3029------------------------
3030
3031Certain memory accesses, such as :ref:`load <i_load>`'s,
3032:ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be
3033marked ``volatile``. The optimizers must not change the number of
3034volatile operations or change their order of execution relative to other
3035volatile operations. The optimizers *may* change the order of volatile
3036operations relative to non-volatile operations. This is not Java's
3037"volatile" and has no cross-thread synchronization behavior.
3038
3039A volatile load or store may have additional target-specific semantics.
3040Any volatile operation can have side effects, and any volatile operation
3041can read and/or modify state which is not accessible via a regular load
3042or store in this module. Volatile operations may use addresses which do
3043not point to memory (like MMIO registers). This means the compiler may
3044not use a volatile operation to prove a non-volatile access to that
3045address has defined behavior.
3046
3047The allowed side-effects for volatile accesses are limited.  If a
3048non-volatile store to a given address would be legal, a volatile
3049operation may modify the memory at that address. A volatile operation
3050may not modify any other memory accessible by the module being compiled.
3051A volatile operation may not call any code in the current module.
3052
3053The compiler may assume execution will continue after a volatile operation,
3054so operations which modify memory or may have undefined behavior can be
3055hoisted past a volatile operation.
3056
3057As an exception to the preceding rule, the compiler may not assume execution
3058will continue after a volatile store operation. This restriction is necessary
3059to support the somewhat common pattern in C of intentionally storing to an
3060invalid pointer to crash the program. In the future, it might make sense to
3061allow frontends to control this behavior.
3062
3063IR-level volatile loads and stores cannot safely be optimized into llvm.memcpy
3064or llvm.memmove intrinsics even when those intrinsics are flagged volatile.
3065Likewise, the backend should never split or merge target-legal volatile
3066load/store instructions. Similarly, IR-level volatile loads and stores cannot
3067change from integer to floating-point or vice versa.
3068
3069.. admonition:: Rationale
3070
3071 Platforms may rely on volatile loads and stores of natively supported
3072 data width to be executed as single instruction. For example, in C
3073 this holds for an l-value of volatile primitive type with native
3074 hardware support, but not necessarily for aggregate types. The
3075 frontend upholds these expectations, which are intentionally
3076 unspecified in the IR. The rules above ensure that IR transformations
3077 do not violate the frontend's contract with the language.
3078
3079.. _memmodel:
3080
3081Memory Model for Concurrent Operations
3082--------------------------------------
3083
3084The LLVM IR does not define any way to start parallel threads of
3085execution or to register signal handlers. Nonetheless, there are
3086platform-specific ways to create them, and we define LLVM IR's behavior
3087in their presence. This model is inspired by the C++0x memory model.
3088
3089For a more informal introduction to this model, see the :doc:`Atomics`.
3090
3091We define a *happens-before* partial order as the least partial order
3092that
3093
3094-  Is a superset of single-thread program order, and
3095-  When a *synchronizes-with* ``b``, includes an edge from ``a`` to
3096   ``b``. *Synchronizes-with* pairs are introduced by platform-specific
3097   techniques, like pthread locks, thread creation, thread joining,
3098   etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering
3099   Constraints <ordering>`).
3100
3101Note that program order does not introduce *happens-before* edges
3102between a thread and signals executing inside that thread.
3103
3104Every (defined) read operation (load instructions, memcpy, atomic
3105loads/read-modify-writes, etc.) R reads a series of bytes written by
3106(defined) write operations (store instructions, atomic
3107stores/read-modify-writes, memcpy, etc.). For the purposes of this
3108section, initialized globals are considered to have a write of the
3109initializer which is atomic and happens before any other read or write
3110of the memory in question. For each byte of a read R, R\ :sub:`byte`
3111may see any write to the same byte, except:
3112
3113-  If write\ :sub:`1`  happens before write\ :sub:`2`, and
3114   write\ :sub:`2` happens before R\ :sub:`byte`, then
3115   R\ :sub:`byte` does not see write\ :sub:`1`.
3116-  If R\ :sub:`byte` happens before write\ :sub:`3`, then
3117   R\ :sub:`byte` does not see write\ :sub:`3`.
3118
3119Given that definition, R\ :sub:`byte` is defined as follows:
3120
3121-  If R is volatile, the result is target-dependent. (Volatile is
3122   supposed to give guarantees which can support ``sig_atomic_t`` in
3123   C/C++, and may be used for accesses to addresses that do not behave
3124   like normal memory. It does not generally provide cross-thread
3125   synchronization.)
3126-  Otherwise, if there is no write to the same byte that happens before
3127   R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte.
3128-  Otherwise, if R\ :sub:`byte` may see exactly one write,
3129   R\ :sub:`byte` returns the value written by that write.
3130-  Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may
3131   see are atomic, it chooses one of the values written. See the :ref:`Atomic
3132   Memory Ordering Constraints <ordering>` section for additional
3133   constraints on how the choice is made.
3134-  Otherwise R\ :sub:`byte` returns ``undef``.
3135
3136R returns the value composed of the series of bytes it read. This
3137implies that some bytes within the value may be ``undef`` **without**
3138the entire value being ``undef``. Note that this only defines the
3139semantics of the operation; it doesn't mean that targets will emit more
3140than one instruction to read the series of bytes.
3141
3142Note that in cases where none of the atomic intrinsics are used, this
3143model places only one restriction on IR transformations on top of what
3144is required for single-threaded execution: introducing a store to a byte
3145which might not otherwise be stored is not allowed in general.
3146(Specifically, in the case where another thread might write to and read
3147from an address, introducing a store can change a load that may see
3148exactly one write into a load that may see multiple writes.)
3149
3150.. _ordering:
3151
3152Atomic Memory Ordering Constraints
3153----------------------------------
3154
3155Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`,
3156:ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`,
3157:ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take
3158ordering parameters that determine which other atomic instructions on
3159the same address they *synchronize with*. These semantics are borrowed
3160from Java and C++0x, but are somewhat more colloquial. If these
3161descriptions aren't precise enough, check those specs (see spec
3162references in the :doc:`atomics guide <Atomics>`).
3163:ref:`fence <i_fence>` instructions treat these orderings somewhat
3164differently since they don't take an address. See that instruction's
3165documentation for details.
3166
3167For a simpler introduction to the ordering constraints, see the
3168:doc:`Atomics`.
3169
3170``unordered``
3171    The set of values that can be read is governed by the happens-before
3172    partial order. A value cannot be read unless some operation wrote
3173    it. This is intended to provide a guarantee strong enough to model
3174    Java's non-volatile shared variables. This ordering cannot be
3175    specified for read-modify-write operations; it is not strong enough
3176    to make them atomic in any interesting way.
3177``monotonic``
3178    In addition to the guarantees of ``unordered``, there is a single
3179    total order for modifications by ``monotonic`` operations on each
3180    address. All modification orders must be compatible with the
3181    happens-before order. There is no guarantee that the modification
3182    orders can be combined to a global total order for the whole program
3183    (and this often will not be possible). The read in an atomic
3184    read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and
3185    :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification
3186    order immediately before the value it writes. If one atomic read
3187    happens before another atomic read of the same address, the later
3188    read must see the same value or a later value in the address's
3189    modification order. This disallows reordering of ``monotonic`` (or
3190    stronger) operations on the same address. If an address is written
3191    ``monotonic``-ally by one thread, and other threads ``monotonic``-ally
3192    read that address repeatedly, the other threads must eventually see
3193    the write. This corresponds to the C++0x/C1x
3194    ``memory_order_relaxed``.
3195``acquire``
3196    In addition to the guarantees of ``monotonic``, a
3197    *synchronizes-with* edge may be formed with a ``release`` operation.
3198    This is intended to model C++'s ``memory_order_acquire``.
3199``release``
3200    In addition to the guarantees of ``monotonic``, if this operation
3201    writes a value which is subsequently read by an ``acquire``
3202    operation, it *synchronizes-with* that operation. (This isn't a
3203    complete description; see the C++0x definition of a release
3204    sequence.) This corresponds to the C++0x/C1x
3205    ``memory_order_release``.
3206``acq_rel`` (acquire+release)
3207    Acts as both an ``acquire`` and ``release`` operation on its
3208    address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``.
3209``seq_cst`` (sequentially consistent)
3210    In addition to the guarantees of ``acq_rel`` (``acquire`` for an
3211    operation that only reads, ``release`` for an operation that only
3212    writes), there is a global total order on all
3213    sequentially-consistent operations on all addresses, which is
3214    consistent with the *happens-before* partial order and with the
3215    modification orders of all the affected addresses. Each
3216    sequentially-consistent read sees the last preceding write to the
3217    same address in this global order. This corresponds to the C++0x/C1x
3218    ``memory_order_seq_cst`` and Java volatile.
3219
3220.. _syncscope:
3221
3222If an atomic operation is marked ``syncscope("singlethread")``, it only
3223*synchronizes with* and only participates in the seq\_cst total orderings of
3224other operations running in the same thread (for example, in signal handlers).
3225
3226If an atomic operation is marked ``syncscope("<target-scope>")``, where
3227``<target-scope>`` is a target specific synchronization scope, then it is target
3228dependent if it *synchronizes with* and participates in the seq\_cst total
3229orderings of other operations.
3230
3231Otherwise, an atomic operation that is not marked ``syncscope("singlethread")``
3232or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the
3233seq\_cst total orderings of other operations that are not marked
3234``syncscope("singlethread")`` or ``syncscope("<target-scope>")``.
3235
3236.. _floatenv:
3237
3238Floating-Point Environment
3239--------------------------
3240
3241The default LLVM floating-point environment assumes that floating-point
3242instructions do not have side effects. Results assume the round-to-nearest
3243rounding mode. No floating-point exception state is maintained in this
3244environment. Therefore, there is no attempt to create or preserve invalid
3245operation (SNaN) or division-by-zero exceptions.
3246
3247The benefit of this exception-free assumption is that floating-point
3248operations may be speculated freely without any other fast-math relaxations
3249to the floating-point model.
3250
3251Code that requires different behavior than this should use the
3252:ref:`Constrained Floating-Point Intrinsics <constrainedfp>`.
3253
3254.. _fastmath:
3255
3256Fast-Math Flags
3257---------------
3258
3259LLVM IR floating-point operations (:ref:`fneg <i_fneg>`, :ref:`fadd <i_fadd>`,
3260:ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
3261:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`), :ref:`phi <i_phi>`,
3262:ref:`select <i_select>` and :ref:`call <i_call>`
3263may use the following flags to enable otherwise unsafe
3264floating-point transformations.
3265
3266``nnan``
3267   No NaNs - Allow optimizations to assume the arguments and result are not
3268   NaN. If an argument is a nan, or the result would be a nan, it produces
3269   a :ref:`poison value <poisonvalues>` instead.
3270
3271``ninf``
3272   No Infs - Allow optimizations to assume the arguments and result are not
3273   +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it
3274   produces a :ref:`poison value <poisonvalues>` instead.
3275
3276``nsz``
3277   No Signed Zeros - Allow optimizations to treat the sign of a zero
3278   argument or result as insignificant. This does not imply that -0.0
3279   is poison and/or guaranteed to not exist in the operation.
3280
3281``arcp``
3282   Allow Reciprocal - Allow optimizations to use the reciprocal of an
3283   argument rather than perform division.
3284
3285``contract``
3286   Allow floating-point contraction (e.g. fusing a multiply followed by an
3287   addition into a fused multiply-and-add). This does not enable reassociating
3288   to form arbitrary contractions. For example, ``(a*b) + (c*d) + e`` can not
3289   be transformed into ``(a*b) + ((c*d) + e)`` to create two fma operations.
3290
3291``afn``
3292   Approximate functions - Allow substitution of approximate calculations for
3293   functions (sin, log, sqrt, etc). See floating-point intrinsic definitions
3294   for places where this can apply to LLVM's intrinsic math functions.
3295
3296``reassoc``
3297   Allow reassociation transformations for floating-point instructions.
3298   This may dramatically change results in floating-point.
3299
3300``fast``
3301   This flag implies all of the others.
3302
3303.. _uselistorder:
3304
3305Use-list Order Directives
3306-------------------------
3307
3308Use-list directives encode the in-memory order of each use-list, allowing the
3309order to be recreated. ``<order-indexes>`` is a comma-separated list of
3310indexes that are assigned to the referenced value's uses. The referenced
3311value's use-list is immediately sorted by these indexes.
3312
3313Use-list directives may appear at function scope or global scope. They are not
3314instructions, and have no effect on the semantics of the IR. When they're at
3315function scope, they must appear after the terminator of the final basic block.
3316
3317If basic blocks have their address taken via ``blockaddress()`` expressions,
3318``uselistorder_bb`` can be used to reorder their use-lists from outside their
3319function's scope.
3320
3321:Syntax:
3322
3323::
3324
3325    uselistorder <ty> <value>, { <order-indexes> }
3326    uselistorder_bb @function, %block { <order-indexes> }
3327
3328:Examples:
3329
3330::
3331
3332    define void @foo(i32 %arg1, i32 %arg2) {
3333    entry:
3334      ; ... instructions ...
3335    bb:
3336      ; ... instructions ...
3337
3338      ; At function scope.
3339      uselistorder i32 %arg1, { 1, 0, 2 }
3340      uselistorder label %bb, { 1, 0 }
3341    }
3342
3343    ; At global scope.
3344    uselistorder i32* @global, { 1, 2, 0 }
3345    uselistorder i32 7, { 1, 0 }
3346    uselistorder i32 (i32) @bar, { 1, 0 }
3347    uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 }
3348
3349.. _source_filename:
3350
3351Source Filename
3352---------------
3353
3354The *source filename* string is set to the original module identifier,
3355which will be the name of the compiled source file when compiling from
3356source through the clang front end, for example. It is then preserved through
3357the IR and bitcode.
3358
3359This is currently necessary to generate a consistent unique global
3360identifier for local functions used in profile data, which prepends the
3361source file name to the local function name.
3362
3363The syntax for the source file name is simply:
3364
3365.. code-block:: text
3366
3367    source_filename = "/path/to/source.c"
3368
3369.. _typesystem:
3370
3371Type System
3372===========
3373
3374The LLVM type system is one of the most important features of the
3375intermediate representation. Being typed enables a number of
3376optimizations to be performed on the intermediate representation
3377directly, without having to do extra analyses on the side before the
3378transformation. A strong type system makes it easier to read the
3379generated code and enables novel analyses and transformations that are
3380not feasible to perform on normal three address code representations.
3381
3382.. _t_void:
3383
3384Void Type
3385---------
3386
3387:Overview:
3388
3389
3390The void type does not represent any value and has no size.
3391
3392:Syntax:
3393
3394
3395::
3396
3397      void
3398
3399
3400.. _t_function:
3401
3402Function Type
3403-------------
3404
3405:Overview:
3406
3407
3408The function type can be thought of as a function signature. It consists of a
3409return type and a list of formal parameter types. The return type of a function
3410type is a void type or first class type --- except for :ref:`label <t_label>`
3411and :ref:`metadata <t_metadata>` types.
3412
3413:Syntax:
3414
3415::
3416
3417      <returntype> (<parameter list>)
3418
3419...where '``<parameter list>``' is a comma-separated list of type
3420specifiers. Optionally, the parameter list may include a type ``...``, which
3421indicates that the function takes a variable number of arguments. Variable
3422argument functions can access their arguments with the :ref:`variable argument
3423handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type
3424except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`.
3425
3426:Examples:
3427
3428+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3429| ``i32 (i32)``                   | function taking an ``i32``, returning an ``i32``                                                                                                                    |
3430+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3431| ``float (i16, i32 *) *``        | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``.                                    |
3432+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3433| ``i32 (i8*, ...)``              | A vararg function that takes at least one :ref:`pointer <t_pointer>` to ``i8`` (char in C), which returns an integer. This is the signature for ``printf`` in LLVM. |
3434+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3435| ``{i32, i32} (i32)``            | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values                                                                 |
3436+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3437
3438.. _t_firstclass:
3439
3440First Class Types
3441-----------------
3442
3443The :ref:`first class <t_firstclass>` types are perhaps the most important.
3444Values of these types are the only ones which can be produced by
3445instructions.
3446
3447.. _t_single_value:
3448
3449Single Value Types
3450^^^^^^^^^^^^^^^^^^
3451
3452These are the types that are valid in registers from CodeGen's perspective.
3453
3454.. _t_integer:
3455
3456Integer Type
3457""""""""""""
3458
3459:Overview:
3460
3461The integer type is a very simple type that simply specifies an
3462arbitrary bit width for the integer type desired. Any bit width from 1
3463bit to 2\ :sup:`23`\ (about 8 million) can be specified.
3464
3465:Syntax:
3466
3467::
3468
3469      iN
3470
3471The number of bits the integer will occupy is specified by the ``N``
3472value.
3473
3474Examples:
3475*********
3476
3477+----------------+------------------------------------------------+
3478| ``i1``         | a single-bit integer.                          |
3479+----------------+------------------------------------------------+
3480| ``i32``        | a 32-bit integer.                              |
3481+----------------+------------------------------------------------+
3482| ``i1942652``   | a really big integer of over 1 million bits.   |
3483+----------------+------------------------------------------------+
3484
3485.. _t_floating:
3486
3487Floating-Point Types
3488""""""""""""""""""""
3489
3490.. list-table::
3491   :header-rows: 1
3492
3493   * - Type
3494     - Description
3495
3496   * - ``half``
3497     - 16-bit floating-point value
3498
3499   * - ``bfloat``
3500     - 16-bit "brain" floating-point value (7-bit significand).  Provides the
3501       same number of exponent bits as ``float``, so that it matches its dynamic
3502       range, but with greatly reduced precision.  Used in Intel's AVX-512 BF16
3503       extensions and Arm's ARMv8.6-A extensions, among others.
3504
3505   * - ``float``
3506     - 32-bit floating-point value
3507
3508   * - ``double``
3509     - 64-bit floating-point value
3510
3511   * - ``fp128``
3512     - 128-bit floating-point value (113-bit significand)
3513
3514   * - ``x86_fp80``
3515     -  80-bit floating-point value (X87)
3516
3517   * - ``ppc_fp128``
3518     - 128-bit floating-point value (two 64-bits)
3519
3520The binary format of half, float, double, and fp128 correspond to the
3521IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128
3522respectively.
3523
3524X86_amx Type
3525""""""""""""
3526
3527:Overview:
3528
3529The x86_amx type represents a value held in an AMX tile register on an x86
3530machine. The operations allowed on it are quite limited. Only few intrinsics
3531are allowed: stride load and store, zero and dot product. No instruction is
3532allowed for this type. There are no arguments, arrays, pointers, vectors
3533or constants of this type.
3534
3535:Syntax:
3536
3537::
3538
3539      x86_amx
3540
3541
3542X86_mmx Type
3543""""""""""""
3544
3545:Overview:
3546
3547The x86_mmx type represents a value held in an MMX register on an x86
3548machine. The operations allowed on it are quite limited: parameters and
3549return values, load and store, and bitcast. User-specified MMX
3550instructions are represented as intrinsic or asm calls with arguments
3551and/or results of this type. There are no arrays, vectors or constants
3552of this type.
3553
3554:Syntax:
3555
3556::
3557
3558      x86_mmx
3559
3560
3561.. _t_pointer:
3562
3563Pointer Type
3564""""""""""""
3565
3566:Overview:
3567
3568The pointer type is used to specify memory locations. Pointers are
3569commonly used to reference objects in memory.
3570
3571Pointer types may have an optional address space attribute defining the
3572numbered address space where the pointed-to object resides. The default
3573address space is number zero. The semantics of non-zero address spaces
3574are target-specific.
3575
3576Note that LLVM does not permit pointers to void (``void*``) nor does it
3577permit pointers to labels (``label*``). Use ``i8*`` instead.
3578
3579LLVM is in the process of transitioning to
3580`opaque pointers <OpaquePointers.html#opaque-pointers>`_.
3581Opaque pointers do not have a pointee type. Rather, instructions
3582interacting through pointers specify the type of the underlying memory
3583they are interacting with. Opaque pointers are still in the process of
3584being worked on and are not complete.
3585
3586:Syntax:
3587
3588::
3589
3590      <type> *
3591      ptr
3592
3593:Examples:
3594
3595+-------------------------+--------------------------------------------------------------------------------------------------------------+
3596| ``[4 x i32]*``          | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values.                               |
3597+-------------------------+--------------------------------------------------------------------------------------------------------------+
3598| ``i32 (i32*) *``        | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. |
3599+-------------------------+--------------------------------------------------------------------------------------------------------------+
3600| ``i32 addrspace(5)*``   | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space 5.                            |
3601+-------------------------+--------------------------------------------------------------------------------------------------------------+
3602| ``ptr``                 | An opaque pointer type to a value that resides in address space 0.                                           |
3603+-------------------------+--------------------------------------------------------------------------------------------------------------+
3604| ``ptr addrspace(5)``    | An opaque pointer type to a value that resides in address space 5.                                           |
3605+-------------------------+--------------------------------------------------------------------------------------------------------------+
3606
3607.. _t_vector:
3608
3609Vector Type
3610"""""""""""
3611
3612:Overview:
3613
3614A vector type is a simple derived type that represents a vector of
3615elements. Vector types are used when multiple primitive data are
3616operated in parallel using a single instruction (SIMD). A vector type
3617requires a size (number of elements), an underlying primitive data type,
3618and a scalable property to represent vectors where the exact hardware
3619vector length is unknown at compile time. Vector types are considered
3620:ref:`first class <t_firstclass>`.
3621
3622:Memory Layout:
3623
3624In general vector elements are laid out in memory in the same way as
3625:ref:`array types <t_array>`. Such an analogy works fine as long as the vector
3626elements are byte sized. However, when the elements of the vector aren't byte
3627sized it gets a bit more complicated. One way to describe the layout is by
3628describing what happens when a vector such as <N x iM> is bitcasted to an
3629integer type with N*M bits, and then following the rules for storing such an
3630integer to memory.
3631
3632A bitcast from a vector type to a scalar integer type will see the elements
3633being packed together (without padding). The order in which elements are
3634inserted in the integer depends on endianess. For little endian element zero
3635is put in the least significant bits of the integer, and for big endian
3636element zero is put in the most significant bits.
3637
3638Using a vector such as ``<i4 1, i4 2, i4 3, i4 5>`` as an example, together
3639with the analogy that we can replace a vector store by a bitcast followed by
3640an integer store, we get this for big endian:
3641
3642.. code-block:: llvm
3643
3644      %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16
3645
3646      ; Bitcasting from a vector to an integral type can be seen as
3647      ; concatenating the values:
3648      ;   %val now has the hexadecimal value 0x1235.
3649
3650      store i16 %val, i16* %ptr
3651
3652      ; In memory the content will be (8-bit addressing):
3653      ;
3654      ;    [%ptr + 0]: 00010010  (0x12)
3655      ;    [%ptr + 1]: 00110101  (0x35)
3656
3657The same example for little endian:
3658
3659.. code-block:: llvm
3660
3661      %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16
3662
3663      ; Bitcasting from a vector to an integral type can be seen as
3664      ; concatenating the values:
3665      ;   %val now has the hexadecimal value 0x5321.
3666
3667      store i16 %val, i16* %ptr
3668
3669      ; In memory the content will be (8-bit addressing):
3670      ;
3671      ;    [%ptr + 0]: 01010011  (0x53)
3672      ;    [%ptr + 1]: 00100001  (0x21)
3673
3674When ``<N*M>`` isn't evenly divisible by the byte size the exact memory layout
3675is unspecified (just like it is for an integral type of the same size). This
3676is because different targets could put the padding at different positions when
3677the type size is smaller than the type's store size.
3678
3679:Syntax:
3680
3681::
3682
3683      < <# elements> x <elementtype> >          ; Fixed-length vector
3684      < vscale x <# elements> x <elementtype> > ; Scalable vector
3685
3686The number of elements is a constant integer value larger than 0;
3687elementtype may be any integer, floating-point or pointer type. Vectors
3688of size zero are not allowed. For scalable vectors, the total number of
3689elements is a constant multiple (called vscale) of the specified number
3690of elements; vscale is a positive integer that is unknown at compile time
3691and the same hardware-dependent constant for all scalable vectors at run
3692time. The size of a specific scalable vector type is thus constant within
3693IR, even if the exact size in bytes cannot be determined until run time.
3694
3695:Examples:
3696
3697+------------------------+----------------------------------------------------+
3698| ``<4 x i32>``          | Vector of 4 32-bit integer values.                 |
3699+------------------------+----------------------------------------------------+
3700| ``<8 x float>``        | Vector of 8 32-bit floating-point values.          |
3701+------------------------+----------------------------------------------------+
3702| ``<2 x i64>``          | Vector of 2 64-bit integer values.                 |
3703+------------------------+----------------------------------------------------+
3704| ``<4 x i64*>``         | Vector of 4 pointers to 64-bit integer values.     |
3705+------------------------+----------------------------------------------------+
3706| ``<vscale x 4 x i32>`` | Vector with a multiple of 4 32-bit integer values. |
3707+------------------------+----------------------------------------------------+
3708
3709.. _t_label:
3710
3711Label Type
3712^^^^^^^^^^
3713
3714:Overview:
3715
3716The label type represents code labels.
3717
3718:Syntax:
3719
3720::
3721
3722      label
3723
3724.. _t_token:
3725
3726Token Type
3727^^^^^^^^^^
3728
3729:Overview:
3730
3731The token type is used when a value is associated with an instruction
3732but all uses of the value must not attempt to introspect or obscure it.
3733As such, it is not appropriate to have a :ref:`phi <i_phi>` or
3734:ref:`select <i_select>` of type token.
3735
3736:Syntax:
3737
3738::
3739
3740      token
3741
3742
3743
3744.. _t_metadata:
3745
3746Metadata Type
3747^^^^^^^^^^^^^
3748
3749:Overview:
3750
3751The metadata type represents embedded metadata. No derived types may be
3752created from metadata except for :ref:`function <t_function>` arguments.
3753
3754:Syntax:
3755
3756::
3757
3758      metadata
3759
3760.. _t_aggregate:
3761
3762Aggregate Types
3763^^^^^^^^^^^^^^^
3764
3765Aggregate Types are a subset of derived types that can contain multiple
3766member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are
3767aggregate types. :ref:`Vectors <t_vector>` are not considered to be
3768aggregate types.
3769
3770.. _t_array:
3771
3772Array Type
3773""""""""""
3774
3775:Overview:
3776
3777The array type is a very simple derived type that arranges elements
3778sequentially in memory. The array type requires a size (number of
3779elements) and an underlying data type.
3780
3781:Syntax:
3782
3783::
3784
3785      [<# elements> x <elementtype>]
3786
3787The number of elements is a constant integer value; ``elementtype`` may
3788be any type with a size.
3789
3790:Examples:
3791
3792+------------------+--------------------------------------+
3793| ``[40 x i32]``   | Array of 40 32-bit integer values.   |
3794+------------------+--------------------------------------+
3795| ``[41 x i32]``   | Array of 41 32-bit integer values.   |
3796+------------------+--------------------------------------+
3797| ``[4 x i8]``     | Array of 4 8-bit integer values.     |
3798+------------------+--------------------------------------+
3799
3800Here are some examples of multidimensional arrays:
3801
3802+-----------------------------+----------------------------------------------------------+
3803| ``[3 x [4 x i32]]``         | 3x4 array of 32-bit integer values.                      |
3804+-----------------------------+----------------------------------------------------------+
3805| ``[12 x [10 x float]]``     | 12x10 array of single precision floating-point values.   |
3806+-----------------------------+----------------------------------------------------------+
3807| ``[2 x [3 x [4 x i16]]]``   | 2x3x4 array of 16-bit integer values.                    |
3808+-----------------------------+----------------------------------------------------------+
3809
3810There is no restriction on indexing beyond the end of the array implied
3811by a static type (though there are restrictions on indexing beyond the
3812bounds of an allocated object in some cases). This means that
3813single-dimension 'variable sized array' addressing can be implemented in
3814LLVM with a zero length array type. An implementation of 'pascal style
3815arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for
3816example.
3817
3818.. _t_struct:
3819
3820Structure Type
3821""""""""""""""
3822
3823:Overview:
3824
3825The structure type is used to represent a collection of data members
3826together in memory. The elements of a structure may be any type that has
3827a size.
3828
3829Structures in memory are accessed using '``load``' and '``store``' by
3830getting a pointer to a field with the '``getelementptr``' instruction.
3831Structures in registers are accessed using the '``extractvalue``' and
3832'``insertvalue``' instructions.
3833
3834Structures may optionally be "packed" structures, which indicate that
3835the alignment of the struct is one byte, and that there is no padding
3836between the elements. In non-packed structs, padding between field types
3837is inserted as defined by the DataLayout string in the module, which is
3838required to match what the underlying code generator expects.
3839
3840Structures can either be "literal" or "identified". A literal structure
3841is defined inline with other types (e.g. ``{i32, i32}*``) whereas
3842identified types are always defined at the top level with a name.
3843Literal types are uniqued by their contents and can never be recursive
3844or opaque since there is no way to write one. Identified types can be
3845recursive, can be opaqued, and are never uniqued.
3846
3847:Syntax:
3848
3849::
3850
3851      %T1 = type { <type list> }     ; Identified normal struct type
3852      %T2 = type <{ <type list> }>   ; Identified packed struct type
3853
3854:Examples:
3855
3856+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3857| ``{ i32, i32, i32 }``        | A triple of three ``i32`` values                                                                                                                                                      |
3858+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3859| ``{ float, i32 (i32) * }``   | A pair, where the first element is a ``float`` and the second element is a :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32``, returning an ``i32``.  |
3860+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3861| ``<{ i8, i32 }>``            | A packed struct known to be 5 bytes in size.                                                                                                                                          |
3862+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3863
3864.. _t_opaque:
3865
3866Opaque Structure Types
3867""""""""""""""""""""""
3868
3869:Overview:
3870
3871Opaque structure types are used to represent structure types that
3872do not have a body specified. This corresponds (for example) to the C
3873notion of a forward declared structure. They can be named (``%X``) or
3874unnamed (``%52``).
3875
3876:Syntax:
3877
3878::
3879
3880      %X = type opaque
3881      %52 = type opaque
3882
3883:Examples:
3884
3885+--------------+-------------------+
3886| ``opaque``   | An opaque type.   |
3887+--------------+-------------------+
3888
3889.. _constants:
3890
3891Constants
3892=========
3893
3894LLVM has several different basic types of constants. This section
3895describes them all and their syntax.
3896
3897Simple Constants
3898----------------
3899
3900**Boolean constants**
3901    The two strings '``true``' and '``false``' are both valid constants
3902    of the ``i1`` type.
3903**Integer constants**
3904    Standard integers (such as '4') are constants of the
3905    :ref:`integer <t_integer>` type. Negative numbers may be used with
3906    integer types.
3907**Floating-point constants**
3908    Floating-point constants use standard decimal notation (e.g.
3909    123.421), exponential notation (e.g. 1.23421e+2), or a more precise
3910    hexadecimal notation (see below). The assembler requires the exact
3911    decimal value of a floating-point constant. For example, the
3912    assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating
3913    decimal in binary. Floating-point constants must have a
3914    :ref:`floating-point <t_floating>` type.
3915**Null pointer constants**
3916    The identifier '``null``' is recognized as a null pointer constant
3917    and must be of :ref:`pointer type <t_pointer>`.
3918**Token constants**
3919    The identifier '``none``' is recognized as an empty token constant
3920    and must be of :ref:`token type <t_token>`.
3921
3922The one non-intuitive notation for constants is the hexadecimal form of
3923floating-point constants. For example, the form
3924'``double    0x432ff973cafa8000``' is equivalent to (but harder to read
3925than) '``double 4.5e+15``'. The only time hexadecimal floating-point
3926constants are required (and the only time that they are generated by the
3927disassembler) is when a floating-point constant must be emitted but it
3928cannot be represented as a decimal floating-point number in a reasonable
3929number of digits. For example, NaN's, infinities, and other special
3930values are represented in their IEEE hexadecimal format so that assembly
3931and disassembly do not cause any bits to change in the constants.
3932
3933When using the hexadecimal form, constants of types bfloat, half, float, and
3934double are represented using the 16-digit form shown above (which matches the
3935IEEE754 representation for double); bfloat, half and float values must, however,
3936be exactly representable as bfloat, IEEE 754 half, and IEEE 754 single
3937precision respectively. Hexadecimal format is always used for long double, and
3938there are three forms of long double. The 80-bit format used by x86 is
3939represented as ``0xK`` followed by 20 hexadecimal digits. The 128-bit format
3940used by PowerPC (two adjacent doubles) is represented by ``0xM`` followed by 32
3941hexadecimal digits. The IEEE 128-bit format is represented by ``0xL`` followed
3942by 32 hexadecimal digits. Long doubles will only work if they match the long
3943double format on your target.  The IEEE 16-bit format (half precision) is
3944represented by ``0xH`` followed by 4 hexadecimal digits. The bfloat 16-bit
3945format is represented by ``0xR`` followed by 4 hexadecimal digits. All
3946hexadecimal formats are big-endian (sign bit at the left).
3947
3948There are no constants of type x86_mmx and x86_amx.
3949
3950.. _complexconstants:
3951
3952Complex Constants
3953-----------------
3954
3955Complex constants are a (potentially recursive) combination of simple
3956constants and smaller complex constants.
3957
3958**Structure constants**
3959    Structure constants are represented with notation similar to
3960    structure type definitions (a comma separated list of elements,
3961    surrounded by braces (``{}``)). For example:
3962    "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as
3963    "``@G = external global i32``". Structure constants must have
3964    :ref:`structure type <t_struct>`, and the number and types of elements
3965    must match those specified by the type.
3966**Array constants**
3967    Array constants are represented with notation similar to array type
3968    definitions (a comma separated list of elements, surrounded by
3969    square brackets (``[]``)). For example:
3970    "``[ i32 42, i32 11, i32 74 ]``". Array constants must have
3971    :ref:`array type <t_array>`, and the number and types of elements must
3972    match those specified by the type. As a special case, character array
3973    constants may also be represented as a double-quoted string using the ``c``
3974    prefix. For example: "``c"Hello World\0A\00"``".
3975**Vector constants**
3976    Vector constants are represented with notation similar to vector
3977    type definitions (a comma separated list of elements, surrounded by
3978    less-than/greater-than's (``<>``)). For example:
3979    "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants
3980    must have :ref:`vector type <t_vector>`, and the number and types of
3981    elements must match those specified by the type.
3982**Zero initialization**
3983    The string '``zeroinitializer``' can be used to zero initialize a
3984    value to zero of *any* type, including scalar and
3985    :ref:`aggregate <t_aggregate>` types. This is often used to avoid
3986    having to print large zero initializers (e.g. for large arrays) and
3987    is always exactly equivalent to using explicit zero initializers.
3988**Metadata node**
3989    A metadata node is a constant tuple without types. For example:
3990    "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values,
3991    for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``".
3992    Unlike other typed constants that are meant to be interpreted as part of
3993    the instruction stream, metadata is a place to attach additional
3994    information such as debug info.
3995
3996Global Variable and Function Addresses
3997--------------------------------------
3998
3999The addresses of :ref:`global variables <globalvars>` and
4000:ref:`functions <functionstructure>` are always implicitly valid
4001(link-time) constants. These constants are explicitly referenced when
4002the :ref:`identifier for the global <identifiers>` is used and always have
4003:ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM
4004file:
4005
4006.. code-block:: llvm
4007
4008    @X = global i32 17
4009    @Y = global i32 42
4010    @Z = global [2 x i32*] [ i32* @X, i32* @Y ]
4011
4012.. _undefvalues:
4013
4014Undefined Values
4015----------------
4016
4017The string '``undef``' can be used anywhere a constant is expected, and
4018indicates that the user of the value may receive an unspecified
4019bit-pattern. Undefined values may be of any type (other than '``label``'
4020or '``void``') and be used anywhere a constant is permitted.
4021
4022.. note::
4023
4024  A '``poison``' value (decribed in the next section) should be used instead of
4025  '``undef``' whenever possible. Poison values are stronger than undef, and
4026  enable more optimizations. Just the existence of '``undef``' blocks certain
4027  optimizations (see the examples below).
4028
4029Undefined values are useful because they indicate to the compiler that
4030the program is well defined no matter what value is used. This gives the
4031compiler more freedom to optimize. Here are some examples of
4032(potentially surprising) transformations that are valid (in pseudo IR):
4033
4034.. code-block:: llvm
4035
4036      %A = add %X, undef
4037      %B = sub %X, undef
4038      %C = xor %X, undef
4039    Safe:
4040      %A = undef
4041      %B = undef
4042      %C = undef
4043
4044This is safe because all of the output bits are affected by the undef
4045bits. Any output bit can have a zero or one depending on the input bits.
4046
4047.. code-block:: llvm
4048
4049      %A = or %X, undef
4050      %B = and %X, undef
4051    Safe:
4052      %A = -1
4053      %B = 0
4054    Safe:
4055      %A = %X  ;; By choosing undef as 0
4056      %B = %X  ;; By choosing undef as -1
4057    Unsafe:
4058      %A = undef
4059      %B = undef
4060
4061These logical operations have bits that are not always affected by the
4062input. For example, if ``%X`` has a zero bit, then the output of the
4063'``and``' operation will always be a zero for that bit, no matter what
4064the corresponding bit from the '``undef``' is. As such, it is unsafe to
4065optimize or assume that the result of the '``and``' is '``undef``'.
4066However, it is safe to assume that all bits of the '``undef``' could be
40670, and optimize the '``and``' to 0. Likewise, it is safe to assume that
4068all the bits of the '``undef``' operand to the '``or``' could be set,
4069allowing the '``or``' to be folded to -1.
4070
4071.. code-block:: llvm
4072
4073      %A = select undef, %X, %Y
4074      %B = select undef, 42, %Y
4075      %C = select %X, %Y, undef
4076    Safe:
4077      %A = %X     (or %Y)
4078      %B = 42     (or %Y)
4079      %C = %Y     (if %Y is provably not poison; unsafe otherwise)
4080    Unsafe:
4081      %A = undef
4082      %B = undef
4083      %C = undef
4084
4085This set of examples shows that undefined '``select``' (and conditional
4086branch) conditions can go *either way*, but they have to come from one
4087of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were
4088both known to have a clear low bit, then ``%A`` would have to have a
4089cleared low bit. However, in the ``%C`` example, the optimizer is
4090allowed to assume that the '``undef``' operand could be the same as
4091``%Y`` if ``%Y`` is provably not '``poison``', allowing the whole '``select``'
4092to be eliminated. This is because '``poison``' is stronger than '``undef``'.
4093
4094.. code-block:: llvm
4095
4096      %A = xor undef, undef
4097
4098      %B = undef
4099      %C = xor %B, %B
4100
4101      %D = undef
4102      %E = icmp slt %D, 4
4103      %F = icmp gte %D, 4
4104
4105    Safe:
4106      %A = undef
4107      %B = undef
4108      %C = undef
4109      %D = undef
4110      %E = undef
4111      %F = undef
4112
4113This example points out that two '``undef``' operands are not
4114necessarily the same. This can be surprising to people (and also matches
4115C semantics) where they assume that "``X^X``" is always zero, even if
4116``X`` is undefined. This isn't true for a number of reasons, but the
4117short answer is that an '``undef``' "variable" can arbitrarily change
4118its value over its "live range". This is true because the variable
4119doesn't actually *have a live range*. Instead, the value is logically
4120read from arbitrary registers that happen to be around when needed, so
4121the value is not necessarily consistent over time. In fact, ``%A`` and
4122``%C`` need to have the same semantics or the core LLVM "replace all
4123uses with" concept would not hold.
4124
4125To ensure all uses of a given register observe the same value (even if
4126'``undef``'), the :ref:`freeze instruction <i_freeze>` can be used.
4127
4128.. code-block:: llvm
4129
4130      %A = sdiv undef, %X
4131      %B = sdiv %X, undef
4132    Safe:
4133      %A = 0
4134    b: unreachable
4135
4136These examples show the crucial difference between an *undefined value*
4137and *undefined behavior*. An undefined value (like '``undef``') is
4138allowed to have an arbitrary bit-pattern. This means that the ``%A``
4139operation can be constant folded to '``0``', because the '``undef``'
4140could be zero, and zero divided by any value is zero.
4141However, in the second example, we can make a more aggressive
4142assumption: because the ``undef`` is allowed to be an arbitrary value,
4143we are allowed to assume that it could be zero. Since a divide by zero
4144has *undefined behavior*, we are allowed to assume that the operation
4145does not execute at all. This allows us to delete the divide and all
4146code after it. Because the undefined operation "can't happen", the
4147optimizer can assume that it occurs in dead code.
4148
4149.. code-block:: text
4150
4151    a:  store undef -> %X
4152    b:  store %X -> undef
4153    Safe:
4154    a: <deleted>     (if the stored value in %X is provably not poison)
4155    b: unreachable
4156
4157A store *of* an undefined value can be assumed to not have any effect;
4158we can assume that the value is overwritten with bits that happen to
4159match what was already there. This argument is only valid if the stored value
4160is provably not ``poison``. However, a store *to* an undefined
4161location could clobber arbitrary memory, therefore, it has undefined
4162behavior.
4163
4164Branching on an undefined value is undefined behavior.
4165This explains optimizations that depend on branch conditions to construct
4166predicates, such as Correlated Value Propagation and Global Value Numbering.
4167In case of switch instruction, the branch condition should be frozen, otherwise
4168it is undefined behavior.
4169
4170.. code-block:: llvm
4171
4172    Unsafe:
4173      br undef, BB1, BB2 ; UB
4174
4175      %X = and i32 undef, 255
4176      switch %X, label %ret [ .. ] ; UB
4177
4178      store undef, i8* %ptr
4179      %X = load i8* %ptr ; %X is undef
4180      switch i8 %X, label %ret [ .. ] ; UB
4181
4182    Safe:
4183      %X = or i8 undef, 255 ; always 255
4184      switch i8 %X, label %ret [ .. ] ; Well-defined
4185
4186      %X = freeze i1 undef
4187      br %X, BB1, BB2 ; Well-defined (non-deterministic jump)
4188
4189
4190
4191.. _poisonvalues:
4192
4193Poison Values
4194-------------
4195
4196A poison value is a result of an erroneous operation.
4197In order to facilitate speculative execution, many instructions do not
4198invoke immediate undefined behavior when provided with illegal operands,
4199and return a poison value instead.
4200The string '``poison``' can be used anywhere a constant is expected, and
4201operations such as :ref:`add <i_add>` with the ``nsw`` flag can produce
4202a poison value.
4203
4204Most instructions return '``poison``' when one of their arguments is
4205'``poison``'. A notable exception is the :ref:`select instruction <i_select>`.
4206Propagation of poison can be stopped with the
4207:ref:`freeze instruction <i_freeze>`.
4208
4209It is correct to replace a poison value with an
4210:ref:`undef value <undefvalues>` or any value of the type.
4211
4212This means that immediate undefined behavior occurs if a poison value is
4213used as an instruction operand that has any values that trigger undefined
4214behavior. Notably this includes (but is not limited to):
4215
4216-  The pointer operand of a :ref:`load <i_load>`, :ref:`store <i_store>` or
4217   any other pointer dereferencing instruction (independent of address
4218   space).
4219-  The divisor operand of a ``udiv``, ``sdiv``, ``urem`` or ``srem``
4220   instruction.
4221-  The condition operand of a :ref:`br <i_br>` instruction.
4222-  The callee operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
4223   instruction.
4224-  The parameter operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
4225   instruction, when the function or invoking call site has a ``noundef``
4226   attribute in the corresponding position.
4227-  The operand of a :ref:`ret <i_ret>` instruction if the function or invoking
4228   call site has a `noundef` attribute in the return value position.
4229
4230Here are some examples:
4231
4232.. code-block:: llvm
4233
4234    entry:
4235      %poison = sub nuw i32 0, 1           ; Results in a poison value.
4236      %poison2 = sub i32 poison, 1         ; Also results in a poison value.
4237      %still_poison = and i32 %poison, 0   ; 0, but also poison.
4238      %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison
4239      store i32 0, i32* %poison_yet_again  ; Undefined behavior due to
4240                                           ; store to poison.
4241
4242      store i32 %poison, i32* @g           ; Poison value stored to memory.
4243      %poison3 = load i32, i32* @g         ; Poison value loaded back from memory.
4244
4245      %narrowaddr = bitcast i32* @g to i16*
4246      %wideaddr = bitcast i32* @g to i64*
4247      %poison4 = load i16, i16* %narrowaddr ; Returns a poison value.
4248      %poison5 = load i64, i64* %wideaddr   ; Returns a poison value.
4249
4250      %cmp = icmp slt i32 %poison, 0       ; Returns a poison value.
4251      br i1 %cmp, label %end, label %end   ; undefined behavior
4252
4253    end:
4254
4255.. _welldefinedvalues:
4256
4257Well-Defined Values
4258-------------------
4259
4260Given a program execution, a value is *well defined* if the value does not
4261have an undef bit and is not poison in the execution.
4262An aggregate value or vector is well defined if its elements are well defined.
4263The padding of an aggregate isn't considered, since it isn't visible
4264without storing it into memory and loading it with a different type.
4265
4266A constant of a :ref:`single value <t_single_value>`, non-vector type is well
4267defined if it is neither '``undef``' constant nor '``poison``' constant.
4268The result of :ref:`freeze instruction <i_freeze>` is well defined regardless
4269of its operand.
4270
4271.. _blockaddress:
4272
4273Addresses of Basic Blocks
4274-------------------------
4275
4276``blockaddress(@function, %block)``
4277
4278The '``blockaddress``' constant computes the address of the specified
4279basic block in the specified function.
4280
4281It always has an ``i8 addrspace(P)*`` type, where ``P`` is the address space
4282of the function containing ``%block`` (usually ``addrspace(0)``).
4283
4284Taking the address of the entry block is illegal.
4285
4286This value only has defined behavior when used as an operand to the
4287':ref:`indirectbr <i_indirectbr>`' or ':ref:`callbr <i_callbr>`'instruction, or
4288for comparisons against null. Pointer equality tests between labels addresses
4289results in undefined behavior --- though, again, comparison against null is ok,
4290and no label is equal to the null pointer. This may be passed around as an
4291opaque pointer sized value as long as the bits are not inspected. This
4292allows ``ptrtoint`` and arithmetic to be performed on these values so
4293long as the original value is reconstituted before the ``indirectbr`` or
4294``callbr`` instruction.
4295
4296Finally, some targets may provide defined semantics when using the value
4297as the operand to an inline assembly, but that is target specific.
4298
4299.. _dso_local_equivalent:
4300
4301DSO Local Equivalent
4302--------------------
4303
4304``dso_local_equivalent @func``
4305
4306A '``dso_local_equivalent``' constant represents a function which is
4307functionally equivalent to a given function, but is always defined in the
4308current linkage unit. The resulting pointer has the same type as the underlying
4309function. The resulting pointer is permitted, but not required, to be different
4310from a pointer to the function, and it may have different values in different
4311translation units.
4312
4313The target function may not have ``extern_weak`` linkage.
4314
4315``dso_local_equivalent`` can be implemented as such:
4316
4317- If the function has local linkage, hidden visibility, or is
4318  ``dso_local``, ``dso_local_equivalent`` can be implemented as simply a pointer
4319  to the function.
4320- ``dso_local_equivalent`` can be implemented with a stub that tail-calls the
4321  function. Many targets support relocations that resolve at link time to either
4322  a function or a stub for it, depending on if the function is defined within the
4323  linkage unit; LLVM will use this when available. (This is commonly called a
4324  "PLT stub".) On other targets, the stub may need to be emitted explicitly.
4325
4326This can be used wherever a ``dso_local`` instance of a function is needed without
4327needing to explicitly make the original function ``dso_local``. An instance where
4328this can be used is for static offset calculations between a function and some other
4329``dso_local`` symbol. This is especially useful for the Relative VTables C++ ABI,
4330where dynamic relocations for function pointers in VTables can be replaced with
4331static relocations for offsets between the VTable and virtual functions which
4332may not be ``dso_local``.
4333
4334This is currently only supported for ELF binary formats.
4335
4336.. _no_cfi:
4337
4338No CFI
4339------
4340
4341``no_cfi @func``
4342
4343With `Control-Flow Integrity (CFI)
4344<https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, a '``no_cfi``'
4345constant represents a function reference that does not get replaced with a
4346reference to the CFI jump table in the ``LowerTypeTests`` pass. These constants
4347may be useful in low-level programs, such as operating system kernels, which
4348need to refer to the actual function body.
4349
4350.. _constantexprs:
4351
4352Constant Expressions
4353--------------------
4354
4355Constant expressions are used to allow expressions involving other
4356constants to be used as constants. Constant expressions may be of any
4357:ref:`first class <t_firstclass>` type and may involve any LLVM operation
4358that does not have side effects (e.g. load and call are not supported).
4359The following is the syntax for constant expressions:
4360
4361``trunc (CST to TYPE)``
4362    Perform the :ref:`trunc operation <i_trunc>` on constants.
4363``zext (CST to TYPE)``
4364    Perform the :ref:`zext operation <i_zext>` on constants.
4365``sext (CST to TYPE)``
4366    Perform the :ref:`sext operation <i_sext>` on constants.
4367``fptrunc (CST to TYPE)``
4368    Truncate a floating-point constant to another floating-point type.
4369    The size of CST must be larger than the size of TYPE. Both types
4370    must be floating-point.
4371``fpext (CST to TYPE)``
4372    Floating-point extend a constant to another type. The size of CST
4373    must be smaller or equal to the size of TYPE. Both types must be
4374    floating-point.
4375``fptoui (CST to TYPE)``
4376    Convert a floating-point constant to the corresponding unsigned
4377    integer constant. TYPE must be a scalar or vector integer type. CST
4378    must be of scalar or vector floating-point type. Both CST and TYPE
4379    must be scalars, or vectors of the same number of elements. If the
4380    value won't fit in the integer type, the result is a
4381    :ref:`poison value <poisonvalues>`.
4382``fptosi (CST to TYPE)``
4383    Convert a floating-point constant to the corresponding signed
4384    integer constant. TYPE must be a scalar or vector integer type. CST
4385    must be of scalar or vector floating-point type. Both CST and TYPE
4386    must be scalars, or vectors of the same number of elements. If the
4387    value won't fit in the integer type, the result is a
4388    :ref:`poison value <poisonvalues>`.
4389``uitofp (CST to TYPE)``
4390    Convert an unsigned integer constant to the corresponding
4391    floating-point constant. TYPE must be a scalar or vector floating-point
4392    type.  CST must be of scalar or vector integer type. Both CST and TYPE must
4393    be scalars, or vectors of the same number of elements.
4394``sitofp (CST to TYPE)``
4395    Convert a signed integer constant to the corresponding floating-point
4396    constant. TYPE must be a scalar or vector floating-point type.
4397    CST must be of scalar or vector integer type. Both CST and TYPE must
4398    be scalars, or vectors of the same number of elements.
4399``ptrtoint (CST to TYPE)``
4400    Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants.
4401``inttoptr (CST to TYPE)``
4402    Perform the :ref:`inttoptr operation <i_inttoptr>` on constants.
4403    This one is *really* dangerous!
4404``bitcast (CST to TYPE)``
4405    Convert a constant, CST, to another TYPE.
4406    The constraints of the operands are the same as those for the
4407    :ref:`bitcast instruction <i_bitcast>`.
4408``addrspacecast (CST to TYPE)``
4409    Convert a constant pointer or constant vector of pointer, CST, to another
4410    TYPE in a different address space. The constraints of the operands are the
4411    same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`.
4412``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)``
4413    Perform the :ref:`getelementptr operation <i_getelementptr>` on
4414    constants. As with the :ref:`getelementptr <i_getelementptr>`
4415    instruction, the index list may have one or more indexes, which are
4416    required to make sense for the type of "pointer to TY".
4417``select (COND, VAL1, VAL2)``
4418    Perform the :ref:`select operation <i_select>` on constants.
4419``icmp COND (VAL1, VAL2)``
4420    Perform the :ref:`icmp operation <i_icmp>` on constants.
4421``fcmp COND (VAL1, VAL2)``
4422    Perform the :ref:`fcmp operation <i_fcmp>` on constants.
4423``extractelement (VAL, IDX)``
4424    Perform the :ref:`extractelement operation <i_extractelement>` on
4425    constants.
4426``insertelement (VAL, ELT, IDX)``
4427    Perform the :ref:`insertelement operation <i_insertelement>` on
4428    constants.
4429``shufflevector (VEC1, VEC2, IDXMASK)``
4430    Perform the :ref:`shufflevector operation <i_shufflevector>` on
4431    constants.
4432``extractvalue (VAL, IDX0, IDX1, ...)``
4433    Perform the :ref:`extractvalue operation <i_extractvalue>` on
4434    constants. The index list is interpreted in a similar manner as
4435    indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At
4436    least one index value must be specified.
4437``insertvalue (VAL, ELT, IDX0, IDX1, ...)``
4438    Perform the :ref:`insertvalue operation <i_insertvalue>` on constants.
4439    The index list is interpreted in a similar manner as indices in a
4440    ':ref:`getelementptr <i_getelementptr>`' operation. At least one index
4441    value must be specified.
4442``OPCODE (LHS, RHS)``
4443    Perform the specified operation of the LHS and RHS constants. OPCODE
4444    may be any of the :ref:`binary <binaryops>` or :ref:`bitwise
4445    binary <bitwiseops>` operations. The constraints on operands are
4446    the same as those for the corresponding instruction (e.g. no bitwise
4447    operations on floating-point values are allowed).
4448
4449Other Values
4450============
4451
4452.. _inlineasmexprs:
4453
4454Inline Assembler Expressions
4455----------------------------
4456
4457LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level
4458Inline Assembly <moduleasm>`) through the use of a special value. This value
4459represents the inline assembler as a template string (containing the
4460instructions to emit), a list of operand constraints (stored as a string), a
4461flag that indicates whether or not the inline asm expression has side effects,
4462and a flag indicating whether the function containing the asm needs to align its
4463stack conservatively.
4464
4465The template string supports argument substitution of the operands using "``$``"
4466followed by a number, to indicate substitution of the given register/memory
4467location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also
4468be used, where ``MODIFIER`` is a target-specific annotation for how to print the
4469operand (See :ref:`inline-asm-modifiers`).
4470
4471A literal "``$``" may be included by using "``$$``" in the template. To include
4472other special characters into the output, the usual "``\XX``" escapes may be
4473used, just as in other strings. Note that after template substitution, the
4474resulting assembly string is parsed by LLVM's integrated assembler unless it is
4475disabled -- even when emitting a ``.s`` file -- and thus must contain assembly
4476syntax known to LLVM.
4477
4478LLVM also supports a few more substitutions useful for writing inline assembly:
4479
4480- ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob.
4481  This substitution is useful when declaring a local label. Many standard
4482  compiler optimizations, such as inlining, may duplicate an inline asm blob.
4483  Adding a blob-unique identifier ensures that the two labels will not conflict
4484  during assembly. This is used to implement `GCC's %= special format
4485  string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_.
4486- ``${:comment}``: Expands to the comment character of the current target's
4487  assembly dialect. This is usually ``#``, but many targets use other strings,
4488  such as ``;``, ``//``, or ``!``.
4489- ``${:private}``: Expands to the assembler private label prefix. Labels with
4490  this prefix will not appear in the symbol table of the assembled object.
4491  Typically the prefix is ``L``, but targets may use other strings. ``.L`` is
4492  relatively popular.
4493
4494LLVM's support for inline asm is modeled closely on the requirements of Clang's
4495GCC-compatible inline-asm support. Thus, the feature-set and the constraint and
4496modifier codes listed here are similar or identical to those in GCC's inline asm
4497support. However, to be clear, the syntax of the template and constraint strings
4498described here is *not* the same as the syntax accepted by GCC and Clang, and,
4499while most constraint letters are passed through as-is by Clang, some get
4500translated to other codes when converting from the C source to the LLVM
4501assembly.
4502
4503An example inline assembler expression is:
4504
4505.. code-block:: llvm
4506
4507    i32 (i32) asm "bswap $0", "=r,r"
4508
4509Inline assembler expressions may **only** be used as the callee operand
4510of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction.
4511Thus, typically we have:
4512
4513.. code-block:: llvm
4514
4515    %X = call i32 asm "bswap $0", "=r,r"(i32 %Y)
4516
4517Inline asms with side effects not visible in the constraint list must be
4518marked as having side effects. This is done through the use of the
4519'``sideeffect``' keyword, like so:
4520
4521.. code-block:: llvm
4522
4523    call void asm sideeffect "eieio", ""()
4524
4525In some cases inline asms will contain code that will not work unless
4526the stack is aligned in some way, such as calls or SSE instructions on
4527x86, yet will not contain code that does that alignment within the asm.
4528The compiler should make conservative assumptions about what the asm
4529might contain and should generate its usual stack alignment code in the
4530prologue if the '``alignstack``' keyword is present:
4531
4532.. code-block:: llvm
4533
4534    call void asm alignstack "eieio", ""()
4535
4536Inline asms also support using non-standard assembly dialects. The
4537assumed dialect is ATT. When the '``inteldialect``' keyword is present,
4538the inline asm is using the Intel dialect. Currently, ATT and Intel are
4539the only supported dialects. An example is:
4540
4541.. code-block:: llvm
4542
4543    call void asm inteldialect "eieio", ""()
4544
4545In the case that the inline asm might unwind the stack,
4546the '``unwind``' keyword must be used, so that the compiler emits
4547unwinding information:
4548
4549.. code-block:: llvm
4550
4551    call void asm unwind "call func", ""()
4552
4553If the inline asm unwinds the stack and isn't marked with
4554the '``unwind``' keyword, the behavior is undefined.
4555
4556If multiple keywords appear, the '``sideeffect``' keyword must come
4557first, the '``alignstack``' keyword second, the '``inteldialect``' keyword
4558third and the '``unwind``' keyword last.
4559
4560Inline Asm Constraint String
4561^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4562
4563The constraint list is a comma-separated string, each element containing one or
4564more constraint codes.
4565
4566For each element in the constraint list an appropriate register or memory
4567operand will be chosen, and it will be made available to assembly template
4568string expansion as ``$0`` for the first constraint in the list, ``$1`` for the
4569second, etc.
4570
4571There are three different types of constraints, which are distinguished by a
4572prefix symbol in front of the constraint code: Output, Input, and Clobber. The
4573constraints must always be given in that order: outputs first, then inputs, then
4574clobbers. They cannot be intermingled.
4575
4576There are also three different categories of constraint codes:
4577
4578- Register constraint. This is either a register class, or a fixed physical
4579  register. This kind of constraint will allocate a register, and if necessary,
4580  bitcast the argument or result to the appropriate type.
4581- Memory constraint. This kind of constraint is for use with an instruction
4582  taking a memory operand. Different constraints allow for different addressing
4583  modes used by the target.
4584- Immediate value constraint. This kind of constraint is for an integer or other
4585  immediate value which can be rendered directly into an instruction. The
4586  various target-specific constraints allow the selection of a value in the
4587  proper range for the instruction you wish to use it with.
4588
4589Output constraints
4590""""""""""""""""""
4591
4592Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This
4593indicates that the assembly will write to this operand, and the operand will
4594then be made available as a return value of the ``asm`` expression. Output
4595constraints do not consume an argument from the call instruction. (Except, see
4596below about indirect outputs).
4597
4598Normally, it is expected that no output locations are written to by the assembly
4599expression until *all* of the inputs have been read. As such, LLVM may assign
4600the same register to an output and an input. If this is not safe (e.g. if the
4601assembly contains two instructions, where the first writes to one output, and
4602the second reads an input and writes to a second output), then the "``&``"
4603modifier must be used (e.g. "``=&r``") to specify that the output is an
4604"early-clobber" output. Marking an output as "early-clobber" ensures that LLVM
4605will not use the same register for any inputs (other than an input tied to this
4606output).
4607
4608Input constraints
4609"""""""""""""""""
4610
4611Input constraints do not have a prefix -- just the constraint codes. Each input
4612constraint will consume one argument from the call instruction. It is not
4613permitted for the asm to write to any input register or memory location (unless
4614that input is tied to an output). Note also that multiple inputs may all be
4615assigned to the same register, if LLVM can determine that they necessarily all
4616contain the same value.
4617
4618Instead of providing a Constraint Code, input constraints may also "tie"
4619themselves to an output constraint, by providing an integer as the constraint
4620string. Tied inputs still consume an argument from the call instruction, and
4621take up a position in the asm template numbering as is usual -- they will simply
4622be constrained to always use the same register as the output they've been tied
4623to. For example, a constraint string of "``=r,0``" says to assign a register for
4624output, and use that register as an input as well (it being the 0'th
4625constraint).
4626
4627It is permitted to tie an input to an "early-clobber" output. In that case, no
4628*other* input may share the same register as the input tied to the early-clobber
4629(even when the other input has the same value).
4630
4631You may only tie an input to an output which has a register constraint, not a
4632memory constraint. Only a single input may be tied to an output.
4633
4634There is also an "interesting" feature which deserves a bit of explanation: if a
4635register class constraint allocates a register which is too small for the value
4636type operand provided as input, the input value will be split into multiple
4637registers, and all of them passed to the inline asm.
4638
4639However, this feature is often not as useful as you might think.
4640
4641Firstly, the registers are *not* guaranteed to be consecutive. So, on those
4642architectures that have instructions which operate on multiple consecutive
4643instructions, this is not an appropriate way to support them. (e.g. the 32-bit
4644SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The
4645hardware then loads into both the named register, and the next register. This
4646feature of inline asm would not be useful to support that.)
4647
4648A few of the targets provide a template string modifier allowing explicit access
4649to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and
4650``D``). On such an architecture, you can actually access the second allocated
4651register (yet, still, not any subsequent ones). But, in that case, you're still
4652probably better off simply splitting the value into two separate operands, for
4653clarity. (e.g. see the description of the ``A`` constraint on X86, which,
4654despite existing only for use with this feature, is not really a good idea to
4655use)
4656
4657Indirect inputs and outputs
4658"""""""""""""""""""""""""""
4659
4660Indirect output or input constraints can be specified by the "``*``" modifier
4661(which goes after the "``=``" in case of an output). This indicates that the asm
4662will write to or read from the contents of an *address* provided as an input
4663argument. (Note that in this way, indirect outputs act more like an *input* than
4664an output: just like an input, they consume an argument of the call expression,
4665rather than producing a return value. An indirect output constraint is an
4666"output" only in that the asm is expected to write to the contents of the input
4667memory location, instead of just read from it).
4668
4669This is most typically used for memory constraint, e.g. "``=*m``", to pass the
4670address of a variable as a value.
4671
4672It is also possible to use an indirect *register* constraint, but only on output
4673(e.g. "``=*r``"). This will cause LLVM to allocate a register for an output
4674value normally, and then, separately emit a store to the address provided as
4675input, after the provided inline asm. (It's not clear what value this
4676functionality provides, compared to writing the store explicitly after the asm
4677statement, and it can only produce worse code, since it bypasses many
4678optimization passes. I would recommend not using it.)
4679
4680Call arguments for indirect constraints must have pointer type and must specify
4681the :ref:`elementtype <attr_elementtype>` attribute to indicate the pointer
4682element type.
4683
4684Clobber constraints
4685"""""""""""""""""""
4686
4687A clobber constraint is indicated by a "``~``" prefix. A clobber does not
4688consume an input operand, nor generate an output. Clobbers cannot use any of the
4689general constraint code letters -- they may use only explicit register
4690constraints, e.g. "``~{eax}``". The one exception is that a clobber string of
4691"``~{memory}``" indicates that the assembly writes to arbitrary undeclared
4692memory locations -- not only the memory pointed to by a declared indirect
4693output.
4694
4695Note that clobbering named registers that are also present in output
4696constraints is not legal.
4697
4698Label constraints
4699"""""""""""""""""
4700
4701A label constraint is indicated by a "``!``" prefix and typically used in the
4702form ``"!i"``. Instead of consuming call arguments, label constraints consume
4703indirect destination labels of ``callbr`` instructions.
4704
4705Label constraints can only be used in conjunction with ``callbr`` and the
4706number of label constraints must match the number of indirect destination
4707labels in the ``callbr`` instruction.
4708
4709
4710Constraint Codes
4711""""""""""""""""
4712After a potential prefix comes constraint code, or codes.
4713
4714A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character
4715followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``"
4716(e.g. "``{eax}``").
4717
4718The one and two letter constraint codes are typically chosen to be the same as
4719GCC's constraint codes.
4720
4721A single constraint may include one or more than constraint code in it, leaving
4722it up to LLVM to choose which one to use. This is included mainly for
4723compatibility with the translation of GCC inline asm coming from clang.
4724
4725There are two ways to specify alternatives, and either or both may be used in an
4726inline asm constraint list:
4727
47281) Append the codes to each other, making a constraint code set. E.g. "``im``"
4729   or "``{eax}m``". This means "choose any of the options in the set". The
4730   choice of constraint is made independently for each constraint in the
4731   constraint list.
4732
47332) Use "``|``" between constraint code sets, creating alternatives. Every
4734   constraint in the constraint list must have the same number of alternative
4735   sets. With this syntax, the same alternative in *all* of the items in the
4736   constraint list will be chosen together.
4737
4738Putting those together, you might have a two operand constraint string like
4739``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then
4740operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1
4741may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m.
4742
4743However, the use of either of the alternatives features is *NOT* recommended, as
4744LLVM is not able to make an intelligent choice about which one to use. (At the
4745point it currently needs to choose, not enough information is available to do so
4746in a smart way.) Thus, it simply tries to make a choice that's most likely to
4747compile, not one that will be optimal performance. (e.g., given "``rm``", it'll
4748always choose to use memory, not registers). And, if given multiple registers,
4749or multiple register classes, it will simply choose the first one. (In fact, it
4750doesn't currently even ensure explicitly specified physical registers are
4751unique, so specifying multiple physical registers as alternatives, like
4752``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was
4753intended.)
4754
4755Supported Constraint Code List
4756""""""""""""""""""""""""""""""
4757
4758The constraint codes are, in general, expected to behave the same way they do in
4759GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
4760inline asm code which was supported by GCC. A mismatch in behavior between LLVM
4761and GCC likely indicates a bug in LLVM.
4762
4763Some constraint codes are typically supported by all targets:
4764
4765- ``r``: A register in the target's general purpose register class.
4766- ``m``: A memory address operand. It is target-specific what addressing modes
4767  are supported, typical examples are register, or register + register offset,
4768  or register + immediate offset (of some target-specific size).
4769- ``p``: An address operand. Similar to ``m``, but used by "load address"
4770  type instructions without touching memory.
4771- ``i``: An integer constant (of target-specific width). Allows either a simple
4772  immediate, or a relocatable value.
4773- ``n``: An integer constant -- *not* including relocatable values.
4774- ``s``: An integer constant, but allowing *only* relocatable values.
4775- ``X``: Allows an operand of any kind, no constraint whatsoever. Typically
4776  useful to pass a label for an asm branch or call.
4777
4778  .. FIXME: but that surely isn't actually okay to jump out of an asm
4779     block without telling llvm about the control transfer???)
4780
4781- ``{register-name}``: Requires exactly the named physical register.
4782
4783Other constraints are target-specific:
4784
4785AArch64:
4786
4787- ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate.
4788- ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction,
4789  i.e. 0 to 4095 with optional shift by 12.
4790- ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or
4791  ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12.
4792- ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a
4793  logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register.
4794- ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a
4795  logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register.
4796- ``M``: An immediate integer for use with the ``MOV`` assembly alias on a
4797  32-bit register. This is a superset of ``K``: in addition to the bitmask
4798  immediate, also allows immediate integers which can be loaded with a single
4799  ``MOVZ`` or ``MOVL`` instruction.
4800- ``N``: An immediate integer for use with the ``MOV`` assembly alias on a
4801  64-bit register. This is a superset of ``L``.
4802- ``Q``: Memory address operand must be in a single register (no
4803  offsets). (However, LLVM currently does this for the ``m`` constraint as
4804  well.)
4805- ``r``: A 32 or 64-bit integer register (W* or X*).
4806- ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register.
4807- ``x``: Like w, but restricted to registers 0 to 15 inclusive.
4808- ``y``: Like w, but restricted to SVE vector registers Z0 to Z7 inclusive.
4809- ``Upl``: One of the low eight SVE predicate registers (P0 to P7)
4810- ``Upa``: Any of the SVE predicate registers (P0 to P15)
4811
4812AMDGPU:
4813
4814- ``r``: A 32 or 64-bit integer register.
4815- ``[0-9]v``: The 32-bit VGPR register, number 0-9.
4816- ``[0-9]s``: The 32-bit SGPR register, number 0-9.
4817- ``[0-9]a``: The 32-bit AGPR register, number 0-9.
4818- ``I``: An integer inline constant in the range from -16 to 64.
4819- ``J``: A 16-bit signed integer constant.
4820- ``A``: An integer or a floating-point inline constant.
4821- ``B``: A 32-bit signed integer constant.
4822- ``C``: A 32-bit unsigned integer constant or an integer inline constant in the range from -16 to 64.
4823- ``DA``: A 64-bit constant that can be split into two "A" constants.
4824- ``DB``: A 64-bit constant that can be split into two "B" constants.
4825
4826All ARM modes:
4827
4828- ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address
4829  operand. Treated the same as operand ``m``, at the moment.
4830- ``Te``: An even general-purpose 32-bit integer register: ``r0,r2,...,r12,r14``
4831- ``To``: An odd general-purpose 32-bit integer register: ``r1,r3,...,r11``
4832
4833ARM and ARM's Thumb2 mode:
4834
4835- ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``)
4836- ``I``: An immediate integer valid for a data-processing instruction.
4837- ``J``: An immediate integer between -4095 and 4095.
4838- ``K``: An immediate integer whose bitwise inverse is valid for a
4839  data-processing instruction. (Can be used with template modifier "``B``" to
4840  print the inverted value).
4841- ``L``: An immediate integer whose negation is valid for a data-processing
4842  instruction. (Can be used with template modifier "``n``" to print the negated
4843  value).
4844- ``M``: A power of two or an integer between 0 and 32.
4845- ``N``: Invalid immediate constraint.
4846- ``O``: Invalid immediate constraint.
4847- ``r``: A general-purpose 32-bit integer register (``r0-r15``).
4848- ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same
4849  as ``r``.
4850- ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode,
4851  invalid.
4852- ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
4853  ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively.
4854- ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
4855  ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively.
4856- ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
4857  ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively.
4858
4859ARM's Thumb1 mode:
4860
4861- ``I``: An immediate integer between 0 and 255.
4862- ``J``: An immediate integer between -255 and -1.
4863- ``K``: An immediate integer between 0 and 255, with optional left-shift by
4864  some amount.
4865- ``L``: An immediate integer between -7 and 7.
4866- ``M``: An immediate integer which is a multiple of 4 between 0 and 1020.
4867- ``N``: An immediate integer between 0 and 31.
4868- ``O``: An immediate integer which is a multiple of 4 between -508 and 508.
4869- ``r``: A low 32-bit GPR register (``r0-r7``).
4870- ``l``: A low 32-bit GPR register (``r0-r7``).
4871- ``h``: A high GPR register (``r0-r7``).
4872- ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
4873  ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively.
4874- ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
4875  ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively.
4876- ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
4877  ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively.
4878
4879
4880Hexagon:
4881
4882- ``o``, ``v``: A memory address operand, treated the same as constraint ``m``,
4883  at the moment.
4884- ``r``: A 32 or 64-bit register.
4885
4886MSP430:
4887
4888- ``r``: An 8 or 16-bit register.
4889
4890MIPS:
4891
4892- ``I``: An immediate signed 16-bit integer.
4893- ``J``: An immediate integer zero.
4894- ``K``: An immediate unsigned 16-bit integer.
4895- ``L``: An immediate 32-bit integer, where the lower 16 bits are 0.
4896- ``N``: An immediate integer between -65535 and -1.
4897- ``O``: An immediate signed 15-bit integer.
4898- ``P``: An immediate integer between 1 and 65535.
4899- ``m``: A memory address operand. In MIPS-SE mode, allows a base address
4900  register plus 16-bit immediate offset. In MIPS mode, just a base register.
4901- ``R``: A memory address operand. In MIPS-SE mode, allows a base address
4902  register plus a 9-bit signed offset. In MIPS mode, the same as constraint
4903  ``m``.
4904- ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or
4905  ``sc`` instruction on the given subtarget (details vary).
4906- ``r``, ``d``,  ``y``: A 32 or 64-bit GPR register.
4907- ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register
4908  (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w``
4909  argument modifier for compatibility with GCC.
4910- ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always
4911  ``25``).
4912- ``l``: The ``lo`` register, 32 or 64-bit.
4913- ``x``: Invalid.
4914
4915NVPTX:
4916
4917- ``b``: A 1-bit integer register.
4918- ``c`` or ``h``: A 16-bit integer register.
4919- ``r``: A 32-bit integer register.
4920- ``l`` or ``N``: A 64-bit integer register.
4921- ``f``: A 32-bit float register.
4922- ``d``: A 64-bit float register.
4923
4924
4925PowerPC:
4926
4927- ``I``: An immediate signed 16-bit integer.
4928- ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits.
4929- ``K``: An immediate unsigned 16-bit integer.
4930- ``L``: An immediate signed 16-bit integer, shifted left 16 bits.
4931- ``M``: An immediate integer greater than 31.
4932- ``N``: An immediate integer that is an exact power of 2.
4933- ``O``: The immediate integer constant 0.
4934- ``P``: An immediate integer constant whose negation is a signed 16-bit
4935  constant.
4936- ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently
4937  treated the same as ``m``.
4938- ``r``: A 32 or 64-bit integer register.
4939- ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is:
4940  ``R1-R31``).
4941- ``f``: A 32 or 64-bit float register (``F0-F31``),
4942- ``v``: For ``4 x f32`` or ``4 x f64`` types, a 128-bit altivec vector
4943   register (``V0-V31``).
4944
4945- ``y``: Condition register (``CR0-CR7``).
4946- ``wc``: An individual CR bit in a CR register.
4947- ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX
4948  register set (overlapping both the floating-point and vector register files).
4949- ``ws``: A 32 or 64-bit floating-point register, from the full VSX register
4950  set.
4951
4952RISC-V:
4953
4954- ``A``: An address operand (using a general-purpose register, without an
4955  offset).
4956- ``I``: A 12-bit signed integer immediate operand.
4957- ``J``: A zero integer immediate operand.
4958- ``K``: A 5-bit unsigned integer immediate operand.
4959- ``f``: A 32- or 64-bit floating-point register (requires F or D extension).
4960- ``r``: A 32- or 64-bit general-purpose register (depending on the platform
4961  ``XLEN``).
4962- ``vr``: A vector register. (requires V extension).
4963- ``vm``: A vector register for masking operand. (requires V extension).
4964
4965Sparc:
4966
4967- ``I``: An immediate 13-bit signed integer.
4968- ``r``: A 32-bit integer register.
4969- ``f``: Any floating-point register on SparcV8, or a floating-point
4970  register in the "low" half of the registers on SparcV9.
4971- ``e``: Any floating-point register. (Same as ``f`` on SparcV8.)
4972
4973SystemZ:
4974
4975- ``I``: An immediate unsigned 8-bit integer.
4976- ``J``: An immediate unsigned 12-bit integer.
4977- ``K``: An immediate signed 16-bit integer.
4978- ``L``: An immediate signed 20-bit integer.
4979- ``M``: An immediate integer 0x7fffffff.
4980- ``Q``: A memory address operand with a base address and a 12-bit immediate
4981  unsigned displacement.
4982- ``R``: A memory address operand with a base address, a 12-bit immediate
4983  unsigned displacement, and an index register.
4984- ``S``: A memory address operand with a base address and a 20-bit immediate
4985  signed displacement.
4986- ``T``: A memory address operand with a base address, a 20-bit immediate
4987  signed displacement, and an index register.
4988- ``r`` or ``d``: A 32, 64, or 128-bit integer register.
4989- ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an
4990  address context evaluates as zero).
4991- ``h``: A 32-bit value in the high part of a 64bit data register
4992  (LLVM-specific)
4993- ``f``: A 32, 64, or 128-bit floating-point register.
4994
4995X86:
4996
4997- ``I``: An immediate integer between 0 and 31.
4998- ``J``: An immediate integer between 0 and 64.
4999- ``K``: An immediate signed 8-bit integer.
5000- ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only)
5001  0xffffffff.
5002- ``M``: An immediate integer between 0 and 3.
5003- ``N``: An immediate unsigned 8-bit integer.
5004- ``O``: An immediate integer between 0 and 127.
5005- ``e``: An immediate 32-bit signed integer.
5006- ``Z``: An immediate 32-bit unsigned integer.
5007- ``o``, ``v``: Treated the same as ``m``, at the moment.
5008- ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
5009  ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d``
5010  registers, and on X86-64, it is all of the integer registers.
5011- ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
5012  ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers.
5013- ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register.
5014- ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has
5015  existed since i386, and can be accessed without the REX prefix.
5016- ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register.
5017- ``y``: A 64-bit MMX register, if MMX is enabled.
5018- ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector
5019  operand in a SSE register. If AVX is also enabled, can also be a 256-bit
5020  vector operand in an AVX register. If AVX-512 is also enabled, can also be a
5021  512-bit vector operand in an AVX512 register, Otherwise, an error.
5022- ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error.
5023- ``A``: Special case: allocates EAX first, then EDX, for a single operand (in
5024  32-bit mode, a 64-bit integer operand will get split into two registers). It
5025  is not recommended to use this constraint, as in 64-bit mode, the 64-bit
5026  operand will get allocated only to RAX -- if two 32-bit operands are needed,
5027  you're better off splitting it yourself, before passing it to the asm
5028  statement.
5029
5030XCore:
5031
5032- ``r``: A 32-bit integer register.
5033
5034
5035.. _inline-asm-modifiers:
5036
5037Asm template argument modifiers
5038^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5039
5040In the asm template string, modifiers can be used on the operand reference, like
5041"``${0:n}``".
5042
5043The modifiers are, in general, expected to behave the same way they do in
5044GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
5045inline asm code which was supported by GCC. A mismatch in behavior between LLVM
5046and GCC likely indicates a bug in LLVM.
5047
5048Target-independent:
5049
5050- ``c``: Print an immediate integer constant unadorned, without
5051  the target-specific immediate punctuation (e.g. no ``$`` prefix).
5052- ``n``: Negate and print immediate integer constant unadorned, without the
5053  target-specific immediate punctuation (e.g. no ``$`` prefix).
5054- ``l``: Print as an unadorned label, without the target-specific label
5055  punctuation (e.g. no ``$`` prefix).
5056
5057AArch64:
5058
5059- ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g.,
5060  instead of ``x30``, print ``w30``.
5061- ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow).
5062- ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a
5063  ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of
5064  ``v*``.
5065
5066AMDGPU:
5067
5068- ``r``: No effect.
5069
5070ARM:
5071
5072- ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a
5073  register).
5074- ``P``: No effect.
5075- ``q``: No effect.
5076- ``y``: Print a VFP single-precision register as an indexed double (e.g. print
5077  as ``d4[1]`` instead of ``s9``)
5078- ``B``: Bitwise invert and print an immediate integer constant without ``#``
5079  prefix.
5080- ``L``: Print the low 16-bits of an immediate integer constant.
5081- ``M``: Print as a register set suitable for ldm/stm. Also prints *all*
5082  register operands subsequent to the specified one (!), so use carefully.
5083- ``Q``: Print the low-order register of a register-pair, or the low-order
5084  register of a two-register operand.
5085- ``R``: Print the high-order register of a register-pair, or the high-order
5086  register of a two-register operand.
5087- ``H``: Print the second register of a register-pair. (On a big-endian system,
5088  ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent
5089  to ``R``.)
5090
5091  .. FIXME: H doesn't currently support printing the second register
5092     of a two-register operand.
5093
5094- ``e``: Print the low doubleword register of a NEON quad register.
5095- ``f``: Print the high doubleword register of a NEON quad register.
5096- ``m``: Print the base register of a memory operand without the ``[`` and ``]``
5097  adornment.
5098
5099Hexagon:
5100
5101- ``L``: Print the second register of a two-register operand. Requires that it
5102  has been allocated consecutively to the first.
5103
5104  .. FIXME: why is it restricted to consecutive ones? And there's
5105     nothing that ensures that happens, is there?
5106
5107- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
5108  nothing. Used to print 'addi' vs 'add' instructions.
5109
5110MSP430:
5111
5112No additional modifiers.
5113
5114MIPS:
5115
5116- ``X``: Print an immediate integer as hexadecimal
5117- ``x``: Print the low 16 bits of an immediate integer as hexadecimal.
5118- ``d``: Print an immediate integer as decimal.
5119- ``m``: Subtract one and print an immediate integer as decimal.
5120- ``z``: Print $0 if an immediate zero, otherwise print normally.
5121- ``L``: Print the low-order register of a two-register operand, or prints the
5122  address of the low-order word of a double-word memory operand.
5123
5124  .. FIXME: L seems to be missing memory operand support.
5125
5126- ``M``: Print the high-order register of a two-register operand, or prints the
5127  address of the high-order word of a double-word memory operand.
5128
5129  .. FIXME: M seems to be missing memory operand support.
5130
5131- ``D``: Print the second register of a two-register operand, or prints the
5132  second word of a double-word memory operand. (On a big-endian system, ``D`` is
5133  equivalent to ``L``, and on little-endian system, ``D`` is equivalent to
5134  ``M``.)
5135- ``w``: No effect. Provided for compatibility with GCC which requires this
5136  modifier in order to print MSA registers (``W0-W31``) with the ``f``
5137  constraint.
5138
5139NVPTX:
5140
5141- ``r``: No effect.
5142
5143PowerPC:
5144
5145- ``L``: Print the second register of a two-register operand. Requires that it
5146  has been allocated consecutively to the first.
5147
5148  .. FIXME: why is it restricted to consecutive ones? And there's
5149     nothing that ensures that happens, is there?
5150
5151- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
5152  nothing. Used to print 'addi' vs 'add' instructions.
5153- ``y``: For a memory operand, prints formatter for a two-register X-form
5154  instruction. (Currently always prints ``r0,OPERAND``).
5155- ``U``: Prints 'u' if the memory operand is an update form, and nothing
5156  otherwise. (NOTE: LLVM does not support update form, so this will currently
5157  always print nothing)
5158- ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does
5159  not support indexed form, so this will currently always print nothing)
5160
5161RISC-V:
5162
5163- ``i``: Print the letter 'i' if the operand is not a register, otherwise print
5164  nothing. Used to print 'addi' vs 'add' instructions, etc.
5165- ``z``: Print the register ``zero`` if an immediate zero, otherwise print
5166  normally.
5167
5168Sparc:
5169
5170- ``r``: No effect.
5171
5172SystemZ:
5173
5174SystemZ implements only ``n``, and does *not* support any of the other
5175target-independent modifiers.
5176
5177X86:
5178
5179- ``c``: Print an unadorned integer or symbol name. (The latter is
5180  target-specific behavior for this typically target-independent modifier).
5181- ``A``: Print a register name with a '``*``' before it.
5182- ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory
5183  operand.
5184- ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a
5185  memory operand.
5186- ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory
5187  operand.
5188- ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory
5189  operand.
5190- ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are
5191  available, otherwise the 32-bit register name; do nothing on a memory operand.
5192- ``n``: Negate and print an unadorned integer, or, for operands other than an
5193  immediate integer (e.g. a relocatable symbol expression), print a '-' before
5194  the operand. (The behavior for relocatable symbol expressions is a
5195  target-specific behavior for this typically target-independent modifier)
5196- ``H``: Print a memory reference with additional offset +8.
5197- ``P``: Print a memory reference used as the argument of a call instruction or
5198  used with explicit base reg and index reg as its offset. So it can not use
5199  additional regs to present the memory reference. (E.g. omit ``(rip)``, even
5200  though it's PC-relative.)
5201
5202XCore:
5203
5204No additional modifiers.
5205
5206
5207Inline Asm Metadata
5208^^^^^^^^^^^^^^^^^^^
5209
5210The call instructions that wrap inline asm nodes may have a
5211"``!srcloc``" MDNode attached to it that contains a list of constant
5212integers. If present, the code generator will use the integer as the
5213location cookie value when report errors through the ``LLVMContext``
5214error reporting mechanisms. This allows a front-end to correlate backend
5215errors that occur with inline asm back to the source code that produced
5216it. For example:
5217
5218.. code-block:: llvm
5219
5220    call void asm sideeffect "something bad", ""(), !srcloc !42
5221    ...
5222    !42 = !{ i32 1234567 }
5223
5224It is up to the front-end to make sense of the magic numbers it places
5225in the IR. If the MDNode contains multiple constants, the code generator
5226will use the one that corresponds to the line of the asm that the error
5227occurs on.
5228
5229.. _metadata:
5230
5231Metadata
5232========
5233
5234LLVM IR allows metadata to be attached to instructions and global objects in the
5235program that can convey extra information about the code to the optimizers and
5236code generator. One example application of metadata is source-level
5237debug information. There are two metadata primitives: strings and nodes.
5238
5239Metadata does not have a type, and is not a value. If referenced from a
5240``call`` instruction, it uses the ``metadata`` type.
5241
5242All metadata are identified in syntax by an exclamation point ('``!``').
5243
5244.. _metadata-string:
5245
5246Metadata Nodes and Metadata Strings
5247-----------------------------------
5248
5249A metadata string is a string surrounded by double quotes. It can
5250contain any character by escaping non-printable characters with
5251"``\xx``" where "``xx``" is the two digit hex code. For example:
5252"``!"test\00"``".
5253
5254Metadata nodes are represented with notation similar to structure
5255constants (a comma separated list of elements, surrounded by braces and
5256preceded by an exclamation point). Metadata nodes can have any values as
5257their operand. For example:
5258
5259.. code-block:: llvm
5260
5261    !{ !"test\00", i32 10}
5262
5263Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
5264
5265.. code-block:: text
5266
5267    !0 = distinct !{!"test\00", i32 10}
5268
5269``distinct`` nodes are useful when nodes shouldn't be merged based on their
5270content. They can also occur when transformations cause uniquing collisions
5271when metadata operands change.
5272
5273A :ref:`named metadata <namedmetadatastructure>` is a collection of
5274metadata nodes, which can be looked up in the module symbol table. For
5275example:
5276
5277.. code-block:: llvm
5278
5279    !foo = !{!4, !3}
5280
5281Metadata can be used as function arguments. Here the ``llvm.dbg.value``
5282intrinsic is using three metadata arguments:
5283
5284.. code-block:: llvm
5285
5286    call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26)
5287
5288Metadata can be attached to an instruction. Here metadata ``!21`` is attached
5289to the ``add`` instruction using the ``!dbg`` identifier:
5290
5291.. code-block:: llvm
5292
5293    %indvar.next = add i64 %indvar, 1, !dbg !21
5294
5295Instructions may not have multiple metadata attachments with the same
5296identifier.
5297
5298Metadata can also be attached to a function or a global variable. Here metadata
5299``!22`` is attached to the ``f1`` and ``f2`` functions, and the globals ``g1``
5300and ``g2`` using the ``!dbg`` identifier:
5301
5302.. code-block:: llvm
5303
5304    declare !dbg !22 void @f1()
5305    define void @f2() !dbg !22 {
5306      ret void
5307    }
5308
5309    @g1 = global i32 0, !dbg !22
5310    @g2 = external global i32, !dbg !22
5311
5312Unlike instructions, global objects (functions and global variables) may have
5313multiple metadata attachments with the same identifier.
5314
5315A transformation is required to drop any metadata attachment that it does not
5316know or know it can't preserve. Currently there is an exception for metadata
5317attachment to globals for ``!func_sanitize``, ``!type`` and ``!absolute_symbol`` which can't be
5318unconditionally dropped unless the global is itself deleted.
5319
5320Metadata attached to a module using named metadata may not be dropped, with
5321the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``).
5322
5323More information about specific metadata nodes recognized by the
5324optimizers and code generator is found below.
5325
5326.. _specialized-metadata:
5327
5328Specialized Metadata Nodes
5329^^^^^^^^^^^^^^^^^^^^^^^^^^
5330
5331Specialized metadata nodes are custom data structures in metadata (as opposed
5332to generic tuples). Their fields are labelled, and can be specified in any
5333order.
5334
5335These aren't inherently debug info centric, but currently all the specialized
5336metadata nodes are related to debug info.
5337
5338.. _DICompileUnit:
5339
5340DICompileUnit
5341"""""""""""""
5342
5343``DICompileUnit`` nodes represent a compile unit. The ``enums:``,
5344``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples
5345containing the debug info to be emitted along with the compile unit, regardless
5346of code optimizations (some nodes are only emitted if there are references to
5347them from instructions). The ``debugInfoForProfiling:`` field is a boolean
5348indicating whether or not line-table discriminators are updated to provide
5349more-accurate debug info for profiling results.
5350
5351.. code-block:: text
5352
5353    !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
5354                        isOptimized: true, flags: "-O2", runtimeVersion: 2,
5355                        splitDebugFilename: "abc.debug", emissionKind: FullDebug,
5356                        enums: !2, retainedTypes: !3, globals: !4, imports: !5,
5357                        macros: !6, dwoId: 0x0abcd)
5358
5359Compile unit descriptors provide the root scope for objects declared in a
5360specific compilation unit. File descriptors are defined using this scope.  These
5361descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep
5362track of global variables, type information, and imported entities (declarations
5363and namespaces).
5364
5365.. _DIFile:
5366
5367DIFile
5368""""""
5369
5370``DIFile`` nodes represent files. The ``filename:`` can include slashes.
5371
5372.. code-block:: none
5373
5374    !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir",
5375                 checksumkind: CSK_MD5,
5376                 checksum: "000102030405060708090a0b0c0d0e0f")
5377
5378Files are sometimes used in ``scope:`` fields, and are the only valid target
5379for ``file:`` fields.
5380Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1, CSK_SHA256}
5381
5382.. _DIBasicType:
5383
5384DIBasicType
5385"""""""""""
5386
5387``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
5388``float``. ``tag:`` defaults to ``DW_TAG_base_type``.
5389
5390.. code-block:: text
5391
5392    !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
5393                      encoding: DW_ATE_unsigned_char)
5394    !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
5395
5396The ``encoding:`` describes the details of the type. Usually it's one of the
5397following:
5398
5399.. code-block:: text
5400
5401  DW_ATE_address       = 1
5402  DW_ATE_boolean       = 2
5403  DW_ATE_float         = 4
5404  DW_ATE_signed        = 5
5405  DW_ATE_signed_char   = 6
5406  DW_ATE_unsigned      = 7
5407  DW_ATE_unsigned_char = 8
5408
5409.. _DISubroutineType:
5410
5411DISubroutineType
5412""""""""""""""""
5413
5414``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field
5415refers to a tuple; the first operand is the return type, while the rest are the
5416types of the formal arguments in order. If the first operand is ``null``, that
5417represents a function with no return value (such as ``void foo() {}`` in C++).
5418
5419.. code-block:: text
5420
5421    !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
5422    !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
5423    !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char)
5424
5425.. _DIDerivedType:
5426
5427DIDerivedType
5428"""""""""""""
5429
5430``DIDerivedType`` nodes represent types derived from other types, such as
5431qualified types.
5432
5433.. code-block:: text
5434
5435    !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
5436                      encoding: DW_ATE_unsigned_char)
5437    !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
5438                        align: 32)
5439
5440The following ``tag:`` values are valid:
5441
5442.. code-block:: text
5443
5444  DW_TAG_member             = 13
5445  DW_TAG_pointer_type       = 15
5446  DW_TAG_reference_type     = 16
5447  DW_TAG_typedef            = 22
5448  DW_TAG_inheritance        = 28
5449  DW_TAG_ptr_to_member_type = 31
5450  DW_TAG_const_type         = 38
5451  DW_TAG_friend             = 42
5452  DW_TAG_volatile_type      = 53
5453  DW_TAG_restrict_type      = 55
5454  DW_TAG_atomic_type        = 71
5455  DW_TAG_immutable_type     = 75
5456
5457.. _DIDerivedTypeMember:
5458
5459``DW_TAG_member`` is used to define a member of a :ref:`composite type
5460<DICompositeType>`. The type of the member is the ``baseType:``. The
5461``offset:`` is the member's bit offset.  If the composite type has an ODR
5462``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is
5463uniqued based only on its ``name:`` and ``scope:``.
5464
5465``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:``
5466field of :ref:`composite types <DICompositeType>` to describe parents and
5467friends.
5468
5469``DW_TAG_typedef`` is used to provide a name for the ``baseType:``.
5470
5471``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``,
5472``DW_TAG_volatile_type``, ``DW_TAG_restrict_type``, ``DW_TAG_atomic_type`` and
5473``DW_TAG_immutable_type`` are used to qualify the ``baseType:``.
5474
5475Note that the ``void *`` type is expressed as a type derived from NULL.
5476
5477.. _DICompositeType:
5478
5479DICompositeType
5480"""""""""""""""
5481
5482``DICompositeType`` nodes represent types composed of other types, like
5483structures and unions. ``elements:`` points to a tuple of the composed types.
5484
5485If the source language supports ODR, the ``identifier:`` field gives the unique
5486identifier used for type merging between modules.  When specified,
5487:ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member
5488derived types <DIDerivedTypeMember>` that reference the ODR-type in their
5489``scope:`` change uniquing rules.
5490
5491For a given ``identifier:``, there should only be a single composite type that
5492does not have  ``flags: DIFlagFwdDecl`` set.  LLVM tools that link modules
5493together will unique such definitions at parse time via the ``identifier:``
5494field, even if the nodes are ``distinct``.
5495
5496.. code-block:: text
5497
5498    !0 = !DIEnumerator(name: "SixKind", value: 7)
5499    !1 = !DIEnumerator(name: "SevenKind", value: 7)
5500    !2 = !DIEnumerator(name: "NegEightKind", value: -8)
5501    !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
5502                          line: 2, size: 32, align: 32, identifier: "_M4Enum",
5503                          elements: !{!0, !1, !2})
5504
5505The following ``tag:`` values are valid:
5506
5507.. code-block:: text
5508
5509  DW_TAG_array_type       = 1
5510  DW_TAG_class_type       = 2
5511  DW_TAG_enumeration_type = 4
5512  DW_TAG_structure_type   = 19
5513  DW_TAG_union_type       = 23
5514
5515For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange
5516descriptors <DISubrange>`, each representing the range of subscripts at that
5517level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an
5518array type is a native packed vector. The optional ``dataLocation`` is a
5519DIExpression that describes how to get from an object's address to the actual
5520raw data, if they aren't equivalent. This is only supported for array types,
5521particularly to describe Fortran arrays, which have an array descriptor in
5522addition to the array data. Alternatively it can also be DIVariable which
5523has the address of the actual raw data. The Fortran language supports pointer
5524arrays which can be attached to actual arrays, this attachment between pointer
5525and pointee is called association.  The optional ``associated`` is a
5526DIExpression that describes whether the pointer array is currently associated.
5527The optional ``allocated`` is a DIExpression that describes whether the
5528allocatable array is currently allocated.  The optional ``rank`` is a
5529DIExpression that describes the rank (number of dimensions) of fortran assumed
5530rank array (rank is known at runtime).
5531
5532For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
5533descriptors <DIEnumerator>`, each representing the definition of an enumeration
5534value for the set. All enumeration type descriptors are collected in the
5535``enums:`` field of the :ref:`compile unit <DICompileUnit>`.
5536
5537For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and
5538``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types
5539<DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or
5540``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with
5541``isDefinition: false``.
5542
5543.. _DISubrange:
5544
5545DISubrange
5546""""""""""
5547
5548``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
5549:ref:`DICompositeType`.
5550
5551- ``count: -1`` indicates an empty array.
5552- ``count: !10`` describes the count with a :ref:`DILocalVariable`.
5553- ``count: !12`` describes the count with a :ref:`DIGlobalVariable`.
5554
5555.. code-block:: text
5556
5557    !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0
5558    !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1
5559    !2 = !DISubrange(count: -1) ; empty array.
5560
5561    ; Scopes used in rest of example
5562    !6 = !DIFile(filename: "vla.c", directory: "/path/to/file")
5563    !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6)
5564    !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5)
5565
5566    ; Use of local variable as count value
5567    !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
5568    !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9)
5569    !11 = !DISubrange(count: !10, lowerBound: 0)
5570
5571    ; Use of global variable as count value
5572    !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9)
5573    !13 = !DISubrange(count: !12, lowerBound: 0)
5574
5575.. _DIEnumerator:
5576
5577DIEnumerator
5578""""""""""""
5579
5580``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
5581variants of :ref:`DICompositeType`.
5582
5583.. code-block:: text
5584
5585    !0 = !DIEnumerator(name: "SixKind", value: 7)
5586    !1 = !DIEnumerator(name: "SevenKind", value: 7)
5587    !2 = !DIEnumerator(name: "NegEightKind", value: -8)
5588
5589DITemplateTypeParameter
5590"""""""""""""""""""""""
5591
5592``DITemplateTypeParameter`` nodes represent type parameters to generic source
5593language constructs. They are used (optionally) in :ref:`DICompositeType` and
5594:ref:`DISubprogram` ``templateParams:`` fields.
5595
5596.. code-block:: text
5597
5598    !0 = !DITemplateTypeParameter(name: "Ty", type: !1)
5599
5600DITemplateValueParameter
5601""""""""""""""""""""""""
5602
5603``DITemplateValueParameter`` nodes represent value parameters to generic source
5604language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
5605but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
5606``DW_TAG_GNU_template_param_pack``. They are used (optionally) in
5607:ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields.
5608
5609.. code-block:: text
5610
5611    !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7)
5612
5613DINamespace
5614"""""""""""
5615
5616``DINamespace`` nodes represent namespaces in the source language.
5617
5618.. code-block:: text
5619
5620    !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
5621
5622.. _DIGlobalVariable:
5623
5624DIGlobalVariable
5625""""""""""""""""
5626
5627``DIGlobalVariable`` nodes represent global variables in the source language.
5628
5629.. code-block:: text
5630
5631    @foo = global i32, !dbg !0
5632    !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
5633    !1 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !2,
5634                           file: !3, line: 7, type: !4, isLocal: true,
5635                           isDefinition: false, declaration: !5)
5636
5637
5638DIGlobalVariableExpression
5639""""""""""""""""""""""""""
5640
5641``DIGlobalVariableExpression`` nodes tie a :ref:`DIGlobalVariable` together
5642with a :ref:`DIExpression`.
5643
5644.. code-block:: text
5645
5646    @lower = global i32, !dbg !0
5647    @upper = global i32, !dbg !1
5648    !0 = !DIGlobalVariableExpression(
5649             var: !2,
5650             expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32)
5651             )
5652    !1 = !DIGlobalVariableExpression(
5653             var: !2,
5654             expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32)
5655             )
5656    !2 = !DIGlobalVariable(name: "split64", linkageName: "split64", scope: !3,
5657                           file: !4, line: 8, type: !5, declaration: !6)
5658
5659All global variable expressions should be referenced by the `globals:` field of
5660a :ref:`compile unit <DICompileUnit>`.
5661
5662.. _DISubprogram:
5663
5664DISubprogram
5665""""""""""""
5666
5667``DISubprogram`` nodes represent functions from the source language. A distinct
5668``DISubprogram`` may be attached to a function definition using ``!dbg``
5669metadata. A unique ``DISubprogram`` may be attached to a function declaration
5670used for call site debug info. The ``retainedNodes:`` field is a list of
5671:ref:`variables <DILocalVariable>` and :ref:`labels <DILabel>` that must be
5672retained, even if their IR counterparts are optimized out of the IR. The
5673``type:`` field must point at an :ref:`DISubroutineType`.
5674
5675.. _DISubprogramDeclaration:
5676
5677When ``isDefinition: false``, subprograms describe a declaration in the type
5678tree as opposed to a definition of a function.  If the scope is a composite
5679type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``,
5680then the subprogram declaration is uniqued based only on its ``linkageName:``
5681and ``scope:``.
5682
5683.. code-block:: text
5684
5685    define void @_Z3foov() !dbg !0 {
5686      ...
5687    }
5688
5689    !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
5690                                file: !2, line: 7, type: !3, isLocal: true,
5691                                isDefinition: true, scopeLine: 8,
5692                                containingType: !4,
5693                                virtuality: DW_VIRTUALITY_pure_virtual,
5694                                virtualIndex: 10, flags: DIFlagPrototyped,
5695                                isOptimized: true, unit: !5, templateParams: !6,
5696                                declaration: !7, retainedNodes: !8,
5697                                thrownTypes: !9)
5698
5699.. _DILexicalBlock:
5700
5701DILexicalBlock
5702""""""""""""""
5703
5704``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
5705<DISubprogram>`. The line number and column numbers are used to distinguish
5706two lexical blocks at same depth. They are valid targets for ``scope:``
5707fields.
5708
5709.. code-block:: text
5710
5711    !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
5712
5713Usually lexical blocks are ``distinct`` to prevent node merging based on
5714operands.
5715
5716.. _DILexicalBlockFile:
5717
5718DILexicalBlockFile
5719""""""""""""""""""
5720
5721``DILexicalBlockFile`` nodes are used to discriminate between sections of a
5722:ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to
5723indicate textual inclusion, or the ``discriminator:`` field can be used to
5724discriminate between control flow within a single block in the source language.
5725
5726.. code-block:: text
5727
5728    !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35)
5729    !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0)
5730    !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1)
5731
5732.. _DILocation:
5733
5734DILocation
5735""""""""""
5736
5737``DILocation`` nodes represent source debug locations. The ``scope:`` field is
5738mandatory, and points at an :ref:`DILexicalBlockFile`, an
5739:ref:`DILexicalBlock`, or an :ref:`DISubprogram`.
5740
5741.. code-block:: text
5742
5743    !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
5744
5745.. _DILocalVariable:
5746
5747DILocalVariable
5748"""""""""""""""
5749
5750``DILocalVariable`` nodes represent local variables in the source language. If
5751the ``arg:`` field is set to non-zero, then this variable is a subprogram
5752parameter, and it will be included in the ``retainedNodes:`` field of its
5753:ref:`DISubprogram`.
5754
5755.. code-block:: text
5756
5757    !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7,
5758                          type: !3, flags: DIFlagArtificial)
5759    !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7,
5760                          type: !3)
5761    !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3)
5762
5763.. _DIExpression:
5764
5765DIExpression
5766""""""""""""
5767
5768``DIExpression`` nodes represent expressions that are inspired by the DWARF
5769expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>`
5770(such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the
5771referenced LLVM variable relates to the source language variable. Debug
5772intrinsics are interpreted left-to-right: start by pushing the value/address
5773operand of the intrinsic onto a stack, then repeatedly push and evaluate
5774opcodes from the DIExpression until the final variable description is produced.
5775
5776The current supported opcode vocabulary is limited:
5777
5778- ``DW_OP_deref`` dereferences the top of the expression stack.
5779- ``DW_OP_plus`` pops the last two entries from the expression stack, adds
5780  them together and appends the result to the expression stack.
5781- ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts
5782  the last entry from the second last entry and appends the result to the
5783  expression stack.
5784- ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression.
5785- ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8``
5786  here, respectively) of the variable fragment from the working expression. Note
5787  that contrary to DW_OP_bit_piece, the offset is describing the location
5788  within the described source variable.
5789- ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding
5790  (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the
5791  expression stack is to be converted. Maps into a ``DW_OP_convert`` operation
5792  that references a base type constructed from the supplied values.
5793- ``DW_OP_LLVM_tag_offset, tag_offset`` specifies that a memory tag should be
5794  optionally applied to the pointer. The memory tag is derived from the
5795  given tag offset in an implementation-defined manner.
5796- ``DW_OP_swap`` swaps top two stack entries.
5797- ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top
5798  of the stack is treated as an address. The second stack entry is treated as an
5799  address space identifier.
5800- ``DW_OP_stack_value`` marks a constant value.
5801- ``DW_OP_LLVM_entry_value, N`` may only appear in MIR and at the
5802  beginning of a ``DIExpression``. In DWARF a ``DBG_VALUE``
5803  instruction binding a ``DIExpression(DW_OP_LLVM_entry_value`` to a
5804  register is lowered to a ``DW_OP_entry_value [reg]``, pushing the
5805  value the register had upon function entry onto the stack.  The next
5806  ``(N - 1)`` operations will be part of the ``DW_OP_entry_value``
5807  block argument. For example, ``!DIExpression(DW_OP_LLVM_entry_value,
5808  1, DW_OP_plus_uconst, 123, DW_OP_stack_value)`` specifies an
5809  expression where the entry value of the debug value instruction's
5810  value/address operand is pushed to the stack, and is added
5811  with 123. Due to framework limitations ``N`` can currently only
5812  be 1.
5813
5814  The operation is introduced by the ``LiveDebugValues`` pass, which
5815  applies it only to function parameters that are unmodified
5816  throughout the function. Support is limited to simple register
5817  location descriptions, or as indirect locations (e.g., when a struct
5818  is passed-by-value to a callee via a pointer to a temporary copy
5819  made in the caller). The entry value op is also introduced by the
5820  ``AsmPrinter`` pass when a call site parameter value
5821  (``DW_AT_call_site_parameter_value``) is represented as entry value
5822  of the parameter.
5823- ``DW_OP_LLVM_arg, N`` is used in debug intrinsics that refer to more than one
5824  value, such as one that calculates the sum of two registers. This is always
5825  used in combination with an ordered list of values, such that
5826  ``DW_OP_LLVM_arg, N`` refers to the ``N``th element in that list. For
5827  example, ``!DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus,
5828  DW_OP_stack_value)`` used with the list ``(%reg1, %reg2)`` would evaluate to
5829  ``%reg1 - reg2``. This list of values should be provided by the containing
5830  intrinsic/instruction.
5831- ``DW_OP_breg`` (or ``DW_OP_bregx``) represents a content on the provided
5832  signed offset of the specified register. The opcode is only generated by the
5833  ``AsmPrinter`` pass to describe call site parameter value which requires an
5834  expression over two registers.
5835- ``DW_OP_push_object_address`` pushes the address of the object which can then
5836  serve as a descriptor in subsequent calculation. This opcode can be used to
5837  calculate bounds of fortran allocatable array which has array descriptors.
5838- ``DW_OP_over`` duplicates the entry currently second in the stack at the top
5839  of the stack. This opcode can be used to calculate bounds of fortran assumed
5840  rank array which has rank known at run time and current dimension number is
5841  implicitly first element of the stack.
5842- ``DW_OP_LLVM_implicit_pointer`` It specifies the dereferenced value. It can
5843  be used to represent pointer variables which are optimized out but the value
5844  it points to is known. This operator is required as it is different than DWARF
5845  operator DW_OP_implicit_pointer in representation and specification (number
5846  and types of operands) and later can not be used as multiple level.
5847
5848.. code-block:: text
5849
5850    IR for "*ptr = 4;"
5851    --------------
5852    call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !20)
5853    !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5,
5854                           type: !18)
5855    !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
5856    !19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
5857    !20 = !DIExpression(DW_OP_LLVM_implicit_pointer))
5858
5859    IR for "**ptr = 4;"
5860    --------------
5861    call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !21)
5862    !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5,
5863                           type: !18)
5864    !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
5865    !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
5866    !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
5867    !21 = !DIExpression(DW_OP_LLVM_implicit_pointer,
5868                        DW_OP_LLVM_implicit_pointer))
5869
5870DWARF specifies three kinds of simple location descriptions: Register, memory,
5871and implicit location descriptions.  Note that a location description is
5872defined over certain ranges of a program, i.e the location of a variable may
5873change over the course of the program. Register and memory location
5874descriptions describe the *concrete location* of a source variable (in the
5875sense that a debugger might modify its value), whereas *implicit locations*
5876describe merely the actual *value* of a source variable which might not exist
5877in registers or in memory (see ``DW_OP_stack_value``).
5878
5879A ``llvm.dbg.addr`` or ``llvm.dbg.declare`` intrinsic describes an indirect
5880value (the address) of a source variable. The first operand of the intrinsic
5881must be an address of some kind. A DIExpression attached to the intrinsic
5882refines this address to produce a concrete location for the source variable.
5883
5884A ``llvm.dbg.value`` intrinsic describes the direct value of a source variable.
5885The first operand of the intrinsic may be a direct or indirect value. A
5886DIExpression attached to the intrinsic refines the first operand to produce a
5887direct value. For example, if the first operand is an indirect value, it may be
5888necessary to insert ``DW_OP_deref`` into the DIExpression in order to produce a
5889valid debug intrinsic.
5890
5891.. note::
5892
5893   A DIExpression is interpreted in the same way regardless of which kind of
5894   debug intrinsic it's attached to.
5895
5896.. code-block:: text
5897
5898    !0 = !DIExpression(DW_OP_deref)
5899    !1 = !DIExpression(DW_OP_plus_uconst, 3)
5900    !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus)
5901    !2 = !DIExpression(DW_OP_bit_piece, 3, 7)
5902    !3 = !DIExpression(DW_OP_deref, DW_OP_constu, 3, DW_OP_plus, DW_OP_LLVM_fragment, 3, 7)
5903    !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef)
5904    !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value)
5905
5906DIArgList
5907""""""""""""
5908
5909``DIArgList`` nodes hold a list of constant or SSA value references. These are
5910used in :ref:`debug intrinsics<dbg_intrinsics>` (currently only in
5911``llvm.dbg.value``) in combination with a ``DIExpression`` that uses the
5912``DW_OP_LLVM_arg`` operator. Because a DIArgList may refer to local values
5913within a function, it must only be used as a function argument, must always be
5914inlined, and cannot appear in named metadata.
5915
5916.. code-block:: text
5917
5918    llvm.dbg.value(metadata !DIArgList(i32 %a, i32 %b),
5919                   metadata !16,
5920                   metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus))
5921
5922DIFlags
5923"""""""""""""""
5924
5925These flags encode various properties of DINodes.
5926
5927The `ExportSymbols` flag marks a class, struct or union whose members
5928may be referenced as if they were defined in the containing class or
5929union. This flag is used to decide whether the DW_AT_export_symbols can
5930be used for the structure type.
5931
5932DIObjCProperty
5933""""""""""""""
5934
5935``DIObjCProperty`` nodes represent Objective-C property nodes.
5936
5937.. code-block:: text
5938
5939    !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
5940                         getter: "getFoo", attributes: 7, type: !2)
5941
5942DIImportedEntity
5943""""""""""""""""
5944
5945``DIImportedEntity`` nodes represent entities (such as modules) imported into a
5946compile unit. The ``elements`` field is a list of renamed entities (such as
5947variables and subprograms) in the imported entity (such as module).
5948
5949.. code-block:: text
5950
5951   !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
5952                          entity: !1, line: 7, elements: !3)
5953   !3 = !{!4}
5954   !4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "bar", scope: !0,
5955                          entity: !5, line: 7)
5956
5957DIMacro
5958"""""""
5959
5960``DIMacro`` nodes represent definition or undefinition of a macro identifiers.
5961The ``name:`` field is the macro identifier, followed by macro parameters when
5962defining a function-like macro, and the ``value`` field is the token-string
5963used to expand the macro identifier.
5964
5965.. code-block:: text
5966
5967   !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)",
5968                 value: "((x) + 1)")
5969   !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo")
5970
5971DIMacroFile
5972"""""""""""
5973
5974``DIMacroFile`` nodes represent inclusion of source files.
5975The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that
5976appear in the included source file.
5977
5978.. code-block:: text
5979
5980   !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2,
5981                     nodes: !3)
5982
5983.. _DILabel:
5984
5985DILabel
5986"""""""
5987
5988``DILabel`` nodes represent labels within a :ref:`DISubprogram`. All fields of
5989a ``DILabel`` are mandatory. The ``scope:`` field must be one of either a
5990:ref:`DILexicalBlockFile`, a :ref:`DILexicalBlock`, or a :ref:`DISubprogram`.
5991The ``name:`` field is the label identifier. The ``file:`` field is the
5992:ref:`DIFile` the label is present in. The ``line:`` field is the source line
5993within the file where the label is declared.
5994
5995.. code-block:: text
5996
5997  !2 = !DILabel(scope: !0, name: "foo", file: !1, line: 7)
5998
5999'``tbaa``' Metadata
6000^^^^^^^^^^^^^^^^^^^
6001
6002In LLVM IR, memory does not have types, so LLVM's own type system is not
6003suitable for doing type based alias analysis (TBAA). Instead, metadata is
6004added to the IR to describe a type system of a higher level language. This
6005can be used to implement C/C++ strict type aliasing rules, but it can also
6006be used to implement custom alias analysis behavior for other languages.
6007
6008This description of LLVM's TBAA system is broken into two parts:
6009:ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and
6010:ref:`Representation<tbaa_node_representation>` talks about the metadata
6011encoding of various entities.
6012
6013It is always possible to trace any TBAA node to a "root" TBAA node (details
6014in the :ref:`Representation<tbaa_node_representation>` section).  TBAA
6015nodes with different roots have an unknown aliasing relationship, and LLVM
6016conservatively infers ``MayAlias`` between them.  The rules mentioned in
6017this section only pertain to TBAA nodes living under the same root.
6018
6019.. _tbaa_node_semantics:
6020
6021Semantics
6022"""""""""
6023
6024The TBAA metadata system, referred to as "struct path TBAA" (not to be
6025confused with ``tbaa.struct``), consists of the following high level
6026concepts: *Type Descriptors*, further subdivided into scalar type
6027descriptors and struct type descriptors; and *Access Tags*.
6028
6029**Type descriptors** describe the type system of the higher level language
6030being compiled.  **Scalar type descriptors** describe types that do not
6031contain other types.  Each scalar type has a parent type, which must also
6032be a scalar type or the TBAA root.  Via this parent relation, scalar types
6033within a TBAA root form a tree.  **Struct type descriptors** denote types
6034that contain a sequence of other type descriptors, at known offsets.  These
6035contained type descriptors can either be struct type descriptors themselves
6036or scalar type descriptors.
6037
6038**Access tags** are metadata nodes attached to load and store instructions.
6039Access tags use type descriptors to describe the *location* being accessed
6040in terms of the type system of the higher level language.  Access tags are
6041tuples consisting of a base type, an access type and an offset.  The base
6042type is a scalar type descriptor or a struct type descriptor, the access
6043type is a scalar type descriptor, and the offset is a constant integer.
6044
6045The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two
6046things:
6047
6048 * If ``BaseTy`` is a struct type, the tag describes a memory access (load
6049   or store) of a value of type ``AccessTy`` contained in the struct type
6050   ``BaseTy`` at offset ``Offset``.
6051
6052 * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and
6053   ``AccessTy`` must be the same; and the access tag describes a scalar
6054   access with scalar type ``AccessTy``.
6055
6056We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)``
6057tuples this way:
6058
6059 * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is
6060   ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as
6061   described in the TBAA metadata.  ``ImmediateParent(BaseTy, Offset)`` is
6062   undefined if ``Offset`` is non-zero.
6063
6064 * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)``
6065   is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in
6066   ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted
6067   to be relative within that inner type.
6068
6069A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)``
6070aliases a memory access with an access tag ``(BaseTy2, AccessTy2,
6071Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2,
6072Offset2)`` via the ``Parent`` relation or vice versa.
6073
6074As a concrete example, the type descriptor graph for the following program
6075
6076.. code-block:: c
6077
6078    struct Inner {
6079      int i;    // offset 0
6080      float f;  // offset 4
6081    };
6082
6083    struct Outer {
6084      float f;  // offset 0
6085      double d; // offset 4
6086      struct Inner inner_a;  // offset 12
6087    };
6088
6089    void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) {
6090      outer->f = 0;            // tag0: (OuterStructTy, FloatScalarTy, 0)
6091      outer->inner_a.i = 0;    // tag1: (OuterStructTy, IntScalarTy, 12)
6092      outer->inner_a.f = 0.0;  // tag2: (OuterStructTy, FloatScalarTy, 16)
6093      *f = 0.0;                // tag3: (FloatScalarTy, FloatScalarTy, 0)
6094    }
6095
6096is (note that in C and C++, ``char`` can be used to access any arbitrary
6097type):
6098
6099.. code-block:: text
6100
6101    Root = "TBAA Root"
6102    CharScalarTy = ("char", Root, 0)
6103    FloatScalarTy = ("float", CharScalarTy, 0)
6104    DoubleScalarTy = ("double", CharScalarTy, 0)
6105    IntScalarTy = ("int", CharScalarTy, 0)
6106    InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)}
6107    OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4),
6108                     (InnerStructTy, 12)}
6109
6110
6111with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy,
61120)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and
6113``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``.
6114
6115.. _tbaa_node_representation:
6116
6117Representation
6118""""""""""""""
6119
6120The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or
6121with exactly one ``MDString`` operand.
6122
6123Scalar type descriptors are represented as an ``MDNode`` s with two
6124operands.  The first operand is an ``MDString`` denoting the name of the
6125struct type.  LLVM does not assign meaning to the value of this operand, it
6126only cares about it being an ``MDString``.  The second operand is an
6127``MDNode`` which points to the parent for said scalar type descriptor,
6128which is either another scalar type descriptor or the TBAA root.  Scalar
6129type descriptors can have an optional third argument, but that must be the
6130constant integer zero.
6131
6132Struct type descriptors are represented as ``MDNode`` s with an odd number
6133of operands greater than 1.  The first operand is an ``MDString`` denoting
6134the name of the struct type.  Like in scalar type descriptors the actual
6135value of this name operand is irrelevant to LLVM.  After the name operand,
6136the struct type descriptors have a sequence of alternating ``MDNode`` and
6137``ConstantInt`` operands.  With N starting from 1, the 2N - 1 th operand,
6138an ``MDNode``, denotes a contained field, and the 2N th operand, a
6139``ConstantInt``, is the offset of the said contained field.  The offsets
6140must be in non-decreasing order.
6141
6142Access tags are represented as ``MDNode`` s with either 3 or 4 operands.
6143The first operand is an ``MDNode`` pointing to the node representing the
6144base type.  The second operand is an ``MDNode`` pointing to the node
6145representing the access type.  The third operand is a ``ConstantInt`` that
6146states the offset of the access.  If a fourth field is present, it must be
6147a ``ConstantInt`` valued at 0 or 1.  If it is 1 then the access tag states
6148that the location being accessed is "constant" (meaning
6149``pointsToConstantMemory`` should return true; see `other useful
6150AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_).  The TBAA root of
6151the access type and the base type of an access tag must be the same, and
6152that is the TBAA root of the access tag.
6153
6154'``tbaa.struct``' Metadata
6155^^^^^^^^^^^^^^^^^^^^^^^^^^
6156
6157The :ref:`llvm.memcpy <int_memcpy>` is often used to implement
6158aggregate assignment operations in C and similar languages, however it
6159is defined to copy a contiguous region of memory, which is more than
6160strictly necessary for aggregate types which contain holes due to
6161padding. Also, it doesn't contain any TBAA information about the fields
6162of the aggregate.
6163
6164``!tbaa.struct`` metadata can describe which memory subregions in a
6165memcpy are padding and what the TBAA tags of the struct are.
6166
6167The current metadata format is very simple. ``!tbaa.struct`` metadata
6168nodes are a list of operands which are in conceptual groups of three.
6169For each group of three, the first operand gives the byte offset of a
6170field in bytes, the second gives its size in bytes, and the third gives
6171its tbaa tag. e.g.:
6172
6173.. code-block:: llvm
6174
6175    !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 }
6176
6177This describes a struct with two fields. The first is at offset 0 bytes
6178with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes
6179and has size 4 bytes and has tbaa tag !2.
6180
6181Note that the fields need not be contiguous. In this example, there is a
61824 byte gap between the two fields. This gap represents padding which
6183does not carry useful data and need not be preserved.
6184
6185'``noalias``' and '``alias.scope``' Metadata
6186^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6187
6188``noalias`` and ``alias.scope`` metadata provide the ability to specify generic
6189noalias memory-access sets. This means that some collection of memory access
6190instructions (loads, stores, memory-accessing calls, etc.) that carry
6191``noalias`` metadata can specifically be specified not to alias with some other
6192collection of memory access instructions that carry ``alias.scope`` metadata.
6193Each type of metadata specifies a list of scopes where each scope has an id and
6194a domain.
6195
6196When evaluating an aliasing query, if for some domain, the set
6197of scopes with that domain in one instruction's ``alias.scope`` list is a
6198subset of (or equal to) the set of scopes for that domain in another
6199instruction's ``noalias`` list, then the two memory accesses are assumed not to
6200alias.
6201
6202Because scopes in one domain don't affect scopes in other domains, separate
6203domains can be used to compose multiple independent noalias sets.  This is
6204used for example during inlining.  As the noalias function parameters are
6205turned into noalias scope metadata, a new domain is used every time the
6206function is inlined.
6207
6208The metadata identifying each domain is itself a list containing one or two
6209entries. The first entry is the name of the domain. Note that if the name is a
6210string then it can be combined across functions and translation units. A
6211self-reference can be used to create globally unique domain names. A
6212descriptive string may optionally be provided as a second list entry.
6213
6214The metadata identifying each scope is also itself a list containing two or
6215three entries. The first entry is the name of the scope. Note that if the name
6216is a string then it can be combined across functions and translation units. A
6217self-reference can be used to create globally unique scope names. A metadata
6218reference to the scope's domain is the second entry. A descriptive string may
6219optionally be provided as a third list entry.
6220
6221For example,
6222
6223.. code-block:: llvm
6224
6225    ; Two scope domains:
6226    !0 = !{!0}
6227    !1 = !{!1}
6228
6229    ; Some scopes in these domains:
6230    !2 = !{!2, !0}
6231    !3 = !{!3, !0}
6232    !4 = !{!4, !1}
6233
6234    ; Some scope lists:
6235    !5 = !{!4} ; A list containing only scope !4
6236    !6 = !{!4, !3, !2}
6237    !7 = !{!3}
6238
6239    ; These two instructions don't alias:
6240    %0 = load float, float* %c, align 4, !alias.scope !5
6241    store float %0, float* %arrayidx.i, align 4, !noalias !5
6242
6243    ; These two instructions also don't alias (for domain !1, the set of scopes
6244    ; in the !alias.scope equals that in the !noalias list):
6245    %2 = load float, float* %c, align 4, !alias.scope !5
6246    store float %2, float* %arrayidx.i2, align 4, !noalias !6
6247
6248    ; These two instructions may alias (for domain !0, the set of scopes in
6249    ; the !noalias list is not a superset of, or equal to, the scopes in the
6250    ; !alias.scope list):
6251    %2 = load float, float* %c, align 4, !alias.scope !6
6252    store float %0, float* %arrayidx.i, align 4, !noalias !7
6253
6254'``fpmath``' Metadata
6255^^^^^^^^^^^^^^^^^^^^^
6256
6257``fpmath`` metadata may be attached to any instruction of floating-point
6258type. It can be used to express the maximum acceptable error in the
6259result of that instruction, in ULPs, thus potentially allowing the
6260compiler to use a more efficient but less accurate method of computing
6261it. ULP is defined as follows:
6262
6263    If ``x`` is a real number that lies between two finite consecutive
6264    floating-point numbers ``a`` and ``b``, without being equal to one
6265    of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the
6266    distance between the two non-equal finite floating-point numbers
6267    nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``.
6268
6269The metadata node shall consist of a single positive float type number
6270representing the maximum relative error, for example:
6271
6272.. code-block:: llvm
6273
6274    !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
6275
6276.. _range-metadata:
6277
6278'``range``' Metadata
6279^^^^^^^^^^^^^^^^^^^^
6280
6281``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of
6282integer types. It expresses the possible ranges the loaded value or the value
6283returned by the called function at this call site is in. If the loaded or
6284returned value is not in the specified range, the behavior is undefined. The
6285ranges are represented with a flattened list of integers. The loaded value or
6286the value returned is known to be in the union of the ranges defined by each
6287consecutive pair. Each pair has the following properties:
6288
6289-  The type must match the type loaded by the instruction.
6290-  The pair ``a,b`` represents the range ``[a,b)``.
6291-  Both ``a`` and ``b`` are constants.
6292-  The range is allowed to wrap.
6293-  The range should not represent the full or empty set. That is,
6294   ``a!=b``.
6295
6296In addition, the pairs must be in signed order of the lower bound and
6297they must be non-contiguous.
6298
6299Examples:
6300
6301.. code-block:: llvm
6302
6303      %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1
6304      %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
6305      %c = call i8 @foo(),       !range !2 ; Can only be 0, 1, 3, 4 or 5
6306      %d = invoke i8 @bar() to label %cont
6307             unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5
6308    ...
6309    !0 = !{ i8 0, i8 2 }
6310    !1 = !{ i8 255, i8 2 }
6311    !2 = !{ i8 0, i8 2, i8 3, i8 6 }
6312    !3 = !{ i8 -2, i8 0, i8 3, i8 6 }
6313
6314'``absolute_symbol``' Metadata
6315^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6316
6317``absolute_symbol`` metadata may be attached to a global variable
6318declaration. It marks the declaration as a reference to an absolute symbol,
6319which causes the backend to use absolute relocations for the symbol even
6320in position independent code, and expresses the possible ranges that the
6321global variable's *address* (not its value) is in, in the same format as
6322``range`` metadata, with the extension that the pair ``all-ones,all-ones``
6323may be used to represent the full set.
6324
6325Example (assuming 64-bit pointers):
6326
6327.. code-block:: llvm
6328
6329      @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256)
6330      @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64)
6331
6332    ...
6333    !0 = !{ i64 0, i64 256 }
6334    !1 = !{ i64 -1, i64 -1 }
6335
6336'``callees``' Metadata
6337^^^^^^^^^^^^^^^^^^^^^^
6338
6339``callees`` metadata may be attached to indirect call sites. If ``callees``
6340metadata is attached to a call site, and any callee is not among the set of
6341functions provided by the metadata, the behavior is undefined. The intent of
6342this metadata is to facilitate optimizations such as indirect-call promotion.
6343For example, in the code below, the call instruction may only target the
6344``add`` or ``sub`` functions:
6345
6346.. code-block:: llvm
6347
6348    %result = call i64 %binop(i64 %x, i64 %y), !callees !0
6349
6350    ...
6351    !0 = !{i64 (i64, i64)* @add, i64 (i64, i64)* @sub}
6352
6353'``callback``' Metadata
6354^^^^^^^^^^^^^^^^^^^^^^^
6355
6356``callback`` metadata may be attached to a function declaration, or definition.
6357(Call sites are excluded only due to the lack of a use case.) For ease of
6358exposition, we'll refer to the function annotated w/ metadata as a broker
6359function. The metadata describes how the arguments of a call to the broker are
6360in turn passed to the callback function specified by the metadata. Thus, the
6361``callback`` metadata provides a partial description of a call site inside the
6362broker function with regards to the arguments of a call to the broker. The only
6363semantic restriction on the broker function itself is that it is not allowed to
6364inspect or modify arguments referenced in the ``callback`` metadata as
6365pass-through to the callback function.
6366
6367The broker is not required to actually invoke the callback function at runtime.
6368However, the assumptions about not inspecting or modifying arguments that would
6369be passed to the specified callback function still hold, even if the callback
6370function is not dynamically invoked. The broker is allowed to invoke the
6371callback function more than once per invocation of the broker. The broker is
6372also allowed to invoke (directly or indirectly) the function passed as a
6373callback through another use. Finally, the broker is also allowed to relay the
6374callback callee invocation to a different thread.
6375
6376The metadata is structured as follows: At the outer level, ``callback``
6377metadata is a list of ``callback`` encodings. Each encoding starts with a
6378constant ``i64`` which describes the argument position of the callback function
6379in the call to the broker. The following elements, except the last, describe
6380what arguments are passed to the callback function. Each element is again an
6381``i64`` constant identifying the argument of the broker that is passed through,
6382or ``i64 -1`` to indicate an unknown or inspected argument. The order in which
6383they are listed has to be the same in which they are passed to the callback
6384callee. The last element of the encoding is a boolean which specifies how
6385variadic arguments of the broker are handled. If it is true, all variadic
6386arguments of the broker are passed through to the callback function *after* the
6387arguments encoded explicitly before.
6388
6389In the code below, the ``pthread_create`` function is marked as a broker
6390through the ``!callback !1`` metadata. In the example, there is only one
6391callback encoding, namely ``!2``, associated with the broker. This encoding
6392identifies the callback function as the second argument of the broker (``i64
63932``) and the sole argument of the callback function as the third one of the
6394broker function (``i64 3``).
6395
6396.. FIXME why does the llvm-sphinx-docs builder give a highlighting
6397   error if the below is set to highlight as 'llvm', despite that we
6398   have misc.highlighting_failure set?
6399
6400.. code-block:: text
6401
6402    declare !callback !1 dso_local i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*)
6403
6404    ...
6405    !2 = !{i64 2, i64 3, i1 false}
6406    !1 = !{!2}
6407
6408Another example is shown below. The callback callee is the second argument of
6409the ``__kmpc_fork_call`` function (``i64 2``). The callee is given two unknown
6410values (each identified by a ``i64 -1``) and afterwards all
6411variadic arguments that are passed to the ``__kmpc_fork_call`` call (due to the
6412final ``i1 true``).
6413
6414.. FIXME why does the llvm-sphinx-docs builder give a highlighting
6415   error if the below is set to highlight as 'llvm', despite that we
6416   have misc.highlighting_failure set?
6417
6418.. code-block:: text
6419
6420    declare !callback !0 dso_local void @__kmpc_fork_call(%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...)
6421
6422    ...
6423    !1 = !{i64 2, i64 -1, i64 -1, i1 true}
6424    !0 = !{!1}
6425
6426'``exclude``' Metadata
6427^^^^^^^^^^^^^^^^^^^^^^
6428
6429``exclude`` metadata may be attached to a global variable to signify that its
6430section should not be included in the final executable or shared library. This
6431option is only valid for global variables with an explicit section targeting ELF
6432or COFF. This is done using the ``SHF_EXCLUDE`` flag on ELF targets and the
6433``IMAGE_SCN_LNK_REMOVE`` and ``IMAGE_SCN_MEM_DISCARDABLE`` flags for COFF
6434targets. Additionally, this metadata is only used as a flag, so the associated
6435node must be empty. The explicit section should not conflict with any other
6436sections that the user does not want removed after linking.
6437
6438.. code-block:: text
6439
6440  @object = private constant [1 x i8] c"\00", section ".foo" !exclude !0
6441
6442  ...
6443  !0 = !{}
6444
6445'``unpredictable``' Metadata
6446^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6447
6448``unpredictable`` metadata may be attached to any branch or switch
6449instruction. It can be used to express the unpredictability of control
6450flow. Similar to the llvm.expect intrinsic, it may be used to alter
6451optimizations related to compare and branch instructions. The metadata
6452is treated as a boolean value; if it exists, it signals that the branch
6453or switch that it is attached to is completely unpredictable.
6454
6455.. _md_dereferenceable:
6456
6457'``dereferenceable``' Metadata
6458^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6459
6460The existence of the ``!dereferenceable`` metadata on the instruction
6461tells the optimizer that the value loaded is known to be dereferenceable.
6462The number of bytes known to be dereferenceable is specified by the integer
6463value in the metadata node. This is analogous to the ''dereferenceable''
6464attribute on parameters and return values.
6465
6466.. _md_dereferenceable_or_null:
6467
6468'``dereferenceable_or_null``' Metadata
6469^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6470
6471The existence of the ``!dereferenceable_or_null`` metadata on the
6472instruction tells the optimizer that the value loaded is known to be either
6473dereferenceable or null.
6474The number of bytes known to be dereferenceable is specified by the integer
6475value in the metadata node. This is analogous to the ''dereferenceable_or_null''
6476attribute on parameters and return values.
6477
6478.. _llvm.loop:
6479
6480'``llvm.loop``'
6481^^^^^^^^^^^^^^^
6482
6483It is sometimes useful to attach information to loop constructs. Currently,
6484loop metadata is implemented as metadata attached to the branch instruction
6485in the loop latch block. The loop metadata node is a list of
6486other metadata nodes, each representing a property of the loop. Usually,
6487the first item of the property node is a string. For example, the
6488``llvm.loop.unroll.count`` suggests an unroll factor to the loop
6489unroller:
6490
6491.. code-block:: llvm
6492
6493      br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0
6494    ...
6495    !0 = !{!0, !1, !2}
6496    !1 = !{!"llvm.loop.unroll.enable"}
6497    !2 = !{!"llvm.loop.unroll.count", i32 4}
6498
6499For legacy reasons, the first item of a loop metadata node must be a
6500reference to itself. Before the advent of the 'distinct' keyword, this
6501forced the preservation of otherwise identical metadata nodes. Since
6502the loop-metadata node can be attached to multiple nodes, the 'distinct'
6503keyword has become unnecessary.
6504
6505Prior to the property nodes, one or two ``DILocation`` (debug location)
6506nodes can be present in the list. The first, if present, identifies the
6507source-code location where the loop begins. The second, if present,
6508identifies the source-code location where the loop ends.
6509
6510Loop metadata nodes cannot be used as unique identifiers. They are
6511neither persistent for the same loop through transformations nor
6512necessarily unique to just one loop.
6513
6514'``llvm.loop.disable_nonforced``'
6515^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6516
6517This metadata disables all optional loop transformations unless
6518explicitly instructed using other transformation metadata such as
6519``llvm.loop.unroll.enable``. That is, no heuristic will try to determine
6520whether a transformation is profitable. The purpose is to avoid that the
6521loop is transformed to a different loop before an explicitly requested
6522(forced) transformation is applied. For instance, loop fusion can make
6523other transformations impossible. Mandatory loop canonicalizations such
6524as loop rotation are still applied.
6525
6526It is recommended to use this metadata in addition to any llvm.loop.*
6527transformation directive. Also, any loop should have at most one
6528directive applied to it (and a sequence of transformations built using
6529followup-attributes). Otherwise, which transformation will be applied
6530depends on implementation details such as the pass pipeline order.
6531
6532See :ref:`transformation-metadata` for details.
6533
6534'``llvm.loop.vectorize``' and '``llvm.loop.interleave``'
6535^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6536
6537Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are
6538used to control per-loop vectorization and interleaving parameters such as
6539vectorization width and interleave count. These metadata should be used in
6540conjunction with ``llvm.loop`` loop identification metadata. The
6541``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only
6542optimization hints and the optimizer will only interleave and vectorize loops if
6543it believes it is safe to do so. The ``llvm.loop.parallel_accesses`` metadata
6544which contains information about loop-carried memory dependencies can be helpful
6545in determining the safety of these transformations.
6546
6547'``llvm.loop.interleave.count``' Metadata
6548^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6549
6550This metadata suggests an interleave count to the loop interleaver.
6551The first operand is the string ``llvm.loop.interleave.count`` and the
6552second operand is an integer specifying the interleave count. For
6553example:
6554
6555.. code-block:: llvm
6556
6557   !0 = !{!"llvm.loop.interleave.count", i32 4}
6558
6559Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving
6560multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0
6561then the interleave count will be determined automatically.
6562
6563'``llvm.loop.vectorize.enable``' Metadata
6564^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6565
6566This metadata selectively enables or disables vectorization for the loop. The
6567first operand is the string ``llvm.loop.vectorize.enable`` and the second operand
6568is a bit. If the bit operand value is 1 vectorization is enabled. A value of
65690 disables vectorization:
6570
6571.. code-block:: llvm
6572
6573   !0 = !{!"llvm.loop.vectorize.enable", i1 0}
6574   !1 = !{!"llvm.loop.vectorize.enable", i1 1}
6575
6576'``llvm.loop.vectorize.predicate.enable``' Metadata
6577^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6578
6579This metadata selectively enables or disables creating predicated instructions
6580for the loop, which can enable folding of the scalar epilogue loop into the
6581main loop. The first operand is the string
6582``llvm.loop.vectorize.predicate.enable`` and the second operand is a bit. If
6583the bit operand value is 1 vectorization is enabled. A value of 0 disables
6584vectorization:
6585
6586.. code-block:: llvm
6587
6588   !0 = !{!"llvm.loop.vectorize.predicate.enable", i1 0}
6589   !1 = !{!"llvm.loop.vectorize.predicate.enable", i1 1}
6590
6591'``llvm.loop.vectorize.scalable.enable``' Metadata
6592^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6593
6594This metadata selectively enables or disables scalable vectorization for the
6595loop, and only has any effect if vectorization for the loop is already enabled.
6596The first operand is the string ``llvm.loop.vectorize.scalable.enable``
6597and the second operand is a bit. If the bit operand value is 1 scalable
6598vectorization is enabled, whereas a value of 0 reverts to the default fixed
6599width vectorization:
6600
6601.. code-block:: llvm
6602
6603   !0 = !{!"llvm.loop.vectorize.scalable.enable", i1 0}
6604   !1 = !{!"llvm.loop.vectorize.scalable.enable", i1 1}
6605
6606'``llvm.loop.vectorize.width``' Metadata
6607^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6608
6609This metadata sets the target width of the vectorizer. The first
6610operand is the string ``llvm.loop.vectorize.width`` and the second
6611operand is an integer specifying the width. For example:
6612
6613.. code-block:: llvm
6614
6615   !0 = !{!"llvm.loop.vectorize.width", i32 4}
6616
6617Note that setting ``llvm.loop.vectorize.width`` to 1 disables
6618vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to
66190 or if the loop does not have this metadata the width will be
6620determined automatically.
6621
6622'``llvm.loop.vectorize.followup_vectorized``' Metadata
6623^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6624
6625This metadata defines which loop attributes the vectorized loop will
6626have. See :ref:`transformation-metadata` for details.
6627
6628'``llvm.loop.vectorize.followup_epilogue``' Metadata
6629^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6630
6631This metadata defines which loop attributes the epilogue will have. The
6632epilogue is not vectorized and is executed when either the vectorized
6633loop is not known to preserve semantics (because e.g., it processes two
6634arrays that are found to alias by a runtime check) or for the last
6635iterations that do not fill a complete set of vector lanes. See
6636:ref:`Transformation Metadata <transformation-metadata>` for details.
6637
6638'``llvm.loop.vectorize.followup_all``' Metadata
6639^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6640
6641Attributes in the metadata will be added to both the vectorized and
6642epilogue loop.
6643See :ref:`Transformation Metadata <transformation-metadata>` for details.
6644
6645'``llvm.loop.unroll``'
6646^^^^^^^^^^^^^^^^^^^^^^
6647
6648Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling
6649optimization hints such as the unroll factor. ``llvm.loop.unroll``
6650metadata should be used in conjunction with ``llvm.loop`` loop
6651identification metadata. The ``llvm.loop.unroll`` metadata are only
6652optimization hints and the unrolling will only be performed if the
6653optimizer believes it is safe to do so.
6654
6655'``llvm.loop.unroll.count``' Metadata
6656^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6657
6658This metadata suggests an unroll factor to the loop unroller. The
6659first operand is the string ``llvm.loop.unroll.count`` and the second
6660operand is a positive integer specifying the unroll factor. For
6661example:
6662
6663.. code-block:: llvm
6664
6665   !0 = !{!"llvm.loop.unroll.count", i32 4}
6666
6667If the trip count of the loop is less than the unroll count the loop
6668will be partially unrolled.
6669
6670'``llvm.loop.unroll.disable``' Metadata
6671^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6672
6673This metadata disables loop unrolling. The metadata has a single operand
6674which is the string ``llvm.loop.unroll.disable``. For example:
6675
6676.. code-block:: llvm
6677
6678   !0 = !{!"llvm.loop.unroll.disable"}
6679
6680'``llvm.loop.unroll.runtime.disable``' Metadata
6681^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6682
6683This metadata disables runtime loop unrolling. The metadata has a single
6684operand which is the string ``llvm.loop.unroll.runtime.disable``. For example:
6685
6686.. code-block:: llvm
6687
6688   !0 = !{!"llvm.loop.unroll.runtime.disable"}
6689
6690'``llvm.loop.unroll.enable``' Metadata
6691^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6692
6693This metadata suggests that the loop should be fully unrolled if the trip count
6694is known at compile time and partially unrolled if the trip count is not known
6695at compile time. The metadata has a single operand which is the string
6696``llvm.loop.unroll.enable``.  For example:
6697
6698.. code-block:: llvm
6699
6700   !0 = !{!"llvm.loop.unroll.enable"}
6701
6702'``llvm.loop.unroll.full``' Metadata
6703^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6704
6705This metadata suggests that the loop should be unrolled fully. The
6706metadata has a single operand which is the string ``llvm.loop.unroll.full``.
6707For example:
6708
6709.. code-block:: llvm
6710
6711   !0 = !{!"llvm.loop.unroll.full"}
6712
6713'``llvm.loop.unroll.followup``' Metadata
6714^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6715
6716This metadata defines which loop attributes the unrolled loop will have.
6717See :ref:`Transformation Metadata <transformation-metadata>` for details.
6718
6719'``llvm.loop.unroll.followup_remainder``' Metadata
6720^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6721
6722This metadata defines which loop attributes the remainder loop after
6723partial/runtime unrolling will have. See
6724:ref:`Transformation Metadata <transformation-metadata>` for details.
6725
6726'``llvm.loop.unroll_and_jam``'
6727^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6728
6729This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata
6730above, but affect the unroll and jam pass. In addition any loop with
6731``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will
6732disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the
6733unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam
6734too.)
6735
6736The metadata for unroll and jam otherwise is the same as for ``unroll``.
6737``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and
6738``llvm.loop.unroll_and_jam.count`` do the same as for unroll.
6739``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints
6740and the normal safety checks will still be performed.
6741
6742'``llvm.loop.unroll_and_jam.count``' Metadata
6743^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6744
6745This metadata suggests an unroll and jam factor to use, similarly to
6746``llvm.loop.unroll.count``. The first operand is the string
6747``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer
6748specifying the unroll factor. For example:
6749
6750.. code-block:: llvm
6751
6752   !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4}
6753
6754If the trip count of the loop is less than the unroll count the loop
6755will be partially unroll and jammed.
6756
6757'``llvm.loop.unroll_and_jam.disable``' Metadata
6758^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6759
6760This metadata disables loop unroll and jamming. The metadata has a single
6761operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example:
6762
6763.. code-block:: llvm
6764
6765   !0 = !{!"llvm.loop.unroll_and_jam.disable"}
6766
6767'``llvm.loop.unroll_and_jam.enable``' Metadata
6768^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6769
6770This metadata suggests that the loop should be fully unroll and jammed if the
6771trip count is known at compile time and partially unrolled if the trip count is
6772not known at compile time. The metadata has a single operand which is the
6773string ``llvm.loop.unroll_and_jam.enable``.  For example:
6774
6775.. code-block:: llvm
6776
6777   !0 = !{!"llvm.loop.unroll_and_jam.enable"}
6778
6779'``llvm.loop.unroll_and_jam.followup_outer``' Metadata
6780^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6781
6782This metadata defines which loop attributes the outer unrolled loop will
6783have. See :ref:`Transformation Metadata <transformation-metadata>` for
6784details.
6785
6786'``llvm.loop.unroll_and_jam.followup_inner``' Metadata
6787^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6788
6789This metadata defines which loop attributes the inner jammed loop will
6790have. See :ref:`Transformation Metadata <transformation-metadata>` for
6791details.
6792
6793'``llvm.loop.unroll_and_jam.followup_remainder_outer``' Metadata
6794^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6795
6796This metadata defines which attributes the epilogue of the outer loop
6797will have. This loop is usually unrolled, meaning there is no such
6798loop. This attribute will be ignored in this case. See
6799:ref:`Transformation Metadata <transformation-metadata>` for details.
6800
6801'``llvm.loop.unroll_and_jam.followup_remainder_inner``' Metadata
6802^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6803
6804This metadata defines which attributes the inner loop of the epilogue
6805will have. The outer epilogue will usually be unrolled, meaning there
6806can be multiple inner remainder loops. See
6807:ref:`Transformation Metadata <transformation-metadata>` for details.
6808
6809'``llvm.loop.unroll_and_jam.followup_all``' Metadata
6810^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6811
6812Attributes specified in the metadata is added to all
6813``llvm.loop.unroll_and_jam.*`` loops. See
6814:ref:`Transformation Metadata <transformation-metadata>` for details.
6815
6816'``llvm.loop.licm_versioning.disable``' Metadata
6817^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6818
6819This metadata indicates that the loop should not be versioned for the purpose
6820of enabling loop-invariant code motion (LICM). The metadata has a single operand
6821which is the string ``llvm.loop.licm_versioning.disable``. For example:
6822
6823.. code-block:: llvm
6824
6825   !0 = !{!"llvm.loop.licm_versioning.disable"}
6826
6827'``llvm.loop.distribute.enable``' Metadata
6828^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6829
6830Loop distribution allows splitting a loop into multiple loops.  Currently,
6831this is only performed if the entire loop cannot be vectorized due to unsafe
6832memory dependencies.  The transformation will attempt to isolate the unsafe
6833dependencies into their own loop.
6834
6835This metadata can be used to selectively enable or disable distribution of the
6836loop.  The first operand is the string ``llvm.loop.distribute.enable`` and the
6837second operand is a bit. If the bit operand value is 1 distribution is
6838enabled. A value of 0 disables distribution:
6839
6840.. code-block:: llvm
6841
6842   !0 = !{!"llvm.loop.distribute.enable", i1 0}
6843   !1 = !{!"llvm.loop.distribute.enable", i1 1}
6844
6845This metadata should be used in conjunction with ``llvm.loop`` loop
6846identification metadata.
6847
6848'``llvm.loop.distribute.followup_coincident``' Metadata
6849^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6850
6851This metadata defines which attributes extracted loops with no cyclic
6852dependencies will have (i.e. can be vectorized). See
6853:ref:`Transformation Metadata <transformation-metadata>` for details.
6854
6855'``llvm.loop.distribute.followup_sequential``' Metadata
6856^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6857
6858This metadata defines which attributes the isolated loops with unsafe
6859memory dependencies will have. See
6860:ref:`Transformation Metadata <transformation-metadata>` for details.
6861
6862'``llvm.loop.distribute.followup_fallback``' Metadata
6863^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6864
6865If loop versioning is necessary, this metadata defined the attributes
6866the non-distributed fallback version will have. See
6867:ref:`Transformation Metadata <transformation-metadata>` for details.
6868
6869'``llvm.loop.distribute.followup_all``' Metadata
6870^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6871
6872The attributes in this metadata is added to all followup loops of the
6873loop distribution pass. See
6874:ref:`Transformation Metadata <transformation-metadata>` for details.
6875
6876'``llvm.licm.disable``' Metadata
6877^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6878
6879This metadata indicates that loop-invariant code motion (LICM) should not be
6880performed on this loop. The metadata has a single operand which is the string
6881``llvm.licm.disable``. For example:
6882
6883.. code-block:: llvm
6884
6885   !0 = !{!"llvm.licm.disable"}
6886
6887Note that although it operates per loop it isn't given the llvm.loop prefix
6888as it is not affected by the ``llvm.loop.disable_nonforced`` metadata.
6889
6890'``llvm.access.group``' Metadata
6891^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6892
6893``llvm.access.group`` metadata can be attached to any instruction that
6894potentially accesses memory. It can point to a single distinct metadata
6895node, which we call access group. This node represents all memory access
6896instructions referring to it via ``llvm.access.group``. When an
6897instruction belongs to multiple access groups, it can also point to a
6898list of accesses groups, illustrated by the following example.
6899
6900.. code-block:: llvm
6901
6902   %val = load i32, i32* %arrayidx, !llvm.access.group !0
6903   ...
6904   !0 = !{!1, !2}
6905   !1 = distinct !{}
6906   !2 = distinct !{}
6907
6908It is illegal for the list node to be empty since it might be confused
6909with an access group.
6910
6911The access group metadata node must be 'distinct' to avoid collapsing
6912multiple access groups by content. A access group metadata node must
6913always be empty which can be used to distinguish an access group
6914metadata node from a list of access groups. Being empty avoids the
6915situation that the content must be updated which, because metadata is
6916immutable by design, would required finding and updating all references
6917to the access group node.
6918
6919The access group can be used to refer to a memory access instruction
6920without pointing to it directly (which is not possible in global
6921metadata). Currently, the only metadata making use of it is
6922``llvm.loop.parallel_accesses``.
6923
6924'``llvm.loop.parallel_accesses``' Metadata
6925^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6926
6927The ``llvm.loop.parallel_accesses`` metadata refers to one or more
6928access group metadata nodes (see ``llvm.access.group``). It denotes that
6929no loop-carried memory dependence exist between it and other instructions
6930in the loop with this metadata.
6931
6932Let ``m1`` and ``m2`` be two instructions that both have the
6933``llvm.access.group`` metadata to the access group ``g1``, respectively
6934``g2`` (which might be identical). If a loop contains both access groups
6935in its ``llvm.loop.parallel_accesses`` metadata, then the compiler can
6936assume that there is no dependency between ``m1`` and ``m2`` carried by
6937this loop. Instructions that belong to multiple access groups are
6938considered having this property if at least one of the access groups
6939matches the ``llvm.loop.parallel_accesses`` list.
6940
6941If all memory-accessing instructions in a loop have
6942``llvm.access.group`` metadata that each refer to one of the access
6943groups of a loop's ``llvm.loop.parallel_accesses`` metadata, then the
6944loop has no loop carried memory dependences and is considered to be a
6945parallel loop.
6946
6947Note that if not all memory access instructions belong to an access
6948group referred to by ``llvm.loop.parallel_accesses``, then the loop must
6949not be considered trivially parallel. Additional
6950memory dependence analysis is required to make that determination. As a fail
6951safe mechanism, this causes loops that were originally parallel to be considered
6952sequential (if optimization passes that are unaware of the parallel semantics
6953insert new memory instructions into the loop body).
6954
6955Example of a loop that is considered parallel due to its correct use of
6956both ``llvm.access.group`` and ``llvm.loop.parallel_accesses``
6957metadata types.
6958
6959.. code-block:: llvm
6960
6961   for.body:
6962     ...
6963     %val0 = load i32, i32* %arrayidx, !llvm.access.group !1
6964     ...
6965     store i32 %val0, i32* %arrayidx1, !llvm.access.group !1
6966     ...
6967     br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
6968
6969   for.end:
6970   ...
6971   !0 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !1}}
6972   !1 = distinct !{}
6973
6974It is also possible to have nested parallel loops:
6975
6976.. code-block:: llvm
6977
6978   outer.for.body:
6979     ...
6980     %val1 = load i32, i32* %arrayidx3, !llvm.access.group !4
6981     ...
6982     br label %inner.for.body
6983
6984   inner.for.body:
6985     ...
6986     %val0 = load i32, i32* %arrayidx1, !llvm.access.group !3
6987     ...
6988     store i32 %val0, i32* %arrayidx2, !llvm.access.group !3
6989     ...
6990     br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1
6991
6992   inner.for.end:
6993     ...
6994     store i32 %val1, i32* %arrayidx4, !llvm.access.group !4
6995     ...
6996     br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2
6997
6998   outer.for.end:                                          ; preds = %for.body
6999   ...
7000   !1 = distinct !{!1, !{!"llvm.loop.parallel_accesses", !3}}     ; metadata for the inner loop
7001   !2 = distinct !{!2, !{!"llvm.loop.parallel_accesses", !3, !4}} ; metadata for the outer loop
7002   !3 = distinct !{} ; access group for instructions in the inner loop (which are implicitly contained in outer loop as well)
7003   !4 = distinct !{} ; access group for instructions in the outer, but not the inner loop
7004
7005.. _langref_llvm_loop_mustprogress:
7006
7007'``llvm.loop.mustprogress``' Metadata
7008^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7009
7010The ``llvm.loop.mustprogress`` metadata indicates that this loop is required to
7011terminate, unwind, or interact with the environment in an observable way e.g.
7012via a volatile memory access, I/O, or other synchronization. If such a loop is
7013not found to interact with the environment in an observable way, the loop may
7014be removed. This corresponds to the ``mustprogress`` function attribute.
7015
7016'``irr_loop``' Metadata
7017^^^^^^^^^^^^^^^^^^^^^^^
7018
7019``irr_loop`` metadata may be attached to the terminator instruction of a basic
7020block that's an irreducible loop header (note that an irreducible loop has more
7021than once header basic blocks.) If ``irr_loop`` metadata is attached to the
7022terminator instruction of a basic block that is not really an irreducible loop
7023header, the behavior is undefined. The intent of this metadata is to improve the
7024accuracy of the block frequency propagation. For example, in the code below, the
7025block ``header0`` may have a loop header weight (relative to the other headers of
7026the irreducible loop) of 100:
7027
7028.. code-block:: llvm
7029
7030    header0:
7031    ...
7032    br i1 %cmp, label %t1, label %t2, !irr_loop !0
7033
7034    ...
7035    !0 = !{"loop_header_weight", i64 100}
7036
7037Irreducible loop header weights are typically based on profile data.
7038
7039.. _md_invariant.group:
7040
7041'``invariant.group``' Metadata
7042^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7043
7044The experimental ``invariant.group`` metadata may be attached to
7045``load``/``store`` instructions referencing a single metadata with no entries.
7046The existence of the ``invariant.group`` metadata on the instruction tells
7047the optimizer that every ``load`` and ``store`` to the same pointer operand
7048can be assumed to load or store the same
7049value (but see the ``llvm.launder.invariant.group`` intrinsic which affects
7050when two pointers are considered the same). Pointers returned by bitcast or
7051getelementptr with only zero indices are considered the same.
7052
7053Examples:
7054
7055.. code-block:: llvm
7056
7057   @unknownPtr = external global i8
7058   ...
7059   %ptr = alloca i8
7060   store i8 42, i8* %ptr, !invariant.group !0
7061   call void @foo(i8* %ptr)
7062
7063   %a = load i8, i8* %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change
7064   call void @foo(i8* %ptr)
7065
7066   %newPtr = call i8* @getPointer(i8* %ptr)
7067   %c = load i8, i8* %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr
7068
7069   %unknownValue = load i8, i8* @unknownPtr
7070   store i8 %unknownValue, i8* %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42
7071
7072   call void @foo(i8* %ptr)
7073   %newPtr2 = call i8* @llvm.launder.invariant.group(i8* %ptr)
7074   %d = load i8, i8* %newPtr2, !invariant.group !0  ; Can't step through launder.invariant.group to get value of %ptr
7075
7076   ...
7077   declare void @foo(i8*)
7078   declare i8* @getPointer(i8*)
7079   declare i8* @llvm.launder.invariant.group(i8*)
7080
7081   !0 = !{}
7082
7083The invariant.group metadata must be dropped when replacing one pointer by
7084another based on aliasing information. This is because invariant.group is tied
7085to the SSA value of the pointer operand.
7086
7087.. code-block:: llvm
7088
7089  %v = load i8, i8* %x, !invariant.group !0
7090  ; if %x mustalias %y then we can replace the above instruction with
7091  %v = load i8, i8* %y
7092
7093Note that this is an experimental feature, which means that its semantics might
7094change in the future.
7095
7096'``type``' Metadata
7097^^^^^^^^^^^^^^^^^^^
7098
7099See :doc:`TypeMetadata`.
7100
7101'``associated``' Metadata
7102^^^^^^^^^^^^^^^^^^^^^^^^^
7103
7104The ``associated`` metadata may be attached to a global variable definition with
7105a single argument that references a global object (optionally through an alias).
7106
7107This metadata lowers to the ELF section flag ``SHF_LINK_ORDER`` which prevents
7108discarding of the global variable in linker GC unless the referenced object is
7109also discarded. The linker support for this feature is spotty. For best
7110compatibility, globals carrying this metadata should:
7111
7112- Be in ``@llvm.compiler.used``.
7113- If the referenced global variable is in a comdat, be in the same comdat.
7114
7115``!associated`` can not express many-to-one relationship. A global variable with
7116the metadata should generally not be referenced by a function: the function may
7117be inlined into other functions, leading to more references to the metadata.
7118Ideally we would want to keep metadata alive as long as any inline location is
7119alive, but this many-to-one relationship is not representable. Moreover, if the
7120metadata is retained while the function is discarded, the linker will report an
7121error of a relocation referencing a discarded section.
7122
7123The metadata is often used with an explicit section consisting of valid C
7124identifiers so that the runtime can find the metadata section with
7125linker-defined encapsulation symbols ``__start_<section_name>`` and
7126``__stop_<section_name>``.
7127
7128It does not have any effect on non-ELF targets.
7129
7130Example:
7131
7132.. code-block:: text
7133
7134    $a = comdat any
7135    @a = global i32 1, comdat $a
7136    @b = internal global i32 2, comdat $a, section "abc", !associated !0
7137    !0 = !{i32* @a}
7138
7139
7140'``prof``' Metadata
7141^^^^^^^^^^^^^^^^^^^
7142
7143The ``prof`` metadata is used to record profile data in the IR.
7144The first operand of the metadata node indicates the profile metadata
7145type. There are currently 3 types:
7146:ref:`branch_weights<prof_node_branch_weights>`,
7147:ref:`function_entry_count<prof_node_function_entry_count>`, and
7148:ref:`VP<prof_node_VP>`.
7149
7150.. _prof_node_branch_weights:
7151
7152branch_weights
7153""""""""""""""
7154
7155Branch weight metadata attached to a branch, select, switch or call instruction
7156represents the likeliness of the associated branch being taken.
7157For more information, see :doc:`BranchWeightMetadata`.
7158
7159.. _prof_node_function_entry_count:
7160
7161function_entry_count
7162""""""""""""""""""""
7163
7164Function entry count metadata can be attached to function definitions
7165to record the number of times the function is called. Used with BFI
7166information, it is also used to derive the basic block profile count.
7167For more information, see :doc:`BranchWeightMetadata`.
7168
7169.. _prof_node_VP:
7170
7171VP
7172""
7173
7174VP (value profile) metadata can be attached to instructions that have
7175value profile information. Currently this is indirect calls (where it
7176records the hottest callees) and calls to memory intrinsics such as memcpy,
7177memmove, and memset (where it records the hottest byte lengths).
7178
7179Each VP metadata node contains "VP" string, then a uint32_t value for the value
7180profiling kind, a uint64_t value for the total number of times the instruction
7181is executed, followed by uint64_t value and execution count pairs.
7182The value profiling kind is 0 for indirect call targets and 1 for memory
7183operations. For indirect call targets, each profile value is a hash
7184of the callee function name, and for memory operations each value is the
7185byte length.
7186
7187Note that the value counts do not need to add up to the total count
7188listed in the third operand (in practice only the top hottest values
7189are tracked and reported).
7190
7191Indirect call example:
7192
7193.. code-block:: llvm
7194
7195    call void %f(), !prof !1
7196    !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410}
7197
7198Note that the VP type is 0 (the second operand), which indicates this is
7199an indirect call value profile data. The third operand indicates that the
7200indirect call executed 1600 times. The 4th and 6th operands give the
7201hashes of the 2 hottest target functions' names (this is the same hash used
7202to represent function names in the profile database), and the 5th and 7th
7203operands give the execution count that each of the respective prior target
7204functions was called.
7205
7206.. _md_annotation:
7207
7208'``annotation``' Metadata
7209^^^^^^^^^^^^^^^^^^^^^^^^^
7210
7211The ``annotation`` metadata can be used to attach a tuple of annotation strings
7212to any instruction. This metadata does not impact the semantics of the program
7213and may only be used to provide additional insight about the program and
7214transformations to users.
7215
7216Example:
7217
7218.. code-block:: text
7219
7220    %a.addr = alloca float*, align 8, !annotation !0
7221    !0 = !{!"auto-init"}
7222
7223'``func_sanitize``' Metadata
7224^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7225
7226The ``func_sanitize`` metadata is used to attach two values for the function
7227sanitizer instrumentation. The first value is the ubsan function signature.
7228The second value is the address of the proxy variable which stores the address
7229of the RTTI descriptor. If :ref:`prologue <prologuedata>` and '``func_sanitize``'
7230are used at the same time, :ref:`prologue <prologuedata>` is emitted before
7231'``func_sanitize``' in the output.
7232
7233Example:
7234
7235.. code-block:: text
7236
7237    @__llvm_rtti_proxy = private unnamed_addr constant i8* bitcast ({ i8*, i8* }* @_ZTIFvvE to i8*)
7238    define void @_Z3funv() !func_sanitize !0 {
7239      return void
7240    }
7241    !0 = !{i32 846595819, i8** @__llvm_rtti_proxy}
7242
7243Module Flags Metadata
7244=====================
7245
7246Information about the module as a whole is difficult to convey to LLVM's
7247subsystems. The LLVM IR isn't sufficient to transmit this information.
7248The ``llvm.module.flags`` named metadata exists in order to facilitate
7249this. These flags are in the form of key / value pairs --- much like a
7250dictionary --- making it easy for any subsystem who cares about a flag to
7251look it up.
7252
7253The ``llvm.module.flags`` metadata contains a list of metadata triplets.
7254Each triplet has the following form:
7255
7256-  The first element is a *behavior* flag, which specifies the behavior
7257   when two (or more) modules are merged together, and it encounters two
7258   (or more) metadata with the same ID. The supported behaviors are
7259   described below.
7260-  The second element is a metadata string that is a unique ID for the
7261   metadata. Each module may only have one flag entry for each unique ID (not
7262   including entries with the **Require** behavior).
7263-  The third element is the value of the flag.
7264
7265When two (or more) modules are merged together, the resulting
7266``llvm.module.flags`` metadata is the union of the modules' flags. That is, for
7267each unique metadata ID string, there will be exactly one entry in the merged
7268modules ``llvm.module.flags`` metadata table, and the value for that entry will
7269be determined by the merge behavior flag, as described below. The only exception
7270is that entries with the *Require* behavior are always preserved.
7271
7272The following behaviors are supported:
7273
7274.. list-table::
7275   :header-rows: 1
7276   :widths: 10 90
7277
7278   * - Value
7279     - Behavior
7280
7281   * - 1
7282     - **Error**
7283           Emits an error if two values disagree, otherwise the resulting value
7284           is that of the operands.
7285
7286   * - 2
7287     - **Warning**
7288           Emits a warning if two values disagree. The result value will be the
7289           operand for the flag from the first module being linked, or the max
7290           if the other module uses **Max** (in which case the resulting flag
7291           will be **Max**).
7292
7293   * - 3
7294     - **Require**
7295           Adds a requirement that another module flag be present and have a
7296           specified value after linking is performed. The value must be a
7297           metadata pair, where the first element of the pair is the ID of the
7298           module flag to be restricted, and the second element of the pair is
7299           the value the module flag should be restricted to. This behavior can
7300           be used to restrict the allowable results (via triggering of an
7301           error) of linking IDs with the **Override** behavior.
7302
7303   * - 4
7304     - **Override**
7305           Uses the specified value, regardless of the behavior or value of the
7306           other module. If both modules specify **Override**, but the values
7307           differ, an error will be emitted.
7308
7309   * - 5
7310     - **Append**
7311           Appends the two values, which are required to be metadata nodes.
7312
7313   * - 6
7314     - **AppendUnique**
7315           Appends the two values, which are required to be metadata
7316           nodes. However, duplicate entries in the second list are dropped
7317           during the append operation.
7318
7319   * - 7
7320     - **Max**
7321           Takes the max of the two values, which are required to be integers.
7322
7323It is an error for a particular unique flag ID to have multiple behaviors,
7324except in the case of **Require** (which adds restrictions on another metadata
7325value) or **Override**.
7326
7327An example of module flags:
7328
7329.. code-block:: llvm
7330
7331    !0 = !{ i32 1, !"foo", i32 1 }
7332    !1 = !{ i32 4, !"bar", i32 37 }
7333    !2 = !{ i32 2, !"qux", i32 42 }
7334    !3 = !{ i32 3, !"qux",
7335      !{
7336        !"foo", i32 1
7337      }
7338    }
7339    !llvm.module.flags = !{ !0, !1, !2, !3 }
7340
7341-  Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior
7342   if two or more ``!"foo"`` flags are seen is to emit an error if their
7343   values are not equal.
7344
7345-  Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The
7346   behavior if two or more ``!"bar"`` flags are seen is to use the value
7347   '37'.
7348
7349-  Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The
7350   behavior if two or more ``!"qux"`` flags are seen is to emit a
7351   warning if their values are not equal.
7352
7353-  Metadata ``!3`` has the ID ``!"qux"`` and the value:
7354
7355   ::
7356
7357       !{ !"foo", i32 1 }
7358
7359   The behavior is to emit an error if the ``llvm.module.flags`` does not
7360   contain a flag with the ID ``!"foo"`` that has the value '1' after linking is
7361   performed.
7362
7363Synthesized Functions Module Flags Metadata
7364-------------------------------------------
7365
7366These metadata specify the default attributes synthesized functions should have.
7367These metadata are currently respected by a few instrumentation passes, such as
7368sanitizers.
7369
7370These metadata correspond to a few function attributes with significant code
7371generation behaviors. Function attributes with just optimization purposes
7372should not be listed because the performance impact of these synthesized
7373functions is small.
7374
7375- "frame-pointer": **Max**. The value can be 0, 1, or 2. A synthesized function
7376  will get the "frame-pointer" function attribute, with value being "none",
7377  "non-leaf", or "all", respectively.
7378- "function_return_thunk_extern": The synthesized function will get the
7379  ``fn_return_thunk_extern`` function attribute.
7380- "uwtable": **Max**. The value can be 0, 1, or 2. If the value is 1, a synthesized
7381  function will get the ``uwtable(sync)`` function attribute, if the value is 2,
7382  a synthesized function will get the ``uwtable(async)`` function attribute.
7383
7384Objective-C Garbage Collection Module Flags Metadata
7385----------------------------------------------------
7386
7387On the Mach-O platform, Objective-C stores metadata about garbage
7388collection in a special section called "image info". The metadata
7389consists of a version number and a bitmask specifying what types of
7390garbage collection are supported (if any) by the file. If two or more
7391modules are linked together their garbage collection metadata needs to
7392be merged rather than appended together.
7393
7394The Objective-C garbage collection module flags metadata consists of the
7395following key-value pairs:
7396
7397.. list-table::
7398   :header-rows: 1
7399   :widths: 30 70
7400
7401   * - Key
7402     - Value
7403
7404   * - ``Objective-C Version``
7405     - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2.
7406
7407   * - ``Objective-C Image Info Version``
7408     - **[Required]** --- The version of the image info section. Currently
7409       always 0.
7410
7411   * - ``Objective-C Image Info Section``
7412     - **[Required]** --- The section to place the metadata. Valid values are
7413       ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and
7414       ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for
7415       Objective-C ABI version 2.
7416
7417   * - ``Objective-C Garbage Collection``
7418     - **[Required]** --- Specifies whether garbage collection is supported or
7419       not. Valid values are 0, for no garbage collection, and 2, for garbage
7420       collection supported.
7421
7422   * - ``Objective-C GC Only``
7423     - **[Optional]** --- Specifies that only garbage collection is supported.
7424       If present, its value must be 6. This flag requires that the
7425       ``Objective-C Garbage Collection`` flag have the value 2.
7426
7427Some important flag interactions:
7428
7429-  If a module with ``Objective-C Garbage Collection`` set to 0 is
7430   merged with a module with ``Objective-C Garbage Collection`` set to
7431   2, then the resulting module has the
7432   ``Objective-C Garbage Collection`` flag set to 0.
7433-  A module with ``Objective-C Garbage Collection`` set to 0 cannot be
7434   merged with a module with ``Objective-C GC Only`` set to 6.
7435
7436C type width Module Flags Metadata
7437----------------------------------
7438
7439The ARM backend emits a section into each generated object file describing the
7440options that it was compiled with (in a compiler-independent way) to prevent
7441linking incompatible objects, and to allow automatic library selection. Some
7442of these options are not visible at the IR level, namely wchar_t width and enum
7443width.
7444
7445To pass this information to the backend, these options are encoded in module
7446flags metadata, using the following key-value pairs:
7447
7448.. list-table::
7449   :header-rows: 1
7450   :widths: 30 70
7451
7452   * - Key
7453     - Value
7454
7455   * - short_wchar
7456     - * 0 --- sizeof(wchar_t) == 4
7457       * 1 --- sizeof(wchar_t) == 2
7458
7459   * - short_enum
7460     - * 0 --- Enums are at least as large as an ``int``.
7461       * 1 --- Enums are stored in the smallest integer type which can
7462         represent all of its values.
7463
7464For example, the following metadata section specifies that the module was
7465compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an
7466enum is the smallest type which can represent all of its values::
7467
7468    !llvm.module.flags = !{!0, !1}
7469    !0 = !{i32 1, !"short_wchar", i32 1}
7470    !1 = !{i32 1, !"short_enum", i32 0}
7471
7472LTO Post-Link Module Flags Metadata
7473-----------------------------------
7474
7475Some optimisations are only when the entire LTO unit is present in the current
7476module. This is represented by the ``LTOPostLink`` module flags metadata, which
7477will be created with a value of ``1`` when LTO linking occurs.
7478
7479Embedded Objects Names Metadata
7480===============================
7481
7482Offloading compilations need to embed device code into the host section table to
7483create a fat binary. This metadata node references each global that will be
7484embedded in the module. The primary use for this is to make referencing these
7485globals more efficient in the IR. The metadata references nodes containing
7486pointers to the global to be embedded followed by the section name it will be
7487stored at::
7488
7489    !llvm.embedded.objects = !{!0}
7490    !0 = !{ptr @object, !".section"}
7491
7492Automatic Linker Flags Named Metadata
7493=====================================
7494
7495Some targets support embedding of flags to the linker inside individual object
7496files. Typically this is used in conjunction with language extensions which
7497allow source files to contain linker command line options, and have these
7498automatically be transmitted to the linker via object files.
7499
7500These flags are encoded in the IR using named metadata with the name
7501``!llvm.linker.options``. Each operand is expected to be a metadata node
7502which should be a list of other metadata nodes, each of which should be a
7503list of metadata strings defining linker options.
7504
7505For example, the following metadata section specifies two separate sets of
7506linker options, presumably to link against ``libz`` and the ``Cocoa``
7507framework::
7508
7509    !0 = !{ !"-lz" }
7510    !1 = !{ !"-framework", !"Cocoa" }
7511    !llvm.linker.options = !{ !0, !1 }
7512
7513The metadata encoding as lists of lists of options, as opposed to a collapsed
7514list of options, is chosen so that the IR encoding can use multiple option
7515strings to specify e.g., a single library, while still having that specifier be
7516preserved as an atomic element that can be recognized by a target specific
7517assembly writer or object file emitter.
7518
7519Each individual option is required to be either a valid option for the target's
7520linker, or an option that is reserved by the target specific assembly writer or
7521object file emitter. No other aspect of these options is defined by the IR.
7522
7523Dependent Libs Named Metadata
7524=============================
7525
7526Some targets support embedding of strings into object files to indicate
7527a set of libraries to add to the link. Typically this is used in conjunction
7528with language extensions which allow source files to explicitly declare the
7529libraries they depend on, and have these automatically be transmitted to the
7530linker via object files.
7531
7532The list is encoded in the IR using named metadata with the name
7533``!llvm.dependent-libraries``. Each operand is expected to be a metadata node
7534which should contain a single string operand.
7535
7536For example, the following metadata section contains two library specifiers::
7537
7538    !0 = !{!"a library specifier"}
7539    !1 = !{!"another library specifier"}
7540    !llvm.dependent-libraries = !{ !0, !1 }
7541
7542Each library specifier will be handled independently by the consuming linker.
7543The effect of the library specifiers are defined by the consuming linker.
7544
7545.. _summary:
7546
7547ThinLTO Summary
7548===============
7549
7550Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_
7551causes the building of a compact summary of the module that is emitted into
7552the bitcode. The summary is emitted into the LLVM assembly and identified
7553in syntax by a caret ('``^``').
7554
7555The summary is parsed into a bitcode output, along with the Module
7556IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes
7557of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the
7558summary entries (just as they currently ignore summary entries in a bitcode
7559input file).
7560
7561Eventually, the summary will be parsed into a ModuleSummaryIndex object under
7562the same conditions where summary index is currently built from bitcode.
7563Specifically, tools that test the Thin Link portion of a ThinLTO compile
7564(i.e. llvm-lto and llvm-lto2), or when parsing a combined index
7565for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag
7566(this part is not yet implemented, use llvm-as to create a bitcode object
7567before feeding into thin link tools for now).
7568
7569There are currently 3 types of summary entries in the LLVM assembly:
7570:ref:`module paths<module_path_summary>`,
7571:ref:`global values<gv_summary>`, and
7572:ref:`type identifiers<typeid_summary>`.
7573
7574.. _module_path_summary:
7575
7576Module Path Summary Entry
7577-------------------------
7578
7579Each module path summary entry lists a module containing global values included
7580in the summary. For a single IR module there will be one such entry, but
7581in a combined summary index produced during the thin link, there will be
7582one module path entry per linked module with summary.
7583
7584Example:
7585
7586.. code-block:: text
7587
7588    ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418))
7589
7590The ``path`` field is a string path to the bitcode file, and the ``hash``
7591field is the 160-bit SHA-1 hash of the IR bitcode contents, used for
7592incremental builds and caching.
7593
7594.. _gv_summary:
7595
7596Global Value Summary Entry
7597--------------------------
7598
7599Each global value summary entry corresponds to a global value defined or
7600referenced by a summarized module.
7601
7602Example:
7603
7604.. code-block:: text
7605
7606    ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831
7607
7608For declarations, there will not be a summary list. For definitions, a
7609global value will contain a list of summaries, one per module containing
7610a definition. There can be multiple entries in a combined summary index
7611for symbols with weak linkage.
7612
7613Each ``Summary`` format will depend on whether the global value is a
7614:ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or
7615:ref:`alias<alias_summary>`.
7616
7617.. _function_summary:
7618
7619Function Summary
7620^^^^^^^^^^^^^^^^
7621
7622If the global value is a function, the ``Summary`` entry will look like:
7623
7624.. code-block:: text
7625
7626    function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Params]?[, Refs]?
7627
7628The ``module`` field includes the summary entry id for the module containing
7629this definition, and the ``flags`` field contains information such as
7630the linkage type, a flag indicating whether it is legal to import the
7631definition, whether it is globally live and whether the linker resolved it
7632to a local definition (the latter two are populated during the thin link).
7633The ``insts`` field contains the number of IR instructions in the function.
7634Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`,
7635:ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`,
7636:ref:`Params<params_summary>`, :ref:`Refs<refs_summary>`.
7637
7638.. _variable_summary:
7639
7640Global Variable Summary
7641^^^^^^^^^^^^^^^^^^^^^^^
7642
7643If the global value is a variable, the ``Summary`` entry will look like:
7644
7645.. code-block:: text
7646
7647    variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]?
7648
7649The variable entry contains a subset of the fields in a
7650:ref:`function summary <function_summary>`, see the descriptions there.
7651
7652.. _alias_summary:
7653
7654Alias Summary
7655^^^^^^^^^^^^^
7656
7657If the global value is an alias, the ``Summary`` entry will look like:
7658
7659.. code-block:: text
7660
7661    alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2)
7662
7663The ``module`` and ``flags`` fields are as described for a
7664:ref:`function summary <function_summary>`. The ``aliasee`` field
7665contains a reference to the global value summary entry of the aliasee.
7666
7667.. _funcflags_summary:
7668
7669Function Flags
7670^^^^^^^^^^^^^^
7671
7672The optional ``FuncFlags`` field looks like:
7673
7674.. code-block:: text
7675
7676    funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0, noUnwind: 1, mayThrow: 0, hasUnknownCall: 0)
7677
7678If unspecified, flags are assumed to hold the conservative ``false`` value of
7679``0``.
7680
7681.. _calls_summary:
7682
7683Calls
7684^^^^^
7685
7686The optional ``Calls`` field looks like:
7687
7688.. code-block:: text
7689
7690    calls: ((Callee)[, (Callee)]*)
7691
7692where each ``Callee`` looks like:
7693
7694.. code-block:: text
7695
7696    callee: ^1[, hotness: None]?[, relbf: 0]?
7697
7698The ``callee`` refers to the summary entry id of the callee. At most one
7699of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``,
7700``Hot``, and ``Critical``), and ``relbf`` (which holds the integer
7701branch frequency relative to the entry frequency, scaled down by 2^8)
7702may be specified. The defaults are ``Unknown`` and ``0``, respectively.
7703
7704.. _params_summary:
7705
7706Params
7707^^^^^^
7708
7709The optional ``Params`` is used by ``StackSafety`` and looks like:
7710
7711.. code-block:: text
7712
7713    Params: ((Param)[, (Param)]*)
7714
7715where each ``Param`` describes pointer parameter access inside of the
7716function and looks like:
7717
7718.. code-block:: text
7719
7720    param: 4, offset: [0, 5][, calls: ((Callee)[, (Callee)]*)]?
7721
7722where the first ``param`` is the number of the parameter it describes,
7723``offset`` is the inclusive range of offsets from the pointer parameter to bytes
7724which can be accessed by the function. This range does not include accesses by
7725function calls from ``calls`` list.
7726
7727where each ``Callee`` describes how parameter is forwarded into other
7728functions and looks like:
7729
7730.. code-block:: text
7731
7732    callee: ^3, param: 5, offset: [-3, 3]
7733
7734The ``callee`` refers to the summary entry id of the callee,  ``param`` is
7735the number of the callee parameter which points into the callers parameter
7736with offset known to be inside of the ``offset`` range. ``calls`` will be
7737consumed and removed by thin link stage to update ``Param::offset`` so it
7738covers all accesses possible by ``calls``.
7739
7740Pointer parameter without corresponding ``Param`` is considered unsafe and we
7741assume that access with any offset is possible.
7742
7743Example:
7744
7745If we have the following function:
7746
7747.. code-block:: text
7748
7749    define i64 @foo(i64* %0, i32* %1, i8* %2, i8 %3) {
7750      store i32* %1, i32** @x
7751      %5 = getelementptr inbounds i8, i8* %2, i64 5
7752      %6 = load i8, i8* %5
7753      %7 = getelementptr inbounds i8, i8* %2, i8 %3
7754      tail call void @bar(i8 %3, i8* %7)
7755      %8 = load i64, i64* %0
7756      ret i64 %8
7757    }
7758
7759We can expect the record like this:
7760
7761.. code-block:: text
7762
7763    params: ((param: 0, offset: [0, 7]),(param: 2, offset: [5, 5], calls: ((callee: ^3, param: 1, offset: [-128, 127]))))
7764
7765The function may access just 8 bytes of the parameter %0 . ``calls`` is empty,
7766so the parameter is either not used for function calls or ``offset`` already
7767covers all accesses from nested function calls.
7768Parameter %1 escapes, so access is unknown.
7769The function itself can access just a single byte of the parameter %2. Additional
7770access is possible inside of the ``@bar`` or ``^3``. The function adds signed
7771offset to the pointer and passes the result as the argument %1 into ``^3``.
7772This record itself does not tell us how ``^3`` will access the parameter.
7773Parameter %3 is not a pointer.
7774
7775.. _refs_summary:
7776
7777Refs
7778^^^^
7779
7780The optional ``Refs`` field looks like:
7781
7782.. code-block:: text
7783
7784    refs: ((Ref)[, (Ref)]*)
7785
7786where each ``Ref`` contains a reference to the summary id of the referenced
7787value (e.g. ``^1``).
7788
7789.. _typeidinfo_summary:
7790
7791TypeIdInfo
7792^^^^^^^^^^
7793
7794The optional ``TypeIdInfo`` field, used for
7795`Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
7796looks like:
7797
7798.. code-block:: text
7799
7800    typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]?
7801
7802These optional fields have the following forms:
7803
7804TypeTests
7805"""""""""
7806
7807.. code-block:: text
7808
7809    typeTests: (TypeIdRef[, TypeIdRef]*)
7810
7811Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
7812by summary id or ``GUID``.
7813
7814TypeTestAssumeVCalls
7815""""""""""""""""""""
7816
7817.. code-block:: text
7818
7819    typeTestAssumeVCalls: (VFuncId[, VFuncId]*)
7820
7821Where each VFuncId has the format:
7822
7823.. code-block:: text
7824
7825    vFuncId: (TypeIdRef, offset: 16)
7826
7827Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
7828by summary id or ``GUID`` preceded by a ``guid:`` tag.
7829
7830TypeCheckedLoadVCalls
7831"""""""""""""""""""""
7832
7833.. code-block:: text
7834
7835    typeCheckedLoadVCalls: (VFuncId[, VFuncId]*)
7836
7837Where each VFuncId has the format described for ``TypeTestAssumeVCalls``.
7838
7839TypeTestAssumeConstVCalls
7840"""""""""""""""""""""""""
7841
7842.. code-block:: text
7843
7844    typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*)
7845
7846Where each ConstVCall has the format:
7847
7848.. code-block:: text
7849
7850    (VFuncId, args: (Arg[, Arg]*))
7851
7852and where each VFuncId has the format described for ``TypeTestAssumeVCalls``,
7853and each Arg is an integer argument number.
7854
7855TypeCheckedLoadConstVCalls
7856""""""""""""""""""""""""""
7857
7858.. code-block:: text
7859
7860    typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*)
7861
7862Where each ConstVCall has the format described for
7863``TypeTestAssumeConstVCalls``.
7864
7865.. _typeid_summary:
7866
7867Type ID Summary Entry
7868---------------------
7869
7870Each type id summary entry corresponds to a type identifier resolution
7871which is generated during the LTO link portion of the compile when building
7872with `Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
7873so these are only present in a combined summary index.
7874
7875Example:
7876
7877.. code-block:: text
7878
7879    ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778
7880
7881The ``typeTestRes`` gives the type test resolution ``kind`` (which may
7882be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and
7883the ``size-1`` bit width. It is followed by optional flags, which default to 0,
7884and an optional WpdResolutions (whole program devirtualization resolution)
7885field that looks like:
7886
7887.. code-block:: text
7888
7889    wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]*
7890
7891where each entry is a mapping from the given byte offset to the whole-program
7892devirtualization resolution WpdRes, that has one of the following formats:
7893
7894.. code-block:: text
7895
7896    wpdRes: (kind: branchFunnel)
7897    wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi")
7898    wpdRes: (kind: indir)
7899
7900Additionally, each wpdRes has an optional ``resByArg`` field, which
7901describes the resolutions for calls with all constant integer arguments:
7902
7903.. code-block:: text
7904
7905    resByArg: (ResByArg[, ResByArg]*)
7906
7907where ResByArg is:
7908
7909.. code-block:: text
7910
7911    args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0])
7912
7913Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal``
7914or ``VirtualConstProp``. The ``info`` field is only used if the kind
7915is ``UniformRetVal`` (indicates the uniform return value), or
7916``UniqueRetVal`` (holds the return value associated with the unique vtable
7917(0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does
7918not support the use of absolute symbols to store constants.
7919
7920.. _intrinsicglobalvariables:
7921
7922Intrinsic Global Variables
7923==========================
7924
7925LLVM has a number of "magic" global variables that contain data that
7926affect code generation or other IR semantics. These are documented here.
7927All globals of this sort should have a section specified as
7928"``llvm.metadata``". This section and all globals that start with
7929"``llvm.``" are reserved for use by LLVM.
7930
7931.. _gv_llvmused:
7932
7933The '``llvm.used``' Global Variable
7934-----------------------------------
7935
7936The ``@llvm.used`` global is an array which has
7937:ref:`appending linkage <linkage_appending>`. This array contains a list of
7938pointers to named global variables, functions and aliases which may optionally
7939have a pointer cast formed of bitcast or getelementptr. For example, a legal
7940use of it is:
7941
7942.. code-block:: llvm
7943
7944    @X = global i8 4
7945    @Y = global i32 123
7946
7947    @llvm.used = appending global [2 x i8*] [
7948       i8* @X,
7949       i8* bitcast (i32* @Y to i8*)
7950    ], section "llvm.metadata"
7951
7952If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler,
7953and linker are required to treat the symbol as if there is a reference to the
7954symbol that it cannot see (which is why they have to be named). For example, if
7955a variable has internal linkage and no references other than that from the
7956``@llvm.used`` list, it cannot be deleted. This is commonly used to represent
7957references from inline asms and other things the compiler cannot "see", and
7958corresponds to "``attribute((used))``" in GNU C.
7959
7960On some targets, the code generator must emit a directive to the
7961assembler or object file to prevent the assembler and linker from
7962removing the symbol.
7963
7964.. _gv_llvmcompilerused:
7965
7966The '``llvm.compiler.used``' Global Variable
7967--------------------------------------------
7968
7969The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used``
7970directive, except that it only prevents the compiler from touching the
7971symbol. On targets that support it, this allows an intelligent linker to
7972optimize references to the symbol without being impeded as it would be
7973by ``@llvm.used``.
7974
7975This is a rare construct that should only be used in rare circumstances,
7976and should not be exposed to source languages.
7977
7978.. _gv_llvmglobalctors:
7979
7980The '``llvm.global_ctors``' Global Variable
7981-------------------------------------------
7982
7983.. code-block:: llvm
7984
7985    %0 = type { i32, void ()*, i8* }
7986    @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }]
7987
7988The ``@llvm.global_ctors`` array contains a list of constructor
7989functions, priorities, and an associated global or function.
7990The functions referenced by this array will be called in ascending order
7991of priority (i.e. lowest first) when the module is loaded. The order of
7992functions with the same priority is not defined.
7993
7994If the third field is non-null, and points to a global variable
7995or function, the initializer function will only run if the associated
7996data from the current module is not discarded.
7997On ELF the referenced global variable or function must be in a comdat.
7998
7999.. _llvmglobaldtors:
8000
8001The '``llvm.global_dtors``' Global Variable
8002-------------------------------------------
8003
8004.. code-block:: llvm
8005
8006    %0 = type { i32, void ()*, i8* }
8007    @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }]
8008
8009The ``@llvm.global_dtors`` array contains a list of destructor
8010functions, priorities, and an associated global or function.
8011The functions referenced by this array will be called in descending
8012order of priority (i.e. highest first) when the module is unloaded. The
8013order of functions with the same priority is not defined.
8014
8015If the third field is non-null, and points to a global variable
8016or function, the destructor function will only run if the associated
8017data from the current module is not discarded.
8018On ELF the referenced global variable or function must be in a comdat.
8019
8020Instruction Reference
8021=====================
8022
8023The LLVM instruction set consists of several different classifications
8024of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
8025instructions <binaryops>`, :ref:`bitwise binary
8026instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
8027:ref:`other instructions <otherops>`.
8028
8029.. _terminators:
8030
8031Terminator Instructions
8032-----------------------
8033
8034As mentioned :ref:`previously <functionstructure>`, every basic block in a
8035program ends with a "Terminator" instruction, which indicates which
8036block should be executed after the current block is finished. These
8037terminator instructions typically yield a '``void``' value: they produce
8038control flow, not values (the one exception being the
8039':ref:`invoke <i_invoke>`' instruction).
8040
8041The terminator instructions are: ':ref:`ret <i_ret>`',
8042':ref:`br <i_br>`', ':ref:`switch <i_switch>`',
8043':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`',
8044':ref:`callbr <i_callbr>`'
8045':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`',
8046':ref:`catchret <i_catchret>`',
8047':ref:`cleanupret <i_cleanupret>`',
8048and ':ref:`unreachable <i_unreachable>`'.
8049
8050.. _i_ret:
8051
8052'``ret``' Instruction
8053^^^^^^^^^^^^^^^^^^^^^
8054
8055Syntax:
8056"""""""
8057
8058::
8059
8060      ret <type> <value>       ; Return a value from a non-void function
8061      ret void                 ; Return from void function
8062
8063Overview:
8064"""""""""
8065
8066The '``ret``' instruction is used to return control flow (and optionally
8067a value) from a function back to the caller.
8068
8069There are two forms of the '``ret``' instruction: one that returns a
8070value and then causes control flow, and one that just causes control
8071flow to occur.
8072
8073Arguments:
8074""""""""""
8075
8076The '``ret``' instruction optionally accepts a single argument, the
8077return value. The type of the return value must be a ':ref:`first
8078class <t_firstclass>`' type.
8079
8080A function is not :ref:`well formed <wellformed>` if it has a non-void
8081return type and contains a '``ret``' instruction with no return value or
8082a return value with a type that does not match its type, or if it has a
8083void return type and contains a '``ret``' instruction with a return
8084value.
8085
8086Semantics:
8087""""""""""
8088
8089When the '``ret``' instruction is executed, control flow returns back to
8090the calling function's context. If the caller is a
8091":ref:`call <i_call>`" instruction, execution continues at the
8092instruction after the call. If the caller was an
8093":ref:`invoke <i_invoke>`" instruction, execution continues at the
8094beginning of the "normal" destination block. If the instruction returns
8095a value, that value shall set the call or invoke instruction's return
8096value.
8097
8098Example:
8099""""""""
8100
8101.. code-block:: llvm
8102
8103      ret i32 5                       ; Return an integer value of 5
8104      ret void                        ; Return from a void function
8105      ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2
8106
8107.. _i_br:
8108
8109'``br``' Instruction
8110^^^^^^^^^^^^^^^^^^^^
8111
8112Syntax:
8113"""""""
8114
8115::
8116
8117      br i1 <cond>, label <iftrue>, label <iffalse>
8118      br label <dest>          ; Unconditional branch
8119
8120Overview:
8121"""""""""
8122
8123The '``br``' instruction is used to cause control flow to transfer to a
8124different basic block in the current function. There are two forms of
8125this instruction, corresponding to a conditional branch and an
8126unconditional branch.
8127
8128Arguments:
8129""""""""""
8130
8131The conditional branch form of the '``br``' instruction takes a single
8132'``i1``' value and two '``label``' values. The unconditional form of the
8133'``br``' instruction takes a single '``label``' value as a target.
8134
8135Semantics:
8136""""""""""
8137
8138Upon execution of a conditional '``br``' instruction, the '``i1``'
8139argument is evaluated. If the value is ``true``, control flows to the
8140'``iftrue``' ``label`` argument. If "cond" is ``false``, control flows
8141to the '``iffalse``' ``label`` argument.
8142If '``cond``' is ``poison`` or ``undef``, this instruction has undefined
8143behavior.
8144
8145Example:
8146""""""""
8147
8148.. code-block:: llvm
8149
8150    Test:
8151      %cond = icmp eq i32 %a, %b
8152      br i1 %cond, label %IfEqual, label %IfUnequal
8153    IfEqual:
8154      ret i32 1
8155    IfUnequal:
8156      ret i32 0
8157
8158.. _i_switch:
8159
8160'``switch``' Instruction
8161^^^^^^^^^^^^^^^^^^^^^^^^
8162
8163Syntax:
8164"""""""
8165
8166::
8167
8168      switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
8169
8170Overview:
8171"""""""""
8172
8173The '``switch``' instruction is used to transfer control flow to one of
8174several different places. It is a generalization of the '``br``'
8175instruction, allowing a branch to occur to one of many possible
8176destinations.
8177
8178Arguments:
8179""""""""""
8180
8181The '``switch``' instruction uses three parameters: an integer
8182comparison value '``value``', a default '``label``' destination, and an
8183array of pairs of comparison value constants and '``label``'s. The table
8184is not allowed to contain duplicate constant entries.
8185
8186Semantics:
8187""""""""""
8188
8189The ``switch`` instruction specifies a table of values and destinations.
8190When the '``switch``' instruction is executed, this table is searched
8191for the given value. If the value is found, control flow is transferred
8192to the corresponding destination; otherwise, control flow is transferred
8193to the default destination.
8194If '``value``' is ``poison`` or ``undef``, this instruction has undefined
8195behavior.
8196
8197Implementation:
8198"""""""""""""""
8199
8200Depending on properties of the target machine and the particular
8201``switch`` instruction, this instruction may be code generated in
8202different ways. For example, it could be generated as a series of
8203chained conditional branches or with a lookup table.
8204
8205Example:
8206""""""""
8207
8208.. code-block:: llvm
8209
8210     ; Emulate a conditional br instruction
8211     %Val = zext i1 %value to i32
8212     switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
8213
8214     ; Emulate an unconditional br instruction
8215     switch i32 0, label %dest [ ]
8216
8217     ; Implement a jump table:
8218     switch i32 %val, label %otherwise [ i32 0, label %onzero
8219                                         i32 1, label %onone
8220                                         i32 2, label %ontwo ]
8221
8222.. _i_indirectbr:
8223
8224'``indirectbr``' Instruction
8225^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8226
8227Syntax:
8228"""""""
8229
8230::
8231
8232      indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ]
8233
8234Overview:
8235"""""""""
8236
8237The '``indirectbr``' instruction implements an indirect branch to a
8238label within the current function, whose address is specified by
8239"``address``". Address must be derived from a
8240:ref:`blockaddress <blockaddress>` constant.
8241
8242Arguments:
8243""""""""""
8244
8245The '``address``' argument is the address of the label to jump to. The
8246rest of the arguments indicate the full set of possible destinations
8247that the address may point to. Blocks are allowed to occur multiple
8248times in the destination list, though this isn't particularly useful.
8249
8250This destination list is required so that dataflow analysis has an
8251accurate understanding of the CFG.
8252
8253Semantics:
8254""""""""""
8255
8256Control transfers to the block specified in the address argument. All
8257possible destination blocks must be listed in the label list, otherwise
8258this instruction has undefined behavior. This implies that jumps to
8259labels defined in other functions have undefined behavior as well.
8260If '``address``' is ``poison`` or ``undef``, this instruction has undefined
8261behavior.
8262
8263Implementation:
8264"""""""""""""""
8265
8266This is typically implemented with a jump through a register.
8267
8268Example:
8269""""""""
8270
8271.. code-block:: llvm
8272
8273     indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ]
8274
8275.. _i_invoke:
8276
8277'``invoke``' Instruction
8278^^^^^^^^^^^^^^^^^^^^^^^^
8279
8280Syntax:
8281"""""""
8282
8283::
8284
8285      <result> = invoke [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
8286                    [operand bundles] to label <normal label> unwind label <exception label>
8287
8288Overview:
8289"""""""""
8290
8291The '``invoke``' instruction causes control to transfer to a specified
8292function, with the possibility of control flow transfer to either the
8293'``normal``' label or the '``exception``' label. If the callee function
8294returns with the "``ret``" instruction, control flow will return to the
8295"normal" label. If the callee (or any indirect callees) returns via the
8296":ref:`resume <i_resume>`" instruction or other exception handling
8297mechanism, control is interrupted and continued at the dynamically
8298nearest "exception" label.
8299
8300The '``exception``' label is a `landing
8301pad <ExceptionHandling.html#overview>`_ for the exception. As such,
8302'``exception``' label is required to have the
8303":ref:`landingpad <i_landingpad>`" instruction, which contains the
8304information about the behavior of the program after unwinding happens,
8305as its first non-PHI instruction. The restrictions on the
8306"``landingpad``" instruction's tightly couples it to the "``invoke``"
8307instruction, so that the important information contained within the
8308"``landingpad``" instruction can't be lost through normal code motion.
8309
8310Arguments:
8311""""""""""
8312
8313This instruction requires several arguments:
8314
8315#. The optional "cconv" marker indicates which :ref:`calling
8316   convention <callingconv>` the call should use. If none is
8317   specified, the call defaults to using C calling conventions.
8318#. The optional :ref:`Parameter Attributes <paramattrs>` list for return
8319   values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
8320   are valid here.
8321#. The optional addrspace attribute can be used to indicate the address space
8322   of the called function. If it is not specified, the program address space
8323   from the :ref:`datalayout string<langref_datalayout>` will be used.
8324#. '``ty``': the type of the call instruction itself which is also the
8325   type of the return value. Functions that return no value are marked
8326   ``void``.
8327#. '``fnty``': shall be the signature of the function being invoked. The
8328   argument types must match the types implied by this signature. This
8329   type can be omitted if the function is not varargs.
8330#. '``fnptrval``': An LLVM value containing a pointer to a function to
8331   be invoked. In most cases, this is a direct function invocation, but
8332   indirect ``invoke``'s are just as possible, calling an arbitrary pointer
8333   to function value.
8334#. '``function args``': argument list whose types match the function
8335   signature argument types and parameter attributes. All arguments must
8336   be of :ref:`first class <t_firstclass>` type. If the function signature
8337   indicates the function accepts a variable number of arguments, the
8338   extra arguments can be specified.
8339#. '``normal label``': the label reached when the called function
8340   executes a '``ret``' instruction.
8341#. '``exception label``': the label reached when a callee returns via
8342   the :ref:`resume <i_resume>` instruction or other exception handling
8343   mechanism.
8344#. The optional :ref:`function attributes <fnattrs>` list.
8345#. The optional :ref:`operand bundles <opbundles>` list.
8346
8347Semantics:
8348""""""""""
8349
8350This instruction is designed to operate as a standard '``call``'
8351instruction in most regards. The primary difference is that it
8352establishes an association with a label, which is used by the runtime
8353library to unwind the stack.
8354
8355This instruction is used in languages with destructors to ensure that
8356proper cleanup is performed in the case of either a ``longjmp`` or a
8357thrown exception. Additionally, this is important for implementation of
8358'``catch``' clauses in high-level languages that support them.
8359
8360For the purposes of the SSA form, the definition of the value returned
8361by the '``invoke``' instruction is deemed to occur on the edge from the
8362current block to the "normal" label. If the callee unwinds then no
8363return value is available.
8364
8365Example:
8366""""""""
8367
8368.. code-block:: llvm
8369
8370      %retval = invoke i32 @Test(i32 15) to label %Continue
8371                  unwind label %TestCleanup              ; i32:retval set
8372      %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue
8373                  unwind label %TestCleanup              ; i32:retval set
8374
8375.. _i_callbr:
8376
8377'``callbr``' Instruction
8378^^^^^^^^^^^^^^^^^^^^^^^^
8379
8380Syntax:
8381"""""""
8382
8383::
8384
8385      <result> = callbr [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
8386                    [operand bundles] to label <fallthrough label> [indirect labels]
8387
8388Overview:
8389"""""""""
8390
8391The '``callbr``' instruction causes control to transfer to a specified
8392function, with the possibility of control flow transfer to either the
8393'``fallthrough``' label or one of the '``indirect``' labels.
8394
8395This instruction should only be used to implement the "goto" feature of gcc
8396style inline assembly. Any other usage is an error in the IR verifier.
8397
8398Arguments:
8399""""""""""
8400
8401This instruction requires several arguments:
8402
8403#. The optional "cconv" marker indicates which :ref:`calling
8404   convention <callingconv>` the call should use. If none is
8405   specified, the call defaults to using C calling conventions.
8406#. The optional :ref:`Parameter Attributes <paramattrs>` list for return
8407   values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
8408   are valid here.
8409#. The optional addrspace attribute can be used to indicate the address space
8410   of the called function. If it is not specified, the program address space
8411   from the :ref:`datalayout string<langref_datalayout>` will be used.
8412#. '``ty``': the type of the call instruction itself which is also the
8413   type of the return value. Functions that return no value are marked
8414   ``void``.
8415#. '``fnty``': shall be the signature of the function being called. The
8416   argument types must match the types implied by this signature. This
8417   type can be omitted if the function is not varargs.
8418#. '``fnptrval``': An LLVM value containing a pointer to a function to
8419   be called. In most cases, this is a direct function call, but
8420   other ``callbr``'s are just as possible, calling an arbitrary pointer
8421   to function value.
8422#. '``function args``': argument list whose types match the function
8423   signature argument types and parameter attributes. All arguments must
8424   be of :ref:`first class <t_firstclass>` type. If the function signature
8425   indicates the function accepts a variable number of arguments, the
8426   extra arguments can be specified.
8427#. '``fallthrough label``': the label reached when the inline assembly's
8428   execution exits the bottom.
8429#. '``indirect labels``': the labels reached when a callee transfers control
8430   to a location other than the '``fallthrough label``'. Label constraints
8431   refer to these destinations.
8432#. The optional :ref:`function attributes <fnattrs>` list.
8433#. The optional :ref:`operand bundles <opbundles>` list.
8434
8435Semantics:
8436""""""""""
8437
8438This instruction is designed to operate as a standard '``call``'
8439instruction in most regards. The primary difference is that it
8440establishes an association with additional labels to define where control
8441flow goes after the call.
8442
8443The output values of a '``callbr``' instruction are available only to
8444the '``fallthrough``' block, not to any '``indirect``' blocks(s).
8445
8446The only use of this today is to implement the "goto" feature of gcc inline
8447assembly where additional labels can be provided as locations for the inline
8448assembly to jump to.
8449
8450Example:
8451""""""""
8452
8453.. code-block:: llvm
8454
8455      ; "asm goto" without output constraints.
8456      callbr void asm "", "r,!i"(i32 %x)
8457                  to label %fallthrough [label %indirect]
8458
8459      ; "asm goto" with output constraints.
8460      <result> = callbr i32 asm "", "=r,r,!i"(i32 %x)
8461                  to label %fallthrough [label %indirect]
8462
8463.. _i_resume:
8464
8465'``resume``' Instruction
8466^^^^^^^^^^^^^^^^^^^^^^^^
8467
8468Syntax:
8469"""""""
8470
8471::
8472
8473      resume <type> <value>
8474
8475Overview:
8476"""""""""
8477
8478The '``resume``' instruction is a terminator instruction that has no
8479successors.
8480
8481Arguments:
8482""""""""""
8483
8484The '``resume``' instruction requires one argument, which must have the
8485same type as the result of any '``landingpad``' instruction in the same
8486function.
8487
8488Semantics:
8489""""""""""
8490
8491The '``resume``' instruction resumes propagation of an existing
8492(in-flight) exception whose unwinding was interrupted with a
8493:ref:`landingpad <i_landingpad>` instruction.
8494
8495Example:
8496""""""""
8497
8498.. code-block:: llvm
8499
8500      resume { i8*, i32 } %exn
8501
8502.. _i_catchswitch:
8503
8504'``catchswitch``' Instruction
8505^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8506
8507Syntax:
8508"""""""
8509
8510::
8511
8512      <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller
8513      <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default>
8514
8515Overview:
8516"""""""""
8517
8518The '``catchswitch``' instruction is used by `LLVM's exception handling system
8519<ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers
8520that may be executed by the :ref:`EH personality routine <personalityfn>`.
8521
8522Arguments:
8523""""""""""
8524
8525The ``parent`` argument is the token of the funclet that contains the
8526``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet,
8527this operand may be the token ``none``.
8528
8529The ``default`` argument is the label of another basic block beginning with
8530either a ``cleanuppad`` or ``catchswitch`` instruction.  This unwind destination
8531must be a legal target with respect to the ``parent`` links, as described in
8532the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
8533
8534The ``handlers`` are a nonempty list of successor blocks that each begin with a
8535:ref:`catchpad <i_catchpad>` instruction.
8536
8537Semantics:
8538""""""""""
8539
8540Executing this instruction transfers control to one of the successors in
8541``handlers``, if appropriate, or continues to unwind via the unwind label if
8542present.
8543
8544The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that
8545it must be both the first non-phi instruction and last instruction in the basic
8546block. Therefore, it must be the only non-phi instruction in the block.
8547
8548Example:
8549""""""""
8550
8551.. code-block:: text
8552
8553    dispatch1:
8554      %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller
8555    dispatch2:
8556      %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup
8557
8558.. _i_catchret:
8559
8560'``catchret``' Instruction
8561^^^^^^^^^^^^^^^^^^^^^^^^^^
8562
8563Syntax:
8564"""""""
8565
8566::
8567
8568      catchret from <token> to label <normal>
8569
8570Overview:
8571"""""""""
8572
8573The '``catchret``' instruction is a terminator instruction that has a
8574single successor.
8575
8576
8577Arguments:
8578""""""""""
8579
8580The first argument to a '``catchret``' indicates which ``catchpad`` it
8581exits.  It must be a :ref:`catchpad <i_catchpad>`.
8582The second argument to a '``catchret``' specifies where control will
8583transfer to next.
8584
8585Semantics:
8586""""""""""
8587
8588The '``catchret``' instruction ends an existing (in-flight) exception whose
8589unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction.  The
8590:ref:`personality function <personalityfn>` gets a chance to execute arbitrary
8591code to, for example, destroy the active exception.  Control then transfers to
8592``normal``.
8593
8594The ``token`` argument must be a token produced by a ``catchpad`` instruction.
8595If the specified ``catchpad`` is not the most-recently-entered not-yet-exited
8596funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
8597the ``catchret``'s behavior is undefined.
8598
8599Example:
8600""""""""
8601
8602.. code-block:: text
8603
8604      catchret from %catch to label %continue
8605
8606.. _i_cleanupret:
8607
8608'``cleanupret``' Instruction
8609^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8610
8611Syntax:
8612"""""""
8613
8614::
8615
8616      cleanupret from <value> unwind label <continue>
8617      cleanupret from <value> unwind to caller
8618
8619Overview:
8620"""""""""
8621
8622The '``cleanupret``' instruction is a terminator instruction that has
8623an optional successor.
8624
8625
8626Arguments:
8627""""""""""
8628
8629The '``cleanupret``' instruction requires one argument, which indicates
8630which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`.
8631If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited
8632funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
8633the ``cleanupret``'s behavior is undefined.
8634
8635The '``cleanupret``' instruction also has an optional successor, ``continue``,
8636which must be the label of another basic block beginning with either a
8637``cleanuppad`` or ``catchswitch`` instruction.  This unwind destination must
8638be a legal target with respect to the ``parent`` links, as described in the
8639`exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
8640
8641Semantics:
8642""""""""""
8643
8644The '``cleanupret``' instruction indicates to the
8645:ref:`personality function <personalityfn>` that one
8646:ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended.
8647It transfers control to ``continue`` or unwinds out of the function.
8648
8649Example:
8650""""""""
8651
8652.. code-block:: text
8653
8654      cleanupret from %cleanup unwind to caller
8655      cleanupret from %cleanup unwind label %continue
8656
8657.. _i_unreachable:
8658
8659'``unreachable``' Instruction
8660^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8661
8662Syntax:
8663"""""""
8664
8665::
8666
8667      unreachable
8668
8669Overview:
8670"""""""""
8671
8672The '``unreachable``' instruction has no defined semantics. This
8673instruction is used to inform the optimizer that a particular portion of
8674the code is not reachable. This can be used to indicate that the code
8675after a no-return function cannot be reached, and other facts.
8676
8677Semantics:
8678""""""""""
8679
8680The '``unreachable``' instruction has no defined semantics.
8681
8682.. _unaryops:
8683
8684Unary Operations
8685-----------------
8686
8687Unary operators require a single operand, execute an operation on
8688it, and produce a single value. The operand might represent multiple
8689data, as is the case with the :ref:`vector <t_vector>` data type. The
8690result value has the same type as its operand.
8691
8692.. _i_fneg:
8693
8694'``fneg``' Instruction
8695^^^^^^^^^^^^^^^^^^^^^^
8696
8697Syntax:
8698"""""""
8699
8700::
8701
8702      <result> = fneg [fast-math flags]* <ty> <op1>   ; yields ty:result
8703
8704Overview:
8705"""""""""
8706
8707The '``fneg``' instruction returns the negation of its operand.
8708
8709Arguments:
8710""""""""""
8711
8712The argument to the '``fneg``' instruction must be a
8713:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
8714floating-point values.
8715
8716Semantics:
8717""""""""""
8718
8719The value produced is a copy of the operand with its sign bit flipped.
8720This instruction can also take any number of :ref:`fast-math
8721flags <fastmath>`, which are optimization hints to enable otherwise
8722unsafe floating-point optimizations:
8723
8724Example:
8725""""""""
8726
8727.. code-block:: text
8728
8729      <result> = fneg float %val          ; yields float:result = -%var
8730
8731.. _binaryops:
8732
8733Binary Operations
8734-----------------
8735
8736Binary operators are used to do most of the computation in a program.
8737They require two operands of the same type, execute an operation on
8738them, and produce a single value. The operands might represent multiple
8739data, as is the case with the :ref:`vector <t_vector>` data type. The
8740result value has the same type as its operands.
8741
8742There are several different binary operators:
8743
8744.. _i_add:
8745
8746'``add``' Instruction
8747^^^^^^^^^^^^^^^^^^^^^
8748
8749Syntax:
8750"""""""
8751
8752::
8753
8754      <result> = add <ty> <op1>, <op2>          ; yields ty:result
8755      <result> = add nuw <ty> <op1>, <op2>      ; yields ty:result
8756      <result> = add nsw <ty> <op1>, <op2>      ; yields ty:result
8757      <result> = add nuw nsw <ty> <op1>, <op2>  ; yields ty:result
8758
8759Overview:
8760"""""""""
8761
8762The '``add``' instruction returns the sum of its two operands.
8763
8764Arguments:
8765""""""""""
8766
8767The two arguments to the '``add``' instruction must be
8768:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
8769arguments must have identical types.
8770
8771Semantics:
8772""""""""""
8773
8774The value produced is the integer sum of the two operands.
8775
8776If the sum has unsigned overflow, the result returned is the
8777mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
8778the result.
8779
8780Because LLVM integers use a two's complement representation, this
8781instruction is appropriate for both signed and unsigned integers.
8782
8783``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
8784respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
8785result value of the ``add`` is a :ref:`poison value <poisonvalues>` if
8786unsigned and/or signed overflow, respectively, occurs.
8787
8788Example:
8789""""""""
8790
8791.. code-block:: text
8792
8793      <result> = add i32 4, %var          ; yields i32:result = 4 + %var
8794
8795.. _i_fadd:
8796
8797'``fadd``' Instruction
8798^^^^^^^^^^^^^^^^^^^^^^
8799
8800Syntax:
8801"""""""
8802
8803::
8804
8805      <result> = fadd [fast-math flags]* <ty> <op1>, <op2>   ; yields ty:result
8806
8807Overview:
8808"""""""""
8809
8810The '``fadd``' instruction returns the sum of its two operands.
8811
8812Arguments:
8813""""""""""
8814
8815The two arguments to the '``fadd``' instruction must be
8816:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
8817floating-point values. Both arguments must have identical types.
8818
8819Semantics:
8820""""""""""
8821
8822The value produced is the floating-point sum of the two operands.
8823This instruction is assumed to execute in the default :ref:`floating-point
8824environment <floatenv>`.
8825This instruction can also take any number of :ref:`fast-math
8826flags <fastmath>`, which are optimization hints to enable otherwise
8827unsafe floating-point optimizations:
8828
8829Example:
8830""""""""
8831
8832.. code-block:: text
8833
8834      <result> = fadd float 4.0, %var          ; yields float:result = 4.0 + %var
8835
8836.. _i_sub:
8837
8838'``sub``' Instruction
8839^^^^^^^^^^^^^^^^^^^^^
8840
8841Syntax:
8842"""""""
8843
8844::
8845
8846      <result> = sub <ty> <op1>, <op2>          ; yields ty:result
8847      <result> = sub nuw <ty> <op1>, <op2>      ; yields ty:result
8848      <result> = sub nsw <ty> <op1>, <op2>      ; yields ty:result
8849      <result> = sub nuw nsw <ty> <op1>, <op2>  ; yields ty:result
8850
8851Overview:
8852"""""""""
8853
8854The '``sub``' instruction returns the difference of its two operands.
8855
8856Note that the '``sub``' instruction is used to represent the '``neg``'
8857instruction present in most other intermediate representations.
8858
8859Arguments:
8860""""""""""
8861
8862The two arguments to the '``sub``' instruction must be
8863:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
8864arguments must have identical types.
8865
8866Semantics:
8867""""""""""
8868
8869The value produced is the integer difference of the two operands.
8870
8871If the difference has unsigned overflow, the result returned is the
8872mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
8873the result.
8874
8875Because LLVM integers use a two's complement representation, this
8876instruction is appropriate for both signed and unsigned integers.
8877
8878``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
8879respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
8880result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if
8881unsigned and/or signed overflow, respectively, occurs.
8882
8883Example:
8884""""""""
8885
8886.. code-block:: text
8887
8888      <result> = sub i32 4, %var          ; yields i32:result = 4 - %var
8889      <result> = sub i32 0, %val          ; yields i32:result = -%var
8890
8891.. _i_fsub:
8892
8893'``fsub``' Instruction
8894^^^^^^^^^^^^^^^^^^^^^^
8895
8896Syntax:
8897"""""""
8898
8899::
8900
8901      <result> = fsub [fast-math flags]* <ty> <op1>, <op2>   ; yields ty:result
8902
8903Overview:
8904"""""""""
8905
8906The '``fsub``' instruction returns the difference of its two operands.
8907
8908Arguments:
8909""""""""""
8910
8911The two arguments to the '``fsub``' instruction must be
8912:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
8913floating-point values. Both arguments must have identical types.
8914
8915Semantics:
8916""""""""""
8917
8918The value produced is the floating-point difference of the two operands.
8919This instruction is assumed to execute in the default :ref:`floating-point
8920environment <floatenv>`.
8921This instruction can also take any number of :ref:`fast-math
8922flags <fastmath>`, which are optimization hints to enable otherwise
8923unsafe floating-point optimizations:
8924
8925Example:
8926""""""""
8927
8928.. code-block:: text
8929
8930      <result> = fsub float 4.0, %var           ; yields float:result = 4.0 - %var
8931      <result> = fsub float -0.0, %val          ; yields float:result = -%var
8932
8933.. _i_mul:
8934
8935'``mul``' Instruction
8936^^^^^^^^^^^^^^^^^^^^^
8937
8938Syntax:
8939"""""""
8940
8941::
8942
8943      <result> = mul <ty> <op1>, <op2>          ; yields ty:result
8944      <result> = mul nuw <ty> <op1>, <op2>      ; yields ty:result
8945      <result> = mul nsw <ty> <op1>, <op2>      ; yields ty:result
8946      <result> = mul nuw nsw <ty> <op1>, <op2>  ; yields ty:result
8947
8948Overview:
8949"""""""""
8950
8951The '``mul``' instruction returns the product of its two operands.
8952
8953Arguments:
8954""""""""""
8955
8956The two arguments to the '``mul``' instruction must be
8957:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
8958arguments must have identical types.
8959
8960Semantics:
8961""""""""""
8962
8963The value produced is the integer product of the two operands.
8964
8965If the result of the multiplication has unsigned overflow, the result
8966returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the
8967bit width of the result.
8968
8969Because LLVM integers use a two's complement representation, and the
8970result is the same width as the operands, this instruction returns the
8971correct result for both signed and unsigned integers. If a full product
8972(e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be
8973sign-extended or zero-extended as appropriate to the width of the full
8974product.
8975
8976``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
8977respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
8978result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if
8979unsigned and/or signed overflow, respectively, occurs.
8980
8981Example:
8982""""""""
8983
8984.. code-block:: text
8985
8986      <result> = mul i32 4, %var          ; yields i32:result = 4 * %var
8987
8988.. _i_fmul:
8989
8990'``fmul``' Instruction
8991^^^^^^^^^^^^^^^^^^^^^^
8992
8993Syntax:
8994"""""""
8995
8996::
8997
8998      <result> = fmul [fast-math flags]* <ty> <op1>, <op2>   ; yields ty:result
8999
9000Overview:
9001"""""""""
9002
9003The '``fmul``' instruction returns the product of its two operands.
9004
9005Arguments:
9006""""""""""
9007
9008The two arguments to the '``fmul``' instruction must be
9009:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9010floating-point values. Both arguments must have identical types.
9011
9012Semantics:
9013""""""""""
9014
9015The value produced is the floating-point product of the two operands.
9016This instruction is assumed to execute in the default :ref:`floating-point
9017environment <floatenv>`.
9018This instruction can also take any number of :ref:`fast-math
9019flags <fastmath>`, which are optimization hints to enable otherwise
9020unsafe floating-point optimizations:
9021
9022Example:
9023""""""""
9024
9025.. code-block:: text
9026
9027      <result> = fmul float 4.0, %var          ; yields float:result = 4.0 * %var
9028
9029.. _i_udiv:
9030
9031'``udiv``' Instruction
9032^^^^^^^^^^^^^^^^^^^^^^
9033
9034Syntax:
9035"""""""
9036
9037::
9038
9039      <result> = udiv <ty> <op1>, <op2>         ; yields ty:result
9040      <result> = udiv exact <ty> <op1>, <op2>   ; yields ty:result
9041
9042Overview:
9043"""""""""
9044
9045The '``udiv``' instruction returns the quotient of its two operands.
9046
9047Arguments:
9048""""""""""
9049
9050The two arguments to the '``udiv``' instruction must be
9051:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9052arguments must have identical types.
9053
9054Semantics:
9055""""""""""
9056
9057The value produced is the unsigned integer quotient of the two operands.
9058
9059Note that unsigned integer division and signed integer division are
9060distinct operations; for signed integer division, use '``sdiv``'.
9061
9062Division by zero is undefined behavior. For vectors, if any element
9063of the divisor is zero, the operation has undefined behavior.
9064
9065
9066If the ``exact`` keyword is present, the result value of the ``udiv`` is
9067a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as
9068such, "((a udiv exact b) mul b) == a").
9069
9070Example:
9071""""""""
9072
9073.. code-block:: text
9074
9075      <result> = udiv i32 4, %var          ; yields i32:result = 4 / %var
9076
9077.. _i_sdiv:
9078
9079'``sdiv``' Instruction
9080^^^^^^^^^^^^^^^^^^^^^^
9081
9082Syntax:
9083"""""""
9084
9085::
9086
9087      <result> = sdiv <ty> <op1>, <op2>         ; yields ty:result
9088      <result> = sdiv exact <ty> <op1>, <op2>   ; yields ty:result
9089
9090Overview:
9091"""""""""
9092
9093The '``sdiv``' instruction returns the quotient of its two operands.
9094
9095Arguments:
9096""""""""""
9097
9098The two arguments to the '``sdiv``' instruction must be
9099:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9100arguments must have identical types.
9101
9102Semantics:
9103""""""""""
9104
9105The value produced is the signed integer quotient of the two operands
9106rounded towards zero.
9107
9108Note that signed integer division and unsigned integer division are
9109distinct operations; for unsigned integer division, use '``udiv``'.
9110
9111Division by zero is undefined behavior. For vectors, if any element
9112of the divisor is zero, the operation has undefined behavior.
9113Overflow also leads to undefined behavior; this is a rare case, but can
9114occur, for example, by doing a 32-bit division of -2147483648 by -1.
9115
9116If the ``exact`` keyword is present, the result value of the ``sdiv`` is
9117a :ref:`poison value <poisonvalues>` if the result would be rounded.
9118
9119Example:
9120""""""""
9121
9122.. code-block:: text
9123
9124      <result> = sdiv i32 4, %var          ; yields i32:result = 4 / %var
9125
9126.. _i_fdiv:
9127
9128'``fdiv``' Instruction
9129^^^^^^^^^^^^^^^^^^^^^^
9130
9131Syntax:
9132"""""""
9133
9134::
9135
9136      <result> = fdiv [fast-math flags]* <ty> <op1>, <op2>   ; yields ty:result
9137
9138Overview:
9139"""""""""
9140
9141The '``fdiv``' instruction returns the quotient of its two operands.
9142
9143Arguments:
9144""""""""""
9145
9146The two arguments to the '``fdiv``' instruction must be
9147:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9148floating-point values. Both arguments must have identical types.
9149
9150Semantics:
9151""""""""""
9152
9153The value produced is the floating-point quotient of the two operands.
9154This instruction is assumed to execute in the default :ref:`floating-point
9155environment <floatenv>`.
9156This instruction can also take any number of :ref:`fast-math
9157flags <fastmath>`, which are optimization hints to enable otherwise
9158unsafe floating-point optimizations:
9159
9160Example:
9161""""""""
9162
9163.. code-block:: text
9164
9165      <result> = fdiv float 4.0, %var          ; yields float:result = 4.0 / %var
9166
9167.. _i_urem:
9168
9169'``urem``' Instruction
9170^^^^^^^^^^^^^^^^^^^^^^
9171
9172Syntax:
9173"""""""
9174
9175::
9176
9177      <result> = urem <ty> <op1>, <op2>   ; yields ty:result
9178
9179Overview:
9180"""""""""
9181
9182The '``urem``' instruction returns the remainder from the unsigned
9183division of its two arguments.
9184
9185Arguments:
9186""""""""""
9187
9188The two arguments to the '``urem``' instruction must be
9189:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9190arguments must have identical types.
9191
9192Semantics:
9193""""""""""
9194
9195This instruction returns the unsigned integer *remainder* of a division.
9196This instruction always performs an unsigned division to get the
9197remainder.
9198
9199Note that unsigned integer remainder and signed integer remainder are
9200distinct operations; for signed integer remainder, use '``srem``'.
9201
9202Taking the remainder of a division by zero is undefined behavior.
9203For vectors, if any element of the divisor is zero, the operation has
9204undefined behavior.
9205
9206Example:
9207""""""""
9208
9209.. code-block:: text
9210
9211      <result> = urem i32 4, %var          ; yields i32:result = 4 % %var
9212
9213.. _i_srem:
9214
9215'``srem``' Instruction
9216^^^^^^^^^^^^^^^^^^^^^^
9217
9218Syntax:
9219"""""""
9220
9221::
9222
9223      <result> = srem <ty> <op1>, <op2>   ; yields ty:result
9224
9225Overview:
9226"""""""""
9227
9228The '``srem``' instruction returns the remainder from the signed
9229division of its two operands. This instruction can also take
9230:ref:`vector <t_vector>` versions of the values in which case the elements
9231must be integers.
9232
9233Arguments:
9234""""""""""
9235
9236The two arguments to the '``srem``' instruction must be
9237:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9238arguments must have identical types.
9239
9240Semantics:
9241""""""""""
9242
9243This instruction returns the *remainder* of a division (where the result
9244is either zero or has the same sign as the dividend, ``op1``), not the
9245*modulo* operator (where the result is either zero or has the same sign
9246as the divisor, ``op2``) of a value. For more information about the
9247difference, see `The Math
9248Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a
9249table of how this is implemented in various languages, please see
9250`Wikipedia: modulo
9251operation <http://en.wikipedia.org/wiki/Modulo_operation>`_.
9252
9253Note that signed integer remainder and unsigned integer remainder are
9254distinct operations; for unsigned integer remainder, use '``urem``'.
9255
9256Taking the remainder of a division by zero is undefined behavior.
9257For vectors, if any element of the divisor is zero, the operation has
9258undefined behavior.
9259Overflow also leads to undefined behavior; this is a rare case, but can
9260occur, for example, by taking the remainder of a 32-bit division of
9261-2147483648 by -1. (The remainder doesn't actually overflow, but this
9262rule lets srem be implemented using instructions that return both the
9263result of the division and the remainder.)
9264
9265Example:
9266""""""""
9267
9268.. code-block:: text
9269
9270      <result> = srem i32 4, %var          ; yields i32:result = 4 % %var
9271
9272.. _i_frem:
9273
9274'``frem``' Instruction
9275^^^^^^^^^^^^^^^^^^^^^^
9276
9277Syntax:
9278"""""""
9279
9280::
9281
9282      <result> = frem [fast-math flags]* <ty> <op1>, <op2>   ; yields ty:result
9283
9284Overview:
9285"""""""""
9286
9287The '``frem``' instruction returns the remainder from the division of
9288its two operands.
9289
9290Arguments:
9291""""""""""
9292
9293The two arguments to the '``frem``' instruction must be
9294:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9295floating-point values. Both arguments must have identical types.
9296
9297Semantics:
9298""""""""""
9299
9300The value produced is the floating-point remainder of the two operands.
9301This is the same output as a libm '``fmod``' function, but without any
9302possibility of setting ``errno``. The remainder has the same sign as the
9303dividend.
9304This instruction is assumed to execute in the default :ref:`floating-point
9305environment <floatenv>`.
9306This instruction can also take any number of :ref:`fast-math
9307flags <fastmath>`, which are optimization hints to enable otherwise
9308unsafe floating-point optimizations:
9309
9310Example:
9311""""""""
9312
9313.. code-block:: text
9314
9315      <result> = frem float 4.0, %var          ; yields float:result = 4.0 % %var
9316
9317.. _bitwiseops:
9318
9319Bitwise Binary Operations
9320-------------------------
9321
9322Bitwise binary operators are used to do various forms of bit-twiddling
9323in a program. They are generally very efficient instructions and can
9324commonly be strength reduced from other instructions. They require two
9325operands of the same type, execute an operation on them, and produce a
9326single value. The resulting value is the same type as its operands.
9327
9328.. _i_shl:
9329
9330'``shl``' Instruction
9331^^^^^^^^^^^^^^^^^^^^^
9332
9333Syntax:
9334"""""""
9335
9336::
9337
9338      <result> = shl <ty> <op1>, <op2>           ; yields ty:result
9339      <result> = shl nuw <ty> <op1>, <op2>       ; yields ty:result
9340      <result> = shl nsw <ty> <op1>, <op2>       ; yields ty:result
9341      <result> = shl nuw nsw <ty> <op1>, <op2>   ; yields ty:result
9342
9343Overview:
9344"""""""""
9345
9346The '``shl``' instruction returns the first operand shifted to the left
9347a specified number of bits.
9348
9349Arguments:
9350""""""""""
9351
9352Both arguments to the '``shl``' instruction must be the same
9353:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
9354'``op2``' is treated as an unsigned value.
9355
9356Semantics:
9357""""""""""
9358
9359The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`,
9360where ``n`` is the width of the result. If ``op2`` is (statically or
9361dynamically) equal to or larger than the number of bits in
9362``op1``, this instruction returns a :ref:`poison value <poisonvalues>`.
9363If the arguments are vectors, each vector element of ``op1`` is shifted
9364by the corresponding shift amount in ``op2``.
9365
9366If the ``nuw`` keyword is present, then the shift produces a poison
9367value if it shifts out any non-zero bits.
9368If the ``nsw`` keyword is present, then the shift produces a poison
9369value if it shifts out any bits that disagree with the resultant sign bit.
9370
9371Example:
9372""""""""
9373
9374.. code-block:: text
9375
9376      <result> = shl i32 4, %var   ; yields i32: 4 << %var
9377      <result> = shl i32 4, 2      ; yields i32: 16
9378      <result> = shl i32 1, 10     ; yields i32: 1024
9379      <result> = shl i32 1, 32     ; undefined
9380      <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2>   ; yields: result=<2 x i32> < i32 2, i32 4>
9381
9382.. _i_lshr:
9383
9384
9385'``lshr``' Instruction
9386^^^^^^^^^^^^^^^^^^^^^^
9387
9388Syntax:
9389"""""""
9390
9391::
9392
9393      <result> = lshr <ty> <op1>, <op2>         ; yields ty:result
9394      <result> = lshr exact <ty> <op1>, <op2>   ; yields ty:result
9395
9396Overview:
9397"""""""""
9398
9399The '``lshr``' instruction (logical shift right) returns the first
9400operand shifted to the right a specified number of bits with zero fill.
9401
9402Arguments:
9403""""""""""
9404
9405Both arguments to the '``lshr``' instruction must be the same
9406:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
9407'``op2``' is treated as an unsigned value.
9408
9409Semantics:
9410""""""""""
9411
9412This instruction always performs a logical shift right operation. The
9413most significant bits of the result will be filled with zero bits after
9414the shift. If ``op2`` is (statically or dynamically) equal to or larger
9415than the number of bits in ``op1``, this instruction returns a :ref:`poison
9416value <poisonvalues>`. If the arguments are vectors, each vector element
9417of ``op1`` is shifted by the corresponding shift amount in ``op2``.
9418
9419If the ``exact`` keyword is present, the result value of the ``lshr`` is
9420a poison value if any of the bits shifted out are non-zero.
9421
9422Example:
9423""""""""
9424
9425.. code-block:: text
9426
9427      <result> = lshr i32 4, 1   ; yields i32:result = 2
9428      <result> = lshr i32 4, 2   ; yields i32:result = 1
9429      <result> = lshr i8  4, 3   ; yields i8:result = 0
9430      <result> = lshr i8 -2, 1   ; yields i8:result = 0x7F
9431      <result> = lshr i32 1, 32  ; undefined
9432      <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2>   ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1>
9433
9434.. _i_ashr:
9435
9436'``ashr``' Instruction
9437^^^^^^^^^^^^^^^^^^^^^^
9438
9439Syntax:
9440"""""""
9441
9442::
9443
9444      <result> = ashr <ty> <op1>, <op2>         ; yields ty:result
9445      <result> = ashr exact <ty> <op1>, <op2>   ; yields ty:result
9446
9447Overview:
9448"""""""""
9449
9450The '``ashr``' instruction (arithmetic shift right) returns the first
9451operand shifted to the right a specified number of bits with sign
9452extension.
9453
9454Arguments:
9455""""""""""
9456
9457Both arguments to the '``ashr``' instruction must be the same
9458:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
9459'``op2``' is treated as an unsigned value.
9460
9461Semantics:
9462""""""""""
9463
9464This instruction always performs an arithmetic shift right operation,
9465The most significant bits of the result will be filled with the sign bit
9466of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger
9467than the number of bits in ``op1``, this instruction returns a :ref:`poison
9468value <poisonvalues>`. If the arguments are vectors, each vector element
9469of ``op1`` is shifted by the corresponding shift amount in ``op2``.
9470
9471If the ``exact`` keyword is present, the result value of the ``ashr`` is
9472a poison value if any of the bits shifted out are non-zero.
9473
9474Example:
9475""""""""
9476
9477.. code-block:: text
9478
9479      <result> = ashr i32 4, 1   ; yields i32:result = 2
9480      <result> = ashr i32 4, 2   ; yields i32:result = 1
9481      <result> = ashr i8  4, 3   ; yields i8:result = 0
9482      <result> = ashr i8 -2, 1   ; yields i8:result = -1
9483      <result> = ashr i32 1, 32  ; undefined
9484      <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3>   ; yields: result=<2 x i32> < i32 -1, i32 0>
9485
9486.. _i_and:
9487
9488'``and``' Instruction
9489^^^^^^^^^^^^^^^^^^^^^
9490
9491Syntax:
9492"""""""
9493
9494::
9495
9496      <result> = and <ty> <op1>, <op2>   ; yields ty:result
9497
9498Overview:
9499"""""""""
9500
9501The '``and``' instruction returns the bitwise logical and of its two
9502operands.
9503
9504Arguments:
9505""""""""""
9506
9507The two arguments to the '``and``' instruction must be
9508:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9509arguments must have identical types.
9510
9511Semantics:
9512""""""""""
9513
9514The truth table used for the '``and``' instruction is:
9515
9516+-----+-----+-----+
9517| In0 | In1 | Out |
9518+-----+-----+-----+
9519|   0 |   0 |   0 |
9520+-----+-----+-----+
9521|   0 |   1 |   0 |
9522+-----+-----+-----+
9523|   1 |   0 |   0 |
9524+-----+-----+-----+
9525|   1 |   1 |   1 |
9526+-----+-----+-----+
9527
9528Example:
9529""""""""
9530
9531.. code-block:: text
9532
9533      <result> = and i32 4, %var         ; yields i32:result = 4 & %var
9534      <result> = and i32 15, 40          ; yields i32:result = 8
9535      <result> = and i32 4, 8            ; yields i32:result = 0
9536
9537.. _i_or:
9538
9539'``or``' Instruction
9540^^^^^^^^^^^^^^^^^^^^
9541
9542Syntax:
9543"""""""
9544
9545::
9546
9547      <result> = or <ty> <op1>, <op2>   ; yields ty:result
9548
9549Overview:
9550"""""""""
9551
9552The '``or``' instruction returns the bitwise logical inclusive or of its
9553two operands.
9554
9555Arguments:
9556""""""""""
9557
9558The two arguments to the '``or``' instruction must be
9559:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9560arguments must have identical types.
9561
9562Semantics:
9563""""""""""
9564
9565The truth table used for the '``or``' instruction is:
9566
9567+-----+-----+-----+
9568| In0 | In1 | Out |
9569+-----+-----+-----+
9570|   0 |   0 |   0 |
9571+-----+-----+-----+
9572|   0 |   1 |   1 |
9573+-----+-----+-----+
9574|   1 |   0 |   1 |
9575+-----+-----+-----+
9576|   1 |   1 |   1 |
9577+-----+-----+-----+
9578
9579Example:
9580""""""""
9581
9582::
9583
9584      <result> = or i32 4, %var         ; yields i32:result = 4 | %var
9585      <result> = or i32 15, 40          ; yields i32:result = 47
9586      <result> = or i32 4, 8            ; yields i32:result = 12
9587
9588.. _i_xor:
9589
9590'``xor``' Instruction
9591^^^^^^^^^^^^^^^^^^^^^
9592
9593Syntax:
9594"""""""
9595
9596::
9597
9598      <result> = xor <ty> <op1>, <op2>   ; yields ty:result
9599
9600Overview:
9601"""""""""
9602
9603The '``xor``' instruction returns the bitwise logical exclusive or of
9604its two operands. The ``xor`` is used to implement the "one's
9605complement" operation, which is the "~" operator in C.
9606
9607Arguments:
9608""""""""""
9609
9610The two arguments to the '``xor``' instruction must be
9611:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9612arguments must have identical types.
9613
9614Semantics:
9615""""""""""
9616
9617The truth table used for the '``xor``' instruction is:
9618
9619+-----+-----+-----+
9620| In0 | In1 | Out |
9621+-----+-----+-----+
9622|   0 |   0 |   0 |
9623+-----+-----+-----+
9624|   0 |   1 |   1 |
9625+-----+-----+-----+
9626|   1 |   0 |   1 |
9627+-----+-----+-----+
9628|   1 |   1 |   0 |
9629+-----+-----+-----+
9630
9631Example:
9632""""""""
9633
9634.. code-block:: text
9635
9636      <result> = xor i32 4, %var         ; yields i32:result = 4 ^ %var
9637      <result> = xor i32 15, 40          ; yields i32:result = 39
9638      <result> = xor i32 4, 8            ; yields i32:result = 12
9639      <result> = xor i32 %V, -1          ; yields i32:result = ~%V
9640
9641Vector Operations
9642-----------------
9643
9644LLVM supports several instructions to represent vector operations in a
9645target-independent manner. These instructions cover the element-access
9646and vector-specific operations needed to process vectors effectively.
9647While LLVM does directly support these vector operations, many
9648sophisticated algorithms will want to use target-specific intrinsics to
9649take full advantage of a specific target.
9650
9651.. _i_extractelement:
9652
9653'``extractelement``' Instruction
9654^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9655
9656Syntax:
9657"""""""
9658
9659::
9660
9661      <result> = extractelement <n x <ty>> <val>, <ty2> <idx>  ; yields <ty>
9662      <result> = extractelement <vscale x n x <ty>> <val>, <ty2> <idx> ; yields <ty>
9663
9664Overview:
9665"""""""""
9666
9667The '``extractelement``' instruction extracts a single scalar element
9668from a vector at a specified index.
9669
9670Arguments:
9671""""""""""
9672
9673The first operand of an '``extractelement``' instruction is a value of
9674:ref:`vector <t_vector>` type. The second operand is an index indicating
9675the position from which to extract the element. The index may be a
9676variable of any integer type.
9677
9678Semantics:
9679""""""""""
9680
9681The result is a scalar of the same type as the element type of ``val``.
9682Its value is the value at position ``idx`` of ``val``. If ``idx``
9683exceeds the length of ``val`` for a fixed-length vector, the result is a
9684:ref:`poison value <poisonvalues>`. For a scalable vector, if the value
9685of ``idx`` exceeds the runtime length of the vector, the result is a
9686:ref:`poison value <poisonvalues>`.
9687
9688Example:
9689""""""""
9690
9691.. code-block:: text
9692
9693      <result> = extractelement <4 x i32> %vec, i32 0    ; yields i32
9694
9695.. _i_insertelement:
9696
9697'``insertelement``' Instruction
9698^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9699
9700Syntax:
9701"""""""
9702
9703::
9704
9705      <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx>    ; yields <n x <ty>>
9706      <result> = insertelement <vscale x n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <vscale x n x <ty>>
9707
9708Overview:
9709"""""""""
9710
9711The '``insertelement``' instruction inserts a scalar element into a
9712vector at a specified index.
9713
9714Arguments:
9715""""""""""
9716
9717The first operand of an '``insertelement``' instruction is a value of
9718:ref:`vector <t_vector>` type. The second operand is a scalar value whose
9719type must equal the element type of the first operand. The third operand
9720is an index indicating the position at which to insert the value. The
9721index may be a variable of any integer type.
9722
9723Semantics:
9724""""""""""
9725
9726The result is a vector of the same type as ``val``. Its element values
9727are those of ``val`` except at position ``idx``, where it gets the value
9728``elt``. If ``idx`` exceeds the length of ``val`` for a fixed-length vector,
9729the result is a :ref:`poison value <poisonvalues>`. For a scalable vector,
9730if the value of ``idx`` exceeds the runtime length of the vector, the result
9731is a :ref:`poison value <poisonvalues>`.
9732
9733Example:
9734""""""""
9735
9736.. code-block:: text
9737
9738      <result> = insertelement <4 x i32> %vec, i32 1, i32 0    ; yields <4 x i32>
9739
9740.. _i_shufflevector:
9741
9742'``shufflevector``' Instruction
9743^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9744
9745Syntax:
9746"""""""
9747
9748::
9749
9750      <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask>    ; yields <m x <ty>>
9751      <result> = shufflevector <vscale x n x <ty>> <v1>, <vscale x n x <ty>> v2, <vscale x m x i32> <mask>  ; yields <vscale x m x <ty>>
9752
9753Overview:
9754"""""""""
9755
9756The '``shufflevector``' instruction constructs a permutation of elements
9757from two input vectors, returning a vector with the same element type as
9758the input and length that is the same as the shuffle mask.
9759
9760Arguments:
9761""""""""""
9762
9763The first two operands of a '``shufflevector``' instruction are vectors
9764with the same type. The third argument is a shuffle mask vector constant
9765whose element type is ``i32``. The mask vector elements must be constant
9766integers or ``undef`` values. The result of the instruction is a vector
9767whose length is the same as the shuffle mask and whose element type is the
9768same as the element type of the first two operands.
9769
9770Semantics:
9771""""""""""
9772
9773The elements of the two input vectors are numbered from left to right
9774across both of the vectors. For each element of the result vector, the
9775shuffle mask selects an element from one of the input vectors to copy
9776to the result. Non-negative elements in the mask represent an index
9777into the concatenated pair of input vectors.
9778
9779If the shuffle mask is undefined, the result vector is undefined. If
9780the shuffle mask selects an undefined element from one of the input
9781vectors, the resulting element is undefined. An undefined element
9782in the mask vector specifies that the resulting element is undefined.
9783An undefined element in the mask vector prevents a poisoned vector
9784element from propagating.
9785
9786For scalable vectors, the only valid mask values at present are
9787``zeroinitializer`` and ``undef``, since we cannot write all indices as
9788literals for a vector with a length unknown at compile time.
9789
9790Example:
9791""""""""
9792
9793.. code-block:: text
9794
9795      <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
9796                              <4 x i32> <i32 0, i32 4, i32 1, i32 5>  ; yields <4 x i32>
9797      <result> = shufflevector <4 x i32> %v1, <4 x i32> undef,
9798                              <4 x i32> <i32 0, i32 1, i32 2, i32 3>  ; yields <4 x i32> - Identity shuffle.
9799      <result> = shufflevector <8 x i32> %v1, <8 x i32> undef,
9800                              <4 x i32> <i32 0, i32 1, i32 2, i32 3>  ; yields <4 x i32>
9801      <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
9802                              <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 >  ; yields <8 x i32>
9803
9804Aggregate Operations
9805--------------------
9806
9807LLVM supports several instructions for working with
9808:ref:`aggregate <t_aggregate>` values.
9809
9810.. _i_extractvalue:
9811
9812'``extractvalue``' Instruction
9813^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9814
9815Syntax:
9816"""""""
9817
9818::
9819
9820      <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
9821
9822Overview:
9823"""""""""
9824
9825The '``extractvalue``' instruction extracts the value of a member field
9826from an :ref:`aggregate <t_aggregate>` value.
9827
9828Arguments:
9829""""""""""
9830
9831The first operand of an '``extractvalue``' instruction is a value of
9832:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are
9833constant indices to specify which value to extract in a similar manner
9834as indices in a '``getelementptr``' instruction.
9835
9836The major differences to ``getelementptr`` indexing are:
9837
9838-  Since the value being indexed is not a pointer, the first index is
9839   omitted and assumed to be zero.
9840-  At least one index must be specified.
9841-  Not only struct indices but also array indices must be in bounds.
9842
9843Semantics:
9844""""""""""
9845
9846The result is the value at the position in the aggregate specified by
9847the index operands.
9848
9849Example:
9850""""""""
9851
9852.. code-block:: text
9853
9854      <result> = extractvalue {i32, float} %agg, 0    ; yields i32
9855
9856.. _i_insertvalue:
9857
9858'``insertvalue``' Instruction
9859^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9860
9861Syntax:
9862"""""""
9863
9864::
9865
9866      <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}*    ; yields <aggregate type>
9867
9868Overview:
9869"""""""""
9870
9871The '``insertvalue``' instruction inserts a value into a member field in
9872an :ref:`aggregate <t_aggregate>` value.
9873
9874Arguments:
9875""""""""""
9876
9877The first operand of an '``insertvalue``' instruction is a value of
9878:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is
9879a first-class value to insert. The following operands are constant
9880indices indicating the position at which to insert the value in a
9881similar manner as indices in a '``extractvalue``' instruction. The value
9882to insert must have the same type as the value identified by the
9883indices.
9884
9885Semantics:
9886""""""""""
9887
9888The result is an aggregate of the same type as ``val``. Its value is
9889that of ``val`` except that the value at the position specified by the
9890indices is that of ``elt``.
9891
9892Example:
9893""""""""
9894
9895.. code-block:: llvm
9896
9897      %agg1 = insertvalue {i32, float} undef, i32 1, 0              ; yields {i32 1, float undef}
9898      %agg2 = insertvalue {i32, float} %agg1, float %val, 1         ; yields {i32 1, float %val}
9899      %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0    ; yields {i32 undef, {float %val}}
9900
9901.. _memoryops:
9902
9903Memory Access and Addressing Operations
9904---------------------------------------
9905
9906A key design point of an SSA-based representation is how it represents
9907memory. In LLVM, no memory locations are in SSA form, which makes things
9908very simple. This section describes how to read, write, and allocate
9909memory in LLVM.
9910
9911.. _i_alloca:
9912
9913'``alloca``' Instruction
9914^^^^^^^^^^^^^^^^^^^^^^^^
9915
9916Syntax:
9917"""""""
9918
9919::
9920
9921      <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)]     ; yields type addrspace(num)*:result
9922
9923Overview:
9924"""""""""
9925
9926The '``alloca``' instruction allocates memory on the stack frame of the
9927currently executing function, to be automatically released when this
9928function returns to its caller.  If the address space is not explicitly
9929specified, the object is allocated in the alloca address space from the
9930:ref:`datalayout string<langref_datalayout>`.
9931
9932Arguments:
9933""""""""""
9934
9935The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements``
9936bytes of memory on the runtime stack, returning a pointer of the
9937appropriate type to the program. If "NumElements" is specified, it is
9938the number of elements allocated, otherwise "NumElements" is defaulted
9939to be one. If a constant alignment is specified, the value result of the
9940allocation is guaranteed to be aligned to at least that boundary. The
9941alignment may not be greater than ``1 << 32``. If not specified, or if
9942zero, the target can choose to align the allocation on any convenient
9943boundary compatible with the type.
9944
9945'``type``' may be any sized type.
9946
9947Semantics:
9948""""""""""
9949
9950Memory is allocated; a pointer is returned. The allocated memory is
9951uninitialized, and loading from uninitialized memory produces an undefined
9952value. The operation itself is undefined if there is insufficient stack
9953space for the allocation.'``alloca``'d memory is automatically released
9954when the function returns. The '``alloca``' instruction is commonly used
9955to represent automatic variables that must have an address available. When
9956the function returns (either with the ``ret`` or ``resume`` instructions),
9957the memory is reclaimed. Allocating zero bytes is legal, but the returned
9958pointer may not be unique. The order in which memory is allocated (ie.,
9959which way the stack grows) is not specified.
9960
9961Note that '``alloca``' outside of the alloca address space from the
9962:ref:`datalayout string<langref_datalayout>` is meaningful only if the
9963target has assigned it a semantics.
9964
9965If the returned pointer is used by :ref:`llvm.lifetime.start <int_lifestart>`,
9966the returned object is initially dead.
9967See :ref:`llvm.lifetime.start <int_lifestart>` and
9968:ref:`llvm.lifetime.end <int_lifeend>` for the precise semantics of
9969lifetime-manipulating intrinsics.
9970
9971Example:
9972""""""""
9973
9974.. code-block:: llvm
9975
9976      %ptr = alloca i32                             ; yields i32*:ptr
9977      %ptr = alloca i32, i32 4                      ; yields i32*:ptr
9978      %ptr = alloca i32, i32 4, align 1024          ; yields i32*:ptr
9979      %ptr = alloca i32, align 1024                 ; yields i32*:ptr
9980
9981.. _i_load:
9982
9983'``load``' Instruction
9984^^^^^^^^^^^^^^^^^^^^^^
9985
9986Syntax:
9987"""""""
9988
9989::
9990
9991      <result> = load [volatile] <ty>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<nontemp_node>][, !invariant.load !<empty_node>][, !invariant.group !<empty_node>][, !nonnull !<empty_node>][, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>][, !align !<align_node>][, !noundef !<empty_node>]
9992      <result> = load atomic [volatile] <ty>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>]
9993      !<nontemp_node> = !{ i32 1 }
9994      !<empty_node> = !{}
9995      !<deref_bytes_node> = !{ i64 <dereferenceable_bytes> }
9996      !<align_node> = !{ i64 <value_alignment> }
9997
9998Overview:
9999"""""""""
10000
10001The '``load``' instruction is used to read from memory.
10002
10003Arguments:
10004""""""""""
10005
10006The argument to the ``load`` instruction specifies the memory address from which
10007to load. The type specified must be a :ref:`first class <t_firstclass>` type of
10008known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If
10009the ``load`` is marked as ``volatile``, then the optimizer is not allowed to
10010modify the number or order of execution of this ``load`` with other
10011:ref:`volatile operations <volatile>`.
10012
10013If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering
10014<ordering>` and optional ``syncscope("<target-scope>")`` argument. The
10015``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions.
10016Atomic loads produce :ref:`defined <memmodel>` results when they may see
10017multiple atomic stores. The type of the pointee must be an integer, pointer, or
10018floating-point type whose bit width is a power of two greater than or equal to
10019eight and less than or equal to a target-specific size limit.  ``align`` must be
10020explicitly specified on atomic loads, and the load has undefined behavior if the
10021alignment is not set to a value which is at least the size in bytes of the
10022pointee. ``!nontemporal`` does not have any defined semantics for atomic loads.
10023
10024The optional constant ``align`` argument specifies the alignment of the
10025operation (that is, the alignment of the memory address). A value of 0
10026or an omitted ``align`` argument means that the operation has the ABI
10027alignment for the target. It is the responsibility of the code emitter
10028to ensure that the alignment information is correct. Overestimating the
10029alignment results in undefined behavior. Underestimating the alignment
10030may produce less efficient code. An alignment of 1 is always safe. The
10031maximum possible alignment is ``1 << 32``. An alignment value higher
10032than the size of the loaded type implies memory up to the alignment
10033value bytes can be safely loaded without trapping in the default
10034address space. Access of the high bytes can interfere with debugging
10035tools, so should not be accessed if the function has the
10036``sanitize_thread`` or ``sanitize_address`` attributes.
10037
10038The optional ``!nontemporal`` metadata must reference a single
10039metadata name ``<nontemp_node>`` corresponding to a metadata node with one
10040``i32`` entry of value 1. The existence of the ``!nontemporal``
10041metadata on the instruction tells the optimizer and code generator
10042that this load is not expected to be reused in the cache. The code
10043generator may select special instructions to save cache bandwidth, such
10044as the ``MOVNT`` instruction on x86.
10045
10046The optional ``!invariant.load`` metadata must reference a single
10047metadata name ``<empty_node>`` corresponding to a metadata node with no
10048entries. If a load instruction tagged with the ``!invariant.load``
10049metadata is executed, the memory location referenced by the load has
10050to contain the same value at all points in the program where the
10051memory location is dereferenceable; otherwise, the behavior is
10052undefined.
10053
10054The optional ``!invariant.group`` metadata must reference a single metadata name
10055 ``<empty_node>`` corresponding to a metadata node with no entries.
10056 See ``invariant.group`` metadata :ref:`invariant.group <md_invariant.group>`.
10057
10058The optional ``!nonnull`` metadata must reference a single
10059metadata name ``<empty_node>`` corresponding to a metadata node with no
10060entries. The existence of the ``!nonnull`` metadata on the
10061instruction tells the optimizer that the value loaded is known to
10062never be null. If the value is null at runtime, the behavior is undefined.
10063This is analogous to the ``nonnull`` attribute on parameters and return
10064values. This metadata can only be applied to loads of a pointer type.
10065
10066The optional ``!dereferenceable`` metadata must reference a single metadata
10067name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
10068entry.
10069See ``dereferenceable`` metadata :ref:`dereferenceable <md_dereferenceable>`.
10070
10071The optional ``!dereferenceable_or_null`` metadata must reference a single
10072metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
10073``i64`` entry.
10074See ``dereferenceable_or_null`` metadata :ref:`dereferenceable_or_null
10075<md_dereferenceable_or_null>`.
10076
10077The optional ``!align`` metadata must reference a single metadata name
10078``<align_node>`` corresponding to a metadata node with one ``i64`` entry.
10079The existence of the ``!align`` metadata on the instruction tells the
10080optimizer that the value loaded is known to be aligned to a boundary specified
10081by the integer value in the metadata node. The alignment must be a power of 2.
10082This is analogous to the ''align'' attribute on parameters and return values.
10083This metadata can only be applied to loads of a pointer type. If the returned
10084value is not appropriately aligned at runtime, the behavior is undefined.
10085
10086The optional ``!noundef`` metadata must reference a single metadata name
10087``<empty_node>`` corresponding to a node with no entries. The existence of
10088``!noundef`` metadata on the instruction tells the optimizer that the value
10089loaded is known to be :ref:`well defined <welldefinedvalues>`.
10090If the value isn't well defined, the behavior is undefined.
10091
10092Semantics:
10093""""""""""
10094
10095The location of memory pointed to is loaded. If the value being loaded
10096is of scalar type then the number of bytes read does not exceed the
10097minimum number of bytes needed to hold all bits of the type. For
10098example, loading an ``i24`` reads at most three bytes. When loading a
10099value of a type like ``i20`` with a size that is not an integral number
10100of bytes, the result is undefined if the value was not originally
10101written using a store of the same type.
10102If the value being loaded is of aggregate type, the bytes that correspond to
10103padding may be accessed but are ignored, because it is impossible to observe
10104padding from the loaded aggregate value.
10105If ``<pointer>`` is not a well-defined value, the behavior is undefined.
10106
10107Examples:
10108"""""""""
10109
10110.. code-block:: llvm
10111
10112      %ptr = alloca i32                               ; yields i32*:ptr
10113      store i32 3, i32* %ptr                          ; yields void
10114      %val = load i32, i32* %ptr                      ; yields i32:val = i32 3
10115
10116.. _i_store:
10117
10118'``store``' Instruction
10119^^^^^^^^^^^^^^^^^^^^^^^
10120
10121Syntax:
10122"""""""
10123
10124::
10125
10126      store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<nontemp_node>][, !invariant.group !<empty_node>]        ; yields void
10127      store atomic [volatile] <ty> <value>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>] ; yields void
10128      !<nontemp_node> = !{ i32 1 }
10129      !<empty_node> = !{}
10130
10131Overview:
10132"""""""""
10133
10134The '``store``' instruction is used to write to memory.
10135
10136Arguments:
10137""""""""""
10138
10139There are two arguments to the ``store`` instruction: a value to store and an
10140address at which to store it. The type of the ``<pointer>`` operand must be a
10141pointer to the :ref:`first class <t_firstclass>` type of the ``<value>``
10142operand. If the ``store`` is marked as ``volatile``, then the optimizer is not
10143allowed to modify the number or order of execution of this ``store`` with other
10144:ref:`volatile operations <volatile>`.  Only values of :ref:`first class
10145<t_firstclass>` types of known size (i.e. not containing an :ref:`opaque
10146structural type <t_opaque>`) can be stored.
10147
10148If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering
10149<ordering>` and optional ``syncscope("<target-scope>")`` argument. The
10150``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions.
10151Atomic loads produce :ref:`defined <memmodel>` results when they may see
10152multiple atomic stores. The type of the pointee must be an integer, pointer, or
10153floating-point type whose bit width is a power of two greater than or equal to
10154eight and less than or equal to a target-specific size limit.  ``align`` must be
10155explicitly specified on atomic stores, and the store has undefined behavior if
10156the alignment is not set to a value which is at least the size in bytes of the
10157pointee. ``!nontemporal`` does not have any defined semantics for atomic stores.
10158
10159The optional constant ``align`` argument specifies the alignment of the
10160operation (that is, the alignment of the memory address). A value of 0
10161or an omitted ``align`` argument means that the operation has the ABI
10162alignment for the target. It is the responsibility of the code emitter
10163to ensure that the alignment information is correct. Overestimating the
10164alignment results in undefined behavior. Underestimating the
10165alignment may produce less efficient code. An alignment of 1 is always
10166safe. The maximum possible alignment is ``1 << 32``. An alignment
10167value higher than the size of the stored type implies memory up to the
10168alignment value bytes can be stored to without trapping in the default
10169address space. Storing to the higher bytes however may result in data
10170races if another thread can access the same address. Introducing a
10171data race is not allowed. Storing to the extra bytes is not allowed
10172even in situations where a data race is known to not exist if the
10173function has the ``sanitize_address`` attribute.
10174
10175The optional ``!nontemporal`` metadata must reference a single metadata
10176name ``<nontemp_node>`` corresponding to a metadata node with one ``i32`` entry
10177of value 1. The existence of the ``!nontemporal`` metadata on the instruction
10178tells the optimizer and code generator that this load is not expected to
10179be reused in the cache. The code generator may select special
10180instructions to save cache bandwidth, such as the ``MOVNT`` instruction on
10181x86.
10182
10183The optional ``!invariant.group`` metadata must reference a
10184single metadata name ``<empty_node>``. See ``invariant.group`` metadata.
10185
10186Semantics:
10187""""""""""
10188
10189The contents of memory are updated to contain ``<value>`` at the
10190location specified by the ``<pointer>`` operand. If ``<value>`` is
10191of scalar type then the number of bytes written does not exceed the
10192minimum number of bytes needed to hold all bits of the type. For
10193example, storing an ``i24`` writes at most three bytes. When writing a
10194value of a type like ``i20`` with a size that is not an integral number
10195of bytes, it is unspecified what happens to the extra bits that do not
10196belong to the type, but they will typically be overwritten.
10197If ``<value>`` is of aggregate type, padding is filled with
10198:ref:`undef <undefvalues>`.
10199If ``<pointer>`` is not a well-defined value, the behavior is undefined.
10200
10201Example:
10202""""""""
10203
10204.. code-block:: llvm
10205
10206      %ptr = alloca i32                               ; yields i32*:ptr
10207      store i32 3, i32* %ptr                          ; yields void
10208      %val = load i32, i32* %ptr                      ; yields i32:val = i32 3
10209
10210.. _i_fence:
10211
10212'``fence``' Instruction
10213^^^^^^^^^^^^^^^^^^^^^^^
10214
10215Syntax:
10216"""""""
10217
10218::
10219
10220      fence [syncscope("<target-scope>")] <ordering>  ; yields void
10221
10222Overview:
10223"""""""""
10224
10225The '``fence``' instruction is used to introduce happens-before edges
10226between operations.
10227
10228Arguments:
10229""""""""""
10230
10231'``fence``' instructions take an :ref:`ordering <ordering>` argument which
10232defines what *synchronizes-with* edges they add. They can only be given
10233``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings.
10234
10235Semantics:
10236""""""""""
10237
10238A fence A which has (at least) ``release`` ordering semantics
10239*synchronizes with* a fence B with (at least) ``acquire`` ordering
10240semantics if and only if there exist atomic operations X and Y, both
10241operating on some atomic object M, such that A is sequenced before X, X
10242modifies M (either directly or through some side effect of a sequence
10243headed by X), Y is sequenced before B, and Y observes M. This provides a
10244*happens-before* dependency between A and B. Rather than an explicit
10245``fence``, one (but not both) of the atomic operations X or Y might
10246provide a ``release`` or ``acquire`` (resp.) ordering constraint and
10247still *synchronize-with* the explicit ``fence`` and establish the
10248*happens-before* edge.
10249
10250A ``fence`` which has ``seq_cst`` ordering, in addition to having both
10251``acquire`` and ``release`` semantics specified above, participates in
10252the global program order of other ``seq_cst`` operations and/or fences.
10253
10254A ``fence`` instruction can also take an optional
10255":ref:`syncscope <syncscope>`" argument.
10256
10257Example:
10258""""""""
10259
10260.. code-block:: text
10261
10262      fence acquire                                        ; yields void
10263      fence syncscope("singlethread") seq_cst              ; yields void
10264      fence syncscope("agent") seq_cst                     ; yields void
10265
10266.. _i_cmpxchg:
10267
10268'``cmpxchg``' Instruction
10269^^^^^^^^^^^^^^^^^^^^^^^^^
10270
10271Syntax:
10272"""""""
10273
10274::
10275
10276      cmpxchg [weak] [volatile] <ty>* <pointer>, <ty> <cmp>, <ty> <new> [syncscope("<target-scope>")] <success ordering> <failure ordering>[, align <alignment>] ; yields  { ty, i1 }
10277
10278Overview:
10279"""""""""
10280
10281The '``cmpxchg``' instruction is used to atomically modify memory. It
10282loads a value in memory and compares it to a given value. If they are
10283equal, it tries to store a new value into the memory.
10284
10285Arguments:
10286""""""""""
10287
10288There are three arguments to the '``cmpxchg``' instruction: an address
10289to operate on, a value to compare to the value currently be at that
10290address, and a new value to place at that address if the compared values
10291are equal. The type of '<cmp>' must be an integer or pointer type whose
10292bit width is a power of two greater than or equal to eight and less
10293than or equal to a target-specific size limit. '<cmp>' and '<new>' must
10294have the same type, and the type of '<pointer>' must be a pointer to
10295that type. If the ``cmpxchg`` is marked as ``volatile``, then the
10296optimizer is not allowed to modify the number or order of execution of
10297this ``cmpxchg`` with other :ref:`volatile operations <volatile>`.
10298
10299The success and failure :ref:`ordering <ordering>` arguments specify how this
10300``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters
10301must be at least ``monotonic``, the failure ordering cannot be either
10302``release`` or ``acq_rel``.
10303
10304A ``cmpxchg`` instruction can also take an optional
10305":ref:`syncscope <syncscope>`" argument.
10306
10307The instruction can take an optional ``align`` attribute.
10308The alignment must be a power of two greater or equal to the size of the
10309`<value>` type. If unspecified, the alignment is assumed to be equal to the
10310size of the '<value>' type. Note that this default alignment assumption is
10311different from the alignment used for the load/store instructions when align
10312isn't specified.
10313
10314The pointer passed into cmpxchg must have alignment greater than or
10315equal to the size in memory of the operand.
10316
10317Semantics:
10318""""""""""
10319
10320The contents of memory at the location specified by the '``<pointer>``' operand
10321is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is
10322written to the location. The original value at the location is returned,
10323together with a flag indicating success (true) or failure (false).
10324
10325If the cmpxchg operation is marked as ``weak`` then a spurious failure is
10326permitted: the operation may not write ``<new>`` even if the comparison
10327matched.
10328
10329If the cmpxchg operation is strong (the default), the i1 value is 1 if and only
10330if the value loaded equals ``cmp``.
10331
10332A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of
10333identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic
10334load with an ordering parameter determined the second ordering parameter.
10335
10336Example:
10337""""""""
10338
10339.. code-block:: llvm
10340
10341    entry:
10342      %orig = load atomic i32, i32* %ptr unordered, align 4                      ; yields i32
10343      br label %loop
10344
10345    loop:
10346      %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop]
10347      %squared = mul i32 %cmp, %cmp
10348      %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields  { i32, i1 }
10349      %value_loaded = extractvalue { i32, i1 } %val_success, 0
10350      %success = extractvalue { i32, i1 } %val_success, 1
10351      br i1 %success, label %done, label %loop
10352
10353    done:
10354      ...
10355
10356.. _i_atomicrmw:
10357
10358'``atomicrmw``' Instruction
10359^^^^^^^^^^^^^^^^^^^^^^^^^^^
10360
10361Syntax:
10362"""""""
10363
10364::
10365
10366      atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering>[, align <alignment>]  ; yields ty
10367
10368Overview:
10369"""""""""
10370
10371The '``atomicrmw``' instruction is used to atomically modify memory.
10372
10373Arguments:
10374""""""""""
10375
10376There are three arguments to the '``atomicrmw``' instruction: an
10377operation to apply, an address whose value to modify, an argument to the
10378operation. The operation must be one of the following keywords:
10379
10380-  xchg
10381-  add
10382-  sub
10383-  and
10384-  nand
10385-  or
10386-  xor
10387-  max
10388-  min
10389-  umax
10390-  umin
10391-  fadd
10392-  fsub
10393-  fmax
10394-  fmin
10395
10396For most of these operations, the type of '<value>' must be an integer
10397type whose bit width is a power of two greater than or equal to eight
10398and less than or equal to a target-specific size limit. For xchg, this
10399may also be a floating point or a pointer type with the same size constraints
10400as integers.  For fadd/fsub/fmax/fmin, this must be a floating point type.  The
10401type of the '``<pointer>``' operand must be a pointer to that type. If
10402the ``atomicrmw`` is marked as ``volatile``, then the optimizer is not
10403allowed to modify the number or order of execution of this
10404``atomicrmw`` with other :ref:`volatile operations <volatile>`.
10405
10406The instruction can take an optional ``align`` attribute.
10407The alignment must be a power of two greater or equal to the size of the
10408`<value>` type. If unspecified, the alignment is assumed to be equal to the
10409size of the '<value>' type. Note that this default alignment assumption is
10410different from the alignment used for the load/store instructions when align
10411isn't specified.
10412
10413A ``atomicrmw`` instruction can also take an optional
10414":ref:`syncscope <syncscope>`" argument.
10415
10416Semantics:
10417""""""""""
10418
10419The contents of memory at the location specified by the '``<pointer>``'
10420operand are atomically read, modified, and written back. The original
10421value at the location is returned. The modification is specified by the
10422operation argument:
10423
10424-  xchg: ``*ptr = val``
10425-  add: ``*ptr = *ptr + val``
10426-  sub: ``*ptr = *ptr - val``
10427-  and: ``*ptr = *ptr & val``
10428-  nand: ``*ptr = ~(*ptr & val)``
10429-  or: ``*ptr = *ptr | val``
10430-  xor: ``*ptr = *ptr ^ val``
10431-  max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison)
10432-  min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison)
10433-  umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned comparison)
10434-  umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned comparison)
10435- fadd: ``*ptr = *ptr + val`` (using floating point arithmetic)
10436- fsub: ``*ptr = *ptr - val`` (using floating point arithmetic)
10437-  fmax: ``*ptr = maxnum(*ptr, val)`` (match the `llvm.maxnum.*`` intrinsic)
10438-  fmin: ``*ptr = minnum(*ptr, val)`` (match the `llvm.minnum.*`` intrinsic)
10439
10440Example:
10441""""""""
10442
10443.. code-block:: llvm
10444
10445      %old = atomicrmw add i32* %ptr, i32 1 acquire                        ; yields i32
10446
10447.. _i_getelementptr:
10448
10449'``getelementptr``' Instruction
10450^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10451
10452Syntax:
10453"""""""
10454
10455::
10456
10457      <result> = getelementptr <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
10458      <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
10459      <result> = getelementptr <ty>, <ptr vector> <ptrval>, [inrange] <vector index type> <idx>
10460
10461Overview:
10462"""""""""
10463
10464The '``getelementptr``' instruction is used to get the address of a
10465subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs
10466address calculation only and does not access memory. The instruction can also
10467be used to calculate a vector of such addresses.
10468
10469Arguments:
10470""""""""""
10471
10472The first argument is always a type used as the basis for the calculations.
10473The second argument is always a pointer or a vector of pointers, and is the
10474base address to start from. The remaining arguments are indices
10475that indicate which of the elements of the aggregate object are indexed.
10476The interpretation of each index is dependent on the type being indexed
10477into. The first index always indexes the pointer value given as the
10478second argument, the second index indexes a value of the type pointed to
10479(not necessarily the value directly pointed to, since the first index
10480can be non-zero), etc. The first type indexed into must be a pointer
10481value, subsequent types can be arrays, vectors, and structs. Note that
10482subsequent types being indexed into can never be pointers, since that
10483would require loading the pointer before continuing calculation.
10484
10485The type of each index argument depends on the type it is indexing into.
10486When indexing into a (optionally packed) structure, only ``i32`` integer
10487**constants** are allowed (when using a vector of indices they must all
10488be the **same** ``i32`` integer constant). When indexing into an array,
10489pointer or vector, integers of any width are allowed, and they are not
10490required to be constant. These integers are treated as signed values
10491where relevant.
10492
10493For example, let's consider a C code fragment and how it gets compiled
10494to LLVM:
10495
10496.. code-block:: c
10497
10498    struct RT {
10499      char A;
10500      int B[10][20];
10501      char C;
10502    };
10503    struct ST {
10504      int X;
10505      double Y;
10506      struct RT Z;
10507    };
10508
10509    int *foo(struct ST *s) {
10510      return &s[1].Z.B[5][13];
10511    }
10512
10513The LLVM code generated by Clang is:
10514
10515.. code-block:: llvm
10516
10517    %struct.RT = type { i8, [10 x [20 x i32]], i8 }
10518    %struct.ST = type { i32, double, %struct.RT }
10519
10520    define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
10521    entry:
10522      %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13
10523      ret i32* %arrayidx
10524    }
10525
10526Semantics:
10527""""""""""
10528
10529In the example above, the first index is indexing into the
10530'``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``'
10531= '``{ i32, double, %struct.RT }``' type, a structure. The second index
10532indexes into the third element of the structure, yielding a
10533'``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another
10534structure. The third index indexes into the second element of the
10535structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two
10536dimensions of the array are subscripted into, yielding an '``i32``'
10537type. The '``getelementptr``' instruction returns a pointer to this
10538element, thus computing a value of '``i32*``' type.
10539
10540Note that it is perfectly legal to index partially through a structure,
10541returning a pointer to an inner element. Because of this, the LLVM code
10542for the given testcase is equivalent to:
10543
10544.. code-block:: llvm
10545
10546    define i32* @foo(%struct.ST* %s) {
10547      %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1                        ; yields %struct.ST*:%t1
10548      %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2                ; yields %struct.RT*:%t2
10549      %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1                ; yields [10 x [20 x i32]]*:%t3
10550      %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5  ; yields [20 x i32]*:%t4
10551      %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13               ; yields i32*:%t5
10552      ret i32* %t5
10553    }
10554
10555If the ``inbounds`` keyword is present, the result value of the
10556``getelementptr`` is a :ref:`poison value <poisonvalues>` if one of the
10557following rules is violated:
10558
10559*  The base pointer has an *in bounds* address of an allocated object, which
10560   means that it points into an allocated object, or to its end. The only
10561   *in bounds* address for a null pointer in the default address-space is the
10562   null pointer itself.
10563*  If the type of an index is larger than the pointer index type, the
10564   truncation to the pointer index type preserves the signed value.
10565*  The multiplication of an index by the type size does not wrap the pointer
10566   index type in a signed sense (``nsw``).
10567*  The successive addition of offsets (without adding the base address) does
10568   not wrap the pointer index type in a signed sense (``nsw``).
10569*  The successive addition of the current address, interpreted as an unsigned
10570   number, and an offset, interpreted as a signed number, does not wrap the
10571   unsigned address space and remains *in bounds* of the allocated object.
10572   As a corollary, if the added offset is non-negative, the addition does not
10573   wrap in an unsigned sense (``nuw``).
10574*  In cases where the base is a vector of pointers, the ``inbounds`` keyword
10575   applies to each of the computations element-wise.
10576
10577These rules are based on the assumption that no allocated object may cross
10578the unsigned address space boundary, and no allocated object may be larger
10579than half the pointer index type space.
10580
10581If the ``inbounds`` keyword is not present, the offsets are added to the
10582base address with silently-wrapping two's complement arithmetic. If the
10583offsets have a different width from the pointer, they are sign-extended
10584or truncated to the width of the pointer. The result value of the
10585``getelementptr`` may be outside the object pointed to by the base
10586pointer. The result value may not necessarily be used to access memory
10587though, even if it happens to point into allocated storage. See the
10588:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more
10589information.
10590
10591If the ``inrange`` keyword is present before any index, loading from or
10592storing to any pointer derived from the ``getelementptr`` has undefined
10593behavior if the load or store would access memory outside of the bounds of
10594the element selected by the index marked as ``inrange``. The result of a
10595pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations
10596involving memory) involving a pointer derived from a ``getelementptr`` with
10597the ``inrange`` keyword is undefined, with the exception of comparisons
10598in the case where both operands are in the range of the element selected
10599by the ``inrange`` keyword, inclusive of the address one past the end of
10600that element. Note that the ``inrange`` keyword is currently only allowed
10601in constant ``getelementptr`` expressions.
10602
10603The getelementptr instruction is often confusing. For some more insight
10604into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`.
10605
10606Example:
10607""""""""
10608
10609.. code-block:: llvm
10610
10611        ; yields [12 x i8]*:aptr
10612        %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1
10613        ; yields i8*:vptr
10614        %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1
10615        ; yields i8*:eptr
10616        %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1
10617        ; yields i32*:iptr
10618        %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0
10619
10620Vector of pointers:
10621"""""""""""""""""""
10622
10623The ``getelementptr`` returns a vector of pointers, instead of a single address,
10624when one or more of its arguments is a vector. In such cases, all vector
10625arguments should have the same number of elements, and every scalar argument
10626will be effectively broadcast into a vector during address calculation.
10627
10628.. code-block:: llvm
10629
10630     ; All arguments are vectors:
10631     ;   A[i] = ptrs[i] + offsets[i]*sizeof(i8)
10632     %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets
10633
10634     ; Add the same scalar offset to each pointer of a vector:
10635     ;   A[i] = ptrs[i] + offset*sizeof(i8)
10636     %A = getelementptr i8, <4 x i8*> %ptrs, i64 %offset
10637
10638     ; Add distinct offsets to the same pointer:
10639     ;   A[i] = ptr + offsets[i]*sizeof(i8)
10640     %A = getelementptr i8, i8* %ptr, <4 x i64> %offsets
10641
10642     ; In all cases described above the type of the result is <4 x i8*>
10643
10644The two following instructions are equivalent:
10645
10646.. code-block:: llvm
10647
10648     getelementptr  %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
10649       <4 x i32> <i32 2, i32 2, i32 2, i32 2>,
10650       <4 x i32> <i32 1, i32 1, i32 1, i32 1>,
10651       <4 x i32> %ind4,
10652       <4 x i64> <i64 13, i64 13, i64 13, i64 13>
10653
10654     getelementptr  %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
10655       i32 2, i32 1, <4 x i32> %ind4, i64 13
10656
10657Let's look at the C code, where the vector version of ``getelementptr``
10658makes sense:
10659
10660.. code-block:: c
10661
10662    // Let's assume that we vectorize the following loop:
10663    double *A, *B; int *C;
10664    for (int i = 0; i < size; ++i) {
10665      A[i] = B[C[i]];
10666    }
10667
10668.. code-block:: llvm
10669
10670    ; get pointers for 8 elements from array B
10671    %ptrs = getelementptr double, double* %B, <8 x i32> %C
10672    ; load 8 elements from array B into A
10673    %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x double*> %ptrs,
10674         i32 8, <8 x i1> %mask, <8 x double> %passthru)
10675
10676Conversion Operations
10677---------------------
10678
10679The instructions in this category are the conversion instructions
10680(casting) which all take a single operand and a type. They perform
10681various bit conversions on the operand.
10682
10683.. _i_trunc:
10684
10685'``trunc .. to``' Instruction
10686^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10687
10688Syntax:
10689"""""""
10690
10691::
10692
10693      <result> = trunc <ty> <value> to <ty2>             ; yields ty2
10694
10695Overview:
10696"""""""""
10697
10698The '``trunc``' instruction truncates its operand to the type ``ty2``.
10699
10700Arguments:
10701""""""""""
10702
10703The '``trunc``' instruction takes a value to trunc, and a type to trunc
10704it to. Both types must be of :ref:`integer <t_integer>` types, or vectors
10705of the same number of integers. The bit size of the ``value`` must be
10706larger than the bit size of the destination type, ``ty2``. Equal sized
10707types are not allowed.
10708
10709Semantics:
10710""""""""""
10711
10712The '``trunc``' instruction truncates the high order bits in ``value``
10713and converts the remaining bits to ``ty2``. Since the source size must
10714be larger than the destination size, ``trunc`` cannot be a *no-op cast*.
10715It will always truncate bits.
10716
10717Example:
10718""""""""
10719
10720.. code-block:: llvm
10721
10722      %X = trunc i32 257 to i8                        ; yields i8:1
10723      %Y = trunc i32 123 to i1                        ; yields i1:true
10724      %Z = trunc i32 122 to i1                        ; yields i1:false
10725      %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7>
10726
10727.. _i_zext:
10728
10729'``zext .. to``' Instruction
10730^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10731
10732Syntax:
10733"""""""
10734
10735::
10736
10737      <result> = zext <ty> <value> to <ty2>             ; yields ty2
10738
10739Overview:
10740"""""""""
10741
10742The '``zext``' instruction zero extends its operand to type ``ty2``.
10743
10744Arguments:
10745""""""""""
10746
10747The '``zext``' instruction takes a value to cast, and a type to cast it
10748to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
10749the same number of integers. The bit size of the ``value`` must be
10750smaller than the bit size of the destination type, ``ty2``.
10751
10752Semantics:
10753""""""""""
10754
10755The ``zext`` fills the high order bits of the ``value`` with zero bits
10756until it reaches the size of the destination type, ``ty2``.
10757
10758When zero extending from i1, the result will always be either 0 or 1.
10759
10760Example:
10761""""""""
10762
10763.. code-block:: llvm
10764
10765      %X = zext i32 257 to i64              ; yields i64:257
10766      %Y = zext i1 true to i32              ; yields i32:1
10767      %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
10768
10769.. _i_sext:
10770
10771'``sext .. to``' Instruction
10772^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10773
10774Syntax:
10775"""""""
10776
10777::
10778
10779      <result> = sext <ty> <value> to <ty2>             ; yields ty2
10780
10781Overview:
10782"""""""""
10783
10784The '``sext``' sign extends ``value`` to the type ``ty2``.
10785
10786Arguments:
10787""""""""""
10788
10789The '``sext``' instruction takes a value to cast, and a type to cast it
10790to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
10791the same number of integers. The bit size of the ``value`` must be
10792smaller than the bit size of the destination type, ``ty2``.
10793
10794Semantics:
10795""""""""""
10796
10797The '``sext``' instruction performs a sign extension by copying the sign
10798bit (highest order bit) of the ``value`` until it reaches the bit size
10799of the type ``ty2``.
10800
10801When sign extending from i1, the extension always results in -1 or 0.
10802
10803Example:
10804""""""""
10805
10806.. code-block:: llvm
10807
10808      %X = sext i8  -1 to i16              ; yields i16   :65535
10809      %Y = sext i1 true to i32             ; yields i32:-1
10810      %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
10811
10812'``fptrunc .. to``' Instruction
10813^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10814
10815Syntax:
10816"""""""
10817
10818::
10819
10820      <result> = fptrunc <ty> <value> to <ty2>             ; yields ty2
10821
10822Overview:
10823"""""""""
10824
10825The '``fptrunc``' instruction truncates ``value`` to type ``ty2``.
10826
10827Arguments:
10828""""""""""
10829
10830The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>`
10831value to cast and a :ref:`floating-point <t_floating>` type to cast it to.
10832The size of ``value`` must be larger than the size of ``ty2``. This
10833implies that ``fptrunc`` cannot be used to make a *no-op cast*.
10834
10835Semantics:
10836""""""""""
10837
10838The '``fptrunc``' instruction casts a ``value`` from a larger
10839:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
10840<t_floating>` type.
10841This instruction is assumed to execute in the default :ref:`floating-point
10842environment <floatenv>`.
10843
10844Example:
10845""""""""
10846
10847.. code-block:: llvm
10848
10849      %X = fptrunc double 16777217.0 to float    ; yields float:16777216.0
10850      %Y = fptrunc double 1.0E+300 to half       ; yields half:+infinity
10851
10852'``fpext .. to``' Instruction
10853^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10854
10855Syntax:
10856"""""""
10857
10858::
10859
10860      <result> = fpext <ty> <value> to <ty2>             ; yields ty2
10861
10862Overview:
10863"""""""""
10864
10865The '``fpext``' extends a floating-point ``value`` to a larger floating-point
10866value.
10867
10868Arguments:
10869""""""""""
10870
10871The '``fpext``' instruction takes a :ref:`floating-point <t_floating>`
10872``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it
10873to. The source type must be smaller than the destination type.
10874
10875Semantics:
10876""""""""""
10877
10878The '``fpext``' instruction extends the ``value`` from a smaller
10879:ref:`floating-point <t_floating>` type to a larger :ref:`floating-point
10880<t_floating>` type. The ``fpext`` cannot be used to make a
10881*no-op cast* because it always changes bits. Use ``bitcast`` to make a
10882*no-op cast* for a floating-point cast.
10883
10884Example:
10885""""""""
10886
10887.. code-block:: llvm
10888
10889      %X = fpext float 3.125 to double         ; yields double:3.125000e+00
10890      %Y = fpext double %X to fp128            ; yields fp128:0xL00000000000000004000900000000000
10891
10892'``fptoui .. to``' Instruction
10893^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10894
10895Syntax:
10896"""""""
10897
10898::
10899
10900      <result> = fptoui <ty> <value> to <ty2>             ; yields ty2
10901
10902Overview:
10903"""""""""
10904
10905The '``fptoui``' converts a floating-point ``value`` to its unsigned
10906integer equivalent of type ``ty2``.
10907
10908Arguments:
10909""""""""""
10910
10911The '``fptoui``' instruction takes a value to cast, which must be a
10912scalar or vector :ref:`floating-point <t_floating>` value, and a type to
10913cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
10914``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
10915type with the same number of elements as ``ty``
10916
10917Semantics:
10918""""""""""
10919
10920The '``fptoui``' instruction converts its :ref:`floating-point
10921<t_floating>` operand into the nearest (rounding towards zero)
10922unsigned integer value. If the value cannot fit in ``ty2``, the result
10923is a :ref:`poison value <poisonvalues>`.
10924
10925Example:
10926""""""""
10927
10928.. code-block:: llvm
10929
10930      %X = fptoui double 123.0 to i32      ; yields i32:123
10931      %Y = fptoui float 1.0E+300 to i1     ; yields undefined:1
10932      %Z = fptoui float 1.04E+17 to i8     ; yields undefined:1
10933
10934'``fptosi .. to``' Instruction
10935^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10936
10937Syntax:
10938"""""""
10939
10940::
10941
10942      <result> = fptosi <ty> <value> to <ty2>             ; yields ty2
10943
10944Overview:
10945"""""""""
10946
10947The '``fptosi``' instruction converts :ref:`floating-point <t_floating>`
10948``value`` to type ``ty2``.
10949
10950Arguments:
10951""""""""""
10952
10953The '``fptosi``' instruction takes a value to cast, which must be a
10954scalar or vector :ref:`floating-point <t_floating>` value, and a type to
10955cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
10956``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
10957type with the same number of elements as ``ty``
10958
10959Semantics:
10960""""""""""
10961
10962The '``fptosi``' instruction converts its :ref:`floating-point
10963<t_floating>` operand into the nearest (rounding towards zero)
10964signed integer value. If the value cannot fit in ``ty2``, the result
10965is a :ref:`poison value <poisonvalues>`.
10966
10967Example:
10968""""""""
10969
10970.. code-block:: llvm
10971
10972      %X = fptosi double -123.0 to i32      ; yields i32:-123
10973      %Y = fptosi float 1.0E-247 to i1      ; yields undefined:1
10974      %Z = fptosi float 1.04E+17 to i8      ; yields undefined:1
10975
10976'``uitofp .. to``' Instruction
10977^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10978
10979Syntax:
10980"""""""
10981
10982::
10983
10984      <result> = uitofp <ty> <value> to <ty2>             ; yields ty2
10985
10986Overview:
10987"""""""""
10988
10989The '``uitofp``' instruction regards ``value`` as an unsigned integer
10990and converts that value to the ``ty2`` type.
10991
10992Arguments:
10993""""""""""
10994
10995The '``uitofp``' instruction takes a value to cast, which must be a
10996scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
10997``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
10998``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
10999type with the same number of elements as ``ty``
11000
11001Semantics:
11002""""""""""
11003
11004The '``uitofp``' instruction interprets its operand as an unsigned
11005integer quantity and converts it to the corresponding floating-point
11006value. If the value cannot be exactly represented, it is rounded using
11007the default rounding mode.
11008
11009
11010Example:
11011""""""""
11012
11013.. code-block:: llvm
11014
11015      %X = uitofp i32 257 to float         ; yields float:257.0
11016      %Y = uitofp i8 -1 to double          ; yields double:255.0
11017
11018'``sitofp .. to``' Instruction
11019^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11020
11021Syntax:
11022"""""""
11023
11024::
11025
11026      <result> = sitofp <ty> <value> to <ty2>             ; yields ty2
11027
11028Overview:
11029"""""""""
11030
11031The '``sitofp``' instruction regards ``value`` as a signed integer and
11032converts that value to the ``ty2`` type.
11033
11034Arguments:
11035""""""""""
11036
11037The '``sitofp``' instruction takes a value to cast, which must be a
11038scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
11039``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
11040``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
11041type with the same number of elements as ``ty``
11042
11043Semantics:
11044""""""""""
11045
11046The '``sitofp``' instruction interprets its operand as a signed integer
11047quantity and converts it to the corresponding floating-point value. If the
11048value cannot be exactly represented, it is rounded using the default rounding
11049mode.
11050
11051Example:
11052""""""""
11053
11054.. code-block:: llvm
11055
11056      %X = sitofp i32 257 to float         ; yields float:257.0
11057      %Y = sitofp i8 -1 to double          ; yields double:-1.0
11058
11059.. _i_ptrtoint:
11060
11061'``ptrtoint .. to``' Instruction
11062^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11063
11064Syntax:
11065"""""""
11066
11067::
11068
11069      <result> = ptrtoint <ty> <value> to <ty2>             ; yields ty2
11070
11071Overview:
11072"""""""""
11073
11074The '``ptrtoint``' instruction converts the pointer or a vector of
11075pointers ``value`` to the integer (or vector of integers) type ``ty2``.
11076
11077Arguments:
11078""""""""""
11079
11080The '``ptrtoint``' instruction takes a ``value`` to cast, which must be
11081a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
11082type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
11083a vector of integers type.
11084
11085Semantics:
11086""""""""""
11087
11088The '``ptrtoint``' instruction converts ``value`` to integer type
11089``ty2`` by interpreting the pointer value as an integer and either
11090truncating or zero extending that value to the size of the integer type.
11091If ``value`` is smaller than ``ty2`` then a zero extension is done. If
11092``value`` is larger than ``ty2`` then a truncation is done. If they are
11093the same size, then nothing is done (*no-op cast*) other than a type
11094change.
11095
11096Example:
11097""""""""
11098
11099.. code-block:: llvm
11100
11101      %X = ptrtoint i32* %P to i8                         ; yields truncation on 32-bit architecture
11102      %Y = ptrtoint i32* %P to i64                        ; yields zero extension on 32-bit architecture
11103      %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
11104
11105.. _i_inttoptr:
11106
11107'``inttoptr .. to``' Instruction
11108^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11109
11110Syntax:
11111"""""""
11112
11113::
11114
11115      <result> = inttoptr <ty> <value> to <ty2>[, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>]             ; yields ty2
11116
11117Overview:
11118"""""""""
11119
11120The '``inttoptr``' instruction converts an integer ``value`` to a
11121pointer type, ``ty2``.
11122
11123Arguments:
11124""""""""""
11125
11126The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to
11127cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>`
11128type.
11129
11130The optional ``!dereferenceable`` metadata must reference a single metadata
11131name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
11132entry.
11133See ``dereferenceable`` metadata.
11134
11135The optional ``!dereferenceable_or_null`` metadata must reference a single
11136metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
11137``i64`` entry.
11138See ``dereferenceable_or_null`` metadata.
11139
11140Semantics:
11141""""""""""
11142
11143The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by
11144applying either a zero extension or a truncation depending on the size
11145of the integer ``value``. If ``value`` is larger than the size of a
11146pointer then a truncation is done. If ``value`` is smaller than the size
11147of a pointer then a zero extension is done. If they are the same size,
11148nothing is done (*no-op cast*).
11149
11150Example:
11151""""""""
11152
11153.. code-block:: llvm
11154
11155      %X = inttoptr i32 255 to i32*          ; yields zero extension on 64-bit architecture
11156      %Y = inttoptr i32 255 to i32*          ; yields no-op on 32-bit architecture
11157      %Z = inttoptr i64 0 to i32*            ; yields truncation on 32-bit architecture
11158      %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers
11159
11160.. _i_bitcast:
11161
11162'``bitcast .. to``' Instruction
11163^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11164
11165Syntax:
11166"""""""
11167
11168::
11169
11170      <result> = bitcast <ty> <value> to <ty2>             ; yields ty2
11171
11172Overview:
11173"""""""""
11174
11175The '``bitcast``' instruction converts ``value`` to type ``ty2`` without
11176changing any bits.
11177
11178Arguments:
11179""""""""""
11180
11181The '``bitcast``' instruction takes a value to cast, which must be a
11182non-aggregate first class value, and a type to cast it to, which must
11183also be a non-aggregate :ref:`first class <t_firstclass>` type. The
11184bit sizes of ``value`` and the destination type, ``ty2``, must be
11185identical. If the source type is a pointer, the destination type must
11186also be a pointer of the same size. This instruction supports bitwise
11187conversion of vectors to integers and to vectors of other types (as
11188long as they have the same size).
11189
11190Semantics:
11191""""""""""
11192
11193The '``bitcast``' instruction converts ``value`` to type ``ty2``. It
11194is always a *no-op cast* because no bits change with this
11195conversion. The conversion is done as if the ``value`` had been stored
11196to memory and read back as type ``ty2``. Pointer (or vector of
11197pointers) types may only be converted to other pointer (or vector of
11198pointers) types with the same address space through this instruction.
11199To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>`
11200or :ref:`ptrtoint <i_ptrtoint>` instructions first.
11201
11202There is a caveat for bitcasts involving vector types in relation to
11203endianess. For example ``bitcast <2 x i8> <value> to i16`` puts element zero
11204of the vector in the least significant bits of the i16 for little-endian while
11205element zero ends up in the most significant bits for big-endian.
11206
11207Example:
11208""""""""
11209
11210.. code-block:: text
11211
11212      %X = bitcast i8 255 to i8          ; yields i8 :-1
11213      %Y = bitcast i32* %x to i16*      ; yields i16*:%x
11214      %Z = bitcast <2 x i32> %V to i64;  ; yields i64: %V (depends on endianess)
11215      %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
11216
11217.. _i_addrspacecast:
11218
11219'``addrspacecast .. to``' Instruction
11220^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11221
11222Syntax:
11223"""""""
11224
11225::
11226
11227      <result> = addrspacecast <pty> <ptrval> to <pty2>       ; yields pty2
11228
11229Overview:
11230"""""""""
11231
11232The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in
11233address space ``n`` to type ``pty2`` in address space ``m``.
11234
11235Arguments:
11236""""""""""
11237
11238The '``addrspacecast``' instruction takes a pointer or vector of pointer value
11239to cast and a pointer type to cast it to, which must have a different
11240address space.
11241
11242Semantics:
11243""""""""""
11244
11245The '``addrspacecast``' instruction converts the pointer value
11246``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex
11247value modification, depending on the target and the address space
11248pair. Pointer conversions within the same address space must be
11249performed with the ``bitcast`` instruction. Note that if the address space
11250conversion is legal then both result and operand refer to the same memory
11251location.
11252
11253Example:
11254""""""""
11255
11256.. code-block:: llvm
11257
11258      %X = addrspacecast i32* %x to i32 addrspace(1)*    ; yields i32 addrspace(1)*:%x
11259      %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)*    ; yields i64 addrspace(2)*:%y
11260      %Z = addrspacecast <4 x i32*> %z to <4 x float addrspace(3)*>   ; yields <4 x float addrspace(3)*>:%z
11261
11262.. _otherops:
11263
11264Other Operations
11265----------------
11266
11267The instructions in this category are the "miscellaneous" instructions,
11268which defy better classification.
11269
11270.. _i_icmp:
11271
11272'``icmp``' Instruction
11273^^^^^^^^^^^^^^^^^^^^^^
11274
11275Syntax:
11276"""""""
11277
11278::
11279
11280      <result> = icmp <cond> <ty> <op1>, <op2>   ; yields i1 or <N x i1>:result
11281
11282Overview:
11283"""""""""
11284
11285The '``icmp``' instruction returns a boolean value or a vector of
11286boolean values based on comparison of its two integer, integer vector,
11287pointer, or pointer vector operands.
11288
11289Arguments:
11290""""""""""
11291
11292The '``icmp``' instruction takes three operands. The first operand is
11293the condition code indicating the kind of comparison to perform. It is
11294not a value, just a keyword. The possible condition codes are:
11295
11296.. _icmp_md_cc:
11297
11298#. ``eq``: equal
11299#. ``ne``: not equal
11300#. ``ugt``: unsigned greater than
11301#. ``uge``: unsigned greater or equal
11302#. ``ult``: unsigned less than
11303#. ``ule``: unsigned less or equal
11304#. ``sgt``: signed greater than
11305#. ``sge``: signed greater or equal
11306#. ``slt``: signed less than
11307#. ``sle``: signed less or equal
11308
11309The remaining two arguments must be :ref:`integer <t_integer>` or
11310:ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They
11311must also be identical types.
11312
11313Semantics:
11314""""""""""
11315
11316The '``icmp``' compares ``op1`` and ``op2`` according to the condition
11317code given as ``cond``. The comparison performed always yields either an
11318:ref:`i1 <t_integer>` or vector of ``i1`` result, as follows:
11319
11320.. _icmp_md_cc_sem:
11321
11322#. ``eq``: yields ``true`` if the operands are equal, ``false``
11323   otherwise. No sign interpretation is necessary or performed.
11324#. ``ne``: yields ``true`` if the operands are unequal, ``false``
11325   otherwise. No sign interpretation is necessary or performed.
11326#. ``ugt``: interprets the operands as unsigned values and yields
11327   ``true`` if ``op1`` is greater than ``op2``.
11328#. ``uge``: interprets the operands as unsigned values and yields
11329   ``true`` if ``op1`` is greater than or equal to ``op2``.
11330#. ``ult``: interprets the operands as unsigned values and yields
11331   ``true`` if ``op1`` is less than ``op2``.
11332#. ``ule``: interprets the operands as unsigned values and yields
11333   ``true`` if ``op1`` is less than or equal to ``op2``.
11334#. ``sgt``: interprets the operands as signed values and yields ``true``
11335   if ``op1`` is greater than ``op2``.
11336#. ``sge``: interprets the operands as signed values and yields ``true``
11337   if ``op1`` is greater than or equal to ``op2``.
11338#. ``slt``: interprets the operands as signed values and yields ``true``
11339   if ``op1`` is less than ``op2``.
11340#. ``sle``: interprets the operands as signed values and yields ``true``
11341   if ``op1`` is less than or equal to ``op2``.
11342
11343If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
11344are compared as if they were integers.
11345
11346If the operands are integer vectors, then they are compared element by
11347element. The result is an ``i1`` vector with the same number of elements
11348as the values being compared. Otherwise, the result is an ``i1``.
11349
11350Example:
11351""""""""
11352
11353.. code-block:: text
11354
11355      <result> = icmp eq i32 4, 5          ; yields: result=false
11356      <result> = icmp ne float* %X, %X     ; yields: result=false
11357      <result> = icmp ult i16  4, 5        ; yields: result=true
11358      <result> = icmp sgt i16  4, 5        ; yields: result=false
11359      <result> = icmp ule i16 -4, 5        ; yields: result=false
11360      <result> = icmp sge i16  4, 5        ; yields: result=false
11361
11362.. _i_fcmp:
11363
11364'``fcmp``' Instruction
11365^^^^^^^^^^^^^^^^^^^^^^
11366
11367Syntax:
11368"""""""
11369
11370::
11371
11372      <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2>     ; yields i1 or <N x i1>:result
11373
11374Overview:
11375"""""""""
11376
11377The '``fcmp``' instruction returns a boolean value or vector of boolean
11378values based on comparison of its operands.
11379
11380If the operands are floating-point scalars, then the result type is a
11381boolean (:ref:`i1 <t_integer>`).
11382
11383If the operands are floating-point vectors, then the result type is a
11384vector of boolean with the same number of elements as the operands being
11385compared.
11386
11387Arguments:
11388""""""""""
11389
11390The '``fcmp``' instruction takes three operands. The first operand is
11391the condition code indicating the kind of comparison to perform. It is
11392not a value, just a keyword. The possible condition codes are:
11393
11394#. ``false``: no comparison, always returns false
11395#. ``oeq``: ordered and equal
11396#. ``ogt``: ordered and greater than
11397#. ``oge``: ordered and greater than or equal
11398#. ``olt``: ordered and less than
11399#. ``ole``: ordered and less than or equal
11400#. ``one``: ordered and not equal
11401#. ``ord``: ordered (no nans)
11402#. ``ueq``: unordered or equal
11403#. ``ugt``: unordered or greater than
11404#. ``uge``: unordered or greater than or equal
11405#. ``ult``: unordered or less than
11406#. ``ule``: unordered or less than or equal
11407#. ``une``: unordered or not equal
11408#. ``uno``: unordered (either nans)
11409#. ``true``: no comparison, always returns true
11410
11411*Ordered* means that neither operand is a QNAN while *unordered* means
11412that either operand may be a QNAN.
11413
11414Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point
11415<t_floating>` type or a :ref:`vector <t_vector>` of floating-point type.
11416They must have identical types.
11417
11418Semantics:
11419""""""""""
11420
11421The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the
11422condition code given as ``cond``. If the operands are vectors, then the
11423vectors are compared element by element. Each comparison performed
11424always yields an :ref:`i1 <t_integer>` result, as follows:
11425
11426#. ``false``: always yields ``false``, regardless of operands.
11427#. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1``
11428   is equal to ``op2``.
11429#. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1``
11430   is greater than ``op2``.
11431#. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1``
11432   is greater than or equal to ``op2``.
11433#. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1``
11434   is less than ``op2``.
11435#. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1``
11436   is less than or equal to ``op2``.
11437#. ``one``: yields ``true`` if both operands are not a QNAN and ``op1``
11438   is not equal to ``op2``.
11439#. ``ord``: yields ``true`` if both operands are not a QNAN.
11440#. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is
11441   equal to ``op2``.
11442#. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is
11443   greater than ``op2``.
11444#. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is
11445   greater than or equal to ``op2``.
11446#. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is
11447   less than ``op2``.
11448#. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is
11449   less than or equal to ``op2``.
11450#. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is
11451   not equal to ``op2``.
11452#. ``uno``: yields ``true`` if either operand is a QNAN.
11453#. ``true``: always yields ``true``, regardless of operands.
11454
11455The ``fcmp`` instruction can also optionally take any number of
11456:ref:`fast-math flags <fastmath>`, which are optimization hints to enable
11457otherwise unsafe floating-point optimizations.
11458
11459Any set of fast-math flags are legal on an ``fcmp`` instruction, but the
11460only flags that have any effect on its semantics are those that allow
11461assumptions to be made about the values of input arguments; namely
11462``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information.
11463
11464Example:
11465""""""""
11466
11467.. code-block:: text
11468
11469      <result> = fcmp oeq float 4.0, 5.0    ; yields: result=false
11470      <result> = fcmp one float 4.0, 5.0    ; yields: result=true
11471      <result> = fcmp olt float 4.0, 5.0    ; yields: result=true
11472      <result> = fcmp ueq double 1.0, 2.0   ; yields: result=false
11473
11474.. _i_phi:
11475
11476'``phi``' Instruction
11477^^^^^^^^^^^^^^^^^^^^^
11478
11479Syntax:
11480"""""""
11481
11482::
11483
11484      <result> = phi [fast-math-flags] <ty> [ <val0>, <label0>], ...
11485
11486Overview:
11487"""""""""
11488
11489The '``phi``' instruction is used to implement the φ node in the SSA
11490graph representing the function.
11491
11492Arguments:
11493""""""""""
11494
11495The type of the incoming values is specified with the first type field.
11496After this, the '``phi``' instruction takes a list of pairs as
11497arguments, with one pair for each predecessor basic block of the current
11498block. Only values of :ref:`first class <t_firstclass>` type may be used as
11499the value arguments to the PHI node. Only labels may be used as the
11500label arguments.
11501
11502There must be no non-phi instructions between the start of a basic block
11503and the PHI instructions: i.e. PHI instructions must be first in a basic
11504block.
11505
11506For the purposes of the SSA form, the use of each incoming value is
11507deemed to occur on the edge from the corresponding predecessor block to
11508the current block (but after any definition of an '``invoke``'
11509instruction's return value on the same edge).
11510
11511The optional ``fast-math-flags`` marker indicates that the phi has one
11512or more :ref:`fast-math-flags <fastmath>`. These are optimization hints
11513to enable otherwise unsafe floating-point optimizations. Fast-math-flags
11514are only valid for phis that return a floating-point scalar or vector
11515type, or an array (nested to any depth) of floating-point scalar or vector
11516types.
11517
11518Semantics:
11519""""""""""
11520
11521At runtime, the '``phi``' instruction logically takes on the value
11522specified by the pair corresponding to the predecessor basic block that
11523executed just prior to the current block.
11524
11525Example:
11526""""""""
11527
11528.. code-block:: llvm
11529
11530    Loop:       ; Infinite loop that counts from 0 on up...
11531      %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
11532      %nextindvar = add i32 %indvar, 1
11533      br label %Loop
11534
11535.. _i_select:
11536
11537'``select``' Instruction
11538^^^^^^^^^^^^^^^^^^^^^^^^
11539
11540Syntax:
11541"""""""
11542
11543::
11544
11545      <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2>             ; yields ty
11546
11547      selty is either i1 or {<N x i1>}
11548
11549Overview:
11550"""""""""
11551
11552The '``select``' instruction is used to choose one value based on a
11553condition, without IR-level branching.
11554
11555Arguments:
11556""""""""""
11557
11558The '``select``' instruction requires an 'i1' value or a vector of 'i1'
11559values indicating the condition, and two values of the same :ref:`first
11560class <t_firstclass>` type.
11561
11562#. The optional ``fast-math flags`` marker indicates that the select has one or more
11563   :ref:`fast-math flags <fastmath>`. These are optimization hints to enable
11564   otherwise unsafe floating-point optimizations. Fast-math flags are only valid
11565   for selects that return a floating-point scalar or vector type, or an array
11566   (nested to any depth) of floating-point scalar or vector types.
11567
11568Semantics:
11569""""""""""
11570
11571If the condition is an i1 and it evaluates to 1, the instruction returns
11572the first value argument; otherwise, it returns the second value
11573argument.
11574
11575If the condition is a vector of i1, then the value arguments must be
11576vectors of the same size, and the selection is done element by element.
11577
11578If the condition is an i1 and the value arguments are vectors of the
11579same size, then an entire vector is selected.
11580
11581Example:
11582""""""""
11583
11584.. code-block:: llvm
11585
11586      %X = select i1 true, i8 17, i8 42          ; yields i8:17
11587
11588
11589.. _i_freeze:
11590
11591'``freeze``' Instruction
11592^^^^^^^^^^^^^^^^^^^^^^^^
11593
11594Syntax:
11595"""""""
11596
11597::
11598
11599      <result> = freeze ty <val>    ; yields ty:result
11600
11601Overview:
11602"""""""""
11603
11604The '``freeze``' instruction is used to stop propagation of
11605:ref:`undef <undefvalues>` and :ref:`poison <poisonvalues>` values.
11606
11607Arguments:
11608""""""""""
11609
11610The '``freeze``' instruction takes a single argument.
11611
11612Semantics:
11613""""""""""
11614
11615If the argument is ``undef`` or ``poison``, '``freeze``' returns an
11616arbitrary, but fixed, value of type '``ty``'.
11617Otherwise, this instruction is a no-op and returns the input argument.
11618All uses of a value returned by the same '``freeze``' instruction are
11619guaranteed to always observe the same value, while different '``freeze``'
11620instructions may yield different values.
11621
11622While ``undef`` and ``poison`` pointers can be frozen, the result is a
11623non-dereferenceable pointer. See the
11624:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more information.
11625If an aggregate value or vector is frozen, the operand is frozen element-wise.
11626The padding of an aggregate isn't considered, since it isn't visible
11627without storing it into memory and loading it with a different type.
11628
11629
11630Example:
11631""""""""
11632
11633.. code-block:: text
11634
11635      %w = i32 undef
11636      %x = freeze i32 %w
11637      %y = add i32 %w, %w         ; undef
11638      %z = add i32 %x, %x         ; even number because all uses of %x observe
11639                                  ; the same value
11640      %x2 = freeze i32 %w
11641      %cmp = icmp eq i32 %x, %x2  ; can be true or false
11642
11643      ; example with vectors
11644      %v = <2 x i32> <i32 undef, i32 poison>
11645      %a = extractelement <2 x i32> %v, i32 0    ; undef
11646      %b = extractelement <2 x i32> %v, i32 1    ; poison
11647      %add = add i32 %a, %a                      ; undef
11648
11649      %v.fr = freeze <2 x i32> %v                ; element-wise freeze
11650      %d = extractelement <2 x i32> %v.fr, i32 0 ; not undef
11651      %add.f = add i32 %d, %d                    ; even number
11652
11653      ; branching on frozen value
11654      %poison = add nsw i1 %k, undef   ; poison
11655      %c = freeze i1 %poison
11656      br i1 %c, label %foo, label %bar ; non-deterministic branch to %foo or %bar
11657
11658
11659.. _i_call:
11660
11661'``call``' Instruction
11662^^^^^^^^^^^^^^^^^^^^^^
11663
11664Syntax:
11665"""""""
11666
11667::
11668
11669      <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] [addrspace(<num>)]
11670                 <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] [ operand bundles ]
11671
11672Overview:
11673"""""""""
11674
11675The '``call``' instruction represents a simple function call.
11676
11677Arguments:
11678""""""""""
11679
11680This instruction requires several arguments:
11681
11682#. The optional ``tail`` and ``musttail`` markers indicate that the optimizers
11683   should perform tail call optimization. The ``tail`` marker is a hint that
11684   `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker
11685   means that the call must be tail call optimized in order for the program to
11686   be correct. The ``musttail`` marker provides these guarantees:
11687
11688   #. The call will not cause unbounded stack growth if it is part of a
11689      recursive cycle in the call graph.
11690   #. Arguments with the :ref:`inalloca <attr_inalloca>` or
11691      :ref:`preallocated <attr_preallocated>` attribute are forwarded in place.
11692   #. If the musttail call appears in a function with the ``"thunk"`` attribute
11693      and the caller and callee both have varargs, than any unprototyped
11694      arguments in register or memory are forwarded to the callee. Similarly,
11695      the return value of the callee is returned to the caller's caller, even
11696      if a void return type is in use.
11697
11698   Both markers imply that the callee does not access allocas from the caller.
11699   The ``tail`` marker additionally implies that the callee does not access
11700   varargs from the caller. Calls marked ``musttail`` must obey the following
11701   additional  rules:
11702
11703   - The call must immediately precede a :ref:`ret <i_ret>` instruction,
11704     or a pointer bitcast followed by a ret instruction.
11705   - The ret instruction must return the (possibly bitcasted) value
11706     produced by the call, undef, or void.
11707   - The calling conventions of the caller and callee must match.
11708   - The callee must be varargs iff the caller is varargs. Bitcasting a
11709     non-varargs function to the appropriate varargs type is legal so
11710     long as the non-varargs prefixes obey the other rules.
11711   - The return type must not undergo automatic conversion to an `sret` pointer.
11712
11713  In addition, if the calling convention is not `swifttailcc` or `tailcc`:
11714
11715   - All ABI-impacting function attributes, such as sret, byval, inreg,
11716     returned, and inalloca, must match.
11717   - The caller and callee prototypes must match. Pointer types of parameters
11718     or return types may differ in pointee type, but not in address space.
11719
11720  On the other hand, if the calling convention is `swifttailcc` or `swiftcc`:
11721
11722   - Only these ABI-impacting attributes attributes are allowed: sret, byval,
11723     swiftself, and swiftasync.
11724   - Prototypes are not required to match.
11725
11726   Tail call optimization for calls marked ``tail`` is guaranteed to occur if
11727   the following conditions are met:
11728
11729   -  Caller and callee both have the calling convention ``fastcc`` or ``tailcc``.
11730   -  The call is in tail position (ret immediately follows call and ret
11731      uses value of call or is void).
11732   -  Option ``-tailcallopt`` is enabled,
11733      ``llvm::GuaranteedTailCallOpt`` is ``true``, or the calling convention
11734      is ``tailcc``
11735   -  `Platform-specific constraints are
11736      met. <CodeGenerator.html#tailcallopt>`_
11737
11738#. The optional ``notail`` marker indicates that the optimizers should not add
11739   ``tail`` or ``musttail`` markers to the call. It is used to prevent tail
11740   call optimization from being performed on the call.
11741
11742#. The optional ``fast-math flags`` marker indicates that the call has one or more
11743   :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
11744   otherwise unsafe floating-point optimizations. Fast-math flags are only valid
11745   for calls that return a floating-point scalar or vector type, or an array
11746   (nested to any depth) of floating-point scalar or vector types.
11747
11748#. The optional "cconv" marker indicates which :ref:`calling
11749   convention <callingconv>` the call should use. If none is
11750   specified, the call defaults to using C calling conventions. The
11751   calling convention of the call must match the calling convention of
11752   the target function, or else the behavior is undefined.
11753#. The optional :ref:`Parameter Attributes <paramattrs>` list for return
11754   values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
11755   are valid here.
11756#. The optional addrspace attribute can be used to indicate the address space
11757   of the called function. If it is not specified, the program address space
11758   from the :ref:`datalayout string<langref_datalayout>` will be used.
11759#. '``ty``': the type of the call instruction itself which is also the
11760   type of the return value. Functions that return no value are marked
11761   ``void``.
11762#. '``fnty``': shall be the signature of the function being called. The
11763   argument types must match the types implied by this signature. This
11764   type can be omitted if the function is not varargs.
11765#. '``fnptrval``': An LLVM value containing a pointer to a function to
11766   be called. In most cases, this is a direct function call, but
11767   indirect ``call``'s are just as possible, calling an arbitrary pointer
11768   to function value.
11769#. '``function args``': argument list whose types match the function
11770   signature argument types and parameter attributes. All arguments must
11771   be of :ref:`first class <t_firstclass>` type. If the function signature
11772   indicates the function accepts a variable number of arguments, the
11773   extra arguments can be specified.
11774#. The optional :ref:`function attributes <fnattrs>` list.
11775#. The optional :ref:`operand bundles <opbundles>` list.
11776
11777Semantics:
11778""""""""""
11779
11780The '``call``' instruction is used to cause control flow to transfer to
11781a specified function, with its incoming arguments bound to the specified
11782values. Upon a '``ret``' instruction in the called function, control
11783flow continues with the instruction after the function call, and the
11784return value of the function is bound to the result argument.
11785
11786Example:
11787""""""""
11788
11789.. code-block:: llvm
11790
11791      %retval = call i32 @test(i32 %argc)
11792      call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42)        ; yields i32
11793      %X = tail call i32 @foo()                                    ; yields i32
11794      %Y = tail call fastcc i32 @foo()  ; yields i32
11795      call void %foo(i8 signext 97)
11796
11797      %struct.A = type { i32, i8 }
11798      %r = call %struct.A @foo()                        ; yields { i32, i8 }
11799      %gr = extractvalue %struct.A %r, 0                ; yields i32
11800      %gr1 = extractvalue %struct.A %r, 1               ; yields i8
11801      %Z = call void @foo() noreturn                    ; indicates that %foo never returns normally
11802      %ZZ = call zeroext i32 @bar()                     ; Return value is %zero extended
11803
11804llvm treats calls to some functions with names and arguments that match
11805the standard C99 library as being the C99 library functions, and may
11806perform optimizations or generate code for them under that assumption.
11807This is something we'd like to change in the future to provide better
11808support for freestanding environments and non-C-based languages.
11809
11810.. _i_va_arg:
11811
11812'``va_arg``' Instruction
11813^^^^^^^^^^^^^^^^^^^^^^^^
11814
11815Syntax:
11816"""""""
11817
11818::
11819
11820      <resultval> = va_arg <va_list*> <arglist>, <argty>
11821
11822Overview:
11823"""""""""
11824
11825The '``va_arg``' instruction is used to access arguments passed through
11826the "variable argument" area of a function call. It is used to implement
11827the ``va_arg`` macro in C.
11828
11829Arguments:
11830""""""""""
11831
11832This instruction takes a ``va_list*`` value and the type of the
11833argument. It returns a value of the specified argument type and
11834increments the ``va_list`` to point to the next argument. The actual
11835type of ``va_list`` is target specific.
11836
11837Semantics:
11838""""""""""
11839
11840The '``va_arg``' instruction loads an argument of the specified type
11841from the specified ``va_list`` and causes the ``va_list`` to point to
11842the next argument. For more information, see the variable argument
11843handling :ref:`Intrinsic Functions <int_varargs>`.
11844
11845It is legal for this instruction to be called in a function which does
11846not take a variable number of arguments, for example, the ``vfprintf``
11847function.
11848
11849``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic
11850function <intrinsics>` because it takes a type as an argument.
11851
11852Example:
11853""""""""
11854
11855See the :ref:`variable argument processing <int_varargs>` section.
11856
11857Note that the code generator does not yet fully support va\_arg on many
11858targets. Also, it does not currently support va\_arg with aggregate
11859types on any target.
11860
11861.. _i_landingpad:
11862
11863'``landingpad``' Instruction
11864^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11865
11866Syntax:
11867"""""""
11868
11869::
11870
11871      <resultval> = landingpad <resultty> <clause>+
11872      <resultval> = landingpad <resultty> cleanup <clause>*
11873
11874      <clause> := catch <type> <value>
11875      <clause> := filter <array constant type> <array constant>
11876
11877Overview:
11878"""""""""
11879
11880The '``landingpad``' instruction is used by `LLVM's exception handling
11881system <ExceptionHandling.html#overview>`_ to specify that a basic block
11882is a landing pad --- one where the exception lands, and corresponds to the
11883code found in the ``catch`` portion of a ``try``/``catch`` sequence. It
11884defines values supplied by the :ref:`personality function <personalityfn>` upon
11885re-entry to the function. The ``resultval`` has the type ``resultty``.
11886
11887Arguments:
11888""""""""""
11889
11890The optional
11891``cleanup`` flag indicates that the landing pad block is a cleanup.
11892
11893A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and
11894contains the global variable representing the "type" that may be caught
11895or filtered respectively. Unlike the ``catch`` clause, the ``filter``
11896clause takes an array constant as its argument. Use
11897"``[0 x i8**] undef``" for a filter which cannot throw. The
11898'``landingpad``' instruction must contain *at least* one ``clause`` or
11899the ``cleanup`` flag.
11900
11901Semantics:
11902""""""""""
11903
11904The '``landingpad``' instruction defines the values which are set by the
11905:ref:`personality function <personalityfn>` upon re-entry to the function, and
11906therefore the "result type" of the ``landingpad`` instruction. As with
11907calling conventions, how the personality function results are
11908represented in LLVM IR is target specific.
11909
11910The clauses are applied in order from top to bottom. If two
11911``landingpad`` instructions are merged together through inlining, the
11912clauses from the calling function are appended to the list of clauses.
11913When the call stack is being unwound due to an exception being thrown,
11914the exception is compared against each ``clause`` in turn. If it doesn't
11915match any of the clauses, and the ``cleanup`` flag is not set, then
11916unwinding continues further up the call stack.
11917
11918The ``landingpad`` instruction has several restrictions:
11919
11920-  A landing pad block is a basic block which is the unwind destination
11921   of an '``invoke``' instruction.
11922-  A landing pad block must have a '``landingpad``' instruction as its
11923   first non-PHI instruction.
11924-  There can be only one '``landingpad``' instruction within the landing
11925   pad block.
11926-  A basic block that is not a landing pad block may not include a
11927   '``landingpad``' instruction.
11928
11929Example:
11930""""""""
11931
11932.. code-block:: llvm
11933
11934      ;; A landing pad which can catch an integer.
11935      %res = landingpad { i8*, i32 }
11936               catch i8** @_ZTIi
11937      ;; A landing pad that is a cleanup.
11938      %res = landingpad { i8*, i32 }
11939               cleanup
11940      ;; A landing pad which can catch an integer and can only throw a double.
11941      %res = landingpad { i8*, i32 }
11942               catch i8** @_ZTIi
11943               filter [1 x i8**] [i8** @_ZTId]
11944
11945.. _i_catchpad:
11946
11947'``catchpad``' Instruction
11948^^^^^^^^^^^^^^^^^^^^^^^^^^
11949
11950Syntax:
11951"""""""
11952
11953::
11954
11955      <resultval> = catchpad within <catchswitch> [<args>*]
11956
11957Overview:
11958"""""""""
11959
11960The '``catchpad``' instruction is used by `LLVM's exception handling
11961system <ExceptionHandling.html#overview>`_ to specify that a basic block
11962begins a catch handler --- one where a personality routine attempts to transfer
11963control to catch an exception.
11964
11965Arguments:
11966""""""""""
11967
11968The ``catchswitch`` operand must always be a token produced by a
11969:ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This
11970ensures that each ``catchpad`` has exactly one predecessor block, and it always
11971terminates in a ``catchswitch``.
11972
11973The ``args`` correspond to whatever information the personality routine
11974requires to know if this is an appropriate handler for the exception. Control
11975will transfer to the ``catchpad`` if this is the first appropriate handler for
11976the exception.
11977
11978The ``resultval`` has the type :ref:`token <t_token>` and is used to match the
11979``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH
11980pads.
11981
11982Semantics:
11983""""""""""
11984
11985When the call stack is being unwound due to an exception being thrown, the
11986exception is compared against the ``args``. If it doesn't match, control will
11987not reach the ``catchpad`` instruction.  The representation of ``args`` is
11988entirely target and personality function-specific.
11989
11990Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad``
11991instruction must be the first non-phi of its parent basic block.
11992
11993The meaning of the tokens produced and consumed by ``catchpad`` and other "pad"
11994instructions is described in the
11995`Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_.
11996
11997When a ``catchpad`` has been "entered" but not yet "exited" (as
11998described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
11999it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
12000that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
12001
12002Example:
12003""""""""
12004
12005.. code-block:: text
12006
12007    dispatch:
12008      %cs = catchswitch within none [label %handler0] unwind to caller
12009      ;; A catch block which can catch an integer.
12010    handler0:
12011      %tok = catchpad within %cs [i8** @_ZTIi]
12012
12013.. _i_cleanuppad:
12014
12015'``cleanuppad``' Instruction
12016^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12017
12018Syntax:
12019"""""""
12020
12021::
12022
12023      <resultval> = cleanuppad within <parent> [<args>*]
12024
12025Overview:
12026"""""""""
12027
12028The '``cleanuppad``' instruction is used by `LLVM's exception handling
12029system <ExceptionHandling.html#overview>`_ to specify that a basic block
12030is a cleanup block --- one where a personality routine attempts to
12031transfer control to run cleanup actions.
12032The ``args`` correspond to whatever additional
12033information the :ref:`personality function <personalityfn>` requires to
12034execute the cleanup.
12035The ``resultval`` has the type :ref:`token <t_token>` and is used to
12036match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`.
12037The ``parent`` argument is the token of the funclet that contains the
12038``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet,
12039this operand may be the token ``none``.
12040
12041Arguments:
12042""""""""""
12043
12044The instruction takes a list of arbitrary values which are interpreted
12045by the :ref:`personality function <personalityfn>`.
12046
12047Semantics:
12048""""""""""
12049
12050When the call stack is being unwound due to an exception being thrown,
12051the :ref:`personality function <personalityfn>` transfers control to the
12052``cleanuppad`` with the aid of the personality-specific arguments.
12053As with calling conventions, how the personality function results are
12054represented in LLVM IR is target specific.
12055
12056The ``cleanuppad`` instruction has several restrictions:
12057
12058-  A cleanup block is a basic block which is the unwind destination of
12059   an exceptional instruction.
12060-  A cleanup block must have a '``cleanuppad``' instruction as its
12061   first non-PHI instruction.
12062-  There can be only one '``cleanuppad``' instruction within the
12063   cleanup block.
12064-  A basic block that is not a cleanup block may not include a
12065   '``cleanuppad``' instruction.
12066
12067When a ``cleanuppad`` has been "entered" but not yet "exited" (as
12068described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
12069it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
12070that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
12071
12072Example:
12073""""""""
12074
12075.. code-block:: text
12076
12077      %tok = cleanuppad within %cs []
12078
12079.. _intrinsics:
12080
12081Intrinsic Functions
12082===================
12083
12084LLVM supports the notion of an "intrinsic function". These functions
12085have well known names and semantics and are required to follow certain
12086restrictions. Overall, these intrinsics represent an extension mechanism
12087for the LLVM language that does not require changing all of the
12088transformations in LLVM when adding to the language (or the bitcode
12089reader/writer, the parser, etc...).
12090
12091Intrinsic function names must all start with an "``llvm.``" prefix. This
12092prefix is reserved in LLVM for intrinsic names; thus, function names may
12093not begin with this prefix. Intrinsic functions must always be external
12094functions: you cannot define the body of intrinsic functions. Intrinsic
12095functions may only be used in call or invoke instructions: it is illegal
12096to take the address of an intrinsic function. Additionally, because
12097intrinsic functions are part of the LLVM language, it is required if any
12098are added that they be documented here.
12099
12100Some intrinsic functions can be overloaded, i.e., the intrinsic
12101represents a family of functions that perform the same operation but on
12102different data types. Because LLVM can represent over 8 million
12103different integer types, overloading is used commonly to allow an
12104intrinsic function to operate on any integer type. One or more of the
12105argument types or the result type can be overloaded to accept any
12106integer type. Argument types may also be defined as exactly matching a
12107previous argument's type or the result type. This allows an intrinsic
12108function which accepts multiple arguments, but needs all of them to be
12109of the same type, to only be overloaded with respect to a single
12110argument or the result.
12111
12112Overloaded intrinsics will have the names of its overloaded argument
12113types encoded into its function name, each preceded by a period. Only
12114those types which are overloaded result in a name suffix. Arguments
12115whose type is matched against another type do not. For example, the
12116``llvm.ctpop`` function can take an integer of any width and returns an
12117integer of exactly the same integer width. This leads to a family of
12118functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and
12119``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is
12120overloaded, and only one type suffix is required. Because the argument's
12121type is matched against the return type, it does not require its own
12122name suffix.
12123
12124:ref:`Unnamed types <t_opaque>` are encoded as ``s_s``. Overloaded intrinsics
12125that depend on an unnamed type in one of its overloaded argument types get an
12126additional ``.<number>`` suffix. This allows differentiating intrinsics with
12127different unnamed types as arguments. (For example:
12128``llvm.ssa.copy.p0s_s.2(%42*)``) The number is tracked in the LLVM module and
12129it ensures unique names in the module. While linking together two modules, it is
12130still possible to get a name clash. In that case one of the names will be
12131changed by getting a new number.
12132
12133For target developers who are defining intrinsics for back-end code
12134generation, any intrinsic overloads based solely the distinction between
12135integer or floating point types should not be relied upon for correct
12136code generation. In such cases, the recommended approach for target
12137maintainers when defining intrinsics is to create separate integer and
12138FP intrinsics rather than rely on overloading. For example, if different
12139codegen is required for ``llvm.target.foo(<4 x i32>)`` and
12140``llvm.target.foo(<4 x float>)`` then these should be split into
12141different intrinsics.
12142
12143To learn how to add an intrinsic function, please see the `Extending
12144LLVM Guide <ExtendingLLVM.html>`_.
12145
12146.. _int_varargs:
12147
12148Variable Argument Handling Intrinsics
12149-------------------------------------
12150
12151Variable argument support is defined in LLVM with the
12152:ref:`va_arg <i_va_arg>` instruction and these three intrinsic
12153functions. These functions are related to the similarly named macros
12154defined in the ``<stdarg.h>`` header file.
12155
12156All of these functions operate on arguments that use a target-specific
12157value type "``va_list``". The LLVM assembly language reference manual
12158does not define what this type is, so all transformations should be
12159prepared to handle these functions regardless of the type used.
12160
12161This example shows how the :ref:`va_arg <i_va_arg>` instruction and the
12162variable argument handling intrinsic functions are used.
12163
12164.. code-block:: llvm
12165
12166    ; This struct is different for every platform. For most platforms,
12167    ; it is merely an i8*.
12168    %struct.va_list = type { i8* }
12169
12170    ; For Unix x86_64 platforms, va_list is the following struct:
12171    ; %struct.va_list = type { i32, i32, i8*, i8* }
12172
12173    define i32 @test(i32 %X, ...) {
12174      ; Initialize variable argument processing
12175      %ap = alloca %struct.va_list
12176      %ap2 = bitcast %struct.va_list* %ap to i8*
12177      call void @llvm.va_start(i8* %ap2)
12178
12179      ; Read a single integer argument
12180      %tmp = va_arg i8* %ap2, i32
12181
12182      ; Demonstrate usage of llvm.va_copy and llvm.va_end
12183      %aq = alloca i8*
12184      %aq2 = bitcast i8** %aq to i8*
12185      call void @llvm.va_copy(i8* %aq2, i8* %ap2)
12186      call void @llvm.va_end(i8* %aq2)
12187
12188      ; Stop processing of arguments.
12189      call void @llvm.va_end(i8* %ap2)
12190      ret i32 %tmp
12191    }
12192
12193    declare void @llvm.va_start(i8*)
12194    declare void @llvm.va_copy(i8*, i8*)
12195    declare void @llvm.va_end(i8*)
12196
12197.. _int_va_start:
12198
12199'``llvm.va_start``' Intrinsic
12200^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12201
12202Syntax:
12203"""""""
12204
12205::
12206
12207      declare void @llvm.va_start(i8* <arglist>)
12208
12209Overview:
12210"""""""""
12211
12212The '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for
12213subsequent use by ``va_arg``.
12214
12215Arguments:
12216""""""""""
12217
12218The argument is a pointer to a ``va_list`` element to initialize.
12219
12220Semantics:
12221""""""""""
12222
12223The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro
12224available in C. In a target-dependent way, it initializes the
12225``va_list`` element to which the argument points, so that the next call
12226to ``va_arg`` will produce the first variable argument passed to the
12227function. Unlike the C ``va_start`` macro, this intrinsic does not need
12228to know the last argument of the function as the compiler can figure
12229that out.
12230
12231'``llvm.va_end``' Intrinsic
12232^^^^^^^^^^^^^^^^^^^^^^^^^^^
12233
12234Syntax:
12235"""""""
12236
12237::
12238
12239      declare void @llvm.va_end(i8* <arglist>)
12240
12241Overview:
12242"""""""""
12243
12244The '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been
12245initialized previously with ``llvm.va_start`` or ``llvm.va_copy``.
12246
12247Arguments:
12248""""""""""
12249
12250The argument is a pointer to a ``va_list`` to destroy.
12251
12252Semantics:
12253""""""""""
12254
12255The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro
12256available in C. In a target-dependent way, it destroys the ``va_list``
12257element to which the argument points. Calls to
12258:ref:`llvm.va_start <int_va_start>` and
12259:ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to
12260``llvm.va_end``.
12261
12262.. _int_va_copy:
12263
12264'``llvm.va_copy``' Intrinsic
12265^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12266
12267Syntax:
12268"""""""
12269
12270::
12271
12272      declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>)
12273
12274Overview:
12275"""""""""
12276
12277The '``llvm.va_copy``' intrinsic copies the current argument position
12278from the source argument list to the destination argument list.
12279
12280Arguments:
12281""""""""""
12282
12283The first argument is a pointer to a ``va_list`` element to initialize.
12284The second argument is a pointer to a ``va_list`` element to copy from.
12285
12286Semantics:
12287""""""""""
12288
12289The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro
12290available in C. In a target-dependent way, it copies the source
12291``va_list`` element into the destination ``va_list`` element. This
12292intrinsic is necessary because the `` llvm.va_start`` intrinsic may be
12293arbitrarily complex and require, for example, memory allocation.
12294
12295Accurate Garbage Collection Intrinsics
12296--------------------------------------
12297
12298LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_
12299(GC) requires the frontend to generate code containing appropriate intrinsic
12300calls and select an appropriate GC strategy which knows how to lower these
12301intrinsics in a manner which is appropriate for the target collector.
12302
12303These intrinsics allow identification of :ref:`GC roots on the
12304stack <int_gcroot>`, as well as garbage collector implementations that
12305require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers.
12306Frontends for type-safe garbage collected languages should generate
12307these intrinsics to make use of the LLVM garbage collectors. For more
12308details, see `Garbage Collection with LLVM <GarbageCollection.html>`_.
12309
12310LLVM provides an second experimental set of intrinsics for describing garbage
12311collection safepoints in compiled code. These intrinsics are an alternative
12312to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for
12313:ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The
12314differences in approach are covered in the `Garbage Collection with LLVM
12315<GarbageCollection.html>`_ documentation. The intrinsics themselves are
12316described in :doc:`Statepoints`.
12317
12318.. _int_gcroot:
12319
12320'``llvm.gcroot``' Intrinsic
12321^^^^^^^^^^^^^^^^^^^^^^^^^^^
12322
12323Syntax:
12324"""""""
12325
12326::
12327
12328      declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
12329
12330Overview:
12331"""""""""
12332
12333The '``llvm.gcroot``' intrinsic declares the existence of a GC root to
12334the code generator, and allows some metadata to be associated with it.
12335
12336Arguments:
12337""""""""""
12338
12339The first argument specifies the address of a stack object that contains
12340the root pointer. The second pointer (which must be either a constant or
12341a global value address) contains the meta-data to be associated with the
12342root.
12343
12344Semantics:
12345""""""""""
12346
12347At runtime, a call to this intrinsic stores a null pointer into the
12348"ptrloc" location. At compile-time, the code generator generates
12349information to allow the runtime to find the pointer at GC safe points.
12350The '``llvm.gcroot``' intrinsic may only be used in a function which
12351:ref:`specifies a GC algorithm <gc>`.
12352
12353.. _int_gcread:
12354
12355'``llvm.gcread``' Intrinsic
12356^^^^^^^^^^^^^^^^^^^^^^^^^^^
12357
12358Syntax:
12359"""""""
12360
12361::
12362
12363      declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
12364
12365Overview:
12366"""""""""
12367
12368The '``llvm.gcread``' intrinsic identifies reads of references from heap
12369locations, allowing garbage collector implementations that require read
12370barriers.
12371
12372Arguments:
12373""""""""""
12374
12375The second argument is the address to read from, which should be an
12376address allocated from the garbage collector. The first object is a
12377pointer to the start of the referenced object, if needed by the language
12378runtime (otherwise null).
12379
12380Semantics:
12381""""""""""
12382
12383The '``llvm.gcread``' intrinsic has the same semantics as a load
12384instruction, but may be replaced with substantially more complex code by
12385the garbage collector runtime, as needed. The '``llvm.gcread``'
12386intrinsic may only be used in a function which :ref:`specifies a GC
12387algorithm <gc>`.
12388
12389.. _int_gcwrite:
12390
12391'``llvm.gcwrite``' Intrinsic
12392^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12393
12394Syntax:
12395"""""""
12396
12397::
12398
12399      declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
12400
12401Overview:
12402"""""""""
12403
12404The '``llvm.gcwrite``' intrinsic identifies writes of references to heap
12405locations, allowing garbage collector implementations that require write
12406barriers (such as generational or reference counting collectors).
12407
12408Arguments:
12409""""""""""
12410
12411The first argument is the reference to store, the second is the start of
12412the object to store it to, and the third is the address of the field of
12413Obj to store to. If the runtime does not require a pointer to the
12414object, Obj may be null.
12415
12416Semantics:
12417""""""""""
12418
12419The '``llvm.gcwrite``' intrinsic has the same semantics as a store
12420instruction, but may be replaced with substantially more complex code by
12421the garbage collector runtime, as needed. The '``llvm.gcwrite``'
12422intrinsic may only be used in a function which :ref:`specifies a GC
12423algorithm <gc>`.
12424
12425
12426.. _gc_statepoint:
12427
12428'llvm.experimental.gc.statepoint' Intrinsic
12429^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12430
12431Syntax:
12432"""""""
12433
12434::
12435
12436      declare token
12437        @llvm.experimental.gc.statepoint(i64 <id>, i32 <num patch bytes>,
12438                       func_type* elementtype(func_type) <target>,
12439                       i64 <#call args>, i64 <flags>,
12440                       ... (call parameters),
12441                       i64 0, i64 0)
12442
12443Overview:
12444"""""""""
12445
12446The statepoint intrinsic represents a call which is parse-able by the
12447runtime.
12448
12449Operands:
12450"""""""""
12451
12452The 'id' operand is a constant integer that is reported as the ID
12453field in the generated stackmap.  LLVM does not interpret this
12454parameter in any way and its meaning is up to the statepoint user to
12455decide.  Note that LLVM is free to duplicate code containing
12456statepoint calls, and this may transform IR that had a unique 'id' per
12457lexical call to statepoint to IR that does not.
12458
12459If 'num patch bytes' is non-zero then the call instruction
12460corresponding to the statepoint is not emitted and LLVM emits 'num
12461patch bytes' bytes of nops in its place.  LLVM will emit code to
12462prepare the function arguments and retrieve the function return value
12463in accordance to the calling convention; the former before the nop
12464sequence and the latter after the nop sequence.  It is expected that
12465the user will patch over the 'num patch bytes' bytes of nops with a
12466calling sequence specific to their runtime before executing the
12467generated machine code.  There are no guarantees with respect to the
12468alignment of the nop sequence.  Unlike :doc:`StackMaps` statepoints do
12469not have a concept of shadow bytes.  Note that semantically the
12470statepoint still represents a call or invoke to 'target', and the nop
12471sequence after patching is expected to represent an operation
12472equivalent to a call or invoke to 'target'.
12473
12474The 'target' operand is the function actually being called. The operand
12475must have an :ref:`elementtype <attr_elementtype>` attribute specifying
12476the function type of the target. The target can be specified as either
12477a symbolic LLVM function, or as an arbitrary Value of pointer type. Note
12478that the function type must match the signature of the callee and the
12479types of the 'call parameters' arguments.
12480
12481The '#call args' operand is the number of arguments to the actual
12482call.  It must exactly match the number of arguments passed in the
12483'call parameters' variable length section.
12484
12485The 'flags' operand is used to specify extra information about the
12486statepoint. This is currently only used to mark certain statepoints
12487as GC transitions. This operand is a 64-bit integer with the following
12488layout, where bit 0 is the least significant bit:
12489
12490  +-------+---------------------------------------------------+
12491  | Bit # | Usage                                             |
12492  +=======+===================================================+
12493  |     0 | Set if the statepoint is a GC transition, cleared |
12494  |       | otherwise.                                        |
12495  +-------+---------------------------------------------------+
12496  |  1-63 | Reserved for future use; must be cleared.         |
12497  +-------+---------------------------------------------------+
12498
12499The 'call parameters' arguments are simply the arguments which need to
12500be passed to the call target.  They will be lowered according to the
12501specified calling convention and otherwise handled like a normal call
12502instruction.  The number of arguments must exactly match what is
12503specified in '# call args'.  The types must match the signature of
12504'target'.
12505
12506The 'call parameter' attributes must be followed by two 'i64 0' constants.
12507These were originally the length prefixes for 'gc transition parameter' and
12508'deopt parameter' arguments, but the role of these parameter sets have been
12509entirely replaced with the corresponding operand bundles.  In a future
12510revision, these now redundant arguments will be removed.
12511
12512Semantics:
12513""""""""""
12514
12515A statepoint is assumed to read and write all memory.  As a result,
12516memory operations can not be reordered past a statepoint.  It is
12517illegal to mark a statepoint as being either 'readonly' or 'readnone'.
12518
12519Note that legal IR can not perform any memory operation on a 'gc
12520pointer' argument of the statepoint in a location statically reachable
12521from the statepoint.  Instead, the explicitly relocated value (from a
12522``gc.relocate``) must be used.
12523
12524'llvm.experimental.gc.result' Intrinsic
12525^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12526
12527Syntax:
12528"""""""
12529
12530::
12531
12532      declare type*
12533        @llvm.experimental.gc.result(token %statepoint_token)
12534
12535Overview:
12536"""""""""
12537
12538``gc.result`` extracts the result of the original call instruction
12539which was replaced by the ``gc.statepoint``.  The ``gc.result``
12540intrinsic is actually a family of three intrinsics due to an
12541implementation limitation.  Other than the type of the return value,
12542the semantics are the same.
12543
12544Operands:
12545"""""""""
12546
12547The first and only argument is the ``gc.statepoint`` which starts
12548the safepoint sequence of which this ``gc.result`` is a part.
12549Despite the typing of this as a generic token, *only* the value defined
12550by a ``gc.statepoint`` is legal here.
12551
12552Semantics:
12553""""""""""
12554
12555The ``gc.result`` represents the return value of the call target of
12556the ``statepoint``.  The type of the ``gc.result`` must exactly match
12557the type of the target.  If the call target returns void, there will
12558be no ``gc.result``.
12559
12560A ``gc.result`` is modeled as a 'readnone' pure function.  It has no
12561side effects since it is just a projection of the return value of the
12562previous call represented by the ``gc.statepoint``.
12563
12564'llvm.experimental.gc.relocate' Intrinsic
12565^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12566
12567Syntax:
12568"""""""
12569
12570::
12571
12572      declare <pointer type>
12573        @llvm.experimental.gc.relocate(token %statepoint_token,
12574                                       i32 %base_offset,
12575                                       i32 %pointer_offset)
12576
12577Overview:
12578"""""""""
12579
12580A ``gc.relocate`` returns the potentially relocated value of a pointer
12581at the safepoint.
12582
12583Operands:
12584"""""""""
12585
12586The first argument is the ``gc.statepoint`` which starts the
12587safepoint sequence of which this ``gc.relocation`` is a part.
12588Despite the typing of this as a generic token, *only* the value defined
12589by a ``gc.statepoint`` is legal here.
12590
12591The second and third arguments are both indices into operands of the
12592corresponding statepoint's :ref:`gc-live <ob_gc_live>` operand bundle.
12593
12594The second argument is an index which specifies the allocation for the pointer
12595being relocated. The associated value must be within the object with which the
12596pointer being relocated is associated. The optimizer is free to change *which*
12597interior derived pointer is reported, provided that it does not replace an
12598actual base pointer with another interior derived pointer. Collectors are
12599allowed to rely on the base pointer operand remaining an actual base pointer if
12600so constructed.
12601
12602The third argument is an index which specify the (potentially) derived pointer
12603being relocated.  It is legal for this index to be the same as the second
12604argument if-and-only-if a base pointer is being relocated.
12605
12606Semantics:
12607""""""""""
12608
12609The return value of ``gc.relocate`` is the potentially relocated value
12610of the pointer specified by its arguments.  It is unspecified how the
12611value of the returned pointer relates to the argument to the
12612``gc.statepoint`` other than that a) it points to the same source
12613language object with the same offset, and b) the 'based-on'
12614relationship of the newly relocated pointers is a projection of the
12615unrelocated pointers.  In particular, the integer value of the pointer
12616returned is unspecified.
12617
12618A ``gc.relocate`` is modeled as a ``readnone`` pure function.  It has no
12619side effects since it is just a way to extract information about work
12620done during the actual call modeled by the ``gc.statepoint``.
12621
12622.. _gc.get.pointer.base:
12623
12624'llvm.experimental.gc.get.pointer.base' Intrinsic
12625^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12626
12627Syntax:
12628"""""""
12629
12630::
12631
12632      declare <pointer type>
12633        @llvm.experimental.gc.get.pointer.base(
12634          <pointer type> readnone nocapture %derived_ptr)
12635          nounwind readnone willreturn
12636
12637Overview:
12638"""""""""
12639
12640``gc.get.pointer.base`` for a derived pointer returns its base pointer.
12641
12642Operands:
12643"""""""""
12644
12645The only argument is a pointer which is based on some object with
12646an unknown offset from the base of said object.
12647
12648Semantics:
12649""""""""""
12650
12651This intrinsic is used in the abstract machine model for GC to represent
12652the base pointer for an arbitrary derived pointer.
12653
12654This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by
12655replacing all uses of this callsite with the offset of a derived pointer from
12656its base pointer value. The replacement is done as part of the lowering to the
12657explicit statepoint model.
12658
12659The return pointer type must be the same as the type of the parameter.
12660
12661
12662'llvm.experimental.gc.get.pointer.offset' Intrinsic
12663^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12664
12665Syntax:
12666"""""""
12667
12668::
12669
12670      declare i64
12671        @llvm.experimental.gc.get.pointer.offset(
12672          <pointer type> readnone nocapture %derived_ptr)
12673          nounwind readnone willreturn
12674
12675Overview:
12676"""""""""
12677
12678``gc.get.pointer.offset`` for a derived pointer returns the offset from its
12679base pointer.
12680
12681Operands:
12682"""""""""
12683
12684The only argument is a pointer which is based on some object with
12685an unknown offset from the base of said object.
12686
12687Semantics:
12688""""""""""
12689
12690This intrinsic is used in the abstract machine model for GC to represent
12691the offset of an arbitrary derived pointer from its base pointer.
12692
12693This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by
12694replacing all uses of this callsite with the offset of a derived pointer from
12695its base pointer value. The replacement is done as part of the lowering to the
12696explicit statepoint model.
12697
12698Basically this call calculates difference between the derived pointer and its
12699base pointer (see :ref:`gc.get.pointer.base`) both ptrtoint casted. But
12700this cast done outside the :ref:`RewriteStatepointsForGC` pass could result
12701in the pointers lost for further lowering from the abstract model to the
12702explicit physical one.
12703
12704Code Generator Intrinsics
12705-------------------------
12706
12707These intrinsics are provided by LLVM to expose special features that
12708may only be implemented with code generator support.
12709
12710'``llvm.returnaddress``' Intrinsic
12711^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12712
12713Syntax:
12714"""""""
12715
12716::
12717
12718      declare i8* @llvm.returnaddress(i32 <level>)
12719
12720Overview:
12721"""""""""
12722
12723The '``llvm.returnaddress``' intrinsic attempts to compute a
12724target-specific value indicating the return address of the current
12725function or one of its callers.
12726
12727Arguments:
12728""""""""""
12729
12730The argument to this intrinsic indicates which function to return the
12731address for. Zero indicates the calling function, one indicates its
12732caller, etc. The argument is **required** to be a constant integer
12733value.
12734
12735Semantics:
12736""""""""""
12737
12738The '``llvm.returnaddress``' intrinsic either returns a pointer
12739indicating the return address of the specified call frame, or zero if it
12740cannot be identified. The value returned by this intrinsic is likely to
12741be incorrect or 0 for arguments other than zero, so it should only be
12742used for debugging purposes.
12743
12744Note that calling this intrinsic does not prevent function inlining or
12745other aggressive transformations, so the value returned may not be that
12746of the obvious source-language caller.
12747
12748'``llvm.addressofreturnaddress``' Intrinsic
12749^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12750
12751Syntax:
12752"""""""
12753
12754::
12755
12756      declare i8* @llvm.addressofreturnaddress()
12757
12758Overview:
12759"""""""""
12760
12761The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific
12762pointer to the place in the stack frame where the return address of the
12763current function is stored.
12764
12765Semantics:
12766""""""""""
12767
12768Note that calling this intrinsic does not prevent function inlining or
12769other aggressive transformations, so the value returned may not be that
12770of the obvious source-language caller.
12771
12772This intrinsic is only implemented for x86 and aarch64.
12773
12774'``llvm.sponentry``' Intrinsic
12775^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12776
12777Syntax:
12778"""""""
12779
12780::
12781
12782      declare i8* @llvm.sponentry()
12783
12784Overview:
12785"""""""""
12786
12787The '``llvm.sponentry``' intrinsic returns the stack pointer value at
12788the entry of the current function calling this intrinsic.
12789
12790Semantics:
12791""""""""""
12792
12793Note this intrinsic is only verified on AArch64 and ARM.
12794
12795'``llvm.frameaddress``' Intrinsic
12796^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12797
12798Syntax:
12799"""""""
12800
12801::
12802
12803      declare i8* @llvm.frameaddress(i32 <level>)
12804
12805Overview:
12806"""""""""
12807
12808The '``llvm.frameaddress``' intrinsic attempts to return the
12809target-specific frame pointer value for the specified stack frame.
12810
12811Arguments:
12812""""""""""
12813
12814The argument to this intrinsic indicates which function to return the
12815frame pointer for. Zero indicates the calling function, one indicates
12816its caller, etc. The argument is **required** to be a constant integer
12817value.
12818
12819Semantics:
12820""""""""""
12821
12822The '``llvm.frameaddress``' intrinsic either returns a pointer
12823indicating the frame address of the specified call frame, or zero if it
12824cannot be identified. The value returned by this intrinsic is likely to
12825be incorrect or 0 for arguments other than zero, so it should only be
12826used for debugging purposes.
12827
12828Note that calling this intrinsic does not prevent function inlining or
12829other aggressive transformations, so the value returned may not be that
12830of the obvious source-language caller.
12831
12832'``llvm.swift.async.context.addr``' Intrinsic
12833^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12834
12835Syntax:
12836"""""""
12837
12838::
12839
12840      declare i8** @llvm.swift.async.context.addr()
12841
12842Overview:
12843"""""""""
12844
12845The '``llvm.swift.async.context.addr``' intrinsic returns a pointer to
12846the part of the extended frame record containing the asynchronous
12847context of a Swift execution.
12848
12849Semantics:
12850""""""""""
12851
12852If the caller has a ``swiftasync`` parameter, that argument will initially
12853be stored at the returned address. If not, it will be initialized to null.
12854
12855'``llvm.localescape``' and '``llvm.localrecover``' Intrinsics
12856^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12857
12858Syntax:
12859"""""""
12860
12861::
12862
12863      declare void @llvm.localescape(...)
12864      declare i8* @llvm.localrecover(i8* %func, i8* %fp, i32 %idx)
12865
12866Overview:
12867"""""""""
12868
12869The '``llvm.localescape``' intrinsic escapes offsets of a collection of static
12870allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a
12871live frame pointer to recover the address of the allocation. The offset is
12872computed during frame layout of the caller of ``llvm.localescape``.
12873
12874Arguments:
12875""""""""""
12876
12877All arguments to '``llvm.localescape``' must be pointers to static allocas or
12878casts of static allocas. Each function can only call '``llvm.localescape``'
12879once, and it can only do so from the entry block.
12880
12881The ``func`` argument to '``llvm.localrecover``' must be a constant
12882bitcasted pointer to a function defined in the current module. The code
12883generator cannot determine the frame allocation offset of functions defined in
12884other modules.
12885
12886The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a
12887call frame that is currently live. The return value of '``llvm.localaddress``'
12888is one way to produce such a value, but various runtimes also expose a suitable
12889pointer in platform-specific ways.
12890
12891The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to
12892'``llvm.localescape``' to recover. It is zero-indexed.
12893
12894Semantics:
12895""""""""""
12896
12897These intrinsics allow a group of functions to share access to a set of local
12898stack allocations of a one parent function. The parent function may call the
12899'``llvm.localescape``' intrinsic once from the function entry block, and the
12900child functions can use '``llvm.localrecover``' to access the escaped allocas.
12901The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where
12902the escaped allocas are allocated, which would break attempts to use
12903'``llvm.localrecover``'.
12904
12905'``llvm.seh.try.begin``' and '``llvm.seh.try.end``' Intrinsics
12906^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12907
12908Syntax:
12909"""""""
12910
12911::
12912
12913      declare void @llvm.seh.try.begin()
12914      declare void @llvm.seh.try.end()
12915
12916Overview:
12917"""""""""
12918
12919The '``llvm.seh.try.begin``' and '``llvm.seh.try.end``' intrinsics mark
12920the boundary of a _try region for Windows SEH Asynchrous Exception Handling.
12921
12922Semantics:
12923""""""""""
12924
12925When a C-function is compiled with Windows SEH Asynchrous Exception option,
12926-feh_asynch (aka MSVC -EHa), these two intrinsics are injected to mark _try
12927boundary and to prevent potential exceptions from being moved across boundary.
12928Any set of operations can then be confined to the region by reading their leaf
12929inputs via volatile loads and writing their root outputs via volatile stores.
12930
12931'``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' Intrinsics
12932^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12933
12934Syntax:
12935"""""""
12936
12937::
12938
12939      declare void @llvm.seh.scope.begin()
12940      declare void @llvm.seh.scope.end()
12941
12942Overview:
12943"""""""""
12944
12945The '``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' intrinsics mark
12946the boundary of a CPP object lifetime for Windows SEH Asynchrous Exception
12947Handling (MSVC option -EHa).
12948
12949Semantics:
12950""""""""""
12951
12952LLVM's ordinary exception-handling representation associates EH cleanups and
12953handlers only with ``invoke``s, which normally correspond only to call sites.  To
12954support arbitrary faulting instructions, it must be possible to recover the current
12955EH scope for any instruction.  Turning every operation in LLVM that could fault
12956into an ``invoke`` of a new, potentially-throwing intrinsic would require adding a
12957large number of intrinsics, impede optimization of those operations, and make
12958compilation slower by introducing many extra basic blocks.  These intrinsics can
12959be used instead to mark the region protected by a cleanup, such as for a local
12960C++ object with a non-trivial destructor.  ``llvm.seh.scope.begin`` is used to mark
12961the start of the region; it is always called with ``invoke``, with the unwind block
12962being the desired unwind destination for any potentially-throwing instructions
12963within the region.  `llvm.seh.scope.end` is used to mark when the scope ends
12964and the EH cleanup is no longer required (e.g. because the destructor is being
12965called).
12966
12967.. _int_read_register:
12968.. _int_read_volatile_register:
12969.. _int_write_register:
12970
12971'``llvm.read_register``', '``llvm.read_volatile_register``', and '``llvm.write_register``' Intrinsics
12972^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12973
12974Syntax:
12975"""""""
12976
12977::
12978
12979      declare i32 @llvm.read_register.i32(metadata)
12980      declare i64 @llvm.read_register.i64(metadata)
12981      declare i32 @llvm.read_volatile_register.i32(metadata)
12982      declare i64 @llvm.read_volatile_register.i64(metadata)
12983      declare void @llvm.write_register.i32(metadata, i32 @value)
12984      declare void @llvm.write_register.i64(metadata, i64 @value)
12985      !0 = !{!"sp\00"}
12986
12987Overview:
12988"""""""""
12989
12990The '``llvm.read_register``', '``llvm.read_volatile_register``', and
12991'``llvm.write_register``' intrinsics provide access to the named register.
12992The register must be valid on the architecture being compiled to. The type
12993needs to be compatible with the register being read.
12994
12995Semantics:
12996""""""""""
12997
12998The '``llvm.read_register``' and '``llvm.read_volatile_register``' intrinsics
12999return the current value of the register, where possible. The
13000'``llvm.write_register``' intrinsic sets the current value of the register,
13001where possible.
13002
13003A call to '``llvm.read_volatile_register``' is assumed to have side-effects
13004and possibly return a different value each time (e.g. for a timer register).
13005
13006This is useful to implement named register global variables that need
13007to always be mapped to a specific register, as is common practice on
13008bare-metal programs including OS kernels.
13009
13010The compiler doesn't check for register availability or use of the used
13011register in surrounding code, including inline assembly. Because of that,
13012allocatable registers are not supported.
13013
13014Warning: So far it only works with the stack pointer on selected
13015architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of
13016work is needed to support other registers and even more so, allocatable
13017registers.
13018
13019.. _int_stacksave:
13020
13021'``llvm.stacksave``' Intrinsic
13022^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13023
13024Syntax:
13025"""""""
13026
13027::
13028
13029      declare i8* @llvm.stacksave()
13030
13031Overview:
13032"""""""""
13033
13034The '``llvm.stacksave``' intrinsic is used to remember the current state
13035of the function stack, for use with
13036:ref:`llvm.stackrestore <int_stackrestore>`. This is useful for
13037implementing language features like scoped automatic variable sized
13038arrays in C99.
13039
13040Semantics:
13041""""""""""
13042
13043This intrinsic returns an opaque pointer value that can be passed to
13044:ref:`llvm.stackrestore <int_stackrestore>`. When an
13045``llvm.stackrestore`` intrinsic is executed with a value saved from
13046``llvm.stacksave``, it effectively restores the state of the stack to
13047the state it was in when the ``llvm.stacksave`` intrinsic executed. In
13048practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that
13049were allocated after the ``llvm.stacksave`` was executed.
13050
13051.. _int_stackrestore:
13052
13053'``llvm.stackrestore``' Intrinsic
13054^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13055
13056Syntax:
13057"""""""
13058
13059::
13060
13061      declare void @llvm.stackrestore(i8* %ptr)
13062
13063Overview:
13064"""""""""
13065
13066The '``llvm.stackrestore``' intrinsic is used to restore the state of
13067the function stack to the state it was in when the corresponding
13068:ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is
13069useful for implementing language features like scoped automatic variable
13070sized arrays in C99.
13071
13072Semantics:
13073""""""""""
13074
13075See the description for :ref:`llvm.stacksave <int_stacksave>`.
13076
13077.. _int_get_dynamic_area_offset:
13078
13079'``llvm.get.dynamic.area.offset``' Intrinsic
13080^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13081
13082Syntax:
13083"""""""
13084
13085::
13086
13087      declare i32 @llvm.get.dynamic.area.offset.i32()
13088      declare i64 @llvm.get.dynamic.area.offset.i64()
13089
13090Overview:
13091"""""""""
13092
13093      The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to
13094      get the offset from native stack pointer to the address of the most
13095      recent dynamic alloca on the caller's stack. These intrinsics are
13096      intended for use in combination with
13097      :ref:`llvm.stacksave <int_stacksave>` to get a
13098      pointer to the most recent dynamic alloca. This is useful, for example,
13099      for AddressSanitizer's stack unpoisoning routines.
13100
13101Semantics:
13102""""""""""
13103
13104      These intrinsics return a non-negative integer value that can be used to
13105      get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>`
13106      on the caller's stack. In particular, for targets where stack grows downwards,
13107      adding this offset to the native stack pointer would get the address of the most
13108      recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more
13109      complicated, because subtracting this value from stack pointer would get the address
13110      one past the end of the most recent dynamic alloca.
13111
13112      Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
13113      returns just a zero, for others, such as PowerPC and PowerPC64, it returns a
13114      compile-time-known constant value.
13115
13116      The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
13117      must match the target's default address space's (address space 0) pointer type.
13118
13119'``llvm.prefetch``' Intrinsic
13120^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13121
13122Syntax:
13123"""""""
13124
13125::
13126
13127      declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>)
13128
13129Overview:
13130"""""""""
13131
13132The '``llvm.prefetch``' intrinsic is a hint to the code generator to
13133insert a prefetch instruction if supported; otherwise, it is a noop.
13134Prefetches have no effect on the behavior of the program but can change
13135its performance characteristics.
13136
13137Arguments:
13138""""""""""
13139
13140``address`` is the address to be prefetched, ``rw`` is the specifier
13141determining if the fetch should be for a read (0) or write (1), and
13142``locality`` is a temporal locality specifier ranging from (0) - no
13143locality, to (3) - extremely local keep in cache. The ``cache type``
13144specifies whether the prefetch is performed on the data (1) or
13145instruction (0) cache. The ``rw``, ``locality`` and ``cache type``
13146arguments must be constant integers.
13147
13148Semantics:
13149""""""""""
13150
13151This intrinsic does not modify the behavior of the program. In
13152particular, prefetches cannot trap and do not produce a value. On
13153targets that support this intrinsic, the prefetch can provide hints to
13154the processor cache for better performance.
13155
13156'``llvm.pcmarker``' Intrinsic
13157^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13158
13159Syntax:
13160"""""""
13161
13162::
13163
13164      declare void @llvm.pcmarker(i32 <id>)
13165
13166Overview:
13167"""""""""
13168
13169The '``llvm.pcmarker``' intrinsic is a method to export a Program
13170Counter (PC) in a region of code to simulators and other tools. The
13171method is target specific, but it is expected that the marker will use
13172exported symbols to transmit the PC of the marker. The marker makes no
13173guarantees that it will remain with any specific instruction after
13174optimizations. It is possible that the presence of a marker will inhibit
13175optimizations. The intended use is to be inserted after optimizations to
13176allow correlations of simulation runs.
13177
13178Arguments:
13179""""""""""
13180
13181``id`` is a numerical id identifying the marker.
13182
13183Semantics:
13184""""""""""
13185
13186This intrinsic does not modify the behavior of the program. Backends
13187that do not support this intrinsic may ignore it.
13188
13189'``llvm.readcyclecounter``' Intrinsic
13190^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13191
13192Syntax:
13193"""""""
13194
13195::
13196
13197      declare i64 @llvm.readcyclecounter()
13198
13199Overview:
13200"""""""""
13201
13202The '``llvm.readcyclecounter``' intrinsic provides access to the cycle
13203counter register (or similar low latency, high accuracy clocks) on those
13204targets that support it. On X86, it should map to RDTSC. On Alpha, it
13205should map to RPCC. As the backing counters overflow quickly (on the
13206order of 9 seconds on alpha), this should only be used for small
13207timings.
13208
13209Semantics:
13210""""""""""
13211
13212When directly supported, reading the cycle counter should not modify any
13213memory. Implementations are allowed to either return an application
13214specific value or a system wide value. On backends without support, this
13215is lowered to a constant 0.
13216
13217Note that runtime support may be conditional on the privilege-level code is
13218running at and the host platform.
13219
13220'``llvm.clear_cache``' Intrinsic
13221^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13222
13223Syntax:
13224"""""""
13225
13226::
13227
13228      declare void @llvm.clear_cache(i8*, i8*)
13229
13230Overview:
13231"""""""""
13232
13233The '``llvm.clear_cache``' intrinsic ensures visibility of modifications
13234in the specified range to the execution unit of the processor. On
13235targets with non-unified instruction and data cache, the implementation
13236flushes the instruction cache.
13237
13238Semantics:
13239""""""""""
13240
13241On platforms with coherent instruction and data caches (e.g. x86), this
13242intrinsic is a nop. On platforms with non-coherent instruction and data
13243cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate
13244instructions or a system call, if cache flushing requires special
13245privileges.
13246
13247The default behavior is to emit a call to ``__clear_cache`` from the run
13248time library.
13249
13250This intrinsic does *not* empty the instruction pipeline. Modifications
13251of the current function are outside the scope of the intrinsic.
13252
13253'``llvm.instrprof.increment``' Intrinsic
13254^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13255
13256Syntax:
13257"""""""
13258
13259::
13260
13261      declare void @llvm.instrprof.increment(i8* <name>, i64 <hash>,
13262                                             i32 <num-counters>, i32 <index>)
13263
13264Overview:
13265"""""""""
13266
13267The '``llvm.instrprof.increment``' intrinsic can be emitted by a
13268frontend for use with instrumentation based profiling. These will be
13269lowered by the ``-instrprof`` pass to generate execution counts of a
13270program at runtime.
13271
13272Arguments:
13273""""""""""
13274
13275The first argument is a pointer to a global variable containing the
13276name of the entity being instrumented. This should generally be the
13277(mangled) function name for a set of counters.
13278
13279The second argument is a hash value that can be used by the consumer
13280of the profile data to detect changes to the instrumented source, and
13281the third is the number of counters associated with ``name``. It is an
13282error if ``hash`` or ``num-counters`` differ between two instances of
13283``instrprof.increment`` that refer to the same name.
13284
13285The last argument refers to which of the counters for ``name`` should
13286be incremented. It should be a value between 0 and ``num-counters``.
13287
13288Semantics:
13289""""""""""
13290
13291This intrinsic represents an increment of a profiling counter. It will
13292cause the ``-instrprof`` pass to generate the appropriate data
13293structures and the code to increment the appropriate value, in a
13294format that can be written out by a compiler runtime and consumed via
13295the ``llvm-profdata`` tool.
13296
13297'``llvm.instrprof.increment.step``' Intrinsic
13298^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13299
13300Syntax:
13301"""""""
13302
13303::
13304
13305      declare void @llvm.instrprof.increment.step(i8* <name>, i64 <hash>,
13306                                                  i32 <num-counters>,
13307                                                  i32 <index>, i64 <step>)
13308
13309Overview:
13310"""""""""
13311
13312The '``llvm.instrprof.increment.step``' intrinsic is an extension to
13313the '``llvm.instrprof.increment``' intrinsic with an additional fifth
13314argument to specify the step of the increment.
13315
13316Arguments:
13317""""""""""
13318The first four arguments are the same as '``llvm.instrprof.increment``'
13319intrinsic.
13320
13321The last argument specifies the value of the increment of the counter variable.
13322
13323Semantics:
13324""""""""""
13325See description of '``llvm.instrprof.increment``' intrinsic.
13326
13327'``llvm.instrprof.cover``' Intrinsic
13328^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13329
13330Syntax:
13331"""""""
13332
13333::
13334
13335      declare void @llvm.instrprof.cover(i8* <name>, i64 <hash>,
13336                                         i32 <num-counters>, i32 <index>)
13337
13338Overview:
13339"""""""""
13340
13341The '``llvm.instrprof.cover``' intrinsic is used to implement coverage
13342instrumentation.
13343
13344Arguments:
13345""""""""""
13346The arguments are the same as the first four arguments of
13347'``llvm.instrprof.increment``'.
13348
13349Semantics:
13350""""""""""
13351Similar to the '``llvm.instrprof.increment``' intrinsic, but it stores zero to
13352the profiling variable to signify that the function has been covered. We store
13353zero because this is more efficient on some targets.
13354
13355'``llvm.instrprof.value.profile``' Intrinsic
13356^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13357
13358Syntax:
13359"""""""
13360
13361::
13362
13363      declare void @llvm.instrprof.value.profile(i8* <name>, i64 <hash>,
13364                                                 i64 <value>, i32 <value_kind>,
13365                                                 i32 <index>)
13366
13367Overview:
13368"""""""""
13369
13370The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a
13371frontend for use with instrumentation based profiling. This will be
13372lowered by the ``-instrprof`` pass to find out the target values,
13373instrumented expressions take in a program at runtime.
13374
13375Arguments:
13376""""""""""
13377
13378The first argument is a pointer to a global variable containing the
13379name of the entity being instrumented. ``name`` should generally be the
13380(mangled) function name for a set of counters.
13381
13382The second argument is a hash value that can be used by the consumer
13383of the profile data to detect changes to the instrumented source. It
13384is an error if ``hash`` differs between two instances of
13385``llvm.instrprof.*`` that refer to the same name.
13386
13387The third argument is the value of the expression being profiled. The profiled
13388expression's value should be representable as an unsigned 64-bit value. The
13389fourth argument represents the kind of value profiling that is being done. The
13390supported value profiling kinds are enumerated through the
13391``InstrProfValueKind`` type declared in the
13392``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the
13393index of the instrumented expression within ``name``. It should be >= 0.
13394
13395Semantics:
13396""""""""""
13397
13398This intrinsic represents the point where a call to a runtime routine
13399should be inserted for value profiling of target expressions. ``-instrprof``
13400pass will generate the appropriate data structures and replace the
13401``llvm.instrprof.value.profile`` intrinsic with the call to the profile
13402runtime library with proper arguments.
13403
13404'``llvm.thread.pointer``' Intrinsic
13405^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13406
13407Syntax:
13408"""""""
13409
13410::
13411
13412      declare i8* @llvm.thread.pointer()
13413
13414Overview:
13415"""""""""
13416
13417The '``llvm.thread.pointer``' intrinsic returns the value of the thread
13418pointer.
13419
13420Semantics:
13421""""""""""
13422
13423The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area
13424for the current thread.  The exact semantics of this value are target
13425specific: it may point to the start of TLS area, to the end, or somewhere
13426in the middle.  Depending on the target, this intrinsic may read a register,
13427call a helper function, read from an alternate memory space, or perform
13428other operations necessary to locate the TLS area.  Not all targets support
13429this intrinsic.
13430
13431'``llvm.call.preallocated.setup``' Intrinsic
13432^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13433
13434Syntax:
13435"""""""
13436
13437::
13438
13439      declare token @llvm.call.preallocated.setup(i32 %num_args)
13440
13441Overview:
13442"""""""""
13443
13444The '``llvm.call.preallocated.setup``' intrinsic returns a token which can
13445be used with a call's ``"preallocated"`` operand bundle to indicate that
13446certain arguments are allocated and initialized before the call.
13447
13448Semantics:
13449""""""""""
13450
13451The '``llvm.call.preallocated.setup``' intrinsic returns a token which is
13452associated with at most one call. The token can be passed to
13453'``@llvm.call.preallocated.arg``' to get a pointer to get that
13454corresponding argument. The token must be the parameter to a
13455``"preallocated"`` operand bundle for the corresponding call.
13456
13457Nested calls to '``llvm.call.preallocated.setup``' are allowed, but must
13458be properly nested. e.g.
13459
13460:: code-block:: llvm
13461
13462      %t1 = call token @llvm.call.preallocated.setup(i32 0)
13463      %t2 = call token @llvm.call.preallocated.setup(i32 0)
13464      call void foo() ["preallocated"(token %t2)]
13465      call void foo() ["preallocated"(token %t1)]
13466
13467is allowed, but not
13468
13469:: code-block:: llvm
13470
13471      %t1 = call token @llvm.call.preallocated.setup(i32 0)
13472      %t2 = call token @llvm.call.preallocated.setup(i32 0)
13473      call void foo() ["preallocated"(token %t1)]
13474      call void foo() ["preallocated"(token %t2)]
13475
13476.. _int_call_preallocated_arg:
13477
13478'``llvm.call.preallocated.arg``' Intrinsic
13479^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13480
13481Syntax:
13482"""""""
13483
13484::
13485
13486      declare i8* @llvm.call.preallocated.arg(token %setup_token, i32 %arg_index)
13487
13488Overview:
13489"""""""""
13490
13491The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the
13492corresponding preallocated argument for the preallocated call.
13493
13494Semantics:
13495""""""""""
13496
13497The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the
13498``%arg_index``th argument with the ``preallocated`` attribute for
13499the call associated with the ``%setup_token``, which must be from
13500'``llvm.call.preallocated.setup``'.
13501
13502A call to '``llvm.call.preallocated.arg``' must have a call site
13503``preallocated`` attribute. The type of the ``preallocated`` attribute must
13504match the type used by the ``preallocated`` attribute of the corresponding
13505argument at the preallocated call. The type is used in the case that an
13506``llvm.call.preallocated.setup`` does not have a corresponding call (e.g. due
13507to DCE), where otherwise we cannot know how large the arguments are.
13508
13509It is undefined behavior if this is called with a token from an
13510'``llvm.call.preallocated.setup``' if another
13511'``llvm.call.preallocated.setup``' has already been called or if the
13512preallocated call corresponding to the '``llvm.call.preallocated.setup``'
13513has already been called.
13514
13515.. _int_call_preallocated_teardown:
13516
13517'``llvm.call.preallocated.teardown``' Intrinsic
13518^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13519
13520Syntax:
13521"""""""
13522
13523::
13524
13525      declare i8* @llvm.call.preallocated.teardown(token %setup_token)
13526
13527Overview:
13528"""""""""
13529
13530The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack
13531created by a '``llvm.call.preallocated.setup``'.
13532
13533Semantics:
13534""""""""""
13535
13536The token argument must be a '``llvm.call.preallocated.setup``'.
13537
13538The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack
13539allocated by the corresponding '``llvm.call.preallocated.setup``'. Exactly
13540one of this or the preallocated call must be called to prevent stack leaks.
13541It is undefined behavior to call both a '``llvm.call.preallocated.teardown``'
13542and the preallocated call for a given '``llvm.call.preallocated.setup``'.
13543
13544For example, if the stack is allocated for a preallocated call by a
13545'``llvm.call.preallocated.setup``', then an initializer function called on an
13546allocated argument throws an exception, there should be a
13547'``llvm.call.preallocated.teardown``' in the exception handler to prevent
13548stack leaks.
13549
13550Following the nesting rules in '``llvm.call.preallocated.setup``', nested
13551calls to '``llvm.call.preallocated.setup``' and
13552'``llvm.call.preallocated.teardown``' are allowed but must be properly
13553nested.
13554
13555Example:
13556""""""""
13557
13558.. code-block:: llvm
13559
13560        %cs = call token @llvm.call.preallocated.setup(i32 1)
13561        %x = call i8* @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32)
13562        %y = bitcast i8* %x to i32*
13563        invoke void @constructor(i32* %y) to label %conta unwind label %contb
13564    conta:
13565        call void @foo1(i32* preallocated(i32) %y) ["preallocated"(token %cs)]
13566        ret void
13567    contb:
13568        %s = catchswitch within none [label %catch] unwind to caller
13569    catch:
13570        %p = catchpad within %s []
13571        call void @llvm.call.preallocated.teardown(token %cs)
13572        ret void
13573
13574Standard C/C++ Library Intrinsics
13575---------------------------------
13576
13577LLVM provides intrinsics for a few important standard C/C++ library
13578functions. These intrinsics allow source-language front-ends to pass
13579information about the alignment of the pointer arguments to the code
13580generator, providing opportunity for more efficient code generation.
13581
13582
13583'``llvm.abs.*``' Intrinsic
13584^^^^^^^^^^^^^^^^^^^^^^^^^^
13585
13586Syntax:
13587"""""""
13588
13589This is an overloaded intrinsic. You can use ``llvm.abs`` on any
13590integer bit width or any vector of integer elements.
13591
13592::
13593
13594      declare i32 @llvm.abs.i32(i32 <src>, i1 <is_int_min_poison>)
13595      declare <4 x i32> @llvm.abs.v4i32(<4 x i32> <src>, i1 <is_int_min_poison>)
13596
13597Overview:
13598"""""""""
13599
13600The '``llvm.abs``' family of intrinsic functions returns the absolute value
13601of an argument.
13602
13603Arguments:
13604""""""""""
13605
13606The first argument is the value for which the absolute value is to be returned.
13607This argument may be of any integer type or a vector with integer element type.
13608The return type must match the first argument type.
13609
13610The second argument must be a constant and is a flag to indicate whether the
13611result value of the '``llvm.abs``' intrinsic is a
13612:ref:`poison value <poisonvalues>` if the argument is statically or dynamically
13613an ``INT_MIN`` value.
13614
13615Semantics:
13616""""""""""
13617
13618The '``llvm.abs``' intrinsic returns the magnitude (always positive) of the
13619argument or each element of a vector argument.". If the argument is ``INT_MIN``,
13620then the result is also ``INT_MIN`` if ``is_int_min_poison == 0`` and
13621``poison`` otherwise.
13622
13623
13624'``llvm.smax.*``' Intrinsic
13625^^^^^^^^^^^^^^^^^^^^^^^^^^^
13626
13627Syntax:
13628"""""""
13629
13630This is an overloaded intrinsic. You can use ``@llvm.smax`` on any
13631integer bit width or any vector of integer elements.
13632
13633::
13634
13635      declare i32 @llvm.smax.i32(i32 %a, i32 %b)
13636      declare <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> %b)
13637
13638Overview:
13639"""""""""
13640
13641Return the larger of ``%a`` and ``%b`` comparing the values as signed integers.
13642Vector intrinsics operate on a per-element basis. The larger element of ``%a``
13643and ``%b`` at a given index is returned for that index.
13644
13645Arguments:
13646""""""""""
13647
13648The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
13649integer element type. The argument types must match each other, and the return
13650type must match the argument type.
13651
13652
13653'``llvm.smin.*``' Intrinsic
13654^^^^^^^^^^^^^^^^^^^^^^^^^^^
13655
13656Syntax:
13657"""""""
13658
13659This is an overloaded intrinsic. You can use ``@llvm.smin`` on any
13660integer bit width or any vector of integer elements.
13661
13662::
13663
13664      declare i32 @llvm.smin.i32(i32 %a, i32 %b)
13665      declare <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> %b)
13666
13667Overview:
13668"""""""""
13669
13670Return the smaller of ``%a`` and ``%b`` comparing the values as signed integers.
13671Vector intrinsics operate on a per-element basis. The smaller element of ``%a``
13672and ``%b`` at a given index is returned for that index.
13673
13674Arguments:
13675""""""""""
13676
13677The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
13678integer element type. The argument types must match each other, and the return
13679type must match the argument type.
13680
13681
13682'``llvm.umax.*``' Intrinsic
13683^^^^^^^^^^^^^^^^^^^^^^^^^^^
13684
13685Syntax:
13686"""""""
13687
13688This is an overloaded intrinsic. You can use ``@llvm.umax`` on any
13689integer bit width or any vector of integer elements.
13690
13691::
13692
13693      declare i32 @llvm.umax.i32(i32 %a, i32 %b)
13694      declare <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> %b)
13695
13696Overview:
13697"""""""""
13698
13699Return the larger of ``%a`` and ``%b`` comparing the values as unsigned
13700integers. Vector intrinsics operate on a per-element basis. The larger element
13701of ``%a`` and ``%b`` at a given index is returned for that index.
13702
13703Arguments:
13704""""""""""
13705
13706The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
13707integer element type. The argument types must match each other, and the return
13708type must match the argument type.
13709
13710
13711'``llvm.umin.*``' Intrinsic
13712^^^^^^^^^^^^^^^^^^^^^^^^^^^
13713
13714Syntax:
13715"""""""
13716
13717This is an overloaded intrinsic. You can use ``@llvm.umin`` on any
13718integer bit width or any vector of integer elements.
13719
13720::
13721
13722      declare i32 @llvm.umin.i32(i32 %a, i32 %b)
13723      declare <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> %b)
13724
13725Overview:
13726"""""""""
13727
13728Return the smaller of ``%a`` and ``%b`` comparing the values as unsigned
13729integers. Vector intrinsics operate on a per-element basis. The smaller element
13730of ``%a`` and ``%b`` at a given index is returned for that index.
13731
13732Arguments:
13733""""""""""
13734
13735The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
13736integer element type. The argument types must match each other, and the return
13737type must match the argument type.
13738
13739
13740.. _int_memcpy:
13741
13742'``llvm.memcpy``' Intrinsic
13743^^^^^^^^^^^^^^^^^^^^^^^^^^^
13744
13745Syntax:
13746"""""""
13747
13748This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any
13749integer bit width and for different address spaces. Not all targets
13750support all bit widths however.
13751
13752::
13753
13754      declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
13755                                              i32 <len>, i1 <isvolatile>)
13756      declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
13757                                              i64 <len>, i1 <isvolatile>)
13758
13759Overview:
13760"""""""""
13761
13762The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
13763source location to the destination location.
13764
13765Note that, unlike the standard libc function, the ``llvm.memcpy.*``
13766intrinsics do not return a value, takes extra isvolatile
13767arguments and the pointers can be in specified address spaces.
13768
13769Arguments:
13770""""""""""
13771
13772The first argument is a pointer to the destination, the second is a
13773pointer to the source. The third argument is an integer argument
13774specifying the number of bytes to copy, and the fourth is a
13775boolean indicating a volatile access.
13776
13777The :ref:`align <attr_align>` parameter attribute can be provided
13778for the first and second arguments.
13779
13780If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is
13781a :ref:`volatile operation <volatile>`. The detailed access behavior is not
13782very cleanly specified and it is unwise to depend on it.
13783
13784Semantics:
13785""""""""""
13786
13787The '``llvm.memcpy.*``' intrinsics copy a block of memory from the source
13788location to the destination location, which must either be equal or
13789non-overlapping. It copies "len" bytes of memory over. If the argument is known
13790to be aligned to some boundary, this can be specified as an attribute on the
13791argument.
13792
13793If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
13794the arguments.
13795If ``<len>`` is not a well-defined value, the behavior is undefined.
13796If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined,
13797otherwise the behavior is undefined.
13798
13799.. _int_memcpy_inline:
13800
13801'``llvm.memcpy.inline``' Intrinsic
13802^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13803
13804Syntax:
13805"""""""
13806
13807This is an overloaded intrinsic. You can use ``llvm.memcpy.inline`` on any
13808integer bit width and for different address spaces. Not all targets
13809support all bit widths however.
13810
13811::
13812
13813      declare void @llvm.memcpy.inline.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
13814                                                     i32 <len>, i1 <isvolatile>)
13815      declare void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
13816                                                     i64 <len>, i1 <isvolatile>)
13817
13818Overview:
13819"""""""""
13820
13821The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the
13822source location to the destination location and guarantees that no external
13823functions are called.
13824
13825Note that, unlike the standard libc function, the ``llvm.memcpy.inline.*``
13826intrinsics do not return a value, takes extra isvolatile
13827arguments and the pointers can be in specified address spaces.
13828
13829Arguments:
13830""""""""""
13831
13832The first argument is a pointer to the destination, the second is a
13833pointer to the source. The third argument is a constant integer argument
13834specifying the number of bytes to copy, and the fourth is a
13835boolean indicating a volatile access.
13836
13837The :ref:`align <attr_align>` parameter attribute can be provided
13838for the first and second arguments.
13839
13840If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy.inline`` call is
13841a :ref:`volatile operation <volatile>`. The detailed access behavior is not
13842very cleanly specified and it is unwise to depend on it.
13843
13844Semantics:
13845""""""""""
13846
13847The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the
13848source location to the destination location, which are not allowed to
13849overlap. It copies "len" bytes of memory over. If the argument is known
13850to be aligned to some boundary, this can be specified as an attribute on
13851the argument.
13852The behavior of '``llvm.memcpy.inline.*``' is equivalent to the behavior of
13853'``llvm.memcpy.*``', but the generated code is guaranteed not to call any
13854external functions.
13855
13856.. _int_memmove:
13857
13858'``llvm.memmove``' Intrinsic
13859^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13860
13861Syntax:
13862"""""""
13863
13864This is an overloaded intrinsic. You can use llvm.memmove on any integer
13865bit width and for different address space. Not all targets support all
13866bit widths however.
13867
13868::
13869
13870      declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
13871                                               i32 <len>, i1 <isvolatile>)
13872      declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
13873                                               i64 <len>, i1 <isvolatile>)
13874
13875Overview:
13876"""""""""
13877
13878The '``llvm.memmove.*``' intrinsics move a block of memory from the
13879source location to the destination location. It is similar to the
13880'``llvm.memcpy``' intrinsic but allows the two memory locations to
13881overlap.
13882
13883Note that, unlike the standard libc function, the ``llvm.memmove.*``
13884intrinsics do not return a value, takes an extra isvolatile
13885argument and the pointers can be in specified address spaces.
13886
13887Arguments:
13888""""""""""
13889
13890The first argument is a pointer to the destination, the second is a
13891pointer to the source. The third argument is an integer argument
13892specifying the number of bytes to copy, and the fourth is a
13893boolean indicating a volatile access.
13894
13895The :ref:`align <attr_align>` parameter attribute can be provided
13896for the first and second arguments.
13897
13898If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call
13899is a :ref:`volatile operation <volatile>`. The detailed access behavior is
13900not very cleanly specified and it is unwise to depend on it.
13901
13902Semantics:
13903""""""""""
13904
13905The '``llvm.memmove.*``' intrinsics copy a block of memory from the
13906source location to the destination location, which may overlap. It
13907copies "len" bytes of memory over. If the argument is known to be
13908aligned to some boundary, this can be specified as an attribute on
13909the argument.
13910
13911If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
13912the arguments.
13913If ``<len>`` is not a well-defined value, the behavior is undefined.
13914If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined,
13915otherwise the behavior is undefined.
13916
13917.. _int_memset:
13918
13919'``llvm.memset.*``' Intrinsics
13920^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13921
13922Syntax:
13923"""""""
13924
13925This is an overloaded intrinsic. You can use llvm.memset on any integer
13926bit width and for different address spaces. However, not all targets
13927support all bit widths.
13928
13929::
13930
13931      declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>,
13932                                         i32 <len>, i1 <isvolatile>)
13933      declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>,
13934                                         i64 <len>, i1 <isvolatile>)
13935
13936Overview:
13937"""""""""
13938
13939The '``llvm.memset.*``' intrinsics fill a block of memory with a
13940particular byte value.
13941
13942Note that, unlike the standard libc function, the ``llvm.memset``
13943intrinsic does not return a value and takes an extra volatile
13944argument. Also, the destination can be in an arbitrary address space.
13945
13946Arguments:
13947""""""""""
13948
13949The first argument is a pointer to the destination to fill, the second
13950is the byte value with which to fill it, the third argument is an
13951integer argument specifying the number of bytes to fill, and the fourth
13952is a boolean indicating a volatile access.
13953
13954The :ref:`align <attr_align>` parameter attribute can be provided
13955for the first arguments.
13956
13957If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is
13958a :ref:`volatile operation <volatile>`. The detailed access behavior is not
13959very cleanly specified and it is unwise to depend on it.
13960
13961Semantics:
13962""""""""""
13963
13964The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting
13965at the destination location. If the argument is known to be
13966aligned to some boundary, this can be specified as an attribute on
13967the argument.
13968
13969If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
13970the arguments.
13971If ``<len>`` is not a well-defined value, the behavior is undefined.
13972If ``<len>`` is not zero, ``<dest>`` should be well-defined, otherwise the
13973behavior is undefined.
13974
13975.. _int_memset_inline:
13976
13977'``llvm.memset.inline``' Intrinsic
13978^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13979
13980Syntax:
13981"""""""
13982
13983This is an overloaded intrinsic. You can use ``llvm.memset.inline`` on any
13984integer bit width and for different address spaces. Not all targets
13985support all bit widths however.
13986
13987::
13988
13989      declare void @llvm.memset.inline.p0i8.p0i8.i32(i8* <dest>, i8 <val>,
13990                                                     i32 <len>,
13991                                                     i1 <isvolatile>)
13992      declare void @llvm.memset.inline.p0i8.p0i8.i64(i8* <dest>, i8 <val>,
13993                                                     i64 <len>,
13994                                                     i1 <isvolatile>)
13995
13996Overview:
13997"""""""""
13998
13999The '``llvm.memset.inline.*``' intrinsics fill a block of memory with a
14000particular byte value and guarantees that no external functions are called.
14001
14002Note that, unlike the standard libc function, the ``llvm.memset.inline.*``
14003intrinsics do not return a value, take an extra isvolatile argument and the
14004pointer can be in specified address spaces.
14005
14006Arguments:
14007""""""""""
14008
14009The first argument is a pointer to the destination to fill, the second
14010is the byte value with which to fill it, the third argument is a constant
14011integer argument specifying the number of bytes to fill, and the fourth
14012is a boolean indicating a volatile access.
14013
14014The :ref:`align <attr_align>` parameter attribute can be provided
14015for the first argument.
14016
14017If the ``isvolatile`` parameter is ``true``, the ``llvm.memset.inline`` call is
14018a :ref:`volatile operation <volatile>`. The detailed access behavior is not
14019very cleanly specified and it is unwise to depend on it.
14020
14021Semantics:
14022""""""""""
14023
14024The '``llvm.memset.inline.*``' intrinsics fill "len" bytes of memory starting
14025at the destination location. If the argument is known to be
14026aligned to some boundary, this can be specified as an attribute on
14027the argument.
14028
14029``len`` must be a constant expression.
14030If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
14031the arguments.
14032If ``<len>`` is not a well-defined value, the behavior is undefined.
14033If ``<len>`` is not zero, ``<dest>`` should be well-defined, otherwise the
14034behavior is undefined.
14035
14036The behavior of '``llvm.memset.inline.*``' is equivalent to the behavior of
14037'``llvm.memset.*``', but the generated code is guaranteed not to call any
14038external functions.
14039
14040'``llvm.sqrt.*``' Intrinsic
14041^^^^^^^^^^^^^^^^^^^^^^^^^^^
14042
14043Syntax:
14044"""""""
14045
14046This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any
14047floating-point or vector of floating-point type. Not all targets support
14048all types however.
14049
14050::
14051
14052      declare float     @llvm.sqrt.f32(float %Val)
14053      declare double    @llvm.sqrt.f64(double %Val)
14054      declare x86_fp80  @llvm.sqrt.f80(x86_fp80 %Val)
14055      declare fp128     @llvm.sqrt.f128(fp128 %Val)
14056      declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
14057
14058Overview:
14059"""""""""
14060
14061The '``llvm.sqrt``' intrinsics return the square root of the specified value.
14062
14063Arguments:
14064""""""""""
14065
14066The argument and return value are floating-point numbers of the same type.
14067
14068Semantics:
14069""""""""""
14070
14071Return the same value as a corresponding libm '``sqrt``' function but without
14072trapping or setting ``errno``. For types specified by IEEE-754, the result
14073matches a conforming libm implementation.
14074
14075When specified with the fast-math-flag 'afn', the result may be approximated
14076using a less accurate calculation.
14077
14078'``llvm.powi.*``' Intrinsic
14079^^^^^^^^^^^^^^^^^^^^^^^^^^^
14080
14081Syntax:
14082"""""""
14083
14084This is an overloaded intrinsic. You can use ``llvm.powi`` on any
14085floating-point or vector of floating-point type. Not all targets support
14086all types however.
14087
14088Generally, the only supported type for the exponent is the one matching
14089with the C type ``int``.
14090
14091::
14092
14093      declare float     @llvm.powi.f32.i32(float  %Val, i32 %power)
14094      declare double    @llvm.powi.f64.i16(double %Val, i16 %power)
14095      declare x86_fp80  @llvm.powi.f80.i32(x86_fp80  %Val, i32 %power)
14096      declare fp128     @llvm.powi.f128.i32(fp128 %Val, i32 %power)
14097      declare ppc_fp128 @llvm.powi.ppcf128.i32(ppc_fp128  %Val, i32 %power)
14098
14099Overview:
14100"""""""""
14101
14102The '``llvm.powi.*``' intrinsics return the first operand raised to the
14103specified (positive or negative) power. The order of evaluation of
14104multiplications is not defined. When a vector of floating-point type is
14105used, the second argument remains a scalar integer value.
14106
14107Arguments:
14108""""""""""
14109
14110The second argument is an integer power, and the first is a value to
14111raise to that power.
14112
14113Semantics:
14114""""""""""
14115
14116This function returns the first value raised to the second power with an
14117unspecified sequence of rounding operations.
14118
14119'``llvm.sin.*``' Intrinsic
14120^^^^^^^^^^^^^^^^^^^^^^^^^^
14121
14122Syntax:
14123"""""""
14124
14125This is an overloaded intrinsic. You can use ``llvm.sin`` on any
14126floating-point or vector of floating-point type. Not all targets support
14127all types however.
14128
14129::
14130
14131      declare float     @llvm.sin.f32(float  %Val)
14132      declare double    @llvm.sin.f64(double %Val)
14133      declare x86_fp80  @llvm.sin.f80(x86_fp80  %Val)
14134      declare fp128     @llvm.sin.f128(fp128 %Val)
14135      declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128  %Val)
14136
14137Overview:
14138"""""""""
14139
14140The '``llvm.sin.*``' intrinsics return the sine of the operand.
14141
14142Arguments:
14143""""""""""
14144
14145The argument and return value are floating-point numbers of the same type.
14146
14147Semantics:
14148""""""""""
14149
14150Return the same value as a corresponding libm '``sin``' function but without
14151trapping or setting ``errno``.
14152
14153When specified with the fast-math-flag 'afn', the result may be approximated
14154using a less accurate calculation.
14155
14156'``llvm.cos.*``' Intrinsic
14157^^^^^^^^^^^^^^^^^^^^^^^^^^
14158
14159Syntax:
14160"""""""
14161
14162This is an overloaded intrinsic. You can use ``llvm.cos`` on any
14163floating-point or vector of floating-point type. Not all targets support
14164all types however.
14165
14166::
14167
14168      declare float     @llvm.cos.f32(float  %Val)
14169      declare double    @llvm.cos.f64(double %Val)
14170      declare x86_fp80  @llvm.cos.f80(x86_fp80  %Val)
14171      declare fp128     @llvm.cos.f128(fp128 %Val)
14172      declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128  %Val)
14173
14174Overview:
14175"""""""""
14176
14177The '``llvm.cos.*``' intrinsics return the cosine of the operand.
14178
14179Arguments:
14180""""""""""
14181
14182The argument and return value are floating-point numbers of the same type.
14183
14184Semantics:
14185""""""""""
14186
14187Return the same value as a corresponding libm '``cos``' function but without
14188trapping or setting ``errno``.
14189
14190When specified with the fast-math-flag 'afn', the result may be approximated
14191using a less accurate calculation.
14192
14193'``llvm.pow.*``' Intrinsic
14194^^^^^^^^^^^^^^^^^^^^^^^^^^
14195
14196Syntax:
14197"""""""
14198
14199This is an overloaded intrinsic. You can use ``llvm.pow`` on any
14200floating-point or vector of floating-point type. Not all targets support
14201all types however.
14202
14203::
14204
14205      declare float     @llvm.pow.f32(float  %Val, float %Power)
14206      declare double    @llvm.pow.f64(double %Val, double %Power)
14207      declare x86_fp80  @llvm.pow.f80(x86_fp80  %Val, x86_fp80 %Power)
14208      declare fp128     @llvm.pow.f128(fp128 %Val, fp128 %Power)
14209      declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128  %Val, ppc_fp128 Power)
14210
14211Overview:
14212"""""""""
14213
14214The '``llvm.pow.*``' intrinsics return the first operand raised to the
14215specified (positive or negative) power.
14216
14217Arguments:
14218""""""""""
14219
14220The arguments and return value are floating-point numbers of the same type.
14221
14222Semantics:
14223""""""""""
14224
14225Return the same value as a corresponding libm '``pow``' function but without
14226trapping or setting ``errno``.
14227
14228When specified with the fast-math-flag 'afn', the result may be approximated
14229using a less accurate calculation.
14230
14231'``llvm.exp.*``' Intrinsic
14232^^^^^^^^^^^^^^^^^^^^^^^^^^
14233
14234Syntax:
14235"""""""
14236
14237This is an overloaded intrinsic. You can use ``llvm.exp`` on any
14238floating-point or vector of floating-point type. Not all targets support
14239all types however.
14240
14241::
14242
14243      declare float     @llvm.exp.f32(float  %Val)
14244      declare double    @llvm.exp.f64(double %Val)
14245      declare x86_fp80  @llvm.exp.f80(x86_fp80  %Val)
14246      declare fp128     @llvm.exp.f128(fp128 %Val)
14247      declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128  %Val)
14248
14249Overview:
14250"""""""""
14251
14252The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified
14253value.
14254
14255Arguments:
14256""""""""""
14257
14258The argument and return value are floating-point numbers of the same type.
14259
14260Semantics:
14261""""""""""
14262
14263Return the same value as a corresponding libm '``exp``' function but without
14264trapping or setting ``errno``.
14265
14266When specified with the fast-math-flag 'afn', the result may be approximated
14267using a less accurate calculation.
14268
14269'``llvm.exp2.*``' Intrinsic
14270^^^^^^^^^^^^^^^^^^^^^^^^^^^
14271
14272Syntax:
14273"""""""
14274
14275This is an overloaded intrinsic. You can use ``llvm.exp2`` on any
14276floating-point or vector of floating-point type. Not all targets support
14277all types however.
14278
14279::
14280
14281      declare float     @llvm.exp2.f32(float  %Val)
14282      declare double    @llvm.exp2.f64(double %Val)
14283      declare x86_fp80  @llvm.exp2.f80(x86_fp80  %Val)
14284      declare fp128     @llvm.exp2.f128(fp128 %Val)
14285      declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128  %Val)
14286
14287Overview:
14288"""""""""
14289
14290The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the
14291specified value.
14292
14293Arguments:
14294""""""""""
14295
14296The argument and return value are floating-point numbers of the same type.
14297
14298Semantics:
14299""""""""""
14300
14301Return the same value as a corresponding libm '``exp2``' function but without
14302trapping or setting ``errno``.
14303
14304When specified with the fast-math-flag 'afn', the result may be approximated
14305using a less accurate calculation.
14306
14307'``llvm.log.*``' Intrinsic
14308^^^^^^^^^^^^^^^^^^^^^^^^^^
14309
14310Syntax:
14311"""""""
14312
14313This is an overloaded intrinsic. You can use ``llvm.log`` on any
14314floating-point or vector of floating-point type. Not all targets support
14315all types however.
14316
14317::
14318
14319      declare float     @llvm.log.f32(float  %Val)
14320      declare double    @llvm.log.f64(double %Val)
14321      declare x86_fp80  @llvm.log.f80(x86_fp80  %Val)
14322      declare fp128     @llvm.log.f128(fp128 %Val)
14323      declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128  %Val)
14324
14325Overview:
14326"""""""""
14327
14328The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified
14329value.
14330
14331Arguments:
14332""""""""""
14333
14334The argument and return value are floating-point numbers of the same type.
14335
14336Semantics:
14337""""""""""
14338
14339Return the same value as a corresponding libm '``log``' function but without
14340trapping or setting ``errno``.
14341
14342When specified with the fast-math-flag 'afn', the result may be approximated
14343using a less accurate calculation.
14344
14345'``llvm.log10.*``' Intrinsic
14346^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14347
14348Syntax:
14349"""""""
14350
14351This is an overloaded intrinsic. You can use ``llvm.log10`` on any
14352floating-point or vector of floating-point type. Not all targets support
14353all types however.
14354
14355::
14356
14357      declare float     @llvm.log10.f32(float  %Val)
14358      declare double    @llvm.log10.f64(double %Val)
14359      declare x86_fp80  @llvm.log10.f80(x86_fp80  %Val)
14360      declare fp128     @llvm.log10.f128(fp128 %Val)
14361      declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128  %Val)
14362
14363Overview:
14364"""""""""
14365
14366The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the
14367specified value.
14368
14369Arguments:
14370""""""""""
14371
14372The argument and return value are floating-point numbers of the same type.
14373
14374Semantics:
14375""""""""""
14376
14377Return the same value as a corresponding libm '``log10``' function but without
14378trapping or setting ``errno``.
14379
14380When specified with the fast-math-flag 'afn', the result may be approximated
14381using a less accurate calculation.
14382
14383'``llvm.log2.*``' Intrinsic
14384^^^^^^^^^^^^^^^^^^^^^^^^^^^
14385
14386Syntax:
14387"""""""
14388
14389This is an overloaded intrinsic. You can use ``llvm.log2`` on any
14390floating-point or vector of floating-point type. Not all targets support
14391all types however.
14392
14393::
14394
14395      declare float     @llvm.log2.f32(float  %Val)
14396      declare double    @llvm.log2.f64(double %Val)
14397      declare x86_fp80  @llvm.log2.f80(x86_fp80  %Val)
14398      declare fp128     @llvm.log2.f128(fp128 %Val)
14399      declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128  %Val)
14400
14401Overview:
14402"""""""""
14403
14404The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified
14405value.
14406
14407Arguments:
14408""""""""""
14409
14410The argument and return value are floating-point numbers of the same type.
14411
14412Semantics:
14413""""""""""
14414
14415Return the same value as a corresponding libm '``log2``' function but without
14416trapping or setting ``errno``.
14417
14418When specified with the fast-math-flag 'afn', the result may be approximated
14419using a less accurate calculation.
14420
14421.. _int_fma:
14422
14423'``llvm.fma.*``' Intrinsic
14424^^^^^^^^^^^^^^^^^^^^^^^^^^
14425
14426Syntax:
14427"""""""
14428
14429This is an overloaded intrinsic. You can use ``llvm.fma`` on any
14430floating-point or vector of floating-point type. Not all targets support
14431all types however.
14432
14433::
14434
14435      declare float     @llvm.fma.f32(float  %a, float  %b, float  %c)
14436      declare double    @llvm.fma.f64(double %a, double %b, double %c)
14437      declare x86_fp80  @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c)
14438      declare fp128     @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c)
14439      declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c)
14440
14441Overview:
14442"""""""""
14443
14444The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation.
14445
14446Arguments:
14447""""""""""
14448
14449The arguments and return value are floating-point numbers of the same type.
14450
14451Semantics:
14452""""""""""
14453
14454Return the same value as a corresponding libm '``fma``' function but without
14455trapping or setting ``errno``.
14456
14457When specified with the fast-math-flag 'afn', the result may be approximated
14458using a less accurate calculation.
14459
14460'``llvm.fabs.*``' Intrinsic
14461^^^^^^^^^^^^^^^^^^^^^^^^^^^
14462
14463Syntax:
14464"""""""
14465
14466This is an overloaded intrinsic. You can use ``llvm.fabs`` on any
14467floating-point or vector of floating-point type. Not all targets support
14468all types however.
14469
14470::
14471
14472      declare float     @llvm.fabs.f32(float  %Val)
14473      declare double    @llvm.fabs.f64(double %Val)
14474      declare x86_fp80  @llvm.fabs.f80(x86_fp80 %Val)
14475      declare fp128     @llvm.fabs.f128(fp128 %Val)
14476      declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
14477
14478Overview:
14479"""""""""
14480
14481The '``llvm.fabs.*``' intrinsics return the absolute value of the
14482operand.
14483
14484Arguments:
14485""""""""""
14486
14487The argument and return value are floating-point numbers of the same
14488type.
14489
14490Semantics:
14491""""""""""
14492
14493This function returns the same values as the libm ``fabs`` functions
14494would, and handles error conditions in the same way.
14495
14496'``llvm.minnum.*``' Intrinsic
14497^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14498
14499Syntax:
14500"""""""
14501
14502This is an overloaded intrinsic. You can use ``llvm.minnum`` on any
14503floating-point or vector of floating-point type. Not all targets support
14504all types however.
14505
14506::
14507
14508      declare float     @llvm.minnum.f32(float %Val0, float %Val1)
14509      declare double    @llvm.minnum.f64(double %Val0, double %Val1)
14510      declare x86_fp80  @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
14511      declare fp128     @llvm.minnum.f128(fp128 %Val0, fp128 %Val1)
14512      declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
14513
14514Overview:
14515"""""""""
14516
14517The '``llvm.minnum.*``' intrinsics return the minimum of the two
14518arguments.
14519
14520
14521Arguments:
14522""""""""""
14523
14524The arguments and return value are floating-point numbers of the same
14525type.
14526
14527Semantics:
14528""""""""""
14529
14530Follows the IEEE-754 semantics for minNum, except for handling of
14531signaling NaNs. This match's the behavior of libm's fmin.
14532
14533If either operand is a NaN, returns the other non-NaN operand. Returns
14534NaN only if both operands are NaN. The returned NaN is always
14535quiet. If the operands compare equal, returns a value that compares
14536equal to both operands. This means that fmin(+/-0.0, +/-0.0) could
14537return either -0.0 or 0.0.
14538
14539Unlike the IEEE-754 2008 behavior, this does not distinguish between
14540signaling and quiet NaN inputs. If a target's implementation follows
14541the standard and returns a quiet NaN if either input is a signaling
14542NaN, the intrinsic lowering is responsible for quieting the inputs to
14543correctly return the non-NaN input (e.g. by using the equivalent of
14544``llvm.canonicalize``).
14545
14546
14547'``llvm.maxnum.*``' Intrinsic
14548^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14549
14550Syntax:
14551"""""""
14552
14553This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any
14554floating-point or vector of floating-point type. Not all targets support
14555all types however.
14556
14557::
14558
14559      declare float     @llvm.maxnum.f32(float  %Val0, float  %Val1)
14560      declare double    @llvm.maxnum.f64(double %Val0, double %Val1)
14561      declare x86_fp80  @llvm.maxnum.f80(x86_fp80  %Val0, x86_fp80  %Val1)
14562      declare fp128     @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1)
14563      declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128  %Val0, ppc_fp128  %Val1)
14564
14565Overview:
14566"""""""""
14567
14568The '``llvm.maxnum.*``' intrinsics return the maximum of the two
14569arguments.
14570
14571
14572Arguments:
14573""""""""""
14574
14575The arguments and return value are floating-point numbers of the same
14576type.
14577
14578Semantics:
14579""""""""""
14580Follows the IEEE-754 semantics for maxNum except for the handling of
14581signaling NaNs. This matches the behavior of libm's fmax.
14582
14583If either operand is a NaN, returns the other non-NaN operand. Returns
14584NaN only if both operands are NaN. The returned NaN is always
14585quiet. If the operands compare equal, returns a value that compares
14586equal to both operands. This means that fmax(+/-0.0, +/-0.0) could
14587return either -0.0 or 0.0.
14588
14589Unlike the IEEE-754 2008 behavior, this does not distinguish between
14590signaling and quiet NaN inputs. If a target's implementation follows
14591the standard and returns a quiet NaN if either input is a signaling
14592NaN, the intrinsic lowering is responsible for quieting the inputs to
14593correctly return the non-NaN input (e.g. by using the equivalent of
14594``llvm.canonicalize``).
14595
14596'``llvm.minimum.*``' Intrinsic
14597^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14598
14599Syntax:
14600"""""""
14601
14602This is an overloaded intrinsic. You can use ``llvm.minimum`` on any
14603floating-point or vector of floating-point type. Not all targets support
14604all types however.
14605
14606::
14607
14608      declare float     @llvm.minimum.f32(float %Val0, float %Val1)
14609      declare double    @llvm.minimum.f64(double %Val0, double %Val1)
14610      declare x86_fp80  @llvm.minimum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
14611      declare fp128     @llvm.minimum.f128(fp128 %Val0, fp128 %Val1)
14612      declare ppc_fp128 @llvm.minimum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
14613
14614Overview:
14615"""""""""
14616
14617The '``llvm.minimum.*``' intrinsics return the minimum of the two
14618arguments, propagating NaNs and treating -0.0 as less than +0.0.
14619
14620
14621Arguments:
14622""""""""""
14623
14624The arguments and return value are floating-point numbers of the same
14625type.
14626
14627Semantics:
14628""""""""""
14629If either operand is a NaN, returns NaN. Otherwise returns the lesser
14630of the two arguments. -0.0 is considered to be less than +0.0 for this
14631intrinsic. Note that these are the semantics specified in the draft of
14632IEEE 754-2018.
14633
14634'``llvm.maximum.*``' Intrinsic
14635^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14636
14637Syntax:
14638"""""""
14639
14640This is an overloaded intrinsic. You can use ``llvm.maximum`` on any
14641floating-point or vector of floating-point type. Not all targets support
14642all types however.
14643
14644::
14645
14646      declare float     @llvm.maximum.f32(float %Val0, float %Val1)
14647      declare double    @llvm.maximum.f64(double %Val0, double %Val1)
14648      declare x86_fp80  @llvm.maximum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
14649      declare fp128     @llvm.maximum.f128(fp128 %Val0, fp128 %Val1)
14650      declare ppc_fp128 @llvm.maximum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
14651
14652Overview:
14653"""""""""
14654
14655The '``llvm.maximum.*``' intrinsics return the maximum of the two
14656arguments, propagating NaNs and treating -0.0 as less than +0.0.
14657
14658
14659Arguments:
14660""""""""""
14661
14662The arguments and return value are floating-point numbers of the same
14663type.
14664
14665Semantics:
14666""""""""""
14667If either operand is a NaN, returns NaN. Otherwise returns the greater
14668of the two arguments. -0.0 is considered to be less than +0.0 for this
14669intrinsic. Note that these are the semantics specified in the draft of
14670IEEE 754-2018.
14671
14672'``llvm.copysign.*``' Intrinsic
14673^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14674
14675Syntax:
14676"""""""
14677
14678This is an overloaded intrinsic. You can use ``llvm.copysign`` on any
14679floating-point or vector of floating-point type. Not all targets support
14680all types however.
14681
14682::
14683
14684      declare float     @llvm.copysign.f32(float  %Mag, float  %Sgn)
14685      declare double    @llvm.copysign.f64(double %Mag, double %Sgn)
14686      declare x86_fp80  @llvm.copysign.f80(x86_fp80  %Mag, x86_fp80  %Sgn)
14687      declare fp128     @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn)
14688      declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128  %Mag, ppc_fp128  %Sgn)
14689
14690Overview:
14691"""""""""
14692
14693The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the
14694first operand and the sign of the second operand.
14695
14696Arguments:
14697""""""""""
14698
14699The arguments and return value are floating-point numbers of the same
14700type.
14701
14702Semantics:
14703""""""""""
14704
14705This function returns the same values as the libm ``copysign``
14706functions would, and handles error conditions in the same way.
14707
14708'``llvm.floor.*``' Intrinsic
14709^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14710
14711Syntax:
14712"""""""
14713
14714This is an overloaded intrinsic. You can use ``llvm.floor`` on any
14715floating-point or vector of floating-point type. Not all targets support
14716all types however.
14717
14718::
14719
14720      declare float     @llvm.floor.f32(float  %Val)
14721      declare double    @llvm.floor.f64(double %Val)
14722      declare x86_fp80  @llvm.floor.f80(x86_fp80  %Val)
14723      declare fp128     @llvm.floor.f128(fp128 %Val)
14724      declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128  %Val)
14725
14726Overview:
14727"""""""""
14728
14729The '``llvm.floor.*``' intrinsics return the floor of the operand.
14730
14731Arguments:
14732""""""""""
14733
14734The argument and return value are floating-point numbers of the same
14735type.
14736
14737Semantics:
14738""""""""""
14739
14740This function returns the same values as the libm ``floor`` functions
14741would, and handles error conditions in the same way.
14742
14743'``llvm.ceil.*``' Intrinsic
14744^^^^^^^^^^^^^^^^^^^^^^^^^^^
14745
14746Syntax:
14747"""""""
14748
14749This is an overloaded intrinsic. You can use ``llvm.ceil`` on any
14750floating-point or vector of floating-point type. Not all targets support
14751all types however.
14752
14753::
14754
14755      declare float     @llvm.ceil.f32(float  %Val)
14756      declare double    @llvm.ceil.f64(double %Val)
14757      declare x86_fp80  @llvm.ceil.f80(x86_fp80  %Val)
14758      declare fp128     @llvm.ceil.f128(fp128 %Val)
14759      declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128  %Val)
14760
14761Overview:
14762"""""""""
14763
14764The '``llvm.ceil.*``' intrinsics return the ceiling of the operand.
14765
14766Arguments:
14767""""""""""
14768
14769The argument and return value are floating-point numbers of the same
14770type.
14771
14772Semantics:
14773""""""""""
14774
14775This function returns the same values as the libm ``ceil`` functions
14776would, and handles error conditions in the same way.
14777
14778'``llvm.trunc.*``' Intrinsic
14779^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14780
14781Syntax:
14782"""""""
14783
14784This is an overloaded intrinsic. You can use ``llvm.trunc`` on any
14785floating-point or vector of floating-point type. Not all targets support
14786all types however.
14787
14788::
14789
14790      declare float     @llvm.trunc.f32(float  %Val)
14791      declare double    @llvm.trunc.f64(double %Val)
14792      declare x86_fp80  @llvm.trunc.f80(x86_fp80  %Val)
14793      declare fp128     @llvm.trunc.f128(fp128 %Val)
14794      declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128  %Val)
14795
14796Overview:
14797"""""""""
14798
14799The '``llvm.trunc.*``' intrinsics returns the operand rounded to the
14800nearest integer not larger in magnitude than the operand.
14801
14802Arguments:
14803""""""""""
14804
14805The argument and return value are floating-point numbers of the same
14806type.
14807
14808Semantics:
14809""""""""""
14810
14811This function returns the same values as the libm ``trunc`` functions
14812would, and handles error conditions in the same way.
14813
14814'``llvm.rint.*``' Intrinsic
14815^^^^^^^^^^^^^^^^^^^^^^^^^^^
14816
14817Syntax:
14818"""""""
14819
14820This is an overloaded intrinsic. You can use ``llvm.rint`` on any
14821floating-point or vector of floating-point type. Not all targets support
14822all types however.
14823
14824::
14825
14826      declare float     @llvm.rint.f32(float  %Val)
14827      declare double    @llvm.rint.f64(double %Val)
14828      declare x86_fp80  @llvm.rint.f80(x86_fp80  %Val)
14829      declare fp128     @llvm.rint.f128(fp128 %Val)
14830      declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128  %Val)
14831
14832Overview:
14833"""""""""
14834
14835The '``llvm.rint.*``' intrinsics returns the operand rounded to the
14836nearest integer. It may raise an inexact floating-point exception if the
14837operand isn't an integer.
14838
14839Arguments:
14840""""""""""
14841
14842The argument and return value are floating-point numbers of the same
14843type.
14844
14845Semantics:
14846""""""""""
14847
14848This function returns the same values as the libm ``rint`` functions
14849would, and handles error conditions in the same way.
14850
14851'``llvm.nearbyint.*``' Intrinsic
14852^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14853
14854Syntax:
14855"""""""
14856
14857This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any
14858floating-point or vector of floating-point type. Not all targets support
14859all types however.
14860
14861::
14862
14863      declare float     @llvm.nearbyint.f32(float  %Val)
14864      declare double    @llvm.nearbyint.f64(double %Val)
14865      declare x86_fp80  @llvm.nearbyint.f80(x86_fp80  %Val)
14866      declare fp128     @llvm.nearbyint.f128(fp128 %Val)
14867      declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128  %Val)
14868
14869Overview:
14870"""""""""
14871
14872The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the
14873nearest integer.
14874
14875Arguments:
14876""""""""""
14877
14878The argument and return value are floating-point numbers of the same
14879type.
14880
14881Semantics:
14882""""""""""
14883
14884This function returns the same values as the libm ``nearbyint``
14885functions would, and handles error conditions in the same way.
14886
14887'``llvm.round.*``' Intrinsic
14888^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14889
14890Syntax:
14891"""""""
14892
14893This is an overloaded intrinsic. You can use ``llvm.round`` on any
14894floating-point or vector of floating-point type. Not all targets support
14895all types however.
14896
14897::
14898
14899      declare float     @llvm.round.f32(float  %Val)
14900      declare double    @llvm.round.f64(double %Val)
14901      declare x86_fp80  @llvm.round.f80(x86_fp80  %Val)
14902      declare fp128     @llvm.round.f128(fp128 %Val)
14903      declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128  %Val)
14904
14905Overview:
14906"""""""""
14907
14908The '``llvm.round.*``' intrinsics returns the operand rounded to the
14909nearest integer.
14910
14911Arguments:
14912""""""""""
14913
14914The argument and return value are floating-point numbers of the same
14915type.
14916
14917Semantics:
14918""""""""""
14919
14920This function returns the same values as the libm ``round``
14921functions would, and handles error conditions in the same way.
14922
14923'``llvm.roundeven.*``' Intrinsic
14924^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14925
14926Syntax:
14927"""""""
14928
14929This is an overloaded intrinsic. You can use ``llvm.roundeven`` on any
14930floating-point or vector of floating-point type. Not all targets support
14931all types however.
14932
14933::
14934
14935      declare float     @llvm.roundeven.f32(float  %Val)
14936      declare double    @llvm.roundeven.f64(double %Val)
14937      declare x86_fp80  @llvm.roundeven.f80(x86_fp80  %Val)
14938      declare fp128     @llvm.roundeven.f128(fp128 %Val)
14939      declare ppc_fp128 @llvm.roundeven.ppcf128(ppc_fp128  %Val)
14940
14941Overview:
14942"""""""""
14943
14944The '``llvm.roundeven.*``' intrinsics returns the operand rounded to the nearest
14945integer in floating-point format rounding halfway cases to even (that is, to the
14946nearest value that is an even integer).
14947
14948Arguments:
14949""""""""""
14950
14951The argument and return value are floating-point numbers of the same type.
14952
14953Semantics:
14954""""""""""
14955
14956This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It
14957also behaves in the same way as C standard function ``roundeven``, except that
14958it does not raise floating point exceptions.
14959
14960
14961'``llvm.lround.*``' Intrinsic
14962^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14963
14964Syntax:
14965"""""""
14966
14967This is an overloaded intrinsic. You can use ``llvm.lround`` on any
14968floating-point type. Not all targets support all types however.
14969
14970::
14971
14972      declare i32 @llvm.lround.i32.f32(float %Val)
14973      declare i32 @llvm.lround.i32.f64(double %Val)
14974      declare i32 @llvm.lround.i32.f80(float %Val)
14975      declare i32 @llvm.lround.i32.f128(double %Val)
14976      declare i32 @llvm.lround.i32.ppcf128(double %Val)
14977
14978      declare i64 @llvm.lround.i64.f32(float %Val)
14979      declare i64 @llvm.lround.i64.f64(double %Val)
14980      declare i64 @llvm.lround.i64.f80(float %Val)
14981      declare i64 @llvm.lround.i64.f128(double %Val)
14982      declare i64 @llvm.lround.i64.ppcf128(double %Val)
14983
14984Overview:
14985"""""""""
14986
14987The '``llvm.lround.*``' intrinsics return the operand rounded to the nearest
14988integer with ties away from zero.
14989
14990
14991Arguments:
14992""""""""""
14993
14994The argument is a floating-point number and the return value is an integer
14995type.
14996
14997Semantics:
14998""""""""""
14999
15000This function returns the same values as the libm ``lround``
15001functions would, but without setting errno.
15002
15003'``llvm.llround.*``' Intrinsic
15004^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15005
15006Syntax:
15007"""""""
15008
15009This is an overloaded intrinsic. You can use ``llvm.llround`` on any
15010floating-point type. Not all targets support all types however.
15011
15012::
15013
15014      declare i64 @llvm.lround.i64.f32(float %Val)
15015      declare i64 @llvm.lround.i64.f64(double %Val)
15016      declare i64 @llvm.lround.i64.f80(float %Val)
15017      declare i64 @llvm.lround.i64.f128(double %Val)
15018      declare i64 @llvm.lround.i64.ppcf128(double %Val)
15019
15020Overview:
15021"""""""""
15022
15023The '``llvm.llround.*``' intrinsics return the operand rounded to the nearest
15024integer with ties away from zero.
15025
15026Arguments:
15027""""""""""
15028
15029The argument is a floating-point number and the return value is an integer
15030type.
15031
15032Semantics:
15033""""""""""
15034
15035This function returns the same values as the libm ``llround``
15036functions would, but without setting errno.
15037
15038'``llvm.lrint.*``' Intrinsic
15039^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15040
15041Syntax:
15042"""""""
15043
15044This is an overloaded intrinsic. You can use ``llvm.lrint`` on any
15045floating-point type. Not all targets support all types however.
15046
15047::
15048
15049      declare i32 @llvm.lrint.i32.f32(float %Val)
15050      declare i32 @llvm.lrint.i32.f64(double %Val)
15051      declare i32 @llvm.lrint.i32.f80(float %Val)
15052      declare i32 @llvm.lrint.i32.f128(double %Val)
15053      declare i32 @llvm.lrint.i32.ppcf128(double %Val)
15054
15055      declare i64 @llvm.lrint.i64.f32(float %Val)
15056      declare i64 @llvm.lrint.i64.f64(double %Val)
15057      declare i64 @llvm.lrint.i64.f80(float %Val)
15058      declare i64 @llvm.lrint.i64.f128(double %Val)
15059      declare i64 @llvm.lrint.i64.ppcf128(double %Val)
15060
15061Overview:
15062"""""""""
15063
15064The '``llvm.lrint.*``' intrinsics return the operand rounded to the nearest
15065integer.
15066
15067
15068Arguments:
15069""""""""""
15070
15071The argument is a floating-point number and the return value is an integer
15072type.
15073
15074Semantics:
15075""""""""""
15076
15077This function returns the same values as the libm ``lrint``
15078functions would, but without setting errno.
15079
15080'``llvm.llrint.*``' Intrinsic
15081^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15082
15083Syntax:
15084"""""""
15085
15086This is an overloaded intrinsic. You can use ``llvm.llrint`` on any
15087floating-point type. Not all targets support all types however.
15088
15089::
15090
15091      declare i64 @llvm.llrint.i64.f32(float %Val)
15092      declare i64 @llvm.llrint.i64.f64(double %Val)
15093      declare i64 @llvm.llrint.i64.f80(float %Val)
15094      declare i64 @llvm.llrint.i64.f128(double %Val)
15095      declare i64 @llvm.llrint.i64.ppcf128(double %Val)
15096
15097Overview:
15098"""""""""
15099
15100The '``llvm.llrint.*``' intrinsics return the operand rounded to the nearest
15101integer.
15102
15103Arguments:
15104""""""""""
15105
15106The argument is a floating-point number and the return value is an integer
15107type.
15108
15109Semantics:
15110""""""""""
15111
15112This function returns the same values as the libm ``llrint``
15113functions would, but without setting errno.
15114
15115Bit Manipulation Intrinsics
15116---------------------------
15117
15118LLVM provides intrinsics for a few important bit manipulation
15119operations. These allow efficient code generation for some algorithms.
15120
15121'``llvm.bitreverse.*``' Intrinsics
15122^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15123
15124Syntax:
15125"""""""
15126
15127This is an overloaded intrinsic function. You can use bitreverse on any
15128integer type.
15129
15130::
15131
15132      declare i16 @llvm.bitreverse.i16(i16 <id>)
15133      declare i32 @llvm.bitreverse.i32(i32 <id>)
15134      declare i64 @llvm.bitreverse.i64(i64 <id>)
15135      declare <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> <id>)
15136
15137Overview:
15138"""""""""
15139
15140The '``llvm.bitreverse``' family of intrinsics is used to reverse the
15141bitpattern of an integer value or vector of integer values; for example
15142``0b10110110`` becomes ``0b01101101``.
15143
15144Semantics:
15145""""""""""
15146
15147The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit
15148``M`` in the input moved to bit ``N-M-1`` in the output. The vector
15149intrinsics, such as ``llvm.bitreverse.v4i32``, operate on a per-element
15150basis and the element order is not affected.
15151
15152'``llvm.bswap.*``' Intrinsics
15153^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15154
15155Syntax:
15156"""""""
15157
15158This is an overloaded intrinsic function. You can use bswap on any
15159integer type that is an even number of bytes (i.e. BitWidth % 16 == 0).
15160
15161::
15162
15163      declare i16 @llvm.bswap.i16(i16 <id>)
15164      declare i32 @llvm.bswap.i32(i32 <id>)
15165      declare i64 @llvm.bswap.i64(i64 <id>)
15166      declare <4 x i32> @llvm.bswap.v4i32(<4 x i32> <id>)
15167
15168Overview:
15169"""""""""
15170
15171The '``llvm.bswap``' family of intrinsics is used to byte swap an integer
15172value or vector of integer values with an even number of bytes (positive
15173multiple of 16 bits).
15174
15175Semantics:
15176""""""""""
15177
15178The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high
15179and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32``
15180intrinsic returns an i32 value that has the four bytes of the input i32
15181swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the
15182returned i32 will have its bytes in 3, 2, 1, 0 order. The
15183``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this
15184concept to additional even-byte lengths (6 bytes, 8 bytes and more,
15185respectively). The vector intrinsics, such as ``llvm.bswap.v4i32``,
15186operate on a per-element basis and the element order is not affected.
15187
15188'``llvm.ctpop.*``' Intrinsic
15189^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15190
15191Syntax:
15192"""""""
15193
15194This is an overloaded intrinsic. You can use llvm.ctpop on any integer
15195bit width, or on any vector with integer elements. Not all targets
15196support all bit widths or vector types, however.
15197
15198::
15199
15200      declare i8 @llvm.ctpop.i8(i8  <src>)
15201      declare i16 @llvm.ctpop.i16(i16 <src>)
15202      declare i32 @llvm.ctpop.i32(i32 <src>)
15203      declare i64 @llvm.ctpop.i64(i64 <src>)
15204      declare i256 @llvm.ctpop.i256(i256 <src>)
15205      declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>)
15206
15207Overview:
15208"""""""""
15209
15210The '``llvm.ctpop``' family of intrinsics counts the number of bits set
15211in a value.
15212
15213Arguments:
15214""""""""""
15215
15216The only argument is the value to be counted. The argument may be of any
15217integer type, or a vector with integer elements. The return type must
15218match the argument type.
15219
15220Semantics:
15221""""""""""
15222
15223The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within
15224each element of a vector.
15225
15226'``llvm.ctlz.*``' Intrinsic
15227^^^^^^^^^^^^^^^^^^^^^^^^^^^
15228
15229Syntax:
15230"""""""
15231
15232This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any
15233integer bit width, or any vector whose elements are integers. Not all
15234targets support all bit widths or vector types, however.
15235
15236::
15237
15238      declare i8   @llvm.ctlz.i8  (i8   <src>, i1 <is_zero_poison>)
15239      declare <2 x i37> @llvm.ctlz.v2i37(<2 x i37> <src>, i1 <is_zero_poison>)
15240
15241Overview:
15242"""""""""
15243
15244The '``llvm.ctlz``' family of intrinsic functions counts the number of
15245leading zeros in a variable.
15246
15247Arguments:
15248""""""""""
15249
15250The first argument is the value to be counted. This argument may be of
15251any integer type, or a vector with integer element type. The return
15252type must match the first argument type.
15253
15254The second argument is a constant flag that indicates whether the intrinsic
15255returns a valid result if the first argument is zero. If the first
15256argument is zero and the second argument is true, the result is poison.
15257Historically some architectures did not provide a defined result for zero
15258values as efficiently, and many algorithms are now predicated on avoiding
15259zero-value inputs.
15260
15261Semantics:
15262""""""""""
15263
15264The '``llvm.ctlz``' intrinsic counts the leading (most significant)
15265zeros in a variable, or within each element of the vector. If
15266``src == 0`` then the result is the size in bits of the type of ``src``
15267if ``is_zero_poison == 0`` and ``poison`` otherwise. For example,
15268``llvm.ctlz(i32 2) = 30``.
15269
15270'``llvm.cttz.*``' Intrinsic
15271^^^^^^^^^^^^^^^^^^^^^^^^^^^
15272
15273Syntax:
15274"""""""
15275
15276This is an overloaded intrinsic. You can use ``llvm.cttz`` on any
15277integer bit width, or any vector of integer elements. Not all targets
15278support all bit widths or vector types, however.
15279
15280::
15281
15282      declare i42   @llvm.cttz.i42  (i42   <src>, i1 <is_zero_poison>)
15283      declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_poison>)
15284
15285Overview:
15286"""""""""
15287
15288The '``llvm.cttz``' family of intrinsic functions counts the number of
15289trailing zeros.
15290
15291Arguments:
15292""""""""""
15293
15294The first argument is the value to be counted. This argument may be of
15295any integer type, or a vector with integer element type. The return
15296type must match the first argument type.
15297
15298The second argument is a constant flag that indicates whether the intrinsic
15299returns a valid result if the first argument is zero. If the first
15300argument is zero and the second argument is true, the result is poison.
15301Historically some architectures did not provide a defined result for zero
15302values as efficiently, and many algorithms are now predicated on avoiding
15303zero-value inputs.
15304
15305Semantics:
15306""""""""""
15307
15308The '``llvm.cttz``' intrinsic counts the trailing (least significant)
15309zeros in a variable, or within each element of a vector. If ``src == 0``
15310then the result is the size in bits of the type of ``src`` if
15311``is_zero_poison == 0`` and ``poison`` otherwise. For example,
15312``llvm.cttz(2) = 1``.
15313
15314.. _int_overflow:
15315
15316'``llvm.fshl.*``' Intrinsic
15317^^^^^^^^^^^^^^^^^^^^^^^^^^^
15318
15319Syntax:
15320"""""""
15321
15322This is an overloaded intrinsic. You can use ``llvm.fshl`` on any
15323integer bit width or any vector of integer elements. Not all targets
15324support all bit widths or vector types, however.
15325
15326::
15327
15328      declare i8  @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c)
15329      declare i67 @llvm.fshl.i67(i67 %a, i67 %b, i67 %c)
15330      declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
15331
15332Overview:
15333"""""""""
15334
15335The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left:
15336the first two values are concatenated as { %a : %b } (%a is the most significant
15337bits of the wide value), the combined value is shifted left, and the most
15338significant bits are extracted to produce a result that is the same size as the
15339original arguments. If the first 2 arguments are identical, this is equivalent
15340to a rotate left operation. For vector types, the operation occurs for each
15341element of the vector. The shift argument is treated as an unsigned amount
15342modulo the element size of the arguments.
15343
15344Arguments:
15345""""""""""
15346
15347The first two arguments are the values to be concatenated. The third
15348argument is the shift amount. The arguments may be any integer type or a
15349vector with integer element type. All arguments and the return value must
15350have the same type.
15351
15352Example:
15353""""""""
15354
15355.. code-block:: text
15356
15357      %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z)  ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8)
15358      %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15)  ; %r = i8: 128 (0b10000000)
15359      %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11)  ; %r = i8: 120 (0b01111000)
15360      %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8)   ; %r = i8: 0   (0b00000000)
15361
15362'``llvm.fshr.*``' Intrinsic
15363^^^^^^^^^^^^^^^^^^^^^^^^^^^
15364
15365Syntax:
15366"""""""
15367
15368This is an overloaded intrinsic. You can use ``llvm.fshr`` on any
15369integer bit width or any vector of integer elements. Not all targets
15370support all bit widths or vector types, however.
15371
15372::
15373
15374      declare i8  @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c)
15375      declare i67 @llvm.fshr.i67(i67 %a, i67 %b, i67 %c)
15376      declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
15377
15378Overview:
15379"""""""""
15380
15381The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right:
15382the first two values are concatenated as { %a : %b } (%a is the most significant
15383bits of the wide value), the combined value is shifted right, and the least
15384significant bits are extracted to produce a result that is the same size as the
15385original arguments. If the first 2 arguments are identical, this is equivalent
15386to a rotate right operation. For vector types, the operation occurs for each
15387element of the vector. The shift argument is treated as an unsigned amount
15388modulo the element size of the arguments.
15389
15390Arguments:
15391""""""""""
15392
15393The first two arguments are the values to be concatenated. The third
15394argument is the shift amount. The arguments may be any integer type or a
15395vector with integer element type. All arguments and the return value must
15396have the same type.
15397
15398Example:
15399""""""""
15400
15401.. code-block:: text
15402
15403      %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z)  ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8)
15404      %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15)  ; %r = i8: 254 (0b11111110)
15405      %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11)  ; %r = i8: 225 (0b11100001)
15406      %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8)   ; %r = i8: 255 (0b11111111)
15407
15408Arithmetic with Overflow Intrinsics
15409-----------------------------------
15410
15411LLVM provides intrinsics for fast arithmetic overflow checking.
15412
15413Each of these intrinsics returns a two-element struct. The first
15414element of this struct contains the result of the corresponding
15415arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of
15416the result. Therefore, for example, the first element of the struct
15417returned by ``llvm.sadd.with.overflow.i32`` is always the same as the
15418result of a 32-bit ``add`` instruction with the same operands, where
15419the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag.
15420
15421The second element of the result is an ``i1`` that is 1 if the
15422arithmetic operation overflowed and 0 otherwise. An operation
15423overflows if, for any values of its operands ``A`` and ``B`` and for
15424any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is
15425not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is
15426``sext`` for signed overflow and ``zext`` for unsigned overflow, and
15427``op`` is the underlying arithmetic operation.
15428
15429The behavior of these intrinsics is well-defined for all argument
15430values.
15431
15432'``llvm.sadd.with.overflow.*``' Intrinsics
15433^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15434
15435Syntax:
15436"""""""
15437
15438This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow``
15439on any integer bit width or vectors of integers.
15440
15441::
15442
15443      declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
15444      declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
15445      declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
15446      declare {<4 x i32>, <4 x i1>} @llvm.sadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15447
15448Overview:
15449"""""""""
15450
15451The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
15452a signed addition of the two arguments, and indicate whether an overflow
15453occurred during the signed summation.
15454
15455Arguments:
15456""""""""""
15457
15458The arguments (%a and %b) and the first element of the result structure
15459may be of integer types of any bit width, but they must have the same
15460bit width. The second element of the result structure must be of type
15461``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
15462addition.
15463
15464Semantics:
15465""""""""""
15466
15467The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
15468a signed addition of the two variables. They return a structure --- the
15469first element of which is the signed summation, and the second element
15470of which is a bit specifying if the signed summation resulted in an
15471overflow.
15472
15473Examples:
15474"""""""""
15475
15476.. code-block:: llvm
15477
15478      %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
15479      %sum = extractvalue {i32, i1} %res, 0
15480      %obit = extractvalue {i32, i1} %res, 1
15481      br i1 %obit, label %overflow, label %normal
15482
15483'``llvm.uadd.with.overflow.*``' Intrinsics
15484^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15485
15486Syntax:
15487"""""""
15488
15489This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow``
15490on any integer bit width or vectors of integers.
15491
15492::
15493
15494      declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
15495      declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
15496      declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
15497      declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15498
15499Overview:
15500"""""""""
15501
15502The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
15503an unsigned addition of the two arguments, and indicate whether a carry
15504occurred during the unsigned summation.
15505
15506Arguments:
15507""""""""""
15508
15509The arguments (%a and %b) and the first element of the result structure
15510may be of integer types of any bit width, but they must have the same
15511bit width. The second element of the result structure must be of type
15512``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
15513addition.
15514
15515Semantics:
15516""""""""""
15517
15518The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
15519an unsigned addition of the two arguments. They return a structure --- the
15520first element of which is the sum, and the second element of which is a
15521bit specifying if the unsigned summation resulted in a carry.
15522
15523Examples:
15524"""""""""
15525
15526.. code-block:: llvm
15527
15528      %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
15529      %sum = extractvalue {i32, i1} %res, 0
15530      %obit = extractvalue {i32, i1} %res, 1
15531      br i1 %obit, label %carry, label %normal
15532
15533'``llvm.ssub.with.overflow.*``' Intrinsics
15534^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15535
15536Syntax:
15537"""""""
15538
15539This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow``
15540on any integer bit width or vectors of integers.
15541
15542::
15543
15544      declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
15545      declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
15546      declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
15547      declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15548
15549Overview:
15550"""""""""
15551
15552The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
15553a signed subtraction of the two arguments, and indicate whether an
15554overflow occurred during the signed subtraction.
15555
15556Arguments:
15557""""""""""
15558
15559The arguments (%a and %b) and the first element of the result structure
15560may be of integer types of any bit width, but they must have the same
15561bit width. The second element of the result structure must be of type
15562``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
15563subtraction.
15564
15565Semantics:
15566""""""""""
15567
15568The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
15569a signed subtraction of the two arguments. They return a structure --- the
15570first element of which is the subtraction, and the second element of
15571which is a bit specifying if the signed subtraction resulted in an
15572overflow.
15573
15574Examples:
15575"""""""""
15576
15577.. code-block:: llvm
15578
15579      %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
15580      %sum = extractvalue {i32, i1} %res, 0
15581      %obit = extractvalue {i32, i1} %res, 1
15582      br i1 %obit, label %overflow, label %normal
15583
15584'``llvm.usub.with.overflow.*``' Intrinsics
15585^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15586
15587Syntax:
15588"""""""
15589
15590This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow``
15591on any integer bit width or vectors of integers.
15592
15593::
15594
15595      declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
15596      declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
15597      declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
15598      declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15599
15600Overview:
15601"""""""""
15602
15603The '``llvm.usub.with.overflow``' family of intrinsic functions perform
15604an unsigned subtraction of the two arguments, and indicate whether an
15605overflow occurred during the unsigned subtraction.
15606
15607Arguments:
15608""""""""""
15609
15610The arguments (%a and %b) and the first element of the result structure
15611may be of integer types of any bit width, but they must have the same
15612bit width. The second element of the result structure must be of type
15613``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
15614subtraction.
15615
15616Semantics:
15617""""""""""
15618
15619The '``llvm.usub.with.overflow``' family of intrinsic functions perform
15620an unsigned subtraction of the two arguments. They return a structure ---
15621the first element of which is the subtraction, and the second element of
15622which is a bit specifying if the unsigned subtraction resulted in an
15623overflow.
15624
15625Examples:
15626"""""""""
15627
15628.. code-block:: llvm
15629
15630      %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
15631      %sum = extractvalue {i32, i1} %res, 0
15632      %obit = extractvalue {i32, i1} %res, 1
15633      br i1 %obit, label %overflow, label %normal
15634
15635'``llvm.smul.with.overflow.*``' Intrinsics
15636^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15637
15638Syntax:
15639"""""""
15640
15641This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow``
15642on any integer bit width or vectors of integers.
15643
15644::
15645
15646      declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
15647      declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
15648      declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
15649      declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15650
15651Overview:
15652"""""""""
15653
15654The '``llvm.smul.with.overflow``' family of intrinsic functions perform
15655a signed multiplication of the two arguments, and indicate whether an
15656overflow occurred during the signed multiplication.
15657
15658Arguments:
15659""""""""""
15660
15661The arguments (%a and %b) and the first element of the result structure
15662may be of integer types of any bit width, but they must have the same
15663bit width. The second element of the result structure must be of type
15664``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
15665multiplication.
15666
15667Semantics:
15668""""""""""
15669
15670The '``llvm.smul.with.overflow``' family of intrinsic functions perform
15671a signed multiplication of the two arguments. They return a structure ---
15672the first element of which is the multiplication, and the second element
15673of which is a bit specifying if the signed multiplication resulted in an
15674overflow.
15675
15676Examples:
15677"""""""""
15678
15679.. code-block:: llvm
15680
15681      %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
15682      %sum = extractvalue {i32, i1} %res, 0
15683      %obit = extractvalue {i32, i1} %res, 1
15684      br i1 %obit, label %overflow, label %normal
15685
15686'``llvm.umul.with.overflow.*``' Intrinsics
15687^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15688
15689Syntax:
15690"""""""
15691
15692This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow``
15693on any integer bit width or vectors of integers.
15694
15695::
15696
15697      declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
15698      declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
15699      declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
15700      declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15701
15702Overview:
15703"""""""""
15704
15705The '``llvm.umul.with.overflow``' family of intrinsic functions perform
15706a unsigned multiplication of the two arguments, and indicate whether an
15707overflow occurred during the unsigned multiplication.
15708
15709Arguments:
15710""""""""""
15711
15712The arguments (%a and %b) and the first element of the result structure
15713may be of integer types of any bit width, but they must have the same
15714bit width. The second element of the result structure must be of type
15715``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
15716multiplication.
15717
15718Semantics:
15719""""""""""
15720
15721The '``llvm.umul.with.overflow``' family of intrinsic functions perform
15722an unsigned multiplication of the two arguments. They return a structure ---
15723the first element of which is the multiplication, and the second
15724element of which is a bit specifying if the unsigned multiplication
15725resulted in an overflow.
15726
15727Examples:
15728"""""""""
15729
15730.. code-block:: llvm
15731
15732      %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
15733      %sum = extractvalue {i32, i1} %res, 0
15734      %obit = extractvalue {i32, i1} %res, 1
15735      br i1 %obit, label %overflow, label %normal
15736
15737Saturation Arithmetic Intrinsics
15738---------------------------------
15739
15740Saturation arithmetic is a version of arithmetic in which operations are
15741limited to a fixed range between a minimum and maximum value. If the result of
15742an operation is greater than the maximum value, the result is set (or
15743"clamped") to this maximum. If it is below the minimum, it is clamped to this
15744minimum.
15745
15746
15747'``llvm.sadd.sat.*``' Intrinsics
15748^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15749
15750Syntax
15751"""""""
15752
15753This is an overloaded intrinsic. You can use ``llvm.sadd.sat``
15754on any integer bit width or vectors of integers.
15755
15756::
15757
15758      declare i16 @llvm.sadd.sat.i16(i16 %a, i16 %b)
15759      declare i32 @llvm.sadd.sat.i32(i32 %a, i32 %b)
15760      declare i64 @llvm.sadd.sat.i64(i64 %a, i64 %b)
15761      declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
15762
15763Overview
15764"""""""""
15765
15766The '``llvm.sadd.sat``' family of intrinsic functions perform signed
15767saturating addition on the 2 arguments.
15768
15769Arguments
15770""""""""""
15771
15772The arguments (%a and %b) and the result may be of integer types of any bit
15773width, but they must have the same bit width. ``%a`` and ``%b`` are the two
15774values that will undergo signed addition.
15775
15776Semantics:
15777""""""""""
15778
15779The maximum value this operation can clamp to is the largest signed value
15780representable by the bit width of the arguments. The minimum value is the
15781smallest signed value representable by this bit width.
15782
15783
15784Examples
15785"""""""""
15786
15787.. code-block:: llvm
15788
15789      %res = call i4 @llvm.sadd.sat.i4(i4 1, i4 2)  ; %res = 3
15790      %res = call i4 @llvm.sadd.sat.i4(i4 5, i4 6)  ; %res = 7
15791      %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 2)  ; %res = -2
15792      %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 -5)  ; %res = -8
15793
15794
15795'``llvm.uadd.sat.*``' Intrinsics
15796^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15797
15798Syntax
15799"""""""
15800
15801This is an overloaded intrinsic. You can use ``llvm.uadd.sat``
15802on any integer bit width or vectors of integers.
15803
15804::
15805
15806      declare i16 @llvm.uadd.sat.i16(i16 %a, i16 %b)
15807      declare i32 @llvm.uadd.sat.i32(i32 %a, i32 %b)
15808      declare i64 @llvm.uadd.sat.i64(i64 %a, i64 %b)
15809      declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
15810
15811Overview
15812"""""""""
15813
15814The '``llvm.uadd.sat``' family of intrinsic functions perform unsigned
15815saturating addition on the 2 arguments.
15816
15817Arguments
15818""""""""""
15819
15820The arguments (%a and %b) and the result may be of integer types of any bit
15821width, but they must have the same bit width. ``%a`` and ``%b`` are the two
15822values that will undergo unsigned addition.
15823
15824Semantics:
15825""""""""""
15826
15827The maximum value this operation can clamp to is the largest unsigned value
15828representable by the bit width of the arguments. Because this is an unsigned
15829operation, the result will never saturate towards zero.
15830
15831
15832Examples
15833"""""""""
15834
15835.. code-block:: llvm
15836
15837      %res = call i4 @llvm.uadd.sat.i4(i4 1, i4 2)  ; %res = 3
15838      %res = call i4 @llvm.uadd.sat.i4(i4 5, i4 6)  ; %res = 11
15839      %res = call i4 @llvm.uadd.sat.i4(i4 8, i4 8)  ; %res = 15
15840
15841
15842'``llvm.ssub.sat.*``' Intrinsics
15843^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15844
15845Syntax
15846"""""""
15847
15848This is an overloaded intrinsic. You can use ``llvm.ssub.sat``
15849on any integer bit width or vectors of integers.
15850
15851::
15852
15853      declare i16 @llvm.ssub.sat.i16(i16 %a, i16 %b)
15854      declare i32 @llvm.ssub.sat.i32(i32 %a, i32 %b)
15855      declare i64 @llvm.ssub.sat.i64(i64 %a, i64 %b)
15856      declare <4 x i32> @llvm.ssub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
15857
15858Overview
15859"""""""""
15860
15861The '``llvm.ssub.sat``' family of intrinsic functions perform signed
15862saturating subtraction on the 2 arguments.
15863
15864Arguments
15865""""""""""
15866
15867The arguments (%a and %b) and the result may be of integer types of any bit
15868width, but they must have the same bit width. ``%a`` and ``%b`` are the two
15869values that will undergo signed subtraction.
15870
15871Semantics:
15872""""""""""
15873
15874The maximum value this operation can clamp to is the largest signed value
15875representable by the bit width of the arguments. The minimum value is the
15876smallest signed value representable by this bit width.
15877
15878
15879Examples
15880"""""""""
15881
15882.. code-block:: llvm
15883
15884      %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 1)  ; %res = 1
15885      %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 6)  ; %res = -4
15886      %res = call i4 @llvm.ssub.sat.i4(i4 -4, i4 5)  ; %res = -8
15887      %res = call i4 @llvm.ssub.sat.i4(i4 4, i4 -5)  ; %res = 7
15888
15889
15890'``llvm.usub.sat.*``' Intrinsics
15891^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15892
15893Syntax
15894"""""""
15895
15896This is an overloaded intrinsic. You can use ``llvm.usub.sat``
15897on any integer bit width or vectors of integers.
15898
15899::
15900
15901      declare i16 @llvm.usub.sat.i16(i16 %a, i16 %b)
15902      declare i32 @llvm.usub.sat.i32(i32 %a, i32 %b)
15903      declare i64 @llvm.usub.sat.i64(i64 %a, i64 %b)
15904      declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
15905
15906Overview
15907"""""""""
15908
15909The '``llvm.usub.sat``' family of intrinsic functions perform unsigned
15910saturating subtraction on the 2 arguments.
15911
15912Arguments
15913""""""""""
15914
15915The arguments (%a and %b) and the result may be of integer types of any bit
15916width, but they must have the same bit width. ``%a`` and ``%b`` are the two
15917values that will undergo unsigned subtraction.
15918
15919Semantics:
15920""""""""""
15921
15922The minimum value this operation can clamp to is 0, which is the smallest
15923unsigned value representable by the bit width of the unsigned arguments.
15924Because this is an unsigned operation, the result will never saturate towards
15925the largest possible value representable by this bit width.
15926
15927
15928Examples
15929"""""""""
15930
15931.. code-block:: llvm
15932
15933      %res = call i4 @llvm.usub.sat.i4(i4 2, i4 1)  ; %res = 1
15934      %res = call i4 @llvm.usub.sat.i4(i4 2, i4 6)  ; %res = 0
15935
15936
15937'``llvm.sshl.sat.*``' Intrinsics
15938^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15939
15940Syntax
15941"""""""
15942
15943This is an overloaded intrinsic. You can use ``llvm.sshl.sat``
15944on integers or vectors of integers of any bit width.
15945
15946::
15947
15948      declare i16 @llvm.sshl.sat.i16(i16 %a, i16 %b)
15949      declare i32 @llvm.sshl.sat.i32(i32 %a, i32 %b)
15950      declare i64 @llvm.sshl.sat.i64(i64 %a, i64 %b)
15951      declare <4 x i32> @llvm.sshl.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
15952
15953Overview
15954"""""""""
15955
15956The '``llvm.sshl.sat``' family of intrinsic functions perform signed
15957saturating left shift on the first argument.
15958
15959Arguments
15960""""""""""
15961
15962The arguments (``%a`` and ``%b``) and the result may be of integer types of any
15963bit width, but they must have the same bit width. ``%a`` is the value to be
15964shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or
15965dynamically) equal to or larger than the integer bit width of the arguments,
15966the result is a :ref:`poison value <poisonvalues>`. If the arguments are
15967vectors, each vector element of ``a`` is shifted by the corresponding shift
15968amount in ``b``.
15969
15970
15971Semantics:
15972""""""""""
15973
15974The maximum value this operation can clamp to is the largest signed value
15975representable by the bit width of the arguments. The minimum value is the
15976smallest signed value representable by this bit width.
15977
15978
15979Examples
15980"""""""""
15981
15982.. code-block:: llvm
15983
15984      %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 1)  ; %res = 4
15985      %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 2)  ; %res = 7
15986      %res = call i4 @llvm.sshl.sat.i4(i4 -5, i4 1)  ; %res = -8
15987      %res = call i4 @llvm.sshl.sat.i4(i4 -1, i4 1)  ; %res = -2
15988
15989
15990'``llvm.ushl.sat.*``' Intrinsics
15991^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15992
15993Syntax
15994"""""""
15995
15996This is an overloaded intrinsic. You can use ``llvm.ushl.sat``
15997on integers or vectors of integers of any bit width.
15998
15999::
16000
16001      declare i16 @llvm.ushl.sat.i16(i16 %a, i16 %b)
16002      declare i32 @llvm.ushl.sat.i32(i32 %a, i32 %b)
16003      declare i64 @llvm.ushl.sat.i64(i64 %a, i64 %b)
16004      declare <4 x i32> @llvm.ushl.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16005
16006Overview
16007"""""""""
16008
16009The '``llvm.ushl.sat``' family of intrinsic functions perform unsigned
16010saturating left shift on the first argument.
16011
16012Arguments
16013""""""""""
16014
16015The arguments (``%a`` and ``%b``) and the result may be of integer types of any
16016bit width, but they must have the same bit width. ``%a`` is the value to be
16017shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or
16018dynamically) equal to or larger than the integer bit width of the arguments,
16019the result is a :ref:`poison value <poisonvalues>`. If the arguments are
16020vectors, each vector element of ``a`` is shifted by the corresponding shift
16021amount in ``b``.
16022
16023Semantics:
16024""""""""""
16025
16026The maximum value this operation can clamp to is the largest unsigned value
16027representable by the bit width of the arguments.
16028
16029
16030Examples
16031"""""""""
16032
16033.. code-block:: llvm
16034
16035      %res = call i4 @llvm.ushl.sat.i4(i4 2, i4 1)  ; %res = 4
16036      %res = call i4 @llvm.ushl.sat.i4(i4 3, i4 3)  ; %res = 15
16037
16038
16039Fixed Point Arithmetic Intrinsics
16040---------------------------------
16041
16042A fixed point number represents a real data type for a number that has a fixed
16043number of digits after a radix point (equivalent to the decimal point '.').
16044The number of digits after the radix point is referred as the `scale`. These
16045are useful for representing fractional values to a specific precision. The
16046following intrinsics perform fixed point arithmetic operations on 2 operands
16047of the same scale, specified as the third argument.
16048
16049The ``llvm.*mul.fix`` family of intrinsic functions represents a multiplication
16050of fixed point numbers through scaled integers. Therefore, fixed point
16051multiplication can be represented as
16052
16053.. code-block:: llvm
16054
16055        %result = call i4 @llvm.smul.fix.i4(i4 %a, i4 %b, i32 %scale)
16056
16057        ; Expands to
16058        %a2 = sext i4 %a to i8
16059        %b2 = sext i4 %b to i8
16060        %mul = mul nsw nuw i8 %a2, %b2
16061        %scale2 = trunc i32 %scale to i8
16062        %r = ashr i8 %mul, i8 %scale2  ; this is for a target rounding down towards negative infinity
16063        %result = trunc i8 %r to i4
16064
16065The ``llvm.*div.fix`` family of intrinsic functions represents a division of
16066fixed point numbers through scaled integers. Fixed point division can be
16067represented as:
16068
16069.. code-block:: llvm
16070
16071        %result call i4 @llvm.sdiv.fix.i4(i4 %a, i4 %b, i32 %scale)
16072
16073        ; Expands to
16074        %a2 = sext i4 %a to i8
16075        %b2 = sext i4 %b to i8
16076        %scale2 = trunc i32 %scale to i8
16077        %a3 = shl i8 %a2, %scale2
16078        %r = sdiv i8 %a3, %b2 ; this is for a target rounding towards zero
16079        %result = trunc i8 %r to i4
16080
16081For each of these functions, if the result cannot be represented exactly with
16082the provided scale, the result is rounded. Rounding is unspecified since
16083preferred rounding may vary for different targets. Rounding is specified
16084through a target hook. Different pipelines should legalize or optimize this
16085using the rounding specified by this hook if it is provided. Operations like
16086constant folding, instruction combining, KnownBits, and ValueTracking should
16087also use this hook, if provided, and not assume the direction of rounding. A
16088rounded result must always be within one unit of precision from the true
16089result. That is, the error between the returned result and the true result must
16090be less than 1/2^(scale).
16091
16092
16093'``llvm.smul.fix.*``' Intrinsics
16094^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16095
16096Syntax
16097"""""""
16098
16099This is an overloaded intrinsic. You can use ``llvm.smul.fix``
16100on any integer bit width or vectors of integers.
16101
16102::
16103
16104      declare i16 @llvm.smul.fix.i16(i16 %a, i16 %b, i32 %scale)
16105      declare i32 @llvm.smul.fix.i32(i32 %a, i32 %b, i32 %scale)
16106      declare i64 @llvm.smul.fix.i64(i64 %a, i64 %b, i32 %scale)
16107      declare <4 x i32> @llvm.smul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16108
16109Overview
16110"""""""""
16111
16112The '``llvm.smul.fix``' family of intrinsic functions perform signed
16113fixed point multiplication on 2 arguments of the same scale.
16114
16115Arguments
16116""""""""""
16117
16118The arguments (%a and %b) and the result may be of integer types of any bit
16119width, but they must have the same bit width. The arguments may also work with
16120int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16121values that will undergo signed fixed point multiplication. The argument
16122``%scale`` represents the scale of both operands, and must be a constant
16123integer.
16124
16125Semantics:
16126""""""""""
16127
16128This operation performs fixed point multiplication on the 2 arguments of a
16129specified scale. The result will also be returned in the same scale specified
16130in the third argument.
16131
16132If the result value cannot be precisely represented in the given scale, the
16133value is rounded up or down to the closest representable value. The rounding
16134direction is unspecified.
16135
16136It is undefined behavior if the result value does not fit within the range of
16137the fixed point type.
16138
16139
16140Examples
16141"""""""""
16142
16143.. code-block:: llvm
16144
16145      %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 0)  ; %res = 6 (2 x 3 = 6)
16146      %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 1)  ; %res = 3 (1.5 x 1 = 1.5)
16147      %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -2, i32 1)  ; %res = -3 (1.5 x -1 = -1.5)
16148
16149      ; The result in the following could be rounded up to -2 or down to -2.5
16150      %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -3, i32 1)  ; %res = -5 (or -4) (1.5 x -1.5 = -2.25)
16151
16152
16153'``llvm.umul.fix.*``' Intrinsics
16154^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16155
16156Syntax
16157"""""""
16158
16159This is an overloaded intrinsic. You can use ``llvm.umul.fix``
16160on any integer bit width or vectors of integers.
16161
16162::
16163
16164      declare i16 @llvm.umul.fix.i16(i16 %a, i16 %b, i32 %scale)
16165      declare i32 @llvm.umul.fix.i32(i32 %a, i32 %b, i32 %scale)
16166      declare i64 @llvm.umul.fix.i64(i64 %a, i64 %b, i32 %scale)
16167      declare <4 x i32> @llvm.umul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16168
16169Overview
16170"""""""""
16171
16172The '``llvm.umul.fix``' family of intrinsic functions perform unsigned
16173fixed point multiplication on 2 arguments of the same scale.
16174
16175Arguments
16176""""""""""
16177
16178The arguments (%a and %b) and the result may be of integer types of any bit
16179width, but they must have the same bit width. The arguments may also work with
16180int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16181values that will undergo unsigned fixed point multiplication. The argument
16182``%scale`` represents the scale of both operands, and must be a constant
16183integer.
16184
16185Semantics:
16186""""""""""
16187
16188This operation performs unsigned fixed point multiplication on the 2 arguments of a
16189specified scale. The result will also be returned in the same scale specified
16190in the third argument.
16191
16192If the result value cannot be precisely represented in the given scale, the
16193value is rounded up or down to the closest representable value. The rounding
16194direction is unspecified.
16195
16196It is undefined behavior if the result value does not fit within the range of
16197the fixed point type.
16198
16199
16200Examples
16201"""""""""
16202
16203.. code-block:: llvm
16204
16205      %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 0)  ; %res = 6 (2 x 3 = 6)
16206      %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 1)  ; %res = 3 (1.5 x 1 = 1.5)
16207
16208      ; The result in the following could be rounded down to 3.5 or up to 4
16209      %res = call i4 @llvm.umul.fix.i4(i4 15, i4 1, i32 1)  ; %res = 7 (or 8) (7.5 x 0.5 = 3.75)
16210
16211
16212'``llvm.smul.fix.sat.*``' Intrinsics
16213^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16214
16215Syntax
16216"""""""
16217
16218This is an overloaded intrinsic. You can use ``llvm.smul.fix.sat``
16219on any integer bit width or vectors of integers.
16220
16221::
16222
16223      declare i16 @llvm.smul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16224      declare i32 @llvm.smul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16225      declare i64 @llvm.smul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16226      declare <4 x i32> @llvm.smul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16227
16228Overview
16229"""""""""
16230
16231The '``llvm.smul.fix.sat``' family of intrinsic functions perform signed
16232fixed point saturating multiplication on 2 arguments of the same scale.
16233
16234Arguments
16235""""""""""
16236
16237The arguments (%a and %b) and the result may be of integer types of any bit
16238width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16239values that will undergo signed fixed point multiplication. The argument
16240``%scale`` represents the scale of both operands, and must be a constant
16241integer.
16242
16243Semantics:
16244""""""""""
16245
16246This operation performs fixed point multiplication on the 2 arguments of a
16247specified scale. The result will also be returned in the same scale specified
16248in the third argument.
16249
16250If the result value cannot be precisely represented in the given scale, the
16251value is rounded up or down to the closest representable value. The rounding
16252direction is unspecified.
16253
16254The maximum value this operation can clamp to is the largest signed value
16255representable by the bit width of the first 2 arguments. The minimum value is the
16256smallest signed value representable by this bit width.
16257
16258
16259Examples
16260"""""""""
16261
16262.. code-block:: llvm
16263
16264      %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 0)  ; %res = 6 (2 x 3 = 6)
16265      %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 1)  ; %res = 3 (1.5 x 1 = 1.5)
16266      %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -2, i32 1)  ; %res = -3 (1.5 x -1 = -1.5)
16267
16268      ; The result in the following could be rounded up to -2 or down to -2.5
16269      %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -3, i32 1)  ; %res = -5 (or -4) (1.5 x -1.5 = -2.25)
16270
16271      ; Saturation
16272      %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 0)  ; %res = 7
16273      %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 4, i32 2)  ; %res = 7
16274      %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 5, i32 2)  ; %res = -8
16275      %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 -2, i32 1)  ; %res = 7
16276
16277      ; Scale can affect the saturation result
16278      %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 0)  ; %res = 7 (2 x 4 -> clamped to 7)
16279      %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 1)  ; %res = 4 (1 x 2 = 2)
16280
16281
16282'``llvm.umul.fix.sat.*``' Intrinsics
16283^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16284
16285Syntax
16286"""""""
16287
16288This is an overloaded intrinsic. You can use ``llvm.umul.fix.sat``
16289on any integer bit width or vectors of integers.
16290
16291::
16292
16293      declare i16 @llvm.umul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16294      declare i32 @llvm.umul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16295      declare i64 @llvm.umul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16296      declare <4 x i32> @llvm.umul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16297
16298Overview
16299"""""""""
16300
16301The '``llvm.umul.fix.sat``' family of intrinsic functions perform unsigned
16302fixed point saturating multiplication on 2 arguments of the same scale.
16303
16304Arguments
16305""""""""""
16306
16307The arguments (%a and %b) and the result may be of integer types of any bit
16308width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16309values that will undergo unsigned fixed point multiplication. The argument
16310``%scale`` represents the scale of both operands, and must be a constant
16311integer.
16312
16313Semantics:
16314""""""""""
16315
16316This operation performs fixed point multiplication on the 2 arguments of a
16317specified scale. The result will also be returned in the same scale specified
16318in the third argument.
16319
16320If the result value cannot be precisely represented in the given scale, the
16321value is rounded up or down to the closest representable value. The rounding
16322direction is unspecified.
16323
16324The maximum value this operation can clamp to is the largest unsigned value
16325representable by the bit width of the first 2 arguments. The minimum value is the
16326smallest unsigned value representable by this bit width (zero).
16327
16328
16329Examples
16330"""""""""
16331
16332.. code-block:: llvm
16333
16334      %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 0)  ; %res = 6 (2 x 3 = 6)
16335      %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 1)  ; %res = 3 (1.5 x 1 = 1.5)
16336
16337      ; The result in the following could be rounded down to 2 or up to 2.5
16338      %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 3, i32 1)  ; %res = 4 (or 5) (1.5 x 1.5 = 2.25)
16339
16340      ; Saturation
16341      %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 2, i32 0)  ; %res = 15 (8 x 2 -> clamped to 15)
16342      %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 8, i32 2)  ; %res = 15 (2 x 2 -> clamped to 3.75)
16343
16344      ; Scale can affect the saturation result
16345      %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 0)  ; %res = 7 (2 x 4 -> clamped to 7)
16346      %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 1)  ; %res = 4 (1 x 2 = 2)
16347
16348
16349'``llvm.sdiv.fix.*``' Intrinsics
16350^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16351
16352Syntax
16353"""""""
16354
16355This is an overloaded intrinsic. You can use ``llvm.sdiv.fix``
16356on any integer bit width or vectors of integers.
16357
16358::
16359
16360      declare i16 @llvm.sdiv.fix.i16(i16 %a, i16 %b, i32 %scale)
16361      declare i32 @llvm.sdiv.fix.i32(i32 %a, i32 %b, i32 %scale)
16362      declare i64 @llvm.sdiv.fix.i64(i64 %a, i64 %b, i32 %scale)
16363      declare <4 x i32> @llvm.sdiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16364
16365Overview
16366"""""""""
16367
16368The '``llvm.sdiv.fix``' family of intrinsic functions perform signed
16369fixed point division on 2 arguments of the same scale.
16370
16371Arguments
16372""""""""""
16373
16374The arguments (%a and %b) and the result may be of integer types of any bit
16375width, but they must have the same bit width. The arguments may also work with
16376int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16377values that will undergo signed fixed point division. The argument
16378``%scale`` represents the scale of both operands, and must be a constant
16379integer.
16380
16381Semantics:
16382""""""""""
16383
16384This operation performs fixed point division on the 2 arguments of a
16385specified scale. The result will also be returned in the same scale specified
16386in the third argument.
16387
16388If the result value cannot be precisely represented in the given scale, the
16389value is rounded up or down to the closest representable value. The rounding
16390direction is unspecified.
16391
16392It is undefined behavior if the result value does not fit within the range of
16393the fixed point type, or if the second argument is zero.
16394
16395
16396Examples
16397"""""""""
16398
16399.. code-block:: llvm
16400
16401      %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 2, i32 0)  ; %res = 3 (6 / 2 = 3)
16402      %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 4, i32 1)  ; %res = 3 (3 / 2 = 1.5)
16403      %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5)
16404
16405      ; The result in the following could be rounded up to 1 or down to 0.5
16406      %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 4, i32 1)  ; %res = 2 (or 1) (1.5 / 2 = 0.75)
16407
16408
16409'``llvm.udiv.fix.*``' Intrinsics
16410^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16411
16412Syntax
16413"""""""
16414
16415This is an overloaded intrinsic. You can use ``llvm.udiv.fix``
16416on any integer bit width or vectors of integers.
16417
16418::
16419
16420      declare i16 @llvm.udiv.fix.i16(i16 %a, i16 %b, i32 %scale)
16421      declare i32 @llvm.udiv.fix.i32(i32 %a, i32 %b, i32 %scale)
16422      declare i64 @llvm.udiv.fix.i64(i64 %a, i64 %b, i32 %scale)
16423      declare <4 x i32> @llvm.udiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16424
16425Overview
16426"""""""""
16427
16428The '``llvm.udiv.fix``' family of intrinsic functions perform unsigned
16429fixed point division on 2 arguments of the same scale.
16430
16431Arguments
16432""""""""""
16433
16434The arguments (%a and %b) and the result may be of integer types of any bit
16435width, but they must have the same bit width. The arguments may also work with
16436int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16437values that will undergo unsigned fixed point division. The argument
16438``%scale`` represents the scale of both operands, and must be a constant
16439integer.
16440
16441Semantics:
16442""""""""""
16443
16444This operation performs fixed point division on the 2 arguments of a
16445specified scale. The result will also be returned in the same scale specified
16446in the third argument.
16447
16448If the result value cannot be precisely represented in the given scale, the
16449value is rounded up or down to the closest representable value. The rounding
16450direction is unspecified.
16451
16452It is undefined behavior if the result value does not fit within the range of
16453the fixed point type, or if the second argument is zero.
16454
16455
16456Examples
16457"""""""""
16458
16459.. code-block:: llvm
16460
16461      %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 2, i32 0)  ; %res = 3 (6 / 2 = 3)
16462      %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 4, i32 1)  ; %res = 3 (3 / 2 = 1.5)
16463      %res = call i4 @llvm.udiv.fix.i4(i4 1, i4 -8, i32 4) ; %res = 2 (0.0625 / 0.5 = 0.125)
16464
16465      ; The result in the following could be rounded up to 1 or down to 0.5
16466      %res = call i4 @llvm.udiv.fix.i4(i4 3, i4 4, i32 1)  ; %res = 2 (or 1) (1.5 / 2 = 0.75)
16467
16468
16469'``llvm.sdiv.fix.sat.*``' Intrinsics
16470^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16471
16472Syntax
16473"""""""
16474
16475This is an overloaded intrinsic. You can use ``llvm.sdiv.fix.sat``
16476on any integer bit width or vectors of integers.
16477
16478::
16479
16480      declare i16 @llvm.sdiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16481      declare i32 @llvm.sdiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16482      declare i64 @llvm.sdiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16483      declare <4 x i32> @llvm.sdiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16484
16485Overview
16486"""""""""
16487
16488The '``llvm.sdiv.fix.sat``' family of intrinsic functions perform signed
16489fixed point saturating division on 2 arguments of the same scale.
16490
16491Arguments
16492""""""""""
16493
16494The arguments (%a and %b) and the result may be of integer types of any bit
16495width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16496values that will undergo signed fixed point division. The argument
16497``%scale`` represents the scale of both operands, and must be a constant
16498integer.
16499
16500Semantics:
16501""""""""""
16502
16503This operation performs fixed point division on the 2 arguments of a
16504specified scale. The result will also be returned in the same scale specified
16505in the third argument.
16506
16507If the result value cannot be precisely represented in the given scale, the
16508value is rounded up or down to the closest representable value. The rounding
16509direction is unspecified.
16510
16511The maximum value this operation can clamp to is the largest signed value
16512representable by the bit width of the first 2 arguments. The minimum value is the
16513smallest signed value representable by this bit width.
16514
16515It is undefined behavior if the second argument is zero.
16516
16517
16518Examples
16519"""""""""
16520
16521.. code-block:: llvm
16522
16523      %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 2, i32 0)  ; %res = 3 (6 / 2 = 3)
16524      %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 4, i32 1)  ; %res = 3 (3 / 2 = 1.5)
16525      %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5)
16526
16527      ; The result in the following could be rounded up to 1 or down to 0.5
16528      %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 4, i32 1)  ; %res = 2 (or 1) (1.5 / 2 = 0.75)
16529
16530      ; Saturation
16531      %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -8, i4 -1, i32 0)  ; %res = 7 (-8 / -1 = 8 => 7)
16532      %res = call i4 @llvm.sdiv.fix.sat.i4(i4 4, i4 2, i32 2)  ; %res = 7 (1 / 0.5 = 2 => 1.75)
16533      %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -4, i4 1, i32 2)  ; %res = -8 (-1 / 0.25 = -4 => -2)
16534
16535
16536'``llvm.udiv.fix.sat.*``' Intrinsics
16537^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16538
16539Syntax
16540"""""""
16541
16542This is an overloaded intrinsic. You can use ``llvm.udiv.fix.sat``
16543on any integer bit width or vectors of integers.
16544
16545::
16546
16547      declare i16 @llvm.udiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16548      declare i32 @llvm.udiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16549      declare i64 @llvm.udiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16550      declare <4 x i32> @llvm.udiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16551
16552Overview
16553"""""""""
16554
16555The '``llvm.udiv.fix.sat``' family of intrinsic functions perform unsigned
16556fixed point saturating division on 2 arguments of the same scale.
16557
16558Arguments
16559""""""""""
16560
16561The arguments (%a and %b) and the result may be of integer types of any bit
16562width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16563values that will undergo unsigned fixed point division. The argument
16564``%scale`` represents the scale of both operands, and must be a constant
16565integer.
16566
16567Semantics:
16568""""""""""
16569
16570This operation performs fixed point division on the 2 arguments of a
16571specified scale. The result will also be returned in the same scale specified
16572in the third argument.
16573
16574If the result value cannot be precisely represented in the given scale, the
16575value is rounded up or down to the closest representable value. The rounding
16576direction is unspecified.
16577
16578The maximum value this operation can clamp to is the largest unsigned value
16579representable by the bit width of the first 2 arguments. The minimum value is the
16580smallest unsigned value representable by this bit width (zero).
16581
16582It is undefined behavior if the second argument is zero.
16583
16584Examples
16585"""""""""
16586
16587.. code-block:: llvm
16588
16589      %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 2, i32 0)  ; %res = 3 (6 / 2 = 3)
16590      %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 4, i32 1)  ; %res = 3 (3 / 2 = 1.5)
16591
16592      ; The result in the following could be rounded down to 0.5 or up to 1
16593      %res = call i4 @llvm.udiv.fix.sat.i4(i4 3, i4 4, i32 1)  ; %res = 1 (or 2) (1.5 / 2 = 0.75)
16594
16595      ; Saturation
16596      %res = call i4 @llvm.udiv.fix.sat.i4(i4 8, i4 2, i32 2)  ; %res = 15 (2 / 0.5 = 4 => 3.75)
16597
16598
16599Specialised Arithmetic Intrinsics
16600---------------------------------
16601
16602.. _i_intr_llvm_canonicalize:
16603
16604'``llvm.canonicalize.*``' Intrinsic
16605^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16606
16607Syntax:
16608"""""""
16609
16610::
16611
16612      declare float @llvm.canonicalize.f32(float %a)
16613      declare double @llvm.canonicalize.f64(double %b)
16614
16615Overview:
16616"""""""""
16617
16618The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical
16619encoding of a floating-point number. This canonicalization is useful for
16620implementing certain numeric primitives such as frexp. The canonical encoding is
16621defined by IEEE-754-2008 to be:
16622
16623::
16624
16625      2.1.8 canonical encoding: The preferred encoding of a floating-point
16626      representation in a format. Applied to declets, significands of finite
16627      numbers, infinities, and NaNs, especially in decimal formats.
16628
16629This operation can also be considered equivalent to the IEEE-754-2008
16630conversion of a floating-point value to the same format. NaNs are handled
16631according to section 6.2.
16632
16633Examples of non-canonical encodings:
16634
16635- x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are
16636  converted to a canonical representation per hardware-specific protocol.
16637- Many normal decimal floating-point numbers have non-canonical alternative
16638  encodings.
16639- Some machines, like GPUs or ARMv7 NEON, do not support subnormal values.
16640  These are treated as non-canonical encodings of zero and will be flushed to
16641  a zero of the same sign by this operation.
16642
16643Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with
16644default exception handling must signal an invalid exception, and produce a
16645quiet NaN result.
16646
16647This function should always be implementable as multiplication by 1.0, provided
16648that the compiler does not constant fold the operation. Likewise, division by
166491.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with
16650-0.0 is also sufficient provided that the rounding mode is not -Infinity.
16651
16652``@llvm.canonicalize`` must preserve the equality relation. That is:
16653
16654- ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)``
16655- ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to
16656  to ``(x == y)``
16657
16658Additionally, the sign of zero must be conserved:
16659``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0``
16660
16661The payload bits of a NaN must be conserved, with two exceptions.
16662First, environments which use only a single canonical representation of NaN
16663must perform said canonicalization. Second, SNaNs must be quieted per the
16664usual methods.
16665
16666The canonicalization operation may be optimized away if:
16667
16668- The input is known to be canonical. For example, it was produced by a
16669  floating-point operation that is required by the standard to be canonical.
16670- The result is consumed only by (or fused with) other floating-point
16671  operations. That is, the bits of the floating-point value are not examined.
16672
16673'``llvm.fmuladd.*``' Intrinsic
16674^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16675
16676Syntax:
16677"""""""
16678
16679::
16680
16681      declare float @llvm.fmuladd.f32(float %a, float %b, float %c)
16682      declare double @llvm.fmuladd.f64(double %a, double %b, double %c)
16683
16684Overview:
16685"""""""""
16686
16687The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add
16688expressions that can be fused if the code generator determines that (a) the
16689target instruction set has support for a fused operation, and (b) that the
16690fused operation is more efficient than the equivalent, separate pair of mul
16691and add instructions.
16692
16693Arguments:
16694""""""""""
16695
16696The '``llvm.fmuladd.*``' intrinsics each take three arguments: two
16697multiplicands, a and b, and an addend c.
16698
16699Semantics:
16700""""""""""
16701
16702The expression:
16703
16704::
16705
16706      %0 = call float @llvm.fmuladd.f32(%a, %b, %c)
16707
16708is equivalent to the expression a \* b + c, except that it is unspecified
16709whether rounding will be performed between the multiplication and addition
16710steps. Fusion is not guaranteed, even if the target platform supports it.
16711If a fused multiply-add is required, the corresponding
16712:ref:`llvm.fma <int_fma>` intrinsic function should be used instead.
16713This never sets errno, just as '``llvm.fma.*``'.
16714
16715Examples:
16716"""""""""
16717
16718.. code-block:: llvm
16719
16720      %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c
16721
16722
16723Hardware-Loop Intrinsics
16724------------------------
16725
16726LLVM support several intrinsics to mark a loop as a hardware-loop. They are
16727hints to the backend which are required to lower these intrinsics further to target
16728specific instructions, or revert the hardware-loop to a normal loop if target
16729specific restriction are not met and a hardware-loop can't be generated.
16730
16731These intrinsics may be modified in the future and are not intended to be used
16732outside the backend. Thus, front-end and mid-level optimizations should not be
16733generating these intrinsics.
16734
16735
16736'``llvm.set.loop.iterations.*``' Intrinsic
16737^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16738
16739Syntax:
16740"""""""
16741
16742This is an overloaded intrinsic.
16743
16744::
16745
16746      declare void @llvm.set.loop.iterations.i32(i32)
16747      declare void @llvm.set.loop.iterations.i64(i64)
16748
16749Overview:
16750"""""""""
16751
16752The '``llvm.set.loop.iterations.*``' intrinsics are used to specify the
16753hardware-loop trip count. They are placed in the loop preheader basic block and
16754are marked as ``IntrNoDuplicate`` to avoid optimizers duplicating these
16755instructions.
16756
16757Arguments:
16758""""""""""
16759
16760The integer operand is the loop trip count of the hardware-loop, and thus
16761not e.g. the loop back-edge taken count.
16762
16763Semantics:
16764""""""""""
16765
16766The '``llvm.set.loop.iterations.*``' intrinsics do not perform any arithmetic
16767on their operand. It's a hint to the backend that can use this to set up the
16768hardware-loop count with a target specific instruction, usually a move of this
16769value to a special register or a hardware-loop instruction.
16770
16771
16772'``llvm.start.loop.iterations.*``' Intrinsic
16773^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16774
16775Syntax:
16776"""""""
16777
16778This is an overloaded intrinsic.
16779
16780::
16781
16782      declare i32 @llvm.start.loop.iterations.i32(i32)
16783      declare i64 @llvm.start.loop.iterations.i64(i64)
16784
16785Overview:
16786"""""""""
16787
16788The '``llvm.start.loop.iterations.*``' intrinsics are similar to the
16789'``llvm.set.loop.iterations.*``' intrinsics, used to specify the
16790hardware-loop trip count but also produce a value identical to the input
16791that can be used as the input to the loop. They are placed in the loop
16792preheader basic block and the output is expected to be the input to the
16793phi for the induction variable of the loop, decremented by the
16794'``llvm.loop.decrement.reg.*``'.
16795
16796Arguments:
16797""""""""""
16798
16799The integer operand is the loop trip count of the hardware-loop, and thus
16800not e.g. the loop back-edge taken count.
16801
16802Semantics:
16803""""""""""
16804
16805The '``llvm.start.loop.iterations.*``' intrinsics do not perform any arithmetic
16806on their operand. It's a hint to the backend that can use this to set up the
16807hardware-loop count with a target specific instruction, usually a move of this
16808value to a special register or a hardware-loop instruction.
16809
16810'``llvm.test.set.loop.iterations.*``' Intrinsic
16811^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16812
16813Syntax:
16814"""""""
16815
16816This is an overloaded intrinsic.
16817
16818::
16819
16820      declare i1 @llvm.test.set.loop.iterations.i32(i32)
16821      declare i1 @llvm.test.set.loop.iterations.i64(i64)
16822
16823Overview:
16824"""""""""
16825
16826The '``llvm.test.set.loop.iterations.*``' intrinsics are used to specify the
16827the loop trip count, and also test that the given count is not zero, allowing
16828it to control entry to a while-loop.  They are placed in the loop preheader's
16829predecessor basic block, and are marked as ``IntrNoDuplicate`` to avoid
16830optimizers duplicating these instructions.
16831
16832Arguments:
16833""""""""""
16834
16835The integer operand is the loop trip count of the hardware-loop, and thus
16836not e.g. the loop back-edge taken count.
16837
16838Semantics:
16839""""""""""
16840
16841The '``llvm.test.set.loop.iterations.*``' intrinsics do not perform any
16842arithmetic on their operand. It's a hint to the backend that can use this to
16843set up the hardware-loop count with a target specific instruction, usually a
16844move of this value to a special register or a hardware-loop instruction.
16845The result is the conditional value of whether the given count is not zero.
16846
16847
16848'``llvm.test.start.loop.iterations.*``' Intrinsic
16849^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16850
16851Syntax:
16852"""""""
16853
16854This is an overloaded intrinsic.
16855
16856::
16857
16858      declare {i32, i1} @llvm.test.start.loop.iterations.i32(i32)
16859      declare {i64, i1} @llvm.test.start.loop.iterations.i64(i64)
16860
16861Overview:
16862"""""""""
16863
16864The '``llvm.test.start.loop.iterations.*``' intrinsics are similar to the
16865'``llvm.test.set.loop.iterations.*``' and '``llvm.start.loop.iterations.*``'
16866intrinsics, used to specify the hardware-loop trip count, but also produce a
16867value identical to the input that can be used as the input to the loop. The
16868second i1 output controls entry to a while-loop.
16869
16870Arguments:
16871""""""""""
16872
16873The integer operand is the loop trip count of the hardware-loop, and thus
16874not e.g. the loop back-edge taken count.
16875
16876Semantics:
16877""""""""""
16878
16879The '``llvm.test.start.loop.iterations.*``' intrinsics do not perform any
16880arithmetic on their operand. It's a hint to the backend that can use this to
16881set up the hardware-loop count with a target specific instruction, usually a
16882move of this value to a special register or a hardware-loop instruction.
16883The result is a pair of the input and a conditional value of whether the
16884given count is not zero.
16885
16886
16887'``llvm.loop.decrement.reg.*``' Intrinsic
16888^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16889
16890Syntax:
16891"""""""
16892
16893This is an overloaded intrinsic.
16894
16895::
16896
16897      declare i32 @llvm.loop.decrement.reg.i32(i32, i32)
16898      declare i64 @llvm.loop.decrement.reg.i64(i64, i64)
16899
16900Overview:
16901"""""""""
16902
16903The '``llvm.loop.decrement.reg.*``' intrinsics are used to lower the loop
16904iteration counter and return an updated value that will be used in the next
16905loop test check.
16906
16907Arguments:
16908""""""""""
16909
16910Both arguments must have identical integer types. The first operand is the
16911loop iteration counter. The second operand is the maximum number of elements
16912processed in an iteration.
16913
16914Semantics:
16915""""""""""
16916
16917The '``llvm.loop.decrement.reg.*``' intrinsics do an integer ``SUB`` of its
16918two operands, which is not allowed to wrap. They return the remaining number of
16919iterations still to be executed, and can be used together with a ``PHI``,
16920``ICMP`` and ``BR`` to control the number of loop iterations executed. Any
16921optimisations are allowed to treat it is a ``SUB``, and it is supported by
16922SCEV, so it's the backends responsibility to handle cases where it may be
16923optimised. These intrinsics are marked as ``IntrNoDuplicate`` to avoid
16924optimizers duplicating these instructions.
16925
16926
16927'``llvm.loop.decrement.*``' Intrinsic
16928^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16929
16930Syntax:
16931"""""""
16932
16933This is an overloaded intrinsic.
16934
16935::
16936
16937      declare i1 @llvm.loop.decrement.i32(i32)
16938      declare i1 @llvm.loop.decrement.i64(i64)
16939
16940Overview:
16941"""""""""
16942
16943The HardwareLoops pass allows the loop decrement value to be specified with an
16944option. It defaults to a loop decrement value of 1, but it can be an unsigned
16945integer value provided by this option.  The '``llvm.loop.decrement.*``'
16946intrinsics decrement the loop iteration counter with this value, and return a
16947false predicate if the loop should exit, and true otherwise.
16948This is emitted if the loop counter is not updated via a ``PHI`` node, which
16949can also be controlled with an option.
16950
16951Arguments:
16952""""""""""
16953
16954The integer argument is the loop decrement value used to decrement the loop
16955iteration counter.
16956
16957Semantics:
16958""""""""""
16959
16960The '``llvm.loop.decrement.*``' intrinsics do a ``SUB`` of the loop iteration
16961counter with the given loop decrement value, and return false if the loop
16962should exit, this ``SUB`` is not allowed to wrap. The result is a condition
16963that is used by the conditional branch controlling the loop.
16964
16965
16966Vector Reduction Intrinsics
16967---------------------------
16968
16969Horizontal reductions of vectors can be expressed using the following
16970intrinsics. Each one takes a vector operand as an input and applies its
16971respective operation across all elements of the vector, returning a single
16972scalar result of the same element type.
16973
16974.. _int_vector_reduce_add:
16975
16976'``llvm.vector.reduce.add.*``' Intrinsic
16977^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16978
16979Syntax:
16980"""""""
16981
16982::
16983
16984      declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a)
16985      declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a)
16986
16987Overview:
16988"""""""""
16989
16990The '``llvm.vector.reduce.add.*``' intrinsics do an integer ``ADD``
16991reduction of a vector, returning the result as a scalar. The return type matches
16992the element-type of the vector input.
16993
16994Arguments:
16995""""""""""
16996The argument to this intrinsic must be a vector of integer values.
16997
16998.. _int_vector_reduce_fadd:
16999
17000'``llvm.vector.reduce.fadd.*``' Intrinsic
17001^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17002
17003Syntax:
17004"""""""
17005
17006::
17007
17008      declare float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %a)
17009      declare double @llvm.vector.reduce.fadd.v2f64(double %start_value, <2 x double> %a)
17010
17011Overview:
17012"""""""""
17013
17014The '``llvm.vector.reduce.fadd.*``' intrinsics do a floating-point
17015``ADD`` reduction of a vector, returning the result as a scalar. The return type
17016matches the element-type of the vector input.
17017
17018If the intrinsic call has the 'reassoc' flag set, then the reduction will not
17019preserve the associativity of an equivalent scalarized counterpart. Otherwise
17020the reduction will be *sequential*, thus implying that the operation respects
17021the associativity of a scalarized reduction. That is, the reduction begins with
17022the start value and performs an fadd operation with consecutively increasing
17023vector element indices. See the following pseudocode:
17024
17025::
17026
17027    float sequential_fadd(start_value, input_vector)
17028      result = start_value
17029      for i = 0 to length(input_vector)
17030        result = result + input_vector[i]
17031      return result
17032
17033
17034Arguments:
17035""""""""""
17036The first argument to this intrinsic is a scalar start value for the reduction.
17037The type of the start value matches the element-type of the vector input.
17038The second argument must be a vector of floating-point values.
17039
17040To ignore the start value, negative zero (``-0.0``) can be used, as it is
17041the neutral value of floating point addition.
17042
17043Examples:
17044"""""""""
17045
17046::
17047
17048      %unord = call reassoc float @llvm.vector.reduce.fadd.v4f32(float -0.0, <4 x float> %input) ; relaxed reduction
17049      %ord = call float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %input) ; sequential reduction
17050
17051
17052.. _int_vector_reduce_mul:
17053
17054'``llvm.vector.reduce.mul.*``' Intrinsic
17055^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17056
17057Syntax:
17058"""""""
17059
17060::
17061
17062      declare i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %a)
17063      declare i64 @llvm.vector.reduce.mul.v2i64(<2 x i64> %a)
17064
17065Overview:
17066"""""""""
17067
17068The '``llvm.vector.reduce.mul.*``' intrinsics do an integer ``MUL``
17069reduction of a vector, returning the result as a scalar. The return type matches
17070the element-type of the vector input.
17071
17072Arguments:
17073""""""""""
17074The argument to this intrinsic must be a vector of integer values.
17075
17076.. _int_vector_reduce_fmul:
17077
17078'``llvm.vector.reduce.fmul.*``' Intrinsic
17079^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17080
17081Syntax:
17082"""""""
17083
17084::
17085
17086      declare float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %a)
17087      declare double @llvm.vector.reduce.fmul.v2f64(double %start_value, <2 x double> %a)
17088
17089Overview:
17090"""""""""
17091
17092The '``llvm.vector.reduce.fmul.*``' intrinsics do a floating-point
17093``MUL`` reduction of a vector, returning the result as a scalar. The return type
17094matches the element-type of the vector input.
17095
17096If the intrinsic call has the 'reassoc' flag set, then the reduction will not
17097preserve the associativity of an equivalent scalarized counterpart. Otherwise
17098the reduction will be *sequential*, thus implying that the operation respects
17099the associativity of a scalarized reduction. That is, the reduction begins with
17100the start value and performs an fmul operation with consecutively increasing
17101vector element indices. See the following pseudocode:
17102
17103::
17104
17105    float sequential_fmul(start_value, input_vector)
17106      result = start_value
17107      for i = 0 to length(input_vector)
17108        result = result * input_vector[i]
17109      return result
17110
17111
17112Arguments:
17113""""""""""
17114The first argument to this intrinsic is a scalar start value for the reduction.
17115The type of the start value matches the element-type of the vector input.
17116The second argument must be a vector of floating-point values.
17117
17118To ignore the start value, one (``1.0``) can be used, as it is the neutral
17119value of floating point multiplication.
17120
17121Examples:
17122"""""""""
17123
17124::
17125
17126      %unord = call reassoc float @llvm.vector.reduce.fmul.v4f32(float 1.0, <4 x float> %input) ; relaxed reduction
17127      %ord = call float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %input) ; sequential reduction
17128
17129.. _int_vector_reduce_and:
17130
17131'``llvm.vector.reduce.and.*``' Intrinsic
17132^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17133
17134Syntax:
17135"""""""
17136
17137::
17138
17139      declare i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %a)
17140
17141Overview:
17142"""""""""
17143
17144The '``llvm.vector.reduce.and.*``' intrinsics do a bitwise ``AND``
17145reduction of a vector, returning the result as a scalar. The return type matches
17146the element-type of the vector input.
17147
17148Arguments:
17149""""""""""
17150The argument to this intrinsic must be a vector of integer values.
17151
17152.. _int_vector_reduce_or:
17153
17154'``llvm.vector.reduce.or.*``' Intrinsic
17155^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17156
17157Syntax:
17158"""""""
17159
17160::
17161
17162      declare i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %a)
17163
17164Overview:
17165"""""""""
17166
17167The '``llvm.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction
17168of a vector, returning the result as a scalar. The return type matches the
17169element-type of the vector input.
17170
17171Arguments:
17172""""""""""
17173The argument to this intrinsic must be a vector of integer values.
17174
17175.. _int_vector_reduce_xor:
17176
17177'``llvm.vector.reduce.xor.*``' Intrinsic
17178^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17179
17180Syntax:
17181"""""""
17182
17183::
17184
17185      declare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %a)
17186
17187Overview:
17188"""""""""
17189
17190The '``llvm.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR``
17191reduction of a vector, returning the result as a scalar. The return type matches
17192the element-type of the vector input.
17193
17194Arguments:
17195""""""""""
17196The argument to this intrinsic must be a vector of integer values.
17197
17198.. _int_vector_reduce_smax:
17199
17200'``llvm.vector.reduce.smax.*``' Intrinsic
17201^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17202
17203Syntax:
17204"""""""
17205
17206::
17207
17208      declare i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %a)
17209
17210Overview:
17211"""""""""
17212
17213The '``llvm.vector.reduce.smax.*``' intrinsics do a signed integer
17214``MAX`` reduction of a vector, returning the result as a scalar. The return type
17215matches the element-type of the vector input.
17216
17217Arguments:
17218""""""""""
17219The argument to this intrinsic must be a vector of integer values.
17220
17221.. _int_vector_reduce_smin:
17222
17223'``llvm.vector.reduce.smin.*``' Intrinsic
17224^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17225
17226Syntax:
17227"""""""
17228
17229::
17230
17231      declare i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %a)
17232
17233Overview:
17234"""""""""
17235
17236The '``llvm.vector.reduce.smin.*``' intrinsics do a signed integer
17237``MIN`` reduction of a vector, returning the result as a scalar. The return type
17238matches the element-type of the vector input.
17239
17240Arguments:
17241""""""""""
17242The argument to this intrinsic must be a vector of integer values.
17243
17244.. _int_vector_reduce_umax:
17245
17246'``llvm.vector.reduce.umax.*``' Intrinsic
17247^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17248
17249Syntax:
17250"""""""
17251
17252::
17253
17254      declare i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %a)
17255
17256Overview:
17257"""""""""
17258
17259The '``llvm.vector.reduce.umax.*``' intrinsics do an unsigned
17260integer ``MAX`` reduction of a vector, returning the result as a scalar. The
17261return type matches the element-type of the vector input.
17262
17263Arguments:
17264""""""""""
17265The argument to this intrinsic must be a vector of integer values.
17266
17267.. _int_vector_reduce_umin:
17268
17269'``llvm.vector.reduce.umin.*``' Intrinsic
17270^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17271
17272Syntax:
17273"""""""
17274
17275::
17276
17277      declare i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %a)
17278
17279Overview:
17280"""""""""
17281
17282The '``llvm.vector.reduce.umin.*``' intrinsics do an unsigned
17283integer ``MIN`` reduction of a vector, returning the result as a scalar. The
17284return type matches the element-type of the vector input.
17285
17286Arguments:
17287""""""""""
17288The argument to this intrinsic must be a vector of integer values.
17289
17290.. _int_vector_reduce_fmax:
17291
17292'``llvm.vector.reduce.fmax.*``' Intrinsic
17293^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17294
17295Syntax:
17296"""""""
17297
17298::
17299
17300      declare float @llvm.vector.reduce.fmax.v4f32(<4 x float> %a)
17301      declare double @llvm.vector.reduce.fmax.v2f64(<2 x double> %a)
17302
17303Overview:
17304"""""""""
17305
17306The '``llvm.vector.reduce.fmax.*``' intrinsics do a floating-point
17307``MAX`` reduction of a vector, returning the result as a scalar. The return type
17308matches the element-type of the vector input.
17309
17310This instruction has the same comparison semantics as the '``llvm.maxnum.*``'
17311intrinsic. That is, the result will always be a number unless all elements of
17312the vector are NaN. For a vector with maximum element magnitude 0.0 and
17313containing both +0.0 and -0.0 elements, the sign of the result is unspecified.
17314
17315If the intrinsic call has the ``nnan`` fast-math flag, then the operation can
17316assume that NaNs are not present in the input vector.
17317
17318Arguments:
17319""""""""""
17320The argument to this intrinsic must be a vector of floating-point values.
17321
17322.. _int_vector_reduce_fmin:
17323
17324'``llvm.vector.reduce.fmin.*``' Intrinsic
17325^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17326
17327Syntax:
17328"""""""
17329This is an overloaded intrinsic.
17330
17331::
17332
17333      declare float @llvm.vector.reduce.fmin.v4f32(<4 x float> %a)
17334      declare double @llvm.vector.reduce.fmin.v2f64(<2 x double> %a)
17335
17336Overview:
17337"""""""""
17338
17339The '``llvm.vector.reduce.fmin.*``' intrinsics do a floating-point
17340``MIN`` reduction of a vector, returning the result as a scalar. The return type
17341matches the element-type of the vector input.
17342
17343This instruction has the same comparison semantics as the '``llvm.minnum.*``'
17344intrinsic. That is, the result will always be a number unless all elements of
17345the vector are NaN. For a vector with minimum element magnitude 0.0 and
17346containing both +0.0 and -0.0 elements, the sign of the result is unspecified.
17347
17348If the intrinsic call has the ``nnan`` fast-math flag, then the operation can
17349assume that NaNs are not present in the input vector.
17350
17351Arguments:
17352""""""""""
17353The argument to this intrinsic must be a vector of floating-point values.
17354
17355'``llvm.vector.insert``' Intrinsic
17356^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17357
17358Syntax:
17359"""""""
17360This is an overloaded intrinsic.
17361
17362::
17363
17364      ; Insert fixed type into scalable type
17365      declare <vscale x 4 x float> @llvm.vector.insert.nxv4f32.v4f32(<vscale x 4 x float> %vec, <4 x float> %subvec, i64 <idx>)
17366      declare <vscale x 2 x double> @llvm.vector.insert.nxv2f64.v2f64(<vscale x 2 x double> %vec, <2 x double> %subvec, i64 <idx>)
17367
17368      ; Insert scalable type into scalable type
17369      declare <vscale x 4 x float> @llvm.vector.insert.nxv4f64.nxv2f64(<vscale x 4 x float> %vec, <vscale x 2 x float> %subvec, i64 <idx>)
17370
17371      ; Insert fixed type into fixed type
17372      declare <4 x double> @llvm.vector.insert.v4f64.v2f64(<4 x double> %vec, <2 x double> %subvec, i64 <idx>)
17373
17374Overview:
17375"""""""""
17376
17377The '``llvm.vector.insert.*``' intrinsics insert a vector into another vector
17378starting from a given index. The return type matches the type of the vector we
17379insert into. Conceptually, this can be used to build a scalable vector out of
17380non-scalable vectors, however this intrinsic can also be used on purely fixed
17381types.
17382
17383Scalable vectors can only be inserted into other scalable vectors.
17384
17385Arguments:
17386""""""""""
17387
17388The ``vec`` is the vector which ``subvec`` will be inserted into.
17389The ``subvec`` is the vector that will be inserted.
17390
17391``idx`` represents the starting element number at which ``subvec`` will be
17392inserted. ``idx`` must be a constant multiple of ``subvec``'s known minimum
17393vector length. If ``subvec`` is a scalable vector, ``idx`` is first scaled by
17394the runtime scaling factor of ``subvec``. The elements of ``vec`` starting at
17395``idx`` are overwritten with ``subvec``. Elements ``idx`` through (``idx`` +
17396num_elements(``subvec``) - 1) must be valid ``vec`` indices. If this condition
17397cannot be determined statically but is false at runtime, then the result vector
17398is a :ref:`poison value <poisonvalues>`.
17399
17400
17401'``llvm.vector.extract``' Intrinsic
17402^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17403
17404Syntax:
17405"""""""
17406This is an overloaded intrinsic.
17407
17408::
17409
17410      ; Extract fixed type from scalable type
17411      declare <4 x float> @llvm.vector.extract.v4f32.nxv4f32(<vscale x 4 x float> %vec, i64 <idx>)
17412      declare <2 x double> @llvm.vector.extract.v2f64.nxv2f64(<vscale x 2 x double> %vec, i64 <idx>)
17413
17414      ; Extract scalable type from scalable type
17415      declare <vscale x 2 x float> @llvm.vector.extract.nxv2f32.nxv4f32(<vscale x 4 x float> %vec, i64 <idx>)
17416
17417      ; Extract fixed type from fixed type
17418      declare <2 x double> @llvm.vector.extract.v2f64.v4f64(<4 x double> %vec, i64 <idx>)
17419
17420Overview:
17421"""""""""
17422
17423The '``llvm.vector.extract.*``' intrinsics extract a vector from within another
17424vector starting from a given index. The return type must be explicitly
17425specified. Conceptually, this can be used to decompose a scalable vector into
17426non-scalable parts, however this intrinsic can also be used on purely fixed
17427types.
17428
17429Scalable vectors can only be extracted from other scalable vectors.
17430
17431Arguments:
17432""""""""""
17433
17434The ``vec`` is the vector from which we will extract a subvector.
17435
17436The ``idx`` specifies the starting element number within ``vec`` from which a
17437subvector is extracted. ``idx`` must be a constant multiple of the known-minimum
17438vector length of the result type. If the result type is a scalable vector,
17439``idx`` is first scaled by the result type's runtime scaling factor. Elements
17440``idx`` through (``idx`` + num_elements(result_type) - 1) must be valid vector
17441indices. If this condition cannot be determined statically but is false at
17442runtime, then the result vector is a :ref:`poison value <poisonvalues>`. The
17443``idx`` parameter must be a vector index constant type (for most targets this
17444will be an integer pointer type).
17445
17446'``llvm.experimental.vector.reverse``' Intrinsic
17447^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17448
17449Syntax:
17450"""""""
17451This is an overloaded intrinsic.
17452
17453::
17454
17455      declare <2 x i8> @llvm.experimental.vector.reverse.v2i8(<2 x i8> %a)
17456      declare <vscale x 4 x i32> @llvm.experimental.vector.reverse.nxv4i32(<vscale x 4 x i32> %a)
17457
17458Overview:
17459"""""""""
17460
17461The '``llvm.experimental.vector.reverse.*``' intrinsics reverse a vector.
17462The intrinsic takes a single vector and returns a vector of matching type but
17463with the original lane order reversed. These intrinsics work for both fixed
17464and scalable vectors. While this intrinsic is marked as experimental the
17465recommended way to express reverse operations for fixed-width vectors is still
17466to use a shufflevector, as that may allow for more optimization opportunities.
17467
17468Arguments:
17469""""""""""
17470
17471The argument to this intrinsic must be a vector.
17472
17473'``llvm.experimental.vector.splice``' Intrinsic
17474^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17475
17476Syntax:
17477"""""""
17478This is an overloaded intrinsic.
17479
17480::
17481
17482      declare <2 x double> @llvm.experimental.vector.splice.v2f64(<2 x double> %vec1, <2 x double> %vec2, i32 %imm)
17483      declare <vscale x 4 x i32> @llvm.experimental.vector.splice.nxv4i32(<vscale x 4 x i32> %vec1, <vscale x 4 x i32> %vec2, i32 %imm)
17484
17485Overview:
17486"""""""""
17487
17488The '``llvm.experimental.vector.splice.*``' intrinsics construct a vector by
17489concatenating elements from the first input vector with elements of the second
17490input vector, returning a vector of the same type as the input vectors. The
17491signed immediate, modulo the number of elements in the vector, is the index
17492into the first vector from which to extract the result value. This means
17493conceptually that for a positive immediate, a vector is extracted from
17494``concat(%vec1, %vec2)`` starting at index ``imm``, whereas for a negative
17495immediate, it extracts ``-imm`` trailing elements from the first vector, and
17496the remaining elements from ``%vec2``.
17497
17498These intrinsics work for both fixed and scalable vectors. While this intrinsic
17499is marked as experimental, the recommended way to express this operation for
17500fixed-width vectors is still to use a shufflevector, as that may allow for more
17501optimization opportunities.
17502
17503For example:
17504
17505.. code-block:: text
17506
17507 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, 1)  ==> <B, C, D, E> ; index
17508 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, -3) ==> <B, C, D, E> ; trailing elements
17509
17510
17511Arguments:
17512""""""""""
17513
17514The first two operands are vectors with the same type. The start index is imm
17515modulo the runtime number of elements in the source vector. For a fixed-width
17516vector <N x eltty>, imm is a signed integer constant in the range
17517-N <= imm < N. For a scalable vector <vscale x N x eltty>, imm is a signed
17518integer constant in the range -X <= imm < X where X=vscale_range_min * N.
17519
17520'``llvm.experimental.stepvector``' Intrinsic
17521^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17522
17523This is an overloaded intrinsic. You can use ``llvm.experimental.stepvector``
17524to generate a vector whose lane values comprise the linear sequence
17525<0, 1, 2, ...>. It is primarily intended for scalable vectors.
17526
17527::
17528
17529      declare <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
17530      declare <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16()
17531
17532The '``llvm.experimental.stepvector``' intrinsics are used to create vectors
17533of integers whose elements contain a linear sequence of values starting from 0
17534with a step of 1.  This experimental intrinsic can only be used for vectors
17535with integer elements that are at least 8 bits in size. If the sequence value
17536exceeds the allowed limit for the element type then the result for that lane is
17537undefined.
17538
17539These intrinsics work for both fixed and scalable vectors. While this intrinsic
17540is marked as experimental, the recommended way to express this operation for
17541fixed-width vectors is still to generate a constant vector instead.
17542
17543
17544Arguments:
17545""""""""""
17546
17547None.
17548
17549
17550Matrix Intrinsics
17551-----------------
17552
17553Operations on matrixes requiring shape information (like number of rows/columns
17554or the memory layout) can be expressed using the matrix intrinsics. These
17555intrinsics require matrix dimensions to be passed as immediate arguments, and
17556matrixes are passed and returned as vectors. This means that for a ``R`` x
17557``C`` matrix, element ``i`` of column ``j`` is at index ``j * R + i`` in the
17558corresponding vector, with indices starting at 0. Currently column-major layout
17559is assumed.  The intrinsics support both integer and floating point matrixes.
17560
17561
17562'``llvm.matrix.transpose.*``' Intrinsic
17563^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17564
17565Syntax:
17566"""""""
17567This is an overloaded intrinsic.
17568
17569::
17570
17571      declare vectorty @llvm.matrix.transpose.*(vectorty %In, i32 <Rows>, i32 <Cols>)
17572
17573Overview:
17574"""""""""
17575
17576The '``llvm.matrix.transpose.*``' intrinsics treat ``%In`` as a ``<Rows> x
17577<Cols>`` matrix and return the transposed matrix in the result vector.
17578
17579Arguments:
17580""""""""""
17581
17582The first argument ``%In`` is a vector that corresponds to a ``<Rows> x
17583<Cols>`` matrix. Thus, arguments ``<Rows>`` and ``<Cols>`` correspond to the
17584number of rows and columns, respectively, and must be positive, constant
17585integers. The returned vector must have ``<Rows> * <Cols>`` elements, and have
17586the same float or integer element type as ``%In``.
17587
17588'``llvm.matrix.multiply.*``' Intrinsic
17589^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17590
17591Syntax:
17592"""""""
17593This is an overloaded intrinsic.
17594
17595::
17596
17597      declare vectorty @llvm.matrix.multiply.*(vectorty %A, vectorty %B, i32 <OuterRows>, i32 <Inner>, i32 <OuterColumns>)
17598
17599Overview:
17600"""""""""
17601
17602The '``llvm.matrix.multiply.*``' intrinsics treat ``%A`` as a ``<OuterRows> x
17603<Inner>`` matrix, ``%B`` as a ``<Inner> x <OuterColumns>`` matrix, and
17604multiplies them. The result matrix is returned in the result vector.
17605
17606Arguments:
17607""""""""""
17608
17609The first vector argument ``%A`` corresponds to a matrix with ``<OuterRows> *
17610<Inner>`` elements, and the second argument ``%B`` to a matrix with
17611``<Inner> * <OuterColumns>`` elements. Arguments ``<OuterRows>``,
17612``<Inner>`` and ``<OuterColumns>`` must be positive, constant integers. The
17613returned vector must have ``<OuterRows> * <OuterColumns>`` elements.
17614Vectors ``%A``, ``%B``, and the returned vector all have the same float or
17615integer element type.
17616
17617
17618'``llvm.matrix.column.major.load.*``' Intrinsic
17619^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17620
17621Syntax:
17622"""""""
17623This is an overloaded intrinsic.
17624
17625::
17626
17627      declare vectorty @llvm.matrix.column.major.load.*(
17628          ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>)
17629
17630Overview:
17631"""""""""
17632
17633The '``llvm.matrix.column.major.load.*``' intrinsics load a ``<Rows> x <Cols>``
17634matrix using a stride of ``%Stride`` to compute the start address of the
17635different columns.  The offset is computed using ``%Stride``'s bitwidth. This
17636allows for convenient loading of sub matrixes. If ``<IsVolatile>`` is true, the
17637intrinsic is considered a :ref:`volatile memory access <volatile>`. The result
17638matrix is returned in the result vector. If the ``%Ptr`` argument is known to
17639be aligned to some boundary, this can be specified as an attribute on the
17640argument.
17641
17642Arguments:
17643""""""""""
17644
17645The first argument ``%Ptr`` is a pointer type to the returned vector type, and
17646corresponds to the start address to load from. The second argument ``%Stride``
17647is a positive, constant integer with ``%Stride >= <Rows>``. ``%Stride`` is used
17648to compute the column memory addresses. I.e., for a column ``C``, its start
17649memory addresses is calculated with ``%Ptr + C * %Stride``. The third Argument
17650``<IsVolatile>`` is a boolean value.  The fourth and fifth arguments,
17651``<Rows>`` and ``<Cols>``, correspond to the number of rows and columns,
17652respectively, and must be positive, constant integers. The returned vector must
17653have ``<Rows> * <Cols>`` elements.
17654
17655The :ref:`align <attr_align>` parameter attribute can be provided for the
17656``%Ptr`` arguments.
17657
17658
17659'``llvm.matrix.column.major.store.*``' Intrinsic
17660^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17661
17662Syntax:
17663"""""""
17664
17665::
17666
17667      declare void @llvm.matrix.column.major.store.*(
17668          vectorty %In, ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>)
17669
17670Overview:
17671"""""""""
17672
17673The '``llvm.matrix.column.major.store.*``' intrinsics store the ``<Rows> x
17674<Cols>`` matrix in ``%In`` to memory using a stride of ``%Stride`` between
17675columns. The offset is computed using ``%Stride``'s bitwidth. If
17676``<IsVolatile>`` is true, the intrinsic is considered a
17677:ref:`volatile memory access <volatile>`.
17678
17679If the ``%Ptr`` argument is known to be aligned to some boundary, this can be
17680specified as an attribute on the argument.
17681
17682Arguments:
17683""""""""""
17684
17685The first argument ``%In`` is a vector that corresponds to a ``<Rows> x
17686<Cols>`` matrix to be stored to memory. The second argument ``%Ptr`` is a
17687pointer to the vector type of ``%In``, and is the start address of the matrix
17688in memory. The third argument ``%Stride`` is a positive, constant integer with
17689``%Stride >= <Rows>``.  ``%Stride`` is used to compute the column memory
17690addresses. I.e., for a column ``C``, its start memory addresses is calculated
17691with ``%Ptr + C * %Stride``.  The fourth argument ``<IsVolatile>`` is a boolean
17692value. The arguments ``<Rows>`` and ``<Cols>`` correspond to the number of rows
17693and columns, respectively, and must be positive, constant integers.
17694
17695The :ref:`align <attr_align>` parameter attribute can be provided
17696for the ``%Ptr`` arguments.
17697
17698
17699Half Precision Floating-Point Intrinsics
17700----------------------------------------
17701
17702For most target platforms, half precision floating-point is a
17703storage-only format. This means that it is a dense encoding (in memory)
17704but does not support computation in the format.
17705
17706This means that code must first load the half-precision floating-point
17707value as an i16, then convert it to float with
17708:ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can
17709then be performed on the float value (including extending to double
17710etc). To store the value back to memory, it is first converted to float
17711if needed, then converted to i16 with
17712:ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an
17713i16 value.
17714
17715.. _int_convert_to_fp16:
17716
17717'``llvm.convert.to.fp16``' Intrinsic
17718^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17719
17720Syntax:
17721"""""""
17722
17723::
17724
17725      declare i16 @llvm.convert.to.fp16.f32(float %a)
17726      declare i16 @llvm.convert.to.fp16.f64(double %a)
17727
17728Overview:
17729"""""""""
17730
17731The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
17732conventional floating-point type to half precision floating-point format.
17733
17734Arguments:
17735""""""""""
17736
17737The intrinsic function contains single argument - the value to be
17738converted.
17739
17740Semantics:
17741""""""""""
17742
17743The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
17744conventional floating-point format to half precision floating-point format. The
17745return value is an ``i16`` which contains the converted number.
17746
17747Examples:
17748"""""""""
17749
17750.. code-block:: llvm
17751
17752      %res = call i16 @llvm.convert.to.fp16.f32(float %a)
17753      store i16 %res, i16* @x, align 2
17754
17755.. _int_convert_from_fp16:
17756
17757'``llvm.convert.from.fp16``' Intrinsic
17758^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17759
17760Syntax:
17761"""""""
17762
17763::
17764
17765      declare float @llvm.convert.from.fp16.f32(i16 %a)
17766      declare double @llvm.convert.from.fp16.f64(i16 %a)
17767
17768Overview:
17769"""""""""
17770
17771The '``llvm.convert.from.fp16``' intrinsic function performs a
17772conversion from half precision floating-point format to single precision
17773floating-point format.
17774
17775Arguments:
17776""""""""""
17777
17778The intrinsic function contains single argument - the value to be
17779converted.
17780
17781Semantics:
17782""""""""""
17783
17784The '``llvm.convert.from.fp16``' intrinsic function performs a
17785conversion from half single precision floating-point format to single
17786precision floating-point format. The input half-float value is
17787represented by an ``i16`` value.
17788
17789Examples:
17790"""""""""
17791
17792.. code-block:: llvm
17793
17794      %a = load i16, i16* @x, align 2
17795      %res = call float @llvm.convert.from.fp16(i16 %a)
17796
17797Saturating floating-point to integer conversions
17798------------------------------------------------
17799
17800The ``fptoui`` and ``fptosi`` instructions return a
17801:ref:`poison value <poisonvalues>` if the rounded-towards-zero value is not
17802representable by the result type. These intrinsics provide an alternative
17803conversion, which will saturate towards the smallest and largest representable
17804integer values instead.
17805
17806'``llvm.fptoui.sat.*``' Intrinsic
17807^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17808
17809Syntax:
17810"""""""
17811
17812This is an overloaded intrinsic. You can use ``llvm.fptoui.sat`` on any
17813floating-point argument type and any integer result type, or vectors thereof.
17814Not all targets may support all types, however.
17815
17816::
17817
17818      declare i32 @llvm.fptoui.sat.i32.f32(float %f)
17819      declare i19 @llvm.fptoui.sat.i19.f64(double %f)
17820      declare <4 x i100> @llvm.fptoui.sat.v4i100.v4f128(<4 x fp128> %f)
17821
17822Overview:
17823"""""""""
17824
17825This intrinsic converts the argument into an unsigned integer using saturating
17826semantics.
17827
17828Arguments:
17829""""""""""
17830
17831The argument may be any floating-point or vector of floating-point type. The
17832return value may be any integer or vector of integer type. The number of vector
17833elements in argument and return must be the same.
17834
17835Semantics:
17836""""""""""
17837
17838The conversion to integer is performed subject to the following rules:
17839
17840- If the argument is any NaN, zero is returned.
17841- If the argument is smaller than zero (this includes negative infinity),
17842  zero is returned.
17843- If the argument is larger than the largest representable unsigned integer of
17844  the result type (this includes positive infinity), the largest representable
17845  unsigned integer is returned.
17846- Otherwise, the result of rounding the argument towards zero is returned.
17847
17848Example:
17849""""""""
17850
17851.. code-block:: text
17852
17853      %a = call i8 @llvm.fptoui.sat.i8.f32(float 123.9)              ; yields i8: 123
17854      %b = call i8 @llvm.fptoui.sat.i8.f32(float -5.7)               ; yields i8:   0
17855      %c = call i8 @llvm.fptoui.sat.i8.f32(float 377.0)              ; yields i8: 255
17856      %d = call i8 @llvm.fptoui.sat.i8.f32(float 0xFFF8000000000000) ; yields i8:   0
17857
17858'``llvm.fptosi.sat.*``' Intrinsic
17859^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17860
17861Syntax:
17862"""""""
17863
17864This is an overloaded intrinsic. You can use ``llvm.fptosi.sat`` on any
17865floating-point argument type and any integer result type, or vectors thereof.
17866Not all targets may support all types, however.
17867
17868::
17869
17870      declare i32 @llvm.fptosi.sat.i32.f32(float %f)
17871      declare i19 @llvm.fptosi.sat.i19.f64(double %f)
17872      declare <4 x i100> @llvm.fptosi.sat.v4i100.v4f128(<4 x fp128> %f)
17873
17874Overview:
17875"""""""""
17876
17877This intrinsic converts the argument into a signed integer using saturating
17878semantics.
17879
17880Arguments:
17881""""""""""
17882
17883The argument may be any floating-point or vector of floating-point type. The
17884return value may be any integer or vector of integer type. The number of vector
17885elements in argument and return must be the same.
17886
17887Semantics:
17888""""""""""
17889
17890The conversion to integer is performed subject to the following rules:
17891
17892- If the argument is any NaN, zero is returned.
17893- If the argument is smaller than the smallest representable signed integer of
17894  the result type (this includes negative infinity), the smallest
17895  representable signed integer is returned.
17896- If the argument is larger than the largest representable signed integer of
17897  the result type (this includes positive infinity), the largest representable
17898  signed integer is returned.
17899- Otherwise, the result of rounding the argument towards zero is returned.
17900
17901Example:
17902""""""""
17903
17904.. code-block:: text
17905
17906      %a = call i8 @llvm.fptosi.sat.i8.f32(float 23.9)               ; yields i8:   23
17907      %b = call i8 @llvm.fptosi.sat.i8.f32(float -130.8)             ; yields i8: -128
17908      %c = call i8 @llvm.fptosi.sat.i8.f32(float 999.0)              ; yields i8:  127
17909      %d = call i8 @llvm.fptosi.sat.i8.f32(float 0xFFF8000000000000) ; yields i8:    0
17910
17911.. _dbg_intrinsics:
17912
17913Debugger Intrinsics
17914-------------------
17915
17916The LLVM debugger intrinsics (which all start with ``llvm.dbg.``
17917prefix), are described in the `LLVM Source Level
17918Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_
17919document.
17920
17921Exception Handling Intrinsics
17922-----------------------------
17923
17924The LLVM exception handling intrinsics (which all start with
17925``llvm.eh.`` prefix), are described in the `LLVM Exception
17926Handling <ExceptionHandling.html#format-common-intrinsics>`_ document.
17927
17928Pointer Authentication Intrinsics
17929---------------------------------
17930
17931The LLVM pointer authentication intrinsics (which all start with
17932``llvm.ptrauth.`` prefix), are described in the `Pointer Authentication
17933<PointerAuth.html#intrinsics>`_ document.
17934
17935.. _int_trampoline:
17936
17937Trampoline Intrinsics
17938---------------------
17939
17940These intrinsics make it possible to excise one parameter, marked with
17941the :ref:`nest <nest>` attribute, from a function. The result is a
17942callable function pointer lacking the nest parameter - the caller does
17943not need to provide a value for it. Instead, the value to use is stored
17944in advance in a "trampoline", a block of memory usually allocated on the
17945stack, which also contains code to splice the nest value into the
17946argument list. This is used to implement the GCC nested function address
17947extension.
17948
17949For example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)``
17950then the resulting function pointer has signature ``i32 (i32, i32)*``.
17951It can be created as follows:
17952
17953.. code-block:: llvm
17954
17955      %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
17956      %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0
17957      call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval)
17958      %p = call i8* @llvm.adjust.trampoline(i8* %tramp1)
17959      %fp = bitcast i8* %p to i32 (i32, i32)*
17960
17961The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to
17962``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``.
17963
17964.. _int_it:
17965
17966'``llvm.init.trampoline``' Intrinsic
17967^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17968
17969Syntax:
17970"""""""
17971
17972::
17973
17974      declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
17975
17976Overview:
17977"""""""""
17978
17979This fills the memory pointed to by ``tramp`` with executable code,
17980turning it into a trampoline.
17981
17982Arguments:
17983""""""""""
17984
17985The ``llvm.init.trampoline`` intrinsic takes three arguments, all
17986pointers. The ``tramp`` argument must point to a sufficiently large and
17987sufficiently aligned block of memory; this memory is written to by the
17988intrinsic. Note that the size and the alignment are target-specific -
17989LLVM currently provides no portable way of determining them, so a
17990front-end that generates this intrinsic needs to have some
17991target-specific knowledge. The ``func`` argument must hold a function
17992bitcast to an ``i8*``.
17993
17994Semantics:
17995""""""""""
17996
17997The block of memory pointed to by ``tramp`` is filled with target
17998dependent code, turning it into a function. Then ``tramp`` needs to be
17999passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can
18000be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new
18001function's signature is the same as that of ``func`` with any arguments
18002marked with the ``nest`` attribute removed. At most one such ``nest``
18003argument is allowed, and it must be of pointer type. Calling the new
18004function is equivalent to calling ``func`` with the same argument list,
18005but with ``nval`` used for the missing ``nest`` argument. If, after
18006calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is
18007modified, then the effect of any later call to the returned function
18008pointer is undefined.
18009
18010.. _int_at:
18011
18012'``llvm.adjust.trampoline``' Intrinsic
18013^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18014
18015Syntax:
18016"""""""
18017
18018::
18019
18020      declare i8* @llvm.adjust.trampoline(i8* <tramp>)
18021
18022Overview:
18023"""""""""
18024
18025This performs any required machine-specific adjustment to the address of
18026a trampoline (passed as ``tramp``).
18027
18028Arguments:
18029""""""""""
18030
18031``tramp`` must point to a block of memory which already has trampoline
18032code filled in by a previous call to
18033:ref:`llvm.init.trampoline <int_it>`.
18034
18035Semantics:
18036""""""""""
18037
18038On some architectures the address of the code to be executed needs to be
18039different than the address where the trampoline is actually stored. This
18040intrinsic returns the executable address corresponding to ``tramp``
18041after performing the required machine specific adjustments. The pointer
18042returned can then be :ref:`bitcast and executed <int_trampoline>`.
18043
18044
18045.. _int_vp:
18046
18047Vector Predication Intrinsics
18048-----------------------------
18049VP intrinsics are intended for predicated SIMD/vector code.  A typical VP
18050operation takes a vector mask and an explicit vector length parameter as in:
18051
18052::
18053
18054      <W x T> llvm.vp.<opcode>.*(<W x T> %x, <W x T> %y, <W x i1> %mask, i32 %evl)
18055
18056The vector mask parameter (%mask) always has a vector of `i1` type, for example
18057`<32 x i1>`.  The explicit vector length parameter always has the type `i32` and
18058is an unsigned integer value.  The explicit vector length parameter (%evl) is in
18059the range:
18060
18061::
18062
18063      0 <= %evl <= W,  where W is the number of vector elements
18064
18065Note that for :ref:`scalable vector types <t_vector>` ``W`` is the runtime
18066length of the vector.
18067
18068The VP intrinsic has undefined behavior if ``%evl > W``.  The explicit vector
18069length (%evl) creates a mask, %EVLmask, with all elements ``0 <= i < %evl`` set
18070to True, and all other lanes ``%evl <= i < W`` to False.  A new mask %M is
18071calculated with an element-wise AND from %mask and %EVLmask:
18072
18073::
18074
18075      M = %mask AND %EVLmask
18076
18077A vector operation ``<opcode>`` on vectors ``A`` and ``B`` calculates:
18078
18079::
18080
18081       A <opcode> B =  {  A[i] <opcode> B[i]   M[i] = True, and
18082                       {  undef otherwise
18083
18084Optimization Hint
18085^^^^^^^^^^^^^^^^^
18086
18087Some targets, such as AVX512, do not support the %evl parameter in hardware.
18088The use of an effective %evl is discouraged for those targets.  The function
18089``TargetTransformInfo::hasActiveVectorLength()`` returns true when the target
18090has native support for %evl.
18091
18092.. _int_vp_select:
18093
18094'``llvm.vp.select.*``' Intrinsics
18095^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18096
18097Syntax:
18098"""""""
18099This is an overloaded intrinsic.
18100
18101::
18102
18103      declare <16 x i32>  @llvm.vp.select.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <evl>)
18104      declare <vscale x 4 x i64>  @llvm.vp.select.nxv4i64 (<vscale x 4 x i1> <condition>, <vscale x 4 x i64> <on_true>, <vscale x 4 x i64> <on_false>, i32 <evl>)
18105
18106Overview:
18107"""""""""
18108
18109The '``llvm.vp.select``' intrinsic is used to choose one value based on a
18110condition vector, without IR-level branching.
18111
18112Arguments:
18113""""""""""
18114
18115The first operand is a vector of ``i1`` and indicates the condition.  The
18116second operand is the value that is selected where the condition vector is
18117true.  The third operand is the value that is selected where the condition
18118vector is false.  The vectors must be of the same size.  The fourth operand is
18119the explicit vector length.
18120
18121#. The optional ``fast-math flags`` marker indicates that the select has one or
18122   more :ref:`fast-math flags <fastmath>`. These are optimization hints to
18123   enable otherwise unsafe floating-point optimizations. Fast-math flags are
18124   only valid for selects that return a floating-point scalar or vector type,
18125   or an array (nested to any depth) of floating-point scalar or vector types.
18126
18127Semantics:
18128""""""""""
18129
18130The intrinsic selects lanes from the second and third operand depending on a
18131condition vector.
18132
18133All result lanes at positions greater or equal than ``%evl`` are undefined.
18134For all lanes below ``%evl`` where the condition vector is true the lane is
18135taken from the second operand.  Otherwise, the lane is taken from the third
18136operand.
18137
18138Example:
18139""""""""
18140
18141.. code-block:: llvm
18142
18143      %r = call <4 x i32> @llvm.vp.select.v4i32(<4 x i1> %cond, <4 x i32> %on_true, <4 x i32> %on_false, i32 %evl)
18144
18145      ;;; Expansion.
18146      ;; Any result is legal on lanes at and above %evl.
18147      %also.r = select <4 x i1> %cond, <4 x i32> %on_true, <4 x i32> %on_false
18148
18149
18150.. _int_vp_merge:
18151
18152'``llvm.vp.merge.*``' Intrinsics
18153^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18154
18155Syntax:
18156"""""""
18157This is an overloaded intrinsic.
18158
18159::
18160
18161      declare <16 x i32>  @llvm.vp.merge.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <pivot>)
18162      declare <vscale x 4 x i64>  @llvm.vp.merge.nxv4i64 (<vscale x 4 x i1> <condition>, <vscale x 4 x i64> <on_true>, <vscale x 4 x i64> <on_false>, i32 <pivot>)
18163
18164Overview:
18165"""""""""
18166
18167The '``llvm.vp.merge``' intrinsic is used to choose one value based on a
18168condition vector and an index operand, without IR-level branching.
18169
18170Arguments:
18171""""""""""
18172
18173The first operand is a vector of ``i1`` and indicates the condition.  The
18174second operand is the value that is merged where the condition vector is true.
18175The third operand is the value that is selected where the condition vector is
18176false or the lane position is greater equal than the pivot. The fourth operand
18177is the pivot.
18178
18179#. The optional ``fast-math flags`` marker indicates that the merge has one or
18180   more :ref:`fast-math flags <fastmath>`. These are optimization hints to
18181   enable otherwise unsafe floating-point optimizations. Fast-math flags are
18182   only valid for merges that return a floating-point scalar or vector type,
18183   or an array (nested to any depth) of floating-point scalar or vector types.
18184
18185Semantics:
18186""""""""""
18187
18188The intrinsic selects lanes from the second and third operand depending on a
18189condition vector and pivot value.
18190
18191For all lanes where the condition vector is true and the lane position is less
18192than ``%pivot`` the lane is taken from the second operand.  Otherwise, the lane
18193is taken from the third operand.
18194
18195Example:
18196""""""""
18197
18198.. code-block:: llvm
18199
18200      %r = call <4 x i32> @llvm.vp.merge.v4i32(<4 x i1> %cond, <4 x i32> %on_true, <4 x i32> %on_false, i32 %pivot)
18201
18202      ;;; Expansion.
18203      ;; Lanes at and above %pivot are taken from %on_false
18204      %atfirst = insertelement <4 x i32> undef, i32 %pivot, i32 0
18205      %splat = shufflevector <4 x i32> %atfirst, <4 x i32> poison, <4 x i32> zeroinitializer
18206      %pivotmask = icmp ult <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32> %splat
18207      %mergemask = and <4 x i1> %cond, <4 x i1> %pivotmask
18208      %also.r = select <4 x i1> %mergemask, <4 x i32> %on_true, <4 x i32> %on_false
18209
18210
18211
18212.. _int_vp_add:
18213
18214'``llvm.vp.add.*``' Intrinsics
18215^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18216
18217Syntax:
18218"""""""
18219This is an overloaded intrinsic.
18220
18221::
18222
18223      declare <16 x i32>  @llvm.vp.add.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18224      declare <vscale x 4 x i32>  @llvm.vp.add.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18225      declare <256 x i64>  @llvm.vp.add.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18226
18227Overview:
18228"""""""""
18229
18230Predicated integer addition of two vectors of integers.
18231
18232
18233Arguments:
18234""""""""""
18235
18236The first two operands and the result have the same vector of integer type. The
18237third operand is the vector mask and has the same number of elements as the
18238result vector type. The fourth operand is the explicit vector length of the
18239operation.
18240
18241Semantics:
18242""""""""""
18243
18244The '``llvm.vp.add``' intrinsic performs integer addition (:ref:`add <i_add>`)
18245of the first and second vector operand on each enabled lane.  The result on
18246disabled lanes is undefined.
18247
18248Examples:
18249"""""""""
18250
18251.. code-block:: llvm
18252
18253      %r = call <4 x i32> @llvm.vp.add.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18254      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18255
18256      %t = add <4 x i32> %a, %b
18257      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18258
18259.. _int_vp_sub:
18260
18261'``llvm.vp.sub.*``' Intrinsics
18262^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18263
18264Syntax:
18265"""""""
18266This is an overloaded intrinsic.
18267
18268::
18269
18270      declare <16 x i32>  @llvm.vp.sub.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18271      declare <vscale x 4 x i32>  @llvm.vp.sub.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18272      declare <256 x i64>  @llvm.vp.sub.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18273
18274Overview:
18275"""""""""
18276
18277Predicated integer subtraction of two vectors of integers.
18278
18279
18280Arguments:
18281""""""""""
18282
18283The first two operands and the result have the same vector of integer type. The
18284third operand is the vector mask and has the same number of elements as the
18285result vector type. The fourth operand is the explicit vector length of the
18286operation.
18287
18288Semantics:
18289""""""""""
18290
18291The '``llvm.vp.sub``' intrinsic performs integer subtraction
18292(:ref:`sub <i_sub>`)  of the first and second vector operand on each enabled
18293lane. The result on disabled lanes is undefined.
18294
18295Examples:
18296"""""""""
18297
18298.. code-block:: llvm
18299
18300      %r = call <4 x i32> @llvm.vp.sub.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18301      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18302
18303      %t = sub <4 x i32> %a, %b
18304      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18305
18306
18307
18308.. _int_vp_mul:
18309
18310'``llvm.vp.mul.*``' Intrinsics
18311^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18312
18313Syntax:
18314"""""""
18315This is an overloaded intrinsic.
18316
18317::
18318
18319      declare <16 x i32>  @llvm.vp.mul.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18320      declare <vscale x 4 x i32>  @llvm.vp.mul.nxv46i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18321      declare <256 x i64>  @llvm.vp.mul.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18322
18323Overview:
18324"""""""""
18325
18326Predicated integer multiplication of two vectors of integers.
18327
18328
18329Arguments:
18330""""""""""
18331
18332The first two operands and the result have the same vector of integer type. The
18333third operand is the vector mask and has the same number of elements as the
18334result vector type. The fourth operand is the explicit vector length of the
18335operation.
18336
18337Semantics:
18338""""""""""
18339The '``llvm.vp.mul``' intrinsic performs integer multiplication
18340(:ref:`mul <i_mul>`) of the first and second vector operand on each enabled
18341lane. The result on disabled lanes is undefined.
18342
18343Examples:
18344"""""""""
18345
18346.. code-block:: llvm
18347
18348      %r = call <4 x i32> @llvm.vp.mul.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18349      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18350
18351      %t = mul <4 x i32> %a, %b
18352      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18353
18354
18355.. _int_vp_sdiv:
18356
18357'``llvm.vp.sdiv.*``' Intrinsics
18358^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18359
18360Syntax:
18361"""""""
18362This is an overloaded intrinsic.
18363
18364::
18365
18366      declare <16 x i32>  @llvm.vp.sdiv.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18367      declare <vscale x 4 x i32>  @llvm.vp.sdiv.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18368      declare <256 x i64>  @llvm.vp.sdiv.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18369
18370Overview:
18371"""""""""
18372
18373Predicated, signed division of two vectors of integers.
18374
18375
18376Arguments:
18377""""""""""
18378
18379The first two operands and the result have the same vector of integer type. The
18380third operand is the vector mask and has the same number of elements as the
18381result vector type. The fourth operand is the explicit vector length of the
18382operation.
18383
18384Semantics:
18385""""""""""
18386
18387The '``llvm.vp.sdiv``' intrinsic performs signed division (:ref:`sdiv <i_sdiv>`)
18388of the first and second vector operand on each enabled lane.  The result on
18389disabled lanes is undefined.
18390
18391Examples:
18392"""""""""
18393
18394.. code-block:: llvm
18395
18396      %r = call <4 x i32> @llvm.vp.sdiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18397      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18398
18399      %t = sdiv <4 x i32> %a, %b
18400      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18401
18402
18403.. _int_vp_udiv:
18404
18405'``llvm.vp.udiv.*``' Intrinsics
18406^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18407
18408Syntax:
18409"""""""
18410This is an overloaded intrinsic.
18411
18412::
18413
18414      declare <16 x i32>  @llvm.vp.udiv.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18415      declare <vscale x 4 x i32>  @llvm.vp.udiv.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18416      declare <256 x i64>  @llvm.vp.udiv.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18417
18418Overview:
18419"""""""""
18420
18421Predicated, unsigned division of two vectors of integers.
18422
18423
18424Arguments:
18425""""""""""
18426
18427The first two operands and the result have the same vector of integer type. The third operand is the vector mask and has the same number of elements as the result vector type. The fourth operand is the explicit vector length of the operation.
18428
18429Semantics:
18430""""""""""
18431
18432The '``llvm.vp.udiv``' intrinsic performs unsigned division
18433(:ref:`udiv <i_udiv>`) of the first and second vector operand on each enabled
18434lane. The result on disabled lanes is undefined.
18435
18436Examples:
18437"""""""""
18438
18439.. code-block:: llvm
18440
18441      %r = call <4 x i32> @llvm.vp.udiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18442      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18443
18444      %t = udiv <4 x i32> %a, %b
18445      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18446
18447
18448
18449.. _int_vp_srem:
18450
18451'``llvm.vp.srem.*``' Intrinsics
18452^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18453
18454Syntax:
18455"""""""
18456This is an overloaded intrinsic.
18457
18458::
18459
18460      declare <16 x i32>  @llvm.vp.srem.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18461      declare <vscale x 4 x i32>  @llvm.vp.srem.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18462      declare <256 x i64>  @llvm.vp.srem.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18463
18464Overview:
18465"""""""""
18466
18467Predicated computations of the signed remainder of two integer vectors.
18468
18469
18470Arguments:
18471""""""""""
18472
18473The first two operands and the result have the same vector of integer type. The
18474third operand is the vector mask and has the same number of elements as the
18475result vector type. The fourth operand is the explicit vector length of the
18476operation.
18477
18478Semantics:
18479""""""""""
18480
18481The '``llvm.vp.srem``' intrinsic computes the remainder of the signed division
18482(:ref:`srem <i_srem>`) of the first and second vector operand on each enabled
18483lane.  The result on disabled lanes is undefined.
18484
18485Examples:
18486"""""""""
18487
18488.. code-block:: llvm
18489
18490      %r = call <4 x i32> @llvm.vp.srem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18491      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18492
18493      %t = srem <4 x i32> %a, %b
18494      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18495
18496
18497
18498.. _int_vp_urem:
18499
18500'``llvm.vp.urem.*``' Intrinsics
18501^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18502
18503Syntax:
18504"""""""
18505This is an overloaded intrinsic.
18506
18507::
18508
18509      declare <16 x i32>  @llvm.vp.urem.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18510      declare <vscale x 4 x i32>  @llvm.vp.urem.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18511      declare <256 x i64>  @llvm.vp.urem.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18512
18513Overview:
18514"""""""""
18515
18516Predicated computation of the unsigned remainder of two integer vectors.
18517
18518
18519Arguments:
18520""""""""""
18521
18522The first two operands and the result have the same vector of integer type. The
18523third operand is the vector mask and has the same number of elements as the
18524result vector type. The fourth operand is the explicit vector length of the
18525operation.
18526
18527Semantics:
18528""""""""""
18529
18530The '``llvm.vp.urem``' intrinsic computes the remainder of the unsigned division
18531(:ref:`urem <i_urem>`) of the first and second vector operand on each enabled
18532lane.  The result on disabled lanes is undefined.
18533
18534Examples:
18535"""""""""
18536
18537.. code-block:: llvm
18538
18539      %r = call <4 x i32> @llvm.vp.urem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18540      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18541
18542      %t = urem <4 x i32> %a, %b
18543      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18544
18545
18546.. _int_vp_ashr:
18547
18548'``llvm.vp.ashr.*``' Intrinsics
18549^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18550
18551Syntax:
18552"""""""
18553This is an overloaded intrinsic.
18554
18555::
18556
18557      declare <16 x i32>  @llvm.vp.ashr.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18558      declare <vscale x 4 x i32>  @llvm.vp.ashr.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18559      declare <256 x i64>  @llvm.vp.ashr.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18560
18561Overview:
18562"""""""""
18563
18564Vector-predicated arithmetic right-shift.
18565
18566
18567Arguments:
18568""""""""""
18569
18570The first two operands and the result have the same vector of integer type. The
18571third operand is the vector mask and has the same number of elements as the
18572result vector type. The fourth operand is the explicit vector length of the
18573operation.
18574
18575Semantics:
18576""""""""""
18577
18578The '``llvm.vp.ashr``' intrinsic computes the arithmetic right shift
18579(:ref:`ashr <i_ashr>`) of the first operand by the second operand on each
18580enabled lane. The result on disabled lanes is undefined.
18581
18582Examples:
18583"""""""""
18584
18585.. code-block:: llvm
18586
18587      %r = call <4 x i32> @llvm.vp.ashr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18588      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18589
18590      %t = ashr <4 x i32> %a, %b
18591      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18592
18593
18594.. _int_vp_lshr:
18595
18596
18597'``llvm.vp.lshr.*``' Intrinsics
18598^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18599
18600Syntax:
18601"""""""
18602This is an overloaded intrinsic.
18603
18604::
18605
18606      declare <16 x i32>  @llvm.vp.lshr.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18607      declare <vscale x 4 x i32>  @llvm.vp.lshr.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18608      declare <256 x i64>  @llvm.vp.lshr.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18609
18610Overview:
18611"""""""""
18612
18613Vector-predicated logical right-shift.
18614
18615
18616Arguments:
18617""""""""""
18618
18619The first two operands and the result have the same vector of integer type. The
18620third operand is the vector mask and has the same number of elements as the
18621result vector type. The fourth operand is the explicit vector length of the
18622operation.
18623
18624Semantics:
18625""""""""""
18626
18627The '``llvm.vp.lshr``' intrinsic computes the logical right shift
18628(:ref:`lshr <i_lshr>`) of the first operand by the second operand on each
18629enabled lane. The result on disabled lanes is undefined.
18630
18631Examples:
18632"""""""""
18633
18634.. code-block:: llvm
18635
18636      %r = call <4 x i32> @llvm.vp.lshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18637      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18638
18639      %t = lshr <4 x i32> %a, %b
18640      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18641
18642
18643.. _int_vp_shl:
18644
18645'``llvm.vp.shl.*``' Intrinsics
18646^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18647
18648Syntax:
18649"""""""
18650This is an overloaded intrinsic.
18651
18652::
18653
18654      declare <16 x i32>  @llvm.vp.shl.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18655      declare <vscale x 4 x i32>  @llvm.vp.shl.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18656      declare <256 x i64>  @llvm.vp.shl.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18657
18658Overview:
18659"""""""""
18660
18661Vector-predicated left shift.
18662
18663
18664Arguments:
18665""""""""""
18666
18667The first two operands and the result have the same vector of integer type. The
18668third operand is the vector mask and has the same number of elements as the
18669result vector type. The fourth operand is the explicit vector length of the
18670operation.
18671
18672Semantics:
18673""""""""""
18674
18675The '``llvm.vp.shl``' intrinsic computes the left shift (:ref:`shl <i_shl>`) of
18676the first operand by the second operand on each enabled lane.  The result on
18677disabled lanes is undefined.
18678
18679Examples:
18680"""""""""
18681
18682.. code-block:: llvm
18683
18684      %r = call <4 x i32> @llvm.vp.shl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18685      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18686
18687      %t = shl <4 x i32> %a, %b
18688      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18689
18690
18691.. _int_vp_or:
18692
18693'``llvm.vp.or.*``' Intrinsics
18694^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18695
18696Syntax:
18697"""""""
18698This is an overloaded intrinsic.
18699
18700::
18701
18702      declare <16 x i32>  @llvm.vp.or.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18703      declare <vscale x 4 x i32>  @llvm.vp.or.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18704      declare <256 x i64>  @llvm.vp.or.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18705
18706Overview:
18707"""""""""
18708
18709Vector-predicated or.
18710
18711
18712Arguments:
18713""""""""""
18714
18715The first two operands and the result have the same vector of integer type. The
18716third operand is the vector mask and has the same number of elements as the
18717result vector type. The fourth operand is the explicit vector length of the
18718operation.
18719
18720Semantics:
18721""""""""""
18722
18723The '``llvm.vp.or``' intrinsic performs a bitwise or (:ref:`or <i_or>`) of the
18724first two operands on each enabled lane.  The result on disabled lanes is
18725undefined.
18726
18727Examples:
18728"""""""""
18729
18730.. code-block:: llvm
18731
18732      %r = call <4 x i32> @llvm.vp.or.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18733      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18734
18735      %t = or <4 x i32> %a, %b
18736      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18737
18738
18739.. _int_vp_and:
18740
18741'``llvm.vp.and.*``' Intrinsics
18742^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18743
18744Syntax:
18745"""""""
18746This is an overloaded intrinsic.
18747
18748::
18749
18750      declare <16 x i32>  @llvm.vp.and.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18751      declare <vscale x 4 x i32>  @llvm.vp.and.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18752      declare <256 x i64>  @llvm.vp.and.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18753
18754Overview:
18755"""""""""
18756
18757Vector-predicated and.
18758
18759
18760Arguments:
18761""""""""""
18762
18763The first two operands and the result have the same vector of integer type. The
18764third operand is the vector mask and has the same number of elements as the
18765result vector type. The fourth operand is the explicit vector length of the
18766operation.
18767
18768Semantics:
18769""""""""""
18770
18771The '``llvm.vp.and``' intrinsic performs a bitwise and (:ref:`and <i_or>`) of
18772the first two operands on each enabled lane.  The result on disabled lanes is
18773undefined.
18774
18775Examples:
18776"""""""""
18777
18778.. code-block:: llvm
18779
18780      %r = call <4 x i32> @llvm.vp.and.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18781      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18782
18783      %t = and <4 x i32> %a, %b
18784      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18785
18786
18787.. _int_vp_xor:
18788
18789'``llvm.vp.xor.*``' Intrinsics
18790^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18791
18792Syntax:
18793"""""""
18794This is an overloaded intrinsic.
18795
18796::
18797
18798      declare <16 x i32>  @llvm.vp.xor.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18799      declare <vscale x 4 x i32>  @llvm.vp.xor.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18800      declare <256 x i64>  @llvm.vp.xor.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18801
18802Overview:
18803"""""""""
18804
18805Vector-predicated, bitwise xor.
18806
18807
18808Arguments:
18809""""""""""
18810
18811The first two operands and the result have the same vector of integer type. The
18812third operand is the vector mask and has the same number of elements as the
18813result vector type. The fourth operand is the explicit vector length of the
18814operation.
18815
18816Semantics:
18817""""""""""
18818
18819The '``llvm.vp.xor``' intrinsic performs a bitwise xor (:ref:`xor <i_xor>`) of
18820the first two operands on each enabled lane.
18821The result on disabled lanes is undefined.
18822
18823Examples:
18824"""""""""
18825
18826.. code-block:: llvm
18827
18828      %r = call <4 x i32> @llvm.vp.xor.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18829      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18830
18831      %t = xor <4 x i32> %a, %b
18832      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18833
18834
18835.. _int_vp_fadd:
18836
18837'``llvm.vp.fadd.*``' Intrinsics
18838^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18839
18840Syntax:
18841"""""""
18842This is an overloaded intrinsic.
18843
18844::
18845
18846      declare <16 x float>  @llvm.vp.fadd.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18847      declare <vscale x 4 x float>  @llvm.vp.fadd.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18848      declare <256 x double>  @llvm.vp.fadd.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18849
18850Overview:
18851"""""""""
18852
18853Predicated floating-point addition of two vectors of floating-point values.
18854
18855
18856Arguments:
18857""""""""""
18858
18859The first two operands and the result have the same vector of floating-point type. The
18860third operand is the vector mask and has the same number of elements as the
18861result vector type. The fourth operand is the explicit vector length of the
18862operation.
18863
18864Semantics:
18865""""""""""
18866
18867The '``llvm.vp.fadd``' intrinsic performs floating-point addition (:ref:`fadd <i_fadd>`)
18868of the first and second vector operand on each enabled lane.  The result on
18869disabled lanes is undefined.  The operation is performed in the default
18870floating-point environment.
18871
18872Examples:
18873"""""""""
18874
18875.. code-block:: llvm
18876
18877      %r = call <4 x float> @llvm.vp.fadd.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
18878      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18879
18880      %t = fadd <4 x float> %a, %b
18881      %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
18882
18883
18884.. _int_vp_fsub:
18885
18886'``llvm.vp.fsub.*``' Intrinsics
18887^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18888
18889Syntax:
18890"""""""
18891This is an overloaded intrinsic.
18892
18893::
18894
18895      declare <16 x float>  @llvm.vp.fsub.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18896      declare <vscale x 4 x float>  @llvm.vp.fsub.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18897      declare <256 x double>  @llvm.vp.fsub.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18898
18899Overview:
18900"""""""""
18901
18902Predicated floating-point subtraction of two vectors of floating-point values.
18903
18904
18905Arguments:
18906""""""""""
18907
18908The first two operands and the result have the same vector of floating-point type. The
18909third operand is the vector mask and has the same number of elements as the
18910result vector type. The fourth operand is the explicit vector length of the
18911operation.
18912
18913Semantics:
18914""""""""""
18915
18916The '``llvm.vp.fsub``' intrinsic performs floating-point subtraction (:ref:`fsub <i_fsub>`)
18917of the first and second vector operand on each enabled lane.  The result on
18918disabled lanes is undefined.  The operation is performed in the default
18919floating-point environment.
18920
18921Examples:
18922"""""""""
18923
18924.. code-block:: llvm
18925
18926      %r = call <4 x float> @llvm.vp.fsub.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
18927      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18928
18929      %t = fsub <4 x float> %a, %b
18930      %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
18931
18932
18933.. _int_vp_fmul:
18934
18935'``llvm.vp.fmul.*``' Intrinsics
18936^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18937
18938Syntax:
18939"""""""
18940This is an overloaded intrinsic.
18941
18942::
18943
18944      declare <16 x float>  @llvm.vp.fmul.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18945      declare <vscale x 4 x float>  @llvm.vp.fmul.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18946      declare <256 x double>  @llvm.vp.fmul.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18947
18948Overview:
18949"""""""""
18950
18951Predicated floating-point multiplication of two vectors of floating-point values.
18952
18953
18954Arguments:
18955""""""""""
18956
18957The first two operands and the result have the same vector of floating-point type. The
18958third operand is the vector mask and has the same number of elements as the
18959result vector type. The fourth operand is the explicit vector length of the
18960operation.
18961
18962Semantics:
18963""""""""""
18964
18965The '``llvm.vp.fmul``' intrinsic performs floating-point multiplication (:ref:`fmul <i_fmul>`)
18966of the first and second vector operand on each enabled lane.  The result on
18967disabled lanes is undefined.  The operation is performed in the default
18968floating-point environment.
18969
18970Examples:
18971"""""""""
18972
18973.. code-block:: llvm
18974
18975      %r = call <4 x float> @llvm.vp.fmul.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
18976      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18977
18978      %t = fmul <4 x float> %a, %b
18979      %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
18980
18981
18982.. _int_vp_fdiv:
18983
18984'``llvm.vp.fdiv.*``' Intrinsics
18985^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18986
18987Syntax:
18988"""""""
18989This is an overloaded intrinsic.
18990
18991::
18992
18993      declare <16 x float>  @llvm.vp.fdiv.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
18994      declare <vscale x 4 x float>  @llvm.vp.fdiv.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
18995      declare <256 x double>  @llvm.vp.fdiv.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
18996
18997Overview:
18998"""""""""
18999
19000Predicated floating-point division of two vectors of floating-point values.
19001
19002
19003Arguments:
19004""""""""""
19005
19006The first two operands and the result have the same vector of floating-point type. The
19007third operand is the vector mask and has the same number of elements as the
19008result vector type. The fourth operand is the explicit vector length of the
19009operation.
19010
19011Semantics:
19012""""""""""
19013
19014The '``llvm.vp.fdiv``' intrinsic performs floating-point division (:ref:`fdiv <i_fdiv>`)
19015of the first and second vector operand on each enabled lane.  The result on
19016disabled lanes is undefined.  The operation is performed in the default
19017floating-point environment.
19018
19019Examples:
19020"""""""""
19021
19022.. code-block:: llvm
19023
19024      %r = call <4 x float> @llvm.vp.fdiv.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
19025      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19026
19027      %t = fdiv <4 x float> %a, %b
19028      %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
19029
19030
19031.. _int_vp_frem:
19032
19033'``llvm.vp.frem.*``' Intrinsics
19034^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19035
19036Syntax:
19037"""""""
19038This is an overloaded intrinsic.
19039
19040::
19041
19042      declare <16 x float>  @llvm.vp.frem.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
19043      declare <vscale x 4 x float>  @llvm.vp.frem.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
19044      declare <256 x double>  @llvm.vp.frem.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
19045
19046Overview:
19047"""""""""
19048
19049Predicated floating-point remainder of two vectors of floating-point values.
19050
19051
19052Arguments:
19053""""""""""
19054
19055The first two operands and the result have the same vector of floating-point type. The
19056third operand is the vector mask and has the same number of elements as the
19057result vector type. The fourth operand is the explicit vector length of the
19058operation.
19059
19060Semantics:
19061""""""""""
19062
19063The '``llvm.vp.frem``' intrinsic performs floating-point remainder (:ref:`frem <i_frem>`)
19064of the first and second vector operand on each enabled lane.  The result on
19065disabled lanes is undefined.  The operation is performed in the default
19066floating-point environment.
19067
19068Examples:
19069"""""""""
19070
19071.. code-block:: llvm
19072
19073      %r = call <4 x float> @llvm.vp.frem.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
19074      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19075
19076      %t = frem <4 x float> %a, %b
19077      %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
19078
19079
19080.. _int_vp_fneg:
19081
19082'``llvm.vp.fneg.*``' Intrinsics
19083^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19084
19085Syntax:
19086"""""""
19087This is an overloaded intrinsic.
19088
19089::
19090
19091      declare <16 x float>  @llvm.vp.fneg.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
19092      declare <vscale x 4 x float>  @llvm.vp.fneg.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
19093      declare <256 x double>  @llvm.vp.fneg.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
19094
19095Overview:
19096"""""""""
19097
19098Predicated floating-point negation of a vector of floating-point values.
19099
19100
19101Arguments:
19102""""""""""
19103
19104The first operand and the result have the same vector of floating-point type.
19105The second operand is the vector mask and has the same number of elements as the
19106result vector type. The third operand is the explicit vector length of the
19107operation.
19108
19109Semantics:
19110""""""""""
19111
19112The '``llvm.vp.fneg``' intrinsic performs floating-point negation (:ref:`fneg <i_fneg>`)
19113of the first vector operand on each enabled lane.  The result on disabled lanes
19114is undefined.
19115
19116Examples:
19117"""""""""
19118
19119.. code-block:: llvm
19120
19121      %r = call <4 x float> @llvm.vp.fneg.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
19122      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19123
19124      %t = fneg <4 x float> %a
19125      %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
19126
19127
19128.. _int_vp_fma:
19129
19130'``llvm.vp.fma.*``' Intrinsics
19131^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19132
19133Syntax:
19134"""""""
19135This is an overloaded intrinsic.
19136
19137::
19138
19139      declare <16 x float>  @llvm.vp.fma.v16f32 (<16 x float> <left_op>, <16 x float> <middle_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
19140      declare <vscale x 4 x float>  @llvm.vp.fma.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <middle_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
19141      declare <256 x double>  @llvm.vp.fma.v256f64 (<256 x double> <left_op>, <256 x double> <middle_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
19142
19143Overview:
19144"""""""""
19145
19146Predicated floating-point fused multiply-add of two vectors of floating-point values.
19147
19148
19149Arguments:
19150""""""""""
19151
19152The first three operands and the result have the same vector of floating-point type. The
19153fourth operand is the vector mask and has the same number of elements as the
19154result vector type. The fifth operand is the explicit vector length of the
19155operation.
19156
19157Semantics:
19158""""""""""
19159
19160The '``llvm.vp.fma``' intrinsic performs floating-point fused multiply-add (:ref:`llvm.fma <int_fma>`)
19161of the first, second, and third vector operand on each enabled lane.  The result on
19162disabled lanes is undefined.  The operation is performed in the default
19163floating-point environment.
19164
19165Examples:
19166"""""""""
19167
19168.. code-block:: llvm
19169
19170      %r = call <4 x float> @llvm.vp.fma.v4f32(<4 x float> %a, <4 x float> %b, <4 x float> %c, <4 x i1> %mask, i32 %evl)
19171      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19172
19173      %t = call <4 x float> @llvm.fma(<4 x float> %a, <4 x float> %b, <4 x float> %c)
19174      %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
19175
19176
19177.. _int_vp_reduce_add:
19178
19179'``llvm.vp.reduce.add.*``' Intrinsics
19180^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19181
19182Syntax:
19183"""""""
19184This is an overloaded intrinsic.
19185
19186::
19187
19188      declare i32 @llvm.vp.reduce.add.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19189      declare i16 @llvm.vp.reduce.add.nxv8i16(i16 <start_value>, <vscale x 8 x i16> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19190
19191Overview:
19192"""""""""
19193
19194Predicated integer ``ADD`` reduction of a vector and a scalar starting value,
19195returning the result as a scalar.
19196
19197Arguments:
19198""""""""""
19199
19200The first operand is the start value of the reduction, which must be a scalar
19201integer type equal to the result type. The second operand is the vector on
19202which the reduction is performed and must be a vector of integer values whose
19203element type is the result/start type. The third operand is the vector mask and
19204is a vector of boolean values with the same number of elements as the vector
19205operand. The fourth operand is the explicit vector length of the operation.
19206
19207Semantics:
19208""""""""""
19209
19210The '``llvm.vp.reduce.add``' intrinsic performs the integer ``ADD`` reduction
19211(:ref:`llvm.vector.reduce.add <int_vector_reduce_add>`) of the vector operand
19212``val`` on each enabled lane, adding it to the scalar ``start_value``. Disabled
19213lanes are treated as containing the neutral value ``0`` (i.e. having no effect
19214on the reduction operation). If the vector length is zero, the result is equal
19215to ``start_value``.
19216
19217To ignore the start value, the neutral value can be used.
19218
19219Examples:
19220"""""""""
19221
19222.. code-block:: llvm
19223
19224      %r = call i32 @llvm.vp.reduce.add.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19225      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19226      ; are treated as though %mask were false for those lanes.
19227
19228      %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> zeroinitializer
19229      %reduction = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %masked.a)
19230      %also.r = add i32 %reduction, %start
19231
19232
19233.. _int_vp_reduce_fadd:
19234
19235'``llvm.vp.reduce.fadd.*``' Intrinsics
19236^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19237
19238Syntax:
19239"""""""
19240This is an overloaded intrinsic.
19241
19242::
19243
19244      declare float @llvm.vp.reduce.fadd.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>)
19245      declare double @llvm.vp.reduce.fadd.nxv8f64(double <start_value>, <vscale x 8 x double> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19246
19247Overview:
19248"""""""""
19249
19250Predicated floating-point ``ADD`` reduction of a vector and a scalar starting
19251value, returning the result as a scalar.
19252
19253Arguments:
19254""""""""""
19255
19256The first operand is the start value of the reduction, which must be a scalar
19257floating-point type equal to the result type. The second operand is the vector
19258on which the reduction is performed and must be a vector of floating-point
19259values whose element type is the result/start type. The third operand is the
19260vector mask and is a vector of boolean values with the same number of elements
19261as the vector operand. The fourth operand is the explicit vector length of the
19262operation.
19263
19264Semantics:
19265""""""""""
19266
19267The '``llvm.vp.reduce.fadd``' intrinsic performs the floating-point ``ADD``
19268reduction (:ref:`llvm.vector.reduce.fadd <int_vector_reduce_fadd>`) of the
19269vector operand ``val`` on each enabled lane, adding it to the scalar
19270``start_value``. Disabled lanes are treated as containing the neutral value
19271``-0.0`` (i.e. having no effect on the reduction operation). If no lanes are
19272enabled, the resulting value will be equal to ``start_value``.
19273
19274To ignore the start value, the neutral value can be used.
19275
19276See the unpredicated version (:ref:`llvm.vector.reduce.fadd
19277<int_vector_reduce_fadd>`) for more detail on the semantics of the reduction.
19278
19279Examples:
19280"""""""""
19281
19282.. code-block:: llvm
19283
19284      %r = call float @llvm.vp.reduce.fadd.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
19285      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19286      ; are treated as though %mask were false for those lanes.
19287
19288      %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>
19289      %also.r = call float @llvm.vector.reduce.fadd.v4f32(float %start, <4 x float> %masked.a)
19290
19291
19292.. _int_vp_reduce_mul:
19293
19294'``llvm.vp.reduce.mul.*``' Intrinsics
19295^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19296
19297Syntax:
19298"""""""
19299This is an overloaded intrinsic.
19300
19301::
19302
19303      declare i32 @llvm.vp.reduce.mul.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19304      declare i16 @llvm.vp.reduce.mul.nxv8i16(i16 <start_value>, <vscale x 8 x i16> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19305
19306Overview:
19307"""""""""
19308
19309Predicated integer ``MUL`` reduction of a vector and a scalar starting value,
19310returning the result as a scalar.
19311
19312
19313Arguments:
19314""""""""""
19315
19316The first operand is the start value of the reduction, which must be a scalar
19317integer type equal to the result type. The second operand is the vector on
19318which the reduction is performed and must be a vector of integer values whose
19319element type is the result/start type. The third operand is the vector mask and
19320is a vector of boolean values with the same number of elements as the vector
19321operand. The fourth operand is the explicit vector length of the operation.
19322
19323Semantics:
19324""""""""""
19325
19326The '``llvm.vp.reduce.mul``' intrinsic performs the integer ``MUL`` reduction
19327(:ref:`llvm.vector.reduce.mul <int_vector_reduce_mul>`) of the vector operand ``val``
19328on each enabled lane, multiplying it by the scalar ``start_value``. Disabled
19329lanes are treated as containing the neutral value ``1`` (i.e. having no effect
19330on the reduction operation). If the vector length is zero, the result is the
19331start value.
19332
19333To ignore the start value, the neutral value can be used.
19334
19335Examples:
19336"""""""""
19337
19338.. code-block:: llvm
19339
19340      %r = call i32 @llvm.vp.reduce.mul.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19341      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19342      ; are treated as though %mask were false for those lanes.
19343
19344      %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
19345      %reduction = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %masked.a)
19346      %also.r = mul i32 %reduction, %start
19347
19348.. _int_vp_reduce_fmul:
19349
19350'``llvm.vp.reduce.fmul.*``' Intrinsics
19351^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19352
19353Syntax:
19354"""""""
19355This is an overloaded intrinsic.
19356
19357::
19358
19359      declare float @llvm.vp.reduce.fmul.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>)
19360      declare double @llvm.vp.reduce.fmul.nxv8f64(double <start_value>, <vscale x 8 x double> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19361
19362Overview:
19363"""""""""
19364
19365Predicated floating-point ``MUL`` reduction of a vector and a scalar starting
19366value, returning the result as a scalar.
19367
19368
19369Arguments:
19370""""""""""
19371
19372The first operand is the start value of the reduction, which must be a scalar
19373floating-point type equal to the result type. The second operand is the vector
19374on which the reduction is performed and must be a vector of floating-point
19375values whose element type is the result/start type. The third operand is the
19376vector mask and is a vector of boolean values with the same number of elements
19377as the vector operand. The fourth operand is the explicit vector length of the
19378operation.
19379
19380Semantics:
19381""""""""""
19382
19383The '``llvm.vp.reduce.fmul``' intrinsic performs the floating-point ``MUL``
19384reduction (:ref:`llvm.vector.reduce.fmul <int_vector_reduce_fmul>`) of the
19385vector operand ``val`` on each enabled lane, multiplying it by the scalar
19386`start_value``. Disabled lanes are treated as containing the neutral value
19387``1.0`` (i.e. having no effect on the reduction operation). If no lanes are
19388enabled, the resulting value will be equal to the starting value.
19389
19390To ignore the start value, the neutral value can be used.
19391
19392See the unpredicated version (:ref:`llvm.vector.reduce.fmul
19393<int_vector_reduce_fmul>`) for more detail on the semantics.
19394
19395Examples:
19396"""""""""
19397
19398.. code-block:: llvm
19399
19400      %r = call float @llvm.vp.reduce.fmul.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
19401      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19402      ; are treated as though %mask were false for those lanes.
19403
19404      %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float 1.0, float 1.0, float 1.0, float 1.0>
19405      %also.r = call float @llvm.vector.reduce.fmul.v4f32(float %start, <4 x float> %masked.a)
19406
19407
19408.. _int_vp_reduce_and:
19409
19410'``llvm.vp.reduce.and.*``' Intrinsics
19411^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19412
19413Syntax:
19414"""""""
19415This is an overloaded intrinsic.
19416
19417::
19418
19419      declare i32 @llvm.vp.reduce.and.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19420      declare i16 @llvm.vp.reduce.and.nxv8i16(i16 <start_value>, <vscale x 8 x i16> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19421
19422Overview:
19423"""""""""
19424
19425Predicated integer ``AND`` reduction of a vector and a scalar starting value,
19426returning the result as a scalar.
19427
19428
19429Arguments:
19430""""""""""
19431
19432The first operand is the start value of the reduction, which must be a scalar
19433integer type equal to the result type. The second operand is the vector on
19434which the reduction is performed and must be a vector of integer values whose
19435element type is the result/start type. The third operand is the vector mask and
19436is a vector of boolean values with the same number of elements as the vector
19437operand. The fourth operand is the explicit vector length of the operation.
19438
19439Semantics:
19440""""""""""
19441
19442The '``llvm.vp.reduce.and``' intrinsic performs the integer ``AND`` reduction
19443(:ref:`llvm.vector.reduce.and <int_vector_reduce_and>`) of the vector operand
19444``val`` on each enabled lane, performing an '``and``' of that with with the
19445scalar ``start_value``. Disabled lanes are treated as containing the neutral
19446value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction
19447operation). If the vector length is zero, the result is the start value.
19448
19449To ignore the start value, the neutral value can be used.
19450
19451Examples:
19452"""""""""
19453
19454.. code-block:: llvm
19455
19456      %r = call i32 @llvm.vp.reduce.and.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19457      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19458      ; are treated as though %mask were false for those lanes.
19459
19460      %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
19461      %reduction = call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %masked.a)
19462      %also.r = and i32 %reduction, %start
19463
19464
19465.. _int_vp_reduce_or:
19466
19467'``llvm.vp.reduce.or.*``' Intrinsics
19468^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19469
19470Syntax:
19471"""""""
19472This is an overloaded intrinsic.
19473
19474::
19475
19476      declare i32 @llvm.vp.reduce.or.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19477      declare i16 @llvm.vp.reduce.or.nxv8i16(i16 <start_value>, <vscale x 8 x i16> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19478
19479Overview:
19480"""""""""
19481
19482Predicated integer ``OR`` reduction of a vector and a scalar starting value,
19483returning the result as a scalar.
19484
19485
19486Arguments:
19487""""""""""
19488
19489The first operand is the start value of the reduction, which must be a scalar
19490integer type equal to the result type. The second operand is the vector on
19491which the reduction is performed and must be a vector of integer values whose
19492element type is the result/start type. The third operand is the vector mask and
19493is a vector of boolean values with the same number of elements as the vector
19494operand. The fourth operand is the explicit vector length of the operation.
19495
19496Semantics:
19497""""""""""
19498
19499The '``llvm.vp.reduce.or``' intrinsic performs the integer ``OR`` reduction
19500(:ref:`llvm.vector.reduce.or <int_vector_reduce_or>`) of the vector operand
19501``val`` on each enabled lane, performing an '``or``' of that with the scalar
19502``start_value``. Disabled lanes are treated as containing the neutral value
19503``0`` (i.e. having no effect on the reduction operation). If the vector length
19504is zero, the result is the start value.
19505
19506To ignore the start value, the neutral value can be used.
19507
19508Examples:
19509"""""""""
19510
19511.. code-block:: llvm
19512
19513      %r = call i32 @llvm.vp.reduce.or.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19514      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19515      ; are treated as though %mask were false for those lanes.
19516
19517      %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
19518      %reduction = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %masked.a)
19519      %also.r = or i32 %reduction, %start
19520
19521.. _int_vp_reduce_xor:
19522
19523'``llvm.vp.reduce.xor.*``' Intrinsics
19524^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19525
19526Syntax:
19527"""""""
19528This is an overloaded intrinsic.
19529
19530::
19531
19532      declare i32 @llvm.vp.reduce.xor.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19533      declare i16 @llvm.vp.reduce.xor.nxv8i16(i16 <start_value>, <vscale x 8 x i16> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19534
19535Overview:
19536"""""""""
19537
19538Predicated integer ``XOR`` reduction of a vector and a scalar starting value,
19539returning the result as a scalar.
19540
19541
19542Arguments:
19543""""""""""
19544
19545The first operand is the start value of the reduction, which must be a scalar
19546integer type equal to the result type. The second operand is the vector on
19547which the reduction is performed and must be a vector of integer values whose
19548element type is the result/start type. The third operand is the vector mask and
19549is a vector of boolean values with the same number of elements as the vector
19550operand. The fourth operand is the explicit vector length of the operation.
19551
19552Semantics:
19553""""""""""
19554
19555The '``llvm.vp.reduce.xor``' intrinsic performs the integer ``XOR`` reduction
19556(:ref:`llvm.vector.reduce.xor <int_vector_reduce_xor>`) of the vector operand
19557``val`` on each enabled lane, performing an '``xor``' of that with the scalar
19558``start_value``. Disabled lanes are treated as containing the neutral value
19559``0`` (i.e. having no effect on the reduction operation). If the vector length
19560is zero, the result is the start value.
19561
19562To ignore the start value, the neutral value can be used.
19563
19564Examples:
19565"""""""""
19566
19567.. code-block:: llvm
19568
19569      %r = call i32 @llvm.vp.reduce.xor.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19570      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19571      ; are treated as though %mask were false for those lanes.
19572
19573      %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
19574      %reduction = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %masked.a)
19575      %also.r = xor i32 %reduction, %start
19576
19577
19578.. _int_vp_reduce_smax:
19579
19580'``llvm.vp.reduce.smax.*``' Intrinsics
19581^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19582
19583Syntax:
19584"""""""
19585This is an overloaded intrinsic.
19586
19587::
19588
19589      declare i32 @llvm.vp.reduce.smax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19590      declare i16 @llvm.vp.reduce.smax.nxv8i16(i16 <start_value>, <vscale x 8 x i16> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19591
19592Overview:
19593"""""""""
19594
19595Predicated signed-integer ``MAX`` reduction of a vector and a scalar starting
19596value, returning the result as a scalar.
19597
19598
19599Arguments:
19600""""""""""
19601
19602The first operand is the start value of the reduction, which must be a scalar
19603integer type equal to the result type. The second operand is the vector on
19604which the reduction is performed and must be a vector of integer values whose
19605element type is the result/start type. The third operand is the vector mask and
19606is a vector of boolean values with the same number of elements as the vector
19607operand. The fourth operand is the explicit vector length of the operation.
19608
19609Semantics:
19610""""""""""
19611
19612The '``llvm.vp.reduce.smax``' intrinsic performs the signed-integer ``MAX``
19613reduction (:ref:`llvm.vector.reduce.smax <int_vector_reduce_smax>`) of the
19614vector operand ``val`` on each enabled lane, and taking the maximum of that and
19615the scalar ``start_value``. Disabled lanes are treated as containing the
19616neutral value ``INT_MIN`` (i.e. having no effect on the reduction operation).
19617If the vector length is zero, the result is the start value.
19618
19619To ignore the start value, the neutral value can be used.
19620
19621Examples:
19622"""""""""
19623
19624.. code-block:: llvm
19625
19626      %r = call i8 @llvm.vp.reduce.smax.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl)
19627      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19628      ; are treated as though %mask were false for those lanes.
19629
19630      %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 -128, i8 -128, i8 -128, i8 -128>
19631      %reduction = call i8 @llvm.vector.reduce.smax.v4i8(<4 x i8> %masked.a)
19632      %also.r = call i8 @llvm.smax.i8(i8 %reduction, i8 %start)
19633
19634
19635.. _int_vp_reduce_smin:
19636
19637'``llvm.vp.reduce.smin.*``' Intrinsics
19638^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19639
19640Syntax:
19641"""""""
19642This is an overloaded intrinsic.
19643
19644::
19645
19646      declare i32 @llvm.vp.reduce.smin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19647      declare i16 @llvm.vp.reduce.smin.nxv8i16(i16 <start_value>, <vscale x 8 x i16> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19648
19649Overview:
19650"""""""""
19651
19652Predicated signed-integer ``MIN`` reduction of a vector and a scalar starting
19653value, returning the result as a scalar.
19654
19655
19656Arguments:
19657""""""""""
19658
19659The first operand is the start value of the reduction, which must be a scalar
19660integer type equal to the result type. The second operand is the vector on
19661which the reduction is performed and must be a vector of integer values whose
19662element type is the result/start type. The third operand is the vector mask and
19663is a vector of boolean values with the same number of elements as the vector
19664operand. The fourth operand is the explicit vector length of the operation.
19665
19666Semantics:
19667""""""""""
19668
19669The '``llvm.vp.reduce.smin``' intrinsic performs the signed-integer ``MIN``
19670reduction (:ref:`llvm.vector.reduce.smin <int_vector_reduce_smin>`) of the
19671vector operand ``val`` on each enabled lane, and taking the minimum of that and
19672the scalar ``start_value``. Disabled lanes are treated as containing the
19673neutral value ``INT_MAX`` (i.e. having no effect on the reduction operation).
19674If the vector length is zero, the result is the start value.
19675
19676To ignore the start value, the neutral value can be used.
19677
19678Examples:
19679"""""""""
19680
19681.. code-block:: llvm
19682
19683      %r = call i8 @llvm.vp.reduce.smin.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl)
19684      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19685      ; are treated as though %mask were false for those lanes.
19686
19687      %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 127, i8 127, i8 127, i8 127>
19688      %reduction = call i8 @llvm.vector.reduce.smin.v4i8(<4 x i8> %masked.a)
19689      %also.r = call i8 @llvm.smin.i8(i8 %reduction, i8 %start)
19690
19691
19692.. _int_vp_reduce_umax:
19693
19694'``llvm.vp.reduce.umax.*``' Intrinsics
19695^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19696
19697Syntax:
19698"""""""
19699This is an overloaded intrinsic.
19700
19701::
19702
19703      declare i32 @llvm.vp.reduce.umax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19704      declare i16 @llvm.vp.reduce.umax.nxv8i16(i16 <start_value>, <vscale x 8 x i16> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19705
19706Overview:
19707"""""""""
19708
19709Predicated unsigned-integer ``MAX`` reduction of a vector and a scalar starting
19710value, returning the result as a scalar.
19711
19712
19713Arguments:
19714""""""""""
19715
19716The first operand is the start value of the reduction, which must be a scalar
19717integer type equal to the result type. The second operand is the vector on
19718which the reduction is performed and must be a vector of integer values whose
19719element type is the result/start type. The third operand is the vector mask and
19720is a vector of boolean values with the same number of elements as the vector
19721operand. The fourth operand is the explicit vector length of the operation.
19722
19723Semantics:
19724""""""""""
19725
19726The '``llvm.vp.reduce.umax``' intrinsic performs the unsigned-integer ``MAX``
19727reduction (:ref:`llvm.vector.reduce.umax <int_vector_reduce_umax>`) of the
19728vector operand ``val`` on each enabled lane, and taking the maximum of that and
19729the scalar ``start_value``. Disabled lanes are treated as containing the
19730neutral value ``0`` (i.e. having no effect on the reduction operation). If the
19731vector length is zero, the result is the start value.
19732
19733To ignore the start value, the neutral value can be used.
19734
19735Examples:
19736"""""""""
19737
19738.. code-block:: llvm
19739
19740      %r = call i32 @llvm.vp.reduce.umax.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19741      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19742      ; are treated as though %mask were false for those lanes.
19743
19744      %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
19745      %reduction = call i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %masked.a)
19746      %also.r = call i32 @llvm.umax.i32(i32 %reduction, i32 %start)
19747
19748
19749.. _int_vp_reduce_umin:
19750
19751'``llvm.vp.reduce.umin.*``' Intrinsics
19752^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19753
19754Syntax:
19755"""""""
19756This is an overloaded intrinsic.
19757
19758::
19759
19760      declare i32 @llvm.vp.reduce.umin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19761      declare i16 @llvm.vp.reduce.umin.nxv8i16(i16 <start_value>, <vscale x 8 x i16> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19762
19763Overview:
19764"""""""""
19765
19766Predicated unsigned-integer ``MIN`` reduction of a vector and a scalar starting
19767value, returning the result as a scalar.
19768
19769
19770Arguments:
19771""""""""""
19772
19773The first operand is the start value of the reduction, which must be a scalar
19774integer type equal to the result type. The second operand is the vector on
19775which the reduction is performed and must be a vector of integer values whose
19776element type is the result/start type. The third operand is the vector mask and
19777is a vector of boolean values with the same number of elements as the vector
19778operand. The fourth operand is the explicit vector length of the operation.
19779
19780Semantics:
19781""""""""""
19782
19783The '``llvm.vp.reduce.umin``' intrinsic performs the unsigned-integer ``MIN``
19784reduction (:ref:`llvm.vector.reduce.umin <int_vector_reduce_umin>`) of the
19785vector operand ``val`` on each enabled lane, taking the minimum of that and the
19786scalar ``start_value``. Disabled lanes are treated as containing the neutral
19787value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction
19788operation). If the vector length is zero, the result is the start value.
19789
19790To ignore the start value, the neutral value can be used.
19791
19792Examples:
19793"""""""""
19794
19795.. code-block:: llvm
19796
19797      %r = call i32 @llvm.vp.reduce.umin.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19798      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19799      ; are treated as though %mask were false for those lanes.
19800
19801      %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
19802      %reduction = call i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %masked.a)
19803      %also.r = call i32 @llvm.umin.i32(i32 %reduction, i32 %start)
19804
19805
19806.. _int_vp_reduce_fmax:
19807
19808'``llvm.vp.reduce.fmax.*``' Intrinsics
19809^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19810
19811Syntax:
19812"""""""
19813This is an overloaded intrinsic.
19814
19815::
19816
19817      declare float @llvm.vp.reduce.fmax.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>)
19818      declare double @llvm.vp.reduce.fmax.nxv8f64(double <start_value>, <vscale x 8 x double> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19819
19820Overview:
19821"""""""""
19822
19823Predicated floating-point ``MAX`` reduction of a vector and a scalar starting
19824value, returning the result as a scalar.
19825
19826
19827Arguments:
19828""""""""""
19829
19830The first operand is the start value of the reduction, which must be a scalar
19831floating-point type equal to the result type. The second operand is the vector
19832on which the reduction is performed and must be a vector of floating-point
19833values whose element type is the result/start type. The third operand is the
19834vector mask and is a vector of boolean values with the same number of elements
19835as the vector operand. The fourth operand is the explicit vector length of the
19836operation.
19837
19838Semantics:
19839""""""""""
19840
19841The '``llvm.vp.reduce.fmax``' intrinsic performs the floating-point ``MAX``
19842reduction (:ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>`) of the
19843vector operand ``val`` on each enabled lane, taking the maximum of that and the
19844scalar ``start_value``. Disabled lanes are treated as containing the neutral
19845value (i.e. having no effect on the reduction operation). If the vector length
19846is zero, the result is the start value.
19847
19848The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
19849flags are set, the neutral value is ``-QNAN``. If ``nnan``  and ``ninf`` are
19850both set, then the neutral value is the smallest floating-point value for the
19851result type. If only ``nnan`` is set then the neutral value is ``-Infinity``.
19852
19853This instruction has the same comparison semantics as the
19854:ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>` intrinsic (and thus the
19855'``llvm.maxnum.*``' intrinsic). That is, the result will always be a number
19856unless all elements of the vector and the starting value are ``NaN``. For a
19857vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and
19858``-0.0`` elements, the sign of the result is unspecified.
19859
19860To ignore the start value, the neutral value can be used.
19861
19862Examples:
19863"""""""""
19864
19865.. code-block:: llvm
19866
19867      %r = call float @llvm.vp.reduce.fmax.v4f32(float %float, <4 x float> %a, <4 x i1> %mask, i32 %evl)
19868      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19869      ; are treated as though %mask were false for those lanes.
19870
19871      %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN>
19872      %reduction = call float @llvm.vector.reduce.fmax.v4f32(<4 x float> %masked.a)
19873      %also.r = call float @llvm.maxnum.f32(float %reduction, float %start)
19874
19875
19876.. _int_vp_reduce_fmin:
19877
19878'``llvm.vp.reduce.fmin.*``' Intrinsics
19879^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19880
19881Syntax:
19882"""""""
19883This is an overloaded intrinsic.
19884
19885::
19886
19887      declare float @llvm.vp.reduce.fmin.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>)
19888      declare double @llvm.vp.reduce.fmin.nxv8f64(double <start_value>, <vscale x 8 x double> <val>, <vscale x 8 x i1> <mask>, i32 <vector_length>)
19889
19890Overview:
19891"""""""""
19892
19893Predicated floating-point ``MIN`` reduction of a vector and a scalar starting
19894value, returning the result as a scalar.
19895
19896
19897Arguments:
19898""""""""""
19899
19900The first operand is the start value of the reduction, which must be a scalar
19901floating-point type equal to the result type. The second operand is the vector
19902on which the reduction is performed and must be a vector of floating-point
19903values whose element type is the result/start type. The third operand is the
19904vector mask and is a vector of boolean values with the same number of elements
19905as the vector operand. The fourth operand is the explicit vector length of the
19906operation.
19907
19908Semantics:
19909""""""""""
19910
19911The '``llvm.vp.reduce.fmin``' intrinsic performs the floating-point ``MIN``
19912reduction (:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>`) of the
19913vector operand ``val`` on each enabled lane, taking the minimum of that and the
19914scalar ``start_value``. Disabled lanes are treated as containing the neutral
19915value (i.e. having no effect on the reduction operation). If the vector length
19916is zero, the result is the start value.
19917
19918The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
19919flags are set, the neutral value is ``+QNAN``. If ``nnan``  and ``ninf`` are
19920both set, then the neutral value is the largest floating-point value for the
19921result type. If only ``nnan`` is set then the neutral value is ``+Infinity``.
19922
19923This instruction has the same comparison semantics as the
19924:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>` intrinsic (and thus the
19925'``llvm.minnum.*``' intrinsic). That is, the result will always be a number
19926unless all elements of the vector and the starting value are ``NaN``. For a
19927vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and
19928``-0.0`` elements, the sign of the result is unspecified.
19929
19930To ignore the start value, the neutral value can be used.
19931
19932Examples:
19933"""""""""
19934
19935.. code-block:: llvm
19936
19937      %r = call float @llvm.vp.reduce.fmin.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
19938      ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19939      ; are treated as though %mask were false for those lanes.
19940
19941      %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN>
19942      %reduction = call float @llvm.vector.reduce.fmin.v4f32(<4 x float> %masked.a)
19943      %also.r = call float @llvm.minnum.f32(float %reduction, float %start)
19944
19945
19946.. _int_get_active_lane_mask:
19947
19948'``llvm.get.active.lane.mask.*``' Intrinsics
19949^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19950
19951Syntax:
19952"""""""
19953This is an overloaded intrinsic.
19954
19955::
19956
19957      declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %base, i32 %n)
19958      declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 %base, i64 %n)
19959      declare <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 %base, i64 %n)
19960      declare <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 %base, i64 %n)
19961
19962
19963Overview:
19964"""""""""
19965
19966Create a mask representing active and inactive vector lanes.
19967
19968
19969Arguments:
19970""""""""""
19971
19972Both operands have the same scalar integer type. The result is a vector with
19973the i1 element type.
19974
19975Semantics:
19976""""""""""
19977
19978The '``llvm.get.active.lane.mask.*``' intrinsics are semantically equivalent
19979to:
19980
19981::
19982
19983      %m[i] = icmp ult (%base + i), %n
19984
19985where ``%m`` is a vector (mask) of active/inactive lanes with its elements
19986indexed by ``i``,  and ``%base``, ``%n`` are the two arguments to
19987``llvm.get.active.lane.mask.*``, ``%icmp`` is an integer compare and ``ult``
19988the unsigned less-than comparison operator.  Overflow cannot occur in
19989``(%base + i)`` and its comparison against ``%n`` as it is performed in integer
19990numbers and not in machine numbers.  If ``%n`` is ``0``, then the result is a
19991poison value. The above is equivalent to:
19992
19993::
19994
19995      %m = @llvm.get.active.lane.mask(%base, %n)
19996
19997This can, for example, be emitted by the loop vectorizer in which case
19998``%base`` is the first element of the vector induction variable (VIV) and
19999``%n`` is the loop tripcount. Thus, these intrinsics perform an element-wise
20000less than comparison of VIV with the loop tripcount, producing a mask of
20001true/false values representing active/inactive vector lanes, except if the VIV
20002overflows in which case they return false in the lanes where the VIV overflows.
20003The arguments are scalar types to accommodate scalable vector types, for which
20004it is unknown what the type of the step vector needs to be that enumerate its
20005lanes without overflow.
20006
20007This mask ``%m`` can e.g. be used in masked load/store instructions. These
20008intrinsics provide a hint to the backend. I.e., for a vector loop, the
20009back-edge taken count of the original scalar loop is explicit as the second
20010argument.
20011
20012
20013Examples:
20014"""""""""
20015
20016.. code-block:: llvm
20017
20018      %active.lane.mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 %elem0, i64 429)
20019      %wide.masked.load = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %3, i32 4, <4 x i1> %active.lane.mask, <4 x i32> undef)
20020
20021
20022.. _int_experimental_vp_splice:
20023
20024'``llvm.experimental.vp.splice``' Intrinsic
20025^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20026
20027Syntax:
20028"""""""
20029This is an overloaded intrinsic.
20030
20031::
20032
20033      declare <2 x double> @llvm.experimental.vp.splice.v2f64(<2 x double> %vec1, <2 x double> %vec2, i32 %imm, <2 x i1> %mask, i32 %evl1, i32 %evl2)
20034      declare <vscale x 4 x i32> @llvm.experimental.vp.splice.nxv4i32(<vscale x 4 x i32> %vec1, <vscale x 4 x i32> %vec2, i32 %imm, <vscale x 4 x i1> %mask, i32 %evl1, i32 %evl2)
20035
20036Overview:
20037"""""""""
20038
20039The '``llvm.experimental.vp.splice.*``' intrinsic is the vector length
20040predicated version of the '``llvm.experimental.vector.splice.*``' intrinsic.
20041
20042Arguments:
20043""""""""""
20044
20045The result and the first two arguments ``vec1`` and ``vec2`` are vectors with
20046the same type.  The third argument ``imm`` is an immediate signed integer that
20047indicates the offset index.  The fourth argument ``mask`` is a vector mask and
20048has the same number of elements as the result.  The last two arguments ``evl1``
20049and ``evl2`` are unsigned integers indicating the explicit vector lengths of
20050``vec1`` and ``vec2`` respectively.  ``imm``, ``evl1`` and ``evl2`` should
20051respect the following constraints: ``-evl1 <= imm < evl1``, ``0 <= evl1 <= VL``
20052and ``0 <= evl2 <= VL``, where ``VL`` is the runtime vector factor. If these
20053constraints are not satisfied the intrinsic has undefined behaviour.
20054
20055Semantics:
20056""""""""""
20057
20058Effectively, this intrinsic concatenates ``vec1[0..evl1-1]`` and
20059``vec2[0..evl2-1]`` and creates the result vector by selecting the elements in a
20060window of size ``evl2``, starting at index ``imm`` (for a positive immediate) of
20061the concatenated vector. Elements in the result vector beyond ``evl2`` are
20062``undef``.  If ``imm`` is negative the starting index is ``evl1 + imm``.  The result
20063vector of active vector length ``evl2`` contains ``evl1 - imm`` (``-imm`` for
20064negative ``imm``) elements from indices ``[imm..evl1 - 1]``
20065(``[evl1 + imm..evl1 -1]`` for negative ``imm``) of ``vec1`` followed by the
20066first ``evl2 - (evl1 - imm)`` (``evl2 + imm`` for negative ``imm``) elements of
20067``vec2``. If ``evl1 - imm`` (``-imm``) >= ``evl2``, only the first ``evl2``
20068elements are considered and the remaining are ``undef``.  The lanes in the result
20069vector disabled by ``mask`` are ``undef``.
20070
20071Examples:
20072"""""""""
20073
20074.. code-block:: text
20075
20076 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, 1, 2, 3)  ==> <B, E, F, undef> ; index
20077 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, -2, 3, 2) ==> <B, C, undef, undef> ; trailing elements
20078
20079
20080.. _int_vp_load:
20081
20082'``llvm.vp.load``' Intrinsic
20083^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20084
20085Syntax:
20086"""""""
20087This is an overloaded intrinsic.
20088
20089::
20090
20091    declare <4 x float> @llvm.vp.load.v4f32.p0v4f32(<4 x float>* %ptr, <4 x i1> %mask, i32 %evl)
20092    declare <vscale x 2 x i16> @llvm.vp.load.nxv2i16.p0nxv2i16(<vscale x 2 x i16>* %ptr, <vscale x 2 x i1> %mask, i32 %evl)
20093    declare <8 x float> @llvm.vp.load.v8f32.p1v8f32(<8 x float> addrspace(1)* %ptr, <8 x i1> %mask, i32 %evl)
20094    declare <vscale x 1 x i64> @llvm.vp.load.nxv1i64.p6nxv1i64(<vscale x 1 x i64> addrspace(6)* %ptr, <vscale x 1 x i1> %mask, i32 %evl)
20095
20096Overview:
20097"""""""""
20098
20099The '``llvm.vp.load.*``' intrinsic is the vector length predicated version of
20100the :ref:`llvm.masked.load <int_mload>` intrinsic.
20101
20102Arguments:
20103""""""""""
20104
20105The first operand is the base pointer for the load. The second operand is a
20106vector of boolean values with the same number of elements as the return type.
20107The third is the explicit vector length of the operation. The return type and
20108underlying type of the base pointer are the same vector types.
20109
20110The :ref:`align <attr_align>` parameter attribute can be provided for the first
20111operand.
20112
20113Semantics:
20114""""""""""
20115
20116The '``llvm.vp.load``' intrinsic reads a vector from memory in the same way as
20117the '``llvm.masked.load``' intrinsic, where the mask is taken from the
20118combination of the '``mask``' and '``evl``' operands in the usual VP way.
20119Certain '``llvm.masked.load``' operands do not have corresponding operands in
20120'``llvm.vp.load``': the '``passthru``' operand is implicitly ``undef``; the
20121'``alignment``' operand is taken as the ``align`` parameter attribute, if
20122provided. The default alignment is taken as the ABI alignment of the return
20123type as specified by the :ref:`datalayout string<langref_datalayout>`.
20124
20125Examples:
20126"""""""""
20127
20128.. code-block:: text
20129
20130     %r = call <8 x i8> @llvm.vp.load.v8i8.p0v8i8(<8 x i8>* align 2 %ptr, <8 x i1> %mask, i32 %evl)
20131     ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20132
20133     %also.r = call <8 x i8> @llvm.masked.load.v8i8.p0v8i8(<8 x i8>* %ptr, i32 2, <8 x i1> %mask, <8 x i8> undef)
20134
20135
20136.. _int_vp_store:
20137
20138'``llvm.vp.store``' Intrinsic
20139^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20140
20141Syntax:
20142"""""""
20143This is an overloaded intrinsic.
20144
20145::
20146
20147    declare void @llvm.vp.store.v4f32.p0v4f32(<4 x float> %val, <4 x float>* %ptr, <4 x i1> %mask, i32 %evl)
20148    declare void @llvm.vp.store.nxv2i16.p0nxv2i16(<vscale x 2 x i16> %val, <vscale x 2 x i16>* %ptr, <vscale x 2 x i1> %mask, i32 %evl)
20149    declare void @llvm.vp.store.v8f32.p1v8f32(<8 x float> %val, <8 x float> addrspace(1)* %ptr, <8 x i1> %mask, i32 %evl)
20150    declare void @llvm.vp.store.nxv1i64.p6nxv1i64(<vscale x 1 x i64> %val, <vscale x 1 x i64> addrspace(6)* %ptr, <vscale x 1 x i1> %mask, i32 %evl)
20151
20152Overview:
20153"""""""""
20154
20155The '``llvm.vp.store.*``' intrinsic is the vector length predicated version of
20156the :ref:`llvm.masked.store <int_mstore>` intrinsic.
20157
20158Arguments:
20159""""""""""
20160
20161The first operand is the vector value to be written to memory. The second
20162operand is the base pointer for the store. It has the same underlying type as
20163the value operand. The third operand is a vector of boolean values with the
20164same number of elements as the return type. The fourth is the explicit vector
20165length of the operation.
20166
20167The :ref:`align <attr_align>` parameter attribute can be provided for the
20168second operand.
20169
20170Semantics:
20171""""""""""
20172
20173The '``llvm.vp.store``' intrinsic reads a vector from memory in the same way as
20174the '``llvm.masked.store``' intrinsic, where the mask is taken from the
20175combination of the '``mask``' and '``evl``' operands in the usual VP way. The
20176alignment of the operation (corresponding to the '``alignment``' operand of
20177'``llvm.masked.store``') is specified by the ``align`` parameter attribute (see
20178above). If it is not provided then the ABI alignment of the type of the
20179'``value``' operand as specified by the :ref:`datalayout
20180string<langref_datalayout>` is used instead.
20181
20182Examples:
20183"""""""""
20184
20185.. code-block:: text
20186
20187     call void @llvm.vp.store.v8i8.p0v8i8(<8 x i8> %val, <8 x i8>* align 4 %ptr, <8 x i1> %mask, i32 %evl)
20188     ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below.
20189
20190     call void @llvm.masked.store.v8i8.p0v8i8(<8 x i8> %val, <8 x i8>* %ptr, i32 4, <8 x i1> %mask)
20191
20192
20193.. _int_experimental_vp_strided_load:
20194
20195'``llvm.experimental.vp.strided.load``' Intrinsic
20196^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20197
20198Syntax:
20199"""""""
20200This is an overloaded intrinsic.
20201
20202::
20203
20204    declare <4 x float> @llvm.experimental.vp.strided.load.v4f32.i64(float* %ptr, i64 %stride, <4 x i1> %mask, i32 %evl)
20205    declare <vscale x 2 x i16> @llvm.experimental.vp.strided.load.nxv2i16.i64(i16* %ptr, i64 %stride, <vscale x 2 x i1> %mask, i32 %evl)
20206
20207Overview:
20208"""""""""
20209
20210The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, scalar values from
20211memory locations evenly spaced apart by '``stride``' number of bytes, starting from '``ptr``'.
20212
20213Arguments:
20214""""""""""
20215
20216The first operand is the base pointer for the load. The second operand is the stride
20217value expressed in bytes. The third operand is a vector of boolean values
20218with the same number of elements as the return type. The fourth is the explicit
20219vector length of the operation. The base pointer underlying type matches the type of the scalar
20220elements of the return operand.
20221
20222The :ref:`align <attr_align>` parameter attribute can be provided for the first
20223operand.
20224
20225Semantics:
20226""""""""""
20227
20228The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, multiple scalar
20229values from memory in the same way as the :ref:`llvm.vp.gather <int_vp_gather>` intrinsic,
20230where the vector of pointers is in the form:
20231
20232   ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``,
20233
20234with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed
20235integer and all arithmetic occurring in the pointer type.
20236
20237Examples:
20238"""""""""
20239
20240.. code-block:: text
20241
20242	 %r = call <8 x i64> @llvm.experimental.vp.strided.load.v8i64.i64(i64* %ptr, i64 %stride, <8 x i64> %mask, i32 %evl)
20243	 ;; The operation can also be expressed like this:
20244
20245	 %addr = bitcast i64* %ptr to i8*
20246	 ;; Create a vector of pointers %addrs in the form:
20247	 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...>
20248	 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* >
20249	 %also.r = call <8 x i64> @llvm.vp.gather.v8i64.v8p0i64(<8 x i64* > %ptrs, <8 x i64> %mask, i32 %evl)
20250
20251
20252.. _int_experimental_vp_strided_store:
20253
20254'``llvm.experimental.vp.strided.store``' Intrinsic
20255^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20256
20257Syntax:
20258"""""""
20259This is an overloaded intrinsic.
20260
20261::
20262
20263    declare void @llvm.experimental.vp.strided.store.v4f32.i64(<4 x float> %val, float* %ptr, i64 %stride, <4 x i1> %mask, i32 %evl)
20264    declare void @llvm.experimental.vp.strided.store.nxv2i16.i64(<vscale x 2 x i16> %val, i16* %ptr, i64 %stride, <vscale x 2 x i1> %mask, i32 %evl)
20265
20266Overview:
20267"""""""""
20268
20269The '``@llvm.experimental.vp.strided.store``' intrinsic stores the elements of
20270'``val``' into memory locations evenly spaced apart by '``stride``' number of
20271bytes, starting from '``ptr``'.
20272
20273Arguments:
20274""""""""""
20275
20276The first operand is the vector value to be written to memory. The second
20277operand is the base pointer for the store. Its underlying type matches the
20278scalar element type of the value operand. The third operand is the stride value
20279expressed in bytes. The fourth operand is a vector of boolean values with the
20280same number of elements as the return type. The fifth is the explicit vector
20281length of the operation.
20282
20283The :ref:`align <attr_align>` parameter attribute can be provided for the
20284second operand.
20285
20286Semantics:
20287""""""""""
20288
20289The '``llvm.experimental.vp.strided.store``' intrinsic stores the elements of
20290'``val``' in the same way as the :ref:`llvm.vp.scatter <int_vp_scatter>` intrinsic,
20291where the vector of pointers is in the form:
20292
20293	``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``,
20294
20295with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed
20296integer and all arithmetic occurring in the pointer type.
20297
20298Examples:
20299"""""""""
20300
20301.. code-block:: text
20302
20303	 call void @llvm.experimental.vp.strided.store.v8i64.i64(<8 x i64> %val, i64* %ptr, i64 %stride, <8 x i1> %mask, i32 %evl)
20304	 ;; The operation can also be expressed like this:
20305
20306	 %addr = bitcast i64* %ptr to i8*
20307	 ;; Create a vector of pointers %addrs in the form:
20308	 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...>
20309	 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* >
20310	 call void @llvm.vp.scatter.v8i64.v8p0i64(<8 x i64> %val, <8 x i64*> %ptrs, <8 x i1> %mask, i32 %evl)
20311
20312
20313.. _int_vp_gather:
20314
20315'``llvm.vp.gather``' Intrinsic
20316^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20317
20318Syntax:
20319"""""""
20320This is an overloaded intrinsic.
20321
20322::
20323
20324    declare <4 x double> @llvm.vp.gather.v4f64.v4p0f64(<4 x double*> %ptrs, <4 x i1> %mask, i32 %evl)
20325    declare <vscale x 2 x i8> @llvm.vp.gather.nxv2i8.nxv2p0i8(<vscale x 2 x i8*> %ptrs, <vscale x 2 x i1> %mask, i32 %evl)
20326    declare <2 x float> @llvm.vp.gather.v2f32.v2p2f32(<2 x float addrspace(2)*> %ptrs, <2 x i1> %mask, i32 %evl)
20327    declare <vscale x 4 x i32> @llvm.vp.gather.nxv4i32.nxv4p4i32(<vscale x 4 x i32 addrspace(4)*> %ptrs, <vscale x 4 x i1> %mask, i32 %evl)
20328
20329Overview:
20330"""""""""
20331
20332The '``llvm.vp.gather.*``' intrinsic is the vector length predicated version of
20333the :ref:`llvm.masked.gather <int_mgather>` intrinsic.
20334
20335Arguments:
20336""""""""""
20337
20338The first operand is a vector of pointers which holds all memory addresses to
20339read. The second operand is a vector of boolean values with the same number of
20340elements as the return type. The third is the explicit vector length of the
20341operation. The return type and underlying type of the vector of pointers are
20342the same vector types.
20343
20344The :ref:`align <attr_align>` parameter attribute can be provided for the first
20345operand.
20346
20347Semantics:
20348""""""""""
20349
20350The '``llvm.vp.gather``' intrinsic reads multiple scalar values from memory in
20351the same way as the '``llvm.masked.gather``' intrinsic, where the mask is taken
20352from the combination of the '``mask``' and '``evl``' operands in the usual VP
20353way. Certain '``llvm.masked.gather``' operands do not have corresponding
20354operands in '``llvm.vp.gather``': the '``passthru``' operand is implicitly
20355``undef``; the '``alignment``' operand is taken as the ``align`` parameter, if
20356provided. The default alignment is taken as the ABI alignment of the source
20357addresses as specified by the :ref:`datalayout string<langref_datalayout>`.
20358
20359Examples:
20360"""""""""
20361
20362.. code-block:: text
20363
20364     %r = call <8 x i8> @llvm.vp.gather.v8i8.v8p0i8(<8 x i8*>  align 8 %ptrs, <8 x i1> %mask, i32 %evl)
20365     ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20366
20367     %also.r = call <8 x i8> @llvm.masked.gather.v8i8.v8p0i8(<8 x i8*> %ptrs, i32 8, <8 x i1> %mask, <8 x i8> undef)
20368
20369
20370.. _int_vp_scatter:
20371
20372'``llvm.vp.scatter``' Intrinsic
20373^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20374
20375Syntax:
20376"""""""
20377This is an overloaded intrinsic.
20378
20379::
20380
20381    declare void @llvm.vp.scatter.v4f64.v4p0f64(<4 x double> %val, <4 x double*> %ptrs, <4 x i1> %mask, i32 %evl)
20382    declare void @llvm.vp.scatter.nxv2i8.nxv2p0i8(<vscale x 2 x i8> %val, <vscale x 2 x i8*> %ptrs, <vscale x 2 x i1> %mask, i32 %evl)
20383    declare void @llvm.vp.scatter.v2f32.v2p2f32(<2 x float> %val, <2 x float addrspace(2)*> %ptrs, <2 x i1> %mask, i32 %evl)
20384    declare void @llvm.vp.scatter.nxv4i32.nxv4p4i32(<vscale x 4 x i32> %val, <vscale x 4 x i32 addrspace(4)*> %ptrs, <vscale x 4 x i1> %mask, i32 %evl)
20385
20386Overview:
20387"""""""""
20388
20389The '``llvm.vp.scatter.*``' intrinsic is the vector length predicated version of
20390the :ref:`llvm.masked.scatter <int_mscatter>` intrinsic.
20391
20392Arguments:
20393""""""""""
20394
20395The first operand is a vector value to be written to memory. The second operand
20396is a vector of pointers, pointing to where the value elements should be stored.
20397The third operand is a vector of boolean values with the same number of
20398elements as the return type. The fourth is the explicit vector length of the
20399operation.
20400
20401The :ref:`align <attr_align>` parameter attribute can be provided for the
20402second operand.
20403
20404Semantics:
20405""""""""""
20406
20407The '``llvm.vp.scatter``' intrinsic writes multiple scalar values to memory in
20408the same way as the '``llvm.masked.scatter``' intrinsic, where the mask is
20409taken from the combination of the '``mask``' and '``evl``' operands in the
20410usual VP way. The '``alignment``' operand of the '``llvm.masked.scatter``' does
20411not have a corresponding operand in '``llvm.vp.scatter``': it is instead
20412provided via the optional ``align`` parameter attribute on the
20413vector-of-pointers operand. Otherwise it is taken as the ABI alignment of the
20414destination addresses as specified by the :ref:`datalayout
20415string<langref_datalayout>`.
20416
20417Examples:
20418"""""""""
20419
20420.. code-block:: text
20421
20422     call void @llvm.vp.scatter.v8i8.v8p0i8(<8 x i8> %val, <8 x i8*> align 1 %ptrs, <8 x i1> %mask, i32 %evl)
20423     ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below.
20424
20425     call void @llvm.masked.scatter.v8i8.v8p0i8(<8 x i8> %val, <8 x i8*> %ptrs, i32 1, <8 x i1> %mask)
20426
20427
20428.. _int_vp_trunc:
20429
20430'``llvm.vp.trunc.*``' Intrinsics
20431^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20432
20433Syntax:
20434"""""""
20435This is an overloaded intrinsic.
20436
20437::
20438
20439      declare <16 x i16>  @llvm.vp.trunc.v16i16.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
20440      declare <vscale x 4 x i16>  @llvm.vp.trunc.nxv4i16.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20441
20442Overview:
20443"""""""""
20444
20445The '``llvm.vp.trunc``' intrinsic truncates its first operand to the return
20446type. The operation has a mask and an explicit vector length parameter.
20447
20448
20449Arguments:
20450""""""""""
20451
20452The '``llvm.vp.trunc``' intrinsic takes a value to cast as its first operand.
20453The return type is the type to cast the value to. Both types must be vector of
20454:ref:`integer <t_integer>` type. The bit size of the value must be larger than
20455the bit size of the return type. The second operand is the vector mask. The
20456return type, the value to cast, and the vector mask have the same number of
20457elements.  The third operand is the explicit vector length of the operation.
20458
20459Semantics:
20460""""""""""
20461
20462The '``llvm.vp.trunc``' intrinsic truncates the high order bits in value and
20463converts the remaining bits to return type. Since the source size must be larger
20464than the destination size, '``llvm.vp.trunc``' cannot be a *no-op cast*. It will
20465always truncate bits. The conversion is performed on lane positions below the
20466explicit vector length and where the vector mask is true.  Masked-off lanes are
20467undefined.
20468
20469Examples:
20470"""""""""
20471
20472.. code-block:: llvm
20473
20474      %r = call <4 x i16> @llvm.vp.trunc.v4i16.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
20475      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20476
20477      %t = trunc <4 x i32> %a to <4 x i16>
20478      %also.r = select <4 x i1> %mask, <4 x i16> %t, <4 x i16> undef
20479
20480
20481.. _int_vp_zext:
20482
20483'``llvm.vp.zext.*``' Intrinsics
20484^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20485
20486Syntax:
20487"""""""
20488This is an overloaded intrinsic.
20489
20490::
20491
20492      declare <16 x i32>  @llvm.vp.zext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>)
20493      declare <vscale x 4 x i32>  @llvm.vp.zext.nxv4i32.nxv4i16 (<vscale x 4 x i16> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20494
20495Overview:
20496"""""""""
20497
20498The '``llvm.vp.zext``' intrinsic zero extends its first operand to the return
20499type. The operation has a mask and an explicit vector length parameter.
20500
20501
20502Arguments:
20503""""""""""
20504
20505The '``llvm.vp.zext``' intrinsic takes a value to cast as its first operand.
20506The return type is the type to cast the value to. Both types must be vectors of
20507:ref:`integer <t_integer>` type. The bit size of the value must be smaller than
20508the bit size of the return type. The second operand is the vector mask. The
20509return type, the value to cast, and the vector mask have the same number of
20510elements.  The third operand is the explicit vector length of the operation.
20511
20512Semantics:
20513""""""""""
20514
20515The '``llvm.vp.zext``' intrinsic fill the high order bits of the value with zero
20516bits until it reaches the size of the return type. When zero extending from i1,
20517the result will always be either 0 or 1. The conversion is performed on lane
20518positions below the explicit vector length and where the vector mask is true.
20519Masked-off lanes are undefined.
20520
20521Examples:
20522"""""""""
20523
20524.. code-block:: llvm
20525
20526      %r = call <4 x i32> @llvm.vp.zext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl)
20527      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20528
20529      %t = zext <4 x i16> %a to <4 x i32>
20530      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
20531
20532
20533.. _int_vp_sext:
20534
20535'``llvm.vp.sext.*``' Intrinsics
20536^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20537
20538Syntax:
20539"""""""
20540This is an overloaded intrinsic.
20541
20542::
20543
20544      declare <16 x i32>  @llvm.vp.sext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>)
20545      declare <vscale x 4 x i32>  @llvm.vp.sext.nxv4i32.nxv4i16 (<vscale x 4 x i16> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20546
20547Overview:
20548"""""""""
20549
20550The '``llvm.vp.sext``' intrinsic sign extends its first operand to the return
20551type. The operation has a mask and an explicit vector length parameter.
20552
20553
20554Arguments:
20555""""""""""
20556
20557The '``llvm.vp.sext``' intrinsic takes a value to cast as its first operand.
20558The return type is the type to cast the value to. Both types must be vectors of
20559:ref:`integer <t_integer>` type. The bit size of the value must be smaller than
20560the bit size of the return type. The second operand is the vector mask. The
20561return type, the value to cast, and the vector mask have the same number of
20562elements.  The third operand is the explicit vector length of the operation.
20563
20564Semantics:
20565""""""""""
20566
20567The '``llvm.vp.sext``' intrinsic performs a sign extension by copying the sign
20568bit (highest order bit) of the value until it reaches the size of the return
20569type. When zero extending from i1, the result will always be either -1 or 0.
20570The conversion is performed on lane positions below the explicit vector length
20571and where the vector mask is true. Masked-off lanes are undefined.
20572
20573Examples:
20574"""""""""
20575
20576.. code-block:: llvm
20577
20578      %r = call <4 x i32> @llvm.vp.sext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl)
20579      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20580
20581      %t = sext <4 x i16> %a to <4 x i32>
20582      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
20583
20584
20585.. _int_vp_fptrunc:
20586
20587'``llvm.vp.fptrunc.*``' Intrinsics
20588^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20589
20590Syntax:
20591"""""""
20592This is an overloaded intrinsic.
20593
20594::
20595
20596      declare <16 x float>  @llvm.vp.fptrunc.v16f32.v16f64 (<16 x double> <op>, <16 x i1> <mask>, i32 <vector_length>)
20597      declare <vscale x 4 x float>  @llvm.vp.trunc.nxv4f32.nxv4f64 (<vscale x 4 x double> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20598
20599Overview:
20600"""""""""
20601
20602The '``llvm.vp.fptrunc``' intrinsic truncates its first operand to the return
20603type. The operation has a mask and an explicit vector length parameter.
20604
20605
20606Arguments:
20607""""""""""
20608
20609The '``llvm.vp.fptrunc``' intrinsic takes a value to cast as its first operand.
20610The return type is the type to cast the value to. Both types must be vector of
20611:ref:`floating-point <t_floating>` type. The bit size of the value must be
20612larger than the bit size of the return type. This implies that
20613'``llvm.vp.fptrunc``' cannot be used to make a *no-op cast*. The second operand
20614is the vector mask. The return type, the value to cast, and the vector mask have
20615the same number of elements.  The third operand is the explicit vector length of
20616the operation.
20617
20618Semantics:
20619""""""""""
20620
20621The '``llvm.vp.fptrunc``' intrinsic casts a ``value`` from a larger
20622:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
20623<t_floating>` type.
20624This instruction is assumed to execute in the default :ref:`floating-point
20625environment <floatenv>`. The conversion is performed on lane positions below the
20626explicit vector length and where the vector mask is true.  Masked-off lanes are
20627undefined.
20628
20629Examples:
20630"""""""""
20631
20632.. code-block:: llvm
20633
20634      %r = call <4 x float> @llvm.vp.fptrunc.v4f32.v4f64(<4 x double> %a, <4 x i1> %mask, i32 %evl)
20635      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20636
20637      %t = fptrunc <4 x double> %a to <4 x float>
20638      %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
20639
20640
20641.. _int_vp_fpext:
20642
20643'``llvm.vp.fpext.*``' Intrinsics
20644^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20645
20646Syntax:
20647"""""""
20648This is an overloaded intrinsic.
20649
20650::
20651
20652      declare <16 x double>  @llvm.vp.fpext.v16f64.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
20653      declare <vscale x 4 x double>  @llvm.vp.fpext.nxv4f64.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20654
20655Overview:
20656"""""""""
20657
20658The '``llvm.vp.fpext``' intrinsic extends its first operand to the return
20659type. The operation has a mask and an explicit vector length parameter.
20660
20661
20662Arguments:
20663""""""""""
20664
20665The '``llvm.vp.fpext``' intrinsic takes a value to cast as its first operand.
20666The return type is the type to cast the value to. Both types must be vector of
20667:ref:`floating-point <t_floating>` type. The bit size of the value must be
20668smaller than the bit size of the return type. This implies that
20669'``llvm.vp.fpext``' cannot be used to make a *no-op cast*. The second operand
20670is the vector mask. The return type, the value to cast, and the vector mask have
20671the same number of elements.  The third operand is the explicit vector length of
20672the operation.
20673
20674Semantics:
20675""""""""""
20676
20677The '``llvm.vp.fpext``' intrinsic extends the ``value`` from a smaller
20678:ref:`floating-point <t_floating>` type to a larger :ref:`floating-point
20679<t_floating>` type. The '``llvm.vp.fpext``' cannot be used to make a
20680*no-op cast* because it always changes bits. Use ``bitcast`` to make a
20681*no-op cast* for a floating-point cast.
20682The conversion is performed on lane positions below the explicit vector length
20683and where the vector mask is true.  Masked-off lanes are undefined.
20684
20685Examples:
20686"""""""""
20687
20688.. code-block:: llvm
20689
20690      %r = call <4 x double> @llvm.vp.fpext.v4f64.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
20691      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20692
20693      %t = fpext <4 x float> %a to <4 x double>
20694      %also.r = select <4 x i1> %mask, <4 x double> %t, <4 x double> undef
20695
20696
20697.. _int_vp_fptoui:
20698
20699'``llvm.vp.fptoui.*``' Intrinsics
20700^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20701
20702Syntax:
20703"""""""
20704This is an overloaded intrinsic.
20705
20706::
20707
20708      declare <16 x i32>  @llvm.vp.fptoui.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
20709      declare <vscale x 4 x i32>  @llvm.vp.fptoui.nxv4i32.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20710      declare <256 x i64>  @llvm.vp.fptoui.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
20711
20712Overview:
20713"""""""""
20714
20715The '``llvm.vp.fptoui``' intrinsic converts the :ref:`floating-point
20716<t_floating>` operand to the unsigned integer return type.
20717The operation has a mask and an explicit vector length parameter.
20718
20719
20720Arguments:
20721""""""""""
20722
20723The '``llvm.vp.fptoui``' intrinsic takes a value to cast as its first operand.
20724The value to cast must be a vector of :ref:`floating-point <t_floating>` type.
20725The return type is the type to cast the value to. The return type must be
20726vector of :ref:`integer <t_integer>` type.  The second operand is the vector
20727mask. The return type, the value to cast, and the vector mask have the same
20728number of elements.  The third operand is the explicit vector length of the
20729operation.
20730
20731Semantics:
20732""""""""""
20733
20734The '``llvm.vp.fptoui``' intrinsic converts its :ref:`floating-point
20735<t_floating>` operand into the nearest (rounding towards zero) unsigned integer
20736value where the lane position is below the explicit vector length and the
20737vector mask is true.  Masked-off lanes are undefined. On enabled lanes where
20738conversion takes place and the value cannot fit in the return type, the result
20739on that lane is a :ref:`poison value <poisonvalues>`.
20740
20741Examples:
20742"""""""""
20743
20744.. code-block:: llvm
20745
20746      %r = call <4 x i32> @llvm.vp.fptoui.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
20747      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20748
20749      %t = fptoui <4 x float> %a to <4 x i32>
20750      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
20751
20752
20753.. _int_vp_fptosi:
20754
20755'``llvm.vp.fptosi.*``' Intrinsics
20756^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20757
20758Syntax:
20759"""""""
20760This is an overloaded intrinsic.
20761
20762::
20763
20764      declare <16 x i32>  @llvm.vp.fptosi.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
20765      declare <vscale x 4 x i32>  @llvm.vp.fptosi.nxv4i32.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20766      declare <256 x i64>  @llvm.vp.fptosi.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
20767
20768Overview:
20769"""""""""
20770
20771The '``llvm.vp.fptosi``' intrinsic converts the :ref:`floating-point
20772<t_floating>` operand to the signed integer return type.
20773The operation has a mask and an explicit vector length parameter.
20774
20775
20776Arguments:
20777""""""""""
20778
20779The '``llvm.vp.fptosi``' intrinsic takes a value to cast as its first operand.
20780The value to cast must be a vector of :ref:`floating-point <t_floating>` type.
20781The return type is the type to cast the value to. The return type must be
20782vector of :ref:`integer <t_integer>` type.  The second operand is the vector
20783mask. The return type, the value to cast, and the vector mask have the same
20784number of elements.  The third operand is the explicit vector length of the
20785operation.
20786
20787Semantics:
20788""""""""""
20789
20790The '``llvm.vp.fptosi``' intrinsic converts its :ref:`floating-point
20791<t_floating>` operand into the nearest (rounding towards zero) signed integer
20792value where the lane position is below the explicit vector length and the
20793vector mask is true.  Masked-off lanes are undefined. On enabled lanes where
20794conversion takes place and the value cannot fit in the return type, the result
20795on that lane is a :ref:`poison value <poisonvalues>`.
20796
20797Examples:
20798"""""""""
20799
20800.. code-block:: llvm
20801
20802      %r = call <4 x i32> @llvm.vp.fptosi.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
20803      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20804
20805      %t = fptosi <4 x float> %a to <4 x i32>
20806      %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
20807
20808
20809.. _int_vp_uitofp:
20810
20811'``llvm.vp.uitofp.*``' Intrinsics
20812^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20813
20814Syntax:
20815"""""""
20816This is an overloaded intrinsic.
20817
20818::
20819
20820      declare <16 x float>  @llvm.vp.uitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
20821      declare <vscale x 4 x float>  @llvm.vp.uitofp.nxv4f32.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20822      declare <256 x double>  @llvm.vp.uitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
20823
20824Overview:
20825"""""""""
20826
20827The '``llvm.vp.uitofp``' intrinsic converts its unsigned integer operand to the
20828:ref:`floating-point <t_floating>` return type.  The operation has a mask and
20829an explicit vector length parameter.
20830
20831
20832Arguments:
20833""""""""""
20834
20835The '``llvm.vp.uitofp``' intrinsic takes a value to cast as its first operand.
20836The value to cast must be vector of :ref:`integer <t_integer>` type.  The
20837return type is the type to cast the value to.  The return type must be a vector
20838of :ref:`floating-point <t_floating>` type.  The second operand is the vector
20839mask. The return type, the value to cast, and the vector mask have the same
20840number of elements.  The third operand is the explicit vector length of the
20841operation.
20842
20843Semantics:
20844""""""""""
20845
20846The '``llvm.vp.uitofp``' intrinsic interprets its first operand as an unsigned
20847integer quantity and converts it to the corresponding floating-point value. If
20848the value cannot be exactly represented, it is rounded using the default
20849rounding mode.  The conversion is performed on lane positions below the
20850explicit vector length and where the vector mask is true.  Masked-off lanes are
20851undefined.
20852
20853Examples:
20854"""""""""
20855
20856.. code-block:: llvm
20857
20858      %r = call <4 x float> @llvm.vp.uitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
20859      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20860
20861      %t = uitofp <4 x i32> %a to <4 x float>
20862      %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
20863
20864
20865.. _int_vp_sitofp:
20866
20867'``llvm.vp.sitofp.*``' Intrinsics
20868^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20869
20870Syntax:
20871"""""""
20872This is an overloaded intrinsic.
20873
20874::
20875
20876      declare <16 x float>  @llvm.vp.sitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
20877      declare <vscale x 4 x float>  @llvm.vp.sitofp.nxv4f32.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20878      declare <256 x double>  @llvm.vp.sitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
20879
20880Overview:
20881"""""""""
20882
20883The '``llvm.vp.sitofp``' intrinsic converts its signed integer operand to the
20884:ref:`floating-point <t_floating>` return type.  The operation has a mask and
20885an explicit vector length parameter.
20886
20887
20888Arguments:
20889""""""""""
20890
20891The '``llvm.vp.sitofp``' intrinsic takes a value to cast as its first operand.
20892The value to cast must be vector of :ref:`integer <t_integer>` type.  The
20893return type is the type to cast the value to.  The return type must be a vector
20894of :ref:`floating-point <t_floating>` type.  The second operand is the vector
20895mask. The return type, the value to cast, and the vector mask have the same
20896number of elements.  The third operand is the explicit vector length of the
20897operation.
20898
20899Semantics:
20900""""""""""
20901
20902The '``llvm.vp.sitofp``' intrinsic interprets its first operand as a signed
20903integer quantity and converts it to the corresponding floating-point value. If
20904the value cannot be exactly represented, it is rounded using the default
20905rounding mode.  The conversion is performed on lane positions below the
20906explicit vector length and where the vector mask is true.  Masked-off lanes are
20907undefined.
20908
20909Examples:
20910"""""""""
20911
20912.. code-block:: llvm
20913
20914      %r = call <4 x float> @llvm.vp.sitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
20915      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20916
20917      %t = sitofp <4 x i32> %a to <4 x float>
20918      %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
20919
20920
20921.. _int_vp_ptrtoint:
20922
20923'``llvm.vp.ptrtoint.*``' Intrinsics
20924^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20925
20926Syntax:
20927"""""""
20928This is an overloaded intrinsic.
20929
20930::
20931
20932      declare <16 x i8>  @llvm.vp.ptrtoint.v16i8.v16p0i32 (<16 x i32*> <op>, <16 x i1> <mask>, i32 <vector_length>)
20933      declare <vscale x 4 x i8>  @llvm.vp.ptrtoint.nxv4i8.nxv4p0i32 (<vscale x 4 x i32*> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20934      declare <256 x i64>  @llvm.vp.ptrtoint.v16i64.v16p0i32 (<256 x i32*> <op>, <256 x i1> <mask>, i32 <vector_length>)
20935
20936Overview:
20937"""""""""
20938
20939The '``llvm.vp.ptrtoint``' intrinsic converts its pointer to the integer return
20940type.  The operation has a mask and an explicit vector length parameter.
20941
20942
20943Arguments:
20944""""""""""
20945
20946The '``llvm.vp.ptrtoint``' intrinsic takes a value to cast as its first operand
20947, which must be a vector of pointers, and a type to cast it to return type,
20948which must be a vector of :ref:`integer <t_integer>` type.
20949The second operand is the vector mask. The return type, the value to cast, and
20950the vector mask have the same number of elements.
20951The third operand is the explicit vector length of the operation.
20952
20953Semantics:
20954""""""""""
20955
20956The '``llvm.vp.ptrtoint``' intrinsic converts value to return type by
20957interpreting the pointer value as an integer and either truncating or zero
20958extending that value to the size of the integer type.
20959If ``value`` is smaller than return type, then a zero extension is done. If
20960``value`` is larger than return type, then a truncation is done. If they are
20961the same size, then nothing is done (*no-op cast*) other than a type
20962change.
20963The conversion is performed on lane positions below the explicit vector length
20964and where the vector mask is true.  Masked-off lanes are undefined.
20965
20966Examples:
20967"""""""""
20968
20969.. code-block:: llvm
20970
20971      %r = call <4 x i8> @llvm.vp.ptrtoint.v4i8.v4p0i32(<4 x i32*> %a, <4 x i1> %mask, i32 %evl)
20972      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20973
20974      %t = ptrtoint <4 x i32*> %a to <4 x i8>
20975      %also.r = select <4 x i1> %mask, <4 x i8> %t, <4 x i8> undef
20976
20977
20978.. _int_vp_inttoptr:
20979
20980'``llvm.vp.inttoptr.*``' Intrinsics
20981^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20982
20983Syntax:
20984"""""""
20985This is an overloaded intrinsic.
20986
20987::
20988
20989      declare <16 x i32*>  @llvm.vp.inttoptr.v16p0i32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
20990      declare <vscale x 4 x i32*>  @llvm.vp.inttoptr.nxv4p0i32.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20991      declare <256 x i32*>  @llvm.vp.inttoptr.v256p0i32.v256i32 (<256 x i32> <op>, <256 x i1> <mask>, i32 <vector_length>)
20992
20993Overview:
20994"""""""""
20995
20996The '``llvm.vp.inttoptr``' intrinsic converts its integer value to the point
20997return type. The operation has a mask and an explicit vector length parameter.
20998
20999
21000Arguments:
21001""""""""""
21002
21003The '``llvm.vp.inttoptr``' intrinsic takes a value to cast as its first operand
21004, which must be a vector of :ref:`integer <t_integer>` type, and a type to cast
21005it to return type, which must be a vector of pointers type.
21006The second operand is the vector mask. The return type, the value to cast, and
21007the vector mask have the same number of elements.
21008The third operand is the explicit vector length of the operation.
21009
21010Semantics:
21011""""""""""
21012
21013The '``llvm.vp.inttoptr``' intrinsic converts ``value`` to return type by
21014applying either a zero extension or a truncation depending on the size of the
21015integer ``value``. If ``value`` is larger than the size of a pointer, then a
21016truncation is done. If ``value`` is smaller than the size of a pointer, then a
21017zero extension is done. If they are the same size, nothing is done (*no-op cast*).
21018The conversion is performed on lane positions below the explicit vector length
21019and where the vector mask is true.  Masked-off lanes are undefined.
21020
21021Examples:
21022"""""""""
21023
21024.. code-block:: llvm
21025
21026      %r = call <4 x i32*> @llvm.vp.inttoptr.v4p0i32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
21027      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21028
21029      %t = inttoptr <4 x i32> %a to <4 x i32*>
21030      %also.r = select <4 x i1> %mask, <4 x i32*> %t, <4 x i32*> undef
21031
21032
21033.. _int_vp_fcmp:
21034
21035'``llvm.vp.fcmp.*``' Intrinsics
21036^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21037
21038Syntax:
21039"""""""
21040This is an overloaded intrinsic.
21041
21042::
21043
21044      declare <16 x i1> @llvm.vp.fcmp.v16f32(<16 x float> <left_op>, <16 x float> <right_op>, metadata <condition code>, <16 x i1> <mask>, i32 <vector_length>)
21045      declare <vscale x 4 x i1> @llvm.vp.fcmp.nxv4f32(<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, metadata <condition code>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
21046      declare <256 x i1> @llvm.vp.fcmp.v256f64(<256 x double> <left_op>, <256 x double> <right_op>, metadata <condition code>, <256 x i1> <mask>, i32 <vector_length>)
21047
21048Overview:
21049"""""""""
21050
21051The '``llvm.vp.fcmp``' intrinsic returns a vector of boolean values based on
21052the comparison of its operands. The operation has a mask and an explicit vector
21053length parameter.
21054
21055
21056Arguments:
21057""""""""""
21058
21059The '``llvm.vp.fcmp``' intrinsic takes the two values to compare as its first
21060and second operands. These two values must be vectors of :ref:`floating-point
21061<t_floating>` types.
21062The return type is the result of the comparison. The return type must be a
21063vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask.
21064The return type, the values to compare, and the vector mask have the same
21065number of elements. The third operand is the condition code indicating the kind
21066of comparison to perform. It must be a metadata string with :ref:`one of the
21067supported floating-point condition code values <fcmp_md_cc>`. The fifth operand
21068is the explicit vector length of the operation.
21069
21070Semantics:
21071""""""""""
21072
21073The '``llvm.vp.fcmp``' compares its first two operands according to the
21074condition code given as the third operand. The operands are compared element by
21075element on each enabled lane, where the the semantics of the comparison are
21076defined :ref:`according to the condition code <fcmp_md_cc_sem>`. Masked-off
21077lanes are undefined.
21078
21079Examples:
21080"""""""""
21081
21082.. code-block:: llvm
21083
21084      %r = call <4 x i1> @llvm.vp.fcmp.v4f32(<4 x float> %a, <4 x float> %b, metadata !"oeq", <4 x i1> %mask, i32 %evl)
21085      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21086
21087      %t = fcmp oeq <4 x float> %a, %b
21088      %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> undef
21089
21090
21091.. _int_vp_icmp:
21092
21093'``llvm.vp.icmp.*``' Intrinsics
21094^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21095
21096Syntax:
21097"""""""
21098This is an overloaded intrinsic.
21099
21100::
21101
21102      declare <32 x i1> @llvm.vp.icmp.v32i32(<32 x i32> <left_op>, <32 x i32> <right_op>, metadata <condition code>, <32 x i1> <mask>, i32 <vector_length>)
21103      declare <vscale x 2 x i1> @llvm.vp.icmp.nxv2i32(<vscale x 2 x i32> <left_op>, <vscale x 2 x i32> <right_op>, metadata <condition code>, <vscale x 2 x i1> <mask>, i32 <vector_length>)
21104      declare <128 x i1> @llvm.vp.icmp.v128i8(<128 x i8> <left_op>, <128 x i8> <right_op>, metadata <condition code>, <128 x i1> <mask>, i32 <vector_length>)
21105
21106Overview:
21107"""""""""
21108
21109The '``llvm.vp.icmp``' intrinsic returns a vector of boolean values based on
21110the comparison of its operands. The operation has a mask and an explicit vector
21111length parameter.
21112
21113
21114Arguments:
21115""""""""""
21116
21117The '``llvm.vp.icmp``' intrinsic takes the two values to compare as its first
21118and second operands. These two values must be vectors of :ref:`integer
21119<t_integer>` types.
21120The return type is the result of the comparison. The return type must be a
21121vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask.
21122The return type, the values to compare, and the vector mask have the same
21123number of elements. The third operand is the condition code indicating the kind
21124of comparison to perform. It must be a metadata string with :ref:`one of the
21125supported integer condition code values <icmp_md_cc>`. The fifth operand is the
21126explicit vector length of the operation.
21127
21128Semantics:
21129""""""""""
21130
21131The '``llvm.vp.icmp``' compares its first two operands according to the
21132condition code given as the third operand. The operands are compared element by
21133element on each enabled lane, where the the semantics of the comparison are
21134defined :ref:`according to the condition code <icmp_md_cc_sem>`. Masked-off
21135lanes are undefined.
21136
21137Examples:
21138"""""""""
21139
21140.. code-block:: llvm
21141
21142      %r = call <4 x i1> @llvm.vp.icmp.v4i32(<4 x i32> %a, <4 x i32> %b, metadata !"ne", <4 x i1> %mask, i32 %evl)
21143      ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21144
21145      %t = icmp ne <4 x i32> %a, %b
21146      %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> undef
21147
21148
21149.. _int_mload_mstore:
21150
21151Masked Vector Load and Store Intrinsics
21152---------------------------------------
21153
21154LLVM provides intrinsics for predicated vector load and store operations. The predicate is specified by a mask operand, which holds one bit per vector element, switching the associated vector lane on or off. The memory addresses corresponding to the "off" lanes are not accessed. When all bits of the mask are on, the intrinsic is identical to a regular vector load or store. When all bits are off, no memory is accessed.
21155
21156.. _int_mload:
21157
21158'``llvm.masked.load.*``' Intrinsics
21159^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21160
21161Syntax:
21162"""""""
21163This is an overloaded intrinsic. The loaded data is a vector of any integer, floating-point or pointer data type.
21164
21165::
21166
21167      declare <16 x float>  @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
21168      declare <2 x double>  @llvm.masked.load.v2f64.p0v2f64  (<2 x double>* <ptr>, i32 <alignment>, <2 x i1>  <mask>, <2 x double> <passthru>)
21169      ;; The data is a vector of pointers to double
21170      declare <8 x double*> @llvm.masked.load.v8p0f64.p0v8p0f64    (<8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x double*> <passthru>)
21171      ;; The data is a vector of function pointers
21172      declare <8 x i32 ()*> @llvm.masked.load.v8p0f_i32f.p0v8p0f_i32f (<8 x i32 ()*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x i32 ()*> <passthru>)
21173
21174Overview:
21175"""""""""
21176
21177Reads a vector from memory according to the provided mask. The mask holds a bit for each vector lane, and is used to prevent memory accesses to the masked-off lanes. The masked-off lanes in the result vector are taken from the corresponding lanes of the '``passthru``' operand.
21178
21179
21180Arguments:
21181""""""""""
21182
21183The first operand is the base pointer for the load. The second operand is the alignment of the source location. It must be a power of two constant integer value. The third operand, mask, is a vector of boolean values with the same number of elements as the return type. The fourth is a pass-through value that is used to fill the masked-off lanes of the result. The return type, underlying type of the base pointer and the type of the '``passthru``' operand are the same vector types.
21184
21185Semantics:
21186""""""""""
21187
21188The '``llvm.masked.load``' intrinsic is designed for conditional reading of selected vector elements in a single IR operation. It is useful for targets that support vector masked loads and allows vectorizing predicated basic blocks on these targets. Other targets may support this intrinsic differently, for example by lowering it into a sequence of branches that guard scalar load operations.
21189The result of this operation is equivalent to a regular vector load instruction followed by a 'select' between the loaded and the passthru values, predicated on the same mask. However, using this intrinsic prevents exceptions on memory access to masked-off lanes.
21190
21191
21192::
21193
21194       %res = call <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru)
21195
21196       ;; The result of the two following instructions is identical aside from potential memory access exception
21197       %loadlal = load <16 x float>, <16 x float>* %ptr, align 4
21198       %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru
21199
21200.. _int_mstore:
21201
21202'``llvm.masked.store.*``' Intrinsics
21203^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21204
21205Syntax:
21206"""""""
21207This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type.
21208
21209::
21210
21211       declare void @llvm.masked.store.v8i32.p0v8i32  (<8  x i32>   <value>, <8  x i32>*   <ptr>, i32 <alignment>,  <8  x i1> <mask>)
21212       declare void @llvm.masked.store.v16f32.p0v16f32 (<16 x float> <value>, <16 x float>* <ptr>, i32 <alignment>,  <16 x i1> <mask>)
21213       ;; The data is a vector of pointers to double
21214       declare void @llvm.masked.store.v8p0f64.p0v8p0f64    (<8 x double*> <value>, <8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>)
21215       ;; The data is a vector of function pointers
21216       declare void @llvm.masked.store.v4p0f_i32f.p0v4p0f_i32f (<4 x i32 ()*> <value>, <4 x i32 ()*>* <ptr>, i32 <alignment>, <4 x i1> <mask>)
21217
21218Overview:
21219"""""""""
21220
21221Writes a vector to memory according to the provided mask. The mask holds a bit for each vector lane, and is used to prevent memory accesses to the masked-off lanes.
21222
21223Arguments:
21224""""""""""
21225
21226The first operand is the vector value to be written to memory. The second operand is the base pointer for the store, it has the same underlying type as the value operand. The third operand is the alignment of the destination location. It must be a power of two constant integer value. The fourth operand, mask, is a vector of boolean values. The types of the mask and the value operand must have the same number of vector elements.
21227
21228
21229Semantics:
21230""""""""""
21231
21232The '``llvm.masked.store``' intrinsics is designed for conditional writing of selected vector elements in a single IR operation. It is useful for targets that support vector masked store and allows vectorizing predicated basic blocks on these targets. Other targets may support this intrinsic differently, for example by lowering it into a sequence of branches that guard scalar store operations.
21233The result of this operation is equivalent to a load-modify-store sequence. However, using this intrinsic prevents exceptions and data races on memory access to masked-off lanes.
21234
21235::
21236
21237       call void @llvm.masked.store.v16f32.p0v16f32(<16 x float> %value, <16 x float>* %ptr, i32 4,  <16 x i1> %mask)
21238
21239       ;; The result of the following instructions is identical aside from potential data races and memory access exceptions
21240       %oldval = load <16 x float>, <16 x float>* %ptr, align 4
21241       %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval
21242       store <16 x float> %res, <16 x float>* %ptr, align 4
21243
21244
21245Masked Vector Gather and Scatter Intrinsics
21246-------------------------------------------
21247
21248LLVM provides intrinsics for vector gather and scatter operations. They are similar to :ref:`Masked Vector Load and Store <int_mload_mstore>`, except they are designed for arbitrary memory accesses, rather than sequential memory accesses. Gather and scatter also employ a mask operand, which holds one bit per vector element, switching the associated vector lane on or off. The memory addresses corresponding to the "off" lanes are not accessed. When all bits are off, no memory is accessed.
21249
21250.. _int_mgather:
21251
21252'``llvm.masked.gather.*``' Intrinsics
21253^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21254
21255Syntax:
21256"""""""
21257This is an overloaded intrinsic. The loaded data are multiple scalar values of any integer, floating-point or pointer data type gathered together into one vector.
21258
21259::
21260
21261      declare <16 x float> @llvm.masked.gather.v16f32.v16p0f32   (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
21262      declare <2 x double> @llvm.masked.gather.v2f64.v2p1f64     (<2 x double addrspace(1)*> <ptrs>, i32 <alignment>, <2 x i1>  <mask>, <2 x double> <passthru>)
21263      declare <8 x float*> @llvm.masked.gather.v8p0f32.v8p0p0f32 (<8 x float**> <ptrs>, i32 <alignment>, <8 x i1>  <mask>, <8 x float*> <passthru>)
21264
21265Overview:
21266"""""""""
21267
21268Reads scalar values from arbitrary memory locations and gathers them into one vector. The memory locations are provided in the vector of pointers '``ptrs``'. The memory is accessed according to the provided mask. The mask holds a bit for each vector lane, and is used to prevent memory accesses to the masked-off lanes. The masked-off lanes in the result vector are taken from the corresponding lanes of the '``passthru``' operand.
21269
21270
21271Arguments:
21272""""""""""
21273
21274The first operand is a vector of pointers which holds all memory addresses to read. The second operand is an alignment of the source addresses. It must be 0 or a power of two constant integer value. The third operand, mask, is a vector of boolean values with the same number of elements as the return type. The fourth is a pass-through value that is used to fill the masked-off lanes of the result. The return type, underlying type of the vector of pointers and the type of the '``passthru``' operand are the same vector types.
21275
21276Semantics:
21277""""""""""
21278
21279The '``llvm.masked.gather``' intrinsic is designed for conditional reading of multiple scalar values from arbitrary memory locations in a single IR operation. It is useful for targets that support vector masked gathers and allows vectorizing basic blocks with data and control divergence. Other targets may support this intrinsic differently, for example by lowering it into a sequence of scalar load operations.
21280The semantics of this operation are equivalent to a sequence of conditional scalar loads with subsequent gathering all loaded values into a single vector. The mask restricts memory access to certain lanes and facilitates vectorization of predicated basic blocks.
21281
21282
21283::
21284
21285       %res = call <4 x double> @llvm.masked.gather.v4f64.v4p0f64 (<4 x double*> %ptrs, i32 8, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x double> undef)
21286
21287       ;; The gather with all-true mask is equivalent to the following instruction sequence
21288       %ptr0 = extractelement <4 x double*> %ptrs, i32 0
21289       %ptr1 = extractelement <4 x double*> %ptrs, i32 1
21290       %ptr2 = extractelement <4 x double*> %ptrs, i32 2
21291       %ptr3 = extractelement <4 x double*> %ptrs, i32 3
21292
21293       %val0 = load double, double* %ptr0, align 8
21294       %val1 = load double, double* %ptr1, align 8
21295       %val2 = load double, double* %ptr2, align 8
21296       %val3 = load double, double* %ptr3, align 8
21297
21298       %vec0    = insertelement <4 x double>undef, %val0, 0
21299       %vec01   = insertelement <4 x double>%vec0, %val1, 1
21300       %vec012  = insertelement <4 x double>%vec01, %val2, 2
21301       %vec0123 = insertelement <4 x double>%vec012, %val3, 3
21302
21303.. _int_mscatter:
21304
21305'``llvm.masked.scatter.*``' Intrinsics
21306^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21307
21308Syntax:
21309"""""""
21310This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type. Each vector element is stored in an arbitrary memory address. Scatter with overlapping addresses is guaranteed to be ordered from least-significant to most-significant element.
21311
21312::
21313
21314       declare void @llvm.masked.scatter.v8i32.v8p0i32     (<8 x i32>     <value>, <8 x i32*>     <ptrs>, i32 <alignment>, <8 x i1>  <mask>)
21315       declare void @llvm.masked.scatter.v16f32.v16p1f32   (<16 x float>  <value>, <16 x float addrspace(1)*>  <ptrs>, i32 <alignment>, <16 x i1> <mask>)
21316       declare void @llvm.masked.scatter.v4p0f64.v4p0p0f64 (<4 x double*> <value>, <4 x double**> <ptrs>, i32 <alignment>, <4 x i1>  <mask>)
21317
21318Overview:
21319"""""""""
21320
21321Writes each element from the value vector to the corresponding memory address. The memory addresses are represented as a vector of pointers. Writing is done according to the provided mask. The mask holds a bit for each vector lane, and is used to prevent memory accesses to the masked-off lanes.
21322
21323Arguments:
21324""""""""""
21325
21326The first operand is a vector value to be written to memory. The second operand is a vector of pointers, pointing to where the value elements should be stored. It has the same underlying type as the value operand. The third operand is an alignment of the destination addresses. It must be 0 or a power of two constant integer value. The fourth operand, mask, is a vector of boolean values. The types of the mask and the value operand must have the same number of vector elements.
21327
21328Semantics:
21329""""""""""
21330
21331The '``llvm.masked.scatter``' intrinsics is designed for writing selected vector elements to arbitrary memory addresses in a single IR operation. The operation may be conditional, when not all bits in the mask are switched on. It is useful for targets that support vector masked scatter and allows vectorizing basic blocks with data and control divergence. Other targets may support this intrinsic differently, for example by lowering it into a sequence of branches that guard scalar store operations.
21332
21333::
21334
21335       ;; This instruction unconditionally stores data vector in multiple addresses
21336       call @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> %value, <8 x i32*> %ptrs, i32 4,  <8 x i1>  <true, true, .. true>)
21337
21338       ;; It is equivalent to a list of scalar stores
21339       %val0 = extractelement <8 x i32> %value, i32 0
21340       %val1 = extractelement <8 x i32> %value, i32 1
21341       ..
21342       %val7 = extractelement <8 x i32> %value, i32 7
21343       %ptr0 = extractelement <8 x i32*> %ptrs, i32 0
21344       %ptr1 = extractelement <8 x i32*> %ptrs, i32 1
21345       ..
21346       %ptr7 = extractelement <8 x i32*> %ptrs, i32 7
21347       ;; Note: the order of the following stores is important when they overlap:
21348       store i32 %val0, i32* %ptr0, align 4
21349       store i32 %val1, i32* %ptr1, align 4
21350       ..
21351       store i32 %val7, i32* %ptr7, align 4
21352
21353
21354Masked Vector Expanding Load and Compressing Store Intrinsics
21355-------------------------------------------------------------
21356
21357LLVM provides intrinsics for expanding load and compressing store operations. Data selected from a vector according to a mask is stored in consecutive memory addresses (compressed store), and vice-versa (expanding load). These operations effective map to "if (cond.i) a[j++] = v.i" and "if (cond.i) v.i = a[j++]" patterns, respectively. Note that when the mask starts with '1' bits followed by '0' bits, these operations are identical to :ref:`llvm.masked.store <int_mstore>` and :ref:`llvm.masked.load <int_mload>`.
21358
21359.. _int_expandload:
21360
21361'``llvm.masked.expandload.*``' Intrinsics
21362^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21363
21364Syntax:
21365"""""""
21366This is an overloaded intrinsic. Several values of integer, floating point or pointer data type are loaded from consecutive memory addresses and stored into the elements of a vector according to the mask.
21367
21368::
21369
21370      declare <16 x float>  @llvm.masked.expandload.v16f32 (float* <ptr>, <16 x i1> <mask>, <16 x float> <passthru>)
21371      declare <2 x i64>     @llvm.masked.expandload.v2i64 (i64* <ptr>, <2 x i1>  <mask>, <2 x i64> <passthru>)
21372
21373Overview:
21374"""""""""
21375
21376Reads a number of scalar values sequentially from memory location provided in '``ptr``' and spreads them in a vector. The '``mask``' holds a bit for each vector lane. The number of elements read from memory is equal to the number of '1' bits in the mask. The loaded elements are positioned in the destination vector according to the sequence of '1' and '0' bits in the mask. E.g., if the mask vector is '10010001', "expandload" reads 3 values from memory addresses ptr, ptr+1, ptr+2 and places them in lanes 0, 3 and 7 accordingly. The masked-off lanes are filled by elements from the corresponding lanes of the '``passthru``' operand.
21377
21378
21379Arguments:
21380""""""""""
21381
21382The first operand is the base pointer for the load. It has the same underlying type as the element of the returned vector. The second operand, mask, is a vector of boolean values with the same number of elements as the return type. The third is a pass-through value that is used to fill the masked-off lanes of the result. The return type and the type of the '``passthru``' operand have the same vector type.
21383
21384Semantics:
21385""""""""""
21386
21387The '``llvm.masked.expandload``' intrinsic is designed for reading multiple scalar values from adjacent memory addresses into possibly non-adjacent vector lanes. It is useful for targets that support vector expanding loads and allows vectorizing loop with cross-iteration dependency like in the following example:
21388
21389.. code-block:: c
21390
21391    // In this loop we load from B and spread the elements into array A.
21392    double *A, B; int *C;
21393    for (int i = 0; i < size; ++i) {
21394      if (C[i] != 0)
21395        A[i] = B[j++];
21396    }
21397
21398
21399.. code-block:: llvm
21400
21401    ; Load several elements from array B and expand them in a vector.
21402    ; The number of loaded elements is equal to the number of '1' elements in the Mask.
21403    %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(double* %Bptr, <8 x i1> %Mask, <8 x double> undef)
21404    ; Store the result in A
21405    call void @llvm.masked.store.v8f64.p0v8f64(<8 x double> %Tmp, <8 x double>* %Aptr, i32 8, <8 x i1> %Mask)
21406
21407    ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
21408    %MaskI = bitcast <8 x i1> %Mask to i8
21409    %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
21410    %MaskI64 = zext i8 %MaskIPopcnt to i64
21411    %BNextInd = add i64 %BInd, %MaskI64
21412
21413
21414Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles.
21415If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load.
21416
21417.. _int_compressstore:
21418
21419'``llvm.masked.compressstore.*``' Intrinsics
21420^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21421
21422Syntax:
21423"""""""
21424This is an overloaded intrinsic. A number of scalar values of integer, floating point or pointer data type are collected from an input vector and stored into adjacent memory addresses. A mask defines which elements to collect from the vector.
21425
21426::
21427
21428      declare void @llvm.masked.compressstore.v8i32  (<8  x i32>   <value>, i32*   <ptr>, <8  x i1> <mask>)
21429      declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, float* <ptr>, <16 x i1> <mask>)
21430
21431Overview:
21432"""""""""
21433
21434Selects elements from input vector '``value``' according to the '``mask``'. All selected elements are written into adjacent memory addresses starting at address '`ptr`', from lower to higher. The mask holds a bit for each vector lane, and is used to select elements to be stored. The number of elements to be stored is equal to the number of active bits in the mask.
21435
21436Arguments:
21437""""""""""
21438
21439The first operand is the input vector, from which elements are collected and written to memory. The second operand is the base pointer for the store, it has the same underlying type as the element of the input vector operand. The third operand is the mask, a vector of boolean values. The mask and the input vector must have the same number of vector elements.
21440
21441
21442Semantics:
21443""""""""""
21444
21445The '``llvm.masked.compressstore``' intrinsic is designed for compressing data in memory. It allows to collect elements from possibly non-adjacent lanes of a vector and store them contiguously in memory in one IR operation. It is useful for targets that support compressing store operations and allows vectorizing loops with cross-iteration dependences like in the following example:
21446
21447.. code-block:: c
21448
21449    // In this loop we load elements from A and store them consecutively in B
21450    double *A, B; int *C;
21451    for (int i = 0; i < size; ++i) {
21452      if (C[i] != 0)
21453        B[j++] = A[i]
21454    }
21455
21456
21457.. code-block:: llvm
21458
21459    ; Load elements from A.
21460    %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0v8f64(<8 x double>* %Aptr, i32 8, <8 x i1> %Mask, <8 x double> undef)
21461    ; Store all selected elements consecutively in array B
21462    call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, double* %Bptr, <8 x i1> %Mask)
21463
21464    ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
21465    %MaskI = bitcast <8 x i1> %Mask to i8
21466    %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
21467    %MaskI64 = zext i8 %MaskIPopcnt to i64
21468    %BNextInd = add i64 %BInd, %MaskI64
21469
21470
21471Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations.
21472
21473
21474Memory Use Markers
21475------------------
21476
21477This class of intrinsics provides information about the
21478:ref:`lifetime of memory objects <objectlifetime>` and ranges where variables
21479are immutable.
21480
21481.. _int_lifestart:
21482
21483'``llvm.lifetime.start``' Intrinsic
21484^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21485
21486Syntax:
21487"""""""
21488
21489::
21490
21491      declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>)
21492
21493Overview:
21494"""""""""
21495
21496The '``llvm.lifetime.start``' intrinsic specifies the start of a memory
21497object's lifetime.
21498
21499Arguments:
21500""""""""""
21501
21502The first argument is a constant integer representing the size of the
21503object, or -1 if it is variable sized. The second argument is a pointer
21504to the object.
21505
21506Semantics:
21507""""""""""
21508
21509If ``ptr`` is a stack-allocated object and it points to the first byte of
21510the object, the object is initially marked as dead.
21511``ptr`` is conservatively considered as a non-stack-allocated object if
21512the stack coloring algorithm that is used in the optimization pipeline cannot
21513conclude that ``ptr`` is a stack-allocated object.
21514
21515After '``llvm.lifetime.start``', the stack object that ``ptr`` points is marked
21516as alive and has an uninitialized value.
21517The stack object is marked as dead when either
21518:ref:`llvm.lifetime.end <int_lifeend>` to the alloca is executed or the
21519function returns.
21520
21521After :ref:`llvm.lifetime.end <int_lifeend>` is called,
21522'``llvm.lifetime.start``' on the stack object can be called again.
21523The second '``llvm.lifetime.start``' call marks the object as alive, but it
21524does not change the address of the object.
21525
21526If ``ptr`` is a non-stack-allocated object, it does not point to the first
21527byte of the object or it is a stack object that is already alive, it simply
21528fills all bytes of the object with ``poison``.
21529
21530
21531.. _int_lifeend:
21532
21533'``llvm.lifetime.end``' Intrinsic
21534^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21535
21536Syntax:
21537"""""""
21538
21539::
21540
21541      declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>)
21542
21543Overview:
21544"""""""""
21545
21546The '``llvm.lifetime.end``' intrinsic specifies the end of a memory object's
21547lifetime.
21548
21549Arguments:
21550""""""""""
21551
21552The first argument is a constant integer representing the size of the
21553object, or -1 if it is variable sized. The second argument is a pointer
21554to the object.
21555
21556Semantics:
21557""""""""""
21558
21559If ``ptr`` is a stack-allocated object and it points to the first byte of the
21560object, the object is dead.
21561``ptr`` is conservatively considered as a non-stack-allocated object if
21562the stack coloring algorithm that is used in the optimization pipeline cannot
21563conclude that ``ptr`` is a stack-allocated object.
21564
21565Calling ``llvm.lifetime.end`` on an already dead alloca is no-op.
21566
21567If ``ptr`` is a non-stack-allocated object or it does not point to the first
21568byte of the object, it is equivalent to simply filling all bytes of the object
21569with ``poison``.
21570
21571
21572'``llvm.invariant.start``' Intrinsic
21573^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21574
21575Syntax:
21576"""""""
21577This is an overloaded intrinsic. The memory object can belong to any address space.
21578
21579::
21580
21581      declare {}* @llvm.invariant.start.p0i8(i64 <size>, i8* nocapture <ptr>)
21582
21583Overview:
21584"""""""""
21585
21586The '``llvm.invariant.start``' intrinsic specifies that the contents of
21587a memory object will not change.
21588
21589Arguments:
21590""""""""""
21591
21592The first argument is a constant integer representing the size of the
21593object, or -1 if it is variable sized. The second argument is a pointer
21594to the object.
21595
21596Semantics:
21597""""""""""
21598
21599This intrinsic indicates that until an ``llvm.invariant.end`` that uses
21600the return value, the referenced memory location is constant and
21601unchanging.
21602
21603'``llvm.invariant.end``' Intrinsic
21604^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21605
21606Syntax:
21607"""""""
21608This is an overloaded intrinsic. The memory object can belong to any address space.
21609
21610::
21611
21612      declare void @llvm.invariant.end.p0i8({}* <start>, i64 <size>, i8* nocapture <ptr>)
21613
21614Overview:
21615"""""""""
21616
21617The '``llvm.invariant.end``' intrinsic specifies that the contents of a
21618memory object are mutable.
21619
21620Arguments:
21621""""""""""
21622
21623The first argument is the matching ``llvm.invariant.start`` intrinsic.
21624The second argument is a constant integer representing the size of the
21625object, or -1 if it is variable sized and the third argument is a
21626pointer to the object.
21627
21628Semantics:
21629""""""""""
21630
21631This intrinsic indicates that the memory is mutable again.
21632
21633'``llvm.launder.invariant.group``' Intrinsic
21634^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21635
21636Syntax:
21637"""""""
21638This is an overloaded intrinsic. The memory object can belong to any address
21639space. The returned pointer must belong to the same address space as the
21640argument.
21641
21642::
21643
21644      declare i8* @llvm.launder.invariant.group.p0i8(i8* <ptr>)
21645
21646Overview:
21647"""""""""
21648
21649The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant
21650established by ``invariant.group`` metadata no longer holds, to obtain a new
21651pointer value that carries fresh invariant group information. It is an
21652experimental intrinsic, which means that its semantics might change in the
21653future.
21654
21655
21656Arguments:
21657""""""""""
21658
21659The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer
21660to the memory.
21661
21662Semantics:
21663""""""""""
21664
21665Returns another pointer that aliases its argument but which is considered different
21666for the purposes of ``load``/``store`` ``invariant.group`` metadata.
21667It does not read any accessible memory and the execution can be speculated.
21668
21669'``llvm.strip.invariant.group``' Intrinsic
21670^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21671
21672Syntax:
21673"""""""
21674This is an overloaded intrinsic. The memory object can belong to any address
21675space. The returned pointer must belong to the same address space as the
21676argument.
21677
21678::
21679
21680      declare i8* @llvm.strip.invariant.group.p0i8(i8* <ptr>)
21681
21682Overview:
21683"""""""""
21684
21685The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant
21686established by ``invariant.group`` metadata no longer holds, to obtain a new pointer
21687value that does not carry the invariant information. It is an experimental
21688intrinsic, which means that its semantics might change in the future.
21689
21690
21691Arguments:
21692""""""""""
21693
21694The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer
21695to the memory.
21696
21697Semantics:
21698""""""""""
21699
21700Returns another pointer that aliases its argument but which has no associated
21701``invariant.group`` metadata.
21702It does not read any memory and can be speculated.
21703
21704
21705
21706.. _constrainedfp:
21707
21708Constrained Floating-Point Intrinsics
21709-------------------------------------
21710
21711These intrinsics are used to provide special handling of floating-point
21712operations when specific rounding mode or floating-point exception behavior is
21713required.  By default, LLVM optimization passes assume that the rounding mode is
21714round-to-nearest and that floating-point exceptions will not be monitored.
21715Constrained FP intrinsics are used to support non-default rounding modes and
21716accurately preserve exception behavior without compromising LLVM's ability to
21717optimize FP code when the default behavior is used.
21718
21719If any FP operation in a function is constrained then they all must be
21720constrained. This is required for correct LLVM IR. Optimizations that
21721move code around can create miscompiles if mixing of constrained and normal
21722operations is done. The correct way to mix constrained and less constrained
21723operations is to use the rounding mode and exception handling metadata to
21724mark constrained intrinsics as having LLVM's default behavior.
21725
21726Each of these intrinsics corresponds to a normal floating-point operation. The
21727data arguments and the return value are the same as the corresponding FP
21728operation.
21729
21730The rounding mode argument is a metadata string specifying what
21731assumptions, if any, the optimizer can make when transforming constant
21732values. Some constrained FP intrinsics omit this argument. If required
21733by the intrinsic, this argument must be one of the following strings:
21734
21735::
21736
21737      "round.dynamic"
21738      "round.tonearest"
21739      "round.downward"
21740      "round.upward"
21741      "round.towardzero"
21742      "round.tonearestaway"
21743
21744If this argument is "round.dynamic" optimization passes must assume that the
21745rounding mode is unknown and may change at runtime.  No transformations that
21746depend on rounding mode may be performed in this case.
21747
21748The other possible values for the rounding mode argument correspond to the
21749similarly named IEEE rounding modes.  If the argument is any of these values
21750optimization passes may perform transformations as long as they are consistent
21751with the specified rounding mode.
21752
21753For example, 'x-0'->'x' is not a valid transformation if the rounding mode is
21754"round.downward" or "round.dynamic" because if the value of 'x' is +0 then
21755'x-0' should evaluate to '-0' when rounding downward.  However, this
21756transformation is legal for all other rounding modes.
21757
21758For values other than "round.dynamic" optimization passes may assume that the
21759actual runtime rounding mode (as defined in a target-specific manner) matches
21760the specified rounding mode, but this is not guaranteed.  Using a specific
21761non-dynamic rounding mode which does not match the actual rounding mode at
21762runtime results in undefined behavior.
21763
21764The exception behavior argument is a metadata string describing the floating
21765point exception semantics that required for the intrinsic. This argument
21766must be one of the following strings:
21767
21768::
21769
21770      "fpexcept.ignore"
21771      "fpexcept.maytrap"
21772      "fpexcept.strict"
21773
21774If this argument is "fpexcept.ignore" optimization passes may assume that the
21775exception status flags will not be read and that floating-point exceptions will
21776be masked.  This allows transformations to be performed that may change the
21777exception semantics of the original code.  For example, FP operations may be
21778speculatively executed in this case whereas they must not be for either of the
21779other possible values of this argument.
21780
21781If the exception behavior argument is "fpexcept.maytrap" optimization passes
21782must avoid transformations that may raise exceptions that would not have been
21783raised by the original code (such as speculatively executing FP operations), but
21784passes are not required to preserve all exceptions that are implied by the
21785original code.  For example, exceptions may be potentially hidden by constant
21786folding.
21787
21788If the exception behavior argument is "fpexcept.strict" all transformations must
21789strictly preserve the floating-point exception semantics of the original code.
21790Any FP exception that would have been raised by the original code must be raised
21791by the transformed code, and the transformed code must not raise any FP
21792exceptions that would not have been raised by the original code.  This is the
21793exception behavior argument that will be used if the code being compiled reads
21794the FP exception status flags, but this mode can also be used with code that
21795unmasks FP exceptions.
21796
21797The number and order of floating-point exceptions is NOT guaranteed.  For
21798example, a series of FP operations that each may raise exceptions may be
21799vectorized into a single instruction that raises each unique exception a single
21800time.
21801
21802Proper :ref:`function attributes <fnattrs>` usage is required for the
21803constrained intrinsics to function correctly.
21804
21805All function *calls* done in a function that uses constrained floating
21806point intrinsics must have the ``strictfp`` attribute.
21807
21808All function *definitions* that use constrained floating point intrinsics
21809must have the ``strictfp`` attribute.
21810
21811'``llvm.experimental.constrained.fadd``' Intrinsic
21812^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21813
21814Syntax:
21815"""""""
21816
21817::
21818
21819      declare <type>
21820      @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>,
21821                                          metadata <rounding mode>,
21822                                          metadata <exception behavior>)
21823
21824Overview:
21825"""""""""
21826
21827The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its
21828two operands.
21829
21830
21831Arguments:
21832""""""""""
21833
21834The first two arguments to the '``llvm.experimental.constrained.fadd``'
21835intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
21836of floating-point values. Both arguments must have identical types.
21837
21838The third and fourth arguments specify the rounding mode and exception
21839behavior as described above.
21840
21841Semantics:
21842""""""""""
21843
21844The value produced is the floating-point sum of the two value operands and has
21845the same type as the operands.
21846
21847
21848'``llvm.experimental.constrained.fsub``' Intrinsic
21849^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21850
21851Syntax:
21852"""""""
21853
21854::
21855
21856      declare <type>
21857      @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>,
21858                                          metadata <rounding mode>,
21859                                          metadata <exception behavior>)
21860
21861Overview:
21862"""""""""
21863
21864The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference
21865of its two operands.
21866
21867
21868Arguments:
21869""""""""""
21870
21871The first two arguments to the '``llvm.experimental.constrained.fsub``'
21872intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
21873of floating-point values. Both arguments must have identical types.
21874
21875The third and fourth arguments specify the rounding mode and exception
21876behavior as described above.
21877
21878Semantics:
21879""""""""""
21880
21881The value produced is the floating-point difference of the two value operands
21882and has the same type as the operands.
21883
21884
21885'``llvm.experimental.constrained.fmul``' Intrinsic
21886^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21887
21888Syntax:
21889"""""""
21890
21891::
21892
21893      declare <type>
21894      @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>,
21895                                          metadata <rounding mode>,
21896                                          metadata <exception behavior>)
21897
21898Overview:
21899"""""""""
21900
21901The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of
21902its two operands.
21903
21904
21905Arguments:
21906""""""""""
21907
21908The first two arguments to the '``llvm.experimental.constrained.fmul``'
21909intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
21910of floating-point values. Both arguments must have identical types.
21911
21912The third and fourth arguments specify the rounding mode and exception
21913behavior as described above.
21914
21915Semantics:
21916""""""""""
21917
21918The value produced is the floating-point product of the two value operands and
21919has the same type as the operands.
21920
21921
21922'``llvm.experimental.constrained.fdiv``' Intrinsic
21923^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21924
21925Syntax:
21926"""""""
21927
21928::
21929
21930      declare <type>
21931      @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>,
21932                                          metadata <rounding mode>,
21933                                          metadata <exception behavior>)
21934
21935Overview:
21936"""""""""
21937
21938The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of
21939its two operands.
21940
21941
21942Arguments:
21943""""""""""
21944
21945The first two arguments to the '``llvm.experimental.constrained.fdiv``'
21946intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
21947of floating-point values. Both arguments must have identical types.
21948
21949The third and fourth arguments specify the rounding mode and exception
21950behavior as described above.
21951
21952Semantics:
21953""""""""""
21954
21955The value produced is the floating-point quotient of the two value operands and
21956has the same type as the operands.
21957
21958
21959'``llvm.experimental.constrained.frem``' Intrinsic
21960^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21961
21962Syntax:
21963"""""""
21964
21965::
21966
21967      declare <type>
21968      @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>,
21969                                          metadata <rounding mode>,
21970                                          metadata <exception behavior>)
21971
21972Overview:
21973"""""""""
21974
21975The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder
21976from the division of its two operands.
21977
21978
21979Arguments:
21980""""""""""
21981
21982The first two arguments to the '``llvm.experimental.constrained.frem``'
21983intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
21984of floating-point values. Both arguments must have identical types.
21985
21986The third and fourth arguments specify the rounding mode and exception
21987behavior as described above.  The rounding mode argument has no effect, since
21988the result of frem is never rounded, but the argument is included for
21989consistency with the other constrained floating-point intrinsics.
21990
21991Semantics:
21992""""""""""
21993
21994The value produced is the floating-point remainder from the division of the two
21995value operands and has the same type as the operands.  The remainder has the
21996same sign as the dividend.
21997
21998'``llvm.experimental.constrained.fma``' Intrinsic
21999^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22000
22001Syntax:
22002"""""""
22003
22004::
22005
22006      declare <type>
22007      @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>,
22008                                          metadata <rounding mode>,
22009                                          metadata <exception behavior>)
22010
22011Overview:
22012"""""""""
22013
22014The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a
22015fused-multiply-add operation on its operands.
22016
22017Arguments:
22018""""""""""
22019
22020The first three arguments to the '``llvm.experimental.constrained.fma``'
22021intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector
22022<t_vector>` of floating-point values. All arguments must have identical types.
22023
22024The fourth and fifth arguments specify the rounding mode and exception behavior
22025as described above.
22026
22027Semantics:
22028""""""""""
22029
22030The result produced is the product of the first two operands added to the third
22031operand computed with infinite precision, and then rounded to the target
22032precision.
22033
22034'``llvm.experimental.constrained.fptoui``' Intrinsic
22035^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22036
22037Syntax:
22038"""""""
22039
22040::
22041
22042      declare <ty2>
22043      @llvm.experimental.constrained.fptoui(<type> <value>,
22044                                          metadata <exception behavior>)
22045
22046Overview:
22047"""""""""
22048
22049The '``llvm.experimental.constrained.fptoui``' intrinsic converts a
22050floating-point ``value`` to its unsigned integer equivalent of type ``ty2``.
22051
22052Arguments:
22053""""""""""
22054
22055The first argument to the '``llvm.experimental.constrained.fptoui``'
22056intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
22057<t_vector>` of floating point values.
22058
22059The second argument specifies the exception behavior as described above.
22060
22061Semantics:
22062""""""""""
22063
22064The result produced is an unsigned integer converted from the floating
22065point operand. The value is truncated, so it is rounded towards zero.
22066
22067'``llvm.experimental.constrained.fptosi``' Intrinsic
22068^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22069
22070Syntax:
22071"""""""
22072
22073::
22074
22075      declare <ty2>
22076      @llvm.experimental.constrained.fptosi(<type> <value>,
22077                                          metadata <exception behavior>)
22078
22079Overview:
22080"""""""""
22081
22082The '``llvm.experimental.constrained.fptosi``' intrinsic converts
22083:ref:`floating-point <t_floating>` ``value`` to type ``ty2``.
22084
22085Arguments:
22086""""""""""
22087
22088The first argument to the '``llvm.experimental.constrained.fptosi``'
22089intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
22090<t_vector>` of floating point values.
22091
22092The second argument specifies the exception behavior as described above.
22093
22094Semantics:
22095""""""""""
22096
22097The result produced is a signed integer converted from the floating
22098point operand. The value is truncated, so it is rounded towards zero.
22099
22100'``llvm.experimental.constrained.uitofp``' Intrinsic
22101^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22102
22103Syntax:
22104"""""""
22105
22106::
22107
22108      declare <ty2>
22109      @llvm.experimental.constrained.uitofp(<type> <value>,
22110                                          metadata <rounding mode>,
22111                                          metadata <exception behavior>)
22112
22113Overview:
22114"""""""""
22115
22116The '``llvm.experimental.constrained.uitofp``' intrinsic converts an
22117unsigned integer ``value`` to a floating-point of type ``ty2``.
22118
22119Arguments:
22120""""""""""
22121
22122The first argument to the '``llvm.experimental.constrained.uitofp``'
22123intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector
22124<t_vector>` of integer values.
22125
22126The second and third arguments specify the rounding mode and exception
22127behavior as described above.
22128
22129Semantics:
22130""""""""""
22131
22132An inexact floating-point exception will be raised if rounding is required.
22133Any result produced is a floating point value converted from the input
22134integer operand.
22135
22136'``llvm.experimental.constrained.sitofp``' Intrinsic
22137^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22138
22139Syntax:
22140"""""""
22141
22142::
22143
22144      declare <ty2>
22145      @llvm.experimental.constrained.sitofp(<type> <value>,
22146                                          metadata <rounding mode>,
22147                                          metadata <exception behavior>)
22148
22149Overview:
22150"""""""""
22151
22152The '``llvm.experimental.constrained.sitofp``' intrinsic converts a
22153signed integer ``value`` to a floating-point of type ``ty2``.
22154
22155Arguments:
22156""""""""""
22157
22158The first argument to the '``llvm.experimental.constrained.sitofp``'
22159intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector
22160<t_vector>` of integer values.
22161
22162The second and third arguments specify the rounding mode and exception
22163behavior as described above.
22164
22165Semantics:
22166""""""""""
22167
22168An inexact floating-point exception will be raised if rounding is required.
22169Any result produced is a floating point value converted from the input
22170integer operand.
22171
22172'``llvm.experimental.constrained.fptrunc``' Intrinsic
22173^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22174
22175Syntax:
22176"""""""
22177
22178::
22179
22180      declare <ty2>
22181      @llvm.experimental.constrained.fptrunc(<type> <value>,
22182                                          metadata <rounding mode>,
22183                                          metadata <exception behavior>)
22184
22185Overview:
22186"""""""""
22187
22188The '``llvm.experimental.constrained.fptrunc``' intrinsic truncates ``value``
22189to type ``ty2``.
22190
22191Arguments:
22192""""""""""
22193
22194The first argument to the '``llvm.experimental.constrained.fptrunc``'
22195intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
22196<t_vector>` of floating point values. This argument must be larger in size
22197than the result.
22198
22199The second and third arguments specify the rounding mode and exception
22200behavior as described above.
22201
22202Semantics:
22203""""""""""
22204
22205The result produced is a floating point value truncated to be smaller in size
22206than the operand.
22207
22208'``llvm.experimental.constrained.fpext``' Intrinsic
22209^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22210
22211Syntax:
22212"""""""
22213
22214::
22215
22216      declare <ty2>
22217      @llvm.experimental.constrained.fpext(<type> <value>,
22218                                          metadata <exception behavior>)
22219
22220Overview:
22221"""""""""
22222
22223The '``llvm.experimental.constrained.fpext``' intrinsic extends a
22224floating-point ``value`` to a larger floating-point value.
22225
22226Arguments:
22227""""""""""
22228
22229The first argument to the '``llvm.experimental.constrained.fpext``'
22230intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
22231<t_vector>` of floating point values. This argument must be smaller in size
22232than the result.
22233
22234The second argument specifies the exception behavior as described above.
22235
22236Semantics:
22237""""""""""
22238
22239The result produced is a floating point value extended to be larger in size
22240than the operand. All restrictions that apply to the fpext instruction also
22241apply to this intrinsic.
22242
22243'``llvm.experimental.constrained.fcmp``' and '``llvm.experimental.constrained.fcmps``' Intrinsics
22244^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22245
22246Syntax:
22247"""""""
22248
22249::
22250
22251      declare <ty2>
22252      @llvm.experimental.constrained.fcmp(<type> <op1>, <type> <op2>,
22253                                          metadata <condition code>,
22254                                          metadata <exception behavior>)
22255      declare <ty2>
22256      @llvm.experimental.constrained.fcmps(<type> <op1>, <type> <op2>,
22257                                           metadata <condition code>,
22258                                           metadata <exception behavior>)
22259
22260Overview:
22261"""""""""
22262
22263The '``llvm.experimental.constrained.fcmp``' and
22264'``llvm.experimental.constrained.fcmps``' intrinsics return a boolean
22265value or vector of boolean values based on comparison of its operands.
22266
22267If the operands are floating-point scalars, then the result type is a
22268boolean (:ref:`i1 <t_integer>`).
22269
22270If the operands are floating-point vectors, then the result type is a
22271vector of boolean with the same number of elements as the operands being
22272compared.
22273
22274The '``llvm.experimental.constrained.fcmp``' intrinsic performs a quiet
22275comparison operation while the '``llvm.experimental.constrained.fcmps``'
22276intrinsic performs a signaling comparison operation.
22277
22278Arguments:
22279""""""""""
22280
22281The first two arguments to the '``llvm.experimental.constrained.fcmp``'
22282and '``llvm.experimental.constrained.fcmps``' intrinsics must be
22283:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
22284of floating-point values. Both arguments must have identical types.
22285
22286The third argument is the condition code indicating the kind of comparison
22287to perform. It must be a metadata string with one of the following values:
22288
22289.. _fcmp_md_cc:
22290
22291- "``oeq``": ordered and equal
22292- "``ogt``": ordered and greater than
22293- "``oge``": ordered and greater than or equal
22294- "``olt``": ordered and less than
22295- "``ole``": ordered and less than or equal
22296- "``one``": ordered and not equal
22297- "``ord``": ordered (no nans)
22298- "``ueq``": unordered or equal
22299- "``ugt``": unordered or greater than
22300- "``uge``": unordered or greater than or equal
22301- "``ult``": unordered or less than
22302- "``ule``": unordered or less than or equal
22303- "``une``": unordered or not equal
22304- "``uno``": unordered (either nans)
22305
22306*Ordered* means that neither operand is a NAN while *unordered* means
22307that either operand may be a NAN.
22308
22309The fourth argument specifies the exception behavior as described above.
22310
22311Semantics:
22312""""""""""
22313
22314``op1`` and ``op2`` are compared according to the condition code given
22315as the third argument. If the operands are vectors, then the
22316vectors are compared element by element. Each comparison performed
22317always yields an :ref:`i1 <t_integer>` result, as follows:
22318
22319.. _fcmp_md_cc_sem:
22320
22321- "``oeq``": yields ``true`` if both operands are not a NAN and ``op1``
22322  is equal to ``op2``.
22323- "``ogt``": yields ``true`` if both operands are not a NAN and ``op1``
22324  is greater than ``op2``.
22325- "``oge``": yields ``true`` if both operands are not a NAN and ``op1``
22326  is greater than or equal to ``op2``.
22327- "``olt``": yields ``true`` if both operands are not a NAN and ``op1``
22328  is less than ``op2``.
22329- "``ole``": yields ``true`` if both operands are not a NAN and ``op1``
22330  is less than or equal to ``op2``.
22331- "``one``": yields ``true`` if both operands are not a NAN and ``op1``
22332  is not equal to ``op2``.
22333- "``ord``": yields ``true`` if both operands are not a NAN.
22334- "``ueq``": yields ``true`` if either operand is a NAN or ``op1`` is
22335  equal to ``op2``.
22336- "``ugt``": yields ``true`` if either operand is a NAN or ``op1`` is
22337  greater than ``op2``.
22338- "``uge``": yields ``true`` if either operand is a NAN or ``op1`` is
22339  greater than or equal to ``op2``.
22340- "``ult``": yields ``true`` if either operand is a NAN or ``op1`` is
22341  less than ``op2``.
22342- "``ule``": yields ``true`` if either operand is a NAN or ``op1`` is
22343  less than or equal to ``op2``.
22344- "``une``": yields ``true`` if either operand is a NAN or ``op1`` is
22345  not equal to ``op2``.
22346- "``uno``": yields ``true`` if either operand is a NAN.
22347
22348The quiet comparison operation performed by
22349'``llvm.experimental.constrained.fcmp``' will only raise an exception
22350if either operand is a SNAN.  The signaling comparison operation
22351performed by '``llvm.experimental.constrained.fcmps``' will raise an
22352exception if either operand is a NAN (QNAN or SNAN). Such an exception
22353does not preclude a result being produced (e.g. exception might only
22354set a flag), therefore the distinction between ordered and unordered
22355comparisons is also relevant for the
22356'``llvm.experimental.constrained.fcmps``' intrinsic.
22357
22358'``llvm.experimental.constrained.fmuladd``' Intrinsic
22359^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22360
22361Syntax:
22362"""""""
22363
22364::
22365
22366      declare <type>
22367      @llvm.experimental.constrained.fmuladd(<type> <op1>, <type> <op2>,
22368                                             <type> <op3>,
22369                                             metadata <rounding mode>,
22370                                             metadata <exception behavior>)
22371
22372Overview:
22373"""""""""
22374
22375The '``llvm.experimental.constrained.fmuladd``' intrinsic represents
22376multiply-add expressions that can be fused if the code generator determines
22377that (a) the target instruction set has support for a fused operation,
22378and (b) that the fused operation is more efficient than the equivalent,
22379separate pair of mul and add instructions.
22380
22381Arguments:
22382""""""""""
22383
22384The first three arguments to the '``llvm.experimental.constrained.fmuladd``'
22385intrinsic must be floating-point or vector of floating-point values.
22386All three arguments must have identical types.
22387
22388The fourth and fifth arguments specify the rounding mode and exception behavior
22389as described above.
22390
22391Semantics:
22392""""""""""
22393
22394The expression:
22395
22396::
22397
22398      %0 = call float @llvm.experimental.constrained.fmuladd.f32(%a, %b, %c,
22399                                                                 metadata <rounding mode>,
22400                                                                 metadata <exception behavior>)
22401
22402is equivalent to the expression:
22403
22404::
22405
22406      %0 = call float @llvm.experimental.constrained.fmul.f32(%a, %b,
22407                                                              metadata <rounding mode>,
22408                                                              metadata <exception behavior>)
22409      %1 = call float @llvm.experimental.constrained.fadd.f32(%0, %c,
22410                                                              metadata <rounding mode>,
22411                                                              metadata <exception behavior>)
22412
22413except that it is unspecified whether rounding will be performed between the
22414multiplication and addition steps. Fusion is not guaranteed, even if the target
22415platform supports it.
22416If a fused multiply-add is required, the corresponding
22417:ref:`llvm.experimental.constrained.fma <int_fma>` intrinsic function should be
22418used instead.
22419This never sets errno, just as '``llvm.experimental.constrained.fma.*``'.
22420
22421Constrained libm-equivalent Intrinsics
22422--------------------------------------
22423
22424In addition to the basic floating-point operations for which constrained
22425intrinsics are described above, there are constrained versions of various
22426operations which provide equivalent behavior to a corresponding libm function.
22427These intrinsics allow the precise behavior of these operations with respect to
22428rounding mode and exception behavior to be controlled.
22429
22430As with the basic constrained floating-point intrinsics, the rounding mode
22431and exception behavior arguments only control the behavior of the optimizer.
22432They do not change the runtime floating-point environment.
22433
22434
22435'``llvm.experimental.constrained.sqrt``' Intrinsic
22436^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22437
22438Syntax:
22439"""""""
22440
22441::
22442
22443      declare <type>
22444      @llvm.experimental.constrained.sqrt(<type> <op1>,
22445                                          metadata <rounding mode>,
22446                                          metadata <exception behavior>)
22447
22448Overview:
22449"""""""""
22450
22451The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root
22452of the specified value, returning the same value as the libm '``sqrt``'
22453functions would, but without setting ``errno``.
22454
22455Arguments:
22456""""""""""
22457
22458The first argument and the return type are floating-point numbers of the same
22459type.
22460
22461The second and third arguments specify the rounding mode and exception
22462behavior as described above.
22463
22464Semantics:
22465""""""""""
22466
22467This function returns the nonnegative square root of the specified value.
22468If the value is less than negative zero, a floating-point exception occurs
22469and the return value is architecture specific.
22470
22471
22472'``llvm.experimental.constrained.pow``' Intrinsic
22473^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22474
22475Syntax:
22476"""""""
22477
22478::
22479
22480      declare <type>
22481      @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>,
22482                                         metadata <rounding mode>,
22483                                         metadata <exception behavior>)
22484
22485Overview:
22486"""""""""
22487
22488The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand
22489raised to the (positive or negative) power specified by the second operand.
22490
22491Arguments:
22492""""""""""
22493
22494The first two arguments and the return value are floating-point numbers of the
22495same type.  The second argument specifies the power to which the first argument
22496should be raised.
22497
22498The third and fourth arguments specify the rounding mode and exception
22499behavior as described above.
22500
22501Semantics:
22502""""""""""
22503
22504This function returns the first value raised to the second power,
22505returning the same values as the libm ``pow`` functions would, and
22506handles error conditions in the same way.
22507
22508
22509'``llvm.experimental.constrained.powi``' Intrinsic
22510^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22511
22512Syntax:
22513"""""""
22514
22515::
22516
22517      declare <type>
22518      @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>,
22519                                          metadata <rounding mode>,
22520                                          metadata <exception behavior>)
22521
22522Overview:
22523"""""""""
22524
22525The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand
22526raised to the (positive or negative) power specified by the second operand. The
22527order of evaluation of multiplications is not defined. When a vector of
22528floating-point type is used, the second argument remains a scalar integer value.
22529
22530
22531Arguments:
22532""""""""""
22533
22534The first argument and the return value are floating-point numbers of the same
22535type.  The second argument is a 32-bit signed integer specifying the power to
22536which the first argument should be raised.
22537
22538The third and fourth arguments specify the rounding mode and exception
22539behavior as described above.
22540
22541Semantics:
22542""""""""""
22543
22544This function returns the first value raised to the second power with an
22545unspecified sequence of rounding operations.
22546
22547
22548'``llvm.experimental.constrained.sin``' Intrinsic
22549^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22550
22551Syntax:
22552"""""""
22553
22554::
22555
22556      declare <type>
22557      @llvm.experimental.constrained.sin(<type> <op1>,
22558                                         metadata <rounding mode>,
22559                                         metadata <exception behavior>)
22560
22561Overview:
22562"""""""""
22563
22564The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the
22565first operand.
22566
22567Arguments:
22568""""""""""
22569
22570The first argument and the return type are floating-point numbers of the same
22571type.
22572
22573The second and third arguments specify the rounding mode and exception
22574behavior as described above.
22575
22576Semantics:
22577""""""""""
22578
22579This function returns the sine of the specified operand, returning the
22580same values as the libm ``sin`` functions would, and handles error
22581conditions in the same way.
22582
22583
22584'``llvm.experimental.constrained.cos``' Intrinsic
22585^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22586
22587Syntax:
22588"""""""
22589
22590::
22591
22592      declare <type>
22593      @llvm.experimental.constrained.cos(<type> <op1>,
22594                                         metadata <rounding mode>,
22595                                         metadata <exception behavior>)
22596
22597Overview:
22598"""""""""
22599
22600The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the
22601first operand.
22602
22603Arguments:
22604""""""""""
22605
22606The first argument and the return type are floating-point numbers of the same
22607type.
22608
22609The second and third arguments specify the rounding mode and exception
22610behavior as described above.
22611
22612Semantics:
22613""""""""""
22614
22615This function returns the cosine of the specified operand, returning the
22616same values as the libm ``cos`` functions would, and handles error
22617conditions in the same way.
22618
22619
22620'``llvm.experimental.constrained.exp``' Intrinsic
22621^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22622
22623Syntax:
22624"""""""
22625
22626::
22627
22628      declare <type>
22629      @llvm.experimental.constrained.exp(<type> <op1>,
22630                                         metadata <rounding mode>,
22631                                         metadata <exception behavior>)
22632
22633Overview:
22634"""""""""
22635
22636The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e
22637exponential of the specified value.
22638
22639Arguments:
22640""""""""""
22641
22642The first argument and the return value are floating-point numbers of the same
22643type.
22644
22645The second and third arguments specify the rounding mode and exception
22646behavior as described above.
22647
22648Semantics:
22649""""""""""
22650
22651This function returns the same values as the libm ``exp`` functions
22652would, and handles error conditions in the same way.
22653
22654
22655'``llvm.experimental.constrained.exp2``' Intrinsic
22656^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22657
22658Syntax:
22659"""""""
22660
22661::
22662
22663      declare <type>
22664      @llvm.experimental.constrained.exp2(<type> <op1>,
22665                                          metadata <rounding mode>,
22666                                          metadata <exception behavior>)
22667
22668Overview:
22669"""""""""
22670
22671The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2
22672exponential of the specified value.
22673
22674
22675Arguments:
22676""""""""""
22677
22678The first argument and the return value are floating-point numbers of the same
22679type.
22680
22681The second and third arguments specify the rounding mode and exception
22682behavior as described above.
22683
22684Semantics:
22685""""""""""
22686
22687This function returns the same values as the libm ``exp2`` functions
22688would, and handles error conditions in the same way.
22689
22690
22691'``llvm.experimental.constrained.log``' Intrinsic
22692^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22693
22694Syntax:
22695"""""""
22696
22697::
22698
22699      declare <type>
22700      @llvm.experimental.constrained.log(<type> <op1>,
22701                                         metadata <rounding mode>,
22702                                         metadata <exception behavior>)
22703
22704Overview:
22705"""""""""
22706
22707The '``llvm.experimental.constrained.log``' intrinsic computes the base-e
22708logarithm of the specified value.
22709
22710Arguments:
22711""""""""""
22712
22713The first argument and the return value are floating-point numbers of the same
22714type.
22715
22716The second and third arguments specify the rounding mode and exception
22717behavior as described above.
22718
22719
22720Semantics:
22721""""""""""
22722
22723This function returns the same values as the libm ``log`` functions
22724would, and handles error conditions in the same way.
22725
22726
22727'``llvm.experimental.constrained.log10``' Intrinsic
22728^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22729
22730Syntax:
22731"""""""
22732
22733::
22734
22735      declare <type>
22736      @llvm.experimental.constrained.log10(<type> <op1>,
22737                                           metadata <rounding mode>,
22738                                           metadata <exception behavior>)
22739
22740Overview:
22741"""""""""
22742
22743The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10
22744logarithm of the specified value.
22745
22746Arguments:
22747""""""""""
22748
22749The first argument and the return value are floating-point numbers of the same
22750type.
22751
22752The second and third arguments specify the rounding mode and exception
22753behavior as described above.
22754
22755Semantics:
22756""""""""""
22757
22758This function returns the same values as the libm ``log10`` functions
22759would, and handles error conditions in the same way.
22760
22761
22762'``llvm.experimental.constrained.log2``' Intrinsic
22763^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22764
22765Syntax:
22766"""""""
22767
22768::
22769
22770      declare <type>
22771      @llvm.experimental.constrained.log2(<type> <op1>,
22772                                          metadata <rounding mode>,
22773                                          metadata <exception behavior>)
22774
22775Overview:
22776"""""""""
22777
22778The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2
22779logarithm of the specified value.
22780
22781Arguments:
22782""""""""""
22783
22784The first argument and the return value are floating-point numbers of the same
22785type.
22786
22787The second and third arguments specify the rounding mode and exception
22788behavior as described above.
22789
22790Semantics:
22791""""""""""
22792
22793This function returns the same values as the libm ``log2`` functions
22794would, and handles error conditions in the same way.
22795
22796
22797'``llvm.experimental.constrained.rint``' Intrinsic
22798^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22799
22800Syntax:
22801"""""""
22802
22803::
22804
22805      declare <type>
22806      @llvm.experimental.constrained.rint(<type> <op1>,
22807                                          metadata <rounding mode>,
22808                                          metadata <exception behavior>)
22809
22810Overview:
22811"""""""""
22812
22813The '``llvm.experimental.constrained.rint``' intrinsic returns the first
22814operand rounded to the nearest integer. It may raise an inexact floating-point
22815exception if the operand is not an integer.
22816
22817Arguments:
22818""""""""""
22819
22820The first argument and the return value are floating-point numbers of the same
22821type.
22822
22823The second and third arguments specify the rounding mode and exception
22824behavior as described above.
22825
22826Semantics:
22827""""""""""
22828
22829This function returns the same values as the libm ``rint`` functions
22830would, and handles error conditions in the same way.  The rounding mode is
22831described, not determined, by the rounding mode argument.  The actual rounding
22832mode is determined by the runtime floating-point environment.  The rounding
22833mode argument is only intended as information to the compiler.
22834
22835
22836'``llvm.experimental.constrained.lrint``' Intrinsic
22837^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22838
22839Syntax:
22840"""""""
22841
22842::
22843
22844      declare <inttype>
22845      @llvm.experimental.constrained.lrint(<fptype> <op1>,
22846                                           metadata <rounding mode>,
22847                                           metadata <exception behavior>)
22848
22849Overview:
22850"""""""""
22851
22852The '``llvm.experimental.constrained.lrint``' intrinsic returns the first
22853operand rounded to the nearest integer. An inexact floating-point exception
22854will be raised if the operand is not an integer. An invalid exception is
22855raised if the result is too large to fit into a supported integer type,
22856and in this case the result is undefined.
22857
22858Arguments:
22859""""""""""
22860
22861The first argument is a floating-point number. The return value is an
22862integer type. Not all types are supported on all targets. The supported
22863types are the same as the ``llvm.lrint`` intrinsic and the ``lrint``
22864libm functions.
22865
22866The second and third arguments specify the rounding mode and exception
22867behavior as described above.
22868
22869Semantics:
22870""""""""""
22871
22872This function returns the same values as the libm ``lrint`` functions
22873would, and handles error conditions in the same way.
22874
22875The rounding mode is described, not determined, by the rounding mode
22876argument.  The actual rounding mode is determined by the runtime floating-point
22877environment.  The rounding mode argument is only intended as information
22878to the compiler.
22879
22880If the runtime floating-point environment is using the default rounding mode
22881then the results will be the same as the llvm.lrint intrinsic.
22882
22883
22884'``llvm.experimental.constrained.llrint``' Intrinsic
22885^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22886
22887Syntax:
22888"""""""
22889
22890::
22891
22892      declare <inttype>
22893      @llvm.experimental.constrained.llrint(<fptype> <op1>,
22894                                            metadata <rounding mode>,
22895                                            metadata <exception behavior>)
22896
22897Overview:
22898"""""""""
22899
22900The '``llvm.experimental.constrained.llrint``' intrinsic returns the first
22901operand rounded to the nearest integer. An inexact floating-point exception
22902will be raised if the operand is not an integer. An invalid exception is
22903raised if the result is too large to fit into a supported integer type,
22904and in this case the result is undefined.
22905
22906Arguments:
22907""""""""""
22908
22909The first argument is a floating-point number. The return value is an
22910integer type. Not all types are supported on all targets. The supported
22911types are the same as the ``llvm.llrint`` intrinsic and the ``llrint``
22912libm functions.
22913
22914The second and third arguments specify the rounding mode and exception
22915behavior as described above.
22916
22917Semantics:
22918""""""""""
22919
22920This function returns the same values as the libm ``llrint`` functions
22921would, and handles error conditions in the same way.
22922
22923The rounding mode is described, not determined, by the rounding mode
22924argument.  The actual rounding mode is determined by the runtime floating-point
22925environment.  The rounding mode argument is only intended as information
22926to the compiler.
22927
22928If the runtime floating-point environment is using the default rounding mode
22929then the results will be the same as the llvm.llrint intrinsic.
22930
22931
22932'``llvm.experimental.constrained.nearbyint``' Intrinsic
22933^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22934
22935Syntax:
22936"""""""
22937
22938::
22939
22940      declare <type>
22941      @llvm.experimental.constrained.nearbyint(<type> <op1>,
22942                                               metadata <rounding mode>,
22943                                               metadata <exception behavior>)
22944
22945Overview:
22946"""""""""
22947
22948The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first
22949operand rounded to the nearest integer. It will not raise an inexact
22950floating-point exception if the operand is not an integer.
22951
22952
22953Arguments:
22954""""""""""
22955
22956The first argument and the return value are floating-point numbers of the same
22957type.
22958
22959The second and third arguments specify the rounding mode and exception
22960behavior as described above.
22961
22962Semantics:
22963""""""""""
22964
22965This function returns the same values as the libm ``nearbyint`` functions
22966would, and handles error conditions in the same way.  The rounding mode is
22967described, not determined, by the rounding mode argument.  The actual rounding
22968mode is determined by the runtime floating-point environment.  The rounding
22969mode argument is only intended as information to the compiler.
22970
22971
22972'``llvm.experimental.constrained.maxnum``' Intrinsic
22973^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22974
22975Syntax:
22976"""""""
22977
22978::
22979
22980      declare <type>
22981      @llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2>
22982                                            metadata <exception behavior>)
22983
22984Overview:
22985"""""""""
22986
22987The '``llvm.experimental.constrained.maxnum``' intrinsic returns the maximum
22988of the two arguments.
22989
22990Arguments:
22991""""""""""
22992
22993The first two arguments and the return value are floating-point numbers
22994of the same type.
22995
22996The third argument specifies the exception behavior as described above.
22997
22998Semantics:
22999""""""""""
23000
23001This function follows the IEEE-754 semantics for maxNum.
23002
23003
23004'``llvm.experimental.constrained.minnum``' Intrinsic
23005^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23006
23007Syntax:
23008"""""""
23009
23010::
23011
23012      declare <type>
23013      @llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2>
23014                                            metadata <exception behavior>)
23015
23016Overview:
23017"""""""""
23018
23019The '``llvm.experimental.constrained.minnum``' intrinsic returns the minimum
23020of the two arguments.
23021
23022Arguments:
23023""""""""""
23024
23025The first two arguments and the return value are floating-point numbers
23026of the same type.
23027
23028The third argument specifies the exception behavior as described above.
23029
23030Semantics:
23031""""""""""
23032
23033This function follows the IEEE-754 semantics for minNum.
23034
23035
23036'``llvm.experimental.constrained.maximum``' Intrinsic
23037^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23038
23039Syntax:
23040"""""""
23041
23042::
23043
23044      declare <type>
23045      @llvm.experimental.constrained.maximum(<type> <op1>, <type> <op2>
23046                                             metadata <exception behavior>)
23047
23048Overview:
23049"""""""""
23050
23051The '``llvm.experimental.constrained.maximum``' intrinsic returns the maximum
23052of the two arguments, propagating NaNs and treating -0.0 as less than +0.0.
23053
23054Arguments:
23055""""""""""
23056
23057The first two arguments and the return value are floating-point numbers
23058of the same type.
23059
23060The third argument specifies the exception behavior as described above.
23061
23062Semantics:
23063""""""""""
23064
23065This function follows semantics specified in the draft of IEEE 754-2018.
23066
23067
23068'``llvm.experimental.constrained.minimum``' Intrinsic
23069^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23070
23071Syntax:
23072"""""""
23073
23074::
23075
23076      declare <type>
23077      @llvm.experimental.constrained.minimum(<type> <op1>, <type> <op2>
23078                                             metadata <exception behavior>)
23079
23080Overview:
23081"""""""""
23082
23083The '``llvm.experimental.constrained.minimum``' intrinsic returns the minimum
23084of the two arguments, propagating NaNs and treating -0.0 as less than +0.0.
23085
23086Arguments:
23087""""""""""
23088
23089The first two arguments and the return value are floating-point numbers
23090of the same type.
23091
23092The third argument specifies the exception behavior as described above.
23093
23094Semantics:
23095""""""""""
23096
23097This function follows semantics specified in the draft of IEEE 754-2018.
23098
23099
23100'``llvm.experimental.constrained.ceil``' Intrinsic
23101^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23102
23103Syntax:
23104"""""""
23105
23106::
23107
23108      declare <type>
23109      @llvm.experimental.constrained.ceil(<type> <op1>,
23110                                          metadata <exception behavior>)
23111
23112Overview:
23113"""""""""
23114
23115The '``llvm.experimental.constrained.ceil``' intrinsic returns the ceiling of the
23116first operand.
23117
23118Arguments:
23119""""""""""
23120
23121The first argument and the return value are floating-point numbers of the same
23122type.
23123
23124The second argument specifies the exception behavior as described above.
23125
23126Semantics:
23127""""""""""
23128
23129This function returns the same values as the libm ``ceil`` functions
23130would and handles error conditions in the same way.
23131
23132
23133'``llvm.experimental.constrained.floor``' Intrinsic
23134^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23135
23136Syntax:
23137"""""""
23138
23139::
23140
23141      declare <type>
23142      @llvm.experimental.constrained.floor(<type> <op1>,
23143                                           metadata <exception behavior>)
23144
23145Overview:
23146"""""""""
23147
23148The '``llvm.experimental.constrained.floor``' intrinsic returns the floor of the
23149first operand.
23150
23151Arguments:
23152""""""""""
23153
23154The first argument and the return value are floating-point numbers of the same
23155type.
23156
23157The second argument specifies the exception behavior as described above.
23158
23159Semantics:
23160""""""""""
23161
23162This function returns the same values as the libm ``floor`` functions
23163would and handles error conditions in the same way.
23164
23165
23166'``llvm.experimental.constrained.round``' Intrinsic
23167^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23168
23169Syntax:
23170"""""""
23171
23172::
23173
23174      declare <type>
23175      @llvm.experimental.constrained.round(<type> <op1>,
23176                                           metadata <exception behavior>)
23177
23178Overview:
23179"""""""""
23180
23181The '``llvm.experimental.constrained.round``' intrinsic returns the first
23182operand rounded to the nearest integer.
23183
23184Arguments:
23185""""""""""
23186
23187The first argument and the return value are floating-point numbers of the same
23188type.
23189
23190The second argument specifies the exception behavior as described above.
23191
23192Semantics:
23193""""""""""
23194
23195This function returns the same values as the libm ``round`` functions
23196would and handles error conditions in the same way.
23197
23198
23199'``llvm.experimental.constrained.roundeven``' Intrinsic
23200^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23201
23202Syntax:
23203"""""""
23204
23205::
23206
23207      declare <type>
23208      @llvm.experimental.constrained.roundeven(<type> <op1>,
23209                                               metadata <exception behavior>)
23210
23211Overview:
23212"""""""""
23213
23214The '``llvm.experimental.constrained.roundeven``' intrinsic returns the first
23215operand rounded to the nearest integer in floating-point format, rounding
23216halfway cases to even (that is, to the nearest value that is an even integer),
23217regardless of the current rounding direction.
23218
23219Arguments:
23220""""""""""
23221
23222The first argument and the return value are floating-point numbers of the same
23223type.
23224
23225The second argument specifies the exception behavior as described above.
23226
23227Semantics:
23228""""""""""
23229
23230This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It
23231also behaves in the same way as C standard function ``roundeven`` and can signal
23232the invalid operation exception for a SNAN operand.
23233
23234
23235'``llvm.experimental.constrained.lround``' Intrinsic
23236^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23237
23238Syntax:
23239"""""""
23240
23241::
23242
23243      declare <inttype>
23244      @llvm.experimental.constrained.lround(<fptype> <op1>,
23245                                            metadata <exception behavior>)
23246
23247Overview:
23248"""""""""
23249
23250The '``llvm.experimental.constrained.lround``' intrinsic returns the first
23251operand rounded to the nearest integer with ties away from zero.  It will
23252raise an inexact floating-point exception if the operand is not an integer.
23253An invalid exception is raised if the result is too large to fit into a
23254supported integer type, and in this case the result is undefined.
23255
23256Arguments:
23257""""""""""
23258
23259The first argument is a floating-point number. The return value is an
23260integer type. Not all types are supported on all targets. The supported
23261types are the same as the ``llvm.lround`` intrinsic and the ``lround``
23262libm functions.
23263
23264The second argument specifies the exception behavior as described above.
23265
23266Semantics:
23267""""""""""
23268
23269This function returns the same values as the libm ``lround`` functions
23270would and handles error conditions in the same way.
23271
23272
23273'``llvm.experimental.constrained.llround``' Intrinsic
23274^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23275
23276Syntax:
23277"""""""
23278
23279::
23280
23281      declare <inttype>
23282      @llvm.experimental.constrained.llround(<fptype> <op1>,
23283                                             metadata <exception behavior>)
23284
23285Overview:
23286"""""""""
23287
23288The '``llvm.experimental.constrained.llround``' intrinsic returns the first
23289operand rounded to the nearest integer with ties away from zero. It will
23290raise an inexact floating-point exception if the operand is not an integer.
23291An invalid exception is raised if the result is too large to fit into a
23292supported integer type, and in this case the result is undefined.
23293
23294Arguments:
23295""""""""""
23296
23297The first argument is a floating-point number. The return value is an
23298integer type. Not all types are supported on all targets. The supported
23299types are the same as the ``llvm.llround`` intrinsic and the ``llround``
23300libm functions.
23301
23302The second argument specifies the exception behavior as described above.
23303
23304Semantics:
23305""""""""""
23306
23307This function returns the same values as the libm ``llround`` functions
23308would and handles error conditions in the same way.
23309
23310
23311'``llvm.experimental.constrained.trunc``' Intrinsic
23312^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23313
23314Syntax:
23315"""""""
23316
23317::
23318
23319      declare <type>
23320      @llvm.experimental.constrained.trunc(<type> <op1>,
23321                                           metadata <exception behavior>)
23322
23323Overview:
23324"""""""""
23325
23326The '``llvm.experimental.constrained.trunc``' intrinsic returns the first
23327operand rounded to the nearest integer not larger in magnitude than the
23328operand.
23329
23330Arguments:
23331""""""""""
23332
23333The first argument and the return value are floating-point numbers of the same
23334type.
23335
23336The second argument specifies the exception behavior as described above.
23337
23338Semantics:
23339""""""""""
23340
23341This function returns the same values as the libm ``trunc`` functions
23342would and handles error conditions in the same way.
23343
23344.. _int_experimental_noalias_scope_decl:
23345
23346'``llvm.experimental.noalias.scope.decl``' Intrinsic
23347^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23348
23349Syntax:
23350"""""""
23351
23352
23353::
23354
23355      declare void @llvm.experimental.noalias.scope.decl(metadata !id.scope.list)
23356
23357Overview:
23358"""""""""
23359
23360The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a
23361noalias scope is declared. When the intrinsic is duplicated, a decision must
23362also be made about the scope: depending on the reason of the duplication,
23363the scope might need to be duplicated as well.
23364
23365
23366Arguments:
23367""""""""""
23368
23369The ``!id.scope.list`` argument is metadata that is a list of ``noalias``
23370metadata references. The format is identical to that required for ``noalias``
23371metadata. This list must have exactly one element.
23372
23373Semantics:
23374""""""""""
23375
23376The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a
23377noalias scope is declared. When the intrinsic is duplicated, a decision must
23378also be made about the scope: depending on the reason of the duplication,
23379the scope might need to be duplicated as well.
23380
23381For example, when the intrinsic is used inside a loop body, and that loop is
23382unrolled, the associated noalias scope must also be duplicated. Otherwise, the
23383noalias property it signifies would spill across loop iterations, whereas it
23384was only valid within a single iteration.
23385
23386.. code-block:: llvm
23387
23388  ; This examples shows two possible positions for noalias.decl and how they impact the semantics:
23389  ; If it is outside the loop (Version 1), then %a and %b are noalias across *all* iterations.
23390  ; If it is inside the loop (Version 2), then %a and %b are noalias only within *one* iteration.
23391  declare void @decl_in_loop(i8* %a.base, i8* %b.base) {
23392  entry:
23393    ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 1: noalias decl outside loop
23394    br label %loop
23395
23396  loop:
23397    %a = phi i8* [ %a.base, %entry ], [ %a.inc, %loop ]
23398    %b = phi i8* [ %b.base, %entry ], [ %b.inc, %loop ]
23399    ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 2: noalias decl inside loop
23400    %val = load i8, i8* %a, !alias.scope !2
23401    store i8 %val, i8* %b, !noalias !2
23402    %a.inc = getelementptr inbounds i8, i8* %a, i64 1
23403    %b.inc = getelementptr inbounds i8, i8* %b, i64 1
23404    %cond = call i1 @cond()
23405    br i1 %cond, label %loop, label %exit
23406
23407  exit:
23408    ret void
23409  }
23410
23411  !0 = !{!0} ; domain
23412  !1 = !{!1, !0} ; scope
23413  !2 = !{!1} ; scope list
23414
23415Multiple calls to `@llvm.experimental.noalias.scope.decl` for the same scope
23416are possible, but one should never dominate another. Violations are pointed out
23417by the verifier as they indicate a problem in either a transformation pass or
23418the input.
23419
23420
23421Floating Point Environment Manipulation intrinsics
23422--------------------------------------------------
23423
23424These functions read or write floating point environment, such as rounding
23425mode or state of floating point exceptions. Altering the floating point
23426environment requires special care. See :ref:`Floating Point Environment <floatenv>`.
23427
23428'``llvm.flt.rounds``' Intrinsic
23429^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23430
23431Syntax:
23432"""""""
23433
23434::
23435
23436      declare i32 @llvm.flt.rounds()
23437
23438Overview:
23439"""""""""
23440
23441The '``llvm.flt.rounds``' intrinsic reads the current rounding mode.
23442
23443Semantics:
23444""""""""""
23445
23446The '``llvm.flt.rounds``' intrinsic returns the current rounding mode.
23447Encoding of the returned values is same as the result of ``FLT_ROUNDS``,
23448specified by C standard:
23449
23450::
23451
23452    0  - toward zero
23453    1  - to nearest, ties to even
23454    2  - toward positive infinity
23455    3  - toward negative infinity
23456    4  - to nearest, ties away from zero
23457
23458Other values may be used to represent additional rounding modes, supported by a
23459target. These values are target-specific.
23460
23461
23462'``llvm.set.rounding``' Intrinsic
23463^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23464
23465Syntax:
23466"""""""
23467
23468::
23469
23470      declare void @llvm.set.rounding(i32 <val>)
23471
23472Overview:
23473"""""""""
23474
23475The '``llvm.set.rounding``' intrinsic sets current rounding mode.
23476
23477Arguments:
23478""""""""""
23479
23480The argument is the required rounding mode. Encoding of rounding mode is
23481the same as used by '``llvm.flt.rounds``'.
23482
23483Semantics:
23484""""""""""
23485
23486The '``llvm.set.rounding``' intrinsic sets the current rounding mode. It is
23487similar to C library function 'fesetround', however this intrinsic does not
23488return any value and uses platform-independent representation of IEEE rounding
23489modes.
23490
23491
23492Floating-Point Test Intrinsics
23493------------------------------
23494
23495These functions get properties of floating-point values.
23496
23497
23498'``llvm.is.fpclass``' Intrinsic
23499^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23500
23501Syntax:
23502"""""""
23503
23504::
23505
23506      declare i1 @llvm.is.fpclass(<fptype> <op>, i32 <test>)
23507      declare <N x i1> @llvm.is.fpclass(<vector-fptype> <op>, i32 <test>)
23508
23509Overview:
23510"""""""""
23511
23512The '``llvm.is.fpclass``' intrinsic returns a boolean value or vector of boolean
23513values depending on whether the first argument satisfies the test specified by
23514the second argument.
23515
23516If the first argument is a floating-point scalar, then the result type is a
23517boolean (:ref:`i1 <t_integer>`).
23518
23519If the first argument is a floating-point vector, then the result type is a
23520vector of boolean with the same number of elements as the first argument.
23521
23522Arguments:
23523""""""""""
23524
23525The first argument to the '``llvm.is.fpclass``' intrinsic must be
23526:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
23527of floating-point values.
23528
23529The second argument specifies, which tests to perform. It must be a compile-time
23530integer constant, each bit in which specifies floating-point class:
23531
23532+-------+----------------------+
23533| Bit # | floating-point class |
23534+=======+======================+
23535| 0     | Signaling NaN        |
23536+-------+----------------------+
23537| 1     | Quiet NaN            |
23538+-------+----------------------+
23539| 2     | Negative infinity    |
23540+-------+----------------------+
23541| 3     | Negative normal      |
23542+-------+----------------------+
23543| 4     | Negative subnormal   |
23544+-------+----------------------+
23545| 5     | Negative zero        |
23546+-------+----------------------+
23547| 6     | Positive zero        |
23548+-------+----------------------+
23549| 7     | Positive subnormal   |
23550+-------+----------------------+
23551| 8     | Positive normal      |
23552+-------+----------------------+
23553| 9     | Positive infinity    |
23554+-------+----------------------+
23555
23556Semantics:
23557""""""""""
23558
23559The function checks if ``op`` belongs to any of the floating-point classes
23560specified by ``test``. If ``op`` is a vector, then the check is made element by
23561element. Each check yields an :ref:`i1 <t_integer>` result, which is ``true``,
23562if the element value satisfies the specified test. The argument ``test`` is a
23563bit mask where each bit specifies floating-point class to test. For example, the
23564value 0x108 makes test for normal value, - bits 3 and 8 in it are set, which
23565means that the function returns ``true`` if ``op`` is a positive or negative
23566normal value. The function never raises floating-point exceptions.
23567
23568
23569General Intrinsics
23570------------------
23571
23572This class of intrinsics is designed to be generic and has no specific
23573purpose.
23574
23575'``llvm.var.annotation``' Intrinsic
23576^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23577
23578Syntax:
23579"""""""
23580
23581::
23582
23583      declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32  <int>)
23584
23585Overview:
23586"""""""""
23587
23588The '``llvm.var.annotation``' intrinsic.
23589
23590Arguments:
23591""""""""""
23592
23593The first argument is a pointer to a value, the second is a pointer to a
23594global string, the third is a pointer to a global string which is the
23595source file name, and the last argument is the line number.
23596
23597Semantics:
23598""""""""""
23599
23600This intrinsic allows annotation of local variables with arbitrary
23601strings. This can be useful for special purpose optimizations that want
23602to look for these annotations. These have no other defined use; they are
23603ignored by code generation and optimization.
23604
23605'``llvm.ptr.annotation.*``' Intrinsic
23606^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23607
23608Syntax:
23609"""""""
23610
23611This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a
23612pointer to an integer of any width. *NOTE* you must specify an address space for
23613the pointer. The identifier for the default address space is the integer
23614'``0``'.
23615
23616::
23617
23618      declare i8*   @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32  <int>)
23619      declare i16*  @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32  <int>)
23620      declare i32*  @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32  <int>)
23621      declare i64*  @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32  <int>)
23622      declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32  <int>)
23623
23624Overview:
23625"""""""""
23626
23627The '``llvm.ptr.annotation``' intrinsic.
23628
23629Arguments:
23630""""""""""
23631
23632The first argument is a pointer to an integer value of arbitrary bitwidth
23633(result of some expression), the second is a pointer to a global string, the
23634third is a pointer to a global string which is the source file name, and the
23635last argument is the line number. It returns the value of the first argument.
23636
23637Semantics:
23638""""""""""
23639
23640This intrinsic allows annotation of a pointer to an integer with arbitrary
23641strings. This can be useful for special purpose optimizations that want to look
23642for these annotations. These have no other defined use; transformations preserve
23643annotations on a best-effort basis but are allowed to replace the intrinsic with
23644its first argument without breaking semantics and the intrinsic is completely
23645dropped during instruction selection.
23646
23647'``llvm.annotation.*``' Intrinsic
23648^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23649
23650Syntax:
23651"""""""
23652
23653This is an overloaded intrinsic. You can use '``llvm.annotation``' on
23654any integer bit width.
23655
23656::
23657
23658      declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32  <int>)
23659      declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32  <int>)
23660      declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32  <int>)
23661      declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32  <int>)
23662      declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32  <int>)
23663
23664Overview:
23665"""""""""
23666
23667The '``llvm.annotation``' intrinsic.
23668
23669Arguments:
23670""""""""""
23671
23672The first argument is an integer value (result of some expression), the
23673second is a pointer to a global string, the third is a pointer to a
23674global string which is the source file name, and the last argument is
23675the line number. It returns the value of the first argument.
23676
23677Semantics:
23678""""""""""
23679
23680This intrinsic allows annotations to be put on arbitrary expressions with
23681arbitrary strings. This can be useful for special purpose optimizations that
23682want to look for these annotations. These have no other defined use;
23683transformations preserve annotations on a best-effort basis but are allowed to
23684replace the intrinsic with its first argument without breaking semantics and the
23685intrinsic is completely dropped during instruction selection.
23686
23687'``llvm.codeview.annotation``' Intrinsic
23688^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23689
23690Syntax:
23691"""""""
23692
23693This annotation emits a label at its program point and an associated
23694``S_ANNOTATION`` codeview record with some additional string metadata. This is
23695used to implement MSVC's ``__annotation`` intrinsic. It is marked
23696``noduplicate``, so calls to this intrinsic prevent inlining and should be
23697considered expensive.
23698
23699::
23700
23701      declare void @llvm.codeview.annotation(metadata)
23702
23703Arguments:
23704""""""""""
23705
23706The argument should be an MDTuple containing any number of MDStrings.
23707
23708'``llvm.trap``' Intrinsic
23709^^^^^^^^^^^^^^^^^^^^^^^^^
23710
23711Syntax:
23712"""""""
23713
23714::
23715
23716      declare void @llvm.trap() cold noreturn nounwind
23717
23718Overview:
23719"""""""""
23720
23721The '``llvm.trap``' intrinsic.
23722
23723Arguments:
23724""""""""""
23725
23726None.
23727
23728Semantics:
23729""""""""""
23730
23731This intrinsic is lowered to the target dependent trap instruction. If
23732the target does not have a trap instruction, this intrinsic will be
23733lowered to a call of the ``abort()`` function.
23734
23735'``llvm.debugtrap``' Intrinsic
23736^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23737
23738Syntax:
23739"""""""
23740
23741::
23742
23743      declare void @llvm.debugtrap() nounwind
23744
23745Overview:
23746"""""""""
23747
23748The '``llvm.debugtrap``' intrinsic.
23749
23750Arguments:
23751""""""""""
23752
23753None.
23754
23755Semantics:
23756""""""""""
23757
23758This intrinsic is lowered to code which is intended to cause an
23759execution trap with the intention of requesting the attention of a
23760debugger.
23761
23762'``llvm.ubsantrap``' Intrinsic
23763^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23764
23765Syntax:
23766"""""""
23767
23768::
23769
23770      declare void @llvm.ubsantrap(i8 immarg) cold noreturn nounwind
23771
23772Overview:
23773"""""""""
23774
23775The '``llvm.ubsantrap``' intrinsic.
23776
23777Arguments:
23778""""""""""
23779
23780An integer describing the kind of failure detected.
23781
23782Semantics:
23783""""""""""
23784
23785This intrinsic is lowered to code which is intended to cause an execution trap,
23786embedding the argument into encoding of that trap somehow to discriminate
23787crashes if possible.
23788
23789Equivalent to ``@llvm.trap`` for targets that do not support this behaviour.
23790
23791'``llvm.stackprotector``' Intrinsic
23792^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23793
23794Syntax:
23795"""""""
23796
23797::
23798
23799      declare void @llvm.stackprotector(i8* <guard>, i8** <slot>)
23800
23801Overview:
23802"""""""""
23803
23804The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it
23805onto the stack at ``slot``. The stack slot is adjusted to ensure that it
23806is placed on the stack before local variables.
23807
23808Arguments:
23809""""""""""
23810
23811The ``llvm.stackprotector`` intrinsic requires two pointer arguments.
23812The first argument is the value loaded from the stack guard
23813``@__stack_chk_guard``. The second variable is an ``alloca`` that has
23814enough space to hold the value of the guard.
23815
23816Semantics:
23817""""""""""
23818
23819This intrinsic causes the prologue/epilogue inserter to force the position of
23820the ``AllocaInst`` stack slot to be before local variables on the stack. This is
23821to ensure that if a local variable on the stack is overwritten, it will destroy
23822the value of the guard. When the function exits, the guard on the stack is
23823checked against the original guard by ``llvm.stackprotectorcheck``. If they are
23824different, then ``llvm.stackprotectorcheck`` causes the program to abort by
23825calling the ``__stack_chk_fail()`` function.
23826
23827'``llvm.stackguard``' Intrinsic
23828^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23829
23830Syntax:
23831"""""""
23832
23833::
23834
23835      declare i8* @llvm.stackguard()
23836
23837Overview:
23838"""""""""
23839
23840The ``llvm.stackguard`` intrinsic returns the system stack guard value.
23841
23842It should not be generated by frontends, since it is only for internal usage.
23843The reason why we create this intrinsic is that we still support IR form Stack
23844Protector in FastISel.
23845
23846Arguments:
23847""""""""""
23848
23849None.
23850
23851Semantics:
23852""""""""""
23853
23854On some platforms, the value returned by this intrinsic remains unchanged
23855between loads in the same thread. On other platforms, it returns the same
23856global variable value, if any, e.g. ``@__stack_chk_guard``.
23857
23858Currently some platforms have IR-level customized stack guard loading (e.g.
23859X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be
23860in the future.
23861
23862'``llvm.objectsize``' Intrinsic
23863^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23864
23865Syntax:
23866"""""""
23867
23868::
23869
23870      declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
23871      declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
23872
23873Overview:
23874"""""""""
23875
23876The ``llvm.objectsize`` intrinsic is designed to provide information to the
23877optimizer to determine whether a) an operation (like memcpy) will overflow a
23878buffer that corresponds to an object, or b) that a runtime check for overflow
23879isn't necessary. An object in this context means an allocation of a specific
23880class, structure, array, or other object.
23881
23882Arguments:
23883""""""""""
23884
23885The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a
23886pointer to or into the ``object``. The second argument determines whether
23887``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size is
23888unknown. The third argument controls how ``llvm.objectsize`` acts when ``null``
23889in address space 0 is used as its pointer argument. If it's ``false``,
23890``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if
23891the ``null`` is in a non-zero address space or if ``true`` is given for the
23892third argument of ``llvm.objectsize``, we assume its size is unknown. The fourth
23893argument to ``llvm.objectsize`` determines if the value should be evaluated at
23894runtime.
23895
23896The second, third, and fourth arguments only accept constants.
23897
23898Semantics:
23899""""""""""
23900
23901The ``llvm.objectsize`` intrinsic is lowered to a value representing the size of
23902the object concerned. If the size cannot be determined, ``llvm.objectsize``
23903returns ``i32/i64 -1 or 0`` (depending on the ``min`` argument).
23904
23905'``llvm.expect``' Intrinsic
23906^^^^^^^^^^^^^^^^^^^^^^^^^^^
23907
23908Syntax:
23909"""""""
23910
23911This is an overloaded intrinsic. You can use ``llvm.expect`` on any
23912integer bit width.
23913
23914::
23915
23916      declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>)
23917      declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
23918      declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
23919
23920Overview:
23921"""""""""
23922
23923The ``llvm.expect`` intrinsic provides information about expected (the
23924most probable) value of ``val``, which can be used by optimizers.
23925
23926Arguments:
23927""""""""""
23928
23929The ``llvm.expect`` intrinsic takes two arguments. The first argument is
23930a value. The second argument is an expected value.
23931
23932Semantics:
23933""""""""""
23934
23935This intrinsic is lowered to the ``val``.
23936
23937'``llvm.expect.with.probability``' Intrinsic
23938^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23939
23940Syntax:
23941"""""""
23942
23943This intrinsic is similar to ``llvm.expect``. This is an overloaded intrinsic.
23944You can use ``llvm.expect.with.probability`` on any integer bit width.
23945
23946::
23947
23948      declare i1 @llvm.expect.with.probability.i1(i1 <val>, i1 <expected_val>, double <prob>)
23949      declare i32 @llvm.expect.with.probability.i32(i32 <val>, i32 <expected_val>, double <prob>)
23950      declare i64 @llvm.expect.with.probability.i64(i64 <val>, i64 <expected_val>, double <prob>)
23951
23952Overview:
23953"""""""""
23954
23955The ``llvm.expect.with.probability`` intrinsic provides information about
23956expected value of ``val`` with probability(or confidence) ``prob``, which can
23957be used by optimizers.
23958
23959Arguments:
23960""""""""""
23961
23962The ``llvm.expect.with.probability`` intrinsic takes three arguments. The first
23963argument is a value. The second argument is an expected value. The third
23964argument is a probability.
23965
23966Semantics:
23967""""""""""
23968
23969This intrinsic is lowered to the ``val``.
23970
23971.. _int_assume:
23972
23973'``llvm.assume``' Intrinsic
23974^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23975
23976Syntax:
23977"""""""
23978
23979::
23980
23981      declare void @llvm.assume(i1 %cond)
23982
23983Overview:
23984"""""""""
23985
23986The ``llvm.assume`` allows the optimizer to assume that the provided
23987condition is true. This information can then be used in simplifying other parts
23988of the code.
23989
23990More complex assumptions can be encoded as
23991:ref:`assume operand bundles <assume_opbundles>`.
23992
23993Arguments:
23994""""""""""
23995
23996The argument of the call is the condition which the optimizer may assume is
23997always true.
23998
23999Semantics:
24000""""""""""
24001
24002The intrinsic allows the optimizer to assume that the provided condition is
24003always true whenever the control flow reaches the intrinsic call. No code is
24004generated for this intrinsic, and instructions that contribute only to the
24005provided condition are not used for code generation. If the condition is
24006violated during execution, the behavior is undefined.
24007
24008Note that the optimizer might limit the transformations performed on values
24009used by the ``llvm.assume`` intrinsic in order to preserve the instructions
24010only used to form the intrinsic's input argument. This might prove undesirable
24011if the extra information provided by the ``llvm.assume`` intrinsic does not cause
24012sufficient overall improvement in code quality. For this reason,
24013``llvm.assume`` should not be used to document basic mathematical invariants
24014that the optimizer can otherwise deduce or facts that are of little use to the
24015optimizer.
24016
24017.. _int_ssa_copy:
24018
24019'``llvm.ssa.copy``' Intrinsic
24020^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24021
24022Syntax:
24023"""""""
24024
24025::
24026
24027      declare type @llvm.ssa.copy(type %operand) returned(1) readnone
24028
24029Arguments:
24030""""""""""
24031
24032The first argument is an operand which is used as the returned value.
24033
24034Overview:
24035""""""""""
24036
24037The ``llvm.ssa.copy`` intrinsic can be used to attach information to
24038operations by copying them and giving them new names.  For example,
24039the PredicateInfo utility uses it to build Extended SSA form, and
24040attach various forms of information to operands that dominate specific
24041uses.  It is not meant for general use, only for building temporary
24042renaming forms that require value splits at certain points.
24043
24044.. _type.test:
24045
24046'``llvm.type.test``' Intrinsic
24047^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24048
24049Syntax:
24050"""""""
24051
24052::
24053
24054      declare i1 @llvm.type.test(i8* %ptr, metadata %type) nounwind readnone
24055
24056
24057Arguments:
24058""""""""""
24059
24060The first argument is a pointer to be tested. The second argument is a
24061metadata object representing a :doc:`type identifier <TypeMetadata>`.
24062
24063Overview:
24064"""""""""
24065
24066The ``llvm.type.test`` intrinsic tests whether the given pointer is associated
24067with the given type identifier.
24068
24069.. _type.checked.load:
24070
24071'``llvm.type.checked.load``' Intrinsic
24072^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24073
24074Syntax:
24075"""""""
24076
24077::
24078
24079      declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly
24080
24081
24082Arguments:
24083""""""""""
24084
24085The first argument is a pointer from which to load a function pointer. The
24086second argument is the byte offset from which to load the function pointer. The
24087third argument is a metadata object representing a :doc:`type identifier
24088<TypeMetadata>`.
24089
24090Overview:
24091"""""""""
24092
24093The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a
24094virtual table pointer using type metadata. This intrinsic is used to implement
24095control flow integrity in conjunction with virtual call optimization. The
24096virtual call optimization pass will optimize away ``llvm.type.checked.load``
24097intrinsics associated with devirtualized calls, thereby removing the type
24098check in cases where it is not needed to enforce the control flow integrity
24099constraint.
24100
24101If the given pointer is associated with a type metadata identifier, this
24102function returns true as the second element of its return value. (Note that
24103the function may also return true if the given pointer is not associated
24104with a type metadata identifier.) If the function's return value's second
24105element is true, the following rules apply to the first element:
24106
24107- If the given pointer is associated with the given type metadata identifier,
24108  it is the function pointer loaded from the given byte offset from the given
24109  pointer.
24110
24111- If the given pointer is not associated with the given type metadata
24112  identifier, it is one of the following (the choice of which is unspecified):
24113
24114  1. The function pointer that would have been loaded from an arbitrarily chosen
24115     (through an unspecified mechanism) pointer associated with the type
24116     metadata.
24117
24118  2. If the function has a non-void return type, a pointer to a function that
24119     returns an unspecified value without causing side effects.
24120
24121If the function's return value's second element is false, the value of the
24122first element is undefined.
24123
24124
24125'``llvm.arithmetic.fence``' Intrinsic
24126^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24127
24128Syntax:
24129"""""""
24130
24131::
24132
24133      declare <type>
24134      @llvm.arithmetic.fence(<type> <op>)
24135
24136Overview:
24137"""""""""
24138
24139The purpose of the ``llvm.arithmetic.fence`` intrinsic
24140is to prevent the optimizer from performing fast-math optimizations,
24141particularly reassociation,
24142between the argument and the expression that contains the argument.
24143It can be used to preserve the parentheses in the source language.
24144
24145Arguments:
24146""""""""""
24147
24148The ``llvm.arithmetic.fence`` intrinsic takes only one argument.
24149The argument and the return value are floating-point numbers,
24150or vector floating-point numbers, of the same type.
24151
24152Semantics:
24153""""""""""
24154
24155This intrinsic returns the value of its operand. The optimizer can optimize
24156the argument, but the optimizer cannot hoist any component of the operand
24157to the containing context, and the optimizer cannot move the calculation of
24158any expression in the containing context into the operand.
24159
24160
24161'``llvm.donothing``' Intrinsic
24162^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24163
24164Syntax:
24165"""""""
24166
24167::
24168
24169      declare void @llvm.donothing() nounwind readnone
24170
24171Overview:
24172"""""""""
24173
24174The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only
24175three intrinsics (besides ``llvm.experimental.patchpoint`` and
24176``llvm.experimental.gc.statepoint``) that can be called with an invoke
24177instruction.
24178
24179Arguments:
24180""""""""""
24181
24182None.
24183
24184Semantics:
24185""""""""""
24186
24187This intrinsic does nothing, and it's removed by optimizers and ignored
24188by codegen.
24189
24190'``llvm.experimental.deoptimize``' Intrinsic
24191^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24192
24193Syntax:
24194"""""""
24195
24196::
24197
24198      declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ]
24199
24200Overview:
24201"""""""""
24202
24203This intrinsic, together with :ref:`deoptimization operand bundles
24204<deopt_opbundles>`, allow frontends to express transfer of control and
24205frame-local state from the currently executing (typically more specialized,
24206hence faster) version of a function into another (typically more generic, hence
24207slower) version.
24208
24209In languages with a fully integrated managed runtime like Java and JavaScript
24210this intrinsic can be used to implement "uncommon trap" or "side exit" like
24211functionality.  In unmanaged languages like C and C++, this intrinsic can be
24212used to represent the slow paths of specialized functions.
24213
24214
24215Arguments:
24216""""""""""
24217
24218The intrinsic takes an arbitrary number of arguments, whose meaning is
24219decided by the :ref:`lowering strategy<deoptimize_lowering>`.
24220
24221Semantics:
24222""""""""""
24223
24224The ``@llvm.experimental.deoptimize`` intrinsic executes an attached
24225deoptimization continuation (denoted using a :ref:`deoptimization
24226operand bundle <deopt_opbundles>`) and returns the value returned by
24227the deoptimization continuation.  Defining the semantic properties of
24228the continuation itself is out of scope of the language reference --
24229as far as LLVM is concerned, the deoptimization continuation can
24230invoke arbitrary side effects, including reading from and writing to
24231the entire heap.
24232
24233Deoptimization continuations expressed using ``"deopt"`` operand bundles always
24234continue execution to the end of the physical frame containing them, so all
24235calls to ``@llvm.experimental.deoptimize`` must be in "tail position":
24236
24237   - ``@llvm.experimental.deoptimize`` cannot be invoked.
24238   - The call must immediately precede a :ref:`ret <i_ret>` instruction.
24239   - The ``ret`` instruction must return the value produced by the
24240     ``@llvm.experimental.deoptimize`` call if there is one, or void.
24241
24242Note that the above restrictions imply that the return type for a call to
24243``@llvm.experimental.deoptimize`` will match the return type of its immediate
24244caller.
24245
24246The inliner composes the ``"deopt"`` continuations of the caller into the
24247``"deopt"`` continuations present in the inlinee, and also updates calls to this
24248intrinsic to return directly from the frame of the function it inlined into.
24249
24250All declarations of ``@llvm.experimental.deoptimize`` must share the
24251same calling convention.
24252
24253.. _deoptimize_lowering:
24254
24255Lowering:
24256"""""""""
24257
24258Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the
24259symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to
24260ensure that this symbol is defined).  The call arguments to
24261``@llvm.experimental.deoptimize`` are lowered as if they were formal
24262arguments of the specified types, and not as varargs.
24263
24264
24265'``llvm.experimental.guard``' Intrinsic
24266^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24267
24268Syntax:
24269"""""""
24270
24271::
24272
24273      declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ]
24274
24275Overview:
24276"""""""""
24277
24278This intrinsic, together with :ref:`deoptimization operand bundles
24279<deopt_opbundles>`, allows frontends to express guards or checks on
24280optimistic assumptions made during compilation.  The semantics of
24281``@llvm.experimental.guard`` is defined in terms of
24282``@llvm.experimental.deoptimize`` -- its body is defined to be
24283equivalent to:
24284
24285.. code-block:: text
24286
24287  define void @llvm.experimental.guard(i1 %pred, <args...>) {
24288    %realPred = and i1 %pred, undef
24289    br i1 %realPred, label %continue, label %leave [, !make.implicit !{}]
24290
24291  leave:
24292    call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ]
24293    ret void
24294
24295  continue:
24296    ret void
24297  }
24298
24299
24300with the optional ``[, !make.implicit !{}]`` present if and only if it
24301is present on the call site.  For more details on ``!make.implicit``,
24302see :doc:`FaultMaps`.
24303
24304In words, ``@llvm.experimental.guard`` executes the attached
24305``"deopt"`` continuation if (but **not** only if) its first argument
24306is ``false``.  Since the optimizer is allowed to replace the ``undef``
24307with an arbitrary value, it can optimize guard to fail "spuriously",
24308i.e. without the original condition being false (hence the "not only
24309if"); and this allows for "check widening" type optimizations.
24310
24311``@llvm.experimental.guard`` cannot be invoked.
24312
24313After ``@llvm.experimental.guard`` was first added, a more general
24314formulation was found in ``@llvm.experimental.widenable.condition``.
24315Support for ``@llvm.experimental.guard`` is slowly being rephrased in
24316terms of this alternate.
24317
24318'``llvm.experimental.widenable.condition``' Intrinsic
24319^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24320
24321Syntax:
24322"""""""
24323
24324::
24325
24326      declare i1 @llvm.experimental.widenable.condition()
24327
24328Overview:
24329"""""""""
24330
24331This intrinsic represents a "widenable condition" which is
24332boolean expressions with the following property: whether this
24333expression is `true` or `false`, the program is correct and
24334well-defined.
24335
24336Together with :ref:`deoptimization operand bundles <deopt_opbundles>`,
24337``@llvm.experimental.widenable.condition`` allows frontends to
24338express guards or checks on optimistic assumptions made during
24339compilation and represent them as branch instructions on special
24340conditions.
24341
24342While this may appear similar in semantics to `undef`, it is very
24343different in that an invocation produces a particular, singular
24344value. It is also intended to be lowered late, and remain available
24345for specific optimizations and transforms that can benefit from its
24346special properties.
24347
24348Arguments:
24349""""""""""
24350
24351None.
24352
24353Semantics:
24354""""""""""
24355
24356The intrinsic ``@llvm.experimental.widenable.condition()``
24357returns either `true` or `false`. For each evaluation of a call
24358to this intrinsic, the program must be valid and correct both if
24359it returns `true` and if it returns `false`. This allows
24360transformation passes to replace evaluations of this intrinsic
24361with either value whenever one is beneficial.
24362
24363When used in a branch condition, it allows us to choose between
24364two alternative correct solutions for the same problem, like
24365in example below:
24366
24367.. code-block:: text
24368
24369    %cond = call i1 @llvm.experimental.widenable.condition()
24370    br i1 %cond, label %solution_1, label %solution_2
24371
24372  label %fast_path:
24373    ; Apply memory-consuming but fast solution for a task.
24374
24375  label %slow_path:
24376    ; Cheap in memory but slow solution.
24377
24378Whether the result of intrinsic's call is `true` or `false`,
24379it should be correct to pick either solution. We can switch
24380between them by replacing the result of
24381``@llvm.experimental.widenable.condition`` with different
24382`i1` expressions.
24383
24384This is how it can be used to represent guards as widenable branches:
24385
24386.. code-block:: text
24387
24388  block:
24389    ; Unguarded instructions
24390    call void @llvm.experimental.guard(i1 %cond, <args...>) ["deopt"(<deopt_args...>)]
24391    ; Guarded instructions
24392
24393Can be expressed in an alternative equivalent form of explicit branch using
24394``@llvm.experimental.widenable.condition``:
24395
24396.. code-block:: text
24397
24398  block:
24399    ; Unguarded instructions
24400    %widenable_condition = call i1 @llvm.experimental.widenable.condition()
24401    %guard_condition = and i1 %cond, %widenable_condition
24402    br i1 %guard_condition, label %guarded, label %deopt
24403
24404  guarded:
24405    ; Guarded instructions
24406
24407  deopt:
24408    call type @llvm.experimental.deoptimize(<args...>) [ "deopt"(<deopt_args...>) ]
24409
24410So the block `guarded` is only reachable when `%cond` is `true`,
24411and it should be valid to go to the block `deopt` whenever `%cond`
24412is `true` or `false`.
24413
24414``@llvm.experimental.widenable.condition`` will never throw, thus
24415it cannot be invoked.
24416
24417Guard widening:
24418"""""""""""""""
24419
24420When ``@llvm.experimental.widenable.condition()`` is used in
24421condition of a guard represented as explicit branch, it is
24422legal to widen the guard's condition with any additional
24423conditions.
24424
24425Guard widening looks like replacement of
24426
24427.. code-block:: text
24428
24429  %widenable_cond = call i1 @llvm.experimental.widenable.condition()
24430  %guard_cond = and i1 %cond, %widenable_cond
24431  br i1 %guard_cond, label %guarded, label %deopt
24432
24433with
24434
24435.. code-block:: text
24436
24437  %widenable_cond = call i1 @llvm.experimental.widenable.condition()
24438  %new_cond = and i1 %any_other_cond, %widenable_cond
24439  %new_guard_cond = and i1 %cond, %new_cond
24440  br i1 %new_guard_cond, label %guarded, label %deopt
24441
24442for this branch. Here `%any_other_cond` is an arbitrarily chosen
24443well-defined `i1` value. By making guard widening, we may
24444impose stricter conditions on `guarded` block and bail to the
24445deopt when the new condition is not met.
24446
24447Lowering:
24448"""""""""
24449
24450Default lowering strategy is replacing the result of
24451call of ``@llvm.experimental.widenable.condition``  with
24452constant `true`. However it is always correct to replace
24453it with any other `i1` value. Any pass can
24454freely do it if it can benefit from non-default lowering.
24455
24456
24457'``llvm.load.relative``' Intrinsic
24458^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24459
24460Syntax:
24461"""""""
24462
24463::
24464
24465      declare i8* @llvm.load.relative.iN(i8* %ptr, iN %offset) argmemonly nounwind readonly
24466
24467Overview:
24468"""""""""
24469
24470This intrinsic loads a 32-bit value from the address ``%ptr + %offset``,
24471adds ``%ptr`` to that value and returns it. The constant folder specifically
24472recognizes the form of this intrinsic and the constant initializers it may
24473load from; if a loaded constant initializer is known to have the form
24474``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``.
24475
24476LLVM provides that the calculation of such a constant initializer will
24477not overflow at link time under the medium code model if ``x`` is an
24478``unnamed_addr`` function. However, it does not provide this guarantee for
24479a constant initializer folded into a function body. This intrinsic can be
24480used to avoid the possibility of overflows when loading from such a constant.
24481
24482.. _llvm_sideeffect:
24483
24484'``llvm.sideeffect``' Intrinsic
24485^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24486
24487Syntax:
24488"""""""
24489
24490::
24491
24492      declare void @llvm.sideeffect() inaccessiblememonly nounwind willreturn
24493
24494Overview:
24495"""""""""
24496
24497The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers
24498treat it as having side effects, so it can be inserted into a loop to
24499indicate that the loop shouldn't be assumed to terminate (which could
24500potentially lead to the loop being optimized away entirely), even if it's
24501an infinite loop with no other side effects.
24502
24503Arguments:
24504""""""""""
24505
24506None.
24507
24508Semantics:
24509""""""""""
24510
24511This intrinsic actually does nothing, but optimizers must assume that it
24512has externally observable side effects.
24513
24514'``llvm.is.constant.*``' Intrinsic
24515^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24516
24517Syntax:
24518"""""""
24519
24520This is an overloaded intrinsic. You can use llvm.is.constant with any argument type.
24521
24522::
24523
24524      declare i1 @llvm.is.constant.i32(i32 %operand) nounwind readnone
24525      declare i1 @llvm.is.constant.f32(float %operand) nounwind readnone
24526      declare i1 @llvm.is.constant.TYPENAME(TYPE %operand) nounwind readnone
24527
24528Overview:
24529"""""""""
24530
24531The '``llvm.is.constant``' intrinsic will return true if the argument
24532is known to be a manifest compile-time constant. It is guaranteed to
24533fold to either true or false before generating machine code.
24534
24535Semantics:
24536""""""""""
24537
24538This intrinsic generates no code. If its argument is known to be a
24539manifest compile-time constant value, then the intrinsic will be
24540converted to a constant true value. Otherwise, it will be converted to
24541a constant false value.
24542
24543In particular, note that if the argument is a constant expression
24544which refers to a global (the address of which _is_ a constant, but
24545not manifest during the compile), then the intrinsic evaluates to
24546false.
24547
24548The result also intentionally depends on the result of optimization
24549passes -- e.g., the result can change depending on whether a
24550function gets inlined or not. A function's parameters are
24551obviously not constant. However, a call like
24552``llvm.is.constant.i32(i32 %param)`` *can* return true after the
24553function is inlined, if the value passed to the function parameter was
24554a constant.
24555
24556On the other hand, if constant folding is not run, it will never
24557evaluate to true, even in simple cases.
24558
24559.. _int_ptrmask:
24560
24561'``llvm.ptrmask``' Intrinsic
24562^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24563
24564Syntax:
24565"""""""
24566
24567::
24568
24569      declare ptrty llvm.ptrmask(ptrty %ptr, intty %mask) readnone speculatable
24570
24571Arguments:
24572""""""""""
24573
24574The first argument is a pointer. The second argument is an integer.
24575
24576Overview:
24577""""""""""
24578
24579The ``llvm.ptrmask`` intrinsic masks out bits of the pointer according to a mask.
24580This allows stripping data from tagged pointers without converting them to an
24581integer (ptrtoint/inttoptr). As a consequence, we can preserve more information
24582to facilitate alias analysis and underlying-object detection.
24583
24584Semantics:
24585""""""""""
24586
24587The result of ``ptrmask(ptr, mask)`` is equivalent to
24588``getelementptr ptr, (ptrtoint(ptr) & mask) - ptrtoint(ptr)``. Both the returned
24589pointer and the first argument are based on the same underlying object (for more
24590information on the *based on* terminology see
24591:ref:`the pointer aliasing rules <pointeraliasing>`). If the bitwidth of the
24592mask argument does not match the pointer size of the target, the mask is
24593zero-extended or truncated accordingly.
24594
24595.. _int_vscale:
24596
24597'``llvm.vscale``' Intrinsic
24598^^^^^^^^^^^^^^^^^^^^^^^^^^^
24599
24600Syntax:
24601"""""""
24602
24603::
24604
24605      declare i32 llvm.vscale.i32()
24606      declare i64 llvm.vscale.i64()
24607
24608Overview:
24609"""""""""
24610
24611The ``llvm.vscale`` intrinsic returns the value for ``vscale`` in scalable
24612vectors such as ``<vscale x 16 x i8>``.
24613
24614Semantics:
24615""""""""""
24616
24617``vscale`` is a positive value that is constant throughout program
24618execution, but is unknown at compile time.
24619If the result value does not fit in the result type, then the result is
24620a :ref:`poison value <poisonvalues>`.
24621
24622
24623Stack Map Intrinsics
24624--------------------
24625
24626LLVM provides experimental intrinsics to support runtime patching
24627mechanisms commonly desired in dynamic language JITs. These intrinsics
24628are described in :doc:`StackMaps`.
24629
24630Element Wise Atomic Memory Intrinsics
24631-------------------------------------
24632
24633These intrinsics are similar to the standard library memory intrinsics except
24634that they perform memory transfer as a sequence of atomic memory accesses.
24635
24636.. _int_memcpy_element_unordered_atomic:
24637
24638'``llvm.memcpy.element.unordered.atomic``' Intrinsic
24639^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24640
24641Syntax:
24642"""""""
24643
24644This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on
24645any integer bit width and for different address spaces. Not all targets
24646support all bit widths however.
24647
24648::
24649
24650      declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>,
24651                                                                       i8* <src>,
24652                                                                       i32 <len>,
24653                                                                       i32 <element_size>)
24654      declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>,
24655                                                                       i8* <src>,
24656                                                                       i64 <len>,
24657                                                                       i32 <element_size>)
24658
24659Overview:
24660"""""""""
24661
24662The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the
24663'``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated
24664as arrays with elements that are exactly ``element_size`` bytes, and the copy between
24665buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations
24666that are a positive integer multiple of the ``element_size`` in size.
24667
24668Arguments:
24669""""""""""
24670
24671The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>`
24672intrinsic, with the added constraint that ``len`` is required to be a positive integer
24673multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
24674``element_size``, then the behaviour of the intrinsic is undefined.
24675
24676``element_size`` must be a compile-time constant positive power of two no greater than
24677target-specific atomic access size limit.
24678
24679For each of the input pointers ``align`` parameter attribute must be specified. It
24680must be a power of two no less than the ``element_size``. Caller guarantees that
24681both the source and destination pointers are aligned to that boundary.
24682
24683Semantics:
24684""""""""""
24685
24686The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of
24687memory from the source location to the destination location. These locations are not
24688allowed to overlap. The memory copy is performed as a sequence of load/store operations
24689where each access is guaranteed to be a multiple of ``element_size`` bytes wide and
24690aligned at an ``element_size`` boundary.
24691
24692The order of the copy is unspecified. The same value may be read from the source
24693buffer many times, but only one write is issued to the destination buffer per
24694element. It is well defined to have concurrent reads and writes to both source and
24695destination provided those reads and writes are unordered atomic when specified.
24696
24697This intrinsic does not provide any additional ordering guarantees over those
24698provided by a set of unordered loads from the source location and stores to the
24699destination.
24700
24701Lowering:
24702"""""""""
24703
24704In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is
24705lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*'
24706is replaced with an actual element size. See :ref:`RewriteStatepointsForGC intrinsic
24707lowering <RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific
24708lowering.
24709
24710Optimizer is allowed to inline memory copy when it's profitable to do so.
24711
24712'``llvm.memmove.element.unordered.atomic``' Intrinsic
24713^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24714
24715Syntax:
24716"""""""
24717
24718This is an overloaded intrinsic. You can use
24719``llvm.memmove.element.unordered.atomic`` on any integer bit width and for
24720different address spaces. Not all targets support all bit widths however.
24721
24722::
24723
24724      declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>,
24725                                                                        i8* <src>,
24726                                                                        i32 <len>,
24727                                                                        i32 <element_size>)
24728      declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>,
24729                                                                        i8* <src>,
24730                                                                        i64 <len>,
24731                                                                        i32 <element_size>)
24732
24733Overview:
24734"""""""""
24735
24736The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization
24737of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and
24738``src`` are treated as arrays with elements that are exactly ``element_size``
24739bytes, and the copy between buffers uses a sequence of
24740:ref:`unordered atomic <ordering>` load/store operations that are a positive
24741integer multiple of the ``element_size`` in size.
24742
24743Arguments:
24744""""""""""
24745
24746The first three arguments are the same as they are in the
24747:ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that
24748``len`` is required to be a positive integer multiple of the ``element_size``.
24749If ``len`` is not a positive integer multiple of ``element_size``, then the
24750behaviour of the intrinsic is undefined.
24751
24752``element_size`` must be a compile-time constant positive power of two no
24753greater than a target-specific atomic access size limit.
24754
24755For each of the input pointers the ``align`` parameter attribute must be
24756specified. It must be a power of two no less than the ``element_size``. Caller
24757guarantees that both the source and destination pointers are aligned to that
24758boundary.
24759
24760Semantics:
24761""""""""""
24762
24763The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes
24764of memory from the source location to the destination location. These locations
24765are allowed to overlap. The memory copy is performed as a sequence of load/store
24766operations where each access is guaranteed to be a multiple of ``element_size``
24767bytes wide and aligned at an ``element_size`` boundary.
24768
24769The order of the copy is unspecified. The same value may be read from the source
24770buffer many times, but only one write is issued to the destination buffer per
24771element. It is well defined to have concurrent reads and writes to both source
24772and destination provided those reads and writes are unordered atomic when
24773specified.
24774
24775This intrinsic does not provide any additional ordering guarantees over those
24776provided by a set of unordered loads from the source location and stores to the
24777destination.
24778
24779Lowering:
24780"""""""""
24781
24782In the most general case call to the
24783'``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol
24784``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an
24785actual element size. See :ref:`RewriteStatepointsForGC intrinsic lowering
24786<RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific
24787lowering.
24788
24789The optimizer is allowed to inline the memory copy when it's profitable to do so.
24790
24791.. _int_memset_element_unordered_atomic:
24792
24793'``llvm.memset.element.unordered.atomic``' Intrinsic
24794^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24795
24796Syntax:
24797"""""""
24798
24799This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on
24800any integer bit width and for different address spaces. Not all targets
24801support all bit widths however.
24802
24803::
24804
24805      declare void @llvm.memset.element.unordered.atomic.p0i8.i32(i8* <dest>,
24806                                                                  i8 <value>,
24807                                                                  i32 <len>,
24808                                                                  i32 <element_size>)
24809      declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* <dest>,
24810                                                                  i8 <value>,
24811                                                                  i64 <len>,
24812                                                                  i32 <element_size>)
24813
24814Overview:
24815"""""""""
24816
24817The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the
24818'``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array
24819with elements that are exactly ``element_size`` bytes, and the assignment to that array
24820uses uses a sequence of :ref:`unordered atomic <ordering>` store operations
24821that are a positive integer multiple of the ``element_size`` in size.
24822
24823Arguments:
24824""""""""""
24825
24826The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>`
24827intrinsic, with the added constraint that ``len`` is required to be a positive integer
24828multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
24829``element_size``, then the behaviour of the intrinsic is undefined.
24830
24831``element_size`` must be a compile-time constant positive power of two no greater than
24832target-specific atomic access size limit.
24833
24834The ``dest`` input pointer must have the ``align`` parameter attribute specified. It
24835must be a power of two no less than the ``element_size``. Caller guarantees that
24836the destination pointer is aligned to that boundary.
24837
24838Semantics:
24839""""""""""
24840
24841The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of
24842memory starting at the destination location to the given ``value``. The memory is
24843set with a sequence of store operations where each access is guaranteed to be a
24844multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary.
24845
24846The order of the assignment is unspecified. Only one write is issued to the
24847destination buffer per element. It is well defined to have concurrent reads and
24848writes to the destination provided those reads and writes are unordered atomic
24849when specified.
24850
24851This intrinsic does not provide any additional ordering guarantees over those
24852provided by a set of unordered stores to the destination.
24853
24854Lowering:
24855"""""""""
24856
24857In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is
24858lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*'
24859is replaced with an actual element size.
24860
24861The optimizer is allowed to inline the memory assignment when it's profitable to do so.
24862
24863Objective-C ARC Runtime Intrinsics
24864----------------------------------
24865
24866LLVM provides intrinsics that lower to Objective-C ARC runtime entry points.
24867LLVM is aware of the semantics of these functions, and optimizes based on that
24868knowledge. You can read more about the details of Objective-C ARC `here
24869<https://clang.llvm.org/docs/AutomaticReferenceCounting.html>`_.
24870
24871'``llvm.objc.autorelease``' Intrinsic
24872^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24873
24874Syntax:
24875"""""""
24876::
24877
24878      declare i8* @llvm.objc.autorelease(i8*)
24879
24880Lowering:
24881"""""""""
24882
24883Lowers to a call to `objc_autorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autorelease>`_.
24884
24885'``llvm.objc.autoreleasePoolPop``' Intrinsic
24886^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24887
24888Syntax:
24889"""""""
24890::
24891
24892      declare void @llvm.objc.autoreleasePoolPop(i8*)
24893
24894Lowering:
24895"""""""""
24896
24897Lowers to a call to `objc_autoreleasePoolPop <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpop-void-pool>`_.
24898
24899'``llvm.objc.autoreleasePoolPush``' Intrinsic
24900^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24901
24902Syntax:
24903"""""""
24904::
24905
24906      declare i8* @llvm.objc.autoreleasePoolPush()
24907
24908Lowering:
24909"""""""""
24910
24911Lowers to a call to `objc_autoreleasePoolPush <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpush-void>`_.
24912
24913'``llvm.objc.autoreleaseReturnValue``' Intrinsic
24914^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24915
24916Syntax:
24917"""""""
24918::
24919
24920      declare i8* @llvm.objc.autoreleaseReturnValue(i8*)
24921
24922Lowering:
24923"""""""""
24924
24925Lowers to a call to `objc_autoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue>`_.
24926
24927'``llvm.objc.copyWeak``' Intrinsic
24928^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24929
24930Syntax:
24931"""""""
24932::
24933
24934      declare void @llvm.objc.copyWeak(i8**, i8**)
24935
24936Lowering:
24937"""""""""
24938
24939Lowers to a call to `objc_copyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-copyweak-id-dest-id-src>`_.
24940
24941'``llvm.objc.destroyWeak``' Intrinsic
24942^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24943
24944Syntax:
24945"""""""
24946::
24947
24948      declare void @llvm.objc.destroyWeak(i8**)
24949
24950Lowering:
24951"""""""""
24952
24953Lowers to a call to `objc_destroyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-destroyweak-id-object>`_.
24954
24955'``llvm.objc.initWeak``' Intrinsic
24956^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24957
24958Syntax:
24959"""""""
24960::
24961
24962      declare i8* @llvm.objc.initWeak(i8**, i8*)
24963
24964Lowering:
24965"""""""""
24966
24967Lowers to a call to `objc_initWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-initweak>`_.
24968
24969'``llvm.objc.loadWeak``' Intrinsic
24970^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24971
24972Syntax:
24973"""""""
24974::
24975
24976      declare i8* @llvm.objc.loadWeak(i8**)
24977
24978Lowering:
24979"""""""""
24980
24981Lowers to a call to `objc_loadWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweak>`_.
24982
24983'``llvm.objc.loadWeakRetained``' Intrinsic
24984^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24985
24986Syntax:
24987"""""""
24988::
24989
24990      declare i8* @llvm.objc.loadWeakRetained(i8**)
24991
24992Lowering:
24993"""""""""
24994
24995Lowers to a call to `objc_loadWeakRetained <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweakretained>`_.
24996
24997'``llvm.objc.moveWeak``' Intrinsic
24998^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24999
25000Syntax:
25001"""""""
25002::
25003
25004      declare void @llvm.objc.moveWeak(i8**, i8**)
25005
25006Lowering:
25007"""""""""
25008
25009Lowers to a call to `objc_moveWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-moveweak-id-dest-id-src>`_.
25010
25011'``llvm.objc.release``' Intrinsic
25012^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25013
25014Syntax:
25015"""""""
25016::
25017
25018      declare void @llvm.objc.release(i8*)
25019
25020Lowering:
25021"""""""""
25022
25023Lowers to a call to `objc_release <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-release-id-value>`_.
25024
25025'``llvm.objc.retain``' Intrinsic
25026^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25027
25028Syntax:
25029"""""""
25030::
25031
25032      declare i8* @llvm.objc.retain(i8*)
25033
25034Lowering:
25035"""""""""
25036
25037Lowers to a call to `objc_retain <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>`_.
25038
25039'``llvm.objc.retainAutorelease``' Intrinsic
25040^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25041
25042Syntax:
25043"""""""
25044::
25045
25046      declare i8* @llvm.objc.retainAutorelease(i8*)
25047
25048Lowering:
25049"""""""""
25050
25051Lowers to a call to `objc_retainAutorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautorelease>`_.
25052
25053'``llvm.objc.retainAutoreleaseReturnValue``' Intrinsic
25054^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25055
25056Syntax:
25057"""""""
25058::
25059
25060      declare i8* @llvm.objc.retainAutoreleaseReturnValue(i8*)
25061
25062Lowering:
25063"""""""""
25064
25065Lowers to a call to `objc_retainAutoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasereturnvalue>`_.
25066
25067'``llvm.objc.retainAutoreleasedReturnValue``' Intrinsic
25068^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25069
25070Syntax:
25071"""""""
25072::
25073
25074      declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8*)
25075
25076Lowering:
25077"""""""""
25078
25079Lowers to a call to `objc_retainAutoreleasedReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasedreturnvalue>`_.
25080
25081'``llvm.objc.retainBlock``' Intrinsic
25082^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25083
25084Syntax:
25085"""""""
25086::
25087
25088      declare i8* @llvm.objc.retainBlock(i8*)
25089
25090Lowering:
25091"""""""""
25092
25093Lowers to a call to `objc_retainBlock <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainblock>`_.
25094
25095'``llvm.objc.storeStrong``' Intrinsic
25096^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25097
25098Syntax:
25099"""""""
25100::
25101
25102      declare void @llvm.objc.storeStrong(i8**, i8*)
25103
25104Lowering:
25105"""""""""
25106
25107Lowers to a call to `objc_storeStrong <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-storestrong-id-object-id-value>`_.
25108
25109'``llvm.objc.storeWeak``' Intrinsic
25110^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25111
25112Syntax:
25113"""""""
25114::
25115
25116      declare i8* @llvm.objc.storeWeak(i8**, i8*)
25117
25118Lowering:
25119"""""""""
25120
25121Lowers to a call to `objc_storeWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-storeweak>`_.
25122
25123Preserving Debug Information Intrinsics
25124^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25125
25126These intrinsics are used to carry certain debuginfo together with
25127IR-level operations. For example, it may be desirable to
25128know the structure/union name and the original user-level field
25129indices. Such information got lost in IR GetElementPtr instruction
25130since the IR types are different from debugInfo types and unions
25131are converted to structs in IR.
25132
25133'``llvm.preserve.array.access.index``' Intrinsic
25134^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25135
25136Syntax:
25137"""""""
25138::
25139
25140      declare <ret_type>
25141      @llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons(<type> base,
25142                                                                           i32 dim,
25143                                                                           i32 index)
25144
25145Overview:
25146"""""""""
25147
25148The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address
25149based on array base ``base``, array dimension ``dim`` and the last access index ``index``
25150into the array. The return type ``ret_type`` is a pointer type to the array element.
25151The array ``dim`` and ``index`` are preserved which is more robust than
25152getelementptr instruction which may be subject to compiler transformation.
25153The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
25154to provide array or pointer debuginfo type.
25155The metadata is a ``DICompositeType`` or ``DIDerivedType`` representing the
25156debuginfo version of ``type``.
25157
25158Arguments:
25159""""""""""
25160
25161The ``base`` is the array base address.  The ``dim`` is the array dimension.
25162The ``base`` is a pointer if ``dim`` equals 0.
25163The ``index`` is the last access index into the array or pointer.
25164
25165The ``base`` argument must be annotated with an :ref:`elementtype
25166<attr_elementtype>` attribute at the call-site. This attribute specifies the
25167getelementptr element type.
25168
25169Semantics:
25170""""""""""
25171
25172The '``llvm.preserve.array.access.index``' intrinsic produces the same result
25173as a getelementptr with base ``base`` and access operands ``{dim's 0's, index}``.
25174
25175'``llvm.preserve.union.access.index``' Intrinsic
25176^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25177
25178Syntax:
25179"""""""
25180::
25181
25182      declare <type>
25183      @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(<type> base,
25184                                                                        i32 di_index)
25185
25186Overview:
25187"""""""""
25188
25189The '``llvm.preserve.union.access.index``' intrinsic carries the debuginfo field index
25190``di_index`` and returns the ``base`` address.
25191The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
25192to provide union debuginfo type.
25193The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
25194The return type ``type`` is the same as the ``base`` type.
25195
25196Arguments:
25197""""""""""
25198
25199The ``base`` is the union base address. The ``di_index`` is the field index in debuginfo.
25200
25201Semantics:
25202""""""""""
25203
25204The '``llvm.preserve.union.access.index``' intrinsic returns the ``base`` address.
25205
25206'``llvm.preserve.struct.access.index``' Intrinsic
25207^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25208
25209Syntax:
25210"""""""
25211::
25212
25213      declare <ret_type>
25214      @llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s(<type> base,
25215                                                                 i32 gep_index,
25216                                                                 i32 di_index)
25217
25218Overview:
25219"""""""""
25220
25221The '``llvm.preserve.struct.access.index``' intrinsic returns the getelementptr address
25222based on struct base ``base`` and IR struct member index ``gep_index``.
25223The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
25224to provide struct debuginfo type.
25225The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
25226The return type ``ret_type`` is a pointer type to the structure member.
25227
25228Arguments:
25229""""""""""
25230
25231The ``base`` is the structure base address. The ``gep_index`` is the struct member index
25232based on IR structures. The ``di_index`` is the struct member index based on debuginfo.
25233
25234The ``base`` argument must be annotated with an :ref:`elementtype
25235<attr_elementtype>` attribute at the call-site. This attribute specifies the
25236getelementptr element type.
25237
25238Semantics:
25239""""""""""
25240
25241The '``llvm.preserve.struct.access.index``' intrinsic produces the same result
25242as a getelementptr with base ``base`` and access operands ``{0, gep_index}``.
25243
25244'``llvm.fptrunc.round``' Intrinsic
25245^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25246
25247Syntax:
25248"""""""
25249
25250::
25251
25252      declare <ty2>
25253      @llvm.fptrunc.round(<type> <value>, metadata <rounding mode>)
25254
25255Overview:
25256"""""""""
25257
25258The '``llvm.fptrunc.round``' intrinsic truncates
25259:ref:`floating-point <t_floating>` ``value`` to type ``ty2``
25260with a specified rounding mode.
25261
25262Arguments:
25263""""""""""
25264
25265The '``llvm.fptrunc.round``' intrinsic takes a :ref:`floating-point
25266<t_floating>` value to cast and a :ref:`floating-point <t_floating>` type
25267to cast it to. This argument must be larger in size than the result.
25268
25269The second argument specifies the rounding mode as described in the constrained
25270intrinsics section.
25271For this intrinsic, the "round.dynamic" mode is not supported.
25272
25273Semantics:
25274""""""""""
25275
25276The '``llvm.fptrunc.round``' intrinsic casts a ``value`` from a larger
25277:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
25278<t_floating>` type.
25279This intrinsic is assumed to execute in the default :ref:`floating-point
25280environment <floatenv>` *except* for the rounding mode.
25281This intrinsic is not supported on all targets. Some targets may not support
25282all rounding modes.
25283