1 ==============================
2 LLVM Language Reference Manual
3 ==============================
12 This document is a reference manual for the LLVM assembly language. LLVM
13 is a Static Single Assignment (SSA) based representation that provides
14 type safety, low-level operations, flexibility, and the capability of
15 representing 'all' high-level languages cleanly. It is the common code
16 representation used throughout all phases of the LLVM compilation
22 The LLVM code representation is designed to be used in three different
23 forms: 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
25 readable assembly language representation. This allows LLVM to provide a
26 powerful intermediate representation for efficient compiler
27 transformations and analysis, while providing a natural means to debug
28 and visualize the transformations. The three different forms of LLVM are
29 all equivalent. This document describes the human readable
30 representation and notation.
32 The LLVM representation aims to be light-weight and low-level while
33 being expressive, typed, and extensible at the same time. It aims to be
34 a "universal IR" of sorts, by being at a low enough level that
35 high-level ideas may be cleanly mapped to it (similar to how
36 microprocessors are "universal IR's", allowing many source languages to
37 be mapped to them). By providing type information, LLVM can be used as
38 the target of optimizations: for example, through pointer analysis, it
39 can be proven that a C automatic variable is never accessed outside of
40 the current function, allowing it to be promoted to a simple SSA value
41 instead of a memory location.
48 It is important to note that this document describes 'well formed' LLVM
49 assembly language. There is a difference between what the parser accepts
50 and what is considered 'well formed'. For example, the following
51 instruction is syntactically okay, but not well formed:
57 because the definition of ``%x`` does not dominate all of its uses. The
58 LLVM infrastructure provides a verification pass that may be used to
59 verify that an LLVM module is well formed. This pass is automatically
60 run by the parser after parsing input assembly and by the optimizer
61 before it outputs bitcode. The violations pointed out by the verifier
62 pass indicate bugs in transformation passes or input to the parser.
69 LLVM identifiers come in two basic types: global and local. Global
70 identifiers (functions, global variables) begin with the ``'@'``
71 character. Local identifiers (register names, types) begin with the
72 ``'%'`` character. Additionally, there are three different formats for
73 identifiers, for different purposes:
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.
88 LLVM requires that values start with a prefix for two reasons: Compilers
89 don't need to worry about name clashes with reserved words, and the set
90 of reserved words may be expanded in the future without penalty.
91 Additionally, unnamed identifiers allow a compiler to quickly come up
92 with a temporary variable without having to avoid symbol table
95 Reserved words in LLVM are very similar to reserved words in other
96 languages. 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
99 with variable names, because none of them start with a prefix character
100 (``'%'`` or ``'@'``).
102 Here is an example of LLVM code to multiply the integer variable
109 %result = mul i32 %X, 8
111 After strength reduction:
115 %result = shl i32 %X, 3
121 %0 = add i32 %X, %X ; yields i32:%0
122 %1 = add i32 %0, %0 ; yields i32:%1
123 %result = add i32 %1, %1
125 This last way of multiplying ``%X`` by 8 illustrates several important
126 lexical features of LLVM:
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.
137 It also shows a convention that we follow in this document. When
138 demonstrating instructions, we will follow an instruction with a comment
139 that defines the type and name of value produced.
147 LLVM programs are composed of ``Module``'s, each of which is a
148 translation unit of the input programs. Each module consists of
149 functions, global variables, and symbol table entries. Modules may be
150 combined together with the LLVM linker, which merges function (and
151 global variable) definitions, resolves forward declarations, and merges
152 symbol table entries. Here is an example of the "hello world" module:
156 ; Declare the string constant as a global constant.
157 @.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
159 ; External declaration of the puts function
160 declare i32 @puts(ptr nocapture) nounwind
162 ; Definition of main function
164 ; Call puts function to write out the string to stdout.
165 call i32 @puts(ptr @.str)
170 !0 = !{i32 42, null, !"string"}
173 This example is made up of a :ref:`global variable <globalvars>` named
174 "``.str``", an external declaration of the "``puts``" function, a
175 :ref:`function definition <functionstructure>` for "``main``" and
176 :ref:`named metadata <namedmetadatastructure>` "``foo``".
178 In general, a module is made up of a list of global values (where both
179 functions and global variables are global values). Global values are
180 represented by a pointer to a memory location (in this case, a pointer
181 to an array of char, and a pointer to a function), and have one of the
182 following :ref:`linkage types <linkage>`.
189 All Global Variables and Functions have one of the following types of
193 Global values with "``private``" linkage are only directly
194 accessible by objects in the current module. In particular, linking
195 code into a module with a private global value may cause the
196 private to be renamed as necessary to avoid collisions. Because the
197 symbol is private to the module, all references can be updated. This
198 doesn't show up in any symbol table in the object file.
200 Similar to private, but the value shows as a local symbol
201 (``STB_LOCAL`` in the case of ELF) in the object file. This
202 corresponds to the notion of the '``static``' keyword in C.
203 ``available_externally``
204 Globals with "``available_externally``" linkage are never emitted into
205 the object file corresponding to the LLVM module. From the linker's
206 perspective, an ``available_externally`` global is equivalent to
207 an external declaration. They exist to allow inlining and other
208 optimizations to take place given knowledge of the definition of the
209 global, which is known to be somewhere outside the module. Globals
210 with ``available_externally`` linkage are allowed to be discarded at
211 will, and allow inlining and other optimizations. This linkage type is
212 only allowed on definitions, not declarations.
214 Globals with "``linkonce``" linkage are merged with other globals of
215 the same name when linkage occurs. This can be used to implement
216 some forms of inline functions, templates, or other code which must
217 be generated in each translation unit that uses it, but where the
218 body may be overridden with a more definitive definition later.
219 Unreferenced ``linkonce`` globals are allowed to be discarded. Note
220 that ``linkonce`` linkage does not actually allow the optimizer to
221 inline the body of this function into callers because it doesn't
222 know if this definition of the function is the definitive definition
223 within the program or whether it will be overridden by a stronger
224 definition. To enable inlining and other optimizations, use
225 "``linkonce_odr``" linkage.
227 "``weak``" linkage has the same merging semantics as ``linkonce``
228 linkage, except that unreferenced globals with ``weak`` linkage may
229 not be discarded. This is used for globals that are declared "weak"
232 "``common``" linkage is most similar to "``weak``" linkage, but they
233 are used for tentative definitions in C, such as "``int X;``" at
234 global scope. Symbols with "``common``" linkage are merged in the
235 same way as ``weak symbols``, and they may not be deleted if
236 unreferenced. ``common`` symbols may not have an explicit section,
237 must have a zero initializer, and may not be marked
238 ':ref:`constant <globalvars>`'. Functions and aliases may not have
241 .. _linkage_appending:
244 "``appending``" linkage may only be applied to global variables of
245 pointer to array type. When two global variables with appending
246 linkage are linked together, the two global arrays are appended
247 together. This is the LLVM, typesafe, equivalent of having the
248 system linker append together "sections" with identical names when
251 Unfortunately this doesn't correspond to any feature in .o files, so it
252 can only be used for variables like ``llvm.global_ctors`` which llvm
253 interprets specially.
256 The semantics of this linkage follow the ELF object file model: the
257 symbol is weak until linked, if not linked, the symbol becomes null
258 instead of being an undefined reference.
259 ``linkonce_odr``, ``weak_odr``
260 Some languages allow differing globals to be merged, such as two
261 functions with different semantics. Other languages, such as
262 ``C++``, ensure that only equivalent globals are ever merged (the
263 "one definition rule" --- "ODR"). Such languages can use the
264 ``linkonce_odr`` and ``weak_odr`` linkage types to indicate that the
265 global will only be merged with equivalent globals. These linkage
266 types are otherwise the same as their non-``odr`` versions.
268 If none of the above identifiers are used, the global is externally
269 visible, meaning that it participates in linkage and can be used to
270 resolve external symbol references.
272 It is illegal for a global variable or function *declaration* to have any
273 linkage type other than ``external`` or ``extern_weak``.
280 LLVM :ref:`functions <functionstructure>`, :ref:`calls <i_call>` and
281 :ref:`invokes <i_invoke>` can all have an optional calling convention
282 specified for the call. The calling convention of any pair of dynamic
283 caller/callee must match, or the behavior of the program is undefined.
284 The following calling conventions are supported by LLVM, and more may be
287 "``ccc``" - The C calling convention
288 This calling convention (the default if no other calling convention
289 is specified) matches the target C calling conventions. This calling
290 convention supports varargs function calls and tolerates some
291 mismatch in the declared prototype and implemented declaration of
292 the function (as does normal C).
293 "``fastcc``" - The fast calling convention
294 This calling convention attempts to make calls as fast as possible
295 (e.g. by passing things in registers). This calling convention
296 allows the target to use whatever tricks it wants to produce fast
297 code for the target, without having to conform to an externally
298 specified ABI (Application Binary Interface). `Tail calls can only
299 be optimized when this, the tailcc, the GHC or the HiPE convention is
300 used. <CodeGenerator.html#tail-call-optimization>`_ This calling
301 convention does not support varargs and requires the prototype of all
302 callees to exactly match the prototype of the function definition.
303 "``coldcc``" - The cold calling convention
304 This calling convention attempts to make code in the caller as
305 efficient as possible under the assumption that the call is not
306 commonly executed. As such, these calls often preserve all registers
307 so that the call does not break any live ranges in the caller side.
308 This calling convention does not support varargs and requires the
309 prototype of all callees to exactly match the prototype of the
310 function definition. Furthermore the inliner doesn't consider such function
312 "``cc 10``" - GHC convention
313 This calling convention has been implemented specifically for use by
314 the `Glasgow Haskell Compiler (GHC) <http://www.haskell.org/ghc>`_.
315 It passes everything in registers, going to extremes to achieve this
316 by disabling callee save registers. This calling convention should
317 not be used lightly but only for specific situations such as an
318 alternative to the *register pinning* performance technique often
319 used when implementing functional programming languages. At the
320 moment only X86 supports this convention and it has the following
323 - On *X86-32* only supports up to 4 bit type parameters. No
324 floating-point types are supported.
325 - On *X86-64* only supports up to 10 bit type parameters and 6
326 floating-point parameters.
328 This calling convention supports `tail call
329 optimization <CodeGenerator.html#tail-call-optimization>`_ but requires
330 both the caller and callee are using it.
331 "``cc 11``" - The HiPE calling convention
332 This calling convention has been implemented specifically for use by
333 the `High-Performance Erlang
334 (HiPE) <http://www.it.uu.se/research/group/hipe/>`_ compiler, *the*
335 native code compiler of the `Ericsson's Open Source Erlang/OTP
336 system <http://www.erlang.org/download.shtml>`_. It uses more
337 registers for argument passing than the ordinary C calling
338 convention and defines no callee-saved registers. The calling
339 convention properly supports `tail call
340 optimization <CodeGenerator.html#tail-call-optimization>`_ but requires
341 that both the caller and the callee use it. It uses a *register pinning*
342 mechanism, similar to GHC's convention, for keeping frequently
343 accessed runtime components pinned to specific hardware registers.
344 At the moment only X86 supports this convention (both 32 and 64
346 "``webkit_jscc``" - WebKit's JavaScript calling convention
347 This calling convention has been implemented for `WebKit FTL JIT
348 <https://trac.webkit.org/wiki/FTLJIT>`_. It passes arguments on the
349 stack right to left (as cdecl does), and returns a value in the
350 platform's customary return register.
351 "``anyregcc``" - Dynamic calling convention for code patching
352 This is a special convention that supports patching an arbitrary code
353 sequence in place of a call site. This convention forces the call
354 arguments into registers but allows them to be dynamically
355 allocated. This can currently only be used with calls to
356 llvm.experimental.patchpoint because only this intrinsic records
357 the location of its arguments in a side table. See :doc:`StackMaps`.
358 "``preserve_mostcc``" - The `PreserveMost` calling convention
359 This calling convention attempts to make the code in the caller as
360 unintrusive as possible. This convention behaves identically to the `C`
361 calling convention on how arguments and return values are passed, but it
362 uses a different set of caller/callee-saved registers. This alleviates the
363 burden of saving and recovering a large register set before and after the
364 call in the caller. If the arguments are passed in callee-saved registers,
365 then they will be preserved by the callee across the call. This doesn't
366 apply for values returned in callee-saved registers.
368 - On X86-64 the callee preserves all general purpose registers, except for
369 R11 and return registers, if any. R11 can be used as a scratch register.
370 Floating-point registers (XMMs/YMMs) are not preserved and need to be
373 - On AArch64 the callee preserve all general purpose registers, except X0-X8
376 The idea behind this convention is to support calls to runtime functions
377 that have a hot path and a cold path. The hot path is usually a small piece
378 of code that doesn't use many registers. The cold path might need to call out to
379 another function and therefore only needs to preserve the caller-saved
380 registers, which haven't already been saved by the caller. The
381 `PreserveMost` calling convention is very similar to the `cold` calling
382 convention in terms of caller/callee-saved registers, but they are used for
383 different types of function calls. `coldcc` is for function calls that are
384 rarely executed, whereas `preserve_mostcc` function calls are intended to be
385 on the hot path and definitely executed a lot. Furthermore `preserve_mostcc`
386 doesn't prevent the inliner from inlining the function call.
388 This calling convention will be used by a future version of the ObjectiveC
389 runtime and should therefore still be considered experimental at this time.
390 Although this convention was created to optimize certain runtime calls to
391 the ObjectiveC runtime, it is not limited to this runtime and might be used
392 by other runtimes in the future too. The current implementation only
393 supports X86-64, but the intention is to support more architectures in the
395 "``preserve_allcc``" - The `PreserveAll` calling convention
396 This calling convention attempts to make the code in the caller even less
397 intrusive than the `PreserveMost` calling convention. This calling
398 convention also behaves identical to the `C` calling convention on how
399 arguments and return values are passed, but it uses a different set of
400 caller/callee-saved registers. This removes the burden of saving and
401 recovering a large register set before and after the call in the caller. If
402 the arguments are passed in callee-saved registers, then they will be
403 preserved by the callee across the call. This doesn't apply for values
404 returned in callee-saved registers.
406 - On X86-64 the callee preserves all general purpose registers, except for
407 R11. R11 can be used as a scratch register. Furthermore it also preserves
408 all floating-point registers (XMMs/YMMs).
410 - On AArch64 the callee preserve all general purpose registers, except X0-X8
411 and X16-X18. Furthermore it also preserves lower 128 bits of V8-V31 SIMD -
412 floating point registers.
414 The idea behind this convention is to support calls to runtime functions
415 that don't need to call out to any other functions.
417 This calling convention, like the `PreserveMost` calling convention, will be
418 used by a future version of the ObjectiveC runtime and should be considered
419 experimental at this time.
420 "``cxx_fast_tlscc``" - The `CXX_FAST_TLS` calling convention for access functions
421 Clang generates an access function to access C++-style TLS. The access
422 function generally has an entry block, an exit block and an initialization
423 block that is run at the first time. The entry and exit blocks can access
424 a few TLS IR variables, each access will be lowered to a platform-specific
427 This calling convention aims to minimize overhead in the caller by
428 preserving as many registers as possible (all the registers that are
429 preserved on the fast path, composed of the entry and exit blocks).
431 This calling convention behaves identical to the `C` calling convention on
432 how arguments and return values are passed, but it uses a different set of
433 caller/callee-saved registers.
435 Given that each platform has its own lowering sequence, hence its own set
436 of preserved registers, we can't use the existing `PreserveMost`.
438 - On X86-64 the callee preserves all general purpose registers, except for
440 "``tailcc``" - Tail callable calling convention
441 This calling convention ensures that calls in tail position will always be
442 tail call optimized. This calling convention is equivalent to fastcc,
443 except for an additional guarantee that tail calls will be produced
444 whenever possible. `Tail calls can only be optimized when this, the fastcc,
445 the GHC or the HiPE convention is used. <CodeGenerator.html#tail-call-optimization>`_
446 This calling convention does not support varargs and requires the prototype of
447 all callees to exactly match the prototype of the function definition.
448 "``swiftcc``" - This calling convention is used for Swift language.
449 - On X86-64 RCX and R8 are available for additional integer returns, and
450 XMM2 and XMM3 are available for additional FP/vector returns.
451 - On iOS platforms, we use AAPCS-VFP calling convention.
453 This calling convention is like ``swiftcc`` in most respects, but also the
454 callee pops the argument area of the stack so that mandatory tail calls are
455 possible as in ``tailcc``.
456 "``cfguard_checkcc``" - Windows Control Flow Guard (Check mechanism)
457 This calling convention is used for the Control Flow Guard check function,
458 calls to which can be inserted before indirect calls to check that the call
459 target is a valid function address. The check function has no return value,
460 but it will trigger an OS-level error if the address is not a valid target.
461 The set of registers preserved by the check function, and the register
462 containing the target address are architecture-specific.
464 - On X86 the target address is passed in ECX.
465 - On ARM the target address is passed in R0.
466 - On AArch64 the target address is passed in X15.
467 "``cc <n>``" - Numbered convention
468 Any calling convention may be specified by number, allowing
469 target-specific calling conventions to be used. Target specific
470 calling conventions start at 64.
472 More calling conventions can be added/defined on an as-needed basis, to
473 support Pascal conventions or any other well-known target-independent
476 .. _visibilitystyles:
481 All Global Variables and Functions have one of the following visibility
484 "``default``" - Default style
485 On targets that use the ELF object file format, default visibility
486 means that the declaration is visible to other modules and, in
487 shared libraries, means that the declared entity may be overridden.
488 On Darwin, default visibility means that the declaration is visible
489 to other modules. On XCOFF, default visibility means no explicit
490 visibility bit will be set and whether the symbol is visible
491 (i.e "exported") to other modules depends primarily on export lists
492 provided to the linker. Default visibility corresponds to "external
493 linkage" in the language.
494 "``hidden``" - Hidden style
495 Two declarations of an object with hidden visibility refer to the
496 same object if they are in the same shared object. Usually, hidden
497 visibility indicates that the symbol will not be placed into the
498 dynamic symbol table, so no other module (executable or shared
499 library) can reference it directly.
500 "``protected``" - Protected style
501 On ELF, protected visibility indicates that the symbol will be
502 placed in the dynamic symbol table, but that references within the
503 defining module will bind to the local symbol. That is, the symbol
504 cannot be overridden by another module.
506 A symbol with ``internal`` or ``private`` linkage must have ``default``
514 All Global Variables, Functions and Aliases can have one of the following
518 "``dllimport``" causes the compiler to reference a function or variable via
519 a global pointer to a pointer that is set up by the DLL exporting the
520 symbol. On Microsoft Windows targets, the pointer name is formed by
521 combining ``__imp_`` and the function or variable name.
523 On Microsoft Windows targets, "``dllexport``" causes the compiler to provide
524 a global pointer to a pointer in a DLL, so that it can be referenced with the
525 ``dllimport`` attribute. the pointer name is formed by combining ``__imp_``
526 and the function or variable name. On XCOFF targets, ``dllexport`` indicates
527 that the symbol will be made visible to other modules using "exported"
528 visibility and thus placed by the linker in the loader section symbol table.
529 Since this storage class exists for defining a dll interface, the compiler,
530 assembler and linker know it is externally referenced and must refrain from
533 A symbol with ``internal`` or ``private`` linkage cannot have a DLL storage
538 Thread Local Storage Models
539 ---------------------------
541 A variable may be defined as ``thread_local``, which means that it will
542 not be shared by threads (each thread will have a separated copy of the
543 variable). Not all targets support thread-local variables. Optionally, a
544 TLS model may be specified:
547 For variables that are only used within the current shared library.
549 For variables in modules that will not be loaded dynamically.
551 For variables defined in the executable and only used within it.
553 If no explicit model is given, the "general dynamic" model is used.
555 The models correspond to the ELF TLS models; see `ELF Handling For
556 Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for
557 more information on under which circumstances the different models may
558 be used. The target may choose a different TLS model if the specified
559 model is not supported, or if a better choice of model can be made.
561 A model can also be specified in an alias, but then it only governs how
562 the alias is accessed. It will not have any effect in the aliasee.
564 For platforms without linker support of ELF TLS model, the -femulated-tls
565 flag can be used to generate GCC compatible emulated TLS code.
567 .. _runtime_preemption_model:
569 Runtime Preemption Specifiers
570 -----------------------------
572 Global variables, functions and aliases may have an optional runtime preemption
573 specifier. If a preemption specifier isn't given explicitly, then a
574 symbol is assumed to be ``dso_preemptable``.
577 Indicates that the function or variable may be replaced by a symbol from
578 outside the linkage unit at runtime.
581 The compiler may assume that a function or variable marked as ``dso_local``
582 will resolve to a symbol within the same linkage unit. Direct access will
583 be generated even if the definition is not within this compilation unit.
590 LLVM IR allows you to specify both "identified" and "literal" :ref:`structure
591 types <t_struct>`. Literal types are uniqued structurally, but identified types
592 are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used
593 to forward declare a type that is not yet available.
595 An example of an identified structure specification is:
599 %mytype = type { %mytype*, i32 }
601 Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only
602 literal types are uniqued in recent versions of LLVM.
606 Non-Integral Pointer Type
607 -------------------------
609 Note: non-integral pointer types are a work in progress, and they should be
610 considered experimental at this time.
612 LLVM IR optionally allows the frontend to denote pointers in certain address
613 spaces as "non-integral" via the :ref:`datalayout string<langref_datalayout>`.
614 Non-integral pointer types represent pointers that have an *unspecified* bitwise
615 representation; that is, the integral representation may be target dependent or
616 unstable (not backed by a fixed integer).
618 ``inttoptr`` and ``ptrtoint`` instructions have the same semantics as for
619 integral (i.e. normal) pointers in that they convert integers to and from
620 corresponding pointer types, but there are additional implications to be
621 aware of. Because the bit-representation of a non-integral pointer may
622 not be stable, two identical casts of the same operand may or may not
623 return the same value. Said differently, the conversion to or from the
624 non-integral type depends on environmental state in an implementation
627 If the frontend wishes to observe a *particular* value following a cast, the
628 generated IR must fence with the underlying environment in an implementation
629 defined manner. (In practice, this tends to require ``noinline`` routines for
632 From the perspective of the optimizer, ``inttoptr`` and ``ptrtoint`` for
633 non-integral types are analogous to ones on integral types with one
634 key exception: the optimizer may not, in general, insert new dynamic
635 occurrences of such casts. If a new cast is inserted, the optimizer would
636 need to either ensure that a) all possible values are valid, or b)
637 appropriate fencing is inserted. Since the appropriate fencing is
638 implementation defined, the optimizer can't do the latter. The former is
639 challenging as many commonly expected properties, such as
640 ``ptrtoint(v)-ptrtoint(v) == 0``, don't hold for non-integral types.
647 Global variables define regions of memory allocated at compilation time
650 Global variable definitions must be initialized.
652 Global variables in other translation units can also be declared, in which
653 case they don't have an initializer.
655 Global variables can optionally specify a :ref:`linkage type <linkage>`.
657 Either global variable definitions or declarations may have an explicit section
658 to be placed in and may have an optional explicit alignment specified. If there
659 is a mismatch between the explicit or inferred section information for the
660 variable declaration and its definition the resulting behavior is undefined.
662 A variable may be defined as a global ``constant``, which indicates that
663 the contents of the variable will **never** be modified (enabling better
664 optimization, allowing the global data to be placed in the read-only
665 section of an executable, etc). Note that variables that need runtime
666 initialization cannot be marked ``constant`` as there is a store to the
669 LLVM explicitly allows *declarations* of global variables to be marked
670 constant, even if the final definition of the global is not. This
671 capability can be used to enable slightly better optimization of the
672 program, but requires the language definition to guarantee that
673 optimizations based on the 'constantness' are valid for the translation
674 units that do not include the definition.
676 As SSA values, global variables define pointer values that are in scope
677 (i.e. they dominate) all basic blocks in the program. Global variables
678 always define a pointer to their "content" type because they describe a
679 region of memory, and all memory objects in LLVM are accessed through
682 Global variables can be marked with ``unnamed_addr`` which indicates
683 that the address is not significant, only the content. Constants marked
684 like this can be merged with other constants if they have the same
685 initializer. Note that a constant with significant address *can* be
686 merged with a ``unnamed_addr`` constant, the result being a constant
687 whose address is significant.
689 If the ``local_unnamed_addr`` attribute is given, the address is known to
690 not be significant within the module.
692 A global variable may be declared to reside in a target-specific
693 numbered address space. For targets that support them, address spaces
694 may affect how optimizations are performed and/or what target
695 instructions are used to access the variable. The default address space
696 is zero. The address space qualifier must precede any other attributes.
698 LLVM allows an explicit section to be specified for globals. If the
699 target supports it, it will emit globals to the section specified.
700 Additionally, the global can placed in a comdat if the target has the necessary
703 External declarations may have an explicit section specified. Section
704 information is retained in LLVM IR for targets that make use of this
705 information. Attaching section information to an external declaration is an
706 assertion that its definition is located in the specified section. If the
707 definition is located in a different section, the behavior is undefined.
709 By default, global initializers are optimized by assuming that global
710 variables defined within the module are not modified from their
711 initial values before the start of the global initializer. This is
712 true even for variables potentially accessible from outside the
713 module, including those with external linkage or appearing in
714 ``@llvm.used`` or dllexported variables. This assumption may be suppressed
715 by marking the variable with ``externally_initialized``.
717 An explicit alignment may be specified for a global, which must be a
718 power of 2. If not present, or if the alignment is set to zero, the
719 alignment of the global is set by the target to whatever it feels
720 convenient. If an explicit alignment is specified, the global is forced
721 to have exactly that alignment. Targets and optimizers are not allowed
722 to over-align the global if the global has an assigned section. In this
723 case, the extra alignment could be observable: for example, code could
724 assume that the globals are densely packed in their section and try to
725 iterate over them as an array, alignment padding would break this
726 iteration. For TLS variables, the module flag ``MaxTLSAlign``, if present,
727 limits the alignment to the given value. Optimizers are not allowed to
728 impose a stronger alignment on these variables. The maximum alignment
731 For global variable declarations, as well as definitions that may be
732 replaced at link time (``linkonce``, ``weak``, ``extern_weak`` and ``common``
733 linkage types), the allocation size and alignment of the definition it resolves
734 to must be greater than or equal to that of the declaration or replaceable
735 definition, otherwise the behavior is undefined.
737 Globals can also have a :ref:`DLL storage class <dllstorageclass>`,
738 an optional :ref:`runtime preemption specifier <runtime_preemption_model>`,
739 an optional :ref:`global attributes <glattrs>` and
740 an optional list of attached :ref:`metadata <metadata>`.
742 Variables and aliases can have a
743 :ref:`Thread Local Storage Model <tls_model>`.
745 :ref:`Scalable vectors <t_vector>` cannot be global variables or members of
746 arrays because their size is unknown at compile time. They are allowed in
747 structs to facilitate intrinsics returning multiple values. Generally, structs
748 containing scalable vectors are not considered "sized" and cannot be used in
749 loads, stores, allocas, or GEPs. The only exception to this rule is for structs
750 that contain scalable vectors of the same type (e.g. ``{<vscale x 2 x i32>,
751 <vscale x 2 x i32>}`` contains the same type while ``{<vscale x 2 x i32>,
752 <vscale x 2 x i64>}`` doesn't). These kinds of structs (we may call them
753 homogeneous scalable vector structs) are considered sized and can be used in
754 loads, stores, allocas, but not GEPs.
758 @<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility]
759 [DLLStorageClass] [ThreadLocal]
760 [(unnamed_addr|local_unnamed_addr)] [AddrSpace]
761 [ExternallyInitialized]
762 <global | constant> <Type> [<InitializerConstant>]
763 [, section "name"] [, partition "name"]
764 [, comdat [($name)]] [, align <Alignment>]
765 [, no_sanitize_address] [, no_sanitize_hwaddress]
766 [, sanitize_address_dyninit] [, sanitize_memtag]
769 For example, the following defines a global in a numbered address space
770 with an initializer, section, and alignment:
774 @G = addrspace(5) constant float 1.0, section "foo", align 4
776 The following example just declares a global variable
780 @G = external global i32
782 The following example defines a thread-local global with the
783 ``initialexec`` TLS model:
787 @G = thread_local(initialexec) global i32 0, align 4
789 .. _functionstructure:
794 LLVM function definitions consist of the "``define``" keyword, an
795 optional :ref:`linkage type <linkage>`, an optional :ref:`runtime preemption
796 specifier <runtime_preemption_model>`, an optional :ref:`visibility
797 style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`,
798 an optional :ref:`calling convention <callingconv>`,
799 an optional ``unnamed_addr`` attribute, a return type, an optional
800 :ref:`parameter attribute <paramattrs>` for the return type, a function
801 name, a (possibly empty) argument list (each with optional :ref:`parameter
802 attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`,
803 an optional address space, an optional section, an optional partition,
804 an optional alignment, an optional :ref:`comdat <langref_comdats>`,
805 an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`,
806 an optional :ref:`prologue <prologuedata>`,
807 an optional :ref:`personality <personalityfn>`,
808 an optional list of attached :ref:`metadata <metadata>`,
809 an opening curly brace, a list of basic blocks, and a closing curly brace.
813 define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass]
815 <ResultType> @<FunctionName> ([argument list])
816 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs]
817 [section "name"] [partition "name"] [comdat [($name)]] [align N]
818 [gc] [prefix Constant] [prologue Constant] [personality Constant]
821 The argument list is a comma separated sequence of arguments where each
822 argument is of the following form:
826 <type> [parameter Attrs] [name]
828 LLVM function declarations consist of the "``declare``" keyword, an
829 optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style
830 <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an
831 optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr``
832 or ``local_unnamed_addr`` attribute, an optional address space, a return type,
833 an optional :ref:`parameter attribute <paramattrs>` for the return type, a function name, a possibly
834 empty list of arguments, an optional alignment, an optional :ref:`garbage
835 collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional
836 :ref:`prologue <prologuedata>`.
840 declare [linkage] [visibility] [DLLStorageClass]
842 <ResultType> @<FunctionName> ([argument list])
843 [(unnamed_addr|local_unnamed_addr)] [align N] [gc]
844 [prefix Constant] [prologue Constant]
846 A function definition contains a list of basic blocks, forming the CFG (Control
847 Flow Graph) for the function. Each basic block may optionally start with a label
848 (giving the basic block a symbol table entry), contains a list of instructions,
849 and ends with a :ref:`terminator <terminators>` instruction (such as a branch or
850 function return). If an explicit label name is not provided, a block is assigned
851 an implicit numbered label, using the next value from the same counter as used
852 for unnamed temporaries (:ref:`see above<identifiers>`). For example, if a
853 function entry block does not have an explicit label, it will be assigned label
854 "%0", then the first unnamed temporary in that block will be "%1", etc. If a
855 numeric label is explicitly specified, it must match the numeric label that
856 would be used implicitly.
858 The first basic block in a function is special in two ways: it is
859 immediately executed on entrance to the function, and it is not allowed
860 to have predecessor basic blocks (i.e. there can not be any branches to
861 the entry block of a function). Because the block can have no
862 predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`.
864 LLVM allows an explicit section to be specified for functions. If the
865 target supports it, it will emit functions to the section specified.
866 Additionally, the function can be placed in a COMDAT.
868 An explicit alignment may be specified for a function. If not present,
869 or if the alignment is set to zero, the alignment of the function is set
870 by the target to whatever it feels convenient. If an explicit alignment
871 is specified, the function is forced to have at least that much
872 alignment. All alignments must be a power of 2.
874 If the ``unnamed_addr`` attribute is given, the address is known to not
875 be significant and two identical functions can be merged.
877 If the ``local_unnamed_addr`` attribute is given, the address is known to
878 not be significant within the module.
880 If an explicit address space is not given, it will default to the program
881 address space from the :ref:`datalayout string<langref_datalayout>`.
888 Aliases, unlike function or variables, don't create any new data. They
889 are just a new symbol and metadata for an existing position.
891 Aliases have a name and an aliasee that is either a global value or a
894 Aliases may have an optional :ref:`linkage type <linkage>`, an optional
895 :ref:`runtime preemption specifier <runtime_preemption_model>`, an optional
896 :ref:`visibility style <visibility>`, an optional :ref:`DLL storage class
897 <dllstorageclass>` and an optional :ref:`tls model <tls_model>`.
901 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee>
904 The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
905 ``linkonce_odr``, ``weak_odr``, ``external``, ``available_externally``. Note
906 that some system linkers might not correctly handle dropping a weak symbol that
909 Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
910 the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
913 If the ``local_unnamed_addr`` attribute is given, the address is known to
914 not be significant within the module.
916 Since aliases are only a second name, some restrictions apply, of which
917 some can only be checked when producing an object file:
919 * The expression defining the aliasee must be computable at assembly
920 time. Since it is just a name, no relocations can be used.
922 * No alias in the expression can be weak as the possibility of the
923 intermediate alias being overridden cannot be represented in an
926 * If the alias has the ``available_externally`` linkage, the aliasee must be an
927 ``available_externally`` global value; otherwise the aliasee can be an
928 expression but no global value in the expression can be a declaration, since
929 that would require a relocation, which is not possible.
931 * If either the alias or the aliasee may be replaced by a symbol outside the
932 module at link time or runtime, any optimization cannot replace the alias with
933 the aliasee, since the behavior may be different. The alias may be used as a
934 name guaranteed to point to the content in the current module.
941 IFuncs, like as aliases, don't create any new data or func. They are just a new
942 symbol that dynamic linker resolves at runtime by calling a resolver function.
944 IFuncs have a name and a resolver that is a function called by dynamic linker
945 that returns address of another function associated with the name.
947 IFunc may have an optional :ref:`linkage type <linkage>` and an optional
948 :ref:`visibility style <visibility>`.
952 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver>
961 Comdat IR provides access to object file COMDAT/section group functionality
962 which represents interrelated sections.
964 Comdats have a name which represents the COMDAT key and a selection kind to
965 provide input on how the linker deduplicates comdats with the same key in two
966 different object files. A comdat must be included or omitted as a unit.
967 Discarding the whole comdat is allowed but discarding a subset is not.
969 A global object may be a member of at most one comdat. Aliases are placed in the
970 same COMDAT that their aliasee computes to, if any.
974 $<Name> = comdat SelectionKind
976 For selection kinds other than ``nodeduplicate``, only one of the duplicate
977 comdats may be retained by the linker and the members of the remaining comdats
978 must be discarded. The following selection kinds are supported:
981 The linker may choose any COMDAT key, the choice is arbitrary.
983 The linker may choose any COMDAT key but the sections must contain the
986 The linker will choose the section containing the largest COMDAT key.
988 No deduplication is performed.
990 The linker may choose any COMDAT key but the sections must contain the
993 - XCOFF and Mach-O don't support COMDATs.
994 - COFF supports all selection kinds. Non-``nodeduplicate`` selection kinds need
995 a non-local linkage COMDAT symbol.
996 - ELF supports ``any`` and ``nodeduplicate``.
997 - WebAssembly only supports ``any``.
999 Here is an example of a COFF COMDAT where a function will only be selected if
1000 the COMDAT key's section is the largest:
1002 .. code-block:: text
1004 $foo = comdat largest
1005 @foo = global i32 2, comdat($foo)
1007 define void @bar() comdat($foo) {
1011 In a COFF object file, this will create a COMDAT section with selection kind
1012 ``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol
1013 and another COMDAT section with selection kind
1014 ``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT
1015 section and contains the contents of the ``@bar`` symbol.
1017 As a syntactic sugar the ``$name`` can be omitted if the name is the same as
1020 .. code-block:: llvm
1023 @foo = global i32 2, comdat
1024 @bar = global i32 3, comdat($foo)
1026 There are some restrictions on the properties of the global object.
1027 It, or an alias to it, must have the same name as the COMDAT group when
1029 The contents and size of this object may be used during link-time to determine
1030 which COMDAT groups get selected depending on the selection kind.
1031 Because the name of the object must match the name of the COMDAT group, the
1032 linkage of the global object must not be local; local symbols can get renamed
1033 if a collision occurs in the symbol table.
1035 The combined use of COMDATS and section attributes may yield surprising results.
1038 .. code-block:: llvm
1042 @g1 = global i32 42, section "sec", comdat($foo)
1043 @g2 = global i32 42, section "sec", comdat($bar)
1045 From the object file perspective, this requires the creation of two sections
1046 with the same name. This is necessary because both globals belong to different
1047 COMDAT groups and COMDATs, at the object file level, are represented by
1050 Note that certain IR constructs like global variables and functions may
1051 create COMDATs in the object file in addition to any which are specified using
1052 COMDAT IR. This arises when the code generator is configured to emit globals
1053 in individual sections (e.g. when `-data-sections` or `-function-sections`
1054 is supplied to `llc`).
1056 .. _namedmetadatastructure:
1061 Named metadata is a collection of metadata. :ref:`Metadata
1062 nodes <metadata>` (but not metadata strings) are the only valid
1063 operands for a named metadata.
1065 #. Named metadata are represented as a string of characters with the
1066 metadata prefix. The rules for metadata names are the same as for
1067 identifiers, but quoted names are not allowed. ``"\xx"`` type escapes
1068 are still valid, which allows any character to be part of a name.
1072 ; Some unnamed metadata nodes, which are referenced by the named metadata.
1077 !name = !{!0, !1, !2}
1081 Parameter Attributes
1082 --------------------
1084 The return type and each parameter of a function type may have a set of
1085 *parameter attributes* associated with them. Parameter attributes are
1086 used to communicate additional information about the result or
1087 parameters of a function. Parameter attributes are considered to be part
1088 of the function, not of the function type, so functions with different
1089 parameter attributes can have the same function type.
1091 Parameter attributes are simple keywords that follow the type specified.
1092 If multiple parameter attributes are needed, they are space separated.
1095 .. code-block:: llvm
1097 declare i32 @printf(ptr noalias nocapture, ...)
1098 declare i32 @atoi(i8 zeroext)
1099 declare signext i8 @returns_signed_char()
1101 Note that any attributes for the function result (``nonnull``,
1102 ``signext``) come before the result type.
1104 Currently, only the following parameter attributes are defined:
1107 This indicates to the code generator that the parameter or return
1108 value should be zero-extended to the extent required by the target's
1109 ABI by the caller (for a parameter) or the callee (for a return value).
1111 This indicates to the code generator that the parameter or return
1112 value should be sign-extended to the extent required by the target's
1113 ABI (which is usually 32-bits) by the caller (for a parameter) or
1114 the callee (for a return value).
1116 This indicates that this parameter or return value should be treated
1117 in a special target-dependent fashion while emitting code for
1118 a function call or return (usually, by putting it in a register as
1119 opposed to memory, though some targets use it to distinguish between
1120 two different kinds of registers). Use of this attribute is
1123 This indicates that the pointer parameter should really be passed by
1124 value to the function. The attribute implies that a hidden copy of
1125 the pointee is made between the caller and the callee, so the callee
1126 is unable to modify the value in the caller. This attribute is only
1127 valid on LLVM pointer arguments. It is generally used to pass
1128 structs and arrays by value, but is also valid on pointers to
1129 scalars. The copy is considered to belong to the caller not the
1130 callee (for example, ``readonly`` functions should not write to
1131 ``byval`` parameters). This is not a valid attribute for return
1134 The byval type argument indicates the in-memory value type, and
1135 must be the same as the pointee type of the argument.
1137 The byval attribute also supports specifying an alignment with the
1138 align attribute. It indicates the alignment of the stack slot to
1139 form and the known alignment of the pointer specified to the call
1140 site. If the alignment is not specified, then the code generator
1141 makes a target-specific assumption.
1147 The ``byref`` argument attribute allows specifying the pointee
1148 memory type of an argument. This is similar to ``byval``, but does
1149 not imply a copy is made anywhere, or that the argument is passed
1150 on the stack. This implies the pointer is dereferenceable up to
1151 the storage size of the type.
1153 It is not generally permissible to introduce a write to an
1154 ``byref`` pointer. The pointer may have any address space and may
1157 This is not a valid attribute for return values.
1159 The alignment for an ``byref`` parameter can be explicitly
1160 specified by combining it with the ``align`` attribute, similar to
1161 ``byval``. If the alignment is not specified, then the code generator
1162 makes a target-specific assumption.
1164 This is intended for representing ABI constraints, and is not
1165 intended to be inferred for optimization use.
1167 .. _attr_preallocated:
1169 ``preallocated(<ty>)``
1170 This indicates that the pointer parameter should really be passed by
1171 value to the function, and that the pointer parameter's pointee has
1172 already been initialized before the call instruction. This attribute
1173 is only valid on LLVM pointer arguments. The argument must be the value
1174 returned by the appropriate
1175 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` on non
1176 ``musttail`` calls, or the corresponding caller parameter in ``musttail``
1177 calls, although it is ignored during codegen.
1179 A non ``musttail`` function call with a ``preallocated`` attribute in
1180 any parameter must have a ``"preallocated"`` operand bundle. A ``musttail``
1181 function call cannot have a ``"preallocated"`` operand bundle.
1183 The preallocated attribute requires a type argument, which must be
1184 the same as the pointee type of the argument.
1186 The preallocated attribute also supports specifying an alignment with the
1187 align attribute. It indicates the alignment of the stack slot to
1188 form and the known alignment of the pointer specified to the call
1189 site. If the alignment is not specified, then the code generator
1190 makes a target-specific assumption.
1196 The ``inalloca`` argument attribute allows the caller to take the
1197 address of outgoing stack arguments. An ``inalloca`` argument must
1198 be a pointer to stack memory produced by an ``alloca`` instruction.
1199 The alloca, or argument allocation, must also be tagged with the
1200 inalloca keyword. Only the last argument may have the ``inalloca``
1201 attribute, and that argument is guaranteed to be passed in memory.
1203 An argument allocation may be used by a call at most once because
1204 the call may deallocate it. The ``inalloca`` attribute cannot be
1205 used in conjunction with other attributes that affect argument
1206 storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The
1207 ``inalloca`` attribute also disables LLVM's implicit lowering of
1208 large aggregate return values, which means that frontend authors
1209 must lower them with ``sret`` pointers.
1211 When the call site is reached, the argument allocation must have
1212 been the most recent stack allocation that is still live, or the
1213 behavior is undefined. It is possible to allocate additional stack
1214 space after an argument allocation and before its call site, but it
1215 must be cleared off with :ref:`llvm.stackrestore
1216 <int_stackrestore>`.
1218 The inalloca attribute requires a type argument, which must be the
1219 same as the pointee type of the argument.
1221 See :doc:`InAlloca` for more information on how to use this
1225 This indicates that the pointer parameter specifies the address of a
1226 structure that is the return value of the function in the source
1227 program. This pointer must be guaranteed by the caller to be valid:
1228 loads and stores to the structure may be assumed by the callee not
1229 to trap and to be properly aligned. This is not a valid attribute
1232 The sret type argument specifies the in memory type, which must be
1233 the same as the pointee type of the argument.
1235 .. _attr_elementtype:
1237 ``elementtype(<ty>)``
1239 The ``elementtype`` argument attribute can be used to specify a pointer
1240 element type in a way that is compatible with `opaque pointers
1241 <OpaquePointers.html>`__.
1243 The ``elementtype`` attribute by itself does not carry any specific
1244 semantics. However, certain intrinsics may require this attribute to be
1245 present and assign it particular semantics. This will be documented on
1246 individual intrinsics.
1248 The attribute may only be applied to pointer typed arguments of intrinsic
1249 calls. It cannot be applied to non-intrinsic calls, and cannot be applied
1250 to parameters on function declarations. For non-opaque pointers, the type
1251 passed to ``elementtype`` must match the pointer element type.
1255 ``align <n>`` or ``align(<n>)``
1256 This indicates that the pointer value or vector of pointers has the
1257 specified alignment. If applied to a vector of pointers, *all* pointers
1258 (elements) have the specified alignment. If the pointer value does not have
1259 the specified alignment, :ref:`poison value <poisonvalues>` is returned or
1260 passed instead. The ``align`` attribute should be combined with the
1261 ``noundef`` attribute to ensure a pointer is aligned, or otherwise the
1262 behavior is undefined. Note that ``align 1`` has no effect on non-byval,
1263 non-preallocated arguments.
1265 Note that this attribute has additional semantics when combined with the
1266 ``byval`` or ``preallocated`` attribute, which are documented there.
1271 This indicates that memory locations accessed via pointer values
1272 :ref:`based <pointeraliasing>` on the argument or return value are not also
1273 accessed, during the execution of the function, via pointer values not
1274 *based* on the argument or return value. This guarantee only holds for
1275 memory locations that are *modified*, by any means, during the execution of
1276 the function. The attribute on a return value also has additional semantics
1277 described below. The caller shares the responsibility with the callee for
1278 ensuring that these requirements are met. For further details, please see
1279 the discussion of the NoAlias response in :ref:`alias analysis <Must, May,
1282 Note that this definition of ``noalias`` is intentionally similar
1283 to the definition of ``restrict`` in C99 for function arguments.
1285 For function return values, C99's ``restrict`` is not meaningful,
1286 while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias``
1287 attribute on return values are stronger than the semantics of the attribute
1288 when used on function arguments. On function return values, the ``noalias``
1289 attribute indicates that the function acts like a system memory allocation
1290 function, returning a pointer to allocated storage disjoint from the
1291 storage for any other object accessible to the caller.
1296 This indicates that the callee does not :ref:`capture <pointercapture>` the
1297 pointer. This is not a valid attribute for return values.
1298 This attribute applies only to the particular copy of the pointer passed in
1299 this argument. A caller could pass two copies of the same pointer with one
1300 being annotated nocapture and the other not, and the callee could validly
1301 capture through the non annotated parameter.
1303 .. code-block:: llvm
1305 define void @f(ptr nocapture %a, ptr %b) {
1309 call void @f(ptr @glb, ptr @glb) ; well-defined
1312 This indicates that callee does not free the pointer argument. This is not
1313 a valid attribute for return values.
1318 This indicates that the pointer parameter can be excised using the
1319 :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid
1320 attribute for return values and can only be applied to one parameter.
1323 This indicates that the function always returns the argument as its return
1324 value. This is a hint to the optimizer and code generator used when
1325 generating the caller, allowing value propagation, tail call optimization,
1326 and omission of register saves and restores in some cases; it is not
1327 checked or enforced when generating the callee. The parameter and the
1328 function return type must be valid operands for the
1329 :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for
1330 return values and can only be applied to one parameter.
1333 This indicates that the parameter or return pointer is not null. This
1334 attribute may only be applied to pointer typed parameters. This is not
1335 checked or enforced by LLVM; if the parameter or return pointer is null,
1336 :ref:`poison value <poisonvalues>` is returned or passed instead.
1337 The ``nonnull`` attribute should be combined with the ``noundef`` attribute
1338 to ensure a pointer is not null or otherwise the behavior is undefined.
1340 ``dereferenceable(<n>)``
1341 This indicates that the parameter or return pointer is dereferenceable. This
1342 attribute may only be applied to pointer typed parameters. A pointer that
1343 is dereferenceable can be loaded from speculatively without a risk of
1344 trapping. The number of bytes known to be dereferenceable must be provided
1345 in parentheses. It is legal for the number of bytes to be less than the
1346 size of the pointee type. The ``nonnull`` attribute does not imply
1347 dereferenceability (consider a pointer to one element past the end of an
1348 array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in
1349 ``addrspace(0)`` (which is the default address space), except if the
1350 ``null_pointer_is_valid`` function attribute is present.
1351 ``n`` should be a positive number. The pointer should be well defined,
1352 otherwise it is undefined behavior. This means ``dereferenceable(<n>)``
1353 implies ``noundef``.
1355 ``dereferenceable_or_null(<n>)``
1356 This indicates that the parameter or return value isn't both
1357 non-null and non-dereferenceable (up to ``<n>`` bytes) at the same
1358 time. All non-null pointers tagged with
1359 ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``.
1360 For address space 0 ``dereferenceable_or_null(<n>)`` implies that
1361 a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``,
1362 and in other address spaces ``dereferenceable_or_null(<n>)``
1363 implies that a pointer is at least one of ``dereferenceable(<n>)``
1364 or ``null`` (i.e. it may be both ``null`` and
1365 ``dereferenceable(<n>)``). This attribute may only be applied to
1366 pointer typed parameters.
1369 This indicates that the parameter is the self/context parameter. This is not
1370 a valid attribute for return values and can only be applied to one
1376 This indicates that the parameter is the asynchronous context parameter and
1377 triggers the creation of a target-specific extended frame record to store
1378 this pointer. This is not a valid attribute for return values and can only
1379 be applied to one parameter.
1382 This attribute is motivated to model and optimize Swift error handling. It
1383 can be applied to a parameter with pointer to pointer type or a
1384 pointer-sized alloca. At the call site, the actual argument that corresponds
1385 to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or
1386 the ``swifterror`` parameter of the caller. A ``swifterror`` value (either
1387 the parameter or the alloca) can only be loaded and stored from, or used as
1388 a ``swifterror`` argument. This is not a valid attribute for return values
1389 and can only be applied to one parameter.
1391 These constraints allow the calling convention to optimize access to
1392 ``swifterror`` variables by associating them with a specific register at
1393 call boundaries rather than placing them in memory. Since this does change
1394 the calling convention, a function which uses the ``swifterror`` attribute
1395 on a parameter is not ABI-compatible with one which does not.
1397 These constraints also allow LLVM to assume that a ``swifterror`` argument
1398 does not alias any other memory visible within a function and that a
1399 ``swifterror`` alloca passed as an argument does not escape.
1402 This indicates the parameter is required to be an immediate
1403 value. This must be a trivial immediate integer or floating-point
1404 constant. Undef or constant expressions are not valid. This is
1405 only valid on intrinsic declarations and cannot be applied to a
1406 call site or arbitrary function.
1409 This attribute applies to parameters and return values. If the value
1410 representation contains any undefined or poison bits, the behavior is
1411 undefined. Note that this does not refer to padding introduced by the
1412 type's storage representation.
1416 ``nofpclass(<test mask>)``
1417 This attribute applies to parameters and return values with
1418 floating-point and vector of floating-point types, as well as
1419 arrays of such types. The test mask has the same format as the
1420 second argument to the :ref:`llvm.is.fpclass <llvm.is.fpclass>`,
1421 and indicates which classes of floating-point values are not
1422 permitted for the value. For example a bitmask of 3 indicates
1423 the parameter may not be a NaN.
1425 If the value is a floating-point class indicated by the
1426 ``nofpclass`` test mask, a :ref:`poison value <poisonvalues>` is
1427 passed or returned instead.
1429 .. code-block:: text
1430 :caption: The following invariants hold
1432 @llvm.is.fpclass(nofpclass(test_mask) %x, test_mask) => false
1433 @llvm.is.fpclass(nofpclass(test_mask) %x, ~test_mask) => true
1434 nofpclass(all) => poison
1437 In textual IR, various string names are supported for readability
1438 and can be combined. For example ``nofpclass(nan pinf nzero)``
1439 evaluates to a mask of 547.
1441 This does not depend on the floating-point environment. For
1442 example, a function parameter marked ``nofpclass(zero)`` indicates
1443 no zero inputs. If this is applied to an argument in a function
1444 marked with :ref:`\"denormal-fp-math\" <denormal_fp_math>`
1445 indicating zero treatment of input denormals, it does not imply the
1446 value cannot be a denormal value which would compare equal to 0.
1448 .. table:: Recognized test mask names
1450 +-------+----------------------+---------------+
1451 | Name | floating-point class | Bitmask value |
1452 +=======+======================+===============+
1453 | nan | Any NaN | 3 |
1454 +-------+----------------------+---------------+
1455 | inf | +/- infinity | 516 |
1456 +-------+----------------------+---------------+
1457 | norm | +/- normal | 26 |
1458 +-------+----------------------+---------------+
1459 | sub | +/- subnormal | 144 |
1460 +-------+----------------------+---------------+
1461 | zero | +/- 0 | 96 |
1462 +-------+----------------------+---------------+
1463 | all | All values | 1023 |
1464 +-------+----------------------+---------------+
1465 | snan | Signaling NaN | 1 |
1466 +-------+----------------------+---------------+
1467 | qnan | Quiet NaN | 2 |
1468 +-------+----------------------+---------------+
1469 | ninf | Negative infinity | 4 |
1470 +-------+----------------------+---------------+
1471 | nnorm | Negative normal | 8 |
1472 +-------+----------------------+---------------+
1473 | nsub | Negative subnormal | 16 |
1474 +-------+----------------------+---------------+
1475 | nzero | Negative zero | 32 |
1476 +-------+----------------------+---------------+
1477 | pzero | Positive zero | 64 |
1478 +-------+----------------------+---------------+
1479 | psub | Positive subnormal | 128 |
1480 +-------+----------------------+---------------+
1481 | pnorm | Positive normal | 256 |
1482 +-------+----------------------+---------------+
1483 | pinf | Positive infinity | 512 |
1484 +-------+----------------------+---------------+
1488 This indicates the alignment that should be considered by the backend when
1489 assigning this parameter to a stack slot during calling convention
1490 lowering. The enforcement of the specified alignment is target-dependent,
1491 as target-specific calling convention rules may override this value. This
1492 attribute serves the purpose of carrying language specific alignment
1493 information that is not mapped to base types in the backend (for example,
1494 over-alignment specification through language attributes).
1497 The function parameter marked with this attribute is is the alignment in bytes of the
1498 newly allocated block returned by this function. The returned value must either have
1499 the specified alignment or be the null pointer. The return value MAY be more aligned
1500 than the requested alignment, but not less aligned. Invalid (e.g. non-power-of-2)
1501 alignments are permitted for the allocalign parameter, so long as the returned pointer
1502 is null. This attribute may only be applied to integer parameters.
1505 The function parameter marked with this attribute is the pointer
1506 that will be manipulated by the allocator. For a realloc-like
1507 function the pointer will be invalidated upon success (but the
1508 same address may be returned), for a free-like function the
1509 pointer will always be invalidated.
1512 This attribute indicates that the function does not dereference that
1513 pointer argument, even though it may read or write the memory that the
1514 pointer points to if accessed through other pointers.
1516 If a function reads from or writes to a readnone pointer argument, the
1517 behavior is undefined.
1520 This attribute indicates that the function does not write through this
1521 pointer argument, even though it may write to the memory that the pointer
1524 If a function writes to a readonly pointer argument, the behavior is
1528 This attribute indicates that the function may write to, but does not read
1529 through this pointer argument (even though it may read from the memory that
1530 the pointer points to).
1532 If a function reads from a writeonly pointer argument, the behavior is
1537 Garbage Collector Strategy Names
1538 --------------------------------
1540 Each function may specify a garbage collector strategy name, which is simply a
1543 .. code-block:: llvm
1545 define void @f() gc "name" { ... }
1547 The supported values of *name* includes those :ref:`built in to LLVM
1548 <builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC
1549 strategy will cause the compiler to alter its output in order to support the
1550 named garbage collection algorithm. Note that LLVM itself does not contain a
1551 garbage collector, this functionality is restricted to generating machine code
1552 which can interoperate with a collector provided externally.
1559 Prefix data is data associated with a function which the code
1560 generator will emit immediately before the function's entrypoint.
1561 The purpose of this feature is to allow frontends to associate
1562 language-specific runtime metadata with specific functions and make it
1563 available through the function pointer while still allowing the
1564 function pointer to be called.
1566 To access the data for a given function, a program may bitcast the
1567 function pointer to a pointer to the constant's type and dereference
1568 index -1. This implies that the IR symbol points just past the end of
1569 the prefix data. For instance, take the example of a function annotated
1570 with a single ``i32``,
1572 .. code-block:: llvm
1574 define void @f() prefix i32 123 { ... }
1576 The prefix data can be referenced as,
1578 .. code-block:: llvm
1580 %a = getelementptr inbounds i32, ptr @f, i32 -1
1581 %b = load i32, ptr %a
1583 Prefix data is laid out as if it were an initializer for a global variable
1584 of the prefix data's type. The function will be placed such that the
1585 beginning of the prefix data is aligned. This means that if the size
1586 of the prefix data is not a multiple of the alignment size, the
1587 function's entrypoint will not be aligned. If alignment of the
1588 function's entrypoint is desired, padding must be added to the prefix
1591 A function may have prefix data but no body. This has similar semantics
1592 to the ``available_externally`` linkage in that the data may be used by the
1593 optimizers but will not be emitted in the object file.
1600 The ``prologue`` attribute allows arbitrary code (encoded as bytes) to
1601 be inserted prior to the function body. This can be used for enabling
1602 function hot-patching and instrumentation.
1604 To maintain the semantics of ordinary function calls, the prologue data must
1605 have a particular format. Specifically, it must begin with a sequence of
1606 bytes which decode to a sequence of machine instructions, valid for the
1607 module's target, which transfer control to the point immediately succeeding
1608 the prologue data, without performing any other visible action. This allows
1609 the inliner and other passes to reason about the semantics of the function
1610 definition without needing to reason about the prologue data. Obviously this
1611 makes the format of the prologue data highly target dependent.
1613 A trivial example of valid prologue data for the x86 architecture is ``i8 144``,
1614 which encodes the ``nop`` instruction:
1616 .. code-block:: text
1618 define void @f() prologue i8 144 { ... }
1620 Generally prologue data can be formed by encoding a relative branch instruction
1621 which skips the metadata, as in this example of valid prologue data for the
1622 x86_64 architecture, where the first two bytes encode ``jmp .+10``:
1624 .. code-block:: text
1626 %0 = type <{ i8, i8, ptr }>
1628 define void @f() prologue %0 <{ i8 235, i8 8, ptr @md}> { ... }
1630 A function may have prologue data but no body. This has similar semantics
1631 to the ``available_externally`` linkage in that the data may be used by the
1632 optimizers but will not be emitted in the object file.
1636 Personality Function
1637 --------------------
1639 The ``personality`` attribute permits functions to specify what function
1640 to use for exception handling.
1647 Attribute groups are groups of attributes that are referenced by objects within
1648 the IR. They are important for keeping ``.ll`` files readable, because a lot of
1649 functions will use the same set of attributes. In the degenerative case of a
1650 ``.ll`` file that corresponds to a single ``.c`` file, the single attribute
1651 group will capture the important command line flags used to build that file.
1653 An attribute group is a module-level object. To use an attribute group, an
1654 object references the attribute group's ID (e.g. ``#37``). An object may refer
1655 to more than one attribute group. In that situation, the attributes from the
1656 different groups are merged.
1658 Here is an example of attribute groups for a function that should always be
1659 inlined, has a stack alignment of 4, and which shouldn't use SSE instructions:
1661 .. code-block:: llvm
1663 ; Target-independent attributes:
1664 attributes #0 = { alwaysinline alignstack=4 }
1666 ; Target-dependent attributes:
1667 attributes #1 = { "no-sse" }
1669 ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse".
1670 define void @f() #0 #1 { ... }
1677 Function attributes are set to communicate additional information about
1678 a function. Function attributes are considered to be part of the
1679 function, not of the function type, so functions with different function
1680 attributes can have the same function type.
1682 Function attributes are simple keywords that follow the type specified.
1683 If multiple attributes are needed, they are space separated. For
1686 .. code-block:: llvm
1688 define void @f() noinline { ... }
1689 define void @f() alwaysinline { ... }
1690 define void @f() alwaysinline optsize { ... }
1691 define void @f() optsize { ... }
1694 This attribute indicates that, when emitting the prologue and
1695 epilogue, the backend should forcibly align the stack pointer.
1696 Specify the desired alignment, which must be a power of two, in
1698 ``"alloc-family"="FAMILY"``
1699 This indicates which "family" an allocator function is part of. To avoid
1700 collisions, the family name should match the mangled name of the primary
1701 allocator function, that is "malloc" for malloc/calloc/realloc/free,
1702 "_Znwm" for ``::operator::new`` and ``::operator::delete``, and
1703 "_ZnwmSt11align_val_t" for aligned ``::operator::new`` and
1704 ``::operator::delete``. Matching malloc/realloc/free calls within a family
1705 can be optimized, but mismatched ones will be left alone.
1706 ``allockind("KIND")``
1707 Describes the behavior of an allocation function. The KIND string contains comma
1708 separated entries from the following options:
1710 * "alloc": the function returns a new block of memory or null.
1711 * "realloc": the function returns a new block of memory or null. If the
1712 result is non-null the memory contents from the start of the block up to
1713 the smaller of the original allocation size and the new allocation size
1714 will match that of the ``allocptr`` argument and the ``allocptr``
1715 argument is invalidated, even if the function returns the same address.
1716 * "free": the function frees the block of memory specified by ``allocptr``.
1717 Functions marked as "free" ``allockind`` must return void.
1718 * "uninitialized": Any newly-allocated memory (either a new block from
1719 a "alloc" function or the enlarged capacity from a "realloc" function)
1720 will be uninitialized.
1721 * "zeroed": Any newly-allocated memory (either a new block from a "alloc"
1722 function or the enlarged capacity from a "realloc" function) will be
1724 * "aligned": the function returns memory aligned according to the
1725 ``allocalign`` parameter.
1727 The first three options are mutually exclusive, and the remaining options
1728 describe more details of how the function behaves. The remaining options
1729 are invalid for "free"-type functions.
1730 ``allocsize(<EltSizeParam>[, <NumEltsParam>])``
1731 This attribute indicates that the annotated function will always return at
1732 least a given number of bytes (or null). Its arguments are zero-indexed
1733 parameter numbers; if one argument is provided, then it's assumed that at
1734 least ``CallSite.Args[EltSizeParam]`` bytes will be available at the
1735 returned pointer. If two are provided, then it's assumed that
1736 ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are
1737 available. The referenced parameters must be integer types. No assumptions
1738 are made about the contents of the returned block of memory.
1740 This attribute indicates that the inliner should attempt to inline
1741 this function into callers whenever possible, ignoring any active
1742 inlining size threshold for this caller.
1744 This indicates that the callee function at a call site should be
1745 recognized as a built-in function, even though the function's declaration
1746 uses the ``nobuiltin`` attribute. This is only valid at call sites for
1747 direct calls to functions that are declared with the ``nobuiltin``
1750 This attribute indicates that this function is rarely called. When
1751 computing edge weights, basic blocks post-dominated by a cold
1752 function call are also considered to be cold; and, thus, given low
1755 In some parallel execution models, there exist operations that cannot be
1756 made control-dependent on any additional values. We call such operations
1757 ``convergent``, and mark them with this attribute.
1759 The ``convergent`` attribute may appear on functions or call/invoke
1760 instructions. When it appears on a function, it indicates that calls to
1761 this function should not be made control-dependent on additional values.
1762 For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so
1763 calls to this intrinsic cannot be made control-dependent on additional
1766 When it appears on a call/invoke, the ``convergent`` attribute indicates
1767 that we should treat the call as though we're calling a convergent
1768 function. This is particularly useful on indirect calls; without this we
1769 may treat such calls as though the target is non-convergent.
1771 The optimizer may remove the ``convergent`` attribute on functions when it
1772 can prove that the function does not execute any convergent operations.
1773 Similarly, the optimizer may remove ``convergent`` on calls/invokes when it
1774 can prove that the call/invoke cannot call a convergent function.
1775 ``disable_sanitizer_instrumentation``
1776 When instrumenting code with sanitizers, it can be important to skip certain
1777 functions to ensure no instrumentation is applied to them.
1779 This attribute is not always similar to absent ``sanitize_<name>``
1780 attributes: depending on the specific sanitizer, code can be inserted into
1781 functions regardless of the ``sanitize_<name>`` attribute to prevent false
1784 ``disable_sanitizer_instrumentation`` disables all kinds of instrumentation,
1785 taking precedence over the ``sanitize_<name>`` attributes and other compiler
1787 ``"dontcall-error"``
1788 This attribute denotes that an error diagnostic should be emitted when a
1789 call of a function with this attribute is not eliminated via optimization.
1790 Front ends can provide optional ``srcloc`` metadata nodes on call sites of
1791 such callees to attach information about where in the source language such a
1792 call came from. A string value can be provided as a note.
1794 This attribute denotes that a warning diagnostic should be emitted when a
1795 call of a function with this attribute is not eliminated via optimization.
1796 Front ends can provide optional ``srcloc`` metadata nodes on call sites of
1797 such callees to attach information about where in the source language such a
1798 call came from. A string value can be provided as a note.
1799 ``fn_ret_thunk_extern``
1800 This attribute tells the code generator that returns from functions should
1801 be replaced with jumps to externally-defined architecture-specific symbols.
1802 For X86, this symbol's identifier is ``__x86_return_thunk``.
1804 This attribute tells the code generator whether the function
1805 should keep the frame pointer. The code generator may emit the frame pointer
1806 even if this attribute says the frame pointer can be eliminated.
1807 The allowed string values are:
1809 * ``"none"`` (default) - the frame pointer can be eliminated.
1810 * ``"non-leaf"`` - the frame pointer should be kept if the function calls
1812 * ``"all"`` - the frame pointer should be kept.
1814 This attribute indicates that this function is a hot spot of the program
1815 execution. The function will be optimized more aggressively and will be
1816 placed into special subsection of the text section to improving locality.
1818 When profile feedback is enabled, this attribute has the precedence over
1819 the profile information. By marking a function ``hot``, users can work
1820 around the cases where the training input does not have good coverage
1821 on all the hot functions.
1823 This attribute indicates that the source code contained a hint that
1824 inlining this function is desirable (such as the "inline" keyword in
1825 C/C++). It is just a hint; it imposes no requirements on the
1828 This attribute indicates that the function should be added to a
1829 jump-instruction table at code-generation time, and that all address-taken
1830 references to this function should be replaced with a reference to the
1831 appropriate jump-instruction-table function pointer. Note that this creates
1832 a new pointer for the original function, which means that code that depends
1833 on function-pointer identity can break. So, any function annotated with
1834 ``jumptable`` must also be ``unnamed_addr``.
1836 This attribute specifies the possible memory effects of the call-site or
1837 function. It allows specifying the possible access kinds (``none``,
1838 ``read``, ``write``, or ``readwrite``) for the possible memory location
1839 kinds (``argmem``, ``inaccessiblemem``, as well as a default). It is best
1840 understood by example:
1842 - ``memory(none)``: Does not access any memory.
1843 - ``memory(read)``: May read (but not write) any memory.
1844 - ``memory(write)``: May write (but not read) any memory.
1845 - ``memory(readwrite)``: May read or write any memory.
1846 - ``memory(argmem: read)``: May only read argument memory.
1847 - ``memory(argmem: read, inaccessiblemem: write)``: May only read argument
1848 memory and only write inaccessible memory.
1849 - ``memory(read, argmem: readwrite)``: May read any memory (default mode)
1850 and additionally write argument memory.
1851 - ``memory(readwrite, argmem: none)``: May access any memory apart from
1854 The supported memory location kinds are:
1856 - ``argmem``: This refers to accesses that are based on pointer arguments
1858 - ``inaccessiblemem``: This refers to accesses to memory which is not
1859 accessible by the current module (before return from the function -- an
1860 allocator function may return newly accessible memory while only
1861 accessing inaccessible memory itself). Inaccessible memory is often used
1862 to model control dependencies of intrinsics.
1863 - The default access kind (specified without a location prefix) applies to
1864 all locations that haven't been specified explicitly, including those that
1865 don't currently have a dedicated location kind (e.g. accesses to globals
1866 or captured pointers).
1868 If the ``memory`` attribute is not specified, then ``memory(readwrite)``
1869 is implied (all memory effects are possible).
1871 The memory effects of a call can be computed as
1872 ``CallSiteEffects & (FunctionEffects | OperandBundleEffects)``. Thus, the
1873 call-site annotation takes precedence over the potential effects described
1874 by either the function annotation or the operand bundles.
1876 This attribute suggests that optimization passes and code generator
1877 passes make choices that keep the code size of this function as small
1878 as possible and perform optimizations that may sacrifice runtime
1879 performance in order to minimize the size of the generated code.
1881 This attribute disables prologue / epilogue emission for the
1882 function. This can have very system-specific consequences.
1883 ``"no-inline-line-tables"``
1884 When this attribute is set to true, the inliner discards source locations
1885 when inlining code and instead uses the source location of the call site.
1886 Breakpoints set on code that was inlined into the current function will
1887 not fire during the execution of the inlined call sites. If the debugger
1888 stops inside an inlined call site, it will appear to be stopped at the
1889 outermost inlined call site.
1891 When this attribute is set to true, the jump tables and lookup tables that
1892 can be generated from a switch case lowering are disabled.
1894 This indicates that the callee function at a call site is not recognized as
1895 a built-in function. LLVM will retain the original call and not replace it
1896 with equivalent code based on the semantics of the built-in function, unless
1897 the call site uses the ``builtin`` attribute. This is valid at call sites
1898 and on function declarations and definitions.
1900 This attribute indicates that the function is only allowed to jump back into
1901 caller's module by a return or an exception, and is not allowed to jump back
1902 by invoking a callback function, a direct, possibly transitive, external
1903 function call, use of ``longjmp``, or other means. It is a compiler hint that
1904 is used at module level to improve dataflow analysis, dropped during linking,
1905 and has no effect on functions defined in the current module.
1907 This attribute indicates that calls to the function cannot be
1908 duplicated. A call to a ``noduplicate`` function may be moved
1909 within its parent function, but may not be duplicated within
1910 its parent function.
1912 A function containing a ``noduplicate`` call may still
1913 be an inlining candidate, provided that the call is not
1914 duplicated by inlining. That implies that the function has
1915 internal linkage and only has one call site, so the original
1916 call is dead after inlining.
1918 This function attribute indicates that the function does not, directly or
1919 transitively, call a memory-deallocation function (``free``, for example)
1920 on a memory allocation which existed before the call.
1922 As a result, uncaptured pointers that are known to be dereferenceable
1923 prior to a call to a function with the ``nofree`` attribute are still
1924 known to be dereferenceable after the call. The capturing condition is
1925 necessary in environments where the function might communicate the
1926 pointer to another thread which then deallocates the memory. Alternatively,
1927 ``nosync`` would ensure such communication cannot happen and even captured
1928 pointers cannot be freed by the function.
1930 A ``nofree`` function is explicitly allowed to free memory which it
1931 allocated or (if not ``nosync``) arrange for another thread to free
1932 memory on it's behalf. As a result, perhaps surprisingly, a ``nofree``
1933 function can return a pointer to a previously deallocated memory object.
1935 Disallows implicit floating-point code. This inhibits optimizations that
1936 use floating-point code and floating-point registers for operations that are
1937 not nominally floating-point. LLVM instructions that perform floating-point
1938 operations or require access to floating-point registers may still cause
1939 floating-point code to be generated.
1941 Also inhibits optimizations that create SIMD/vector code and registers from
1942 scalar code such as vectorization or memcpy/memset optimization. This
1943 includes integer vectors. Vector instructions present in IR may still cause
1944 vector code to be generated.
1946 This attribute indicates that the inliner should never inline this
1947 function in any situation. This attribute may not be used together
1948 with the ``alwaysinline`` attribute.
1950 This attribute indicates that calls to this function should never be merged
1951 during optimization. For example, it will prevent tail merging otherwise
1952 identical code sequences that raise an exception or terminate the program.
1953 Tail merging normally reduces the precision of source location information,
1954 making stack traces less useful for debugging. This attribute gives the
1955 user control over the tradeoff between code size and debug information
1958 This attribute suppresses lazy symbol binding for the function. This
1959 may make calls to the function faster, at the cost of extra program
1960 startup time if the function is not called during program startup.
1962 This function attribute prevents instrumentation based profiling, used for
1963 coverage or profile based optimization, from being added to a function. It
1964 also blocks inlining if the caller and callee have different values of this
1967 This function attribute prevents instrumentation based profiling, used for
1968 coverage or profile based optimization, from being added to a function. This
1969 attribute does not restrict inlining, so instrumented instruction could end
1970 up in this function.
1972 This attribute indicates that the code generator should not use a
1973 red zone, even if the target-specific ABI normally permits it.
1974 ``indirect-tls-seg-refs``
1975 This attribute indicates that the code generator should not use
1976 direct TLS access through segment registers, even if the
1977 target-specific ABI normally permits it.
1979 This function attribute indicates that the function never returns
1980 normally, hence through a return instruction. This produces undefined
1981 behavior at runtime if the function ever does dynamically return. Annotated
1982 functions may still raise an exception, i.a., ``nounwind`` is not implied.
1984 This function attribute indicates that the function does not call itself
1985 either directly or indirectly down any possible call path. This produces
1986 undefined behavior at runtime if the function ever does recurse.
1988 .. _langref_willreturn:
1991 This function attribute indicates that a call of this function will
1992 either exhibit undefined behavior or comes back and continues execution
1993 at a point in the existing call stack that includes the current invocation.
1994 Annotated functions may still raise an exception, i.a., ``nounwind`` is not implied.
1995 If an invocation of an annotated function does not return control back
1996 to a point in the call stack, the behavior is undefined.
1998 This function attribute indicates that the function does not communicate
1999 (synchronize) with another thread through memory or other well-defined means.
2000 Synchronization is considered possible in the presence of `atomic` accesses
2001 that enforce an order, thus not "unordered" and "monotonic", `volatile` accesses,
2002 as well as `convergent` function calls. Note that through `convergent` function calls
2003 non-memory communication, e.g., cross-lane operations, are possible and are also
2004 considered synchronization. However `convergent` does not contradict `nosync`.
2005 If an annotated function does ever synchronize with another thread,
2006 the behavior is undefined.
2008 This function attribute indicates that the function never raises an
2009 exception. If the function does raise an exception, its runtime
2010 behavior is undefined. However, functions marked nounwind may still
2011 trap or generate asynchronous exceptions. Exception handling schemes
2012 that are recognized by LLVM to handle asynchronous exceptions, such
2013 as SEH, will still provide their implementation defined semantics.
2014 ``nosanitize_bounds``
2015 This attribute indicates that bounds checking sanitizer instrumentation
2016 is disabled for this function.
2017 ``nosanitize_coverage``
2018 This attribute indicates that SanitizerCoverage instrumentation is disabled
2020 ``null_pointer_is_valid``
2021 If ``null_pointer_is_valid`` is set, then the ``null`` address
2022 in address-space 0 is considered to be a valid address for memory loads and
2023 stores. Any analysis or optimization should not treat dereferencing a
2024 pointer to ``null`` as undefined behavior in this function.
2025 Note: Comparing address of a global variable to ``null`` may still
2026 evaluate to false because of a limitation in querying this attribute inside
2027 constant expressions.
2029 This attribute indicates that this function should be optimized
2030 for maximum fuzzing signal.
2032 This function attribute indicates that most optimization passes will skip
2033 this function, with the exception of interprocedural optimization passes.
2034 Code generation defaults to the "fast" instruction selector.
2035 This attribute cannot be used together with the ``alwaysinline``
2036 attribute; this attribute is also incompatible
2037 with the ``minsize`` attribute and the ``optsize`` attribute.
2039 This attribute requires the ``noinline`` attribute to be specified on
2040 the function as well, so the function is never inlined into any caller.
2041 Only functions with the ``alwaysinline`` attribute are valid
2042 candidates for inlining into the body of this function.
2044 This attribute suggests that optimization passes and code generator
2045 passes make choices that keep the code size of this function low,
2046 and otherwise do optimizations specifically to reduce code size as
2047 long as they do not significantly impact runtime performance.
2048 ``"patchable-function"``
2049 This attribute tells the code generator that the code
2050 generated for this function needs to follow certain conventions that
2051 make it possible for a runtime function to patch over it later.
2052 The exact effect of this attribute depends on its string value,
2053 for which there currently is one legal possibility:
2055 * ``"prologue-short-redirect"`` - This style of patchable
2056 function is intended to support patching a function prologue to
2057 redirect control away from the function in a thread safe
2058 manner. It guarantees that the first instruction of the
2059 function will be large enough to accommodate a short jump
2060 instruction, and will be sufficiently aligned to allow being
2061 fully changed via an atomic compare-and-swap instruction.
2062 While the first requirement can be satisfied by inserting large
2063 enough NOP, LLVM can and will try to re-purpose an existing
2064 instruction (i.e. one that would have to be emitted anyway) as
2065 the patchable instruction larger than a short jump.
2067 ``"prologue-short-redirect"`` is currently only supported on
2070 This attribute by itself does not imply restrictions on
2071 inter-procedural optimizations. All of the semantic effects the
2072 patching may have to be separately conveyed via the linkage type.
2074 This attribute indicates that the function will trigger a guard region
2075 in the end of the stack. It ensures that accesses to the stack must be
2076 no further apart than the size of the guard region to a previous
2077 access of the stack. It takes one required string value, the name of
2078 the stack probing function that will be called.
2080 If a function that has a ``"probe-stack"`` attribute is inlined into
2081 a function with another ``"probe-stack"`` attribute, the resulting
2082 function has the ``"probe-stack"`` attribute of the caller. If a
2083 function that has a ``"probe-stack"`` attribute is inlined into a
2084 function that has no ``"probe-stack"`` attribute at all, the resulting
2085 function has the ``"probe-stack"`` attribute of the callee.
2086 ``"stack-probe-size"``
2087 This attribute controls the behavior of stack probes: either
2088 the ``"probe-stack"`` attribute, or ABI-required stack probes, if any.
2089 It defines the size of the guard region. It ensures that if the function
2090 may use more stack space than the size of the guard region, stack probing
2091 sequence will be emitted. It takes one required integer value, which
2094 If a function that has a ``"stack-probe-size"`` attribute is inlined into
2095 a function with another ``"stack-probe-size"`` attribute, the resulting
2096 function has the ``"stack-probe-size"`` attribute that has the lower
2097 numeric value. If a function that has a ``"stack-probe-size"`` attribute is
2098 inlined into a function that has no ``"stack-probe-size"`` attribute
2099 at all, the resulting function has the ``"stack-probe-size"`` attribute
2101 ``"no-stack-arg-probe"``
2102 This attribute disables ABI-required stack probes, if any.
2104 This attribute indicates that this function can return twice. The C
2105 ``setjmp`` is an example of such a function. The compiler disables
2106 some optimizations (like tail calls) in the caller of these
2109 This attribute indicates that
2110 `SafeStack <https://clang.llvm.org/docs/SafeStack.html>`_
2111 protection is enabled for this function.
2113 If a function that has a ``safestack`` attribute is inlined into a
2114 function that doesn't have a ``safestack`` attribute or which has an
2115 ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting
2116 function will have a ``safestack`` attribute.
2117 ``sanitize_address``
2118 This attribute indicates that AddressSanitizer checks
2119 (dynamic address safety analysis) are enabled for this function.
2121 This attribute indicates that MemorySanitizer checks (dynamic detection
2122 of accesses to uninitialized memory) are enabled for this function.
2124 This attribute indicates that ThreadSanitizer checks
2125 (dynamic thread safety analysis) are enabled for this function.
2126 ``sanitize_hwaddress``
2127 This attribute indicates that HWAddressSanitizer checks
2128 (dynamic address safety analysis based on tagged pointers) are enabled for
2131 This attribute indicates that MemTagSanitizer checks
2132 (dynamic address safety analysis based on Armv8 MTE) are enabled for
2134 ``speculative_load_hardening``
2135 This attribute indicates that
2136 `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_
2137 should be enabled for the function body.
2139 Speculative Load Hardening is a best-effort mitigation against
2140 information leak attacks that make use of control flow
2141 miss-speculation - specifically miss-speculation of whether a branch
2142 is taken or not. Typically vulnerabilities enabling such attacks are
2143 classified as "Spectre variant #1". Notably, this does not attempt to
2144 mitigate against miss-speculation of branch target, classified as
2145 "Spectre variant #2" vulnerabilities.
2147 When inlining, the attribute is sticky. Inlining a function that carries
2148 this attribute will cause the caller to gain the attribute. This is intended
2149 to provide a maximally conservative model where the code in a function
2150 annotated with this attribute will always (even after inlining) end up
2153 This function attribute indicates that the function does not have any
2154 effects besides calculating its result and does not have undefined behavior.
2155 Note that ``speculatable`` is not enough to conclude that along any
2156 particular execution path the number of calls to this function will not be
2157 externally observable. This attribute is only valid on functions
2158 and declarations, not on individual call sites. If a function is
2159 incorrectly marked as speculatable and really does exhibit
2160 undefined behavior, the undefined behavior may be observed even
2161 if the call site is dead code.
2164 This attribute indicates that the function should emit a stack
2165 smashing protector. It is in the form of a "canary" --- a random value
2166 placed on the stack before the local variables that's checked upon
2167 return from the function to see if it has been overwritten. A
2168 heuristic is used to determine if a function needs stack protectors
2169 or not. The heuristic used will enable protectors for functions with:
2171 - Character arrays larger than ``ssp-buffer-size`` (default 8).
2172 - Aggregates containing character arrays larger than ``ssp-buffer-size``.
2173 - Calls to alloca() with variable sizes or constant sizes greater than
2174 ``ssp-buffer-size``.
2176 Variables that are identified as requiring a protector will be arranged
2177 on the stack such that they are adjacent to the stack protector guard.
2179 If a function with an ``ssp`` attribute is inlined into a calling function,
2180 the attribute is not carried over to the calling function.
2183 This attribute indicates that the function should emit a stack smashing
2184 protector. This attribute causes a strong heuristic to be used when
2185 determining if a function needs stack protectors. The strong heuristic
2186 will enable protectors for functions with:
2188 - Arrays of any size and type
2189 - Aggregates containing an array of any size and type.
2190 - Calls to alloca().
2191 - Local variables that have had their address taken.
2193 Variables that are identified as requiring a protector will be arranged
2194 on the stack such that they are adjacent to the stack protector guard.
2195 The specific layout rules are:
2197 #. Large arrays and structures containing large arrays
2198 (``>= ssp-buffer-size``) are closest to the stack protector.
2199 #. Small arrays and structures containing small arrays
2200 (``< ssp-buffer-size``) are 2nd closest to the protector.
2201 #. Variables that have had their address taken are 3rd closest to the
2204 This overrides the ``ssp`` function attribute.
2206 If a function with an ``sspstrong`` attribute is inlined into a calling
2207 function which has an ``ssp`` attribute, the calling function's attribute
2208 will be upgraded to ``sspstrong``.
2211 This attribute indicates that the function should *always* emit a stack
2212 smashing protector. This overrides the ``ssp`` and ``sspstrong`` function
2215 Variables that are identified as requiring a protector will be arranged
2216 on the stack such that they are adjacent to the stack protector guard.
2217 The specific layout rules are:
2219 #. Large arrays and structures containing large arrays
2220 (``>= ssp-buffer-size``) are closest to the stack protector.
2221 #. Small arrays and structures containing small arrays
2222 (``< ssp-buffer-size``) are 2nd closest to the protector.
2223 #. Variables that have had their address taken are 3rd closest to the
2226 If a function with an ``sspreq`` attribute is inlined into a calling
2227 function which has an ``ssp`` or ``sspstrong`` attribute, the calling
2228 function's attribute will be upgraded to ``sspreq``.
2231 This attribute indicates that the function was called from a scope that
2232 requires strict floating-point semantics. LLVM will not attempt any
2233 optimizations that require assumptions about the floating-point rounding
2234 mode or that might alter the state of floating-point status flags that
2235 might otherwise be set or cleared by calling this function. LLVM will
2236 not introduce any new floating-point instructions that may trap.
2238 .. _denormal_fp_math:
2240 ``"denormal-fp-math"``
2241 This indicates the denormal (subnormal) handling that may be
2242 assumed for the default floating-point environment. This is a
2243 comma separated pair. The elements may be one of ``"ieee"``,
2244 ``"preserve-sign"``, ``"positive-zero"``, or ``"dynamic"``. The
2245 first entry indicates the flushing mode for the result of floating
2246 point operations. The second indicates the handling of denormal inputs
2247 to floating point instructions. For compatibility with older
2248 bitcode, if the second value is omitted, both input and output
2249 modes will assume the same mode.
2251 If this is attribute is not specified, the default is ``"ieee,ieee"``.
2253 If the output mode is ``"preserve-sign"``, or ``"positive-zero"``,
2254 denormal outputs may be flushed to zero by standard floating-point
2255 operations. It is not mandated that flushing to zero occurs, but if
2256 a denormal output is flushed to zero, it must respect the sign
2257 mode. Not all targets support all modes.
2259 If the mode is ``"dynamic"``, the behavior is derived from the
2260 dynamic state of the floating-point environment. Transformations
2261 which depend on the behavior of denormal values should not be
2264 While this indicates the expected floating point mode the function
2265 will be executed with, this does not make any attempt to ensure
2266 the mode is consistent. User or platform code is expected to set
2267 the floating point mode appropriately before function entry.
2269 If the input mode is ``"preserve-sign"``, or ``"positive-zero"``,
2270 a floating-point operation must treat any input denormal value as
2271 zero. In some situations, if an instruction does not respect this
2272 mode, the input may need to be converted to 0 as if by
2273 ``@llvm.canonicalize`` during lowering for correctness.
2275 ``"denormal-fp-math-f32"``
2276 Same as ``"denormal-fp-math"``, but only controls the behavior of
2277 the 32-bit float type (or vectors of 32-bit floats). If both are
2278 are present, this overrides ``"denormal-fp-math"``. Not all targets
2279 support separately setting the denormal mode per type, and no
2280 attempt is made to diagnose unsupported uses. Currently this
2281 attribute is respected by the AMDGPU and NVPTX backends.
2284 This attribute indicates that the function will delegate to some other
2285 function with a tail call. The prototype of a thunk should not be used for
2286 optimization purposes. The caller is expected to cast the thunk prototype to
2287 match the thunk target prototype.
2289 ``"tls-load-hoist"``
2290 This attribute indicates that the function will try to reduce redundant
2291 tls address calculation by hoisting tls variable.
2293 ``uwtable[(sync|async)]``
2294 This attribute indicates that the ABI being targeted requires that
2295 an unwind table entry be produced for this function even if we can
2296 show that no exceptions passes by it. This is normally the case for
2297 the ELF x86-64 abi, but it can be disabled for some compilation
2298 units. The optional parameter describes what kind of unwind tables
2299 to generate: ``sync`` for normal unwind tables, ``async`` for asynchronous
2300 (instruction precise) unwind tables. Without the parameter, the attribute
2301 ``uwtable`` is equivalent to ``uwtable(async)``.
2303 This attribute indicates that no control-flow check will be performed on
2304 the attributed entity. It disables -fcf-protection=<> for a specific
2305 entity to fine grain the HW control flow protection mechanism. The flag
2306 is target independent and currently appertains to a function or function
2309 This attribute indicates that the ShadowCallStack checks are enabled for
2310 the function. The instrumentation checks that the return address for the
2311 function has not changed between the function prolog and epilog. It is
2312 currently x86_64-specific.
2314 .. _langref_mustprogress:
2317 This attribute indicates that the function is required to return, unwind,
2318 or interact with the environment in an observable way e.g. via a volatile
2319 memory access, I/O, or other synchronization. The ``mustprogress``
2320 attribute is intended to model the requirements of the first section of
2321 [intro.progress] of the C++ Standard. As a consequence, a loop in a
2322 function with the `mustprogress` attribute can be assumed to terminate if
2323 it does not interact with the environment in an observable way, and
2324 terminating loops without side-effects can be removed. If a `mustprogress`
2325 function does not satisfy this contract, the behavior is undefined. This
2326 attribute does not apply transitively to callees, but does apply to call
2327 sites within the function. Note that `willreturn` implies `mustprogress`.
2328 ``"warn-stack-size"="<threshold>"``
2329 This attribute sets a threshold to emit diagnostics once the frame size is
2330 known should the frame size exceed the specified value. It takes one
2331 required integer value, which should be a non-negative integer, and less
2332 than `UINT_MAX`. It's unspecified which threshold will be used when
2333 duplicate definitions are linked together with differing values.
2334 ``vscale_range(<min>[, <max>])``
2335 This attribute indicates the minimum and maximum vscale value for the given
2336 function. The min must be greater than 0. A maximum value of 0 means
2337 unbounded. If the optional max value is omitted then max is set to the
2338 value of min. If the attribute is not present, no assumptions are made
2339 about the range of vscale.
2341 This attribute indicates that outlining passes should not modify the
2344 Call Site Attributes
2345 ----------------------
2347 In addition to function attributes the following call site only
2348 attributes are supported:
2350 ``vector-function-abi-variant``
2351 This attribute can be attached to a :ref:`call <i_call>` to list
2352 the vector functions associated to the function. Notice that the
2353 attribute cannot be attached to a :ref:`invoke <i_invoke>` or a
2354 :ref:`callbr <i_callbr>` instruction. The attribute consists of a
2355 comma separated list of mangled names. The order of the list does
2356 not imply preference (it is logically a set). The compiler is free
2357 to pick any listed vector function of its choosing.
2359 The syntax for the mangled names is as follows:::
2361 _ZGV<isa><mask><vlen><parameters>_<scalar_name>[(<vector_redirection>)]
2363 When present, the attribute informs the compiler that the function
2364 ``<scalar_name>`` has a corresponding vector variant that can be
2365 used to perform the concurrent invocation of ``<scalar_name>`` on
2366 vectors. The shape of the vector function is described by the
2367 tokens between the prefix ``_ZGV`` and the ``<scalar_name>``
2368 token. The standard name of the vector function is
2369 ``_ZGV<isa><mask><vlen><parameters>_<scalar_name>``. When present,
2370 the optional token ``(<vector_redirection>)`` informs the compiler
2371 that a custom name is provided in addition to the standard one
2372 (custom names can be provided for example via the use of ``declare
2373 variant`` in OpenMP 5.0). The declaration of the variant must be
2374 present in the IR Module. The signature of the vector variant is
2375 determined by the rules of the Vector Function ABI (VFABI)
2376 specifications of the target. For Arm and X86, the VFABI can be
2377 found at https://github.com/ARM-software/abi-aa and
2378 https://software.intel.com/content/www/us/en/develop/download/vector-simd-function-abi.html,
2381 For X86 and Arm targets, the values of the tokens in the standard
2382 name are those that are defined in the VFABI. LLVM has an internal
2383 ``<isa>`` token that can be used to create scalar-to-vector
2384 mappings for functions that are not directly associated to any of
2385 the target ISAs (for example, some of the mappings stored in the
2386 TargetLibraryInfo). Valid values for the ``<isa>`` token are:::
2388 <isa>:= b | c | d | e -> X86 SSE, AVX, AVX2, AVX512
2389 | n | s -> Armv8 Advanced SIMD, SVE
2390 | __LLVM__ -> Internal LLVM Vector ISA
2392 For all targets currently supported (x86, Arm and Internal LLVM),
2393 the remaining tokens can have the following values:::
2395 <mask>:= M | N -> mask | no mask
2397 <vlen>:= number -> number of lanes
2398 | x -> VLA (Vector Length Agnostic)
2400 <parameters>:= v -> vector
2401 | l | l <number> -> linear
2402 | R | R <number> -> linear with ref modifier
2403 | L | L <number> -> linear with val modifier
2404 | U | U <number> -> linear with uval modifier
2405 | ls <pos> -> runtime linear
2406 | Rs <pos> -> runtime linear with ref modifier
2407 | Ls <pos> -> runtime linear with val modifier
2408 | Us <pos> -> runtime linear with uval modifier
2411 <scalar_name>:= name of the scalar function
2413 <vector_redirection>:= optional, custom name of the vector function
2415 ``preallocated(<ty>)``
2416 This attribute is required on calls to ``llvm.call.preallocated.arg``
2417 and cannot be used on any other call. See
2418 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` for more
2426 Attributes may be set to communicate additional information about a global variable.
2427 Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable
2428 are grouped into a single :ref:`attribute group <attrgrp>`.
2430 ``no_sanitize_address``
2431 This attribute indicates that the global variable should not have
2432 AddressSanitizer instrumentation applied to it, because it was annotated
2433 with `__attribute__((no_sanitize("address")))`,
2434 `__attribute__((disable_sanitizer_instrumentation))`, or included in the
2435 `-fsanitize-ignorelist` file.
2436 ``no_sanitize_hwaddress``
2437 This attribute indicates that the global variable should not have
2438 HWAddressSanitizer instrumentation applied to it, because it was annotated
2439 with `__attribute__((no_sanitize("hwaddress")))`,
2440 `__attribute__((disable_sanitizer_instrumentation))`, or included in the
2441 `-fsanitize-ignorelist` file.
2443 This attribute indicates that the global variable should have AArch64 memory
2444 tags (MTE) instrumentation applied to it. This attribute causes the
2445 suppression of certain optimisations, like GlobalMerge, as well as ensuring
2446 extra directives are emitted in the assembly and extra bits of metadata are
2447 placed in the object file so that the linker can ensure the accesses are
2448 protected by MTE. This attribute is added by clang when
2449 `-fsanitize=memtag-globals` is provided, as long as the global is not marked
2450 with `__attribute__((no_sanitize("memtag")))`,
2451 `__attribute__((disable_sanitizer_instrumentation))`, or included in the
2452 `-fsanitize-ignorelist` file. The AArch64 Globals Tagging pass may remove
2453 this attribute when it's not possible to tag the global (e.g. it's a TLS
2455 ``sanitize_address_dyninit``
2456 This attribute indicates that the global variable, when instrumented with
2457 AddressSanitizer, should be checked for ODR violations. This attribute is
2458 applied to global variables that are dynamically initialized according to
2466 Operand bundles are tagged sets of SSA values that can be associated
2467 with certain LLVM instructions (currently only ``call`` s and
2468 ``invoke`` s). In a way they are like metadata, but dropping them is
2469 incorrect and will change program semantics.
2473 operand bundle set ::= '[' operand bundle (, operand bundle )* ']'
2474 operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')'
2475 bundle operand ::= SSA value
2476 tag ::= string constant
2478 Operand bundles are **not** part of a function's signature, and a
2479 given function may be called from multiple places with different kinds
2480 of operand bundles. This reflects the fact that the operand bundles
2481 are conceptually a part of the ``call`` (or ``invoke``), not the
2482 callee being dispatched to.
2484 Operand bundles are a generic mechanism intended to support
2485 runtime-introspection-like functionality for managed languages. While
2486 the exact semantics of an operand bundle depend on the bundle tag,
2487 there are certain limitations to how much the presence of an operand
2488 bundle can influence the semantics of a program. These restrictions
2489 are described as the semantics of an "unknown" operand bundle. As
2490 long as the behavior of an operand bundle is describable within these
2491 restrictions, LLVM does not need to have special knowledge of the
2492 operand bundle to not miscompile programs containing it.
2494 - The bundle operands for an unknown operand bundle escape in unknown
2495 ways before control is transferred to the callee or invokee.
2496 - Calls and invokes with operand bundles have unknown read / write
2497 effect on the heap on entry and exit (even if the call target specifies
2498 a ``memory`` attribute), unless they're overridden with
2499 callsite specific attributes.
2500 - An operand bundle at a call site cannot change the implementation
2501 of the called function. Inter-procedural optimizations work as
2502 usual as long as they take into account the first two properties.
2504 More specific types of operand bundles are described below.
2506 .. _deopt_opbundles:
2508 Deoptimization Operand Bundles
2509 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2511 Deoptimization operand bundles are characterized by the ``"deopt"``
2512 operand bundle tag. These operand bundles represent an alternate
2513 "safe" continuation for the call site they're attached to, and can be
2514 used by a suitable runtime to deoptimize the compiled frame at the
2515 specified call site. There can be at most one ``"deopt"`` operand
2516 bundle attached to a call site. Exact details of deoptimization is
2517 out of scope for the language reference, but it usually involves
2518 rewriting a compiled frame into a set of interpreted frames.
2520 From the compiler's perspective, deoptimization operand bundles make
2521 the call sites they're attached to at least ``readonly``. They read
2522 through all of their pointer typed operands (even if they're not
2523 otherwise escaped) and the entire visible heap. Deoptimization
2524 operand bundles do not capture their operands except during
2525 deoptimization, in which case control will not be returned to the
2528 The inliner knows how to inline through calls that have deoptimization
2529 operand bundles. Just like inlining through a normal call site
2530 involves composing the normal and exceptional continuations, inlining
2531 through a call site with a deoptimization operand bundle needs to
2532 appropriately compose the "safe" deoptimization continuation. The
2533 inliner does this by prepending the parent's deoptimization
2534 continuation to every deoptimization continuation in the inlined body.
2535 E.g. inlining ``@f`` into ``@g`` in the following example
2537 .. code-block:: llvm
2540 call void @x() ;; no deopt state
2541 call void @y() [ "deopt"(i32 10) ]
2542 call void @y() [ "deopt"(i32 10), "unknown"(ptr null) ]
2547 call void @f() [ "deopt"(i32 20) ]
2553 .. code-block:: llvm
2556 call void @x() ;; still no deopt state
2557 call void @y() [ "deopt"(i32 20, i32 10) ]
2558 call void @y() [ "deopt"(i32 20, i32 10), "unknown"(ptr null) ]
2562 It is the frontend's responsibility to structure or encode the
2563 deoptimization state in a way that syntactically prepending the
2564 caller's deoptimization state to the callee's deoptimization state is
2565 semantically equivalent to composing the caller's deoptimization
2566 continuation after the callee's deoptimization continuation.
2570 Funclet Operand Bundles
2571 ^^^^^^^^^^^^^^^^^^^^^^^
2573 Funclet operand bundles are characterized by the ``"funclet"``
2574 operand bundle tag. These operand bundles indicate that a call site
2575 is within a particular funclet. There can be at most one
2576 ``"funclet"`` operand bundle attached to a call site and it must have
2577 exactly one bundle operand.
2579 If any funclet EH pads have been "entered" but not "exited" (per the
2580 `description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_),
2581 it is undefined behavior to execute a ``call`` or ``invoke`` which:
2583 * does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind
2585 * has a ``"funclet"`` bundle whose operand is not the most-recently-entered
2586 not-yet-exited funclet EH pad.
2588 Similarly, if no funclet EH pads have been entered-but-not-yet-exited,
2589 executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior.
2591 GC Transition Operand Bundles
2592 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2594 GC transition operand bundles are characterized by the
2595 ``"gc-transition"`` operand bundle tag. These operand bundles mark a
2596 call as a transition between a function with one GC strategy to a
2597 function with a different GC strategy. If coordinating the transition
2598 between GC strategies requires additional code generation at the call
2599 site, these bundles may contain any values that are needed by the
2600 generated code. For more details, see :ref:`GC Transitions
2601 <gc_transition_args>`.
2603 The bundle contain an arbitrary list of Values which need to be passed
2604 to GC transition code. They will be lowered and passed as operands to
2605 the appropriate GC_TRANSITION nodes in the selection DAG. It is assumed
2606 that these arguments must be available before and after (but not
2607 necessarily during) the execution of the callee.
2609 .. _assume_opbundles:
2611 Assume Operand Bundles
2612 ^^^^^^^^^^^^^^^^^^^^^^
2614 Operand bundles on an :ref:`llvm.assume <int_assume>` allows representing
2615 assumptions, such as that a :ref:`parameter attribute <paramattrs>` or a
2616 :ref:`function attribute <fnattrs>` holds for a certain value at a certain
2617 location. Operand bundles enable assumptions that are either hard or impossible
2618 to represent as a boolean argument of an :ref:`llvm.assume <int_assume>`.
2620 An assume operand bundle has the form:
2624 "<tag>"([ <arguments>] ])
2626 In the case of function or parameter attributes, the operand bundle has the
2631 "<tag>"([ <holds for value> [, <attribute argument>] ])
2633 * The tag of the operand bundle is usually the name of attribute that can be
2634 assumed to hold. It can also be `ignore`, this tag doesn't contain any
2635 information and should be ignored.
2636 * The first argument if present is the value for which the attribute hold.
2637 * The second argument if present is an argument of the attribute.
2639 If there are no arguments the attribute is a property of the call location.
2643 .. code-block:: llvm
2645 call void @llvm.assume(i1 true) ["align"(ptr %val, i32 8)]
2647 allows the optimizer to assume that at location of call to
2648 :ref:`llvm.assume <int_assume>` ``%val`` has an alignment of at least 8.
2650 .. code-block:: llvm
2652 call void @llvm.assume(i1 %cond) ["cold"(), "nonnull"(ptr %val)]
2654 allows the optimizer to assume that the :ref:`llvm.assume <int_assume>`
2655 call location is cold and that ``%val`` may not be null.
2657 Just like for the argument of :ref:`llvm.assume <int_assume>`, if any of the
2658 provided guarantees are violated at runtime the behavior is undefined.
2660 While attributes expect constant arguments, assume operand bundles may be
2661 provided a dynamic value, for example:
2663 .. code-block:: llvm
2665 call void @llvm.assume(i1 true) ["align"(ptr %val, i32 %align)]
2667 If the operand bundle value violates any requirements on the attribute value,
2668 the behavior is undefined, unless one of the following exceptions applies:
2670 * ``"align"`` operand bundles may specify a non-power-of-two alignment
2671 (including a zero alignment). If this is the case, then the pointer value
2672 must be a null pointer, otherwise the behavior is undefined.
2674 In addition to allowing operand bundles encoding function and parameter
2675 attributes, an assume operand bundle my also encode a ``separate_storage``
2676 operand bundle. This has the form:
2678 .. code-block:: llvm
2680 separate_storage(<val1>, <val2>)``
2682 This indicates that no pointer :ref:`based <pointeraliasing>` on one of its
2683 arguments can alias any pointer based on the other.
2685 Even if the assumed property can be encoded as a boolean value, like
2686 ``nonnull``, using operand bundles to express the property can still have
2689 * Attributes that can be expressed via operand bundles are directly the
2690 property that the optimizer uses and cares about. Encoding attributes as
2691 operand bundles removes the need for an instruction sequence that represents
2692 the property (e.g., `icmp ne ptr %p, null` for `nonnull`) and for the
2693 optimizer to deduce the property from that instruction sequence.
2694 * Expressing the property using operand bundles makes it easy to identify the
2695 use of the value as a use in an :ref:`llvm.assume <int_assume>`. This then
2696 simplifies and improves heuristics, e.g., for use "use-sensitive"
2699 .. _ob_preallocated:
2701 Preallocated Operand Bundles
2702 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2704 Preallocated operand bundles are characterized by the ``"preallocated"``
2705 operand bundle tag. These operand bundles allow separation of the allocation
2706 of the call argument memory from the call site. This is necessary to pass
2707 non-trivially copyable objects by value in a way that is compatible with MSVC
2708 on some targets. There can be at most one ``"preallocated"`` operand bundle
2709 attached to a call site and it must have exactly one bundle operand, which is
2710 a token generated by ``@llvm.call.preallocated.setup``. A call with this
2711 operand bundle should not adjust the stack before entering the function, as
2712 that will have been done by one of the ``@llvm.call.preallocated.*`` intrinsics.
2714 .. code-block:: llvm
2716 %foo = type { i64, i32 }
2720 %t = call token @llvm.call.preallocated.setup(i32 1)
2721 %a = call ptr @llvm.call.preallocated.arg(token %t, i32 0) preallocated(%foo)
2723 call void @bar(i32 42, ptr preallocated(%foo) %a) ["preallocated"(token %t)]
2727 GC Live Operand Bundles
2728 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2730 A "gc-live" operand bundle is only valid on a :ref:`gc.statepoint <gc_statepoint>`
2731 intrinsic. The operand bundle must contain every pointer to a garbage collected
2732 object which potentially needs to be updated by the garbage collector.
2734 When lowered, any relocated value will be recorded in the corresponding
2735 :ref:`stackmap entry <statepoint-stackmap-format>`. See the intrinsic description
2736 for further details.
2738 ObjC ARC Attached Call Operand Bundles
2739 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2741 A ``"clang.arc.attachedcall"`` operand bundle on a call indicates the call is
2742 implicitly followed by a marker instruction and a call to an ObjC runtime
2743 function that uses the result of the call. The operand bundle takes a mandatory
2744 pointer to the runtime function (``@objc_retainAutoreleasedReturnValue`` or
2745 ``@objc_unsafeClaimAutoreleasedReturnValue``).
2746 The return value of a call with this bundle is used by a call to
2747 ``@llvm.objc.clang.arc.noop.use`` unless the called function's return type is
2748 void, in which case the operand bundle is ignored.
2750 .. code-block:: llvm
2752 ; The marker instruction and a runtime function call are inserted after the call
2754 call ptr @foo() [ "clang.arc.attachedcall"(ptr @objc_retainAutoreleasedReturnValue) ]
2755 call ptr @foo() [ "clang.arc.attachedcall"(ptr @objc_unsafeClaimAutoreleasedReturnValue) ]
2757 The operand bundle is needed to ensure the call is immediately followed by the
2758 marker instruction and the ObjC runtime call in the final output.
2762 Pointer Authentication Operand Bundles
2763 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2765 Pointer Authentication operand bundles are characterized by the
2766 ``"ptrauth"`` operand bundle tag. They are described in the
2767 `Pointer Authentication <PointerAuth.html#operand-bundle>`__ document.
2771 KCFI Operand Bundles
2772 ^^^^^^^^^^^^^^^^^^^^
2774 A ``"kcfi"`` operand bundle on an indirect call indicates that the call will
2775 be preceded by a runtime type check, which validates that the call target is
2776 prefixed with a :ref:`type identifier<md_kcfi_type>` that matches the operand
2777 bundle attribute. For example:
2779 .. code-block:: llvm
2781 call void %0() ["kcfi"(i32 1234)]
2783 Clang emits KCFI operand bundles and the necessary metadata with
2784 ``-fsanitize=kcfi``.
2788 Module-Level Inline Assembly
2789 ----------------------------
2791 Modules may contain "module-level inline asm" blocks, which corresponds
2792 to the GCC "file scope inline asm" blocks. These blocks are internally
2793 concatenated by LLVM and treated as a single unit, but may be separated
2794 in the ``.ll`` file if desired. The syntax is very simple:
2796 .. code-block:: llvm
2798 module asm "inline asm code goes here"
2799 module asm "more can go here"
2801 The strings can contain any character by escaping non-printable
2802 characters. The escape sequence used is simply "\\xx" where "xx" is the
2803 two digit hex code for the number.
2805 Note that the assembly string *must* be parseable by LLVM's integrated assembler
2806 (unless it is disabled), even when emitting a ``.s`` file.
2808 .. _langref_datalayout:
2813 A module may specify a target specific data layout string that specifies
2814 how data is to be laid out in memory. The syntax for the data layout is
2817 .. code-block:: llvm
2819 target datalayout = "layout specification"
2821 The *layout specification* consists of a list of specifications
2822 separated by the minus sign character ('-'). Each specification starts
2823 with a letter and may include other information after the letter to
2824 define some aspect of the data layout. The specifications accepted are
2828 Specifies that the target lays out data in big-endian form. That is,
2829 the bits with the most significance have the lowest address
2832 Specifies that the target lays out data in little-endian form. That
2833 is, the bits with the least significance have the lowest address
2836 Specifies the natural alignment of the stack in bits. Alignment
2837 promotion of stack variables is limited to the natural stack
2838 alignment to avoid dynamic stack realignment. The stack alignment
2839 must be a multiple of 8-bits. If omitted, the natural stack
2840 alignment defaults to "unspecified", which does not prevent any
2841 alignment promotions.
2842 ``P<address space>``
2843 Specifies the address space that corresponds to program memory.
2844 Harvard architectures can use this to specify what space LLVM
2845 should place things such as functions into. If omitted, the
2846 program memory space defaults to the default address space of 0,
2847 which corresponds to a Von Neumann architecture that has code
2848 and data in the same space.
2849 ``G<address space>``
2850 Specifies the address space to be used by default when creating global
2851 variables. If omitted, the globals address space defaults to the default
2853 Note: variable declarations without an address space are always created in
2854 address space 0, this property only affects the default value to be used
2855 when creating globals without additional contextual information (e.g. in
2857 ``A<address space>``
2858 Specifies the address space of objects created by '``alloca``'.
2859 Defaults to the default address space of 0.
2860 ``p[n]:<size>:<abi>[:<pref>][:<idx>]``
2861 This specifies the *size* of a pointer and its ``<abi>`` and
2862 ``<pref>``\erred alignments for address space ``n``. ``<pref>`` is optional
2863 and defaults to ``<abi>``. The fourth parameter ``<idx>`` is the size of the
2864 index that used for address calculation. If not
2865 specified, the default index size is equal to the pointer size. All sizes
2866 are in bits. The address space, ``n``, is optional, and if not specified,
2867 denotes the default address space 0. The value of ``n`` must be
2868 in the range [1,2^24).
2869 ``i<size>:<abi>[:<pref>]``
2870 This specifies the alignment for an integer type of a given bit
2871 ``<size>``. The value of ``<size>`` must be in the range [1,2^24).
2872 ``<pref>`` is optional and defaults to ``<abi>``.
2873 For ``i8``, the ``<abi>`` value must equal 8,
2874 that is, ``i8`` must be naturally aligned.
2875 ``v<size>:<abi>[:<pref>]``
2876 This specifies the alignment for a vector type of a given bit
2877 ``<size>``. The value of ``<size>`` must be in the range [1,2^24).
2878 ``<pref>`` is optional and defaults to ``<abi>``.
2879 ``f<size>:<abi>[:<pref>]``
2880 This specifies the alignment for a floating-point type of a given bit
2881 ``<size>``. Only values of ``<size>`` that are supported by the target
2882 will work. 32 (float) and 64 (double) are supported on all targets; 80
2883 or 128 (different flavors of long double) are also supported on some
2884 targets. The value of ``<size>`` must be in the range [1,2^24).
2885 ``<pref>`` is optional and defaults to ``<abi>``.
2886 ``a:<abi>[:<pref>]``
2887 This specifies the alignment for an object of aggregate type.
2888 ``<pref>`` is optional and defaults to ``<abi>``.
2890 This specifies the alignment for function pointers.
2891 The options for ``<type>`` are:
2893 * ``i``: The alignment of function pointers is independent of the alignment
2894 of functions, and is a multiple of ``<abi>``.
2895 * ``n``: The alignment of function pointers is a multiple of the explicit
2896 alignment specified on the function, and is a multiple of ``<abi>``.
2898 If present, specifies that llvm names are mangled in the output. Symbols
2899 prefixed with the mangling escape character ``\01`` are passed through
2900 directly to the assembler without the escape character. The mangling style
2903 * ``e``: ELF mangling: Private symbols get a ``.L`` prefix.
2904 * ``l``: GOFF mangling: Private symbols get a ``@`` prefix.
2905 * ``m``: Mips mangling: Private symbols get a ``$`` prefix.
2906 * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other
2907 symbols get a ``_`` prefix.
2908 * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix.
2909 Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``,
2910 ``__fastcall``, and ``__vectorcall`` have custom mangling that appends
2911 ``@N`` where N is the number of bytes used to pass parameters. C++ symbols
2912 starting with ``?`` are not mangled in any way.
2913 * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C
2914 symbols do not receive a ``_`` prefix.
2915 * ``a``: XCOFF mangling: Private symbols get a ``L..`` prefix.
2916 ``n<size1>:<size2>:<size3>...``
2917 This specifies a set of native integer widths for the target CPU in
2918 bits. For example, it might contain ``n32`` for 32-bit PowerPC,
2919 ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of
2920 this set are considered to support most general arithmetic operations
2922 ``ni:<address space0>:<address space1>:<address space2>...``
2923 This specifies pointer types with the specified address spaces
2924 as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0``
2925 address space cannot be specified as non-integral.
2927 On every specification that takes a ``<abi>:<pref>``, specifying the
2928 ``<pref>`` alignment is optional. If omitted, the preceding ``:``
2929 should be omitted too and ``<pref>`` will be equal to ``<abi>``.
2931 When constructing the data layout for a given target, LLVM starts with a
2932 default set of specifications which are then (possibly) overridden by
2933 the specifications in the ``datalayout`` keyword. The default
2934 specifications are given in this list:
2936 - ``e`` - little endian
2937 - ``p:64:64:64`` - 64-bit pointers with 64-bit alignment.
2938 - ``p[n]:64:64:64`` - Other address spaces are assumed to be the
2939 same as the default address space.
2940 - ``S0`` - natural stack alignment is unspecified
2941 - ``i1:8:8`` - i1 is 8-bit (byte) aligned
2942 - ``i8:8:8`` - i8 is 8-bit (byte) aligned as mandated
2943 - ``i16:16:16`` - i16 is 16-bit aligned
2944 - ``i32:32:32`` - i32 is 32-bit aligned
2945 - ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred
2946 alignment of 64-bits
2947 - ``f16:16:16`` - half is 16-bit aligned
2948 - ``f32:32:32`` - float is 32-bit aligned
2949 - ``f64:64:64`` - double is 64-bit aligned
2950 - ``f128:128:128`` - quad is 128-bit aligned
2951 - ``v64:64:64`` - 64-bit vector is 64-bit aligned
2952 - ``v128:128:128`` - 128-bit vector is 128-bit aligned
2953 - ``a:0:64`` - aggregates are 64-bit aligned
2955 When LLVM is determining the alignment for a given type, it uses the
2958 #. If the type sought is an exact match for one of the specifications,
2959 that specification is used.
2960 #. If no match is found, and the type sought is an integer type, then
2961 the smallest integer type that is larger than the bitwidth of the
2962 sought type is used. If none of the specifications are larger than
2963 the bitwidth then the largest integer type is used. For example,
2964 given the default specifications above, the i7 type will use the
2965 alignment of i8 (next largest) while both i65 and i256 will use the
2966 alignment of i64 (largest specified).
2968 The function of the data layout string may not be what you expect.
2969 Notably, this is not a specification from the frontend of what alignment
2970 the code generator should use.
2972 Instead, if specified, the target data layout is required to match what
2973 the ultimate *code generator* expects. This string is used by the
2974 mid-level optimizers to improve code, and this only works if it matches
2975 what the ultimate code generator uses. There is no way to generate IR
2976 that does not embed this target-specific detail into the IR. If you
2977 don't specify the string, the default specifications will be used to
2978 generate a Data Layout and the optimization phases will operate
2979 accordingly and introduce target specificity into the IR with respect to
2980 these default specifications.
2987 A module may specify a target triple string that describes the target
2988 host. The syntax for the target triple is simply:
2990 .. code-block:: llvm
2992 target triple = "x86_64-apple-macosx10.7.0"
2994 The *target triple* string consists of a series of identifiers delimited
2995 by the minus sign character ('-'). The canonical forms are:
2999 ARCHITECTURE-VENDOR-OPERATING_SYSTEM
3000 ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
3002 This information is passed along to the backend so that it generates
3003 code for the proper architecture. It's possible to override this on the
3004 command line with the ``-mtriple`` command line option.
3009 ----------------------
3011 A memory object, or simply object, is a region of a memory space that is
3012 reserved by a memory allocation such as :ref:`alloca <i_alloca>`, heap
3013 allocation calls, and global variable definitions.
3014 Once it is allocated, the bytes stored in the region can only be read or written
3015 through a pointer that is :ref:`based on <pointeraliasing>` the allocation
3017 If a pointer that is not based on the object tries to read or write to the
3018 object, it is undefined behavior.
3020 A lifetime of a memory object is a property that decides its accessibility.
3021 Unless stated otherwise, a memory object is alive since its allocation, and
3022 dead after its deallocation.
3023 It is undefined behavior to access a memory object that isn't alive, but
3024 operations that don't dereference it such as
3025 :ref:`getelementptr <i_getelementptr>`, :ref:`ptrtoint <i_ptrtoint>` and
3026 :ref:`icmp <i_icmp>` return a valid result.
3027 This explains code motion of these instructions across operations that
3028 impact the object's lifetime.
3029 A stack object's lifetime can be explicitly specified using
3030 :ref:`llvm.lifetime.start <int_lifestart>` and
3031 :ref:`llvm.lifetime.end <int_lifeend>` intrinsic function calls.
3033 .. _pointeraliasing:
3035 Pointer Aliasing Rules
3036 ----------------------
3038 Any memory access must be done through a pointer value associated with
3039 an address range of the memory access, otherwise the behavior is
3040 undefined. Pointer values are associated with address ranges according
3041 to the following rules:
3043 - A pointer value is associated with the addresses associated with any
3044 value it is *based* on.
3045 - An address of a global variable is associated with the address range
3046 of the variable's storage.
3047 - The result value of an allocation instruction is associated with the
3048 address range of the allocated storage.
3049 - A null pointer in the default address-space is associated with no
3051 - An :ref:`undef value <undefvalues>` in *any* address-space is
3052 associated with no address.
3053 - An integer constant other than zero or a pointer value returned from
3054 a function not defined within LLVM may be associated with address
3055 ranges allocated through mechanisms other than those provided by
3056 LLVM. Such ranges shall not overlap with any ranges of addresses
3057 allocated by mechanisms provided by LLVM.
3059 A pointer value is *based* on another pointer value according to the
3062 - A pointer value formed from a scalar ``getelementptr`` operation is *based* on
3063 the pointer-typed operand of the ``getelementptr``.
3064 - The pointer in lane *l* of the result of a vector ``getelementptr`` operation
3065 is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand
3066 of the ``getelementptr``.
3067 - The result value of a ``bitcast`` is *based* on the operand of the
3069 - A pointer value formed by an ``inttoptr`` is *based* on all pointer
3070 values that contribute (directly or indirectly) to the computation of
3071 the pointer's value.
3072 - The "*based* on" relationship is transitive.
3074 Note that this definition of *"based"* is intentionally similar to the
3075 definition of *"based"* in C99, though it is slightly weaker.
3077 LLVM IR does not associate types with memory. The result type of a
3078 ``load`` merely indicates the size and alignment of the memory from
3079 which to load, as well as the interpretation of the value. The first
3080 operand type of a ``store`` similarly only indicates the size and
3081 alignment of the store.
3083 Consequently, type-based alias analysis, aka TBAA, aka
3084 ``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR.
3085 :ref:`Metadata <metadata>` may be used to encode additional information
3086 which specialized optimization passes may use to implement type-based
3094 Given a function call and a pointer that is passed as an argument or stored in
3095 the memory before the call, a pointer is *captured* by the call if it makes a
3096 copy of any part of the pointer that outlives the call.
3097 To be precise, a pointer is captured if one or more of the following conditions
3100 1. The call stores any bit of the pointer carrying information into a place,
3101 and the stored bits can be read from the place by the caller after this call
3104 .. code-block:: llvm
3106 @glb = global ptr null
3107 @glb2 = global ptr null
3108 @glb3 = global ptr null
3109 @glbi = global i32 0
3111 define ptr @f(ptr %a, ptr %b, ptr %c, ptr %d, ptr %e) {
3112 store ptr %a, ptr @glb ; %a is captured by this call
3114 store ptr %b, ptr @glb2 ; %b isn't captured because the stored value is overwritten by the store below
3115 store ptr null, ptr @glb2
3117 store ptr %c, ptr @glb3
3118 call void @g() ; If @g makes a copy of %c that outlives this call (@f), %c is captured
3119 store ptr null, ptr @glb3
3121 %i = ptrtoint ptr %d to i64
3122 %j = trunc i64 %i to i32
3123 store i32 %j, ptr @glbi ; %d is captured
3125 ret ptr %e ; %e is captured
3128 2. The call stores any bit of the pointer carrying information into a place,
3129 and the stored bits can be safely read from the place by another thread via
3132 .. code-block:: llvm
3134 @lock = global i1 true
3136 define void @f(ptr %a) {
3137 store ptr %a, ptr* @glb
3138 store atomic i1 false, ptr @lock release ; %a is captured because another thread can safely read @glb
3139 store ptr null, ptr @glb
3143 3. The call's behavior depends on any bit of the pointer carrying information.
3145 .. code-block:: llvm
3149 define void @f(ptr %a) {
3150 %c = icmp eq ptr %a, @glb
3151 br i1 %c, label %BB_EXIT, label %BB_CONTINUE ; escapes %a
3159 4. The pointer is used in a volatile access as its address.
3164 Volatile Memory Accesses
3165 ------------------------
3167 Certain memory accesses, such as :ref:`load <i_load>`'s,
3168 :ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be
3169 marked ``volatile``. The optimizers must not change the number of
3170 volatile operations or change their order of execution relative to other
3171 volatile operations. The optimizers *may* change the order of volatile
3172 operations relative to non-volatile operations. This is not Java's
3173 "volatile" and has no cross-thread synchronization behavior.
3175 A volatile load or store may have additional target-specific semantics.
3176 Any volatile operation can have side effects, and any volatile operation
3177 can read and/or modify state which is not accessible via a regular load
3178 or store in this module. Volatile operations may use addresses which do
3179 not point to memory (like MMIO registers). This means the compiler may
3180 not use a volatile operation to prove a non-volatile access to that
3181 address has defined behavior.
3183 The allowed side-effects for volatile accesses are limited. If a
3184 non-volatile store to a given address would be legal, a volatile
3185 operation may modify the memory at that address. A volatile operation
3186 may not modify any other memory accessible by the module being compiled.
3187 A volatile operation may not call any code in the current module.
3189 In general (without target specific context), the address space of a
3190 volatile operation may not be changed. Different address spaces may
3191 have different trapping behavior when dereferencing an invalid
3194 The compiler may assume execution will continue after a volatile operation,
3195 so operations which modify memory or may have undefined behavior can be
3196 hoisted past a volatile operation.
3198 As an exception to the preceding rule, the compiler may not assume execution
3199 will continue after a volatile store operation. This restriction is necessary
3200 to support the somewhat common pattern in C of intentionally storing to an
3201 invalid pointer to crash the program. In the future, it might make sense to
3202 allow frontends to control this behavior.
3204 IR-level volatile loads and stores cannot safely be optimized into llvm.memcpy
3205 or llvm.memmove intrinsics even when those intrinsics are flagged volatile.
3206 Likewise, the backend should never split or merge target-legal volatile
3207 load/store instructions. Similarly, IR-level volatile loads and stores cannot
3208 change from integer to floating-point or vice versa.
3210 .. admonition:: Rationale
3212 Platforms may rely on volatile loads and stores of natively supported
3213 data width to be executed as single instruction. For example, in C
3214 this holds for an l-value of volatile primitive type with native
3215 hardware support, but not necessarily for aggregate types. The
3216 frontend upholds these expectations, which are intentionally
3217 unspecified in the IR. The rules above ensure that IR transformations
3218 do not violate the frontend's contract with the language.
3222 Memory Model for Concurrent Operations
3223 --------------------------------------
3225 The LLVM IR does not define any way to start parallel threads of
3226 execution or to register signal handlers. Nonetheless, there are
3227 platform-specific ways to create them, and we define LLVM IR's behavior
3228 in their presence. This model is inspired by the C++0x memory model.
3230 For a more informal introduction to this model, see the :doc:`Atomics`.
3232 We define a *happens-before* partial order as the least partial order
3235 - Is a superset of single-thread program order, and
3236 - When a *synchronizes-with* ``b``, includes an edge from ``a`` to
3237 ``b``. *Synchronizes-with* pairs are introduced by platform-specific
3238 techniques, like pthread locks, thread creation, thread joining,
3239 etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering
3240 Constraints <ordering>`).
3242 Note that program order does not introduce *happens-before* edges
3243 between a thread and signals executing inside that thread.
3245 Every (defined) read operation (load instructions, memcpy, atomic
3246 loads/read-modify-writes, etc.) R reads a series of bytes written by
3247 (defined) write operations (store instructions, atomic
3248 stores/read-modify-writes, memcpy, etc.). For the purposes of this
3249 section, initialized globals are considered to have a write of the
3250 initializer which is atomic and happens before any other read or write
3251 of the memory in question. For each byte of a read R, R\ :sub:`byte`
3252 may see any write to the same byte, except:
3254 - If write\ :sub:`1` happens before write\ :sub:`2`, and
3255 write\ :sub:`2` happens before R\ :sub:`byte`, then
3256 R\ :sub:`byte` does not see write\ :sub:`1`.
3257 - If R\ :sub:`byte` happens before write\ :sub:`3`, then
3258 R\ :sub:`byte` does not see write\ :sub:`3`.
3260 Given that definition, R\ :sub:`byte` is defined as follows:
3262 - If R is volatile, the result is target-dependent. (Volatile is
3263 supposed to give guarantees which can support ``sig_atomic_t`` in
3264 C/C++, and may be used for accesses to addresses that do not behave
3265 like normal memory. It does not generally provide cross-thread
3267 - Otherwise, if there is no write to the same byte that happens before
3268 R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte.
3269 - Otherwise, if R\ :sub:`byte` may see exactly one write,
3270 R\ :sub:`byte` returns the value written by that write.
3271 - Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may
3272 see are atomic, it chooses one of the values written. See the :ref:`Atomic
3273 Memory Ordering Constraints <ordering>` section for additional
3274 constraints on how the choice is made.
3275 - Otherwise R\ :sub:`byte` returns ``undef``.
3277 R returns the value composed of the series of bytes it read. This
3278 implies that some bytes within the value may be ``undef`` **without**
3279 the entire value being ``undef``. Note that this only defines the
3280 semantics of the operation; it doesn't mean that targets will emit more
3281 than one instruction to read the series of bytes.
3283 Note that in cases where none of the atomic intrinsics are used, this
3284 model places only one restriction on IR transformations on top of what
3285 is required for single-threaded execution: introducing a store to a byte
3286 which might not otherwise be stored is not allowed in general.
3287 (Specifically, in the case where another thread might write to and read
3288 from an address, introducing a store can change a load that may see
3289 exactly one write into a load that may see multiple writes.)
3293 Atomic Memory Ordering Constraints
3294 ----------------------------------
3296 Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`,
3297 :ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`,
3298 :ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take
3299 ordering parameters that determine which other atomic instructions on
3300 the same address they *synchronize with*. These semantics are borrowed
3301 from Java and C++0x, but are somewhat more colloquial. If these
3302 descriptions aren't precise enough, check those specs (see spec
3303 references in the :doc:`atomics guide <Atomics>`).
3304 :ref:`fence <i_fence>` instructions treat these orderings somewhat
3305 differently since they don't take an address. See that instruction's
3306 documentation for details.
3308 For a simpler introduction to the ordering constraints, see the
3312 The set of values that can be read is governed by the happens-before
3313 partial order. A value cannot be read unless some operation wrote
3314 it. This is intended to provide a guarantee strong enough to model
3315 Java's non-volatile shared variables. This ordering cannot be
3316 specified for read-modify-write operations; it is not strong enough
3317 to make them atomic in any interesting way.
3319 In addition to the guarantees of ``unordered``, there is a single
3320 total order for modifications by ``monotonic`` operations on each
3321 address. All modification orders must be compatible with the
3322 happens-before order. There is no guarantee that the modification
3323 orders can be combined to a global total order for the whole program
3324 (and this often will not be possible). The read in an atomic
3325 read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and
3326 :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification
3327 order immediately before the value it writes. If one atomic read
3328 happens before another atomic read of the same address, the later
3329 read must see the same value or a later value in the address's
3330 modification order. This disallows reordering of ``monotonic`` (or
3331 stronger) operations on the same address. If an address is written
3332 ``monotonic``-ally by one thread, and other threads ``monotonic``-ally
3333 read that address repeatedly, the other threads must eventually see
3334 the write. This corresponds to the C++0x/C1x
3335 ``memory_order_relaxed``.
3337 In addition to the guarantees of ``monotonic``, a
3338 *synchronizes-with* edge may be formed with a ``release`` operation.
3339 This is intended to model C++'s ``memory_order_acquire``.
3341 In addition to the guarantees of ``monotonic``, if this operation
3342 writes a value which is subsequently read by an ``acquire``
3343 operation, it *synchronizes-with* that operation. (This isn't a
3344 complete description; see the C++0x definition of a release
3345 sequence.) This corresponds to the C++0x/C1x
3346 ``memory_order_release``.
3347 ``acq_rel`` (acquire+release)
3348 Acts as both an ``acquire`` and ``release`` operation on its
3349 address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``.
3350 ``seq_cst`` (sequentially consistent)
3351 In addition to the guarantees of ``acq_rel`` (``acquire`` for an
3352 operation that only reads, ``release`` for an operation that only
3353 writes), there is a global total order on all
3354 sequentially-consistent operations on all addresses, which is
3355 consistent with the *happens-before* partial order and with the
3356 modification orders of all the affected addresses. Each
3357 sequentially-consistent read sees the last preceding write to the
3358 same address in this global order. This corresponds to the C++0x/C1x
3359 ``memory_order_seq_cst`` and Java volatile.
3363 If an atomic operation is marked ``syncscope("singlethread")``, it only
3364 *synchronizes with* and only participates in the seq\_cst total orderings of
3365 other operations running in the same thread (for example, in signal handlers).
3367 If an atomic operation is marked ``syncscope("<target-scope>")``, where
3368 ``<target-scope>`` is a target specific synchronization scope, then it is target
3369 dependent if it *synchronizes with* and participates in the seq\_cst total
3370 orderings of other operations.
3372 Otherwise, an atomic operation that is not marked ``syncscope("singlethread")``
3373 or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the
3374 seq\_cst total orderings of other operations that are not marked
3375 ``syncscope("singlethread")`` or ``syncscope("<target-scope>")``.
3379 Floating-Point Environment
3380 --------------------------
3382 The default LLVM floating-point environment assumes that traps are disabled and
3383 status flags are not observable. Therefore, floating-point math operations do
3384 not have side effects and may be speculated freely. Results assume the
3385 round-to-nearest rounding mode.
3387 Floating-point math operations are allowed to treat all NaNs as if they were
3388 quiet NaNs. For example, "pow(1.0, SNaN)" may be simplified to 1.0. This also
3389 means that SNaN may be passed through a math operation without quieting. For
3390 example, "fmul SNaN, 1.0" may be simplified to SNaN rather than QNaN. However,
3391 SNaN values are never created by math operations. They may only occur when
3392 provided as a program input value.
3394 Code that requires different behavior than this should use the
3395 :ref:`Constrained Floating-Point Intrinsics <constrainedfp>`.
3402 LLVM IR floating-point operations (:ref:`fneg <i_fneg>`, :ref:`fadd <i_fadd>`,
3403 :ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
3404 :ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`), :ref:`phi <i_phi>`,
3405 :ref:`select <i_select>` and :ref:`call <i_call>`
3406 may use the following flags to enable otherwise unsafe
3407 floating-point transformations.
3410 No NaNs - Allow optimizations to assume the arguments and result are not
3411 NaN. If an argument is a nan, or the result would be a nan, it produces
3412 a :ref:`poison value <poisonvalues>` instead.
3415 No Infs - Allow optimizations to assume the arguments and result are not
3416 +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it
3417 produces a :ref:`poison value <poisonvalues>` instead.
3420 No Signed Zeros - Allow optimizations to treat the sign of a zero
3421 argument or zero result as insignificant. This does not imply that -0.0
3422 is poison and/or guaranteed to not exist in the operation.
3425 Allow Reciprocal - Allow optimizations to use the reciprocal of an
3426 argument rather than perform division.
3429 Allow floating-point contraction (e.g. fusing a multiply followed by an
3430 addition into a fused multiply-and-add). This does not enable reassociating
3431 to form arbitrary contractions. For example, ``(a*b) + (c*d) + e`` can not
3432 be transformed into ``(a*b) + ((c*d) + e)`` to create two fma operations.
3435 Approximate functions - Allow substitution of approximate calculations for
3436 functions (sin, log, sqrt, etc). See floating-point intrinsic definitions
3437 for places where this can apply to LLVM's intrinsic math functions.
3440 Allow reassociation transformations for floating-point instructions.
3441 This may dramatically change results in floating-point.
3444 This flag implies all of the others.
3448 Use-list Order Directives
3449 -------------------------
3451 Use-list directives encode the in-memory order of each use-list, allowing the
3452 order to be recreated. ``<order-indexes>`` is a comma-separated list of
3453 indexes that are assigned to the referenced value's uses. The referenced
3454 value's use-list is immediately sorted by these indexes.
3456 Use-list directives may appear at function scope or global scope. They are not
3457 instructions, and have no effect on the semantics of the IR. When they're at
3458 function scope, they must appear after the terminator of the final basic block.
3460 If basic blocks have their address taken via ``blockaddress()`` expressions,
3461 ``uselistorder_bb`` can be used to reorder their use-lists from outside their
3468 uselistorder <ty> <value>, { <order-indexes> }
3469 uselistorder_bb @function, %block { <order-indexes> }
3475 define void @foo(i32 %arg1, i32 %arg2) {
3477 ; ... instructions ...
3479 ; ... instructions ...
3481 ; At function scope.
3482 uselistorder i32 %arg1, { 1, 0, 2 }
3483 uselistorder label %bb, { 1, 0 }
3487 uselistorder ptr @global, { 1, 2, 0 }
3488 uselistorder i32 7, { 1, 0 }
3489 uselistorder i32 (i32) @bar, { 1, 0 }
3490 uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 }
3492 .. _source_filename:
3497 The *source filename* string is set to the original module identifier,
3498 which will be the name of the compiled source file when compiling from
3499 source through the clang front end, for example. It is then preserved through
3502 This is currently necessary to generate a consistent unique global
3503 identifier for local functions used in profile data, which prepends the
3504 source file name to the local function name.
3506 The syntax for the source file name is simply:
3508 .. code-block:: text
3510 source_filename = "/path/to/source.c"
3517 The LLVM type system is one of the most important features of the
3518 intermediate representation. Being typed enables a number of
3519 optimizations to be performed on the intermediate representation
3520 directly, without having to do extra analyses on the side before the
3521 transformation. A strong type system makes it easier to read the
3522 generated code and enables novel analyses and transformations that are
3523 not feasible to perform on normal three address code representations.
3533 The void type does not represent any value and has no size.
3551 The function type can be thought of as a function signature. It consists of a
3552 return type and a list of formal parameter types. The return type of a function
3553 type is a void type or first class type --- except for :ref:`label <t_label>`
3554 and :ref:`metadata <t_metadata>` types.
3560 <returntype> (<parameter list>)
3562 ...where '``<parameter list>``' is a comma-separated list of type
3563 specifiers. Optionally, the parameter list may include a type ``...``, which
3564 indicates that the function takes a variable number of arguments. Variable
3565 argument functions can access their arguments with the :ref:`variable argument
3566 handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type
3567 except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`.
3571 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3572 | ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` |
3573 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3574 | ``i32 (ptr, ...)`` | A vararg function that takes at least one :ref:`pointer <t_pointer>` argument and returns an integer. This is the signature for ``printf`` in LLVM. |
3575 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3576 | ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values |
3577 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3584 The :ref:`first class <t_firstclass>` types are perhaps the most important.
3585 Values of these types are the only ones which can be produced by
3593 These are the types that are valid in registers from CodeGen's perspective.
3602 The integer type is a very simple type that simply specifies an
3603 arbitrary bit width for the integer type desired. Any bit width from 1
3604 bit to 2\ :sup:`23`\ (about 8 million) can be specified.
3612 The number of bits the integer will occupy is specified by the ``N``
3618 +----------------+------------------------------------------------+
3619 | ``i1`` | a single-bit integer. |
3620 +----------------+------------------------------------------------+
3621 | ``i32`` | a 32-bit integer. |
3622 +----------------+------------------------------------------------+
3623 | ``i1942652`` | a really big integer of over 1 million bits. |
3624 +----------------+------------------------------------------------+
3628 Floating-Point Types
3629 """"""""""""""""""""
3638 - 16-bit floating-point value
3641 - 16-bit "brain" floating-point value (7-bit significand). Provides the
3642 same number of exponent bits as ``float``, so that it matches its dynamic
3643 range, but with greatly reduced precision. Used in Intel's AVX-512 BF16
3644 extensions and Arm's ARMv8.6-A extensions, among others.
3647 - 32-bit floating-point value
3650 - 64-bit floating-point value
3653 - 128-bit floating-point value (113-bit significand)
3656 - 80-bit floating-point value (X87)
3659 - 128-bit floating-point value (two 64-bits)
3661 The binary format of half, float, double, and fp128 correspond to the
3662 IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128
3670 The x86_amx type represents a value held in an AMX tile register on an x86
3671 machine. The operations allowed on it are quite limited. Only few intrinsics
3672 are allowed: stride load and store, zero and dot product. No instruction is
3673 allowed for this type. There are no arguments, arrays, pointers, vectors
3674 or constants of this type.
3688 The x86_mmx type represents a value held in an MMX register on an x86
3689 machine. The operations allowed on it are quite limited: parameters and
3690 return values, load and store, and bitcast. User-specified MMX
3691 instructions are represented as intrinsic or asm calls with arguments
3692 and/or results of this type. There are no arrays, vectors or constants
3709 The pointer type ``ptr`` is used to specify memory locations. Pointers are
3710 commonly used to reference objects in memory.
3712 Pointer types may have an optional address space attribute defining
3713 the numbered address space where the pointed-to object resides. For
3714 example, ``ptr addrspace(5)`` is a pointer to address space 5.
3715 In addition to integer constants, ``addrspace`` can also reference one of the
3716 address spaces defined in the :ref:`datalayout string<langref_datalayout>`.
3717 ``addrspace("A")`` will use the alloca address space, ``addrspace("G")``
3718 the default globals address space and ``addrspace("P")`` the program address
3721 The default address space is number zero.
3723 The semantics of non-zero address spaces are target-specific. Memory
3724 access through a non-dereferenceable pointer is undefined behavior in
3725 any address space. Pointers with the bit-value 0 are only assumed to
3726 be non-dereferenceable in address space 0, unless the function is
3727 marked with the ``null_pointer_is_valid`` attribute.
3729 If an object can be proven accessible through a pointer with a
3730 different address space, the access may be modified to use that
3731 address space. Exceptions apply if the operation is ``volatile``.
3733 Prior to LLVM 15, pointer types also specified a pointee type, such as
3734 ``i8*``, ``[4 x i32]*`` or ``i32 (i32*)*``. In LLVM 15, such "typed
3735 pointers" are still supported under non-default options. See the
3736 `opaque pointers document <OpaquePointers.html>`__ for more information.
3740 Target Extension Type
3741 """""""""""""""""""""
3745 Target extension types represent types that must be preserved through
3746 optimization, but are otherwise generally opaque to the compiler. They may be
3747 used as function parameters or arguments, and in :ref:`phi <i_phi>` or
3748 :ref:`select <i_select>` instructions. Some types may be also used in
3749 :ref:`alloca <i_alloca>` instructions or as global values, and correspondingly
3750 it is legal to use :ref:`load <i_load>` and :ref:`store <i_store>` instructions
3751 on them. Full semantics for these types are defined by the target.
3753 The only constants that target extension types may have are ``zeroinitializer``,
3754 ``undef``, and ``poison``. Other possible values for target extension types may
3755 arise from target-specific intrinsics and functions.
3757 These types cannot be converted to other types. As such, it is not legal to use
3758 them in :ref:`bitcast <i_bitcast>` instructions (as a source or target type),
3759 nor is it legal to use them in :ref:`ptrtoint <i_ptrtoint>` or
3760 :ref:`inttoptr <i_inttoptr>` instructions. Similarly, they are not legal to use
3761 in an :ref:`icmp <i_icmp>` instruction.
3763 Target extension types have a name and optional type or integer parameters. The
3764 meanings of name and parameters are defined by the target. When being defined in
3765 LLVM IR, all of the type parameters must precede all of the integer parameters.
3767 Specific target extension types are registered with LLVM as having specific
3768 properties. These properties can be used to restrict the type from appearing in
3769 certain contexts, such as being the type of a global variable or having a
3770 ``zeroinitializer`` constant be valid. A complete list of type properties may be
3771 found in the documentation for ``llvm::TargetExtType::Property`` (`doxygen
3772 <https://llvm.org/doxygen/classllvm_1_1TargetExtType.html>`_).
3776 .. code-block:: llvm
3779 target("label", void)
3780 target("label", void, i32)
3781 target("label", 0, 1, 2)
3782 target("label", void, i32, 0, 1, 2)
3792 A vector type is a simple derived type that represents a vector of
3793 elements. Vector types are used when multiple primitive data are
3794 operated in parallel using a single instruction (SIMD). A vector type
3795 requires a size (number of elements), an underlying primitive data type,
3796 and a scalable property to represent vectors where the exact hardware
3797 vector length is unknown at compile time. Vector types are considered
3798 :ref:`first class <t_firstclass>`.
3802 In general vector elements are laid out in memory in the same way as
3803 :ref:`array types <t_array>`. Such an analogy works fine as long as the vector
3804 elements are byte sized. However, when the elements of the vector aren't byte
3805 sized it gets a bit more complicated. One way to describe the layout is by
3806 describing what happens when a vector such as <N x iM> is bitcasted to an
3807 integer type with N*M bits, and then following the rules for storing such an
3810 A bitcast from a vector type to a scalar integer type will see the elements
3811 being packed together (without padding). The order in which elements are
3812 inserted in the integer depends on endianess. For little endian element zero
3813 is put in the least significant bits of the integer, and for big endian
3814 element zero is put in the most significant bits.
3816 Using a vector such as ``<i4 1, i4 2, i4 3, i4 5>`` as an example, together
3817 with the analogy that we can replace a vector store by a bitcast followed by
3818 an integer store, we get this for big endian:
3820 .. code-block:: llvm
3822 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16
3824 ; Bitcasting from a vector to an integral type can be seen as
3825 ; concatenating the values:
3826 ; %val now has the hexadecimal value 0x1235.
3828 store i16 %val, ptr %ptr
3830 ; In memory the content will be (8-bit addressing):
3832 ; [%ptr + 0]: 00010010 (0x12)
3833 ; [%ptr + 1]: 00110101 (0x35)
3835 The same example for little endian:
3837 .. code-block:: llvm
3839 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16
3841 ; Bitcasting from a vector to an integral type can be seen as
3842 ; concatenating the values:
3843 ; %val now has the hexadecimal value 0x5321.
3845 store i16 %val, ptr %ptr
3847 ; In memory the content will be (8-bit addressing):
3849 ; [%ptr + 0]: 01010011 (0x53)
3850 ; [%ptr + 1]: 00100001 (0x21)
3852 When ``<N*M>`` isn't evenly divisible by the byte size the exact memory layout
3853 is unspecified (just like it is for an integral type of the same size). This
3854 is because different targets could put the padding at different positions when
3855 the type size is smaller than the type's store size.
3861 < <# elements> x <elementtype> > ; Fixed-length vector
3862 < vscale x <# elements> x <elementtype> > ; Scalable vector
3864 The number of elements is a constant integer value larger than 0;
3865 elementtype may be any integer, floating-point or pointer type. Vectors
3866 of size zero are not allowed. For scalable vectors, the total number of
3867 elements is a constant multiple (called vscale) of the specified number
3868 of elements; vscale is a positive integer that is unknown at compile time
3869 and the same hardware-dependent constant for all scalable vectors at run
3870 time. The size of a specific scalable vector type is thus constant within
3871 IR, even if the exact size in bytes cannot be determined until run time.
3875 +------------------------+----------------------------------------------------+
3876 | ``<4 x i32>`` | Vector of 4 32-bit integer values. |
3877 +------------------------+----------------------------------------------------+
3878 | ``<8 x float>`` | Vector of 8 32-bit floating-point values. |
3879 +------------------------+----------------------------------------------------+
3880 | ``<2 x i64>`` | Vector of 2 64-bit integer values. |
3881 +------------------------+----------------------------------------------------+
3882 | ``<4 x ptr>`` | Vector of 4 pointers |
3883 +------------------------+----------------------------------------------------+
3884 | ``<vscale x 4 x i32>`` | Vector with a multiple of 4 32-bit integer values. |
3885 +------------------------+----------------------------------------------------+
3894 The label type represents code labels.
3909 The token type is used when a value is associated with an instruction
3910 but all uses of the value must not attempt to introspect or obscure it.
3911 As such, it is not appropriate to have a :ref:`phi <i_phi>` or
3912 :ref:`select <i_select>` of type token.
3929 The metadata type represents embedded metadata. No derived types may be
3930 created from metadata except for :ref:`function <t_function>` arguments.
3943 Aggregate Types are a subset of derived types that can contain multiple
3944 member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are
3945 aggregate types. :ref:`Vectors <t_vector>` are not considered to be
3955 The array type is a very simple derived type that arranges elements
3956 sequentially in memory. The array type requires a size (number of
3957 elements) and an underlying data type.
3963 [<# elements> x <elementtype>]
3965 The number of elements is a constant integer value; ``elementtype`` may
3966 be any type with a size.
3970 +------------------+--------------------------------------+
3971 | ``[40 x i32]`` | Array of 40 32-bit integer values. |
3972 +------------------+--------------------------------------+
3973 | ``[41 x i32]`` | Array of 41 32-bit integer values. |
3974 +------------------+--------------------------------------+
3975 | ``[4 x i8]`` | Array of 4 8-bit integer values. |
3976 +------------------+--------------------------------------+
3978 Here are some examples of multidimensional arrays:
3980 +-----------------------------+----------------------------------------------------------+
3981 | ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. |
3982 +-----------------------------+----------------------------------------------------------+
3983 | ``[12 x [10 x float]]`` | 12x10 array of single precision floating-point values. |
3984 +-----------------------------+----------------------------------------------------------+
3985 | ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. |
3986 +-----------------------------+----------------------------------------------------------+
3988 There is no restriction on indexing beyond the end of the array implied
3989 by a static type (though there are restrictions on indexing beyond the
3990 bounds of an allocated object in some cases). This means that
3991 single-dimension 'variable sized array' addressing can be implemented in
3992 LLVM with a zero length array type. An implementation of 'pascal style
3993 arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for
4003 The structure type is used to represent a collection of data members
4004 together in memory. The elements of a structure may be any type that has
4007 Structures in memory are accessed using '``load``' and '``store``' by
4008 getting a pointer to a field with the '``getelementptr``' instruction.
4009 Structures in registers are accessed using the '``extractvalue``' and
4010 '``insertvalue``' instructions.
4012 Structures may optionally be "packed" structures, which indicate that
4013 the alignment of the struct is one byte, and that there is no padding
4014 between the elements. In non-packed structs, padding between field types
4015 is inserted as defined by the DataLayout string in the module, which is
4016 required to match what the underlying code generator expects.
4018 Structures can either be "literal" or "identified". A literal structure
4019 is defined inline with other types (e.g. ``[2 x {i32, i32}]``) whereas
4020 identified types are always defined at the top level with a name.
4021 Literal types are uniqued by their contents and can never be recursive
4022 or opaque since there is no way to write one. Identified types can be
4023 recursive, can be opaqued, and are never uniqued.
4029 %T1 = type { <type list> } ; Identified normal struct type
4030 %T2 = type <{ <type list> }> ; Identified packed struct type
4034 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4035 | ``{ i32, i32, i32 }`` | A triple of three ``i32`` values |
4036 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4037 | ``{ float, ptr }`` | A pair, where the first element is a ``float`` and the second element is a :ref:`pointer <t_pointer>`. |
4038 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4039 | ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. |
4040 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4044 Opaque Structure Types
4045 """"""""""""""""""""""
4049 Opaque structure types are used to represent structure types that
4050 do not have a body specified. This corresponds (for example) to the C
4051 notion of a forward declared structure. They can be named (``%X``) or
4063 +--------------+-------------------+
4064 | ``opaque`` | An opaque type. |
4065 +--------------+-------------------+
4072 LLVM has several different basic types of constants. This section
4073 describes them all and their syntax.
4078 **Boolean constants**
4079 The two strings '``true``' and '``false``' are both valid constants
4081 **Integer constants**
4082 Standard integers (such as '4') are constants of the
4083 :ref:`integer <t_integer>` type. Negative numbers may be used with
4085 **Floating-point constants**
4086 Floating-point constants use standard decimal notation (e.g.
4087 123.421), exponential notation (e.g. 1.23421e+2), or a more precise
4088 hexadecimal notation (see below). The assembler requires the exact
4089 decimal value of a floating-point constant. For example, the
4090 assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating
4091 decimal in binary. Floating-point constants must have a
4092 :ref:`floating-point <t_floating>` type.
4093 **Null pointer constants**
4094 The identifier '``null``' is recognized as a null pointer constant
4095 and must be of :ref:`pointer type <t_pointer>`.
4097 The identifier '``none``' is recognized as an empty token constant
4098 and must be of :ref:`token type <t_token>`.
4100 The one non-intuitive notation for constants is the hexadecimal form of
4101 floating-point constants. For example, the form
4102 '``double 0x432ff973cafa8000``' is equivalent to (but harder to read
4103 than) '``double 4.5e+15``'. The only time hexadecimal floating-point
4104 constants are required (and the only time that they are generated by the
4105 disassembler) is when a floating-point constant must be emitted but it
4106 cannot be represented as a decimal floating-point number in a reasonable
4107 number of digits. For example, NaN's, infinities, and other special
4108 values are represented in their IEEE hexadecimal format so that assembly
4109 and disassembly do not cause any bits to change in the constants.
4111 When using the hexadecimal form, constants of types bfloat, half, float, and
4112 double are represented using the 16-digit form shown above (which matches the
4113 IEEE754 representation for double); bfloat, half and float values must, however,
4114 be exactly representable as bfloat, IEEE 754 half, and IEEE 754 single
4115 precision respectively. Hexadecimal format is always used for long double, and
4116 there are three forms of long double. The 80-bit format used by x86 is
4117 represented as ``0xK`` followed by 20 hexadecimal digits. The 128-bit format
4118 used by PowerPC (two adjacent doubles) is represented by ``0xM`` followed by 32
4119 hexadecimal digits. The IEEE 128-bit format is represented by ``0xL`` followed
4120 by 32 hexadecimal digits. Long doubles will only work if they match the long
4121 double format on your target. The IEEE 16-bit format (half precision) is
4122 represented by ``0xH`` followed by 4 hexadecimal digits. The bfloat 16-bit
4123 format is represented by ``0xR`` followed by 4 hexadecimal digits. All
4124 hexadecimal formats are big-endian (sign bit at the left).
4126 There are no constants of type x86_mmx and x86_amx.
4128 .. _complexconstants:
4133 Complex constants are a (potentially recursive) combination of simple
4134 constants and smaller complex constants.
4136 **Structure constants**
4137 Structure constants are represented with notation similar to
4138 structure type definitions (a comma separated list of elements,
4139 surrounded by braces (``{}``)). For example:
4140 "``{ i32 4, float 17.0, ptr @G }``", where "``@G``" is declared as
4141 "``@G = external global i32``". Structure constants must have
4142 :ref:`structure type <t_struct>`, and the number and types of elements
4143 must match those specified by the type.
4145 Array constants are represented with notation similar to array type
4146 definitions (a comma separated list of elements, surrounded by
4147 square brackets (``[]``)). For example:
4148 "``[ i32 42, i32 11, i32 74 ]``". Array constants must have
4149 :ref:`array type <t_array>`, and the number and types of elements must
4150 match those specified by the type. As a special case, character array
4151 constants may also be represented as a double-quoted string using the ``c``
4152 prefix. For example: "``c"Hello World\0A\00"``".
4153 **Vector constants**
4154 Vector constants are represented with notation similar to vector
4155 type definitions (a comma separated list of elements, surrounded by
4156 less-than/greater-than's (``<>``)). For example:
4157 "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants
4158 must have :ref:`vector type <t_vector>`, and the number and types of
4159 elements must match those specified by the type.
4160 **Zero initialization**
4161 The string '``zeroinitializer``' can be used to zero initialize a
4162 value to zero of *any* type, including scalar and
4163 :ref:`aggregate <t_aggregate>` types. This is often used to avoid
4164 having to print large zero initializers (e.g. for large arrays) and
4165 is always exactly equivalent to using explicit zero initializers.
4167 A metadata node is a constant tuple without types. For example:
4168 "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values,
4169 for example: "``!{!0, i32 0, ptr @global, ptr @function, !"str"}``".
4170 Unlike other typed constants that are meant to be interpreted as part of
4171 the instruction stream, metadata is a place to attach additional
4172 information such as debug info.
4174 Global Variable and Function Addresses
4175 --------------------------------------
4177 The addresses of :ref:`global variables <globalvars>` and
4178 :ref:`functions <functionstructure>` are always implicitly valid
4179 (link-time) constants. These constants are explicitly referenced when
4180 the :ref:`identifier for the global <identifiers>` is used and always have
4181 :ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM
4184 .. code-block:: llvm
4188 @Z = global [2 x ptr] [ ptr @X, ptr @Y ]
4195 The string '``undef``' can be used anywhere a constant is expected, and
4196 indicates that the user of the value may receive an unspecified
4197 bit-pattern. Undefined values may be of any type (other than '``label``'
4198 or '``void``') and be used anywhere a constant is permitted.
4202 A '``poison``' value (described in the next section) should be used instead of
4203 '``undef``' whenever possible. Poison values are stronger than undef, and
4204 enable more optimizations. Just the existence of '``undef``' blocks certain
4205 optimizations (see the examples below).
4207 Undefined values are useful because they indicate to the compiler that
4208 the program is well defined no matter what value is used. This gives the
4209 compiler more freedom to optimize. Here are some examples of
4210 (potentially surprising) transformations that are valid (in pseudo IR):
4212 .. code-block:: llvm
4222 This is safe because all of the output bits are affected by the undef
4223 bits. Any output bit can have a zero or one depending on the input bits.
4225 .. code-block:: llvm
4233 %A = %X ;; By choosing undef as 0
4234 %B = %X ;; By choosing undef as -1
4239 These logical operations have bits that are not always affected by the
4240 input. For example, if ``%X`` has a zero bit, then the output of the
4241 '``and``' operation will always be a zero for that bit, no matter what
4242 the corresponding bit from the '``undef``' is. As such, it is unsafe to
4243 optimize or assume that the result of the '``and``' is '``undef``'.
4244 However, it is safe to assume that all bits of the '``undef``' could be
4245 0, and optimize the '``and``' to 0. Likewise, it is safe to assume that
4246 all the bits of the '``undef``' operand to the '``or``' could be set,
4247 allowing the '``or``' to be folded to -1.
4249 .. code-block:: llvm
4251 %A = select undef, %X, %Y
4252 %B = select undef, 42, %Y
4253 %C = select %X, %Y, undef
4257 %C = %Y (if %Y is provably not poison; unsafe otherwise)
4263 This set of examples shows that undefined '``select``' (and conditional
4264 branch) conditions can go *either way*, but they have to come from one
4265 of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were
4266 both known to have a clear low bit, then ``%A`` would have to have a
4267 cleared low bit. However, in the ``%C`` example, the optimizer is
4268 allowed to assume that the '``undef``' operand could be the same as
4269 ``%Y`` if ``%Y`` is provably not '``poison``', allowing the whole '``select``'
4270 to be eliminated. This is because '``poison``' is stronger than '``undef``'.
4272 .. code-block:: llvm
4274 %A = xor undef, undef
4291 This example points out that two '``undef``' operands are not
4292 necessarily the same. This can be surprising to people (and also matches
4293 C semantics) where they assume that "``X^X``" is always zero, even if
4294 ``X`` is undefined. This isn't true for a number of reasons, but the
4295 short answer is that an '``undef``' "variable" can arbitrarily change
4296 its value over its "live range". This is true because the variable
4297 doesn't actually *have a live range*. Instead, the value is logically
4298 read from arbitrary registers that happen to be around when needed, so
4299 the value is not necessarily consistent over time. In fact, ``%A`` and
4300 ``%C`` need to have the same semantics or the core LLVM "replace all
4301 uses with" concept would not hold.
4303 To ensure all uses of a given register observe the same value (even if
4304 '``undef``'), the :ref:`freeze instruction <i_freeze>` can be used.
4306 .. code-block:: llvm
4314 These examples show the crucial difference between an *undefined value*
4315 and *undefined behavior*. An undefined value (like '``undef``') is
4316 allowed to have an arbitrary bit-pattern. This means that the ``%A``
4317 operation can be constant folded to '``0``', because the '``undef``'
4318 could be zero, and zero divided by any value is zero.
4319 However, in the second example, we can make a more aggressive
4320 assumption: because the ``undef`` is allowed to be an arbitrary value,
4321 we are allowed to assume that it could be zero. Since a divide by zero
4322 has *undefined behavior*, we are allowed to assume that the operation
4323 does not execute at all. This allows us to delete the divide and all
4324 code after it. Because the undefined operation "can't happen", the
4325 optimizer can assume that it occurs in dead code.
4327 .. code-block:: text
4329 a: store undef -> %X
4330 b: store %X -> undef
4332 a: <deleted> (if the stored value in %X is provably not poison)
4335 A store *of* an undefined value can be assumed to not have any effect;
4336 we can assume that the value is overwritten with bits that happen to
4337 match what was already there. This argument is only valid if the stored value
4338 is provably not ``poison``. However, a store *to* an undefined
4339 location could clobber arbitrary memory, therefore, it has undefined
4342 Branching on an undefined value is undefined behavior.
4343 This explains optimizations that depend on branch conditions to construct
4344 predicates, such as Correlated Value Propagation and Global Value Numbering.
4345 In case of switch instruction, the branch condition should be frozen, otherwise
4346 it is undefined behavior.
4348 .. code-block:: llvm
4351 br undef, BB1, BB2 ; UB
4353 %X = and i32 undef, 255
4354 switch %X, label %ret [ .. ] ; UB
4356 store undef, ptr %ptr
4357 %X = load ptr %ptr ; %X is undef
4358 switch i8 %X, label %ret [ .. ] ; UB
4361 %X = or i8 undef, 255 ; always 255
4362 switch i8 %X, label %ret [ .. ] ; Well-defined
4364 %X = freeze i1 undef
4365 br %X, BB1, BB2 ; Well-defined (non-deterministic jump)
4374 A poison value is a result of an erroneous operation.
4375 In order to facilitate speculative execution, many instructions do not
4376 invoke immediate undefined behavior when provided with illegal operands,
4377 and return a poison value instead.
4378 The string '``poison``' can be used anywhere a constant is expected, and
4379 operations such as :ref:`add <i_add>` with the ``nsw`` flag can produce
4382 Most instructions return '``poison``' when one of their arguments is
4383 '``poison``'. A notable exception is the :ref:`select instruction <i_select>`.
4384 Propagation of poison can be stopped with the
4385 :ref:`freeze instruction <i_freeze>`.
4387 It is correct to replace a poison value with an
4388 :ref:`undef value <undefvalues>` or any value of the type.
4390 This means that immediate undefined behavior occurs if a poison value is
4391 used as an instruction operand that has any values that trigger undefined
4392 behavior. Notably this includes (but is not limited to):
4394 - The pointer operand of a :ref:`load <i_load>`, :ref:`store <i_store>` or
4395 any other pointer dereferencing instruction (independent of address
4397 - The divisor operand of a ``udiv``, ``sdiv``, ``urem`` or ``srem``
4399 - The condition operand of a :ref:`br <i_br>` instruction.
4400 - The callee operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
4402 - The parameter operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
4403 instruction, when the function or invoking call site has a ``noundef``
4404 attribute in the corresponding position.
4405 - The operand of a :ref:`ret <i_ret>` instruction if the function or invoking
4406 call site has a `noundef` attribute in the return value position.
4408 Here are some examples:
4410 .. code-block:: llvm
4413 %poison = sub nuw i32 0, 1 ; Results in a poison value.
4414 %poison2 = sub i32 poison, 1 ; Also results in a poison value.
4415 %still_poison = and i32 %poison, 0 ; 0, but also poison.
4416 %poison_yet_again = getelementptr i32, ptr @h, i32 %still_poison
4417 store i32 0, ptr %poison_yet_again ; Undefined behavior due to
4420 store i32 %poison, ptr @g ; Poison value stored to memory.
4421 %poison3 = load i32, ptr @g ; Poison value loaded back from memory.
4423 %poison4 = load i16, ptr @g ; Returns a poison value.
4424 %poison5 = load i64, ptr @g ; Returns a poison value.
4426 %cmp = icmp slt i32 %poison, 0 ; Returns a poison value.
4427 br i1 %cmp, label %end, label %end ; undefined behavior
4431 .. _welldefinedvalues:
4436 Given a program execution, a value is *well defined* if the value does not
4437 have an undef bit and is not poison in the execution.
4438 An aggregate value or vector is well defined if its elements are well defined.
4439 The padding of an aggregate isn't considered, since it isn't visible
4440 without storing it into memory and loading it with a different type.
4442 A constant of a :ref:`single value <t_single_value>`, non-vector type is well
4443 defined if it is neither '``undef``' constant nor '``poison``' constant.
4444 The result of :ref:`freeze instruction <i_freeze>` is well defined regardless
4449 Addresses of Basic Blocks
4450 -------------------------
4452 ``blockaddress(@function, %block)``
4454 The '``blockaddress``' constant computes the address of the specified
4455 basic block in the specified function.
4457 It always has an ``ptr addrspace(P)`` type, where ``P`` is the address space
4458 of the function containing ``%block`` (usually ``addrspace(0)``).
4460 Taking the address of the entry block is illegal.
4462 This value only has defined behavior when used as an operand to the
4463 ':ref:`indirectbr <i_indirectbr>`' or for comparisons against null. Pointer
4464 equality tests between labels addresses results in undefined behavior ---
4465 though, again, comparison against null is ok, and no label is equal to the null
4466 pointer. This may be passed around as an opaque pointer sized value as long as
4467 the bits are not inspected. This allows ``ptrtoint`` and arithmetic to be
4468 performed on these values so long as the original value is reconstituted before
4469 the ``indirectbr`` instruction.
4471 Finally, some targets may provide defined semantics when using the value
4472 as the operand to an inline assembly, but that is target specific.
4474 .. _dso_local_equivalent:
4476 DSO Local Equivalent
4477 --------------------
4479 ``dso_local_equivalent @func``
4481 A '``dso_local_equivalent``' constant represents a function which is
4482 functionally equivalent to a given function, but is always defined in the
4483 current linkage unit. The resulting pointer has the same type as the underlying
4484 function. The resulting pointer is permitted, but not required, to be different
4485 from a pointer to the function, and it may have different values in different
4488 The target function may not have ``extern_weak`` linkage.
4490 ``dso_local_equivalent`` can be implemented as such:
4492 - If the function has local linkage, hidden visibility, or is
4493 ``dso_local``, ``dso_local_equivalent`` can be implemented as simply a pointer
4495 - ``dso_local_equivalent`` can be implemented with a stub that tail-calls the
4496 function. Many targets support relocations that resolve at link time to either
4497 a function or a stub for it, depending on if the function is defined within the
4498 linkage unit; LLVM will use this when available. (This is commonly called a
4499 "PLT stub".) On other targets, the stub may need to be emitted explicitly.
4501 This can be used wherever a ``dso_local`` instance of a function is needed without
4502 needing to explicitly make the original function ``dso_local``. An instance where
4503 this can be used is for static offset calculations between a function and some other
4504 ``dso_local`` symbol. This is especially useful for the Relative VTables C++ ABI,
4505 where dynamic relocations for function pointers in VTables can be replaced with
4506 static relocations for offsets between the VTable and virtual functions which
4507 may not be ``dso_local``.
4509 This is currently only supported for ELF binary formats.
4518 With `Control-Flow Integrity (CFI)
4519 <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, a '``no_cfi``'
4520 constant represents a function reference that does not get replaced with a
4521 reference to the CFI jump table in the ``LowerTypeTests`` pass. These constants
4522 may be useful in low-level programs, such as operating system kernels, which
4523 need to refer to the actual function body.
4527 Constant Expressions
4528 --------------------
4530 Constant expressions are used to allow expressions involving other
4531 constants to be used as constants. Constant expressions may be of any
4532 :ref:`first class <t_firstclass>` type and may involve any LLVM operation
4533 that does not have side effects (e.g. load and call are not supported).
4534 The following is the syntax for constant expressions:
4536 ``trunc (CST to TYPE)``
4537 Perform the :ref:`trunc operation <i_trunc>` on constants.
4538 ``zext (CST to TYPE)``
4539 Perform the :ref:`zext operation <i_zext>` on constants.
4540 ``sext (CST to TYPE)``
4541 Perform the :ref:`sext operation <i_sext>` on constants.
4542 ``fptrunc (CST to TYPE)``
4543 Truncate a floating-point constant to another floating-point type.
4544 The size of CST must be larger than the size of TYPE. Both types
4545 must be floating-point.
4546 ``fpext (CST to TYPE)``
4547 Floating-point extend a constant to another type. The size of CST
4548 must be smaller or equal to the size of TYPE. Both types must be
4550 ``fptoui (CST to TYPE)``
4551 Convert a floating-point constant to the corresponding unsigned
4552 integer constant. TYPE must be a scalar or vector integer type. CST
4553 must be of scalar or vector floating-point type. Both CST and TYPE
4554 must be scalars, or vectors of the same number of elements. If the
4555 value won't fit in the integer type, the result is a
4556 :ref:`poison value <poisonvalues>`.
4557 ``fptosi (CST to TYPE)``
4558 Convert a floating-point constant to the corresponding signed
4559 integer constant. TYPE must be a scalar or vector integer type. CST
4560 must be of scalar or vector floating-point type. Both CST and TYPE
4561 must be scalars, or vectors of the same number of elements. If the
4562 value won't fit in the integer type, the result is a
4563 :ref:`poison value <poisonvalues>`.
4564 ``uitofp (CST to TYPE)``
4565 Convert an unsigned integer constant to the corresponding
4566 floating-point constant. TYPE must be a scalar or vector floating-point
4567 type. CST must be of scalar or vector integer type. Both CST and TYPE must
4568 be scalars, or vectors of the same number of elements.
4569 ``sitofp (CST to TYPE)``
4570 Convert a signed integer constant to the corresponding floating-point
4571 constant. TYPE must be a scalar or vector floating-point type.
4572 CST must be of scalar or vector integer type. Both CST and TYPE must
4573 be scalars, or vectors of the same number of elements.
4574 ``ptrtoint (CST to TYPE)``
4575 Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants.
4576 ``inttoptr (CST to TYPE)``
4577 Perform the :ref:`inttoptr operation <i_inttoptr>` on constants.
4578 This one is *really* dangerous!
4579 ``bitcast (CST to TYPE)``
4580 Convert a constant, CST, to another TYPE.
4581 The constraints of the operands are the same as those for the
4582 :ref:`bitcast instruction <i_bitcast>`.
4583 ``addrspacecast (CST to TYPE)``
4584 Convert a constant pointer or constant vector of pointer, CST, to another
4585 TYPE in a different address space. The constraints of the operands are the
4586 same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`.
4587 ``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)``
4588 Perform the :ref:`getelementptr operation <i_getelementptr>` on
4589 constants. As with the :ref:`getelementptr <i_getelementptr>`
4590 instruction, the index list may have one or more indexes, which are
4591 required to make sense for the type of "pointer to TY". These indexes
4592 may be implicitly sign-extended or truncated to match the index size
4593 of CSTPTR's address space.
4594 ``icmp COND (VAL1, VAL2)``
4595 Perform the :ref:`icmp operation <i_icmp>` on constants.
4596 ``fcmp COND (VAL1, VAL2)``
4597 Perform the :ref:`fcmp operation <i_fcmp>` on constants.
4598 ``extractelement (VAL, IDX)``
4599 Perform the :ref:`extractelement operation <i_extractelement>` on
4601 ``insertelement (VAL, ELT, IDX)``
4602 Perform the :ref:`insertelement operation <i_insertelement>` on
4604 ``shufflevector (VEC1, VEC2, IDXMASK)``
4605 Perform the :ref:`shufflevector operation <i_shufflevector>` on
4608 Perform an addition on constants.
4610 Perform a subtraction on constants.
4612 Perform a multiplication on constants.
4614 Perform a left shift on constants.
4616 Perform a logical right shift on constants.
4618 Perform an arithmetic right shift on constants.
4620 Perform a bitwise and on constants.
4622 Perform a bitwise or on constants.
4624 Perform a bitwise xor on constants.
4631 Inline Assembler Expressions
4632 ----------------------------
4634 LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level
4635 Inline Assembly <moduleasm>`) through the use of a special value. This value
4636 represents the inline assembler as a template string (containing the
4637 instructions to emit), a list of operand constraints (stored as a string), a
4638 flag that indicates whether or not the inline asm expression has side effects,
4639 and a flag indicating whether the function containing the asm needs to align its
4640 stack conservatively.
4642 The template string supports argument substitution of the operands using "``$``"
4643 followed by a number, to indicate substitution of the given register/memory
4644 location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also
4645 be used, where ``MODIFIER`` is a target-specific annotation for how to print the
4646 operand (See :ref:`inline-asm-modifiers`).
4648 A literal "``$``" may be included by using "``$$``" in the template. To include
4649 other special characters into the output, the usual "``\XX``" escapes may be
4650 used, just as in other strings. Note that after template substitution, the
4651 resulting assembly string is parsed by LLVM's integrated assembler unless it is
4652 disabled -- even when emitting a ``.s`` file -- and thus must contain assembly
4653 syntax known to LLVM.
4655 LLVM also supports a few more substitutions useful for writing inline assembly:
4657 - ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob.
4658 This substitution is useful when declaring a local label. Many standard
4659 compiler optimizations, such as inlining, may duplicate an inline asm blob.
4660 Adding a blob-unique identifier ensures that the two labels will not conflict
4661 during assembly. This is used to implement `GCC's %= special format
4662 string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_.
4663 - ``${:comment}``: Expands to the comment character of the current target's
4664 assembly dialect. This is usually ``#``, but many targets use other strings,
4665 such as ``;``, ``//``, or ``!``.
4666 - ``${:private}``: Expands to the assembler private label prefix. Labels with
4667 this prefix will not appear in the symbol table of the assembled object.
4668 Typically the prefix is ``L``, but targets may use other strings. ``.L`` is
4671 LLVM's support for inline asm is modeled closely on the requirements of Clang's
4672 GCC-compatible inline-asm support. Thus, the feature-set and the constraint and
4673 modifier codes listed here are similar or identical to those in GCC's inline asm
4674 support. However, to be clear, the syntax of the template and constraint strings
4675 described here is *not* the same as the syntax accepted by GCC and Clang, and,
4676 while most constraint letters are passed through as-is by Clang, some get
4677 translated to other codes when converting from the C source to the LLVM
4680 An example inline assembler expression is:
4682 .. code-block:: llvm
4684 i32 (i32) asm "bswap $0", "=r,r"
4686 Inline assembler expressions may **only** be used as the callee operand
4687 of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction.
4688 Thus, typically we have:
4690 .. code-block:: llvm
4692 %X = call i32 asm "bswap $0", "=r,r"(i32 %Y)
4694 Inline asms with side effects not visible in the constraint list must be
4695 marked as having side effects. This is done through the use of the
4696 '``sideeffect``' keyword, like so:
4698 .. code-block:: llvm
4700 call void asm sideeffect "eieio", ""()
4702 In some cases inline asms will contain code that will not work unless
4703 the stack is aligned in some way, such as calls or SSE instructions on
4704 x86, yet will not contain code that does that alignment within the asm.
4705 The compiler should make conservative assumptions about what the asm
4706 might contain and should generate its usual stack alignment code in the
4707 prologue if the '``alignstack``' keyword is present:
4709 .. code-block:: llvm
4711 call void asm alignstack "eieio", ""()
4713 Inline asms also support using non-standard assembly dialects. The
4714 assumed dialect is ATT. When the '``inteldialect``' keyword is present,
4715 the inline asm is using the Intel dialect. Currently, ATT and Intel are
4716 the only supported dialects. An example is:
4718 .. code-block:: llvm
4720 call void asm inteldialect "eieio", ""()
4722 In the case that the inline asm might unwind the stack,
4723 the '``unwind``' keyword must be used, so that the compiler emits
4724 unwinding information:
4726 .. code-block:: llvm
4728 call void asm unwind "call func", ""()
4730 If the inline asm unwinds the stack and isn't marked with
4731 the '``unwind``' keyword, the behavior is undefined.
4733 If multiple keywords appear, the '``sideeffect``' keyword must come
4734 first, the '``alignstack``' keyword second, the '``inteldialect``' keyword
4735 third and the '``unwind``' keyword last.
4737 Inline Asm Constraint String
4738 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4740 The constraint list is a comma-separated string, each element containing one or
4741 more constraint codes.
4743 For each element in the constraint list an appropriate register or memory
4744 operand will be chosen, and it will be made available to assembly template
4745 string expansion as ``$0`` for the first constraint in the list, ``$1`` for the
4748 There are three different types of constraints, which are distinguished by a
4749 prefix symbol in front of the constraint code: Output, Input, and Clobber. The
4750 constraints must always be given in that order: outputs first, then inputs, then
4751 clobbers. They cannot be intermingled.
4753 There are also three different categories of constraint codes:
4755 - Register constraint. This is either a register class, or a fixed physical
4756 register. This kind of constraint will allocate a register, and if necessary,
4757 bitcast the argument or result to the appropriate type.
4758 - Memory constraint. This kind of constraint is for use with an instruction
4759 taking a memory operand. Different constraints allow for different addressing
4760 modes used by the target.
4761 - Immediate value constraint. This kind of constraint is for an integer or other
4762 immediate value which can be rendered directly into an instruction. The
4763 various target-specific constraints allow the selection of a value in the
4764 proper range for the instruction you wish to use it with.
4769 Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This
4770 indicates that the assembly will write to this operand, and the operand will
4771 then be made available as a return value of the ``asm`` expression. Output
4772 constraints do not consume an argument from the call instruction. (Except, see
4773 below about indirect outputs).
4775 Normally, it is expected that no output locations are written to by the assembly
4776 expression until *all* of the inputs have been read. As such, LLVM may assign
4777 the same register to an output and an input. If this is not safe (e.g. if the
4778 assembly contains two instructions, where the first writes to one output, and
4779 the second reads an input and writes to a second output), then the "``&``"
4780 modifier must be used (e.g. "``=&r``") to specify that the output is an
4781 "early-clobber" output. Marking an output as "early-clobber" ensures that LLVM
4782 will not use the same register for any inputs (other than an input tied to this
4788 Input constraints do not have a prefix -- just the constraint codes. Each input
4789 constraint will consume one argument from the call instruction. It is not
4790 permitted for the asm to write to any input register or memory location (unless
4791 that input is tied to an output). Note also that multiple inputs may all be
4792 assigned to the same register, if LLVM can determine that they necessarily all
4793 contain the same value.
4795 Instead of providing a Constraint Code, input constraints may also "tie"
4796 themselves to an output constraint, by providing an integer as the constraint
4797 string. Tied inputs still consume an argument from the call instruction, and
4798 take up a position in the asm template numbering as is usual -- they will simply
4799 be constrained to always use the same register as the output they've been tied
4800 to. For example, a constraint string of "``=r,0``" says to assign a register for
4801 output, and use that register as an input as well (it being the 0'th
4804 It is permitted to tie an input to an "early-clobber" output. In that case, no
4805 *other* input may share the same register as the input tied to the early-clobber
4806 (even when the other input has the same value).
4808 You may only tie an input to an output which has a register constraint, not a
4809 memory constraint. Only a single input may be tied to an output.
4811 There is also an "interesting" feature which deserves a bit of explanation: if a
4812 register class constraint allocates a register which is too small for the value
4813 type operand provided as input, the input value will be split into multiple
4814 registers, and all of them passed to the inline asm.
4816 However, this feature is often not as useful as you might think.
4818 Firstly, the registers are *not* guaranteed to be consecutive. So, on those
4819 architectures that have instructions which operate on multiple consecutive
4820 instructions, this is not an appropriate way to support them. (e.g. the 32-bit
4821 SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The
4822 hardware then loads into both the named register, and the next register. This
4823 feature of inline asm would not be useful to support that.)
4825 A few of the targets provide a template string modifier allowing explicit access
4826 to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and
4827 ``D``). On such an architecture, you can actually access the second allocated
4828 register (yet, still, not any subsequent ones). But, in that case, you're still
4829 probably better off simply splitting the value into two separate operands, for
4830 clarity. (e.g. see the description of the ``A`` constraint on X86, which,
4831 despite existing only for use with this feature, is not really a good idea to
4834 Indirect inputs and outputs
4835 """""""""""""""""""""""""""
4837 Indirect output or input constraints can be specified by the "``*``" modifier
4838 (which goes after the "``=``" in case of an output). This indicates that the asm
4839 will write to or read from the contents of an *address* provided as an input
4840 argument. (Note that in this way, indirect outputs act more like an *input* than
4841 an output: just like an input, they consume an argument of the call expression,
4842 rather than producing a return value. An indirect output constraint is an
4843 "output" only in that the asm is expected to write to the contents of the input
4844 memory location, instead of just read from it).
4846 This is most typically used for memory constraint, e.g. "``=*m``", to pass the
4847 address of a variable as a value.
4849 It is also possible to use an indirect *register* constraint, but only on output
4850 (e.g. "``=*r``"). This will cause LLVM to allocate a register for an output
4851 value normally, and then, separately emit a store to the address provided as
4852 input, after the provided inline asm. (It's not clear what value this
4853 functionality provides, compared to writing the store explicitly after the asm
4854 statement, and it can only produce worse code, since it bypasses many
4855 optimization passes. I would recommend not using it.)
4857 Call arguments for indirect constraints must have pointer type and must specify
4858 the :ref:`elementtype <attr_elementtype>` attribute to indicate the pointer
4864 A clobber constraint is indicated by a "``~``" prefix. A clobber does not
4865 consume an input operand, nor generate an output. Clobbers cannot use any of the
4866 general constraint code letters -- they may use only explicit register
4867 constraints, e.g. "``~{eax}``". The one exception is that a clobber string of
4868 "``~{memory}``" indicates that the assembly writes to arbitrary undeclared
4869 memory locations -- not only the memory pointed to by a declared indirect
4872 Note that clobbering named registers that are also present in output
4873 constraints is not legal.
4878 A label constraint is indicated by a "``!``" prefix and typically used in the
4879 form ``"!i"``. Instead of consuming call arguments, label constraints consume
4880 indirect destination labels of ``callbr`` instructions.
4882 Label constraints can only be used in conjunction with ``callbr`` and the
4883 number of label constraints must match the number of indirect destination
4884 labels in the ``callbr`` instruction.
4889 After a potential prefix comes constraint code, or codes.
4891 A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character
4892 followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``"
4895 The one and two letter constraint codes are typically chosen to be the same as
4896 GCC's constraint codes.
4898 A single constraint may include one or more than constraint code in it, leaving
4899 it up to LLVM to choose which one to use. This is included mainly for
4900 compatibility with the translation of GCC inline asm coming from clang.
4902 There are two ways to specify alternatives, and either or both may be used in an
4903 inline asm constraint list:
4905 1) Append the codes to each other, making a constraint code set. E.g. "``im``"
4906 or "``{eax}m``". This means "choose any of the options in the set". The
4907 choice of constraint is made independently for each constraint in the
4910 2) Use "``|``" between constraint code sets, creating alternatives. Every
4911 constraint in the constraint list must have the same number of alternative
4912 sets. With this syntax, the same alternative in *all* of the items in the
4913 constraint list will be chosen together.
4915 Putting those together, you might have a two operand constraint string like
4916 ``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then
4917 operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1
4918 may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m.
4920 However, the use of either of the alternatives features is *NOT* recommended, as
4921 LLVM is not able to make an intelligent choice about which one to use. (At the
4922 point it currently needs to choose, not enough information is available to do so
4923 in a smart way.) Thus, it simply tries to make a choice that's most likely to
4924 compile, not one that will be optimal performance. (e.g., given "``rm``", it'll
4925 always choose to use memory, not registers). And, if given multiple registers,
4926 or multiple register classes, it will simply choose the first one. (In fact, it
4927 doesn't currently even ensure explicitly specified physical registers are
4928 unique, so specifying multiple physical registers as alternatives, like
4929 ``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was
4932 Supported Constraint Code List
4933 """"""""""""""""""""""""""""""
4935 The constraint codes are, in general, expected to behave the same way they do in
4936 GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
4937 inline asm code which was supported by GCC. A mismatch in behavior between LLVM
4938 and GCC likely indicates a bug in LLVM.
4940 Some constraint codes are typically supported by all targets:
4942 - ``r``: A register in the target's general purpose register class.
4943 - ``m``: A memory address operand. It is target-specific what addressing modes
4944 are supported, typical examples are register, or register + register offset,
4945 or register + immediate offset (of some target-specific size).
4946 - ``p``: An address operand. Similar to ``m``, but used by "load address"
4947 type instructions without touching memory.
4948 - ``i``: An integer constant (of target-specific width). Allows either a simple
4949 immediate, or a relocatable value.
4950 - ``n``: An integer constant -- *not* including relocatable values.
4951 - ``s``: An integer constant, but allowing *only* relocatable values.
4952 - ``X``: Allows an operand of any kind, no constraint whatsoever. Typically
4953 useful to pass a label for an asm branch or call.
4955 .. FIXME: but that surely isn't actually okay to jump out of an asm
4956 block without telling llvm about the control transfer???)
4958 - ``{register-name}``: Requires exactly the named physical register.
4960 Other constraints are target-specific:
4964 - ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate.
4965 - ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction,
4966 i.e. 0 to 4095 with optional shift by 12.
4967 - ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or
4968 ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12.
4969 - ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a
4970 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register.
4971 - ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a
4972 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register.
4973 - ``M``: An immediate integer for use with the ``MOV`` assembly alias on a
4974 32-bit register. This is a superset of ``K``: in addition to the bitmask
4975 immediate, also allows immediate integers which can be loaded with a single
4976 ``MOVZ`` or ``MOVL`` instruction.
4977 - ``N``: An immediate integer for use with the ``MOV`` assembly alias on a
4978 64-bit register. This is a superset of ``L``.
4979 - ``Q``: Memory address operand must be in a single register (no
4980 offsets). (However, LLVM currently does this for the ``m`` constraint as
4982 - ``r``: A 32 or 64-bit integer register (W* or X*).
4983 - ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register.
4984 - ``x``: Like w, but restricted to registers 0 to 15 inclusive.
4985 - ``y``: Like w, but restricted to SVE vector registers Z0 to Z7 inclusive.
4986 - ``Upl``: One of the low eight SVE predicate registers (P0 to P7)
4987 - ``Upa``: Any of the SVE predicate registers (P0 to P15)
4991 - ``r``: A 32 or 64-bit integer register.
4992 - ``[0-9]v``: The 32-bit VGPR register, number 0-9.
4993 - ``[0-9]s``: The 32-bit SGPR register, number 0-9.
4994 - ``[0-9]a``: The 32-bit AGPR register, number 0-9.
4995 - ``I``: An integer inline constant in the range from -16 to 64.
4996 - ``J``: A 16-bit signed integer constant.
4997 - ``A``: An integer or a floating-point inline constant.
4998 - ``B``: A 32-bit signed integer constant.
4999 - ``C``: A 32-bit unsigned integer constant or an integer inline constant in the range from -16 to 64.
5000 - ``DA``: A 64-bit constant that can be split into two "A" constants.
5001 - ``DB``: A 64-bit constant that can be split into two "B" constants.
5005 - ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address
5006 operand. Treated the same as operand ``m``, at the moment.
5007 - ``Te``: An even general-purpose 32-bit integer register: ``r0,r2,...,r12,r14``
5008 - ``To``: An odd general-purpose 32-bit integer register: ``r1,r3,...,r11``
5010 ARM and ARM's Thumb2 mode:
5012 - ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``)
5013 - ``I``: An immediate integer valid for a data-processing instruction.
5014 - ``J``: An immediate integer between -4095 and 4095.
5015 - ``K``: An immediate integer whose bitwise inverse is valid for a
5016 data-processing instruction. (Can be used with template modifier "``B``" to
5017 print the inverted value).
5018 - ``L``: An immediate integer whose negation is valid for a data-processing
5019 instruction. (Can be used with template modifier "``n``" to print the negated
5021 - ``M``: A power of two or an integer between 0 and 32.
5022 - ``N``: Invalid immediate constraint.
5023 - ``O``: Invalid immediate constraint.
5024 - ``r``: A general-purpose 32-bit integer register (``r0-r15``).
5025 - ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same
5027 - ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode,
5029 - ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
5030 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively.
5031 - ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
5032 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively.
5033 - ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
5034 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively.
5038 - ``I``: An immediate integer between 0 and 255.
5039 - ``J``: An immediate integer between -255 and -1.
5040 - ``K``: An immediate integer between 0 and 255, with optional left-shift by
5042 - ``L``: An immediate integer between -7 and 7.
5043 - ``M``: An immediate integer which is a multiple of 4 between 0 and 1020.
5044 - ``N``: An immediate integer between 0 and 31.
5045 - ``O``: An immediate integer which is a multiple of 4 between -508 and 508.
5046 - ``r``: A low 32-bit GPR register (``r0-r7``).
5047 - ``l``: A low 32-bit GPR register (``r0-r7``).
5048 - ``h``: A high GPR register (``r0-r7``).
5049 - ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
5050 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively.
5051 - ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
5052 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively.
5053 - ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
5054 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively.
5058 - ``o``, ``v``: A memory address operand, treated the same as constraint ``m``,
5060 - ``r``: A 32 or 64-bit register.
5064 - ``f``: A floating-point register (if available).
5065 - ``k``: A memory operand whose address is formed by a base register and
5066 (optionally scaled) index register.
5067 - ``l``: A signed 16-bit constant.
5068 - ``m``: A memory operand whose address is formed by a base register and
5069 offset that is suitable for use in instructions with the same addressing
5070 mode as st.w and ld.w.
5071 - ``I``: A signed 12-bit constant (for arithmetic instructions).
5072 - ``J``: An immediate integer zero.
5073 - ``K``: An unsigned 12-bit constant (for logic instructions).
5074 - ``ZB``: An address that is held in a general-purpose register. The offset
5076 - ``ZC``: A memory operand whose address is formed by a base register and
5077 offset that is suitable for use in instructions with the same addressing
5078 mode as ll.w and sc.w.
5082 - ``r``: An 8 or 16-bit register.
5086 - ``I``: An immediate signed 16-bit integer.
5087 - ``J``: An immediate integer zero.
5088 - ``K``: An immediate unsigned 16-bit integer.
5089 - ``L``: An immediate 32-bit integer, where the lower 16 bits are 0.
5090 - ``N``: An immediate integer between -65535 and -1.
5091 - ``O``: An immediate signed 15-bit integer.
5092 - ``P``: An immediate integer between 1 and 65535.
5093 - ``m``: A memory address operand. In MIPS-SE mode, allows a base address
5094 register plus 16-bit immediate offset. In MIPS mode, just a base register.
5095 - ``R``: A memory address operand. In MIPS-SE mode, allows a base address
5096 register plus a 9-bit signed offset. In MIPS mode, the same as constraint
5098 - ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or
5099 ``sc`` instruction on the given subtarget (details vary).
5100 - ``r``, ``d``, ``y``: A 32 or 64-bit GPR register.
5101 - ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register
5102 (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w``
5103 argument modifier for compatibility with GCC.
5104 - ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always
5106 - ``l``: The ``lo`` register, 32 or 64-bit.
5111 - ``b``: A 1-bit integer register.
5112 - ``c`` or ``h``: A 16-bit integer register.
5113 - ``r``: A 32-bit integer register.
5114 - ``l`` or ``N``: A 64-bit integer register.
5115 - ``f``: A 32-bit float register.
5116 - ``d``: A 64-bit float register.
5121 - ``I``: An immediate signed 16-bit integer.
5122 - ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits.
5123 - ``K``: An immediate unsigned 16-bit integer.
5124 - ``L``: An immediate signed 16-bit integer, shifted left 16 bits.
5125 - ``M``: An immediate integer greater than 31.
5126 - ``N``: An immediate integer that is an exact power of 2.
5127 - ``O``: The immediate integer constant 0.
5128 - ``P``: An immediate integer constant whose negation is a signed 16-bit
5130 - ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently
5131 treated the same as ``m``.
5132 - ``r``: A 32 or 64-bit integer register.
5133 - ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is:
5135 - ``f``: A 32 or 64-bit float register (``F0-F31``),
5136 - ``v``: For ``4 x f32`` or ``4 x f64`` types, a 128-bit altivec vector
5137 register (``V0-V31``).
5139 - ``y``: Condition register (``CR0-CR7``).
5140 - ``wc``: An individual CR bit in a CR register.
5141 - ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX
5142 register set (overlapping both the floating-point and vector register files).
5143 - ``ws``: A 32 or 64-bit floating-point register, from the full VSX register
5148 - ``A``: An address operand (using a general-purpose register, without an
5150 - ``I``: A 12-bit signed integer immediate operand.
5151 - ``J``: A zero integer immediate operand.
5152 - ``K``: A 5-bit unsigned integer immediate operand.
5153 - ``f``: A 32- or 64-bit floating-point register (requires F or D extension).
5154 - ``r``: A 32- or 64-bit general-purpose register (depending on the platform
5156 - ``vr``: A vector register. (requires V extension).
5157 - ``vm``: A vector register for masking operand. (requires V extension).
5161 - ``I``: An immediate 13-bit signed integer.
5162 - ``r``: A 32-bit integer register.
5163 - ``f``: Any floating-point register on SparcV8, or a floating-point
5164 register in the "low" half of the registers on SparcV9.
5165 - ``e``: Any floating-point register. (Same as ``f`` on SparcV8.)
5169 - ``I``: An immediate unsigned 8-bit integer.
5170 - ``J``: An immediate unsigned 12-bit integer.
5171 - ``K``: An immediate signed 16-bit integer.
5172 - ``L``: An immediate signed 20-bit integer.
5173 - ``M``: An immediate integer 0x7fffffff.
5174 - ``Q``: A memory address operand with a base address and a 12-bit immediate
5175 unsigned displacement.
5176 - ``R``: A memory address operand with a base address, a 12-bit immediate
5177 unsigned displacement, and an index register.
5178 - ``S``: A memory address operand with a base address and a 20-bit immediate
5179 signed displacement.
5180 - ``T``: A memory address operand with a base address, a 20-bit immediate
5181 signed displacement, and an index register.
5182 - ``r`` or ``d``: A 32, 64, or 128-bit integer register.
5183 - ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an
5184 address context evaluates as zero).
5185 - ``h``: A 32-bit value in the high part of a 64bit data register
5187 - ``f``: A 32, 64, or 128-bit floating-point register.
5191 - ``I``: An immediate integer between 0 and 31.
5192 - ``J``: An immediate integer between 0 and 64.
5193 - ``K``: An immediate signed 8-bit integer.
5194 - ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only)
5196 - ``M``: An immediate integer between 0 and 3.
5197 - ``N``: An immediate unsigned 8-bit integer.
5198 - ``O``: An immediate integer between 0 and 127.
5199 - ``e``: An immediate 32-bit signed integer.
5200 - ``Z``: An immediate 32-bit unsigned integer.
5201 - ``o``, ``v``: Treated the same as ``m``, at the moment.
5202 - ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
5203 ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d``
5204 registers, and on X86-64, it is all of the integer registers.
5205 - ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
5206 ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers.
5207 - ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register.
5208 - ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has
5209 existed since i386, and can be accessed without the REX prefix.
5210 - ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register.
5211 - ``y``: A 64-bit MMX register, if MMX is enabled.
5212 - ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector
5213 operand in a SSE register. If AVX is also enabled, can also be a 256-bit
5214 vector operand in an AVX register. If AVX-512 is also enabled, can also be a
5215 512-bit vector operand in an AVX512 register, Otherwise, an error.
5216 - ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error.
5217 - ``A``: Special case: allocates EAX first, then EDX, for a single operand (in
5218 32-bit mode, a 64-bit integer operand will get split into two registers). It
5219 is not recommended to use this constraint, as in 64-bit mode, the 64-bit
5220 operand will get allocated only to RAX -- if two 32-bit operands are needed,
5221 you're better off splitting it yourself, before passing it to the asm
5226 - ``r``: A 32-bit integer register.
5229 .. _inline-asm-modifiers:
5231 Asm template argument modifiers
5232 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5234 In the asm template string, modifiers can be used on the operand reference, like
5237 The modifiers are, in general, expected to behave the same way they do in
5238 GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
5239 inline asm code which was supported by GCC. A mismatch in behavior between LLVM
5240 and GCC likely indicates a bug in LLVM.
5244 - ``c``: Print an immediate integer constant unadorned, without
5245 the target-specific immediate punctuation (e.g. no ``$`` prefix).
5246 - ``n``: Negate and print immediate integer constant unadorned, without the
5247 target-specific immediate punctuation (e.g. no ``$`` prefix).
5248 - ``l``: Print as an unadorned label, without the target-specific label
5249 punctuation (e.g. no ``$`` prefix).
5253 - ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g.,
5254 instead of ``x30``, print ``w30``.
5255 - ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow).
5256 - ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a
5257 ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of
5266 - ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a
5270 - ``y``: Print a VFP single-precision register as an indexed double (e.g. print
5271 as ``d4[1]`` instead of ``s9``)
5272 - ``B``: Bitwise invert and print an immediate integer constant without ``#``
5274 - ``L``: Print the low 16-bits of an immediate integer constant.
5275 - ``M``: Print as a register set suitable for ldm/stm. Also prints *all*
5276 register operands subsequent to the specified one (!), so use carefully.
5277 - ``Q``: Print the low-order register of a register-pair, or the low-order
5278 register of a two-register operand.
5279 - ``R``: Print the high-order register of a register-pair, or the high-order
5280 register of a two-register operand.
5281 - ``H``: Print the second register of a register-pair. (On a big-endian system,
5282 ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent
5285 .. FIXME: H doesn't currently support printing the second register
5286 of a two-register operand.
5288 - ``e``: Print the low doubleword register of a NEON quad register.
5289 - ``f``: Print the high doubleword register of a NEON quad register.
5290 - ``m``: Print the base register of a memory operand without the ``[`` and ``]``
5295 - ``L``: Print the second register of a two-register operand. Requires that it
5296 has been allocated consecutively to the first.
5298 .. FIXME: why is it restricted to consecutive ones? And there's
5299 nothing that ensures that happens, is there?
5301 - ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
5302 nothing. Used to print 'addi' vs 'add' instructions.
5306 - ``z``: Print $zero register if operand is zero, otherwise print it normally.
5310 No additional modifiers.
5314 - ``X``: Print an immediate integer as hexadecimal
5315 - ``x``: Print the low 16 bits of an immediate integer as hexadecimal.
5316 - ``d``: Print an immediate integer as decimal.
5317 - ``m``: Subtract one and print an immediate integer as decimal.
5318 - ``z``: Print $0 if an immediate zero, otherwise print normally.
5319 - ``L``: Print the low-order register of a two-register operand, or prints the
5320 address of the low-order word of a double-word memory operand.
5322 .. FIXME: L seems to be missing memory operand support.
5324 - ``M``: Print the high-order register of a two-register operand, or prints the
5325 address of the high-order word of a double-word memory operand.
5327 .. FIXME: M seems to be missing memory operand support.
5329 - ``D``: Print the second register of a two-register operand, or prints the
5330 second word of a double-word memory operand. (On a big-endian system, ``D`` is
5331 equivalent to ``L``, and on little-endian system, ``D`` is equivalent to
5333 - ``w``: No effect. Provided for compatibility with GCC which requires this
5334 modifier in order to print MSA registers (``W0-W31``) with the ``f``
5343 - ``L``: Print the second register of a two-register operand. Requires that it
5344 has been allocated consecutively to the first.
5346 .. FIXME: why is it restricted to consecutive ones? And there's
5347 nothing that ensures that happens, is there?
5349 - ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
5350 nothing. Used to print 'addi' vs 'add' instructions.
5351 - ``y``: For a memory operand, prints formatter for a two-register X-form
5352 instruction. (Currently always prints ``r0,OPERAND``).
5353 - ``U``: Prints 'u' if the memory operand is an update form, and nothing
5354 otherwise. (NOTE: LLVM does not support update form, so this will currently
5355 always print nothing)
5356 - ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does
5357 not support indexed form, so this will currently always print nothing)
5361 - ``i``: Print the letter 'i' if the operand is not a register, otherwise print
5362 nothing. Used to print 'addi' vs 'add' instructions, etc.
5363 - ``z``: Print the register ``zero`` if an immediate zero, otherwise print
5372 SystemZ implements only ``n``, and does *not* support any of the other
5373 target-independent modifiers.
5377 - ``c``: Print an unadorned integer or symbol name. (The latter is
5378 target-specific behavior for this typically target-independent modifier).
5379 - ``A``: Print a register name with a '``*``' before it.
5380 - ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory
5382 - ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a
5384 - ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory
5386 - ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory
5388 - ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are
5389 available, otherwise the 32-bit register name; do nothing on a memory operand.
5390 - ``n``: Negate and print an unadorned integer, or, for operands other than an
5391 immediate integer (e.g. a relocatable symbol expression), print a '-' before
5392 the operand. (The behavior for relocatable symbol expressions is a
5393 target-specific behavior for this typically target-independent modifier)
5394 - ``H``: Print a memory reference with additional offset +8.
5395 - ``P``: Print a memory reference used as the argument of a call instruction or
5396 used with explicit base reg and index reg as its offset. So it can not use
5397 additional regs to present the memory reference. (E.g. omit ``(rip)``, even
5398 though it's PC-relative.)
5402 No additional modifiers.
5408 The call instructions that wrap inline asm nodes may have a
5409 "``!srcloc``" MDNode attached to it that contains a list of constant
5410 integers. If present, the code generator will use the integer as the
5411 location cookie value when report errors through the ``LLVMContext``
5412 error reporting mechanisms. This allows a front-end to correlate backend
5413 errors that occur with inline asm back to the source code that produced
5416 .. code-block:: llvm
5418 call void asm sideeffect "something bad", ""(), !srcloc !42
5420 !42 = !{ i32 1234567 }
5422 It is up to the front-end to make sense of the magic numbers it places
5423 in the IR. If the MDNode contains multiple constants, the code generator
5424 will use the one that corresponds to the line of the asm that the error
5432 LLVM IR allows metadata to be attached to instructions and global objects in the
5433 program that can convey extra information about the code to the optimizers and
5434 code generator. One example application of metadata is source-level
5435 debug information. There are two metadata primitives: strings and nodes.
5437 Metadata does not have a type, and is not a value. If referenced from a
5438 ``call`` instruction, it uses the ``metadata`` type.
5440 All metadata are identified in syntax by an exclamation point ('``!``').
5442 .. _metadata-string:
5444 Metadata Nodes and Metadata Strings
5445 -----------------------------------
5447 A metadata string is a string surrounded by double quotes. It can
5448 contain any character by escaping non-printable characters with
5449 "``\xx``" where "``xx``" is the two digit hex code. For example:
5452 Metadata nodes are represented with notation similar to structure
5453 constants (a comma separated list of elements, surrounded by braces and
5454 preceded by an exclamation point). Metadata nodes can have any values as
5455 their operand. For example:
5457 .. code-block:: llvm
5459 !{ !"test\00", i32 10}
5461 Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
5463 .. code-block:: text
5465 !0 = distinct !{!"test\00", i32 10}
5467 ``distinct`` nodes are useful when nodes shouldn't be merged based on their
5468 content. They can also occur when transformations cause uniquing collisions
5469 when metadata operands change.
5471 A :ref:`named metadata <namedmetadatastructure>` is a collection of
5472 metadata nodes, which can be looked up in the module symbol table. For
5475 .. code-block:: llvm
5479 Metadata can be used as function arguments. Here the ``llvm.dbg.value``
5480 intrinsic is using three metadata arguments:
5482 .. code-block:: llvm
5484 call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26)
5486 Metadata can be attached to an instruction. Here metadata ``!21`` is attached
5487 to the ``add`` instruction using the ``!dbg`` identifier:
5489 .. code-block:: llvm
5491 %indvar.next = add i64 %indvar, 1, !dbg !21
5493 Instructions may not have multiple metadata attachments with the same
5496 Metadata can also be attached to a function or a global variable. Here metadata
5497 ``!22`` is attached to the ``f1`` and ``f2`` functions, and the globals ``g1``
5498 and ``g2`` using the ``!dbg`` identifier:
5500 .. code-block:: llvm
5502 declare !dbg !22 void @f1()
5503 define void @f2() !dbg !22 {
5507 @g1 = global i32 0, !dbg !22
5508 @g2 = external global i32, !dbg !22
5510 Unlike instructions, global objects (functions and global variables) may have
5511 multiple metadata attachments with the same identifier.
5513 A transformation is required to drop any metadata attachment that it
5514 does not know or know it can't preserve. Currently there is an
5515 exception for metadata attachment to globals for ``!func_sanitize``,
5516 ``!type``, ``!absolute_symbol`` and ``!associated`` which can't be
5517 unconditionally dropped unless the global is itself deleted.
5519 Metadata attached to a module using named metadata may not be dropped, with
5520 the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``).
5522 More information about specific metadata nodes recognized by the
5523 optimizers and code generator is found below.
5525 .. _specialized-metadata:
5527 Specialized Metadata Nodes
5528 ^^^^^^^^^^^^^^^^^^^^^^^^^^
5530 Specialized metadata nodes are custom data structures in metadata (as opposed
5531 to generic tuples). Their fields are labelled, and can be specified in any
5534 These aren't inherently debug info centric, but currently all the specialized
5535 metadata nodes are related to debug info.
5542 ``DICompileUnit`` nodes represent a compile unit. The ``enums:``,
5543 ``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples
5544 containing the debug info to be emitted along with the compile unit, regardless
5545 of code optimizations (some nodes are only emitted if there are references to
5546 them from instructions). The ``debugInfoForProfiling:`` field is a boolean
5547 indicating whether or not line-table discriminators are updated to provide
5548 more-accurate debug info for profiling results.
5550 .. code-block:: text
5552 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
5553 isOptimized: true, flags: "-O2", runtimeVersion: 2,
5554 splitDebugFilename: "abc.debug", emissionKind: FullDebug,
5555 enums: !2, retainedTypes: !3, globals: !4, imports: !5,
5556 macros: !6, dwoId: 0x0abcd)
5558 Compile unit descriptors provide the root scope for objects declared in a
5559 specific compilation unit. File descriptors are defined using this scope. These
5560 descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep
5561 track of global variables, type information, and imported entities (declarations
5569 ``DIFile`` nodes represent files. The ``filename:`` can include slashes.
5571 .. code-block:: none
5573 !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir",
5574 checksumkind: CSK_MD5,
5575 checksum: "000102030405060708090a0b0c0d0e0f")
5577 Files are sometimes used in ``scope:`` fields, and are the only valid target
5578 for ``file:`` fields.
5579 Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1, CSK_SHA256}
5586 ``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
5587 ``float``. ``tag:`` defaults to ``DW_TAG_base_type``.
5589 .. code-block:: text
5591 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
5592 encoding: DW_ATE_unsigned_char)
5593 !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
5595 The ``encoding:`` describes the details of the type. Usually it's one of the
5598 .. code-block:: text
5604 DW_ATE_signed_char = 6
5606 DW_ATE_unsigned_char = 8
5608 .. _DISubroutineType:
5613 ``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field
5614 refers to a tuple; the first operand is the return type, while the rest are the
5615 types of the formal arguments in order. If the first operand is ``null``, that
5616 represents a function with no return value (such as ``void foo() {}`` in C++).
5618 .. code-block:: text
5620 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
5621 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
5622 !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char)
5629 ``DIDerivedType`` nodes represent types derived from other types, such as
5632 .. code-block:: text
5634 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
5635 encoding: DW_ATE_unsigned_char)
5636 !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
5639 The following ``tag:`` values are valid:
5641 .. code-block:: text
5644 DW_TAG_pointer_type = 15
5645 DW_TAG_reference_type = 16
5647 DW_TAG_inheritance = 28
5648 DW_TAG_ptr_to_member_type = 31
5649 DW_TAG_const_type = 38
5651 DW_TAG_volatile_type = 53
5652 DW_TAG_restrict_type = 55
5653 DW_TAG_atomic_type = 71
5654 DW_TAG_immutable_type = 75
5656 .. _DIDerivedTypeMember:
5658 ``DW_TAG_member`` is used to define a member of a :ref:`composite type
5659 <DICompositeType>`. The type of the member is the ``baseType:``. The
5660 ``offset:`` is the member's bit offset. If the composite type has an ODR
5661 ``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is
5662 uniqued based only on its ``name:`` and ``scope:``.
5664 ``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:``
5665 field of :ref:`composite types <DICompositeType>` to describe parents and
5668 ``DW_TAG_typedef`` is used to provide a name for the ``baseType:``.
5670 ``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``,
5671 ``DW_TAG_volatile_type``, ``DW_TAG_restrict_type``, ``DW_TAG_atomic_type`` and
5672 ``DW_TAG_immutable_type`` are used to qualify the ``baseType:``.
5674 Note that the ``void *`` type is expressed as a type derived from NULL.
5676 .. _DICompositeType:
5681 ``DICompositeType`` nodes represent types composed of other types, like
5682 structures and unions. ``elements:`` points to a tuple of the composed types.
5684 If the source language supports ODR, the ``identifier:`` field gives the unique
5685 identifier used for type merging between modules. When specified,
5686 :ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member
5687 derived types <DIDerivedTypeMember>` that reference the ODR-type in their
5688 ``scope:`` change uniquing rules.
5690 For a given ``identifier:``, there should only be a single composite type that
5691 does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules
5692 together will unique such definitions at parse time via the ``identifier:``
5693 field, even if the nodes are ``distinct``.
5695 .. code-block:: text
5697 !0 = !DIEnumerator(name: "SixKind", value: 7)
5698 !1 = !DIEnumerator(name: "SevenKind", value: 7)
5699 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
5700 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
5701 line: 2, size: 32, align: 32, identifier: "_M4Enum",
5702 elements: !{!0, !1, !2})
5704 The following ``tag:`` values are valid:
5706 .. code-block:: text
5708 DW_TAG_array_type = 1
5709 DW_TAG_class_type = 2
5710 DW_TAG_enumeration_type = 4
5711 DW_TAG_structure_type = 19
5712 DW_TAG_union_type = 23
5714 For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange
5715 descriptors <DISubrange>`, each representing the range of subscripts at that
5716 level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an
5717 array type is a native packed vector. The optional ``dataLocation`` is a
5718 DIExpression that describes how to get from an object's address to the actual
5719 raw data, if they aren't equivalent. This is only supported for array types,
5720 particularly to describe Fortran arrays, which have an array descriptor in
5721 addition to the array data. Alternatively it can also be DIVariable which
5722 has the address of the actual raw data. The Fortran language supports pointer
5723 arrays which can be attached to actual arrays, this attachment between pointer
5724 and pointee is called association. The optional ``associated`` is a
5725 DIExpression that describes whether the pointer array is currently associated.
5726 The optional ``allocated`` is a DIExpression that describes whether the
5727 allocatable array is currently allocated. The optional ``rank`` is a
5728 DIExpression that describes the rank (number of dimensions) of fortran assumed
5729 rank array (rank is known at runtime).
5731 For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
5732 descriptors <DIEnumerator>`, each representing the definition of an enumeration
5733 value for the set. All enumeration type descriptors are collected in the
5734 ``enums:`` field of the :ref:`compile unit <DICompileUnit>`.
5736 For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and
5737 ``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types
5738 <DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or
5739 ``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with
5740 ``isDefinition: false``.
5747 ``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
5748 :ref:`DICompositeType`.
5750 - ``count: -1`` indicates an empty array.
5751 - ``count: !10`` describes the count with a :ref:`DILocalVariable`.
5752 - ``count: !12`` describes the count with a :ref:`DIGlobalVariable`.
5754 .. code-block:: text
5756 !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0
5757 !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1
5758 !2 = !DISubrange(count: -1) ; empty array.
5760 ; Scopes used in rest of example
5761 !6 = !DIFile(filename: "vla.c", directory: "/path/to/file")
5762 !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6)
5763 !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5)
5765 ; Use of local variable as count value
5766 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
5767 !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9)
5768 !11 = !DISubrange(count: !10, lowerBound: 0)
5770 ; Use of global variable as count value
5771 !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9)
5772 !13 = !DISubrange(count: !12, lowerBound: 0)
5779 ``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
5780 variants of :ref:`DICompositeType`.
5782 .. code-block:: text
5784 !0 = !DIEnumerator(name: "SixKind", value: 7)
5785 !1 = !DIEnumerator(name: "SevenKind", value: 7)
5786 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
5788 DITemplateTypeParameter
5789 """""""""""""""""""""""
5791 ``DITemplateTypeParameter`` nodes represent type parameters to generic source
5792 language constructs. They are used (optionally) in :ref:`DICompositeType` and
5793 :ref:`DISubprogram` ``templateParams:`` fields.
5795 .. code-block:: text
5797 !0 = !DITemplateTypeParameter(name: "Ty", type: !1)
5799 DITemplateValueParameter
5800 """"""""""""""""""""""""
5802 ``DITemplateValueParameter`` nodes represent value parameters to generic source
5803 language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
5804 but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
5805 ``DW_TAG_GNU_template_param_pack``. They are used (optionally) in
5806 :ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields.
5808 .. code-block:: text
5810 !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7)
5815 ``DINamespace`` nodes represent namespaces in the source language.
5817 .. code-block:: text
5819 !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
5821 .. _DIGlobalVariable:
5826 ``DIGlobalVariable`` nodes represent global variables in the source language.
5828 .. code-block:: text
5830 @foo = global i32, !dbg !0
5831 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
5832 !1 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !2,
5833 file: !3, line: 7, type: !4, isLocal: true,
5834 isDefinition: false, declaration: !5)
5837 DIGlobalVariableExpression
5838 """"""""""""""""""""""""""
5840 ``DIGlobalVariableExpression`` nodes tie a :ref:`DIGlobalVariable` together
5841 with a :ref:`DIExpression`.
5843 .. code-block:: text
5845 @lower = global i32, !dbg !0
5846 @upper = global i32, !dbg !1
5847 !0 = !DIGlobalVariableExpression(
5849 expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32)
5851 !1 = !DIGlobalVariableExpression(
5853 expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32)
5855 !2 = !DIGlobalVariable(name: "split64", linkageName: "split64", scope: !3,
5856 file: !4, line: 8, type: !5, declaration: !6)
5858 All global variable expressions should be referenced by the `globals:` field of
5859 a :ref:`compile unit <DICompileUnit>`.
5866 ``DISubprogram`` nodes represent functions from the source language. A distinct
5867 ``DISubprogram`` may be attached to a function definition using ``!dbg``
5868 metadata. A unique ``DISubprogram`` may be attached to a function declaration
5869 used for call site debug info. The ``retainedNodes:`` field is a list of
5870 :ref:`variables <DILocalVariable>` and :ref:`labels <DILabel>` that must be
5871 retained, even if their IR counterparts are optimized out of the IR. The
5872 ``type:`` field must point at an :ref:`DISubroutineType`.
5874 .. _DISubprogramDeclaration:
5876 When ``spFlags: DISPFlagDefinition`` is not present, subprograms describe a
5877 declaration in the type tree as opposed to a definition of a function. In this
5878 case, the ``declaration`` field must be empty. If the scope is a composite type
5879 with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``, then
5880 the subprogram declaration is uniqued based only on its ``linkageName:`` and
5883 .. code-block:: text
5885 define void @_Z3foov() !dbg !0 {
5889 !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
5890 file: !2, line: 7, type: !3,
5891 spFlags: DISPFlagDefinition | DISPFlagLocalToUnit,
5892 scopeLine: 8, containingType: !4,
5893 virtuality: DW_VIRTUALITY_pure_virtual,
5894 virtualIndex: 10, flags: DIFlagPrototyped,
5895 isOptimized: true, unit: !5, templateParams: !6,
5896 declaration: !7, retainedNodes: !8,
5904 ``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
5905 <DISubprogram>`. The line number and column numbers are used to distinguish
5906 two lexical blocks at same depth. They are valid targets for ``scope:``
5909 .. code-block:: text
5911 !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
5913 Usually lexical blocks are ``distinct`` to prevent node merging based on
5916 .. _DILexicalBlockFile:
5921 ``DILexicalBlockFile`` nodes are used to discriminate between sections of a
5922 :ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to
5923 indicate textual inclusion, or the ``discriminator:`` field can be used to
5924 discriminate between control flow within a single block in the source language.
5926 .. code-block:: text
5928 !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35)
5929 !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0)
5930 !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1)
5937 ``DILocation`` nodes represent source debug locations. The ``scope:`` field is
5938 mandatory, and points at an :ref:`DILexicalBlockFile`, an
5939 :ref:`DILexicalBlock`, or an :ref:`DISubprogram`.
5941 .. code-block:: text
5943 !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
5945 .. _DILocalVariable:
5950 ``DILocalVariable`` nodes represent local variables in the source language. If
5951 the ``arg:`` field is set to non-zero, then this variable is a subprogram
5952 parameter, and it will be included in the ``retainedNodes:`` field of its
5953 :ref:`DISubprogram`.
5955 .. code-block:: text
5957 !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7,
5958 type: !3, flags: DIFlagArtificial)
5959 !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7,
5961 !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3)
5968 ``DIExpression`` nodes represent expressions that are inspired by the DWARF
5969 expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>`
5970 (such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the
5971 referenced LLVM variable relates to the source language variable. Debug
5972 intrinsics are interpreted left-to-right: start by pushing the value/address
5973 operand of the intrinsic onto a stack, then repeatedly push and evaluate
5974 opcodes from the DIExpression until the final variable description is produced.
5976 The current supported opcode vocabulary is limited:
5978 - ``DW_OP_deref`` dereferences the top of the expression stack.
5979 - ``DW_OP_plus`` pops the last two entries from the expression stack, adds
5980 them together and appends the result to the expression stack.
5981 - ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts
5982 the last entry from the second last entry and appends the result to the
5984 - ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression.
5985 - ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8``
5986 here, respectively) of the variable fragment from the working expression. Note
5987 that contrary to DW_OP_bit_piece, the offset is describing the location
5988 within the described source variable.
5989 - ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding
5990 (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the
5991 expression stack is to be converted. Maps into a ``DW_OP_convert`` operation
5992 that references a base type constructed from the supplied values.
5993 - ``DW_OP_LLVM_tag_offset, tag_offset`` specifies that a memory tag should be
5994 optionally applied to the pointer. The memory tag is derived from the
5995 given tag offset in an implementation-defined manner.
5996 - ``DW_OP_swap`` swaps top two stack entries.
5997 - ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top
5998 of the stack is treated as an address. The second stack entry is treated as an
5999 address space identifier.
6000 - ``DW_OP_stack_value`` marks a constant value.
6001 - ``DW_OP_LLVM_entry_value, N`` refers to the value a register had upon
6002 function entry. When targeting DWARF, a ``DBG_VALUE(reg, ...,
6003 DIExpression(DW_OP_LLVM_entry_value, 1, ...)`` is lowered to
6004 ``DW_OP_entry_value [reg], ...``, which pushes the value ``reg`` had upon
6005 function entry onto the DWARF expression stack.
6007 The next ``(N - 1)`` operations will be part of the ``DW_OP_entry_value``
6008 block argument. For example, ``!DIExpression(DW_OP_LLVM_entry_value, 1,
6009 DW_OP_plus_uconst, 123, DW_OP_stack_value)`` specifies an expression where
6010 the entry value of ``reg`` is pushed onto the stack, and is added with 123.
6011 Due to framework limitations ``N`` must be 1, in other words,
6012 ``DW_OP_entry_value`` always refers to the value/address operand of the
6015 Because ``DW_OP_LLVM_entry_value`` is defined in terms of registers, it is
6016 usually used in MIR, but it is also allowed in LLVM IR when targetting a
6017 :ref:`swiftasync <swiftasync>` argument. The operation is introduced by:
6019 - ``LiveDebugValues`` pass, which applies it to function parameters that
6020 are unmodified throughout the function. Support is limited to simple
6021 register location descriptions, or as indirect locations (e.g.,
6022 parameters passed-by-value to a callee via a pointer to a temporary copy
6023 made in the caller).
6024 - ``AsmPrinter`` pass when a call site parameter value
6025 (``DW_AT_call_site_parameter_value``) is represented as entry value of
6027 - ``CoroSplit`` pass, which may move variables from allocas into a
6028 coroutine frame. If the coroutine frame is a
6029 :ref:`swiftasync <swiftasync>` argument, the variable is described with
6030 an ``DW_OP_LLVM_entry_value`` operation.
6032 - ``DW_OP_LLVM_arg, N`` is used in debug intrinsics that refer to more than one
6033 value, such as one that calculates the sum of two registers. This is always
6034 used in combination with an ordered list of values, such that
6035 ``DW_OP_LLVM_arg, N`` refers to the ``N``\ :sup:`th` element in that list. For
6036 example, ``!DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus,
6037 DW_OP_stack_value)`` used with the list ``(%reg1, %reg2)`` would evaluate to
6038 ``%reg1 - reg2``. This list of values should be provided by the containing
6039 intrinsic/instruction.
6040 - ``DW_OP_breg`` (or ``DW_OP_bregx``) represents a content on the provided
6041 signed offset of the specified register. The opcode is only generated by the
6042 ``AsmPrinter`` pass to describe call site parameter value which requires an
6043 expression over two registers.
6044 - ``DW_OP_push_object_address`` pushes the address of the object which can then
6045 serve as a descriptor in subsequent calculation. This opcode can be used to
6046 calculate bounds of fortran allocatable array which has array descriptors.
6047 - ``DW_OP_over`` duplicates the entry currently second in the stack at the top
6048 of the stack. This opcode can be used to calculate bounds of fortran assumed
6049 rank array which has rank known at run time and current dimension number is
6050 implicitly first element of the stack.
6051 - ``DW_OP_LLVM_implicit_pointer`` It specifies the dereferenced value. It can
6052 be used to represent pointer variables which are optimized out but the value
6053 it points to is known. This operator is required as it is different than DWARF
6054 operator DW_OP_implicit_pointer in representation and specification (number
6055 and types of operands) and later can not be used as multiple level.
6057 .. code-block:: text
6061 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !20)
6062 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5,
6064 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
6065 !19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
6066 !20 = !DIExpression(DW_OP_LLVM_implicit_pointer))
6070 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !21)
6071 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5,
6073 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
6074 !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
6075 !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
6076 !21 = !DIExpression(DW_OP_LLVM_implicit_pointer,
6077 DW_OP_LLVM_implicit_pointer))
6079 DWARF specifies three kinds of simple location descriptions: Register, memory,
6080 and implicit location descriptions. Note that a location description is
6081 defined over certain ranges of a program, i.e the location of a variable may
6082 change over the course of the program. Register and memory location
6083 descriptions describe the *concrete location* of a source variable (in the
6084 sense that a debugger might modify its value), whereas *implicit locations*
6085 describe merely the actual *value* of a source variable which might not exist
6086 in registers or in memory (see ``DW_OP_stack_value``).
6088 A ``llvm.dbg.declare`` intrinsic describes an indirect value (the address) of a
6089 source variable. The first operand of the intrinsic must be an address of some
6090 kind. A DIExpression attached to the intrinsic refines this address to produce a
6091 concrete location for the source variable.
6093 A ``llvm.dbg.value`` intrinsic describes the direct value of a source variable.
6094 The first operand of the intrinsic may be a direct or indirect value. A
6095 DIExpression attached to the intrinsic refines the first operand to produce a
6096 direct value. For example, if the first operand is an indirect value, it may be
6097 necessary to insert ``DW_OP_deref`` into the DIExpression in order to produce a
6098 valid debug intrinsic.
6102 A DIExpression is interpreted in the same way regardless of which kind of
6103 debug intrinsic it's attached to.
6105 .. code-block:: text
6107 !0 = !DIExpression(DW_OP_deref)
6108 !1 = !DIExpression(DW_OP_plus_uconst, 3)
6109 !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus)
6110 !2 = !DIExpression(DW_OP_bit_piece, 3, 7)
6111 !3 = !DIExpression(DW_OP_deref, DW_OP_constu, 3, DW_OP_plus, DW_OP_LLVM_fragment, 3, 7)
6112 !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef)
6113 !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value)
6118 ``DIAssignID`` nodes have no operands and are always distinct. They are used to
6119 link together `@llvm.dbg.assign` intrinsics (:ref:`debug
6120 intrinsics<dbg_intrinsics>`) and instructions that store in IR. See `Debug Info
6121 Assignment Tracking <AssignmentTracking.html>`_ for more info.
6123 .. code-block:: llvm
6125 store i32 %a, ptr %a.addr, align 4, !DIAssignID !2
6126 llvm.dbg.assign(metadata %a, metadata !1, metadata !DIExpression(), !2, metadata %a.addr, metadata !DIExpression()), !dbg !3
6128 !2 = distinct !DIAssignID()
6133 ``DIArgList`` nodes hold a list of constant or SSA value references. These are
6134 used in :ref:`debug intrinsics<dbg_intrinsics>` (currently only in
6135 ``llvm.dbg.value``) in combination with a ``DIExpression`` that uses the
6136 ``DW_OP_LLVM_arg`` operator. Because a DIArgList may refer to local values
6137 within a function, it must only be used as a function argument, must always be
6138 inlined, and cannot appear in named metadata.
6140 .. code-block:: text
6142 llvm.dbg.value(metadata !DIArgList(i32 %a, i32 %b),
6144 metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus))
6149 These flags encode various properties of DINodes.
6151 The `ExportSymbols` flag marks a class, struct or union whose members
6152 may be referenced as if they were defined in the containing class or
6153 union. This flag is used to decide whether the DW_AT_export_symbols can
6154 be used for the structure type.
6159 ``DIObjCProperty`` nodes represent Objective-C property nodes.
6161 .. code-block:: text
6163 !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
6164 getter: "getFoo", attributes: 7, type: !2)
6169 ``DIImportedEntity`` nodes represent entities (such as modules) imported into a
6170 compile unit. The ``elements`` field is a list of renamed entities (such as
6171 variables and subprograms) in the imported entity (such as module).
6173 .. code-block:: text
6175 !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
6176 entity: !1, line: 7, elements: !3)
6178 !4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "bar", scope: !0,
6179 entity: !5, line: 7)
6184 ``DIMacro`` nodes represent definition or undefinition of a macro identifiers.
6185 The ``name:`` field is the macro identifier, followed by macro parameters when
6186 defining a function-like macro, and the ``value`` field is the token-string
6187 used to expand the macro identifier.
6189 .. code-block:: text
6191 !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)",
6193 !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo")
6198 ``DIMacroFile`` nodes represent inclusion of source files.
6199 The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that
6200 appear in the included source file.
6202 .. code-block:: text
6204 !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2,
6212 ``DILabel`` nodes represent labels within a :ref:`DISubprogram`. All fields of
6213 a ``DILabel`` are mandatory. The ``scope:`` field must be one of either a
6214 :ref:`DILexicalBlockFile`, a :ref:`DILexicalBlock`, or a :ref:`DISubprogram`.
6215 The ``name:`` field is the label identifier. The ``file:`` field is the
6216 :ref:`DIFile` the label is present in. The ``line:`` field is the source line
6217 within the file where the label is declared.
6219 .. code-block:: text
6221 !2 = !DILabel(scope: !0, name: "foo", file: !1, line: 7)
6226 In LLVM IR, memory does not have types, so LLVM's own type system is not
6227 suitable for doing type based alias analysis (TBAA). Instead, metadata is
6228 added to the IR to describe a type system of a higher level language. This
6229 can be used to implement C/C++ strict type aliasing rules, but it can also
6230 be used to implement custom alias analysis behavior for other languages.
6232 This description of LLVM's TBAA system is broken into two parts:
6233 :ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and
6234 :ref:`Representation<tbaa_node_representation>` talks about the metadata
6235 encoding of various entities.
6237 It is always possible to trace any TBAA node to a "root" TBAA node (details
6238 in the :ref:`Representation<tbaa_node_representation>` section). TBAA
6239 nodes with different roots have an unknown aliasing relationship, and LLVM
6240 conservatively infers ``MayAlias`` between them. The rules mentioned in
6241 this section only pertain to TBAA nodes living under the same root.
6243 .. _tbaa_node_semantics:
6248 The TBAA metadata system, referred to as "struct path TBAA" (not to be
6249 confused with ``tbaa.struct``), consists of the following high level
6250 concepts: *Type Descriptors*, further subdivided into scalar type
6251 descriptors and struct type descriptors; and *Access Tags*.
6253 **Type descriptors** describe the type system of the higher level language
6254 being compiled. **Scalar type descriptors** describe types that do not
6255 contain other types. Each scalar type has a parent type, which must also
6256 be a scalar type or the TBAA root. Via this parent relation, scalar types
6257 within a TBAA root form a tree. **Struct type descriptors** denote types
6258 that contain a sequence of other type descriptors, at known offsets. These
6259 contained type descriptors can either be struct type descriptors themselves
6260 or scalar type descriptors.
6262 **Access tags** are metadata nodes attached to load and store instructions.
6263 Access tags use type descriptors to describe the *location* being accessed
6264 in terms of the type system of the higher level language. Access tags are
6265 tuples consisting of a base type, an access type and an offset. The base
6266 type is a scalar type descriptor or a struct type descriptor, the access
6267 type is a scalar type descriptor, and the offset is a constant integer.
6269 The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two
6272 * If ``BaseTy`` is a struct type, the tag describes a memory access (load
6273 or store) of a value of type ``AccessTy`` contained in the struct type
6274 ``BaseTy`` at offset ``Offset``.
6276 * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and
6277 ``AccessTy`` must be the same; and the access tag describes a scalar
6278 access with scalar type ``AccessTy``.
6280 We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)``
6283 * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is
6284 ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as
6285 described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is
6286 undefined if ``Offset`` is non-zero.
6288 * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)``
6289 is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in
6290 ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted
6291 to be relative within that inner type.
6293 A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)``
6294 aliases a memory access with an access tag ``(BaseTy2, AccessTy2,
6295 Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2,
6296 Offset2)`` via the ``Parent`` relation or vice versa.
6298 As a concrete example, the type descriptor graph for the following program
6304 float f; // offset 4
6308 float f; // offset 0
6309 double d; // offset 4
6310 struct Inner inner_a; // offset 12
6313 void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) {
6314 outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0)
6315 outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12)
6316 outer->inner_a.f = 0.0; // tag2: (OuterStructTy, FloatScalarTy, 16)
6317 *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0)
6320 is (note that in C and C++, ``char`` can be used to access any arbitrary
6323 .. code-block:: text
6326 CharScalarTy = ("char", Root, 0)
6327 FloatScalarTy = ("float", CharScalarTy, 0)
6328 DoubleScalarTy = ("double", CharScalarTy, 0)
6329 IntScalarTy = ("int", CharScalarTy, 0)
6330 InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)}
6331 OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4),
6332 (InnerStructTy, 12)}
6335 with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy,
6336 0)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and
6337 ``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``.
6339 .. _tbaa_node_representation:
6344 The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or
6345 with exactly one ``MDString`` operand.
6347 Scalar type descriptors are represented as an ``MDNode`` s with two
6348 operands. The first operand is an ``MDString`` denoting the name of the
6349 struct type. LLVM does not assign meaning to the value of this operand, it
6350 only cares about it being an ``MDString``. The second operand is an
6351 ``MDNode`` which points to the parent for said scalar type descriptor,
6352 which is either another scalar type descriptor or the TBAA root. Scalar
6353 type descriptors can have an optional third argument, but that must be the
6354 constant integer zero.
6356 Struct type descriptors are represented as ``MDNode`` s with an odd number
6357 of operands greater than 1. The first operand is an ``MDString`` denoting
6358 the name of the struct type. Like in scalar type descriptors the actual
6359 value of this name operand is irrelevant to LLVM. After the name operand,
6360 the struct type descriptors have a sequence of alternating ``MDNode`` and
6361 ``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand,
6362 an ``MDNode``, denotes a contained field, and the 2N th operand, a
6363 ``ConstantInt``, is the offset of the said contained field. The offsets
6364 must be in non-decreasing order.
6366 Access tags are represented as ``MDNode`` s with either 3 or 4 operands.
6367 The first operand is an ``MDNode`` pointing to the node representing the
6368 base type. The second operand is an ``MDNode`` pointing to the node
6369 representing the access type. The third operand is a ``ConstantInt`` that
6370 states the offset of the access. If a fourth field is present, it must be
6371 a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states
6372 that the location being accessed is "constant" (meaning
6373 ``pointsToConstantMemory`` should return true; see `other useful
6374 AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of
6375 the access type and the base type of an access tag must be the same, and
6376 that is the TBAA root of the access tag.
6378 '``tbaa.struct``' Metadata
6379 ^^^^^^^^^^^^^^^^^^^^^^^^^^
6381 The :ref:`llvm.memcpy <int_memcpy>` is often used to implement
6382 aggregate assignment operations in C and similar languages, however it
6383 is defined to copy a contiguous region of memory, which is more than
6384 strictly necessary for aggregate types which contain holes due to
6385 padding. Also, it doesn't contain any TBAA information about the fields
6388 ``!tbaa.struct`` metadata can describe which memory subregions in a
6389 memcpy are padding and what the TBAA tags of the struct are.
6391 The current metadata format is very simple. ``!tbaa.struct`` metadata
6392 nodes are a list of operands which are in conceptual groups of three.
6393 For each group of three, the first operand gives the byte offset of a
6394 field in bytes, the second gives its size in bytes, and the third gives
6397 .. code-block:: llvm
6399 !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 }
6401 This describes a struct with two fields. The first is at offset 0 bytes
6402 with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes
6403 and has size 4 bytes and has tbaa tag !2.
6405 Note that the fields need not be contiguous. In this example, there is a
6406 4 byte gap between the two fields. This gap represents padding which
6407 does not carry useful data and need not be preserved.
6409 '``noalias``' and '``alias.scope``' Metadata
6410 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6412 ``noalias`` and ``alias.scope`` metadata provide the ability to specify generic
6413 noalias memory-access sets. This means that some collection of memory access
6414 instructions (loads, stores, memory-accessing calls, etc.) that carry
6415 ``noalias`` metadata can specifically be specified not to alias with some other
6416 collection of memory access instructions that carry ``alias.scope`` metadata.
6417 Each type of metadata specifies a list of scopes where each scope has an id and
6420 When evaluating an aliasing query, if for some domain, the set
6421 of scopes with that domain in one instruction's ``alias.scope`` list is a
6422 subset of (or equal to) the set of scopes for that domain in another
6423 instruction's ``noalias`` list, then the two memory accesses are assumed not to
6426 Because scopes in one domain don't affect scopes in other domains, separate
6427 domains can be used to compose multiple independent noalias sets. This is
6428 used for example during inlining. As the noalias function parameters are
6429 turned into noalias scope metadata, a new domain is used every time the
6430 function is inlined.
6432 The metadata identifying each domain is itself a list containing one or two
6433 entries. The first entry is the name of the domain. Note that if the name is a
6434 string then it can be combined across functions and translation units. A
6435 self-reference can be used to create globally unique domain names. A
6436 descriptive string may optionally be provided as a second list entry.
6438 The metadata identifying each scope is also itself a list containing two or
6439 three entries. The first entry is the name of the scope. Note that if the name
6440 is a string then it can be combined across functions and translation units. A
6441 self-reference can be used to create globally unique scope names. A metadata
6442 reference to the scope's domain is the second entry. A descriptive string may
6443 optionally be provided as a third list entry.
6447 .. code-block:: llvm
6449 ; Two scope domains:
6453 ; Some scopes in these domains:
6459 !5 = !{!4} ; A list containing only scope !4
6463 ; These two instructions don't alias:
6464 %0 = load float, ptr %c, align 4, !alias.scope !5
6465 store float %0, ptr %arrayidx.i, align 4, !noalias !5
6467 ; These two instructions also don't alias (for domain !1, the set of scopes
6468 ; in the !alias.scope equals that in the !noalias list):
6469 %2 = load float, ptr %c, align 4, !alias.scope !5
6470 store float %2, ptr %arrayidx.i2, align 4, !noalias !6
6472 ; These two instructions may alias (for domain !0, the set of scopes in
6473 ; the !noalias list is not a superset of, or equal to, the scopes in the
6474 ; !alias.scope list):
6475 %2 = load float, ptr %c, align 4, !alias.scope !6
6476 store float %0, ptr %arrayidx.i, align 4, !noalias !7
6478 '``fpmath``' Metadata
6479 ^^^^^^^^^^^^^^^^^^^^^
6481 ``fpmath`` metadata may be attached to any instruction of floating-point
6482 type. It can be used to express the maximum acceptable error in the
6483 result of that instruction, in ULPs, thus potentially allowing the
6484 compiler to use a more efficient but less accurate method of computing
6485 it. ULP is defined as follows:
6487 If ``x`` is a real number that lies between two finite consecutive
6488 floating-point numbers ``a`` and ``b``, without being equal to one
6489 of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the
6490 distance between the two non-equal finite floating-point numbers
6491 nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``.
6493 The metadata node shall consist of a single positive float type number
6494 representing the maximum relative error, for example:
6496 .. code-block:: llvm
6498 !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
6502 '``range``' Metadata
6503 ^^^^^^^^^^^^^^^^^^^^
6505 ``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of
6506 integer or vector of integer types. It expresses the possible ranges the loaded
6507 value or the value returned by the called function at this call site is in. If
6508 the loaded or returned value is not in the specified range, a poison value is
6509 returned instead. The ranges are represented with a flattened list of integers.
6510 The loaded value or the value returned is known to be in the union of the ranges
6511 defined by each consecutive pair. Each pair has the following properties:
6513 - The type must match the scalar type of the instruction.
6514 - The pair ``a,b`` represents the range ``[a,b)``.
6515 - Both ``a`` and ``b`` are constants.
6516 - The range is allowed to wrap.
6517 - The range should not represent the full or empty set. That is,
6520 In addition, the pairs must be in signed order of the lower bound and
6521 they must be non-contiguous.
6523 For vector-typed instructions, the range is applied element-wise.
6527 .. code-block:: llvm
6529 %a = load i8, ptr %x, align 1, !range !0 ; Can only be 0 or 1
6530 %b = load i8, ptr %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
6531 %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5
6532 %d = invoke i8 @bar() to label %cont
6533 unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5
6534 %e = load <2 x i8>, ptr %x, !range 0 ; Can only be <0 or 1, 0 or 1>
6536 !0 = !{ i8 0, i8 2 }
6537 !1 = !{ i8 255, i8 2 }
6538 !2 = !{ i8 0, i8 2, i8 3, i8 6 }
6539 !3 = !{ i8 -2, i8 0, i8 3, i8 6 }
6541 '``absolute_symbol``' Metadata
6542 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6544 ``absolute_symbol`` metadata may be attached to a global variable
6545 declaration. It marks the declaration as a reference to an absolute symbol,
6546 which causes the backend to use absolute relocations for the symbol even
6547 in position independent code, and expresses the possible ranges that the
6548 global variable's *address* (not its value) is in, in the same format as
6549 ``range`` metadata, with the extension that the pair ``all-ones,all-ones``
6550 may be used to represent the full set.
6552 Example (assuming 64-bit pointers):
6554 .. code-block:: llvm
6556 @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256)
6557 @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64)
6560 !0 = !{ i64 0, i64 256 }
6561 !1 = !{ i64 -1, i64 -1 }
6563 '``callees``' Metadata
6564 ^^^^^^^^^^^^^^^^^^^^^^
6566 ``callees`` metadata may be attached to indirect call sites. If ``callees``
6567 metadata is attached to a call site, and any callee is not among the set of
6568 functions provided by the metadata, the behavior is undefined. The intent of
6569 this metadata is to facilitate optimizations such as indirect-call promotion.
6570 For example, in the code below, the call instruction may only target the
6571 ``add`` or ``sub`` functions:
6573 .. code-block:: llvm
6575 %result = call i64 %binop(i64 %x, i64 %y), !callees !0
6578 !0 = !{ptr @add, ptr @sub}
6580 '``callback``' Metadata
6581 ^^^^^^^^^^^^^^^^^^^^^^^
6583 ``callback`` metadata may be attached to a function declaration, or definition.
6584 (Call sites are excluded only due to the lack of a use case.) For ease of
6585 exposition, we'll refer to the function annotated w/ metadata as a broker
6586 function. The metadata describes how the arguments of a call to the broker are
6587 in turn passed to the callback function specified by the metadata. Thus, the
6588 ``callback`` metadata provides a partial description of a call site inside the
6589 broker function with regards to the arguments of a call to the broker. The only
6590 semantic restriction on the broker function itself is that it is not allowed to
6591 inspect or modify arguments referenced in the ``callback`` metadata as
6592 pass-through to the callback function.
6594 The broker is not required to actually invoke the callback function at runtime.
6595 However, the assumptions about not inspecting or modifying arguments that would
6596 be passed to the specified callback function still hold, even if the callback
6597 function is not dynamically invoked. The broker is allowed to invoke the
6598 callback function more than once per invocation of the broker. The broker is
6599 also allowed to invoke (directly or indirectly) the function passed as a
6600 callback through another use. Finally, the broker is also allowed to relay the
6601 callback callee invocation to a different thread.
6603 The metadata is structured as follows: At the outer level, ``callback``
6604 metadata is a list of ``callback`` encodings. Each encoding starts with a
6605 constant ``i64`` which describes the argument position of the callback function
6606 in the call to the broker. The following elements, except the last, describe
6607 what arguments are passed to the callback function. Each element is again an
6608 ``i64`` constant identifying the argument of the broker that is passed through,
6609 or ``i64 -1`` to indicate an unknown or inspected argument. The order in which
6610 they are listed has to be the same in which they are passed to the callback
6611 callee. The last element of the encoding is a boolean which specifies how
6612 variadic arguments of the broker are handled. If it is true, all variadic
6613 arguments of the broker are passed through to the callback function *after* the
6614 arguments encoded explicitly before.
6616 In the code below, the ``pthread_create`` function is marked as a broker
6617 through the ``!callback !1`` metadata. In the example, there is only one
6618 callback encoding, namely ``!2``, associated with the broker. This encoding
6619 identifies the callback function as the second argument of the broker (``i64
6620 2``) and the sole argument of the callback function as the third one of the
6621 broker function (``i64 3``).
6623 .. FIXME why does the llvm-sphinx-docs builder give a highlighting
6624 error if the below is set to highlight as 'llvm', despite that we
6625 have misc.highlighting_failure set?
6627 .. code-block:: text
6629 declare !callback !1 dso_local i32 @pthread_create(ptr, ptr, ptr, ptr)
6632 !2 = !{i64 2, i64 3, i1 false}
6635 Another example is shown below. The callback callee is the second argument of
6636 the ``__kmpc_fork_call`` function (``i64 2``). The callee is given two unknown
6637 values (each identified by a ``i64 -1``) and afterwards all
6638 variadic arguments that are passed to the ``__kmpc_fork_call`` call (due to the
6641 .. FIXME why does the llvm-sphinx-docs builder give a highlighting
6642 error if the below is set to highlight as 'llvm', despite that we
6643 have misc.highlighting_failure set?
6645 .. code-block:: text
6647 declare !callback !0 dso_local void @__kmpc_fork_call(ptr, i32, ptr, ...)
6650 !1 = !{i64 2, i64 -1, i64 -1, i1 true}
6653 '``exclude``' Metadata
6654 ^^^^^^^^^^^^^^^^^^^^^^
6656 ``exclude`` metadata may be attached to a global variable to signify that its
6657 section should not be included in the final executable or shared library. This
6658 option is only valid for global variables with an explicit section targeting ELF
6659 or COFF. This is done using the ``SHF_EXCLUDE`` flag on ELF targets and the
6660 ``IMAGE_SCN_LNK_REMOVE`` and ``IMAGE_SCN_MEM_DISCARDABLE`` flags for COFF
6661 targets. Additionally, this metadata is only used as a flag, so the associated
6662 node must be empty. The explicit section should not conflict with any other
6663 sections that the user does not want removed after linking.
6665 .. code-block:: text
6667 @object = private constant [1 x i8] c"\00", section ".foo" !exclude !0
6672 '``unpredictable``' Metadata
6673 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6675 ``unpredictable`` metadata may be attached to any branch or switch
6676 instruction. It can be used to express the unpredictability of control
6677 flow. Similar to the llvm.expect intrinsic, it may be used to alter
6678 optimizations related to compare and branch instructions. The metadata
6679 is treated as a boolean value; if it exists, it signals that the branch
6680 or switch that it is attached to is completely unpredictable.
6682 .. _md_dereferenceable:
6684 '``dereferenceable``' Metadata
6685 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6687 The existence of the ``!dereferenceable`` metadata on the instruction
6688 tells the optimizer that the value loaded is known to be dereferenceable,
6689 otherwise the behavior is undefined.
6690 The number of bytes known to be dereferenceable is specified by the integer
6691 value in the metadata node. This is analogous to the ''dereferenceable''
6692 attribute on parameters and return values.
6694 .. _md_dereferenceable_or_null:
6696 '``dereferenceable_or_null``' Metadata
6697 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6699 The existence of the ``!dereferenceable_or_null`` metadata on the
6700 instruction tells the optimizer that the value loaded is known to be either
6701 dereferenceable or null, otherwise the behavior is undefined.
6702 The number of bytes known to be dereferenceable is specified by the integer
6703 value in the metadata node. This is analogous to the ''dereferenceable_or_null''
6704 attribute on parameters and return values.
6711 It is sometimes useful to attach information to loop constructs. Currently,
6712 loop metadata is implemented as metadata attached to the branch instruction
6713 in the loop latch block. The loop metadata node is a list of
6714 other metadata nodes, each representing a property of the loop. Usually,
6715 the first item of the property node is a string. For example, the
6716 ``llvm.loop.unroll.count`` suggests an unroll factor to the loop
6719 .. code-block:: llvm
6721 br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0
6724 !1 = !{!"llvm.loop.unroll.enable"}
6725 !2 = !{!"llvm.loop.unroll.count", i32 4}
6727 For legacy reasons, the first item of a loop metadata node must be a
6728 reference to itself. Before the advent of the 'distinct' keyword, this
6729 forced the preservation of otherwise identical metadata nodes. Since
6730 the loop-metadata node can be attached to multiple nodes, the 'distinct'
6731 keyword has become unnecessary.
6733 Prior to the property nodes, one or two ``DILocation`` (debug location)
6734 nodes can be present in the list. The first, if present, identifies the
6735 source-code location where the loop begins. The second, if present,
6736 identifies the source-code location where the loop ends.
6738 Loop metadata nodes cannot be used as unique identifiers. They are
6739 neither persistent for the same loop through transformations nor
6740 necessarily unique to just one loop.
6742 '``llvm.loop.disable_nonforced``'
6743 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6745 This metadata disables all optional loop transformations unless
6746 explicitly instructed using other transformation metadata such as
6747 ``llvm.loop.unroll.enable``. That is, no heuristic will try to determine
6748 whether a transformation is profitable. The purpose is to avoid that the
6749 loop is transformed to a different loop before an explicitly requested
6750 (forced) transformation is applied. For instance, loop fusion can make
6751 other transformations impossible. Mandatory loop canonicalizations such
6752 as loop rotation are still applied.
6754 It is recommended to use this metadata in addition to any llvm.loop.*
6755 transformation directive. Also, any loop should have at most one
6756 directive applied to it (and a sequence of transformations built using
6757 followup-attributes). Otherwise, which transformation will be applied
6758 depends on implementation details such as the pass pipeline order.
6760 See :ref:`transformation-metadata` for details.
6762 '``llvm.loop.vectorize``' and '``llvm.loop.interleave``'
6763 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6765 Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are
6766 used to control per-loop vectorization and interleaving parameters such as
6767 vectorization width and interleave count. These metadata should be used in
6768 conjunction with ``llvm.loop`` loop identification metadata. The
6769 ``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only
6770 optimization hints and the optimizer will only interleave and vectorize loops if
6771 it believes it is safe to do so. The ``llvm.loop.parallel_accesses`` metadata
6772 which contains information about loop-carried memory dependencies can be helpful
6773 in determining the safety of these transformations.
6775 '``llvm.loop.interleave.count``' Metadata
6776 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6778 This metadata suggests an interleave count to the loop interleaver.
6779 The first operand is the string ``llvm.loop.interleave.count`` and the
6780 second operand is an integer specifying the interleave count. For
6783 .. code-block:: llvm
6785 !0 = !{!"llvm.loop.interleave.count", i32 4}
6787 Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving
6788 multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0
6789 then the interleave count will be determined automatically.
6791 '``llvm.loop.vectorize.enable``' Metadata
6792 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6794 This metadata selectively enables or disables vectorization for the loop. The
6795 first operand is the string ``llvm.loop.vectorize.enable`` and the second operand
6796 is a bit. If the bit operand value is 1 vectorization is enabled. A value of
6797 0 disables vectorization:
6799 .. code-block:: llvm
6801 !0 = !{!"llvm.loop.vectorize.enable", i1 0}
6802 !1 = !{!"llvm.loop.vectorize.enable", i1 1}
6804 '``llvm.loop.vectorize.predicate.enable``' Metadata
6805 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6807 This metadata selectively enables or disables creating predicated instructions
6808 for the loop, which can enable folding of the scalar epilogue loop into the
6809 main loop. The first operand is the string
6810 ``llvm.loop.vectorize.predicate.enable`` and the second operand is a bit. If
6811 the bit operand value is 1 vectorization is enabled. A value of 0 disables
6814 .. code-block:: llvm
6816 !0 = !{!"llvm.loop.vectorize.predicate.enable", i1 0}
6817 !1 = !{!"llvm.loop.vectorize.predicate.enable", i1 1}
6819 '``llvm.loop.vectorize.scalable.enable``' Metadata
6820 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6822 This metadata selectively enables or disables scalable vectorization for the
6823 loop, and only has any effect if vectorization for the loop is already enabled.
6824 The first operand is the string ``llvm.loop.vectorize.scalable.enable``
6825 and the second operand is a bit. If the bit operand value is 1 scalable
6826 vectorization is enabled, whereas a value of 0 reverts to the default fixed
6827 width vectorization:
6829 .. code-block:: llvm
6831 !0 = !{!"llvm.loop.vectorize.scalable.enable", i1 0}
6832 !1 = !{!"llvm.loop.vectorize.scalable.enable", i1 1}
6834 '``llvm.loop.vectorize.width``' Metadata
6835 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6837 This metadata sets the target width of the vectorizer. The first
6838 operand is the string ``llvm.loop.vectorize.width`` and the second
6839 operand is an integer specifying the width. For example:
6841 .. code-block:: llvm
6843 !0 = !{!"llvm.loop.vectorize.width", i32 4}
6845 Note that setting ``llvm.loop.vectorize.width`` to 1 disables
6846 vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to
6847 0 or if the loop does not have this metadata the width will be
6848 determined automatically.
6850 '``llvm.loop.vectorize.followup_vectorized``' Metadata
6851 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6853 This metadata defines which loop attributes the vectorized loop will
6854 have. See :ref:`transformation-metadata` for details.
6856 '``llvm.loop.vectorize.followup_epilogue``' Metadata
6857 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6859 This metadata defines which loop attributes the epilogue will have. The
6860 epilogue is not vectorized and is executed when either the vectorized
6861 loop is not known to preserve semantics (because e.g., it processes two
6862 arrays that are found to alias by a runtime check) or for the last
6863 iterations that do not fill a complete set of vector lanes. See
6864 :ref:`Transformation Metadata <transformation-metadata>` for details.
6866 '``llvm.loop.vectorize.followup_all``' Metadata
6867 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6869 Attributes in the metadata will be added to both the vectorized and
6871 See :ref:`Transformation Metadata <transformation-metadata>` for details.
6873 '``llvm.loop.unroll``'
6874 ^^^^^^^^^^^^^^^^^^^^^^
6876 Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling
6877 optimization hints such as the unroll factor. ``llvm.loop.unroll``
6878 metadata should be used in conjunction with ``llvm.loop`` loop
6879 identification metadata. The ``llvm.loop.unroll`` metadata are only
6880 optimization hints and the unrolling will only be performed if the
6881 optimizer believes it is safe to do so.
6883 '``llvm.loop.unroll.count``' Metadata
6884 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6886 This metadata suggests an unroll factor to the loop unroller. The
6887 first operand is the string ``llvm.loop.unroll.count`` and the second
6888 operand is a positive integer specifying the unroll factor. For
6891 .. code-block:: llvm
6893 !0 = !{!"llvm.loop.unroll.count", i32 4}
6895 If the trip count of the loop is less than the unroll count the loop
6896 will be partially unrolled.
6898 '``llvm.loop.unroll.disable``' Metadata
6899 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6901 This metadata disables loop unrolling. The metadata has a single operand
6902 which is the string ``llvm.loop.unroll.disable``. For example:
6904 .. code-block:: llvm
6906 !0 = !{!"llvm.loop.unroll.disable"}
6908 '``llvm.loop.unroll.runtime.disable``' Metadata
6909 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6911 This metadata disables runtime loop unrolling. The metadata has a single
6912 operand which is the string ``llvm.loop.unroll.runtime.disable``. For example:
6914 .. code-block:: llvm
6916 !0 = !{!"llvm.loop.unroll.runtime.disable"}
6918 '``llvm.loop.unroll.enable``' Metadata
6919 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6921 This metadata suggests that the loop should be fully unrolled if the trip count
6922 is known at compile time and partially unrolled if the trip count is not known
6923 at compile time. The metadata has a single operand which is the string
6924 ``llvm.loop.unroll.enable``. For example:
6926 .. code-block:: llvm
6928 !0 = !{!"llvm.loop.unroll.enable"}
6930 '``llvm.loop.unroll.full``' Metadata
6931 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6933 This metadata suggests that the loop should be unrolled fully. The
6934 metadata has a single operand which is the string ``llvm.loop.unroll.full``.
6937 .. code-block:: llvm
6939 !0 = !{!"llvm.loop.unroll.full"}
6941 '``llvm.loop.unroll.followup``' Metadata
6942 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6944 This metadata defines which loop attributes the unrolled loop will have.
6945 See :ref:`Transformation Metadata <transformation-metadata>` for details.
6947 '``llvm.loop.unroll.followup_remainder``' Metadata
6948 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6950 This metadata defines which loop attributes the remainder loop after
6951 partial/runtime unrolling will have. See
6952 :ref:`Transformation Metadata <transformation-metadata>` for details.
6954 '``llvm.loop.unroll_and_jam``'
6955 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6957 This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata
6958 above, but affect the unroll and jam pass. In addition any loop with
6959 ``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will
6960 disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the
6961 unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam
6964 The metadata for unroll and jam otherwise is the same as for ``unroll``.
6965 ``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and
6966 ``llvm.loop.unroll_and_jam.count`` do the same as for unroll.
6967 ``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints
6968 and the normal safety checks will still be performed.
6970 '``llvm.loop.unroll_and_jam.count``' Metadata
6971 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6973 This metadata suggests an unroll and jam factor to use, similarly to
6974 ``llvm.loop.unroll.count``. The first operand is the string
6975 ``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer
6976 specifying the unroll factor. For example:
6978 .. code-block:: llvm
6980 !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4}
6982 If the trip count of the loop is less than the unroll count the loop
6983 will be partially unroll and jammed.
6985 '``llvm.loop.unroll_and_jam.disable``' Metadata
6986 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6988 This metadata disables loop unroll and jamming. The metadata has a single
6989 operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example:
6991 .. code-block:: llvm
6993 !0 = !{!"llvm.loop.unroll_and_jam.disable"}
6995 '``llvm.loop.unroll_and_jam.enable``' Metadata
6996 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6998 This metadata suggests that the loop should be fully unroll and jammed if the
6999 trip count is known at compile time and partially unrolled if the trip count is
7000 not known at compile time. The metadata has a single operand which is the
7001 string ``llvm.loop.unroll_and_jam.enable``. For example:
7003 .. code-block:: llvm
7005 !0 = !{!"llvm.loop.unroll_and_jam.enable"}
7007 '``llvm.loop.unroll_and_jam.followup_outer``' Metadata
7008 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7010 This metadata defines which loop attributes the outer unrolled loop will
7011 have. See :ref:`Transformation Metadata <transformation-metadata>` for
7014 '``llvm.loop.unroll_and_jam.followup_inner``' Metadata
7015 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7017 This metadata defines which loop attributes the inner jammed loop will
7018 have. See :ref:`Transformation Metadata <transformation-metadata>` for
7021 '``llvm.loop.unroll_and_jam.followup_remainder_outer``' Metadata
7022 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7024 This metadata defines which attributes the epilogue of the outer loop
7025 will have. This loop is usually unrolled, meaning there is no such
7026 loop. This attribute will be ignored in this case. See
7027 :ref:`Transformation Metadata <transformation-metadata>` for details.
7029 '``llvm.loop.unroll_and_jam.followup_remainder_inner``' Metadata
7030 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7032 This metadata defines which attributes the inner loop of the epilogue
7033 will have. The outer epilogue will usually be unrolled, meaning there
7034 can be multiple inner remainder loops. See
7035 :ref:`Transformation Metadata <transformation-metadata>` for details.
7037 '``llvm.loop.unroll_and_jam.followup_all``' Metadata
7038 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7040 Attributes specified in the metadata is added to all
7041 ``llvm.loop.unroll_and_jam.*`` loops. See
7042 :ref:`Transformation Metadata <transformation-metadata>` for details.
7044 '``llvm.loop.licm_versioning.disable``' Metadata
7045 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7047 This metadata indicates that the loop should not be versioned for the purpose
7048 of enabling loop-invariant code motion (LICM). The metadata has a single operand
7049 which is the string ``llvm.loop.licm_versioning.disable``. For example:
7051 .. code-block:: llvm
7053 !0 = !{!"llvm.loop.licm_versioning.disable"}
7055 '``llvm.loop.distribute.enable``' Metadata
7056 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7058 Loop distribution allows splitting a loop into multiple loops. Currently,
7059 this is only performed if the entire loop cannot be vectorized due to unsafe
7060 memory dependencies. The transformation will attempt to isolate the unsafe
7061 dependencies into their own loop.
7063 This metadata can be used to selectively enable or disable distribution of the
7064 loop. The first operand is the string ``llvm.loop.distribute.enable`` and the
7065 second operand is a bit. If the bit operand value is 1 distribution is
7066 enabled. A value of 0 disables distribution:
7068 .. code-block:: llvm
7070 !0 = !{!"llvm.loop.distribute.enable", i1 0}
7071 !1 = !{!"llvm.loop.distribute.enable", i1 1}
7073 This metadata should be used in conjunction with ``llvm.loop`` loop
7074 identification metadata.
7076 '``llvm.loop.distribute.followup_coincident``' Metadata
7077 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7079 This metadata defines which attributes extracted loops with no cyclic
7080 dependencies will have (i.e. can be vectorized). See
7081 :ref:`Transformation Metadata <transformation-metadata>` for details.
7083 '``llvm.loop.distribute.followup_sequential``' Metadata
7084 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7086 This metadata defines which attributes the isolated loops with unsafe
7087 memory dependencies will have. See
7088 :ref:`Transformation Metadata <transformation-metadata>` for details.
7090 '``llvm.loop.distribute.followup_fallback``' Metadata
7091 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7093 If loop versioning is necessary, this metadata defined the attributes
7094 the non-distributed fallback version will have. See
7095 :ref:`Transformation Metadata <transformation-metadata>` for details.
7097 '``llvm.loop.distribute.followup_all``' Metadata
7098 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7100 The attributes in this metadata is added to all followup loops of the
7101 loop distribution pass. See
7102 :ref:`Transformation Metadata <transformation-metadata>` for details.
7104 '``llvm.licm.disable``' Metadata
7105 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7107 This metadata indicates that loop-invariant code motion (LICM) should not be
7108 performed on this loop. The metadata has a single operand which is the string
7109 ``llvm.licm.disable``. For example:
7111 .. code-block:: llvm
7113 !0 = !{!"llvm.licm.disable"}
7115 Note that although it operates per loop it isn't given the llvm.loop prefix
7116 as it is not affected by the ``llvm.loop.disable_nonforced`` metadata.
7118 '``llvm.access.group``' Metadata
7119 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7121 ``llvm.access.group`` metadata can be attached to any instruction that
7122 potentially accesses memory. It can point to a single distinct metadata
7123 node, which we call access group. This node represents all memory access
7124 instructions referring to it via ``llvm.access.group``. When an
7125 instruction belongs to multiple access groups, it can also point to a
7126 list of accesses groups, illustrated by the following example.
7128 .. code-block:: llvm
7130 %val = load i32, ptr %arrayidx, !llvm.access.group !0
7136 It is illegal for the list node to be empty since it might be confused
7137 with an access group.
7139 The access group metadata node must be 'distinct' to avoid collapsing
7140 multiple access groups by content. A access group metadata node must
7141 always be empty which can be used to distinguish an access group
7142 metadata node from a list of access groups. Being empty avoids the
7143 situation that the content must be updated which, because metadata is
7144 immutable by design, would required finding and updating all references
7145 to the access group node.
7147 The access group can be used to refer to a memory access instruction
7148 without pointing to it directly (which is not possible in global
7149 metadata). Currently, the only metadata making use of it is
7150 ``llvm.loop.parallel_accesses``.
7152 '``llvm.loop.parallel_accesses``' Metadata
7153 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7155 The ``llvm.loop.parallel_accesses`` metadata refers to one or more
7156 access group metadata nodes (see ``llvm.access.group``). It denotes that
7157 no loop-carried memory dependence exist between it and other instructions
7158 in the loop with this metadata.
7160 Let ``m1`` and ``m2`` be two instructions that both have the
7161 ``llvm.access.group`` metadata to the access group ``g1``, respectively
7162 ``g2`` (which might be identical). If a loop contains both access groups
7163 in its ``llvm.loop.parallel_accesses`` metadata, then the compiler can
7164 assume that there is no dependency between ``m1`` and ``m2`` carried by
7165 this loop. Instructions that belong to multiple access groups are
7166 considered having this property if at least one of the access groups
7167 matches the ``llvm.loop.parallel_accesses`` list.
7169 If all memory-accessing instructions in a loop have
7170 ``llvm.access.group`` metadata that each refer to one of the access
7171 groups of a loop's ``llvm.loop.parallel_accesses`` metadata, then the
7172 loop has no loop carried memory dependences and is considered to be a
7175 Note that if not all memory access instructions belong to an access
7176 group referred to by ``llvm.loop.parallel_accesses``, then the loop must
7177 not be considered trivially parallel. Additional
7178 memory dependence analysis is required to make that determination. As a fail
7179 safe mechanism, this causes loops that were originally parallel to be considered
7180 sequential (if optimization passes that are unaware of the parallel semantics
7181 insert new memory instructions into the loop body).
7183 Example of a loop that is considered parallel due to its correct use of
7184 both ``llvm.access.group`` and ``llvm.loop.parallel_accesses``
7187 .. code-block:: llvm
7191 %val0 = load i32, ptr %arrayidx, !llvm.access.group !1
7193 store i32 %val0, ptr %arrayidx1, !llvm.access.group !1
7195 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
7199 !0 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !1}}
7202 It is also possible to have nested parallel loops:
7204 .. code-block:: llvm
7208 %val1 = load i32, ptr %arrayidx3, !llvm.access.group !4
7210 br label %inner.for.body
7214 %val0 = load i32, ptr %arrayidx1, !llvm.access.group !3
7216 store i32 %val0, ptr %arrayidx2, !llvm.access.group !3
7218 br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1
7222 store i32 %val1, ptr %arrayidx4, !llvm.access.group !4
7224 br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2
7226 outer.for.end: ; preds = %for.body
7228 !1 = distinct !{!1, !{!"llvm.loop.parallel_accesses", !3}} ; metadata for the inner loop
7229 !2 = distinct !{!2, !{!"llvm.loop.parallel_accesses", !3, !4}} ; metadata for the outer loop
7230 !3 = distinct !{} ; access group for instructions in the inner loop (which are implicitly contained in outer loop as well)
7231 !4 = distinct !{} ; access group for instructions in the outer, but not the inner loop
7233 .. _langref_llvm_loop_mustprogress:
7235 '``llvm.loop.mustprogress``' Metadata
7236 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7238 The ``llvm.loop.mustprogress`` metadata indicates that this loop is required to
7239 terminate, unwind, or interact with the environment in an observable way e.g.
7240 via a volatile memory access, I/O, or other synchronization. If such a loop is
7241 not found to interact with the environment in an observable way, the loop may
7242 be removed. This corresponds to the ``mustprogress`` function attribute.
7244 '``irr_loop``' Metadata
7245 ^^^^^^^^^^^^^^^^^^^^^^^
7247 ``irr_loop`` metadata may be attached to the terminator instruction of a basic
7248 block that's an irreducible loop header (note that an irreducible loop has more
7249 than once header basic blocks.) If ``irr_loop`` metadata is attached to the
7250 terminator instruction of a basic block that is not really an irreducible loop
7251 header, the behavior is undefined. The intent of this metadata is to improve the
7252 accuracy of the block frequency propagation. For example, in the code below, the
7253 block ``header0`` may have a loop header weight (relative to the other headers of
7254 the irreducible loop) of 100:
7256 .. code-block:: llvm
7260 br i1 %cmp, label %t1, label %t2, !irr_loop !0
7263 !0 = !{"loop_header_weight", i64 100}
7265 Irreducible loop header weights are typically based on profile data.
7267 .. _md_invariant.group:
7269 '``invariant.group``' Metadata
7270 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7272 The experimental ``invariant.group`` metadata may be attached to
7273 ``load``/``store`` instructions referencing a single metadata with no entries.
7274 The existence of the ``invariant.group`` metadata on the instruction tells
7275 the optimizer that every ``load`` and ``store`` to the same pointer operand
7276 can be assumed to load or store the same
7277 value (but see the ``llvm.launder.invariant.group`` intrinsic which affects
7278 when two pointers are considered the same). Pointers returned by bitcast or
7279 getelementptr with only zero indices are considered the same.
7283 .. code-block:: llvm
7285 @unknownPtr = external global i8
7288 store i8 42, ptr %ptr, !invariant.group !0
7289 call void @foo(ptr %ptr)
7291 %a = load i8, ptr %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change
7292 call void @foo(ptr %ptr)
7294 %newPtr = call ptr @getPointer(ptr %ptr)
7295 %c = load i8, ptr %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr
7297 %unknownValue = load i8, ptr @unknownPtr
7298 store i8 %unknownValue, ptr %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42
7300 call void @foo(ptr %ptr)
7301 %newPtr2 = call ptr @llvm.launder.invariant.group.p0(ptr %ptr)
7302 %d = load i8, ptr %newPtr2, !invariant.group !0 ; Can't step through launder.invariant.group to get value of %ptr
7305 declare void @foo(ptr)
7306 declare ptr @getPointer(ptr)
7307 declare ptr @llvm.launder.invariant.group.p0(ptr)
7311 The invariant.group metadata must be dropped when replacing one pointer by
7312 another based on aliasing information. This is because invariant.group is tied
7313 to the SSA value of the pointer operand.
7315 .. code-block:: llvm
7317 %v = load i8, ptr %x, !invariant.group !0
7318 ; if %x mustalias %y then we can replace the above instruction with
7319 %v = load i8, ptr %y
7321 Note that this is an experimental feature, which means that its semantics might
7322 change in the future.
7327 See :doc:`TypeMetadata`.
7329 '``associated``' Metadata
7330 ^^^^^^^^^^^^^^^^^^^^^^^^^
7332 The ``associated`` metadata may be attached to a global variable definition with
7333 a single argument that references a global object (optionally through an alias).
7335 This metadata lowers to the ELF section flag ``SHF_LINK_ORDER`` which prevents
7336 discarding of the global variable in linker GC unless the referenced object is
7337 also discarded. The linker support for this feature is spotty. For best
7338 compatibility, globals carrying this metadata should:
7340 - Be in ``@llvm.compiler.used``.
7341 - If the referenced global variable is in a comdat, be in the same comdat.
7343 ``!associated`` can not express many-to-one relationship. A global variable with
7344 the metadata should generally not be referenced by a function: the function may
7345 be inlined into other functions, leading to more references to the metadata.
7346 Ideally we would want to keep metadata alive as long as any inline location is
7347 alive, but this many-to-one relationship is not representable. Moreover, if the
7348 metadata is retained while the function is discarded, the linker will report an
7349 error of a relocation referencing a discarded section.
7351 The metadata is often used with an explicit section consisting of valid C
7352 identifiers so that the runtime can find the metadata section with
7353 linker-defined encapsulation symbols ``__start_<section_name>`` and
7354 ``__stop_<section_name>``.
7356 It does not have any effect on non-ELF targets.
7360 .. code-block:: text
7363 @a = global i32 1, comdat $a
7364 @b = internal global i32 2, comdat $a, section "abc", !associated !0
7371 The ``prof`` metadata is used to record profile data in the IR.
7372 The first operand of the metadata node indicates the profile metadata
7373 type. There are currently 3 types:
7374 :ref:`branch_weights<prof_node_branch_weights>`,
7375 :ref:`function_entry_count<prof_node_function_entry_count>`, and
7376 :ref:`VP<prof_node_VP>`.
7378 .. _prof_node_branch_weights:
7383 Branch weight metadata attached to a branch, select, switch or call instruction
7384 represents the likeliness of the associated branch being taken.
7385 For more information, see :doc:`BranchWeightMetadata`.
7387 .. _prof_node_function_entry_count:
7389 function_entry_count
7390 """"""""""""""""""""
7392 Function entry count metadata can be attached to function definitions
7393 to record the number of times the function is called. Used with BFI
7394 information, it is also used to derive the basic block profile count.
7395 For more information, see :doc:`BranchWeightMetadata`.
7402 VP (value profile) metadata can be attached to instructions that have
7403 value profile information. Currently this is indirect calls (where it
7404 records the hottest callees) and calls to memory intrinsics such as memcpy,
7405 memmove, and memset (where it records the hottest byte lengths).
7407 Each VP metadata node contains "VP" string, then a uint32_t value for the value
7408 profiling kind, a uint64_t value for the total number of times the instruction
7409 is executed, followed by uint64_t value and execution count pairs.
7410 The value profiling kind is 0 for indirect call targets and 1 for memory
7411 operations. For indirect call targets, each profile value is a hash
7412 of the callee function name, and for memory operations each value is the
7415 Note that the value counts do not need to add up to the total count
7416 listed in the third operand (in practice only the top hottest values
7417 are tracked and reported).
7419 Indirect call example:
7421 .. code-block:: llvm
7423 call void %f(), !prof !1
7424 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410}
7426 Note that the VP type is 0 (the second operand), which indicates this is
7427 an indirect call value profile data. The third operand indicates that the
7428 indirect call executed 1600 times. The 4th and 6th operands give the
7429 hashes of the 2 hottest target functions' names (this is the same hash used
7430 to represent function names in the profile database), and the 5th and 7th
7431 operands give the execution count that each of the respective prior target
7432 functions was called.
7436 '``annotation``' Metadata
7437 ^^^^^^^^^^^^^^^^^^^^^^^^^
7439 The ``annotation`` metadata can be used to attach a tuple of annotation strings
7440 or a tuple of a tuple of annotation strings to any instruction. This metadata does
7441 not impact the semantics of the program and may only be used to provide additional
7442 insight about the program and transformations to users.
7446 .. code-block:: text
7448 %a.addr = alloca ptr, align 8, !annotation !0
7449 !0 = !{!"auto-init"}
7451 Embedding tuple of strings example:
7453 .. code-block:: text
7455 %a.ptr = getelementptr ptr, ptr %base, i64 0. !annotation !0
7457 !1 = !{!"gep offset", !"0"}
7459 '``func_sanitize``' Metadata
7460 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7462 The ``func_sanitize`` metadata is used to attach two values for the function
7463 sanitizer instrumentation. The first value is the ubsan function signature.
7464 The second value is the address of the proxy variable which stores the address
7465 of the RTTI descriptor. If :ref:`prologue <prologuedata>` and '``func_sanitize``'
7466 are used at the same time, :ref:`prologue <prologuedata>` is emitted before
7467 '``func_sanitize``' in the output.
7471 .. code-block:: text
7473 @__llvm_rtti_proxy = private unnamed_addr constant ptr @_ZTIFvvE
7474 define void @_Z3funv() !func_sanitize !0 {
7477 !0 = !{i32 846595819, ptr @__llvm_rtti_proxy}
7481 '``kcfi_type``' Metadata
7482 ^^^^^^^^^^^^^^^^^^^^^^^^
7484 The ``kcfi_type`` metadata can be used to attach a type identifier to
7485 functions that can be called indirectly. The type data is emitted before the
7486 function entry in the assembly. Indirect calls with the :ref:`kcfi operand
7487 bundle<ob_kcfi>` will emit a check that compares the type identifier to the
7492 .. code-block:: text
7494 define dso_local i32 @f() !kcfi_type !0 {
7497 !0 = !{i32 12345678}
7499 Clang emits ``kcfi_type`` metadata nodes for address-taken functions with
7500 ``-fsanitize=kcfi``.
7504 '``memprof``' Metadata
7505 ^^^^^^^^^^^^^^^^^^^^^^^^
7507 The ``memprof`` metadata is used to record memory profile data on heap
7508 allocation calls. Multiple context-sensitive profiles can be represented
7509 with a single ``memprof`` metadata attachment.
7513 .. code-block:: text
7515 %call = call ptr @_Znam(i64 10), !memprof !0, !callsite !5
7518 !2 = !{i64 4854880825882961848, i64 1905834578520680781}
7519 !3 = !{!4, !"notcold"}
7520 !4 = !{i64 4854880825882961848, i64 -6528110295079665978}
7521 !5 = !{i64 4854880825882961848}
7523 Each operand in the ``memprof`` metadata attachment describes the profiled
7524 behavior of memory allocated by the associated allocation for a given context.
7525 In the above example, there were 2 profiled contexts, one allocating memory
7526 that was typically cold and one allocating memory that was typically not cold.
7528 The format of the metadata describing a context specific profile (e.g.
7529 ``!1`` and ``!3`` above) requires a first operand that is a metadata node
7530 describing the context, followed by a list of string metadata tags describing
7531 the profile behavior (e.g. ``cold`` and ``notcold``) above. The metadata nodes
7532 describing the context (e.g. ``!2`` and ``!4`` above) are unique ids
7533 corresponding to callsites, which can be matched to associated IR calls via
7534 :ref:`callsite metadata<md_callsite>`. In practice these ids are formed via
7535 a hash of the callsite's debug info, and the associated call may be in a
7536 different module. The contexts are listed in order from leaf-most call (the
7537 allocation itself) to the outermost callsite context required for uniquely
7538 identifying the described profile behavior (note this may not be the top of
7539 the profiled call stack).
7543 '``callsite``' Metadata
7544 ^^^^^^^^^^^^^^^^^^^^^^^^
7546 The ``callsite`` metadata is used to identify callsites involved in memory
7547 profile contexts described in :ref:`memprof metadata<md_memprof>`.
7549 It is attached both to the profile allocation calls (see the example in
7550 :ref:`memprof metadata<md_memprof>`), as well as to other callsites
7551 in profiled contexts described in heap allocation ``memprof`` metadata.
7555 .. code-block:: text
7557 %call = call ptr @_Z1Bb(void), !callsite !0
7558 !0 = !{i64 -6528110295079665978, i64 5462047985461644151}
7560 Each operand in the ``callsite`` metadata attachment is a unique id
7561 corresponding to a callsite (possibly inlined). In practice these ids are
7562 formed via a hash of the callsite's debug info. If the call was not inlined
7563 into any callers it will contain a single operand (id). If it was inlined
7564 it will contain a list of ids, including the ids of the callsites in the
7565 full inline sequence, in order from the leaf-most call's id to the outermost
7568 Module Flags Metadata
7569 =====================
7571 Information about the module as a whole is difficult to convey to LLVM's
7572 subsystems. The LLVM IR isn't sufficient to transmit this information.
7573 The ``llvm.module.flags`` named metadata exists in order to facilitate
7574 this. These flags are in the form of key / value pairs --- much like a
7575 dictionary --- making it easy for any subsystem who cares about a flag to
7578 The ``llvm.module.flags`` metadata contains a list of metadata triplets.
7579 Each triplet has the following form:
7581 - The first element is a *behavior* flag, which specifies the behavior
7582 when two (or more) modules are merged together, and it encounters two
7583 (or more) metadata with the same ID. The supported behaviors are
7585 - The second element is a metadata string that is a unique ID for the
7586 metadata. Each module may only have one flag entry for each unique ID (not
7587 including entries with the **Require** behavior).
7588 - The third element is the value of the flag.
7590 When two (or more) modules are merged together, the resulting
7591 ``llvm.module.flags`` metadata is the union of the modules' flags. That is, for
7592 each unique metadata ID string, there will be exactly one entry in the merged
7593 modules ``llvm.module.flags`` metadata table, and the value for that entry will
7594 be determined by the merge behavior flag, as described below. The only exception
7595 is that entries with the *Require* behavior are always preserved.
7597 The following behaviors are supported:
7608 Emits an error if two values disagree, otherwise the resulting value
7609 is that of the operands.
7613 Emits a warning if two values disagree. The result value will be the
7614 operand for the flag from the first module being linked, or the max
7615 if the other module uses **Max** (in which case the resulting flag
7620 Adds a requirement that another module flag be present and have a
7621 specified value after linking is performed. The value must be a
7622 metadata pair, where the first element of the pair is the ID of the
7623 module flag to be restricted, and the second element of the pair is
7624 the value the module flag should be restricted to. This behavior can
7625 be used to restrict the allowable results (via triggering of an
7626 error) of linking IDs with the **Override** behavior.
7630 Uses the specified value, regardless of the behavior or value of the
7631 other module. If both modules specify **Override**, but the values
7632 differ, an error will be emitted.
7636 Appends the two values, which are required to be metadata nodes.
7640 Appends the two values, which are required to be metadata
7641 nodes. However, duplicate entries in the second list are dropped
7642 during the append operation.
7646 Takes the max of the two values, which are required to be integers.
7650 Takes the min of the two values, which are required to be non-negative integers.
7651 An absent module flag is treated as having the value 0.
7653 It is an error for a particular unique flag ID to have multiple behaviors,
7654 except in the case of **Require** (which adds restrictions on another metadata
7655 value) or **Override**.
7657 An example of module flags:
7659 .. code-block:: llvm
7661 !0 = !{ i32 1, !"foo", i32 1 }
7662 !1 = !{ i32 4, !"bar", i32 37 }
7663 !2 = !{ i32 2, !"qux", i32 42 }
7664 !3 = !{ i32 3, !"qux",
7669 !llvm.module.flags = !{ !0, !1, !2, !3 }
7671 - Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior
7672 if two or more ``!"foo"`` flags are seen is to emit an error if their
7673 values are not equal.
7675 - Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The
7676 behavior if two or more ``!"bar"`` flags are seen is to use the value
7679 - Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The
7680 behavior if two or more ``!"qux"`` flags are seen is to emit a
7681 warning if their values are not equal.
7683 - Metadata ``!3`` has the ID ``!"qux"`` and the value:
7689 The behavior is to emit an error if the ``llvm.module.flags`` does not
7690 contain a flag with the ID ``!"foo"`` that has the value '1' after linking is
7693 Synthesized Functions Module Flags Metadata
7694 -------------------------------------------
7696 These metadata specify the default attributes synthesized functions should have.
7697 These metadata are currently respected by a few instrumentation passes, such as
7700 These metadata correspond to a few function attributes with significant code
7701 generation behaviors. Function attributes with just optimization purposes
7702 should not be listed because the performance impact of these synthesized
7705 - "frame-pointer": **Max**. The value can be 0, 1, or 2. A synthesized function
7706 will get the "frame-pointer" function attribute, with value being "none",
7707 "non-leaf", or "all", respectively.
7708 - "function_return_thunk_extern": The synthesized function will get the
7709 ``fn_return_thunk_extern`` function attribute.
7710 - "uwtable": **Max**. The value can be 0, 1, or 2. If the value is 1, a synthesized
7711 function will get the ``uwtable(sync)`` function attribute, if the value is 2,
7712 a synthesized function will get the ``uwtable(async)`` function attribute.
7714 Objective-C Garbage Collection Module Flags Metadata
7715 ----------------------------------------------------
7717 On the Mach-O platform, Objective-C stores metadata about garbage
7718 collection in a special section called "image info". The metadata
7719 consists of a version number and a bitmask specifying what types of
7720 garbage collection are supported (if any) by the file. If two or more
7721 modules are linked together their garbage collection metadata needs to
7722 be merged rather than appended together.
7724 The Objective-C garbage collection module flags metadata consists of the
7725 following key-value pairs:
7734 * - ``Objective-C Version``
7735 - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2.
7737 * - ``Objective-C Image Info Version``
7738 - **[Required]** --- The version of the image info section. Currently
7741 * - ``Objective-C Image Info Section``
7742 - **[Required]** --- The section to place the metadata. Valid values are
7743 ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and
7744 ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for
7745 Objective-C ABI version 2.
7747 * - ``Objective-C Garbage Collection``
7748 - **[Required]** --- Specifies whether garbage collection is supported or
7749 not. Valid values are 0, for no garbage collection, and 2, for garbage
7750 collection supported.
7752 * - ``Objective-C GC Only``
7753 - **[Optional]** --- Specifies that only garbage collection is supported.
7754 If present, its value must be 6. This flag requires that the
7755 ``Objective-C Garbage Collection`` flag have the value 2.
7757 Some important flag interactions:
7759 - If a module with ``Objective-C Garbage Collection`` set to 0 is
7760 merged with a module with ``Objective-C Garbage Collection`` set to
7761 2, then the resulting module has the
7762 ``Objective-C Garbage Collection`` flag set to 0.
7763 - A module with ``Objective-C Garbage Collection`` set to 0 cannot be
7764 merged with a module with ``Objective-C GC Only`` set to 6.
7766 C type width Module Flags Metadata
7767 ----------------------------------
7769 The ARM backend emits a section into each generated object file describing the
7770 options that it was compiled with (in a compiler-independent way) to prevent
7771 linking incompatible objects, and to allow automatic library selection. Some
7772 of these options are not visible at the IR level, namely wchar_t width and enum
7775 To pass this information to the backend, these options are encoded in module
7776 flags metadata, using the following key-value pairs:
7786 - * 0 --- sizeof(wchar_t) == 4
7787 * 1 --- sizeof(wchar_t) == 2
7790 - * 0 --- Enums are at least as large as an ``int``.
7791 * 1 --- Enums are stored in the smallest integer type which can
7792 represent all of its values.
7794 For example, the following metadata section specifies that the module was
7795 compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an
7796 enum is the smallest type which can represent all of its values::
7798 !llvm.module.flags = !{!0, !1}
7799 !0 = !{i32 1, !"short_wchar", i32 1}
7800 !1 = !{i32 1, !"short_enum", i32 0}
7802 LTO Post-Link Module Flags Metadata
7803 -----------------------------------
7805 Some optimisations are only when the entire LTO unit is present in the current
7806 module. This is represented by the ``LTOPostLink`` module flags metadata, which
7807 will be created with a value of ``1`` when LTO linking occurs.
7809 Embedded Objects Names Metadata
7810 ===============================
7812 Offloading compilations need to embed device code into the host section table to
7813 create a fat binary. This metadata node references each global that will be
7814 embedded in the module. The primary use for this is to make referencing these
7815 globals more efficient in the IR. The metadata references nodes containing
7816 pointers to the global to be embedded followed by the section name it will be
7819 !llvm.embedded.objects = !{!0}
7820 !0 = !{ptr @object, !".section"}
7822 Automatic Linker Flags Named Metadata
7823 =====================================
7825 Some targets support embedding of flags to the linker inside individual object
7826 files. Typically this is used in conjunction with language extensions which
7827 allow source files to contain linker command line options, and have these
7828 automatically be transmitted to the linker via object files.
7830 These flags are encoded in the IR using named metadata with the name
7831 ``!llvm.linker.options``. Each operand is expected to be a metadata node
7832 which should be a list of other metadata nodes, each of which should be a
7833 list of metadata strings defining linker options.
7835 For example, the following metadata section specifies two separate sets of
7836 linker options, presumably to link against ``libz`` and the ``Cocoa``
7840 !1 = !{ !"-framework", !"Cocoa" }
7841 !llvm.linker.options = !{ !0, !1 }
7843 The metadata encoding as lists of lists of options, as opposed to a collapsed
7844 list of options, is chosen so that the IR encoding can use multiple option
7845 strings to specify e.g., a single library, while still having that specifier be
7846 preserved as an atomic element that can be recognized by a target specific
7847 assembly writer or object file emitter.
7849 Each individual option is required to be either a valid option for the target's
7850 linker, or an option that is reserved by the target specific assembly writer or
7851 object file emitter. No other aspect of these options is defined by the IR.
7853 Dependent Libs Named Metadata
7854 =============================
7856 Some targets support embedding of strings into object files to indicate
7857 a set of libraries to add to the link. Typically this is used in conjunction
7858 with language extensions which allow source files to explicitly declare the
7859 libraries they depend on, and have these automatically be transmitted to the
7860 linker via object files.
7862 The list is encoded in the IR using named metadata with the name
7863 ``!llvm.dependent-libraries``. Each operand is expected to be a metadata node
7864 which should contain a single string operand.
7866 For example, the following metadata section contains two library specifiers::
7868 !0 = !{!"a library specifier"}
7869 !1 = !{!"another library specifier"}
7870 !llvm.dependent-libraries = !{ !0, !1 }
7872 Each library specifier will be handled independently by the consuming linker.
7873 The effect of the library specifiers are defined by the consuming linker.
7880 Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_
7881 causes the building of a compact summary of the module that is emitted into
7882 the bitcode. The summary is emitted into the LLVM assembly and identified
7883 in syntax by a caret ('``^``').
7885 The summary is parsed into a bitcode output, along with the Module
7886 IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes
7887 of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the
7888 summary entries (just as they currently ignore summary entries in a bitcode
7891 Eventually, the summary will be parsed into a ModuleSummaryIndex object under
7892 the same conditions where summary index is currently built from bitcode.
7893 Specifically, tools that test the Thin Link portion of a ThinLTO compile
7894 (i.e. llvm-lto and llvm-lto2), or when parsing a combined index
7895 for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag
7896 (this part is not yet implemented, use llvm-as to create a bitcode object
7897 before feeding into thin link tools for now).
7899 There are currently 3 types of summary entries in the LLVM assembly:
7900 :ref:`module paths<module_path_summary>`,
7901 :ref:`global values<gv_summary>`, and
7902 :ref:`type identifiers<typeid_summary>`.
7904 .. _module_path_summary:
7906 Module Path Summary Entry
7907 -------------------------
7909 Each module path summary entry lists a module containing global values included
7910 in the summary. For a single IR module there will be one such entry, but
7911 in a combined summary index produced during the thin link, there will be
7912 one module path entry per linked module with summary.
7916 .. code-block:: text
7918 ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418))
7920 The ``path`` field is a string path to the bitcode file, and the ``hash``
7921 field is the 160-bit SHA-1 hash of the IR bitcode contents, used for
7922 incremental builds and caching.
7926 Global Value Summary Entry
7927 --------------------------
7929 Each global value summary entry corresponds to a global value defined or
7930 referenced by a summarized module.
7934 .. code-block:: text
7936 ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831
7938 For declarations, there will not be a summary list. For definitions, a
7939 global value will contain a list of summaries, one per module containing
7940 a definition. There can be multiple entries in a combined summary index
7941 for symbols with weak linkage.
7943 Each ``Summary`` format will depend on whether the global value is a
7944 :ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or
7945 :ref:`alias<alias_summary>`.
7947 .. _function_summary:
7952 If the global value is a function, the ``Summary`` entry will look like:
7954 .. code-block:: text
7956 function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Params]?[, Refs]?
7958 The ``module`` field includes the summary entry id for the module containing
7959 this definition, and the ``flags`` field contains information such as
7960 the linkage type, a flag indicating whether it is legal to import the
7961 definition, whether it is globally live and whether the linker resolved it
7962 to a local definition (the latter two are populated during the thin link).
7963 The ``insts`` field contains the number of IR instructions in the function.
7964 Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`,
7965 :ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`,
7966 :ref:`Params<params_summary>`, :ref:`Refs<refs_summary>`.
7968 .. _variable_summary:
7970 Global Variable Summary
7971 ^^^^^^^^^^^^^^^^^^^^^^^
7973 If the global value is a variable, the ``Summary`` entry will look like:
7975 .. code-block:: text
7977 variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]?
7979 The variable entry contains a subset of the fields in a
7980 :ref:`function summary <function_summary>`, see the descriptions there.
7987 If the global value is an alias, the ``Summary`` entry will look like:
7989 .. code-block:: text
7991 alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2)
7993 The ``module`` and ``flags`` fields are as described for a
7994 :ref:`function summary <function_summary>`. The ``aliasee`` field
7995 contains a reference to the global value summary entry of the aliasee.
7997 .. _funcflags_summary:
8002 The optional ``FuncFlags`` field looks like:
8004 .. code-block:: text
8006 funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0, noUnwind: 1, mayThrow: 0, hasUnknownCall: 0)
8008 If unspecified, flags are assumed to hold the conservative ``false`` value of
8016 The optional ``Calls`` field looks like:
8018 .. code-block:: text
8020 calls: ((Callee)[, (Callee)]*)
8022 where each ``Callee`` looks like:
8024 .. code-block:: text
8026 callee: ^1[, hotness: None]?[, relbf: 0]?
8028 The ``callee`` refers to the summary entry id of the callee. At most one
8029 of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``,
8030 ``Hot``, and ``Critical``), and ``relbf`` (which holds the integer
8031 branch frequency relative to the entry frequency, scaled down by 2^8)
8032 may be specified. The defaults are ``Unknown`` and ``0``, respectively.
8039 The optional ``Params`` is used by ``StackSafety`` and looks like:
8041 .. code-block:: text
8043 Params: ((Param)[, (Param)]*)
8045 where each ``Param`` describes pointer parameter access inside of the
8046 function and looks like:
8048 .. code-block:: text
8050 param: 4, offset: [0, 5][, calls: ((Callee)[, (Callee)]*)]?
8052 where the first ``param`` is the number of the parameter it describes,
8053 ``offset`` is the inclusive range of offsets from the pointer parameter to bytes
8054 which can be accessed by the function. This range does not include accesses by
8055 function calls from ``calls`` list.
8057 where each ``Callee`` describes how parameter is forwarded into other
8058 functions and looks like:
8060 .. code-block:: text
8062 callee: ^3, param: 5, offset: [-3, 3]
8064 The ``callee`` refers to the summary entry id of the callee, ``param`` is
8065 the number of the callee parameter which points into the callers parameter
8066 with offset known to be inside of the ``offset`` range. ``calls`` will be
8067 consumed and removed by thin link stage to update ``Param::offset`` so it
8068 covers all accesses possible by ``calls``.
8070 Pointer parameter without corresponding ``Param`` is considered unsafe and we
8071 assume that access with any offset is possible.
8075 If we have the following function:
8077 .. code-block:: text
8079 define i64 @foo(ptr %0, ptr %1, ptr %2, i8 %3) {
8080 store ptr %1, ptr @x
8081 %5 = getelementptr inbounds i8, ptr %2, i64 5
8082 %6 = load i8, ptr %5
8083 %7 = getelementptr inbounds i8, ptr %2, i8 %3
8084 tail call void @bar(i8 %3, ptr %7)
8085 %8 = load i64, ptr %0
8089 We can expect the record like this:
8091 .. code-block:: text
8093 params: ((param: 0, offset: [0, 7]),(param: 2, offset: [5, 5], calls: ((callee: ^3, param: 1, offset: [-128, 127]))))
8095 The function may access just 8 bytes of the parameter %0 . ``calls`` is empty,
8096 so the parameter is either not used for function calls or ``offset`` already
8097 covers all accesses from nested function calls.
8098 Parameter %1 escapes, so access is unknown.
8099 The function itself can access just a single byte of the parameter %2. Additional
8100 access is possible inside of the ``@bar`` or ``^3``. The function adds signed
8101 offset to the pointer and passes the result as the argument %1 into ``^3``.
8102 This record itself does not tell us how ``^3`` will access the parameter.
8103 Parameter %3 is not a pointer.
8110 The optional ``Refs`` field looks like:
8112 .. code-block:: text
8114 refs: ((Ref)[, (Ref)]*)
8116 where each ``Ref`` contains a reference to the summary id of the referenced
8117 value (e.g. ``^1``).
8119 .. _typeidinfo_summary:
8124 The optional ``TypeIdInfo`` field, used for
8125 `Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
8128 .. code-block:: text
8130 typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]?
8132 These optional fields have the following forms:
8137 .. code-block:: text
8139 typeTests: (TypeIdRef[, TypeIdRef]*)
8141 Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
8142 by summary id or ``GUID``.
8144 TypeTestAssumeVCalls
8145 """"""""""""""""""""
8147 .. code-block:: text
8149 typeTestAssumeVCalls: (VFuncId[, VFuncId]*)
8151 Where each VFuncId has the format:
8153 .. code-block:: text
8155 vFuncId: (TypeIdRef, offset: 16)
8157 Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
8158 by summary id or ``GUID`` preceded by a ``guid:`` tag.
8160 TypeCheckedLoadVCalls
8161 """""""""""""""""""""
8163 .. code-block:: text
8165 typeCheckedLoadVCalls: (VFuncId[, VFuncId]*)
8167 Where each VFuncId has the format described for ``TypeTestAssumeVCalls``.
8169 TypeTestAssumeConstVCalls
8170 """""""""""""""""""""""""
8172 .. code-block:: text
8174 typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*)
8176 Where each ConstVCall has the format:
8178 .. code-block:: text
8180 (VFuncId, args: (Arg[, Arg]*))
8182 and where each VFuncId has the format described for ``TypeTestAssumeVCalls``,
8183 and each Arg is an integer argument number.
8185 TypeCheckedLoadConstVCalls
8186 """"""""""""""""""""""""""
8188 .. code-block:: text
8190 typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*)
8192 Where each ConstVCall has the format described for
8193 ``TypeTestAssumeConstVCalls``.
8197 Type ID Summary Entry
8198 ---------------------
8200 Each type id summary entry corresponds to a type identifier resolution
8201 which is generated during the LTO link portion of the compile when building
8202 with `Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
8203 so these are only present in a combined summary index.
8207 .. code-block:: text
8209 ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778
8211 The ``typeTestRes`` gives the type test resolution ``kind`` (which may
8212 be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and
8213 the ``size-1`` bit width. It is followed by optional flags, which default to 0,
8214 and an optional WpdResolutions (whole program devirtualization resolution)
8215 field that looks like:
8217 .. code-block:: text
8219 wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]*
8221 where each entry is a mapping from the given byte offset to the whole-program
8222 devirtualization resolution WpdRes, that has one of the following formats:
8224 .. code-block:: text
8226 wpdRes: (kind: branchFunnel)
8227 wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi")
8228 wpdRes: (kind: indir)
8230 Additionally, each wpdRes has an optional ``resByArg`` field, which
8231 describes the resolutions for calls with all constant integer arguments:
8233 .. code-block:: text
8235 resByArg: (ResByArg[, ResByArg]*)
8239 .. code-block:: text
8241 args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0])
8243 Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal``
8244 or ``VirtualConstProp``. The ``info`` field is only used if the kind
8245 is ``UniformRetVal`` (indicates the uniform return value), or
8246 ``UniqueRetVal`` (holds the return value associated with the unique vtable
8247 (0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does
8248 not support the use of absolute symbols to store constants.
8250 .. _intrinsicglobalvariables:
8252 Intrinsic Global Variables
8253 ==========================
8255 LLVM has a number of "magic" global variables that contain data that
8256 affect code generation or other IR semantics. These are documented here.
8257 All globals of this sort should have a section specified as
8258 "``llvm.metadata``". This section and all globals that start with
8259 "``llvm.``" are reserved for use by LLVM.
8263 The '``llvm.used``' Global Variable
8264 -----------------------------------
8266 The ``@llvm.used`` global is an array which has
8267 :ref:`appending linkage <linkage_appending>`. This array contains a list of
8268 pointers to named global variables, functions and aliases which may optionally
8269 have a pointer cast formed of bitcast or getelementptr. For example, a legal
8272 .. code-block:: llvm
8277 @llvm.used = appending global [2 x ptr] [
8280 ], section "llvm.metadata"
8282 If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler,
8283 and linker are required to treat the symbol as if there is a reference to the
8284 symbol that it cannot see (which is why they have to be named). For example, if
8285 a variable has internal linkage and no references other than that from the
8286 ``@llvm.used`` list, it cannot be deleted. This is commonly used to represent
8287 references from inline asms and other things the compiler cannot "see", and
8288 corresponds to "``attribute((used))``" in GNU C.
8290 On some targets, the code generator must emit a directive to the
8291 assembler or object file to prevent the assembler and linker from
8292 removing the symbol.
8294 .. _gv_llvmcompilerused:
8296 The '``llvm.compiler.used``' Global Variable
8297 --------------------------------------------
8299 The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used``
8300 directive, except that it only prevents the compiler from touching the
8301 symbol. On targets that support it, this allows an intelligent linker to
8302 optimize references to the symbol without being impeded as it would be
8305 This is a rare construct that should only be used in rare circumstances,
8306 and should not be exposed to source languages.
8308 .. _gv_llvmglobalctors:
8310 The '``llvm.global_ctors``' Global Variable
8311 -------------------------------------------
8313 .. code-block:: llvm
8315 %0 = type { i32, ptr, ptr }
8316 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, ptr @ctor, ptr @data }]
8318 The ``@llvm.global_ctors`` array contains a list of constructor
8319 functions, priorities, and an associated global or function.
8320 The functions referenced by this array will be called in ascending order
8321 of priority (i.e. lowest first) when the module is loaded. The order of
8322 functions with the same priority is not defined.
8324 If the third field is non-null, and points to a global variable
8325 or function, the initializer function will only run if the associated
8326 data from the current module is not discarded.
8327 On ELF the referenced global variable or function must be in a comdat.
8329 .. _llvmglobaldtors:
8331 The '``llvm.global_dtors``' Global Variable
8332 -------------------------------------------
8334 .. code-block:: llvm
8336 %0 = type { i32, ptr, ptr }
8337 @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, ptr @dtor, ptr @data }]
8339 The ``@llvm.global_dtors`` array contains a list of destructor
8340 functions, priorities, and an associated global or function.
8341 The functions referenced by this array will be called in descending
8342 order of priority (i.e. highest first) when the module is unloaded. The
8343 order of functions with the same priority is not defined.
8345 If the third field is non-null, and points to a global variable
8346 or function, the destructor function will only run if the associated
8347 data from the current module is not discarded.
8348 On ELF the referenced global variable or function must be in a comdat.
8350 Instruction Reference
8351 =====================
8353 The LLVM instruction set consists of several different classifications
8354 of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
8355 instructions <binaryops>`, :ref:`bitwise binary
8356 instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
8357 :ref:`other instructions <otherops>`.
8361 Terminator Instructions
8362 -----------------------
8364 As mentioned :ref:`previously <functionstructure>`, every basic block in a
8365 program ends with a "Terminator" instruction, which indicates which
8366 block should be executed after the current block is finished. These
8367 terminator instructions typically yield a '``void``' value: they produce
8368 control flow, not values (the one exception being the
8369 ':ref:`invoke <i_invoke>`' instruction).
8371 The terminator instructions are: ':ref:`ret <i_ret>`',
8372 ':ref:`br <i_br>`', ':ref:`switch <i_switch>`',
8373 ':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`',
8374 ':ref:`callbr <i_callbr>`'
8375 ':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`',
8376 ':ref:`catchret <i_catchret>`',
8377 ':ref:`cleanupret <i_cleanupret>`',
8378 and ':ref:`unreachable <i_unreachable>`'.
8382 '``ret``' Instruction
8383 ^^^^^^^^^^^^^^^^^^^^^
8390 ret <type> <value> ; Return a value from a non-void function
8391 ret void ; Return from void function
8396 The '``ret``' instruction is used to return control flow (and optionally
8397 a value) from a function back to the caller.
8399 There are two forms of the '``ret``' instruction: one that returns a
8400 value and then causes control flow, and one that just causes control
8406 The '``ret``' instruction optionally accepts a single argument, the
8407 return value. The type of the return value must be a ':ref:`first
8408 class <t_firstclass>`' type.
8410 A function is not :ref:`well formed <wellformed>` if it has a non-void
8411 return type and contains a '``ret``' instruction with no return value or
8412 a return value with a type that does not match its type, or if it has a
8413 void return type and contains a '``ret``' instruction with a return
8419 When the '``ret``' instruction is executed, control flow returns back to
8420 the calling function's context. If the caller is a
8421 ":ref:`call <i_call>`" instruction, execution continues at the
8422 instruction after the call. If the caller was an
8423 ":ref:`invoke <i_invoke>`" instruction, execution continues at the
8424 beginning of the "normal" destination block. If the instruction returns
8425 a value, that value shall set the call or invoke instruction's return
8431 .. code-block:: llvm
8433 ret i32 5 ; Return an integer value of 5
8434 ret void ; Return from a void function
8435 ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2
8439 '``br``' Instruction
8440 ^^^^^^^^^^^^^^^^^^^^
8447 br i1 <cond>, label <iftrue>, label <iffalse>
8448 br label <dest> ; Unconditional branch
8453 The '``br``' instruction is used to cause control flow to transfer to a
8454 different basic block in the current function. There are two forms of
8455 this instruction, corresponding to a conditional branch and an
8456 unconditional branch.
8461 The conditional branch form of the '``br``' instruction takes a single
8462 '``i1``' value and two '``label``' values. The unconditional form of the
8463 '``br``' instruction takes a single '``label``' value as a target.
8468 Upon execution of a conditional '``br``' instruction, the '``i1``'
8469 argument is evaluated. If the value is ``true``, control flows to the
8470 '``iftrue``' ``label`` argument. If "cond" is ``false``, control flows
8471 to the '``iffalse``' ``label`` argument.
8472 If '``cond``' is ``poison`` or ``undef``, this instruction has undefined
8478 .. code-block:: llvm
8481 %cond = icmp eq i32 %a, %b
8482 br i1 %cond, label %IfEqual, label %IfUnequal
8490 '``switch``' Instruction
8491 ^^^^^^^^^^^^^^^^^^^^^^^^
8498 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
8503 The '``switch``' instruction is used to transfer control flow to one of
8504 several different places. It is a generalization of the '``br``'
8505 instruction, allowing a branch to occur to one of many possible
8511 The '``switch``' instruction uses three parameters: an integer
8512 comparison value '``value``', a default '``label``' destination, and an
8513 array of pairs of comparison value constants and '``label``'s. The table
8514 is not allowed to contain duplicate constant entries.
8519 The ``switch`` instruction specifies a table of values and destinations.
8520 When the '``switch``' instruction is executed, this table is searched
8521 for the given value. If the value is found, control flow is transferred
8522 to the corresponding destination; otherwise, control flow is transferred
8523 to the default destination.
8524 If '``value``' is ``poison`` or ``undef``, this instruction has undefined
8530 Depending on properties of the target machine and the particular
8531 ``switch`` instruction, this instruction may be code generated in
8532 different ways. For example, it could be generated as a series of
8533 chained conditional branches or with a lookup table.
8538 .. code-block:: llvm
8540 ; Emulate a conditional br instruction
8541 %Val = zext i1 %value to i32
8542 switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
8544 ; Emulate an unconditional br instruction
8545 switch i32 0, label %dest [ ]
8547 ; Implement a jump table:
8548 switch i32 %val, label %otherwise [ i32 0, label %onzero
8550 i32 2, label %ontwo ]
8554 '``indirectbr``' Instruction
8555 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8562 indirectbr ptr <address>, [ label <dest1>, label <dest2>, ... ]
8567 The '``indirectbr``' instruction implements an indirect branch to a
8568 label within the current function, whose address is specified by
8569 "``address``". Address must be derived from a
8570 :ref:`blockaddress <blockaddress>` constant.
8575 The '``address``' argument is the address of the label to jump to. The
8576 rest of the arguments indicate the full set of possible destinations
8577 that the address may point to. Blocks are allowed to occur multiple
8578 times in the destination list, though this isn't particularly useful.
8580 This destination list is required so that dataflow analysis has an
8581 accurate understanding of the CFG.
8586 Control transfers to the block specified in the address argument. All
8587 possible destination blocks must be listed in the label list, otherwise
8588 this instruction has undefined behavior. This implies that jumps to
8589 labels defined in other functions have undefined behavior as well.
8590 If '``address``' is ``poison`` or ``undef``, this instruction has undefined
8596 This is typically implemented with a jump through a register.
8601 .. code-block:: llvm
8603 indirectbr ptr %Addr, [ label %bb1, label %bb2, label %bb3 ]
8607 '``invoke``' Instruction
8608 ^^^^^^^^^^^^^^^^^^^^^^^^
8615 <result> = invoke [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
8616 [operand bundles] to label <normal label> unwind label <exception label>
8621 The '``invoke``' instruction causes control to transfer to a specified
8622 function, with the possibility of control flow transfer to either the
8623 '``normal``' label or the '``exception``' label. If the callee function
8624 returns with the "``ret``" instruction, control flow will return to the
8625 "normal" label. If the callee (or any indirect callees) returns via the
8626 ":ref:`resume <i_resume>`" instruction or other exception handling
8627 mechanism, control is interrupted and continued at the dynamically
8628 nearest "exception" label.
8630 The '``exception``' label is a `landing
8631 pad <ExceptionHandling.html#overview>`_ for the exception. As such,
8632 '``exception``' label is required to have the
8633 ":ref:`landingpad <i_landingpad>`" instruction, which contains the
8634 information about the behavior of the program after unwinding happens,
8635 as its first non-PHI instruction. The restrictions on the
8636 "``landingpad``" instruction's tightly couples it to the "``invoke``"
8637 instruction, so that the important information contained within the
8638 "``landingpad``" instruction can't be lost through normal code motion.
8643 This instruction requires several arguments:
8645 #. The optional "cconv" marker indicates which :ref:`calling
8646 convention <callingconv>` the call should use. If none is
8647 specified, the call defaults to using C calling conventions.
8648 #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
8649 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
8651 #. The optional addrspace attribute can be used to indicate the address space
8652 of the called function. If it is not specified, the program address space
8653 from the :ref:`datalayout string<langref_datalayout>` will be used.
8654 #. '``ty``': the type of the call instruction itself which is also the
8655 type of the return value. Functions that return no value are marked
8657 #. '``fnty``': shall be the signature of the function being invoked. The
8658 argument types must match the types implied by this signature. This
8659 type can be omitted if the function is not varargs.
8660 #. '``fnptrval``': An LLVM value containing a pointer to a function to
8661 be invoked. In most cases, this is a direct function invocation, but
8662 indirect ``invoke``'s are just as possible, calling an arbitrary pointer
8664 #. '``function args``': argument list whose types match the function
8665 signature argument types and parameter attributes. All arguments must
8666 be of :ref:`first class <t_firstclass>` type. If the function signature
8667 indicates the function accepts a variable number of arguments, the
8668 extra arguments can be specified.
8669 #. '``normal label``': the label reached when the called function
8670 executes a '``ret``' instruction.
8671 #. '``exception label``': the label reached when a callee returns via
8672 the :ref:`resume <i_resume>` instruction or other exception handling
8674 #. The optional :ref:`function attributes <fnattrs>` list.
8675 #. The optional :ref:`operand bundles <opbundles>` list.
8680 This instruction is designed to operate as a standard '``call``'
8681 instruction in most regards. The primary difference is that it
8682 establishes an association with a label, which is used by the runtime
8683 library to unwind the stack.
8685 This instruction is used in languages with destructors to ensure that
8686 proper cleanup is performed in the case of either a ``longjmp`` or a
8687 thrown exception. Additionally, this is important for implementation of
8688 '``catch``' clauses in high-level languages that support them.
8690 For the purposes of the SSA form, the definition of the value returned
8691 by the '``invoke``' instruction is deemed to occur on the edge from the
8692 current block to the "normal" label. If the callee unwinds then no
8693 return value is available.
8698 .. code-block:: llvm
8700 %retval = invoke i32 @Test(i32 15) to label %Continue
8701 unwind label %TestCleanup ; i32:retval set
8702 %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue
8703 unwind label %TestCleanup ; i32:retval set
8707 '``callbr``' Instruction
8708 ^^^^^^^^^^^^^^^^^^^^^^^^
8715 <result> = callbr [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
8716 [operand bundles] to label <fallthrough label> [indirect labels]
8721 The '``callbr``' instruction causes control to transfer to a specified
8722 function, with the possibility of control flow transfer to either the
8723 '``fallthrough``' label or one of the '``indirect``' labels.
8725 This instruction should only be used to implement the "goto" feature of gcc
8726 style inline assembly. Any other usage is an error in the IR verifier.
8728 Note that in order to support outputs along indirect edges, LLVM may need to
8729 split critical edges, which may require synthesizing a replacement block for
8730 the ``indirect labels``. Therefore, the address of a label as seen by another
8731 ``callbr`` instruction, or for a :ref:`blockaddress <blockaddress>` constant,
8732 may not be equal to the address provided for the same block to this
8733 instruction's ``indirect labels`` operand. The assembly code may only transfer
8734 control to addresses provided via this instruction's ``indirect labels``.
8739 This instruction requires several arguments:
8741 #. The optional "cconv" marker indicates which :ref:`calling
8742 convention <callingconv>` the call should use. If none is
8743 specified, the call defaults to using C calling conventions.
8744 #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
8745 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
8747 #. The optional addrspace attribute can be used to indicate the address space
8748 of the called function. If it is not specified, the program address space
8749 from the :ref:`datalayout string<langref_datalayout>` will be used.
8750 #. '``ty``': the type of the call instruction itself which is also the
8751 type of the return value. Functions that return no value are marked
8753 #. '``fnty``': shall be the signature of the function being called. The
8754 argument types must match the types implied by this signature. This
8755 type can be omitted if the function is not varargs.
8756 #. '``fnptrval``': An LLVM value containing a pointer to a function to
8757 be called. In most cases, this is a direct function call, but
8758 other ``callbr``'s are just as possible, calling an arbitrary pointer
8760 #. '``function args``': argument list whose types match the function
8761 signature argument types and parameter attributes. All arguments must
8762 be of :ref:`first class <t_firstclass>` type. If the function signature
8763 indicates the function accepts a variable number of arguments, the
8764 extra arguments can be specified.
8765 #. '``fallthrough label``': the label reached when the inline assembly's
8766 execution exits the bottom.
8767 #. '``indirect labels``': the labels reached when a callee transfers control
8768 to a location other than the '``fallthrough label``'. Label constraints
8769 refer to these destinations.
8770 #. The optional :ref:`function attributes <fnattrs>` list.
8771 #. The optional :ref:`operand bundles <opbundles>` list.
8776 This instruction is designed to operate as a standard '``call``'
8777 instruction in most regards. The primary difference is that it
8778 establishes an association with additional labels to define where control
8779 flow goes after the call.
8781 The output values of a '``callbr``' instruction are available only to
8782 the '``fallthrough``' block, not to any '``indirect``' blocks(s).
8784 The only use of this today is to implement the "goto" feature of gcc inline
8785 assembly where additional labels can be provided as locations for the inline
8786 assembly to jump to.
8791 .. code-block:: llvm
8793 ; "asm goto" without output constraints.
8794 callbr void asm "", "r,!i"(i32 %x)
8795 to label %fallthrough [label %indirect]
8797 ; "asm goto" with output constraints.
8798 <result> = callbr i32 asm "", "=r,r,!i"(i32 %x)
8799 to label %fallthrough [label %indirect]
8803 '``resume``' Instruction
8804 ^^^^^^^^^^^^^^^^^^^^^^^^
8811 resume <type> <value>
8816 The '``resume``' instruction is a terminator instruction that has no
8822 The '``resume``' instruction requires one argument, which must have the
8823 same type as the result of any '``landingpad``' instruction in the same
8829 The '``resume``' instruction resumes propagation of an existing
8830 (in-flight) exception whose unwinding was interrupted with a
8831 :ref:`landingpad <i_landingpad>` instruction.
8836 .. code-block:: llvm
8838 resume { ptr, i32 } %exn
8842 '``catchswitch``' Instruction
8843 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8850 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller
8851 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default>
8856 The '``catchswitch``' instruction is used by `LLVM's exception handling system
8857 <ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers
8858 that may be executed by the :ref:`EH personality routine <personalityfn>`.
8863 The ``parent`` argument is the token of the funclet that contains the
8864 ``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet,
8865 this operand may be the token ``none``.
8867 The ``default`` argument is the label of another basic block beginning with
8868 either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination
8869 must be a legal target with respect to the ``parent`` links, as described in
8870 the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
8872 The ``handlers`` are a nonempty list of successor blocks that each begin with a
8873 :ref:`catchpad <i_catchpad>` instruction.
8878 Executing this instruction transfers control to one of the successors in
8879 ``handlers``, if appropriate, or continues to unwind via the unwind label if
8882 The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that
8883 it must be both the first non-phi instruction and last instruction in the basic
8884 block. Therefore, it must be the only non-phi instruction in the block.
8889 .. code-block:: text
8892 %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller
8894 %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup
8898 '``catchret``' Instruction
8899 ^^^^^^^^^^^^^^^^^^^^^^^^^^
8906 catchret from <token> to label <normal>
8911 The '``catchret``' instruction is a terminator instruction that has a
8918 The first argument to a '``catchret``' indicates which ``catchpad`` it
8919 exits. It must be a :ref:`catchpad <i_catchpad>`.
8920 The second argument to a '``catchret``' specifies where control will
8926 The '``catchret``' instruction ends an existing (in-flight) exception whose
8927 unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The
8928 :ref:`personality function <personalityfn>` gets a chance to execute arbitrary
8929 code to, for example, destroy the active exception. Control then transfers to
8932 The ``token`` argument must be a token produced by a ``catchpad`` instruction.
8933 If the specified ``catchpad`` is not the most-recently-entered not-yet-exited
8934 funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
8935 the ``catchret``'s behavior is undefined.
8940 .. code-block:: text
8942 catchret from %catch to label %continue
8946 '``cleanupret``' Instruction
8947 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8954 cleanupret from <value> unwind label <continue>
8955 cleanupret from <value> unwind to caller
8960 The '``cleanupret``' instruction is a terminator instruction that has
8961 an optional successor.
8967 The '``cleanupret``' instruction requires one argument, which indicates
8968 which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`.
8969 If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited
8970 funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
8971 the ``cleanupret``'s behavior is undefined.
8973 The '``cleanupret``' instruction also has an optional successor, ``continue``,
8974 which must be the label of another basic block beginning with either a
8975 ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must
8976 be a legal target with respect to the ``parent`` links, as described in the
8977 `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
8982 The '``cleanupret``' instruction indicates to the
8983 :ref:`personality function <personalityfn>` that one
8984 :ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended.
8985 It transfers control to ``continue`` or unwinds out of the function.
8990 .. code-block:: text
8992 cleanupret from %cleanup unwind to caller
8993 cleanupret from %cleanup unwind label %continue
8997 '``unreachable``' Instruction
8998 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9010 The '``unreachable``' instruction has no defined semantics. This
9011 instruction is used to inform the optimizer that a particular portion of
9012 the code is not reachable. This can be used to indicate that the code
9013 after a no-return function cannot be reached, and other facts.
9018 The '``unreachable``' instruction has no defined semantics.
9025 Unary operators require a single operand, execute an operation on
9026 it, and produce a single value. The operand might represent multiple
9027 data, as is the case with the :ref:`vector <t_vector>` data type. The
9028 result value has the same type as its operand.
9032 '``fneg``' Instruction
9033 ^^^^^^^^^^^^^^^^^^^^^^
9040 <result> = fneg [fast-math flags]* <ty> <op1> ; yields ty:result
9045 The '``fneg``' instruction returns the negation of its operand.
9050 The argument to the '``fneg``' instruction must be a
9051 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9052 floating-point values.
9057 The value produced is a copy of the operand with its sign bit flipped.
9058 This instruction can also take any number of :ref:`fast-math
9059 flags <fastmath>`, which are optimization hints to enable otherwise
9060 unsafe floating-point optimizations:
9065 .. code-block:: text
9067 <result> = fneg float %val ; yields float:result = -%var
9074 Binary operators are used to do most of the computation in a program.
9075 They require two operands of the same type, execute an operation on
9076 them, and produce a single value. The operands might represent multiple
9077 data, as is the case with the :ref:`vector <t_vector>` data type. The
9078 result value has the same type as its operands.
9080 There are several different binary operators:
9084 '``add``' Instruction
9085 ^^^^^^^^^^^^^^^^^^^^^
9092 <result> = add <ty> <op1>, <op2> ; yields ty:result
9093 <result> = add nuw <ty> <op1>, <op2> ; yields ty:result
9094 <result> = add nsw <ty> <op1>, <op2> ; yields ty:result
9095 <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result
9100 The '``add``' instruction returns the sum of its two operands.
9105 The two arguments to the '``add``' instruction must be
9106 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9107 arguments must have identical types.
9112 The value produced is the integer sum of the two operands.
9114 If the sum has unsigned overflow, the result returned is the
9115 mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
9118 Because LLVM integers use a two's complement representation, this
9119 instruction is appropriate for both signed and unsigned integers.
9121 ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
9122 respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
9123 result value of the ``add`` is a :ref:`poison value <poisonvalues>` if
9124 unsigned and/or signed overflow, respectively, occurs.
9129 .. code-block:: text
9131 <result> = add i32 4, %var ; yields i32:result = 4 + %var
9135 '``fadd``' Instruction
9136 ^^^^^^^^^^^^^^^^^^^^^^
9143 <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
9148 The '``fadd``' instruction returns the sum of its two operands.
9153 The two arguments to the '``fadd``' instruction must be
9154 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9155 floating-point values. Both arguments must have identical types.
9160 The value produced is the floating-point sum of the two operands.
9161 This instruction is assumed to execute in the default :ref:`floating-point
9162 environment <floatenv>`.
9163 This instruction can also take any number of :ref:`fast-math
9164 flags <fastmath>`, which are optimization hints to enable otherwise
9165 unsafe floating-point optimizations:
9170 .. code-block:: text
9172 <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var
9176 '``sub``' Instruction
9177 ^^^^^^^^^^^^^^^^^^^^^
9184 <result> = sub <ty> <op1>, <op2> ; yields ty:result
9185 <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result
9186 <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result
9187 <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result
9192 The '``sub``' instruction returns the difference of its two operands.
9194 Note that the '``sub``' instruction is used to represent the '``neg``'
9195 instruction present in most other intermediate representations.
9200 The two arguments to the '``sub``' instruction must be
9201 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9202 arguments must have identical types.
9207 The value produced is the integer difference of the two operands.
9209 If the difference has unsigned overflow, the result returned is the
9210 mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
9213 Because LLVM integers use a two's complement representation, this
9214 instruction is appropriate for both signed and unsigned integers.
9216 ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
9217 respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
9218 result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if
9219 unsigned and/or signed overflow, respectively, occurs.
9224 .. code-block:: text
9226 <result> = sub i32 4, %var ; yields i32:result = 4 - %var
9227 <result> = sub i32 0, %val ; yields i32:result = -%var
9231 '``fsub``' Instruction
9232 ^^^^^^^^^^^^^^^^^^^^^^
9239 <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
9244 The '``fsub``' instruction returns the difference of its two operands.
9249 The two arguments to the '``fsub``' instruction must be
9250 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9251 floating-point values. Both arguments must have identical types.
9256 The value produced is the floating-point difference of the two operands.
9257 This instruction is assumed to execute in the default :ref:`floating-point
9258 environment <floatenv>`.
9259 This instruction can also take any number of :ref:`fast-math
9260 flags <fastmath>`, which are optimization hints to enable otherwise
9261 unsafe floating-point optimizations:
9266 .. code-block:: text
9268 <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var
9269 <result> = fsub float -0.0, %val ; yields float:result = -%var
9273 '``mul``' Instruction
9274 ^^^^^^^^^^^^^^^^^^^^^
9281 <result> = mul <ty> <op1>, <op2> ; yields ty:result
9282 <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result
9283 <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result
9284 <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result
9289 The '``mul``' instruction returns the product of its two operands.
9294 The two arguments to the '``mul``' instruction must be
9295 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9296 arguments must have identical types.
9301 The value produced is the integer product of the two operands.
9303 If the result of the multiplication has unsigned overflow, the result
9304 returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the
9305 bit width of the result.
9307 Because LLVM integers use a two's complement representation, and the
9308 result is the same width as the operands, this instruction returns the
9309 correct result for both signed and unsigned integers. If a full product
9310 (e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be
9311 sign-extended or zero-extended as appropriate to the width of the full
9314 ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
9315 respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
9316 result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if
9317 unsigned and/or signed overflow, respectively, occurs.
9322 .. code-block:: text
9324 <result> = mul i32 4, %var ; yields i32:result = 4 * %var
9328 '``fmul``' Instruction
9329 ^^^^^^^^^^^^^^^^^^^^^^
9336 <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
9341 The '``fmul``' instruction returns the product of its two operands.
9346 The two arguments to the '``fmul``' instruction must be
9347 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9348 floating-point values. Both arguments must have identical types.
9353 The value produced is the floating-point product of the two operands.
9354 This instruction is assumed to execute in the default :ref:`floating-point
9355 environment <floatenv>`.
9356 This instruction can also take any number of :ref:`fast-math
9357 flags <fastmath>`, which are optimization hints to enable otherwise
9358 unsafe floating-point optimizations:
9363 .. code-block:: text
9365 <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var
9369 '``udiv``' Instruction
9370 ^^^^^^^^^^^^^^^^^^^^^^
9377 <result> = udiv <ty> <op1>, <op2> ; yields ty:result
9378 <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result
9383 The '``udiv``' instruction returns the quotient of its two operands.
9388 The two arguments to the '``udiv``' instruction must be
9389 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9390 arguments must have identical types.
9395 The value produced is the unsigned integer quotient of the two operands.
9397 Note that unsigned integer division and signed integer division are
9398 distinct operations; for signed integer division, use '``sdiv``'.
9400 Division by zero is undefined behavior. For vectors, if any element
9401 of the divisor is zero, the operation has undefined behavior.
9404 If the ``exact`` keyword is present, the result value of the ``udiv`` is
9405 a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as
9406 such, "((a udiv exact b) mul b) == a").
9411 .. code-block:: text
9413 <result> = udiv i32 4, %var ; yields i32:result = 4 / %var
9417 '``sdiv``' Instruction
9418 ^^^^^^^^^^^^^^^^^^^^^^
9425 <result> = sdiv <ty> <op1>, <op2> ; yields ty:result
9426 <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result
9431 The '``sdiv``' instruction returns the quotient of its two operands.
9436 The two arguments to the '``sdiv``' instruction must be
9437 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9438 arguments must have identical types.
9443 The value produced is the signed integer quotient of the two operands
9444 rounded towards zero.
9446 Note that signed integer division and unsigned integer division are
9447 distinct operations; for unsigned integer division, use '``udiv``'.
9449 Division by zero is undefined behavior. For vectors, if any element
9450 of the divisor is zero, the operation has undefined behavior.
9451 Overflow also leads to undefined behavior; this is a rare case, but can
9452 occur, for example, by doing a 32-bit division of -2147483648 by -1.
9454 If the ``exact`` keyword is present, the result value of the ``sdiv`` is
9455 a :ref:`poison value <poisonvalues>` if the result would be rounded.
9460 .. code-block:: text
9462 <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var
9466 '``fdiv``' Instruction
9467 ^^^^^^^^^^^^^^^^^^^^^^
9474 <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
9479 The '``fdiv``' instruction returns the quotient of its two operands.
9484 The two arguments to the '``fdiv``' instruction must be
9485 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9486 floating-point values. Both arguments must have identical types.
9491 The value produced is the floating-point quotient of the two operands.
9492 This instruction is assumed to execute in the default :ref:`floating-point
9493 environment <floatenv>`.
9494 This instruction can also take any number of :ref:`fast-math
9495 flags <fastmath>`, which are optimization hints to enable otherwise
9496 unsafe floating-point optimizations:
9501 .. code-block:: text
9503 <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var
9507 '``urem``' Instruction
9508 ^^^^^^^^^^^^^^^^^^^^^^
9515 <result> = urem <ty> <op1>, <op2> ; yields ty:result
9520 The '``urem``' instruction returns the remainder from the unsigned
9521 division of its two arguments.
9526 The two arguments to the '``urem``' instruction must be
9527 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9528 arguments must have identical types.
9533 This instruction returns the unsigned integer *remainder* of a division.
9534 This instruction always performs an unsigned division to get the
9537 Note that unsigned integer remainder and signed integer remainder are
9538 distinct operations; for signed integer remainder, use '``srem``'.
9540 Taking the remainder of a division by zero is undefined behavior.
9541 For vectors, if any element of the divisor is zero, the operation has
9547 .. code-block:: text
9549 <result> = urem i32 4, %var ; yields i32:result = 4 % %var
9553 '``srem``' Instruction
9554 ^^^^^^^^^^^^^^^^^^^^^^
9561 <result> = srem <ty> <op1>, <op2> ; yields ty:result
9566 The '``srem``' instruction returns the remainder from the signed
9567 division of its two operands. This instruction can also take
9568 :ref:`vector <t_vector>` versions of the values in which case the elements
9574 The two arguments to the '``srem``' instruction must be
9575 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9576 arguments must have identical types.
9581 This instruction returns the *remainder* of a division (where the result
9582 is either zero or has the same sign as the dividend, ``op1``), not the
9583 *modulo* operator (where the result is either zero or has the same sign
9584 as the divisor, ``op2``) of a value. For more information about the
9585 difference, see `The Math
9586 Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a
9587 table of how this is implemented in various languages, please see
9589 operation <http://en.wikipedia.org/wiki/Modulo_operation>`_.
9591 Note that signed integer remainder and unsigned integer remainder are
9592 distinct operations; for unsigned integer remainder, use '``urem``'.
9594 Taking the remainder of a division by zero is undefined behavior.
9595 For vectors, if any element of the divisor is zero, the operation has
9597 Overflow also leads to undefined behavior; this is a rare case, but can
9598 occur, for example, by taking the remainder of a 32-bit division of
9599 -2147483648 by -1. (The remainder doesn't actually overflow, but this
9600 rule lets srem be implemented using instructions that return both the
9601 result of the division and the remainder.)
9606 .. code-block:: text
9608 <result> = srem i32 4, %var ; yields i32:result = 4 % %var
9612 '``frem``' Instruction
9613 ^^^^^^^^^^^^^^^^^^^^^^
9620 <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
9625 The '``frem``' instruction returns the remainder from the division of
9630 The instruction is implemented as a call to libm's '``fmod``'
9631 for some targets, and using the instruction may thus require linking libm.
9637 The two arguments to the '``frem``' instruction must be
9638 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9639 floating-point values. Both arguments must have identical types.
9644 The value produced is the floating-point remainder of the two operands.
9645 This is the same output as a libm '``fmod``' function, but without any
9646 possibility of setting ``errno``. The remainder has the same sign as the
9648 This instruction is assumed to execute in the default :ref:`floating-point
9649 environment <floatenv>`.
9650 This instruction can also take any number of :ref:`fast-math
9651 flags <fastmath>`, which are optimization hints to enable otherwise
9652 unsafe floating-point optimizations:
9657 .. code-block:: text
9659 <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var
9663 Bitwise Binary Operations
9664 -------------------------
9666 Bitwise binary operators are used to do various forms of bit-twiddling
9667 in a program. They are generally very efficient instructions and can
9668 commonly be strength reduced from other instructions. They require two
9669 operands of the same type, execute an operation on them, and produce a
9670 single value. The resulting value is the same type as its operands.
9674 '``shl``' Instruction
9675 ^^^^^^^^^^^^^^^^^^^^^
9682 <result> = shl <ty> <op1>, <op2> ; yields ty:result
9683 <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result
9684 <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result
9685 <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result
9690 The '``shl``' instruction returns the first operand shifted to the left
9691 a specified number of bits.
9696 Both arguments to the '``shl``' instruction must be the same
9697 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
9698 '``op2``' is treated as an unsigned value.
9703 The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`,
9704 where ``n`` is the width of the result. If ``op2`` is (statically or
9705 dynamically) equal to or larger than the number of bits in
9706 ``op1``, this instruction returns a :ref:`poison value <poisonvalues>`.
9707 If the arguments are vectors, each vector element of ``op1`` is shifted
9708 by the corresponding shift amount in ``op2``.
9710 If the ``nuw`` keyword is present, then the shift produces a poison
9711 value if it shifts out any non-zero bits.
9712 If the ``nsw`` keyword is present, then the shift produces a poison
9713 value if it shifts out any bits that disagree with the resultant sign bit.
9718 .. code-block:: text
9720 <result> = shl i32 4, %var ; yields i32: 4 << %var
9721 <result> = shl i32 4, 2 ; yields i32: 16
9722 <result> = shl i32 1, 10 ; yields i32: 1024
9723 <result> = shl i32 1, 32 ; undefined
9724 <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4>
9729 '``lshr``' Instruction
9730 ^^^^^^^^^^^^^^^^^^^^^^
9737 <result> = lshr <ty> <op1>, <op2> ; yields ty:result
9738 <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result
9743 The '``lshr``' instruction (logical shift right) returns the first
9744 operand shifted to the right a specified number of bits with zero fill.
9749 Both arguments to the '``lshr``' instruction must be the same
9750 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
9751 '``op2``' is treated as an unsigned value.
9756 This instruction always performs a logical shift right operation. The
9757 most significant bits of the result will be filled with zero bits after
9758 the shift. If ``op2`` is (statically or dynamically) equal to or larger
9759 than the number of bits in ``op1``, this instruction returns a :ref:`poison
9760 value <poisonvalues>`. If the arguments are vectors, each vector element
9761 of ``op1`` is shifted by the corresponding shift amount in ``op2``.
9763 If the ``exact`` keyword is present, the result value of the ``lshr`` is
9764 a poison value if any of the bits shifted out are non-zero.
9769 .. code-block:: text
9771 <result> = lshr i32 4, 1 ; yields i32:result = 2
9772 <result> = lshr i32 4, 2 ; yields i32:result = 1
9773 <result> = lshr i8 4, 3 ; yields i8:result = 0
9774 <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F
9775 <result> = lshr i32 1, 32 ; undefined
9776 <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1>
9780 '``ashr``' Instruction
9781 ^^^^^^^^^^^^^^^^^^^^^^
9788 <result> = ashr <ty> <op1>, <op2> ; yields ty:result
9789 <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result
9794 The '``ashr``' instruction (arithmetic shift right) returns the first
9795 operand shifted to the right a specified number of bits with sign
9801 Both arguments to the '``ashr``' instruction must be the same
9802 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
9803 '``op2``' is treated as an unsigned value.
9808 This instruction always performs an arithmetic shift right operation,
9809 The most significant bits of the result will be filled with the sign bit
9810 of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger
9811 than the number of bits in ``op1``, this instruction returns a :ref:`poison
9812 value <poisonvalues>`. If the arguments are vectors, each vector element
9813 of ``op1`` is shifted by the corresponding shift amount in ``op2``.
9815 If the ``exact`` keyword is present, the result value of the ``ashr`` is
9816 a poison value if any of the bits shifted out are non-zero.
9821 .. code-block:: text
9823 <result> = ashr i32 4, 1 ; yields i32:result = 2
9824 <result> = ashr i32 4, 2 ; yields i32:result = 1
9825 <result> = ashr i8 4, 3 ; yields i8:result = 0
9826 <result> = ashr i8 -2, 1 ; yields i8:result = -1
9827 <result> = ashr i32 1, 32 ; undefined
9828 <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0>
9832 '``and``' Instruction
9833 ^^^^^^^^^^^^^^^^^^^^^
9840 <result> = and <ty> <op1>, <op2> ; yields ty:result
9845 The '``and``' instruction returns the bitwise logical and of its two
9851 The two arguments to the '``and``' instruction must be
9852 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9853 arguments must have identical types.
9858 The truth table used for the '``and``' instruction is:
9875 .. code-block:: text
9877 <result> = and i32 4, %var ; yields i32:result = 4 & %var
9878 <result> = and i32 15, 40 ; yields i32:result = 8
9879 <result> = and i32 4, 8 ; yields i32:result = 0
9883 '``or``' Instruction
9884 ^^^^^^^^^^^^^^^^^^^^
9891 <result> = or <ty> <op1>, <op2> ; yields ty:result
9896 The '``or``' instruction returns the bitwise logical inclusive or of its
9902 The two arguments to the '``or``' instruction must be
9903 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9904 arguments must have identical types.
9909 The truth table used for the '``or``' instruction is:
9928 <result> = or i32 4, %var ; yields i32:result = 4 | %var
9929 <result> = or i32 15, 40 ; yields i32:result = 47
9930 <result> = or i32 4, 8 ; yields i32:result = 12
9934 '``xor``' Instruction
9935 ^^^^^^^^^^^^^^^^^^^^^
9942 <result> = xor <ty> <op1>, <op2> ; yields ty:result
9947 The '``xor``' instruction returns the bitwise logical exclusive or of
9948 its two operands. The ``xor`` is used to implement the "one's
9949 complement" operation, which is the "~" operator in C.
9954 The two arguments to the '``xor``' instruction must be
9955 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9956 arguments must have identical types.
9961 The truth table used for the '``xor``' instruction is:
9978 .. code-block:: text
9980 <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var
9981 <result> = xor i32 15, 40 ; yields i32:result = 39
9982 <result> = xor i32 4, 8 ; yields i32:result = 12
9983 <result> = xor i32 %V, -1 ; yields i32:result = ~%V
9988 LLVM supports several instructions to represent vector operations in a
9989 target-independent manner. These instructions cover the element-access
9990 and vector-specific operations needed to process vectors effectively.
9991 While LLVM does directly support these vector operations, many
9992 sophisticated algorithms will want to use target-specific intrinsics to
9993 take full advantage of a specific target.
9995 .. _i_extractelement:
9997 '``extractelement``' Instruction
9998 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10005 <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty>
10006 <result> = extractelement <vscale x n x <ty>> <val>, <ty2> <idx> ; yields <ty>
10011 The '``extractelement``' instruction extracts a single scalar element
10012 from a vector at a specified index.
10017 The first operand of an '``extractelement``' instruction is a value of
10018 :ref:`vector <t_vector>` type. The second operand is an index indicating
10019 the position from which to extract the element. The index may be a
10020 variable of any integer type, and will be treated as an unsigned integer.
10025 The result is a scalar of the same type as the element type of ``val``.
10026 Its value is the value at position ``idx`` of ``val``. If ``idx``
10027 exceeds the length of ``val`` for a fixed-length vector, the result is a
10028 :ref:`poison value <poisonvalues>`. For a scalable vector, if the value
10029 of ``idx`` exceeds the runtime length of the vector, the result is a
10030 :ref:`poison value <poisonvalues>`.
10035 .. code-block:: text
10037 <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32
10039 .. _i_insertelement:
10041 '``insertelement``' Instruction
10042 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10049 <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>>
10050 <result> = insertelement <vscale x n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <vscale x n x <ty>>
10055 The '``insertelement``' instruction inserts a scalar element into a
10056 vector at a specified index.
10061 The first operand of an '``insertelement``' instruction is a value of
10062 :ref:`vector <t_vector>` type. The second operand is a scalar value whose
10063 type must equal the element type of the first operand. The third operand
10064 is an index indicating the position at which to insert the value. The
10065 index may be a variable of any integer type, and will be treated as an
10071 The result is a vector of the same type as ``val``. Its element values
10072 are those of ``val`` except at position ``idx``, where it gets the value
10073 ``elt``. If ``idx`` exceeds the length of ``val`` for a fixed-length vector,
10074 the result is a :ref:`poison value <poisonvalues>`. For a scalable vector,
10075 if the value of ``idx`` exceeds the runtime length of the vector, the result
10076 is a :ref:`poison value <poisonvalues>`.
10081 .. code-block:: text
10083 <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32>
10085 .. _i_shufflevector:
10087 '``shufflevector``' Instruction
10088 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10095 <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>>
10096 <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>>
10101 The '``shufflevector``' instruction constructs a permutation of elements
10102 from two input vectors, returning a vector with the same element type as
10103 the input and length that is the same as the shuffle mask.
10108 The first two operands of a '``shufflevector``' instruction are vectors
10109 with the same type. The third argument is a shuffle mask vector constant
10110 whose element type is ``i32``. The mask vector elements must be constant
10111 integers or ``poison`` values. The result of the instruction is a vector
10112 whose length is the same as the shuffle mask and whose element type is the
10113 same as the element type of the first two operands.
10118 The elements of the two input vectors are numbered from left to right
10119 across both of the vectors. For each element of the result vector, the
10120 shuffle mask selects an element from one of the input vectors to copy
10121 to the result. Non-negative elements in the mask represent an index
10122 into the concatenated pair of input vectors.
10124 A ``poison`` element in the mask vector specifies that the resulting element
10126 For backwards-compatibility reasons, LLVM temporarily also accepts ``undef``
10127 mask elements, which will be interpreted the same way as ``poison`` elements.
10128 If the shuffle mask selects an ``undef`` element from one of the input
10129 vectors, the resulting element is ``undef``.
10131 For scalable vectors, the only valid mask values at present are
10132 ``zeroinitializer``, ``undef`` and ``poison``, since we cannot write all indices as
10133 literals for a vector with a length unknown at compile time.
10138 .. code-block:: text
10140 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
10141 <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32>
10142 <result> = shufflevector <4 x i32> %v1, <4 x i32> poison,
10143 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle.
10144 <result> = shufflevector <8 x i32> %v1, <8 x i32> poison,
10145 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32>
10146 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
10147 <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32>
10149 Aggregate Operations
10150 --------------------
10152 LLVM supports several instructions for working with
10153 :ref:`aggregate <t_aggregate>` values.
10155 .. _i_extractvalue:
10157 '``extractvalue``' Instruction
10158 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10165 <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
10170 The '``extractvalue``' instruction extracts the value of a member field
10171 from an :ref:`aggregate <t_aggregate>` value.
10176 The first operand of an '``extractvalue``' instruction is a value of
10177 :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are
10178 constant indices to specify which value to extract in a similar manner
10179 as indices in a '``getelementptr``' instruction.
10181 The major differences to ``getelementptr`` indexing are:
10183 - Since the value being indexed is not a pointer, the first index is
10184 omitted and assumed to be zero.
10185 - At least one index must be specified.
10186 - Not only struct indices but also array indices must be in bounds.
10191 The result is the value at the position in the aggregate specified by
10192 the index operands.
10197 .. code-block:: text
10199 <result> = extractvalue {i32, float} %agg, 0 ; yields i32
10203 '``insertvalue``' Instruction
10204 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10211 <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type>
10216 The '``insertvalue``' instruction inserts a value into a member field in
10217 an :ref:`aggregate <t_aggregate>` value.
10222 The first operand of an '``insertvalue``' instruction is a value of
10223 :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is
10224 a first-class value to insert. The following operands are constant
10225 indices indicating the position at which to insert the value in a
10226 similar manner as indices in a '``extractvalue``' instruction. The value
10227 to insert must have the same type as the value identified by the
10233 The result is an aggregate of the same type as ``val``. Its value is
10234 that of ``val`` except that the value at the position specified by the
10235 indices is that of ``elt``.
10240 .. code-block:: llvm
10242 %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef}
10243 %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val}
10244 %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}}
10248 Memory Access and Addressing Operations
10249 ---------------------------------------
10251 A key design point of an SSA-based representation is how it represents
10252 memory. In LLVM, no memory locations are in SSA form, which makes things
10253 very simple. This section describes how to read, write, and allocate
10258 '``alloca``' Instruction
10259 ^^^^^^^^^^^^^^^^^^^^^^^^
10266 <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result
10271 The '``alloca``' instruction allocates memory on the stack frame of the
10272 currently executing function, to be automatically released when this
10273 function returns to its caller. If the address space is not explicitly
10274 specified, the object is allocated in the alloca address space from the
10275 :ref:`datalayout string<langref_datalayout>`.
10280 The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements``
10281 bytes of memory on the runtime stack, returning a pointer of the
10282 appropriate type to the program. If "NumElements" is specified, it is
10283 the number of elements allocated, otherwise "NumElements" is defaulted
10286 If a constant alignment is specified, the value result of the
10287 allocation is guaranteed to be aligned to at least that boundary. The
10288 alignment may not be greater than ``1 << 32``.
10290 The alignment is only optional when parsing textual IR; for in-memory IR,
10291 it is always present. If not specified, the target can choose to align the
10292 allocation on any convenient boundary compatible with the type.
10294 '``type``' may be any sized type.
10296 Structs containing scalable vectors cannot be used in allocas unless all
10297 fields are the same scalable vector type (e.g. ``{<vscale x 2 x i32>,
10298 <vscale x 2 x i32>}`` contains the same type while ``{<vscale x 2 x i32>,
10299 <vscale x 2 x i64>}`` doesn't).
10304 Memory is allocated; a pointer is returned. The allocated memory is
10305 uninitialized, and loading from uninitialized memory produces an undefined
10306 value. The operation itself is undefined if there is insufficient stack
10307 space for the allocation.'``alloca``'d memory is automatically released
10308 when the function returns. The '``alloca``' instruction is commonly used
10309 to represent automatic variables that must have an address available. When
10310 the function returns (either with the ``ret`` or ``resume`` instructions),
10311 the memory is reclaimed. Allocating zero bytes is legal, but the returned
10312 pointer may not be unique. The order in which memory is allocated (ie.,
10313 which way the stack grows) is not specified.
10315 Note that '``alloca``' outside of the alloca address space from the
10316 :ref:`datalayout string<langref_datalayout>` is meaningful only if the
10317 target has assigned it a semantics.
10319 If the returned pointer is used by :ref:`llvm.lifetime.start <int_lifestart>`,
10320 the returned object is initially dead.
10321 See :ref:`llvm.lifetime.start <int_lifestart>` and
10322 :ref:`llvm.lifetime.end <int_lifeend>` for the precise semantics of
10323 lifetime-manipulating intrinsics.
10328 .. code-block:: llvm
10330 %ptr = alloca i32 ; yields ptr
10331 %ptr = alloca i32, i32 4 ; yields ptr
10332 %ptr = alloca i32, i32 4, align 1024 ; yields ptr
10333 %ptr = alloca i32, align 1024 ; yields ptr
10337 '``load``' Instruction
10338 ^^^^^^^^^^^^^^^^^^^^^^
10345 <result> = load [volatile] <ty>, ptr <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>]
10346 <result> = load atomic [volatile] <ty>, ptr <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>]
10347 !<nontemp_node> = !{ i32 1 }
10348 !<empty_node> = !{}
10349 !<deref_bytes_node> = !{ i64 <dereferenceable_bytes> }
10350 !<align_node> = !{ i64 <value_alignment> }
10355 The '``load``' instruction is used to read from memory.
10360 The argument to the ``load`` instruction specifies the memory address from which
10361 to load. The type specified must be a :ref:`first class <t_firstclass>` type of
10362 known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If
10363 the ``load`` is marked as ``volatile``, then the optimizer is not allowed to
10364 modify the number or order of execution of this ``load`` with other
10365 :ref:`volatile operations <volatile>`.
10367 If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering
10368 <ordering>` and optional ``syncscope("<target-scope>")`` argument. The
10369 ``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions.
10370 Atomic loads produce :ref:`defined <memmodel>` results when they may see
10371 multiple atomic stores. The type of the pointee must be an integer, pointer, or
10372 floating-point type whose bit width is a power of two greater than or equal to
10373 eight and less than or equal to a target-specific size limit. ``align`` must be
10374 explicitly specified on atomic loads, and the load has undefined behavior if the
10375 alignment is not set to a value which is at least the size in bytes of the
10376 pointee. ``!nontemporal`` does not have any defined semantics for atomic loads.
10378 The optional constant ``align`` argument specifies the alignment of the
10379 operation (that is, the alignment of the memory address). It is the
10380 responsibility of the code emitter to ensure that the alignment information is
10381 correct. Overestimating the alignment results in undefined behavior.
10382 Underestimating the alignment may produce less efficient code. An alignment of
10383 1 is always safe. The maximum possible alignment is ``1 << 32``. An alignment
10384 value higher than the size of the loaded type implies memory up to the
10385 alignment value bytes can be safely loaded without trapping in the default
10386 address space. Access of the high bytes can interfere with debugging tools, so
10387 should not be accessed if the function has the ``sanitize_thread`` or
10388 ``sanitize_address`` attributes.
10390 The alignment is only optional when parsing textual IR; for in-memory IR, it is
10391 always present. An omitted ``align`` argument means that the operation has the
10392 ABI alignment for the target.
10394 The optional ``!nontemporal`` metadata must reference a single
10395 metadata name ``<nontemp_node>`` corresponding to a metadata node with one
10396 ``i32`` entry of value 1. The existence of the ``!nontemporal``
10397 metadata on the instruction tells the optimizer and code generator
10398 that this load is not expected to be reused in the cache. The code
10399 generator may select special instructions to save cache bandwidth, such
10400 as the ``MOVNT`` instruction on x86.
10402 The optional ``!invariant.load`` metadata must reference a single
10403 metadata name ``<empty_node>`` corresponding to a metadata node with no
10404 entries. If a load instruction tagged with the ``!invariant.load``
10405 metadata is executed, the memory location referenced by the load has
10406 to contain the same value at all points in the program where the
10407 memory location is dereferenceable; otherwise, the behavior is
10410 The optional ``!invariant.group`` metadata must reference a single metadata name
10411 ``<empty_node>`` corresponding to a metadata node with no entries.
10412 See ``invariant.group`` metadata :ref:`invariant.group <md_invariant.group>`.
10414 The optional ``!nonnull`` metadata must reference a single
10415 metadata name ``<empty_node>`` corresponding to a metadata node with no
10416 entries. The existence of the ``!nonnull`` metadata on the
10417 instruction tells the optimizer that the value loaded is known to
10418 never be null. If the value is null at runtime, a poison value is returned
10419 instead. This is analogous to the ``nonnull`` attribute on parameters and
10420 return values. This metadata can only be applied to loads of a pointer type.
10422 The optional ``!dereferenceable`` metadata must reference a single metadata
10423 name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
10425 See ``dereferenceable`` metadata :ref:`dereferenceable <md_dereferenceable>`.
10427 The optional ``!dereferenceable_or_null`` metadata must reference a single
10428 metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
10430 See ``dereferenceable_or_null`` metadata :ref:`dereferenceable_or_null
10431 <md_dereferenceable_or_null>`.
10433 The optional ``!align`` metadata must reference a single metadata name
10434 ``<align_node>`` corresponding to a metadata node with one ``i64`` entry.
10435 The existence of the ``!align`` metadata on the instruction tells the
10436 optimizer that the value loaded is known to be aligned to a boundary specified
10437 by the integer value in the metadata node. The alignment must be a power of 2.
10438 This is analogous to the ''align'' attribute on parameters and return values.
10439 This metadata can only be applied to loads of a pointer type. If the returned
10440 value is not appropriately aligned at runtime, a poison value is returned
10443 The optional ``!noundef`` metadata must reference a single metadata name
10444 ``<empty_node>`` corresponding to a node with no entries. The existence of
10445 ``!noundef`` metadata on the instruction tells the optimizer that the value
10446 loaded is known to be :ref:`well defined <welldefinedvalues>`.
10447 If the value isn't well defined, the behavior is undefined. If the ``!noundef``
10448 metadata is combined with poison-generating metadata like ``!nonnull``,
10449 violation of that metadata constraint will also result in undefined behavior.
10454 The location of memory pointed to is loaded. If the value being loaded
10455 is of scalar type then the number of bytes read does not exceed the
10456 minimum number of bytes needed to hold all bits of the type. For
10457 example, loading an ``i24`` reads at most three bytes. When loading a
10458 value of a type like ``i20`` with a size that is not an integral number
10459 of bytes, the result is undefined if the value was not originally
10460 written using a store of the same type.
10461 If the value being loaded is of aggregate type, the bytes that correspond to
10462 padding may be accessed but are ignored, because it is impossible to observe
10463 padding from the loaded aggregate value.
10464 If ``<pointer>`` is not a well-defined value, the behavior is undefined.
10469 .. code-block:: llvm
10471 %ptr = alloca i32 ; yields ptr
10472 store i32 3, ptr %ptr ; yields void
10473 %val = load i32, ptr %ptr ; yields i32:val = i32 3
10477 '``store``' Instruction
10478 ^^^^^^^^^^^^^^^^^^^^^^^
10485 store [volatile] <ty> <value>, ptr <pointer>[, align <alignment>][, !nontemporal !<nontemp_node>][, !invariant.group !<empty_node>] ; yields void
10486 store atomic [volatile] <ty> <value>, ptr <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>] ; yields void
10487 !<nontemp_node> = !{ i32 1 }
10488 !<empty_node> = !{}
10493 The '``store``' instruction is used to write to memory.
10498 There are two arguments to the ``store`` instruction: a value to store and an
10499 address at which to store it. The type of the ``<pointer>`` operand must be a
10500 pointer to the :ref:`first class <t_firstclass>` type of the ``<value>``
10501 operand. If the ``store`` is marked as ``volatile``, then the optimizer is not
10502 allowed to modify the number or order of execution of this ``store`` with other
10503 :ref:`volatile operations <volatile>`. Only values of :ref:`first class
10504 <t_firstclass>` types of known size (i.e. not containing an :ref:`opaque
10505 structural type <t_opaque>`) can be stored.
10507 If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering
10508 <ordering>` and optional ``syncscope("<target-scope>")`` argument. The
10509 ``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions.
10510 Atomic loads produce :ref:`defined <memmodel>` results when they may see
10511 multiple atomic stores. The type of the pointee must be an integer, pointer, or
10512 floating-point type whose bit width is a power of two greater than or equal to
10513 eight and less than or equal to a target-specific size limit. ``align`` must be
10514 explicitly specified on atomic stores, and the store has undefined behavior if
10515 the alignment is not set to a value which is at least the size in bytes of the
10516 pointee. ``!nontemporal`` does not have any defined semantics for atomic stores.
10518 The optional constant ``align`` argument specifies the alignment of the
10519 operation (that is, the alignment of the memory address). It is the
10520 responsibility of the code emitter to ensure that the alignment information is
10521 correct. Overestimating the alignment results in undefined behavior.
10522 Underestimating the alignment may produce less efficient code. An alignment of
10523 1 is always safe. The maximum possible alignment is ``1 << 32``. An alignment
10524 value higher than the size of the loaded type implies memory up to the
10525 alignment value bytes can be safely loaded without trapping in the default
10526 address space. Access of the high bytes can interfere with debugging tools, so
10527 should not be accessed if the function has the ``sanitize_thread`` or
10528 ``sanitize_address`` attributes.
10530 The alignment is only optional when parsing textual IR; for in-memory IR, it is
10531 always present. An omitted ``align`` argument means that the operation has the
10532 ABI alignment for the target.
10534 The optional ``!nontemporal`` metadata must reference a single metadata
10535 name ``<nontemp_node>`` corresponding to a metadata node with one ``i32`` entry
10536 of value 1. The existence of the ``!nontemporal`` metadata on the instruction
10537 tells the optimizer and code generator that this load is not expected to
10538 be reused in the cache. The code generator may select special
10539 instructions to save cache bandwidth, such as the ``MOVNT`` instruction on
10542 The optional ``!invariant.group`` metadata must reference a
10543 single metadata name ``<empty_node>``. See ``invariant.group`` metadata.
10548 The contents of memory are updated to contain ``<value>`` at the
10549 location specified by the ``<pointer>`` operand. If ``<value>`` is
10550 of scalar type then the number of bytes written does not exceed the
10551 minimum number of bytes needed to hold all bits of the type. For
10552 example, storing an ``i24`` writes at most three bytes. When writing a
10553 value of a type like ``i20`` with a size that is not an integral number
10554 of bytes, it is unspecified what happens to the extra bits that do not
10555 belong to the type, but they will typically be overwritten.
10556 If ``<value>`` is of aggregate type, padding is filled with
10557 :ref:`undef <undefvalues>`.
10558 If ``<pointer>`` is not a well-defined value, the behavior is undefined.
10563 .. code-block:: llvm
10565 %ptr = alloca i32 ; yields ptr
10566 store i32 3, ptr %ptr ; yields void
10567 %val = load i32, ptr %ptr ; yields i32:val = i32 3
10571 '``fence``' Instruction
10572 ^^^^^^^^^^^^^^^^^^^^^^^
10579 fence [syncscope("<target-scope>")] <ordering> ; yields void
10584 The '``fence``' instruction is used to introduce happens-before edges
10585 between operations.
10590 '``fence``' instructions take an :ref:`ordering <ordering>` argument which
10591 defines what *synchronizes-with* edges they add. They can only be given
10592 ``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings.
10597 A fence A which has (at least) ``release`` ordering semantics
10598 *synchronizes with* a fence B with (at least) ``acquire`` ordering
10599 semantics if and only if there exist atomic operations X and Y, both
10600 operating on some atomic object M, such that A is sequenced before X, X
10601 modifies M (either directly or through some side effect of a sequence
10602 headed by X), Y is sequenced before B, and Y observes M. This provides a
10603 *happens-before* dependency between A and B. Rather than an explicit
10604 ``fence``, one (but not both) of the atomic operations X or Y might
10605 provide a ``release`` or ``acquire`` (resp.) ordering constraint and
10606 still *synchronize-with* the explicit ``fence`` and establish the
10607 *happens-before* edge.
10609 A ``fence`` which has ``seq_cst`` ordering, in addition to having both
10610 ``acquire`` and ``release`` semantics specified above, participates in
10611 the global program order of other ``seq_cst`` operations and/or fences.
10613 A ``fence`` instruction can also take an optional
10614 ":ref:`syncscope <syncscope>`" argument.
10619 .. code-block:: text
10621 fence acquire ; yields void
10622 fence syncscope("singlethread") seq_cst ; yields void
10623 fence syncscope("agent") seq_cst ; yields void
10627 '``cmpxchg``' Instruction
10628 ^^^^^^^^^^^^^^^^^^^^^^^^^
10635 cmpxchg [weak] [volatile] ptr <pointer>, <ty> <cmp>, <ty> <new> [syncscope("<target-scope>")] <success ordering> <failure ordering>[, align <alignment>] ; yields { ty, i1 }
10640 The '``cmpxchg``' instruction is used to atomically modify memory. It
10641 loads a value in memory and compares it to a given value. If they are
10642 equal, it tries to store a new value into the memory.
10647 There are three arguments to the '``cmpxchg``' instruction: an address
10648 to operate on, a value to compare to the value currently be at that
10649 address, and a new value to place at that address if the compared values
10650 are equal. The type of '<cmp>' must be an integer or pointer type whose
10651 bit width is a power of two greater than or equal to eight and less
10652 than or equal to a target-specific size limit. '<cmp>' and '<new>' must
10653 have the same type, and the type of '<pointer>' must be a pointer to
10654 that type. If the ``cmpxchg`` is marked as ``volatile``, then the
10655 optimizer is not allowed to modify the number or order of execution of
10656 this ``cmpxchg`` with other :ref:`volatile operations <volatile>`.
10658 The success and failure :ref:`ordering <ordering>` arguments specify how this
10659 ``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters
10660 must be at least ``monotonic``, the failure ordering cannot be either
10661 ``release`` or ``acq_rel``.
10663 A ``cmpxchg`` instruction can also take an optional
10664 ":ref:`syncscope <syncscope>`" argument.
10666 The alignment must be a power of two greater or equal to the size of the
10669 The alignment is only optional when parsing textual IR; for in-memory IR, it is
10670 always present. If unspecified, the alignment is assumed to be equal to the
10671 size of the '<value>' type. Note that this default alignment assumption is
10672 different from the alignment used for the load/store instructions when align
10675 The pointer passed into cmpxchg must have alignment greater than or
10676 equal to the size in memory of the operand.
10681 The contents of memory at the location specified by the '``<pointer>``' operand
10682 is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is
10683 written to the location. The original value at the location is returned,
10684 together with a flag indicating success (true) or failure (false).
10686 If the cmpxchg operation is marked as ``weak`` then a spurious failure is
10687 permitted: the operation may not write ``<new>`` even if the comparison
10690 If the cmpxchg operation is strong (the default), the i1 value is 1 if and only
10691 if the value loaded equals ``cmp``.
10693 A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of
10694 identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic
10695 load with an ordering parameter determined the second ordering parameter.
10700 .. code-block:: llvm
10703 %orig = load atomic i32, ptr %ptr unordered, align 4 ; yields i32
10707 %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop]
10708 %squared = mul i32 %cmp, %cmp
10709 %val_success = cmpxchg ptr %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 }
10710 %value_loaded = extractvalue { i32, i1 } %val_success, 0
10711 %success = extractvalue { i32, i1 } %val_success, 1
10712 br i1 %success, label %done, label %loop
10719 '``atomicrmw``' Instruction
10720 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10727 atomicrmw [volatile] <operation> ptr <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering>[, align <alignment>] ; yields ty
10732 The '``atomicrmw``' instruction is used to atomically modify memory.
10737 There are three arguments to the '``atomicrmw``' instruction: an
10738 operation to apply, an address whose value to modify, an argument to the
10739 operation. The operation must be one of the following keywords:
10759 For most of these operations, the type of '<value>' must be an integer
10760 type whose bit width is a power of two greater than or equal to eight
10761 and less than or equal to a target-specific size limit. For xchg, this
10762 may also be a floating point or a pointer type with the same size constraints
10763 as integers. For fadd/fsub/fmax/fmin, this must be a floating point type. The
10764 type of the '``<pointer>``' operand must be a pointer to that type. If
10765 the ``atomicrmw`` is marked as ``volatile``, then the optimizer is not
10766 allowed to modify the number or order of execution of this
10767 ``atomicrmw`` with other :ref:`volatile operations <volatile>`.
10769 The alignment must be a power of two greater or equal to the size of the
10772 The alignment is only optional when parsing textual IR; for in-memory IR, it is
10773 always present. If unspecified, the alignment is assumed to be equal to the
10774 size of the '<value>' type. Note that this default alignment assumption is
10775 different from the alignment used for the load/store instructions when align
10778 A ``atomicrmw`` instruction can also take an optional
10779 ":ref:`syncscope <syncscope>`" argument.
10784 The contents of memory at the location specified by the '``<pointer>``'
10785 operand are atomically read, modified, and written back. The original
10786 value at the location is returned. The modification is specified by the
10787 operation argument:
10789 - xchg: ``*ptr = val``
10790 - add: ``*ptr = *ptr + val``
10791 - sub: ``*ptr = *ptr - val``
10792 - and: ``*ptr = *ptr & val``
10793 - nand: ``*ptr = ~(*ptr & val)``
10794 - or: ``*ptr = *ptr | val``
10795 - xor: ``*ptr = *ptr ^ val``
10796 - max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison)
10797 - min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison)
10798 - umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned comparison)
10799 - umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned comparison)
10800 - fadd: ``*ptr = *ptr + val`` (using floating point arithmetic)
10801 - fsub: ``*ptr = *ptr - val`` (using floating point arithmetic)
10802 - fmax: ``*ptr = maxnum(*ptr, val)`` (match the `llvm.maxnum.*`` intrinsic)
10803 - fmin: ``*ptr = minnum(*ptr, val)`` (match the `llvm.minnum.*`` intrinsic)
10804 - uinc_wrap: ``*ptr = (*ptr u>= val) ? 0 : (*ptr + 1)`` (increment value with wraparound to zero when incremented above input value)
10805 - udec_wrap: ``*ptr = ((*ptr == 0) || (*ptr u> val)) ? val : (*ptr - 1)`` (decrement with wraparound to input value when decremented below zero).
10811 .. code-block:: llvm
10813 %old = atomicrmw add ptr %ptr, i32 1 acquire ; yields i32
10815 .. _i_getelementptr:
10817 '``getelementptr``' Instruction
10818 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10825 <result> = getelementptr <ty>, ptr <ptrval>{, [inrange] <ty> <idx>}*
10826 <result> = getelementptr inbounds <ty>, ptr <ptrval>{, [inrange] <ty> <idx>}*
10827 <result> = getelementptr <ty>, <N x ptr> <ptrval>, [inrange] <vector index type> <idx>
10832 The '``getelementptr``' instruction is used to get the address of a
10833 subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs
10834 address calculation only and does not access memory. The instruction can also
10835 be used to calculate a vector of such addresses.
10840 The first argument is always a type used as the basis for the calculations.
10841 The second argument is always a pointer or a vector of pointers, and is the
10842 base address to start from. The remaining arguments are indices
10843 that indicate which of the elements of the aggregate object are indexed.
10844 The interpretation of each index is dependent on the type being indexed
10845 into. The first index always indexes the pointer value given as the
10846 second argument, the second index indexes a value of the type pointed to
10847 (not necessarily the value directly pointed to, since the first index
10848 can be non-zero), etc. The first type indexed into must be a pointer
10849 value, subsequent types can be arrays, vectors, and structs. Note that
10850 subsequent types being indexed into can never be pointers, since that
10851 would require loading the pointer before continuing calculation.
10853 The type of each index argument depends on the type it is indexing into.
10854 When indexing into a (optionally packed) structure, only ``i32`` integer
10855 **constants** are allowed (when using a vector of indices they must all
10856 be the **same** ``i32`` integer constant). When indexing into an array,
10857 pointer or vector, integers of any width are allowed, and they are not
10858 required to be constant. These integers are treated as signed values
10861 For example, let's consider a C code fragment and how it gets compiled
10877 int *foo(struct ST *s) {
10878 return &s[1].Z.B[5][13];
10881 The LLVM code generated by Clang is approximately:
10883 .. code-block:: llvm
10885 %struct.RT = type { i8, [10 x [20 x i32]], i8 }
10886 %struct.ST = type { i32, double, %struct.RT }
10888 define ptr @foo(ptr %s) {
10890 %arrayidx = getelementptr inbounds %struct.ST, ptr %s, i64 1, i32 2, i32 1, i64 5, i64 13
10897 In the example above, the first index is indexing into the
10898 '``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``'
10899 = '``{ i32, double, %struct.RT }``' type, a structure. The second index
10900 indexes into the third element of the structure, yielding a
10901 '``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another
10902 structure. The third index indexes into the second element of the
10903 structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two
10904 dimensions of the array are subscripted into, yielding an '``i32``'
10905 type. The '``getelementptr``' instruction returns a pointer to this
10908 Note that it is perfectly legal to index partially through a structure,
10909 returning a pointer to an inner element. Because of this, the LLVM code
10910 for the given testcase is equivalent to:
10912 .. code-block:: llvm
10914 define ptr @foo(ptr %s) {
10915 %t1 = getelementptr %struct.ST, ptr %s, i32 1
10916 %t2 = getelementptr %struct.ST, ptr %t1, i32 0, i32 2
10917 %t3 = getelementptr %struct.RT, ptr %t2, i32 0, i32 1
10918 %t4 = getelementptr [10 x [20 x i32]], ptr %t3, i32 0, i32 5
10919 %t5 = getelementptr [20 x i32], ptr %t4, i32 0, i32 13
10923 If the ``inbounds`` keyword is present, the result value of the
10924 ``getelementptr`` is a :ref:`poison value <poisonvalues>` if one of the
10925 following rules is violated:
10927 * The base pointer has an *in bounds* address of an allocated object, which
10928 means that it points into an allocated object, or to its end. The only
10929 *in bounds* address for a null pointer in the default address-space is the
10930 null pointer itself.
10931 * If the type of an index is larger than the pointer index type, the
10932 truncation to the pointer index type preserves the signed value.
10933 * The multiplication of an index by the type size does not wrap the pointer
10934 index type in a signed sense (``nsw``).
10935 * The successive addition of offsets (without adding the base address) does
10936 not wrap the pointer index type in a signed sense (``nsw``).
10937 * The successive addition of the current address, interpreted as an unsigned
10938 number, and an offset, interpreted as a signed number, does not wrap the
10939 unsigned address space and remains *in bounds* of the allocated object.
10940 As a corollary, if the added offset is non-negative, the addition does not
10941 wrap in an unsigned sense (``nuw``).
10942 * In cases where the base is a vector of pointers, the ``inbounds`` keyword
10943 applies to each of the computations element-wise.
10945 These rules are based on the assumption that no allocated object may cross
10946 the unsigned address space boundary, and no allocated object may be larger
10947 than half the pointer index type space.
10949 If the ``inbounds`` keyword is not present, the offsets are added to the
10950 base address with silently-wrapping two's complement arithmetic. If the
10951 offsets have a different width from the pointer's index type, they are
10952 sign-extended or truncated to the width of the pointer's index type. The result
10953 value of the ``getelementptr`` may be outside the object pointed to by the base
10954 pointer. The result value may not necessarily be used to access memory
10955 though, even if it happens to point into allocated storage. See the
10956 :ref:`Pointer Aliasing Rules <pointeraliasing>` section for more
10959 If the ``inrange`` keyword is present before any index, loading from or
10960 storing to any pointer derived from the ``getelementptr`` has undefined
10961 behavior if the load or store would access memory outside of the bounds of
10962 the element selected by the index marked as ``inrange``. The result of a
10963 pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations
10964 involving memory) involving a pointer derived from a ``getelementptr`` with
10965 the ``inrange`` keyword is undefined, with the exception of comparisons
10966 in the case where both operands are in the range of the element selected
10967 by the ``inrange`` keyword, inclusive of the address one past the end of
10968 that element. Note that the ``inrange`` keyword is currently only allowed
10969 in constant ``getelementptr`` expressions.
10971 The getelementptr instruction is often confusing. For some more insight
10972 into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`.
10977 .. code-block:: llvm
10979 %aptr = getelementptr {i32, [12 x i8]}, ptr %saptr, i64 0, i32 1
10980 %vptr = getelementptr {i32, <2 x i8>}, ptr %svptr, i64 0, i32 1, i32 1
10981 %eptr = getelementptr [12 x i8], ptr %aptr, i64 0, i32 1
10982 %iptr = getelementptr [10 x i32], ptr @arr, i16 0, i16 0
10984 Vector of pointers:
10985 """""""""""""""""""
10987 The ``getelementptr`` returns a vector of pointers, instead of a single address,
10988 when one or more of its arguments is a vector. In such cases, all vector
10989 arguments should have the same number of elements, and every scalar argument
10990 will be effectively broadcast into a vector during address calculation.
10992 .. code-block:: llvm
10994 ; All arguments are vectors:
10995 ; A[i] = ptrs[i] + offsets[i]*sizeof(i8)
10996 %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets
10998 ; Add the same scalar offset to each pointer of a vector:
10999 ; A[i] = ptrs[i] + offset*sizeof(i8)
11000 %A = getelementptr i8, <4 x ptr> %ptrs, i64 %offset
11002 ; Add distinct offsets to the same pointer:
11003 ; A[i] = ptr + offsets[i]*sizeof(i8)
11004 %A = getelementptr i8, ptr %ptr, <4 x i64> %offsets
11006 ; In all cases described above the type of the result is <4 x ptr>
11008 The two following instructions are equivalent:
11010 .. code-block:: llvm
11012 getelementptr %struct.ST, <4 x ptr> %s, <4 x i64> %ind1,
11013 <4 x i32> <i32 2, i32 2, i32 2, i32 2>,
11014 <4 x i32> <i32 1, i32 1, i32 1, i32 1>,
11016 <4 x i64> <i64 13, i64 13, i64 13, i64 13>
11018 getelementptr %struct.ST, <4 x ptr> %s, <4 x i64> %ind1,
11019 i32 2, i32 1, <4 x i32> %ind4, i64 13
11021 Let's look at the C code, where the vector version of ``getelementptr``
11026 // Let's assume that we vectorize the following loop:
11027 double *A, *B; int *C;
11028 for (int i = 0; i < size; ++i) {
11032 .. code-block:: llvm
11034 ; get pointers for 8 elements from array B
11035 %ptrs = getelementptr double, ptr %B, <8 x i32> %C
11036 ; load 8 elements from array B into A
11037 %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x ptr> %ptrs,
11038 i32 8, <8 x i1> %mask, <8 x double> %passthru)
11040 Conversion Operations
11041 ---------------------
11043 The instructions in this category are the conversion instructions
11044 (casting) which all take a single operand and a type. They perform
11045 various bit conversions on the operand.
11049 '``trunc .. to``' Instruction
11050 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11057 <result> = trunc <ty> <value> to <ty2> ; yields ty2
11062 The '``trunc``' instruction truncates its operand to the type ``ty2``.
11067 The '``trunc``' instruction takes a value to trunc, and a type to trunc
11068 it to. Both types must be of :ref:`integer <t_integer>` types, or vectors
11069 of the same number of integers. The bit size of the ``value`` must be
11070 larger than the bit size of the destination type, ``ty2``. Equal sized
11071 types are not allowed.
11076 The '``trunc``' instruction truncates the high order bits in ``value``
11077 and converts the remaining bits to ``ty2``. Since the source size must
11078 be larger than the destination size, ``trunc`` cannot be a *no-op cast*.
11079 It will always truncate bits.
11084 .. code-block:: llvm
11086 %X = trunc i32 257 to i8 ; yields i8:1
11087 %Y = trunc i32 123 to i1 ; yields i1:true
11088 %Z = trunc i32 122 to i1 ; yields i1:false
11089 %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7>
11093 '``zext .. to``' Instruction
11094 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11101 <result> = zext <ty> <value> to <ty2> ; yields ty2
11106 The '``zext``' instruction zero extends its operand to type ``ty2``.
11111 The '``zext``' instruction takes a value to cast, and a type to cast it
11112 to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
11113 the same number of integers. The bit size of the ``value`` must be
11114 smaller than the bit size of the destination type, ``ty2``.
11119 The ``zext`` fills the high order bits of the ``value`` with zero bits
11120 until it reaches the size of the destination type, ``ty2``.
11122 When zero extending from i1, the result will always be either 0 or 1.
11127 .. code-block:: llvm
11129 %X = zext i32 257 to i64 ; yields i64:257
11130 %Y = zext i1 true to i32 ; yields i32:1
11131 %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
11135 '``sext .. to``' Instruction
11136 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11143 <result> = sext <ty> <value> to <ty2> ; yields ty2
11148 The '``sext``' sign extends ``value`` to the type ``ty2``.
11153 The '``sext``' instruction takes a value to cast, and a type to cast it
11154 to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
11155 the same number of integers. The bit size of the ``value`` must be
11156 smaller than the bit size of the destination type, ``ty2``.
11161 The '``sext``' instruction performs a sign extension by copying the sign
11162 bit (highest order bit) of the ``value`` until it reaches the bit size
11163 of the type ``ty2``.
11165 When sign extending from i1, the extension always results in -1 or 0.
11170 .. code-block:: llvm
11172 %X = sext i8 -1 to i16 ; yields i16 :65535
11173 %Y = sext i1 true to i32 ; yields i32:-1
11174 %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
11176 '``fptrunc .. to``' Instruction
11177 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11184 <result> = fptrunc <ty> <value> to <ty2> ; yields ty2
11189 The '``fptrunc``' instruction truncates ``value`` to type ``ty2``.
11194 The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>`
11195 value to cast and a :ref:`floating-point <t_floating>` type to cast it to.
11196 The size of ``value`` must be larger than the size of ``ty2``. This
11197 implies that ``fptrunc`` cannot be used to make a *no-op cast*.
11202 The '``fptrunc``' instruction casts a ``value`` from a larger
11203 :ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
11204 <t_floating>` type.
11205 This instruction is assumed to execute in the default :ref:`floating-point
11206 environment <floatenv>`.
11211 .. code-block:: llvm
11213 %X = fptrunc double 16777217.0 to float ; yields float:16777216.0
11214 %Y = fptrunc double 1.0E+300 to half ; yields half:+infinity
11216 '``fpext .. to``' Instruction
11217 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11224 <result> = fpext <ty> <value> to <ty2> ; yields ty2
11229 The '``fpext``' extends a floating-point ``value`` to a larger floating-point
11235 The '``fpext``' instruction takes a :ref:`floating-point <t_floating>`
11236 ``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it
11237 to. The source type must be smaller than the destination type.
11242 The '``fpext``' instruction extends the ``value`` from a smaller
11243 :ref:`floating-point <t_floating>` type to a larger :ref:`floating-point
11244 <t_floating>` type. The ``fpext`` cannot be used to make a
11245 *no-op cast* because it always changes bits. Use ``bitcast`` to make a
11246 *no-op cast* for a floating-point cast.
11251 .. code-block:: llvm
11253 %X = fpext float 3.125 to double ; yields double:3.125000e+00
11254 %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000
11256 '``fptoui .. to``' Instruction
11257 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11264 <result> = fptoui <ty> <value> to <ty2> ; yields ty2
11269 The '``fptoui``' converts a floating-point ``value`` to its unsigned
11270 integer equivalent of type ``ty2``.
11275 The '``fptoui``' instruction takes a value to cast, which must be a
11276 scalar or vector :ref:`floating-point <t_floating>` value, and a type to
11277 cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
11278 ``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
11279 type with the same number of elements as ``ty``
11284 The '``fptoui``' instruction converts its :ref:`floating-point
11285 <t_floating>` operand into the nearest (rounding towards zero)
11286 unsigned integer value. If the value cannot fit in ``ty2``, the result
11287 is a :ref:`poison value <poisonvalues>`.
11292 .. code-block:: llvm
11294 %X = fptoui double 123.0 to i32 ; yields i32:123
11295 %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1
11296 %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1
11298 '``fptosi .. to``' Instruction
11299 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11306 <result> = fptosi <ty> <value> to <ty2> ; yields ty2
11311 The '``fptosi``' instruction converts :ref:`floating-point <t_floating>`
11312 ``value`` to type ``ty2``.
11317 The '``fptosi``' instruction takes a value to cast, which must be a
11318 scalar or vector :ref:`floating-point <t_floating>` value, and a type to
11319 cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
11320 ``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
11321 type with the same number of elements as ``ty``
11326 The '``fptosi``' instruction converts its :ref:`floating-point
11327 <t_floating>` operand into the nearest (rounding towards zero)
11328 signed integer value. If the value cannot fit in ``ty2``, the result
11329 is a :ref:`poison value <poisonvalues>`.
11334 .. code-block:: llvm
11336 %X = fptosi double -123.0 to i32 ; yields i32:-123
11337 %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1
11338 %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1
11340 '``uitofp .. to``' Instruction
11341 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11348 <result> = uitofp <ty> <value> to <ty2> ; yields ty2
11353 The '``uitofp``' instruction regards ``value`` as an unsigned integer
11354 and converts that value to the ``ty2`` type.
11359 The '``uitofp``' instruction takes a value to cast, which must be a
11360 scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
11361 ``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
11362 ``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
11363 type with the same number of elements as ``ty``
11368 The '``uitofp``' instruction interprets its operand as an unsigned
11369 integer quantity and converts it to the corresponding floating-point
11370 value. If the value cannot be exactly represented, it is rounded using
11371 the default rounding mode.
11377 .. code-block:: llvm
11379 %X = uitofp i32 257 to float ; yields float:257.0
11380 %Y = uitofp i8 -1 to double ; yields double:255.0
11382 '``sitofp .. to``' Instruction
11383 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11390 <result> = sitofp <ty> <value> to <ty2> ; yields ty2
11395 The '``sitofp``' instruction regards ``value`` as a signed integer and
11396 converts that value to the ``ty2`` type.
11401 The '``sitofp``' instruction takes a value to cast, which must be a
11402 scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
11403 ``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
11404 ``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
11405 type with the same number of elements as ``ty``
11410 The '``sitofp``' instruction interprets its operand as a signed integer
11411 quantity and converts it to the corresponding floating-point value. If the
11412 value cannot be exactly represented, it is rounded using the default rounding
11418 .. code-block:: llvm
11420 %X = sitofp i32 257 to float ; yields float:257.0
11421 %Y = sitofp i8 -1 to double ; yields double:-1.0
11425 '``ptrtoint .. to``' Instruction
11426 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11433 <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2
11438 The '``ptrtoint``' instruction converts the pointer or a vector of
11439 pointers ``value`` to the integer (or vector of integers) type ``ty2``.
11444 The '``ptrtoint``' instruction takes a ``value`` to cast, which must be
11445 a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
11446 type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
11447 a vector of integers type.
11452 The '``ptrtoint``' instruction converts ``value`` to integer type
11453 ``ty2`` by interpreting the pointer value as an integer and either
11454 truncating or zero extending that value to the size of the integer type.
11455 If ``value`` is smaller than ``ty2`` then a zero extension is done. If
11456 ``value`` is larger than ``ty2`` then a truncation is done. If they are
11457 the same size, then nothing is done (*no-op cast*) other than a type
11463 .. code-block:: llvm
11465 %X = ptrtoint ptr %P to i8 ; yields truncation on 32-bit architecture
11466 %Y = ptrtoint ptr %P to i64 ; yields zero extension on 32-bit architecture
11467 %Z = ptrtoint <4 x ptr> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
11471 '``inttoptr .. to``' Instruction
11472 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11479 <result> = inttoptr <ty> <value> to <ty2>[, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>] ; yields ty2
11484 The '``inttoptr``' instruction converts an integer ``value`` to a
11485 pointer type, ``ty2``.
11490 The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to
11491 cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>`
11494 The optional ``!dereferenceable`` metadata must reference a single metadata
11495 name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
11497 See ``dereferenceable`` metadata.
11499 The optional ``!dereferenceable_or_null`` metadata must reference a single
11500 metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
11502 See ``dereferenceable_or_null`` metadata.
11507 The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by
11508 applying either a zero extension or a truncation depending on the size
11509 of the integer ``value``. If ``value`` is larger than the size of a
11510 pointer then a truncation is done. If ``value`` is smaller than the size
11511 of a pointer then a zero extension is done. If they are the same size,
11512 nothing is done (*no-op cast*).
11517 .. code-block:: llvm
11519 %X = inttoptr i32 255 to ptr ; yields zero extension on 64-bit architecture
11520 %Y = inttoptr i32 255 to ptr ; yields no-op on 32-bit architecture
11521 %Z = inttoptr i64 0 to ptr ; yields truncation on 32-bit architecture
11522 %Z = inttoptr <4 x i32> %G to <4 x ptr>; yields truncation of vector G to four pointers
11526 '``bitcast .. to``' Instruction
11527 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11534 <result> = bitcast <ty> <value> to <ty2> ; yields ty2
11539 The '``bitcast``' instruction converts ``value`` to type ``ty2`` without
11545 The '``bitcast``' instruction takes a value to cast, which must be a
11546 non-aggregate first class value, and a type to cast it to, which must
11547 also be a non-aggregate :ref:`first class <t_firstclass>` type. The
11548 bit sizes of ``value`` and the destination type, ``ty2``, must be
11549 identical. If the source type is a pointer, the destination type must
11550 also be a pointer of the same size. This instruction supports bitwise
11551 conversion of vectors to integers and to vectors of other types (as
11552 long as they have the same size).
11557 The '``bitcast``' instruction converts ``value`` to type ``ty2``. It
11558 is always a *no-op cast* because no bits change with this
11559 conversion. The conversion is done as if the ``value`` had been stored
11560 to memory and read back as type ``ty2``. Pointer (or vector of
11561 pointers) types may only be converted to other pointer (or vector of
11562 pointers) types with the same address space through this instruction.
11563 To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>`
11564 or :ref:`ptrtoint <i_ptrtoint>` instructions first.
11566 There is a caveat for bitcasts involving vector types in relation to
11567 endianess. For example ``bitcast <2 x i8> <value> to i16`` puts element zero
11568 of the vector in the least significant bits of the i16 for little-endian while
11569 element zero ends up in the most significant bits for big-endian.
11574 .. code-block:: text
11576 %X = bitcast i8 255 to i8 ; yields i8 :-1
11577 %Y = bitcast i32* %x to i16* ; yields i16*:%x
11578 %Z = bitcast <2 x i32> %V to i64; ; yields i64: %V (depends on endianess)
11579 %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
11581 .. _i_addrspacecast:
11583 '``addrspacecast .. to``' Instruction
11584 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11591 <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2
11596 The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in
11597 address space ``n`` to type ``pty2`` in address space ``m``.
11602 The '``addrspacecast``' instruction takes a pointer or vector of pointer value
11603 to cast and a pointer type to cast it to, which must have a different
11609 The '``addrspacecast``' instruction converts the pointer value
11610 ``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex
11611 value modification, depending on the target and the address space
11612 pair. Pointer conversions within the same address space must be
11613 performed with the ``bitcast`` instruction. Note that if the address
11614 space conversion produces a dereferenceable result then both result
11615 and operand refer to the same memory location. The conversion must
11616 have no side effects, and must not capture the value of the pointer.
11618 If the source is :ref:`poison <poisonvalues>`, the result is
11619 :ref:`poison <poisonvalues>`.
11621 If the source is not :ref:`poison <poisonvalues>`, and both source and
11622 destination are :ref:`integral pointers <nointptrtype>`, and the
11623 result pointer is dereferenceable, the cast is assumed to be
11624 reversible (i.e. casting the result back to the original address space
11625 should yield the original bit pattern).
11630 .. code-block:: llvm
11632 %X = addrspacecast ptr %x to ptr addrspace(1)
11633 %Y = addrspacecast ptr addrspace(1) %y to ptr addrspace(2)
11634 %Z = addrspacecast <4 x ptr> %z to <4 x ptr addrspace(3)>
11641 The instructions in this category are the "miscellaneous" instructions,
11642 which defy better classification.
11646 '``icmp``' Instruction
11647 ^^^^^^^^^^^^^^^^^^^^^^
11654 <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
11659 The '``icmp``' instruction returns a boolean value or a vector of
11660 boolean values based on comparison of its two integer, integer vector,
11661 pointer, or pointer vector operands.
11666 The '``icmp``' instruction takes three operands. The first operand is
11667 the condition code indicating the kind of comparison to perform. It is
11668 not a value, just a keyword. The possible condition codes are:
11673 #. ``ne``: not equal
11674 #. ``ugt``: unsigned greater than
11675 #. ``uge``: unsigned greater or equal
11676 #. ``ult``: unsigned less than
11677 #. ``ule``: unsigned less or equal
11678 #. ``sgt``: signed greater than
11679 #. ``sge``: signed greater or equal
11680 #. ``slt``: signed less than
11681 #. ``sle``: signed less or equal
11683 The remaining two arguments must be :ref:`integer <t_integer>` or
11684 :ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They
11685 must also be identical types.
11690 The '``icmp``' compares ``op1`` and ``op2`` according to the condition
11691 code given as ``cond``. The comparison performed always yields either an
11692 :ref:`i1 <t_integer>` or vector of ``i1`` result, as follows:
11694 .. _icmp_md_cc_sem:
11696 #. ``eq``: yields ``true`` if the operands are equal, ``false``
11697 otherwise. No sign interpretation is necessary or performed.
11698 #. ``ne``: yields ``true`` if the operands are unequal, ``false``
11699 otherwise. No sign interpretation is necessary or performed.
11700 #. ``ugt``: interprets the operands as unsigned values and yields
11701 ``true`` if ``op1`` is greater than ``op2``.
11702 #. ``uge``: interprets the operands as unsigned values and yields
11703 ``true`` if ``op1`` is greater than or equal to ``op2``.
11704 #. ``ult``: interprets the operands as unsigned values and yields
11705 ``true`` if ``op1`` is less than ``op2``.
11706 #. ``ule``: interprets the operands as unsigned values and yields
11707 ``true`` if ``op1`` is less than or equal to ``op2``.
11708 #. ``sgt``: interprets the operands as signed values and yields ``true``
11709 if ``op1`` is greater than ``op2``.
11710 #. ``sge``: interprets the operands as signed values and yields ``true``
11711 if ``op1`` is greater than or equal to ``op2``.
11712 #. ``slt``: interprets the operands as signed values and yields ``true``
11713 if ``op1`` is less than ``op2``.
11714 #. ``sle``: interprets the operands as signed values and yields ``true``
11715 if ``op1`` is less than or equal to ``op2``.
11717 If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
11718 are compared as if they were integers.
11720 If the operands are integer vectors, then they are compared element by
11721 element. The result is an ``i1`` vector with the same number of elements
11722 as the values being compared. Otherwise, the result is an ``i1``.
11727 .. code-block:: text
11729 <result> = icmp eq i32 4, 5 ; yields: result=false
11730 <result> = icmp ne ptr %X, %X ; yields: result=false
11731 <result> = icmp ult i16 4, 5 ; yields: result=true
11732 <result> = icmp sgt i16 4, 5 ; yields: result=false
11733 <result> = icmp ule i16 -4, 5 ; yields: result=false
11734 <result> = icmp sge i16 4, 5 ; yields: result=false
11738 '``fcmp``' Instruction
11739 ^^^^^^^^^^^^^^^^^^^^^^
11746 <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
11751 The '``fcmp``' instruction returns a boolean value or vector of boolean
11752 values based on comparison of its operands.
11754 If the operands are floating-point scalars, then the result type is a
11755 boolean (:ref:`i1 <t_integer>`).
11757 If the operands are floating-point vectors, then the result type is a
11758 vector of boolean with the same number of elements as the operands being
11764 The '``fcmp``' instruction takes three operands. The first operand is
11765 the condition code indicating the kind of comparison to perform. It is
11766 not a value, just a keyword. The possible condition codes are:
11768 #. ``false``: no comparison, always returns false
11769 #. ``oeq``: ordered and equal
11770 #. ``ogt``: ordered and greater than
11771 #. ``oge``: ordered and greater than or equal
11772 #. ``olt``: ordered and less than
11773 #. ``ole``: ordered and less than or equal
11774 #. ``one``: ordered and not equal
11775 #. ``ord``: ordered (no nans)
11776 #. ``ueq``: unordered or equal
11777 #. ``ugt``: unordered or greater than
11778 #. ``uge``: unordered or greater than or equal
11779 #. ``ult``: unordered or less than
11780 #. ``ule``: unordered or less than or equal
11781 #. ``une``: unordered or not equal
11782 #. ``uno``: unordered (either nans)
11783 #. ``true``: no comparison, always returns true
11785 *Ordered* means that neither operand is a QNAN while *unordered* means
11786 that either operand may be a QNAN.
11788 Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point
11789 <t_floating>` type or a :ref:`vector <t_vector>` of floating-point type.
11790 They must have identical types.
11795 The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the
11796 condition code given as ``cond``. If the operands are vectors, then the
11797 vectors are compared element by element. Each comparison performed
11798 always yields an :ref:`i1 <t_integer>` result, as follows:
11800 #. ``false``: always yields ``false``, regardless of operands.
11801 #. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1``
11802 is equal to ``op2``.
11803 #. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1``
11804 is greater than ``op2``.
11805 #. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1``
11806 is greater than or equal to ``op2``.
11807 #. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1``
11808 is less than ``op2``.
11809 #. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1``
11810 is less than or equal to ``op2``.
11811 #. ``one``: yields ``true`` if both operands are not a QNAN and ``op1``
11812 is not equal to ``op2``.
11813 #. ``ord``: yields ``true`` if both operands are not a QNAN.
11814 #. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is
11816 #. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is
11817 greater than ``op2``.
11818 #. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is
11819 greater than or equal to ``op2``.
11820 #. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is
11822 #. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is
11823 less than or equal to ``op2``.
11824 #. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is
11825 not equal to ``op2``.
11826 #. ``uno``: yields ``true`` if either operand is a QNAN.
11827 #. ``true``: always yields ``true``, regardless of operands.
11829 The ``fcmp`` instruction can also optionally take any number of
11830 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
11831 otherwise unsafe floating-point optimizations.
11833 Any set of fast-math flags are legal on an ``fcmp`` instruction, but the
11834 only flags that have any effect on its semantics are those that allow
11835 assumptions to be made about the values of input arguments; namely
11836 ``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information.
11841 .. code-block:: text
11843 <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false
11844 <result> = fcmp one float 4.0, 5.0 ; yields: result=true
11845 <result> = fcmp olt float 4.0, 5.0 ; yields: result=true
11846 <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false
11850 '``phi``' Instruction
11851 ^^^^^^^^^^^^^^^^^^^^^
11858 <result> = phi [fast-math-flags] <ty> [ <val0>, <label0>], ...
11863 The '``phi``' instruction is used to implement the φ node in the SSA
11864 graph representing the function.
11869 The type of the incoming values is specified with the first type field.
11870 After this, the '``phi``' instruction takes a list of pairs as
11871 arguments, with one pair for each predecessor basic block of the current
11872 block. Only values of :ref:`first class <t_firstclass>` type may be used as
11873 the value arguments to the PHI node. Only labels may be used as the
11876 There must be no non-phi instructions between the start of a basic block
11877 and the PHI instructions: i.e. PHI instructions must be first in a basic
11880 For the purposes of the SSA form, the use of each incoming value is
11881 deemed to occur on the edge from the corresponding predecessor block to
11882 the current block (but after any definition of an '``invoke``'
11883 instruction's return value on the same edge).
11885 The optional ``fast-math-flags`` marker indicates that the phi has one
11886 or more :ref:`fast-math-flags <fastmath>`. These are optimization hints
11887 to enable otherwise unsafe floating-point optimizations. Fast-math-flags
11888 are only valid for phis that return a floating-point scalar or vector
11889 type, or an array (nested to any depth) of floating-point scalar or vector
11895 At runtime, the '``phi``' instruction logically takes on the value
11896 specified by the pair corresponding to the predecessor basic block that
11897 executed just prior to the current block.
11902 .. code-block:: llvm
11904 Loop: ; Infinite loop that counts from 0 on up...
11905 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
11906 %nextindvar = add i32 %indvar, 1
11911 '``select``' Instruction
11912 ^^^^^^^^^^^^^^^^^^^^^^^^
11919 <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty
11921 selty is either i1 or {<N x i1>}
11926 The '``select``' instruction is used to choose one value based on a
11927 condition, without IR-level branching.
11932 The '``select``' instruction requires an 'i1' value or a vector of 'i1'
11933 values indicating the condition, and two values of the same :ref:`first
11934 class <t_firstclass>` type.
11936 #. The optional ``fast-math flags`` marker indicates that the select has one or more
11937 :ref:`fast-math flags <fastmath>`. These are optimization hints to enable
11938 otherwise unsafe floating-point optimizations. Fast-math flags are only valid
11939 for selects that return a floating-point scalar or vector type, or an array
11940 (nested to any depth) of floating-point scalar or vector types.
11945 If the condition is an i1 and it evaluates to 1, the instruction returns
11946 the first value argument; otherwise, it returns the second value
11949 If the condition is a vector of i1, then the value arguments must be
11950 vectors of the same size, and the selection is done element by element.
11952 If the condition is an i1 and the value arguments are vectors of the
11953 same size, then an entire vector is selected.
11958 .. code-block:: llvm
11960 %X = select i1 true, i8 17, i8 42 ; yields i8:17
11965 '``freeze``' Instruction
11966 ^^^^^^^^^^^^^^^^^^^^^^^^
11973 <result> = freeze ty <val> ; yields ty:result
11978 The '``freeze``' instruction is used to stop propagation of
11979 :ref:`undef <undefvalues>` and :ref:`poison <poisonvalues>` values.
11984 The '``freeze``' instruction takes a single argument.
11989 If the argument is ``undef`` or ``poison``, '``freeze``' returns an
11990 arbitrary, but fixed, value of type '``ty``'.
11991 Otherwise, this instruction is a no-op and returns the input argument.
11992 All uses of a value returned by the same '``freeze``' instruction are
11993 guaranteed to always observe the same value, while different '``freeze``'
11994 instructions may yield different values.
11996 While ``undef`` and ``poison`` pointers can be frozen, the result is a
11997 non-dereferenceable pointer. See the
11998 :ref:`Pointer Aliasing Rules <pointeraliasing>` section for more information.
11999 If an aggregate value or vector is frozen, the operand is frozen element-wise.
12000 The padding of an aggregate isn't considered, since it isn't visible
12001 without storing it into memory and loading it with a different type.
12007 .. code-block:: text
12011 %y = add i32 %w, %w ; undef
12012 %z = add i32 %x, %x ; even number because all uses of %x observe
12014 %x2 = freeze i32 %w
12015 %cmp = icmp eq i32 %x, %x2 ; can be true or false
12017 ; example with vectors
12018 %v = <2 x i32> <i32 undef, i32 poison>
12019 %a = extractelement <2 x i32> %v, i32 0 ; undef
12020 %b = extractelement <2 x i32> %v, i32 1 ; poison
12021 %add = add i32 %a, %a ; undef
12023 %v.fr = freeze <2 x i32> %v ; element-wise freeze
12024 %d = extractelement <2 x i32> %v.fr, i32 0 ; not undef
12025 %add.f = add i32 %d, %d ; even number
12027 ; branching on frozen value
12028 %poison = add nsw i1 %k, undef ; poison
12029 %c = freeze i1 %poison
12030 br i1 %c, label %foo, label %bar ; non-deterministic branch to %foo or %bar
12035 '``call``' Instruction
12036 ^^^^^^^^^^^^^^^^^^^^^^
12043 <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] [addrspace(<num>)]
12044 <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] [ operand bundles ]
12049 The '``call``' instruction represents a simple function call.
12054 This instruction requires several arguments:
12056 #. The optional ``tail`` and ``musttail`` markers indicate that the optimizers
12057 should perform tail call optimization. The ``tail`` marker is a hint that
12058 `can be ignored <CodeGenerator.html#tail-call-optimization>`_. The
12059 ``musttail`` marker means that the call must be tail call optimized in order
12060 for the program to be correct. This is true even in the presence of
12061 attributes like "disable-tail-calls". The ``musttail`` marker provides these
12064 #. The call will not cause unbounded stack growth if it is part of a
12065 recursive cycle in the call graph.
12066 #. Arguments with the :ref:`inalloca <attr_inalloca>` or
12067 :ref:`preallocated <attr_preallocated>` attribute are forwarded in place.
12068 #. If the musttail call appears in a function with the ``"thunk"`` attribute
12069 and the caller and callee both have varargs, than any unprototyped
12070 arguments in register or memory are forwarded to the callee. Similarly,
12071 the return value of the callee is returned to the caller's caller, even
12072 if a void return type is in use.
12074 Both markers imply that the callee does not access allocas from the caller.
12075 The ``tail`` marker additionally implies that the callee does not access
12076 varargs from the caller. Calls marked ``musttail`` must obey the following
12079 - The call must immediately precede a :ref:`ret <i_ret>` instruction,
12080 or a pointer bitcast followed by a ret instruction.
12081 - The ret instruction must return the (possibly bitcasted) value
12082 produced by the call, undef, or void.
12083 - The calling conventions of the caller and callee must match.
12084 - The callee must be varargs iff the caller is varargs. Bitcasting a
12085 non-varargs function to the appropriate varargs type is legal so
12086 long as the non-varargs prefixes obey the other rules.
12087 - The return type must not undergo automatic conversion to an `sret` pointer.
12089 In addition, if the calling convention is not `swifttailcc` or `tailcc`:
12091 - All ABI-impacting function attributes, such as sret, byval, inreg,
12092 returned, and inalloca, must match.
12093 - The caller and callee prototypes must match. Pointer types of parameters
12094 or return types may differ in pointee type, but not in address space.
12096 On the other hand, if the calling convention is `swifttailcc` or `swiftcc`:
12098 - Only these ABI-impacting attributes attributes are allowed: sret, byval,
12099 swiftself, and swiftasync.
12100 - Prototypes are not required to match.
12102 Tail call optimization for calls marked ``tail`` is guaranteed to occur if
12103 the following conditions are met:
12105 - Caller and callee both have the calling convention ``fastcc`` or ``tailcc``.
12106 - The call is in tail position (ret immediately follows call and ret
12107 uses value of call or is void).
12108 - Option ``-tailcallopt`` is enabled,
12109 ``llvm::GuaranteedTailCallOpt`` is ``true``, or the calling convention
12111 - `Platform-specific constraints are
12112 met. <CodeGenerator.html#tailcallopt>`_
12114 #. The optional ``notail`` marker indicates that the optimizers should not add
12115 ``tail`` or ``musttail`` markers to the call. It is used to prevent tail
12116 call optimization from being performed on the call.
12118 #. The optional ``fast-math flags`` marker indicates that the call has one or more
12119 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
12120 otherwise unsafe floating-point optimizations. Fast-math flags are only valid
12121 for calls that return a floating-point scalar or vector type, or an array
12122 (nested to any depth) of floating-point scalar or vector types.
12124 #. The optional "cconv" marker indicates which :ref:`calling
12125 convention <callingconv>` the call should use. If none is
12126 specified, the call defaults to using C calling conventions. The
12127 calling convention of the call must match the calling convention of
12128 the target function, or else the behavior is undefined.
12129 #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
12130 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
12132 #. The optional addrspace attribute can be used to indicate the address space
12133 of the called function. If it is not specified, the program address space
12134 from the :ref:`datalayout string<langref_datalayout>` will be used.
12135 #. '``ty``': the type of the call instruction itself which is also the
12136 type of the return value. Functions that return no value are marked
12138 #. '``fnty``': shall be the signature of the function being called. The
12139 argument types must match the types implied by this signature. This
12140 type can be omitted if the function is not varargs.
12141 #. '``fnptrval``': An LLVM value containing a pointer to a function to
12142 be called. In most cases, this is a direct function call, but
12143 indirect ``call``'s are just as possible, calling an arbitrary pointer
12145 #. '``function args``': argument list whose types match the function
12146 signature argument types and parameter attributes. All arguments must
12147 be of :ref:`first class <t_firstclass>` type. If the function signature
12148 indicates the function accepts a variable number of arguments, the
12149 extra arguments can be specified.
12150 #. The optional :ref:`function attributes <fnattrs>` list.
12151 #. The optional :ref:`operand bundles <opbundles>` list.
12156 The '``call``' instruction is used to cause control flow to transfer to
12157 a specified function, with its incoming arguments bound to the specified
12158 values. Upon a '``ret``' instruction in the called function, control
12159 flow continues with the instruction after the function call, and the
12160 return value of the function is bound to the result argument.
12165 .. code-block:: llvm
12167 %retval = call i32 @test(i32 %argc)
12168 call i32 (ptr, ...) @printf(ptr %msg, i32 12, i8 42) ; yields i32
12169 %X = tail call i32 @foo() ; yields i32
12170 %Y = tail call fastcc i32 @foo() ; yields i32
12171 call void %foo(i8 signext 97)
12173 %struct.A = type { i32, i8 }
12174 %r = call %struct.A @foo() ; yields { i32, i8 }
12175 %gr = extractvalue %struct.A %r, 0 ; yields i32
12176 %gr1 = extractvalue %struct.A %r, 1 ; yields i8
12177 %Z = call void @foo() noreturn ; indicates that %foo never returns normally
12178 %ZZ = call zeroext i32 @bar() ; Return value is %zero extended
12180 llvm treats calls to some functions with names and arguments that match
12181 the standard C99 library as being the C99 library functions, and may
12182 perform optimizations or generate code for them under that assumption.
12183 This is something we'd like to change in the future to provide better
12184 support for freestanding environments and non-C-based languages.
12188 '``va_arg``' Instruction
12189 ^^^^^^^^^^^^^^^^^^^^^^^^
12196 <resultval> = va_arg <va_list*> <arglist>, <argty>
12201 The '``va_arg``' instruction is used to access arguments passed through
12202 the "variable argument" area of a function call. It is used to implement
12203 the ``va_arg`` macro in C.
12208 This instruction takes a ``va_list*`` value and the type of the
12209 argument. It returns a value of the specified argument type and
12210 increments the ``va_list`` to point to the next argument. The actual
12211 type of ``va_list`` is target specific.
12216 The '``va_arg``' instruction loads an argument of the specified type
12217 from the specified ``va_list`` and causes the ``va_list`` to point to
12218 the next argument. For more information, see the variable argument
12219 handling :ref:`Intrinsic Functions <int_varargs>`.
12221 It is legal for this instruction to be called in a function which does
12222 not take a variable number of arguments, for example, the ``vfprintf``
12225 ``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic
12226 function <intrinsics>` because it takes a type as an argument.
12231 See the :ref:`variable argument processing <int_varargs>` section.
12233 Note that the code generator does not yet fully support va\_arg on many
12234 targets. Also, it does not currently support va\_arg with aggregate
12235 types on any target.
12239 '``landingpad``' Instruction
12240 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12247 <resultval> = landingpad <resultty> <clause>+
12248 <resultval> = landingpad <resultty> cleanup <clause>*
12250 <clause> := catch <type> <value>
12251 <clause> := filter <array constant type> <array constant>
12256 The '``landingpad``' instruction is used by `LLVM's exception handling
12257 system <ExceptionHandling.html#overview>`_ to specify that a basic block
12258 is a landing pad --- one where the exception lands, and corresponds to the
12259 code found in the ``catch`` portion of a ``try``/``catch`` sequence. It
12260 defines values supplied by the :ref:`personality function <personalityfn>` upon
12261 re-entry to the function. The ``resultval`` has the type ``resultty``.
12267 ``cleanup`` flag indicates that the landing pad block is a cleanup.
12269 A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and
12270 contains the global variable representing the "type" that may be caught
12271 or filtered respectively. Unlike the ``catch`` clause, the ``filter``
12272 clause takes an array constant as its argument. Use
12273 "``[0 x ptr] undef``" for a filter which cannot throw. The
12274 '``landingpad``' instruction must contain *at least* one ``clause`` or
12275 the ``cleanup`` flag.
12280 The '``landingpad``' instruction defines the values which are set by the
12281 :ref:`personality function <personalityfn>` upon re-entry to the function, and
12282 therefore the "result type" of the ``landingpad`` instruction. As with
12283 calling conventions, how the personality function results are
12284 represented in LLVM IR is target specific.
12286 The clauses are applied in order from top to bottom. If two
12287 ``landingpad`` instructions are merged together through inlining, the
12288 clauses from the calling function are appended to the list of clauses.
12289 When the call stack is being unwound due to an exception being thrown,
12290 the exception is compared against each ``clause`` in turn. If it doesn't
12291 match any of the clauses, and the ``cleanup`` flag is not set, then
12292 unwinding continues further up the call stack.
12294 The ``landingpad`` instruction has several restrictions:
12296 - A landing pad block is a basic block which is the unwind destination
12297 of an '``invoke``' instruction.
12298 - A landing pad block must have a '``landingpad``' instruction as its
12299 first non-PHI instruction.
12300 - There can be only one '``landingpad``' instruction within the landing
12302 - A basic block that is not a landing pad block may not include a
12303 '``landingpad``' instruction.
12308 .. code-block:: llvm
12310 ;; A landing pad which can catch an integer.
12311 %res = landingpad { ptr, i32 }
12313 ;; A landing pad that is a cleanup.
12314 %res = landingpad { ptr, i32 }
12316 ;; A landing pad which can catch an integer and can only throw a double.
12317 %res = landingpad { ptr, i32 }
12319 filter [1 x ptr] [ptr @_ZTId]
12323 '``catchpad``' Instruction
12324 ^^^^^^^^^^^^^^^^^^^^^^^^^^
12331 <resultval> = catchpad within <catchswitch> [<args>*]
12336 The '``catchpad``' instruction is used by `LLVM's exception handling
12337 system <ExceptionHandling.html#overview>`_ to specify that a basic block
12338 begins a catch handler --- one where a personality routine attempts to transfer
12339 control to catch an exception.
12344 The ``catchswitch`` operand must always be a token produced by a
12345 :ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This
12346 ensures that each ``catchpad`` has exactly one predecessor block, and it always
12347 terminates in a ``catchswitch``.
12349 The ``args`` correspond to whatever information the personality routine
12350 requires to know if this is an appropriate handler for the exception. Control
12351 will transfer to the ``catchpad`` if this is the first appropriate handler for
12354 The ``resultval`` has the type :ref:`token <t_token>` and is used to match the
12355 ``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH
12361 When the call stack is being unwound due to an exception being thrown, the
12362 exception is compared against the ``args``. If it doesn't match, control will
12363 not reach the ``catchpad`` instruction. The representation of ``args`` is
12364 entirely target and personality function-specific.
12366 Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad``
12367 instruction must be the first non-phi of its parent basic block.
12369 The meaning of the tokens produced and consumed by ``catchpad`` and other "pad"
12370 instructions is described in the
12371 `Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_.
12373 When a ``catchpad`` has been "entered" but not yet "exited" (as
12374 described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
12375 it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
12376 that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
12381 .. code-block:: text
12384 %cs = catchswitch within none [label %handler0] unwind to caller
12385 ;; A catch block which can catch an integer.
12387 %tok = catchpad within %cs [ptr @_ZTIi]
12391 '``cleanuppad``' Instruction
12392 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12399 <resultval> = cleanuppad within <parent> [<args>*]
12404 The '``cleanuppad``' instruction is used by `LLVM's exception handling
12405 system <ExceptionHandling.html#overview>`_ to specify that a basic block
12406 is a cleanup block --- one where a personality routine attempts to
12407 transfer control to run cleanup actions.
12408 The ``args`` correspond to whatever additional
12409 information the :ref:`personality function <personalityfn>` requires to
12410 execute the cleanup.
12411 The ``resultval`` has the type :ref:`token <t_token>` and is used to
12412 match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`.
12413 The ``parent`` argument is the token of the funclet that contains the
12414 ``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet,
12415 this operand may be the token ``none``.
12420 The instruction takes a list of arbitrary values which are interpreted
12421 by the :ref:`personality function <personalityfn>`.
12426 When the call stack is being unwound due to an exception being thrown,
12427 the :ref:`personality function <personalityfn>` transfers control to the
12428 ``cleanuppad`` with the aid of the personality-specific arguments.
12429 As with calling conventions, how the personality function results are
12430 represented in LLVM IR is target specific.
12432 The ``cleanuppad`` instruction has several restrictions:
12434 - A cleanup block is a basic block which is the unwind destination of
12435 an exceptional instruction.
12436 - A cleanup block must have a '``cleanuppad``' instruction as its
12437 first non-PHI instruction.
12438 - There can be only one '``cleanuppad``' instruction within the
12440 - A basic block that is not a cleanup block may not include a
12441 '``cleanuppad``' instruction.
12443 When a ``cleanuppad`` has been "entered" but not yet "exited" (as
12444 described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
12445 it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
12446 that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
12451 .. code-block:: text
12453 %tok = cleanuppad within %cs []
12457 Intrinsic Functions
12458 ===================
12460 LLVM supports the notion of an "intrinsic function". These functions
12461 have well known names and semantics and are required to follow certain
12462 restrictions. Overall, these intrinsics represent an extension mechanism
12463 for the LLVM language that does not require changing all of the
12464 transformations in LLVM when adding to the language (or the bitcode
12465 reader/writer, the parser, etc...).
12467 Intrinsic function names must all start with an "``llvm.``" prefix. This
12468 prefix is reserved in LLVM for intrinsic names; thus, function names may
12469 not begin with this prefix. Intrinsic functions must always be external
12470 functions: you cannot define the body of intrinsic functions. Intrinsic
12471 functions may only be used in call or invoke instructions: it is illegal
12472 to take the address of an intrinsic function. Additionally, because
12473 intrinsic functions are part of the LLVM language, it is required if any
12474 are added that they be documented here.
12476 Some intrinsic functions can be overloaded, i.e., the intrinsic
12477 represents a family of functions that perform the same operation but on
12478 different data types. Because LLVM can represent over 8 million
12479 different integer types, overloading is used commonly to allow an
12480 intrinsic function to operate on any integer type. One or more of the
12481 argument types or the result type can be overloaded to accept any
12482 integer type. Argument types may also be defined as exactly matching a
12483 previous argument's type or the result type. This allows an intrinsic
12484 function which accepts multiple arguments, but needs all of them to be
12485 of the same type, to only be overloaded with respect to a single
12486 argument or the result.
12488 Overloaded intrinsics will have the names of its overloaded argument
12489 types encoded into its function name, each preceded by a period. Only
12490 those types which are overloaded result in a name suffix. Arguments
12491 whose type is matched against another type do not. For example, the
12492 ``llvm.ctpop`` function can take an integer of any width and returns an
12493 integer of exactly the same integer width. This leads to a family of
12494 functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and
12495 ``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is
12496 overloaded, and only one type suffix is required. Because the argument's
12497 type is matched against the return type, it does not require its own
12500 :ref:`Unnamed types <t_opaque>` are encoded as ``s_s``. Overloaded intrinsics
12501 that depend on an unnamed type in one of its overloaded argument types get an
12502 additional ``.<number>`` suffix. This allows differentiating intrinsics with
12503 different unnamed types as arguments. (For example:
12504 ``llvm.ssa.copy.p0s_s.2(%42*)``) The number is tracked in the LLVM module and
12505 it ensures unique names in the module. While linking together two modules, it is
12506 still possible to get a name clash. In that case one of the names will be
12507 changed by getting a new number.
12509 For target developers who are defining intrinsics for back-end code
12510 generation, any intrinsic overloads based solely the distinction between
12511 integer or floating point types should not be relied upon for correct
12512 code generation. In such cases, the recommended approach for target
12513 maintainers when defining intrinsics is to create separate integer and
12514 FP intrinsics rather than rely on overloading. For example, if different
12515 codegen is required for ``llvm.target.foo(<4 x i32>)`` and
12516 ``llvm.target.foo(<4 x float>)`` then these should be split into
12517 different intrinsics.
12519 To learn how to add an intrinsic function, please see the `Extending
12520 LLVM Guide <ExtendingLLVM.html>`_.
12524 Variable Argument Handling Intrinsics
12525 -------------------------------------
12527 Variable argument support is defined in LLVM with the
12528 :ref:`va_arg <i_va_arg>` instruction and these three intrinsic
12529 functions. These functions are related to the similarly named macros
12530 defined in the ``<stdarg.h>`` header file.
12532 All of these functions operate on arguments that use a target-specific
12533 value type "``va_list``". The LLVM assembly language reference manual
12534 does not define what this type is, so all transformations should be
12535 prepared to handle these functions regardless of the type used.
12537 This example shows how the :ref:`va_arg <i_va_arg>` instruction and the
12538 variable argument handling intrinsic functions are used.
12540 .. code-block:: llvm
12542 ; This struct is different for every platform. For most platforms,
12543 ; it is merely a ptr.
12544 %struct.va_list = type { ptr }
12546 ; For Unix x86_64 platforms, va_list is the following struct:
12547 ; %struct.va_list = type { i32, i32, ptr, ptr }
12549 define i32 @test(i32 %X, ...) {
12550 ; Initialize variable argument processing
12551 %ap = alloca %struct.va_list
12552 call void @llvm.va_start(ptr %ap)
12554 ; Read a single integer argument
12555 %tmp = va_arg ptr %ap, i32
12557 ; Demonstrate usage of llvm.va_copy and llvm.va_end
12559 call void @llvm.va_copy(ptr %aq, ptr %ap)
12560 call void @llvm.va_end(ptr %aq)
12562 ; Stop processing of arguments.
12563 call void @llvm.va_end(ptr %ap)
12567 declare void @llvm.va_start(ptr)
12568 declare void @llvm.va_copy(ptr, ptr)
12569 declare void @llvm.va_end(ptr)
12573 '``llvm.va_start``' Intrinsic
12574 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12581 declare void @llvm.va_start(ptr <arglist>)
12586 The '``llvm.va_start``' intrinsic initializes ``<arglist>`` for
12587 subsequent use by ``va_arg``.
12592 The argument is a pointer to a ``va_list`` element to initialize.
12597 The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro
12598 available in C. In a target-dependent way, it initializes the
12599 ``va_list`` element to which the argument points, so that the next call
12600 to ``va_arg`` will produce the first variable argument passed to the
12601 function. Unlike the C ``va_start`` macro, this intrinsic does not need
12602 to know the last argument of the function as the compiler can figure
12605 '``llvm.va_end``' Intrinsic
12606 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12613 declare void @llvm.va_end(ptr <arglist>)
12618 The '``llvm.va_end``' intrinsic destroys ``<arglist>``, which has been
12619 initialized previously with ``llvm.va_start`` or ``llvm.va_copy``.
12624 The argument is a pointer to a ``va_list`` to destroy.
12629 The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro
12630 available in C. In a target-dependent way, it destroys the ``va_list``
12631 element to which the argument points. Calls to
12632 :ref:`llvm.va_start <int_va_start>` and
12633 :ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to
12638 '``llvm.va_copy``' Intrinsic
12639 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12646 declare void @llvm.va_copy(ptr <destarglist>, ptr <srcarglist>)
12651 The '``llvm.va_copy``' intrinsic copies the current argument position
12652 from the source argument list to the destination argument list.
12657 The first argument is a pointer to a ``va_list`` element to initialize.
12658 The second argument is a pointer to a ``va_list`` element to copy from.
12663 The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro
12664 available in C. In a target-dependent way, it copies the source
12665 ``va_list`` element into the destination ``va_list`` element. This
12666 intrinsic is necessary because the `` llvm.va_start`` intrinsic may be
12667 arbitrarily complex and require, for example, memory allocation.
12669 Accurate Garbage Collection Intrinsics
12670 --------------------------------------
12672 LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_
12673 (GC) requires the frontend to generate code containing appropriate intrinsic
12674 calls and select an appropriate GC strategy which knows how to lower these
12675 intrinsics in a manner which is appropriate for the target collector.
12677 These intrinsics allow identification of :ref:`GC roots on the
12678 stack <int_gcroot>`, as well as garbage collector implementations that
12679 require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers.
12680 Frontends for type-safe garbage collected languages should generate
12681 these intrinsics to make use of the LLVM garbage collectors. For more
12682 details, see `Garbage Collection with LLVM <GarbageCollection.html>`_.
12684 LLVM provides an second experimental set of intrinsics for describing garbage
12685 collection safepoints in compiled code. These intrinsics are an alternative
12686 to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for
12687 :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The
12688 differences in approach are covered in the `Garbage Collection with LLVM
12689 <GarbageCollection.html>`_ documentation. The intrinsics themselves are
12690 described in :doc:`Statepoints`.
12694 '``llvm.gcroot``' Intrinsic
12695 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12702 declare void @llvm.gcroot(ptr %ptrloc, ptr %metadata)
12707 The '``llvm.gcroot``' intrinsic declares the existence of a GC root to
12708 the code generator, and allows some metadata to be associated with it.
12713 The first argument specifies the address of a stack object that contains
12714 the root pointer. The second pointer (which must be either a constant or
12715 a global value address) contains the meta-data to be associated with the
12721 At runtime, a call to this intrinsic stores a null pointer into the
12722 "ptrloc" location. At compile-time, the code generator generates
12723 information to allow the runtime to find the pointer at GC safe points.
12724 The '``llvm.gcroot``' intrinsic may only be used in a function which
12725 :ref:`specifies a GC algorithm <gc>`.
12729 '``llvm.gcread``' Intrinsic
12730 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12737 declare ptr @llvm.gcread(ptr %ObjPtr, ptr %Ptr)
12742 The '``llvm.gcread``' intrinsic identifies reads of references from heap
12743 locations, allowing garbage collector implementations that require read
12749 The second argument is the address to read from, which should be an
12750 address allocated from the garbage collector. The first object is a
12751 pointer to the start of the referenced object, if needed by the language
12752 runtime (otherwise null).
12757 The '``llvm.gcread``' intrinsic has the same semantics as a load
12758 instruction, but may be replaced with substantially more complex code by
12759 the garbage collector runtime, as needed. The '``llvm.gcread``'
12760 intrinsic may only be used in a function which :ref:`specifies a GC
12765 '``llvm.gcwrite``' Intrinsic
12766 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12773 declare void @llvm.gcwrite(ptr %P1, ptr %Obj, ptr %P2)
12778 The '``llvm.gcwrite``' intrinsic identifies writes of references to heap
12779 locations, allowing garbage collector implementations that require write
12780 barriers (such as generational or reference counting collectors).
12785 The first argument is the reference to store, the second is the start of
12786 the object to store it to, and the third is the address of the field of
12787 Obj to store to. If the runtime does not require a pointer to the
12788 object, Obj may be null.
12793 The '``llvm.gcwrite``' intrinsic has the same semantics as a store
12794 instruction, but may be replaced with substantially more complex code by
12795 the garbage collector runtime, as needed. The '``llvm.gcwrite``'
12796 intrinsic may only be used in a function which :ref:`specifies a GC
12802 '``llvm.experimental.gc.statepoint``' Intrinsic
12803 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12811 @llvm.experimental.gc.statepoint(i64 <id>, i32 <num patch bytes>,
12812 ptr elementtype(func_type) <target>,
12813 i64 <#call args>, i64 <flags>,
12814 ... (call parameters),
12820 The statepoint intrinsic represents a call which is parse-able by the
12826 The 'id' operand is a constant integer that is reported as the ID
12827 field in the generated stackmap. LLVM does not interpret this
12828 parameter in any way and its meaning is up to the statepoint user to
12829 decide. Note that LLVM is free to duplicate code containing
12830 statepoint calls, and this may transform IR that had a unique 'id' per
12831 lexical call to statepoint to IR that does not.
12833 If 'num patch bytes' is non-zero then the call instruction
12834 corresponding to the statepoint is not emitted and LLVM emits 'num
12835 patch bytes' bytes of nops in its place. LLVM will emit code to
12836 prepare the function arguments and retrieve the function return value
12837 in accordance to the calling convention; the former before the nop
12838 sequence and the latter after the nop sequence. It is expected that
12839 the user will patch over the 'num patch bytes' bytes of nops with a
12840 calling sequence specific to their runtime before executing the
12841 generated machine code. There are no guarantees with respect to the
12842 alignment of the nop sequence. Unlike :doc:`StackMaps` statepoints do
12843 not have a concept of shadow bytes. Note that semantically the
12844 statepoint still represents a call or invoke to 'target', and the nop
12845 sequence after patching is expected to represent an operation
12846 equivalent to a call or invoke to 'target'.
12848 The 'target' operand is the function actually being called. The operand
12849 must have an :ref:`elementtype <attr_elementtype>` attribute specifying
12850 the function type of the target. The target can be specified as either
12851 a symbolic LLVM function, or as an arbitrary Value of pointer type. Note
12852 that the function type must match the signature of the callee and the
12853 types of the 'call parameters' arguments.
12855 The '#call args' operand is the number of arguments to the actual
12856 call. It must exactly match the number of arguments passed in the
12857 'call parameters' variable length section.
12859 The 'flags' operand is used to specify extra information about the
12860 statepoint. This is currently only used to mark certain statepoints
12861 as GC transitions. This operand is a 64-bit integer with the following
12862 layout, where bit 0 is the least significant bit:
12864 +-------+---------------------------------------------------+
12866 +=======+===================================================+
12867 | 0 | Set if the statepoint is a GC transition, cleared |
12869 +-------+---------------------------------------------------+
12870 | 1-63 | Reserved for future use; must be cleared. |
12871 +-------+---------------------------------------------------+
12873 The 'call parameters' arguments are simply the arguments which need to
12874 be passed to the call target. They will be lowered according to the
12875 specified calling convention and otherwise handled like a normal call
12876 instruction. The number of arguments must exactly match what is
12877 specified in '# call args'. The types must match the signature of
12880 The 'call parameter' attributes must be followed by two 'i64 0' constants.
12881 These were originally the length prefixes for 'gc transition parameter' and
12882 'deopt parameter' arguments, but the role of these parameter sets have been
12883 entirely replaced with the corresponding operand bundles. In a future
12884 revision, these now redundant arguments will be removed.
12889 A statepoint is assumed to read and write all memory. As a result,
12890 memory operations can not be reordered past a statepoint. It is
12891 illegal to mark a statepoint as being either 'readonly' or 'readnone'.
12893 Note that legal IR can not perform any memory operation on a 'gc
12894 pointer' argument of the statepoint in a location statically reachable
12895 from the statepoint. Instead, the explicitly relocated value (from a
12896 ``gc.relocate``) must be used.
12898 '``llvm.experimental.gc.result``' Intrinsic
12899 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12907 @llvm.experimental.gc.result(token %statepoint_token)
12912 ``gc.result`` extracts the result of the original call instruction
12913 which was replaced by the ``gc.statepoint``. The ``gc.result``
12914 intrinsic is actually a family of three intrinsics due to an
12915 implementation limitation. Other than the type of the return value,
12916 the semantics are the same.
12921 The first and only argument is the ``gc.statepoint`` which starts
12922 the safepoint sequence of which this ``gc.result`` is a part.
12923 Despite the typing of this as a generic token, *only* the value defined
12924 by a ``gc.statepoint`` is legal here.
12929 The ``gc.result`` represents the return value of the call target of
12930 the ``statepoint``. The type of the ``gc.result`` must exactly match
12931 the type of the target. If the call target returns void, there will
12932 be no ``gc.result``.
12934 A ``gc.result`` is modeled as a 'readnone' pure function. It has no
12935 side effects since it is just a projection of the return value of the
12936 previous call represented by the ``gc.statepoint``.
12938 '``llvm.experimental.gc.relocate``' Intrinsic
12939 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12946 declare <pointer type>
12947 @llvm.experimental.gc.relocate(token %statepoint_token,
12949 i32 %pointer_offset)
12954 A ``gc.relocate`` returns the potentially relocated value of a pointer
12960 The first argument is the ``gc.statepoint`` which starts the
12961 safepoint sequence of which this ``gc.relocation`` is a part.
12962 Despite the typing of this as a generic token, *only* the value defined
12963 by a ``gc.statepoint`` is legal here.
12965 The second and third arguments are both indices into operands of the
12966 corresponding statepoint's :ref:`gc-live <ob_gc_live>` operand bundle.
12968 The second argument is an index which specifies the allocation for the pointer
12969 being relocated. The associated value must be within the object with which the
12970 pointer being relocated is associated. The optimizer is free to change *which*
12971 interior derived pointer is reported, provided that it does not replace an
12972 actual base pointer with another interior derived pointer. Collectors are
12973 allowed to rely on the base pointer operand remaining an actual base pointer if
12976 The third argument is an index which specify the (potentially) derived pointer
12977 being relocated. It is legal for this index to be the same as the second
12978 argument if-and-only-if a base pointer is being relocated.
12983 The return value of ``gc.relocate`` is the potentially relocated value
12984 of the pointer specified by its arguments. It is unspecified how the
12985 value of the returned pointer relates to the argument to the
12986 ``gc.statepoint`` other than that a) it points to the same source
12987 language object with the same offset, and b) the 'based-on'
12988 relationship of the newly relocated pointers is a projection of the
12989 unrelocated pointers. In particular, the integer value of the pointer
12990 returned is unspecified.
12992 A ``gc.relocate`` is modeled as a ``readnone`` pure function. It has no
12993 side effects since it is just a way to extract information about work
12994 done during the actual call modeled by the ``gc.statepoint``.
12996 .. _gc.get.pointer.base:
12998 '``llvm.experimental.gc.get.pointer.base``' Intrinsic
12999 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13006 declare <pointer type>
13007 @llvm.experimental.gc.get.pointer.base(
13008 <pointer type> readnone nocapture %derived_ptr)
13009 nounwind willreturn memory(none)
13014 ``gc.get.pointer.base`` for a derived pointer returns its base pointer.
13019 The only argument is a pointer which is based on some object with
13020 an unknown offset from the base of said object.
13025 This intrinsic is used in the abstract machine model for GC to represent
13026 the base pointer for an arbitrary derived pointer.
13028 This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by
13029 replacing all uses of this callsite with the offset of a derived pointer from
13030 its base pointer value. The replacement is done as part of the lowering to the
13031 explicit statepoint model.
13033 The return pointer type must be the same as the type of the parameter.
13036 '``llvm.experimental.gc.get.pointer.offset``' Intrinsic
13037 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13045 @llvm.experimental.gc.get.pointer.offset(
13046 <pointer type> readnone nocapture %derived_ptr)
13047 nounwind willreturn memory(none)
13052 ``gc.get.pointer.offset`` for a derived pointer returns the offset from its
13058 The only argument is a pointer which is based on some object with
13059 an unknown offset from the base of said object.
13064 This intrinsic is used in the abstract machine model for GC to represent
13065 the offset of an arbitrary derived pointer from its base pointer.
13067 This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by
13068 replacing all uses of this callsite with the offset of a derived pointer from
13069 its base pointer value. The replacement is done as part of the lowering to the
13070 explicit statepoint model.
13072 Basically this call calculates difference between the derived pointer and its
13073 base pointer (see :ref:`gc.get.pointer.base`) both ptrtoint casted. But
13074 this cast done outside the :ref:`RewriteStatepointsForGC` pass could result
13075 in the pointers lost for further lowering from the abstract model to the
13076 explicit physical one.
13078 Code Generator Intrinsics
13079 -------------------------
13081 These intrinsics are provided by LLVM to expose special features that
13082 may only be implemented with code generator support.
13084 '``llvm.returnaddress``' Intrinsic
13085 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13092 declare ptr @llvm.returnaddress(i32 <level>)
13097 The '``llvm.returnaddress``' intrinsic attempts to compute a
13098 target-specific value indicating the return address of the current
13099 function or one of its callers.
13104 The argument to this intrinsic indicates which function to return the
13105 address for. Zero indicates the calling function, one indicates its
13106 caller, etc. The argument is **required** to be a constant integer
13112 The '``llvm.returnaddress``' intrinsic either returns a pointer
13113 indicating the return address of the specified call frame, or zero if it
13114 cannot be identified. The value returned by this intrinsic is likely to
13115 be incorrect or 0 for arguments other than zero, so it should only be
13116 used for debugging purposes.
13118 Note that calling this intrinsic does not prevent function inlining or
13119 other aggressive transformations, so the value returned may not be that
13120 of the obvious source-language caller.
13122 '``llvm.addressofreturnaddress``' Intrinsic
13123 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13130 declare ptr @llvm.addressofreturnaddress()
13135 The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific
13136 pointer to the place in the stack frame where the return address of the
13137 current function is stored.
13142 Note that calling this intrinsic does not prevent function inlining or
13143 other aggressive transformations, so the value returned may not be that
13144 of the obvious source-language caller.
13146 This intrinsic is only implemented for x86 and aarch64.
13148 '``llvm.sponentry``' Intrinsic
13149 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13156 declare ptr @llvm.sponentry()
13161 The '``llvm.sponentry``' intrinsic returns the stack pointer value at
13162 the entry of the current function calling this intrinsic.
13167 Note this intrinsic is only verified on AArch64 and ARM.
13169 '``llvm.frameaddress``' Intrinsic
13170 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13177 declare ptr @llvm.frameaddress(i32 <level>)
13182 The '``llvm.frameaddress``' intrinsic attempts to return the
13183 target-specific frame pointer value for the specified stack frame.
13188 The argument to this intrinsic indicates which function to return the
13189 frame pointer for. Zero indicates the calling function, one indicates
13190 its caller, etc. The argument is **required** to be a constant integer
13196 The '``llvm.frameaddress``' intrinsic either returns a pointer
13197 indicating the frame address of the specified call frame, or zero if it
13198 cannot be identified. The value returned by this intrinsic is likely to
13199 be incorrect or 0 for arguments other than zero, so it should only be
13200 used for debugging purposes.
13202 Note that calling this intrinsic does not prevent function inlining or
13203 other aggressive transformations, so the value returned may not be that
13204 of the obvious source-language caller.
13206 '``llvm.swift.async.context.addr``' Intrinsic
13207 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13214 declare ptr @llvm.swift.async.context.addr()
13219 The '``llvm.swift.async.context.addr``' intrinsic returns a pointer to
13220 the part of the extended frame record containing the asynchronous
13221 context of a Swift execution.
13226 If the caller has a ``swiftasync`` parameter, that argument will initially
13227 be stored at the returned address. If not, it will be initialized to null.
13229 '``llvm.localescape``' and '``llvm.localrecover``' Intrinsics
13230 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13237 declare void @llvm.localescape(...)
13238 declare ptr @llvm.localrecover(ptr %func, ptr %fp, i32 %idx)
13243 The '``llvm.localescape``' intrinsic escapes offsets of a collection of static
13244 allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a
13245 live frame pointer to recover the address of the allocation. The offset is
13246 computed during frame layout of the caller of ``llvm.localescape``.
13251 All arguments to '``llvm.localescape``' must be pointers to static allocas or
13252 casts of static allocas. Each function can only call '``llvm.localescape``'
13253 once, and it can only do so from the entry block.
13255 The ``func`` argument to '``llvm.localrecover``' must be a constant
13256 bitcasted pointer to a function defined in the current module. The code
13257 generator cannot determine the frame allocation offset of functions defined in
13260 The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a
13261 call frame that is currently live. The return value of '``llvm.localaddress``'
13262 is one way to produce such a value, but various runtimes also expose a suitable
13263 pointer in platform-specific ways.
13265 The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to
13266 '``llvm.localescape``' to recover. It is zero-indexed.
13271 These intrinsics allow a group of functions to share access to a set of local
13272 stack allocations of a one parent function. The parent function may call the
13273 '``llvm.localescape``' intrinsic once from the function entry block, and the
13274 child functions can use '``llvm.localrecover``' to access the escaped allocas.
13275 The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where
13276 the escaped allocas are allocated, which would break attempts to use
13277 '``llvm.localrecover``'.
13279 '``llvm.seh.try.begin``' and '``llvm.seh.try.end``' Intrinsics
13280 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13287 declare void @llvm.seh.try.begin()
13288 declare void @llvm.seh.try.end()
13293 The '``llvm.seh.try.begin``' and '``llvm.seh.try.end``' intrinsics mark
13294 the boundary of a _try region for Windows SEH Asynchrous Exception Handling.
13299 When a C-function is compiled with Windows SEH Asynchrous Exception option,
13300 -feh_asynch (aka MSVC -EHa), these two intrinsics are injected to mark _try
13301 boundary and to prevent potential exceptions from being moved across boundary.
13302 Any set of operations can then be confined to the region by reading their leaf
13303 inputs via volatile loads and writing their root outputs via volatile stores.
13305 '``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' Intrinsics
13306 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13313 declare void @llvm.seh.scope.begin()
13314 declare void @llvm.seh.scope.end()
13319 The '``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' intrinsics mark
13320 the boundary of a CPP object lifetime for Windows SEH Asynchrous Exception
13321 Handling (MSVC option -EHa).
13326 LLVM's ordinary exception-handling representation associates EH cleanups and
13327 handlers only with ``invoke``s, which normally correspond only to call sites. To
13328 support arbitrary faulting instructions, it must be possible to recover the current
13329 EH scope for any instruction. Turning every operation in LLVM that could fault
13330 into an ``invoke`` of a new, potentially-throwing intrinsic would require adding a
13331 large number of intrinsics, impede optimization of those operations, and make
13332 compilation slower by introducing many extra basic blocks. These intrinsics can
13333 be used instead to mark the region protected by a cleanup, such as for a local
13334 C++ object with a non-trivial destructor. ``llvm.seh.scope.begin`` is used to mark
13335 the start of the region; it is always called with ``invoke``, with the unwind block
13336 being the desired unwind destination for any potentially-throwing instructions
13337 within the region. `llvm.seh.scope.end` is used to mark when the scope ends
13338 and the EH cleanup is no longer required (e.g. because the destructor is being
13341 .. _int_read_register:
13342 .. _int_read_volatile_register:
13343 .. _int_write_register:
13345 '``llvm.read_register``', '``llvm.read_volatile_register``', and '``llvm.write_register``' Intrinsics
13346 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13353 declare i32 @llvm.read_register.i32(metadata)
13354 declare i64 @llvm.read_register.i64(metadata)
13355 declare i32 @llvm.read_volatile_register.i32(metadata)
13356 declare i64 @llvm.read_volatile_register.i64(metadata)
13357 declare void @llvm.write_register.i32(metadata, i32 @value)
13358 declare void @llvm.write_register.i64(metadata, i64 @value)
13364 The '``llvm.read_register``', '``llvm.read_volatile_register``', and
13365 '``llvm.write_register``' intrinsics provide access to the named register.
13366 The register must be valid on the architecture being compiled to. The type
13367 needs to be compatible with the register being read.
13372 The '``llvm.read_register``' and '``llvm.read_volatile_register``' intrinsics
13373 return the current value of the register, where possible. The
13374 '``llvm.write_register``' intrinsic sets the current value of the register,
13377 A call to '``llvm.read_volatile_register``' is assumed to have side-effects
13378 and possibly return a different value each time (e.g. for a timer register).
13380 This is useful to implement named register global variables that need
13381 to always be mapped to a specific register, as is common practice on
13382 bare-metal programs including OS kernels.
13384 The compiler doesn't check for register availability or use of the used
13385 register in surrounding code, including inline assembly. Because of that,
13386 allocatable registers are not supported.
13388 Warning: So far it only works with the stack pointer on selected
13389 architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of
13390 work is needed to support other registers and even more so, allocatable
13395 '``llvm.stacksave``' Intrinsic
13396 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13403 declare ptr @llvm.stacksave()
13408 The '``llvm.stacksave``' intrinsic is used to remember the current state
13409 of the function stack, for use with
13410 :ref:`llvm.stackrestore <int_stackrestore>`. This is useful for
13411 implementing language features like scoped automatic variable sized
13417 This intrinsic returns an opaque pointer value that can be passed to
13418 :ref:`llvm.stackrestore <int_stackrestore>`. When an
13419 ``llvm.stackrestore`` intrinsic is executed with a value saved from
13420 ``llvm.stacksave``, it effectively restores the state of the stack to
13421 the state it was in when the ``llvm.stacksave`` intrinsic executed. In
13422 practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that
13423 were allocated after the ``llvm.stacksave`` was executed.
13425 .. _int_stackrestore:
13427 '``llvm.stackrestore``' Intrinsic
13428 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13435 declare void @llvm.stackrestore(ptr %ptr)
13440 The '``llvm.stackrestore``' intrinsic is used to restore the state of
13441 the function stack to the state it was in when the corresponding
13442 :ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is
13443 useful for implementing language features like scoped automatic variable
13444 sized arrays in C99.
13449 See the description for :ref:`llvm.stacksave <int_stacksave>`.
13451 .. _int_get_dynamic_area_offset:
13453 '``llvm.get.dynamic.area.offset``' Intrinsic
13454 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13461 declare i32 @llvm.get.dynamic.area.offset.i32()
13462 declare i64 @llvm.get.dynamic.area.offset.i64()
13467 The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to
13468 get the offset from native stack pointer to the address of the most
13469 recent dynamic alloca on the caller's stack. These intrinsics are
13470 intended for use in combination with
13471 :ref:`llvm.stacksave <int_stacksave>` to get a
13472 pointer to the most recent dynamic alloca. This is useful, for example,
13473 for AddressSanitizer's stack unpoisoning routines.
13478 These intrinsics return a non-negative integer value that can be used to
13479 get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>`
13480 on the caller's stack. In particular, for targets where stack grows downwards,
13481 adding this offset to the native stack pointer would get the address of the most
13482 recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more
13483 complicated, because subtracting this value from stack pointer would get the address
13484 one past the end of the most recent dynamic alloca.
13486 Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
13487 returns just a zero, for others, such as PowerPC and PowerPC64, it returns a
13488 compile-time-known constant value.
13490 The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
13491 must match the target's default address space's (address space 0) pointer type.
13493 '``llvm.prefetch``' Intrinsic
13494 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13501 declare void @llvm.prefetch(ptr <address>, i32 <rw>, i32 <locality>, i32 <cache type>)
13506 The '``llvm.prefetch``' intrinsic is a hint to the code generator to
13507 insert a prefetch instruction if supported; otherwise, it is a noop.
13508 Prefetches have no effect on the behavior of the program but can change
13509 its performance characteristics.
13514 ``address`` is the address to be prefetched, ``rw`` is the specifier
13515 determining if the fetch should be for a read (0) or write (1), and
13516 ``locality`` is a temporal locality specifier ranging from (0) - no
13517 locality, to (3) - extremely local keep in cache. The ``cache type``
13518 specifies whether the prefetch is performed on the data (1) or
13519 instruction (0) cache. The ``rw``, ``locality`` and ``cache type``
13520 arguments must be constant integers.
13525 This intrinsic does not modify the behavior of the program. In
13526 particular, prefetches cannot trap and do not produce a value. On
13527 targets that support this intrinsic, the prefetch can provide hints to
13528 the processor cache for better performance.
13530 '``llvm.pcmarker``' Intrinsic
13531 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13538 declare void @llvm.pcmarker(i32 <id>)
13543 The '``llvm.pcmarker``' intrinsic is a method to export a Program
13544 Counter (PC) in a region of code to simulators and other tools. The
13545 method is target specific, but it is expected that the marker will use
13546 exported symbols to transmit the PC of the marker. The marker makes no
13547 guarantees that it will remain with any specific instruction after
13548 optimizations. It is possible that the presence of a marker will inhibit
13549 optimizations. The intended use is to be inserted after optimizations to
13550 allow correlations of simulation runs.
13555 ``id`` is a numerical id identifying the marker.
13560 This intrinsic does not modify the behavior of the program. Backends
13561 that do not support this intrinsic may ignore it.
13563 '``llvm.readcyclecounter``' Intrinsic
13564 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13571 declare i64 @llvm.readcyclecounter()
13576 The '``llvm.readcyclecounter``' intrinsic provides access to the cycle
13577 counter register (or similar low latency, high accuracy clocks) on those
13578 targets that support it. On X86, it should map to RDTSC. On Alpha, it
13579 should map to RPCC. As the backing counters overflow quickly (on the
13580 order of 9 seconds on alpha), this should only be used for small
13586 When directly supported, reading the cycle counter should not modify any
13587 memory. Implementations are allowed to either return an application
13588 specific value or a system wide value. On backends without support, this
13589 is lowered to a constant 0.
13591 Note that runtime support may be conditional on the privilege-level code is
13592 running at and the host platform.
13594 '``llvm.clear_cache``' Intrinsic
13595 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13602 declare void @llvm.clear_cache(ptr, ptr)
13607 The '``llvm.clear_cache``' intrinsic ensures visibility of modifications
13608 in the specified range to the execution unit of the processor. On
13609 targets with non-unified instruction and data cache, the implementation
13610 flushes the instruction cache.
13615 On platforms with coherent instruction and data caches (e.g. x86), this
13616 intrinsic is a nop. On platforms with non-coherent instruction and data
13617 cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate
13618 instructions or a system call, if cache flushing requires special
13621 The default behavior is to emit a call to ``__clear_cache`` from the run
13624 This intrinsic does *not* empty the instruction pipeline. Modifications
13625 of the current function are outside the scope of the intrinsic.
13627 '``llvm.instrprof.increment``' Intrinsic
13628 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13635 declare void @llvm.instrprof.increment(ptr <name>, i64 <hash>,
13636 i32 <num-counters>, i32 <index>)
13641 The '``llvm.instrprof.increment``' intrinsic can be emitted by a
13642 frontend for use with instrumentation based profiling. These will be
13643 lowered by the ``-instrprof`` pass to generate execution counts of a
13644 program at runtime.
13649 The first argument is a pointer to a global variable containing the
13650 name of the entity being instrumented. This should generally be the
13651 (mangled) function name for a set of counters.
13653 The second argument is a hash value that can be used by the consumer
13654 of the profile data to detect changes to the instrumented source, and
13655 the third is the number of counters associated with ``name``. It is an
13656 error if ``hash`` or ``num-counters`` differ between two instances of
13657 ``instrprof.increment`` that refer to the same name.
13659 The last argument refers to which of the counters for ``name`` should
13660 be incremented. It should be a value between 0 and ``num-counters``.
13665 This intrinsic represents an increment of a profiling counter. It will
13666 cause the ``-instrprof`` pass to generate the appropriate data
13667 structures and the code to increment the appropriate value, in a
13668 format that can be written out by a compiler runtime and consumed via
13669 the ``llvm-profdata`` tool.
13671 '``llvm.instrprof.increment.step``' Intrinsic
13672 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13679 declare void @llvm.instrprof.increment.step(ptr <name>, i64 <hash>,
13680 i32 <num-counters>,
13681 i32 <index>, i64 <step>)
13686 The '``llvm.instrprof.increment.step``' intrinsic is an extension to
13687 the '``llvm.instrprof.increment``' intrinsic with an additional fifth
13688 argument to specify the step of the increment.
13692 The first four arguments are the same as '``llvm.instrprof.increment``'
13695 The last argument specifies the value of the increment of the counter variable.
13699 See description of '``llvm.instrprof.increment``' intrinsic.
13701 '``llvm.instrprof.timestamp``' Intrinsic
13702 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13709 declare void @llvm.instrprof.timestamp(i8* <name>, i64 <hash>,
13710 i32 <num-counters>, i32 <index>)
13715 The '``llvm.instrprof.timestamp``' intrinsic is used to implement temporal
13720 The arguments are the same as '``llvm.instrprof.increment``'. The ``index`` is
13721 expected to always be zero.
13725 Similar to the '``llvm.instrprof.increment``' intrinsic, but it stores a
13726 timestamp representing when this function was executed for the first time.
13728 '``llvm.instrprof.cover``' Intrinsic
13729 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13736 declare void @llvm.instrprof.cover(ptr <name>, i64 <hash>,
13737 i32 <num-counters>, i32 <index>)
13742 The '``llvm.instrprof.cover``' intrinsic is used to implement coverage
13747 The arguments are the same as the first four arguments of
13748 '``llvm.instrprof.increment``'.
13752 Similar to the '``llvm.instrprof.increment``' intrinsic, but it stores zero to
13753 the profiling variable to signify that the function has been covered. We store
13754 zero because this is more efficient on some targets.
13756 '``llvm.instrprof.value.profile``' Intrinsic
13757 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13764 declare void @llvm.instrprof.value.profile(ptr <name>, i64 <hash>,
13765 i64 <value>, i32 <value_kind>,
13771 The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a
13772 frontend for use with instrumentation based profiling. This will be
13773 lowered by the ``-instrprof`` pass to find out the target values,
13774 instrumented expressions take in a program at runtime.
13779 The first argument is a pointer to a global variable containing the
13780 name of the entity being instrumented. ``name`` should generally be the
13781 (mangled) function name for a set of counters.
13783 The second argument is a hash value that can be used by the consumer
13784 of the profile data to detect changes to the instrumented source. It
13785 is an error if ``hash`` differs between two instances of
13786 ``llvm.instrprof.*`` that refer to the same name.
13788 The third argument is the value of the expression being profiled. The profiled
13789 expression's value should be representable as an unsigned 64-bit value. The
13790 fourth argument represents the kind of value profiling that is being done. The
13791 supported value profiling kinds are enumerated through the
13792 ``InstrProfValueKind`` type declared in the
13793 ``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the
13794 index of the instrumented expression within ``name``. It should be >= 0.
13799 This intrinsic represents the point where a call to a runtime routine
13800 should be inserted for value profiling of target expressions. ``-instrprof``
13801 pass will generate the appropriate data structures and replace the
13802 ``llvm.instrprof.value.profile`` intrinsic with the call to the profile
13803 runtime library with proper arguments.
13805 '``llvm.thread.pointer``' Intrinsic
13806 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13813 declare ptr @llvm.thread.pointer()
13818 The '``llvm.thread.pointer``' intrinsic returns the value of the thread
13824 The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area
13825 for the current thread. The exact semantics of this value are target
13826 specific: it may point to the start of TLS area, to the end, or somewhere
13827 in the middle. Depending on the target, this intrinsic may read a register,
13828 call a helper function, read from an alternate memory space, or perform
13829 other operations necessary to locate the TLS area. Not all targets support
13832 '``llvm.call.preallocated.setup``' Intrinsic
13833 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13840 declare token @llvm.call.preallocated.setup(i32 %num_args)
13845 The '``llvm.call.preallocated.setup``' intrinsic returns a token which can
13846 be used with a call's ``"preallocated"`` operand bundle to indicate that
13847 certain arguments are allocated and initialized before the call.
13852 The '``llvm.call.preallocated.setup``' intrinsic returns a token which is
13853 associated with at most one call. The token can be passed to
13854 '``@llvm.call.preallocated.arg``' to get a pointer to get that
13855 corresponding argument. The token must be the parameter to a
13856 ``"preallocated"`` operand bundle for the corresponding call.
13858 Nested calls to '``llvm.call.preallocated.setup``' are allowed, but must
13859 be properly nested. e.g.
13861 :: code-block:: llvm
13863 %t1 = call token @llvm.call.preallocated.setup(i32 0)
13864 %t2 = call token @llvm.call.preallocated.setup(i32 0)
13865 call void foo() ["preallocated"(token %t2)]
13866 call void foo() ["preallocated"(token %t1)]
13868 is allowed, but not
13870 :: code-block:: llvm
13872 %t1 = call token @llvm.call.preallocated.setup(i32 0)
13873 %t2 = call token @llvm.call.preallocated.setup(i32 0)
13874 call void foo() ["preallocated"(token %t1)]
13875 call void foo() ["preallocated"(token %t2)]
13877 .. _int_call_preallocated_arg:
13879 '``llvm.call.preallocated.arg``' Intrinsic
13880 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13887 declare ptr @llvm.call.preallocated.arg(token %setup_token, i32 %arg_index)
13892 The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the
13893 corresponding preallocated argument for the preallocated call.
13898 The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the
13899 ``%arg_index``th argument with the ``preallocated`` attribute for
13900 the call associated with the ``%setup_token``, which must be from
13901 '``llvm.call.preallocated.setup``'.
13903 A call to '``llvm.call.preallocated.arg``' must have a call site
13904 ``preallocated`` attribute. The type of the ``preallocated`` attribute must
13905 match the type used by the ``preallocated`` attribute of the corresponding
13906 argument at the preallocated call. The type is used in the case that an
13907 ``llvm.call.preallocated.setup`` does not have a corresponding call (e.g. due
13908 to DCE), where otherwise we cannot know how large the arguments are.
13910 It is undefined behavior if this is called with a token from an
13911 '``llvm.call.preallocated.setup``' if another
13912 '``llvm.call.preallocated.setup``' has already been called or if the
13913 preallocated call corresponding to the '``llvm.call.preallocated.setup``'
13914 has already been called.
13916 .. _int_call_preallocated_teardown:
13918 '``llvm.call.preallocated.teardown``' Intrinsic
13919 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13926 declare ptr @llvm.call.preallocated.teardown(token %setup_token)
13931 The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack
13932 created by a '``llvm.call.preallocated.setup``'.
13937 The token argument must be a '``llvm.call.preallocated.setup``'.
13939 The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack
13940 allocated by the corresponding '``llvm.call.preallocated.setup``'. Exactly
13941 one of this or the preallocated call must be called to prevent stack leaks.
13942 It is undefined behavior to call both a '``llvm.call.preallocated.teardown``'
13943 and the preallocated call for a given '``llvm.call.preallocated.setup``'.
13945 For example, if the stack is allocated for a preallocated call by a
13946 '``llvm.call.preallocated.setup``', then an initializer function called on an
13947 allocated argument throws an exception, there should be a
13948 '``llvm.call.preallocated.teardown``' in the exception handler to prevent
13951 Following the nesting rules in '``llvm.call.preallocated.setup``', nested
13952 calls to '``llvm.call.preallocated.setup``' and
13953 '``llvm.call.preallocated.teardown``' are allowed but must be properly
13959 .. code-block:: llvm
13961 %cs = call token @llvm.call.preallocated.setup(i32 1)
13962 %x = call ptr @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32)
13963 invoke void @constructor(ptr %x) to label %conta unwind label %contb
13965 call void @foo1(ptr preallocated(i32) %x) ["preallocated"(token %cs)]
13968 %s = catchswitch within none [label %catch] unwind to caller
13970 %p = catchpad within %s []
13971 call void @llvm.call.preallocated.teardown(token %cs)
13974 Standard C/C++ Library Intrinsics
13975 ---------------------------------
13977 LLVM provides intrinsics for a few important standard C/C++ library
13978 functions. These intrinsics allow source-language front-ends to pass
13979 information about the alignment of the pointer arguments to the code
13980 generator, providing opportunity for more efficient code generation.
13984 '``llvm.abs.*``' Intrinsic
13985 ^^^^^^^^^^^^^^^^^^^^^^^^^^
13990 This is an overloaded intrinsic. You can use ``llvm.abs`` on any
13991 integer bit width or any vector of integer elements.
13995 declare i32 @llvm.abs.i32(i32 <src>, i1 <is_int_min_poison>)
13996 declare <4 x i32> @llvm.abs.v4i32(<4 x i32> <src>, i1 <is_int_min_poison>)
14001 The '``llvm.abs``' family of intrinsic functions returns the absolute value
14007 The first argument is the value for which the absolute value is to be returned.
14008 This argument may be of any integer type or a vector with integer element type.
14009 The return type must match the first argument type.
14011 The second argument must be a constant and is a flag to indicate whether the
14012 result value of the '``llvm.abs``' intrinsic is a
14013 :ref:`poison value <poisonvalues>` if the argument is statically or dynamically
14014 an ``INT_MIN`` value.
14019 The '``llvm.abs``' intrinsic returns the magnitude (always positive) of the
14020 argument or each element of a vector argument.". If the argument is ``INT_MIN``,
14021 then the result is also ``INT_MIN`` if ``is_int_min_poison == 0`` and
14022 ``poison`` otherwise.
14027 '``llvm.smax.*``' Intrinsic
14028 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14033 This is an overloaded intrinsic. You can use ``@llvm.smax`` on any
14034 integer bit width or any vector of integer elements.
14038 declare i32 @llvm.smax.i32(i32 %a, i32 %b)
14039 declare <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> %b)
14044 Return the larger of ``%a`` and ``%b`` comparing the values as signed integers.
14045 Vector intrinsics operate on a per-element basis. The larger element of ``%a``
14046 and ``%b`` at a given index is returned for that index.
14051 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
14052 integer element type. The argument types must match each other, and the return
14053 type must match the argument type.
14058 '``llvm.smin.*``' Intrinsic
14059 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14064 This is an overloaded intrinsic. You can use ``@llvm.smin`` on any
14065 integer bit width or any vector of integer elements.
14069 declare i32 @llvm.smin.i32(i32 %a, i32 %b)
14070 declare <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> %b)
14075 Return the smaller of ``%a`` and ``%b`` comparing the values as signed integers.
14076 Vector intrinsics operate on a per-element basis. The smaller element of ``%a``
14077 and ``%b`` at a given index is returned for that index.
14082 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
14083 integer element type. The argument types must match each other, and the return
14084 type must match the argument type.
14089 '``llvm.umax.*``' Intrinsic
14090 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14095 This is an overloaded intrinsic. You can use ``@llvm.umax`` on any
14096 integer bit width or any vector of integer elements.
14100 declare i32 @llvm.umax.i32(i32 %a, i32 %b)
14101 declare <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> %b)
14106 Return the larger of ``%a`` and ``%b`` comparing the values as unsigned
14107 integers. Vector intrinsics operate on a per-element basis. The larger element
14108 of ``%a`` and ``%b`` at a given index is returned for that index.
14113 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
14114 integer element type. The argument types must match each other, and the return
14115 type must match the argument type.
14120 '``llvm.umin.*``' Intrinsic
14121 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14126 This is an overloaded intrinsic. You can use ``@llvm.umin`` on any
14127 integer bit width or any vector of integer elements.
14131 declare i32 @llvm.umin.i32(i32 %a, i32 %b)
14132 declare <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> %b)
14137 Return the smaller of ``%a`` and ``%b`` comparing the values as unsigned
14138 integers. Vector intrinsics operate on a per-element basis. The smaller element
14139 of ``%a`` and ``%b`` at a given index is returned for that index.
14144 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
14145 integer element type. The argument types must match each other, and the return
14146 type must match the argument type.
14151 '``llvm.memcpy``' Intrinsic
14152 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14157 This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any
14158 integer bit width and for different address spaces. Not all targets
14159 support all bit widths however.
14163 declare void @llvm.memcpy.p0.p0.i32(ptr <dest>, ptr <src>,
14164 i32 <len>, i1 <isvolatile>)
14165 declare void @llvm.memcpy.p0.p0.i64(ptr <dest>, ptr <src>,
14166 i64 <len>, i1 <isvolatile>)
14171 The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
14172 source location to the destination location.
14174 Note that, unlike the standard libc function, the ``llvm.memcpy.*``
14175 intrinsics do not return a value, takes extra isvolatile
14176 arguments and the pointers can be in specified address spaces.
14181 The first argument is a pointer to the destination, the second is a
14182 pointer to the source. The third argument is an integer argument
14183 specifying the number of bytes to copy, and the fourth is a
14184 boolean indicating a volatile access.
14186 The :ref:`align <attr_align>` parameter attribute can be provided
14187 for the first and second arguments.
14189 If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is
14190 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
14191 very cleanly specified and it is unwise to depend on it.
14196 The '``llvm.memcpy.*``' intrinsics copy a block of memory from the source
14197 location to the destination location, which must either be equal or
14198 non-overlapping. It copies "len" bytes of memory over. If the argument is known
14199 to be aligned to some boundary, this can be specified as an attribute on the
14202 If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
14204 If ``<len>`` is not a well-defined value, the behavior is undefined.
14205 If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined,
14206 otherwise the behavior is undefined.
14208 .. _int_memcpy_inline:
14210 '``llvm.memcpy.inline``' Intrinsic
14211 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14216 This is an overloaded intrinsic. You can use ``llvm.memcpy.inline`` on any
14217 integer bit width and for different address spaces. Not all targets
14218 support all bit widths however.
14222 declare void @llvm.memcpy.inline.p0.p0.i32(ptr <dest>, ptr <src>,
14223 i32 <len>, i1 <isvolatile>)
14224 declare void @llvm.memcpy.inline.p0.p0.i64(ptr <dest>, ptr <src>,
14225 i64 <len>, i1 <isvolatile>)
14230 The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the
14231 source location to the destination location and guarantees that no external
14232 functions are called.
14234 Note that, unlike the standard libc function, the ``llvm.memcpy.inline.*``
14235 intrinsics do not return a value, takes extra isvolatile
14236 arguments and the pointers can be in specified address spaces.
14241 The first argument is a pointer to the destination, the second is a
14242 pointer to the source. The third argument is a constant integer argument
14243 specifying the number of bytes to copy, and the fourth is a
14244 boolean indicating a volatile access.
14246 The :ref:`align <attr_align>` parameter attribute can be provided
14247 for the first and second arguments.
14249 If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy.inline`` call is
14250 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
14251 very cleanly specified and it is unwise to depend on it.
14256 The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the
14257 source location to the destination location, which are not allowed to
14258 overlap. It copies "len" bytes of memory over. If the argument is known
14259 to be aligned to some boundary, this can be specified as an attribute on
14261 The behavior of '``llvm.memcpy.inline.*``' is equivalent to the behavior of
14262 '``llvm.memcpy.*``', but the generated code is guaranteed not to call any
14263 external functions.
14267 '``llvm.memmove``' Intrinsic
14268 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14273 This is an overloaded intrinsic. You can use llvm.memmove on any integer
14274 bit width and for different address space. Not all targets support all
14275 bit widths however.
14279 declare void @llvm.memmove.p0.p0.i32(ptr <dest>, ptr <src>,
14280 i32 <len>, i1 <isvolatile>)
14281 declare void @llvm.memmove.p0.p0.i64(ptr <dest>, ptr <src>,
14282 i64 <len>, i1 <isvolatile>)
14287 The '``llvm.memmove.*``' intrinsics move a block of memory from the
14288 source location to the destination location. It is similar to the
14289 '``llvm.memcpy``' intrinsic but allows the two memory locations to
14292 Note that, unlike the standard libc function, the ``llvm.memmove.*``
14293 intrinsics do not return a value, takes an extra isvolatile
14294 argument and the pointers can be in specified address spaces.
14299 The first argument is a pointer to the destination, the second is a
14300 pointer to the source. The third argument is an integer argument
14301 specifying the number of bytes to copy, and the fourth is a
14302 boolean indicating a volatile access.
14304 The :ref:`align <attr_align>` parameter attribute can be provided
14305 for the first and second arguments.
14307 If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call
14308 is a :ref:`volatile operation <volatile>`. The detailed access behavior is
14309 not very cleanly specified and it is unwise to depend on it.
14314 The '``llvm.memmove.*``' intrinsics copy a block of memory from the
14315 source location to the destination location, which may overlap. It
14316 copies "len" bytes of memory over. If the argument is known to be
14317 aligned to some boundary, this can be specified as an attribute on
14320 If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
14322 If ``<len>`` is not a well-defined value, the behavior is undefined.
14323 If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined,
14324 otherwise the behavior is undefined.
14328 '``llvm.memset.*``' Intrinsics
14329 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14334 This is an overloaded intrinsic. You can use llvm.memset on any integer
14335 bit width and for different address spaces. However, not all targets
14336 support all bit widths.
14340 declare void @llvm.memset.p0.i32(ptr <dest>, i8 <val>,
14341 i32 <len>, i1 <isvolatile>)
14342 declare void @llvm.memset.p0.i64(ptr <dest>, i8 <val>,
14343 i64 <len>, i1 <isvolatile>)
14348 The '``llvm.memset.*``' intrinsics fill a block of memory with a
14349 particular byte value.
14351 Note that, unlike the standard libc function, the ``llvm.memset``
14352 intrinsic does not return a value and takes an extra volatile
14353 argument. Also, the destination can be in an arbitrary address space.
14358 The first argument is a pointer to the destination to fill, the second
14359 is the byte value with which to fill it, the third argument is an
14360 integer argument specifying the number of bytes to fill, and the fourth
14361 is a boolean indicating a volatile access.
14363 The :ref:`align <attr_align>` parameter attribute can be provided
14364 for the first arguments.
14366 If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is
14367 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
14368 very cleanly specified and it is unwise to depend on it.
14373 The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting
14374 at the destination location. If the argument is known to be
14375 aligned to some boundary, this can be specified as an attribute on
14378 If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
14380 If ``<len>`` is not a well-defined value, the behavior is undefined.
14381 If ``<len>`` is not zero, ``<dest>`` should be well-defined, otherwise the
14382 behavior is undefined.
14384 .. _int_memset_inline:
14386 '``llvm.memset.inline``' Intrinsic
14387 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14392 This is an overloaded intrinsic. You can use ``llvm.memset.inline`` on any
14393 integer bit width and for different address spaces. Not all targets
14394 support all bit widths however.
14398 declare void @llvm.memset.inline.p0.p0i8.i32(ptr <dest>, i8 <val>,
14399 i32 <len>, i1 <isvolatile>)
14400 declare void @llvm.memset.inline.p0.p0.i64(ptr <dest>, i8 <val>,
14401 i64 <len>, i1 <isvolatile>)
14406 The '``llvm.memset.inline.*``' intrinsics fill a block of memory with a
14407 particular byte value and guarantees that no external functions are called.
14409 Note that, unlike the standard libc function, the ``llvm.memset.inline.*``
14410 intrinsics do not return a value, take an extra isvolatile argument and the
14411 pointer can be in specified address spaces.
14416 The first argument is a pointer to the destination to fill, the second
14417 is the byte value with which to fill it, the third argument is a constant
14418 integer argument specifying the number of bytes to fill, and the fourth
14419 is a boolean indicating a volatile access.
14421 The :ref:`align <attr_align>` parameter attribute can be provided
14422 for the first argument.
14424 If the ``isvolatile`` parameter is ``true``, the ``llvm.memset.inline`` call is
14425 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
14426 very cleanly specified and it is unwise to depend on it.
14431 The '``llvm.memset.inline.*``' intrinsics fill "len" bytes of memory starting
14432 at the destination location. If the argument is known to be
14433 aligned to some boundary, this can be specified as an attribute on
14436 ``len`` must be a constant expression.
14437 If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
14439 If ``<len>`` is not a well-defined value, the behavior is undefined.
14440 If ``<len>`` is not zero, ``<dest>`` should be well-defined, otherwise the
14441 behavior is undefined.
14443 The behavior of '``llvm.memset.inline.*``' is equivalent to the behavior of
14444 '``llvm.memset.*``', but the generated code is guaranteed not to call any
14445 external functions.
14449 '``llvm.sqrt.*``' Intrinsic
14450 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14455 This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any
14456 floating-point or vector of floating-point type. Not all targets support
14461 declare float @llvm.sqrt.f32(float %Val)
14462 declare double @llvm.sqrt.f64(double %Val)
14463 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
14464 declare fp128 @llvm.sqrt.f128(fp128 %Val)
14465 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
14470 The '``llvm.sqrt``' intrinsics return the square root of the specified value.
14475 The argument and return value are floating-point numbers of the same type.
14480 Return the same value as a corresponding libm '``sqrt``' function but without
14481 trapping or setting ``errno``. For types specified by IEEE-754, the result
14482 matches a conforming libm implementation.
14484 When specified with the fast-math-flag 'afn', the result may be approximated
14485 using a less accurate calculation.
14487 '``llvm.powi.*``' Intrinsic
14488 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14493 This is an overloaded intrinsic. You can use ``llvm.powi`` on any
14494 floating-point or vector of floating-point type. Not all targets support
14497 Generally, the only supported type for the exponent is the one matching
14498 with the C type ``int``.
14502 declare float @llvm.powi.f32.i32(float %Val, i32 %power)
14503 declare double @llvm.powi.f64.i16(double %Val, i16 %power)
14504 declare x86_fp80 @llvm.powi.f80.i32(x86_fp80 %Val, i32 %power)
14505 declare fp128 @llvm.powi.f128.i32(fp128 %Val, i32 %power)
14506 declare ppc_fp128 @llvm.powi.ppcf128.i32(ppc_fp128 %Val, i32 %power)
14511 The '``llvm.powi.*``' intrinsics return the first operand raised to the
14512 specified (positive or negative) power. The order of evaluation of
14513 multiplications is not defined. When a vector of floating-point type is
14514 used, the second argument remains a scalar integer value.
14519 The second argument is an integer power, and the first is a value to
14520 raise to that power.
14525 This function returns the first value raised to the second power with an
14526 unspecified sequence of rounding operations.
14528 '``llvm.sin.*``' Intrinsic
14529 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14534 This is an overloaded intrinsic. You can use ``llvm.sin`` on any
14535 floating-point or vector of floating-point type. Not all targets support
14540 declare float @llvm.sin.f32(float %Val)
14541 declare double @llvm.sin.f64(double %Val)
14542 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
14543 declare fp128 @llvm.sin.f128(fp128 %Val)
14544 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
14549 The '``llvm.sin.*``' intrinsics return the sine of the operand.
14554 The argument and return value are floating-point numbers of the same type.
14559 Return the same value as a corresponding libm '``sin``' function but without
14560 trapping or setting ``errno``.
14562 When specified with the fast-math-flag 'afn', the result may be approximated
14563 using a less accurate calculation.
14565 '``llvm.cos.*``' Intrinsic
14566 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14571 This is an overloaded intrinsic. You can use ``llvm.cos`` on any
14572 floating-point or vector of floating-point type. Not all targets support
14577 declare float @llvm.cos.f32(float %Val)
14578 declare double @llvm.cos.f64(double %Val)
14579 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
14580 declare fp128 @llvm.cos.f128(fp128 %Val)
14581 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
14586 The '``llvm.cos.*``' intrinsics return the cosine of the operand.
14591 The argument and return value are floating-point numbers of the same type.
14596 Return the same value as a corresponding libm '``cos``' function but without
14597 trapping or setting ``errno``.
14599 When specified with the fast-math-flag 'afn', the result may be approximated
14600 using a less accurate calculation.
14602 '``llvm.pow.*``' Intrinsic
14603 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14608 This is an overloaded intrinsic. You can use ``llvm.pow`` on any
14609 floating-point or vector of floating-point type. Not all targets support
14614 declare float @llvm.pow.f32(float %Val, float %Power)
14615 declare double @llvm.pow.f64(double %Val, double %Power)
14616 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
14617 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
14618 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
14623 The '``llvm.pow.*``' intrinsics return the first operand raised to the
14624 specified (positive or negative) power.
14629 The arguments and return value are floating-point numbers of the same type.
14634 Return the same value as a corresponding libm '``pow``' function but without
14635 trapping or setting ``errno``.
14637 When specified with the fast-math-flag 'afn', the result may be approximated
14638 using a less accurate calculation.
14640 '``llvm.exp.*``' Intrinsic
14641 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14646 This is an overloaded intrinsic. You can use ``llvm.exp`` on any
14647 floating-point or vector of floating-point type. Not all targets support
14652 declare float @llvm.exp.f32(float %Val)
14653 declare double @llvm.exp.f64(double %Val)
14654 declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val)
14655 declare fp128 @llvm.exp.f128(fp128 %Val)
14656 declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val)
14661 The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified
14667 The argument and return value are floating-point numbers of the same type.
14672 Return the same value as a corresponding libm '``exp``' function but without
14673 trapping or setting ``errno``.
14675 When specified with the fast-math-flag 'afn', the result may be approximated
14676 using a less accurate calculation.
14678 '``llvm.exp2.*``' Intrinsic
14679 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14684 This is an overloaded intrinsic. You can use ``llvm.exp2`` on any
14685 floating-point or vector of floating-point type. Not all targets support
14690 declare float @llvm.exp2.f32(float %Val)
14691 declare double @llvm.exp2.f64(double %Val)
14692 declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val)
14693 declare fp128 @llvm.exp2.f128(fp128 %Val)
14694 declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val)
14699 The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the
14705 The argument and return value are floating-point numbers of the same type.
14710 Return the same value as a corresponding libm '``exp2``' function but without
14711 trapping or setting ``errno``.
14713 When specified with the fast-math-flag 'afn', the result may be approximated
14714 using a less accurate calculation.
14716 '``llvm.ldexp.*``' Intrinsic
14717 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14722 This is an overloaded intrinsic. You can use ``llvm.ldexp`` on any
14723 floating point or vector of floating point type. Not all targets support
14728 declare float @llvm.ldexp.f32.i32(float %Val, i32 %Exp)
14729 declare double @llvm.ldexp.f64.i32(double %Val, i32 %Exp)
14730 declare x86_fp80 @llvm.ldexp.f80.i32(x86_fp80 %Val, i32 %Exp)
14731 declare fp128 @llvm.ldexp.f128.i32(fp128 %Val, i32 %Exp)
14732 declare ppc_fp128 @llvm.ldexp.ppcf128.i32(ppc_fp128 %Val, i32 %Exp)
14733 declare <2 x float> @llvm.ldexp.v2f32.v2i32(<2 x float> %Val, <2 x i32> %Exp)
14738 The '``llvm.ldexp.*``' intrinsics perform the ldexp function.
14743 The first argument and the return value are :ref:`floating-point
14744 <t_floating>` or :ref:`vector <t_vector>` of floating-point values of
14745 the same type. The second argument is an integer with the same number
14751 This function multiplies the first argument by 2 raised to the second
14752 argument's power. If the first argument is NaN or infinite, the same
14753 value is returned. If the result underflows a zero with the same sign
14754 is returned. If the result overflows, the result is an infinity with
14757 '``llvm.log.*``' Intrinsic
14758 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14763 This is an overloaded intrinsic. You can use ``llvm.log`` on any
14764 floating-point or vector of floating-point type. Not all targets support
14769 declare float @llvm.log.f32(float %Val)
14770 declare double @llvm.log.f64(double %Val)
14771 declare x86_fp80 @llvm.log.f80(x86_fp80 %Val)
14772 declare fp128 @llvm.log.f128(fp128 %Val)
14773 declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val)
14778 The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified
14784 The argument and return value are floating-point numbers of the same type.
14789 Return the same value as a corresponding libm '``log``' function but without
14790 trapping or setting ``errno``.
14792 When specified with the fast-math-flag 'afn', the result may be approximated
14793 using a less accurate calculation.
14795 '``llvm.log10.*``' Intrinsic
14796 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14801 This is an overloaded intrinsic. You can use ``llvm.log10`` on any
14802 floating-point or vector of floating-point type. Not all targets support
14807 declare float @llvm.log10.f32(float %Val)
14808 declare double @llvm.log10.f64(double %Val)
14809 declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val)
14810 declare fp128 @llvm.log10.f128(fp128 %Val)
14811 declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val)
14816 The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the
14822 The argument and return value are floating-point numbers of the same type.
14827 Return the same value as a corresponding libm '``log10``' function but without
14828 trapping or setting ``errno``.
14830 When specified with the fast-math-flag 'afn', the result may be approximated
14831 using a less accurate calculation.
14833 '``llvm.log2.*``' Intrinsic
14834 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14839 This is an overloaded intrinsic. You can use ``llvm.log2`` on any
14840 floating-point or vector of floating-point type. Not all targets support
14845 declare float @llvm.log2.f32(float %Val)
14846 declare double @llvm.log2.f64(double %Val)
14847 declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val)
14848 declare fp128 @llvm.log2.f128(fp128 %Val)
14849 declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val)
14854 The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified
14860 The argument and return value are floating-point numbers of the same type.
14865 Return the same value as a corresponding libm '``log2``' function but without
14866 trapping or setting ``errno``.
14868 When specified with the fast-math-flag 'afn', the result may be approximated
14869 using a less accurate calculation.
14873 '``llvm.fma.*``' Intrinsic
14874 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14879 This is an overloaded intrinsic. You can use ``llvm.fma`` on any
14880 floating-point or vector of floating-point type. Not all targets support
14885 declare float @llvm.fma.f32(float %a, float %b, float %c)
14886 declare double @llvm.fma.f64(double %a, double %b, double %c)
14887 declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c)
14888 declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c)
14889 declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c)
14894 The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation.
14899 The arguments and return value are floating-point numbers of the same type.
14904 Return the same value as a corresponding libm '``fma``' function but without
14905 trapping or setting ``errno``.
14907 When specified with the fast-math-flag 'afn', the result may be approximated
14908 using a less accurate calculation.
14912 '``llvm.fabs.*``' Intrinsic
14913 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14918 This is an overloaded intrinsic. You can use ``llvm.fabs`` on any
14919 floating-point or vector of floating-point type. Not all targets support
14924 declare float @llvm.fabs.f32(float %Val)
14925 declare double @llvm.fabs.f64(double %Val)
14926 declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val)
14927 declare fp128 @llvm.fabs.f128(fp128 %Val)
14928 declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
14933 The '``llvm.fabs.*``' intrinsics return the absolute value of the
14939 The argument and return value are floating-point numbers of the same
14945 This function returns the same values as the libm ``fabs`` functions
14946 would, and handles error conditions in the same way.
14950 '``llvm.minnum.*``' Intrinsic
14951 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14956 This is an overloaded intrinsic. You can use ``llvm.minnum`` on any
14957 floating-point or vector of floating-point type. Not all targets support
14962 declare float @llvm.minnum.f32(float %Val0, float %Val1)
14963 declare double @llvm.minnum.f64(double %Val0, double %Val1)
14964 declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
14965 declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1)
14966 declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
14971 The '``llvm.minnum.*``' intrinsics return the minimum of the two
14978 The arguments and return value are floating-point numbers of the same
14984 Follows the IEEE-754 semantics for minNum, except for handling of
14985 signaling NaNs. This match's the behavior of libm's fmin.
14987 If either operand is a NaN, returns the other non-NaN operand. Returns
14988 NaN only if both operands are NaN. If the operands compare equal,
14989 returns either one of the operands. For example, this means that
14990 fmin(+0.0, -0.0) returns either operand.
14992 Unlike the IEEE-754 2008 behavior, this does not distinguish between
14993 signaling and quiet NaN inputs. If a target's implementation follows
14994 the standard and returns a quiet NaN if either input is a signaling
14995 NaN, the intrinsic lowering is responsible for quieting the inputs to
14996 correctly return the non-NaN input (e.g. by using the equivalent of
14997 ``llvm.canonicalize``).
15001 '``llvm.maxnum.*``' Intrinsic
15002 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15007 This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any
15008 floating-point or vector of floating-point type. Not all targets support
15013 declare float @llvm.maxnum.f32(float %Val0, float %Val1)
15014 declare double @llvm.maxnum.f64(double %Val0, double %Val1)
15015 declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
15016 declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1)
15017 declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
15022 The '``llvm.maxnum.*``' intrinsics return the maximum of the two
15029 The arguments and return value are floating-point numbers of the same
15034 Follows the IEEE-754 semantics for maxNum except for the handling of
15035 signaling NaNs. This matches the behavior of libm's fmax.
15037 If either operand is a NaN, returns the other non-NaN operand. Returns
15038 NaN only if both operands are NaN. If the operands compare equal,
15039 returns either one of the operands. For example, this means that
15040 fmax(+0.0, -0.0) returns either -0.0 or 0.0.
15042 Unlike the IEEE-754 2008 behavior, this does not distinguish between
15043 signaling and quiet NaN inputs. If a target's implementation follows
15044 the standard and returns a quiet NaN if either input is a signaling
15045 NaN, the intrinsic lowering is responsible for quieting the inputs to
15046 correctly return the non-NaN input (e.g. by using the equivalent of
15047 ``llvm.canonicalize``).
15049 '``llvm.minimum.*``' Intrinsic
15050 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15055 This is an overloaded intrinsic. You can use ``llvm.minimum`` on any
15056 floating-point or vector of floating-point type. Not all targets support
15061 declare float @llvm.minimum.f32(float %Val0, float %Val1)
15062 declare double @llvm.minimum.f64(double %Val0, double %Val1)
15063 declare x86_fp80 @llvm.minimum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
15064 declare fp128 @llvm.minimum.f128(fp128 %Val0, fp128 %Val1)
15065 declare ppc_fp128 @llvm.minimum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
15070 The '``llvm.minimum.*``' intrinsics return the minimum of the two
15071 arguments, propagating NaNs and treating -0.0 as less than +0.0.
15077 The arguments and return value are floating-point numbers of the same
15082 If either operand is a NaN, returns NaN. Otherwise returns the lesser
15083 of the two arguments. -0.0 is considered to be less than +0.0 for this
15084 intrinsic. Note that these are the semantics specified in the draft of
15087 '``llvm.maximum.*``' Intrinsic
15088 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15093 This is an overloaded intrinsic. You can use ``llvm.maximum`` on any
15094 floating-point or vector of floating-point type. Not all targets support
15099 declare float @llvm.maximum.f32(float %Val0, float %Val1)
15100 declare double @llvm.maximum.f64(double %Val0, double %Val1)
15101 declare x86_fp80 @llvm.maximum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
15102 declare fp128 @llvm.maximum.f128(fp128 %Val0, fp128 %Val1)
15103 declare ppc_fp128 @llvm.maximum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
15108 The '``llvm.maximum.*``' intrinsics return the maximum of the two
15109 arguments, propagating NaNs and treating -0.0 as less than +0.0.
15115 The arguments and return value are floating-point numbers of the same
15120 If either operand is a NaN, returns NaN. Otherwise returns the greater
15121 of the two arguments. -0.0 is considered to be less than +0.0 for this
15122 intrinsic. Note that these are the semantics specified in the draft of
15127 '``llvm.copysign.*``' Intrinsic
15128 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15133 This is an overloaded intrinsic. You can use ``llvm.copysign`` on any
15134 floating-point or vector of floating-point type. Not all targets support
15139 declare float @llvm.copysign.f32(float %Mag, float %Sgn)
15140 declare double @llvm.copysign.f64(double %Mag, double %Sgn)
15141 declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn)
15142 declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn)
15143 declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn)
15148 The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the
15149 first operand and the sign of the second operand.
15154 The arguments and return value are floating-point numbers of the same
15160 This function returns the same values as the libm ``copysign``
15161 functions would, and handles error conditions in the same way.
15165 '``llvm.floor.*``' Intrinsic
15166 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15171 This is an overloaded intrinsic. You can use ``llvm.floor`` on any
15172 floating-point or vector of floating-point type. Not all targets support
15177 declare float @llvm.floor.f32(float %Val)
15178 declare double @llvm.floor.f64(double %Val)
15179 declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val)
15180 declare fp128 @llvm.floor.f128(fp128 %Val)
15181 declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val)
15186 The '``llvm.floor.*``' intrinsics return the floor of the operand.
15191 The argument and return value are floating-point numbers of the same
15197 This function returns the same values as the libm ``floor`` functions
15198 would, and handles error conditions in the same way.
15202 '``llvm.ceil.*``' Intrinsic
15203 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15208 This is an overloaded intrinsic. You can use ``llvm.ceil`` on any
15209 floating-point or vector of floating-point type. Not all targets support
15214 declare float @llvm.ceil.f32(float %Val)
15215 declare double @llvm.ceil.f64(double %Val)
15216 declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val)
15217 declare fp128 @llvm.ceil.f128(fp128 %Val)
15218 declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val)
15223 The '``llvm.ceil.*``' intrinsics return the ceiling of the operand.
15228 The argument and return value are floating-point numbers of the same
15234 This function returns the same values as the libm ``ceil`` functions
15235 would, and handles error conditions in the same way.
15238 .. _int_llvm_trunc:
15240 '``llvm.trunc.*``' Intrinsic
15241 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15246 This is an overloaded intrinsic. You can use ``llvm.trunc`` on any
15247 floating-point or vector of floating-point type. Not all targets support
15252 declare float @llvm.trunc.f32(float %Val)
15253 declare double @llvm.trunc.f64(double %Val)
15254 declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val)
15255 declare fp128 @llvm.trunc.f128(fp128 %Val)
15256 declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val)
15261 The '``llvm.trunc.*``' intrinsics returns the operand rounded to the
15262 nearest integer not larger in magnitude than the operand.
15267 The argument and return value are floating-point numbers of the same
15273 This function returns the same values as the libm ``trunc`` functions
15274 would, and handles error conditions in the same way.
15278 '``llvm.rint.*``' Intrinsic
15279 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15284 This is an overloaded intrinsic. You can use ``llvm.rint`` on any
15285 floating-point or vector of floating-point type. Not all targets support
15290 declare float @llvm.rint.f32(float %Val)
15291 declare double @llvm.rint.f64(double %Val)
15292 declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val)
15293 declare fp128 @llvm.rint.f128(fp128 %Val)
15294 declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val)
15299 The '``llvm.rint.*``' intrinsics returns the operand rounded to the
15300 nearest integer. It may raise an inexact floating-point exception if the
15301 operand isn't an integer.
15306 The argument and return value are floating-point numbers of the same
15312 This function returns the same values as the libm ``rint`` functions
15313 would, and handles error conditions in the same way.
15317 '``llvm.nearbyint.*``' Intrinsic
15318 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15323 This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any
15324 floating-point or vector of floating-point type. Not all targets support
15329 declare float @llvm.nearbyint.f32(float %Val)
15330 declare double @llvm.nearbyint.f64(double %Val)
15331 declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val)
15332 declare fp128 @llvm.nearbyint.f128(fp128 %Val)
15333 declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val)
15338 The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the
15344 The argument and return value are floating-point numbers of the same
15350 This function returns the same values as the libm ``nearbyint``
15351 functions would, and handles error conditions in the same way.
15355 '``llvm.round.*``' Intrinsic
15356 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15361 This is an overloaded intrinsic. You can use ``llvm.round`` on any
15362 floating-point or vector of floating-point type. Not all targets support
15367 declare float @llvm.round.f32(float %Val)
15368 declare double @llvm.round.f64(double %Val)
15369 declare x86_fp80 @llvm.round.f80(x86_fp80 %Val)
15370 declare fp128 @llvm.round.f128(fp128 %Val)
15371 declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val)
15376 The '``llvm.round.*``' intrinsics returns the operand rounded to the
15382 The argument and return value are floating-point numbers of the same
15388 This function returns the same values as the libm ``round``
15389 functions would, and handles error conditions in the same way.
15393 '``llvm.roundeven.*``' Intrinsic
15394 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15399 This is an overloaded intrinsic. You can use ``llvm.roundeven`` on any
15400 floating-point or vector of floating-point type. Not all targets support
15405 declare float @llvm.roundeven.f32(float %Val)
15406 declare double @llvm.roundeven.f64(double %Val)
15407 declare x86_fp80 @llvm.roundeven.f80(x86_fp80 %Val)
15408 declare fp128 @llvm.roundeven.f128(fp128 %Val)
15409 declare ppc_fp128 @llvm.roundeven.ppcf128(ppc_fp128 %Val)
15414 The '``llvm.roundeven.*``' intrinsics returns the operand rounded to the nearest
15415 integer in floating-point format rounding halfway cases to even (that is, to the
15416 nearest value that is an even integer).
15421 The argument and return value are floating-point numbers of the same type.
15426 This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It
15427 also behaves in the same way as C standard function ``roundeven``, except that
15428 it does not raise floating point exceptions.
15431 '``llvm.lround.*``' Intrinsic
15432 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15437 This is an overloaded intrinsic. You can use ``llvm.lround`` on any
15438 floating-point type. Not all targets support all types however.
15442 declare i32 @llvm.lround.i32.f32(float %Val)
15443 declare i32 @llvm.lround.i32.f64(double %Val)
15444 declare i32 @llvm.lround.i32.f80(float %Val)
15445 declare i32 @llvm.lround.i32.f128(double %Val)
15446 declare i32 @llvm.lround.i32.ppcf128(double %Val)
15448 declare i64 @llvm.lround.i64.f32(float %Val)
15449 declare i64 @llvm.lround.i64.f64(double %Val)
15450 declare i64 @llvm.lround.i64.f80(float %Val)
15451 declare i64 @llvm.lround.i64.f128(double %Val)
15452 declare i64 @llvm.lround.i64.ppcf128(double %Val)
15457 The '``llvm.lround.*``' intrinsics return the operand rounded to the nearest
15458 integer with ties away from zero.
15464 The argument is a floating-point number and the return value is an integer
15470 This function returns the same values as the libm ``lround`` functions
15471 would, but without setting errno. If the rounded value is too large to
15472 be stored in the result type, the return value is a non-deterministic
15473 value (equivalent to `freeze poison`).
15475 '``llvm.llround.*``' Intrinsic
15476 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15481 This is an overloaded intrinsic. You can use ``llvm.llround`` on any
15482 floating-point type. Not all targets support all types however.
15486 declare i64 @llvm.lround.i64.f32(float %Val)
15487 declare i64 @llvm.lround.i64.f64(double %Val)
15488 declare i64 @llvm.lround.i64.f80(float %Val)
15489 declare i64 @llvm.lround.i64.f128(double %Val)
15490 declare i64 @llvm.lround.i64.ppcf128(double %Val)
15495 The '``llvm.llround.*``' intrinsics return the operand rounded to the nearest
15496 integer with ties away from zero.
15501 The argument is a floating-point number and the return value is an integer
15507 This function returns the same values as the libm ``llround``
15508 functions would, but without setting errno. If the rounded value is
15509 too large to be stored in the result type, the return value is a
15510 non-deterministic value (equivalent to `freeze poison`).
15512 '``llvm.lrint.*``' Intrinsic
15513 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15518 This is an overloaded intrinsic. You can use ``llvm.lrint`` on any
15519 floating-point type. Not all targets support all types however.
15523 declare i32 @llvm.lrint.i32.f32(float %Val)
15524 declare i32 @llvm.lrint.i32.f64(double %Val)
15525 declare i32 @llvm.lrint.i32.f80(float %Val)
15526 declare i32 @llvm.lrint.i32.f128(double %Val)
15527 declare i32 @llvm.lrint.i32.ppcf128(double %Val)
15529 declare i64 @llvm.lrint.i64.f32(float %Val)
15530 declare i64 @llvm.lrint.i64.f64(double %Val)
15531 declare i64 @llvm.lrint.i64.f80(float %Val)
15532 declare i64 @llvm.lrint.i64.f128(double %Val)
15533 declare i64 @llvm.lrint.i64.ppcf128(double %Val)
15538 The '``llvm.lrint.*``' intrinsics return the operand rounded to the nearest
15545 The argument is a floating-point number and the return value is an integer
15551 This function returns the same values as the libm ``lrint`` functions
15552 would, but without setting errno. If the rounded value is too large to
15553 be stored in the result type, the return value is a non-deterministic
15554 value (equivalent to `freeze poison`).
15556 '``llvm.llrint.*``' Intrinsic
15557 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15562 This is an overloaded intrinsic. You can use ``llvm.llrint`` on any
15563 floating-point type. Not all targets support all types however.
15567 declare i64 @llvm.llrint.i64.f32(float %Val)
15568 declare i64 @llvm.llrint.i64.f64(double %Val)
15569 declare i64 @llvm.llrint.i64.f80(float %Val)
15570 declare i64 @llvm.llrint.i64.f128(double %Val)
15571 declare i64 @llvm.llrint.i64.ppcf128(double %Val)
15576 The '``llvm.llrint.*``' intrinsics return the operand rounded to the nearest
15582 The argument is a floating-point number and the return value is an integer
15588 This function returns the same values as the libm ``llrint`` functions
15589 would, but without setting errno. If the rounded value is too large to
15590 be stored in the result type, the return value is a non-deterministic
15591 value (equivalent to `freeze poison`).
15593 Bit Manipulation Intrinsics
15594 ---------------------------
15596 LLVM provides intrinsics for a few important bit manipulation
15597 operations. These allow efficient code generation for some algorithms.
15599 .. _int_bitreverse:
15601 '``llvm.bitreverse.*``' Intrinsics
15602 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15607 This is an overloaded intrinsic function. You can use bitreverse on any
15612 declare i16 @llvm.bitreverse.i16(i16 <id>)
15613 declare i32 @llvm.bitreverse.i32(i32 <id>)
15614 declare i64 @llvm.bitreverse.i64(i64 <id>)
15615 declare <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> <id>)
15620 The '``llvm.bitreverse``' family of intrinsics is used to reverse the
15621 bitpattern of an integer value or vector of integer values; for example
15622 ``0b10110110`` becomes ``0b01101101``.
15627 The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit
15628 ``M`` in the input moved to bit ``N-M-1`` in the output. The vector
15629 intrinsics, such as ``llvm.bitreverse.v4i32``, operate on a per-element
15630 basis and the element order is not affected.
15634 '``llvm.bswap.*``' Intrinsics
15635 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15640 This is an overloaded intrinsic function. You can use bswap on any
15641 integer type that is an even number of bytes (i.e. BitWidth % 16 == 0).
15645 declare i16 @llvm.bswap.i16(i16 <id>)
15646 declare i32 @llvm.bswap.i32(i32 <id>)
15647 declare i64 @llvm.bswap.i64(i64 <id>)
15648 declare <4 x i32> @llvm.bswap.v4i32(<4 x i32> <id>)
15653 The '``llvm.bswap``' family of intrinsics is used to byte swap an integer
15654 value or vector of integer values with an even number of bytes (positive
15655 multiple of 16 bits).
15660 The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high
15661 and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32``
15662 intrinsic returns an i32 value that has the four bytes of the input i32
15663 swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the
15664 returned i32 will have its bytes in 3, 2, 1, 0 order. The
15665 ``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this
15666 concept to additional even-byte lengths (6 bytes, 8 bytes and more,
15667 respectively). The vector intrinsics, such as ``llvm.bswap.v4i32``,
15668 operate on a per-element basis and the element order is not affected.
15672 '``llvm.ctpop.*``' Intrinsic
15673 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15678 This is an overloaded intrinsic. You can use llvm.ctpop on any integer
15679 bit width, or on any vector with integer elements. Not all targets
15680 support all bit widths or vector types, however.
15684 declare i8 @llvm.ctpop.i8(i8 <src>)
15685 declare i16 @llvm.ctpop.i16(i16 <src>)
15686 declare i32 @llvm.ctpop.i32(i32 <src>)
15687 declare i64 @llvm.ctpop.i64(i64 <src>)
15688 declare i256 @llvm.ctpop.i256(i256 <src>)
15689 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>)
15694 The '``llvm.ctpop``' family of intrinsics counts the number of bits set
15700 The only argument is the value to be counted. The argument may be of any
15701 integer type, or a vector with integer elements. The return type must
15702 match the argument type.
15707 The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within
15708 each element of a vector.
15712 '``llvm.ctlz.*``' Intrinsic
15713 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15718 This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any
15719 integer bit width, or any vector whose elements are integers. Not all
15720 targets support all bit widths or vector types, however.
15724 declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_poison>)
15725 declare <2 x i37> @llvm.ctlz.v2i37(<2 x i37> <src>, i1 <is_zero_poison>)
15730 The '``llvm.ctlz``' family of intrinsic functions counts the number of
15731 leading zeros in a variable.
15736 The first argument is the value to be counted. This argument may be of
15737 any integer type, or a vector with integer element type. The return
15738 type must match the first argument type.
15740 The second argument is a constant flag that indicates whether the intrinsic
15741 returns a valid result if the first argument is zero. If the first
15742 argument is zero and the second argument is true, the result is poison.
15743 Historically some architectures did not provide a defined result for zero
15744 values as efficiently, and many algorithms are now predicated on avoiding
15750 The '``llvm.ctlz``' intrinsic counts the leading (most significant)
15751 zeros in a variable, or within each element of the vector. If
15752 ``src == 0`` then the result is the size in bits of the type of ``src``
15753 if ``is_zero_poison == 0`` and ``poison`` otherwise. For example,
15754 ``llvm.ctlz(i32 2) = 30``.
15758 '``llvm.cttz.*``' Intrinsic
15759 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15764 This is an overloaded intrinsic. You can use ``llvm.cttz`` on any
15765 integer bit width, or any vector of integer elements. Not all targets
15766 support all bit widths or vector types, however.
15770 declare i42 @llvm.cttz.i42 (i42 <src>, i1 <is_zero_poison>)
15771 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_poison>)
15776 The '``llvm.cttz``' family of intrinsic functions counts the number of
15782 The first argument is the value to be counted. This argument may be of
15783 any integer type, or a vector with integer element type. The return
15784 type must match the first argument type.
15786 The second argument is a constant flag that indicates whether the intrinsic
15787 returns a valid result if the first argument is zero. If the first
15788 argument is zero and the second argument is true, the result is poison.
15789 Historically some architectures did not provide a defined result for zero
15790 values as efficiently, and many algorithms are now predicated on avoiding
15796 The '``llvm.cttz``' intrinsic counts the trailing (least significant)
15797 zeros in a variable, or within each element of a vector. If ``src == 0``
15798 then the result is the size in bits of the type of ``src`` if
15799 ``is_zero_poison == 0`` and ``poison`` otherwise. For example,
15800 ``llvm.cttz(2) = 1``.
15806 '``llvm.fshl.*``' Intrinsic
15807 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15812 This is an overloaded intrinsic. You can use ``llvm.fshl`` on any
15813 integer bit width or any vector of integer elements. Not all targets
15814 support all bit widths or vector types, however.
15818 declare i8 @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c)
15819 declare i64 @llvm.fshl.i64(i64 %a, i64 %b, i64 %c)
15820 declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
15825 The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left:
15826 the first two values are concatenated as { %a : %b } (%a is the most significant
15827 bits of the wide value), the combined value is shifted left, and the most
15828 significant bits are extracted to produce a result that is the same size as the
15829 original arguments. If the first 2 arguments are identical, this is equivalent
15830 to a rotate left operation. For vector types, the operation occurs for each
15831 element of the vector. The shift argument is treated as an unsigned amount
15832 modulo the element size of the arguments.
15837 The first two arguments are the values to be concatenated. The third
15838 argument is the shift amount. The arguments may be any integer type or a
15839 vector with integer element type. All arguments and the return value must
15840 have the same type.
15845 .. code-block:: text
15847 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8)
15848 %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15) ; %r = i8: 128 (0b10000000)
15849 %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11) ; %r = i8: 120 (0b01111000)
15850 %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8) ; %r = i8: 0 (0b00000000)
15854 '``llvm.fshr.*``' Intrinsic
15855 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15860 This is an overloaded intrinsic. You can use ``llvm.fshr`` on any
15861 integer bit width or any vector of integer elements. Not all targets
15862 support all bit widths or vector types, however.
15866 declare i8 @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c)
15867 declare i64 @llvm.fshr.i64(i64 %a, i64 %b, i64 %c)
15868 declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
15873 The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right:
15874 the first two values are concatenated as { %a : %b } (%a is the most significant
15875 bits of the wide value), the combined value is shifted right, and the least
15876 significant bits are extracted to produce a result that is the same size as the
15877 original arguments. If the first 2 arguments are identical, this is equivalent
15878 to a rotate right operation. For vector types, the operation occurs for each
15879 element of the vector. The shift argument is treated as an unsigned amount
15880 modulo the element size of the arguments.
15885 The first two arguments are the values to be concatenated. The third
15886 argument is the shift amount. The arguments may be any integer type or a
15887 vector with integer element type. All arguments and the return value must
15888 have the same type.
15893 .. code-block:: text
15895 %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8)
15896 %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15) ; %r = i8: 254 (0b11111110)
15897 %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11) ; %r = i8: 225 (0b11100001)
15898 %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8) ; %r = i8: 255 (0b11111111)
15900 Arithmetic with Overflow Intrinsics
15901 -----------------------------------
15903 LLVM provides intrinsics for fast arithmetic overflow checking.
15905 Each of these intrinsics returns a two-element struct. The first
15906 element of this struct contains the result of the corresponding
15907 arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of
15908 the result. Therefore, for example, the first element of the struct
15909 returned by ``llvm.sadd.with.overflow.i32`` is always the same as the
15910 result of a 32-bit ``add`` instruction with the same operands, where
15911 the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag.
15913 The second element of the result is an ``i1`` that is 1 if the
15914 arithmetic operation overflowed and 0 otherwise. An operation
15915 overflows if, for any values of its operands ``A`` and ``B`` and for
15916 any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is
15917 not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is
15918 ``sext`` for signed overflow and ``zext`` for unsigned overflow, and
15919 ``op`` is the underlying arithmetic operation.
15921 The behavior of these intrinsics is well-defined for all argument
15924 '``llvm.sadd.with.overflow.*``' Intrinsics
15925 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15930 This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow``
15931 on any integer bit width or vectors of integers.
15935 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
15936 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
15937 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
15938 declare {<4 x i32>, <4 x i1>} @llvm.sadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15943 The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
15944 a signed addition of the two arguments, and indicate whether an overflow
15945 occurred during the signed summation.
15950 The arguments (%a and %b) and the first element of the result structure
15951 may be of integer types of any bit width, but they must have the same
15952 bit width. The second element of the result structure must be of type
15953 ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
15959 The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
15960 a signed addition of the two variables. They return a structure --- the
15961 first element of which is the signed summation, and the second element
15962 of which is a bit specifying if the signed summation resulted in an
15968 .. code-block:: llvm
15970 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
15971 %sum = extractvalue {i32, i1} %res, 0
15972 %obit = extractvalue {i32, i1} %res, 1
15973 br i1 %obit, label %overflow, label %normal
15975 '``llvm.uadd.with.overflow.*``' Intrinsics
15976 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15981 This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow``
15982 on any integer bit width or vectors of integers.
15986 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
15987 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
15988 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
15989 declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15994 The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
15995 an unsigned addition of the two arguments, and indicate whether a carry
15996 occurred during the unsigned summation.
16001 The arguments (%a and %b) and the first element of the result structure
16002 may be of integer types of any bit width, but they must have the same
16003 bit width. The second element of the result structure must be of type
16004 ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
16010 The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
16011 an unsigned addition of the two arguments. They return a structure --- the
16012 first element of which is the sum, and the second element of which is a
16013 bit specifying if the unsigned summation resulted in a carry.
16018 .. code-block:: llvm
16020 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
16021 %sum = extractvalue {i32, i1} %res, 0
16022 %obit = extractvalue {i32, i1} %res, 1
16023 br i1 %obit, label %carry, label %normal
16025 '``llvm.ssub.with.overflow.*``' Intrinsics
16026 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16031 This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow``
16032 on any integer bit width or vectors of integers.
16036 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
16037 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
16038 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
16039 declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
16044 The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
16045 a signed subtraction of the two arguments, and indicate whether an
16046 overflow occurred during the signed subtraction.
16051 The arguments (%a and %b) and the first element of the result structure
16052 may be of integer types of any bit width, but they must have the same
16053 bit width. The second element of the result structure must be of type
16054 ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
16060 The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
16061 a signed subtraction of the two arguments. They return a structure --- the
16062 first element of which is the subtraction, and the second element of
16063 which is a bit specifying if the signed subtraction resulted in an
16069 .. code-block:: llvm
16071 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
16072 %sum = extractvalue {i32, i1} %res, 0
16073 %obit = extractvalue {i32, i1} %res, 1
16074 br i1 %obit, label %overflow, label %normal
16076 '``llvm.usub.with.overflow.*``' Intrinsics
16077 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16082 This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow``
16083 on any integer bit width or vectors of integers.
16087 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
16088 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
16089 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
16090 declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
16095 The '``llvm.usub.with.overflow``' family of intrinsic functions perform
16096 an unsigned subtraction of the two arguments, and indicate whether an
16097 overflow occurred during the unsigned subtraction.
16102 The arguments (%a and %b) and the first element of the result structure
16103 may be of integer types of any bit width, but they must have the same
16104 bit width. The second element of the result structure must be of type
16105 ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
16111 The '``llvm.usub.with.overflow``' family of intrinsic functions perform
16112 an unsigned subtraction of the two arguments. They return a structure ---
16113 the first element of which is the subtraction, and the second element of
16114 which is a bit specifying if the unsigned subtraction resulted in an
16120 .. code-block:: llvm
16122 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
16123 %sum = extractvalue {i32, i1} %res, 0
16124 %obit = extractvalue {i32, i1} %res, 1
16125 br i1 %obit, label %overflow, label %normal
16127 '``llvm.smul.with.overflow.*``' Intrinsics
16128 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16133 This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow``
16134 on any integer bit width or vectors of integers.
16138 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
16139 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
16140 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
16141 declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
16146 The '``llvm.smul.with.overflow``' family of intrinsic functions perform
16147 a signed multiplication of the two arguments, and indicate whether an
16148 overflow occurred during the signed multiplication.
16153 The arguments (%a and %b) and the first element of the result structure
16154 may be of integer types of any bit width, but they must have the same
16155 bit width. The second element of the result structure must be of type
16156 ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
16162 The '``llvm.smul.with.overflow``' family of intrinsic functions perform
16163 a signed multiplication of the two arguments. They return a structure ---
16164 the first element of which is the multiplication, and the second element
16165 of which is a bit specifying if the signed multiplication resulted in an
16171 .. code-block:: llvm
16173 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
16174 %sum = extractvalue {i32, i1} %res, 0
16175 %obit = extractvalue {i32, i1} %res, 1
16176 br i1 %obit, label %overflow, label %normal
16178 '``llvm.umul.with.overflow.*``' Intrinsics
16179 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16184 This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow``
16185 on any integer bit width or vectors of integers.
16189 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
16190 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
16191 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
16192 declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
16197 The '``llvm.umul.with.overflow``' family of intrinsic functions perform
16198 a unsigned multiplication of the two arguments, and indicate whether an
16199 overflow occurred during the unsigned multiplication.
16204 The arguments (%a and %b) and the first element of the result structure
16205 may be of integer types of any bit width, but they must have the same
16206 bit width. The second element of the result structure must be of type
16207 ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
16213 The '``llvm.umul.with.overflow``' family of intrinsic functions perform
16214 an unsigned multiplication of the two arguments. They return a structure ---
16215 the first element of which is the multiplication, and the second
16216 element of which is a bit specifying if the unsigned multiplication
16217 resulted in an overflow.
16222 .. code-block:: llvm
16224 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
16225 %sum = extractvalue {i32, i1} %res, 0
16226 %obit = extractvalue {i32, i1} %res, 1
16227 br i1 %obit, label %overflow, label %normal
16229 Saturation Arithmetic Intrinsics
16230 ---------------------------------
16232 Saturation arithmetic is a version of arithmetic in which operations are
16233 limited to a fixed range between a minimum and maximum value. If the result of
16234 an operation is greater than the maximum value, the result is set (or
16235 "clamped") to this maximum. If it is below the minimum, it is clamped to this
16239 '``llvm.sadd.sat.*``' Intrinsics
16240 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16245 This is an overloaded intrinsic. You can use ``llvm.sadd.sat``
16246 on any integer bit width or vectors of integers.
16250 declare i16 @llvm.sadd.sat.i16(i16 %a, i16 %b)
16251 declare i32 @llvm.sadd.sat.i32(i32 %a, i32 %b)
16252 declare i64 @llvm.sadd.sat.i64(i64 %a, i64 %b)
16253 declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16258 The '``llvm.sadd.sat``' family of intrinsic functions perform signed
16259 saturating addition on the 2 arguments.
16264 The arguments (%a and %b) and the result may be of integer types of any bit
16265 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16266 values that will undergo signed addition.
16271 The maximum value this operation can clamp to is the largest signed value
16272 representable by the bit width of the arguments. The minimum value is the
16273 smallest signed value representable by this bit width.
16279 .. code-block:: llvm
16281 %res = call i4 @llvm.sadd.sat.i4(i4 1, i4 2) ; %res = 3
16282 %res = call i4 @llvm.sadd.sat.i4(i4 5, i4 6) ; %res = 7
16283 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 2) ; %res = -2
16284 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 -5) ; %res = -8
16287 '``llvm.uadd.sat.*``' Intrinsics
16288 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16293 This is an overloaded intrinsic. You can use ``llvm.uadd.sat``
16294 on any integer bit width or vectors of integers.
16298 declare i16 @llvm.uadd.sat.i16(i16 %a, i16 %b)
16299 declare i32 @llvm.uadd.sat.i32(i32 %a, i32 %b)
16300 declare i64 @llvm.uadd.sat.i64(i64 %a, i64 %b)
16301 declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16306 The '``llvm.uadd.sat``' family of intrinsic functions perform unsigned
16307 saturating addition on the 2 arguments.
16312 The arguments (%a and %b) and the result may be of integer types of any bit
16313 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16314 values that will undergo unsigned addition.
16319 The maximum value this operation can clamp to is the largest unsigned value
16320 representable by the bit width of the arguments. Because this is an unsigned
16321 operation, the result will never saturate towards zero.
16327 .. code-block:: llvm
16329 %res = call i4 @llvm.uadd.sat.i4(i4 1, i4 2) ; %res = 3
16330 %res = call i4 @llvm.uadd.sat.i4(i4 5, i4 6) ; %res = 11
16331 %res = call i4 @llvm.uadd.sat.i4(i4 8, i4 8) ; %res = 15
16334 '``llvm.ssub.sat.*``' Intrinsics
16335 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16340 This is an overloaded intrinsic. You can use ``llvm.ssub.sat``
16341 on any integer bit width or vectors of integers.
16345 declare i16 @llvm.ssub.sat.i16(i16 %a, i16 %b)
16346 declare i32 @llvm.ssub.sat.i32(i32 %a, i32 %b)
16347 declare i64 @llvm.ssub.sat.i64(i64 %a, i64 %b)
16348 declare <4 x i32> @llvm.ssub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16353 The '``llvm.ssub.sat``' family of intrinsic functions perform signed
16354 saturating subtraction on the 2 arguments.
16359 The arguments (%a and %b) and the result may be of integer types of any bit
16360 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16361 values that will undergo signed subtraction.
16366 The maximum value this operation can clamp to is the largest signed value
16367 representable by the bit width of the arguments. The minimum value is the
16368 smallest signed value representable by this bit width.
16374 .. code-block:: llvm
16376 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 1) ; %res = 1
16377 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 6) ; %res = -4
16378 %res = call i4 @llvm.ssub.sat.i4(i4 -4, i4 5) ; %res = -8
16379 %res = call i4 @llvm.ssub.sat.i4(i4 4, i4 -5) ; %res = 7
16382 '``llvm.usub.sat.*``' Intrinsics
16383 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16388 This is an overloaded intrinsic. You can use ``llvm.usub.sat``
16389 on any integer bit width or vectors of integers.
16393 declare i16 @llvm.usub.sat.i16(i16 %a, i16 %b)
16394 declare i32 @llvm.usub.sat.i32(i32 %a, i32 %b)
16395 declare i64 @llvm.usub.sat.i64(i64 %a, i64 %b)
16396 declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16401 The '``llvm.usub.sat``' family of intrinsic functions perform unsigned
16402 saturating subtraction on the 2 arguments.
16407 The arguments (%a and %b) and the result may be of integer types of any bit
16408 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16409 values that will undergo unsigned subtraction.
16414 The minimum value this operation can clamp to is 0, which is the smallest
16415 unsigned value representable by the bit width of the unsigned arguments.
16416 Because this is an unsigned operation, the result will never saturate towards
16417 the largest possible value representable by this bit width.
16423 .. code-block:: llvm
16425 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 1) ; %res = 1
16426 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 6) ; %res = 0
16429 '``llvm.sshl.sat.*``' Intrinsics
16430 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16435 This is an overloaded intrinsic. You can use ``llvm.sshl.sat``
16436 on integers or vectors of integers of any bit width.
16440 declare i16 @llvm.sshl.sat.i16(i16 %a, i16 %b)
16441 declare i32 @llvm.sshl.sat.i32(i32 %a, i32 %b)
16442 declare i64 @llvm.sshl.sat.i64(i64 %a, i64 %b)
16443 declare <4 x i32> @llvm.sshl.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16448 The '``llvm.sshl.sat``' family of intrinsic functions perform signed
16449 saturating left shift on the first argument.
16454 The arguments (``%a`` and ``%b``) and the result may be of integer types of any
16455 bit width, but they must have the same bit width. ``%a`` is the value to be
16456 shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or
16457 dynamically) equal to or larger than the integer bit width of the arguments,
16458 the result is a :ref:`poison value <poisonvalues>`. If the arguments are
16459 vectors, each vector element of ``a`` is shifted by the corresponding shift
16466 The maximum value this operation can clamp to is the largest signed value
16467 representable by the bit width of the arguments. The minimum value is the
16468 smallest signed value representable by this bit width.
16474 .. code-block:: llvm
16476 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 1) ; %res = 4
16477 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 2) ; %res = 7
16478 %res = call i4 @llvm.sshl.sat.i4(i4 -5, i4 1) ; %res = -8
16479 %res = call i4 @llvm.sshl.sat.i4(i4 -1, i4 1) ; %res = -2
16482 '``llvm.ushl.sat.*``' Intrinsics
16483 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16488 This is an overloaded intrinsic. You can use ``llvm.ushl.sat``
16489 on integers or vectors of integers of any bit width.
16493 declare i16 @llvm.ushl.sat.i16(i16 %a, i16 %b)
16494 declare i32 @llvm.ushl.sat.i32(i32 %a, i32 %b)
16495 declare i64 @llvm.ushl.sat.i64(i64 %a, i64 %b)
16496 declare <4 x i32> @llvm.ushl.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16501 The '``llvm.ushl.sat``' family of intrinsic functions perform unsigned
16502 saturating left shift on the first argument.
16507 The arguments (``%a`` and ``%b``) and the result may be of integer types of any
16508 bit width, but they must have the same bit width. ``%a`` is the value to be
16509 shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or
16510 dynamically) equal to or larger than the integer bit width of the arguments,
16511 the result is a :ref:`poison value <poisonvalues>`. If the arguments are
16512 vectors, each vector element of ``a`` is shifted by the corresponding shift
16518 The maximum value this operation can clamp to is the largest unsigned value
16519 representable by the bit width of the arguments.
16525 .. code-block:: llvm
16527 %res = call i4 @llvm.ushl.sat.i4(i4 2, i4 1) ; %res = 4
16528 %res = call i4 @llvm.ushl.sat.i4(i4 3, i4 3) ; %res = 15
16531 Fixed Point Arithmetic Intrinsics
16532 ---------------------------------
16534 A fixed point number represents a real data type for a number that has a fixed
16535 number of digits after a radix point (equivalent to the decimal point '.').
16536 The number of digits after the radix point is referred as the `scale`. These
16537 are useful for representing fractional values to a specific precision. The
16538 following intrinsics perform fixed point arithmetic operations on 2 operands
16539 of the same scale, specified as the third argument.
16541 The ``llvm.*mul.fix`` family of intrinsic functions represents a multiplication
16542 of fixed point numbers through scaled integers. Therefore, fixed point
16543 multiplication can be represented as
16545 .. code-block:: llvm
16547 %result = call i4 @llvm.smul.fix.i4(i4 %a, i4 %b, i32 %scale)
16550 %a2 = sext i4 %a to i8
16551 %b2 = sext i4 %b to i8
16552 %mul = mul nsw nuw i8 %a2, %b2
16553 %scale2 = trunc i32 %scale to i8
16554 %r = ashr i8 %mul, i8 %scale2 ; this is for a target rounding down towards negative infinity
16555 %result = trunc i8 %r to i4
16557 The ``llvm.*div.fix`` family of intrinsic functions represents a division of
16558 fixed point numbers through scaled integers. Fixed point division can be
16561 .. code-block:: llvm
16563 %result call i4 @llvm.sdiv.fix.i4(i4 %a, i4 %b, i32 %scale)
16566 %a2 = sext i4 %a to i8
16567 %b2 = sext i4 %b to i8
16568 %scale2 = trunc i32 %scale to i8
16569 %a3 = shl i8 %a2, %scale2
16570 %r = sdiv i8 %a3, %b2 ; this is for a target rounding towards zero
16571 %result = trunc i8 %r to i4
16573 For each of these functions, if the result cannot be represented exactly with
16574 the provided scale, the result is rounded. Rounding is unspecified since
16575 preferred rounding may vary for different targets. Rounding is specified
16576 through a target hook. Different pipelines should legalize or optimize this
16577 using the rounding specified by this hook if it is provided. Operations like
16578 constant folding, instruction combining, KnownBits, and ValueTracking should
16579 also use this hook, if provided, and not assume the direction of rounding. A
16580 rounded result must always be within one unit of precision from the true
16581 result. That is, the error between the returned result and the true result must
16582 be less than 1/2^(scale).
16585 '``llvm.smul.fix.*``' Intrinsics
16586 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16591 This is an overloaded intrinsic. You can use ``llvm.smul.fix``
16592 on any integer bit width or vectors of integers.
16596 declare i16 @llvm.smul.fix.i16(i16 %a, i16 %b, i32 %scale)
16597 declare i32 @llvm.smul.fix.i32(i32 %a, i32 %b, i32 %scale)
16598 declare i64 @llvm.smul.fix.i64(i64 %a, i64 %b, i32 %scale)
16599 declare <4 x i32> @llvm.smul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16604 The '``llvm.smul.fix``' family of intrinsic functions perform signed
16605 fixed point multiplication on 2 arguments of the same scale.
16610 The arguments (%a and %b) and the result may be of integer types of any bit
16611 width, but they must have the same bit width. The arguments may also work with
16612 int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16613 values that will undergo signed fixed point multiplication. The argument
16614 ``%scale`` represents the scale of both operands, and must be a constant
16620 This operation performs fixed point multiplication on the 2 arguments of a
16621 specified scale. The result will also be returned in the same scale specified
16622 in the third argument.
16624 If the result value cannot be precisely represented in the given scale, the
16625 value is rounded up or down to the closest representable value. The rounding
16626 direction is unspecified.
16628 It is undefined behavior if the result value does not fit within the range of
16629 the fixed point type.
16635 .. code-block:: llvm
16637 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
16638 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
16639 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5)
16641 ; The result in the following could be rounded up to -2 or down to -2.5
16642 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25)
16645 '``llvm.umul.fix.*``' Intrinsics
16646 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16651 This is an overloaded intrinsic. You can use ``llvm.umul.fix``
16652 on any integer bit width or vectors of integers.
16656 declare i16 @llvm.umul.fix.i16(i16 %a, i16 %b, i32 %scale)
16657 declare i32 @llvm.umul.fix.i32(i32 %a, i32 %b, i32 %scale)
16658 declare i64 @llvm.umul.fix.i64(i64 %a, i64 %b, i32 %scale)
16659 declare <4 x i32> @llvm.umul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16664 The '``llvm.umul.fix``' family of intrinsic functions perform unsigned
16665 fixed point multiplication on 2 arguments of the same scale.
16670 The arguments (%a and %b) and the result may be of integer types of any bit
16671 width, but they must have the same bit width. The arguments may also work with
16672 int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16673 values that will undergo unsigned fixed point multiplication. The argument
16674 ``%scale`` represents the scale of both operands, and must be a constant
16680 This operation performs unsigned fixed point multiplication on the 2 arguments of a
16681 specified scale. The result will also be returned in the same scale specified
16682 in the third argument.
16684 If the result value cannot be precisely represented in the given scale, the
16685 value is rounded up or down to the closest representable value. The rounding
16686 direction is unspecified.
16688 It is undefined behavior if the result value does not fit within the range of
16689 the fixed point type.
16695 .. code-block:: llvm
16697 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
16698 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
16700 ; The result in the following could be rounded down to 3.5 or up to 4
16701 %res = call i4 @llvm.umul.fix.i4(i4 15, i4 1, i32 1) ; %res = 7 (or 8) (7.5 x 0.5 = 3.75)
16704 '``llvm.smul.fix.sat.*``' Intrinsics
16705 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16710 This is an overloaded intrinsic. You can use ``llvm.smul.fix.sat``
16711 on any integer bit width or vectors of integers.
16715 declare i16 @llvm.smul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16716 declare i32 @llvm.smul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16717 declare i64 @llvm.smul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16718 declare <4 x i32> @llvm.smul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16723 The '``llvm.smul.fix.sat``' family of intrinsic functions perform signed
16724 fixed point saturating multiplication on 2 arguments of the same scale.
16729 The arguments (%a and %b) and the result may be of integer types of any bit
16730 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16731 values that will undergo signed fixed point multiplication. The argument
16732 ``%scale`` represents the scale of both operands, and must be a constant
16738 This operation performs fixed point multiplication on the 2 arguments of a
16739 specified scale. The result will also be returned in the same scale specified
16740 in the third argument.
16742 If the result value cannot be precisely represented in the given scale, the
16743 value is rounded up or down to the closest representable value. The rounding
16744 direction is unspecified.
16746 The maximum value this operation can clamp to is the largest signed value
16747 representable by the bit width of the first 2 arguments. The minimum value is the
16748 smallest signed value representable by this bit width.
16754 .. code-block:: llvm
16756 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
16757 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
16758 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5)
16760 ; The result in the following could be rounded up to -2 or down to -2.5
16761 %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)
16764 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 0) ; %res = 7
16765 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 4, i32 2) ; %res = 7
16766 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 5, i32 2) ; %res = -8
16767 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 -2, i32 1) ; %res = 7
16769 ; Scale can affect the saturation result
16770 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7)
16771 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2)
16774 '``llvm.umul.fix.sat.*``' Intrinsics
16775 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16780 This is an overloaded intrinsic. You can use ``llvm.umul.fix.sat``
16781 on any integer bit width or vectors of integers.
16785 declare i16 @llvm.umul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16786 declare i32 @llvm.umul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16787 declare i64 @llvm.umul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16788 declare <4 x i32> @llvm.umul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16793 The '``llvm.umul.fix.sat``' family of intrinsic functions perform unsigned
16794 fixed point saturating multiplication on 2 arguments of the same scale.
16799 The arguments (%a and %b) and the result may be of integer types of any bit
16800 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16801 values that will undergo unsigned fixed point multiplication. The argument
16802 ``%scale`` represents the scale of both operands, and must be a constant
16808 This operation performs fixed point multiplication on the 2 arguments of a
16809 specified scale. The result will also be returned in the same scale specified
16810 in the third argument.
16812 If the result value cannot be precisely represented in the given scale, the
16813 value is rounded up or down to the closest representable value. The rounding
16814 direction is unspecified.
16816 The maximum value this operation can clamp to is the largest unsigned value
16817 representable by the bit width of the first 2 arguments. The minimum value is the
16818 smallest unsigned value representable by this bit width (zero).
16824 .. code-block:: llvm
16826 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
16827 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
16829 ; The result in the following could be rounded down to 2 or up to 2.5
16830 %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)
16833 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 2, i32 0) ; %res = 15 (8 x 2 -> clamped to 15)
16834 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 8, i32 2) ; %res = 15 (2 x 2 -> clamped to 3.75)
16836 ; Scale can affect the saturation result
16837 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7)
16838 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2)
16841 '``llvm.sdiv.fix.*``' Intrinsics
16842 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16847 This is an overloaded intrinsic. You can use ``llvm.sdiv.fix``
16848 on any integer bit width or vectors of integers.
16852 declare i16 @llvm.sdiv.fix.i16(i16 %a, i16 %b, i32 %scale)
16853 declare i32 @llvm.sdiv.fix.i32(i32 %a, i32 %b, i32 %scale)
16854 declare i64 @llvm.sdiv.fix.i64(i64 %a, i64 %b, i32 %scale)
16855 declare <4 x i32> @llvm.sdiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16860 The '``llvm.sdiv.fix``' family of intrinsic functions perform signed
16861 fixed point division on 2 arguments of the same scale.
16866 The arguments (%a and %b) and the result may be of integer types of any bit
16867 width, but they must have the same bit width. The arguments may also work with
16868 int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16869 values that will undergo signed fixed point division. The argument
16870 ``%scale`` represents the scale of both operands, and must be a constant
16876 This operation performs fixed point division on the 2 arguments of a
16877 specified scale. The result will also be returned in the same scale specified
16878 in the third argument.
16880 If the result value cannot be precisely represented in the given scale, the
16881 value is rounded up or down to the closest representable value. The rounding
16882 direction is unspecified.
16884 It is undefined behavior if the result value does not fit within the range of
16885 the fixed point type, or if the second argument is zero.
16891 .. code-block:: llvm
16893 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3)
16894 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5)
16895 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5)
16897 ; The result in the following could be rounded up to 1 or down to 0.5
16898 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75)
16901 '``llvm.udiv.fix.*``' Intrinsics
16902 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16907 This is an overloaded intrinsic. You can use ``llvm.udiv.fix``
16908 on any integer bit width or vectors of integers.
16912 declare i16 @llvm.udiv.fix.i16(i16 %a, i16 %b, i32 %scale)
16913 declare i32 @llvm.udiv.fix.i32(i32 %a, i32 %b, i32 %scale)
16914 declare i64 @llvm.udiv.fix.i64(i64 %a, i64 %b, i32 %scale)
16915 declare <4 x i32> @llvm.udiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16920 The '``llvm.udiv.fix``' family of intrinsic functions perform unsigned
16921 fixed point division on 2 arguments of the same scale.
16926 The arguments (%a and %b) and the result may be of integer types of any bit
16927 width, but they must have the same bit width. The arguments may also work with
16928 int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16929 values that will undergo unsigned fixed point division. The argument
16930 ``%scale`` represents the scale of both operands, and must be a constant
16936 This operation performs fixed point division on the 2 arguments of a
16937 specified scale. The result will also be returned in the same scale specified
16938 in the third argument.
16940 If the result value cannot be precisely represented in the given scale, the
16941 value is rounded up or down to the closest representable value. The rounding
16942 direction is unspecified.
16944 It is undefined behavior if the result value does not fit within the range of
16945 the fixed point type, or if the second argument is zero.
16951 .. code-block:: llvm
16953 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3)
16954 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5)
16955 %res = call i4 @llvm.udiv.fix.i4(i4 1, i4 -8, i32 4) ; %res = 2 (0.0625 / 0.5 = 0.125)
16957 ; The result in the following could be rounded up to 1 or down to 0.5
16958 %res = call i4 @llvm.udiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75)
16961 '``llvm.sdiv.fix.sat.*``' Intrinsics
16962 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16967 This is an overloaded intrinsic. You can use ``llvm.sdiv.fix.sat``
16968 on any integer bit width or vectors of integers.
16972 declare i16 @llvm.sdiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16973 declare i32 @llvm.sdiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16974 declare i64 @llvm.sdiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16975 declare <4 x i32> @llvm.sdiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16980 The '``llvm.sdiv.fix.sat``' family of intrinsic functions perform signed
16981 fixed point saturating division on 2 arguments of the same scale.
16986 The arguments (%a and %b) and the result may be of integer types of any bit
16987 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16988 values that will undergo signed fixed point division. The argument
16989 ``%scale`` represents the scale of both operands, and must be a constant
16995 This operation performs fixed point division on the 2 arguments of a
16996 specified scale. The result will also be returned in the same scale specified
16997 in the third argument.
16999 If the result value cannot be precisely represented in the given scale, the
17000 value is rounded up or down to the closest representable value. The rounding
17001 direction is unspecified.
17003 The maximum value this operation can clamp to is the largest signed value
17004 representable by the bit width of the first 2 arguments. The minimum value is the
17005 smallest signed value representable by this bit width.
17007 It is undefined behavior if the second argument is zero.
17013 .. code-block:: llvm
17015 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3)
17016 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5)
17017 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5)
17019 ; The result in the following could be rounded up to 1 or down to 0.5
17020 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75)
17023 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -8, i4 -1, i32 0) ; %res = 7 (-8 / -1 = 8 => 7)
17024 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 4, i4 2, i32 2) ; %res = 7 (1 / 0.5 = 2 => 1.75)
17025 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -4, i4 1, i32 2) ; %res = -8 (-1 / 0.25 = -4 => -2)
17028 '``llvm.udiv.fix.sat.*``' Intrinsics
17029 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17034 This is an overloaded intrinsic. You can use ``llvm.udiv.fix.sat``
17035 on any integer bit width or vectors of integers.
17039 declare i16 @llvm.udiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
17040 declare i32 @llvm.udiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
17041 declare i64 @llvm.udiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
17042 declare <4 x i32> @llvm.udiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
17047 The '``llvm.udiv.fix.sat``' family of intrinsic functions perform unsigned
17048 fixed point saturating division on 2 arguments of the same scale.
17053 The arguments (%a and %b) and the result may be of integer types of any bit
17054 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
17055 values that will undergo unsigned fixed point division. The argument
17056 ``%scale`` represents the scale of both operands, and must be a constant
17062 This operation performs fixed point division on the 2 arguments of a
17063 specified scale. The result will also be returned in the same scale specified
17064 in the third argument.
17066 If the result value cannot be precisely represented in the given scale, the
17067 value is rounded up or down to the closest representable value. The rounding
17068 direction is unspecified.
17070 The maximum value this operation can clamp to is the largest unsigned value
17071 representable by the bit width of the first 2 arguments. The minimum value is the
17072 smallest unsigned value representable by this bit width (zero).
17074 It is undefined behavior if the second argument is zero.
17079 .. code-block:: llvm
17081 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3)
17082 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5)
17084 ; The result in the following could be rounded down to 0.5 or up to 1
17085 %res = call i4 @llvm.udiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 1 (or 2) (1.5 / 2 = 0.75)
17088 %res = call i4 @llvm.udiv.fix.sat.i4(i4 8, i4 2, i32 2) ; %res = 15 (2 / 0.5 = 4 => 3.75)
17091 Specialised Arithmetic Intrinsics
17092 ---------------------------------
17094 .. _i_intr_llvm_canonicalize:
17096 '``llvm.canonicalize.*``' Intrinsic
17097 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17104 declare float @llvm.canonicalize.f32(float %a)
17105 declare double @llvm.canonicalize.f64(double %b)
17110 The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical
17111 encoding of a floating-point number. This canonicalization is useful for
17112 implementing certain numeric primitives such as frexp. The canonical encoding is
17113 defined by IEEE-754-2008 to be:
17117 2.1.8 canonical encoding: The preferred encoding of a floating-point
17118 representation in a format. Applied to declets, significands of finite
17119 numbers, infinities, and NaNs, especially in decimal formats.
17121 This operation can also be considered equivalent to the IEEE-754-2008
17122 conversion of a floating-point value to the same format. NaNs are handled
17123 according to section 6.2.
17125 Examples of non-canonical encodings:
17127 - x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are
17128 converted to a canonical representation per hardware-specific protocol.
17129 - Many normal decimal floating-point numbers have non-canonical alternative
17131 - Some machines, like GPUs or ARMv7 NEON, do not support subnormal values.
17132 These are treated as non-canonical encodings of zero and will be flushed to
17133 a zero of the same sign by this operation.
17135 Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with
17136 default exception handling must signal an invalid exception, and produce a
17139 This function should always be implementable as multiplication by 1.0, provided
17140 that the compiler does not constant fold the operation. Likewise, division by
17141 1.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with
17142 -0.0 is also sufficient provided that the rounding mode is not -Infinity.
17144 ``@llvm.canonicalize`` must preserve the equality relation. That is:
17146 - ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)``
17147 - ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent
17150 Additionally, the sign of zero must be conserved:
17151 ``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0``
17153 The payload bits of a NaN must be conserved, with two exceptions.
17154 First, environments which use only a single canonical representation of NaN
17155 must perform said canonicalization. Second, SNaNs must be quieted per the
17158 The canonicalization operation may be optimized away if:
17160 - The input is known to be canonical. For example, it was produced by a
17161 floating-point operation that is required by the standard to be canonical.
17162 - The result is consumed only by (or fused with) other floating-point
17163 operations. That is, the bits of the floating-point value are not examined.
17167 '``llvm.fmuladd.*``' Intrinsic
17168 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17175 declare float @llvm.fmuladd.f32(float %a, float %b, float %c)
17176 declare double @llvm.fmuladd.f64(double %a, double %b, double %c)
17181 The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add
17182 expressions that can be fused if the code generator determines that (a) the
17183 target instruction set has support for a fused operation, and (b) that the
17184 fused operation is more efficient than the equivalent, separate pair of mul
17185 and add instructions.
17190 The '``llvm.fmuladd.*``' intrinsics each take three arguments: two
17191 multiplicands, a and b, and an addend c.
17200 %0 = call float @llvm.fmuladd.f32(%a, %b, %c)
17202 is equivalent to the expression a \* b + c, except that it is unspecified
17203 whether rounding will be performed between the multiplication and addition
17204 steps. Fusion is not guaranteed, even if the target platform supports it.
17205 If a fused multiply-add is required, the corresponding
17206 :ref:`llvm.fma <int_fma>` intrinsic function should be used instead.
17207 This never sets errno, just as '``llvm.fma.*``'.
17212 .. code-block:: llvm
17214 %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c
17217 Hardware-Loop Intrinsics
17218 ------------------------
17220 LLVM support several intrinsics to mark a loop as a hardware-loop. They are
17221 hints to the backend which are required to lower these intrinsics further to target
17222 specific instructions, or revert the hardware-loop to a normal loop if target
17223 specific restriction are not met and a hardware-loop can't be generated.
17225 These intrinsics may be modified in the future and are not intended to be used
17226 outside the backend. Thus, front-end and mid-level optimizations should not be
17227 generating these intrinsics.
17230 '``llvm.set.loop.iterations.*``' Intrinsic
17231 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17236 This is an overloaded intrinsic.
17240 declare void @llvm.set.loop.iterations.i32(i32)
17241 declare void @llvm.set.loop.iterations.i64(i64)
17246 The '``llvm.set.loop.iterations.*``' intrinsics are used to specify the
17247 hardware-loop trip count. They are placed in the loop preheader basic block and
17248 are marked as ``IntrNoDuplicate`` to avoid optimizers duplicating these
17254 The integer operand is the loop trip count of the hardware-loop, and thus
17255 not e.g. the loop back-edge taken count.
17260 The '``llvm.set.loop.iterations.*``' intrinsics do not perform any arithmetic
17261 on their operand. It's a hint to the backend that can use this to set up the
17262 hardware-loop count with a target specific instruction, usually a move of this
17263 value to a special register or a hardware-loop instruction.
17266 '``llvm.start.loop.iterations.*``' Intrinsic
17267 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17272 This is an overloaded intrinsic.
17276 declare i32 @llvm.start.loop.iterations.i32(i32)
17277 declare i64 @llvm.start.loop.iterations.i64(i64)
17282 The '``llvm.start.loop.iterations.*``' intrinsics are similar to the
17283 '``llvm.set.loop.iterations.*``' intrinsics, used to specify the
17284 hardware-loop trip count but also produce a value identical to the input
17285 that can be used as the input to the loop. They are placed in the loop
17286 preheader basic block and the output is expected to be the input to the
17287 phi for the induction variable of the loop, decremented by the
17288 '``llvm.loop.decrement.reg.*``'.
17293 The integer operand is the loop trip count of the hardware-loop, and thus
17294 not e.g. the loop back-edge taken count.
17299 The '``llvm.start.loop.iterations.*``' intrinsics do not perform any arithmetic
17300 on their operand. It's a hint to the backend that can use this to set up the
17301 hardware-loop count with a target specific instruction, usually a move of this
17302 value to a special register or a hardware-loop instruction.
17304 '``llvm.test.set.loop.iterations.*``' Intrinsic
17305 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17310 This is an overloaded intrinsic.
17314 declare i1 @llvm.test.set.loop.iterations.i32(i32)
17315 declare i1 @llvm.test.set.loop.iterations.i64(i64)
17320 The '``llvm.test.set.loop.iterations.*``' intrinsics are used to specify the
17321 the loop trip count, and also test that the given count is not zero, allowing
17322 it to control entry to a while-loop. They are placed in the loop preheader's
17323 predecessor basic block, and are marked as ``IntrNoDuplicate`` to avoid
17324 optimizers duplicating these instructions.
17329 The integer operand is the loop trip count of the hardware-loop, and thus
17330 not e.g. the loop back-edge taken count.
17335 The '``llvm.test.set.loop.iterations.*``' intrinsics do not perform any
17336 arithmetic on their operand. It's a hint to the backend that can use this to
17337 set up the hardware-loop count with a target specific instruction, usually a
17338 move of this value to a special register or a hardware-loop instruction.
17339 The result is the conditional value of whether the given count is not zero.
17342 '``llvm.test.start.loop.iterations.*``' Intrinsic
17343 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17348 This is an overloaded intrinsic.
17352 declare {i32, i1} @llvm.test.start.loop.iterations.i32(i32)
17353 declare {i64, i1} @llvm.test.start.loop.iterations.i64(i64)
17358 The '``llvm.test.start.loop.iterations.*``' intrinsics are similar to the
17359 '``llvm.test.set.loop.iterations.*``' and '``llvm.start.loop.iterations.*``'
17360 intrinsics, used to specify the hardware-loop trip count, but also produce a
17361 value identical to the input that can be used as the input to the loop. The
17362 second i1 output controls entry to a while-loop.
17367 The integer operand is the loop trip count of the hardware-loop, and thus
17368 not e.g. the loop back-edge taken count.
17373 The '``llvm.test.start.loop.iterations.*``' intrinsics do not perform any
17374 arithmetic on their operand. It's a hint to the backend that can use this to
17375 set up the hardware-loop count with a target specific instruction, usually a
17376 move of this value to a special register or a hardware-loop instruction.
17377 The result is a pair of the input and a conditional value of whether the
17378 given count is not zero.
17381 '``llvm.loop.decrement.reg.*``' Intrinsic
17382 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17387 This is an overloaded intrinsic.
17391 declare i32 @llvm.loop.decrement.reg.i32(i32, i32)
17392 declare i64 @llvm.loop.decrement.reg.i64(i64, i64)
17397 The '``llvm.loop.decrement.reg.*``' intrinsics are used to lower the loop
17398 iteration counter and return an updated value that will be used in the next
17404 Both arguments must have identical integer types. The first operand is the
17405 loop iteration counter. The second operand is the maximum number of elements
17406 processed in an iteration.
17411 The '``llvm.loop.decrement.reg.*``' intrinsics do an integer ``SUB`` of its
17412 two operands, which is not allowed to wrap. They return the remaining number of
17413 iterations still to be executed, and can be used together with a ``PHI``,
17414 ``ICMP`` and ``BR`` to control the number of loop iterations executed. Any
17415 optimisations are allowed to treat it is a ``SUB``, and it is supported by
17416 SCEV, so it's the backends responsibility to handle cases where it may be
17417 optimised. These intrinsics are marked as ``IntrNoDuplicate`` to avoid
17418 optimizers duplicating these instructions.
17421 '``llvm.loop.decrement.*``' Intrinsic
17422 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17427 This is an overloaded intrinsic.
17431 declare i1 @llvm.loop.decrement.i32(i32)
17432 declare i1 @llvm.loop.decrement.i64(i64)
17437 The HardwareLoops pass allows the loop decrement value to be specified with an
17438 option. It defaults to a loop decrement value of 1, but it can be an unsigned
17439 integer value provided by this option. The '``llvm.loop.decrement.*``'
17440 intrinsics decrement the loop iteration counter with this value, and return a
17441 false predicate if the loop should exit, and true otherwise.
17442 This is emitted if the loop counter is not updated via a ``PHI`` node, which
17443 can also be controlled with an option.
17448 The integer argument is the loop decrement value used to decrement the loop
17454 The '``llvm.loop.decrement.*``' intrinsics do a ``SUB`` of the loop iteration
17455 counter with the given loop decrement value, and return false if the loop
17456 should exit, this ``SUB`` is not allowed to wrap. The result is a condition
17457 that is used by the conditional branch controlling the loop.
17460 Vector Reduction Intrinsics
17461 ---------------------------
17463 Horizontal reductions of vectors can be expressed using the following
17464 intrinsics. Each one takes a vector operand as an input and applies its
17465 respective operation across all elements of the vector, returning a single
17466 scalar result of the same element type.
17468 .. _int_vector_reduce_add:
17470 '``llvm.vector.reduce.add.*``' Intrinsic
17471 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17478 declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a)
17479 declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a)
17484 The '``llvm.vector.reduce.add.*``' intrinsics do an integer ``ADD``
17485 reduction of a vector, returning the result as a scalar. The return type matches
17486 the element-type of the vector input.
17490 The argument to this intrinsic must be a vector of integer values.
17492 .. _int_vector_reduce_fadd:
17494 '``llvm.vector.reduce.fadd.*``' Intrinsic
17495 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17502 declare float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %a)
17503 declare double @llvm.vector.reduce.fadd.v2f64(double %start_value, <2 x double> %a)
17508 The '``llvm.vector.reduce.fadd.*``' intrinsics do a floating-point
17509 ``ADD`` reduction of a vector, returning the result as a scalar. The return type
17510 matches the element-type of the vector input.
17512 If the intrinsic call has the 'reassoc' flag set, then the reduction will not
17513 preserve the associativity of an equivalent scalarized counterpart. Otherwise
17514 the reduction will be *sequential*, thus implying that the operation respects
17515 the associativity of a scalarized reduction. That is, the reduction begins with
17516 the start value and performs an fadd operation with consecutively increasing
17517 vector element indices. See the following pseudocode:
17521 float sequential_fadd(start_value, input_vector)
17522 result = start_value
17523 for i = 0 to length(input_vector)
17524 result = result + input_vector[i]
17530 The first argument to this intrinsic is a scalar start value for the reduction.
17531 The type of the start value matches the element-type of the vector input.
17532 The second argument must be a vector of floating-point values.
17534 To ignore the start value, negative zero (``-0.0``) can be used, as it is
17535 the neutral value of floating point addition.
17542 %unord = call reassoc float @llvm.vector.reduce.fadd.v4f32(float -0.0, <4 x float> %input) ; relaxed reduction
17543 %ord = call float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %input) ; sequential reduction
17546 .. _int_vector_reduce_mul:
17548 '``llvm.vector.reduce.mul.*``' Intrinsic
17549 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17556 declare i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %a)
17557 declare i64 @llvm.vector.reduce.mul.v2i64(<2 x i64> %a)
17562 The '``llvm.vector.reduce.mul.*``' intrinsics do an integer ``MUL``
17563 reduction of a vector, returning the result as a scalar. The return type matches
17564 the element-type of the vector input.
17568 The argument to this intrinsic must be a vector of integer values.
17570 .. _int_vector_reduce_fmul:
17572 '``llvm.vector.reduce.fmul.*``' Intrinsic
17573 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17580 declare float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %a)
17581 declare double @llvm.vector.reduce.fmul.v2f64(double %start_value, <2 x double> %a)
17586 The '``llvm.vector.reduce.fmul.*``' intrinsics do a floating-point
17587 ``MUL`` reduction of a vector, returning the result as a scalar. The return type
17588 matches the element-type of the vector input.
17590 If the intrinsic call has the 'reassoc' flag set, then the reduction will not
17591 preserve the associativity of an equivalent scalarized counterpart. Otherwise
17592 the reduction will be *sequential*, thus implying that the operation respects
17593 the associativity of a scalarized reduction. That is, the reduction begins with
17594 the start value and performs an fmul operation with consecutively increasing
17595 vector element indices. See the following pseudocode:
17599 float sequential_fmul(start_value, input_vector)
17600 result = start_value
17601 for i = 0 to length(input_vector)
17602 result = result * input_vector[i]
17608 The first argument to this intrinsic is a scalar start value for the reduction.
17609 The type of the start value matches the element-type of the vector input.
17610 The second argument must be a vector of floating-point values.
17612 To ignore the start value, one (``1.0``) can be used, as it is the neutral
17613 value of floating point multiplication.
17620 %unord = call reassoc float @llvm.vector.reduce.fmul.v4f32(float 1.0, <4 x float> %input) ; relaxed reduction
17621 %ord = call float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %input) ; sequential reduction
17623 .. _int_vector_reduce_and:
17625 '``llvm.vector.reduce.and.*``' Intrinsic
17626 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17633 declare i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %a)
17638 The '``llvm.vector.reduce.and.*``' intrinsics do a bitwise ``AND``
17639 reduction of a vector, returning the result as a scalar. The return type matches
17640 the element-type of the vector input.
17644 The argument to this intrinsic must be a vector of integer values.
17646 .. _int_vector_reduce_or:
17648 '``llvm.vector.reduce.or.*``' Intrinsic
17649 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17656 declare i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %a)
17661 The '``llvm.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction
17662 of a vector, returning the result as a scalar. The return type matches the
17663 element-type of the vector input.
17667 The argument to this intrinsic must be a vector of integer values.
17669 .. _int_vector_reduce_xor:
17671 '``llvm.vector.reduce.xor.*``' Intrinsic
17672 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17679 declare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %a)
17684 The '``llvm.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR``
17685 reduction of a vector, returning the result as a scalar. The return type matches
17686 the element-type of the vector input.
17690 The argument to this intrinsic must be a vector of integer values.
17692 .. _int_vector_reduce_smax:
17694 '``llvm.vector.reduce.smax.*``' Intrinsic
17695 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17702 declare i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %a)
17707 The '``llvm.vector.reduce.smax.*``' intrinsics do a signed integer
17708 ``MAX`` reduction of a vector, returning the result as a scalar. The return type
17709 matches the element-type of the vector input.
17713 The argument to this intrinsic must be a vector of integer values.
17715 .. _int_vector_reduce_smin:
17717 '``llvm.vector.reduce.smin.*``' Intrinsic
17718 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17725 declare i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %a)
17730 The '``llvm.vector.reduce.smin.*``' intrinsics do a signed integer
17731 ``MIN`` reduction of a vector, returning the result as a scalar. The return type
17732 matches the element-type of the vector input.
17736 The argument to this intrinsic must be a vector of integer values.
17738 .. _int_vector_reduce_umax:
17740 '``llvm.vector.reduce.umax.*``' Intrinsic
17741 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17748 declare i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %a)
17753 The '``llvm.vector.reduce.umax.*``' intrinsics do an unsigned
17754 integer ``MAX`` reduction of a vector, returning the result as a scalar. The
17755 return type matches the element-type of the vector input.
17759 The argument to this intrinsic must be a vector of integer values.
17761 .. _int_vector_reduce_umin:
17763 '``llvm.vector.reduce.umin.*``' Intrinsic
17764 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17771 declare i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %a)
17776 The '``llvm.vector.reduce.umin.*``' intrinsics do an unsigned
17777 integer ``MIN`` reduction of a vector, returning the result as a scalar. The
17778 return type matches the element-type of the vector input.
17782 The argument to this intrinsic must be a vector of integer values.
17784 .. _int_vector_reduce_fmax:
17786 '``llvm.vector.reduce.fmax.*``' Intrinsic
17787 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17794 declare float @llvm.vector.reduce.fmax.v4f32(<4 x float> %a)
17795 declare double @llvm.vector.reduce.fmax.v2f64(<2 x double> %a)
17800 The '``llvm.vector.reduce.fmax.*``' intrinsics do a floating-point
17801 ``MAX`` reduction of a vector, returning the result as a scalar. The return type
17802 matches the element-type of the vector input.
17804 This instruction has the same comparison semantics as the '``llvm.maxnum.*``'
17805 intrinsic. That is, the result will always be a number unless all elements of
17806 the vector are NaN. For a vector with maximum element magnitude 0.0 and
17807 containing both +0.0 and -0.0 elements, the sign of the result is unspecified.
17809 If the intrinsic call has the ``nnan`` fast-math flag, then the operation can
17810 assume that NaNs are not present in the input vector.
17814 The argument to this intrinsic must be a vector of floating-point values.
17816 .. _int_vector_reduce_fmin:
17818 '``llvm.vector.reduce.fmin.*``' Intrinsic
17819 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17823 This is an overloaded intrinsic.
17827 declare float @llvm.vector.reduce.fmin.v4f32(<4 x float> %a)
17828 declare double @llvm.vector.reduce.fmin.v2f64(<2 x double> %a)
17833 The '``llvm.vector.reduce.fmin.*``' intrinsics do a floating-point
17834 ``MIN`` reduction of a vector, returning the result as a scalar. The return type
17835 matches the element-type of the vector input.
17837 This instruction has the same comparison semantics as the '``llvm.minnum.*``'
17838 intrinsic. That is, the result will always be a number unless all elements of
17839 the vector are NaN. For a vector with minimum element magnitude 0.0 and
17840 containing both +0.0 and -0.0 elements, the sign of the result is unspecified.
17842 If the intrinsic call has the ``nnan`` fast-math flag, then the operation can
17843 assume that NaNs are not present in the input vector.
17847 The argument to this intrinsic must be a vector of floating-point values.
17849 .. _int_vector_reduce_fmaximum:
17851 '``llvm.vector.reduce.fmaximum.*``' Intrinsic
17852 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17856 This is an overloaded intrinsic.
17860 declare float @llvm.vector.reduce.fmaximum.v4f32(<4 x float> %a)
17861 declare double @llvm.vector.reduce.fmaximum.v2f64(<2 x double> %a)
17866 The '``llvm.vector.reduce.fmaximum.*``' intrinsics do a floating-point
17867 ``MAX`` reduction of a vector, returning the result as a scalar. The return type
17868 matches the element-type of the vector input.
17870 This instruction has the same comparison semantics as the '``llvm.maximum.*``'
17871 intrinsic. That is, this intrinsic propagates NaNs and +0.0 is considered
17872 greater than -0.0. If any element of the vector is a NaN, the result is NaN.
17876 The argument to this intrinsic must be a vector of floating-point values.
17878 .. _int_vector_reduce_fminimum:
17880 '``llvm.vector.reduce.fminimum.*``' Intrinsic
17881 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17885 This is an overloaded intrinsic.
17889 declare float @llvm.vector.reduce.fminimum.v4f32(<4 x float> %a)
17890 declare double @llvm.vector.reduce.fminimum.v2f64(<2 x double> %a)
17895 The '``llvm.vector.reduce.fminimum.*``' intrinsics do a floating-point
17896 ``MIN`` reduction of a vector, returning the result as a scalar. The return type
17897 matches the element-type of the vector input.
17899 This instruction has the same comparison semantics as the '``llvm.minimum.*``'
17900 intrinsic. That is, this intrinsic propagates NaNs and -0.0 is considered less
17901 than +0.0. If any element of the vector is a NaN, the result is NaN.
17905 The argument to this intrinsic must be a vector of floating-point values.
17907 '``llvm.vector.insert``' Intrinsic
17908 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17912 This is an overloaded intrinsic.
17916 ; Insert fixed type into scalable type
17917 declare <vscale x 4 x float> @llvm.vector.insert.nxv4f32.v4f32(<vscale x 4 x float> %vec, <4 x float> %subvec, i64 <idx>)
17918 declare <vscale x 2 x double> @llvm.vector.insert.nxv2f64.v2f64(<vscale x 2 x double> %vec, <2 x double> %subvec, i64 <idx>)
17920 ; Insert scalable type into scalable type
17921 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>)
17923 ; Insert fixed type into fixed type
17924 declare <4 x double> @llvm.vector.insert.v4f64.v2f64(<4 x double> %vec, <2 x double> %subvec, i64 <idx>)
17929 The '``llvm.vector.insert.*``' intrinsics insert a vector into another vector
17930 starting from a given index. The return type matches the type of the vector we
17931 insert into. Conceptually, this can be used to build a scalable vector out of
17932 non-scalable vectors, however this intrinsic can also be used on purely fixed
17935 Scalable vectors can only be inserted into other scalable vectors.
17940 The ``vec`` is the vector which ``subvec`` will be inserted into.
17941 The ``subvec`` is the vector that will be inserted.
17943 ``idx`` represents the starting element number at which ``subvec`` will be
17944 inserted. ``idx`` must be a constant multiple of ``subvec``'s known minimum
17945 vector length. If ``subvec`` is a scalable vector, ``idx`` is first scaled by
17946 the runtime scaling factor of ``subvec``. The elements of ``vec`` starting at
17947 ``idx`` are overwritten with ``subvec``. Elements ``idx`` through (``idx`` +
17948 num_elements(``subvec``) - 1) must be valid ``vec`` indices. If this condition
17949 cannot be determined statically but is false at runtime, then the result vector
17950 is a :ref:`poison value <poisonvalues>`.
17953 '``llvm.vector.extract``' Intrinsic
17954 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17958 This is an overloaded intrinsic.
17962 ; Extract fixed type from scalable type
17963 declare <4 x float> @llvm.vector.extract.v4f32.nxv4f32(<vscale x 4 x float> %vec, i64 <idx>)
17964 declare <2 x double> @llvm.vector.extract.v2f64.nxv2f64(<vscale x 2 x double> %vec, i64 <idx>)
17966 ; Extract scalable type from scalable type
17967 declare <vscale x 2 x float> @llvm.vector.extract.nxv2f32.nxv4f32(<vscale x 4 x float> %vec, i64 <idx>)
17969 ; Extract fixed type from fixed type
17970 declare <2 x double> @llvm.vector.extract.v2f64.v4f64(<4 x double> %vec, i64 <idx>)
17975 The '``llvm.vector.extract.*``' intrinsics extract a vector from within another
17976 vector starting from a given index. The return type must be explicitly
17977 specified. Conceptually, this can be used to decompose a scalable vector into
17978 non-scalable parts, however this intrinsic can also be used on purely fixed
17981 Scalable vectors can only be extracted from other scalable vectors.
17986 The ``vec`` is the vector from which we will extract a subvector.
17988 The ``idx`` specifies the starting element number within ``vec`` from which a
17989 subvector is extracted. ``idx`` must be a constant multiple of the known-minimum
17990 vector length of the result type. If the result type is a scalable vector,
17991 ``idx`` is first scaled by the result type's runtime scaling factor. Elements
17992 ``idx`` through (``idx`` + num_elements(result_type) - 1) must be valid vector
17993 indices. If this condition cannot be determined statically but is false at
17994 runtime, then the result vector is a :ref:`poison value <poisonvalues>`. The
17995 ``idx`` parameter must be a vector index constant type (for most targets this
17996 will be an integer pointer type).
17998 '``llvm.experimental.vector.reverse``' Intrinsic
17999 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18003 This is an overloaded intrinsic.
18007 declare <2 x i8> @llvm.experimental.vector.reverse.v2i8(<2 x i8> %a)
18008 declare <vscale x 4 x i32> @llvm.experimental.vector.reverse.nxv4i32(<vscale x 4 x i32> %a)
18013 The '``llvm.experimental.vector.reverse.*``' intrinsics reverse a vector.
18014 The intrinsic takes a single vector and returns a vector of matching type but
18015 with the original lane order reversed. These intrinsics work for both fixed
18016 and scalable vectors. While this intrinsic is marked as experimental the
18017 recommended way to express reverse operations for fixed-width vectors is still
18018 to use a shufflevector, as that may allow for more optimization opportunities.
18023 The argument to this intrinsic must be a vector.
18025 '``llvm.experimental.vector.deinterleave2``' Intrinsic
18026 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18030 This is an overloaded intrinsic.
18034 declare {<2 x double>, <2 x double>} @llvm.experimental.vector.deinterleave2.v4f64(<4 x double> %vec1)
18035 declare {<vscale x 4 x i32>, <vscale x 4 x i32>} @llvm.experimental.vector.deinterleave2.nxv8i32(<vscale x 8 x i32> %vec1)
18040 The '``llvm.experimental.vector.deinterleave2``' intrinsic constructs two
18041 vectors by deinterleaving the even and odd lanes of the input vector.
18043 This intrinsic works for both fixed and scalable vectors. While this intrinsic
18044 supports all vector types the recommended way to express this operation for
18045 fixed-width vectors is still to use a shufflevector, as that may allow for more
18046 optimization opportunities.
18050 .. code-block:: text
18052 {<2 x i64>, <2 x i64>} llvm.experimental.vector.deinterleave2.v4i64(<4 x i64> <i64 0, i64 1, i64 2, i64 3>); ==> {<2 x i64> <i64 0, i64 2>, <2 x i64> <i64 1, i64 3>}
18057 The argument is a vector whose type corresponds to the logical concatenation of
18058 the two result types.
18060 '``llvm.experimental.vector.interleave2``' Intrinsic
18061 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18065 This is an overloaded intrinsic.
18069 declare <4 x double> @llvm.experimental.vector.interleave2.v4f64(<2 x double> %vec1, <2 x double> %vec2)
18070 declare <vscale x 8 x i32> @llvm.experimental.vector.interleave2.nxv8i32(<vscale x 4 x i32> %vec1, <vscale x 4 x i32> %vec2)
18075 The '``llvm.experimental.vector.interleave2``' intrinsic constructs a vector
18076 by interleaving two input vectors.
18078 This intrinsic works for both fixed and scalable vectors. While this intrinsic
18079 supports all vector types the recommended way to express this operation for
18080 fixed-width vectors is still to use a shufflevector, as that may allow for more
18081 optimization opportunities.
18085 .. code-block:: text
18087 <4 x i64> llvm.experimental.vector.interleave2.v4i64(<2 x i64> <i64 0, i64 2>, <2 x i64> <i64 1, i64 3>); ==> <4 x i64> <i64 0, i64 1, i64 2, i64 3>
18091 Both arguments must be vectors of the same type whereby their logical
18092 concatenation matches the result type.
18094 '``llvm.experimental.vector.splice``' Intrinsic
18095 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18099 This is an overloaded intrinsic.
18103 declare <2 x double> @llvm.experimental.vector.splice.v2f64(<2 x double> %vec1, <2 x double> %vec2, i32 %imm)
18104 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)
18109 The '``llvm.experimental.vector.splice.*``' intrinsics construct a vector by
18110 concatenating elements from the first input vector with elements of the second
18111 input vector, returning a vector of the same type as the input vectors. The
18112 signed immediate, modulo the number of elements in the vector, is the index
18113 into the first vector from which to extract the result value. This means
18114 conceptually that for a positive immediate, a vector is extracted from
18115 ``concat(%vec1, %vec2)`` starting at index ``imm``, whereas for a negative
18116 immediate, it extracts ``-imm`` trailing elements from the first vector, and
18117 the remaining elements from ``%vec2``.
18119 These intrinsics work for both fixed and scalable vectors. While this intrinsic
18120 is marked as experimental, the recommended way to express this operation for
18121 fixed-width vectors is still to use a shufflevector, as that may allow for more
18122 optimization opportunities.
18126 .. code-block:: text
18128 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, 1) ==> <B, C, D, E> ; index
18129 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, -3) ==> <B, C, D, E> ; trailing elements
18135 The first two operands are vectors with the same type. The start index is imm
18136 modulo the runtime number of elements in the source vector. For a fixed-width
18137 vector <N x eltty>, imm is a signed integer constant in the range
18138 -N <= imm < N. For a scalable vector <vscale x N x eltty>, imm is a signed
18139 integer constant in the range -X <= imm < X where X=vscale_range_min * N.
18141 '``llvm.experimental.stepvector``' Intrinsic
18142 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18144 This is an overloaded intrinsic. You can use ``llvm.experimental.stepvector``
18145 to generate a vector whose lane values comprise the linear sequence
18146 <0, 1, 2, ...>. It is primarily intended for scalable vectors.
18150 declare <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
18151 declare <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16()
18153 The '``llvm.experimental.stepvector``' intrinsics are used to create vectors
18154 of integers whose elements contain a linear sequence of values starting from 0
18155 with a step of 1. This experimental intrinsic can only be used for vectors
18156 with integer elements that are at least 8 bits in size. If the sequence value
18157 exceeds the allowed limit for the element type then the result for that lane is
18160 These intrinsics work for both fixed and scalable vectors. While this intrinsic
18161 is marked as experimental, the recommended way to express this operation for
18162 fixed-width vectors is still to generate a constant vector instead.
18171 '``llvm.experimental.get.vector.length``' Intrinsic
18172 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18176 This is an overloaded intrinsic.
18180 declare i32 @llvm.experimental.get.vector.length.i32(i32 %cnt, i32 immarg %vf, i1 immarg %scalable)
18181 declare i32 @llvm.experimental.get.vector.length.i64(i64 %cnt, i32 immarg %vf, i1 immarg %scalable)
18186 The '``llvm.experimental.get.vector.length.*``' intrinsics take a number of
18187 elements to process and returns how many of the elements can be processed
18188 with the requested vectorization factor.
18193 The first argument is an unsigned value of any scalar integer type and specifies
18194 the total number of elements to be processed. The second argument is an i32
18195 immediate for the vectorization factor. The third argument indicates if the
18196 vectorization factor should be multiplied by vscale.
18201 Returns a positive i32 value (explicit vector length) that is unknown at compile
18202 time and depends on the hardware specification.
18203 If the result value does not fit in the result type, then the result is
18204 a :ref:`poison value <poisonvalues>`.
18206 This intrinsic is intended to be used by loop vectorization with VP intrinsics
18207 in order to get the number of elements to process on each loop iteration. The
18208 result should be used to decrease the count for the next iteration until the
18209 count reaches zero.
18211 If the count is larger than the number of lanes in the type described by the
18212 last 2 arguments, this intrinsic may return a value less than the number of
18213 lanes implied by the type. The result will be at least as large as the result
18214 will be on any later loop iteration.
18216 This intrinsic will only return 0 if the input count is also 0. A non-zero input
18217 count will produce a non-zero result.
18222 Operations on matrixes requiring shape information (like number of rows/columns
18223 or the memory layout) can be expressed using the matrix intrinsics. These
18224 intrinsics require matrix dimensions to be passed as immediate arguments, and
18225 matrixes are passed and returned as vectors. This means that for a ``R`` x
18226 ``C`` matrix, element ``i`` of column ``j`` is at index ``j * R + i`` in the
18227 corresponding vector, with indices starting at 0. Currently column-major layout
18228 is assumed. The intrinsics support both integer and floating point matrixes.
18231 '``llvm.matrix.transpose.*``' Intrinsic
18232 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18236 This is an overloaded intrinsic.
18240 declare vectorty @llvm.matrix.transpose.*(vectorty %In, i32 <Rows>, i32 <Cols>)
18245 The '``llvm.matrix.transpose.*``' intrinsics treat ``%In`` as a ``<Rows> x
18246 <Cols>`` matrix and return the transposed matrix in the result vector.
18251 The first argument ``%In`` is a vector that corresponds to a ``<Rows> x
18252 <Cols>`` matrix. Thus, arguments ``<Rows>`` and ``<Cols>`` correspond to the
18253 number of rows and columns, respectively, and must be positive, constant
18254 integers. The returned vector must have ``<Rows> * <Cols>`` elements, and have
18255 the same float or integer element type as ``%In``.
18257 '``llvm.matrix.multiply.*``' Intrinsic
18258 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18262 This is an overloaded intrinsic.
18266 declare vectorty @llvm.matrix.multiply.*(vectorty %A, vectorty %B, i32 <OuterRows>, i32 <Inner>, i32 <OuterColumns>)
18271 The '``llvm.matrix.multiply.*``' intrinsics treat ``%A`` as a ``<OuterRows> x
18272 <Inner>`` matrix, ``%B`` as a ``<Inner> x <OuterColumns>`` matrix, and
18273 multiplies them. The result matrix is returned in the result vector.
18278 The first vector argument ``%A`` corresponds to a matrix with ``<OuterRows> *
18279 <Inner>`` elements, and the second argument ``%B`` to a matrix with
18280 ``<Inner> * <OuterColumns>`` elements. Arguments ``<OuterRows>``,
18281 ``<Inner>`` and ``<OuterColumns>`` must be positive, constant integers. The
18282 returned vector must have ``<OuterRows> * <OuterColumns>`` elements.
18283 Vectors ``%A``, ``%B``, and the returned vector all have the same float or
18284 integer element type.
18287 '``llvm.matrix.column.major.load.*``' Intrinsic
18288 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18292 This is an overloaded intrinsic.
18296 declare vectorty @llvm.matrix.column.major.load.*(
18297 ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>)
18302 The '``llvm.matrix.column.major.load.*``' intrinsics load a ``<Rows> x <Cols>``
18303 matrix using a stride of ``%Stride`` to compute the start address of the
18304 different columns. The offset is computed using ``%Stride``'s bitwidth. This
18305 allows for convenient loading of sub matrixes. If ``<IsVolatile>`` is true, the
18306 intrinsic is considered a :ref:`volatile memory access <volatile>`. The result
18307 matrix is returned in the result vector. If the ``%Ptr`` argument is known to
18308 be aligned to some boundary, this can be specified as an attribute on the
18314 The first argument ``%Ptr`` is a pointer type to the returned vector type, and
18315 corresponds to the start address to load from. The second argument ``%Stride``
18316 is a positive, constant integer with ``%Stride >= <Rows>``. ``%Stride`` is used
18317 to compute the column memory addresses. I.e., for a column ``C``, its start
18318 memory addresses is calculated with ``%Ptr + C * %Stride``. The third Argument
18319 ``<IsVolatile>`` is a boolean value. The fourth and fifth arguments,
18320 ``<Rows>`` and ``<Cols>``, correspond to the number of rows and columns,
18321 respectively, and must be positive, constant integers. The returned vector must
18322 have ``<Rows> * <Cols>`` elements.
18324 The :ref:`align <attr_align>` parameter attribute can be provided for the
18325 ``%Ptr`` arguments.
18328 '``llvm.matrix.column.major.store.*``' Intrinsic
18329 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18336 declare void @llvm.matrix.column.major.store.*(
18337 vectorty %In, ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>)
18342 The '``llvm.matrix.column.major.store.*``' intrinsics store the ``<Rows> x
18343 <Cols>`` matrix in ``%In`` to memory using a stride of ``%Stride`` between
18344 columns. The offset is computed using ``%Stride``'s bitwidth. If
18345 ``<IsVolatile>`` is true, the intrinsic is considered a
18346 :ref:`volatile memory access <volatile>`.
18348 If the ``%Ptr`` argument is known to be aligned to some boundary, this can be
18349 specified as an attribute on the argument.
18354 The first argument ``%In`` is a vector that corresponds to a ``<Rows> x
18355 <Cols>`` matrix to be stored to memory. The second argument ``%Ptr`` is a
18356 pointer to the vector type of ``%In``, and is the start address of the matrix
18357 in memory. The third argument ``%Stride`` is a positive, constant integer with
18358 ``%Stride >= <Rows>``. ``%Stride`` is used to compute the column memory
18359 addresses. I.e., for a column ``C``, its start memory addresses is calculated
18360 with ``%Ptr + C * %Stride``. The fourth argument ``<IsVolatile>`` is a boolean
18361 value. The arguments ``<Rows>`` and ``<Cols>`` correspond to the number of rows
18362 and columns, respectively, and must be positive, constant integers.
18364 The :ref:`align <attr_align>` parameter attribute can be provided
18365 for the ``%Ptr`` arguments.
18368 Half Precision Floating-Point Intrinsics
18369 ----------------------------------------
18371 For most target platforms, half precision floating-point is a
18372 storage-only format. This means that it is a dense encoding (in memory)
18373 but does not support computation in the format.
18375 This means that code must first load the half-precision floating-point
18376 value as an i16, then convert it to float with
18377 :ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can
18378 then be performed on the float value (including extending to double
18379 etc). To store the value back to memory, it is first converted to float
18380 if needed, then converted to i16 with
18381 :ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an
18384 .. _int_convert_to_fp16:
18386 '``llvm.convert.to.fp16``' Intrinsic
18387 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18394 declare i16 @llvm.convert.to.fp16.f32(float %a)
18395 declare i16 @llvm.convert.to.fp16.f64(double %a)
18400 The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
18401 conventional floating-point type to half precision floating-point format.
18406 The intrinsic function contains single argument - the value to be
18412 The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
18413 conventional floating-point format to half precision floating-point format. The
18414 return value is an ``i16`` which contains the converted number.
18419 .. code-block:: llvm
18421 %res = call i16 @llvm.convert.to.fp16.f32(float %a)
18422 store i16 %res, i16* @x, align 2
18424 .. _int_convert_from_fp16:
18426 '``llvm.convert.from.fp16``' Intrinsic
18427 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18434 declare float @llvm.convert.from.fp16.f32(i16 %a)
18435 declare double @llvm.convert.from.fp16.f64(i16 %a)
18440 The '``llvm.convert.from.fp16``' intrinsic function performs a
18441 conversion from half precision floating-point format to single precision
18442 floating-point format.
18447 The intrinsic function contains single argument - the value to be
18453 The '``llvm.convert.from.fp16``' intrinsic function performs a
18454 conversion from half single precision floating-point format to single
18455 precision floating-point format. The input half-float value is
18456 represented by an ``i16`` value.
18461 .. code-block:: llvm
18463 %a = load i16, ptr @x, align 2
18464 %res = call float @llvm.convert.from.fp16(i16 %a)
18466 Saturating floating-point to integer conversions
18467 ------------------------------------------------
18469 The ``fptoui`` and ``fptosi`` instructions return a
18470 :ref:`poison value <poisonvalues>` if the rounded-towards-zero value is not
18471 representable by the result type. These intrinsics provide an alternative
18472 conversion, which will saturate towards the smallest and largest representable
18473 integer values instead.
18475 '``llvm.fptoui.sat.*``' Intrinsic
18476 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18481 This is an overloaded intrinsic. You can use ``llvm.fptoui.sat`` on any
18482 floating-point argument type and any integer result type, or vectors thereof.
18483 Not all targets may support all types, however.
18487 declare i32 @llvm.fptoui.sat.i32.f32(float %f)
18488 declare i19 @llvm.fptoui.sat.i19.f64(double %f)
18489 declare <4 x i100> @llvm.fptoui.sat.v4i100.v4f128(<4 x fp128> %f)
18494 This intrinsic converts the argument into an unsigned integer using saturating
18500 The argument may be any floating-point or vector of floating-point type. The
18501 return value may be any integer or vector of integer type. The number of vector
18502 elements in argument and return must be the same.
18507 The conversion to integer is performed subject to the following rules:
18509 - If the argument is any NaN, zero is returned.
18510 - If the argument is smaller than zero (this includes negative infinity),
18512 - If the argument is larger than the largest representable unsigned integer of
18513 the result type (this includes positive infinity), the largest representable
18514 unsigned integer is returned.
18515 - Otherwise, the result of rounding the argument towards zero is returned.
18520 .. code-block:: text
18522 %a = call i8 @llvm.fptoui.sat.i8.f32(float 123.9) ; yields i8: 123
18523 %b = call i8 @llvm.fptoui.sat.i8.f32(float -5.7) ; yields i8: 0
18524 %c = call i8 @llvm.fptoui.sat.i8.f32(float 377.0) ; yields i8: 255
18525 %d = call i8 @llvm.fptoui.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0
18527 '``llvm.fptosi.sat.*``' Intrinsic
18528 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18533 This is an overloaded intrinsic. You can use ``llvm.fptosi.sat`` on any
18534 floating-point argument type and any integer result type, or vectors thereof.
18535 Not all targets may support all types, however.
18539 declare i32 @llvm.fptosi.sat.i32.f32(float %f)
18540 declare i19 @llvm.fptosi.sat.i19.f64(double %f)
18541 declare <4 x i100> @llvm.fptosi.sat.v4i100.v4f128(<4 x fp128> %f)
18546 This intrinsic converts the argument into a signed integer using saturating
18552 The argument may be any floating-point or vector of floating-point type. The
18553 return value may be any integer or vector of integer type. The number of vector
18554 elements in argument and return must be the same.
18559 The conversion to integer is performed subject to the following rules:
18561 - If the argument is any NaN, zero is returned.
18562 - If the argument is smaller than the smallest representable signed integer of
18563 the result type (this includes negative infinity), the smallest
18564 representable signed integer is returned.
18565 - If the argument is larger than the largest representable signed integer of
18566 the result type (this includes positive infinity), the largest representable
18567 signed integer is returned.
18568 - Otherwise, the result of rounding the argument towards zero is returned.
18573 .. code-block:: text
18575 %a = call i8 @llvm.fptosi.sat.i8.f32(float 23.9) ; yields i8: 23
18576 %b = call i8 @llvm.fptosi.sat.i8.f32(float -130.8) ; yields i8: -128
18577 %c = call i8 @llvm.fptosi.sat.i8.f32(float 999.0) ; yields i8: 127
18578 %d = call i8 @llvm.fptosi.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0
18580 .. _dbg_intrinsics:
18582 Debugger Intrinsics
18583 -------------------
18585 The LLVM debugger intrinsics (which all start with ``llvm.dbg.``
18586 prefix), are described in the `LLVM Source Level
18587 Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_
18590 Exception Handling Intrinsics
18591 -----------------------------
18593 The LLVM exception handling intrinsics (which all start with
18594 ``llvm.eh.`` prefix), are described in the `LLVM Exception
18595 Handling <ExceptionHandling.html#format-common-intrinsics>`_ document.
18597 Pointer Authentication Intrinsics
18598 ---------------------------------
18600 The LLVM pointer authentication intrinsics (which all start with
18601 ``llvm.ptrauth.`` prefix), are described in the `Pointer Authentication
18602 <PointerAuth.html#intrinsics>`_ document.
18604 .. _int_trampoline:
18606 Trampoline Intrinsics
18607 ---------------------
18609 These intrinsics make it possible to excise one parameter, marked with
18610 the :ref:`nest <nest>` attribute, from a function. The result is a
18611 callable function pointer lacking the nest parameter - the caller does
18612 not need to provide a value for it. Instead, the value to use is stored
18613 in advance in a "trampoline", a block of memory usually allocated on the
18614 stack, which also contains code to splice the nest value into the
18615 argument list. This is used to implement the GCC nested function address
18618 For example, if the function is ``i32 f(ptr nest %c, i32 %x, i32 %y)``
18619 then the resulting function pointer has signature ``i32 (i32, i32)``.
18620 It can be created as follows:
18622 .. code-block:: llvm
18624 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
18625 call ptr @llvm.init.trampoline(ptr %tramp, ptr @f, ptr %nval)
18626 %fp = call ptr @llvm.adjust.trampoline(ptr %tramp)
18628 The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to
18629 ``%val = call i32 %f(ptr %nval, i32 %x, i32 %y)``.
18633 '``llvm.init.trampoline``' Intrinsic
18634 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18641 declare void @llvm.init.trampoline(ptr <tramp>, ptr <func>, ptr <nval>)
18646 This fills the memory pointed to by ``tramp`` with executable code,
18647 turning it into a trampoline.
18652 The ``llvm.init.trampoline`` intrinsic takes three arguments, all
18653 pointers. The ``tramp`` argument must point to a sufficiently large and
18654 sufficiently aligned block of memory; this memory is written to by the
18655 intrinsic. Note that the size and the alignment are target-specific -
18656 LLVM currently provides no portable way of determining them, so a
18657 front-end that generates this intrinsic needs to have some
18658 target-specific knowledge. The ``func`` argument must hold a function.
18663 The block of memory pointed to by ``tramp`` is filled with target
18664 dependent code, turning it into a function. Then ``tramp`` needs to be
18665 passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can
18666 be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new
18667 function's signature is the same as that of ``func`` with any arguments
18668 marked with the ``nest`` attribute removed. At most one such ``nest``
18669 argument is allowed, and it must be of pointer type. Calling the new
18670 function is equivalent to calling ``func`` with the same argument list,
18671 but with ``nval`` used for the missing ``nest`` argument. If, after
18672 calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is
18673 modified, then the effect of any later call to the returned function
18674 pointer is undefined.
18678 '``llvm.adjust.trampoline``' Intrinsic
18679 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18686 declare ptr @llvm.adjust.trampoline(ptr <tramp>)
18691 This performs any required machine-specific adjustment to the address of
18692 a trampoline (passed as ``tramp``).
18697 ``tramp`` must point to a block of memory which already has trampoline
18698 code filled in by a previous call to
18699 :ref:`llvm.init.trampoline <int_it>`.
18704 On some architectures the address of the code to be executed needs to be
18705 different than the address where the trampoline is actually stored. This
18706 intrinsic returns the executable address corresponding to ``tramp``
18707 after performing the required machine specific adjustments. The pointer
18708 returned can then be :ref:`bitcast and executed <int_trampoline>`.
18713 Vector Predication Intrinsics
18714 -----------------------------
18715 VP intrinsics are intended for predicated SIMD/vector code. A typical VP
18716 operation takes a vector mask and an explicit vector length parameter as in:
18720 <W x T> llvm.vp.<opcode>.*(<W x T> %x, <W x T> %y, <W x i1> %mask, i32 %evl)
18722 The vector mask parameter (%mask) always has a vector of `i1` type, for example
18723 `<32 x i1>`. The explicit vector length parameter always has the type `i32` and
18724 is an unsigned integer value. The explicit vector length parameter (%evl) is in
18729 0 <= %evl <= W, where W is the number of vector elements
18731 Note that for :ref:`scalable vector types <t_vector>` ``W`` is the runtime
18732 length of the vector.
18734 The VP intrinsic has undefined behavior if ``%evl > W``. The explicit vector
18735 length (%evl) creates a mask, %EVLmask, with all elements ``0 <= i < %evl`` set
18736 to True, and all other lanes ``%evl <= i < W`` to False. A new mask %M is
18737 calculated with an element-wise AND from %mask and %EVLmask:
18741 M = %mask AND %EVLmask
18743 A vector operation ``<opcode>`` on vectors ``A`` and ``B`` calculates:
18747 A <opcode> B = { A[i] <opcode> B[i] M[i] = True, and
18753 Some targets, such as AVX512, do not support the %evl parameter in hardware.
18754 The use of an effective %evl is discouraged for those targets. The function
18755 ``TargetTransformInfo::hasActiveVectorLength()`` returns true when the target
18756 has native support for %evl.
18760 '``llvm.vp.select.*``' Intrinsics
18761 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18765 This is an overloaded intrinsic.
18769 declare <16 x i32> @llvm.vp.select.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <evl>)
18770 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>)
18775 The '``llvm.vp.select``' intrinsic is used to choose one value based on a
18776 condition vector, without IR-level branching.
18781 The first operand is a vector of ``i1`` and indicates the condition. The
18782 second operand is the value that is selected where the condition vector is
18783 true. The third operand is the value that is selected where the condition
18784 vector is false. The vectors must be of the same size. The fourth operand is
18785 the explicit vector length.
18787 #. The optional ``fast-math flags`` marker indicates that the select has one or
18788 more :ref:`fast-math flags <fastmath>`. These are optimization hints to
18789 enable otherwise unsafe floating-point optimizations. Fast-math flags are
18790 only valid for selects that return a floating-point scalar or vector type,
18791 or an array (nested to any depth) of floating-point scalar or vector types.
18796 The intrinsic selects lanes from the second and third operand depending on a
18799 All result lanes at positions greater or equal than ``%evl`` are undefined.
18800 For all lanes below ``%evl`` where the condition vector is true the lane is
18801 taken from the second operand. Otherwise, the lane is taken from the third
18807 .. code-block:: llvm
18809 %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)
18812 ;; Any result is legal on lanes at and above %evl.
18813 %also.r = select <4 x i1> %cond, <4 x i32> %on_true, <4 x i32> %on_false
18818 '``llvm.vp.merge.*``' Intrinsics
18819 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18823 This is an overloaded intrinsic.
18827 declare <16 x i32> @llvm.vp.merge.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <pivot>)
18828 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>)
18833 The '``llvm.vp.merge``' intrinsic is used to choose one value based on a
18834 condition vector and an index operand, without IR-level branching.
18839 The first operand is a vector of ``i1`` and indicates the condition. The
18840 second operand is the value that is merged where the condition vector is true.
18841 The third operand is the value that is selected where the condition vector is
18842 false or the lane position is greater equal than the pivot. The fourth operand
18845 #. The optional ``fast-math flags`` marker indicates that the merge has one or
18846 more :ref:`fast-math flags <fastmath>`. These are optimization hints to
18847 enable otherwise unsafe floating-point optimizations. Fast-math flags are
18848 only valid for merges that return a floating-point scalar or vector type,
18849 or an array (nested to any depth) of floating-point scalar or vector types.
18854 The intrinsic selects lanes from the second and third operand depending on a
18855 condition vector and pivot value.
18857 For all lanes where the condition vector is true and the lane position is less
18858 than ``%pivot`` the lane is taken from the second operand. Otherwise, the lane
18859 is taken from the third operand.
18864 .. code-block:: llvm
18866 %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)
18869 ;; Lanes at and above %pivot are taken from %on_false
18870 %atfirst = insertelement <4 x i32> undef, i32 %pivot, i32 0
18871 %splat = shufflevector <4 x i32> %atfirst, <4 x i32> poison, <4 x i32> zeroinitializer
18872 %pivotmask = icmp ult <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32> %splat
18873 %mergemask = and <4 x i1> %cond, <4 x i1> %pivotmask
18874 %also.r = select <4 x i1> %mergemask, <4 x i32> %on_true, <4 x i32> %on_false
18880 '``llvm.vp.add.*``' Intrinsics
18881 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18885 This is an overloaded intrinsic.
18889 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>)
18890 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>)
18891 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>)
18896 Predicated integer addition of two vectors of integers.
18902 The first two operands and the result have the same vector of integer type. The
18903 third operand is the vector mask and has the same number of elements as the
18904 result vector type. The fourth operand is the explicit vector length of the
18910 The '``llvm.vp.add``' intrinsic performs integer addition (:ref:`add <i_add>`)
18911 of the first and second vector operand on each enabled lane. The result on
18912 disabled lanes is a :ref:`poison value <poisonvalues>`.
18917 .. code-block:: llvm
18919 %r = call <4 x i32> @llvm.vp.add.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18920 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18922 %t = add <4 x i32> %a, %b
18923 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
18927 '``llvm.vp.sub.*``' Intrinsics
18928 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18932 This is an overloaded intrinsic.
18936 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>)
18937 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>)
18938 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>)
18943 Predicated integer subtraction of two vectors of integers.
18949 The first two operands and the result have the same vector of integer type. The
18950 third operand is the vector mask and has the same number of elements as the
18951 result vector type. The fourth operand is the explicit vector length of the
18957 The '``llvm.vp.sub``' intrinsic performs integer subtraction
18958 (:ref:`sub <i_sub>`) of the first and second vector operand on each enabled
18959 lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
18964 .. code-block:: llvm
18966 %r = call <4 x i32> @llvm.vp.sub.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18967 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18969 %t = sub <4 x i32> %a, %b
18970 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
18976 '``llvm.vp.mul.*``' Intrinsics
18977 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18981 This is an overloaded intrinsic.
18985 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>)
18986 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>)
18987 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>)
18992 Predicated integer multiplication of two vectors of integers.
18998 The first two operands and the result have the same vector of integer type. The
18999 third operand is the vector mask and has the same number of elements as the
19000 result vector type. The fourth operand is the explicit vector length of the
19005 The '``llvm.vp.mul``' intrinsic performs integer multiplication
19006 (:ref:`mul <i_mul>`) of the first and second vector operand on each enabled
19007 lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19012 .. code-block:: llvm
19014 %r = call <4 x i32> @llvm.vp.mul.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19015 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19017 %t = mul <4 x i32> %a, %b
19018 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19023 '``llvm.vp.sdiv.*``' Intrinsics
19024 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19028 This is an overloaded intrinsic.
19032 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>)
19033 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>)
19034 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>)
19039 Predicated, signed division of two vectors of integers.
19045 The first two operands and the result have the same vector of integer type. The
19046 third operand is the vector mask and has the same number of elements as the
19047 result vector type. The fourth operand is the explicit vector length of the
19053 The '``llvm.vp.sdiv``' intrinsic performs signed division (:ref:`sdiv <i_sdiv>`)
19054 of the first and second vector operand on each enabled lane. The result on
19055 disabled lanes is a :ref:`poison value <poisonvalues>`.
19060 .. code-block:: llvm
19062 %r = call <4 x i32> @llvm.vp.sdiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19063 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19065 %t = sdiv <4 x i32> %a, %b
19066 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19071 '``llvm.vp.udiv.*``' Intrinsics
19072 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19076 This is an overloaded intrinsic.
19080 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>)
19081 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>)
19082 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>)
19087 Predicated, unsigned division of two vectors of integers.
19093 The 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.
19098 The '``llvm.vp.udiv``' intrinsic performs unsigned division
19099 (:ref:`udiv <i_udiv>`) of the first and second vector operand on each enabled
19100 lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19105 .. code-block:: llvm
19107 %r = call <4 x i32> @llvm.vp.udiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19108 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19110 %t = udiv <4 x i32> %a, %b
19111 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19117 '``llvm.vp.srem.*``' Intrinsics
19118 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19122 This is an overloaded intrinsic.
19126 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>)
19127 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>)
19128 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>)
19133 Predicated computations of the signed remainder of two integer vectors.
19139 The first two operands and the result have the same vector of integer type. The
19140 third operand is the vector mask and has the same number of elements as the
19141 result vector type. The fourth operand is the explicit vector length of the
19147 The '``llvm.vp.srem``' intrinsic computes the remainder of the signed division
19148 (:ref:`srem <i_srem>`) of the first and second vector operand on each enabled
19149 lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19154 .. code-block:: llvm
19156 %r = call <4 x i32> @llvm.vp.srem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19157 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19159 %t = srem <4 x i32> %a, %b
19160 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19166 '``llvm.vp.urem.*``' Intrinsics
19167 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19171 This is an overloaded intrinsic.
19175 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>)
19176 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>)
19177 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>)
19182 Predicated computation of the unsigned remainder of two integer vectors.
19188 The first two operands and the result have the same vector of integer type. The
19189 third operand is the vector mask and has the same number of elements as the
19190 result vector type. The fourth operand is the explicit vector length of the
19196 The '``llvm.vp.urem``' intrinsic computes the remainder of the unsigned division
19197 (:ref:`urem <i_urem>`) of the first and second vector operand on each enabled
19198 lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19203 .. code-block:: llvm
19205 %r = call <4 x i32> @llvm.vp.urem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19206 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19208 %t = urem <4 x i32> %a, %b
19209 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19214 '``llvm.vp.ashr.*``' Intrinsics
19215 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19219 This is an overloaded intrinsic.
19223 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>)
19224 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>)
19225 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>)
19230 Vector-predicated arithmetic right-shift.
19236 The first two operands and the result have the same vector of integer type. The
19237 third operand is the vector mask and has the same number of elements as the
19238 result vector type. The fourth operand is the explicit vector length of the
19244 The '``llvm.vp.ashr``' intrinsic computes the arithmetic right shift
19245 (:ref:`ashr <i_ashr>`) of the first operand by the second operand on each
19246 enabled lane. The result on disabled lanes is a
19247 :ref:`poison value <poisonvalues>`.
19252 .. code-block:: llvm
19254 %r = call <4 x i32> @llvm.vp.ashr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19255 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19257 %t = ashr <4 x i32> %a, %b
19258 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19264 '``llvm.vp.lshr.*``' Intrinsics
19265 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19269 This is an overloaded intrinsic.
19273 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>)
19274 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>)
19275 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>)
19280 Vector-predicated logical right-shift.
19286 The first two operands and the result have the same vector of integer type. The
19287 third operand is the vector mask and has the same number of elements as the
19288 result vector type. The fourth operand is the explicit vector length of the
19294 The '``llvm.vp.lshr``' intrinsic computes the logical right shift
19295 (:ref:`lshr <i_lshr>`) of the first operand by the second operand on each
19296 enabled lane. The result on disabled lanes is a
19297 :ref:`poison value <poisonvalues>`.
19302 .. code-block:: llvm
19304 %r = call <4 x i32> @llvm.vp.lshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19305 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19307 %t = lshr <4 x i32> %a, %b
19308 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19313 '``llvm.vp.shl.*``' Intrinsics
19314 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19318 This is an overloaded intrinsic.
19322 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>)
19323 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>)
19324 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>)
19329 Vector-predicated left shift.
19335 The first two operands and the result have the same vector of integer type. The
19336 third operand is the vector mask and has the same number of elements as the
19337 result vector type. The fourth operand is the explicit vector length of the
19343 The '``llvm.vp.shl``' intrinsic computes the left shift (:ref:`shl <i_shl>`) of
19344 the first operand by the second operand on each enabled lane. The result on
19345 disabled lanes is a :ref:`poison value <poisonvalues>`.
19350 .. code-block:: llvm
19352 %r = call <4 x i32> @llvm.vp.shl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19353 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19355 %t = shl <4 x i32> %a, %b
19356 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19361 '``llvm.vp.or.*``' Intrinsics
19362 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19366 This is an overloaded intrinsic.
19370 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>)
19371 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>)
19372 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>)
19377 Vector-predicated or.
19383 The first two operands and the result have the same vector of integer type. The
19384 third operand is the vector mask and has the same number of elements as the
19385 result vector type. The fourth operand is the explicit vector length of the
19391 The '``llvm.vp.or``' intrinsic performs a bitwise or (:ref:`or <i_or>`) of the
19392 first two operands on each enabled lane. The result on disabled lanes is
19393 a :ref:`poison value <poisonvalues>`.
19398 .. code-block:: llvm
19400 %r = call <4 x i32> @llvm.vp.or.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19401 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19403 %t = or <4 x i32> %a, %b
19404 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19409 '``llvm.vp.and.*``' Intrinsics
19410 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19414 This is an overloaded intrinsic.
19418 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>)
19419 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>)
19420 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>)
19425 Vector-predicated and.
19431 The first two operands and the result have the same vector of integer type. The
19432 third operand is the vector mask and has the same number of elements as the
19433 result vector type. The fourth operand is the explicit vector length of the
19439 The '``llvm.vp.and``' intrinsic performs a bitwise and (:ref:`and <i_or>`) of
19440 the first two operands on each enabled lane. The result on disabled lanes is
19441 a :ref:`poison value <poisonvalues>`.
19446 .. code-block:: llvm
19448 %r = call <4 x i32> @llvm.vp.and.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19449 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19451 %t = and <4 x i32> %a, %b
19452 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19457 '``llvm.vp.xor.*``' Intrinsics
19458 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19462 This is an overloaded intrinsic.
19466 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>)
19467 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>)
19468 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>)
19473 Vector-predicated, bitwise xor.
19479 The first two operands and the result have the same vector of integer type. The
19480 third operand is the vector mask and has the same number of elements as the
19481 result vector type. The fourth operand is the explicit vector length of the
19487 The '``llvm.vp.xor``' intrinsic performs a bitwise xor (:ref:`xor <i_xor>`) of
19488 the first two operands on each enabled lane.
19489 The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19494 .. code-block:: llvm
19496 %r = call <4 x i32> @llvm.vp.xor.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19497 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19499 %t = xor <4 x i32> %a, %b
19500 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19504 '``llvm.vp.abs.*``' Intrinsics
19505 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19509 This is an overloaded intrinsic.
19513 declare <16 x i32> @llvm.vp.abs.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>, i1 <is_int_min_poison>)
19514 declare <vscale x 4 x i32> @llvm.vp.abs.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>, i1 <is_int_min_poison>)
19515 declare <256 x i64> @llvm.vp.abs.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>, i1 <is_int_min_poison>)
19520 Predicated abs of a vector of integers.
19526 The first operand and the result have the same vector of integer type. The
19527 second operand is the vector mask and has the same number of elements as the
19528 result vector type. The third operand is the explicit vector length of the
19529 operation. The fourth argument must be a constant and is a flag to indicate
19530 whether the result value of the '``llvm.vp.abs``' intrinsic is a
19531 :ref:`poison value <poisonvalues>` if the argument is statically or dynamically
19532 an ``INT_MIN`` value.
19537 The '``llvm.vp.abs``' intrinsic performs abs (:ref:`abs <int_abs>`) of the first operand on each
19538 enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19543 .. code-block:: llvm
19545 %r = call <4 x i32> @llvm.vp.abs.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl, i1 false)
19546 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19548 %t = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %a, i1 false)
19549 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19555 '``llvm.vp.smax.*``' Intrinsics
19556 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19560 This is an overloaded intrinsic.
19564 declare <16 x i32> @llvm.vp.smax.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
19565 declare <vscale x 4 x i32> @llvm.vp.smax.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
19566 declare <256 x i64> @llvm.vp.smax.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
19571 Predicated integer signed maximum of two vectors of integers.
19577 The first two operands and the result have the same vector of integer type. The
19578 third operand is the vector mask and has the same number of elements as the
19579 result vector type. The fourth operand is the explicit vector length of the
19585 The '``llvm.vp.smax``' intrinsic performs integer signed maximum (:ref:`smax <int_smax>`)
19586 of the first and second vector operand on each enabled lane. The result on
19587 disabled lanes is a :ref:`poison value <poisonvalues>`.
19592 .. code-block:: llvm
19594 %r = call <4 x i32> @llvm.vp.smax.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19595 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19597 %t = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> %b)
19598 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19603 '``llvm.vp.smin.*``' Intrinsics
19604 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19608 This is an overloaded intrinsic.
19612 declare <16 x i32> @llvm.vp.smin.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
19613 declare <vscale x 4 x i32> @llvm.vp.smin.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
19614 declare <256 x i64> @llvm.vp.smin.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
19619 Predicated integer signed minimum of two vectors of integers.
19625 The first two operands and the result have the same vector of integer type. The
19626 third operand is the vector mask and has the same number of elements as the
19627 result vector type. The fourth operand is the explicit vector length of the
19633 The '``llvm.vp.smin``' intrinsic performs integer signed minimum (:ref:`smin <int_smin>`)
19634 of the first and second vector operand on each enabled lane. The result on
19635 disabled lanes is a :ref:`poison value <poisonvalues>`.
19640 .. code-block:: llvm
19642 %r = call <4 x i32> @llvm.vp.smin.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19643 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19645 %t = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> %b)
19646 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19651 '``llvm.vp.umax.*``' Intrinsics
19652 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19656 This is an overloaded intrinsic.
19660 declare <16 x i32> @llvm.vp.umax.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
19661 declare <vscale x 4 x i32> @llvm.vp.umax.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
19662 declare <256 x i64> @llvm.vp.umax.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
19667 Predicated integer unsigned maximum of two vectors of integers.
19673 The first two operands and the result have the same vector of integer type. The
19674 third operand is the vector mask and has the same number of elements as the
19675 result vector type. The fourth operand is the explicit vector length of the
19681 The '``llvm.vp.umax``' intrinsic performs integer unsigned maximum (:ref:`umax <int_umax>`)
19682 of the first and second vector operand on each enabled lane. The result on
19683 disabled lanes is a :ref:`poison value <poisonvalues>`.
19688 .. code-block:: llvm
19690 %r = call <4 x i32> @llvm.vp.umax.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19691 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19693 %t = call <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> %b)
19694 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19699 '``llvm.vp.umin.*``' Intrinsics
19700 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19704 This is an overloaded intrinsic.
19708 declare <16 x i32> @llvm.vp.umin.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
19709 declare <vscale x 4 x i32> @llvm.vp.umin.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
19710 declare <256 x i64> @llvm.vp.umin.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
19715 Predicated integer unsigned minimum of two vectors of integers.
19721 The first two operands and the result have the same vector of integer type. The
19722 third operand is the vector mask and has the same number of elements as the
19723 result vector type. The fourth operand is the explicit vector length of the
19729 The '``llvm.vp.umin``' intrinsic performs integer unsigned minimum (:ref:`umin <int_umin>`)
19730 of the first and second vector operand on each enabled lane. The result on
19731 disabled lanes is a :ref:`poison value <poisonvalues>`.
19736 .. code-block:: llvm
19738 %r = call <4 x i32> @llvm.vp.umin.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19739 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19741 %t = call <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> %b)
19742 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19745 .. _int_vp_copysign:
19747 '``llvm.vp.copysign.*``' Intrinsics
19748 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19752 This is an overloaded intrinsic.
19756 declare <16 x float> @llvm.vp.copysign.v16f32 (<16 x float> <mag_op>, <16 x float> <sign_op>, <16 x i1> <mask>, i32 <vector_length>)
19757 declare <vscale x 4 x float> @llvm.vp.copysign.nxv4f32 (<vscale x 4 x float> <mag_op>, <vscale x 4 x float> <sign_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
19758 declare <256 x double> @llvm.vp.copysign.v256f64 (<256 x double> <mag_op>, <256 x double> <sign_op>, <256 x i1> <mask>, i32 <vector_length>)
19763 Predicated floating-point copysign of two vectors of floating-point values.
19769 The first two operands and the result have the same vector of floating-point type. The
19770 third operand is the vector mask and has the same number of elements as the
19771 result vector type. The fourth operand is the explicit vector length of the
19777 The '``llvm.vp.copysign``' intrinsic performs floating-point copysign (:ref:`copysign <int_copysign>`)
19778 of the first and second vector operand on each enabled lane. The result on
19779 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
19780 performed in the default floating-point environment.
19785 .. code-block:: llvm
19787 %r = call <4 x float> @llvm.vp.copysign.v4f32(<4 x float> %mag, <4 x float> %sign, <4 x i1> %mask, i32 %evl)
19788 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19790 %t = call <4 x float> @llvm.copysign.v4f32(<4 x float> %mag, <4 x float> %sign)
19791 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
19796 '``llvm.vp.minnum.*``' Intrinsics
19797 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19801 This is an overloaded intrinsic.
19805 declare <16 x float> @llvm.vp.minnum.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
19806 declare <vscale x 4 x float> @llvm.vp.minnum.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
19807 declare <256 x double> @llvm.vp.minnum.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
19812 Predicated floating-point IEEE-754 minNum of two vectors of floating-point values.
19818 The first two operands and the result have the same vector of floating-point type. The
19819 third operand is the vector mask and has the same number of elements as the
19820 result vector type. The fourth operand is the explicit vector length of the
19826 The '``llvm.vp.minnum``' intrinsic performs floating-point minimum (:ref:`minnum <i_minnum>`)
19827 of the first and second vector operand on each enabled lane. The result on
19828 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
19829 performed in the default floating-point environment.
19834 .. code-block:: llvm
19836 %r = call <4 x float> @llvm.vp.minnum.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
19837 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19839 %t = call <4 x float> @llvm.minnum.v4f32(<4 x float> %a, <4 x float> %b)
19840 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
19845 '``llvm.vp.maxnum.*``' Intrinsics
19846 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19850 This is an overloaded intrinsic.
19854 declare <16 x float> @llvm.vp.maxnum.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
19855 declare <vscale x 4 x float> @llvm.vp.maxnum.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
19856 declare <256 x double> @llvm.vp.maxnum.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
19861 Predicated floating-point IEEE-754 maxNum of two vectors of floating-point values.
19867 The first two operands and the result have the same vector of floating-point type. The
19868 third operand is the vector mask and has the same number of elements as the
19869 result vector type. The fourth operand is the explicit vector length of the
19875 The '``llvm.vp.maxnum``' intrinsic performs floating-point maximum (:ref:`maxnum <i_maxnum>`)
19876 of the first and second vector operand on each enabled lane. The result on
19877 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
19878 performed in the default floating-point environment.
19883 .. code-block:: llvm
19885 %r = call <4 x float> @llvm.vp.maxnum.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
19886 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19888 %t = call <4 x float> @llvm.maxnum.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
19889 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
19894 '``llvm.vp.fadd.*``' Intrinsics
19895 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19899 This is an overloaded intrinsic.
19903 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>)
19904 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>)
19905 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>)
19910 Predicated floating-point addition of two vectors of floating-point values.
19916 The first two operands and the result have the same vector of floating-point type. The
19917 third operand is the vector mask and has the same number of elements as the
19918 result vector type. The fourth operand is the explicit vector length of the
19924 The '``llvm.vp.fadd``' intrinsic performs floating-point addition (:ref:`fadd <i_fadd>`)
19925 of the first and second vector operand on each enabled lane. The result on
19926 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
19927 performed in the default floating-point environment.
19932 .. code-block:: llvm
19934 %r = call <4 x float> @llvm.vp.fadd.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
19935 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19937 %t = fadd <4 x float> %a, %b
19938 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
19943 '``llvm.vp.fsub.*``' Intrinsics
19944 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19948 This is an overloaded intrinsic.
19952 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>)
19953 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>)
19954 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>)
19959 Predicated floating-point subtraction of two vectors of floating-point values.
19965 The first two operands and the result have the same vector of floating-point type. The
19966 third operand is the vector mask and has the same number of elements as the
19967 result vector type. The fourth operand is the explicit vector length of the
19973 The '``llvm.vp.fsub``' intrinsic performs floating-point subtraction (:ref:`fsub <i_fsub>`)
19974 of the first and second vector operand on each enabled lane. The result on
19975 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
19976 performed in the default floating-point environment.
19981 .. code-block:: llvm
19983 %r = call <4 x float> @llvm.vp.fsub.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
19984 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19986 %t = fsub <4 x float> %a, %b
19987 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
19992 '``llvm.vp.fmul.*``' Intrinsics
19993 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19997 This is an overloaded intrinsic.
20001 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>)
20002 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>)
20003 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>)
20008 Predicated floating-point multiplication of two vectors of floating-point values.
20014 The first two operands and the result have the same vector of floating-point type. The
20015 third operand is the vector mask and has the same number of elements as the
20016 result vector type. The fourth operand is the explicit vector length of the
20022 The '``llvm.vp.fmul``' intrinsic performs floating-point multiplication (:ref:`fmul <i_fmul>`)
20023 of the first and second vector operand on each enabled lane. The result on
20024 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20025 performed in the default floating-point environment.
20030 .. code-block:: llvm
20032 %r = call <4 x float> @llvm.vp.fmul.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
20033 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20035 %t = fmul <4 x float> %a, %b
20036 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20041 '``llvm.vp.fdiv.*``' Intrinsics
20042 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20046 This is an overloaded intrinsic.
20050 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>)
20051 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>)
20052 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>)
20057 Predicated floating-point division of two vectors of floating-point values.
20063 The first two operands and the result have the same vector of floating-point type. The
20064 third operand is the vector mask and has the same number of elements as the
20065 result vector type. The fourth operand is the explicit vector length of the
20071 The '``llvm.vp.fdiv``' intrinsic performs floating-point division (:ref:`fdiv <i_fdiv>`)
20072 of the first and second vector operand on each enabled lane. The result on
20073 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20074 performed in the default floating-point environment.
20079 .. code-block:: llvm
20081 %r = call <4 x float> @llvm.vp.fdiv.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
20082 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20084 %t = fdiv <4 x float> %a, %b
20085 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20090 '``llvm.vp.frem.*``' Intrinsics
20091 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20095 This is an overloaded intrinsic.
20099 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>)
20100 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>)
20101 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>)
20106 Predicated floating-point remainder of two vectors of floating-point values.
20112 The first two operands and the result have the same vector of floating-point type. The
20113 third operand is the vector mask and has the same number of elements as the
20114 result vector type. The fourth operand is the explicit vector length of the
20120 The '``llvm.vp.frem``' intrinsic performs floating-point remainder (:ref:`frem <i_frem>`)
20121 of the first and second vector operand on each enabled lane. The result on
20122 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20123 performed in the default floating-point environment.
20128 .. code-block:: llvm
20130 %r = call <4 x float> @llvm.vp.frem.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
20131 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20133 %t = frem <4 x float> %a, %b
20134 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20139 '``llvm.vp.fneg.*``' Intrinsics
20140 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20144 This is an overloaded intrinsic.
20148 declare <16 x float> @llvm.vp.fneg.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
20149 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>)
20150 declare <256 x double> @llvm.vp.fneg.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
20155 Predicated floating-point negation of a vector of floating-point values.
20161 The first operand and the result have the same vector of floating-point type.
20162 The second operand is the vector mask and has the same number of elements as the
20163 result vector type. The third operand is the explicit vector length of the
20169 The '``llvm.vp.fneg``' intrinsic performs floating-point negation (:ref:`fneg <i_fneg>`)
20170 of the first vector operand on each enabled lane. The result on disabled lanes
20171 is a :ref:`poison value <poisonvalues>`.
20176 .. code-block:: llvm
20178 %r = call <4 x float> @llvm.vp.fneg.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
20179 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20181 %t = fneg <4 x float> %a
20182 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20187 '``llvm.vp.fabs.*``' Intrinsics
20188 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20192 This is an overloaded intrinsic.
20196 declare <16 x float> @llvm.vp.fabs.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
20197 declare <vscale x 4 x float> @llvm.vp.fabs.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20198 declare <256 x double> @llvm.vp.fabs.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
20203 Predicated floating-point absolute value of a vector of floating-point values.
20209 The first operand and the result have the same vector of floating-point type.
20210 The second operand is the vector mask and has the same number of elements as the
20211 result vector type. The third operand is the explicit vector length of the
20217 The '``llvm.vp.fabs``' intrinsic performs floating-point absolute value
20218 (:ref:`fabs <int_fabs>`) of the first vector operand on each enabled lane. The
20219 result on disabled lanes is a :ref:`poison value <poisonvalues>`.
20224 .. code-block:: llvm
20226 %r = call <4 x float> @llvm.vp.fabs.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
20227 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20229 %t = call <4 x float> @llvm.fabs.v4f32(<4 x float> %a)
20230 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20235 '``llvm.vp.sqrt.*``' Intrinsics
20236 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20240 This is an overloaded intrinsic.
20244 declare <16 x float> @llvm.vp.sqrt.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
20245 declare <vscale x 4 x float> @llvm.vp.sqrt.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
20246 declare <256 x double> @llvm.vp.sqrt.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
20251 Predicated floating-point square root of a vector of floating-point values.
20257 The first operand and the result have the same vector of floating-point type.
20258 The second operand is the vector mask and has the same number of elements as the
20259 result vector type. The third operand is the explicit vector length of the
20265 The '``llvm.vp.sqrt``' intrinsic performs floating-point square root (:ref:`sqrt <int_sqrt>`) of
20266 the first vector operand on each enabled lane. The result on disabled lanes is
20267 a :ref:`poison value <poisonvalues>`. The operation is performed in the default
20268 floating-point environment.
20273 .. code-block:: llvm
20275 %r = call <4 x float> @llvm.vp.sqrt.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
20276 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20278 %t = call <4 x float> @llvm.sqrt.v4f32(<4 x float> %a)
20279 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20284 '``llvm.vp.fma.*``' Intrinsics
20285 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20289 This is an overloaded intrinsic.
20293 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>)
20294 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>)
20295 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>)
20300 Predicated floating-point fused multiply-add of two vectors of floating-point values.
20306 The first three operands and the result have the same vector of floating-point type. The
20307 fourth operand is the vector mask and has the same number of elements as the
20308 result vector type. The fifth operand is the explicit vector length of the
20314 The '``llvm.vp.fma``' intrinsic performs floating-point fused multiply-add (:ref:`llvm.fma <int_fma>`)
20315 of the first, second, and third vector operand on each enabled lane. The result on
20316 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20317 performed in the default floating-point environment.
20322 .. code-block:: llvm
20324 %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)
20325 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20327 %t = call <4 x float> @llvm.fma(<4 x float> %a, <4 x float> %b, <4 x float> %c)
20328 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20331 .. _int_vp_fmuladd:
20333 '``llvm.vp.fmuladd.*``' Intrinsics
20334 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20338 This is an overloaded intrinsic.
20342 declare <16 x float> @llvm.vp.fmuladd.v16f32 (<16 x float> <left_op>, <16 x float> <middle_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
20343 declare <vscale x 4 x float> @llvm.vp.fmuladd.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>)
20344 declare <256 x double> @llvm.vp.fmuladd.v256f64 (<256 x double> <left_op>, <256 x double> <middle_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
20349 Predicated floating-point multiply-add of two vectors of floating-point values
20350 that can be fused if code generator determines that (a) the target instruction
20351 set has support for a fused operation, and (b) that the fused operation is more
20352 efficient than the equivalent, separate pair of mul and add instructions.
20357 The first three operands and the result have the same vector of floating-point
20358 type. The fourth operand is the vector mask and has the same number of elements
20359 as the result vector type. The fifth operand is the explicit vector length of
20365 The '``llvm.vp.fmuladd``' intrinsic performs floating-point multiply-add (:ref:`llvm.fuladd <int_fmuladd>`)
20366 of the first, second, and third vector operand on each enabled lane. The result
20367 on disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20368 performed in the default floating-point environment.
20373 .. code-block:: llvm
20375 %r = call <4 x float> @llvm.vp.fmuladd.v4f32(<4 x float> %a, <4 x float> %b, <4 x float> %c, <4 x i1> %mask, i32 %evl)
20376 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20378 %t = call <4 x float> @llvm.fmuladd(<4 x float> %a, <4 x float> %b, <4 x float> %c)
20379 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20382 .. _int_vp_reduce_add:
20384 '``llvm.vp.reduce.add.*``' Intrinsics
20385 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20389 This is an overloaded intrinsic.
20393 declare i32 @llvm.vp.reduce.add.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20394 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>)
20399 Predicated integer ``ADD`` reduction of a vector and a scalar starting value,
20400 returning the result as a scalar.
20405 The first operand is the start value of the reduction, which must be a scalar
20406 integer type equal to the result type. The second operand is the vector on
20407 which the reduction is performed and must be a vector of integer values whose
20408 element type is the result/start type. The third operand is the vector mask and
20409 is a vector of boolean values with the same number of elements as the vector
20410 operand. The fourth operand is the explicit vector length of the operation.
20415 The '``llvm.vp.reduce.add``' intrinsic performs the integer ``ADD`` reduction
20416 (:ref:`llvm.vector.reduce.add <int_vector_reduce_add>`) of the vector operand
20417 ``val`` on each enabled lane, adding it to the scalar ``start_value``. Disabled
20418 lanes are treated as containing the neutral value ``0`` (i.e. having no effect
20419 on the reduction operation). If the vector length is zero, the result is equal
20420 to ``start_value``.
20422 To ignore the start value, the neutral value can be used.
20427 .. code-block:: llvm
20429 %r = call i32 @llvm.vp.reduce.add.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
20430 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20431 ; are treated as though %mask were false for those lanes.
20433 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> zeroinitializer
20434 %reduction = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %masked.a)
20435 %also.r = add i32 %reduction, %start
20438 .. _int_vp_reduce_fadd:
20440 '``llvm.vp.reduce.fadd.*``' Intrinsics
20441 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20445 This is an overloaded intrinsic.
20449 declare float @llvm.vp.reduce.fadd.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>)
20450 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>)
20455 Predicated floating-point ``ADD`` reduction of a vector and a scalar starting
20456 value, returning the result as a scalar.
20461 The first operand is the start value of the reduction, which must be a scalar
20462 floating-point type equal to the result type. The second operand is the vector
20463 on which the reduction is performed and must be a vector of floating-point
20464 values whose element type is the result/start type. The third operand is the
20465 vector mask and is a vector of boolean values with the same number of elements
20466 as the vector operand. The fourth operand is the explicit vector length of the
20472 The '``llvm.vp.reduce.fadd``' intrinsic performs the floating-point ``ADD``
20473 reduction (:ref:`llvm.vector.reduce.fadd <int_vector_reduce_fadd>`) of the
20474 vector operand ``val`` on each enabled lane, adding it to the scalar
20475 ``start_value``. Disabled lanes are treated as containing the neutral value
20476 ``-0.0`` (i.e. having no effect on the reduction operation). If no lanes are
20477 enabled, the resulting value will be equal to ``start_value``.
20479 To ignore the start value, the neutral value can be used.
20481 See the unpredicated version (:ref:`llvm.vector.reduce.fadd
20482 <int_vector_reduce_fadd>`) for more detail on the semantics of the reduction.
20487 .. code-block:: llvm
20489 %r = call float @llvm.vp.reduce.fadd.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
20490 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20491 ; are treated as though %mask were false for those lanes.
20493 %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>
20494 %also.r = call float @llvm.vector.reduce.fadd.v4f32(float %start, <4 x float> %masked.a)
20497 .. _int_vp_reduce_mul:
20499 '``llvm.vp.reduce.mul.*``' Intrinsics
20500 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20504 This is an overloaded intrinsic.
20508 declare i32 @llvm.vp.reduce.mul.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20509 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>)
20514 Predicated integer ``MUL`` reduction of a vector and a scalar starting value,
20515 returning the result as a scalar.
20521 The first operand is the start value of the reduction, which must be a scalar
20522 integer type equal to the result type. The second operand is the vector on
20523 which the reduction is performed and must be a vector of integer values whose
20524 element type is the result/start type. The third operand is the vector mask and
20525 is a vector of boolean values with the same number of elements as the vector
20526 operand. The fourth operand is the explicit vector length of the operation.
20531 The '``llvm.vp.reduce.mul``' intrinsic performs the integer ``MUL`` reduction
20532 (:ref:`llvm.vector.reduce.mul <int_vector_reduce_mul>`) of the vector operand ``val``
20533 on each enabled lane, multiplying it by the scalar ``start_value``. Disabled
20534 lanes are treated as containing the neutral value ``1`` (i.e. having no effect
20535 on the reduction operation). If the vector length is zero, the result is the
20538 To ignore the start value, the neutral value can be used.
20543 .. code-block:: llvm
20545 %r = call i32 @llvm.vp.reduce.mul.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
20546 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20547 ; are treated as though %mask were false for those lanes.
20549 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
20550 %reduction = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %masked.a)
20551 %also.r = mul i32 %reduction, %start
20553 .. _int_vp_reduce_fmul:
20555 '``llvm.vp.reduce.fmul.*``' Intrinsics
20556 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20560 This is an overloaded intrinsic.
20564 declare float @llvm.vp.reduce.fmul.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>)
20565 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>)
20570 Predicated floating-point ``MUL`` reduction of a vector and a scalar starting
20571 value, returning the result as a scalar.
20577 The first operand is the start value of the reduction, which must be a scalar
20578 floating-point type equal to the result type. The second operand is the vector
20579 on which the reduction is performed and must be a vector of floating-point
20580 values whose element type is the result/start type. The third operand is the
20581 vector mask and is a vector of boolean values with the same number of elements
20582 as the vector operand. The fourth operand is the explicit vector length of the
20588 The '``llvm.vp.reduce.fmul``' intrinsic performs the floating-point ``MUL``
20589 reduction (:ref:`llvm.vector.reduce.fmul <int_vector_reduce_fmul>`) of the
20590 vector operand ``val`` on each enabled lane, multiplying it by the scalar
20591 `start_value``. Disabled lanes are treated as containing the neutral value
20592 ``1.0`` (i.e. having no effect on the reduction operation). If no lanes are
20593 enabled, the resulting value will be equal to the starting value.
20595 To ignore the start value, the neutral value can be used.
20597 See the unpredicated version (:ref:`llvm.vector.reduce.fmul
20598 <int_vector_reduce_fmul>`) for more detail on the semantics.
20603 .. code-block:: llvm
20605 %r = call float @llvm.vp.reduce.fmul.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
20606 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20607 ; are treated as though %mask were false for those lanes.
20609 %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>
20610 %also.r = call float @llvm.vector.reduce.fmul.v4f32(float %start, <4 x float> %masked.a)
20613 .. _int_vp_reduce_and:
20615 '``llvm.vp.reduce.and.*``' Intrinsics
20616 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20620 This is an overloaded intrinsic.
20624 declare i32 @llvm.vp.reduce.and.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20625 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>)
20630 Predicated integer ``AND`` reduction of a vector and a scalar starting value,
20631 returning the result as a scalar.
20637 The first operand is the start value of the reduction, which must be a scalar
20638 integer type equal to the result type. The second operand is the vector on
20639 which the reduction is performed and must be a vector of integer values whose
20640 element type is the result/start type. The third operand is the vector mask and
20641 is a vector of boolean values with the same number of elements as the vector
20642 operand. The fourth operand is the explicit vector length of the operation.
20647 The '``llvm.vp.reduce.and``' intrinsic performs the integer ``AND`` reduction
20648 (:ref:`llvm.vector.reduce.and <int_vector_reduce_and>`) of the vector operand
20649 ``val`` on each enabled lane, performing an '``and``' of that with with the
20650 scalar ``start_value``. Disabled lanes are treated as containing the neutral
20651 value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction
20652 operation). If the vector length is zero, the result is the start value.
20654 To ignore the start value, the neutral value can be used.
20659 .. code-block:: llvm
20661 %r = call i32 @llvm.vp.reduce.and.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
20662 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20663 ; are treated as though %mask were false for those lanes.
20665 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
20666 %reduction = call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %masked.a)
20667 %also.r = and i32 %reduction, %start
20670 .. _int_vp_reduce_or:
20672 '``llvm.vp.reduce.or.*``' Intrinsics
20673 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20677 This is an overloaded intrinsic.
20681 declare i32 @llvm.vp.reduce.or.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20682 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>)
20687 Predicated integer ``OR`` reduction of a vector and a scalar starting value,
20688 returning the result as a scalar.
20694 The first operand is the start value of the reduction, which must be a scalar
20695 integer type equal to the result type. The second operand is the vector on
20696 which the reduction is performed and must be a vector of integer values whose
20697 element type is the result/start type. The third operand is the vector mask and
20698 is a vector of boolean values with the same number of elements as the vector
20699 operand. The fourth operand is the explicit vector length of the operation.
20704 The '``llvm.vp.reduce.or``' intrinsic performs the integer ``OR`` reduction
20705 (:ref:`llvm.vector.reduce.or <int_vector_reduce_or>`) of the vector operand
20706 ``val`` on each enabled lane, performing an '``or``' of that with the scalar
20707 ``start_value``. Disabled lanes are treated as containing the neutral value
20708 ``0`` (i.e. having no effect on the reduction operation). If the vector length
20709 is zero, the result is the start value.
20711 To ignore the start value, the neutral value can be used.
20716 .. code-block:: llvm
20718 %r = call i32 @llvm.vp.reduce.or.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
20719 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20720 ; are treated as though %mask were false for those lanes.
20722 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
20723 %reduction = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %masked.a)
20724 %also.r = or i32 %reduction, %start
20726 .. _int_vp_reduce_xor:
20728 '``llvm.vp.reduce.xor.*``' Intrinsics
20729 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20733 This is an overloaded intrinsic.
20737 declare i32 @llvm.vp.reduce.xor.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20738 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>)
20743 Predicated integer ``XOR`` reduction of a vector and a scalar starting value,
20744 returning the result as a scalar.
20750 The first operand is the start value of the reduction, which must be a scalar
20751 integer type equal to the result type. The second operand is the vector on
20752 which the reduction is performed and must be a vector of integer values whose
20753 element type is the result/start type. The third operand is the vector mask and
20754 is a vector of boolean values with the same number of elements as the vector
20755 operand. The fourth operand is the explicit vector length of the operation.
20760 The '``llvm.vp.reduce.xor``' intrinsic performs the integer ``XOR`` reduction
20761 (:ref:`llvm.vector.reduce.xor <int_vector_reduce_xor>`) of the vector operand
20762 ``val`` on each enabled lane, performing an '``xor``' of that with the scalar
20763 ``start_value``. Disabled lanes are treated as containing the neutral value
20764 ``0`` (i.e. having no effect on the reduction operation). If the vector length
20765 is zero, the result is the start value.
20767 To ignore the start value, the neutral value can be used.
20772 .. code-block:: llvm
20774 %r = call i32 @llvm.vp.reduce.xor.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
20775 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20776 ; are treated as though %mask were false for those lanes.
20778 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
20779 %reduction = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %masked.a)
20780 %also.r = xor i32 %reduction, %start
20783 .. _int_vp_reduce_smax:
20785 '``llvm.vp.reduce.smax.*``' Intrinsics
20786 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20790 This is an overloaded intrinsic.
20794 declare i32 @llvm.vp.reduce.smax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20795 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>)
20800 Predicated signed-integer ``MAX`` reduction of a vector and a scalar starting
20801 value, returning the result as a scalar.
20807 The first operand is the start value of the reduction, which must be a scalar
20808 integer type equal to the result type. The second operand is the vector on
20809 which the reduction is performed and must be a vector of integer values whose
20810 element type is the result/start type. The third operand is the vector mask and
20811 is a vector of boolean values with the same number of elements as the vector
20812 operand. The fourth operand is the explicit vector length of the operation.
20817 The '``llvm.vp.reduce.smax``' intrinsic performs the signed-integer ``MAX``
20818 reduction (:ref:`llvm.vector.reduce.smax <int_vector_reduce_smax>`) of the
20819 vector operand ``val`` on each enabled lane, and taking the maximum of that and
20820 the scalar ``start_value``. Disabled lanes are treated as containing the
20821 neutral value ``INT_MIN`` (i.e. having no effect on the reduction operation).
20822 If the vector length is zero, the result is the start value.
20824 To ignore the start value, the neutral value can be used.
20829 .. code-block:: llvm
20831 %r = call i8 @llvm.vp.reduce.smax.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl)
20832 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20833 ; are treated as though %mask were false for those lanes.
20835 %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 -128, i8 -128, i8 -128, i8 -128>
20836 %reduction = call i8 @llvm.vector.reduce.smax.v4i8(<4 x i8> %masked.a)
20837 %also.r = call i8 @llvm.smax.i8(i8 %reduction, i8 %start)
20840 .. _int_vp_reduce_smin:
20842 '``llvm.vp.reduce.smin.*``' Intrinsics
20843 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20847 This is an overloaded intrinsic.
20851 declare i32 @llvm.vp.reduce.smin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20852 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>)
20857 Predicated signed-integer ``MIN`` reduction of a vector and a scalar starting
20858 value, returning the result as a scalar.
20864 The first operand is the start value of the reduction, which must be a scalar
20865 integer type equal to the result type. The second operand is the vector on
20866 which the reduction is performed and must be a vector of integer values whose
20867 element type is the result/start type. The third operand is the vector mask and
20868 is a vector of boolean values with the same number of elements as the vector
20869 operand. The fourth operand is the explicit vector length of the operation.
20874 The '``llvm.vp.reduce.smin``' intrinsic performs the signed-integer ``MIN``
20875 reduction (:ref:`llvm.vector.reduce.smin <int_vector_reduce_smin>`) of the
20876 vector operand ``val`` on each enabled lane, and taking the minimum of that and
20877 the scalar ``start_value``. Disabled lanes are treated as containing the
20878 neutral value ``INT_MAX`` (i.e. having no effect on the reduction operation).
20879 If the vector length is zero, the result is the start value.
20881 To ignore the start value, the neutral value can be used.
20886 .. code-block:: llvm
20888 %r = call i8 @llvm.vp.reduce.smin.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl)
20889 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20890 ; are treated as though %mask were false for those lanes.
20892 %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 127, i8 127, i8 127, i8 127>
20893 %reduction = call i8 @llvm.vector.reduce.smin.v4i8(<4 x i8> %masked.a)
20894 %also.r = call i8 @llvm.smin.i8(i8 %reduction, i8 %start)
20897 .. _int_vp_reduce_umax:
20899 '``llvm.vp.reduce.umax.*``' Intrinsics
20900 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20904 This is an overloaded intrinsic.
20908 declare i32 @llvm.vp.reduce.umax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20909 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>)
20914 Predicated unsigned-integer ``MAX`` reduction of a vector and a scalar starting
20915 value, returning the result as a scalar.
20921 The first operand is the start value of the reduction, which must be a scalar
20922 integer type equal to the result type. The second operand is the vector on
20923 which the reduction is performed and must be a vector of integer values whose
20924 element type is the result/start type. The third operand is the vector mask and
20925 is a vector of boolean values with the same number of elements as the vector
20926 operand. The fourth operand is the explicit vector length of the operation.
20931 The '``llvm.vp.reduce.umax``' intrinsic performs the unsigned-integer ``MAX``
20932 reduction (:ref:`llvm.vector.reduce.umax <int_vector_reduce_umax>`) of the
20933 vector operand ``val`` on each enabled lane, and taking the maximum of that and
20934 the scalar ``start_value``. Disabled lanes are treated as containing the
20935 neutral value ``0`` (i.e. having no effect on the reduction operation). If the
20936 vector length is zero, the result is the start value.
20938 To ignore the start value, the neutral value can be used.
20943 .. code-block:: llvm
20945 %r = call i32 @llvm.vp.reduce.umax.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
20946 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20947 ; are treated as though %mask were false for those lanes.
20949 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
20950 %reduction = call i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %masked.a)
20951 %also.r = call i32 @llvm.umax.i32(i32 %reduction, i32 %start)
20954 .. _int_vp_reduce_umin:
20956 '``llvm.vp.reduce.umin.*``' Intrinsics
20957 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20961 This is an overloaded intrinsic.
20965 declare i32 @llvm.vp.reduce.umin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20966 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>)
20971 Predicated unsigned-integer ``MIN`` reduction of a vector and a scalar starting
20972 value, returning the result as a scalar.
20978 The first operand is the start value of the reduction, which must be a scalar
20979 integer type equal to the result type. The second operand is the vector on
20980 which the reduction is performed and must be a vector of integer values whose
20981 element type is the result/start type. The third operand is the vector mask and
20982 is a vector of boolean values with the same number of elements as the vector
20983 operand. The fourth operand is the explicit vector length of the operation.
20988 The '``llvm.vp.reduce.umin``' intrinsic performs the unsigned-integer ``MIN``
20989 reduction (:ref:`llvm.vector.reduce.umin <int_vector_reduce_umin>`) of the
20990 vector operand ``val`` on each enabled lane, taking the minimum of that and the
20991 scalar ``start_value``. Disabled lanes are treated as containing the neutral
20992 value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction
20993 operation). If the vector length is zero, the result is the start value.
20995 To ignore the start value, the neutral value can be used.
21000 .. code-block:: llvm
21002 %r = call i32 @llvm.vp.reduce.umin.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
21003 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
21004 ; are treated as though %mask were false for those lanes.
21006 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
21007 %reduction = call i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %masked.a)
21008 %also.r = call i32 @llvm.umin.i32(i32 %reduction, i32 %start)
21011 .. _int_vp_reduce_fmax:
21013 '``llvm.vp.reduce.fmax.*``' Intrinsics
21014 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21018 This is an overloaded intrinsic.
21022 declare float @llvm.vp.reduce.fmax.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>)
21023 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>)
21028 Predicated floating-point ``MAX`` reduction of a vector and a scalar starting
21029 value, returning the result as a scalar.
21035 The first operand is the start value of the reduction, which must be a scalar
21036 floating-point type equal to the result type. The second operand is the vector
21037 on which the reduction is performed and must be a vector of floating-point
21038 values whose element type is the result/start type. The third operand is the
21039 vector mask and is a vector of boolean values with the same number of elements
21040 as the vector operand. The fourth operand is the explicit vector length of the
21046 The '``llvm.vp.reduce.fmax``' intrinsic performs the floating-point ``MAX``
21047 reduction (:ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>`) of the
21048 vector operand ``val`` on each enabled lane, taking the maximum of that and the
21049 scalar ``start_value``. Disabled lanes are treated as containing the neutral
21050 value (i.e. having no effect on the reduction operation). If the vector length
21051 is zero, the result is the start value.
21053 The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
21054 flags are set, the neutral value is ``-QNAN``. If ``nnan`` and ``ninf`` are
21055 both set, then the neutral value is the smallest floating-point value for the
21056 result type. If only ``nnan`` is set then the neutral value is ``-Infinity``.
21058 This instruction has the same comparison semantics as the
21059 :ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>` intrinsic (and thus the
21060 '``llvm.maxnum.*``' intrinsic). That is, the result will always be a number
21061 unless all elements of the vector and the starting value are ``NaN``. For a
21062 vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and
21063 ``-0.0`` elements, the sign of the result is unspecified.
21065 To ignore the start value, the neutral value can be used.
21070 .. code-block:: llvm
21072 %r = call float @llvm.vp.reduce.fmax.v4f32(float %float, <4 x float> %a, <4 x i1> %mask, i32 %evl)
21073 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
21074 ; are treated as though %mask were false for those lanes.
21076 %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN>
21077 %reduction = call float @llvm.vector.reduce.fmax.v4f32(<4 x float> %masked.a)
21078 %also.r = call float @llvm.maxnum.f32(float %reduction, float %start)
21081 .. _int_vp_reduce_fmin:
21083 '``llvm.vp.reduce.fmin.*``' Intrinsics
21084 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21088 This is an overloaded intrinsic.
21092 declare float @llvm.vp.reduce.fmin.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>)
21093 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>)
21098 Predicated floating-point ``MIN`` reduction of a vector and a scalar starting
21099 value, returning the result as a scalar.
21105 The first operand is the start value of the reduction, which must be a scalar
21106 floating-point type equal to the result type. The second operand is the vector
21107 on which the reduction is performed and must be a vector of floating-point
21108 values whose element type is the result/start type. The third operand is the
21109 vector mask and is a vector of boolean values with the same number of elements
21110 as the vector operand. The fourth operand is the explicit vector length of the
21116 The '``llvm.vp.reduce.fmin``' intrinsic performs the floating-point ``MIN``
21117 reduction (:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>`) of the
21118 vector operand ``val`` on each enabled lane, taking the minimum of that and the
21119 scalar ``start_value``. Disabled lanes are treated as containing the neutral
21120 value (i.e. having no effect on the reduction operation). If the vector length
21121 is zero, the result is the start value.
21123 The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
21124 flags are set, the neutral value is ``+QNAN``. If ``nnan`` and ``ninf`` are
21125 both set, then the neutral value is the largest floating-point value for the
21126 result type. If only ``nnan`` is set then the neutral value is ``+Infinity``.
21128 This instruction has the same comparison semantics as the
21129 :ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>` intrinsic (and thus the
21130 '``llvm.minnum.*``' intrinsic). That is, the result will always be a number
21131 unless all elements of the vector and the starting value are ``NaN``. For a
21132 vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and
21133 ``-0.0`` elements, the sign of the result is unspecified.
21135 To ignore the start value, the neutral value can be used.
21140 .. code-block:: llvm
21142 %r = call float @llvm.vp.reduce.fmin.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
21143 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
21144 ; are treated as though %mask were false for those lanes.
21146 %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN>
21147 %reduction = call float @llvm.vector.reduce.fmin.v4f32(<4 x float> %masked.a)
21148 %also.r = call float @llvm.minnum.f32(float %reduction, float %start)
21151 .. _int_get_active_lane_mask:
21153 '``llvm.get.active.lane.mask.*``' Intrinsics
21154 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21158 This is an overloaded intrinsic.
21162 declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %base, i32 %n)
21163 declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 %base, i64 %n)
21164 declare <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 %base, i64 %n)
21165 declare <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 %base, i64 %n)
21171 Create a mask representing active and inactive vector lanes.
21177 Both operands have the same scalar integer type. The result is a vector with
21178 the i1 element type.
21183 The '``llvm.get.active.lane.mask.*``' intrinsics are semantically equivalent
21188 %m[i] = icmp ult (%base + i), %n
21190 where ``%m`` is a vector (mask) of active/inactive lanes with its elements
21191 indexed by ``i``, and ``%base``, ``%n`` are the two arguments to
21192 ``llvm.get.active.lane.mask.*``, ``%icmp`` is an integer compare and ``ult``
21193 the unsigned less-than comparison operator. Overflow cannot occur in
21194 ``(%base + i)`` and its comparison against ``%n`` as it is performed in integer
21195 numbers and not in machine numbers. If ``%n`` is ``0``, then the result is a
21196 poison value. The above is equivalent to:
21200 %m = @llvm.get.active.lane.mask(%base, %n)
21202 This can, for example, be emitted by the loop vectorizer in which case
21203 ``%base`` is the first element of the vector induction variable (VIV) and
21204 ``%n`` is the loop tripcount. Thus, these intrinsics perform an element-wise
21205 less than comparison of VIV with the loop tripcount, producing a mask of
21206 true/false values representing active/inactive vector lanes, except if the VIV
21207 overflows in which case they return false in the lanes where the VIV overflows.
21208 The arguments are scalar types to accommodate scalable vector types, for which
21209 it is unknown what the type of the step vector needs to be that enumerate its
21210 lanes without overflow.
21212 This mask ``%m`` can e.g. be used in masked load/store instructions. These
21213 intrinsics provide a hint to the backend. I.e., for a vector loop, the
21214 back-edge taken count of the original scalar loop is explicit as the second
21221 .. code-block:: llvm
21223 %active.lane.mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 %elem0, i64 429)
21224 %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> poison)
21227 .. _int_experimental_vp_splice:
21229 '``llvm.experimental.vp.splice``' Intrinsic
21230 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21234 This is an overloaded intrinsic.
21238 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)
21239 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)
21244 The '``llvm.experimental.vp.splice.*``' intrinsic is the vector length
21245 predicated version of the '``llvm.experimental.vector.splice.*``' intrinsic.
21250 The result and the first two arguments ``vec1`` and ``vec2`` are vectors with
21251 the same type. The third argument ``imm`` is an immediate signed integer that
21252 indicates the offset index. The fourth argument ``mask`` is a vector mask and
21253 has the same number of elements as the result. The last two arguments ``evl1``
21254 and ``evl2`` are unsigned integers indicating the explicit vector lengths of
21255 ``vec1`` and ``vec2`` respectively. ``imm``, ``evl1`` and ``evl2`` should
21256 respect the following constraints: ``-evl1 <= imm < evl1``, ``0 <= evl1 <= VL``
21257 and ``0 <= evl2 <= VL``, where ``VL`` is the runtime vector factor. If these
21258 constraints are not satisfied the intrinsic has undefined behaviour.
21263 Effectively, this intrinsic concatenates ``vec1[0..evl1-1]`` and
21264 ``vec2[0..evl2-1]`` and creates the result vector by selecting the elements in a
21265 window of size ``evl2``, starting at index ``imm`` (for a positive immediate) of
21266 the concatenated vector. Elements in the result vector beyond ``evl2`` are
21267 ``undef``. If ``imm`` is negative the starting index is ``evl1 + imm``. The result
21268 vector of active vector length ``evl2`` contains ``evl1 - imm`` (``-imm`` for
21269 negative ``imm``) elements from indices ``[imm..evl1 - 1]``
21270 (``[evl1 + imm..evl1 -1]`` for negative ``imm``) of ``vec1`` followed by the
21271 first ``evl2 - (evl1 - imm)`` (``evl2 + imm`` for negative ``imm``) elements of
21272 ``vec2``. If ``evl1 - imm`` (``-imm``) >= ``evl2``, only the first ``evl2``
21273 elements are considered and the remaining are ``undef``. The lanes in the result
21274 vector disabled by ``mask`` are ``poison``.
21279 .. code-block:: text
21281 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, 1, 2, 3) ==> <B, E, F, poison> ; index
21282 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, -2, 3, 2) ==> <B, C, poison, poison> ; trailing elements
21287 '``llvm.vp.load``' Intrinsic
21288 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21292 This is an overloaded intrinsic.
21296 declare <4 x float> @llvm.vp.load.v4f32.p0(ptr %ptr, <4 x i1> %mask, i32 %evl)
21297 declare <vscale x 2 x i16> @llvm.vp.load.nxv2i16.p0(ptr %ptr, <vscale x 2 x i1> %mask, i32 %evl)
21298 declare <8 x float> @llvm.vp.load.v8f32.p1(ptr addrspace(1) %ptr, <8 x i1> %mask, i32 %evl)
21299 declare <vscale x 1 x i64> @llvm.vp.load.nxv1i64.p6(ptr addrspace(6) %ptr, <vscale x 1 x i1> %mask, i32 %evl)
21304 The '``llvm.vp.load.*``' intrinsic is the vector length predicated version of
21305 the :ref:`llvm.masked.load <int_mload>` intrinsic.
21310 The first operand is the base pointer for the load. The second operand is a
21311 vector of boolean values with the same number of elements as the return type.
21312 The third is the explicit vector length of the operation. The return type and
21313 underlying type of the base pointer are the same vector types.
21315 The :ref:`align <attr_align>` parameter attribute can be provided for the first
21321 The '``llvm.vp.load``' intrinsic reads a vector from memory in the same way as
21322 the '``llvm.masked.load``' intrinsic, where the mask is taken from the
21323 combination of the '``mask``' and '``evl``' operands in the usual VP way.
21324 Certain '``llvm.masked.load``' operands do not have corresponding operands in
21325 '``llvm.vp.load``': the '``passthru``' operand is implicitly ``poison``; the
21326 '``alignment``' operand is taken as the ``align`` parameter attribute, if
21327 provided. The default alignment is taken as the ABI alignment of the return
21328 type as specified by the :ref:`datalayout string<langref_datalayout>`.
21333 .. code-block:: text
21335 %r = call <8 x i8> @llvm.vp.load.v8i8.p0(ptr align 2 %ptr, <8 x i1> %mask, i32 %evl)
21336 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21338 %also.r = call <8 x i8> @llvm.masked.load.v8i8.p0(ptr %ptr, i32 2, <8 x i1> %mask, <8 x i8> poison)
21343 '``llvm.vp.store``' Intrinsic
21344 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21348 This is an overloaded intrinsic.
21352 declare void @llvm.vp.store.v4f32.p0(<4 x float> %val, ptr %ptr, <4 x i1> %mask, i32 %evl)
21353 declare void @llvm.vp.store.nxv2i16.p0(<vscale x 2 x i16> %val, ptr %ptr, <vscale x 2 x i1> %mask, i32 %evl)
21354 declare void @llvm.vp.store.v8f32.p1(<8 x float> %val, ptr addrspace(1) %ptr, <8 x i1> %mask, i32 %evl)
21355 declare void @llvm.vp.store.nxv1i64.p6(<vscale x 1 x i64> %val, ptr addrspace(6) %ptr, <vscale x 1 x i1> %mask, i32 %evl)
21360 The '``llvm.vp.store.*``' intrinsic is the vector length predicated version of
21361 the :ref:`llvm.masked.store <int_mstore>` intrinsic.
21366 The first operand is the vector value to be written to memory. The second
21367 operand is the base pointer for the store. It has the same underlying type as
21368 the value operand. The third operand is a vector of boolean values with the
21369 same number of elements as the return type. The fourth is the explicit vector
21370 length of the operation.
21372 The :ref:`align <attr_align>` parameter attribute can be provided for the
21378 The '``llvm.vp.store``' intrinsic reads a vector from memory in the same way as
21379 the '``llvm.masked.store``' intrinsic, where the mask is taken from the
21380 combination of the '``mask``' and '``evl``' operands in the usual VP way. The
21381 alignment of the operation (corresponding to the '``alignment``' operand of
21382 '``llvm.masked.store``') is specified by the ``align`` parameter attribute (see
21383 above). If it is not provided then the ABI alignment of the type of the
21384 '``value``' operand as specified by the :ref:`datalayout
21385 string<langref_datalayout>` is used instead.
21390 .. code-block:: text
21392 call void @llvm.vp.store.v8i8.p0(<8 x i8> %val, ptr align 4 %ptr, <8 x i1> %mask, i32 %evl)
21393 ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below.
21395 call void @llvm.masked.store.v8i8.p0(<8 x i8> %val, ptr %ptr, i32 4, <8 x i1> %mask)
21398 .. _int_experimental_vp_strided_load:
21400 '``llvm.experimental.vp.strided.load``' Intrinsic
21401 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21405 This is an overloaded intrinsic.
21409 declare <4 x float> @llvm.experimental.vp.strided.load.v4f32.i64(ptr %ptr, i64 %stride, <4 x i1> %mask, i32 %evl)
21410 declare <vscale x 2 x i16> @llvm.experimental.vp.strided.load.nxv2i16.i64(ptr %ptr, i64 %stride, <vscale x 2 x i1> %mask, i32 %evl)
21415 The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, scalar values from
21416 memory locations evenly spaced apart by '``stride``' number of bytes, starting from '``ptr``'.
21421 The first operand is the base pointer for the load. The second operand is the stride
21422 value expressed in bytes. The third operand is a vector of boolean values
21423 with the same number of elements as the return type. The fourth is the explicit
21424 vector length of the operation. The base pointer underlying type matches the type of the scalar
21425 elements of the return operand.
21427 The :ref:`align <attr_align>` parameter attribute can be provided for the first
21433 The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, multiple scalar
21434 values from memory in the same way as the :ref:`llvm.vp.gather <int_vp_gather>` intrinsic,
21435 where the vector of pointers is in the form:
21437 ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``,
21439 with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed
21440 integer and all arithmetic occurring in the pointer type.
21445 .. code-block:: text
21447 %r = call <8 x i64> @llvm.experimental.vp.strided.load.v8i64.i64(i64* %ptr, i64 %stride, <8 x i64> %mask, i32 %evl)
21448 ;; The operation can also be expressed like this:
21450 %addr = bitcast i64* %ptr to i8*
21451 ;; Create a vector of pointers %addrs in the form:
21452 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...>
21453 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* >
21454 %also.r = call <8 x i64> @llvm.vp.gather.v8i64.v8p0i64(<8 x i64* > %ptrs, <8 x i64> %mask, i32 %evl)
21457 .. _int_experimental_vp_strided_store:
21459 '``llvm.experimental.vp.strided.store``' Intrinsic
21460 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21464 This is an overloaded intrinsic.
21468 declare void @llvm.experimental.vp.strided.store.v4f32.i64(<4 x float> %val, ptr %ptr, i64 %stride, <4 x i1> %mask, i32 %evl)
21469 declare void @llvm.experimental.vp.strided.store.nxv2i16.i64(<vscale x 2 x i16> %val, ptr %ptr, i64 %stride, <vscale x 2 x i1> %mask, i32 %evl)
21474 The '``@llvm.experimental.vp.strided.store``' intrinsic stores the elements of
21475 '``val``' into memory locations evenly spaced apart by '``stride``' number of
21476 bytes, starting from '``ptr``'.
21481 The first operand is the vector value to be written to memory. The second
21482 operand is the base pointer for the store. Its underlying type matches the
21483 scalar element type of the value operand. The third operand is the stride value
21484 expressed in bytes. The fourth operand is a vector of boolean values with the
21485 same number of elements as the return type. The fifth is the explicit vector
21486 length of the operation.
21488 The :ref:`align <attr_align>` parameter attribute can be provided for the
21494 The '``llvm.experimental.vp.strided.store``' intrinsic stores the elements of
21495 '``val``' in the same way as the :ref:`llvm.vp.scatter <int_vp_scatter>` intrinsic,
21496 where the vector of pointers is in the form:
21498 ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``,
21500 with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed
21501 integer and all arithmetic occurring in the pointer type.
21506 .. code-block:: text
21508 call void @llvm.experimental.vp.strided.store.v8i64.i64(<8 x i64> %val, i64* %ptr, i64 %stride, <8 x i1> %mask, i32 %evl)
21509 ;; The operation can also be expressed like this:
21511 %addr = bitcast i64* %ptr to i8*
21512 ;; Create a vector of pointers %addrs in the form:
21513 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...>
21514 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* >
21515 call void @llvm.vp.scatter.v8i64.v8p0i64(<8 x i64> %val, <8 x i64*> %ptrs, <8 x i1> %mask, i32 %evl)
21520 '``llvm.vp.gather``' Intrinsic
21521 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21525 This is an overloaded intrinsic.
21529 declare <4 x double> @llvm.vp.gather.v4f64.v4p0(<4 x ptr> %ptrs, <4 x i1> %mask, i32 %evl)
21530 declare <vscale x 2 x i8> @llvm.vp.gather.nxv2i8.nxv2p0(<vscale x 2 x ptr> %ptrs, <vscale x 2 x i1> %mask, i32 %evl)
21531 declare <2 x float> @llvm.vp.gather.v2f32.v2p2(<2 x ptr addrspace(2)> %ptrs, <2 x i1> %mask, i32 %evl)
21532 declare <vscale x 4 x i32> @llvm.vp.gather.nxv4i32.nxv4p4(<vscale x 4 x ptr addrspace(4)> %ptrs, <vscale x 4 x i1> %mask, i32 %evl)
21537 The '``llvm.vp.gather.*``' intrinsic is the vector length predicated version of
21538 the :ref:`llvm.masked.gather <int_mgather>` intrinsic.
21543 The first operand is a vector of pointers which holds all memory addresses to
21544 read. The second operand is a vector of boolean values with the same number of
21545 elements as the return type. The third is the explicit vector length of the
21546 operation. The return type and underlying type of the vector of pointers are
21547 the same vector types.
21549 The :ref:`align <attr_align>` parameter attribute can be provided for the first
21555 The '``llvm.vp.gather``' intrinsic reads multiple scalar values from memory in
21556 the same way as the '``llvm.masked.gather``' intrinsic, where the mask is taken
21557 from the combination of the '``mask``' and '``evl``' operands in the usual VP
21558 way. Certain '``llvm.masked.gather``' operands do not have corresponding
21559 operands in '``llvm.vp.gather``': the '``passthru``' operand is implicitly
21560 ``poison``; the '``alignment``' operand is taken as the ``align`` parameter, if
21561 provided. The default alignment is taken as the ABI alignment of the source
21562 addresses as specified by the :ref:`datalayout string<langref_datalayout>`.
21567 .. code-block:: text
21569 %r = call <8 x i8> @llvm.vp.gather.v8i8.v8p0(<8 x ptr> align 8 %ptrs, <8 x i1> %mask, i32 %evl)
21570 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21572 %also.r = call <8 x i8> @llvm.masked.gather.v8i8.v8p0(<8 x ptr> %ptrs, i32 8, <8 x i1> %mask, <8 x i8> poison)
21575 .. _int_vp_scatter:
21577 '``llvm.vp.scatter``' Intrinsic
21578 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21582 This is an overloaded intrinsic.
21586 declare void @llvm.vp.scatter.v4f64.v4p0(<4 x double> %val, <4 x ptr> %ptrs, <4 x i1> %mask, i32 %evl)
21587 declare void @llvm.vp.scatter.nxv2i8.nxv2p0(<vscale x 2 x i8> %val, <vscale x 2 x ptr> %ptrs, <vscale x 2 x i1> %mask, i32 %evl)
21588 declare void @llvm.vp.scatter.v2f32.v2p2(<2 x float> %val, <2 x ptr addrspace(2)> %ptrs, <2 x i1> %mask, i32 %evl)
21589 declare void @llvm.vp.scatter.nxv4i32.nxv4p4(<vscale x 4 x i32> %val, <vscale x 4 x ptr addrspace(4)> %ptrs, <vscale x 4 x i1> %mask, i32 %evl)
21594 The '``llvm.vp.scatter.*``' intrinsic is the vector length predicated version of
21595 the :ref:`llvm.masked.scatter <int_mscatter>` intrinsic.
21600 The first operand is a vector value to be written to memory. The second operand
21601 is a vector of pointers, pointing to where the value elements should be stored.
21602 The third operand is a vector of boolean values with the same number of
21603 elements as the return type. The fourth is the explicit vector length of the
21606 The :ref:`align <attr_align>` parameter attribute can be provided for the
21612 The '``llvm.vp.scatter``' intrinsic writes multiple scalar values to memory in
21613 the same way as the '``llvm.masked.scatter``' intrinsic, where the mask is
21614 taken from the combination of the '``mask``' and '``evl``' operands in the
21615 usual VP way. The '``alignment``' operand of the '``llvm.masked.scatter``' does
21616 not have a corresponding operand in '``llvm.vp.scatter``': it is instead
21617 provided via the optional ``align`` parameter attribute on the
21618 vector-of-pointers operand. Otherwise it is taken as the ABI alignment of the
21619 destination addresses as specified by the :ref:`datalayout
21620 string<langref_datalayout>`.
21625 .. code-block:: text
21627 call void @llvm.vp.scatter.v8i8.v8p0(<8 x i8> %val, <8 x ptr> align 1 %ptrs, <8 x i1> %mask, i32 %evl)
21628 ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below.
21630 call void @llvm.masked.scatter.v8i8.v8p0(<8 x i8> %val, <8 x ptr> %ptrs, i32 1, <8 x i1> %mask)
21635 '``llvm.vp.trunc.*``' Intrinsics
21636 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21640 This is an overloaded intrinsic.
21644 declare <16 x i16> @llvm.vp.trunc.v16i16.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
21645 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>)
21650 The '``llvm.vp.trunc``' intrinsic truncates its first operand to the return
21651 type. The operation has a mask and an explicit vector length parameter.
21657 The '``llvm.vp.trunc``' intrinsic takes a value to cast as its first operand.
21658 The return type is the type to cast the value to. Both types must be vector of
21659 :ref:`integer <t_integer>` type. The bit size of the value must be larger than
21660 the bit size of the return type. The second operand is the vector mask. The
21661 return type, the value to cast, and the vector mask have the same number of
21662 elements. The third operand is the explicit vector length of the operation.
21667 The '``llvm.vp.trunc``' intrinsic truncates the high order bits in value and
21668 converts the remaining bits to return type. Since the source size must be larger
21669 than the destination size, '``llvm.vp.trunc``' cannot be a *no-op cast*. It will
21670 always truncate bits. The conversion is performed on lane positions below the
21671 explicit vector length and where the vector mask is true. Masked-off lanes are
21677 .. code-block:: llvm
21679 %r = call <4 x i16> @llvm.vp.trunc.v4i16.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
21680 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21682 %t = trunc <4 x i32> %a to <4 x i16>
21683 %also.r = select <4 x i1> %mask, <4 x i16> %t, <4 x i16> poison
21688 '``llvm.vp.zext.*``' Intrinsics
21689 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21693 This is an overloaded intrinsic.
21697 declare <16 x i32> @llvm.vp.zext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>)
21698 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>)
21703 The '``llvm.vp.zext``' intrinsic zero extends its first operand to the return
21704 type. The operation has a mask and an explicit vector length parameter.
21710 The '``llvm.vp.zext``' intrinsic takes a value to cast as its first operand.
21711 The return type is the type to cast the value to. Both types must be vectors of
21712 :ref:`integer <t_integer>` type. The bit size of the value must be smaller than
21713 the bit size of the return type. The second operand is the vector mask. The
21714 return type, the value to cast, and the vector mask have the same number of
21715 elements. The third operand is the explicit vector length of the operation.
21720 The '``llvm.vp.zext``' intrinsic fill the high order bits of the value with zero
21721 bits until it reaches the size of the return type. When zero extending from i1,
21722 the result will always be either 0 or 1. The conversion is performed on lane
21723 positions below the explicit vector length and where the vector mask is true.
21724 Masked-off lanes are ``poison``.
21729 .. code-block:: llvm
21731 %r = call <4 x i32> @llvm.vp.zext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl)
21732 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21734 %t = zext <4 x i16> %a to <4 x i32>
21735 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
21740 '``llvm.vp.sext.*``' Intrinsics
21741 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21745 This is an overloaded intrinsic.
21749 declare <16 x i32> @llvm.vp.sext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>)
21750 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>)
21755 The '``llvm.vp.sext``' intrinsic sign extends its first operand to the return
21756 type. The operation has a mask and an explicit vector length parameter.
21762 The '``llvm.vp.sext``' intrinsic takes a value to cast as its first operand.
21763 The return type is the type to cast the value to. Both types must be vectors of
21764 :ref:`integer <t_integer>` type. The bit size of the value must be smaller than
21765 the bit size of the return type. The second operand is the vector mask. The
21766 return type, the value to cast, and the vector mask have the same number of
21767 elements. The third operand is the explicit vector length of the operation.
21772 The '``llvm.vp.sext``' intrinsic performs a sign extension by copying the sign
21773 bit (highest order bit) of the value until it reaches the size of the return
21774 type. When sign extending from i1, the result will always be either -1 or 0.
21775 The conversion is performed on lane positions below the explicit vector length
21776 and where the vector mask is true. Masked-off lanes are ``poison``.
21781 .. code-block:: llvm
21783 %r = call <4 x i32> @llvm.vp.sext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl)
21784 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21786 %t = sext <4 x i16> %a to <4 x i32>
21787 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
21790 .. _int_vp_fptrunc:
21792 '``llvm.vp.fptrunc.*``' Intrinsics
21793 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21797 This is an overloaded intrinsic.
21801 declare <16 x float> @llvm.vp.fptrunc.v16f32.v16f64 (<16 x double> <op>, <16 x i1> <mask>, i32 <vector_length>)
21802 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>)
21807 The '``llvm.vp.fptrunc``' intrinsic truncates its first operand to the return
21808 type. The operation has a mask and an explicit vector length parameter.
21814 The '``llvm.vp.fptrunc``' intrinsic takes a value to cast as its first operand.
21815 The return type is the type to cast the value to. Both types must be vector of
21816 :ref:`floating-point <t_floating>` type. The bit size of the value must be
21817 larger than the bit size of the return type. This implies that
21818 '``llvm.vp.fptrunc``' cannot be used to make a *no-op cast*. The second operand
21819 is the vector mask. The return type, the value to cast, and the vector mask have
21820 the same number of elements. The third operand is the explicit vector length of
21826 The '``llvm.vp.fptrunc``' intrinsic casts a ``value`` from a larger
21827 :ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
21828 <t_floating>` type.
21829 This instruction is assumed to execute in the default :ref:`floating-point
21830 environment <floatenv>`. The conversion is performed on lane positions below the
21831 explicit vector length and where the vector mask is true. Masked-off lanes are
21837 .. code-block:: llvm
21839 %r = call <4 x float> @llvm.vp.fptrunc.v4f32.v4f64(<4 x double> %a, <4 x i1> %mask, i32 %evl)
21840 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21842 %t = fptrunc <4 x double> %a to <4 x float>
21843 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
21848 '``llvm.vp.fpext.*``' Intrinsics
21849 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21853 This is an overloaded intrinsic.
21857 declare <16 x double> @llvm.vp.fpext.v16f64.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
21858 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>)
21863 The '``llvm.vp.fpext``' intrinsic extends its first operand to the return
21864 type. The operation has a mask and an explicit vector length parameter.
21870 The '``llvm.vp.fpext``' intrinsic takes a value to cast as its first operand.
21871 The return type is the type to cast the value to. Both types must be vector of
21872 :ref:`floating-point <t_floating>` type. The bit size of the value must be
21873 smaller than the bit size of the return type. This implies that
21874 '``llvm.vp.fpext``' cannot be used to make a *no-op cast*. The second operand
21875 is the vector mask. The return type, the value to cast, and the vector mask have
21876 the same number of elements. The third operand is the explicit vector length of
21882 The '``llvm.vp.fpext``' intrinsic extends the ``value`` from a smaller
21883 :ref:`floating-point <t_floating>` type to a larger :ref:`floating-point
21884 <t_floating>` type. The '``llvm.vp.fpext``' cannot be used to make a
21885 *no-op cast* because it always changes bits. Use ``bitcast`` to make a
21886 *no-op cast* for a floating-point cast.
21887 The conversion is performed on lane positions below the explicit vector length
21888 and where the vector mask is true. Masked-off lanes are ``poison``.
21893 .. code-block:: llvm
21895 %r = call <4 x double> @llvm.vp.fpext.v4f64.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
21896 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21898 %t = fpext <4 x float> %a to <4 x double>
21899 %also.r = select <4 x i1> %mask, <4 x double> %t, <4 x double> poison
21904 '``llvm.vp.fptoui.*``' Intrinsics
21905 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21909 This is an overloaded intrinsic.
21913 declare <16 x i32> @llvm.vp.fptoui.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
21914 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>)
21915 declare <256 x i64> @llvm.vp.fptoui.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
21920 The '``llvm.vp.fptoui``' intrinsic converts the :ref:`floating-point
21921 <t_floating>` operand to the unsigned integer return type.
21922 The operation has a mask and an explicit vector length parameter.
21928 The '``llvm.vp.fptoui``' intrinsic takes a value to cast as its first operand.
21929 The value to cast must be a vector of :ref:`floating-point <t_floating>` type.
21930 The return type is the type to cast the value to. The return type must be
21931 vector of :ref:`integer <t_integer>` type. The second operand is the vector
21932 mask. The return type, the value to cast, and the vector mask have the same
21933 number of elements. The third operand is the explicit vector length of the
21939 The '``llvm.vp.fptoui``' intrinsic converts its :ref:`floating-point
21940 <t_floating>` operand into the nearest (rounding towards zero) unsigned integer
21941 value where the lane position is below the explicit vector length and the
21942 vector mask is true. Masked-off lanes are ``poison``. On enabled lanes where
21943 conversion takes place and the value cannot fit in the return type, the result
21944 on that lane is a :ref:`poison value <poisonvalues>`.
21949 .. code-block:: llvm
21951 %r = call <4 x i32> @llvm.vp.fptoui.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
21952 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21954 %t = fptoui <4 x float> %a to <4 x i32>
21955 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
21960 '``llvm.vp.fptosi.*``' Intrinsics
21961 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21965 This is an overloaded intrinsic.
21969 declare <16 x i32> @llvm.vp.fptosi.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
21970 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>)
21971 declare <256 x i64> @llvm.vp.fptosi.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
21976 The '``llvm.vp.fptosi``' intrinsic converts the :ref:`floating-point
21977 <t_floating>` operand to the signed integer return type.
21978 The operation has a mask and an explicit vector length parameter.
21984 The '``llvm.vp.fptosi``' intrinsic takes a value to cast as its first operand.
21985 The value to cast must be a vector of :ref:`floating-point <t_floating>` type.
21986 The return type is the type to cast the value to. The return type must be
21987 vector of :ref:`integer <t_integer>` type. The second operand is the vector
21988 mask. The return type, the value to cast, and the vector mask have the same
21989 number of elements. The third operand is the explicit vector length of the
21995 The '``llvm.vp.fptosi``' intrinsic converts its :ref:`floating-point
21996 <t_floating>` operand into the nearest (rounding towards zero) signed integer
21997 value where the lane position is below the explicit vector length and the
21998 vector mask is true. Masked-off lanes are ``poison``. On enabled lanes where
21999 conversion takes place and the value cannot fit in the return type, the result
22000 on that lane is a :ref:`poison value <poisonvalues>`.
22005 .. code-block:: llvm
22007 %r = call <4 x i32> @llvm.vp.fptosi.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22008 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22010 %t = fptosi <4 x float> %a to <4 x i32>
22011 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
22016 '``llvm.vp.uitofp.*``' Intrinsics
22017 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22021 This is an overloaded intrinsic.
22025 declare <16 x float> @llvm.vp.uitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
22026 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>)
22027 declare <256 x double> @llvm.vp.uitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
22032 The '``llvm.vp.uitofp``' intrinsic converts its unsigned integer operand to the
22033 :ref:`floating-point <t_floating>` return type. The operation has a mask and
22034 an explicit vector length parameter.
22040 The '``llvm.vp.uitofp``' intrinsic takes a value to cast as its first operand.
22041 The value to cast must be vector of :ref:`integer <t_integer>` type. The
22042 return type is the type to cast the value to. The return type must be a vector
22043 of :ref:`floating-point <t_floating>` type. The second operand is the vector
22044 mask. The return type, the value to cast, and the vector mask have the same
22045 number of elements. The third operand is the explicit vector length of the
22051 The '``llvm.vp.uitofp``' intrinsic interprets its first operand as an unsigned
22052 integer quantity and converts it to the corresponding floating-point value. If
22053 the value cannot be exactly represented, it is rounded using the default
22054 rounding mode. The conversion is performed on lane positions below the
22055 explicit vector length and where the vector mask is true. Masked-off lanes are
22061 .. code-block:: llvm
22063 %r = call <4 x float> @llvm.vp.uitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
22064 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22066 %t = uitofp <4 x i32> %a to <4 x float>
22067 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22072 '``llvm.vp.sitofp.*``' Intrinsics
22073 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22077 This is an overloaded intrinsic.
22081 declare <16 x float> @llvm.vp.sitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
22082 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>)
22083 declare <256 x double> @llvm.vp.sitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
22088 The '``llvm.vp.sitofp``' intrinsic converts its signed integer operand to the
22089 :ref:`floating-point <t_floating>` return type. The operation has a mask and
22090 an explicit vector length parameter.
22096 The '``llvm.vp.sitofp``' intrinsic takes a value to cast as its first operand.
22097 The value to cast must be vector of :ref:`integer <t_integer>` type. The
22098 return type is the type to cast the value to. The return type must be a vector
22099 of :ref:`floating-point <t_floating>` type. The second operand is the vector
22100 mask. The return type, the value to cast, and the vector mask have the same
22101 number of elements. The third operand is the explicit vector length of the
22107 The '``llvm.vp.sitofp``' intrinsic interprets its first operand as a signed
22108 integer quantity and converts it to the corresponding floating-point value. If
22109 the value cannot be exactly represented, it is rounded using the default
22110 rounding mode. The conversion is performed on lane positions below the
22111 explicit vector length and where the vector mask is true. Masked-off lanes are
22117 .. code-block:: llvm
22119 %r = call <4 x float> @llvm.vp.sitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
22120 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22122 %t = sitofp <4 x i32> %a to <4 x float>
22123 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22126 .. _int_vp_ptrtoint:
22128 '``llvm.vp.ptrtoint.*``' Intrinsics
22129 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22133 This is an overloaded intrinsic.
22137 declare <16 x i8> @llvm.vp.ptrtoint.v16i8.v16p0(<16 x ptr> <op>, <16 x i1> <mask>, i32 <vector_length>)
22138 declare <vscale x 4 x i8> @llvm.vp.ptrtoint.nxv4i8.nxv4p0(<vscale x 4 x ptr> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22139 declare <256 x i64> @llvm.vp.ptrtoint.v16i64.v16p0(<256 x ptr> <op>, <256 x i1> <mask>, i32 <vector_length>)
22144 The '``llvm.vp.ptrtoint``' intrinsic converts its pointer to the integer return
22145 type. The operation has a mask and an explicit vector length parameter.
22151 The '``llvm.vp.ptrtoint``' intrinsic takes a value to cast as its first operand
22152 , which must be a vector of pointers, and a type to cast it to return type,
22153 which must be a vector of :ref:`integer <t_integer>` type.
22154 The second operand is the vector mask. The return type, the value to cast, and
22155 the vector mask have the same number of elements.
22156 The third operand is the explicit vector length of the operation.
22161 The '``llvm.vp.ptrtoint``' intrinsic converts value to return type by
22162 interpreting the pointer value as an integer and either truncating or zero
22163 extending that value to the size of the integer type.
22164 If ``value`` is smaller than return type, then a zero extension is done. If
22165 ``value`` is larger than return type, then a truncation is done. If they are
22166 the same size, then nothing is done (*no-op cast*) other than a type
22168 The conversion is performed on lane positions below the explicit vector length
22169 and where the vector mask is true. Masked-off lanes are ``poison``.
22174 .. code-block:: llvm
22176 %r = call <4 x i8> @llvm.vp.ptrtoint.v4i8.v4p0i32(<4 x ptr> %a, <4 x i1> %mask, i32 %evl)
22177 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22179 %t = ptrtoint <4 x ptr> %a to <4 x i8>
22180 %also.r = select <4 x i1> %mask, <4 x i8> %t, <4 x i8> poison
22183 .. _int_vp_inttoptr:
22185 '``llvm.vp.inttoptr.*``' Intrinsics
22186 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22190 This is an overloaded intrinsic.
22194 declare <16 x ptr> @llvm.vp.inttoptr.v16p0.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
22195 declare <vscale x 4 x ptr> @llvm.vp.inttoptr.nxv4p0.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22196 declare <256 x ptr> @llvm.vp.inttoptr.v256p0.v256i32 (<256 x i32> <op>, <256 x i1> <mask>, i32 <vector_length>)
22201 The '``llvm.vp.inttoptr``' intrinsic converts its integer value to the point
22202 return type. The operation has a mask and an explicit vector length parameter.
22208 The '``llvm.vp.inttoptr``' intrinsic takes a value to cast as its first operand
22209 , which must be a vector of :ref:`integer <t_integer>` type, and a type to cast
22210 it to return type, which must be a vector of pointers type.
22211 The second operand is the vector mask. The return type, the value to cast, and
22212 the vector mask have the same number of elements.
22213 The third operand is the explicit vector length of the operation.
22218 The '``llvm.vp.inttoptr``' intrinsic converts ``value`` to return type by
22219 applying either a zero extension or a truncation depending on the size of the
22220 integer ``value``. If ``value`` is larger than the size of a pointer, then a
22221 truncation is done. If ``value`` is smaller than the size of a pointer, then a
22222 zero extension is done. If they are the same size, nothing is done (*no-op cast*).
22223 The conversion is performed on lane positions below the explicit vector length
22224 and where the vector mask is true. Masked-off lanes are ``poison``.
22229 .. code-block:: llvm
22231 %r = call <4 x ptr> @llvm.vp.inttoptr.v4p0i32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
22232 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22234 %t = inttoptr <4 x i32> %a to <4 x ptr>
22235 %also.r = select <4 x i1> %mask, <4 x ptr> %t, <4 x ptr> poison
22240 '``llvm.vp.fcmp.*``' Intrinsics
22241 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22245 This is an overloaded intrinsic.
22249 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>)
22250 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>)
22251 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>)
22256 The '``llvm.vp.fcmp``' intrinsic returns a vector of boolean values based on
22257 the comparison of its operands. The operation has a mask and an explicit vector
22264 The '``llvm.vp.fcmp``' intrinsic takes the two values to compare as its first
22265 and second operands. These two values must be vectors of :ref:`floating-point
22266 <t_floating>` types.
22267 The return type is the result of the comparison. The return type must be a
22268 vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask.
22269 The return type, the values to compare, and the vector mask have the same
22270 number of elements. The third operand is the condition code indicating the kind
22271 of comparison to perform. It must be a metadata string with :ref:`one of the
22272 supported floating-point condition code values <fcmp_md_cc>`. The fifth operand
22273 is the explicit vector length of the operation.
22278 The '``llvm.vp.fcmp``' compares its first two operands according to the
22279 condition code given as the third operand. The operands are compared element by
22280 element on each enabled lane, where the the semantics of the comparison are
22281 defined :ref:`according to the condition code <fcmp_md_cc_sem>`. Masked-off
22282 lanes are ``poison``.
22287 .. code-block:: llvm
22289 %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)
22290 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22292 %t = fcmp oeq <4 x float> %a, %b
22293 %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> poison
22298 '``llvm.vp.icmp.*``' Intrinsics
22299 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22303 This is an overloaded intrinsic.
22307 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>)
22308 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>)
22309 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>)
22314 The '``llvm.vp.icmp``' intrinsic returns a vector of boolean values based on
22315 the comparison of its operands. The operation has a mask and an explicit vector
22322 The '``llvm.vp.icmp``' intrinsic takes the two values to compare as its first
22323 and second operands. These two values must be vectors of :ref:`integer
22324 <t_integer>` types.
22325 The return type is the result of the comparison. The return type must be a
22326 vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask.
22327 The return type, the values to compare, and the vector mask have the same
22328 number of elements. The third operand is the condition code indicating the kind
22329 of comparison to perform. It must be a metadata string with :ref:`one of the
22330 supported integer condition code values <icmp_md_cc>`. The fifth operand is the
22331 explicit vector length of the operation.
22336 The '``llvm.vp.icmp``' compares its first two operands according to the
22337 condition code given as the third operand. The operands are compared element by
22338 element on each enabled lane, where the the semantics of the comparison are
22339 defined :ref:`according to the condition code <icmp_md_cc_sem>`. Masked-off
22340 lanes are ``poison``.
22345 .. code-block:: llvm
22347 %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)
22348 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22350 %t = icmp ne <4 x i32> %a, %b
22351 %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> poison
22355 '``llvm.vp.ceil.*``' Intrinsics
22356 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22360 This is an overloaded intrinsic.
22364 declare <16 x float> @llvm.vp.ceil.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22365 declare <vscale x 4 x float> @llvm.vp.ceil.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22366 declare <256 x double> @llvm.vp.ceil.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22371 Predicated floating-point ceiling of a vector of floating-point values.
22377 The first operand and the result have the same vector of floating-point type.
22378 The second operand is the vector mask and has the same number of elements as the
22379 result vector type. The third operand is the explicit vector length of the
22385 The '``llvm.vp.ceil``' intrinsic performs floating-point ceiling
22386 (:ref:`ceil <int_ceil>`) of the first vector operand on each enabled lane. The
22387 result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22392 .. code-block:: llvm
22394 %r = call <4 x float> @llvm.vp.ceil.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22395 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22397 %t = call <4 x float> @llvm.ceil.v4f32(<4 x float> %a)
22398 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22402 '``llvm.vp.floor.*``' Intrinsics
22403 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22407 This is an overloaded intrinsic.
22411 declare <16 x float> @llvm.vp.floor.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22412 declare <vscale x 4 x float> @llvm.vp.floor.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22413 declare <256 x double> @llvm.vp.floor.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22418 Predicated floating-point floor of a vector of floating-point values.
22424 The first operand and the result have the same vector of floating-point type.
22425 The second operand is the vector mask and has the same number of elements as the
22426 result vector type. The third operand is the explicit vector length of the
22432 The '``llvm.vp.floor``' intrinsic performs floating-point floor
22433 (:ref:`floor <int_floor>`) of the first vector operand on each enabled lane.
22434 The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22439 .. code-block:: llvm
22441 %r = call <4 x float> @llvm.vp.floor.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22442 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22444 %t = call <4 x float> @llvm.floor.v4f32(<4 x float> %a)
22445 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22449 '``llvm.vp.rint.*``' Intrinsics
22450 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22454 This is an overloaded intrinsic.
22458 declare <16 x float> @llvm.vp.rint.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22459 declare <vscale x 4 x float> @llvm.vp.rint.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22460 declare <256 x double> @llvm.vp.rint.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22465 Predicated floating-point rint of a vector of floating-point values.
22471 The first operand and the result have the same vector of floating-point type.
22472 The second operand is the vector mask and has the same number of elements as the
22473 result vector type. The third operand is the explicit vector length of the
22479 The '``llvm.vp.rint``' intrinsic performs floating-point rint
22480 (:ref:`rint <int_rint>`) of the first vector operand on each enabled lane.
22481 The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22486 .. code-block:: llvm
22488 %r = call <4 x float> @llvm.vp.rint.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22489 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22491 %t = call <4 x float> @llvm.rint.v4f32(<4 x float> %a)
22492 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22494 .. _int_vp_nearbyint:
22496 '``llvm.vp.nearbyint.*``' Intrinsics
22497 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22501 This is an overloaded intrinsic.
22505 declare <16 x float> @llvm.vp.nearbyint.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22506 declare <vscale x 4 x float> @llvm.vp.nearbyint.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22507 declare <256 x double> @llvm.vp.nearbyint.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22512 Predicated floating-point nearbyint of a vector of floating-point values.
22518 The first operand and the result have the same vector of floating-point type.
22519 The second operand is the vector mask and has the same number of elements as the
22520 result vector type. The third operand is the explicit vector length of the
22526 The '``llvm.vp.nearbyint``' intrinsic performs floating-point nearbyint
22527 (:ref:`nearbyint <int_nearbyint>`) of the first vector operand on each enabled lane.
22528 The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22533 .. code-block:: llvm
22535 %r = call <4 x float> @llvm.vp.nearbyint.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22536 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22538 %t = call <4 x float> @llvm.nearbyint.v4f32(<4 x float> %a)
22539 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22543 '``llvm.vp.round.*``' Intrinsics
22544 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22548 This is an overloaded intrinsic.
22552 declare <16 x float> @llvm.vp.round.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22553 declare <vscale x 4 x float> @llvm.vp.round.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22554 declare <256 x double> @llvm.vp.round.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22559 Predicated floating-point round of a vector of floating-point values.
22565 The first operand and the result have the same vector of floating-point type.
22566 The second operand is the vector mask and has the same number of elements as the
22567 result vector type. The third operand is the explicit vector length of the
22573 The '``llvm.vp.round``' intrinsic performs floating-point round
22574 (:ref:`round <int_round>`) of the first vector operand on each enabled lane.
22575 The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22580 .. code-block:: llvm
22582 %r = call <4 x float> @llvm.vp.round.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22583 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22585 %t = call <4 x float> @llvm.round.v4f32(<4 x float> %a)
22586 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22588 .. _int_vp_roundeven:
22590 '``llvm.vp.roundeven.*``' Intrinsics
22591 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22595 This is an overloaded intrinsic.
22599 declare <16 x float> @llvm.vp.roundeven.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22600 declare <vscale x 4 x float> @llvm.vp.roundeven.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22601 declare <256 x double> @llvm.vp.roundeven.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22606 Predicated floating-point roundeven of a vector of floating-point values.
22612 The first operand and the result have the same vector of floating-point type.
22613 The second operand is the vector mask and has the same number of elements as the
22614 result vector type. The third operand is the explicit vector length of the
22620 The '``llvm.vp.roundeven``' intrinsic performs floating-point roundeven
22621 (:ref:`roundeven <int_roundeven>`) of the first vector operand on each enabled
22622 lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22627 .. code-block:: llvm
22629 %r = call <4 x float> @llvm.vp.roundeven.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22630 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22632 %t = call <4 x float> @llvm.roundeven.v4f32(<4 x float> %a)
22633 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22635 .. _int_vp_roundtozero:
22637 '``llvm.vp.roundtozero.*``' Intrinsics
22638 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22642 This is an overloaded intrinsic.
22646 declare <16 x float> @llvm.vp.roundtozero.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22647 declare <vscale x 4 x float> @llvm.vp.roundtozero.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22648 declare <256 x double> @llvm.vp.roundtozero.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22653 Predicated floating-point round-to-zero of a vector of floating-point values.
22659 The first operand and the result have the same vector of floating-point type.
22660 The second operand is the vector mask and has the same number of elements as the
22661 result vector type. The third operand is the explicit vector length of the
22667 The '``llvm.vp.roundtozero``' intrinsic performs floating-point roundeven
22668 (:ref:`llvm.trunc <int_llvm_trunc>`) of the first vector operand on each enabled lane. The
22669 result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22674 .. code-block:: llvm
22676 %r = call <4 x float> @llvm.vp.roundtozero.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22677 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22679 %t = call <4 x float> @llvm.trunc.v4f32(<4 x float> %a)
22680 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22682 .. _int_vp_bitreverse:
22684 '``llvm.vp.bitreverse.*``' Intrinsics
22685 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22689 This is an overloaded intrinsic.
22693 declare <16 x i32> @llvm.vp.bitreverse.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
22694 declare <vscale x 4 x i32> @llvm.vp.bitreverse.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22695 declare <256 x i64> @llvm.vp.bitreverse.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
22700 Predicated bitreverse of a vector of integers.
22706 The first operand and the result have the same vector of integer type. The
22707 second operand is the vector mask and has the same number of elements as the
22708 result vector type. The third operand is the explicit vector length of the
22714 The '``llvm.vp.bitreverse``' intrinsic performs bitreverse (:ref:`bitreverse <int_bitreverse>`) of the first operand on each
22715 enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22720 .. code-block:: llvm
22722 %r = call <4 x i32> @llvm.vp.bitreverse.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
22723 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22725 %t = call <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> %a)
22726 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
22731 '``llvm.vp.bswap.*``' Intrinsics
22732 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22736 This is an overloaded intrinsic.
22740 declare <16 x i32> @llvm.vp.bswap.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
22741 declare <vscale x 4 x i32> @llvm.vp.bswap.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22742 declare <256 x i64> @llvm.vp.bswap.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
22747 Predicated bswap of a vector of integers.
22753 The first operand and the result have the same vector of integer type. The
22754 second operand is the vector mask and has the same number of elements as the
22755 result vector type. The third operand is the explicit vector length of the
22761 The '``llvm.vp.bswap``' intrinsic performs bswap (:ref:`bswap <int_bswap>`) of the first operand on each
22762 enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22767 .. code-block:: llvm
22769 %r = call <4 x i32> @llvm.vp.bswap.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
22770 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22772 %t = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
22773 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
22778 '``llvm.vp.ctpop.*``' Intrinsics
22779 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22783 This is an overloaded intrinsic.
22787 declare <16 x i32> @llvm.vp.ctpop.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
22788 declare <vscale x 4 x i32> @llvm.vp.ctpop.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22789 declare <256 x i64> @llvm.vp.ctpop.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
22794 Predicated ctpop of a vector of integers.
22800 The first operand and the result have the same vector of integer type. The
22801 second operand is the vector mask and has the same number of elements as the
22802 result vector type. The third operand is the explicit vector length of the
22808 The '``llvm.vp.ctpop``' intrinsic performs ctpop (:ref:`ctpop <int_ctpop>`) of the first operand on each
22809 enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22814 .. code-block:: llvm
22816 %r = call <4 x i32> @llvm.vp.ctpop.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
22817 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22819 %t = call <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %a)
22820 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
22825 '``llvm.vp.ctlz.*``' Intrinsics
22826 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22830 This is an overloaded intrinsic.
22834 declare <16 x i32> @llvm.vp.ctlz.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>)
22835 declare <vscale x 4 x i32> @llvm.vp.ctlz.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>)
22836 declare <256 x i64> @llvm.vp.ctlz.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>)
22841 Predicated ctlz of a vector of integers.
22847 The first operand and the result have the same vector of integer type. The
22848 second operand is the vector mask and has the same number of elements as the
22849 result vector type. The third operand is the explicit vector length of the
22855 The '``llvm.vp.ctlz``' intrinsic performs ctlz (:ref:`ctlz <int_ctlz>`) of the first operand on each
22856 enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22861 .. code-block:: llvm
22863 %r = call <4 x i32> @llvm.vp.ctlz.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl, i1 false)
22864 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22866 %t = call <4 x i32> @llvm.ctlz.v4i32(<4 x i32> %a, i1 false)
22867 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
22872 '``llvm.vp.cttz.*``' Intrinsics
22873 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22877 This is an overloaded intrinsic.
22881 declare <16 x i32> @llvm.vp.cttz.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>)
22882 declare <vscale x 4 x i32> @llvm.vp.cttz.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>)
22883 declare <256 x i64> @llvm.vp.cttz.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>)
22888 Predicated cttz of a vector of integers.
22894 The first operand and the result have the same vector of integer type. The
22895 second operand is the vector mask and has the same number of elements as the
22896 result vector type. The third operand is the explicit vector length of the
22902 The '``llvm.vp.cttz``' intrinsic performs cttz (:ref:`cttz <int_cttz>`) of the first operand on each
22903 enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22908 .. code-block:: llvm
22910 %r = call <4 x i32> @llvm.vp.cttz.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl, i1 false)
22911 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22913 %t = call <4 x i32> @llvm.cttz.v4i32(<4 x i32> %a, i1 false)
22914 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
22919 '``llvm.vp.fshl.*``' Intrinsics
22920 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22924 This is an overloaded intrinsic.
22928 declare <16 x i32> @llvm.vp.fshl.v16i32 (<16 x i32> <left_op>, <16 x i32> <middle_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
22929 declare <vscale x 4 x i32> @llvm.vp.fshl.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <middle_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22930 declare <256 x i64> @llvm.vp.fshl.v256i64 (<256 x i64> <left_op>, <256 x i64> <middle_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
22935 Predicated fshl of three vectors of integers.
22941 The first three operand and the result have the same vector of integer type. The
22942 fourth operand is the vector mask and has the same number of elements as the
22943 result vector type. The fifth operand is the explicit vector length of the
22949 The '``llvm.vp.fshl``' intrinsic performs fshl (:ref:`fshl <int_fshl>`) of the first, second, and third
22950 vector operand on each enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22956 .. code-block:: llvm
22958 %r = call <4 x i32> @llvm.vp.fshl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c, <4 x i1> %mask, i32 %evl)
22959 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22961 %t = call <4 x i32> @llvm.fshl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c)
22962 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
22965 '``llvm.vp.fshr.*``' Intrinsics
22966 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22970 This is an overloaded intrinsic.
22974 declare <16 x i32> @llvm.vp.fshr.v16i32 (<16 x i32> <left_op>, <16 x i32> <middle_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>)
22975 declare <vscale x 4 x i32> @llvm.vp.fshr.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <middle_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>)
22976 declare <256 x i64> @llvm.vp.fshr.v256i64 (<256 x i64> <left_op>, <256 x i64> <middle_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>)
22981 Predicated fshr of three vectors of integers.
22987 The first three operand and the result have the same vector of integer type. The
22988 fourth operand is the vector mask and has the same number of elements as the
22989 result vector type. The fifth operand is the explicit vector length of the
22995 The '``llvm.vp.fshr``' intrinsic performs fshr (:ref:`fshr <int_fshr>`) of the first, second, and third
22996 vector operand on each enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
23002 .. code-block:: llvm
23004 %r = call <4 x i32> @llvm.vp.fshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c, <4 x i1> %mask, i32 %evl)
23005 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
23007 %t = call <4 x i32> @llvm.fshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c)
23008 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
23011 .. _int_mload_mstore:
23013 Masked Vector Load and Store Intrinsics
23014 ---------------------------------------
23016 LLVM 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.
23020 '``llvm.masked.load.*``' Intrinsics
23021 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23025 This is an overloaded intrinsic. The loaded data is a vector of any integer, floating-point or pointer data type.
23029 declare <16 x float> @llvm.masked.load.v16f32.p0(ptr <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
23030 declare <2 x double> @llvm.masked.load.v2f64.p0(ptr <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>)
23031 ;; The data is a vector of pointers
23032 declare <8 x ptr> @llvm.masked.load.v8p0.p0(ptr <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x ptr> <passthru>)
23037 Reads 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.
23043 The 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.
23048 The '``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.
23049 The 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.
23054 %res = call <16 x float> @llvm.masked.load.v16f32.p0(ptr %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru)
23056 ;; The result of the two following instructions is identical aside from potential memory access exception
23057 %loadlal = load <16 x float>, ptr %ptr, align 4
23058 %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru
23062 '``llvm.masked.store.*``' Intrinsics
23063 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23067 This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type.
23071 declare void @llvm.masked.store.v8i32.p0 (<8 x i32> <value>, ptr <ptr>, i32 <alignment>, <8 x i1> <mask>)
23072 declare void @llvm.masked.store.v16f32.p0(<16 x float> <value>, ptr <ptr>, i32 <alignment>, <16 x i1> <mask>)
23073 ;; The data is a vector of pointers
23074 declare void @llvm.masked.store.v8p0.p0 (<8 x ptr> <value>, ptr <ptr>, i32 <alignment>, <8 x i1> <mask>)
23079 Writes 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.
23084 The 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.
23090 The '``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.
23091 The 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.
23095 call void @llvm.masked.store.v16f32.p0(<16 x float> %value, ptr %ptr, i32 4, <16 x i1> %mask)
23097 ;; The result of the following instructions is identical aside from potential data races and memory access exceptions
23098 %oldval = load <16 x float>, ptr %ptr, align 4
23099 %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval
23100 store <16 x float> %res, ptr %ptr, align 4
23103 Masked Vector Gather and Scatter Intrinsics
23104 -------------------------------------------
23106 LLVM 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.
23110 '``llvm.masked.gather.*``' Intrinsics
23111 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23115 This 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.
23119 declare <16 x float> @llvm.masked.gather.v16f32.v16p0(<16 x ptr> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
23120 declare <2 x double> @llvm.masked.gather.v2f64.v2p1(<2 x ptr addrspace(1)> <ptrs>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>)
23121 declare <8 x ptr> @llvm.masked.gather.v8p0.v8p0(<8 x ptr> <ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x ptr> <passthru>)
23126 Reads 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.
23132 The 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.
23137 The '``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.
23138 The 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.
23143 %res = call <4 x double> @llvm.masked.gather.v4f64.v4p0(<4 x ptr> %ptrs, i32 8, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x double> poison)
23145 ;; The gather with all-true mask is equivalent to the following instruction sequence
23146 %ptr0 = extractelement <4 x ptr> %ptrs, i32 0
23147 %ptr1 = extractelement <4 x ptr> %ptrs, i32 1
23148 %ptr2 = extractelement <4 x ptr> %ptrs, i32 2
23149 %ptr3 = extractelement <4 x ptr> %ptrs, i32 3
23151 %val0 = load double, ptr %ptr0, align 8
23152 %val1 = load double, ptr %ptr1, align 8
23153 %val2 = load double, ptr %ptr2, align 8
23154 %val3 = load double, ptr %ptr3, align 8
23156 %vec0 = insertelement <4 x double> poison, %val0, 0
23157 %vec01 = insertelement <4 x double> %vec0, %val1, 1
23158 %vec012 = insertelement <4 x double> %vec01, %val2, 2
23159 %vec0123 = insertelement <4 x double> %vec012, %val3, 3
23163 '``llvm.masked.scatter.*``' Intrinsics
23164 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23168 This 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.
23172 declare void @llvm.masked.scatter.v8i32.v8p0 (<8 x i32> <value>, <8 x ptr> <ptrs>, i32 <alignment>, <8 x i1> <mask>)
23173 declare void @llvm.masked.scatter.v16f32.v16p1(<16 x float> <value>, <16 x ptr addrspace(1)> <ptrs>, i32 <alignment>, <16 x i1> <mask>)
23174 declare void @llvm.masked.scatter.v4p0.v4p0 (<4 x ptr> <value>, <4 x ptr> <ptrs>, i32 <alignment>, <4 x i1> <mask>)
23179 Writes 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.
23184 The 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.
23189 The '``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.
23193 ;; This instruction unconditionally stores data vector in multiple addresses
23194 call @llvm.masked.scatter.v8i32.v8p0(<8 x i32> %value, <8 x ptr> %ptrs, i32 4, <8 x i1> <true, true, .. true>)
23196 ;; It is equivalent to a list of scalar stores
23197 %val0 = extractelement <8 x i32> %value, i32 0
23198 %val1 = extractelement <8 x i32> %value, i32 1
23200 %val7 = extractelement <8 x i32> %value, i32 7
23201 %ptr0 = extractelement <8 x ptr> %ptrs, i32 0
23202 %ptr1 = extractelement <8 x ptr> %ptrs, i32 1
23204 %ptr7 = extractelement <8 x ptr> %ptrs, i32 7
23205 ;; Note: the order of the following stores is important when they overlap:
23206 store i32 %val0, ptr %ptr0, align 4
23207 store i32 %val1, ptr %ptr1, align 4
23209 store i32 %val7, ptr %ptr7, align 4
23212 Masked Vector Expanding Load and Compressing Store Intrinsics
23213 -------------------------------------------------------------
23215 LLVM 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>`.
23217 .. _int_expandload:
23219 '``llvm.masked.expandload.*``' Intrinsics
23220 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23224 This 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.
23228 declare <16 x float> @llvm.masked.expandload.v16f32 (ptr <ptr>, <16 x i1> <mask>, <16 x float> <passthru>)
23229 declare <2 x i64> @llvm.masked.expandload.v2i64 (ptr <ptr>, <2 x i1> <mask>, <2 x i64> <passthru>)
23234 Reads 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.
23240 The 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.
23245 The '``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:
23249 // In this loop we load from B and spread the elements into array A.
23250 double *A, B; int *C;
23251 for (int i = 0; i < size; ++i) {
23257 .. code-block:: llvm
23259 ; Load several elements from array B and expand them in a vector.
23260 ; The number of loaded elements is equal to the number of '1' elements in the Mask.
23261 %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(ptr %Bptr, <8 x i1> %Mask, <8 x double> poison)
23262 ; Store the result in A
23263 call void @llvm.masked.store.v8f64.p0(<8 x double> %Tmp, ptr %Aptr, i32 8, <8 x i1> %Mask)
23265 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
23266 %MaskI = bitcast <8 x i1> %Mask to i8
23267 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
23268 %MaskI64 = zext i8 %MaskIPopcnt to i64
23269 %BNextInd = add i64 %BInd, %MaskI64
23272 Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles.
23273 If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load.
23275 .. _int_compressstore:
23277 '``llvm.masked.compressstore.*``' Intrinsics
23278 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23282 This 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.
23286 declare void @llvm.masked.compressstore.v8i32 (<8 x i32> <value>, ptr <ptr>, <8 x i1> <mask>)
23287 declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, ptr <ptr>, <16 x i1> <mask>)
23292 Selects 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.
23297 The 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.
23303 The '``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:
23307 // In this loop we load elements from A and store them consecutively in B
23308 double *A, B; int *C;
23309 for (int i = 0; i < size; ++i) {
23315 .. code-block:: llvm
23317 ; Load elements from A.
23318 %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0(ptr %Aptr, i32 8, <8 x i1> %Mask, <8 x double> poison)
23319 ; Store all selected elements consecutively in array B
23320 call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, ptr %Bptr, <8 x i1> %Mask)
23322 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
23323 %MaskI = bitcast <8 x i1> %Mask to i8
23324 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
23325 %MaskI64 = zext i8 %MaskIPopcnt to i64
23326 %BNextInd = add i64 %BInd, %MaskI64
23329 Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations.
23335 This class of intrinsics provides information about the
23336 :ref:`lifetime of memory objects <objectlifetime>` and ranges where variables
23341 '``llvm.lifetime.start``' Intrinsic
23342 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23349 declare void @llvm.lifetime.start(i64 <size>, ptr nocapture <ptr>)
23354 The '``llvm.lifetime.start``' intrinsic specifies the start of a memory
23360 The first argument is a constant integer representing the size of the
23361 object, or -1 if it is variable sized. The second argument is a pointer
23367 If ``ptr`` is a stack-allocated object and it points to the first byte of
23368 the object, the object is initially marked as dead.
23369 ``ptr`` is conservatively considered as a non-stack-allocated object if
23370 the stack coloring algorithm that is used in the optimization pipeline cannot
23371 conclude that ``ptr`` is a stack-allocated object.
23373 After '``llvm.lifetime.start``', the stack object that ``ptr`` points is marked
23374 as alive and has an uninitialized value.
23375 The stack object is marked as dead when either
23376 :ref:`llvm.lifetime.end <int_lifeend>` to the alloca is executed or the
23379 After :ref:`llvm.lifetime.end <int_lifeend>` is called,
23380 '``llvm.lifetime.start``' on the stack object can be called again.
23381 The second '``llvm.lifetime.start``' call marks the object as alive, but it
23382 does not change the address of the object.
23384 If ``ptr`` is a non-stack-allocated object, it does not point to the first
23385 byte of the object or it is a stack object that is already alive, it simply
23386 fills all bytes of the object with ``poison``.
23391 '``llvm.lifetime.end``' Intrinsic
23392 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23399 declare void @llvm.lifetime.end(i64 <size>, ptr nocapture <ptr>)
23404 The '``llvm.lifetime.end``' intrinsic specifies the end of a memory object's
23410 The first argument is a constant integer representing the size of the
23411 object, or -1 if it is variable sized. The second argument is a pointer
23417 If ``ptr`` is a stack-allocated object and it points to the first byte of the
23418 object, the object is dead.
23419 ``ptr`` is conservatively considered as a non-stack-allocated object if
23420 the stack coloring algorithm that is used in the optimization pipeline cannot
23421 conclude that ``ptr`` is a stack-allocated object.
23423 Calling ``llvm.lifetime.end`` on an already dead alloca is no-op.
23425 If ``ptr`` is a non-stack-allocated object or it does not point to the first
23426 byte of the object, it is equivalent to simply filling all bytes of the object
23430 '``llvm.invariant.start``' Intrinsic
23431 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23435 This is an overloaded intrinsic. The memory object can belong to any address space.
23439 declare ptr @llvm.invariant.start.p0(i64 <size>, ptr nocapture <ptr>)
23444 The '``llvm.invariant.start``' intrinsic specifies that the contents of
23445 a memory object will not change.
23450 The first argument is a constant integer representing the size of the
23451 object, or -1 if it is variable sized. The second argument is a pointer
23457 This intrinsic indicates that until an ``llvm.invariant.end`` that uses
23458 the return value, the referenced memory location is constant and
23461 '``llvm.invariant.end``' Intrinsic
23462 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23466 This is an overloaded intrinsic. The memory object can belong to any address space.
23470 declare void @llvm.invariant.end.p0(ptr <start>, i64 <size>, ptr nocapture <ptr>)
23475 The '``llvm.invariant.end``' intrinsic specifies that the contents of a
23476 memory object are mutable.
23481 The first argument is the matching ``llvm.invariant.start`` intrinsic.
23482 The second argument is a constant integer representing the size of the
23483 object, or -1 if it is variable sized and the third argument is a
23484 pointer to the object.
23489 This intrinsic indicates that the memory is mutable again.
23491 '``llvm.launder.invariant.group``' Intrinsic
23492 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23496 This is an overloaded intrinsic. The memory object can belong to any address
23497 space. The returned pointer must belong to the same address space as the
23502 declare ptr @llvm.launder.invariant.group.p0(ptr <ptr>)
23507 The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant
23508 established by ``invariant.group`` metadata no longer holds, to obtain a new
23509 pointer value that carries fresh invariant group information. It is an
23510 experimental intrinsic, which means that its semantics might change in the
23517 The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer
23523 Returns another pointer that aliases its argument but which is considered different
23524 for the purposes of ``load``/``store`` ``invariant.group`` metadata.
23525 It does not read any accessible memory and the execution can be speculated.
23527 '``llvm.strip.invariant.group``' Intrinsic
23528 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23532 This is an overloaded intrinsic. The memory object can belong to any address
23533 space. The returned pointer must belong to the same address space as the
23538 declare ptr @llvm.strip.invariant.group.p0(ptr <ptr>)
23543 The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant
23544 established by ``invariant.group`` metadata no longer holds, to obtain a new pointer
23545 value that does not carry the invariant information. It is an experimental
23546 intrinsic, which means that its semantics might change in the future.
23552 The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer
23558 Returns another pointer that aliases its argument but which has no associated
23559 ``invariant.group`` metadata.
23560 It does not read any memory and can be speculated.
23566 Constrained Floating-Point Intrinsics
23567 -------------------------------------
23569 These intrinsics are used to provide special handling of floating-point
23570 operations when specific rounding mode or floating-point exception behavior is
23571 required. By default, LLVM optimization passes assume that the rounding mode is
23572 round-to-nearest and that floating-point exceptions will not be monitored.
23573 Constrained FP intrinsics are used to support non-default rounding modes and
23574 accurately preserve exception behavior without compromising LLVM's ability to
23575 optimize FP code when the default behavior is used.
23577 If any FP operation in a function is constrained then they all must be
23578 constrained. This is required for correct LLVM IR. Optimizations that
23579 move code around can create miscompiles if mixing of constrained and normal
23580 operations is done. The correct way to mix constrained and less constrained
23581 operations is to use the rounding mode and exception handling metadata to
23582 mark constrained intrinsics as having LLVM's default behavior.
23584 Each of these intrinsics corresponds to a normal floating-point operation. The
23585 data arguments and the return value are the same as the corresponding FP
23588 The rounding mode argument is a metadata string specifying what
23589 assumptions, if any, the optimizer can make when transforming constant
23590 values. Some constrained FP intrinsics omit this argument. If required
23591 by the intrinsic, this argument must be one of the following strings:
23600 "round.tonearestaway"
23602 If this argument is "round.dynamic" optimization passes must assume that the
23603 rounding mode is unknown and may change at runtime. No transformations that
23604 depend on rounding mode may be performed in this case.
23606 The other possible values for the rounding mode argument correspond to the
23607 similarly named IEEE rounding modes. If the argument is any of these values
23608 optimization passes may perform transformations as long as they are consistent
23609 with the specified rounding mode.
23611 For example, 'x-0'->'x' is not a valid transformation if the rounding mode is
23612 "round.downward" or "round.dynamic" because if the value of 'x' is +0 then
23613 'x-0' should evaluate to '-0' when rounding downward. However, this
23614 transformation is legal for all other rounding modes.
23616 For values other than "round.dynamic" optimization passes may assume that the
23617 actual runtime rounding mode (as defined in a target-specific manner) matches
23618 the specified rounding mode, but this is not guaranteed. Using a specific
23619 non-dynamic rounding mode which does not match the actual rounding mode at
23620 runtime results in undefined behavior.
23622 The exception behavior argument is a metadata string describing the floating
23623 point exception semantics that required for the intrinsic. This argument
23624 must be one of the following strings:
23632 If this argument is "fpexcept.ignore" optimization passes may assume that the
23633 exception status flags will not be read and that floating-point exceptions will
23634 be masked. This allows transformations to be performed that may change the
23635 exception semantics of the original code. For example, FP operations may be
23636 speculatively executed in this case whereas they must not be for either of the
23637 other possible values of this argument.
23639 If the exception behavior argument is "fpexcept.maytrap" optimization passes
23640 must avoid transformations that may raise exceptions that would not have been
23641 raised by the original code (such as speculatively executing FP operations), but
23642 passes are not required to preserve all exceptions that are implied by the
23643 original code. For example, exceptions may be potentially hidden by constant
23646 If the exception behavior argument is "fpexcept.strict" all transformations must
23647 strictly preserve the floating-point exception semantics of the original code.
23648 Any FP exception that would have been raised by the original code must be raised
23649 by the transformed code, and the transformed code must not raise any FP
23650 exceptions that would not have been raised by the original code. This is the
23651 exception behavior argument that will be used if the code being compiled reads
23652 the FP exception status flags, but this mode can also be used with code that
23653 unmasks FP exceptions.
23655 The number and order of floating-point exceptions is NOT guaranteed. For
23656 example, a series of FP operations that each may raise exceptions may be
23657 vectorized into a single instruction that raises each unique exception a single
23660 Proper :ref:`function attributes <fnattrs>` usage is required for the
23661 constrained intrinsics to function correctly.
23663 All function *calls* done in a function that uses constrained floating
23664 point intrinsics must have the ``strictfp`` attribute either on the
23665 calling instruction or on the declaration or definition of the function
23668 All function *definitions* that use constrained floating point intrinsics
23669 must have the ``strictfp`` attribute.
23671 '``llvm.experimental.constrained.fadd``' Intrinsic
23672 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23680 @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>,
23681 metadata <rounding mode>,
23682 metadata <exception behavior>)
23687 The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its
23694 The first two arguments to the '``llvm.experimental.constrained.fadd``'
23695 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
23696 of floating-point values. Both arguments must have identical types.
23698 The third and fourth arguments specify the rounding mode and exception
23699 behavior as described above.
23704 The value produced is the floating-point sum of the two value operands and has
23705 the same type as the operands.
23708 '``llvm.experimental.constrained.fsub``' Intrinsic
23709 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23717 @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>,
23718 metadata <rounding mode>,
23719 metadata <exception behavior>)
23724 The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference
23725 of its two operands.
23731 The first two arguments to the '``llvm.experimental.constrained.fsub``'
23732 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
23733 of floating-point values. Both arguments must have identical types.
23735 The third and fourth arguments specify the rounding mode and exception
23736 behavior as described above.
23741 The value produced is the floating-point difference of the two value operands
23742 and has the same type as the operands.
23745 '``llvm.experimental.constrained.fmul``' Intrinsic
23746 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23754 @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>,
23755 metadata <rounding mode>,
23756 metadata <exception behavior>)
23761 The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of
23768 The first two arguments to the '``llvm.experimental.constrained.fmul``'
23769 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
23770 of floating-point values. Both arguments must have identical types.
23772 The third and fourth arguments specify the rounding mode and exception
23773 behavior as described above.
23778 The value produced is the floating-point product of the two value operands and
23779 has the same type as the operands.
23782 '``llvm.experimental.constrained.fdiv``' Intrinsic
23783 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23791 @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>,
23792 metadata <rounding mode>,
23793 metadata <exception behavior>)
23798 The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of
23805 The first two arguments to the '``llvm.experimental.constrained.fdiv``'
23806 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
23807 of floating-point values. Both arguments must have identical types.
23809 The third and fourth arguments specify the rounding mode and exception
23810 behavior as described above.
23815 The value produced is the floating-point quotient of the two value operands and
23816 has the same type as the operands.
23819 '``llvm.experimental.constrained.frem``' Intrinsic
23820 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23828 @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>,
23829 metadata <rounding mode>,
23830 metadata <exception behavior>)
23835 The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder
23836 from the division of its two operands.
23842 The first two arguments to the '``llvm.experimental.constrained.frem``'
23843 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
23844 of floating-point values. Both arguments must have identical types.
23846 The third and fourth arguments specify the rounding mode and exception
23847 behavior as described above. The rounding mode argument has no effect, since
23848 the result of frem is never rounded, but the argument is included for
23849 consistency with the other constrained floating-point intrinsics.
23854 The value produced is the floating-point remainder from the division of the two
23855 value operands and has the same type as the operands. The remainder has the
23856 same sign as the dividend.
23858 '``llvm.experimental.constrained.fma``' Intrinsic
23859 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23867 @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>,
23868 metadata <rounding mode>,
23869 metadata <exception behavior>)
23874 The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a
23875 fused-multiply-add operation on its operands.
23880 The first three arguments to the '``llvm.experimental.constrained.fma``'
23881 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector
23882 <t_vector>` of floating-point values. All arguments must have identical types.
23884 The fourth and fifth arguments specify the rounding mode and exception behavior
23885 as described above.
23890 The result produced is the product of the first two operands added to the third
23891 operand computed with infinite precision, and then rounded to the target
23894 '``llvm.experimental.constrained.fptoui``' Intrinsic
23895 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23903 @llvm.experimental.constrained.fptoui(<type> <value>,
23904 metadata <exception behavior>)
23909 The '``llvm.experimental.constrained.fptoui``' intrinsic converts a
23910 floating-point ``value`` to its unsigned integer equivalent of type ``ty2``.
23915 The first argument to the '``llvm.experimental.constrained.fptoui``'
23916 intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
23917 <t_vector>` of floating point values.
23919 The second argument specifies the exception behavior as described above.
23924 The result produced is an unsigned integer converted from the floating
23925 point operand. The value is truncated, so it is rounded towards zero.
23927 '``llvm.experimental.constrained.fptosi``' Intrinsic
23928 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23936 @llvm.experimental.constrained.fptosi(<type> <value>,
23937 metadata <exception behavior>)
23942 The '``llvm.experimental.constrained.fptosi``' intrinsic converts
23943 :ref:`floating-point <t_floating>` ``value`` to type ``ty2``.
23948 The first argument to the '``llvm.experimental.constrained.fptosi``'
23949 intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
23950 <t_vector>` of floating point values.
23952 The second argument specifies the exception behavior as described above.
23957 The result produced is a signed integer converted from the floating
23958 point operand. The value is truncated, so it is rounded towards zero.
23960 '``llvm.experimental.constrained.uitofp``' Intrinsic
23961 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23969 @llvm.experimental.constrained.uitofp(<type> <value>,
23970 metadata <rounding mode>,
23971 metadata <exception behavior>)
23976 The '``llvm.experimental.constrained.uitofp``' intrinsic converts an
23977 unsigned integer ``value`` to a floating-point of type ``ty2``.
23982 The first argument to the '``llvm.experimental.constrained.uitofp``'
23983 intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector
23984 <t_vector>` of integer values.
23986 The second and third arguments specify the rounding mode and exception
23987 behavior as described above.
23992 An inexact floating-point exception will be raised if rounding is required.
23993 Any result produced is a floating point value converted from the input
23996 '``llvm.experimental.constrained.sitofp``' Intrinsic
23997 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24005 @llvm.experimental.constrained.sitofp(<type> <value>,
24006 metadata <rounding mode>,
24007 metadata <exception behavior>)
24012 The '``llvm.experimental.constrained.sitofp``' intrinsic converts a
24013 signed integer ``value`` to a floating-point of type ``ty2``.
24018 The first argument to the '``llvm.experimental.constrained.sitofp``'
24019 intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector
24020 <t_vector>` of integer values.
24022 The second and third arguments specify the rounding mode and exception
24023 behavior as described above.
24028 An inexact floating-point exception will be raised if rounding is required.
24029 Any result produced is a floating point value converted from the input
24032 '``llvm.experimental.constrained.fptrunc``' Intrinsic
24033 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24041 @llvm.experimental.constrained.fptrunc(<type> <value>,
24042 metadata <rounding mode>,
24043 metadata <exception behavior>)
24048 The '``llvm.experimental.constrained.fptrunc``' intrinsic truncates ``value``
24054 The first argument to the '``llvm.experimental.constrained.fptrunc``'
24055 intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
24056 <t_vector>` of floating point values. This argument must be larger in size
24059 The second and third arguments specify the rounding mode and exception
24060 behavior as described above.
24065 The result produced is a floating point value truncated to be smaller in size
24068 '``llvm.experimental.constrained.fpext``' Intrinsic
24069 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24077 @llvm.experimental.constrained.fpext(<type> <value>,
24078 metadata <exception behavior>)
24083 The '``llvm.experimental.constrained.fpext``' intrinsic extends a
24084 floating-point ``value`` to a larger floating-point value.
24089 The first argument to the '``llvm.experimental.constrained.fpext``'
24090 intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
24091 <t_vector>` of floating point values. This argument must be smaller in size
24094 The second argument specifies the exception behavior as described above.
24099 The result produced is a floating point value extended to be larger in size
24100 than the operand. All restrictions that apply to the fpext instruction also
24101 apply to this intrinsic.
24103 '``llvm.experimental.constrained.fcmp``' and '``llvm.experimental.constrained.fcmps``' Intrinsics
24104 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24112 @llvm.experimental.constrained.fcmp(<type> <op1>, <type> <op2>,
24113 metadata <condition code>,
24114 metadata <exception behavior>)
24116 @llvm.experimental.constrained.fcmps(<type> <op1>, <type> <op2>,
24117 metadata <condition code>,
24118 metadata <exception behavior>)
24123 The '``llvm.experimental.constrained.fcmp``' and
24124 '``llvm.experimental.constrained.fcmps``' intrinsics return a boolean
24125 value or vector of boolean values based on comparison of its operands.
24127 If the operands are floating-point scalars, then the result type is a
24128 boolean (:ref:`i1 <t_integer>`).
24130 If the operands are floating-point vectors, then the result type is a
24131 vector of boolean with the same number of elements as the operands being
24134 The '``llvm.experimental.constrained.fcmp``' intrinsic performs a quiet
24135 comparison operation while the '``llvm.experimental.constrained.fcmps``'
24136 intrinsic performs a signaling comparison operation.
24141 The first two arguments to the '``llvm.experimental.constrained.fcmp``'
24142 and '``llvm.experimental.constrained.fcmps``' intrinsics must be
24143 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
24144 of floating-point values. Both arguments must have identical types.
24146 The third argument is the condition code indicating the kind of comparison
24147 to perform. It must be a metadata string with one of the following values:
24151 - "``oeq``": ordered and equal
24152 - "``ogt``": ordered and greater than
24153 - "``oge``": ordered and greater than or equal
24154 - "``olt``": ordered and less than
24155 - "``ole``": ordered and less than or equal
24156 - "``one``": ordered and not equal
24157 - "``ord``": ordered (no nans)
24158 - "``ueq``": unordered or equal
24159 - "``ugt``": unordered or greater than
24160 - "``uge``": unordered or greater than or equal
24161 - "``ult``": unordered or less than
24162 - "``ule``": unordered or less than or equal
24163 - "``une``": unordered or not equal
24164 - "``uno``": unordered (either nans)
24166 *Ordered* means that neither operand is a NAN while *unordered* means
24167 that either operand may be a NAN.
24169 The fourth argument specifies the exception behavior as described above.
24174 ``op1`` and ``op2`` are compared according to the condition code given
24175 as the third argument. If the operands are vectors, then the
24176 vectors are compared element by element. Each comparison performed
24177 always yields an :ref:`i1 <t_integer>` result, as follows:
24179 .. _fcmp_md_cc_sem:
24181 - "``oeq``": yields ``true`` if both operands are not a NAN and ``op1``
24182 is equal to ``op2``.
24183 - "``ogt``": yields ``true`` if both operands are not a NAN and ``op1``
24184 is greater than ``op2``.
24185 - "``oge``": yields ``true`` if both operands are not a NAN and ``op1``
24186 is greater than or equal to ``op2``.
24187 - "``olt``": yields ``true`` if both operands are not a NAN and ``op1``
24188 is less than ``op2``.
24189 - "``ole``": yields ``true`` if both operands are not a NAN and ``op1``
24190 is less than or equal to ``op2``.
24191 - "``one``": yields ``true`` if both operands are not a NAN and ``op1``
24192 is not equal to ``op2``.
24193 - "``ord``": yields ``true`` if both operands are not a NAN.
24194 - "``ueq``": yields ``true`` if either operand is a NAN or ``op1`` is
24196 - "``ugt``": yields ``true`` if either operand is a NAN or ``op1`` is
24197 greater than ``op2``.
24198 - "``uge``": yields ``true`` if either operand is a NAN or ``op1`` is
24199 greater than or equal to ``op2``.
24200 - "``ult``": yields ``true`` if either operand is a NAN or ``op1`` is
24202 - "``ule``": yields ``true`` if either operand is a NAN or ``op1`` is
24203 less than or equal to ``op2``.
24204 - "``une``": yields ``true`` if either operand is a NAN or ``op1`` is
24205 not equal to ``op2``.
24206 - "``uno``": yields ``true`` if either operand is a NAN.
24208 The quiet comparison operation performed by
24209 '``llvm.experimental.constrained.fcmp``' will only raise an exception
24210 if either operand is a SNAN. The signaling comparison operation
24211 performed by '``llvm.experimental.constrained.fcmps``' will raise an
24212 exception if either operand is a NAN (QNAN or SNAN). Such an exception
24213 does not preclude a result being produced (e.g. exception might only
24214 set a flag), therefore the distinction between ordered and unordered
24215 comparisons is also relevant for the
24216 '``llvm.experimental.constrained.fcmps``' intrinsic.
24218 '``llvm.experimental.constrained.fmuladd``' Intrinsic
24219 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24227 @llvm.experimental.constrained.fmuladd(<type> <op1>, <type> <op2>,
24229 metadata <rounding mode>,
24230 metadata <exception behavior>)
24235 The '``llvm.experimental.constrained.fmuladd``' intrinsic represents
24236 multiply-add expressions that can be fused if the code generator determines
24237 that (a) the target instruction set has support for a fused operation,
24238 and (b) that the fused operation is more efficient than the equivalent,
24239 separate pair of mul and add instructions.
24244 The first three arguments to the '``llvm.experimental.constrained.fmuladd``'
24245 intrinsic must be floating-point or vector of floating-point values.
24246 All three arguments must have identical types.
24248 The fourth and fifth arguments specify the rounding mode and exception behavior
24249 as described above.
24258 %0 = call float @llvm.experimental.constrained.fmuladd.f32(%a, %b, %c,
24259 metadata <rounding mode>,
24260 metadata <exception behavior>)
24262 is equivalent to the expression:
24266 %0 = call float @llvm.experimental.constrained.fmul.f32(%a, %b,
24267 metadata <rounding mode>,
24268 metadata <exception behavior>)
24269 %1 = call float @llvm.experimental.constrained.fadd.f32(%0, %c,
24270 metadata <rounding mode>,
24271 metadata <exception behavior>)
24273 except that it is unspecified whether rounding will be performed between the
24274 multiplication and addition steps. Fusion is not guaranteed, even if the target
24275 platform supports it.
24276 If a fused multiply-add is required, the corresponding
24277 :ref:`llvm.experimental.constrained.fma <int_fma>` intrinsic function should be
24279 This never sets errno, just as '``llvm.experimental.constrained.fma.*``'.
24281 Constrained libm-equivalent Intrinsics
24282 --------------------------------------
24284 In addition to the basic floating-point operations for which constrained
24285 intrinsics are described above, there are constrained versions of various
24286 operations which provide equivalent behavior to a corresponding libm function.
24287 These intrinsics allow the precise behavior of these operations with respect to
24288 rounding mode and exception behavior to be controlled.
24290 As with the basic constrained floating-point intrinsics, the rounding mode
24291 and exception behavior arguments only control the behavior of the optimizer.
24292 They do not change the runtime floating-point environment.
24295 '``llvm.experimental.constrained.sqrt``' Intrinsic
24296 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24304 @llvm.experimental.constrained.sqrt(<type> <op1>,
24305 metadata <rounding mode>,
24306 metadata <exception behavior>)
24311 The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root
24312 of the specified value, returning the same value as the libm '``sqrt``'
24313 functions would, but without setting ``errno``.
24318 The first argument and the return type are floating-point numbers of the same
24321 The second and third arguments specify the rounding mode and exception
24322 behavior as described above.
24327 This function returns the nonnegative square root of the specified value.
24328 If the value is less than negative zero, a floating-point exception occurs
24329 and the return value is architecture specific.
24332 '``llvm.experimental.constrained.pow``' Intrinsic
24333 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24341 @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>,
24342 metadata <rounding mode>,
24343 metadata <exception behavior>)
24348 The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand
24349 raised to the (positive or negative) power specified by the second operand.
24354 The first two arguments and the return value are floating-point numbers of the
24355 same type. The second argument specifies the power to which the first argument
24358 The third and fourth arguments specify the rounding mode and exception
24359 behavior as described above.
24364 This function returns the first value raised to the second power,
24365 returning the same values as the libm ``pow`` functions would, and
24366 handles error conditions in the same way.
24369 '``llvm.experimental.constrained.powi``' Intrinsic
24370 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24378 @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>,
24379 metadata <rounding mode>,
24380 metadata <exception behavior>)
24385 The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand
24386 raised to the (positive or negative) power specified by the second operand. The
24387 order of evaluation of multiplications is not defined. When a vector of
24388 floating-point type is used, the second argument remains a scalar integer value.
24394 The first argument and the return value are floating-point numbers of the same
24395 type. The second argument is a 32-bit signed integer specifying the power to
24396 which the first argument should be raised.
24398 The third and fourth arguments specify the rounding mode and exception
24399 behavior as described above.
24404 This function returns the first value raised to the second power with an
24405 unspecified sequence of rounding operations.
24408 '``llvm.experimental.constrained.ldexp``' Intrinsic
24409 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24417 @llvm.experimental.constrained.ldexp(<type0> <op1>, <type1> <op2>,
24418 metadata <rounding mode>,
24419 metadata <exception behavior>)
24424 The '``llvm.experimental.constrained.ldexp``' performs the ldexp function.
24430 The first argument and the return value are :ref:`floating-point
24431 <t_floating>` or :ref:`vector <t_vector>` of floating-point values of
24432 the same type. The second argument is an integer with the same number
24436 The third and fourth arguments specify the rounding mode and exception
24437 behavior as described above.
24442 This function multiplies the first argument by 2 raised to the second
24443 argument's power. If the first argument is NaN or infinite, the same
24444 value is returned. If the result underflows a zero with the same sign
24445 is returned. If the result overflows, the result is an infinity with
24449 '``llvm.experimental.constrained.sin``' Intrinsic
24450 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24458 @llvm.experimental.constrained.sin(<type> <op1>,
24459 metadata <rounding mode>,
24460 metadata <exception behavior>)
24465 The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the
24471 The first argument and the return type are floating-point numbers of the same
24474 The second and third arguments specify the rounding mode and exception
24475 behavior as described above.
24480 This function returns the sine of the specified operand, returning the
24481 same values as the libm ``sin`` functions would, and handles error
24482 conditions in the same way.
24485 '``llvm.experimental.constrained.cos``' Intrinsic
24486 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24494 @llvm.experimental.constrained.cos(<type> <op1>,
24495 metadata <rounding mode>,
24496 metadata <exception behavior>)
24501 The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the
24507 The first argument and the return type are floating-point numbers of the same
24510 The second and third arguments specify the rounding mode and exception
24511 behavior as described above.
24516 This function returns the cosine of the specified operand, returning the
24517 same values as the libm ``cos`` functions would, and handles error
24518 conditions in the same way.
24521 '``llvm.experimental.constrained.exp``' Intrinsic
24522 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24530 @llvm.experimental.constrained.exp(<type> <op1>,
24531 metadata <rounding mode>,
24532 metadata <exception behavior>)
24537 The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e
24538 exponential of the specified value.
24543 The first argument and the return value are floating-point numbers of the same
24546 The second and third arguments specify the rounding mode and exception
24547 behavior as described above.
24552 This function returns the same values as the libm ``exp`` functions
24553 would, and handles error conditions in the same way.
24556 '``llvm.experimental.constrained.exp2``' Intrinsic
24557 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24565 @llvm.experimental.constrained.exp2(<type> <op1>,
24566 metadata <rounding mode>,
24567 metadata <exception behavior>)
24572 The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2
24573 exponential of the specified value.
24579 The first argument and the return value are floating-point numbers of the same
24582 The second and third arguments specify the rounding mode and exception
24583 behavior as described above.
24588 This function returns the same values as the libm ``exp2`` functions
24589 would, and handles error conditions in the same way.
24592 '``llvm.experimental.constrained.log``' Intrinsic
24593 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24601 @llvm.experimental.constrained.log(<type> <op1>,
24602 metadata <rounding mode>,
24603 metadata <exception behavior>)
24608 The '``llvm.experimental.constrained.log``' intrinsic computes the base-e
24609 logarithm of the specified value.
24614 The first argument and the return value are floating-point numbers of the same
24617 The second and third arguments specify the rounding mode and exception
24618 behavior as described above.
24624 This function returns the same values as the libm ``log`` functions
24625 would, and handles error conditions in the same way.
24628 '``llvm.experimental.constrained.log10``' Intrinsic
24629 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24637 @llvm.experimental.constrained.log10(<type> <op1>,
24638 metadata <rounding mode>,
24639 metadata <exception behavior>)
24644 The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10
24645 logarithm of the specified value.
24650 The first argument and the return value are floating-point numbers of the same
24653 The second and third arguments specify the rounding mode and exception
24654 behavior as described above.
24659 This function returns the same values as the libm ``log10`` functions
24660 would, and handles error conditions in the same way.
24663 '``llvm.experimental.constrained.log2``' Intrinsic
24664 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24672 @llvm.experimental.constrained.log2(<type> <op1>,
24673 metadata <rounding mode>,
24674 metadata <exception behavior>)
24679 The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2
24680 logarithm of the specified value.
24685 The first argument and the return value are floating-point numbers of the same
24688 The second and third arguments specify the rounding mode and exception
24689 behavior as described above.
24694 This function returns the same values as the libm ``log2`` functions
24695 would, and handles error conditions in the same way.
24698 '``llvm.experimental.constrained.rint``' Intrinsic
24699 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24707 @llvm.experimental.constrained.rint(<type> <op1>,
24708 metadata <rounding mode>,
24709 metadata <exception behavior>)
24714 The '``llvm.experimental.constrained.rint``' intrinsic returns the first
24715 operand rounded to the nearest integer. It may raise an inexact floating-point
24716 exception if the operand is not an integer.
24721 The first argument and the return value are floating-point numbers of the same
24724 The second and third arguments specify the rounding mode and exception
24725 behavior as described above.
24730 This function returns the same values as the libm ``rint`` functions
24731 would, and handles error conditions in the same way. The rounding mode is
24732 described, not determined, by the rounding mode argument. The actual rounding
24733 mode is determined by the runtime floating-point environment. The rounding
24734 mode argument is only intended as information to the compiler.
24737 '``llvm.experimental.constrained.lrint``' Intrinsic
24738 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24746 @llvm.experimental.constrained.lrint(<fptype> <op1>,
24747 metadata <rounding mode>,
24748 metadata <exception behavior>)
24753 The '``llvm.experimental.constrained.lrint``' intrinsic returns the first
24754 operand rounded to the nearest integer. An inexact floating-point exception
24755 will be raised if the operand is not an integer. An invalid exception is
24756 raised if the result is too large to fit into a supported integer type,
24757 and in this case the result is undefined.
24762 The first argument is a floating-point number. The return value is an
24763 integer type. Not all types are supported on all targets. The supported
24764 types are the same as the ``llvm.lrint`` intrinsic and the ``lrint``
24767 The second and third arguments specify the rounding mode and exception
24768 behavior as described above.
24773 This function returns the same values as the libm ``lrint`` functions
24774 would, and handles error conditions in the same way.
24776 The rounding mode is described, not determined, by the rounding mode
24777 argument. The actual rounding mode is determined by the runtime floating-point
24778 environment. The rounding mode argument is only intended as information
24781 If the runtime floating-point environment is using the default rounding mode
24782 then the results will be the same as the llvm.lrint intrinsic.
24785 '``llvm.experimental.constrained.llrint``' Intrinsic
24786 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24794 @llvm.experimental.constrained.llrint(<fptype> <op1>,
24795 metadata <rounding mode>,
24796 metadata <exception behavior>)
24801 The '``llvm.experimental.constrained.llrint``' intrinsic returns the first
24802 operand rounded to the nearest integer. An inexact floating-point exception
24803 will be raised if the operand is not an integer. An invalid exception is
24804 raised if the result is too large to fit into a supported integer type,
24805 and in this case the result is undefined.
24810 The first argument is a floating-point number. The return value is an
24811 integer type. Not all types are supported on all targets. The supported
24812 types are the same as the ``llvm.llrint`` intrinsic and the ``llrint``
24815 The second and third arguments specify the rounding mode and exception
24816 behavior as described above.
24821 This function returns the same values as the libm ``llrint`` functions
24822 would, and handles error conditions in the same way.
24824 The rounding mode is described, not determined, by the rounding mode
24825 argument. The actual rounding mode is determined by the runtime floating-point
24826 environment. The rounding mode argument is only intended as information
24829 If the runtime floating-point environment is using the default rounding mode
24830 then the results will be the same as the llvm.llrint intrinsic.
24833 '``llvm.experimental.constrained.nearbyint``' Intrinsic
24834 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24842 @llvm.experimental.constrained.nearbyint(<type> <op1>,
24843 metadata <rounding mode>,
24844 metadata <exception behavior>)
24849 The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first
24850 operand rounded to the nearest integer. It will not raise an inexact
24851 floating-point exception if the operand is not an integer.
24857 The first argument and the return value are floating-point numbers of the same
24860 The second and third arguments specify the rounding mode and exception
24861 behavior as described above.
24866 This function returns the same values as the libm ``nearbyint`` functions
24867 would, and handles error conditions in the same way. The rounding mode is
24868 described, not determined, by the rounding mode argument. The actual rounding
24869 mode is determined by the runtime floating-point environment. The rounding
24870 mode argument is only intended as information to the compiler.
24873 '``llvm.experimental.constrained.maxnum``' Intrinsic
24874 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24882 @llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2>
24883 metadata <exception behavior>)
24888 The '``llvm.experimental.constrained.maxnum``' intrinsic returns the maximum
24889 of the two arguments.
24894 The first two arguments and the return value are floating-point numbers
24897 The third argument specifies the exception behavior as described above.
24902 This function follows the IEEE-754 semantics for maxNum.
24905 '``llvm.experimental.constrained.minnum``' Intrinsic
24906 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24914 @llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2>
24915 metadata <exception behavior>)
24920 The '``llvm.experimental.constrained.minnum``' intrinsic returns the minimum
24921 of the two arguments.
24926 The first two arguments and the return value are floating-point numbers
24929 The third argument specifies the exception behavior as described above.
24934 This function follows the IEEE-754 semantics for minNum.
24937 '``llvm.experimental.constrained.maximum``' Intrinsic
24938 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24946 @llvm.experimental.constrained.maximum(<type> <op1>, <type> <op2>
24947 metadata <exception behavior>)
24952 The '``llvm.experimental.constrained.maximum``' intrinsic returns the maximum
24953 of the two arguments, propagating NaNs and treating -0.0 as less than +0.0.
24958 The first two arguments and the return value are floating-point numbers
24961 The third argument specifies the exception behavior as described above.
24966 This function follows semantics specified in the draft of IEEE 754-2018.
24969 '``llvm.experimental.constrained.minimum``' Intrinsic
24970 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24978 @llvm.experimental.constrained.minimum(<type> <op1>, <type> <op2>
24979 metadata <exception behavior>)
24984 The '``llvm.experimental.constrained.minimum``' intrinsic returns the minimum
24985 of the two arguments, propagating NaNs and treating -0.0 as less than +0.0.
24990 The first two arguments and the return value are floating-point numbers
24993 The third argument specifies the exception behavior as described above.
24998 This function follows semantics specified in the draft of IEEE 754-2018.
25001 '``llvm.experimental.constrained.ceil``' Intrinsic
25002 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25010 @llvm.experimental.constrained.ceil(<type> <op1>,
25011 metadata <exception behavior>)
25016 The '``llvm.experimental.constrained.ceil``' intrinsic returns the ceiling of the
25022 The first argument and the return value are floating-point numbers of the same
25025 The second argument specifies the exception behavior as described above.
25030 This function returns the same values as the libm ``ceil`` functions
25031 would and handles error conditions in the same way.
25034 '``llvm.experimental.constrained.floor``' Intrinsic
25035 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25043 @llvm.experimental.constrained.floor(<type> <op1>,
25044 metadata <exception behavior>)
25049 The '``llvm.experimental.constrained.floor``' intrinsic returns the floor of the
25055 The first argument and the return value are floating-point numbers of the same
25058 The second argument specifies the exception behavior as described above.
25063 This function returns the same values as the libm ``floor`` functions
25064 would and handles error conditions in the same way.
25067 '``llvm.experimental.constrained.round``' Intrinsic
25068 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25076 @llvm.experimental.constrained.round(<type> <op1>,
25077 metadata <exception behavior>)
25082 The '``llvm.experimental.constrained.round``' intrinsic returns the first
25083 operand rounded to the nearest integer.
25088 The first argument and the return value are floating-point numbers of the same
25091 The second argument specifies the exception behavior as described above.
25096 This function returns the same values as the libm ``round`` functions
25097 would and handles error conditions in the same way.
25100 '``llvm.experimental.constrained.roundeven``' Intrinsic
25101 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25109 @llvm.experimental.constrained.roundeven(<type> <op1>,
25110 metadata <exception behavior>)
25115 The '``llvm.experimental.constrained.roundeven``' intrinsic returns the first
25116 operand rounded to the nearest integer in floating-point format, rounding
25117 halfway cases to even (that is, to the nearest value that is an even integer),
25118 regardless of the current rounding direction.
25123 The first argument and the return value are floating-point numbers of the same
25126 The second argument specifies the exception behavior as described above.
25131 This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It
25132 also behaves in the same way as C standard function ``roundeven`` and can signal
25133 the invalid operation exception for a SNAN operand.
25136 '``llvm.experimental.constrained.lround``' Intrinsic
25137 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25145 @llvm.experimental.constrained.lround(<fptype> <op1>,
25146 metadata <exception behavior>)
25151 The '``llvm.experimental.constrained.lround``' intrinsic returns the first
25152 operand rounded to the nearest integer with ties away from zero. It will
25153 raise an inexact floating-point exception if the operand is not an integer.
25154 An invalid exception is raised if the result is too large to fit into a
25155 supported integer type, and in this case the result is undefined.
25160 The first argument is a floating-point number. The return value is an
25161 integer type. Not all types are supported on all targets. The supported
25162 types are the same as the ``llvm.lround`` intrinsic and the ``lround``
25165 The second argument specifies the exception behavior as described above.
25170 This function returns the same values as the libm ``lround`` functions
25171 would and handles error conditions in the same way.
25174 '``llvm.experimental.constrained.llround``' Intrinsic
25175 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25183 @llvm.experimental.constrained.llround(<fptype> <op1>,
25184 metadata <exception behavior>)
25189 The '``llvm.experimental.constrained.llround``' intrinsic returns the first
25190 operand rounded to the nearest integer with ties away from zero. It will
25191 raise an inexact floating-point exception if the operand is not an integer.
25192 An invalid exception is raised if the result is too large to fit into a
25193 supported integer type, and in this case the result is undefined.
25198 The first argument is a floating-point number. The return value is an
25199 integer type. Not all types are supported on all targets. The supported
25200 types are the same as the ``llvm.llround`` intrinsic and the ``llround``
25203 The second argument specifies the exception behavior as described above.
25208 This function returns the same values as the libm ``llround`` functions
25209 would and handles error conditions in the same way.
25212 '``llvm.experimental.constrained.trunc``' Intrinsic
25213 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25221 @llvm.experimental.constrained.trunc(<type> <op1>,
25222 metadata <exception behavior>)
25227 The '``llvm.experimental.constrained.trunc``' intrinsic returns the first
25228 operand rounded to the nearest integer not larger in magnitude than the
25234 The first argument and the return value are floating-point numbers of the same
25237 The second argument specifies the exception behavior as described above.
25242 This function returns the same values as the libm ``trunc`` functions
25243 would and handles error conditions in the same way.
25245 .. _int_experimental_noalias_scope_decl:
25247 '``llvm.experimental.noalias.scope.decl``' Intrinsic
25248 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25256 declare void @llvm.experimental.noalias.scope.decl(metadata !id.scope.list)
25261 The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a
25262 noalias scope is declared. When the intrinsic is duplicated, a decision must
25263 also be made about the scope: depending on the reason of the duplication,
25264 the scope might need to be duplicated as well.
25270 The ``!id.scope.list`` argument is metadata that is a list of ``noalias``
25271 metadata references. The format is identical to that required for ``noalias``
25272 metadata. This list must have exactly one element.
25277 The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a
25278 noalias scope is declared. When the intrinsic is duplicated, a decision must
25279 also be made about the scope: depending on the reason of the duplication,
25280 the scope might need to be duplicated as well.
25282 For example, when the intrinsic is used inside a loop body, and that loop is
25283 unrolled, the associated noalias scope must also be duplicated. Otherwise, the
25284 noalias property it signifies would spill across loop iterations, whereas it
25285 was only valid within a single iteration.
25287 .. code-block:: llvm
25289 ; This examples shows two possible positions for noalias.decl and how they impact the semantics:
25290 ; If it is outside the loop (Version 1), then %a and %b are noalias across *all* iterations.
25291 ; If it is inside the loop (Version 2), then %a and %b are noalias only within *one* iteration.
25292 declare void @decl_in_loop(ptr %a.base, ptr %b.base) {
25294 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 1: noalias decl outside loop
25298 %a = phi ptr [ %a.base, %entry ], [ %a.inc, %loop ]
25299 %b = phi ptr [ %b.base, %entry ], [ %b.inc, %loop ]
25300 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 2: noalias decl inside loop
25301 %val = load i8, ptr %a, !alias.scope !2
25302 store i8 %val, ptr %b, !noalias !2
25303 %a.inc = getelementptr inbounds i8, ptr %a, i64 1
25304 %b.inc = getelementptr inbounds i8, ptr %b, i64 1
25305 %cond = call i1 @cond()
25306 br i1 %cond, label %loop, label %exit
25312 !0 = !{!0} ; domain
25313 !1 = !{!1, !0} ; scope
25314 !2 = !{!1} ; scope list
25316 Multiple calls to `@llvm.experimental.noalias.scope.decl` for the same scope
25317 are possible, but one should never dominate another. Violations are pointed out
25318 by the verifier as they indicate a problem in either a transformation pass or
25322 Floating Point Environment Manipulation intrinsics
25323 --------------------------------------------------
25325 These functions read or write floating point environment, such as rounding
25326 mode or state of floating point exceptions. Altering the floating point
25327 environment requires special care. See :ref:`Floating Point Environment <floatenv>`.
25329 '``llvm.get.rounding``' Intrinsic
25330 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25337 declare i32 @llvm.get.rounding()
25342 The '``llvm.get.rounding``' intrinsic reads the current rounding mode.
25347 The '``llvm.get.rounding``' intrinsic returns the current rounding mode.
25348 Encoding of the returned values is same as the result of ``FLT_ROUNDS``,
25349 specified by C standard:
25354 1 - to nearest, ties to even
25355 2 - toward positive infinity
25356 3 - toward negative infinity
25357 4 - to nearest, ties away from zero
25359 Other values may be used to represent additional rounding modes, supported by a
25360 target. These values are target-specific.
25362 '``llvm.set.rounding``' Intrinsic
25363 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25370 declare void @llvm.set.rounding(i32 <val>)
25375 The '``llvm.set.rounding``' intrinsic sets current rounding mode.
25380 The argument is the required rounding mode. Encoding of rounding mode is
25381 the same as used by '``llvm.get.rounding``'.
25386 The '``llvm.set.rounding``' intrinsic sets the current rounding mode. It is
25387 similar to C library function 'fesetround', however this intrinsic does not
25388 return any value and uses platform-independent representation of IEEE rounding
25392 '``llvm.get.fpenv``' Intrinsic
25393 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25400 declare <integer_type> @llvm.get.fpenv()
25405 The '``llvm.get.fpenv``' intrinsic returns bits of the current floating-point
25406 environment. The return value type is platform-specific.
25411 The '``llvm.get.fpenv``' intrinsic reads the current floating-point environment
25412 and returns it as an integer value.
25415 '``llvm.set.fpenv``' Intrinsic
25416 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25423 declare void @llvm.set.fpenv(<integer_type> <val>)
25428 The '``llvm.set.fpenv``' intrinsic sets the current floating-point environment.
25433 The argument is an integer representing the new floating-point environment. The
25434 integer type is platform-specific.
25439 The '``llvm.set.fpenv``' intrinsic sets the current floating-point environment
25440 to the state specified by the argument. The state may be previously obtained by a
25441 call to '``llvm.get.fpenv``' or synthesised in a platform-dependent way.
25444 '``llvm.reset.fpenv``' Intrinsic
25445 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25452 declare void @llvm.reset.fpenv()
25457 The '``llvm.reset.fpenv``' intrinsic sets the default floating-point environment.
25462 The '``llvm.reset.fpenv``' intrinsic sets the current floating-point environment
25463 to default state. It is similar to the call 'fesetenv(FE_DFL_ENV)', except it
25464 does not return any value.
25467 Floating-Point Test Intrinsics
25468 ------------------------------
25470 These functions get properties of floating-point values.
25473 .. _llvm.is.fpclass:
25475 '``llvm.is.fpclass``' Intrinsic
25476 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25483 declare i1 @llvm.is.fpclass(<fptype> <op>, i32 <test>)
25484 declare <N x i1> @llvm.is.fpclass(<vector-fptype> <op>, i32 <test>)
25489 The '``llvm.is.fpclass``' intrinsic returns a boolean value or vector of boolean
25490 values depending on whether the first argument satisfies the test specified by
25491 the second argument.
25493 If the first argument is a floating-point scalar, then the result type is a
25494 boolean (:ref:`i1 <t_integer>`).
25496 If the first argument is a floating-point vector, then the result type is a
25497 vector of boolean with the same number of elements as the first argument.
25502 The first argument to the '``llvm.is.fpclass``' intrinsic must be
25503 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
25504 of floating-point values.
25506 The second argument specifies, which tests to perform. It must be a compile-time
25507 integer constant, each bit in which specifies floating-point class:
25509 +-------+----------------------+
25510 | Bit # | floating-point class |
25511 +=======+======================+
25512 | 0 | Signaling NaN |
25513 +-------+----------------------+
25515 +-------+----------------------+
25516 | 2 | Negative infinity |
25517 +-------+----------------------+
25518 | 3 | Negative normal |
25519 +-------+----------------------+
25520 | 4 | Negative subnormal |
25521 +-------+----------------------+
25522 | 5 | Negative zero |
25523 +-------+----------------------+
25524 | 6 | Positive zero |
25525 +-------+----------------------+
25526 | 7 | Positive subnormal |
25527 +-------+----------------------+
25528 | 8 | Positive normal |
25529 +-------+----------------------+
25530 | 9 | Positive infinity |
25531 +-------+----------------------+
25536 The function checks if ``op`` belongs to any of the floating-point classes
25537 specified by ``test``. If ``op`` is a vector, then the check is made element by
25538 element. Each check yields an :ref:`i1 <t_integer>` result, which is ``true``,
25539 if the element value satisfies the specified test. The argument ``test`` is a
25540 bit mask where each bit specifies floating-point class to test. For example, the
25541 value 0x108 makes test for normal value, - bits 3 and 8 in it are set, which
25542 means that the function returns ``true`` if ``op`` is a positive or negative
25543 normal value. The function never raises floating-point exceptions. The
25544 function does not canonicalize its input value and does not depend
25545 on the floating-point environment. If the floating-point environment
25546 has a zeroing treatment of subnormal input values (such as indicated
25547 by the ``"denormal-fp-math"`` attribute), a subnormal value will be
25548 observed (will not be implicitly treated as zero).
25554 This class of intrinsics is designed to be generic and has no specific
25557 '``llvm.var.annotation``' Intrinsic
25558 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25565 declare void @llvm.var.annotation(ptr <val>, ptr <str>, ptr <str>, i32 <int>)
25570 The '``llvm.var.annotation``' intrinsic.
25575 The first argument is a pointer to a value, the second is a pointer to a
25576 global string, the third is a pointer to a global string which is the
25577 source file name, and the last argument is the line number.
25582 This intrinsic allows annotation of local variables with arbitrary
25583 strings. This can be useful for special purpose optimizations that want
25584 to look for these annotations. These have no other defined use; they are
25585 ignored by code generation and optimization.
25587 '``llvm.ptr.annotation.*``' Intrinsic
25588 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25593 This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a
25594 pointer to an integer of any width. *NOTE* you must specify an address space for
25595 the pointer. The identifier for the default address space is the integer
25600 declare ptr @llvm.ptr.annotation.p0(ptr <val>, ptr <str>, ptr <str>, i32 <int>)
25601 declare ptr @llvm.ptr.annotation.p1(ptr addrspace(1) <val>, ptr <str>, ptr <str>, i32 <int>)
25606 The '``llvm.ptr.annotation``' intrinsic.
25611 The first argument is a pointer to an integer value of arbitrary bitwidth
25612 (result of some expression), the second is a pointer to a global string, the
25613 third is a pointer to a global string which is the source file name, and the
25614 last argument is the line number. It returns the value of the first argument.
25619 This intrinsic allows annotation of a pointer to an integer with arbitrary
25620 strings. This can be useful for special purpose optimizations that want to look
25621 for these annotations. These have no other defined use; transformations preserve
25622 annotations on a best-effort basis but are allowed to replace the intrinsic with
25623 its first argument without breaking semantics and the intrinsic is completely
25624 dropped during instruction selection.
25626 '``llvm.annotation.*``' Intrinsic
25627 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25632 This is an overloaded intrinsic. You can use '``llvm.annotation``' on
25633 any integer bit width.
25637 declare i8 @llvm.annotation.i8(i8 <val>, ptr <str>, ptr <str>, i32 <int>)
25638 declare i16 @llvm.annotation.i16(i16 <val>, ptr <str>, ptr <str>, i32 <int>)
25639 declare i32 @llvm.annotation.i32(i32 <val>, ptr <str>, ptr <str>, i32 <int>)
25640 declare i64 @llvm.annotation.i64(i64 <val>, ptr <str>, ptr <str>, i32 <int>)
25641 declare i256 @llvm.annotation.i256(i256 <val>, ptr <str>, ptr <str>, i32 <int>)
25646 The '``llvm.annotation``' intrinsic.
25651 The first argument is an integer value (result of some expression), the
25652 second is a pointer to a global string, the third is a pointer to a
25653 global string which is the source file name, and the last argument is
25654 the line number. It returns the value of the first argument.
25659 This intrinsic allows annotations to be put on arbitrary expressions with
25660 arbitrary strings. This can be useful for special purpose optimizations that
25661 want to look for these annotations. These have no other defined use;
25662 transformations preserve annotations on a best-effort basis but are allowed to
25663 replace the intrinsic with its first argument without breaking semantics and the
25664 intrinsic is completely dropped during instruction selection.
25666 '``llvm.codeview.annotation``' Intrinsic
25667 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25672 This annotation emits a label at its program point and an associated
25673 ``S_ANNOTATION`` codeview record with some additional string metadata. This is
25674 used to implement MSVC's ``__annotation`` intrinsic. It is marked
25675 ``noduplicate``, so calls to this intrinsic prevent inlining and should be
25676 considered expensive.
25680 declare void @llvm.codeview.annotation(metadata)
25685 The argument should be an MDTuple containing any number of MDStrings.
25687 '``llvm.trap``' Intrinsic
25688 ^^^^^^^^^^^^^^^^^^^^^^^^^
25695 declare void @llvm.trap() cold noreturn nounwind
25700 The '``llvm.trap``' intrinsic.
25710 This intrinsic is lowered to the target dependent trap instruction. If
25711 the target does not have a trap instruction, this intrinsic will be
25712 lowered to a call of the ``abort()`` function.
25714 '``llvm.debugtrap``' Intrinsic
25715 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25722 declare void @llvm.debugtrap() nounwind
25727 The '``llvm.debugtrap``' intrinsic.
25737 This intrinsic is lowered to code which is intended to cause an
25738 execution trap with the intention of requesting the attention of a
25741 '``llvm.ubsantrap``' Intrinsic
25742 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25749 declare void @llvm.ubsantrap(i8 immarg) cold noreturn nounwind
25754 The '``llvm.ubsantrap``' intrinsic.
25759 An integer describing the kind of failure detected.
25764 This intrinsic is lowered to code which is intended to cause an execution trap,
25765 embedding the argument into encoding of that trap somehow to discriminate
25766 crashes if possible.
25768 Equivalent to ``@llvm.trap`` for targets that do not support this behaviour.
25770 '``llvm.stackprotector``' Intrinsic
25771 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25778 declare void @llvm.stackprotector(ptr <guard>, ptr <slot>)
25783 The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it
25784 onto the stack at ``slot``. The stack slot is adjusted to ensure that it
25785 is placed on the stack before local variables.
25790 The ``llvm.stackprotector`` intrinsic requires two pointer arguments.
25791 The first argument is the value loaded from the stack guard
25792 ``@__stack_chk_guard``. The second variable is an ``alloca`` that has
25793 enough space to hold the value of the guard.
25798 This intrinsic causes the prologue/epilogue inserter to force the position of
25799 the ``AllocaInst`` stack slot to be before local variables on the stack. This is
25800 to ensure that if a local variable on the stack is overwritten, it will destroy
25801 the value of the guard. When the function exits, the guard on the stack is
25802 checked against the original guard by ``llvm.stackprotectorcheck``. If they are
25803 different, then ``llvm.stackprotectorcheck`` causes the program to abort by
25804 calling the ``__stack_chk_fail()`` function.
25806 '``llvm.stackguard``' Intrinsic
25807 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25814 declare ptr @llvm.stackguard()
25819 The ``llvm.stackguard`` intrinsic returns the system stack guard value.
25821 It should not be generated by frontends, since it is only for internal usage.
25822 The reason why we create this intrinsic is that we still support IR form Stack
25823 Protector in FastISel.
25833 On some platforms, the value returned by this intrinsic remains unchanged
25834 between loads in the same thread. On other platforms, it returns the same
25835 global variable value, if any, e.g. ``@__stack_chk_guard``.
25837 Currently some platforms have IR-level customized stack guard loading (e.g.
25838 X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be
25841 '``llvm.objectsize``' Intrinsic
25842 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25849 declare i32 @llvm.objectsize.i32(ptr <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
25850 declare i64 @llvm.objectsize.i64(ptr <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
25855 The ``llvm.objectsize`` intrinsic is designed to provide information to the
25856 optimizer to determine whether a) an operation (like memcpy) will overflow a
25857 buffer that corresponds to an object, or b) that a runtime check for overflow
25858 isn't necessary. An object in this context means an allocation of a specific
25859 class, structure, array, or other object.
25864 The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a
25865 pointer to or into the ``object``. The second argument determines whether
25866 ``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size is
25867 unknown. The third argument controls how ``llvm.objectsize`` acts when ``null``
25868 in address space 0 is used as its pointer argument. If it's ``false``,
25869 ``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if
25870 the ``null`` is in a non-zero address space or if ``true`` is given for the
25871 third argument of ``llvm.objectsize``, we assume its size is unknown. The fourth
25872 argument to ``llvm.objectsize`` determines if the value should be evaluated at
25875 The second, third, and fourth arguments only accept constants.
25880 The ``llvm.objectsize`` intrinsic is lowered to a value representing the size of
25881 the object concerned. If the size cannot be determined, ``llvm.objectsize``
25882 returns ``i32/i64 -1 or 0`` (depending on the ``min`` argument).
25884 '``llvm.expect``' Intrinsic
25885 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
25890 This is an overloaded intrinsic. You can use ``llvm.expect`` on any
25895 declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>)
25896 declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
25897 declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
25902 The ``llvm.expect`` intrinsic provides information about expected (the
25903 most probable) value of ``val``, which can be used by optimizers.
25908 The ``llvm.expect`` intrinsic takes two arguments. The first argument is
25909 a value. The second argument is an expected value.
25914 This intrinsic is lowered to the ``val``.
25916 '``llvm.expect.with.probability``' Intrinsic
25917 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25922 This intrinsic is similar to ``llvm.expect``. This is an overloaded intrinsic.
25923 You can use ``llvm.expect.with.probability`` on any integer bit width.
25927 declare i1 @llvm.expect.with.probability.i1(i1 <val>, i1 <expected_val>, double <prob>)
25928 declare i32 @llvm.expect.with.probability.i32(i32 <val>, i32 <expected_val>, double <prob>)
25929 declare i64 @llvm.expect.with.probability.i64(i64 <val>, i64 <expected_val>, double <prob>)
25934 The ``llvm.expect.with.probability`` intrinsic provides information about
25935 expected value of ``val`` with probability(or confidence) ``prob``, which can
25936 be used by optimizers.
25941 The ``llvm.expect.with.probability`` intrinsic takes three arguments. The first
25942 argument is a value. The second argument is an expected value. The third
25943 argument is a probability.
25948 This intrinsic is lowered to the ``val``.
25952 '``llvm.assume``' Intrinsic
25953 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25960 declare void @llvm.assume(i1 %cond)
25965 The ``llvm.assume`` allows the optimizer to assume that the provided
25966 condition is true. This information can then be used in simplifying other parts
25969 More complex assumptions can be encoded as
25970 :ref:`assume operand bundles <assume_opbundles>`.
25975 The argument of the call is the condition which the optimizer may assume is
25981 The intrinsic allows the optimizer to assume that the provided condition is
25982 always true whenever the control flow reaches the intrinsic call. No code is
25983 generated for this intrinsic, and instructions that contribute only to the
25984 provided condition are not used for code generation. If the condition is
25985 violated during execution, the behavior is undefined.
25987 Note that the optimizer might limit the transformations performed on values
25988 used by the ``llvm.assume`` intrinsic in order to preserve the instructions
25989 only used to form the intrinsic's input argument. This might prove undesirable
25990 if the extra information provided by the ``llvm.assume`` intrinsic does not cause
25991 sufficient overall improvement in code quality. For this reason,
25992 ``llvm.assume`` should not be used to document basic mathematical invariants
25993 that the optimizer can otherwise deduce or facts that are of little use to the
25998 '``llvm.ssa.copy``' Intrinsic
25999 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26006 declare type @llvm.ssa.copy(type returned %operand) memory(none)
26011 The first argument is an operand which is used as the returned value.
26016 The ``llvm.ssa.copy`` intrinsic can be used to attach information to
26017 operations by copying them and giving them new names. For example,
26018 the PredicateInfo utility uses it to build Extended SSA form, and
26019 attach various forms of information to operands that dominate specific
26020 uses. It is not meant for general use, only for building temporary
26021 renaming forms that require value splits at certain points.
26025 '``llvm.type.test``' Intrinsic
26026 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26033 declare i1 @llvm.type.test(ptr %ptr, metadata %type) nounwind memory(none)
26039 The first argument is a pointer to be tested. The second argument is a
26040 metadata object representing a :doc:`type identifier <TypeMetadata>`.
26045 The ``llvm.type.test`` intrinsic tests whether the given pointer is associated
26046 with the given type identifier.
26048 .. _type.checked.load:
26050 '``llvm.type.checked.load``' Intrinsic
26051 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26058 declare {ptr, i1} @llvm.type.checked.load(ptr %ptr, i32 %offset, metadata %type) nounwind memory(argmem: read)
26064 The first argument is a pointer from which to load a function pointer. The
26065 second argument is the byte offset from which to load the function pointer. The
26066 third argument is a metadata object representing a :doc:`type identifier
26072 The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a
26073 virtual table pointer using type metadata. This intrinsic is used to implement
26074 control flow integrity in conjunction with virtual call optimization. The
26075 virtual call optimization pass will optimize away ``llvm.type.checked.load``
26076 intrinsics associated with devirtualized calls, thereby removing the type
26077 check in cases where it is not needed to enforce the control flow integrity
26080 If the given pointer is associated with a type metadata identifier, this
26081 function returns true as the second element of its return value. (Note that
26082 the function may also return true if the given pointer is not associated
26083 with a type metadata identifier.) If the function's return value's second
26084 element is true, the following rules apply to the first element:
26086 - If the given pointer is associated with the given type metadata identifier,
26087 it is the function pointer loaded from the given byte offset from the given
26090 - If the given pointer is not associated with the given type metadata
26091 identifier, it is one of the following (the choice of which is unspecified):
26093 1. The function pointer that would have been loaded from an arbitrarily chosen
26094 (through an unspecified mechanism) pointer associated with the type
26097 2. If the function has a non-void return type, a pointer to a function that
26098 returns an unspecified value without causing side effects.
26100 If the function's return value's second element is false, the value of the
26101 first element is undefined.
26104 '``llvm.arithmetic.fence``' Intrinsic
26105 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26113 @llvm.arithmetic.fence(<type> <op>)
26118 The purpose of the ``llvm.arithmetic.fence`` intrinsic
26119 is to prevent the optimizer from performing fast-math optimizations,
26120 particularly reassociation,
26121 between the argument and the expression that contains the argument.
26122 It can be used to preserve the parentheses in the source language.
26127 The ``llvm.arithmetic.fence`` intrinsic takes only one argument.
26128 The argument and the return value are floating-point numbers,
26129 or vector floating-point numbers, of the same type.
26134 This intrinsic returns the value of its operand. The optimizer can optimize
26135 the argument, but the optimizer cannot hoist any component of the operand
26136 to the containing context, and the optimizer cannot move the calculation of
26137 any expression in the containing context into the operand.
26140 '``llvm.donothing``' Intrinsic
26141 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26148 declare void @llvm.donothing() nounwind memory(none)
26153 The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only
26154 three intrinsics (besides ``llvm.experimental.patchpoint`` and
26155 ``llvm.experimental.gc.statepoint``) that can be called with an invoke
26166 This intrinsic does nothing, and it's removed by optimizers and ignored
26169 '``llvm.experimental.deoptimize``' Intrinsic
26170 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26177 declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ]
26182 This intrinsic, together with :ref:`deoptimization operand bundles
26183 <deopt_opbundles>`, allow frontends to express transfer of control and
26184 frame-local state from the currently executing (typically more specialized,
26185 hence faster) version of a function into another (typically more generic, hence
26188 In languages with a fully integrated managed runtime like Java and JavaScript
26189 this intrinsic can be used to implement "uncommon trap" or "side exit" like
26190 functionality. In unmanaged languages like C and C++, this intrinsic can be
26191 used to represent the slow paths of specialized functions.
26197 The intrinsic takes an arbitrary number of arguments, whose meaning is
26198 decided by the :ref:`lowering strategy<deoptimize_lowering>`.
26203 The ``@llvm.experimental.deoptimize`` intrinsic executes an attached
26204 deoptimization continuation (denoted using a :ref:`deoptimization
26205 operand bundle <deopt_opbundles>`) and returns the value returned by
26206 the deoptimization continuation. Defining the semantic properties of
26207 the continuation itself is out of scope of the language reference --
26208 as far as LLVM is concerned, the deoptimization continuation can
26209 invoke arbitrary side effects, including reading from and writing to
26212 Deoptimization continuations expressed using ``"deopt"`` operand bundles always
26213 continue execution to the end of the physical frame containing them, so all
26214 calls to ``@llvm.experimental.deoptimize`` must be in "tail position":
26216 - ``@llvm.experimental.deoptimize`` cannot be invoked.
26217 - The call must immediately precede a :ref:`ret <i_ret>` instruction.
26218 - The ``ret`` instruction must return the value produced by the
26219 ``@llvm.experimental.deoptimize`` call if there is one, or void.
26221 Note that the above restrictions imply that the return type for a call to
26222 ``@llvm.experimental.deoptimize`` will match the return type of its immediate
26225 The inliner composes the ``"deopt"`` continuations of the caller into the
26226 ``"deopt"`` continuations present in the inlinee, and also updates calls to this
26227 intrinsic to return directly from the frame of the function it inlined into.
26229 All declarations of ``@llvm.experimental.deoptimize`` must share the
26230 same calling convention.
26232 .. _deoptimize_lowering:
26237 Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the
26238 symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to
26239 ensure that this symbol is defined). The call arguments to
26240 ``@llvm.experimental.deoptimize`` are lowered as if they were formal
26241 arguments of the specified types, and not as varargs.
26244 '``llvm.experimental.guard``' Intrinsic
26245 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26252 declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ]
26257 This intrinsic, together with :ref:`deoptimization operand bundles
26258 <deopt_opbundles>`, allows frontends to express guards or checks on
26259 optimistic assumptions made during compilation. The semantics of
26260 ``@llvm.experimental.guard`` is defined in terms of
26261 ``@llvm.experimental.deoptimize`` -- its body is defined to be
26264 .. code-block:: text
26266 define void @llvm.experimental.guard(i1 %pred, <args...>) {
26267 %realPred = and i1 %pred, undef
26268 br i1 %realPred, label %continue, label %leave [, !make.implicit !{}]
26271 call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ]
26279 with the optional ``[, !make.implicit !{}]`` present if and only if it
26280 is present on the call site. For more details on ``!make.implicit``,
26281 see :doc:`FaultMaps`.
26283 In words, ``@llvm.experimental.guard`` executes the attached
26284 ``"deopt"`` continuation if (but **not** only if) its first argument
26285 is ``false``. Since the optimizer is allowed to replace the ``undef``
26286 with an arbitrary value, it can optimize guard to fail "spuriously",
26287 i.e. without the original condition being false (hence the "not only
26288 if"); and this allows for "check widening" type optimizations.
26290 ``@llvm.experimental.guard`` cannot be invoked.
26292 After ``@llvm.experimental.guard`` was first added, a more general
26293 formulation was found in ``@llvm.experimental.widenable.condition``.
26294 Support for ``@llvm.experimental.guard`` is slowly being rephrased in
26295 terms of this alternate.
26297 '``llvm.experimental.widenable.condition``' Intrinsic
26298 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26305 declare i1 @llvm.experimental.widenable.condition()
26310 This intrinsic represents a "widenable condition" which is
26311 boolean expressions with the following property: whether this
26312 expression is `true` or `false`, the program is correct and
26315 Together with :ref:`deoptimization operand bundles <deopt_opbundles>`,
26316 ``@llvm.experimental.widenable.condition`` allows frontends to
26317 express guards or checks on optimistic assumptions made during
26318 compilation and represent them as branch instructions on special
26321 While this may appear similar in semantics to `undef`, it is very
26322 different in that an invocation produces a particular, singular
26323 value. It is also intended to be lowered late, and remain available
26324 for specific optimizations and transforms that can benefit from its
26325 special properties.
26335 The intrinsic ``@llvm.experimental.widenable.condition()``
26336 returns either `true` or `false`. For each evaluation of a call
26337 to this intrinsic, the program must be valid and correct both if
26338 it returns `true` and if it returns `false`. This allows
26339 transformation passes to replace evaluations of this intrinsic
26340 with either value whenever one is beneficial.
26342 When used in a branch condition, it allows us to choose between
26343 two alternative correct solutions for the same problem, like
26346 .. code-block:: text
26348 %cond = call i1 @llvm.experimental.widenable.condition()
26349 br i1 %cond, label %solution_1, label %solution_2
26352 ; Apply memory-consuming but fast solution for a task.
26355 ; Cheap in memory but slow solution.
26357 Whether the result of intrinsic's call is `true` or `false`,
26358 it should be correct to pick either solution. We can switch
26359 between them by replacing the result of
26360 ``@llvm.experimental.widenable.condition`` with different
26363 This is how it can be used to represent guards as widenable branches:
26365 .. code-block:: text
26368 ; Unguarded instructions
26369 call void @llvm.experimental.guard(i1 %cond, <args...>) ["deopt"(<deopt_args...>)]
26370 ; Guarded instructions
26372 Can be expressed in an alternative equivalent form of explicit branch using
26373 ``@llvm.experimental.widenable.condition``:
26375 .. code-block:: text
26378 ; Unguarded instructions
26379 %widenable_condition = call i1 @llvm.experimental.widenable.condition()
26380 %guard_condition = and i1 %cond, %widenable_condition
26381 br i1 %guard_condition, label %guarded, label %deopt
26384 ; Guarded instructions
26387 call type @llvm.experimental.deoptimize(<args...>) [ "deopt"(<deopt_args...>) ]
26389 So the block `guarded` is only reachable when `%cond` is `true`,
26390 and it should be valid to go to the block `deopt` whenever `%cond`
26391 is `true` or `false`.
26393 ``@llvm.experimental.widenable.condition`` will never throw, thus
26394 it cannot be invoked.
26399 When ``@llvm.experimental.widenable.condition()`` is used in
26400 condition of a guard represented as explicit branch, it is
26401 legal to widen the guard's condition with any additional
26404 Guard widening looks like replacement of
26406 .. code-block:: text
26408 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
26409 %guard_cond = and i1 %cond, %widenable_cond
26410 br i1 %guard_cond, label %guarded, label %deopt
26414 .. code-block:: text
26416 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
26417 %new_cond = and i1 %any_other_cond, %widenable_cond
26418 %new_guard_cond = and i1 %cond, %new_cond
26419 br i1 %new_guard_cond, label %guarded, label %deopt
26421 for this branch. Here `%any_other_cond` is an arbitrarily chosen
26422 well-defined `i1` value. By making guard widening, we may
26423 impose stricter conditions on `guarded` block and bail to the
26424 deopt when the new condition is not met.
26429 Default lowering strategy is replacing the result of
26430 call of ``@llvm.experimental.widenable.condition`` with
26431 constant `true`. However it is always correct to replace
26432 it with any other `i1` value. Any pass can
26433 freely do it if it can benefit from non-default lowering.
26436 '``llvm.load.relative``' Intrinsic
26437 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26444 declare ptr @llvm.load.relative.iN(ptr %ptr, iN %offset) nounwind memory(argmem: read)
26449 This intrinsic loads a 32-bit value from the address ``%ptr + %offset``,
26450 adds ``%ptr`` to that value and returns it. The constant folder specifically
26451 recognizes the form of this intrinsic and the constant initializers it may
26452 load from; if a loaded constant initializer is known to have the form
26453 ``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``.
26455 LLVM provides that the calculation of such a constant initializer will
26456 not overflow at link time under the medium code model if ``x`` is an
26457 ``unnamed_addr`` function. However, it does not provide this guarantee for
26458 a constant initializer folded into a function body. This intrinsic can be
26459 used to avoid the possibility of overflows when loading from such a constant.
26461 .. _llvm_sideeffect:
26463 '``llvm.sideeffect``' Intrinsic
26464 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26471 declare void @llvm.sideeffect() inaccessiblememonly nounwind willreturn
26476 The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers
26477 treat it as having side effects, so it can be inserted into a loop to
26478 indicate that the loop shouldn't be assumed to terminate (which could
26479 potentially lead to the loop being optimized away entirely), even if it's
26480 an infinite loop with no other side effects.
26490 This intrinsic actually does nothing, but optimizers must assume that it
26491 has externally observable side effects.
26493 '``llvm.is.constant.*``' Intrinsic
26494 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26499 This is an overloaded intrinsic. You can use llvm.is.constant with any argument type.
26503 declare i1 @llvm.is.constant.i32(i32 %operand) nounwind memory(none)
26504 declare i1 @llvm.is.constant.f32(float %operand) nounwind memory(none)
26505 declare i1 @llvm.is.constant.TYPENAME(TYPE %operand) nounwind memory(none)
26510 The '``llvm.is.constant``' intrinsic will return true if the argument
26511 is known to be a manifest compile-time constant. It is guaranteed to
26512 fold to either true or false before generating machine code.
26517 This intrinsic generates no code. If its argument is known to be a
26518 manifest compile-time constant value, then the intrinsic will be
26519 converted to a constant true value. Otherwise, it will be converted to
26520 a constant false value.
26522 In particular, note that if the argument is a constant expression
26523 which refers to a global (the address of which _is_ a constant, but
26524 not manifest during the compile), then the intrinsic evaluates to
26527 The result also intentionally depends on the result of optimization
26528 passes -- e.g., the result can change depending on whether a
26529 function gets inlined or not. A function's parameters are
26530 obviously not constant. However, a call like
26531 ``llvm.is.constant.i32(i32 %param)`` *can* return true after the
26532 function is inlined, if the value passed to the function parameter was
26535 On the other hand, if constant folding is not run, it will never
26536 evaluate to true, even in simple cases.
26540 '``llvm.ptrmask``' Intrinsic
26541 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26548 declare ptrty llvm.ptrmask(ptrty %ptr, intty %mask) speculatable memory(none)
26553 The first argument is a pointer. The second argument is an integer.
26558 The ``llvm.ptrmask`` intrinsic masks out bits of the pointer according to a mask.
26559 This allows stripping data from tagged pointers without converting them to an
26560 integer (ptrtoint/inttoptr). As a consequence, we can preserve more information
26561 to facilitate alias analysis and underlying-object detection.
26566 The result of ``ptrmask(ptr, mask)`` is equivalent to
26567 ``getelementptr ptr, (ptrtoint(ptr) & mask) - ptrtoint(ptr)``. Both the returned
26568 pointer and the first argument are based on the same underlying object (for more
26569 information on the *based on* terminology see
26570 :ref:`the pointer aliasing rules <pointeraliasing>`). If the bitwidth of the
26571 mask argument does not match the pointer size of the target, the mask is
26572 zero-extended or truncated accordingly.
26574 .. _int_threadlocal_address:
26576 '``llvm.threadlocal.address``' Intrinsic
26577 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26584 declare ptr @llvm.threadlocal.address(ptr) nounwind willreturn memory(none)
26589 The first argument is a pointer, which refers to a thread local global.
26594 The address of a thread local global is not a constant, since it depends on
26595 the calling thread. The `llvm.threadlocal.address` intrinsic returns the
26596 address of the given thread local global in the calling thread.
26600 '``llvm.vscale``' Intrinsic
26601 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
26608 declare i32 llvm.vscale.i32()
26609 declare i64 llvm.vscale.i64()
26614 The ``llvm.vscale`` intrinsic returns the value for ``vscale`` in scalable
26615 vectors such as ``<vscale x 16 x i8>``.
26620 ``vscale`` is a positive value that is constant throughout program
26621 execution, but is unknown at compile time.
26622 If the result value does not fit in the result type, then the result is
26623 a :ref:`poison value <poisonvalues>`.
26626 Stack Map Intrinsics
26627 --------------------
26629 LLVM provides experimental intrinsics to support runtime patching
26630 mechanisms commonly desired in dynamic language JITs. These intrinsics
26631 are described in :doc:`StackMaps`.
26633 Element Wise Atomic Memory Intrinsics
26634 -------------------------------------
26636 These intrinsics are similar to the standard library memory intrinsics except
26637 that they perform memory transfer as a sequence of atomic memory accesses.
26639 .. _int_memcpy_element_unordered_atomic:
26641 '``llvm.memcpy.element.unordered.atomic``' Intrinsic
26642 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26647 This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on
26648 any integer bit width and for different address spaces. Not all targets
26649 support all bit widths however.
26653 declare void @llvm.memcpy.element.unordered.atomic.p0.p0.i32(ptr <dest>,
26656 i32 <element_size>)
26657 declare void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr <dest>,
26660 i32 <element_size>)
26665 The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the
26666 '``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated
26667 as arrays with elements that are exactly ``element_size`` bytes, and the copy between
26668 buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations
26669 that are a positive integer multiple of the ``element_size`` in size.
26674 The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>`
26675 intrinsic, with the added constraint that ``len`` is required to be a positive integer
26676 multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
26677 ``element_size``, then the behaviour of the intrinsic is undefined.
26679 ``element_size`` must be a compile-time constant positive power of two no greater than
26680 target-specific atomic access size limit.
26682 For each of the input pointers ``align`` parameter attribute must be specified. It
26683 must be a power of two no less than the ``element_size``. Caller guarantees that
26684 both the source and destination pointers are aligned to that boundary.
26689 The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of
26690 memory from the source location to the destination location. These locations are not
26691 allowed to overlap. The memory copy is performed as a sequence of load/store operations
26692 where each access is guaranteed to be a multiple of ``element_size`` bytes wide and
26693 aligned at an ``element_size`` boundary.
26695 The order of the copy is unspecified. The same value may be read from the source
26696 buffer many times, but only one write is issued to the destination buffer per
26697 element. It is well defined to have concurrent reads and writes to both source and
26698 destination provided those reads and writes are unordered atomic when specified.
26700 This intrinsic does not provide any additional ordering guarantees over those
26701 provided by a set of unordered loads from the source location and stores to the
26707 In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is
26708 lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*'
26709 is replaced with an actual element size. See :ref:`RewriteStatepointsForGC intrinsic
26710 lowering <RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific
26713 Optimizer is allowed to inline memory copy when it's profitable to do so.
26715 '``llvm.memmove.element.unordered.atomic``' Intrinsic
26716 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26721 This is an overloaded intrinsic. You can use
26722 ``llvm.memmove.element.unordered.atomic`` on any integer bit width and for
26723 different address spaces. Not all targets support all bit widths however.
26727 declare void @llvm.memmove.element.unordered.atomic.p0.p0.i32(ptr <dest>,
26730 i32 <element_size>)
26731 declare void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr <dest>,
26734 i32 <element_size>)
26739 The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization
26740 of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and
26741 ``src`` are treated as arrays with elements that are exactly ``element_size``
26742 bytes, and the copy between buffers uses a sequence of
26743 :ref:`unordered atomic <ordering>` load/store operations that are a positive
26744 integer multiple of the ``element_size`` in size.
26749 The first three arguments are the same as they are in the
26750 :ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that
26751 ``len`` is required to be a positive integer multiple of the ``element_size``.
26752 If ``len`` is not a positive integer multiple of ``element_size``, then the
26753 behaviour of the intrinsic is undefined.
26755 ``element_size`` must be a compile-time constant positive power of two no
26756 greater than a target-specific atomic access size limit.
26758 For each of the input pointers the ``align`` parameter attribute must be
26759 specified. It must be a power of two no less than the ``element_size``. Caller
26760 guarantees that both the source and destination pointers are aligned to that
26766 The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes
26767 of memory from the source location to the destination location. These locations
26768 are allowed to overlap. The memory copy is performed as a sequence of load/store
26769 operations where each access is guaranteed to be a multiple of ``element_size``
26770 bytes wide and aligned at an ``element_size`` boundary.
26772 The order of the copy is unspecified. The same value may be read from the source
26773 buffer many times, but only one write is issued to the destination buffer per
26774 element. It is well defined to have concurrent reads and writes to both source
26775 and destination provided those reads and writes are unordered atomic when
26778 This intrinsic does not provide any additional ordering guarantees over those
26779 provided by a set of unordered loads from the source location and stores to the
26785 In the most general case call to the
26786 '``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol
26787 ``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an
26788 actual element size. See :ref:`RewriteStatepointsForGC intrinsic lowering
26789 <RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific
26792 The optimizer is allowed to inline the memory copy when it's profitable to do so.
26794 .. _int_memset_element_unordered_atomic:
26796 '``llvm.memset.element.unordered.atomic``' Intrinsic
26797 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26802 This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on
26803 any integer bit width and for different address spaces. Not all targets
26804 support all bit widths however.
26808 declare void @llvm.memset.element.unordered.atomic.p0.i32(ptr <dest>,
26811 i32 <element_size>)
26812 declare void @llvm.memset.element.unordered.atomic.p0.i64(ptr <dest>,
26815 i32 <element_size>)
26820 The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the
26821 '``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array
26822 with elements that are exactly ``element_size`` bytes, and the assignment to that array
26823 uses uses a sequence of :ref:`unordered atomic <ordering>` store operations
26824 that are a positive integer multiple of the ``element_size`` in size.
26829 The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>`
26830 intrinsic, with the added constraint that ``len`` is required to be a positive integer
26831 multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
26832 ``element_size``, then the behaviour of the intrinsic is undefined.
26834 ``element_size`` must be a compile-time constant positive power of two no greater than
26835 target-specific atomic access size limit.
26837 The ``dest`` input pointer must have the ``align`` parameter attribute specified. It
26838 must be a power of two no less than the ``element_size``. Caller guarantees that
26839 the destination pointer is aligned to that boundary.
26844 The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of
26845 memory starting at the destination location to the given ``value``. The memory is
26846 set with a sequence of store operations where each access is guaranteed to be a
26847 multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary.
26849 The order of the assignment is unspecified. Only one write is issued to the
26850 destination buffer per element. It is well defined to have concurrent reads and
26851 writes to the destination provided those reads and writes are unordered atomic
26854 This intrinsic does not provide any additional ordering guarantees over those
26855 provided by a set of unordered stores to the destination.
26860 In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is
26861 lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*'
26862 is replaced with an actual element size.
26864 The optimizer is allowed to inline the memory assignment when it's profitable to do so.
26866 Objective-C ARC Runtime Intrinsics
26867 ----------------------------------
26869 LLVM provides intrinsics that lower to Objective-C ARC runtime entry points.
26870 LLVM is aware of the semantics of these functions, and optimizes based on that
26871 knowledge. You can read more about the details of Objective-C ARC `here
26872 <https://clang.llvm.org/docs/AutomaticReferenceCounting.html>`_.
26874 '``llvm.objc.autorelease``' Intrinsic
26875 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26881 declare ptr @llvm.objc.autorelease(ptr)
26886 Lowers to a call to `objc_autorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autorelease>`_.
26888 '``llvm.objc.autoreleasePoolPop``' Intrinsic
26889 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26895 declare void @llvm.objc.autoreleasePoolPop(ptr)
26900 Lowers to a call to `objc_autoreleasePoolPop <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpop-void-pool>`_.
26902 '``llvm.objc.autoreleasePoolPush``' Intrinsic
26903 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26909 declare ptr @llvm.objc.autoreleasePoolPush()
26914 Lowers to a call to `objc_autoreleasePoolPush <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpush-void>`_.
26916 '``llvm.objc.autoreleaseReturnValue``' Intrinsic
26917 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26923 declare ptr @llvm.objc.autoreleaseReturnValue(ptr)
26928 Lowers to a call to `objc_autoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue>`_.
26930 '``llvm.objc.copyWeak``' Intrinsic
26931 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26937 declare void @llvm.objc.copyWeak(ptr, ptr)
26942 Lowers to a call to `objc_copyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-copyweak-id-dest-id-src>`_.
26944 '``llvm.objc.destroyWeak``' Intrinsic
26945 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26951 declare void @llvm.objc.destroyWeak(ptr)
26956 Lowers to a call to `objc_destroyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-destroyweak-id-object>`_.
26958 '``llvm.objc.initWeak``' Intrinsic
26959 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26965 declare ptr @llvm.objc.initWeak(ptr, ptr)
26970 Lowers to a call to `objc_initWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-initweak>`_.
26972 '``llvm.objc.loadWeak``' Intrinsic
26973 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26979 declare ptr @llvm.objc.loadWeak(ptr)
26984 Lowers to a call to `objc_loadWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweak>`_.
26986 '``llvm.objc.loadWeakRetained``' Intrinsic
26987 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26993 declare ptr @llvm.objc.loadWeakRetained(ptr)
26998 Lowers to a call to `objc_loadWeakRetained <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweakretained>`_.
27000 '``llvm.objc.moveWeak``' Intrinsic
27001 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27007 declare void @llvm.objc.moveWeak(ptr, ptr)
27012 Lowers to a call to `objc_moveWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-moveweak-id-dest-id-src>`_.
27014 '``llvm.objc.release``' Intrinsic
27015 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27021 declare void @llvm.objc.release(ptr)
27026 Lowers to a call to `objc_release <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-release-id-value>`_.
27028 '``llvm.objc.retain``' Intrinsic
27029 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27035 declare ptr @llvm.objc.retain(ptr)
27040 Lowers to a call to `objc_retain <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>`_.
27042 '``llvm.objc.retainAutorelease``' Intrinsic
27043 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27049 declare ptr @llvm.objc.retainAutorelease(ptr)
27054 Lowers to a call to `objc_retainAutorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautorelease>`_.
27056 '``llvm.objc.retainAutoreleaseReturnValue``' Intrinsic
27057 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27063 declare ptr @llvm.objc.retainAutoreleaseReturnValue(ptr)
27068 Lowers to a call to `objc_retainAutoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasereturnvalue>`_.
27070 '``llvm.objc.retainAutoreleasedReturnValue``' Intrinsic
27071 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27077 declare ptr @llvm.objc.retainAutoreleasedReturnValue(ptr)
27082 Lowers to a call to `objc_retainAutoreleasedReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasedreturnvalue>`_.
27084 '``llvm.objc.retainBlock``' Intrinsic
27085 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27091 declare ptr @llvm.objc.retainBlock(ptr)
27096 Lowers to a call to `objc_retainBlock <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainblock>`_.
27098 '``llvm.objc.storeStrong``' Intrinsic
27099 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27105 declare void @llvm.objc.storeStrong(ptr, ptr)
27110 Lowers to a call to `objc_storeStrong <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-storestrong-id-object-id-value>`_.
27112 '``llvm.objc.storeWeak``' Intrinsic
27113 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27119 declare ptr @llvm.objc.storeWeak(ptr, ptr)
27124 Lowers to a call to `objc_storeWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-storeweak>`_.
27126 Preserving Debug Information Intrinsics
27127 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27129 These intrinsics are used to carry certain debuginfo together with
27130 IR-level operations. For example, it may be desirable to
27131 know the structure/union name and the original user-level field
27132 indices. Such information got lost in IR GetElementPtr instruction
27133 since the IR types are different from debugInfo types and unions
27134 are converted to structs in IR.
27136 '``llvm.preserve.array.access.index``' Intrinsic
27137 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27144 @llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons(<type> base,
27151 The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address
27152 based on array base ``base``, array dimension ``dim`` and the last access index ``index``
27153 into the array. The return type ``ret_type`` is a pointer type to the array element.
27154 The array ``dim`` and ``index`` are preserved which is more robust than
27155 getelementptr instruction which may be subject to compiler transformation.
27156 The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
27157 to provide array or pointer debuginfo type.
27158 The metadata is a ``DICompositeType`` or ``DIDerivedType`` representing the
27159 debuginfo version of ``type``.
27164 The ``base`` is the array base address. The ``dim`` is the array dimension.
27165 The ``base`` is a pointer if ``dim`` equals 0.
27166 The ``index`` is the last access index into the array or pointer.
27168 The ``base`` argument must be annotated with an :ref:`elementtype
27169 <attr_elementtype>` attribute at the call-site. This attribute specifies the
27170 getelementptr element type.
27175 The '``llvm.preserve.array.access.index``' intrinsic produces the same result
27176 as a getelementptr with base ``base`` and access operands ``{dim's 0's, index}``.
27178 '``llvm.preserve.union.access.index``' Intrinsic
27179 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27186 @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(<type> base,
27192 The '``llvm.preserve.union.access.index``' intrinsic carries the debuginfo field index
27193 ``di_index`` and returns the ``base`` address.
27194 The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
27195 to provide union debuginfo type.
27196 The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
27197 The return type ``type`` is the same as the ``base`` type.
27202 The ``base`` is the union base address. The ``di_index`` is the field index in debuginfo.
27207 The '``llvm.preserve.union.access.index``' intrinsic returns the ``base`` address.
27209 '``llvm.preserve.struct.access.index``' Intrinsic
27210 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27217 @llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s(<type> base,
27224 The '``llvm.preserve.struct.access.index``' intrinsic returns the getelementptr address
27225 based on struct base ``base`` and IR struct member index ``gep_index``.
27226 The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
27227 to provide struct debuginfo type.
27228 The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
27229 The return type ``ret_type`` is a pointer type to the structure member.
27234 The ``base`` is the structure base address. The ``gep_index`` is the struct member index
27235 based on IR structures. The ``di_index`` is the struct member index based on debuginfo.
27237 The ``base`` argument must be annotated with an :ref:`elementtype
27238 <attr_elementtype>` attribute at the call-site. This attribute specifies the
27239 getelementptr element type.
27244 The '``llvm.preserve.struct.access.index``' intrinsic produces the same result
27245 as a getelementptr with base ``base`` and access operands ``{0, gep_index}``.
27247 '``llvm.fptrunc.round``' Intrinsic
27248 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27256 @llvm.fptrunc.round(<type> <value>, metadata <rounding mode>)
27261 The '``llvm.fptrunc.round``' intrinsic truncates
27262 :ref:`floating-point <t_floating>` ``value`` to type ``ty2``
27263 with a specified rounding mode.
27268 The '``llvm.fptrunc.round``' intrinsic takes a :ref:`floating-point
27269 <t_floating>` value to cast and a :ref:`floating-point <t_floating>` type
27270 to cast it to. This argument must be larger in size than the result.
27272 The second argument specifies the rounding mode as described in the constrained
27273 intrinsics section.
27274 For this intrinsic, the "round.dynamic" mode is not supported.
27279 The '``llvm.fptrunc.round``' intrinsic casts a ``value`` from a larger
27280 :ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
27281 <t_floating>` type.
27282 This intrinsic is assumed to execute in the default :ref:`floating-point
27283 environment <floatenv>` *except* for the rounding mode.
27284 This intrinsic is not supported on all targets. Some targets may not support
27285 all rounding modes.