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 Globals cannot be or contain :ref:`Scalable vectors <t_vector>` because their
746 size is unknown at compile time. They are allowed in structs to facilitate
747 intrinsics returning multiple values. Generally, structs containing scalable
748 vectors are not considered "sized" and cannot be used in loads, stores, allocas,
749 or GEPs. The only exception to this rule is for structs that contain scalable
750 vectors of the same type (e.g. ``{<vscale x 2 x i32>, <vscale x 2 x i32>}``
751 contains the same type while ``{<vscale x 2 x i32>, <vscale x 2 x i64>}``
752 doesn't). These kinds of structs (we may call them homogeneous scalable vector
753 structs) are considered sized and can be used in loads, stores, allocas, but
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 .. _attr_convergent:
1758 This attribute indicates that this function is convergent.
1759 When it appears on a call/invoke, the convergent attribute
1760 indicates that we should treat the call as though we’re calling a
1761 convergent function. This is particularly useful on indirect
1762 calls; without this we may treat such calls as though the target
1765 See :doc:`ConvergentOperations` for further details.
1767 It is an error to call :ref:`llvm.experimental.convergence.entry
1768 <llvm.experimental.convergence.entry>` from a function that
1769 does not have this attribute.
1770 ``disable_sanitizer_instrumentation``
1771 When instrumenting code with sanitizers, it can be important to skip certain
1772 functions to ensure no instrumentation is applied to them.
1774 This attribute is not always similar to absent ``sanitize_<name>``
1775 attributes: depending on the specific sanitizer, code can be inserted into
1776 functions regardless of the ``sanitize_<name>`` attribute to prevent false
1779 ``disable_sanitizer_instrumentation`` disables all kinds of instrumentation,
1780 taking precedence over the ``sanitize_<name>`` attributes and other compiler
1782 ``"dontcall-error"``
1783 This attribute denotes that an error diagnostic should be emitted when a
1784 call of a function with this attribute is not eliminated via optimization.
1785 Front ends can provide optional ``srcloc`` metadata nodes on call sites of
1786 such callees to attach information about where in the source language such a
1787 call came from. A string value can be provided as a note.
1789 This attribute denotes that a warning diagnostic should be emitted when a
1790 call of a function with this attribute is not eliminated via optimization.
1791 Front ends can provide optional ``srcloc`` metadata nodes on call sites of
1792 such callees to attach information about where in the source language such a
1793 call came from. A string value can be provided as a note.
1794 ``fn_ret_thunk_extern``
1795 This attribute tells the code generator that returns from functions should
1796 be replaced with jumps to externally-defined architecture-specific symbols.
1797 For X86, this symbol's identifier is ``__x86_return_thunk``.
1799 This attribute tells the code generator whether the function
1800 should keep the frame pointer. The code generator may emit the frame pointer
1801 even if this attribute says the frame pointer can be eliminated.
1802 The allowed string values are:
1804 * ``"none"`` (default) - the frame pointer can be eliminated.
1805 * ``"non-leaf"`` - the frame pointer should be kept if the function calls
1807 * ``"all"`` - the frame pointer should be kept.
1809 This attribute indicates that this function is a hot spot of the program
1810 execution. The function will be optimized more aggressively and will be
1811 placed into special subsection of the text section to improving locality.
1813 When profile feedback is enabled, this attribute has the precedence over
1814 the profile information. By marking a function ``hot``, users can work
1815 around the cases where the training input does not have good coverage
1816 on all the hot functions.
1818 This attribute indicates that the source code contained a hint that
1819 inlining this function is desirable (such as the "inline" keyword in
1820 C/C++). It is just a hint; it imposes no requirements on the
1823 This attribute indicates that the function should be added to a
1824 jump-instruction table at code-generation time, and that all address-taken
1825 references to this function should be replaced with a reference to the
1826 appropriate jump-instruction-table function pointer. Note that this creates
1827 a new pointer for the original function, which means that code that depends
1828 on function-pointer identity can break. So, any function annotated with
1829 ``jumptable`` must also be ``unnamed_addr``.
1831 This attribute specifies the possible memory effects of the call-site or
1832 function. It allows specifying the possible access kinds (``none``,
1833 ``read``, ``write``, or ``readwrite``) for the possible memory location
1834 kinds (``argmem``, ``inaccessiblemem``, as well as a default). It is best
1835 understood by example:
1837 - ``memory(none)``: Does not access any memory.
1838 - ``memory(read)``: May read (but not write) any memory.
1839 - ``memory(write)``: May write (but not read) any memory.
1840 - ``memory(readwrite)``: May read or write any memory.
1841 - ``memory(argmem: read)``: May only read argument memory.
1842 - ``memory(argmem: read, inaccessiblemem: write)``: May only read argument
1843 memory and only write inaccessible memory.
1844 - ``memory(read, argmem: readwrite)``: May read any memory (default mode)
1845 and additionally write argument memory.
1846 - ``memory(readwrite, argmem: none)``: May access any memory apart from
1849 The supported memory location kinds are:
1851 - ``argmem``: This refers to accesses that are based on pointer arguments
1853 - ``inaccessiblemem``: This refers to accesses to memory which is not
1854 accessible by the current module (before return from the function -- an
1855 allocator function may return newly accessible memory while only
1856 accessing inaccessible memory itself). Inaccessible memory is often used
1857 to model control dependencies of intrinsics.
1858 - The default access kind (specified without a location prefix) applies to
1859 all locations that haven't been specified explicitly, including those that
1860 don't currently have a dedicated location kind (e.g. accesses to globals
1861 or captured pointers).
1863 If the ``memory`` attribute is not specified, then ``memory(readwrite)``
1864 is implied (all memory effects are possible).
1866 The memory effects of a call can be computed as
1867 ``CallSiteEffects & (FunctionEffects | OperandBundleEffects)``. Thus, the
1868 call-site annotation takes precedence over the potential effects described
1869 by either the function annotation or the operand bundles.
1871 This attribute suggests that optimization passes and code generator
1872 passes make choices that keep the code size of this function as small
1873 as possible and perform optimizations that may sacrifice runtime
1874 performance in order to minimize the size of the generated code.
1876 This attribute disables prologue / epilogue emission for the
1877 function. This can have very system-specific consequences.
1878 ``"no-inline-line-tables"``
1879 When this attribute is set to true, the inliner discards source locations
1880 when inlining code and instead uses the source location of the call site.
1881 Breakpoints set on code that was inlined into the current function will
1882 not fire during the execution of the inlined call sites. If the debugger
1883 stops inside an inlined call site, it will appear to be stopped at the
1884 outermost inlined call site.
1886 When this attribute is set to true, the jump tables and lookup tables that
1887 can be generated from a switch case lowering are disabled.
1889 This indicates that the callee function at a call site is not recognized as
1890 a built-in function. LLVM will retain the original call and not replace it
1891 with equivalent code based on the semantics of the built-in function, unless
1892 the call site uses the ``builtin`` attribute. This is valid at call sites
1893 and on function declarations and definitions.
1895 This attribute indicates that the function is only allowed to jump back into
1896 caller's module by a return or an exception, and is not allowed to jump back
1897 by invoking a callback function, a direct, possibly transitive, external
1898 function call, use of ``longjmp``, or other means. It is a compiler hint that
1899 is used at module level to improve dataflow analysis, dropped during linking,
1900 and has no effect on functions defined in the current module.
1902 This attribute indicates that calls to the function cannot be
1903 duplicated. A call to a ``noduplicate`` function may be moved
1904 within its parent function, but may not be duplicated within
1905 its parent function.
1907 A function containing a ``noduplicate`` call may still
1908 be an inlining candidate, provided that the call is not
1909 duplicated by inlining. That implies that the function has
1910 internal linkage and only has one call site, so the original
1911 call is dead after inlining.
1913 This function attribute indicates that the function does not, directly or
1914 transitively, call a memory-deallocation function (``free``, for example)
1915 on a memory allocation which existed before the call.
1917 As a result, uncaptured pointers that are known to be dereferenceable
1918 prior to a call to a function with the ``nofree`` attribute are still
1919 known to be dereferenceable after the call. The capturing condition is
1920 necessary in environments where the function might communicate the
1921 pointer to another thread which then deallocates the memory. Alternatively,
1922 ``nosync`` would ensure such communication cannot happen and even captured
1923 pointers cannot be freed by the function.
1925 A ``nofree`` function is explicitly allowed to free memory which it
1926 allocated or (if not ``nosync``) arrange for another thread to free
1927 memory on it's behalf. As a result, perhaps surprisingly, a ``nofree``
1928 function can return a pointer to a previously deallocated memory object.
1930 Disallows implicit floating-point code. This inhibits optimizations that
1931 use floating-point code and floating-point registers for operations that are
1932 not nominally floating-point. LLVM instructions that perform floating-point
1933 operations or require access to floating-point registers may still cause
1934 floating-point code to be generated.
1936 Also inhibits optimizations that create SIMD/vector code and registers from
1937 scalar code such as vectorization or memcpy/memset optimization. This
1938 includes integer vectors. Vector instructions present in IR may still cause
1939 vector code to be generated.
1941 This attribute indicates that the inliner should never inline this
1942 function in any situation. This attribute may not be used together
1943 with the ``alwaysinline`` attribute.
1945 This attribute indicates that calls to this function should never be merged
1946 during optimization. For example, it will prevent tail merging otherwise
1947 identical code sequences that raise an exception or terminate the program.
1948 Tail merging normally reduces the precision of source location information,
1949 making stack traces less useful for debugging. This attribute gives the
1950 user control over the tradeoff between code size and debug information
1953 This attribute suppresses lazy symbol binding for the function. This
1954 may make calls to the function faster, at the cost of extra program
1955 startup time if the function is not called during program startup.
1957 This function attribute prevents instrumentation based profiling, used for
1958 coverage or profile based optimization, from being added to a function. It
1959 also blocks inlining if the caller and callee have different values of this
1962 This function attribute prevents instrumentation based profiling, used for
1963 coverage or profile based optimization, from being added to a function. This
1964 attribute does not restrict inlining, so instrumented instruction could end
1965 up in this function.
1967 This attribute indicates that the code generator should not use a
1968 red zone, even if the target-specific ABI normally permits it.
1969 ``indirect-tls-seg-refs``
1970 This attribute indicates that the code generator should not use
1971 direct TLS access through segment registers, even if the
1972 target-specific ABI normally permits it.
1974 This function attribute indicates that the function never returns
1975 normally, hence through a return instruction. This produces undefined
1976 behavior at runtime if the function ever does dynamically return. Annotated
1977 functions may still raise an exception, i.a., ``nounwind`` is not implied.
1979 This function attribute indicates that the function does not call itself
1980 either directly or indirectly down any possible call path. This produces
1981 undefined behavior at runtime if the function ever does recurse.
1983 .. _langref_willreturn:
1986 This function attribute indicates that a call of this function will
1987 either exhibit undefined behavior or comes back and continues execution
1988 at a point in the existing call stack that includes the current invocation.
1989 Annotated functions may still raise an exception, i.a., ``nounwind`` is not implied.
1990 If an invocation of an annotated function does not return control back
1991 to a point in the call stack, the behavior is undefined.
1993 This function attribute indicates that the function does not communicate
1994 (synchronize) with another thread through memory or other well-defined means.
1995 Synchronization is considered possible in the presence of `atomic` accesses
1996 that enforce an order, thus not "unordered" and "monotonic", `volatile` accesses,
1997 as well as `convergent` function calls.
1999 Note that `convergent` operations can involve communication that is
2000 considered to be not through memory and does not necessarily imply an
2001 ordering between threads for the purposes of the memory model. Therefore,
2002 an operation can be both `convergent` and `nosync`.
2004 If a `nosync` function does ever synchronize with another thread,
2005 the behavior is undefined.
2007 This function attribute indicates that the function never raises an
2008 exception. If the function does raise an exception, its runtime
2009 behavior is undefined. However, functions marked nounwind may still
2010 trap or generate asynchronous exceptions. Exception handling schemes
2011 that are recognized by LLVM to handle asynchronous exceptions, such
2012 as SEH, will still provide their implementation defined semantics.
2013 ``nosanitize_bounds``
2014 This attribute indicates that bounds checking sanitizer instrumentation
2015 is disabled for this function.
2016 ``nosanitize_coverage``
2017 This attribute indicates that SanitizerCoverage instrumentation is disabled
2019 ``null_pointer_is_valid``
2020 If ``null_pointer_is_valid`` is set, then the ``null`` address
2021 in address-space 0 is considered to be a valid address for memory loads and
2022 stores. Any analysis or optimization should not treat dereferencing a
2023 pointer to ``null`` as undefined behavior in this function.
2024 Note: Comparing address of a global variable to ``null`` may still
2025 evaluate to false because of a limitation in querying this attribute inside
2026 constant expressions.
2028 This attribute indicates that this function should be optimized
2029 for maximum fuzzing signal.
2031 This function attribute indicates that most optimization passes will skip
2032 this function, with the exception of interprocedural optimization passes.
2033 Code generation defaults to the "fast" instruction selector.
2034 This attribute cannot be used together with the ``alwaysinline``
2035 attribute; this attribute is also incompatible
2036 with the ``minsize`` attribute and the ``optsize`` attribute.
2038 This attribute requires the ``noinline`` attribute to be specified on
2039 the function as well, so the function is never inlined into any caller.
2040 Only functions with the ``alwaysinline`` attribute are valid
2041 candidates for inlining into the body of this function.
2043 This attribute suggests that optimization passes and code generator
2044 passes make choices that keep the code size of this function low,
2045 and otherwise do optimizations specifically to reduce code size as
2046 long as they do not significantly impact runtime performance.
2047 ``"patchable-function"``
2048 This attribute tells the code generator that the code
2049 generated for this function needs to follow certain conventions that
2050 make it possible for a runtime function to patch over it later.
2051 The exact effect of this attribute depends on its string value,
2052 for which there currently is one legal possibility:
2054 * ``"prologue-short-redirect"`` - This style of patchable
2055 function is intended to support patching a function prologue to
2056 redirect control away from the function in a thread safe
2057 manner. It guarantees that the first instruction of the
2058 function will be large enough to accommodate a short jump
2059 instruction, and will be sufficiently aligned to allow being
2060 fully changed via an atomic compare-and-swap instruction.
2061 While the first requirement can be satisfied by inserting large
2062 enough NOP, LLVM can and will try to re-purpose an existing
2063 instruction (i.e. one that would have to be emitted anyway) as
2064 the patchable instruction larger than a short jump.
2066 ``"prologue-short-redirect"`` is currently only supported on
2069 This attribute by itself does not imply restrictions on
2070 inter-procedural optimizations. All of the semantic effects the
2071 patching may have to be separately conveyed via the linkage type.
2073 This attribute indicates that the function will trigger a guard region
2074 in the end of the stack. It ensures that accesses to the stack must be
2075 no further apart than the size of the guard region to a previous
2076 access of the stack. It takes one required string value, the name of
2077 the stack probing function that will be called.
2079 If a function that has a ``"probe-stack"`` attribute is inlined into
2080 a function with another ``"probe-stack"`` attribute, the resulting
2081 function has the ``"probe-stack"`` attribute of the caller. If a
2082 function that has a ``"probe-stack"`` attribute is inlined into a
2083 function that has no ``"probe-stack"`` attribute at all, the resulting
2084 function has the ``"probe-stack"`` attribute of the callee.
2085 ``"stack-probe-size"``
2086 This attribute controls the behavior of stack probes: either
2087 the ``"probe-stack"`` attribute, or ABI-required stack probes, if any.
2088 It defines the size of the guard region. It ensures that if the function
2089 may use more stack space than the size of the guard region, stack probing
2090 sequence will be emitted. It takes one required integer value, which
2093 If a function that has a ``"stack-probe-size"`` attribute is inlined into
2094 a function with another ``"stack-probe-size"`` attribute, the resulting
2095 function has the ``"stack-probe-size"`` attribute that has the lower
2096 numeric value. If a function that has a ``"stack-probe-size"`` attribute is
2097 inlined into a function that has no ``"stack-probe-size"`` attribute
2098 at all, the resulting function has the ``"stack-probe-size"`` attribute
2100 ``"no-stack-arg-probe"``
2101 This attribute disables ABI-required stack probes, if any.
2103 This attribute indicates that this function can return twice. The C
2104 ``setjmp`` is an example of such a function. The compiler disables
2105 some optimizations (like tail calls) in the caller of these
2108 This attribute indicates that
2109 `SafeStack <https://clang.llvm.org/docs/SafeStack.html>`_
2110 protection is enabled for this function.
2112 If a function that has a ``safestack`` attribute is inlined into a
2113 function that doesn't have a ``safestack`` attribute or which has an
2114 ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting
2115 function will have a ``safestack`` attribute.
2116 ``sanitize_address``
2117 This attribute indicates that AddressSanitizer checks
2118 (dynamic address safety analysis) are enabled for this function.
2120 This attribute indicates that MemorySanitizer checks (dynamic detection
2121 of accesses to uninitialized memory) are enabled for this function.
2123 This attribute indicates that ThreadSanitizer checks
2124 (dynamic thread safety analysis) are enabled for this function.
2125 ``sanitize_hwaddress``
2126 This attribute indicates that HWAddressSanitizer checks
2127 (dynamic address safety analysis based on tagged pointers) are enabled for
2130 This attribute indicates that MemTagSanitizer checks
2131 (dynamic address safety analysis based on Armv8 MTE) are enabled for
2133 ``speculative_load_hardening``
2134 This attribute indicates that
2135 `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_
2136 should be enabled for the function body.
2138 Speculative Load Hardening is a best-effort mitigation against
2139 information leak attacks that make use of control flow
2140 miss-speculation - specifically miss-speculation of whether a branch
2141 is taken or not. Typically vulnerabilities enabling such attacks are
2142 classified as "Spectre variant #1". Notably, this does not attempt to
2143 mitigate against miss-speculation of branch target, classified as
2144 "Spectre variant #2" vulnerabilities.
2146 When inlining, the attribute is sticky. Inlining a function that carries
2147 this attribute will cause the caller to gain the attribute. This is intended
2148 to provide a maximally conservative model where the code in a function
2149 annotated with this attribute will always (even after inlining) end up
2152 This function attribute indicates that the function does not have any
2153 effects besides calculating its result and does not have undefined behavior.
2154 Note that ``speculatable`` is not enough to conclude that along any
2155 particular execution path the number of calls to this function will not be
2156 externally observable. This attribute is only valid on functions
2157 and declarations, not on individual call sites. If a function is
2158 incorrectly marked as speculatable and really does exhibit
2159 undefined behavior, the undefined behavior may be observed even
2160 if the call site is dead code.
2163 This attribute indicates that the function should emit a stack
2164 smashing protector. It is in the form of a "canary" --- a random value
2165 placed on the stack before the local variables that's checked upon
2166 return from the function to see if it has been overwritten. A
2167 heuristic is used to determine if a function needs stack protectors
2168 or not. The heuristic used will enable protectors for functions with:
2170 - Character arrays larger than ``ssp-buffer-size`` (default 8).
2171 - Aggregates containing character arrays larger than ``ssp-buffer-size``.
2172 - Calls to alloca() with variable sizes or constant sizes greater than
2173 ``ssp-buffer-size``.
2175 Variables that are identified as requiring a protector will be arranged
2176 on the stack such that they are adjacent to the stack protector guard.
2178 If a function with an ``ssp`` attribute is inlined into a calling function,
2179 the attribute is not carried over to the calling function.
2182 This attribute indicates that the function should emit a stack smashing
2183 protector. This attribute causes a strong heuristic to be used when
2184 determining if a function needs stack protectors. The strong heuristic
2185 will enable protectors for functions with:
2187 - Arrays of any size and type
2188 - Aggregates containing an array of any size and type.
2189 - Calls to alloca().
2190 - Local variables that have had their address taken.
2192 Variables that are identified as requiring a protector will be arranged
2193 on the stack such that they are adjacent to the stack protector guard.
2194 The specific layout rules are:
2196 #. Large arrays and structures containing large arrays
2197 (``>= ssp-buffer-size``) are closest to the stack protector.
2198 #. Small arrays and structures containing small arrays
2199 (``< ssp-buffer-size``) are 2nd closest to the protector.
2200 #. Variables that have had their address taken are 3rd closest to the
2203 This overrides the ``ssp`` function attribute.
2205 If a function with an ``sspstrong`` attribute is inlined into a calling
2206 function which has an ``ssp`` attribute, the calling function's attribute
2207 will be upgraded to ``sspstrong``.
2210 This attribute indicates that the function should *always* emit a stack
2211 smashing protector. This overrides the ``ssp`` and ``sspstrong`` function
2214 Variables that are identified as requiring a protector will be arranged
2215 on the stack such that they are adjacent to the stack protector guard.
2216 The specific layout rules are:
2218 #. Large arrays and structures containing large arrays
2219 (``>= ssp-buffer-size``) are closest to the stack protector.
2220 #. Small arrays and structures containing small arrays
2221 (``< ssp-buffer-size``) are 2nd closest to the protector.
2222 #. Variables that have had their address taken are 3rd closest to the
2225 If a function with an ``sspreq`` attribute is inlined into a calling
2226 function which has an ``ssp`` or ``sspstrong`` attribute, the calling
2227 function's attribute will be upgraded to ``sspreq``.
2230 This attribute indicates that the function was called from a scope that
2231 requires strict floating-point semantics. LLVM will not attempt any
2232 optimizations that require assumptions about the floating-point rounding
2233 mode or that might alter the state of floating-point status flags that
2234 might otherwise be set or cleared by calling this function. LLVM will
2235 not introduce any new floating-point instructions that may trap.
2237 .. _denormal_fp_math:
2239 ``"denormal-fp-math"``
2240 This indicates the denormal (subnormal) handling that may be
2241 assumed for the default floating-point environment. This is a
2242 comma separated pair. The elements may be one of ``"ieee"``,
2243 ``"preserve-sign"``, ``"positive-zero"``, or ``"dynamic"``. The
2244 first entry indicates the flushing mode for the result of floating
2245 point operations. The second indicates the handling of denormal inputs
2246 to floating point instructions. For compatibility with older
2247 bitcode, if the second value is omitted, both input and output
2248 modes will assume the same mode.
2250 If this is attribute is not specified, the default is ``"ieee,ieee"``.
2252 If the output mode is ``"preserve-sign"``, or ``"positive-zero"``,
2253 denormal outputs may be flushed to zero by standard floating-point
2254 operations. It is not mandated that flushing to zero occurs, but if
2255 a denormal output is flushed to zero, it must respect the sign
2256 mode. Not all targets support all modes.
2258 If the mode is ``"dynamic"``, the behavior is derived from the
2259 dynamic state of the floating-point environment. Transformations
2260 which depend on the behavior of denormal values should not be
2263 While this indicates the expected floating point mode the function
2264 will be executed with, this does not make any attempt to ensure
2265 the mode is consistent. User or platform code is expected to set
2266 the floating point mode appropriately before function entry.
2268 If the input mode is ``"preserve-sign"``, or ``"positive-zero"``,
2269 a floating-point operation must treat any input denormal value as
2270 zero. In some situations, if an instruction does not respect this
2271 mode, the input may need to be converted to 0 as if by
2272 ``@llvm.canonicalize`` during lowering for correctness.
2274 ``"denormal-fp-math-f32"``
2275 Same as ``"denormal-fp-math"``, but only controls the behavior of
2276 the 32-bit float type (or vectors of 32-bit floats). If both are
2277 are present, this overrides ``"denormal-fp-math"``. Not all targets
2278 support separately setting the denormal mode per type, and no
2279 attempt is made to diagnose unsupported uses. Currently this
2280 attribute is respected by the AMDGPU and NVPTX backends.
2283 This attribute indicates that the function will delegate to some other
2284 function with a tail call. The prototype of a thunk should not be used for
2285 optimization purposes. The caller is expected to cast the thunk prototype to
2286 match the thunk target prototype.
2288 ``"tls-load-hoist"``
2289 This attribute indicates that the function will try to reduce redundant
2290 tls address calculation by hoisting tls variable.
2292 ``uwtable[(sync|async)]``
2293 This attribute indicates that the ABI being targeted requires that
2294 an unwind table entry be produced for this function even if we can
2295 show that no exceptions passes by it. This is normally the case for
2296 the ELF x86-64 abi, but it can be disabled for some compilation
2297 units. The optional parameter describes what kind of unwind tables
2298 to generate: ``sync`` for normal unwind tables, ``async`` for asynchronous
2299 (instruction precise) unwind tables. Without the parameter, the attribute
2300 ``uwtable`` is equivalent to ``uwtable(async)``.
2302 This attribute indicates that no control-flow check will be performed on
2303 the attributed entity. It disables -fcf-protection=<> for a specific
2304 entity to fine grain the HW control flow protection mechanism. The flag
2305 is target independent and currently appertains to a function or function
2308 This attribute indicates that the ShadowCallStack checks are enabled for
2309 the function. The instrumentation checks that the return address for the
2310 function has not changed between the function prolog and epilog. It is
2311 currently x86_64-specific.
2313 .. _langref_mustprogress:
2316 This attribute indicates that the function is required to return, unwind,
2317 or interact with the environment in an observable way e.g. via a volatile
2318 memory access, I/O, or other synchronization. The ``mustprogress``
2319 attribute is intended to model the requirements of the first section of
2320 [intro.progress] of the C++ Standard. As a consequence, a loop in a
2321 function with the `mustprogress` attribute can be assumed to terminate if
2322 it does not interact with the environment in an observable way, and
2323 terminating loops without side-effects can be removed. If a `mustprogress`
2324 function does not satisfy this contract, the behavior is undefined. This
2325 attribute does not apply transitively to callees, but does apply to call
2326 sites within the function. Note that `willreturn` implies `mustprogress`.
2327 ``"warn-stack-size"="<threshold>"``
2328 This attribute sets a threshold to emit diagnostics once the frame size is
2329 known should the frame size exceed the specified value. It takes one
2330 required integer value, which should be a non-negative integer, and less
2331 than `UINT_MAX`. It's unspecified which threshold will be used when
2332 duplicate definitions are linked together with differing values.
2333 ``vscale_range(<min>[, <max>])``
2334 This function attribute indicates `vscale` is a power-of-two within a
2335 specified range. `min` must be a power-of-two that is greater than 0. When
2336 specified, `max` must be a power-of-two greater-than-or-equal to `min` or 0
2337 to signify an unbounded maximum. The syntax `vscale_range(<val>)` can be
2338 used to set both `min` and `max` to the same value. Functions that don't
2339 include this attribute make no assumptions about the value 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``.
2786 .. _convergencectrl:
2788 Convergence Control Operand Bundles
2789 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2791 A "convergencectrl" operand bundle is only valid on a ``convergent`` operation.
2792 When present, the operand bundle must contain exactly one value of token type.
2793 See the :doc:`ConvergentOperations` document for details.
2797 Module-Level Inline Assembly
2798 ----------------------------
2800 Modules may contain "module-level inline asm" blocks, which corresponds
2801 to the GCC "file scope inline asm" blocks. These blocks are internally
2802 concatenated by LLVM and treated as a single unit, but may be separated
2803 in the ``.ll`` file if desired. The syntax is very simple:
2805 .. code-block:: llvm
2807 module asm "inline asm code goes here"
2808 module asm "more can go here"
2810 The strings can contain any character by escaping non-printable
2811 characters. The escape sequence used is simply "\\xx" where "xx" is the
2812 two digit hex code for the number.
2814 Note that the assembly string *must* be parseable by LLVM's integrated assembler
2815 (unless it is disabled), even when emitting a ``.s`` file.
2817 .. _langref_datalayout:
2822 A module may specify a target specific data layout string that specifies
2823 how data is to be laid out in memory. The syntax for the data layout is
2826 .. code-block:: llvm
2828 target datalayout = "layout specification"
2830 The *layout specification* consists of a list of specifications
2831 separated by the minus sign character ('-'). Each specification starts
2832 with a letter and may include other information after the letter to
2833 define some aspect of the data layout. The specifications accepted are
2837 Specifies that the target lays out data in big-endian form. That is,
2838 the bits with the most significance have the lowest address
2841 Specifies that the target lays out data in little-endian form. That
2842 is, the bits with the least significance have the lowest address
2845 Specifies the natural alignment of the stack in bits. Alignment
2846 promotion of stack variables is limited to the natural stack
2847 alignment to avoid dynamic stack realignment. The stack alignment
2848 must be a multiple of 8-bits. If omitted, the natural stack
2849 alignment defaults to "unspecified", which does not prevent any
2850 alignment promotions.
2851 ``P<address space>``
2852 Specifies the address space that corresponds to program memory.
2853 Harvard architectures can use this to specify what space LLVM
2854 should place things such as functions into. If omitted, the
2855 program memory space defaults to the default address space of 0,
2856 which corresponds to a Von Neumann architecture that has code
2857 and data in the same space.
2858 ``G<address space>``
2859 Specifies the address space to be used by default when creating global
2860 variables. If omitted, the globals address space defaults to the default
2862 Note: variable declarations without an address space are always created in
2863 address space 0, this property only affects the default value to be used
2864 when creating globals without additional contextual information (e.g. in
2867 .. _alloca_addrspace:
2869 ``A<address space>``
2870 Specifies the address space of objects created by '``alloca``'.
2871 Defaults to the default address space of 0.
2872 ``p[n]:<size>:<abi>[:<pref>][:<idx>]``
2873 This specifies the *size* of a pointer and its ``<abi>`` and
2874 ``<pref>``\erred alignments for address space ``n``. ``<pref>`` is optional
2875 and defaults to ``<abi>``. The fourth parameter ``<idx>`` is the size of the
2876 index that used for address calculation. If not
2877 specified, the default index size is equal to the pointer size. All sizes
2878 are in bits. The address space, ``n``, is optional, and if not specified,
2879 denotes the default address space 0. The value of ``n`` must be
2880 in the range [1,2^24).
2881 ``i<size>:<abi>[:<pref>]``
2882 This specifies the alignment for an integer type of a given bit
2883 ``<size>``. The value of ``<size>`` must be in the range [1,2^24).
2884 ``<pref>`` is optional and defaults to ``<abi>``.
2885 For ``i8``, the ``<abi>`` value must equal 8,
2886 that is, ``i8`` must be naturally aligned.
2887 ``v<size>:<abi>[:<pref>]``
2888 This specifies the alignment for a vector type of a given bit
2889 ``<size>``. The value of ``<size>`` must be in the range [1,2^24).
2890 ``<pref>`` is optional and defaults to ``<abi>``.
2891 ``f<size>:<abi>[:<pref>]``
2892 This specifies the alignment for a floating-point type of a given bit
2893 ``<size>``. Only values of ``<size>`` that are supported by the target
2894 will work. 32 (float) and 64 (double) are supported on all targets; 80
2895 or 128 (different flavors of long double) are also supported on some
2896 targets. The value of ``<size>`` must be in the range [1,2^24).
2897 ``<pref>`` is optional and defaults to ``<abi>``.
2898 ``a:<abi>[:<pref>]``
2899 This specifies the alignment for an object of aggregate type.
2900 ``<pref>`` is optional and defaults to ``<abi>``.
2902 This specifies the alignment for function pointers.
2903 The options for ``<type>`` are:
2905 * ``i``: The alignment of function pointers is independent of the alignment
2906 of functions, and is a multiple of ``<abi>``.
2907 * ``n``: The alignment of function pointers is a multiple of the explicit
2908 alignment specified on the function, and is a multiple of ``<abi>``.
2910 If present, specifies that llvm names are mangled in the output. Symbols
2911 prefixed with the mangling escape character ``\01`` are passed through
2912 directly to the assembler without the escape character. The mangling style
2915 * ``e``: ELF mangling: Private symbols get a ``.L`` prefix.
2916 * ``l``: GOFF mangling: Private symbols get a ``@`` prefix.
2917 * ``m``: Mips mangling: Private symbols get a ``$`` prefix.
2918 * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other
2919 symbols get a ``_`` prefix.
2920 * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix.
2921 Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``,
2922 ``__fastcall``, and ``__vectorcall`` have custom mangling that appends
2923 ``@N`` where N is the number of bytes used to pass parameters. C++ symbols
2924 starting with ``?`` are not mangled in any way.
2925 * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C
2926 symbols do not receive a ``_`` prefix.
2927 * ``a``: XCOFF mangling: Private symbols get a ``L..`` prefix.
2928 ``n<size1>:<size2>:<size3>...``
2929 This specifies a set of native integer widths for the target CPU in
2930 bits. For example, it might contain ``n32`` for 32-bit PowerPC,
2931 ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of
2932 this set are considered to support most general arithmetic operations
2934 ``ni:<address space0>:<address space1>:<address space2>...``
2935 This specifies pointer types with the specified address spaces
2936 as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0``
2937 address space cannot be specified as non-integral.
2939 On every specification that takes a ``<abi>:<pref>``, specifying the
2940 ``<pref>`` alignment is optional. If omitted, the preceding ``:``
2941 should be omitted too and ``<pref>`` will be equal to ``<abi>``.
2943 When constructing the data layout for a given target, LLVM starts with a
2944 default set of specifications which are then (possibly) overridden by
2945 the specifications in the ``datalayout`` keyword. The default
2946 specifications are given in this list:
2948 - ``e`` - little endian
2949 - ``p:64:64:64`` - 64-bit pointers with 64-bit alignment.
2950 - ``p[n]:64:64:64`` - Other address spaces are assumed to be the
2951 same as the default address space.
2952 - ``S0`` - natural stack alignment is unspecified
2953 - ``i1:8:8`` - i1 is 8-bit (byte) aligned
2954 - ``i8:8:8`` - i8 is 8-bit (byte) aligned as mandated
2955 - ``i16:16:16`` - i16 is 16-bit aligned
2956 - ``i32:32:32`` - i32 is 32-bit aligned
2957 - ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred
2958 alignment of 64-bits
2959 - ``f16:16:16`` - half is 16-bit aligned
2960 - ``f32:32:32`` - float is 32-bit aligned
2961 - ``f64:64:64`` - double is 64-bit aligned
2962 - ``f128:128:128`` - quad is 128-bit aligned
2963 - ``v64:64:64`` - 64-bit vector is 64-bit aligned
2964 - ``v128:128:128`` - 128-bit vector is 128-bit aligned
2965 - ``a:0:64`` - aggregates are 64-bit aligned
2967 When LLVM is determining the alignment for a given type, it uses the
2970 #. If the type sought is an exact match for one of the specifications,
2971 that specification is used.
2972 #. If no match is found, and the type sought is an integer type, then
2973 the smallest integer type that is larger than the bitwidth of the
2974 sought type is used. If none of the specifications are larger than
2975 the bitwidth then the largest integer type is used. For example,
2976 given the default specifications above, the i7 type will use the
2977 alignment of i8 (next largest) while both i65 and i256 will use the
2978 alignment of i64 (largest specified).
2980 The function of the data layout string may not be what you expect.
2981 Notably, this is not a specification from the frontend of what alignment
2982 the code generator should use.
2984 Instead, if specified, the target data layout is required to match what
2985 the ultimate *code generator* expects. This string is used by the
2986 mid-level optimizers to improve code, and this only works if it matches
2987 what the ultimate code generator uses. There is no way to generate IR
2988 that does not embed this target-specific detail into the IR. If you
2989 don't specify the string, the default specifications will be used to
2990 generate a Data Layout and the optimization phases will operate
2991 accordingly and introduce target specificity into the IR with respect to
2992 these default specifications.
2999 A module may specify a target triple string that describes the target
3000 host. The syntax for the target triple is simply:
3002 .. code-block:: llvm
3004 target triple = "x86_64-apple-macosx10.7.0"
3006 The *target triple* string consists of a series of identifiers delimited
3007 by the minus sign character ('-'). The canonical forms are:
3011 ARCHITECTURE-VENDOR-OPERATING_SYSTEM
3012 ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
3014 This information is passed along to the backend so that it generates
3015 code for the proper architecture. It's possible to override this on the
3016 command line with the ``-mtriple`` command line option.
3021 ----------------------
3023 A memory object, or simply object, is a region of a memory space that is
3024 reserved by a memory allocation such as :ref:`alloca <i_alloca>`, heap
3025 allocation calls, and global variable definitions.
3026 Once it is allocated, the bytes stored in the region can only be read or written
3027 through a pointer that is :ref:`based on <pointeraliasing>` the allocation
3029 If a pointer that is not based on the object tries to read or write to the
3030 object, it is undefined behavior.
3032 A lifetime of a memory object is a property that decides its accessibility.
3033 Unless stated otherwise, a memory object is alive since its allocation, and
3034 dead after its deallocation.
3035 It is undefined behavior to access a memory object that isn't alive, but
3036 operations that don't dereference it such as
3037 :ref:`getelementptr <i_getelementptr>`, :ref:`ptrtoint <i_ptrtoint>` and
3038 :ref:`icmp <i_icmp>` return a valid result.
3039 This explains code motion of these instructions across operations that
3040 impact the object's lifetime.
3041 A stack object's lifetime can be explicitly specified using
3042 :ref:`llvm.lifetime.start <int_lifestart>` and
3043 :ref:`llvm.lifetime.end <int_lifeend>` intrinsic function calls.
3045 .. _pointeraliasing:
3047 Pointer Aliasing Rules
3048 ----------------------
3050 Any memory access must be done through a pointer value associated with
3051 an address range of the memory access, otherwise the behavior is
3052 undefined. Pointer values are associated with address ranges according
3053 to the following rules:
3055 - A pointer value is associated with the addresses associated with any
3056 value it is *based* on.
3057 - An address of a global variable is associated with the address range
3058 of the variable's storage.
3059 - The result value of an allocation instruction is associated with the
3060 address range of the allocated storage.
3061 - A null pointer in the default address-space is associated with no
3063 - An :ref:`undef value <undefvalues>` in *any* address-space is
3064 associated with no address.
3065 - An integer constant other than zero or a pointer value returned from
3066 a function not defined within LLVM may be associated with address
3067 ranges allocated through mechanisms other than those provided by
3068 LLVM. Such ranges shall not overlap with any ranges of addresses
3069 allocated by mechanisms provided by LLVM.
3071 A pointer value is *based* on another pointer value according to the
3074 - A pointer value formed from a scalar ``getelementptr`` operation is *based* on
3075 the pointer-typed operand of the ``getelementptr``.
3076 - The pointer in lane *l* of the result of a vector ``getelementptr`` operation
3077 is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand
3078 of the ``getelementptr``.
3079 - The result value of a ``bitcast`` is *based* on the operand of the
3081 - A pointer value formed by an ``inttoptr`` is *based* on all pointer
3082 values that contribute (directly or indirectly) to the computation of
3083 the pointer's value.
3084 - The "*based* on" relationship is transitive.
3086 Note that this definition of *"based"* is intentionally similar to the
3087 definition of *"based"* in C99, though it is slightly weaker.
3089 LLVM IR does not associate types with memory. The result type of a
3090 ``load`` merely indicates the size and alignment of the memory from
3091 which to load, as well as the interpretation of the value. The first
3092 operand type of a ``store`` similarly only indicates the size and
3093 alignment of the store.
3095 Consequently, type-based alias analysis, aka TBAA, aka
3096 ``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR.
3097 :ref:`Metadata <metadata>` may be used to encode additional information
3098 which specialized optimization passes may use to implement type-based
3106 Given a function call and a pointer that is passed as an argument or stored in
3107 the memory before the call, a pointer is *captured* by the call if it makes a
3108 copy of any part of the pointer that outlives the call.
3109 To be precise, a pointer is captured if one or more of the following conditions
3112 1. The call stores any bit of the pointer carrying information into a place,
3113 and the stored bits can be read from the place by the caller after this call
3116 .. code-block:: llvm
3118 @glb = global ptr null
3119 @glb2 = global ptr null
3120 @glb3 = global ptr null
3121 @glbi = global i32 0
3123 define ptr @f(ptr %a, ptr %b, ptr %c, ptr %d, ptr %e) {
3124 store ptr %a, ptr @glb ; %a is captured by this call
3126 store ptr %b, ptr @glb2 ; %b isn't captured because the stored value is overwritten by the store below
3127 store ptr null, ptr @glb2
3129 store ptr %c, ptr @glb3
3130 call void @g() ; If @g makes a copy of %c that outlives this call (@f), %c is captured
3131 store ptr null, ptr @glb3
3133 %i = ptrtoint ptr %d to i64
3134 %j = trunc i64 %i to i32
3135 store i32 %j, ptr @glbi ; %d is captured
3137 ret ptr %e ; %e is captured
3140 2. The call stores any bit of the pointer carrying information into a place,
3141 and the stored bits can be safely read from the place by another thread via
3144 .. code-block:: llvm
3146 @lock = global i1 true
3148 define void @f(ptr %a) {
3149 store ptr %a, ptr* @glb
3150 store atomic i1 false, ptr @lock release ; %a is captured because another thread can safely read @glb
3151 store ptr null, ptr @glb
3155 3. The call's behavior depends on any bit of the pointer carrying information.
3157 .. code-block:: llvm
3161 define void @f(ptr %a) {
3162 %c = icmp eq ptr %a, @glb
3163 br i1 %c, label %BB_EXIT, label %BB_CONTINUE ; escapes %a
3171 4. The pointer is used in a volatile access as its address.
3176 Volatile Memory Accesses
3177 ------------------------
3179 Certain memory accesses, such as :ref:`load <i_load>`'s,
3180 :ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be
3181 marked ``volatile``. The optimizers must not change the number of
3182 volatile operations or change their order of execution relative to other
3183 volatile operations. The optimizers *may* change the order of volatile
3184 operations relative to non-volatile operations. This is not Java's
3185 "volatile" and has no cross-thread synchronization behavior.
3187 A volatile load or store may have additional target-specific semantics.
3188 Any volatile operation can have side effects, and any volatile operation
3189 can read and/or modify state which is not accessible via a regular load
3190 or store in this module. Volatile operations may use addresses which do
3191 not point to memory (like MMIO registers). This means the compiler may
3192 not use a volatile operation to prove a non-volatile access to that
3193 address has defined behavior.
3195 The allowed side-effects for volatile accesses are limited. If a
3196 non-volatile store to a given address would be legal, a volatile
3197 operation may modify the memory at that address. A volatile operation
3198 may not modify any other memory accessible by the module being compiled.
3199 A volatile operation may not call any code in the current module.
3201 In general (without target specific context), the address space of a
3202 volatile operation may not be changed. Different address spaces may
3203 have different trapping behavior when dereferencing an invalid
3206 The compiler may assume execution will continue after a volatile operation,
3207 so operations which modify memory or may have undefined behavior can be
3208 hoisted past a volatile operation.
3210 As an exception to the preceding rule, the compiler may not assume execution
3211 will continue after a volatile store operation. This restriction is necessary
3212 to support the somewhat common pattern in C of intentionally storing to an
3213 invalid pointer to crash the program. In the future, it might make sense to
3214 allow frontends to control this behavior.
3216 IR-level volatile loads and stores cannot safely be optimized into llvm.memcpy
3217 or llvm.memmove intrinsics even when those intrinsics are flagged volatile.
3218 Likewise, the backend should never split or merge target-legal volatile
3219 load/store instructions. Similarly, IR-level volatile loads and stores cannot
3220 change from integer to floating-point or vice versa.
3222 .. admonition:: Rationale
3224 Platforms may rely on volatile loads and stores of natively supported
3225 data width to be executed as single instruction. For example, in C
3226 this holds for an l-value of volatile primitive type with native
3227 hardware support, but not necessarily for aggregate types. The
3228 frontend upholds these expectations, which are intentionally
3229 unspecified in the IR. The rules above ensure that IR transformations
3230 do not violate the frontend's contract with the language.
3234 Memory Model for Concurrent Operations
3235 --------------------------------------
3237 The LLVM IR does not define any way to start parallel threads of
3238 execution or to register signal handlers. Nonetheless, there are
3239 platform-specific ways to create them, and we define LLVM IR's behavior
3240 in their presence. This model is inspired by the C++0x memory model.
3242 For a more informal introduction to this model, see the :doc:`Atomics`.
3244 We define a *happens-before* partial order as the least partial order
3247 - Is a superset of single-thread program order, and
3248 - When a *synchronizes-with* ``b``, includes an edge from ``a`` to
3249 ``b``. *Synchronizes-with* pairs are introduced by platform-specific
3250 techniques, like pthread locks, thread creation, thread joining,
3251 etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering
3252 Constraints <ordering>`).
3254 Note that program order does not introduce *happens-before* edges
3255 between a thread and signals executing inside that thread.
3257 Every (defined) read operation (load instructions, memcpy, atomic
3258 loads/read-modify-writes, etc.) R reads a series of bytes written by
3259 (defined) write operations (store instructions, atomic
3260 stores/read-modify-writes, memcpy, etc.). For the purposes of this
3261 section, initialized globals are considered to have a write of the
3262 initializer which is atomic and happens before any other read or write
3263 of the memory in question. For each byte of a read R, R\ :sub:`byte`
3264 may see any write to the same byte, except:
3266 - If write\ :sub:`1` happens before write\ :sub:`2`, and
3267 write\ :sub:`2` happens before R\ :sub:`byte`, then
3268 R\ :sub:`byte` does not see write\ :sub:`1`.
3269 - If R\ :sub:`byte` happens before write\ :sub:`3`, then
3270 R\ :sub:`byte` does not see write\ :sub:`3`.
3272 Given that definition, R\ :sub:`byte` is defined as follows:
3274 - If R is volatile, the result is target-dependent. (Volatile is
3275 supposed to give guarantees which can support ``sig_atomic_t`` in
3276 C/C++, and may be used for accesses to addresses that do not behave
3277 like normal memory. It does not generally provide cross-thread
3279 - Otherwise, if there is no write to the same byte that happens before
3280 R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte.
3281 - Otherwise, if R\ :sub:`byte` may see exactly one write,
3282 R\ :sub:`byte` returns the value written by that write.
3283 - Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may
3284 see are atomic, it chooses one of the values written. See the :ref:`Atomic
3285 Memory Ordering Constraints <ordering>` section for additional
3286 constraints on how the choice is made.
3287 - Otherwise R\ :sub:`byte` returns ``undef``.
3289 R returns the value composed of the series of bytes it read. This
3290 implies that some bytes within the value may be ``undef`` **without**
3291 the entire value being ``undef``. Note that this only defines the
3292 semantics of the operation; it doesn't mean that targets will emit more
3293 than one instruction to read the series of bytes.
3295 Note that in cases where none of the atomic intrinsics are used, this
3296 model places only one restriction on IR transformations on top of what
3297 is required for single-threaded execution: introducing a store to a byte
3298 which might not otherwise be stored is not allowed in general.
3299 (Specifically, in the case where another thread might write to and read
3300 from an address, introducing a store can change a load that may see
3301 exactly one write into a load that may see multiple writes.)
3305 Atomic Memory Ordering Constraints
3306 ----------------------------------
3308 Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`,
3309 :ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`,
3310 :ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take
3311 ordering parameters that determine which other atomic instructions on
3312 the same address they *synchronize with*. These semantics are borrowed
3313 from Java and C++0x, but are somewhat more colloquial. If these
3314 descriptions aren't precise enough, check those specs (see spec
3315 references in the :doc:`atomics guide <Atomics>`).
3316 :ref:`fence <i_fence>` instructions treat these orderings somewhat
3317 differently since they don't take an address. See that instruction's
3318 documentation for details.
3320 For a simpler introduction to the ordering constraints, see the
3324 The set of values that can be read is governed by the happens-before
3325 partial order. A value cannot be read unless some operation wrote
3326 it. This is intended to provide a guarantee strong enough to model
3327 Java's non-volatile shared variables. This ordering cannot be
3328 specified for read-modify-write operations; it is not strong enough
3329 to make them atomic in any interesting way.
3331 In addition to the guarantees of ``unordered``, there is a single
3332 total order for modifications by ``monotonic`` operations on each
3333 address. All modification orders must be compatible with the
3334 happens-before order. There is no guarantee that the modification
3335 orders can be combined to a global total order for the whole program
3336 (and this often will not be possible). The read in an atomic
3337 read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and
3338 :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification
3339 order immediately before the value it writes. If one atomic read
3340 happens before another atomic read of the same address, the later
3341 read must see the same value or a later value in the address's
3342 modification order. This disallows reordering of ``monotonic`` (or
3343 stronger) operations on the same address. If an address is written
3344 ``monotonic``-ally by one thread, and other threads ``monotonic``-ally
3345 read that address repeatedly, the other threads must eventually see
3346 the write. This corresponds to the C++0x/C1x
3347 ``memory_order_relaxed``.
3349 In addition to the guarantees of ``monotonic``, a
3350 *synchronizes-with* edge may be formed with a ``release`` operation.
3351 This is intended to model C++'s ``memory_order_acquire``.
3353 In addition to the guarantees of ``monotonic``, if this operation
3354 writes a value which is subsequently read by an ``acquire``
3355 operation, it *synchronizes-with* that operation. (This isn't a
3356 complete description; see the C++0x definition of a release
3357 sequence.) This corresponds to the C++0x/C1x
3358 ``memory_order_release``.
3359 ``acq_rel`` (acquire+release)
3360 Acts as both an ``acquire`` and ``release`` operation on its
3361 address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``.
3362 ``seq_cst`` (sequentially consistent)
3363 In addition to the guarantees of ``acq_rel`` (``acquire`` for an
3364 operation that only reads, ``release`` for an operation that only
3365 writes), there is a global total order on all
3366 sequentially-consistent operations on all addresses, which is
3367 consistent with the *happens-before* partial order and with the
3368 modification orders of all the affected addresses. Each
3369 sequentially-consistent read sees the last preceding write to the
3370 same address in this global order. This corresponds to the C++0x/C1x
3371 ``memory_order_seq_cst`` and Java volatile.
3375 If an atomic operation is marked ``syncscope("singlethread")``, it only
3376 *synchronizes with* and only participates in the seq\_cst total orderings of
3377 other operations running in the same thread (for example, in signal handlers).
3379 If an atomic operation is marked ``syncscope("<target-scope>")``, where
3380 ``<target-scope>`` is a target specific synchronization scope, then it is target
3381 dependent if it *synchronizes with* and participates in the seq\_cst total
3382 orderings of other operations.
3384 Otherwise, an atomic operation that is not marked ``syncscope("singlethread")``
3385 or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the
3386 seq\_cst total orderings of other operations that are not marked
3387 ``syncscope("singlethread")`` or ``syncscope("<target-scope>")``.
3391 Floating-Point Environment
3392 --------------------------
3394 The default LLVM floating-point environment assumes that traps are disabled and
3395 status flags are not observable. Therefore, floating-point math operations do
3396 not have side effects and may be speculated freely. Results assume the
3397 round-to-nearest rounding mode.
3399 Floating-point math operations are allowed to treat all NaNs as if they were
3400 quiet NaNs. For example, "pow(1.0, SNaN)" may be simplified to 1.0. This also
3401 means that SNaN may be passed through a math operation without quieting. For
3402 example, "fmul SNaN, 1.0" may be simplified to SNaN rather than QNaN. However,
3403 SNaN values are never created by math operations. They may only occur when
3404 provided as a program input value.
3406 Code that requires different behavior than this should use the
3407 :ref:`Constrained Floating-Point Intrinsics <constrainedfp>`.
3414 LLVM IR floating-point operations (:ref:`fneg <i_fneg>`, :ref:`fadd <i_fadd>`,
3415 :ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
3416 :ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`), :ref:`phi <i_phi>`,
3417 :ref:`select <i_select>` and :ref:`call <i_call>`
3418 may use the following flags to enable otherwise unsafe
3419 floating-point transformations.
3422 No NaNs - Allow optimizations to assume the arguments and result are not
3423 NaN. If an argument is a nan, or the result would be a nan, it produces
3424 a :ref:`poison value <poisonvalues>` instead.
3427 No Infs - Allow optimizations to assume the arguments and result are not
3428 +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it
3429 produces a :ref:`poison value <poisonvalues>` instead.
3432 No Signed Zeros - Allow optimizations to treat the sign of a zero
3433 argument or zero result as insignificant. This does not imply that -0.0
3434 is poison and/or guaranteed to not exist in the operation.
3437 Allow Reciprocal - Allow optimizations to use the reciprocal of an
3438 argument rather than perform division.
3441 Allow floating-point contraction (e.g. fusing a multiply followed by an
3442 addition into a fused multiply-and-add). This does not enable reassociating
3443 to form arbitrary contractions. For example, ``(a*b) + (c*d) + e`` can not
3444 be transformed into ``(a*b) + ((c*d) + e)`` to create two fma operations.
3449 Approximate functions - Allow substitution of approximate calculations for
3450 functions (sin, log, sqrt, etc). See floating-point intrinsic definitions
3451 for places where this can apply to LLVM's intrinsic math functions.
3454 Allow reassociation transformations for floating-point instructions.
3455 This may dramatically change results in floating-point.
3458 This flag implies all of the others.
3462 Use-list Order Directives
3463 -------------------------
3465 Use-list directives encode the in-memory order of each use-list, allowing the
3466 order to be recreated. ``<order-indexes>`` is a comma-separated list of
3467 indexes that are assigned to the referenced value's uses. The referenced
3468 value's use-list is immediately sorted by these indexes.
3470 Use-list directives may appear at function scope or global scope. They are not
3471 instructions, and have no effect on the semantics of the IR. When they're at
3472 function scope, they must appear after the terminator of the final basic block.
3474 If basic blocks have their address taken via ``blockaddress()`` expressions,
3475 ``uselistorder_bb`` can be used to reorder their use-lists from outside their
3482 uselistorder <ty> <value>, { <order-indexes> }
3483 uselistorder_bb @function, %block { <order-indexes> }
3489 define void @foo(i32 %arg1, i32 %arg2) {
3491 ; ... instructions ...
3493 ; ... instructions ...
3495 ; At function scope.
3496 uselistorder i32 %arg1, { 1, 0, 2 }
3497 uselistorder label %bb, { 1, 0 }
3501 uselistorder ptr @global, { 1, 2, 0 }
3502 uselistorder i32 7, { 1, 0 }
3503 uselistorder i32 (i32) @bar, { 1, 0 }
3504 uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 }
3506 .. _source_filename:
3511 The *source filename* string is set to the original module identifier,
3512 which will be the name of the compiled source file when compiling from
3513 source through the clang front end, for example. It is then preserved through
3516 This is currently necessary to generate a consistent unique global
3517 identifier for local functions used in profile data, which prepends the
3518 source file name to the local function name.
3520 The syntax for the source file name is simply:
3522 .. code-block:: text
3524 source_filename = "/path/to/source.c"
3531 The LLVM type system is one of the most important features of the
3532 intermediate representation. Being typed enables a number of
3533 optimizations to be performed on the intermediate representation
3534 directly, without having to do extra analyses on the side before the
3535 transformation. A strong type system makes it easier to read the
3536 generated code and enables novel analyses and transformations that are
3537 not feasible to perform on normal three address code representations.
3547 The void type does not represent any value and has no size.
3565 The function type can be thought of as a function signature. It consists of a
3566 return type and a list of formal parameter types. The return type of a function
3567 type is a void type or first class type --- except for :ref:`label <t_label>`
3568 and :ref:`metadata <t_metadata>` types.
3574 <returntype> (<parameter list>)
3576 ...where '``<parameter list>``' is a comma-separated list of type
3577 specifiers. Optionally, the parameter list may include a type ``...``, which
3578 indicates that the function takes a variable number of arguments. Variable
3579 argument functions can access their arguments with the :ref:`variable argument
3580 handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type
3581 except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`.
3585 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3586 | ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` |
3587 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3588 | ``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. |
3589 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3590 | ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values |
3591 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3598 The :ref:`first class <t_firstclass>` types are perhaps the most important.
3599 Values of these types are the only ones which can be produced by
3607 These are the types that are valid in registers from CodeGen's perspective.
3616 The integer type is a very simple type that simply specifies an
3617 arbitrary bit width for the integer type desired. Any bit width from 1
3618 bit to 2\ :sup:`23`\ (about 8 million) can be specified.
3626 The number of bits the integer will occupy is specified by the ``N``
3632 +----------------+------------------------------------------------+
3633 | ``i1`` | a single-bit integer. |
3634 +----------------+------------------------------------------------+
3635 | ``i32`` | a 32-bit integer. |
3636 +----------------+------------------------------------------------+
3637 | ``i1942652`` | a really big integer of over 1 million bits. |
3638 +----------------+------------------------------------------------+
3642 Floating-Point Types
3643 """"""""""""""""""""
3652 - 16-bit floating-point value
3655 - 16-bit "brain" floating-point value (7-bit significand). Provides the
3656 same number of exponent bits as ``float``, so that it matches its dynamic
3657 range, but with greatly reduced precision. Used in Intel's AVX-512 BF16
3658 extensions and Arm's ARMv8.6-A extensions, among others.
3661 - 32-bit floating-point value
3664 - 64-bit floating-point value
3667 - 128-bit floating-point value (113-bit significand)
3670 - 80-bit floating-point value (X87)
3673 - 128-bit floating-point value (two 64-bits)
3675 The binary format of half, float, double, and fp128 correspond to the
3676 IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128
3684 The x86_amx type represents a value held in an AMX tile register on an x86
3685 machine. The operations allowed on it are quite limited. Only few intrinsics
3686 are allowed: stride load and store, zero and dot product. No instruction is
3687 allowed for this type. There are no arguments, arrays, pointers, vectors
3688 or constants of this type.
3702 The x86_mmx type represents a value held in an MMX register on an x86
3703 machine. The operations allowed on it are quite limited: parameters and
3704 return values, load and store, and bitcast. User-specified MMX
3705 instructions are represented as intrinsic or asm calls with arguments
3706 and/or results of this type. There are no arrays, vectors or constants
3723 The pointer type ``ptr`` is used to specify memory locations. Pointers are
3724 commonly used to reference objects in memory.
3726 Pointer types may have an optional address space attribute defining
3727 the numbered address space where the pointed-to object resides. For
3728 example, ``ptr addrspace(5)`` is a pointer to address space 5.
3729 In addition to integer constants, ``addrspace`` can also reference one of the
3730 address spaces defined in the :ref:`datalayout string<langref_datalayout>`.
3731 ``addrspace("A")`` will use the alloca address space, ``addrspace("G")``
3732 the default globals address space and ``addrspace("P")`` the program address
3735 The default address space is number zero.
3737 The semantics of non-zero address spaces are target-specific. Memory
3738 access through a non-dereferenceable pointer is undefined behavior in
3739 any address space. Pointers with the bit-value 0 are only assumed to
3740 be non-dereferenceable in address space 0, unless the function is
3741 marked with the ``null_pointer_is_valid`` attribute.
3743 If an object can be proven accessible through a pointer with a
3744 different address space, the access may be modified to use that
3745 address space. Exceptions apply if the operation is ``volatile``.
3747 Prior to LLVM 15, pointer types also specified a pointee type, such as
3748 ``i8*``, ``[4 x i32]*`` or ``i32 (i32*)*``. In LLVM 15, such "typed
3749 pointers" are still supported under non-default options. See the
3750 `opaque pointers document <OpaquePointers.html>`__ for more information.
3754 Target Extension Type
3755 """""""""""""""""""""
3759 Target extension types represent types that must be preserved through
3760 optimization, but are otherwise generally opaque to the compiler. They may be
3761 used as function parameters or arguments, and in :ref:`phi <i_phi>` or
3762 :ref:`select <i_select>` instructions. Some types may be also used in
3763 :ref:`alloca <i_alloca>` instructions or as global values, and correspondingly
3764 it is legal to use :ref:`load <i_load>` and :ref:`store <i_store>` instructions
3765 on them. Full semantics for these types are defined by the target.
3767 The only constants that target extension types may have are ``zeroinitializer``,
3768 ``undef``, and ``poison``. Other possible values for target extension types may
3769 arise from target-specific intrinsics and functions.
3771 These types cannot be converted to other types. As such, it is not legal to use
3772 them in :ref:`bitcast <i_bitcast>` instructions (as a source or target type),
3773 nor is it legal to use them in :ref:`ptrtoint <i_ptrtoint>` or
3774 :ref:`inttoptr <i_inttoptr>` instructions. Similarly, they are not legal to use
3775 in an :ref:`icmp <i_icmp>` instruction.
3777 Target extension types have a name and optional type or integer parameters. The
3778 meanings of name and parameters are defined by the target. When being defined in
3779 LLVM IR, all of the type parameters must precede all of the integer parameters.
3781 Specific target extension types are registered with LLVM as having specific
3782 properties. These properties can be used to restrict the type from appearing in
3783 certain contexts, such as being the type of a global variable or having a
3784 ``zeroinitializer`` constant be valid. A complete list of type properties may be
3785 found in the documentation for ``llvm::TargetExtType::Property`` (`doxygen
3786 <https://llvm.org/doxygen/classllvm_1_1TargetExtType.html>`_).
3790 .. code-block:: llvm
3793 target("label", void)
3794 target("label", void, i32)
3795 target("label", 0, 1, 2)
3796 target("label", void, i32, 0, 1, 2)
3806 A vector type is a simple derived type that represents a vector of
3807 elements. Vector types are used when multiple primitive data are
3808 operated in parallel using a single instruction (SIMD). A vector type
3809 requires a size (number of elements), an underlying primitive data type,
3810 and a scalable property to represent vectors where the exact hardware
3811 vector length is unknown at compile time. Vector types are considered
3812 :ref:`first class <t_firstclass>`.
3816 In general vector elements are laid out in memory in the same way as
3817 :ref:`array types <t_array>`. Such an analogy works fine as long as the vector
3818 elements are byte sized. However, when the elements of the vector aren't byte
3819 sized it gets a bit more complicated. One way to describe the layout is by
3820 describing what happens when a vector such as <N x iM> is bitcasted to an
3821 integer type with N*M bits, and then following the rules for storing such an
3824 A bitcast from a vector type to a scalar integer type will see the elements
3825 being packed together (without padding). The order in which elements are
3826 inserted in the integer depends on endianess. For little endian element zero
3827 is put in the least significant bits of the integer, and for big endian
3828 element zero is put in the most significant bits.
3830 Using a vector such as ``<i4 1, i4 2, i4 3, i4 5>`` as an example, together
3831 with the analogy that we can replace a vector store by a bitcast followed by
3832 an integer store, we get this for big endian:
3834 .. code-block:: llvm
3836 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16
3838 ; Bitcasting from a vector to an integral type can be seen as
3839 ; concatenating the values:
3840 ; %val now has the hexadecimal value 0x1235.
3842 store i16 %val, ptr %ptr
3844 ; In memory the content will be (8-bit addressing):
3846 ; [%ptr + 0]: 00010010 (0x12)
3847 ; [%ptr + 1]: 00110101 (0x35)
3849 The same example for little endian:
3851 .. code-block:: llvm
3853 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16
3855 ; Bitcasting from a vector to an integral type can be seen as
3856 ; concatenating the values:
3857 ; %val now has the hexadecimal value 0x5321.
3859 store i16 %val, ptr %ptr
3861 ; In memory the content will be (8-bit addressing):
3863 ; [%ptr + 0]: 00100001 (0x21)
3864 ; [%ptr + 1]: 01010011 (0x53)
3866 When ``<N*M>`` isn't evenly divisible by the byte size the exact memory layout
3867 is unspecified (just like it is for an integral type of the same size). This
3868 is because different targets could put the padding at different positions when
3869 the type size is smaller than the type's store size.
3875 < <# elements> x <elementtype> > ; Fixed-length vector
3876 < vscale x <# elements> x <elementtype> > ; Scalable vector
3878 The number of elements is a constant integer value larger than 0;
3879 elementtype may be any integer, floating-point or pointer type. Vectors
3880 of size zero are not allowed. For scalable vectors, the total number of
3881 elements is a constant multiple (called vscale) of the specified number
3882 of elements; vscale is a positive integer that is unknown at compile time
3883 and the same hardware-dependent constant for all scalable vectors at run
3884 time. The size of a specific scalable vector type is thus constant within
3885 IR, even if the exact size in bytes cannot be determined until run time.
3889 +------------------------+----------------------------------------------------+
3890 | ``<4 x i32>`` | Vector of 4 32-bit integer values. |
3891 +------------------------+----------------------------------------------------+
3892 | ``<8 x float>`` | Vector of 8 32-bit floating-point values. |
3893 +------------------------+----------------------------------------------------+
3894 | ``<2 x i64>`` | Vector of 2 64-bit integer values. |
3895 +------------------------+----------------------------------------------------+
3896 | ``<4 x ptr>`` | Vector of 4 pointers |
3897 +------------------------+----------------------------------------------------+
3898 | ``<vscale x 4 x i32>`` | Vector with a multiple of 4 32-bit integer values. |
3899 +------------------------+----------------------------------------------------+
3908 The label type represents code labels.
3923 The token type is used when a value is associated with an instruction
3924 but all uses of the value must not attempt to introspect or obscure it.
3925 As such, it is not appropriate to have a :ref:`phi <i_phi>` or
3926 :ref:`select <i_select>` of type token.
3943 The metadata type represents embedded metadata. No derived types may be
3944 created from metadata except for :ref:`function <t_function>` arguments.
3957 Aggregate Types are a subset of derived types that can contain multiple
3958 member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are
3959 aggregate types. :ref:`Vectors <t_vector>` are not considered to be
3969 The array type is a very simple derived type that arranges elements
3970 sequentially in memory. The array type requires a size (number of
3971 elements) and an underlying data type.
3977 [<# elements> x <elementtype>]
3979 The number of elements is a constant integer value; ``elementtype`` may
3980 be any type with a size.
3984 +------------------+--------------------------------------+
3985 | ``[40 x i32]`` | Array of 40 32-bit integer values. |
3986 +------------------+--------------------------------------+
3987 | ``[41 x i32]`` | Array of 41 32-bit integer values. |
3988 +------------------+--------------------------------------+
3989 | ``[4 x i8]`` | Array of 4 8-bit integer values. |
3990 +------------------+--------------------------------------+
3992 Here are some examples of multidimensional arrays:
3994 +-----------------------------+----------------------------------------------------------+
3995 | ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. |
3996 +-----------------------------+----------------------------------------------------------+
3997 | ``[12 x [10 x float]]`` | 12x10 array of single precision floating-point values. |
3998 +-----------------------------+----------------------------------------------------------+
3999 | ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. |
4000 +-----------------------------+----------------------------------------------------------+
4002 There is no restriction on indexing beyond the end of the array implied
4003 by a static type (though there are restrictions on indexing beyond the
4004 bounds of an allocated object in some cases). This means that
4005 single-dimension 'variable sized array' addressing can be implemented in
4006 LLVM with a zero length array type. An implementation of 'pascal style
4007 arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for
4017 The structure type is used to represent a collection of data members
4018 together in memory. The elements of a structure may be any type that has
4021 Structures in memory are accessed using '``load``' and '``store``' by
4022 getting a pointer to a field with the '``getelementptr``' instruction.
4023 Structures in registers are accessed using the '``extractvalue``' and
4024 '``insertvalue``' instructions.
4026 Structures may optionally be "packed" structures, which indicate that
4027 the alignment of the struct is one byte, and that there is no padding
4028 between the elements. In non-packed structs, padding between field types
4029 is inserted as defined by the DataLayout string in the module, which is
4030 required to match what the underlying code generator expects.
4032 Structures can either be "literal" or "identified". A literal structure
4033 is defined inline with other types (e.g. ``[2 x {i32, i32}]``) whereas
4034 identified types are always defined at the top level with a name.
4035 Literal types are uniqued by their contents and can never be recursive
4036 or opaque since there is no way to write one. Identified types can be
4037 recursive, can be opaqued, and are never uniqued.
4043 %T1 = type { <type list> } ; Identified normal struct type
4044 %T2 = type <{ <type list> }> ; Identified packed struct type
4048 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4049 | ``{ i32, i32, i32 }`` | A triple of three ``i32`` values |
4050 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4051 | ``{ float, ptr }`` | A pair, where the first element is a ``float`` and the second element is a :ref:`pointer <t_pointer>`. |
4052 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4053 | ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. |
4054 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4058 Opaque Structure Types
4059 """"""""""""""""""""""
4063 Opaque structure types are used to represent structure types that
4064 do not have a body specified. This corresponds (for example) to the C
4065 notion of a forward declared structure. They can be named (``%X``) or
4077 +--------------+-------------------+
4078 | ``opaque`` | An opaque type. |
4079 +--------------+-------------------+
4086 LLVM has several different basic types of constants. This section
4087 describes them all and their syntax.
4092 **Boolean constants**
4093 The two strings '``true``' and '``false``' are both valid constants
4095 **Integer constants**
4096 Standard integers (such as '4') are constants of the :ref:`integer
4097 <t_integer>` type. They can be either decimal or
4098 hexadecimal. Decimal integers can be prefixed with - to represent
4099 negative integers, e.g. '``-1234``'. Hexadecimal integers must be
4100 prefixed with either u or s to indicate whether they are unsigned
4101 or signed respectively. e.g '``u0x8000``' gives 32768, whilst
4102 '``s0x8000``' gives -32768.
4104 Note that hexadecimal integers are sign extended from the number
4105 of active bits, i.e. the bit width minus the number of leading
4106 zeros. So '``s0x0001``' of type '``i16``' will be -1, not 1.
4107 **Floating-point constants**
4108 Floating-point constants use standard decimal notation (e.g.
4109 123.421), exponential notation (e.g. 1.23421e+2), or a more precise
4110 hexadecimal notation (see below). The assembler requires the exact
4111 decimal value of a floating-point constant. For example, the
4112 assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating
4113 decimal in binary. Floating-point constants must have a
4114 :ref:`floating-point <t_floating>` type.
4115 **Null pointer constants**
4116 The identifier '``null``' is recognized as a null pointer constant
4117 and must be of :ref:`pointer type <t_pointer>`.
4119 The identifier '``none``' is recognized as an empty token constant
4120 and must be of :ref:`token type <t_token>`.
4122 The one non-intuitive notation for constants is the hexadecimal form of
4123 floating-point constants. For example, the form
4124 '``double 0x432ff973cafa8000``' is equivalent to (but harder to read
4125 than) '``double 4.5e+15``'. The only time hexadecimal floating-point
4126 constants are required (and the only time that they are generated by the
4127 disassembler) is when a floating-point constant must be emitted but it
4128 cannot be represented as a decimal floating-point number in a reasonable
4129 number of digits. For example, NaN's, infinities, and other special
4130 values are represented in their IEEE hexadecimal format so that assembly
4131 and disassembly do not cause any bits to change in the constants.
4133 When using the hexadecimal form, constants of types bfloat, half, float, and
4134 double are represented using the 16-digit form shown above (which matches the
4135 IEEE754 representation for double); bfloat, half and float values must, however,
4136 be exactly representable as bfloat, IEEE 754 half, and IEEE 754 single
4137 precision respectively. Hexadecimal format is always used for long double, and
4138 there are three forms of long double. The 80-bit format used by x86 is
4139 represented as ``0xK`` followed by 20 hexadecimal digits. The 128-bit format
4140 used by PowerPC (two adjacent doubles) is represented by ``0xM`` followed by 32
4141 hexadecimal digits. The IEEE 128-bit format is represented by ``0xL`` followed
4142 by 32 hexadecimal digits. Long doubles will only work if they match the long
4143 double format on your target. The IEEE 16-bit format (half precision) is
4144 represented by ``0xH`` followed by 4 hexadecimal digits. The bfloat 16-bit
4145 format is represented by ``0xR`` followed by 4 hexadecimal digits. All
4146 hexadecimal formats are big-endian (sign bit at the left).
4148 There are no constants of type x86_mmx and x86_amx.
4150 .. _complexconstants:
4155 Complex constants are a (potentially recursive) combination of simple
4156 constants and smaller complex constants.
4158 **Structure constants**
4159 Structure constants are represented with notation similar to
4160 structure type definitions (a comma separated list of elements,
4161 surrounded by braces (``{}``)). For example:
4162 "``{ i32 4, float 17.0, ptr @G }``", where "``@G``" is declared as
4163 "``@G = external global i32``". Structure constants must have
4164 :ref:`structure type <t_struct>`, and the number and types of elements
4165 must match those specified by the type.
4167 Array constants are represented with notation similar to array type
4168 definitions (a comma separated list of elements, surrounded by
4169 square brackets (``[]``)). For example:
4170 "``[ i32 42, i32 11, i32 74 ]``". Array constants must have
4171 :ref:`array type <t_array>`, and the number and types of elements must
4172 match those specified by the type. As a special case, character array
4173 constants may also be represented as a double-quoted string using the ``c``
4174 prefix. For example: "``c"Hello World\0A\00"``".
4175 **Vector constants**
4176 Vector constants are represented with notation similar to vector
4177 type definitions (a comma separated list of elements, surrounded by
4178 less-than/greater-than's (``<>``)). For example:
4179 "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants
4180 must have :ref:`vector type <t_vector>`, and the number and types of
4181 elements must match those specified by the type.
4182 **Zero initialization**
4183 The string '``zeroinitializer``' can be used to zero initialize a
4184 value to zero of *any* type, including scalar and
4185 :ref:`aggregate <t_aggregate>` types. This is often used to avoid
4186 having to print large zero initializers (e.g. for large arrays) and
4187 is always exactly equivalent to using explicit zero initializers.
4189 A metadata node is a constant tuple without types. For example:
4190 "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values,
4191 for example: "``!{!0, i32 0, ptr @global, ptr @function, !"str"}``".
4192 Unlike other typed constants that are meant to be interpreted as part of
4193 the instruction stream, metadata is a place to attach additional
4194 information such as debug info.
4196 Global Variable and Function Addresses
4197 --------------------------------------
4199 The addresses of :ref:`global variables <globalvars>` and
4200 :ref:`functions <functionstructure>` are always implicitly valid
4201 (link-time) constants. These constants are explicitly referenced when
4202 the :ref:`identifier for the global <identifiers>` is used and always have
4203 :ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM
4206 .. code-block:: llvm
4210 @Z = global [2 x ptr] [ ptr @X, ptr @Y ]
4217 The string '``undef``' can be used anywhere a constant is expected, and
4218 indicates that the user of the value may receive an unspecified
4219 bit-pattern. Undefined values may be of any type (other than '``label``'
4220 or '``void``') and be used anywhere a constant is permitted.
4224 A '``poison``' value (described in the next section) should be used instead of
4225 '``undef``' whenever possible. Poison values are stronger than undef, and
4226 enable more optimizations. Just the existence of '``undef``' blocks certain
4227 optimizations (see the examples below).
4229 Undefined values are useful because they indicate to the compiler that
4230 the program is well defined no matter what value is used. This gives the
4231 compiler more freedom to optimize. Here are some examples of
4232 (potentially surprising) transformations that are valid (in pseudo IR):
4234 .. code-block:: llvm
4244 This is safe because all of the output bits are affected by the undef
4245 bits. Any output bit can have a zero or one depending on the input bits.
4247 .. code-block:: llvm
4255 %A = %X ;; By choosing undef as 0
4256 %B = %X ;; By choosing undef as -1
4261 These logical operations have bits that are not always affected by the
4262 input. For example, if ``%X`` has a zero bit, then the output of the
4263 '``and``' operation will always be a zero for that bit, no matter what
4264 the corresponding bit from the '``undef``' is. As such, it is unsafe to
4265 optimize or assume that the result of the '``and``' is '``undef``'.
4266 However, it is safe to assume that all bits of the '``undef``' could be
4267 0, and optimize the '``and``' to 0. Likewise, it is safe to assume that
4268 all the bits of the '``undef``' operand to the '``or``' could be set,
4269 allowing the '``or``' to be folded to -1.
4271 .. code-block:: llvm
4273 %A = select undef, %X, %Y
4274 %B = select undef, 42, %Y
4275 %C = select %X, %Y, undef
4279 %C = %Y (if %Y is provably not poison; unsafe otherwise)
4285 This set of examples shows that undefined '``select``' (and conditional
4286 branch) conditions can go *either way*, but they have to come from one
4287 of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were
4288 both known to have a clear low bit, then ``%A`` would have to have a
4289 cleared low bit. However, in the ``%C`` example, the optimizer is
4290 allowed to assume that the '``undef``' operand could be the same as
4291 ``%Y`` if ``%Y`` is provably not '``poison``', allowing the whole '``select``'
4292 to be eliminated. This is because '``poison``' is stronger than '``undef``'.
4294 .. code-block:: llvm
4296 %A = xor undef, undef
4313 This example points out that two '``undef``' operands are not
4314 necessarily the same. This can be surprising to people (and also matches
4315 C semantics) where they assume that "``X^X``" is always zero, even if
4316 ``X`` is undefined. This isn't true for a number of reasons, but the
4317 short answer is that an '``undef``' "variable" can arbitrarily change
4318 its value over its "live range". This is true because the variable
4319 doesn't actually *have a live range*. Instead, the value is logically
4320 read from arbitrary registers that happen to be around when needed, so
4321 the value is not necessarily consistent over time. In fact, ``%A`` and
4322 ``%C`` need to have the same semantics or the core LLVM "replace all
4323 uses with" concept would not hold.
4325 To ensure all uses of a given register observe the same value (even if
4326 '``undef``'), the :ref:`freeze instruction <i_freeze>` can be used.
4328 .. code-block:: llvm
4336 These examples show the crucial difference between an *undefined value*
4337 and *undefined behavior*. An undefined value (like '``undef``') is
4338 allowed to have an arbitrary bit-pattern. This means that the ``%A``
4339 operation can be constant folded to '``0``', because the '``undef``'
4340 could be zero, and zero divided by any value is zero.
4341 However, in the second example, we can make a more aggressive
4342 assumption: because the ``undef`` is allowed to be an arbitrary value,
4343 we are allowed to assume that it could be zero. Since a divide by zero
4344 has *undefined behavior*, we are allowed to assume that the operation
4345 does not execute at all. This allows us to delete the divide and all
4346 code after it. Because the undefined operation "can't happen", the
4347 optimizer can assume that it occurs in dead code.
4349 .. code-block:: text
4351 a: store undef -> %X
4352 b: store %X -> undef
4354 a: <deleted> (if the stored value in %X is provably not poison)
4357 A store *of* an undefined value can be assumed to not have any effect;
4358 we can assume that the value is overwritten with bits that happen to
4359 match what was already there. This argument is only valid if the stored value
4360 is provably not ``poison``. However, a store *to* an undefined
4361 location could clobber arbitrary memory, therefore, it has undefined
4364 Branching on an undefined value is undefined behavior.
4365 This explains optimizations that depend on branch conditions to construct
4366 predicates, such as Correlated Value Propagation and Global Value Numbering.
4367 In case of switch instruction, the branch condition should be frozen, otherwise
4368 it is undefined behavior.
4370 .. code-block:: llvm
4373 br undef, BB1, BB2 ; UB
4375 %X = and i32 undef, 255
4376 switch %X, label %ret [ .. ] ; UB
4378 store undef, ptr %ptr
4379 %X = load ptr %ptr ; %X is undef
4380 switch i8 %X, label %ret [ .. ] ; UB
4383 %X = or i8 undef, 255 ; always 255
4384 switch i8 %X, label %ret [ .. ] ; Well-defined
4386 %X = freeze i1 undef
4387 br %X, BB1, BB2 ; Well-defined (non-deterministic jump)
4396 A poison value is a result of an erroneous operation.
4397 In order to facilitate speculative execution, many instructions do not
4398 invoke immediate undefined behavior when provided with illegal operands,
4399 and return a poison value instead.
4400 The string '``poison``' can be used anywhere a constant is expected, and
4401 operations such as :ref:`add <i_add>` with the ``nsw`` flag can produce
4404 Most instructions return '``poison``' when one of their arguments is
4405 '``poison``'. A notable exception is the :ref:`select instruction <i_select>`.
4406 Propagation of poison can be stopped with the
4407 :ref:`freeze instruction <i_freeze>`.
4409 It is correct to replace a poison value with an
4410 :ref:`undef value <undefvalues>` or any value of the type.
4412 This means that immediate undefined behavior occurs if a poison value is
4413 used as an instruction operand that has any values that trigger undefined
4414 behavior. Notably this includes (but is not limited to):
4416 - The pointer operand of a :ref:`load <i_load>`, :ref:`store <i_store>` or
4417 any other pointer dereferencing instruction (independent of address
4419 - The divisor operand of a ``udiv``, ``sdiv``, ``urem`` or ``srem``
4421 - The condition operand of a :ref:`br <i_br>` instruction.
4422 - The callee operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
4424 - The parameter operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
4425 instruction, when the function or invoking call site has a ``noundef``
4426 attribute in the corresponding position.
4427 - The operand of a :ref:`ret <i_ret>` instruction if the function or invoking
4428 call site has a `noundef` attribute in the return value position.
4430 Here are some examples:
4432 .. code-block:: llvm
4435 %poison = sub nuw i32 0, 1 ; Results in a poison value.
4436 %poison2 = sub i32 poison, 1 ; Also results in a poison value.
4437 %still_poison = and i32 %poison, 0 ; 0, but also poison.
4438 %poison_yet_again = getelementptr i32, ptr @h, i32 %still_poison
4439 store i32 0, ptr %poison_yet_again ; Undefined behavior due to
4442 store i32 %poison, ptr @g ; Poison value stored to memory.
4443 %poison3 = load i32, ptr @g ; Poison value loaded back from memory.
4445 %poison4 = load i16, ptr @g ; Returns a poison value.
4446 %poison5 = load i64, ptr @g ; Returns a poison value.
4448 %cmp = icmp slt i32 %poison, 0 ; Returns a poison value.
4449 br i1 %cmp, label %end, label %end ; undefined behavior
4453 .. _welldefinedvalues:
4458 Given a program execution, a value is *well defined* if the value does not
4459 have an undef bit and is not poison in the execution.
4460 An aggregate value or vector is well defined if its elements are well defined.
4461 The padding of an aggregate isn't considered, since it isn't visible
4462 without storing it into memory and loading it with a different type.
4464 A constant of a :ref:`single value <t_single_value>`, non-vector type is well
4465 defined if it is neither '``undef``' constant nor '``poison``' constant.
4466 The result of :ref:`freeze instruction <i_freeze>` is well defined regardless
4471 Addresses of Basic Blocks
4472 -------------------------
4474 ``blockaddress(@function, %block)``
4476 The '``blockaddress``' constant computes the address of the specified
4477 basic block in the specified function.
4479 It always has an ``ptr addrspace(P)`` type, where ``P`` is the address space
4480 of the function containing ``%block`` (usually ``addrspace(0)``).
4482 Taking the address of the entry block is illegal.
4484 This value only has defined behavior when used as an operand to the
4485 ':ref:`indirectbr <i_indirectbr>`' or for comparisons against null. Pointer
4486 equality tests between labels addresses results in undefined behavior ---
4487 though, again, comparison against null is ok, and no label is equal to the null
4488 pointer. This may be passed around as an opaque pointer sized value as long as
4489 the bits are not inspected. This allows ``ptrtoint`` and arithmetic to be
4490 performed on these values so long as the original value is reconstituted before
4491 the ``indirectbr`` instruction.
4493 Finally, some targets may provide defined semantics when using the value
4494 as the operand to an inline assembly, but that is target specific.
4496 .. _dso_local_equivalent:
4498 DSO Local Equivalent
4499 --------------------
4501 ``dso_local_equivalent @func``
4503 A '``dso_local_equivalent``' constant represents a function which is
4504 functionally equivalent to a given function, but is always defined in the
4505 current linkage unit. The resulting pointer has the same type as the underlying
4506 function. The resulting pointer is permitted, but not required, to be different
4507 from a pointer to the function, and it may have different values in different
4510 The target function may not have ``extern_weak`` linkage.
4512 ``dso_local_equivalent`` can be implemented as such:
4514 - If the function has local linkage, hidden visibility, or is
4515 ``dso_local``, ``dso_local_equivalent`` can be implemented as simply a pointer
4517 - ``dso_local_equivalent`` can be implemented with a stub that tail-calls the
4518 function. Many targets support relocations that resolve at link time to either
4519 a function or a stub for it, depending on if the function is defined within the
4520 linkage unit; LLVM will use this when available. (This is commonly called a
4521 "PLT stub".) On other targets, the stub may need to be emitted explicitly.
4523 This can be used wherever a ``dso_local`` instance of a function is needed without
4524 needing to explicitly make the original function ``dso_local``. An instance where
4525 this can be used is for static offset calculations between a function and some other
4526 ``dso_local`` symbol. This is especially useful for the Relative VTables C++ ABI,
4527 where dynamic relocations for function pointers in VTables can be replaced with
4528 static relocations for offsets between the VTable and virtual functions which
4529 may not be ``dso_local``.
4531 This is currently only supported for ELF binary formats.
4540 With `Control-Flow Integrity (CFI)
4541 <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, a '``no_cfi``'
4542 constant represents a function reference that does not get replaced with a
4543 reference to the CFI jump table in the ``LowerTypeTests`` pass. These constants
4544 may be useful in low-level programs, such as operating system kernels, which
4545 need to refer to the actual function body.
4549 Constant Expressions
4550 --------------------
4552 Constant expressions are used to allow expressions involving other
4553 constants to be used as constants. Constant expressions may be of any
4554 :ref:`first class <t_firstclass>` type and may involve any LLVM operation
4555 that does not have side effects (e.g. load and call are not supported).
4556 The following is the syntax for constant expressions:
4558 ``trunc (CST to TYPE)``
4559 Perform the :ref:`trunc operation <i_trunc>` on constants.
4560 ``zext (CST to TYPE)``
4561 Perform the :ref:`zext operation <i_zext>` on constants.
4562 ``sext (CST to TYPE)``
4563 Perform the :ref:`sext operation <i_sext>` on constants.
4564 ``fptrunc (CST to TYPE)``
4565 Truncate a floating-point constant to another floating-point type.
4566 The size of CST must be larger than the size of TYPE. Both types
4567 must be floating-point.
4568 ``fpext (CST to TYPE)``
4569 Floating-point extend a constant to another type. The size of CST
4570 must be smaller or equal to the size of TYPE. Both types must be
4572 ``fptoui (CST to TYPE)``
4573 Convert a floating-point constant to the corresponding unsigned
4574 integer constant. TYPE must be a scalar or vector integer type. CST
4575 must be of scalar or vector floating-point type. Both CST and TYPE
4576 must be scalars, or vectors of the same number of elements. If the
4577 value won't fit in the integer type, the result is a
4578 :ref:`poison value <poisonvalues>`.
4579 ``fptosi (CST to TYPE)``
4580 Convert a floating-point constant to the corresponding signed
4581 integer constant. TYPE must be a scalar or vector integer type. CST
4582 must be of scalar or vector floating-point type. Both CST and TYPE
4583 must be scalars, or vectors of the same number of elements. If the
4584 value won't fit in the integer type, the result is a
4585 :ref:`poison value <poisonvalues>`.
4586 ``uitofp (CST to TYPE)``
4587 Convert an unsigned integer constant to the corresponding
4588 floating-point constant. TYPE must be a scalar or vector floating-point
4589 type. CST must be of scalar or vector integer type. Both CST and TYPE must
4590 be scalars, or vectors of the same number of elements.
4591 ``sitofp (CST to TYPE)``
4592 Convert a signed integer constant to the corresponding floating-point
4593 constant. TYPE must be a scalar or vector floating-point type.
4594 CST must be of scalar or vector integer type. Both CST and TYPE must
4595 be scalars, or vectors of the same number of elements.
4596 ``ptrtoint (CST to TYPE)``
4597 Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants.
4598 ``inttoptr (CST to TYPE)``
4599 Perform the :ref:`inttoptr operation <i_inttoptr>` on constants.
4600 This one is *really* dangerous!
4601 ``bitcast (CST to TYPE)``
4602 Convert a constant, CST, to another TYPE.
4603 The constraints of the operands are the same as those for the
4604 :ref:`bitcast instruction <i_bitcast>`.
4605 ``addrspacecast (CST to TYPE)``
4606 Convert a constant pointer or constant vector of pointer, CST, to another
4607 TYPE in a different address space. The constraints of the operands are the
4608 same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`.
4609 ``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)``
4610 Perform the :ref:`getelementptr operation <i_getelementptr>` on
4611 constants. As with the :ref:`getelementptr <i_getelementptr>`
4612 instruction, the index list may have one or more indexes, which are
4613 required to make sense for the type of "pointer to TY". These indexes
4614 may be implicitly sign-extended or truncated to match the index size
4615 of CSTPTR's address space.
4616 ``icmp COND (VAL1, VAL2)``
4617 Perform the :ref:`icmp operation <i_icmp>` on constants.
4618 ``fcmp COND (VAL1, VAL2)``
4619 Perform the :ref:`fcmp operation <i_fcmp>` on constants.
4620 ``extractelement (VAL, IDX)``
4621 Perform the :ref:`extractelement operation <i_extractelement>` on
4623 ``insertelement (VAL, ELT, IDX)``
4624 Perform the :ref:`insertelement operation <i_insertelement>` on
4626 ``shufflevector (VEC1, VEC2, IDXMASK)``
4627 Perform the :ref:`shufflevector operation <i_shufflevector>` on
4630 Perform an addition on constants.
4632 Perform a subtraction on constants.
4634 Perform a multiplication on constants.
4636 Perform a left shift on constants.
4638 Perform a logical right shift on constants.
4640 Perform an arithmetic right shift on constants.
4642 Perform a bitwise xor on constants.
4649 Inline Assembler Expressions
4650 ----------------------------
4652 LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level
4653 Inline Assembly <moduleasm>`) through the use of a special value. This value
4654 represents the inline assembler as a template string (containing the
4655 instructions to emit), a list of operand constraints (stored as a string), a
4656 flag that indicates whether or not the inline asm expression has side effects,
4657 and a flag indicating whether the function containing the asm needs to align its
4658 stack conservatively.
4660 The template string supports argument substitution of the operands using "``$``"
4661 followed by a number, to indicate substitution of the given register/memory
4662 location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also
4663 be used, where ``MODIFIER`` is a target-specific annotation for how to print the
4664 operand (See :ref:`inline-asm-modifiers`).
4666 A literal "``$``" may be included by using "``$$``" in the template. To include
4667 other special characters into the output, the usual "``\XX``" escapes may be
4668 used, just as in other strings. Note that after template substitution, the
4669 resulting assembly string is parsed by LLVM's integrated assembler unless it is
4670 disabled -- even when emitting a ``.s`` file -- and thus must contain assembly
4671 syntax known to LLVM.
4673 LLVM also supports a few more substitutions useful for writing inline assembly:
4675 - ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob.
4676 This substitution is useful when declaring a local label. Many standard
4677 compiler optimizations, such as inlining, may duplicate an inline asm blob.
4678 Adding a blob-unique identifier ensures that the two labels will not conflict
4679 during assembly. This is used to implement `GCC's %= special format
4680 string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_.
4681 - ``${:comment}``: Expands to the comment character of the current target's
4682 assembly dialect. This is usually ``#``, but many targets use other strings,
4683 such as ``;``, ``//``, or ``!``.
4684 - ``${:private}``: Expands to the assembler private label prefix. Labels with
4685 this prefix will not appear in the symbol table of the assembled object.
4686 Typically the prefix is ``L``, but targets may use other strings. ``.L`` is
4689 LLVM's support for inline asm is modeled closely on the requirements of Clang's
4690 GCC-compatible inline-asm support. Thus, the feature-set and the constraint and
4691 modifier codes listed here are similar or identical to those in GCC's inline asm
4692 support. However, to be clear, the syntax of the template and constraint strings
4693 described here is *not* the same as the syntax accepted by GCC and Clang, and,
4694 while most constraint letters are passed through as-is by Clang, some get
4695 translated to other codes when converting from the C source to the LLVM
4698 An example inline assembler expression is:
4700 .. code-block:: llvm
4702 i32 (i32) asm "bswap $0", "=r,r"
4704 Inline assembler expressions may **only** be used as the callee operand
4705 of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction.
4706 Thus, typically we have:
4708 .. code-block:: llvm
4710 %X = call i32 asm "bswap $0", "=r,r"(i32 %Y)
4712 Inline asms with side effects not visible in the constraint list must be
4713 marked as having side effects. This is done through the use of the
4714 '``sideeffect``' keyword, like so:
4716 .. code-block:: llvm
4718 call void asm sideeffect "eieio", ""()
4720 In some cases inline asms will contain code that will not work unless
4721 the stack is aligned in some way, such as calls or SSE instructions on
4722 x86, yet will not contain code that does that alignment within the asm.
4723 The compiler should make conservative assumptions about what the asm
4724 might contain and should generate its usual stack alignment code in the
4725 prologue if the '``alignstack``' keyword is present:
4727 .. code-block:: llvm
4729 call void asm alignstack "eieio", ""()
4731 Inline asms also support using non-standard assembly dialects. The
4732 assumed dialect is ATT. When the '``inteldialect``' keyword is present,
4733 the inline asm is using the Intel dialect. Currently, ATT and Intel are
4734 the only supported dialects. An example is:
4736 .. code-block:: llvm
4738 call void asm inteldialect "eieio", ""()
4740 In the case that the inline asm might unwind the stack,
4741 the '``unwind``' keyword must be used, so that the compiler emits
4742 unwinding information:
4744 .. code-block:: llvm
4746 call void asm unwind "call func", ""()
4748 If the inline asm unwinds the stack and isn't marked with
4749 the '``unwind``' keyword, the behavior is undefined.
4751 If multiple keywords appear, the '``sideeffect``' keyword must come
4752 first, the '``alignstack``' keyword second, the '``inteldialect``' keyword
4753 third and the '``unwind``' keyword last.
4755 Inline Asm Constraint String
4756 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4758 The constraint list is a comma-separated string, each element containing one or
4759 more constraint codes.
4761 For each element in the constraint list an appropriate register or memory
4762 operand will be chosen, and it will be made available to assembly template
4763 string expansion as ``$0`` for the first constraint in the list, ``$1`` for the
4766 There are three different types of constraints, which are distinguished by a
4767 prefix symbol in front of the constraint code: Output, Input, and Clobber. The
4768 constraints must always be given in that order: outputs first, then inputs, then
4769 clobbers. They cannot be intermingled.
4771 There are also three different categories of constraint codes:
4773 - Register constraint. This is either a register class, or a fixed physical
4774 register. This kind of constraint will allocate a register, and if necessary,
4775 bitcast the argument or result to the appropriate type.
4776 - Memory constraint. This kind of constraint is for use with an instruction
4777 taking a memory operand. Different constraints allow for different addressing
4778 modes used by the target.
4779 - Immediate value constraint. This kind of constraint is for an integer or other
4780 immediate value which can be rendered directly into an instruction. The
4781 various target-specific constraints allow the selection of a value in the
4782 proper range for the instruction you wish to use it with.
4787 Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This
4788 indicates that the assembly will write to this operand, and the operand will
4789 then be made available as a return value of the ``asm`` expression. Output
4790 constraints do not consume an argument from the call instruction. (Except, see
4791 below about indirect outputs).
4793 Normally, it is expected that no output locations are written to by the assembly
4794 expression until *all* of the inputs have been read. As such, LLVM may assign
4795 the same register to an output and an input. If this is not safe (e.g. if the
4796 assembly contains two instructions, where the first writes to one output, and
4797 the second reads an input and writes to a second output), then the "``&``"
4798 modifier must be used (e.g. "``=&r``") to specify that the output is an
4799 "early-clobber" output. Marking an output as "early-clobber" ensures that LLVM
4800 will not use the same register for any inputs (other than an input tied to this
4806 Input constraints do not have a prefix -- just the constraint codes. Each input
4807 constraint will consume one argument from the call instruction. It is not
4808 permitted for the asm to write to any input register or memory location (unless
4809 that input is tied to an output). Note also that multiple inputs may all be
4810 assigned to the same register, if LLVM can determine that they necessarily all
4811 contain the same value.
4813 Instead of providing a Constraint Code, input constraints may also "tie"
4814 themselves to an output constraint, by providing an integer as the constraint
4815 string. Tied inputs still consume an argument from the call instruction, and
4816 take up a position in the asm template numbering as is usual -- they will simply
4817 be constrained to always use the same register as the output they've been tied
4818 to. For example, a constraint string of "``=r,0``" says to assign a register for
4819 output, and use that register as an input as well (it being the 0'th
4822 It is permitted to tie an input to an "early-clobber" output. In that case, no
4823 *other* input may share the same register as the input tied to the early-clobber
4824 (even when the other input has the same value).
4826 You may only tie an input to an output which has a register constraint, not a
4827 memory constraint. Only a single input may be tied to an output.
4829 There is also an "interesting" feature which deserves a bit of explanation: if a
4830 register class constraint allocates a register which is too small for the value
4831 type operand provided as input, the input value will be split into multiple
4832 registers, and all of them passed to the inline asm.
4834 However, this feature is often not as useful as you might think.
4836 Firstly, the registers are *not* guaranteed to be consecutive. So, on those
4837 architectures that have instructions which operate on multiple consecutive
4838 instructions, this is not an appropriate way to support them. (e.g. the 32-bit
4839 SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The
4840 hardware then loads into both the named register, and the next register. This
4841 feature of inline asm would not be useful to support that.)
4843 A few of the targets provide a template string modifier allowing explicit access
4844 to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and
4845 ``D``). On such an architecture, you can actually access the second allocated
4846 register (yet, still, not any subsequent ones). But, in that case, you're still
4847 probably better off simply splitting the value into two separate operands, for
4848 clarity. (e.g. see the description of the ``A`` constraint on X86, which,
4849 despite existing only for use with this feature, is not really a good idea to
4852 Indirect inputs and outputs
4853 """""""""""""""""""""""""""
4855 Indirect output or input constraints can be specified by the "``*``" modifier
4856 (which goes after the "``=``" in case of an output). This indicates that the asm
4857 will write to or read from the contents of an *address* provided as an input
4858 argument. (Note that in this way, indirect outputs act more like an *input* than
4859 an output: just like an input, they consume an argument of the call expression,
4860 rather than producing a return value. An indirect output constraint is an
4861 "output" only in that the asm is expected to write to the contents of the input
4862 memory location, instead of just read from it).
4864 This is most typically used for memory constraint, e.g. "``=*m``", to pass the
4865 address of a variable as a value.
4867 It is also possible to use an indirect *register* constraint, but only on output
4868 (e.g. "``=*r``"). This will cause LLVM to allocate a register for an output
4869 value normally, and then, separately emit a store to the address provided as
4870 input, after the provided inline asm. (It's not clear what value this
4871 functionality provides, compared to writing the store explicitly after the asm
4872 statement, and it can only produce worse code, since it bypasses many
4873 optimization passes. I would recommend not using it.)
4875 Call arguments for indirect constraints must have pointer type and must specify
4876 the :ref:`elementtype <attr_elementtype>` attribute to indicate the pointer
4882 A clobber constraint is indicated by a "``~``" prefix. A clobber does not
4883 consume an input operand, nor generate an output. Clobbers cannot use any of the
4884 general constraint code letters -- they may use only explicit register
4885 constraints, e.g. "``~{eax}``". The one exception is that a clobber string of
4886 "``~{memory}``" indicates that the assembly writes to arbitrary undeclared
4887 memory locations -- not only the memory pointed to by a declared indirect
4890 Note that clobbering named registers that are also present in output
4891 constraints is not legal.
4896 A label constraint is indicated by a "``!``" prefix and typically used in the
4897 form ``"!i"``. Instead of consuming call arguments, label constraints consume
4898 indirect destination labels of ``callbr`` instructions.
4900 Label constraints can only be used in conjunction with ``callbr`` and the
4901 number of label constraints must match the number of indirect destination
4902 labels in the ``callbr`` instruction.
4907 After a potential prefix comes constraint code, or codes.
4909 A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character
4910 followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``"
4913 The one and two letter constraint codes are typically chosen to be the same as
4914 GCC's constraint codes.
4916 A single constraint may include one or more than constraint code in it, leaving
4917 it up to LLVM to choose which one to use. This is included mainly for
4918 compatibility with the translation of GCC inline asm coming from clang.
4920 There are two ways to specify alternatives, and either or both may be used in an
4921 inline asm constraint list:
4923 1) Append the codes to each other, making a constraint code set. E.g. "``im``"
4924 or "``{eax}m``". This means "choose any of the options in the set". The
4925 choice of constraint is made independently for each constraint in the
4928 2) Use "``|``" between constraint code sets, creating alternatives. Every
4929 constraint in the constraint list must have the same number of alternative
4930 sets. With this syntax, the same alternative in *all* of the items in the
4931 constraint list will be chosen together.
4933 Putting those together, you might have a two operand constraint string like
4934 ``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then
4935 operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1
4936 may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m.
4938 However, the use of either of the alternatives features is *NOT* recommended, as
4939 LLVM is not able to make an intelligent choice about which one to use. (At the
4940 point it currently needs to choose, not enough information is available to do so
4941 in a smart way.) Thus, it simply tries to make a choice that's most likely to
4942 compile, not one that will be optimal performance. (e.g., given "``rm``", it'll
4943 always choose to use memory, not registers). And, if given multiple registers,
4944 or multiple register classes, it will simply choose the first one. (In fact, it
4945 doesn't currently even ensure explicitly specified physical registers are
4946 unique, so specifying multiple physical registers as alternatives, like
4947 ``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was
4950 Supported Constraint Code List
4951 """"""""""""""""""""""""""""""
4953 The constraint codes are, in general, expected to behave the same way they do in
4954 GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
4955 inline asm code which was supported by GCC. A mismatch in behavior between LLVM
4956 and GCC likely indicates a bug in LLVM.
4958 Some constraint codes are typically supported by all targets:
4960 - ``r``: A register in the target's general purpose register class.
4961 - ``m``: A memory address operand. It is target-specific what addressing modes
4962 are supported, typical examples are register, or register + register offset,
4963 or register + immediate offset (of some target-specific size).
4964 - ``p``: An address operand. Similar to ``m``, but used by "load address"
4965 type instructions without touching memory.
4966 - ``i``: An integer constant (of target-specific width). Allows either a simple
4967 immediate, or a relocatable value.
4968 - ``n``: An integer constant -- *not* including relocatable values.
4969 - ``s``: An integer constant, but allowing *only* relocatable values.
4970 - ``X``: Allows an operand of any kind, no constraint whatsoever. Typically
4971 useful to pass a label for an asm branch or call.
4973 .. FIXME: but that surely isn't actually okay to jump out of an asm
4974 block without telling llvm about the control transfer???)
4976 - ``{register-name}``: Requires exactly the named physical register.
4978 Other constraints are target-specific:
4982 - ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate.
4983 - ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction,
4984 i.e. 0 to 4095 with optional shift by 12.
4985 - ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or
4986 ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12.
4987 - ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a
4988 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register.
4989 - ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a
4990 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register.
4991 - ``M``: An immediate integer for use with the ``MOV`` assembly alias on a
4992 32-bit register. This is a superset of ``K``: in addition to the bitmask
4993 immediate, also allows immediate integers which can be loaded with a single
4994 ``MOVZ`` or ``MOVL`` instruction.
4995 - ``N``: An immediate integer for use with the ``MOV`` assembly alias on a
4996 64-bit register. This is a superset of ``L``.
4997 - ``Q``: Memory address operand must be in a single register (no
4998 offsets). (However, LLVM currently does this for the ``m`` constraint as
5000 - ``r``: A 32 or 64-bit integer register (W* or X*).
5001 - ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register.
5002 - ``x``: Like w, but restricted to registers 0 to 15 inclusive.
5003 - ``y``: Like w, but restricted to SVE vector registers Z0 to Z7 inclusive.
5004 - ``Uph``: One of the upper eight SVE predicate registers (P8 to P15)
5005 - ``Upl``: One of the lower eight SVE predicate registers (P0 to P7)
5006 - ``Upa``: Any of the SVE predicate registers (P0 to P15)
5010 - ``r``: A 32 or 64-bit integer register.
5011 - ``[0-9]v``: The 32-bit VGPR register, number 0-9.
5012 - ``[0-9]s``: The 32-bit SGPR register, number 0-9.
5013 - ``[0-9]a``: The 32-bit AGPR register, number 0-9.
5014 - ``I``: An integer inline constant in the range from -16 to 64.
5015 - ``J``: A 16-bit signed integer constant.
5016 - ``A``: An integer or a floating-point inline constant.
5017 - ``B``: A 32-bit signed integer constant.
5018 - ``C``: A 32-bit unsigned integer constant or an integer inline constant in the range from -16 to 64.
5019 - ``DA``: A 64-bit constant that can be split into two "A" constants.
5020 - ``DB``: A 64-bit constant that can be split into two "B" constants.
5024 - ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address
5025 operand. Treated the same as operand ``m``, at the moment.
5026 - ``Te``: An even general-purpose 32-bit integer register: ``r0,r2,...,r12,r14``
5027 - ``To``: An odd general-purpose 32-bit integer register: ``r1,r3,...,r11``
5029 ARM and ARM's Thumb2 mode:
5031 - ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``)
5032 - ``I``: An immediate integer valid for a data-processing instruction.
5033 - ``J``: An immediate integer between -4095 and 4095.
5034 - ``K``: An immediate integer whose bitwise inverse is valid for a
5035 data-processing instruction. (Can be used with template modifier "``B``" to
5036 print the inverted value).
5037 - ``L``: An immediate integer whose negation is valid for a data-processing
5038 instruction. (Can be used with template modifier "``n``" to print the negated
5040 - ``M``: A power of two or an integer between 0 and 32.
5041 - ``N``: Invalid immediate constraint.
5042 - ``O``: Invalid immediate constraint.
5043 - ``r``: A general-purpose 32-bit integer register (``r0-r15``).
5044 - ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same
5046 - ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode,
5048 - ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
5049 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively.
5050 - ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
5051 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively.
5052 - ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
5053 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively.
5057 - ``I``: An immediate integer between 0 and 255.
5058 - ``J``: An immediate integer between -255 and -1.
5059 - ``K``: An immediate integer between 0 and 255, with optional left-shift by
5061 - ``L``: An immediate integer between -7 and 7.
5062 - ``M``: An immediate integer which is a multiple of 4 between 0 and 1020.
5063 - ``N``: An immediate integer between 0 and 31.
5064 - ``O``: An immediate integer which is a multiple of 4 between -508 and 508.
5065 - ``r``: A low 32-bit GPR register (``r0-r7``).
5066 - ``l``: A low 32-bit GPR register (``r0-r7``).
5067 - ``h``: A high GPR register (``r0-r7``).
5068 - ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
5069 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively.
5070 - ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
5071 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively.
5072 - ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
5073 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively.
5077 - ``o``, ``v``: A memory address operand, treated the same as constraint ``m``,
5079 - ``r``: A 32 or 64-bit register.
5083 - ``f``: A floating-point register (if available).
5084 - ``k``: A memory operand whose address is formed by a base register and
5085 (optionally scaled) index register.
5086 - ``l``: A signed 16-bit constant.
5087 - ``m``: A memory operand whose address is formed by a base register and
5088 offset that is suitable for use in instructions with the same addressing
5089 mode as st.w and ld.w.
5090 - ``I``: A signed 12-bit constant (for arithmetic instructions).
5091 - ``J``: An immediate integer zero.
5092 - ``K``: An unsigned 12-bit constant (for logic instructions).
5093 - ``ZB``: An address that is held in a general-purpose register. The offset
5095 - ``ZC``: A memory operand whose address is formed by a base register and
5096 offset that is suitable for use in instructions with the same addressing
5097 mode as ll.w and sc.w.
5101 - ``r``: An 8 or 16-bit register.
5105 - ``I``: An immediate signed 16-bit integer.
5106 - ``J``: An immediate integer zero.
5107 - ``K``: An immediate unsigned 16-bit integer.
5108 - ``L``: An immediate 32-bit integer, where the lower 16 bits are 0.
5109 - ``N``: An immediate integer between -65535 and -1.
5110 - ``O``: An immediate signed 15-bit integer.
5111 - ``P``: An immediate integer between 1 and 65535.
5112 - ``m``: A memory address operand. In MIPS-SE mode, allows a base address
5113 register plus 16-bit immediate offset. In MIPS mode, just a base register.
5114 - ``R``: A memory address operand. In MIPS-SE mode, allows a base address
5115 register plus a 9-bit signed offset. In MIPS mode, the same as constraint
5117 - ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or
5118 ``sc`` instruction on the given subtarget (details vary).
5119 - ``r``, ``d``, ``y``: A 32 or 64-bit GPR register.
5120 - ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register
5121 (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w``
5122 argument modifier for compatibility with GCC.
5123 - ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always
5125 - ``l``: The ``lo`` register, 32 or 64-bit.
5130 - ``b``: A 1-bit integer register.
5131 - ``c`` or ``h``: A 16-bit integer register.
5132 - ``r``: A 32-bit integer register.
5133 - ``l`` or ``N``: A 64-bit integer register.
5134 - ``f``: A 32-bit float register.
5135 - ``d``: A 64-bit float register.
5140 - ``I``: An immediate signed 16-bit integer.
5141 - ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits.
5142 - ``K``: An immediate unsigned 16-bit integer.
5143 - ``L``: An immediate signed 16-bit integer, shifted left 16 bits.
5144 - ``M``: An immediate integer greater than 31.
5145 - ``N``: An immediate integer that is an exact power of 2.
5146 - ``O``: The immediate integer constant 0.
5147 - ``P``: An immediate integer constant whose negation is a signed 16-bit
5149 - ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently
5150 treated the same as ``m``.
5151 - ``r``: A 32 or 64-bit integer register.
5152 - ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is:
5154 - ``f``: A 32 or 64-bit float register (``F0-F31``),
5155 - ``v``: For ``4 x f32`` or ``4 x f64`` types, a 128-bit altivec vector
5156 register (``V0-V31``).
5158 - ``y``: Condition register (``CR0-CR7``).
5159 - ``wc``: An individual CR bit in a CR register.
5160 - ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX
5161 register set (overlapping both the floating-point and vector register files).
5162 - ``ws``: A 32 or 64-bit floating-point register, from the full VSX register
5167 - ``A``: An address operand (using a general-purpose register, without an
5169 - ``I``: A 12-bit signed integer immediate operand.
5170 - ``J``: A zero integer immediate operand.
5171 - ``K``: A 5-bit unsigned integer immediate operand.
5172 - ``f``: A 32- or 64-bit floating-point register (requires F or D extension).
5173 - ``r``: A 32- or 64-bit general-purpose register (depending on the platform
5175 - ``vr``: A vector register. (requires V extension).
5176 - ``vm``: A vector register for masking operand. (requires V extension).
5180 - ``I``: An immediate 13-bit signed integer.
5181 - ``r``: A 32-bit integer register.
5182 - ``f``: Any floating-point register on SparcV8, or a floating-point
5183 register in the "low" half of the registers on SparcV9.
5184 - ``e``: Any floating-point register. (Same as ``f`` on SparcV8.)
5188 - ``I``: An immediate unsigned 8-bit integer.
5189 - ``J``: An immediate unsigned 12-bit integer.
5190 - ``K``: An immediate signed 16-bit integer.
5191 - ``L``: An immediate signed 20-bit integer.
5192 - ``M``: An immediate integer 0x7fffffff.
5193 - ``Q``: A memory address operand with a base address and a 12-bit immediate
5194 unsigned displacement.
5195 - ``R``: A memory address operand with a base address, a 12-bit immediate
5196 unsigned displacement, and an index register.
5197 - ``S``: A memory address operand with a base address and a 20-bit immediate
5198 signed displacement.
5199 - ``T``: A memory address operand with a base address, a 20-bit immediate
5200 signed displacement, and an index register.
5201 - ``r`` or ``d``: A 32, 64, or 128-bit integer register.
5202 - ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an
5203 address context evaluates as zero).
5204 - ``h``: A 32-bit value in the high part of a 64bit data register
5206 - ``f``: A 32, 64, or 128-bit floating-point register.
5210 - ``I``: An immediate integer between 0 and 31.
5211 - ``J``: An immediate integer between 0 and 64.
5212 - ``K``: An immediate signed 8-bit integer.
5213 - ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only)
5215 - ``M``: An immediate integer between 0 and 3.
5216 - ``N``: An immediate unsigned 8-bit integer.
5217 - ``O``: An immediate integer between 0 and 127.
5218 - ``e``: An immediate 32-bit signed integer.
5219 - ``Z``: An immediate 32-bit unsigned integer.
5220 - ``o``, ``v``: Treated the same as ``m``, at the moment.
5221 - ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
5222 ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d``
5223 registers, and on X86-64, it is all of the integer registers.
5224 - ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
5225 ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers.
5226 - ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register.
5227 - ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has
5228 existed since i386, and can be accessed without the REX prefix.
5229 - ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register.
5230 - ``y``: A 64-bit MMX register, if MMX is enabled.
5231 - ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector
5232 operand in a SSE register. If AVX is also enabled, can also be a 256-bit
5233 vector operand in an AVX register. If AVX-512 is also enabled, can also be a
5234 512-bit vector operand in an AVX512 register, Otherwise, an error.
5235 - ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error.
5236 - ``A``: Special case: allocates EAX first, then EDX, for a single operand (in
5237 32-bit mode, a 64-bit integer operand will get split into two registers). It
5238 is not recommended to use this constraint, as in 64-bit mode, the 64-bit
5239 operand will get allocated only to RAX -- if two 32-bit operands are needed,
5240 you're better off splitting it yourself, before passing it to the asm
5245 - ``r``: A 32-bit integer register.
5248 .. _inline-asm-modifiers:
5250 Asm template argument modifiers
5251 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5253 In the asm template string, modifiers can be used on the operand reference, like
5256 The modifiers are, in general, expected to behave the same way they do in
5257 GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
5258 inline asm code which was supported by GCC. A mismatch in behavior between LLVM
5259 and GCC likely indicates a bug in LLVM.
5263 - ``c``: Print an immediate integer constant unadorned, without
5264 the target-specific immediate punctuation (e.g. no ``$`` prefix).
5265 - ``n``: Negate and print immediate integer constant unadorned, without the
5266 target-specific immediate punctuation (e.g. no ``$`` prefix).
5267 - ``l``: Print as an unadorned label, without the target-specific label
5268 punctuation (e.g. no ``$`` prefix).
5272 - ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g.,
5273 instead of ``x30``, print ``w30``.
5274 - ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow).
5275 - ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a
5276 ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of
5285 - ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a
5289 - ``y``: Print a VFP single-precision register as an indexed double (e.g. print
5290 as ``d4[1]`` instead of ``s9``)
5291 - ``B``: Bitwise invert and print an immediate integer constant without ``#``
5293 - ``L``: Print the low 16-bits of an immediate integer constant.
5294 - ``M``: Print as a register set suitable for ldm/stm. Also prints *all*
5295 register operands subsequent to the specified one (!), so use carefully.
5296 - ``Q``: Print the low-order register of a register-pair, or the low-order
5297 register of a two-register operand.
5298 - ``R``: Print the high-order register of a register-pair, or the high-order
5299 register of a two-register operand.
5300 - ``H``: Print the second register of a register-pair. (On a big-endian system,
5301 ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent
5304 .. FIXME: H doesn't currently support printing the second register
5305 of a two-register operand.
5307 - ``e``: Print the low doubleword register of a NEON quad register.
5308 - ``f``: Print the high doubleword register of a NEON quad register.
5309 - ``m``: Print the base register of a memory operand without the ``[`` and ``]``
5314 - ``L``: Print the second register of a two-register operand. Requires that it
5315 has been allocated consecutively to the first.
5317 .. FIXME: why is it restricted to consecutive ones? And there's
5318 nothing that ensures that happens, is there?
5320 - ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
5321 nothing. Used to print 'addi' vs 'add' instructions.
5325 - ``z``: Print $zero register if operand is zero, otherwise print it normally.
5329 No additional modifiers.
5333 - ``X``: Print an immediate integer as hexadecimal
5334 - ``x``: Print the low 16 bits of an immediate integer as hexadecimal.
5335 - ``d``: Print an immediate integer as decimal.
5336 - ``m``: Subtract one and print an immediate integer as decimal.
5337 - ``z``: Print $0 if an immediate zero, otherwise print normally.
5338 - ``L``: Print the low-order register of a two-register operand, or prints the
5339 address of the low-order word of a double-word memory operand.
5341 .. FIXME: L seems to be missing memory operand support.
5343 - ``M``: Print the high-order register of a two-register operand, or prints the
5344 address of the high-order word of a double-word memory operand.
5346 .. FIXME: M seems to be missing memory operand support.
5348 - ``D``: Print the second register of a two-register operand, or prints the
5349 second word of a double-word memory operand. (On a big-endian system, ``D`` is
5350 equivalent to ``L``, and on little-endian system, ``D`` is equivalent to
5352 - ``w``: No effect. Provided for compatibility with GCC which requires this
5353 modifier in order to print MSA registers (``W0-W31``) with the ``f``
5362 - ``L``: Print the second register of a two-register operand. Requires that it
5363 has been allocated consecutively to the first.
5365 .. FIXME: why is it restricted to consecutive ones? And there's
5366 nothing that ensures that happens, is there?
5368 - ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
5369 nothing. Used to print 'addi' vs 'add' instructions.
5370 - ``y``: For a memory operand, prints formatter for a two-register X-form
5371 instruction. (Currently always prints ``r0,OPERAND``).
5372 - ``U``: Prints 'u' if the memory operand is an update form, and nothing
5373 otherwise. (NOTE: LLVM does not support update form, so this will currently
5374 always print nothing)
5375 - ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does
5376 not support indexed form, so this will currently always print nothing)
5380 - ``i``: Print the letter 'i' if the operand is not a register, otherwise print
5381 nothing. Used to print 'addi' vs 'add' instructions, etc.
5382 - ``z``: Print the register ``zero`` if an immediate zero, otherwise print
5391 SystemZ implements only ``n``, and does *not* support any of the other
5392 target-independent modifiers.
5396 - ``c``: Print an unadorned integer or symbol name. (The latter is
5397 target-specific behavior for this typically target-independent modifier).
5398 - ``A``: Print a register name with a '``*``' before it.
5399 - ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory
5401 - ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a
5403 - ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory
5405 - ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory
5407 - ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are
5408 available, otherwise the 32-bit register name; do nothing on a memory operand.
5409 - ``n``: Negate and print an unadorned integer, or, for operands other than an
5410 immediate integer (e.g. a relocatable symbol expression), print a '-' before
5411 the operand. (The behavior for relocatable symbol expressions is a
5412 target-specific behavior for this typically target-independent modifier)
5413 - ``H``: Print a memory reference with additional offset +8.
5414 - ``P``: Print a memory reference used as the argument of a call instruction or
5415 used with explicit base reg and index reg as its offset. So it can not use
5416 additional regs to present the memory reference. (E.g. omit ``(rip)``, even
5417 though it's PC-relative.)
5421 No additional modifiers.
5427 The call instructions that wrap inline asm nodes may have a
5428 "``!srcloc``" MDNode attached to it that contains a list of constant
5429 integers. If present, the code generator will use the integer as the
5430 location cookie value when report errors through the ``LLVMContext``
5431 error reporting mechanisms. This allows a front-end to correlate backend
5432 errors that occur with inline asm back to the source code that produced
5435 .. code-block:: llvm
5437 call void asm sideeffect "something bad", ""(), !srcloc !42
5439 !42 = !{ i32 1234567 }
5441 It is up to the front-end to make sense of the magic numbers it places
5442 in the IR. If the MDNode contains multiple constants, the code generator
5443 will use the one that corresponds to the line of the asm that the error
5451 LLVM IR allows metadata to be attached to instructions and global objects in the
5452 program that can convey extra information about the code to the optimizers and
5453 code generator. One example application of metadata is source-level
5454 debug information. There are two metadata primitives: strings and nodes.
5456 Metadata does not have a type, and is not a value. If referenced from a
5457 ``call`` instruction, it uses the ``metadata`` type.
5459 All metadata are identified in syntax by an exclamation point ('``!``').
5461 .. _metadata-string:
5463 Metadata Nodes and Metadata Strings
5464 -----------------------------------
5466 A metadata string is a string surrounded by double quotes. It can
5467 contain any character by escaping non-printable characters with
5468 "``\xx``" where "``xx``" is the two digit hex code. For example:
5471 Metadata nodes are represented with notation similar to structure
5472 constants (a comma separated list of elements, surrounded by braces and
5473 preceded by an exclamation point). Metadata nodes can have any values as
5474 their operand. For example:
5476 .. code-block:: llvm
5478 !{ !"test\00", i32 10}
5480 Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
5482 .. code-block:: text
5484 !0 = distinct !{!"test\00", i32 10}
5486 ``distinct`` nodes are useful when nodes shouldn't be merged based on their
5487 content. They can also occur when transformations cause uniquing collisions
5488 when metadata operands change.
5490 A :ref:`named metadata <namedmetadatastructure>` is a collection of
5491 metadata nodes, which can be looked up in the module symbol table. For
5494 .. code-block:: llvm
5498 Metadata can be used as function arguments. Here the ``llvm.dbg.value``
5499 intrinsic is using three metadata arguments:
5501 .. code-block:: llvm
5503 call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26)
5505 Metadata can be attached to an instruction. Here metadata ``!21`` is attached
5506 to the ``add`` instruction using the ``!dbg`` identifier:
5508 .. code-block:: llvm
5510 %indvar.next = add i64 %indvar, 1, !dbg !21
5512 Instructions may not have multiple metadata attachments with the same
5515 Metadata can also be attached to a function or a global variable. Here metadata
5516 ``!22`` is attached to the ``f1`` and ``f2`` functions, and the globals ``g1``
5517 and ``g2`` using the ``!dbg`` identifier:
5519 .. code-block:: llvm
5521 declare !dbg !22 void @f1()
5522 define void @f2() !dbg !22 {
5526 @g1 = global i32 0, !dbg !22
5527 @g2 = external global i32, !dbg !22
5529 Unlike instructions, global objects (functions and global variables) may have
5530 multiple metadata attachments with the same identifier.
5532 A transformation is required to drop any metadata attachment that it
5533 does not know or know it can't preserve. Currently there is an
5534 exception for metadata attachment to globals for ``!func_sanitize``,
5535 ``!type``, ``!absolute_symbol`` and ``!associated`` which can't be
5536 unconditionally dropped unless the global is itself deleted.
5538 Metadata attached to a module using named metadata may not be dropped, with
5539 the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``).
5541 More information about specific metadata nodes recognized by the
5542 optimizers and code generator is found below.
5544 .. _specialized-metadata:
5546 Specialized Metadata Nodes
5547 ^^^^^^^^^^^^^^^^^^^^^^^^^^
5549 Specialized metadata nodes are custom data structures in metadata (as opposed
5550 to generic tuples). Their fields are labelled, and can be specified in any
5553 These aren't inherently debug info centric, but currently all the specialized
5554 metadata nodes are related to debug info.
5561 ``DICompileUnit`` nodes represent a compile unit. The ``enums:``,
5562 ``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples
5563 containing the debug info to be emitted along with the compile unit, regardless
5564 of code optimizations (some nodes are only emitted if there are references to
5565 them from instructions). The ``debugInfoForProfiling:`` field is a boolean
5566 indicating whether or not line-table discriminators are updated to provide
5567 more-accurate debug info for profiling results.
5569 .. code-block:: text
5571 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
5572 isOptimized: true, flags: "-O2", runtimeVersion: 2,
5573 splitDebugFilename: "abc.debug", emissionKind: FullDebug,
5574 enums: !2, retainedTypes: !3, globals: !4, imports: !5,
5575 macros: !6, dwoId: 0x0abcd)
5577 Compile unit descriptors provide the root scope for objects declared in a
5578 specific compilation unit. File descriptors are defined using this scope. These
5579 descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep
5580 track of global variables, type information, and imported entities (declarations
5588 ``DIFile`` nodes represent files. The ``filename:`` can include slashes.
5590 .. code-block:: none
5592 !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir",
5593 checksumkind: CSK_MD5,
5594 checksum: "000102030405060708090a0b0c0d0e0f")
5596 Files are sometimes used in ``scope:`` fields, and are the only valid target
5597 for ``file:`` fields.
5599 The ``checksum:`` and ``checksumkind:`` fields are optional. If one of these
5600 fields is present, then the other is required to be present as well. Valid
5601 values for ``checksumkind:`` field are: {CSK_MD5, CSK_SHA1, CSK_SHA256}
5608 ``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
5609 ``float``. ``tag:`` defaults to ``DW_TAG_base_type``.
5611 .. code-block:: text
5613 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
5614 encoding: DW_ATE_unsigned_char)
5615 !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
5617 The ``encoding:`` describes the details of the type. Usually it's one of the
5620 .. code-block:: text
5626 DW_ATE_signed_char = 6
5628 DW_ATE_unsigned_char = 8
5630 .. _DISubroutineType:
5635 ``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field
5636 refers to a tuple; the first operand is the return type, while the rest are the
5637 types of the formal arguments in order. If the first operand is ``null``, that
5638 represents a function with no return value (such as ``void foo() {}`` in C++).
5640 .. code-block:: text
5642 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
5643 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
5644 !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char)
5651 ``DIDerivedType`` nodes represent types derived from other types, such as
5654 .. code-block:: text
5656 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
5657 encoding: DW_ATE_unsigned_char)
5658 !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
5661 The following ``tag:`` values are valid:
5663 .. code-block:: text
5666 DW_TAG_pointer_type = 15
5667 DW_TAG_reference_type = 16
5669 DW_TAG_inheritance = 28
5670 DW_TAG_ptr_to_member_type = 31
5671 DW_TAG_const_type = 38
5673 DW_TAG_volatile_type = 53
5674 DW_TAG_restrict_type = 55
5675 DW_TAG_atomic_type = 71
5676 DW_TAG_immutable_type = 75
5678 .. _DIDerivedTypeMember:
5680 ``DW_TAG_member`` is used to define a member of a :ref:`composite type
5681 <DICompositeType>`. The type of the member is the ``baseType:``. The
5682 ``offset:`` is the member's bit offset. If the composite type has an ODR
5683 ``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is
5684 uniqued based only on its ``name:`` and ``scope:``.
5686 ``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:``
5687 field of :ref:`composite types <DICompositeType>` to describe parents and
5690 ``DW_TAG_typedef`` is used to provide a name for the ``baseType:``.
5692 ``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``,
5693 ``DW_TAG_volatile_type``, ``DW_TAG_restrict_type``, ``DW_TAG_atomic_type`` and
5694 ``DW_TAG_immutable_type`` are used to qualify the ``baseType:``.
5696 Note that the ``void *`` type is expressed as a type derived from NULL.
5698 .. _DICompositeType:
5703 ``DICompositeType`` nodes represent types composed of other types, like
5704 structures and unions. ``elements:`` points to a tuple of the composed types.
5706 If the source language supports ODR, the ``identifier:`` field gives the unique
5707 identifier used for type merging between modules. When specified,
5708 :ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member
5709 derived types <DIDerivedTypeMember>` that reference the ODR-type in their
5710 ``scope:`` change uniquing rules.
5712 For a given ``identifier:``, there should only be a single composite type that
5713 does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules
5714 together will unique such definitions at parse time via the ``identifier:``
5715 field, even if the nodes are ``distinct``.
5717 .. code-block:: text
5719 !0 = !DIEnumerator(name: "SixKind", value: 7)
5720 !1 = !DIEnumerator(name: "SevenKind", value: 7)
5721 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
5722 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
5723 line: 2, size: 32, align: 32, identifier: "_M4Enum",
5724 elements: !{!0, !1, !2})
5726 The following ``tag:`` values are valid:
5728 .. code-block:: text
5730 DW_TAG_array_type = 1
5731 DW_TAG_class_type = 2
5732 DW_TAG_enumeration_type = 4
5733 DW_TAG_structure_type = 19
5734 DW_TAG_union_type = 23
5736 For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange
5737 descriptors <DISubrange>`, each representing the range of subscripts at that
5738 level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an
5739 array type is a native packed vector. The optional ``dataLocation`` is a
5740 DIExpression that describes how to get from an object's address to the actual
5741 raw data, if they aren't equivalent. This is only supported for array types,
5742 particularly to describe Fortran arrays, which have an array descriptor in
5743 addition to the array data. Alternatively it can also be DIVariable which
5744 has the address of the actual raw data. The Fortran language supports pointer
5745 arrays which can be attached to actual arrays, this attachment between pointer
5746 and pointee is called association. The optional ``associated`` is a
5747 DIExpression that describes whether the pointer array is currently associated.
5748 The optional ``allocated`` is a DIExpression that describes whether the
5749 allocatable array is currently allocated. The optional ``rank`` is a
5750 DIExpression that describes the rank (number of dimensions) of fortran assumed
5751 rank array (rank is known at runtime).
5753 For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
5754 descriptors <DIEnumerator>`, each representing the definition of an enumeration
5755 value for the set. All enumeration type descriptors are collected in the
5756 ``enums:`` field of the :ref:`compile unit <DICompileUnit>`.
5758 For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and
5759 ``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types
5760 <DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or
5761 ``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with
5762 ``isDefinition: false``.
5769 ``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
5770 :ref:`DICompositeType`.
5772 - ``count: -1`` indicates an empty array.
5773 - ``count: !10`` describes the count with a :ref:`DILocalVariable`.
5774 - ``count: !12`` describes the count with a :ref:`DIGlobalVariable`.
5776 .. code-block:: text
5778 !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0
5779 !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1
5780 !2 = !DISubrange(count: -1) ; empty array.
5782 ; Scopes used in rest of example
5783 !6 = !DIFile(filename: "vla.c", directory: "/path/to/file")
5784 !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6)
5785 !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5)
5787 ; Use of local variable as count value
5788 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
5789 !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9)
5790 !11 = !DISubrange(count: !10, lowerBound: 0)
5792 ; Use of global variable as count value
5793 !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9)
5794 !13 = !DISubrange(count: !12, lowerBound: 0)
5801 ``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
5802 variants of :ref:`DICompositeType`.
5804 .. code-block:: text
5806 !0 = !DIEnumerator(name: "SixKind", value: 7)
5807 !1 = !DIEnumerator(name: "SevenKind", value: 7)
5808 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
5810 DITemplateTypeParameter
5811 """""""""""""""""""""""
5813 ``DITemplateTypeParameter`` nodes represent type parameters to generic source
5814 language constructs. They are used (optionally) in :ref:`DICompositeType` and
5815 :ref:`DISubprogram` ``templateParams:`` fields.
5817 .. code-block:: text
5819 !0 = !DITemplateTypeParameter(name: "Ty", type: !1)
5821 DITemplateValueParameter
5822 """"""""""""""""""""""""
5824 ``DITemplateValueParameter`` nodes represent value parameters to generic source
5825 language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
5826 but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
5827 ``DW_TAG_GNU_template_param_pack``. They are used (optionally) in
5828 :ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields.
5830 .. code-block:: text
5832 !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7)
5837 ``DINamespace`` nodes represent namespaces in the source language.
5839 .. code-block:: text
5841 !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
5843 .. _DIGlobalVariable:
5848 ``DIGlobalVariable`` nodes represent global variables in the source language.
5850 .. code-block:: text
5852 @foo = global i32, !dbg !0
5853 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
5854 !1 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !2,
5855 file: !3, line: 7, type: !4, isLocal: true,
5856 isDefinition: false, declaration: !5)
5859 DIGlobalVariableExpression
5860 """"""""""""""""""""""""""
5862 ``DIGlobalVariableExpression`` nodes tie a :ref:`DIGlobalVariable` together
5863 with a :ref:`DIExpression`.
5865 .. code-block:: text
5867 @lower = global i32, !dbg !0
5868 @upper = global i32, !dbg !1
5869 !0 = !DIGlobalVariableExpression(
5871 expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32)
5873 !1 = !DIGlobalVariableExpression(
5875 expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32)
5877 !2 = !DIGlobalVariable(name: "split64", linkageName: "split64", scope: !3,
5878 file: !4, line: 8, type: !5, declaration: !6)
5880 All global variable expressions should be referenced by the `globals:` field of
5881 a :ref:`compile unit <DICompileUnit>`.
5888 ``DISubprogram`` nodes represent functions from the source language. A distinct
5889 ``DISubprogram`` may be attached to a function definition using ``!dbg``
5890 metadata. A unique ``DISubprogram`` may be attached to a function declaration
5891 used for call site debug info. The ``retainedNodes:`` field is a list of
5892 :ref:`variables <DILocalVariable>` and :ref:`labels <DILabel>` that must be
5893 retained, even if their IR counterparts are optimized out of the IR. The
5894 ``type:`` field must point at an :ref:`DISubroutineType`.
5896 .. _DISubprogramDeclaration:
5898 When ``spFlags: DISPFlagDefinition`` is not present, subprograms describe a
5899 declaration in the type tree as opposed to a definition of a function. In this
5900 case, the ``declaration`` field must be empty. If the scope is a composite type
5901 with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``, then
5902 the subprogram declaration is uniqued based only on its ``linkageName:`` and
5905 .. code-block:: text
5907 define void @_Z3foov() !dbg !0 {
5911 !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
5912 file: !2, line: 7, type: !3,
5913 spFlags: DISPFlagDefinition | DISPFlagLocalToUnit,
5914 scopeLine: 8, containingType: !4,
5915 virtuality: DW_VIRTUALITY_pure_virtual,
5916 virtualIndex: 10, flags: DIFlagPrototyped,
5917 isOptimized: true, unit: !5, templateParams: !6,
5918 declaration: !7, retainedNodes: !8,
5926 ``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
5927 <DISubprogram>`. The line number and column numbers are used to distinguish
5928 two lexical blocks at same depth. They are valid targets for ``scope:``
5931 .. code-block:: text
5933 !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
5935 Usually lexical blocks are ``distinct`` to prevent node merging based on
5938 .. _DILexicalBlockFile:
5943 ``DILexicalBlockFile`` nodes are used to discriminate between sections of a
5944 :ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to
5945 indicate textual inclusion, or the ``discriminator:`` field can be used to
5946 discriminate between control flow within a single block in the source language.
5948 .. code-block:: text
5950 !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35)
5951 !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0)
5952 !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1)
5959 ``DILocation`` nodes represent source debug locations. The ``scope:`` field is
5960 mandatory, and points at an :ref:`DILexicalBlockFile`, an
5961 :ref:`DILexicalBlock`, or an :ref:`DISubprogram`.
5963 .. code-block:: text
5965 !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
5967 .. _DILocalVariable:
5972 ``DILocalVariable`` nodes represent local variables in the source language. If
5973 the ``arg:`` field is set to non-zero, then this variable is a subprogram
5974 parameter, and it will be included in the ``retainedNodes:`` field of its
5975 :ref:`DISubprogram`.
5977 .. code-block:: text
5979 !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7,
5980 type: !3, flags: DIFlagArtificial)
5981 !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7,
5983 !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3)
5990 ``DIExpression`` nodes represent expressions that are inspired by the DWARF
5991 expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>`
5992 (such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the
5993 referenced LLVM variable relates to the source language variable. Debug
5994 intrinsics are interpreted left-to-right: start by pushing the value/address
5995 operand of the intrinsic onto a stack, then repeatedly push and evaluate
5996 opcodes from the DIExpression until the final variable description is produced.
5998 The current supported opcode vocabulary is limited:
6000 - ``DW_OP_deref`` dereferences the top of the expression stack.
6001 - ``DW_OP_plus`` pops the last two entries from the expression stack, adds
6002 them together and appends the result to the expression stack.
6003 - ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts
6004 the last entry from the second last entry and appends the result to the
6006 - ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression.
6007 - ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8``
6008 here, respectively) of the variable fragment from the working expression. Note
6009 that contrary to DW_OP_bit_piece, the offset is describing the location
6010 within the described source variable.
6011 - ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding
6012 (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the
6013 expression stack is to be converted. Maps into a ``DW_OP_convert`` operation
6014 that references a base type constructed from the supplied values.
6015 - ``DW_OP_LLVM_tag_offset, tag_offset`` specifies that a memory tag should be
6016 optionally applied to the pointer. The memory tag is derived from the
6017 given tag offset in an implementation-defined manner.
6018 - ``DW_OP_swap`` swaps top two stack entries.
6019 - ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top
6020 of the stack is treated as an address. The second stack entry is treated as an
6021 address space identifier.
6022 - ``DW_OP_stack_value`` marks a constant value.
6023 - ``DW_OP_LLVM_entry_value, N`` refers to the value a register had upon
6024 function entry. When targeting DWARF, a ``DBG_VALUE(reg, ...,
6025 DIExpression(DW_OP_LLVM_entry_value, 1, ...)`` is lowered to
6026 ``DW_OP_entry_value [reg], ...``, which pushes the value ``reg`` had upon
6027 function entry onto the DWARF expression stack.
6029 The next ``(N - 1)`` operations will be part of the ``DW_OP_entry_value``
6030 block argument. For example, ``!DIExpression(DW_OP_LLVM_entry_value, 1,
6031 DW_OP_plus_uconst, 123, DW_OP_stack_value)`` specifies an expression where
6032 the entry value of ``reg`` is pushed onto the stack, and is added with 123.
6033 Due to framework limitations ``N`` must be 1, in other words,
6034 ``DW_OP_entry_value`` always refers to the value/address operand of the
6037 Because ``DW_OP_LLVM_entry_value`` is defined in terms of registers, it is
6038 usually used in MIR, but it is also allowed in LLVM IR when targetting a
6039 :ref:`swiftasync <swiftasync>` argument. The operation is introduced by:
6041 - ``LiveDebugValues`` pass, which applies it to function parameters that
6042 are unmodified throughout the function. Support is limited to simple
6043 register location descriptions, or as indirect locations (e.g.,
6044 parameters passed-by-value to a callee via a pointer to a temporary copy
6045 made in the caller).
6046 - ``AsmPrinter`` pass when a call site parameter value
6047 (``DW_AT_call_site_parameter_value``) is represented as entry value of
6049 - ``CoroSplit`` pass, which may move variables from allocas into a
6050 coroutine frame. If the coroutine frame is a
6051 :ref:`swiftasync <swiftasync>` argument, the variable is described with
6052 an ``DW_OP_LLVM_entry_value`` operation.
6054 - ``DW_OP_LLVM_arg, N`` is used in debug intrinsics that refer to more than one
6055 value, such as one that calculates the sum of two registers. This is always
6056 used in combination with an ordered list of values, such that
6057 ``DW_OP_LLVM_arg, N`` refers to the ``N``\ :sup:`th` element in that list. For
6058 example, ``!DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus,
6059 DW_OP_stack_value)`` used with the list ``(%reg1, %reg2)`` would evaluate to
6060 ``%reg1 - reg2``. This list of values should be provided by the containing
6061 intrinsic/instruction.
6062 - ``DW_OP_breg`` (or ``DW_OP_bregx``) represents a content on the provided
6063 signed offset of the specified register. The opcode is only generated by the
6064 ``AsmPrinter`` pass to describe call site parameter value which requires an
6065 expression over two registers.
6066 - ``DW_OP_push_object_address`` pushes the address of the object which can then
6067 serve as a descriptor in subsequent calculation. This opcode can be used to
6068 calculate bounds of fortran allocatable array which has array descriptors.
6069 - ``DW_OP_over`` duplicates the entry currently second in the stack at the top
6070 of the stack. This opcode can be used to calculate bounds of fortran assumed
6071 rank array which has rank known at run time and current dimension number is
6072 implicitly first element of the stack.
6073 - ``DW_OP_LLVM_implicit_pointer`` It specifies the dereferenced value. It can
6074 be used to represent pointer variables which are optimized out but the value
6075 it points to is known. This operator is required as it is different than DWARF
6076 operator DW_OP_implicit_pointer in representation and specification (number
6077 and types of operands) and later can not be used as multiple level.
6079 .. code-block:: text
6083 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !20)
6084 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5,
6086 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
6087 !19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
6088 !20 = !DIExpression(DW_OP_LLVM_implicit_pointer))
6092 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !21)
6093 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5,
6095 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
6096 !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
6097 !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
6098 !21 = !DIExpression(DW_OP_LLVM_implicit_pointer,
6099 DW_OP_LLVM_implicit_pointer))
6101 DWARF specifies three kinds of simple location descriptions: Register, memory,
6102 and implicit location descriptions. Note that a location description is
6103 defined over certain ranges of a program, i.e the location of a variable may
6104 change over the course of the program. Register and memory location
6105 descriptions describe the *concrete location* of a source variable (in the
6106 sense that a debugger might modify its value), whereas *implicit locations*
6107 describe merely the actual *value* of a source variable which might not exist
6108 in registers or in memory (see ``DW_OP_stack_value``).
6110 A ``llvm.dbg.declare`` intrinsic describes an indirect value (the address) of a
6111 source variable. The first operand of the intrinsic must be an address of some
6112 kind. A DIExpression attached to the intrinsic refines this address to produce a
6113 concrete location for the source variable.
6115 A ``llvm.dbg.value`` intrinsic describes the direct value of a source variable.
6116 The first operand of the intrinsic may be a direct or indirect value. A
6117 DIExpression attached to the intrinsic refines the first operand to produce a
6118 direct value. For example, if the first operand is an indirect value, it may be
6119 necessary to insert ``DW_OP_deref`` into the DIExpression in order to produce a
6120 valid debug intrinsic.
6124 A DIExpression is interpreted in the same way regardless of which kind of
6125 debug intrinsic it's attached to.
6127 .. code-block:: text
6129 !0 = !DIExpression(DW_OP_deref)
6130 !1 = !DIExpression(DW_OP_plus_uconst, 3)
6131 !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus)
6132 !2 = !DIExpression(DW_OP_bit_piece, 3, 7)
6133 !3 = !DIExpression(DW_OP_deref, DW_OP_constu, 3, DW_OP_plus, DW_OP_LLVM_fragment, 3, 7)
6134 !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef)
6135 !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value)
6140 ``DIAssignID`` nodes have no operands and are always distinct. They are used to
6141 link together `@llvm.dbg.assign` intrinsics (:ref:`debug
6142 intrinsics<dbg_intrinsics>`) and instructions that store in IR. See `Debug Info
6143 Assignment Tracking <AssignmentTracking.html>`_ for more info.
6145 .. code-block:: llvm
6147 store i32 %a, ptr %a.addr, align 4, !DIAssignID !2
6148 llvm.dbg.assign(metadata %a, metadata !1, metadata !DIExpression(), !2, metadata %a.addr, metadata !DIExpression()), !dbg !3
6150 !2 = distinct !DIAssignID()
6155 ``DIArgList`` nodes hold a list of constant or SSA value references. These are
6156 used in :ref:`debug intrinsics<dbg_intrinsics>` (currently only in
6157 ``llvm.dbg.value``) in combination with a ``DIExpression`` that uses the
6158 ``DW_OP_LLVM_arg`` operator. Because a DIArgList may refer to local values
6159 within a function, it must only be used as a function argument, must always be
6160 inlined, and cannot appear in named metadata.
6162 .. code-block:: text
6164 llvm.dbg.value(metadata !DIArgList(i32 %a, i32 %b),
6166 metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus))
6171 These flags encode various properties of DINodes.
6173 The `ExportSymbols` flag marks a class, struct or union whose members
6174 may be referenced as if they were defined in the containing class or
6175 union. This flag is used to decide whether the DW_AT_export_symbols can
6176 be used for the structure type.
6181 ``DIObjCProperty`` nodes represent Objective-C property nodes.
6183 .. code-block:: text
6185 !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
6186 getter: "getFoo", attributes: 7, type: !2)
6191 ``DIImportedEntity`` nodes represent entities (such as modules) imported into a
6192 compile unit. The ``elements`` field is a list of renamed entities (such as
6193 variables and subprograms) in the imported entity (such as module).
6195 .. code-block:: text
6197 !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
6198 entity: !1, line: 7, elements: !3)
6200 !4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "bar", scope: !0,
6201 entity: !5, line: 7)
6206 ``DIMacro`` nodes represent definition or undefinition of a macro identifiers.
6207 The ``name:`` field is the macro identifier, followed by macro parameters when
6208 defining a function-like macro, and the ``value`` field is the token-string
6209 used to expand the macro identifier.
6211 .. code-block:: text
6213 !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)",
6215 !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo")
6220 ``DIMacroFile`` nodes represent inclusion of source files.
6221 The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that
6222 appear in the included source file.
6224 .. code-block:: text
6226 !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2,
6234 ``DILabel`` nodes represent labels within a :ref:`DISubprogram`. All fields of
6235 a ``DILabel`` are mandatory. The ``scope:`` field must be one of either a
6236 :ref:`DILexicalBlockFile`, a :ref:`DILexicalBlock`, or a :ref:`DISubprogram`.
6237 The ``name:`` field is the label identifier. The ``file:`` field is the
6238 :ref:`DIFile` the label is present in. The ``line:`` field is the source line
6239 within the file where the label is declared.
6241 .. code-block:: text
6243 !2 = !DILabel(scope: !0, name: "foo", file: !1, line: 7)
6248 In LLVM IR, memory does not have types, so LLVM's own type system is not
6249 suitable for doing type based alias analysis (TBAA). Instead, metadata is
6250 added to the IR to describe a type system of a higher level language. This
6251 can be used to implement C/C++ strict type aliasing rules, but it can also
6252 be used to implement custom alias analysis behavior for other languages.
6254 This description of LLVM's TBAA system is broken into two parts:
6255 :ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and
6256 :ref:`Representation<tbaa_node_representation>` talks about the metadata
6257 encoding of various entities.
6259 It is always possible to trace any TBAA node to a "root" TBAA node (details
6260 in the :ref:`Representation<tbaa_node_representation>` section). TBAA
6261 nodes with different roots have an unknown aliasing relationship, and LLVM
6262 conservatively infers ``MayAlias`` between them. The rules mentioned in
6263 this section only pertain to TBAA nodes living under the same root.
6265 .. _tbaa_node_semantics:
6270 The TBAA metadata system, referred to as "struct path TBAA" (not to be
6271 confused with ``tbaa.struct``), consists of the following high level
6272 concepts: *Type Descriptors*, further subdivided into scalar type
6273 descriptors and struct type descriptors; and *Access Tags*.
6275 **Type descriptors** describe the type system of the higher level language
6276 being compiled. **Scalar type descriptors** describe types that do not
6277 contain other types. Each scalar type has a parent type, which must also
6278 be a scalar type or the TBAA root. Via this parent relation, scalar types
6279 within a TBAA root form a tree. **Struct type descriptors** denote types
6280 that contain a sequence of other type descriptors, at known offsets. These
6281 contained type descriptors can either be struct type descriptors themselves
6282 or scalar type descriptors.
6284 **Access tags** are metadata nodes attached to load and store instructions.
6285 Access tags use type descriptors to describe the *location* being accessed
6286 in terms of the type system of the higher level language. Access tags are
6287 tuples consisting of a base type, an access type and an offset. The base
6288 type is a scalar type descriptor or a struct type descriptor, the access
6289 type is a scalar type descriptor, and the offset is a constant integer.
6291 The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two
6294 * If ``BaseTy`` is a struct type, the tag describes a memory access (load
6295 or store) of a value of type ``AccessTy`` contained in the struct type
6296 ``BaseTy`` at offset ``Offset``.
6298 * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and
6299 ``AccessTy`` must be the same; and the access tag describes a scalar
6300 access with scalar type ``AccessTy``.
6302 We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)``
6305 * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is
6306 ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as
6307 described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is
6308 undefined if ``Offset`` is non-zero.
6310 * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)``
6311 is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in
6312 ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted
6313 to be relative within that inner type.
6315 A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)``
6316 aliases a memory access with an access tag ``(BaseTy2, AccessTy2,
6317 Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2,
6318 Offset2)`` via the ``Parent`` relation or vice versa.
6320 As a concrete example, the type descriptor graph for the following program
6326 float f; // offset 4
6330 float f; // offset 0
6331 double d; // offset 4
6332 struct Inner inner_a; // offset 12
6335 void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) {
6336 outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0)
6337 outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12)
6338 outer->inner_a.f = 0.0; // tag2: (OuterStructTy, FloatScalarTy, 16)
6339 *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0)
6342 is (note that in C and C++, ``char`` can be used to access any arbitrary
6345 .. code-block:: text
6348 CharScalarTy = ("char", Root, 0)
6349 FloatScalarTy = ("float", CharScalarTy, 0)
6350 DoubleScalarTy = ("double", CharScalarTy, 0)
6351 IntScalarTy = ("int", CharScalarTy, 0)
6352 InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)}
6353 OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4),
6354 (InnerStructTy, 12)}
6357 with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy,
6358 0)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and
6359 ``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``.
6361 .. _tbaa_node_representation:
6366 The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or
6367 with exactly one ``MDString`` operand.
6369 Scalar type descriptors are represented as an ``MDNode`` s with two
6370 operands. The first operand is an ``MDString`` denoting the name of the
6371 struct type. LLVM does not assign meaning to the value of this operand, it
6372 only cares about it being an ``MDString``. The second operand is an
6373 ``MDNode`` which points to the parent for said scalar type descriptor,
6374 which is either another scalar type descriptor or the TBAA root. Scalar
6375 type descriptors can have an optional third argument, but that must be the
6376 constant integer zero.
6378 Struct type descriptors are represented as ``MDNode`` s with an odd number
6379 of operands greater than 1. The first operand is an ``MDString`` denoting
6380 the name of the struct type. Like in scalar type descriptors the actual
6381 value of this name operand is irrelevant to LLVM. After the name operand,
6382 the struct type descriptors have a sequence of alternating ``MDNode`` and
6383 ``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand,
6384 an ``MDNode``, denotes a contained field, and the 2N th operand, a
6385 ``ConstantInt``, is the offset of the said contained field. The offsets
6386 must be in non-decreasing order.
6388 Access tags are represented as ``MDNode`` s with either 3 or 4 operands.
6389 The first operand is an ``MDNode`` pointing to the node representing the
6390 base type. The second operand is an ``MDNode`` pointing to the node
6391 representing the access type. The third operand is a ``ConstantInt`` that
6392 states the offset of the access. If a fourth field is present, it must be
6393 a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states
6394 that the location being accessed is "constant" (meaning
6395 ``pointsToConstantMemory`` should return true; see `other useful
6396 AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of
6397 the access type and the base type of an access tag must be the same, and
6398 that is the TBAA root of the access tag.
6400 '``tbaa.struct``' Metadata
6401 ^^^^^^^^^^^^^^^^^^^^^^^^^^
6403 The :ref:`llvm.memcpy <int_memcpy>` is often used to implement
6404 aggregate assignment operations in C and similar languages, however it
6405 is defined to copy a contiguous region of memory, which is more than
6406 strictly necessary for aggregate types which contain holes due to
6407 padding. Also, it doesn't contain any TBAA information about the fields
6410 ``!tbaa.struct`` metadata can describe which memory subregions in a
6411 memcpy are padding and what the TBAA tags of the struct are.
6413 The current metadata format is very simple. ``!tbaa.struct`` metadata
6414 nodes are a list of operands which are in conceptual groups of three.
6415 For each group of three, the first operand gives the byte offset of a
6416 field in bytes, the second gives its size in bytes, and the third gives
6419 .. code-block:: llvm
6421 !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 }
6423 This describes a struct with two fields. The first is at offset 0 bytes
6424 with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes
6425 and has size 4 bytes and has tbaa tag !2.
6427 Note that the fields need not be contiguous. In this example, there is a
6428 4 byte gap between the two fields. This gap represents padding which
6429 does not carry useful data and need not be preserved.
6431 '``noalias``' and '``alias.scope``' Metadata
6432 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6434 ``noalias`` and ``alias.scope`` metadata provide the ability to specify generic
6435 noalias memory-access sets. This means that some collection of memory access
6436 instructions (loads, stores, memory-accessing calls, etc.) that carry
6437 ``noalias`` metadata can specifically be specified not to alias with some other
6438 collection of memory access instructions that carry ``alias.scope`` metadata.
6439 Each type of metadata specifies a list of scopes where each scope has an id and
6442 When evaluating an aliasing query, if for some domain, the set
6443 of scopes with that domain in one instruction's ``alias.scope`` list is a
6444 subset of (or equal to) the set of scopes for that domain in another
6445 instruction's ``noalias`` list, then the two memory accesses are assumed not to
6448 Because scopes in one domain don't affect scopes in other domains, separate
6449 domains can be used to compose multiple independent noalias sets. This is
6450 used for example during inlining. As the noalias function parameters are
6451 turned into noalias scope metadata, a new domain is used every time the
6452 function is inlined.
6454 The metadata identifying each domain is itself a list containing one or two
6455 entries. The first entry is the name of the domain. Note that if the name is a
6456 string then it can be combined across functions and translation units. A
6457 self-reference can be used to create globally unique domain names. A
6458 descriptive string may optionally be provided as a second list entry.
6460 The metadata identifying each scope is also itself a list containing two or
6461 three entries. The first entry is the name of the scope. Note that if the name
6462 is a string then it can be combined across functions and translation units. A
6463 self-reference can be used to create globally unique scope names. A metadata
6464 reference to the scope's domain is the second entry. A descriptive string may
6465 optionally be provided as a third list entry.
6469 .. code-block:: llvm
6471 ; Two scope domains:
6475 ; Some scopes in these domains:
6481 !5 = !{!4} ; A list containing only scope !4
6485 ; These two instructions don't alias:
6486 %0 = load float, ptr %c, align 4, !alias.scope !5
6487 store float %0, ptr %arrayidx.i, align 4, !noalias !5
6489 ; These two instructions also don't alias (for domain !1, the set of scopes
6490 ; in the !alias.scope equals that in the !noalias list):
6491 %2 = load float, ptr %c, align 4, !alias.scope !5
6492 store float %2, ptr %arrayidx.i2, align 4, !noalias !6
6494 ; These two instructions may alias (for domain !0, the set of scopes in
6495 ; the !noalias list is not a superset of, or equal to, the scopes in the
6496 ; !alias.scope list):
6497 %2 = load float, ptr %c, align 4, !alias.scope !6
6498 store float %0, ptr %arrayidx.i, align 4, !noalias !7
6500 '``fpmath``' Metadata
6501 ^^^^^^^^^^^^^^^^^^^^^
6503 ``fpmath`` metadata may be attached to any instruction of floating-point
6504 type. It can be used to express the maximum acceptable error in the
6505 result of that instruction, in ULPs, thus potentially allowing the
6506 compiler to use a more efficient but less accurate method of computing
6507 it. ULP is defined as follows:
6509 If ``x`` is a real number that lies between two finite consecutive
6510 floating-point numbers ``a`` and ``b``, without being equal to one
6511 of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the
6512 distance between the two non-equal finite floating-point numbers
6513 nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``.
6515 The metadata node shall consist of a single positive float type number
6516 representing the maximum relative error, for example:
6518 .. code-block:: llvm
6520 !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
6524 '``range``' Metadata
6525 ^^^^^^^^^^^^^^^^^^^^
6527 ``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of
6528 integer or vector of integer types. It expresses the possible ranges the loaded
6529 value or the value returned by the called function at this call site is in. If
6530 the loaded or returned value is not in the specified range, a poison value is
6531 returned instead. The ranges are represented with a flattened list of integers.
6532 The loaded value or the value returned is known to be in the union of the ranges
6533 defined by each consecutive pair. Each pair has the following properties:
6535 - The type must match the scalar type of the instruction.
6536 - The pair ``a,b`` represents the range ``[a,b)``.
6537 - Both ``a`` and ``b`` are constants.
6538 - The range is allowed to wrap.
6539 - The range should not represent the full or empty set. That is,
6542 In addition, the pairs must be in signed order of the lower bound and
6543 they must be non-contiguous.
6545 For vector-typed instructions, the range is applied element-wise.
6549 .. code-block:: llvm
6551 %a = load i8, ptr %x, align 1, !range !0 ; Can only be 0 or 1
6552 %b = load i8, ptr %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
6553 %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5
6554 %d = invoke i8 @bar() to label %cont
6555 unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5
6556 %e = load <2 x i8>, ptr %x, !range 0 ; Can only be <0 or 1, 0 or 1>
6558 !0 = !{ i8 0, i8 2 }
6559 !1 = !{ i8 255, i8 2 }
6560 !2 = !{ i8 0, i8 2, i8 3, i8 6 }
6561 !3 = !{ i8 -2, i8 0, i8 3, i8 6 }
6563 '``absolute_symbol``' Metadata
6564 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6566 ``absolute_symbol`` metadata may be attached to a global variable
6567 declaration. It marks the declaration as a reference to an absolute symbol,
6568 which causes the backend to use absolute relocations for the symbol even
6569 in position independent code, and expresses the possible ranges that the
6570 global variable's *address* (not its value) is in, in the same format as
6571 ``range`` metadata, with the extension that the pair ``all-ones,all-ones``
6572 may be used to represent the full set.
6574 Example (assuming 64-bit pointers):
6576 .. code-block:: llvm
6578 @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256)
6579 @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64)
6582 !0 = !{ i64 0, i64 256 }
6583 !1 = !{ i64 -1, i64 -1 }
6585 '``callees``' Metadata
6586 ^^^^^^^^^^^^^^^^^^^^^^
6588 ``callees`` metadata may be attached to indirect call sites. If ``callees``
6589 metadata is attached to a call site, and any callee is not among the set of
6590 functions provided by the metadata, the behavior is undefined. The intent of
6591 this metadata is to facilitate optimizations such as indirect-call promotion.
6592 For example, in the code below, the call instruction may only target the
6593 ``add`` or ``sub`` functions:
6595 .. code-block:: llvm
6597 %result = call i64 %binop(i64 %x, i64 %y), !callees !0
6600 !0 = !{ptr @add, ptr @sub}
6602 '``callback``' Metadata
6603 ^^^^^^^^^^^^^^^^^^^^^^^
6605 ``callback`` metadata may be attached to a function declaration, or definition.
6606 (Call sites are excluded only due to the lack of a use case.) For ease of
6607 exposition, we'll refer to the function annotated w/ metadata as a broker
6608 function. The metadata describes how the arguments of a call to the broker are
6609 in turn passed to the callback function specified by the metadata. Thus, the
6610 ``callback`` metadata provides a partial description of a call site inside the
6611 broker function with regards to the arguments of a call to the broker. The only
6612 semantic restriction on the broker function itself is that it is not allowed to
6613 inspect or modify arguments referenced in the ``callback`` metadata as
6614 pass-through to the callback function.
6616 The broker is not required to actually invoke the callback function at runtime.
6617 However, the assumptions about not inspecting or modifying arguments that would
6618 be passed to the specified callback function still hold, even if the callback
6619 function is not dynamically invoked. The broker is allowed to invoke the
6620 callback function more than once per invocation of the broker. The broker is
6621 also allowed to invoke (directly or indirectly) the function passed as a
6622 callback through another use. Finally, the broker is also allowed to relay the
6623 callback callee invocation to a different thread.
6625 The metadata is structured as follows: At the outer level, ``callback``
6626 metadata is a list of ``callback`` encodings. Each encoding starts with a
6627 constant ``i64`` which describes the argument position of the callback function
6628 in the call to the broker. The following elements, except the last, describe
6629 what arguments are passed to the callback function. Each element is again an
6630 ``i64`` constant identifying the argument of the broker that is passed through,
6631 or ``i64 -1`` to indicate an unknown or inspected argument. The order in which
6632 they are listed has to be the same in which they are passed to the callback
6633 callee. The last element of the encoding is a boolean which specifies how
6634 variadic arguments of the broker are handled. If it is true, all variadic
6635 arguments of the broker are passed through to the callback function *after* the
6636 arguments encoded explicitly before.
6638 In the code below, the ``pthread_create`` function is marked as a broker
6639 through the ``!callback !1`` metadata. In the example, there is only one
6640 callback encoding, namely ``!2``, associated with the broker. This encoding
6641 identifies the callback function as the second argument of the broker (``i64
6642 2``) and the sole argument of the callback function as the third one of the
6643 broker function (``i64 3``).
6645 .. FIXME why does the llvm-sphinx-docs builder give a highlighting
6646 error if the below is set to highlight as 'llvm', despite that we
6647 have misc.highlighting_failure set?
6649 .. code-block:: text
6651 declare !callback !1 dso_local i32 @pthread_create(ptr, ptr, ptr, ptr)
6654 !2 = !{i64 2, i64 3, i1 false}
6657 Another example is shown below. The callback callee is the second argument of
6658 the ``__kmpc_fork_call`` function (``i64 2``). The callee is given two unknown
6659 values (each identified by a ``i64 -1``) and afterwards all
6660 variadic arguments that are passed to the ``__kmpc_fork_call`` call (due to the
6663 .. FIXME why does the llvm-sphinx-docs builder give a highlighting
6664 error if the below is set to highlight as 'llvm', despite that we
6665 have misc.highlighting_failure set?
6667 .. code-block:: text
6669 declare !callback !0 dso_local void @__kmpc_fork_call(ptr, i32, ptr, ...)
6672 !1 = !{i64 2, i64 -1, i64 -1, i1 true}
6675 '``exclude``' Metadata
6676 ^^^^^^^^^^^^^^^^^^^^^^
6678 ``exclude`` metadata may be attached to a global variable to signify that its
6679 section should not be included in the final executable or shared library. This
6680 option is only valid for global variables with an explicit section targeting ELF
6681 or COFF. This is done using the ``SHF_EXCLUDE`` flag on ELF targets and the
6682 ``IMAGE_SCN_LNK_REMOVE`` and ``IMAGE_SCN_MEM_DISCARDABLE`` flags for COFF
6683 targets. Additionally, this metadata is only used as a flag, so the associated
6684 node must be empty. The explicit section should not conflict with any other
6685 sections that the user does not want removed after linking.
6687 .. code-block:: text
6689 @object = private constant [1 x i8] c"\00", section ".foo" !exclude !0
6694 '``unpredictable``' Metadata
6695 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6697 ``unpredictable`` metadata may be attached to any branch or switch
6698 instruction. It can be used to express the unpredictability of control
6699 flow. Similar to the llvm.expect intrinsic, it may be used to alter
6700 optimizations related to compare and branch instructions. The metadata
6701 is treated as a boolean value; if it exists, it signals that the branch
6702 or switch that it is attached to is completely unpredictable.
6704 .. _md_dereferenceable:
6706 '``dereferenceable``' Metadata
6707 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6709 The existence of the ``!dereferenceable`` metadata on the instruction
6710 tells the optimizer that the value loaded is known to be dereferenceable,
6711 otherwise the behavior is undefined.
6712 The number of bytes known to be dereferenceable is specified by the integer
6713 value in the metadata node. This is analogous to the ''dereferenceable''
6714 attribute on parameters and return values.
6716 .. _md_dereferenceable_or_null:
6718 '``dereferenceable_or_null``' Metadata
6719 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6721 The existence of the ``!dereferenceable_or_null`` metadata on the
6722 instruction tells the optimizer that the value loaded is known to be either
6723 dereferenceable or null, otherwise the behavior is undefined.
6724 The number of bytes known to be dereferenceable is specified by the integer
6725 value in the metadata node. This is analogous to the ''dereferenceable_or_null''
6726 attribute on parameters and return values.
6733 It is sometimes useful to attach information to loop constructs. Currently,
6734 loop metadata is implemented as metadata attached to the branch instruction
6735 in the loop latch block. The loop metadata node is a list of
6736 other metadata nodes, each representing a property of the loop. Usually,
6737 the first item of the property node is a string. For example, the
6738 ``llvm.loop.unroll.count`` suggests an unroll factor to the loop
6741 .. code-block:: llvm
6743 br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0
6746 !1 = !{!"llvm.loop.unroll.enable"}
6747 !2 = !{!"llvm.loop.unroll.count", i32 4}
6749 For legacy reasons, the first item of a loop metadata node must be a
6750 reference to itself. Before the advent of the 'distinct' keyword, this
6751 forced the preservation of otherwise identical metadata nodes. Since
6752 the loop-metadata node can be attached to multiple nodes, the 'distinct'
6753 keyword has become unnecessary.
6755 Prior to the property nodes, one or two ``DILocation`` (debug location)
6756 nodes can be present in the list. The first, if present, identifies the
6757 source-code location where the loop begins. The second, if present,
6758 identifies the source-code location where the loop ends.
6760 Loop metadata nodes cannot be used as unique identifiers. They are
6761 neither persistent for the same loop through transformations nor
6762 necessarily unique to just one loop.
6764 '``llvm.loop.disable_nonforced``'
6765 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6767 This metadata disables all optional loop transformations unless
6768 explicitly instructed using other transformation metadata such as
6769 ``llvm.loop.unroll.enable``. That is, no heuristic will try to determine
6770 whether a transformation is profitable. The purpose is to avoid that the
6771 loop is transformed to a different loop before an explicitly requested
6772 (forced) transformation is applied. For instance, loop fusion can make
6773 other transformations impossible. Mandatory loop canonicalizations such
6774 as loop rotation are still applied.
6776 It is recommended to use this metadata in addition to any llvm.loop.*
6777 transformation directive. Also, any loop should have at most one
6778 directive applied to it (and a sequence of transformations built using
6779 followup-attributes). Otherwise, which transformation will be applied
6780 depends on implementation details such as the pass pipeline order.
6782 See :ref:`transformation-metadata` for details.
6784 '``llvm.loop.vectorize``' and '``llvm.loop.interleave``'
6785 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6787 Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are
6788 used to control per-loop vectorization and interleaving parameters such as
6789 vectorization width and interleave count. These metadata should be used in
6790 conjunction with ``llvm.loop`` loop identification metadata. The
6791 ``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only
6792 optimization hints and the optimizer will only interleave and vectorize loops if
6793 it believes it is safe to do so. The ``llvm.loop.parallel_accesses`` metadata
6794 which contains information about loop-carried memory dependencies can be helpful
6795 in determining the safety of these transformations.
6797 '``llvm.loop.interleave.count``' Metadata
6798 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6800 This metadata suggests an interleave count to the loop interleaver.
6801 The first operand is the string ``llvm.loop.interleave.count`` and the
6802 second operand is an integer specifying the interleave count. For
6805 .. code-block:: llvm
6807 !0 = !{!"llvm.loop.interleave.count", i32 4}
6809 Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving
6810 multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0
6811 then the interleave count will be determined automatically.
6813 '``llvm.loop.vectorize.enable``' Metadata
6814 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6816 This metadata selectively enables or disables vectorization for the loop. The
6817 first operand is the string ``llvm.loop.vectorize.enable`` and the second operand
6818 is a bit. If the bit operand value is 1 vectorization is enabled. A value of
6819 0 disables vectorization:
6821 .. code-block:: llvm
6823 !0 = !{!"llvm.loop.vectorize.enable", i1 0}
6824 !1 = !{!"llvm.loop.vectorize.enable", i1 1}
6826 '``llvm.loop.vectorize.predicate.enable``' Metadata
6827 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6829 This metadata selectively enables or disables creating predicated instructions
6830 for the loop, which can enable folding of the scalar epilogue loop into the
6831 main loop. The first operand is the string
6832 ``llvm.loop.vectorize.predicate.enable`` and the second operand is a bit. If
6833 the bit operand value is 1 vectorization is enabled. A value of 0 disables
6836 .. code-block:: llvm
6838 !0 = !{!"llvm.loop.vectorize.predicate.enable", i1 0}
6839 !1 = !{!"llvm.loop.vectorize.predicate.enable", i1 1}
6841 '``llvm.loop.vectorize.scalable.enable``' Metadata
6842 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6844 This metadata selectively enables or disables scalable vectorization for the
6845 loop, and only has any effect if vectorization for the loop is already enabled.
6846 The first operand is the string ``llvm.loop.vectorize.scalable.enable``
6847 and the second operand is a bit. If the bit operand value is 1 scalable
6848 vectorization is enabled, whereas a value of 0 reverts to the default fixed
6849 width vectorization:
6851 .. code-block:: llvm
6853 !0 = !{!"llvm.loop.vectorize.scalable.enable", i1 0}
6854 !1 = !{!"llvm.loop.vectorize.scalable.enable", i1 1}
6856 '``llvm.loop.vectorize.width``' Metadata
6857 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6859 This metadata sets the target width of the vectorizer. The first
6860 operand is the string ``llvm.loop.vectorize.width`` and the second
6861 operand is an integer specifying the width. For example:
6863 .. code-block:: llvm
6865 !0 = !{!"llvm.loop.vectorize.width", i32 4}
6867 Note that setting ``llvm.loop.vectorize.width`` to 1 disables
6868 vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to
6869 0 or if the loop does not have this metadata the width will be
6870 determined automatically.
6872 '``llvm.loop.vectorize.followup_vectorized``' Metadata
6873 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6875 This metadata defines which loop attributes the vectorized loop will
6876 have. See :ref:`transformation-metadata` for details.
6878 '``llvm.loop.vectorize.followup_epilogue``' Metadata
6879 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6881 This metadata defines which loop attributes the epilogue will have. The
6882 epilogue is not vectorized and is executed when either the vectorized
6883 loop is not known to preserve semantics (because e.g., it processes two
6884 arrays that are found to alias by a runtime check) or for the last
6885 iterations that do not fill a complete set of vector lanes. See
6886 :ref:`Transformation Metadata <transformation-metadata>` for details.
6888 '``llvm.loop.vectorize.followup_all``' Metadata
6889 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6891 Attributes in the metadata will be added to both the vectorized and
6893 See :ref:`Transformation Metadata <transformation-metadata>` for details.
6895 '``llvm.loop.unroll``'
6896 ^^^^^^^^^^^^^^^^^^^^^^
6898 Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling
6899 optimization hints such as the unroll factor. ``llvm.loop.unroll``
6900 metadata should be used in conjunction with ``llvm.loop`` loop
6901 identification metadata. The ``llvm.loop.unroll`` metadata are only
6902 optimization hints and the unrolling will only be performed if the
6903 optimizer believes it is safe to do so.
6905 '``llvm.loop.unroll.count``' Metadata
6906 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6908 This metadata suggests an unroll factor to the loop unroller. The
6909 first operand is the string ``llvm.loop.unroll.count`` and the second
6910 operand is a positive integer specifying the unroll factor. For
6913 .. code-block:: llvm
6915 !0 = !{!"llvm.loop.unroll.count", i32 4}
6917 If the trip count of the loop is less than the unroll count the loop
6918 will be partially unrolled.
6920 '``llvm.loop.unroll.disable``' Metadata
6921 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6923 This metadata disables loop unrolling. The metadata has a single operand
6924 which is the string ``llvm.loop.unroll.disable``. For example:
6926 .. code-block:: llvm
6928 !0 = !{!"llvm.loop.unroll.disable"}
6930 '``llvm.loop.unroll.runtime.disable``' Metadata
6931 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6933 This metadata disables runtime loop unrolling. The metadata has a single
6934 operand which is the string ``llvm.loop.unroll.runtime.disable``. For example:
6936 .. code-block:: llvm
6938 !0 = !{!"llvm.loop.unroll.runtime.disable"}
6940 '``llvm.loop.unroll.enable``' Metadata
6941 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6943 This metadata suggests that the loop should be fully unrolled if the trip count
6944 is known at compile time and partially unrolled if the trip count is not known
6945 at compile time. The metadata has a single operand which is the string
6946 ``llvm.loop.unroll.enable``. For example:
6948 .. code-block:: llvm
6950 !0 = !{!"llvm.loop.unroll.enable"}
6952 '``llvm.loop.unroll.full``' Metadata
6953 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6955 This metadata suggests that the loop should be unrolled fully. The
6956 metadata has a single operand which is the string ``llvm.loop.unroll.full``.
6959 .. code-block:: llvm
6961 !0 = !{!"llvm.loop.unroll.full"}
6963 '``llvm.loop.unroll.followup``' Metadata
6964 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6966 This metadata defines which loop attributes the unrolled loop will have.
6967 See :ref:`Transformation Metadata <transformation-metadata>` for details.
6969 '``llvm.loop.unroll.followup_remainder``' Metadata
6970 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6972 This metadata defines which loop attributes the remainder loop after
6973 partial/runtime unrolling will have. See
6974 :ref:`Transformation Metadata <transformation-metadata>` for details.
6976 '``llvm.loop.unroll_and_jam``'
6977 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6979 This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata
6980 above, but affect the unroll and jam pass. In addition any loop with
6981 ``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will
6982 disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the
6983 unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam
6986 The metadata for unroll and jam otherwise is the same as for ``unroll``.
6987 ``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and
6988 ``llvm.loop.unroll_and_jam.count`` do the same as for unroll.
6989 ``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints
6990 and the normal safety checks will still be performed.
6992 '``llvm.loop.unroll_and_jam.count``' Metadata
6993 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6995 This metadata suggests an unroll and jam factor to use, similarly to
6996 ``llvm.loop.unroll.count``. The first operand is the string
6997 ``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer
6998 specifying the unroll factor. For example:
7000 .. code-block:: llvm
7002 !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4}
7004 If the trip count of the loop is less than the unroll count the loop
7005 will be partially unroll and jammed.
7007 '``llvm.loop.unroll_and_jam.disable``' Metadata
7008 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7010 This metadata disables loop unroll and jamming. The metadata has a single
7011 operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example:
7013 .. code-block:: llvm
7015 !0 = !{!"llvm.loop.unroll_and_jam.disable"}
7017 '``llvm.loop.unroll_and_jam.enable``' Metadata
7018 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7020 This metadata suggests that the loop should be fully unroll and jammed if the
7021 trip count is known at compile time and partially unrolled if the trip count is
7022 not known at compile time. The metadata has a single operand which is the
7023 string ``llvm.loop.unroll_and_jam.enable``. For example:
7025 .. code-block:: llvm
7027 !0 = !{!"llvm.loop.unroll_and_jam.enable"}
7029 '``llvm.loop.unroll_and_jam.followup_outer``' Metadata
7030 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7032 This metadata defines which loop attributes the outer unrolled loop will
7033 have. See :ref:`Transformation Metadata <transformation-metadata>` for
7036 '``llvm.loop.unroll_and_jam.followup_inner``' Metadata
7037 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7039 This metadata defines which loop attributes the inner jammed loop will
7040 have. See :ref:`Transformation Metadata <transformation-metadata>` for
7043 '``llvm.loop.unroll_and_jam.followup_remainder_outer``' Metadata
7044 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7046 This metadata defines which attributes the epilogue of the outer loop
7047 will have. This loop is usually unrolled, meaning there is no such
7048 loop. This attribute will be ignored in this case. See
7049 :ref:`Transformation Metadata <transformation-metadata>` for details.
7051 '``llvm.loop.unroll_and_jam.followup_remainder_inner``' Metadata
7052 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7054 This metadata defines which attributes the inner loop of the epilogue
7055 will have. The outer epilogue will usually be unrolled, meaning there
7056 can be multiple inner remainder loops. See
7057 :ref:`Transformation Metadata <transformation-metadata>` for details.
7059 '``llvm.loop.unroll_and_jam.followup_all``' Metadata
7060 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7062 Attributes specified in the metadata is added to all
7063 ``llvm.loop.unroll_and_jam.*`` loops. See
7064 :ref:`Transformation Metadata <transformation-metadata>` for details.
7066 '``llvm.loop.licm_versioning.disable``' Metadata
7067 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7069 This metadata indicates that the loop should not be versioned for the purpose
7070 of enabling loop-invariant code motion (LICM). The metadata has a single operand
7071 which is the string ``llvm.loop.licm_versioning.disable``. For example:
7073 .. code-block:: llvm
7075 !0 = !{!"llvm.loop.licm_versioning.disable"}
7077 '``llvm.loop.distribute.enable``' Metadata
7078 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7080 Loop distribution allows splitting a loop into multiple loops. Currently,
7081 this is only performed if the entire loop cannot be vectorized due to unsafe
7082 memory dependencies. The transformation will attempt to isolate the unsafe
7083 dependencies into their own loop.
7085 This metadata can be used to selectively enable or disable distribution of the
7086 loop. The first operand is the string ``llvm.loop.distribute.enable`` and the
7087 second operand is a bit. If the bit operand value is 1 distribution is
7088 enabled. A value of 0 disables distribution:
7090 .. code-block:: llvm
7092 !0 = !{!"llvm.loop.distribute.enable", i1 0}
7093 !1 = !{!"llvm.loop.distribute.enable", i1 1}
7095 This metadata should be used in conjunction with ``llvm.loop`` loop
7096 identification metadata.
7098 '``llvm.loop.distribute.followup_coincident``' Metadata
7099 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7101 This metadata defines which attributes extracted loops with no cyclic
7102 dependencies will have (i.e. can be vectorized). See
7103 :ref:`Transformation Metadata <transformation-metadata>` for details.
7105 '``llvm.loop.distribute.followup_sequential``' Metadata
7106 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7108 This metadata defines which attributes the isolated loops with unsafe
7109 memory dependencies will have. See
7110 :ref:`Transformation Metadata <transformation-metadata>` for details.
7112 '``llvm.loop.distribute.followup_fallback``' Metadata
7113 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7115 If loop versioning is necessary, this metadata defined the attributes
7116 the non-distributed fallback version will have. See
7117 :ref:`Transformation Metadata <transformation-metadata>` for details.
7119 '``llvm.loop.distribute.followup_all``' Metadata
7120 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7122 The attributes in this metadata is added to all followup loops of the
7123 loop distribution pass. See
7124 :ref:`Transformation Metadata <transformation-metadata>` for details.
7126 '``llvm.licm.disable``' Metadata
7127 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7129 This metadata indicates that loop-invariant code motion (LICM) should not be
7130 performed on this loop. The metadata has a single operand which is the string
7131 ``llvm.licm.disable``. For example:
7133 .. code-block:: llvm
7135 !0 = !{!"llvm.licm.disable"}
7137 Note that although it operates per loop it isn't given the llvm.loop prefix
7138 as it is not affected by the ``llvm.loop.disable_nonforced`` metadata.
7140 '``llvm.access.group``' Metadata
7141 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7143 ``llvm.access.group`` metadata can be attached to any instruction that
7144 potentially accesses memory. It can point to a single distinct metadata
7145 node, which we call access group. This node represents all memory access
7146 instructions referring to it via ``llvm.access.group``. When an
7147 instruction belongs to multiple access groups, it can also point to a
7148 list of accesses groups, illustrated by the following example.
7150 .. code-block:: llvm
7152 %val = load i32, ptr %arrayidx, !llvm.access.group !0
7158 It is illegal for the list node to be empty since it might be confused
7159 with an access group.
7161 The access group metadata node must be 'distinct' to avoid collapsing
7162 multiple access groups by content. An access group metadata node must
7163 always be empty which can be used to distinguish an access group
7164 metadata node from a list of access groups. Being empty avoids the
7165 situation that the content must be updated which, because metadata is
7166 immutable by design, would required finding and updating all references
7167 to the access group node.
7169 The access group can be used to refer to a memory access instruction
7170 without pointing to it directly (which is not possible in global
7171 metadata). Currently, the only metadata making use of it is
7172 ``llvm.loop.parallel_accesses``.
7174 '``llvm.loop.parallel_accesses``' Metadata
7175 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7177 The ``llvm.loop.parallel_accesses`` metadata refers to one or more
7178 access group metadata nodes (see ``llvm.access.group``). It denotes that
7179 no loop-carried memory dependence exist between it and other instructions
7180 in the loop with this metadata.
7182 Let ``m1`` and ``m2`` be two instructions that both have the
7183 ``llvm.access.group`` metadata to the access group ``g1``, respectively
7184 ``g2`` (which might be identical). If a loop contains both access groups
7185 in its ``llvm.loop.parallel_accesses`` metadata, then the compiler can
7186 assume that there is no dependency between ``m1`` and ``m2`` carried by
7187 this loop. Instructions that belong to multiple access groups are
7188 considered having this property if at least one of the access groups
7189 matches the ``llvm.loop.parallel_accesses`` list.
7191 If all memory-accessing instructions in a loop have
7192 ``llvm.access.group`` metadata that each refer to one of the access
7193 groups of a loop's ``llvm.loop.parallel_accesses`` metadata, then the
7194 loop has no loop carried memory dependences and is considered to be a
7197 Note that if not all memory access instructions belong to an access
7198 group referred to by ``llvm.loop.parallel_accesses``, then the loop must
7199 not be considered trivially parallel. Additional
7200 memory dependence analysis is required to make that determination. As a fail
7201 safe mechanism, this causes loops that were originally parallel to be considered
7202 sequential (if optimization passes that are unaware of the parallel semantics
7203 insert new memory instructions into the loop body).
7205 Example of a loop that is considered parallel due to its correct use of
7206 both ``llvm.access.group`` and ``llvm.loop.parallel_accesses``
7209 .. code-block:: llvm
7213 %val0 = load i32, ptr %arrayidx, !llvm.access.group !1
7215 store i32 %val0, ptr %arrayidx1, !llvm.access.group !1
7217 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
7221 !0 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !1}}
7224 It is also possible to have nested parallel loops:
7226 .. code-block:: llvm
7230 %val1 = load i32, ptr %arrayidx3, !llvm.access.group !4
7232 br label %inner.for.body
7236 %val0 = load i32, ptr %arrayidx1, !llvm.access.group !3
7238 store i32 %val0, ptr %arrayidx2, !llvm.access.group !3
7240 br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1
7244 store i32 %val1, ptr %arrayidx4, !llvm.access.group !4
7246 br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2
7248 outer.for.end: ; preds = %for.body
7250 !1 = distinct !{!1, !{!"llvm.loop.parallel_accesses", !3}} ; metadata for the inner loop
7251 !2 = distinct !{!2, !{!"llvm.loop.parallel_accesses", !3, !4}} ; metadata for the outer loop
7252 !3 = distinct !{} ; access group for instructions in the inner loop (which are implicitly contained in outer loop as well)
7253 !4 = distinct !{} ; access group for instructions in the outer, but not the inner loop
7255 .. _langref_llvm_loop_mustprogress:
7257 '``llvm.loop.mustprogress``' Metadata
7258 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7260 The ``llvm.loop.mustprogress`` metadata indicates that this loop is required to
7261 terminate, unwind, or interact with the environment in an observable way e.g.
7262 via a volatile memory access, I/O, or other synchronization. If such a loop is
7263 not found to interact with the environment in an observable way, the loop may
7264 be removed. This corresponds to the ``mustprogress`` function attribute.
7266 '``irr_loop``' Metadata
7267 ^^^^^^^^^^^^^^^^^^^^^^^
7269 ``irr_loop`` metadata may be attached to the terminator instruction of a basic
7270 block that's an irreducible loop header (note that an irreducible loop has more
7271 than once header basic blocks.) If ``irr_loop`` metadata is attached to the
7272 terminator instruction of a basic block that is not really an irreducible loop
7273 header, the behavior is undefined. The intent of this metadata is to improve the
7274 accuracy of the block frequency propagation. For example, in the code below, the
7275 block ``header0`` may have a loop header weight (relative to the other headers of
7276 the irreducible loop) of 100:
7278 .. code-block:: llvm
7282 br i1 %cmp, label %t1, label %t2, !irr_loop !0
7285 !0 = !{"loop_header_weight", i64 100}
7287 Irreducible loop header weights are typically based on profile data.
7289 .. _md_invariant.group:
7291 '``invariant.group``' Metadata
7292 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7294 The experimental ``invariant.group`` metadata may be attached to
7295 ``load``/``store`` instructions referencing a single metadata with no entries.
7296 The existence of the ``invariant.group`` metadata on the instruction tells
7297 the optimizer that every ``load`` and ``store`` to the same pointer operand
7298 can be assumed to load or store the same
7299 value (but see the ``llvm.launder.invariant.group`` intrinsic which affects
7300 when two pointers are considered the same). Pointers returned by bitcast or
7301 getelementptr with only zero indices are considered the same.
7305 .. code-block:: llvm
7307 @unknownPtr = external global i8
7310 store i8 42, ptr %ptr, !invariant.group !0
7311 call void @foo(ptr %ptr)
7313 %a = load i8, ptr %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change
7314 call void @foo(ptr %ptr)
7316 %newPtr = call ptr @getPointer(ptr %ptr)
7317 %c = load i8, ptr %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr
7319 %unknownValue = load i8, ptr @unknownPtr
7320 store i8 %unknownValue, ptr %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42
7322 call void @foo(ptr %ptr)
7323 %newPtr2 = call ptr @llvm.launder.invariant.group.p0(ptr %ptr)
7324 %d = load i8, ptr %newPtr2, !invariant.group !0 ; Can't step through launder.invariant.group to get value of %ptr
7327 declare void @foo(ptr)
7328 declare ptr @getPointer(ptr)
7329 declare ptr @llvm.launder.invariant.group.p0(ptr)
7333 The invariant.group metadata must be dropped when replacing one pointer by
7334 another based on aliasing information. This is because invariant.group is tied
7335 to the SSA value of the pointer operand.
7337 .. code-block:: llvm
7339 %v = load i8, ptr %x, !invariant.group !0
7340 ; if %x mustalias %y then we can replace the above instruction with
7341 %v = load i8, ptr %y
7343 Note that this is an experimental feature, which means that its semantics might
7344 change in the future.
7349 See :doc:`TypeMetadata`.
7351 '``associated``' Metadata
7352 ^^^^^^^^^^^^^^^^^^^^^^^^^
7354 The ``associated`` metadata may be attached to a global variable definition with
7355 a single argument that references a global object (optionally through an alias).
7357 This metadata lowers to the ELF section flag ``SHF_LINK_ORDER`` which prevents
7358 discarding of the global variable in linker GC unless the referenced object is
7359 also discarded. The linker support for this feature is spotty. For best
7360 compatibility, globals carrying this metadata should:
7362 - Be in ``@llvm.compiler.used``.
7363 - If the referenced global variable is in a comdat, be in the same comdat.
7365 ``!associated`` can not express many-to-one relationship. A global variable with
7366 the metadata should generally not be referenced by a function: the function may
7367 be inlined into other functions, leading to more references to the metadata.
7368 Ideally we would want to keep metadata alive as long as any inline location is
7369 alive, but this many-to-one relationship is not representable. Moreover, if the
7370 metadata is retained while the function is discarded, the linker will report an
7371 error of a relocation referencing a discarded section.
7373 The metadata is often used with an explicit section consisting of valid C
7374 identifiers so that the runtime can find the metadata section with
7375 linker-defined encapsulation symbols ``__start_<section_name>`` and
7376 ``__stop_<section_name>``.
7378 It does not have any effect on non-ELF targets.
7382 .. code-block:: text
7385 @a = global i32 1, comdat $a
7386 @b = internal global i32 2, comdat $a, section "abc", !associated !0
7393 The ``prof`` metadata is used to record profile data in the IR.
7394 The first operand of the metadata node indicates the profile metadata
7395 type. There are currently 3 types:
7396 :ref:`branch_weights<prof_node_branch_weights>`,
7397 :ref:`function_entry_count<prof_node_function_entry_count>`, and
7398 :ref:`VP<prof_node_VP>`.
7400 .. _prof_node_branch_weights:
7405 Branch weight metadata attached to a branch, select, switch or call instruction
7406 represents the likeliness of the associated branch being taken.
7407 For more information, see :doc:`BranchWeightMetadata`.
7409 .. _prof_node_function_entry_count:
7411 function_entry_count
7412 """"""""""""""""""""
7414 Function entry count metadata can be attached to function definitions
7415 to record the number of times the function is called. Used with BFI
7416 information, it is also used to derive the basic block profile count.
7417 For more information, see :doc:`BranchWeightMetadata`.
7424 VP (value profile) metadata can be attached to instructions that have
7425 value profile information. Currently this is indirect calls (where it
7426 records the hottest callees) and calls to memory intrinsics such as memcpy,
7427 memmove, and memset (where it records the hottest byte lengths).
7429 Each VP metadata node contains "VP" string, then a uint32_t value for the value
7430 profiling kind, a uint64_t value for the total number of times the instruction
7431 is executed, followed by uint64_t value and execution count pairs.
7432 The value profiling kind is 0 for indirect call targets and 1 for memory
7433 operations. For indirect call targets, each profile value is a hash
7434 of the callee function name, and for memory operations each value is the
7437 Note that the value counts do not need to add up to the total count
7438 listed in the third operand (in practice only the top hottest values
7439 are tracked and reported).
7441 Indirect call example:
7443 .. code-block:: llvm
7445 call void %f(), !prof !1
7446 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410}
7448 Note that the VP type is 0 (the second operand), which indicates this is
7449 an indirect call value profile data. The third operand indicates that the
7450 indirect call executed 1600 times. The 4th and 6th operands give the
7451 hashes of the 2 hottest target functions' names (this is the same hash used
7452 to represent function names in the profile database), and the 5th and 7th
7453 operands give the execution count that each of the respective prior target
7454 functions was called.
7458 '``annotation``' Metadata
7459 ^^^^^^^^^^^^^^^^^^^^^^^^^
7461 The ``annotation`` metadata can be used to attach a tuple of annotation strings
7462 or a tuple of a tuple of annotation strings to any instruction. This metadata does
7463 not impact the semantics of the program and may only be used to provide additional
7464 insight about the program and transformations to users.
7468 .. code-block:: text
7470 %a.addr = alloca ptr, align 8, !annotation !0
7471 !0 = !{!"auto-init"}
7473 Embedding tuple of strings example:
7475 .. code-block:: text
7477 %a.ptr = getelementptr ptr, ptr %base, i64 0. !annotation !0
7479 !1 = !{!"gep offset", !"0"}
7481 '``func_sanitize``' Metadata
7482 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7484 The ``func_sanitize`` metadata is used to attach two values for the function
7485 sanitizer instrumentation. The first value is the ubsan function signature.
7486 The second value is the address of the proxy variable which stores the address
7487 of the RTTI descriptor. If :ref:`prologue <prologuedata>` and '``func_sanitize``'
7488 are used at the same time, :ref:`prologue <prologuedata>` is emitted before
7489 '``func_sanitize``' in the output.
7493 .. code-block:: text
7495 @__llvm_rtti_proxy = private unnamed_addr constant ptr @_ZTIFvvE
7496 define void @_Z3funv() !func_sanitize !0 {
7499 !0 = !{i32 846595819, ptr @__llvm_rtti_proxy}
7503 '``kcfi_type``' Metadata
7504 ^^^^^^^^^^^^^^^^^^^^^^^^
7506 The ``kcfi_type`` metadata can be used to attach a type identifier to
7507 functions that can be called indirectly. The type data is emitted before the
7508 function entry in the assembly. Indirect calls with the :ref:`kcfi operand
7509 bundle<ob_kcfi>` will emit a check that compares the type identifier to the
7514 .. code-block:: text
7516 define dso_local i32 @f() !kcfi_type !0 {
7519 !0 = !{i32 12345678}
7521 Clang emits ``kcfi_type`` metadata nodes for address-taken functions with
7522 ``-fsanitize=kcfi``.
7526 '``memprof``' Metadata
7527 ^^^^^^^^^^^^^^^^^^^^^^^^
7529 The ``memprof`` metadata is used to record memory profile data on heap
7530 allocation calls. Multiple context-sensitive profiles can be represented
7531 with a single ``memprof`` metadata attachment.
7535 .. code-block:: text
7537 %call = call ptr @_Znam(i64 10), !memprof !0, !callsite !5
7540 !2 = !{i64 4854880825882961848, i64 1905834578520680781}
7541 !3 = !{!4, !"notcold"}
7542 !4 = !{i64 4854880825882961848, i64 -6528110295079665978}
7543 !5 = !{i64 4854880825882961848}
7545 Each operand in the ``memprof`` metadata attachment describes the profiled
7546 behavior of memory allocated by the associated allocation for a given context.
7547 In the above example, there were 2 profiled contexts, one allocating memory
7548 that was typically cold and one allocating memory that was typically not cold.
7550 The format of the metadata describing a context specific profile (e.g.
7551 ``!1`` and ``!3`` above) requires a first operand that is a metadata node
7552 describing the context, followed by a list of string metadata tags describing
7553 the profile behavior (e.g. ``cold`` and ``notcold``) above. The metadata nodes
7554 describing the context (e.g. ``!2`` and ``!4`` above) are unique ids
7555 corresponding to callsites, which can be matched to associated IR calls via
7556 :ref:`callsite metadata<md_callsite>`. In practice these ids are formed via
7557 a hash of the callsite's debug info, and the associated call may be in a
7558 different module. The contexts are listed in order from leaf-most call (the
7559 allocation itself) to the outermost callsite context required for uniquely
7560 identifying the described profile behavior (note this may not be the top of
7561 the profiled call stack).
7565 '``callsite``' Metadata
7566 ^^^^^^^^^^^^^^^^^^^^^^^^
7568 The ``callsite`` metadata is used to identify callsites involved in memory
7569 profile contexts described in :ref:`memprof metadata<md_memprof>`.
7571 It is attached both to the profile allocation calls (see the example in
7572 :ref:`memprof metadata<md_memprof>`), as well as to other callsites
7573 in profiled contexts described in heap allocation ``memprof`` metadata.
7577 .. code-block:: text
7579 %call = call ptr @_Z1Bb(void), !callsite !0
7580 !0 = !{i64 -6528110295079665978, i64 5462047985461644151}
7582 Each operand in the ``callsite`` metadata attachment is a unique id
7583 corresponding to a callsite (possibly inlined). In practice these ids are
7584 formed via a hash of the callsite's debug info. If the call was not inlined
7585 into any callers it will contain a single operand (id). If it was inlined
7586 it will contain a list of ids, including the ids of the callsites in the
7587 full inline sequence, in order from the leaf-most call's id to the outermost
7590 Module Flags Metadata
7591 =====================
7593 Information about the module as a whole is difficult to convey to LLVM's
7594 subsystems. The LLVM IR isn't sufficient to transmit this information.
7595 The ``llvm.module.flags`` named metadata exists in order to facilitate
7596 this. These flags are in the form of key / value pairs --- much like a
7597 dictionary --- making it easy for any subsystem who cares about a flag to
7600 The ``llvm.module.flags`` metadata contains a list of metadata triplets.
7601 Each triplet has the following form:
7603 - The first element is a *behavior* flag, which specifies the behavior
7604 when two (or more) modules are merged together, and it encounters two
7605 (or more) metadata with the same ID. The supported behaviors are
7607 - The second element is a metadata string that is a unique ID for the
7608 metadata. Each module may only have one flag entry for each unique ID (not
7609 including entries with the **Require** behavior).
7610 - The third element is the value of the flag.
7612 When two (or more) modules are merged together, the resulting
7613 ``llvm.module.flags`` metadata is the union of the modules' flags. That is, for
7614 each unique metadata ID string, there will be exactly one entry in the merged
7615 modules ``llvm.module.flags`` metadata table, and the value for that entry will
7616 be determined by the merge behavior flag, as described below. The only exception
7617 is that entries with the *Require* behavior are always preserved.
7619 The following behaviors are supported:
7630 Emits an error if two values disagree, otherwise the resulting value
7631 is that of the operands.
7635 Emits a warning if two values disagree. The result value will be the
7636 operand for the flag from the first module being linked, unless the
7637 other module uses **Min** or **Max**, in which case the result will
7638 be **Min** (with the min value) or **Max** (with the max value),
7643 Adds a requirement that another module flag be present and have a
7644 specified value after linking is performed. The value must be a
7645 metadata pair, where the first element of the pair is the ID of the
7646 module flag to be restricted, and the second element of the pair is
7647 the value the module flag should be restricted to. This behavior can
7648 be used to restrict the allowable results (via triggering of an
7649 error) of linking IDs with the **Override** behavior.
7653 Uses the specified value, regardless of the behavior or value of the
7654 other module. If both modules specify **Override**, but the values
7655 differ, an error will be emitted.
7659 Appends the two values, which are required to be metadata nodes.
7663 Appends the two values, which are required to be metadata
7664 nodes. However, duplicate entries in the second list are dropped
7665 during the append operation.
7669 Takes the max of the two values, which are required to be integers.
7673 Takes the min of the two values, which are required to be non-negative integers.
7674 An absent module flag is treated as having the value 0.
7676 It is an error for a particular unique flag ID to have multiple behaviors,
7677 except in the case of **Require** (which adds restrictions on another metadata
7678 value) or **Override**.
7680 An example of module flags:
7682 .. code-block:: llvm
7684 !0 = !{ i32 1, !"foo", i32 1 }
7685 !1 = !{ i32 4, !"bar", i32 37 }
7686 !2 = !{ i32 2, !"qux", i32 42 }
7687 !3 = !{ i32 3, !"qux",
7692 !llvm.module.flags = !{ !0, !1, !2, !3 }
7694 - Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior
7695 if two or more ``!"foo"`` flags are seen is to emit an error if their
7696 values are not equal.
7698 - Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The
7699 behavior if two or more ``!"bar"`` flags are seen is to use the value
7702 - Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The
7703 behavior if two or more ``!"qux"`` flags are seen is to emit a
7704 warning if their values are not equal.
7706 - Metadata ``!3`` has the ID ``!"qux"`` and the value:
7712 The behavior is to emit an error if the ``llvm.module.flags`` does not
7713 contain a flag with the ID ``!"foo"`` that has the value '1' after linking is
7716 Synthesized Functions Module Flags Metadata
7717 -------------------------------------------
7719 These metadata specify the default attributes synthesized functions should have.
7720 These metadata are currently respected by a few instrumentation passes, such as
7723 These metadata correspond to a few function attributes with significant code
7724 generation behaviors. Function attributes with just optimization purposes
7725 should not be listed because the performance impact of these synthesized
7728 - "frame-pointer": **Max**. The value can be 0, 1, or 2. A synthesized function
7729 will get the "frame-pointer" function attribute, with value being "none",
7730 "non-leaf", or "all", respectively.
7731 - "function_return_thunk_extern": The synthesized function will get the
7732 ``fn_return_thunk_extern`` function attribute.
7733 - "uwtable": **Max**. The value can be 0, 1, or 2. If the value is 1, a synthesized
7734 function will get the ``uwtable(sync)`` function attribute, if the value is 2,
7735 a synthesized function will get the ``uwtable(async)`` function attribute.
7737 Objective-C Garbage Collection Module Flags Metadata
7738 ----------------------------------------------------
7740 On the Mach-O platform, Objective-C stores metadata about garbage
7741 collection in a special section called "image info". The metadata
7742 consists of a version number and a bitmask specifying what types of
7743 garbage collection are supported (if any) by the file. If two or more
7744 modules are linked together their garbage collection metadata needs to
7745 be merged rather than appended together.
7747 The Objective-C garbage collection module flags metadata consists of the
7748 following key-value pairs:
7757 * - ``Objective-C Version``
7758 - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2.
7760 * - ``Objective-C Image Info Version``
7761 - **[Required]** --- The version of the image info section. Currently
7764 * - ``Objective-C Image Info Section``
7765 - **[Required]** --- The section to place the metadata. Valid values are
7766 ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and
7767 ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for
7768 Objective-C ABI version 2.
7770 * - ``Objective-C Garbage Collection``
7771 - **[Required]** --- Specifies whether garbage collection is supported or
7772 not. Valid values are 0, for no garbage collection, and 2, for garbage
7773 collection supported.
7775 * - ``Objective-C GC Only``
7776 - **[Optional]** --- Specifies that only garbage collection is supported.
7777 If present, its value must be 6. This flag requires that the
7778 ``Objective-C Garbage Collection`` flag have the value 2.
7780 Some important flag interactions:
7782 - If a module with ``Objective-C Garbage Collection`` set to 0 is
7783 merged with a module with ``Objective-C Garbage Collection`` set to
7784 2, then the resulting module has the
7785 ``Objective-C Garbage Collection`` flag set to 0.
7786 - A module with ``Objective-C Garbage Collection`` set to 0 cannot be
7787 merged with a module with ``Objective-C GC Only`` set to 6.
7789 C type width Module Flags Metadata
7790 ----------------------------------
7792 The ARM backend emits a section into each generated object file describing the
7793 options that it was compiled with (in a compiler-independent way) to prevent
7794 linking incompatible objects, and to allow automatic library selection. Some
7795 of these options are not visible at the IR level, namely wchar_t width and enum
7798 To pass this information to the backend, these options are encoded in module
7799 flags metadata, using the following key-value pairs:
7809 - * 0 --- sizeof(wchar_t) == 4
7810 * 1 --- sizeof(wchar_t) == 2
7813 - * 0 --- Enums are at least as large as an ``int``.
7814 * 1 --- Enums are stored in the smallest integer type which can
7815 represent all of its values.
7817 For example, the following metadata section specifies that the module was
7818 compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an
7819 enum is the smallest type which can represent all of its values::
7821 !llvm.module.flags = !{!0, !1}
7822 !0 = !{i32 1, !"short_wchar", i32 1}
7823 !1 = !{i32 1, !"short_enum", i32 0}
7825 Stack Alignment Metadata
7826 ------------------------
7828 Changes the default stack alignment from the target ABI's implicit default
7829 stack alignment. Takes an i32 value in bytes. It is considered an error to link
7830 two modules together with different values for this metadata.
7834 !llvm.module.flags = !{!0}
7835 !0 = !{i32 1, !"override-stack-alignment", i32 8}
7837 This will change the stack alignment to 8B.
7839 Embedded Objects Names Metadata
7840 ===============================
7842 Offloading compilations need to embed device code into the host section table to
7843 create a fat binary. This metadata node references each global that will be
7844 embedded in the module. The primary use for this is to make referencing these
7845 globals more efficient in the IR. The metadata references nodes containing
7846 pointers to the global to be embedded followed by the section name it will be
7849 !llvm.embedded.objects = !{!0}
7850 !0 = !{ptr @object, !".section"}
7852 Automatic Linker Flags Named Metadata
7853 =====================================
7855 Some targets support embedding of flags to the linker inside individual object
7856 files. Typically this is used in conjunction with language extensions which
7857 allow source files to contain linker command line options, and have these
7858 automatically be transmitted to the linker via object files.
7860 These flags are encoded in the IR using named metadata with the name
7861 ``!llvm.linker.options``. Each operand is expected to be a metadata node
7862 which should be a list of other metadata nodes, each of which should be a
7863 list of metadata strings defining linker options.
7865 For example, the following metadata section specifies two separate sets of
7866 linker options, presumably to link against ``libz`` and the ``Cocoa``
7870 !1 = !{ !"-framework", !"Cocoa" }
7871 !llvm.linker.options = !{ !0, !1 }
7873 The metadata encoding as lists of lists of options, as opposed to a collapsed
7874 list of options, is chosen so that the IR encoding can use multiple option
7875 strings to specify e.g., a single library, while still having that specifier be
7876 preserved as an atomic element that can be recognized by a target specific
7877 assembly writer or object file emitter.
7879 Each individual option is required to be either a valid option for the target's
7880 linker, or an option that is reserved by the target specific assembly writer or
7881 object file emitter. No other aspect of these options is defined by the IR.
7883 Dependent Libs Named Metadata
7884 =============================
7886 Some targets support embedding of strings into object files to indicate
7887 a set of libraries to add to the link. Typically this is used in conjunction
7888 with language extensions which allow source files to explicitly declare the
7889 libraries they depend on, and have these automatically be transmitted to the
7890 linker via object files.
7892 The list is encoded in the IR using named metadata with the name
7893 ``!llvm.dependent-libraries``. Each operand is expected to be a metadata node
7894 which should contain a single string operand.
7896 For example, the following metadata section contains two library specifiers::
7898 !0 = !{!"a library specifier"}
7899 !1 = !{!"another library specifier"}
7900 !llvm.dependent-libraries = !{ !0, !1 }
7902 Each library specifier will be handled independently by the consuming linker.
7903 The effect of the library specifiers are defined by the consuming linker.
7910 Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_
7911 causes the building of a compact summary of the module that is emitted into
7912 the bitcode. The summary is emitted into the LLVM assembly and identified
7913 in syntax by a caret ('``^``').
7915 The summary is parsed into a bitcode output, along with the Module
7916 IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes
7917 of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the
7918 summary entries (just as they currently ignore summary entries in a bitcode
7921 Eventually, the summary will be parsed into a ModuleSummaryIndex object under
7922 the same conditions where summary index is currently built from bitcode.
7923 Specifically, tools that test the Thin Link portion of a ThinLTO compile
7924 (i.e. llvm-lto and llvm-lto2), or when parsing a combined index
7925 for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag
7926 (this part is not yet implemented, use llvm-as to create a bitcode object
7927 before feeding into thin link tools for now).
7929 There are currently 3 types of summary entries in the LLVM assembly:
7930 :ref:`module paths<module_path_summary>`,
7931 :ref:`global values<gv_summary>`, and
7932 :ref:`type identifiers<typeid_summary>`.
7934 .. _module_path_summary:
7936 Module Path Summary Entry
7937 -------------------------
7939 Each module path summary entry lists a module containing global values included
7940 in the summary. For a single IR module there will be one such entry, but
7941 in a combined summary index produced during the thin link, there will be
7942 one module path entry per linked module with summary.
7946 .. code-block:: text
7948 ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418))
7950 The ``path`` field is a string path to the bitcode file, and the ``hash``
7951 field is the 160-bit SHA-1 hash of the IR bitcode contents, used for
7952 incremental builds and caching.
7956 Global Value Summary Entry
7957 --------------------------
7959 Each global value summary entry corresponds to a global value defined or
7960 referenced by a summarized module.
7964 .. code-block:: text
7966 ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831
7968 For declarations, there will not be a summary list. For definitions, a
7969 global value will contain a list of summaries, one per module containing
7970 a definition. There can be multiple entries in a combined summary index
7971 for symbols with weak linkage.
7973 Each ``Summary`` format will depend on whether the global value is a
7974 :ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or
7975 :ref:`alias<alias_summary>`.
7977 .. _function_summary:
7982 If the global value is a function, the ``Summary`` entry will look like:
7984 .. code-block:: text
7986 function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Params]?[, Refs]?
7988 The ``module`` field includes the summary entry id for the module containing
7989 this definition, and the ``flags`` field contains information such as
7990 the linkage type, a flag indicating whether it is legal to import the
7991 definition, whether it is globally live and whether the linker resolved it
7992 to a local definition (the latter two are populated during the thin link).
7993 The ``insts`` field contains the number of IR instructions in the function.
7994 Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`,
7995 :ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`,
7996 :ref:`Params<params_summary>`, :ref:`Refs<refs_summary>`.
7998 .. _variable_summary:
8000 Global Variable Summary
8001 ^^^^^^^^^^^^^^^^^^^^^^^
8003 If the global value is a variable, the ``Summary`` entry will look like:
8005 .. code-block:: text
8007 variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]?
8009 The variable entry contains a subset of the fields in a
8010 :ref:`function summary <function_summary>`, see the descriptions there.
8017 If the global value is an alias, the ``Summary`` entry will look like:
8019 .. code-block:: text
8021 alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2)
8023 The ``module`` and ``flags`` fields are as described for a
8024 :ref:`function summary <function_summary>`. The ``aliasee`` field
8025 contains a reference to the global value summary entry of the aliasee.
8027 .. _funcflags_summary:
8032 The optional ``FuncFlags`` field looks like:
8034 .. code-block:: text
8036 funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0, noUnwind: 1, mayThrow: 0, hasUnknownCall: 0)
8038 If unspecified, flags are assumed to hold the conservative ``false`` value of
8046 The optional ``Calls`` field looks like:
8048 .. code-block:: text
8050 calls: ((Callee)[, (Callee)]*)
8052 where each ``Callee`` looks like:
8054 .. code-block:: text
8056 callee: ^1[, hotness: None]?[, relbf: 0]?
8058 The ``callee`` refers to the summary entry id of the callee. At most one
8059 of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``,
8060 ``Hot``, and ``Critical``), and ``relbf`` (which holds the integer
8061 branch frequency relative to the entry frequency, scaled down by 2^8)
8062 may be specified. The defaults are ``Unknown`` and ``0``, respectively.
8069 The optional ``Params`` is used by ``StackSafety`` and looks like:
8071 .. code-block:: text
8073 Params: ((Param)[, (Param)]*)
8075 where each ``Param`` describes pointer parameter access inside of the
8076 function and looks like:
8078 .. code-block:: text
8080 param: 4, offset: [0, 5][, calls: ((Callee)[, (Callee)]*)]?
8082 where the first ``param`` is the number of the parameter it describes,
8083 ``offset`` is the inclusive range of offsets from the pointer parameter to bytes
8084 which can be accessed by the function. This range does not include accesses by
8085 function calls from ``calls`` list.
8087 where each ``Callee`` describes how parameter is forwarded into other
8088 functions and looks like:
8090 .. code-block:: text
8092 callee: ^3, param: 5, offset: [-3, 3]
8094 The ``callee`` refers to the summary entry id of the callee, ``param`` is
8095 the number of the callee parameter which points into the callers parameter
8096 with offset known to be inside of the ``offset`` range. ``calls`` will be
8097 consumed and removed by thin link stage to update ``Param::offset`` so it
8098 covers all accesses possible by ``calls``.
8100 Pointer parameter without corresponding ``Param`` is considered unsafe and we
8101 assume that access with any offset is possible.
8105 If we have the following function:
8107 .. code-block:: text
8109 define i64 @foo(ptr %0, ptr %1, ptr %2, i8 %3) {
8110 store ptr %1, ptr @x
8111 %5 = getelementptr inbounds i8, ptr %2, i64 5
8112 %6 = load i8, ptr %5
8113 %7 = getelementptr inbounds i8, ptr %2, i8 %3
8114 tail call void @bar(i8 %3, ptr %7)
8115 %8 = load i64, ptr %0
8119 We can expect the record like this:
8121 .. code-block:: text
8123 params: ((param: 0, offset: [0, 7]),(param: 2, offset: [5, 5], calls: ((callee: ^3, param: 1, offset: [-128, 127]))))
8125 The function may access just 8 bytes of the parameter %0 . ``calls`` is empty,
8126 so the parameter is either not used for function calls or ``offset`` already
8127 covers all accesses from nested function calls.
8128 Parameter %1 escapes, so access is unknown.
8129 The function itself can access just a single byte of the parameter %2. Additional
8130 access is possible inside of the ``@bar`` or ``^3``. The function adds signed
8131 offset to the pointer and passes the result as the argument %1 into ``^3``.
8132 This record itself does not tell us how ``^3`` will access the parameter.
8133 Parameter %3 is not a pointer.
8140 The optional ``Refs`` field looks like:
8142 .. code-block:: text
8144 refs: ((Ref)[, (Ref)]*)
8146 where each ``Ref`` contains a reference to the summary id of the referenced
8147 value (e.g. ``^1``).
8149 .. _typeidinfo_summary:
8154 The optional ``TypeIdInfo`` field, used for
8155 `Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
8158 .. code-block:: text
8160 typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]?
8162 These optional fields have the following forms:
8167 .. code-block:: text
8169 typeTests: (TypeIdRef[, TypeIdRef]*)
8171 Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
8172 by summary id or ``GUID``.
8174 TypeTestAssumeVCalls
8175 """"""""""""""""""""
8177 .. code-block:: text
8179 typeTestAssumeVCalls: (VFuncId[, VFuncId]*)
8181 Where each VFuncId has the format:
8183 .. code-block:: text
8185 vFuncId: (TypeIdRef, offset: 16)
8187 Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
8188 by summary id or ``GUID`` preceded by a ``guid:`` tag.
8190 TypeCheckedLoadVCalls
8191 """""""""""""""""""""
8193 .. code-block:: text
8195 typeCheckedLoadVCalls: (VFuncId[, VFuncId]*)
8197 Where each VFuncId has the format described for ``TypeTestAssumeVCalls``.
8199 TypeTestAssumeConstVCalls
8200 """""""""""""""""""""""""
8202 .. code-block:: text
8204 typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*)
8206 Where each ConstVCall has the format:
8208 .. code-block:: text
8210 (VFuncId, args: (Arg[, Arg]*))
8212 and where each VFuncId has the format described for ``TypeTestAssumeVCalls``,
8213 and each Arg is an integer argument number.
8215 TypeCheckedLoadConstVCalls
8216 """"""""""""""""""""""""""
8218 .. code-block:: text
8220 typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*)
8222 Where each ConstVCall has the format described for
8223 ``TypeTestAssumeConstVCalls``.
8227 Type ID Summary Entry
8228 ---------------------
8230 Each type id summary entry corresponds to a type identifier resolution
8231 which is generated during the LTO link portion of the compile when building
8232 with `Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
8233 so these are only present in a combined summary index.
8237 .. code-block:: text
8239 ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778
8241 The ``typeTestRes`` gives the type test resolution ``kind`` (which may
8242 be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and
8243 the ``size-1`` bit width. It is followed by optional flags, which default to 0,
8244 and an optional WpdResolutions (whole program devirtualization resolution)
8245 field that looks like:
8247 .. code-block:: text
8249 wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]*
8251 where each entry is a mapping from the given byte offset to the whole-program
8252 devirtualization resolution WpdRes, that has one of the following formats:
8254 .. code-block:: text
8256 wpdRes: (kind: branchFunnel)
8257 wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi")
8258 wpdRes: (kind: indir)
8260 Additionally, each wpdRes has an optional ``resByArg`` field, which
8261 describes the resolutions for calls with all constant integer arguments:
8263 .. code-block:: text
8265 resByArg: (ResByArg[, ResByArg]*)
8269 .. code-block:: text
8271 args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0])
8273 Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal``
8274 or ``VirtualConstProp``. The ``info`` field is only used if the kind
8275 is ``UniformRetVal`` (indicates the uniform return value), or
8276 ``UniqueRetVal`` (holds the return value associated with the unique vtable
8277 (0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does
8278 not support the use of absolute symbols to store constants.
8280 .. _intrinsicglobalvariables:
8282 Intrinsic Global Variables
8283 ==========================
8285 LLVM has a number of "magic" global variables that contain data that
8286 affect code generation or other IR semantics. These are documented here.
8287 All globals of this sort should have a section specified as
8288 "``llvm.metadata``". This section and all globals that start with
8289 "``llvm.``" are reserved for use by LLVM.
8293 The '``llvm.used``' Global Variable
8294 -----------------------------------
8296 The ``@llvm.used`` global is an array which has
8297 :ref:`appending linkage <linkage_appending>`. This array contains a list of
8298 pointers to named global variables, functions and aliases which may optionally
8299 have a pointer cast formed of bitcast or getelementptr. For example, a legal
8302 .. code-block:: llvm
8307 @llvm.used = appending global [2 x ptr] [
8310 ], section "llvm.metadata"
8312 If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler,
8313 and linker are required to treat the symbol as if there is a reference to the
8314 symbol that it cannot see (which is why they have to be named). For example, if
8315 a variable has internal linkage and no references other than that from the
8316 ``@llvm.used`` list, it cannot be deleted. This is commonly used to represent
8317 references from inline asms and other things the compiler cannot "see", and
8318 corresponds to "``attribute((used))``" in GNU C.
8320 On some targets, the code generator must emit a directive to the
8321 assembler or object file to prevent the assembler and linker from
8322 removing the symbol.
8324 .. _gv_llvmcompilerused:
8326 The '``llvm.compiler.used``' Global Variable
8327 --------------------------------------------
8329 The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used``
8330 directive, except that it only prevents the compiler from touching the
8331 symbol. On targets that support it, this allows an intelligent linker to
8332 optimize references to the symbol without being impeded as it would be
8335 This is a rare construct that should only be used in rare circumstances,
8336 and should not be exposed to source languages.
8338 .. _gv_llvmglobalctors:
8340 The '``llvm.global_ctors``' Global Variable
8341 -------------------------------------------
8343 .. code-block:: llvm
8345 %0 = type { i32, ptr, ptr }
8346 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, ptr @ctor, ptr @data }]
8348 The ``@llvm.global_ctors`` array contains a list of constructor
8349 functions, priorities, and an associated global or function.
8350 The functions referenced by this array will be called in ascending order
8351 of priority (i.e. lowest first) when the module is loaded. The order of
8352 functions with the same priority is not defined.
8354 If the third field is non-null, and points to a global variable
8355 or function, the initializer function will only run if the associated
8356 data from the current module is not discarded.
8357 On ELF the referenced global variable or function must be in a comdat.
8359 .. _llvmglobaldtors:
8361 The '``llvm.global_dtors``' Global Variable
8362 -------------------------------------------
8364 .. code-block:: llvm
8366 %0 = type { i32, ptr, ptr }
8367 @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, ptr @dtor, ptr @data }]
8369 The ``@llvm.global_dtors`` array contains a list of destructor
8370 functions, priorities, and an associated global or function.
8371 The functions referenced by this array will be called in descending
8372 order of priority (i.e. highest first) when the module is unloaded. The
8373 order of functions with the same priority is not defined.
8375 If the third field is non-null, and points to a global variable
8376 or function, the destructor function will only run if the associated
8377 data from the current module is not discarded.
8378 On ELF the referenced global variable or function must be in a comdat.
8380 Instruction Reference
8381 =====================
8383 The LLVM instruction set consists of several different classifications
8384 of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
8385 instructions <binaryops>`, :ref:`bitwise binary
8386 instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
8387 :ref:`other instructions <otherops>`.
8391 Terminator Instructions
8392 -----------------------
8394 As mentioned :ref:`previously <functionstructure>`, every basic block in a
8395 program ends with a "Terminator" instruction, which indicates which
8396 block should be executed after the current block is finished. These
8397 terminator instructions typically yield a '``void``' value: they produce
8398 control flow, not values (the one exception being the
8399 ':ref:`invoke <i_invoke>`' instruction).
8401 The terminator instructions are: ':ref:`ret <i_ret>`',
8402 ':ref:`br <i_br>`', ':ref:`switch <i_switch>`',
8403 ':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`',
8404 ':ref:`callbr <i_callbr>`'
8405 ':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`',
8406 ':ref:`catchret <i_catchret>`',
8407 ':ref:`cleanupret <i_cleanupret>`',
8408 and ':ref:`unreachable <i_unreachable>`'.
8412 '``ret``' Instruction
8413 ^^^^^^^^^^^^^^^^^^^^^
8420 ret <type> <value> ; Return a value from a non-void function
8421 ret void ; Return from void function
8426 The '``ret``' instruction is used to return control flow (and optionally
8427 a value) from a function back to the caller.
8429 There are two forms of the '``ret``' instruction: one that returns a
8430 value and then causes control flow, and one that just causes control
8436 The '``ret``' instruction optionally accepts a single argument, the
8437 return value. The type of the return value must be a ':ref:`first
8438 class <t_firstclass>`' type.
8440 A function is not :ref:`well formed <wellformed>` if it has a non-void
8441 return type and contains a '``ret``' instruction with no return value or
8442 a return value with a type that does not match its type, or if it has a
8443 void return type and contains a '``ret``' instruction with a return
8449 When the '``ret``' instruction is executed, control flow returns back to
8450 the calling function's context. If the caller is a
8451 ":ref:`call <i_call>`" instruction, execution continues at the
8452 instruction after the call. If the caller was an
8453 ":ref:`invoke <i_invoke>`" instruction, execution continues at the
8454 beginning of the "normal" destination block. If the instruction returns
8455 a value, that value shall set the call or invoke instruction's return
8461 .. code-block:: llvm
8463 ret i32 5 ; Return an integer value of 5
8464 ret void ; Return from a void function
8465 ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2
8469 '``br``' Instruction
8470 ^^^^^^^^^^^^^^^^^^^^
8477 br i1 <cond>, label <iftrue>, label <iffalse>
8478 br label <dest> ; Unconditional branch
8483 The '``br``' instruction is used to cause control flow to transfer to a
8484 different basic block in the current function. There are two forms of
8485 this instruction, corresponding to a conditional branch and an
8486 unconditional branch.
8491 The conditional branch form of the '``br``' instruction takes a single
8492 '``i1``' value and two '``label``' values. The unconditional form of the
8493 '``br``' instruction takes a single '``label``' value as a target.
8498 Upon execution of a conditional '``br``' instruction, the '``i1``'
8499 argument is evaluated. If the value is ``true``, control flows to the
8500 '``iftrue``' ``label`` argument. If "cond" is ``false``, control flows
8501 to the '``iffalse``' ``label`` argument.
8502 If '``cond``' is ``poison`` or ``undef``, this instruction has undefined
8508 .. code-block:: llvm
8511 %cond = icmp eq i32 %a, %b
8512 br i1 %cond, label %IfEqual, label %IfUnequal
8520 '``switch``' Instruction
8521 ^^^^^^^^^^^^^^^^^^^^^^^^
8528 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
8533 The '``switch``' instruction is used to transfer control flow to one of
8534 several different places. It is a generalization of the '``br``'
8535 instruction, allowing a branch to occur to one of many possible
8541 The '``switch``' instruction uses three parameters: an integer
8542 comparison value '``value``', a default '``label``' destination, and an
8543 array of pairs of comparison value constants and '``label``'s. The table
8544 is not allowed to contain duplicate constant entries.
8549 The ``switch`` instruction specifies a table of values and destinations.
8550 When the '``switch``' instruction is executed, this table is searched
8551 for the given value. If the value is found, control flow is transferred
8552 to the corresponding destination; otherwise, control flow is transferred
8553 to the default destination.
8554 If '``value``' is ``poison`` or ``undef``, this instruction has undefined
8560 Depending on properties of the target machine and the particular
8561 ``switch`` instruction, this instruction may be code generated in
8562 different ways. For example, it could be generated as a series of
8563 chained conditional branches or with a lookup table.
8568 .. code-block:: llvm
8570 ; Emulate a conditional br instruction
8571 %Val = zext i1 %value to i32
8572 switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
8574 ; Emulate an unconditional br instruction
8575 switch i32 0, label %dest [ ]
8577 ; Implement a jump table:
8578 switch i32 %val, label %otherwise [ i32 0, label %onzero
8580 i32 2, label %ontwo ]
8584 '``indirectbr``' Instruction
8585 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8592 indirectbr ptr <address>, [ label <dest1>, label <dest2>, ... ]
8597 The '``indirectbr``' instruction implements an indirect branch to a
8598 label within the current function, whose address is specified by
8599 "``address``". Address must be derived from a
8600 :ref:`blockaddress <blockaddress>` constant.
8605 The '``address``' argument is the address of the label to jump to. The
8606 rest of the arguments indicate the full set of possible destinations
8607 that the address may point to. Blocks are allowed to occur multiple
8608 times in the destination list, though this isn't particularly useful.
8610 This destination list is required so that dataflow analysis has an
8611 accurate understanding of the CFG.
8616 Control transfers to the block specified in the address argument. All
8617 possible destination blocks must be listed in the label list, otherwise
8618 this instruction has undefined behavior. This implies that jumps to
8619 labels defined in other functions have undefined behavior as well.
8620 If '``address``' is ``poison`` or ``undef``, this instruction has undefined
8626 This is typically implemented with a jump through a register.
8631 .. code-block:: llvm
8633 indirectbr ptr %Addr, [ label %bb1, label %bb2, label %bb3 ]
8637 '``invoke``' Instruction
8638 ^^^^^^^^^^^^^^^^^^^^^^^^
8645 <result> = invoke [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
8646 [operand bundles] to label <normal label> unwind label <exception label>
8651 The '``invoke``' instruction causes control to transfer to a specified
8652 function, with the possibility of control flow transfer to either the
8653 '``normal``' label or the '``exception``' label. If the callee function
8654 returns with the "``ret``" instruction, control flow will return to the
8655 "normal" label. If the callee (or any indirect callees) returns via the
8656 ":ref:`resume <i_resume>`" instruction or other exception handling
8657 mechanism, control is interrupted and continued at the dynamically
8658 nearest "exception" label.
8660 The '``exception``' label is a `landing
8661 pad <ExceptionHandling.html#overview>`_ for the exception. As such,
8662 '``exception``' label is required to have the
8663 ":ref:`landingpad <i_landingpad>`" instruction, which contains the
8664 information about the behavior of the program after unwinding happens,
8665 as its first non-PHI instruction. The restrictions on the
8666 "``landingpad``" instruction's tightly couples it to the "``invoke``"
8667 instruction, so that the important information contained within the
8668 "``landingpad``" instruction can't be lost through normal code motion.
8673 This instruction requires several arguments:
8675 #. The optional "cconv" marker indicates which :ref:`calling
8676 convention <callingconv>` the call should use. If none is
8677 specified, the call defaults to using C calling conventions.
8678 #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
8679 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
8681 #. The optional addrspace attribute can be used to indicate the address space
8682 of the called function. If it is not specified, the program address space
8683 from the :ref:`datalayout string<langref_datalayout>` will be used.
8684 #. '``ty``': the type of the call instruction itself which is also the
8685 type of the return value. Functions that return no value are marked
8687 #. '``fnty``': shall be the signature of the function being invoked. The
8688 argument types must match the types implied by this signature. This
8689 type can be omitted if the function is not varargs.
8690 #. '``fnptrval``': An LLVM value containing a pointer to a function to
8691 be invoked. In most cases, this is a direct function invocation, but
8692 indirect ``invoke``'s are just as possible, calling an arbitrary pointer
8694 #. '``function args``': argument list whose types match the function
8695 signature argument types and parameter attributes. All arguments must
8696 be of :ref:`first class <t_firstclass>` type. If the function signature
8697 indicates the function accepts a variable number of arguments, the
8698 extra arguments can be specified.
8699 #. '``normal label``': the label reached when the called function
8700 executes a '``ret``' instruction.
8701 #. '``exception label``': the label reached when a callee returns via
8702 the :ref:`resume <i_resume>` instruction or other exception handling
8704 #. The optional :ref:`function attributes <fnattrs>` list.
8705 #. The optional :ref:`operand bundles <opbundles>` list.
8710 This instruction is designed to operate as a standard '``call``'
8711 instruction in most regards. The primary difference is that it
8712 establishes an association with a label, which is used by the runtime
8713 library to unwind the stack.
8715 This instruction is used in languages with destructors to ensure that
8716 proper cleanup is performed in the case of either a ``longjmp`` or a
8717 thrown exception. Additionally, this is important for implementation of
8718 '``catch``' clauses in high-level languages that support them.
8720 For the purposes of the SSA form, the definition of the value returned
8721 by the '``invoke``' instruction is deemed to occur on the edge from the
8722 current block to the "normal" label. If the callee unwinds then no
8723 return value is available.
8728 .. code-block:: llvm
8730 %retval = invoke i32 @Test(i32 15) to label %Continue
8731 unwind label %TestCleanup ; i32:retval set
8732 %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue
8733 unwind label %TestCleanup ; i32:retval set
8737 '``callbr``' Instruction
8738 ^^^^^^^^^^^^^^^^^^^^^^^^
8745 <result> = callbr [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
8746 [operand bundles] to label <fallthrough label> [indirect labels]
8751 The '``callbr``' instruction causes control to transfer to a specified
8752 function, with the possibility of control flow transfer to either the
8753 '``fallthrough``' label or one of the '``indirect``' labels.
8755 This instruction should only be used to implement the "goto" feature of gcc
8756 style inline assembly. Any other usage is an error in the IR verifier.
8758 Note that in order to support outputs along indirect edges, LLVM may need to
8759 split critical edges, which may require synthesizing a replacement block for
8760 the ``indirect labels``. Therefore, the address of a label as seen by another
8761 ``callbr`` instruction, or for a :ref:`blockaddress <blockaddress>` constant,
8762 may not be equal to the address provided for the same block to this
8763 instruction's ``indirect labels`` operand. The assembly code may only transfer
8764 control to addresses provided via this instruction's ``indirect labels``.
8769 This instruction requires several arguments:
8771 #. The optional "cconv" marker indicates which :ref:`calling
8772 convention <callingconv>` the call should use. If none is
8773 specified, the call defaults to using C calling conventions.
8774 #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
8775 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
8777 #. The optional addrspace attribute can be used to indicate the address space
8778 of the called function. If it is not specified, the program address space
8779 from the :ref:`datalayout string<langref_datalayout>` will be used.
8780 #. '``ty``': the type of the call instruction itself which is also the
8781 type of the return value. Functions that return no value are marked
8783 #. '``fnty``': shall be the signature of the function being called. The
8784 argument types must match the types implied by this signature. This
8785 type can be omitted if the function is not varargs.
8786 #. '``fnptrval``': An LLVM value containing a pointer to a function to
8787 be called. In most cases, this is a direct function call, but
8788 other ``callbr``'s are just as possible, calling an arbitrary pointer
8790 #. '``function args``': argument list whose types match the function
8791 signature argument types and parameter attributes. All arguments must
8792 be of :ref:`first class <t_firstclass>` type. If the function signature
8793 indicates the function accepts a variable number of arguments, the
8794 extra arguments can be specified.
8795 #. '``fallthrough label``': the label reached when the inline assembly's
8796 execution exits the bottom.
8797 #. '``indirect labels``': the labels reached when a callee transfers control
8798 to a location other than the '``fallthrough label``'. Label constraints
8799 refer to these destinations.
8800 #. The optional :ref:`function attributes <fnattrs>` list.
8801 #. The optional :ref:`operand bundles <opbundles>` list.
8806 This instruction is designed to operate as a standard '``call``'
8807 instruction in most regards. The primary difference is that it
8808 establishes an association with additional labels to define where control
8809 flow goes after the call.
8811 The output values of a '``callbr``' instruction are available only to
8812 the '``fallthrough``' block, not to any '``indirect``' blocks(s).
8814 The only use of this today is to implement the "goto" feature of gcc inline
8815 assembly where additional labels can be provided as locations for the inline
8816 assembly to jump to.
8821 .. code-block:: llvm
8823 ; "asm goto" without output constraints.
8824 callbr void asm "", "r,!i"(i32 %x)
8825 to label %fallthrough [label %indirect]
8827 ; "asm goto" with output constraints.
8828 <result> = callbr i32 asm "", "=r,r,!i"(i32 %x)
8829 to label %fallthrough [label %indirect]
8833 '``resume``' Instruction
8834 ^^^^^^^^^^^^^^^^^^^^^^^^
8841 resume <type> <value>
8846 The '``resume``' instruction is a terminator instruction that has no
8852 The '``resume``' instruction requires one argument, which must have the
8853 same type as the result of any '``landingpad``' instruction in the same
8859 The '``resume``' instruction resumes propagation of an existing
8860 (in-flight) exception whose unwinding was interrupted with a
8861 :ref:`landingpad <i_landingpad>` instruction.
8866 .. code-block:: llvm
8868 resume { ptr, i32 } %exn
8872 '``catchswitch``' Instruction
8873 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8880 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller
8881 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default>
8886 The '``catchswitch``' instruction is used by `LLVM's exception handling system
8887 <ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers
8888 that may be executed by the :ref:`EH personality routine <personalityfn>`.
8893 The ``parent`` argument is the token of the funclet that contains the
8894 ``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet,
8895 this operand may be the token ``none``.
8897 The ``default`` argument is the label of another basic block beginning with
8898 either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination
8899 must be a legal target with respect to the ``parent`` links, as described in
8900 the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
8902 The ``handlers`` are a nonempty list of successor blocks that each begin with a
8903 :ref:`catchpad <i_catchpad>` instruction.
8908 Executing this instruction transfers control to one of the successors in
8909 ``handlers``, if appropriate, or continues to unwind via the unwind label if
8912 The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that
8913 it must be both the first non-phi instruction and last instruction in the basic
8914 block. Therefore, it must be the only non-phi instruction in the block.
8919 .. code-block:: text
8922 %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller
8924 %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup
8928 '``catchret``' Instruction
8929 ^^^^^^^^^^^^^^^^^^^^^^^^^^
8936 catchret from <token> to label <normal>
8941 The '``catchret``' instruction is a terminator instruction that has a
8948 The first argument to a '``catchret``' indicates which ``catchpad`` it
8949 exits. It must be a :ref:`catchpad <i_catchpad>`.
8950 The second argument to a '``catchret``' specifies where control will
8956 The '``catchret``' instruction ends an existing (in-flight) exception whose
8957 unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The
8958 :ref:`personality function <personalityfn>` gets a chance to execute arbitrary
8959 code to, for example, destroy the active exception. Control then transfers to
8962 The ``token`` argument must be a token produced by a ``catchpad`` instruction.
8963 If the specified ``catchpad`` is not the most-recently-entered not-yet-exited
8964 funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
8965 the ``catchret``'s behavior is undefined.
8970 .. code-block:: text
8972 catchret from %catch to label %continue
8976 '``cleanupret``' Instruction
8977 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8984 cleanupret from <value> unwind label <continue>
8985 cleanupret from <value> unwind to caller
8990 The '``cleanupret``' instruction is a terminator instruction that has
8991 an optional successor.
8997 The '``cleanupret``' instruction requires one argument, which indicates
8998 which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`.
8999 If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited
9000 funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
9001 the ``cleanupret``'s behavior is undefined.
9003 The '``cleanupret``' instruction also has an optional successor, ``continue``,
9004 which must be the label of another basic block beginning with either a
9005 ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must
9006 be a legal target with respect to the ``parent`` links, as described in the
9007 `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
9012 The '``cleanupret``' instruction indicates to the
9013 :ref:`personality function <personalityfn>` that one
9014 :ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended.
9015 It transfers control to ``continue`` or unwinds out of the function.
9020 .. code-block:: text
9022 cleanupret from %cleanup unwind to caller
9023 cleanupret from %cleanup unwind label %continue
9027 '``unreachable``' Instruction
9028 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9040 The '``unreachable``' instruction has no defined semantics. This
9041 instruction is used to inform the optimizer that a particular portion of
9042 the code is not reachable. This can be used to indicate that the code
9043 after a no-return function cannot be reached, and other facts.
9048 The '``unreachable``' instruction has no defined semantics.
9055 Unary operators require a single operand, execute an operation on
9056 it, and produce a single value. The operand might represent multiple
9057 data, as is the case with the :ref:`vector <t_vector>` data type. The
9058 result value has the same type as its operand.
9062 '``fneg``' Instruction
9063 ^^^^^^^^^^^^^^^^^^^^^^
9070 <result> = fneg [fast-math flags]* <ty> <op1> ; yields ty:result
9075 The '``fneg``' instruction returns the negation of its operand.
9080 The argument to the '``fneg``' instruction must be a
9081 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9082 floating-point values.
9087 The value produced is a copy of the operand with its sign bit flipped.
9088 This instruction can also take any number of :ref:`fast-math
9089 flags <fastmath>`, which are optimization hints to enable otherwise
9090 unsafe floating-point optimizations:
9095 .. code-block:: text
9097 <result> = fneg float %val ; yields float:result = -%var
9104 Binary operators are used to do most of the computation in a program.
9105 They require two operands of the same type, execute an operation on
9106 them, and produce a single value. The operands might represent multiple
9107 data, as is the case with the :ref:`vector <t_vector>` data type. The
9108 result value has the same type as its operands.
9110 There are several different binary operators:
9114 '``add``' Instruction
9115 ^^^^^^^^^^^^^^^^^^^^^
9122 <result> = add <ty> <op1>, <op2> ; yields ty:result
9123 <result> = add nuw <ty> <op1>, <op2> ; yields ty:result
9124 <result> = add nsw <ty> <op1>, <op2> ; yields ty:result
9125 <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result
9130 The '``add``' instruction returns the sum of its two operands.
9135 The two arguments to the '``add``' instruction must be
9136 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9137 arguments must have identical types.
9142 The value produced is the integer sum of the two operands.
9144 If the sum has unsigned overflow, the result returned is the
9145 mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
9148 Because LLVM integers use a two's complement representation, this
9149 instruction is appropriate for both signed and unsigned integers.
9151 ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
9152 respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
9153 result value of the ``add`` is a :ref:`poison value <poisonvalues>` if
9154 unsigned and/or signed overflow, respectively, occurs.
9159 .. code-block:: text
9161 <result> = add i32 4, %var ; yields i32:result = 4 + %var
9165 '``fadd``' Instruction
9166 ^^^^^^^^^^^^^^^^^^^^^^
9173 <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
9178 The '``fadd``' instruction returns the sum of its two operands.
9183 The two arguments to the '``fadd``' instruction must be
9184 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9185 floating-point values. Both arguments must have identical types.
9190 The value produced is the floating-point sum of the two operands.
9191 This instruction is assumed to execute in the default :ref:`floating-point
9192 environment <floatenv>`.
9193 This instruction can also take any number of :ref:`fast-math
9194 flags <fastmath>`, which are optimization hints to enable otherwise
9195 unsafe floating-point optimizations:
9200 .. code-block:: text
9202 <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var
9206 '``sub``' Instruction
9207 ^^^^^^^^^^^^^^^^^^^^^
9214 <result> = sub <ty> <op1>, <op2> ; yields ty:result
9215 <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result
9216 <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result
9217 <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result
9222 The '``sub``' instruction returns the difference of its two operands.
9224 Note that the '``sub``' instruction is used to represent the '``neg``'
9225 instruction present in most other intermediate representations.
9230 The two arguments to the '``sub``' instruction must be
9231 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9232 arguments must have identical types.
9237 The value produced is the integer difference of the two operands.
9239 If the difference has unsigned overflow, the result returned is the
9240 mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
9243 Because LLVM integers use a two's complement representation, this
9244 instruction is appropriate for both signed and unsigned integers.
9246 ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
9247 respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
9248 result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if
9249 unsigned and/or signed overflow, respectively, occurs.
9254 .. code-block:: text
9256 <result> = sub i32 4, %var ; yields i32:result = 4 - %var
9257 <result> = sub i32 0, %val ; yields i32:result = -%var
9261 '``fsub``' Instruction
9262 ^^^^^^^^^^^^^^^^^^^^^^
9269 <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
9274 The '``fsub``' instruction returns the difference of its two operands.
9279 The two arguments to the '``fsub``' instruction must be
9280 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9281 floating-point values. Both arguments must have identical types.
9286 The value produced is the floating-point difference of the two operands.
9287 This instruction is assumed to execute in the default :ref:`floating-point
9288 environment <floatenv>`.
9289 This instruction can also take any number of :ref:`fast-math
9290 flags <fastmath>`, which are optimization hints to enable otherwise
9291 unsafe floating-point optimizations:
9296 .. code-block:: text
9298 <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var
9299 <result> = fsub float -0.0, %val ; yields float:result = -%var
9303 '``mul``' Instruction
9304 ^^^^^^^^^^^^^^^^^^^^^
9311 <result> = mul <ty> <op1>, <op2> ; yields ty:result
9312 <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result
9313 <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result
9314 <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result
9319 The '``mul``' instruction returns the product of its two operands.
9324 The two arguments to the '``mul``' instruction must be
9325 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9326 arguments must have identical types.
9331 The value produced is the integer product of the two operands.
9333 If the result of the multiplication has unsigned overflow, the result
9334 returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the
9335 bit width of the result.
9337 Because LLVM integers use a two's complement representation, and the
9338 result is the same width as the operands, this instruction returns the
9339 correct result for both signed and unsigned integers. If a full product
9340 (e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be
9341 sign-extended or zero-extended as appropriate to the width of the full
9344 ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
9345 respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
9346 result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if
9347 unsigned and/or signed overflow, respectively, occurs.
9352 .. code-block:: text
9354 <result> = mul i32 4, %var ; yields i32:result = 4 * %var
9358 '``fmul``' Instruction
9359 ^^^^^^^^^^^^^^^^^^^^^^
9366 <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
9371 The '``fmul``' instruction returns the product of its two operands.
9376 The two arguments to the '``fmul``' instruction must be
9377 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9378 floating-point values. Both arguments must have identical types.
9383 The value produced is the floating-point product of the two operands.
9384 This instruction is assumed to execute in the default :ref:`floating-point
9385 environment <floatenv>`.
9386 This instruction can also take any number of :ref:`fast-math
9387 flags <fastmath>`, which are optimization hints to enable otherwise
9388 unsafe floating-point optimizations:
9393 .. code-block:: text
9395 <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var
9399 '``udiv``' Instruction
9400 ^^^^^^^^^^^^^^^^^^^^^^
9407 <result> = udiv <ty> <op1>, <op2> ; yields ty:result
9408 <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result
9413 The '``udiv``' instruction returns the quotient of its two operands.
9418 The two arguments to the '``udiv``' instruction must be
9419 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9420 arguments must have identical types.
9425 The value produced is the unsigned integer quotient of the two operands.
9427 Note that unsigned integer division and signed integer division are
9428 distinct operations; for signed integer division, use '``sdiv``'.
9430 Division by zero is undefined behavior. For vectors, if any element
9431 of the divisor is zero, the operation has undefined behavior.
9434 If the ``exact`` keyword is present, the result value of the ``udiv`` is
9435 a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as
9436 such, "((a udiv exact b) mul b) == a").
9441 .. code-block:: text
9443 <result> = udiv i32 4, %var ; yields i32:result = 4 / %var
9447 '``sdiv``' Instruction
9448 ^^^^^^^^^^^^^^^^^^^^^^
9455 <result> = sdiv <ty> <op1>, <op2> ; yields ty:result
9456 <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result
9461 The '``sdiv``' instruction returns the quotient of its two operands.
9466 The two arguments to the '``sdiv``' instruction must be
9467 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9468 arguments must have identical types.
9473 The value produced is the signed integer quotient of the two operands
9474 rounded towards zero.
9476 Note that signed integer division and unsigned integer division are
9477 distinct operations; for unsigned integer division, use '``udiv``'.
9479 Division by zero is undefined behavior. For vectors, if any element
9480 of the divisor is zero, the operation has undefined behavior.
9481 Overflow also leads to undefined behavior; this is a rare case, but can
9482 occur, for example, by doing a 32-bit division of -2147483648 by -1.
9484 If the ``exact`` keyword is present, the result value of the ``sdiv`` is
9485 a :ref:`poison value <poisonvalues>` if the result would be rounded.
9490 .. code-block:: text
9492 <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var
9496 '``fdiv``' Instruction
9497 ^^^^^^^^^^^^^^^^^^^^^^
9504 <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
9509 The '``fdiv``' instruction returns the quotient of its two operands.
9514 The two arguments to the '``fdiv``' instruction must be
9515 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9516 floating-point values. Both arguments must have identical types.
9521 The value produced is the floating-point quotient of the two operands.
9522 This instruction is assumed to execute in the default :ref:`floating-point
9523 environment <floatenv>`.
9524 This instruction can also take any number of :ref:`fast-math
9525 flags <fastmath>`, which are optimization hints to enable otherwise
9526 unsafe floating-point optimizations:
9531 .. code-block:: text
9533 <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var
9537 '``urem``' Instruction
9538 ^^^^^^^^^^^^^^^^^^^^^^
9545 <result> = urem <ty> <op1>, <op2> ; yields ty:result
9550 The '``urem``' instruction returns the remainder from the unsigned
9551 division of its two arguments.
9556 The two arguments to the '``urem``' instruction must be
9557 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9558 arguments must have identical types.
9563 This instruction returns the unsigned integer *remainder* of a division.
9564 This instruction always performs an unsigned division to get the
9567 Note that unsigned integer remainder and signed integer remainder are
9568 distinct operations; for signed integer remainder, use '``srem``'.
9570 Taking the remainder of a division by zero is undefined behavior.
9571 For vectors, if any element of the divisor is zero, the operation has
9577 .. code-block:: text
9579 <result> = urem i32 4, %var ; yields i32:result = 4 % %var
9583 '``srem``' Instruction
9584 ^^^^^^^^^^^^^^^^^^^^^^
9591 <result> = srem <ty> <op1>, <op2> ; yields ty:result
9596 The '``srem``' instruction returns the remainder from the signed
9597 division of its two operands. This instruction can also take
9598 :ref:`vector <t_vector>` versions of the values in which case the elements
9604 The two arguments to the '``srem``' instruction must be
9605 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9606 arguments must have identical types.
9611 This instruction returns the *remainder* of a division (where the result
9612 is either zero or has the same sign as the dividend, ``op1``), not the
9613 *modulo* operator (where the result is either zero or has the same sign
9614 as the divisor, ``op2``) of a value. For more information about the
9615 difference, see `The Math
9616 Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a
9617 table of how this is implemented in various languages, please see
9619 operation <http://en.wikipedia.org/wiki/Modulo_operation>`_.
9621 Note that signed integer remainder and unsigned integer remainder are
9622 distinct operations; for unsigned integer remainder, use '``urem``'.
9624 Taking the remainder of a division by zero is undefined behavior.
9625 For vectors, if any element of the divisor is zero, the operation has
9627 Overflow also leads to undefined behavior; this is a rare case, but can
9628 occur, for example, by taking the remainder of a 32-bit division of
9629 -2147483648 by -1. (The remainder doesn't actually overflow, but this
9630 rule lets srem be implemented using instructions that return both the
9631 result of the division and the remainder.)
9636 .. code-block:: text
9638 <result> = srem i32 4, %var ; yields i32:result = 4 % %var
9642 '``frem``' Instruction
9643 ^^^^^^^^^^^^^^^^^^^^^^
9650 <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
9655 The '``frem``' instruction returns the remainder from the division of
9660 The instruction is implemented as a call to libm's '``fmod``'
9661 for some targets, and using the instruction may thus require linking libm.
9667 The two arguments to the '``frem``' instruction must be
9668 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9669 floating-point values. Both arguments must have identical types.
9674 The value produced is the floating-point remainder of the two operands.
9675 This is the same output as a libm '``fmod``' function, but without any
9676 possibility of setting ``errno``. The remainder has the same sign as the
9678 This instruction is assumed to execute in the default :ref:`floating-point
9679 environment <floatenv>`.
9680 This instruction can also take any number of :ref:`fast-math
9681 flags <fastmath>`, which are optimization hints to enable otherwise
9682 unsafe floating-point optimizations:
9687 .. code-block:: text
9689 <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var
9693 Bitwise Binary Operations
9694 -------------------------
9696 Bitwise binary operators are used to do various forms of bit-twiddling
9697 in a program. They are generally very efficient instructions and can
9698 commonly be strength reduced from other instructions. They require two
9699 operands of the same type, execute an operation on them, and produce a
9700 single value. The resulting value is the same type as its operands.
9704 '``shl``' Instruction
9705 ^^^^^^^^^^^^^^^^^^^^^
9712 <result> = shl <ty> <op1>, <op2> ; yields ty:result
9713 <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result
9714 <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result
9715 <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result
9720 The '``shl``' instruction returns the first operand shifted to the left
9721 a specified number of bits.
9726 Both arguments to the '``shl``' instruction must be the same
9727 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
9728 '``op2``' is treated as an unsigned value.
9733 The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`,
9734 where ``n`` is the width of the result. If ``op2`` is (statically or
9735 dynamically) equal to or larger than the number of bits in
9736 ``op1``, this instruction returns a :ref:`poison value <poisonvalues>`.
9737 If the arguments are vectors, each vector element of ``op1`` is shifted
9738 by the corresponding shift amount in ``op2``.
9740 If the ``nuw`` keyword is present, then the shift produces a poison
9741 value if it shifts out any non-zero bits.
9742 If the ``nsw`` keyword is present, then the shift produces a poison
9743 value if it shifts out any bits that disagree with the resultant sign bit.
9748 .. code-block:: text
9750 <result> = shl i32 4, %var ; yields i32: 4 << %var
9751 <result> = shl i32 4, 2 ; yields i32: 16
9752 <result> = shl i32 1, 10 ; yields i32: 1024
9753 <result> = shl i32 1, 32 ; undefined
9754 <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4>
9759 '``lshr``' Instruction
9760 ^^^^^^^^^^^^^^^^^^^^^^
9767 <result> = lshr <ty> <op1>, <op2> ; yields ty:result
9768 <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result
9773 The '``lshr``' instruction (logical shift right) returns the first
9774 operand shifted to the right a specified number of bits with zero fill.
9779 Both arguments to the '``lshr``' instruction must be the same
9780 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
9781 '``op2``' is treated as an unsigned value.
9786 This instruction always performs a logical shift right operation. The
9787 most significant bits of the result will be filled with zero bits after
9788 the shift. If ``op2`` is (statically or dynamically) equal to or larger
9789 than the number of bits in ``op1``, this instruction returns a :ref:`poison
9790 value <poisonvalues>`. If the arguments are vectors, each vector element
9791 of ``op1`` is shifted by the corresponding shift amount in ``op2``.
9793 If the ``exact`` keyword is present, the result value of the ``lshr`` is
9794 a poison value if any of the bits shifted out are non-zero.
9799 .. code-block:: text
9801 <result> = lshr i32 4, 1 ; yields i32:result = 2
9802 <result> = lshr i32 4, 2 ; yields i32:result = 1
9803 <result> = lshr i8 4, 3 ; yields i8:result = 0
9804 <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F
9805 <result> = lshr i32 1, 32 ; undefined
9806 <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1>
9810 '``ashr``' Instruction
9811 ^^^^^^^^^^^^^^^^^^^^^^
9818 <result> = ashr <ty> <op1>, <op2> ; yields ty:result
9819 <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result
9824 The '``ashr``' instruction (arithmetic shift right) returns the first
9825 operand shifted to the right a specified number of bits with sign
9831 Both arguments to the '``ashr``' instruction must be the same
9832 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
9833 '``op2``' is treated as an unsigned value.
9838 This instruction always performs an arithmetic shift right operation,
9839 The most significant bits of the result will be filled with the sign bit
9840 of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger
9841 than the number of bits in ``op1``, this instruction returns a :ref:`poison
9842 value <poisonvalues>`. If the arguments are vectors, each vector element
9843 of ``op1`` is shifted by the corresponding shift amount in ``op2``.
9845 If the ``exact`` keyword is present, the result value of the ``ashr`` is
9846 a poison value if any of the bits shifted out are non-zero.
9851 .. code-block:: text
9853 <result> = ashr i32 4, 1 ; yields i32:result = 2
9854 <result> = ashr i32 4, 2 ; yields i32:result = 1
9855 <result> = ashr i8 4, 3 ; yields i8:result = 0
9856 <result> = ashr i8 -2, 1 ; yields i8:result = -1
9857 <result> = ashr i32 1, 32 ; undefined
9858 <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0>
9862 '``and``' Instruction
9863 ^^^^^^^^^^^^^^^^^^^^^
9870 <result> = and <ty> <op1>, <op2> ; yields ty:result
9875 The '``and``' instruction returns the bitwise logical and of its two
9881 The two arguments to the '``and``' instruction must be
9882 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9883 arguments must have identical types.
9888 The truth table used for the '``and``' instruction is:
9905 .. code-block:: text
9907 <result> = and i32 4, %var ; yields i32:result = 4 & %var
9908 <result> = and i32 15, 40 ; yields i32:result = 8
9909 <result> = and i32 4, 8 ; yields i32:result = 0
9913 '``or``' Instruction
9914 ^^^^^^^^^^^^^^^^^^^^
9921 <result> = or <ty> <op1>, <op2> ; yields ty:result
9926 The '``or``' instruction returns the bitwise logical inclusive or of its
9932 The two arguments to the '``or``' instruction must be
9933 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9934 arguments must have identical types.
9939 The truth table used for the '``or``' instruction is:
9958 <result> = or i32 4, %var ; yields i32:result = 4 | %var
9959 <result> = or i32 15, 40 ; yields i32:result = 47
9960 <result> = or i32 4, 8 ; yields i32:result = 12
9964 '``xor``' Instruction
9965 ^^^^^^^^^^^^^^^^^^^^^
9972 <result> = xor <ty> <op1>, <op2> ; yields ty:result
9977 The '``xor``' instruction returns the bitwise logical exclusive or of
9978 its two operands. The ``xor`` is used to implement the "one's
9979 complement" operation, which is the "~" operator in C.
9984 The two arguments to the '``xor``' instruction must be
9985 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9986 arguments must have identical types.
9991 The truth table used for the '``xor``' instruction is:
10001 +-----+-----+-----+
10003 +-----+-----+-----+
10008 .. code-block:: text
10010 <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var
10011 <result> = xor i32 15, 40 ; yields i32:result = 39
10012 <result> = xor i32 4, 8 ; yields i32:result = 12
10013 <result> = xor i32 %V, -1 ; yields i32:result = ~%V
10018 LLVM supports several instructions to represent vector operations in a
10019 target-independent manner. These instructions cover the element-access
10020 and vector-specific operations needed to process vectors effectively.
10021 While LLVM does directly support these vector operations, many
10022 sophisticated algorithms will want to use target-specific intrinsics to
10023 take full advantage of a specific target.
10025 .. _i_extractelement:
10027 '``extractelement``' Instruction
10028 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10035 <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty>
10036 <result> = extractelement <vscale x n x <ty>> <val>, <ty2> <idx> ; yields <ty>
10041 The '``extractelement``' instruction extracts a single scalar element
10042 from a vector at a specified index.
10047 The first operand of an '``extractelement``' instruction is a value of
10048 :ref:`vector <t_vector>` type. The second operand is an index indicating
10049 the position from which to extract the element. The index may be a
10050 variable of any integer type, and will be treated as an unsigned integer.
10055 The result is a scalar of the same type as the element type of ``val``.
10056 Its value is the value at position ``idx`` of ``val``. If ``idx``
10057 exceeds the length of ``val`` for a fixed-length vector, the result is a
10058 :ref:`poison value <poisonvalues>`. For a scalable vector, if the value
10059 of ``idx`` exceeds the runtime length of the vector, the result is a
10060 :ref:`poison value <poisonvalues>`.
10065 .. code-block:: text
10067 <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32
10069 .. _i_insertelement:
10071 '``insertelement``' Instruction
10072 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10079 <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>>
10080 <result> = insertelement <vscale x n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <vscale x n x <ty>>
10085 The '``insertelement``' instruction inserts a scalar element into a
10086 vector at a specified index.
10091 The first operand of an '``insertelement``' instruction is a value of
10092 :ref:`vector <t_vector>` type. The second operand is a scalar value whose
10093 type must equal the element type of the first operand. The third operand
10094 is an index indicating the position at which to insert the value. The
10095 index may be a variable of any integer type, and will be treated as an
10101 The result is a vector of the same type as ``val``. Its element values
10102 are those of ``val`` except at position ``idx``, where it gets the value
10103 ``elt``. If ``idx`` exceeds the length of ``val`` for a fixed-length vector,
10104 the result is a :ref:`poison value <poisonvalues>`. For a scalable vector,
10105 if the value of ``idx`` exceeds the runtime length of the vector, the result
10106 is a :ref:`poison value <poisonvalues>`.
10111 .. code-block:: text
10113 <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32>
10115 .. _i_shufflevector:
10117 '``shufflevector``' Instruction
10118 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10125 <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>>
10126 <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>>
10131 The '``shufflevector``' instruction constructs a permutation of elements
10132 from two input vectors, returning a vector with the same element type as
10133 the input and length that is the same as the shuffle mask.
10138 The first two operands of a '``shufflevector``' instruction are vectors
10139 with the same type. The third argument is a shuffle mask vector constant
10140 whose element type is ``i32``. The mask vector elements must be constant
10141 integers or ``poison`` values. The result of the instruction is a vector
10142 whose length is the same as the shuffle mask and whose element type is the
10143 same as the element type of the first two operands.
10148 The elements of the two input vectors are numbered from left to right
10149 across both of the vectors. For each element of the result vector, the
10150 shuffle mask selects an element from one of the input vectors to copy
10151 to the result. Non-negative elements in the mask represent an index
10152 into the concatenated pair of input vectors.
10154 A ``poison`` element in the mask vector specifies that the resulting element
10156 For backwards-compatibility reasons, LLVM temporarily also accepts ``undef``
10157 mask elements, which will be interpreted the same way as ``poison`` elements.
10158 If the shuffle mask selects an ``undef`` element from one of the input
10159 vectors, the resulting element is ``undef``.
10161 For scalable vectors, the only valid mask values at present are
10162 ``zeroinitializer``, ``undef`` and ``poison``, since we cannot write all indices as
10163 literals for a vector with a length unknown at compile time.
10168 .. code-block:: text
10170 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
10171 <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32>
10172 <result> = shufflevector <4 x i32> %v1, <4 x i32> poison,
10173 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle.
10174 <result> = shufflevector <8 x i32> %v1, <8 x i32> poison,
10175 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32>
10176 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
10177 <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32>
10179 Aggregate Operations
10180 --------------------
10182 LLVM supports several instructions for working with
10183 :ref:`aggregate <t_aggregate>` values.
10185 .. _i_extractvalue:
10187 '``extractvalue``' Instruction
10188 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10195 <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
10200 The '``extractvalue``' instruction extracts the value of a member field
10201 from an :ref:`aggregate <t_aggregate>` value.
10206 The first operand of an '``extractvalue``' instruction is a value of
10207 :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are
10208 constant indices to specify which value to extract in a similar manner
10209 as indices in a '``getelementptr``' instruction.
10211 The major differences to ``getelementptr`` indexing are:
10213 - Since the value being indexed is not a pointer, the first index is
10214 omitted and assumed to be zero.
10215 - At least one index must be specified.
10216 - Not only struct indices but also array indices must be in bounds.
10221 The result is the value at the position in the aggregate specified by
10222 the index operands.
10227 .. code-block:: text
10229 <result> = extractvalue {i32, float} %agg, 0 ; yields i32
10233 '``insertvalue``' Instruction
10234 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10241 <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type>
10246 The '``insertvalue``' instruction inserts a value into a member field in
10247 an :ref:`aggregate <t_aggregate>` value.
10252 The first operand of an '``insertvalue``' instruction is a value of
10253 :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is
10254 a first-class value to insert. The following operands are constant
10255 indices indicating the position at which to insert the value in a
10256 similar manner as indices in a '``extractvalue``' instruction. The value
10257 to insert must have the same type as the value identified by the
10263 The result is an aggregate of the same type as ``val``. Its value is
10264 that of ``val`` except that the value at the position specified by the
10265 indices is that of ``elt``.
10270 .. code-block:: llvm
10272 %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef}
10273 %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val}
10274 %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}}
10278 Memory Access and Addressing Operations
10279 ---------------------------------------
10281 A key design point of an SSA-based representation is how it represents
10282 memory. In LLVM, no memory locations are in SSA form, which makes things
10283 very simple. This section describes how to read, write, and allocate
10288 '``alloca``' Instruction
10289 ^^^^^^^^^^^^^^^^^^^^^^^^
10296 <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result
10301 The '``alloca``' instruction allocates memory on the stack frame of the
10302 currently executing function, to be automatically released when this
10303 function returns to its caller. If the address space is not explicitly
10304 specified, the object is allocated in the alloca address space from the
10305 :ref:`datalayout string<langref_datalayout>`.
10310 The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements``
10311 bytes of memory on the runtime stack, returning a pointer of the
10312 appropriate type to the program. If "NumElements" is specified, it is
10313 the number of elements allocated, otherwise "NumElements" is defaulted
10316 If a constant alignment is specified, the value result of the
10317 allocation is guaranteed to be aligned to at least that boundary. The
10318 alignment may not be greater than ``1 << 32``.
10320 The alignment is only optional when parsing textual IR; for in-memory IR,
10321 it is always present. If not specified, the target can choose to align the
10322 allocation on any convenient boundary compatible with the type.
10324 '``type``' may be any sized type.
10326 Structs containing scalable vectors cannot be used in allocas unless all
10327 fields are the same scalable vector type (e.g. ``{<vscale x 2 x i32>,
10328 <vscale x 2 x i32>}`` contains the same type while ``{<vscale x 2 x i32>,
10329 <vscale x 2 x i64>}`` doesn't).
10334 Memory is allocated; a pointer is returned. The allocated memory is
10335 uninitialized, and loading from uninitialized memory produces an undefined
10336 value. The operation itself is undefined if there is insufficient stack
10337 space for the allocation.'``alloca``'d memory is automatically released
10338 when the function returns. The '``alloca``' instruction is commonly used
10339 to represent automatic variables that must have an address available. When
10340 the function returns (either with the ``ret`` or ``resume`` instructions),
10341 the memory is reclaimed. Allocating zero bytes is legal, but the returned
10342 pointer may not be unique. The order in which memory is allocated (ie.,
10343 which way the stack grows) is not specified.
10345 Note that '``alloca``' outside of the alloca address space from the
10346 :ref:`datalayout string<langref_datalayout>` is meaningful only if the
10347 target has assigned it a semantics.
10349 If the returned pointer is used by :ref:`llvm.lifetime.start <int_lifestart>`,
10350 the returned object is initially dead.
10351 See :ref:`llvm.lifetime.start <int_lifestart>` and
10352 :ref:`llvm.lifetime.end <int_lifeend>` for the precise semantics of
10353 lifetime-manipulating intrinsics.
10358 .. code-block:: llvm
10360 %ptr = alloca i32 ; yields ptr
10361 %ptr = alloca i32, i32 4 ; yields ptr
10362 %ptr = alloca i32, i32 4, align 1024 ; yields ptr
10363 %ptr = alloca i32, align 1024 ; yields ptr
10367 '``load``' Instruction
10368 ^^^^^^^^^^^^^^^^^^^^^^
10375 <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>]
10376 <result> = load atomic [volatile] <ty>, ptr <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>]
10377 !<nontemp_node> = !{ i32 1 }
10378 !<empty_node> = !{}
10379 !<deref_bytes_node> = !{ i64 <dereferenceable_bytes> }
10380 !<align_node> = !{ i64 <value_alignment> }
10385 The '``load``' instruction is used to read from memory.
10390 The argument to the ``load`` instruction specifies the memory address from which
10391 to load. The type specified must be a :ref:`first class <t_firstclass>` type of
10392 known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If
10393 the ``load`` is marked as ``volatile``, then the optimizer is not allowed to
10394 modify the number or order of execution of this ``load`` with other
10395 :ref:`volatile operations <volatile>`.
10397 If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering
10398 <ordering>` and optional ``syncscope("<target-scope>")`` argument. The
10399 ``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions.
10400 Atomic loads produce :ref:`defined <memmodel>` results when they may see
10401 multiple atomic stores. The type of the pointee must be an integer, pointer, or
10402 floating-point type whose bit width is a power of two greater than or equal to
10403 eight and less than or equal to a target-specific size limit. ``align`` must be
10404 explicitly specified on atomic loads, and the load has undefined behavior if the
10405 alignment is not set to a value which is at least the size in bytes of the
10406 pointee. ``!nontemporal`` does not have any defined semantics for atomic loads.
10408 The optional constant ``align`` argument specifies the alignment of the
10409 operation (that is, the alignment of the memory address). It is the
10410 responsibility of the code emitter to ensure that the alignment information is
10411 correct. Overestimating the alignment results in undefined behavior.
10412 Underestimating the alignment may produce less efficient code. An alignment of
10413 1 is always safe. The maximum possible alignment is ``1 << 32``. An alignment
10414 value higher than the size of the loaded type implies memory up to the
10415 alignment value bytes can be safely loaded without trapping in the default
10416 address space. Access of the high bytes can interfere with debugging tools, so
10417 should not be accessed if the function has the ``sanitize_thread`` or
10418 ``sanitize_address`` attributes.
10420 The alignment is only optional when parsing textual IR; for in-memory IR, it is
10421 always present. An omitted ``align`` argument means that the operation has the
10422 ABI alignment for the target.
10424 The optional ``!nontemporal`` metadata must reference a single
10425 metadata name ``<nontemp_node>`` corresponding to a metadata node with one
10426 ``i32`` entry of value 1. The existence of the ``!nontemporal``
10427 metadata on the instruction tells the optimizer and code generator
10428 that this load is not expected to be reused in the cache. The code
10429 generator may select special instructions to save cache bandwidth, such
10430 as the ``MOVNT`` instruction on x86.
10432 The optional ``!invariant.load`` metadata must reference a single
10433 metadata name ``<empty_node>`` corresponding to a metadata node with no
10434 entries. If a load instruction tagged with the ``!invariant.load``
10435 metadata is executed, the memory location referenced by the load has
10436 to contain the same value at all points in the program where the
10437 memory location is dereferenceable; otherwise, the behavior is
10440 The optional ``!invariant.group`` metadata must reference a single metadata name
10441 ``<empty_node>`` corresponding to a metadata node with no entries.
10442 See ``invariant.group`` metadata :ref:`invariant.group <md_invariant.group>`.
10444 The optional ``!nonnull`` metadata must reference a single
10445 metadata name ``<empty_node>`` corresponding to a metadata node with no
10446 entries. The existence of the ``!nonnull`` metadata on the
10447 instruction tells the optimizer that the value loaded is known to
10448 never be null. If the value is null at runtime, a poison value is returned
10449 instead. This is analogous to the ``nonnull`` attribute on parameters and
10450 return values. This metadata can only be applied to loads of a pointer type.
10452 The optional ``!dereferenceable`` metadata must reference a single metadata
10453 name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
10455 See ``dereferenceable`` metadata :ref:`dereferenceable <md_dereferenceable>`.
10457 The optional ``!dereferenceable_or_null`` metadata must reference a single
10458 metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
10460 See ``dereferenceable_or_null`` metadata :ref:`dereferenceable_or_null
10461 <md_dereferenceable_or_null>`.
10463 The optional ``!align`` metadata must reference a single metadata name
10464 ``<align_node>`` corresponding to a metadata node with one ``i64`` entry.
10465 The existence of the ``!align`` metadata on the instruction tells the
10466 optimizer that the value loaded is known to be aligned to a boundary specified
10467 by the integer value in the metadata node. The alignment must be a power of 2.
10468 This is analogous to the ''align'' attribute on parameters and return values.
10469 This metadata can only be applied to loads of a pointer type. If the returned
10470 value is not appropriately aligned at runtime, a poison value is returned
10473 The optional ``!noundef`` metadata must reference a single metadata name
10474 ``<empty_node>`` corresponding to a node with no entries. The existence of
10475 ``!noundef`` metadata on the instruction tells the optimizer that the value
10476 loaded is known to be :ref:`well defined <welldefinedvalues>`.
10477 If the value isn't well defined, the behavior is undefined. If the ``!noundef``
10478 metadata is combined with poison-generating metadata like ``!nonnull``,
10479 violation of that metadata constraint will also result in undefined behavior.
10484 The location of memory pointed to is loaded. If the value being loaded
10485 is of scalar type then the number of bytes read does not exceed the
10486 minimum number of bytes needed to hold all bits of the type. For
10487 example, loading an ``i24`` reads at most three bytes. When loading a
10488 value of a type like ``i20`` with a size that is not an integral number
10489 of bytes, the result is undefined if the value was not originally
10490 written using a store of the same type.
10491 If the value being loaded is of aggregate type, the bytes that correspond to
10492 padding may be accessed but are ignored, because it is impossible to observe
10493 padding from the loaded aggregate value.
10494 If ``<pointer>`` is not a well-defined value, the behavior is undefined.
10499 .. code-block:: llvm
10501 %ptr = alloca i32 ; yields ptr
10502 store i32 3, ptr %ptr ; yields void
10503 %val = load i32, ptr %ptr ; yields i32:val = i32 3
10507 '``store``' Instruction
10508 ^^^^^^^^^^^^^^^^^^^^^^^
10515 store [volatile] <ty> <value>, ptr <pointer>[, align <alignment>][, !nontemporal !<nontemp_node>][, !invariant.group !<empty_node>] ; yields void
10516 store atomic [volatile] <ty> <value>, ptr <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>] ; yields void
10517 !<nontemp_node> = !{ i32 1 }
10518 !<empty_node> = !{}
10523 The '``store``' instruction is used to write to memory.
10528 There are two arguments to the ``store`` instruction: a value to store and an
10529 address at which to store it. The type of the ``<pointer>`` operand must be a
10530 pointer to the :ref:`first class <t_firstclass>` type of the ``<value>``
10531 operand. If the ``store`` is marked as ``volatile``, then the optimizer is not
10532 allowed to modify the number or order of execution of this ``store`` with other
10533 :ref:`volatile operations <volatile>`. Only values of :ref:`first class
10534 <t_firstclass>` types of known size (i.e. not containing an :ref:`opaque
10535 structural type <t_opaque>`) can be stored.
10537 If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering
10538 <ordering>` and optional ``syncscope("<target-scope>")`` argument. The
10539 ``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions.
10540 Atomic loads produce :ref:`defined <memmodel>` results when they may see
10541 multiple atomic stores. The type of the pointee must be an integer, pointer, or
10542 floating-point type whose bit width is a power of two greater than or equal to
10543 eight and less than or equal to a target-specific size limit. ``align`` must be
10544 explicitly specified on atomic stores, and the store has undefined behavior if
10545 the alignment is not set to a value which is at least the size in bytes of the
10546 pointee. ``!nontemporal`` does not have any defined semantics for atomic stores.
10548 The optional constant ``align`` argument specifies the alignment of the
10549 operation (that is, the alignment of the memory address). It is the
10550 responsibility of the code emitter to ensure that the alignment information is
10551 correct. Overestimating the alignment results in undefined behavior.
10552 Underestimating the alignment may produce less efficient code. An alignment of
10553 1 is always safe. The maximum possible alignment is ``1 << 32``. An alignment
10554 value higher than the size of the loaded type implies memory up to the
10555 alignment value bytes can be safely loaded without trapping in the default
10556 address space. Access of the high bytes can interfere with debugging tools, so
10557 should not be accessed if the function has the ``sanitize_thread`` or
10558 ``sanitize_address`` attributes.
10560 The alignment is only optional when parsing textual IR; for in-memory IR, it is
10561 always present. An omitted ``align`` argument means that the operation has the
10562 ABI alignment for the target.
10564 The optional ``!nontemporal`` metadata must reference a single metadata
10565 name ``<nontemp_node>`` corresponding to a metadata node with one ``i32`` entry
10566 of value 1. The existence of the ``!nontemporal`` metadata on the instruction
10567 tells the optimizer and code generator that this load is not expected to
10568 be reused in the cache. The code generator may select special
10569 instructions to save cache bandwidth, such as the ``MOVNT`` instruction on
10572 The optional ``!invariant.group`` metadata must reference a
10573 single metadata name ``<empty_node>``. See ``invariant.group`` metadata.
10578 The contents of memory are updated to contain ``<value>`` at the
10579 location specified by the ``<pointer>`` operand. If ``<value>`` is
10580 of scalar type then the number of bytes written does not exceed the
10581 minimum number of bytes needed to hold all bits of the type. For
10582 example, storing an ``i24`` writes at most three bytes. When writing a
10583 value of a type like ``i20`` with a size that is not an integral number
10584 of bytes, it is unspecified what happens to the extra bits that do not
10585 belong to the type, but they will typically be overwritten.
10586 If ``<value>`` is of aggregate type, padding is filled with
10587 :ref:`undef <undefvalues>`.
10588 If ``<pointer>`` is not a well-defined value, the behavior is undefined.
10593 .. code-block:: llvm
10595 %ptr = alloca i32 ; yields ptr
10596 store i32 3, ptr %ptr ; yields void
10597 %val = load i32, ptr %ptr ; yields i32:val = i32 3
10601 '``fence``' Instruction
10602 ^^^^^^^^^^^^^^^^^^^^^^^
10609 fence [syncscope("<target-scope>")] <ordering> ; yields void
10614 The '``fence``' instruction is used to introduce happens-before edges
10615 between operations.
10620 '``fence``' instructions take an :ref:`ordering <ordering>` argument which
10621 defines what *synchronizes-with* edges they add. They can only be given
10622 ``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings.
10627 A fence A which has (at least) ``release`` ordering semantics
10628 *synchronizes with* a fence B with (at least) ``acquire`` ordering
10629 semantics if and only if there exist atomic operations X and Y, both
10630 operating on some atomic object M, such that A is sequenced before X, X
10631 modifies M (either directly or through some side effect of a sequence
10632 headed by X), Y is sequenced before B, and Y observes M. This provides a
10633 *happens-before* dependency between A and B. Rather than an explicit
10634 ``fence``, one (but not both) of the atomic operations X or Y might
10635 provide a ``release`` or ``acquire`` (resp.) ordering constraint and
10636 still *synchronize-with* the explicit ``fence`` and establish the
10637 *happens-before* edge.
10639 A ``fence`` which has ``seq_cst`` ordering, in addition to having both
10640 ``acquire`` and ``release`` semantics specified above, participates in
10641 the global program order of other ``seq_cst`` operations and/or fences.
10643 A ``fence`` instruction can also take an optional
10644 ":ref:`syncscope <syncscope>`" argument.
10649 .. code-block:: text
10651 fence acquire ; yields void
10652 fence syncscope("singlethread") seq_cst ; yields void
10653 fence syncscope("agent") seq_cst ; yields void
10657 '``cmpxchg``' Instruction
10658 ^^^^^^^^^^^^^^^^^^^^^^^^^
10665 cmpxchg [weak] [volatile] ptr <pointer>, <ty> <cmp>, <ty> <new> [syncscope("<target-scope>")] <success ordering> <failure ordering>[, align <alignment>] ; yields { ty, i1 }
10670 The '``cmpxchg``' instruction is used to atomically modify memory. It
10671 loads a value in memory and compares it to a given value. If they are
10672 equal, it tries to store a new value into the memory.
10677 There are three arguments to the '``cmpxchg``' instruction: an address
10678 to operate on, a value to compare to the value currently be at that
10679 address, and a new value to place at that address if the compared values
10680 are equal. The type of '<cmp>' must be an integer or pointer type whose
10681 bit width is a power of two greater than or equal to eight and less
10682 than or equal to a target-specific size limit. '<cmp>' and '<new>' must
10683 have the same type, and the type of '<pointer>' must be a pointer to
10684 that type. If the ``cmpxchg`` is marked as ``volatile``, then the
10685 optimizer is not allowed to modify the number or order of execution of
10686 this ``cmpxchg`` with other :ref:`volatile operations <volatile>`.
10688 The success and failure :ref:`ordering <ordering>` arguments specify how this
10689 ``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters
10690 must be at least ``monotonic``, the failure ordering cannot be either
10691 ``release`` or ``acq_rel``.
10693 A ``cmpxchg`` instruction can also take an optional
10694 ":ref:`syncscope <syncscope>`" argument.
10696 The alignment must be a power of two greater or equal to the size of the
10699 The alignment is only optional when parsing textual IR; for in-memory IR, it is
10700 always present. If unspecified, the alignment is assumed to be equal to the
10701 size of the '<value>' type. Note that this default alignment assumption is
10702 different from the alignment used for the load/store instructions when align
10705 The pointer passed into cmpxchg must have alignment greater than or
10706 equal to the size in memory of the operand.
10711 The contents of memory at the location specified by the '``<pointer>``' operand
10712 is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is
10713 written to the location. The original value at the location is returned,
10714 together with a flag indicating success (true) or failure (false).
10716 If the cmpxchg operation is marked as ``weak`` then a spurious failure is
10717 permitted: the operation may not write ``<new>`` even if the comparison
10720 If the cmpxchg operation is strong (the default), the i1 value is 1 if and only
10721 if the value loaded equals ``cmp``.
10723 A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of
10724 identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic
10725 load with an ordering parameter determined the second ordering parameter.
10730 .. code-block:: llvm
10733 %orig = load atomic i32, ptr %ptr unordered, align 4 ; yields i32
10737 %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop]
10738 %squared = mul i32 %cmp, %cmp
10739 %val_success = cmpxchg ptr %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 }
10740 %value_loaded = extractvalue { i32, i1 } %val_success, 0
10741 %success = extractvalue { i32, i1 } %val_success, 1
10742 br i1 %success, label %done, label %loop
10749 '``atomicrmw``' Instruction
10750 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10757 atomicrmw [volatile] <operation> ptr <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering>[, align <alignment>] ; yields ty
10762 The '``atomicrmw``' instruction is used to atomically modify memory.
10767 There are three arguments to the '``atomicrmw``' instruction: an
10768 operation to apply, an address whose value to modify, an argument to the
10769 operation. The operation must be one of the following keywords:
10789 For most of these operations, the type of '<value>' must be an integer
10790 type whose bit width is a power of two greater than or equal to eight
10791 and less than or equal to a target-specific size limit. For xchg, this
10792 may also be a floating point or a pointer type with the same size constraints
10793 as integers. For fadd/fsub/fmax/fmin, this must be a floating point type. The
10794 type of the '``<pointer>``' operand must be a pointer to that type. If
10795 the ``atomicrmw`` is marked as ``volatile``, then the optimizer is not
10796 allowed to modify the number or order of execution of this
10797 ``atomicrmw`` with other :ref:`volatile operations <volatile>`.
10799 The alignment must be a power of two greater or equal to the size of the
10802 The alignment is only optional when parsing textual IR; for in-memory IR, it is
10803 always present. If unspecified, the alignment is assumed to be equal to the
10804 size of the '<value>' type. Note that this default alignment assumption is
10805 different from the alignment used for the load/store instructions when align
10808 A ``atomicrmw`` instruction can also take an optional
10809 ":ref:`syncscope <syncscope>`" argument.
10814 The contents of memory at the location specified by the '``<pointer>``'
10815 operand are atomically read, modified, and written back. The original
10816 value at the location is returned. The modification is specified by the
10817 operation argument:
10819 - xchg: ``*ptr = val``
10820 - add: ``*ptr = *ptr + val``
10821 - sub: ``*ptr = *ptr - val``
10822 - and: ``*ptr = *ptr & val``
10823 - nand: ``*ptr = ~(*ptr & val)``
10824 - or: ``*ptr = *ptr | val``
10825 - xor: ``*ptr = *ptr ^ val``
10826 - max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison)
10827 - min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison)
10828 - umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned comparison)
10829 - umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned comparison)
10830 - fadd: ``*ptr = *ptr + val`` (using floating point arithmetic)
10831 - fsub: ``*ptr = *ptr - val`` (using floating point arithmetic)
10832 - fmax: ``*ptr = maxnum(*ptr, val)`` (match the `llvm.maxnum.*`` intrinsic)
10833 - fmin: ``*ptr = minnum(*ptr, val)`` (match the `llvm.minnum.*`` intrinsic)
10834 - uinc_wrap: ``*ptr = (*ptr u>= val) ? 0 : (*ptr + 1)`` (increment value with wraparound to zero when incremented above input value)
10835 - udec_wrap: ``*ptr = ((*ptr == 0) || (*ptr u> val)) ? val : (*ptr - 1)`` (decrement with wraparound to input value when decremented below zero).
10841 .. code-block:: llvm
10843 %old = atomicrmw add ptr %ptr, i32 1 acquire ; yields i32
10845 .. _i_getelementptr:
10847 '``getelementptr``' Instruction
10848 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10855 <result> = getelementptr <ty>, ptr <ptrval>{, [inrange] <ty> <idx>}*
10856 <result> = getelementptr inbounds <ty>, ptr <ptrval>{, [inrange] <ty> <idx>}*
10857 <result> = getelementptr <ty>, <N x ptr> <ptrval>, [inrange] <vector index type> <idx>
10862 The '``getelementptr``' instruction is used to get the address of a
10863 subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs
10864 address calculation only and does not access memory. The instruction can also
10865 be used to calculate a vector of such addresses.
10870 The first argument is always a type used as the basis for the calculations.
10871 The second argument is always a pointer or a vector of pointers, and is the
10872 base address to start from. The remaining arguments are indices
10873 that indicate which of the elements of the aggregate object are indexed.
10874 The interpretation of each index is dependent on the type being indexed
10875 into. The first index always indexes the pointer value given as the
10876 second argument, the second index indexes a value of the type pointed to
10877 (not necessarily the value directly pointed to, since the first index
10878 can be non-zero), etc. The first type indexed into must be a pointer
10879 value, subsequent types can be arrays, vectors, and structs. Note that
10880 subsequent types being indexed into can never be pointers, since that
10881 would require loading the pointer before continuing calculation.
10883 The type of each index argument depends on the type it is indexing into.
10884 When indexing into a (optionally packed) structure, only ``i32`` integer
10885 **constants** are allowed (when using a vector of indices they must all
10886 be the **same** ``i32`` integer constant). When indexing into an array,
10887 pointer or vector, integers of any width are allowed, and they are not
10888 required to be constant. These integers are treated as signed values
10891 For example, let's consider a C code fragment and how it gets compiled
10907 int *foo(struct ST *s) {
10908 return &s[1].Z.B[5][13];
10911 The LLVM code generated by Clang is approximately:
10913 .. code-block:: llvm
10915 %struct.RT = type { i8, [10 x [20 x i32]], i8 }
10916 %struct.ST = type { i32, double, %struct.RT }
10918 define ptr @foo(ptr %s) {
10920 %arrayidx = getelementptr inbounds %struct.ST, ptr %s, i64 1, i32 2, i32 1, i64 5, i64 13
10927 In the example above, the first index is indexing into the
10928 '``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``'
10929 = '``{ i32, double, %struct.RT }``' type, a structure. The second index
10930 indexes into the third element of the structure, yielding a
10931 '``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another
10932 structure. The third index indexes into the second element of the
10933 structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two
10934 dimensions of the array are subscripted into, yielding an '``i32``'
10935 type. The '``getelementptr``' instruction returns a pointer to this
10938 Note that it is perfectly legal to index partially through a structure,
10939 returning a pointer to an inner element. Because of this, the LLVM code
10940 for the given testcase is equivalent to:
10942 .. code-block:: llvm
10944 define ptr @foo(ptr %s) {
10945 %t1 = getelementptr %struct.ST, ptr %s, i32 1
10946 %t2 = getelementptr %struct.ST, ptr %t1, i32 0, i32 2
10947 %t3 = getelementptr %struct.RT, ptr %t2, i32 0, i32 1
10948 %t4 = getelementptr [10 x [20 x i32]], ptr %t3, i32 0, i32 5
10949 %t5 = getelementptr [20 x i32], ptr %t4, i32 0, i32 13
10953 If the ``inbounds`` keyword is present, the result value of a
10954 ``getelementptr`` with any non-zero indices is a
10955 :ref:`poison value <poisonvalues>` if one of the following rules is violated:
10957 * The base pointer has an *in bounds* address of an allocated object, which
10958 means that it points into an allocated object, or to its end. Note that the
10959 object does not have to be live anymore; being in-bounds of a deallocated
10960 object is sufficient.
10961 * If the type of an index is larger than the pointer index type, the
10962 truncation to the pointer index type preserves the signed value.
10963 * The multiplication of an index by the type size does not wrap the pointer
10964 index type in a signed sense (``nsw``).
10965 * The successive addition of each offset (without adding the base address) does
10966 not wrap the pointer index type in a signed sense (``nsw``).
10967 * The successive addition of the current address, interpreted as an unsigned
10968 number, and each offset, interpreted as a signed number, does not wrap the
10969 unsigned address space and remains *in bounds* of the allocated object.
10970 As a corollary, if the added offset is non-negative, the addition does not
10971 wrap in an unsigned sense (``nuw``).
10972 * In cases where the base is a vector of pointers, the ``inbounds`` keyword
10973 applies to each of the computations element-wise.
10975 Note that ``getelementptr`` with all-zero indices is always considered to be
10976 ``inbounds``, even if the base pointer does not point to an allocated object.
10977 As a corollary, the only pointer in bounds of the null pointer in the default
10978 address space is the null pointer itself.
10980 These rules are based on the assumption that no allocated object may cross
10981 the unsigned address space boundary, and no allocated object may be larger
10982 than half the pointer index type space.
10984 If the ``inbounds`` keyword is not present, the offsets are added to the
10985 base address with silently-wrapping two's complement arithmetic. If the
10986 offsets have a different width from the pointer's index type, they are
10987 sign-extended or truncated to the width of the pointer's index type. The result
10988 value of the ``getelementptr`` may be outside the object pointed to by the base
10989 pointer. The result value may not necessarily be used to access memory
10990 though, even if it happens to point into allocated storage. See the
10991 :ref:`Pointer Aliasing Rules <pointeraliasing>` section for more
10994 If the ``inrange`` keyword is present before any index, loading from or
10995 storing to any pointer derived from the ``getelementptr`` has undefined
10996 behavior if the load or store would access memory outside of the bounds of
10997 the element selected by the index marked as ``inrange``. The result of a
10998 pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations
10999 involving memory) involving a pointer derived from a ``getelementptr`` with
11000 the ``inrange`` keyword is undefined, with the exception of comparisons
11001 in the case where both operands are in the range of the element selected
11002 by the ``inrange`` keyword, inclusive of the address one past the end of
11003 that element. Note that the ``inrange`` keyword is currently only allowed
11004 in constant ``getelementptr`` expressions.
11006 The getelementptr instruction is often confusing. For some more insight
11007 into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`.
11012 .. code-block:: llvm
11014 %aptr = getelementptr {i32, [12 x i8]}, ptr %saptr, i64 0, i32 1
11015 %vptr = getelementptr {i32, <2 x i8>}, ptr %svptr, i64 0, i32 1, i32 1
11016 %eptr = getelementptr [12 x i8], ptr %aptr, i64 0, i32 1
11017 %iptr = getelementptr [10 x i32], ptr @arr, i16 0, i16 0
11019 Vector of pointers:
11020 """""""""""""""""""
11022 The ``getelementptr`` returns a vector of pointers, instead of a single address,
11023 when one or more of its arguments is a vector. In such cases, all vector
11024 arguments should have the same number of elements, and every scalar argument
11025 will be effectively broadcast into a vector during address calculation.
11027 .. code-block:: llvm
11029 ; All arguments are vectors:
11030 ; A[i] = ptrs[i] + offsets[i]*sizeof(i8)
11031 %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets
11033 ; Add the same scalar offset to each pointer of a vector:
11034 ; A[i] = ptrs[i] + offset*sizeof(i8)
11035 %A = getelementptr i8, <4 x ptr> %ptrs, i64 %offset
11037 ; Add distinct offsets to the same pointer:
11038 ; A[i] = ptr + offsets[i]*sizeof(i8)
11039 %A = getelementptr i8, ptr %ptr, <4 x i64> %offsets
11041 ; In all cases described above the type of the result is <4 x ptr>
11043 The two following instructions are equivalent:
11045 .. code-block:: llvm
11047 getelementptr %struct.ST, <4 x ptr> %s, <4 x i64> %ind1,
11048 <4 x i32> <i32 2, i32 2, i32 2, i32 2>,
11049 <4 x i32> <i32 1, i32 1, i32 1, i32 1>,
11051 <4 x i64> <i64 13, i64 13, i64 13, i64 13>
11053 getelementptr %struct.ST, <4 x ptr> %s, <4 x i64> %ind1,
11054 i32 2, i32 1, <4 x i32> %ind4, i64 13
11056 Let's look at the C code, where the vector version of ``getelementptr``
11061 // Let's assume that we vectorize the following loop:
11062 double *A, *B; int *C;
11063 for (int i = 0; i < size; ++i) {
11067 .. code-block:: llvm
11069 ; get pointers for 8 elements from array B
11070 %ptrs = getelementptr double, ptr %B, <8 x i32> %C
11071 ; load 8 elements from array B into A
11072 %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x ptr> %ptrs,
11073 i32 8, <8 x i1> %mask, <8 x double> %passthru)
11075 Conversion Operations
11076 ---------------------
11078 The instructions in this category are the conversion instructions
11079 (casting) which all take a single operand and a type. They perform
11080 various bit conversions on the operand.
11084 '``trunc .. to``' Instruction
11085 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11092 <result> = trunc <ty> <value> to <ty2> ; yields ty2
11097 The '``trunc``' instruction truncates its operand to the type ``ty2``.
11102 The '``trunc``' instruction takes a value to trunc, and a type to trunc
11103 it to. Both types must be of :ref:`integer <t_integer>` types, or vectors
11104 of the same number of integers. The bit size of the ``value`` must be
11105 larger than the bit size of the destination type, ``ty2``. Equal sized
11106 types are not allowed.
11111 The '``trunc``' instruction truncates the high order bits in ``value``
11112 and converts the remaining bits to ``ty2``. Since the source size must
11113 be larger than the destination size, ``trunc`` cannot be a *no-op cast*.
11114 It will always truncate bits.
11119 .. code-block:: llvm
11121 %X = trunc i32 257 to i8 ; yields i8:1
11122 %Y = trunc i32 123 to i1 ; yields i1:true
11123 %Z = trunc i32 122 to i1 ; yields i1:false
11124 %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7>
11128 '``zext .. to``' Instruction
11129 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11136 <result> = zext <ty> <value> to <ty2> ; yields ty2
11141 The '``zext``' instruction zero extends its operand to type ``ty2``.
11146 The '``zext``' instruction takes a value to cast, and a type to cast it
11147 to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
11148 the same number of integers. The bit size of the ``value`` must be
11149 smaller than the bit size of the destination type, ``ty2``.
11154 The ``zext`` fills the high order bits of the ``value`` with zero bits
11155 until it reaches the size of the destination type, ``ty2``.
11157 When zero extending from i1, the result will always be either 0 or 1.
11162 .. code-block:: llvm
11164 %X = zext i32 257 to i64 ; yields i64:257
11165 %Y = zext i1 true to i32 ; yields i32:1
11166 %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
11170 '``sext .. to``' Instruction
11171 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11178 <result> = sext <ty> <value> to <ty2> ; yields ty2
11183 The '``sext``' sign extends ``value`` to the type ``ty2``.
11188 The '``sext``' instruction takes a value to cast, and a type to cast it
11189 to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
11190 the same number of integers. The bit size of the ``value`` must be
11191 smaller than the bit size of the destination type, ``ty2``.
11196 The '``sext``' instruction performs a sign extension by copying the sign
11197 bit (highest order bit) of the ``value`` until it reaches the bit size
11198 of the type ``ty2``.
11200 When sign extending from i1, the extension always results in -1 or 0.
11205 .. code-block:: llvm
11207 %X = sext i8 -1 to i16 ; yields i16 :65535
11208 %Y = sext i1 true to i32 ; yields i32:-1
11209 %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
11211 '``fptrunc .. to``' Instruction
11212 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11219 <result> = fptrunc <ty> <value> to <ty2> ; yields ty2
11224 The '``fptrunc``' instruction truncates ``value`` to type ``ty2``.
11229 The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>`
11230 value to cast and a :ref:`floating-point <t_floating>` type to cast it to.
11231 The size of ``value`` must be larger than the size of ``ty2``. This
11232 implies that ``fptrunc`` cannot be used to make a *no-op cast*.
11237 The '``fptrunc``' instruction casts a ``value`` from a larger
11238 :ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
11239 <t_floating>` type.
11240 This instruction is assumed to execute in the default :ref:`floating-point
11241 environment <floatenv>`.
11246 .. code-block:: llvm
11248 %X = fptrunc double 16777217.0 to float ; yields float:16777216.0
11249 %Y = fptrunc double 1.0E+300 to half ; yields half:+infinity
11251 '``fpext .. to``' Instruction
11252 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11259 <result> = fpext <ty> <value> to <ty2> ; yields ty2
11264 The '``fpext``' extends a floating-point ``value`` to a larger floating-point
11270 The '``fpext``' instruction takes a :ref:`floating-point <t_floating>`
11271 ``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it
11272 to. The source type must be smaller than the destination type.
11277 The '``fpext``' instruction extends the ``value`` from a smaller
11278 :ref:`floating-point <t_floating>` type to a larger :ref:`floating-point
11279 <t_floating>` type. The ``fpext`` cannot be used to make a
11280 *no-op cast* because it always changes bits. Use ``bitcast`` to make a
11281 *no-op cast* for a floating-point cast.
11286 .. code-block:: llvm
11288 %X = fpext float 3.125 to double ; yields double:3.125000e+00
11289 %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000
11291 '``fptoui .. to``' Instruction
11292 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11299 <result> = fptoui <ty> <value> to <ty2> ; yields ty2
11304 The '``fptoui``' converts a floating-point ``value`` to its unsigned
11305 integer equivalent of type ``ty2``.
11310 The '``fptoui``' instruction takes a value to cast, which must be a
11311 scalar or vector :ref:`floating-point <t_floating>` value, and a type to
11312 cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
11313 ``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
11314 type with the same number of elements as ``ty``
11319 The '``fptoui``' instruction converts its :ref:`floating-point
11320 <t_floating>` operand into the nearest (rounding towards zero)
11321 unsigned integer value. If the value cannot fit in ``ty2``, the result
11322 is a :ref:`poison value <poisonvalues>`.
11327 .. code-block:: llvm
11329 %X = fptoui double 123.0 to i32 ; yields i32:123
11330 %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1
11331 %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1
11333 '``fptosi .. to``' Instruction
11334 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11341 <result> = fptosi <ty> <value> to <ty2> ; yields ty2
11346 The '``fptosi``' instruction converts :ref:`floating-point <t_floating>`
11347 ``value`` to type ``ty2``.
11352 The '``fptosi``' instruction takes a value to cast, which must be a
11353 scalar or vector :ref:`floating-point <t_floating>` value, and a type to
11354 cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
11355 ``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
11356 type with the same number of elements as ``ty``
11361 The '``fptosi``' instruction converts its :ref:`floating-point
11362 <t_floating>` operand into the nearest (rounding towards zero)
11363 signed integer value. If the value cannot fit in ``ty2``, the result
11364 is a :ref:`poison value <poisonvalues>`.
11369 .. code-block:: llvm
11371 %X = fptosi double -123.0 to i32 ; yields i32:-123
11372 %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1
11373 %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1
11375 '``uitofp .. to``' Instruction
11376 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11383 <result> = uitofp <ty> <value> to <ty2> ; yields ty2
11388 The '``uitofp``' instruction regards ``value`` as an unsigned integer
11389 and converts that value to the ``ty2`` type.
11394 The '``uitofp``' instruction takes a value to cast, which must be a
11395 scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
11396 ``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
11397 ``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
11398 type with the same number of elements as ``ty``
11403 The '``uitofp``' instruction interprets its operand as an unsigned
11404 integer quantity and converts it to the corresponding floating-point
11405 value. If the value cannot be exactly represented, it is rounded using
11406 the default rounding mode.
11412 .. code-block:: llvm
11414 %X = uitofp i32 257 to float ; yields float:257.0
11415 %Y = uitofp i8 -1 to double ; yields double:255.0
11417 '``sitofp .. to``' Instruction
11418 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11425 <result> = sitofp <ty> <value> to <ty2> ; yields ty2
11430 The '``sitofp``' instruction regards ``value`` as a signed integer and
11431 converts that value to the ``ty2`` type.
11436 The '``sitofp``' instruction takes a value to cast, which must be a
11437 scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
11438 ``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
11439 ``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
11440 type with the same number of elements as ``ty``
11445 The '``sitofp``' instruction interprets its operand as a signed integer
11446 quantity and converts it to the corresponding floating-point value. If the
11447 value cannot be exactly represented, it is rounded using the default rounding
11453 .. code-block:: llvm
11455 %X = sitofp i32 257 to float ; yields float:257.0
11456 %Y = sitofp i8 -1 to double ; yields double:-1.0
11460 '``ptrtoint .. to``' Instruction
11461 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11468 <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2
11473 The '``ptrtoint``' instruction converts the pointer or a vector of
11474 pointers ``value`` to the integer (or vector of integers) type ``ty2``.
11479 The '``ptrtoint``' instruction takes a ``value`` to cast, which must be
11480 a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
11481 type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
11482 a vector of integers type.
11487 The '``ptrtoint``' instruction converts ``value`` to integer type
11488 ``ty2`` by interpreting the pointer value as an integer and either
11489 truncating or zero extending that value to the size of the integer type.
11490 If ``value`` is smaller than ``ty2`` then a zero extension is done. If
11491 ``value`` is larger than ``ty2`` then a truncation is done. If they are
11492 the same size, then nothing is done (*no-op cast*) other than a type
11498 .. code-block:: llvm
11500 %X = ptrtoint ptr %P to i8 ; yields truncation on 32-bit architecture
11501 %Y = ptrtoint ptr %P to i64 ; yields zero extension on 32-bit architecture
11502 %Z = ptrtoint <4 x ptr> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
11506 '``inttoptr .. to``' Instruction
11507 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11514 <result> = inttoptr <ty> <value> to <ty2>[, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>] ; yields ty2
11519 The '``inttoptr``' instruction converts an integer ``value`` to a
11520 pointer type, ``ty2``.
11525 The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to
11526 cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>`
11529 The optional ``!dereferenceable`` metadata must reference a single metadata
11530 name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
11532 See ``dereferenceable`` metadata.
11534 The optional ``!dereferenceable_or_null`` metadata must reference a single
11535 metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
11537 See ``dereferenceable_or_null`` metadata.
11542 The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by
11543 applying either a zero extension or a truncation depending on the size
11544 of the integer ``value``. If ``value`` is larger than the size of a
11545 pointer then a truncation is done. If ``value`` is smaller than the size
11546 of a pointer then a zero extension is done. If they are the same size,
11547 nothing is done (*no-op cast*).
11552 .. code-block:: llvm
11554 %X = inttoptr i32 255 to ptr ; yields zero extension on 64-bit architecture
11555 %Y = inttoptr i32 255 to ptr ; yields no-op on 32-bit architecture
11556 %Z = inttoptr i64 0 to ptr ; yields truncation on 32-bit architecture
11557 %Z = inttoptr <4 x i32> %G to <4 x ptr>; yields truncation of vector G to four pointers
11561 '``bitcast .. to``' Instruction
11562 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11569 <result> = bitcast <ty> <value> to <ty2> ; yields ty2
11574 The '``bitcast``' instruction converts ``value`` to type ``ty2`` without
11580 The '``bitcast``' instruction takes a value to cast, which must be a
11581 non-aggregate first class value, and a type to cast it to, which must
11582 also be a non-aggregate :ref:`first class <t_firstclass>` type. The
11583 bit sizes of ``value`` and the destination type, ``ty2``, must be
11584 identical. If the source type is a pointer, the destination type must
11585 also be a pointer of the same size. This instruction supports bitwise
11586 conversion of vectors to integers and to vectors of other types (as
11587 long as they have the same size).
11592 The '``bitcast``' instruction converts ``value`` to type ``ty2``. It
11593 is always a *no-op cast* because no bits change with this
11594 conversion. The conversion is done as if the ``value`` had been stored
11595 to memory and read back as type ``ty2``. Pointer (or vector of
11596 pointers) types may only be converted to other pointer (or vector of
11597 pointers) types with the same address space through this instruction.
11598 To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>`
11599 or :ref:`ptrtoint <i_ptrtoint>` instructions first.
11601 There is a caveat for bitcasts involving vector types in relation to
11602 endianess. For example ``bitcast <2 x i8> <value> to i16`` puts element zero
11603 of the vector in the least significant bits of the i16 for little-endian while
11604 element zero ends up in the most significant bits for big-endian.
11609 .. code-block:: text
11611 %X = bitcast i8 255 to i8 ; yields i8 :-1
11612 %Y = bitcast i32* %x to i16* ; yields i16*:%x
11613 %Z = bitcast <2 x i32> %V to i64; ; yields i64: %V (depends on endianess)
11614 %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
11616 .. _i_addrspacecast:
11618 '``addrspacecast .. to``' Instruction
11619 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11626 <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2
11631 The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in
11632 address space ``n`` to type ``pty2`` in address space ``m``.
11637 The '``addrspacecast``' instruction takes a pointer or vector of pointer value
11638 to cast and a pointer type to cast it to, which must have a different
11644 The '``addrspacecast``' instruction converts the pointer value
11645 ``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex
11646 value modification, depending on the target and the address space
11647 pair. Pointer conversions within the same address space must be
11648 performed with the ``bitcast`` instruction. Note that if the address
11649 space conversion produces a dereferenceable result then both result
11650 and operand refer to the same memory location. The conversion must
11651 have no side effects, and must not capture the value of the pointer.
11653 If the source is :ref:`poison <poisonvalues>`, the result is
11654 :ref:`poison <poisonvalues>`.
11656 If the source is not :ref:`poison <poisonvalues>`, and both source and
11657 destination are :ref:`integral pointers <nointptrtype>`, and the
11658 result pointer is dereferenceable, the cast is assumed to be
11659 reversible (i.e. casting the result back to the original address space
11660 should yield the original bit pattern).
11665 .. code-block:: llvm
11667 %X = addrspacecast ptr %x to ptr addrspace(1)
11668 %Y = addrspacecast ptr addrspace(1) %y to ptr addrspace(2)
11669 %Z = addrspacecast <4 x ptr> %z to <4 x ptr addrspace(3)>
11676 The instructions in this category are the "miscellaneous" instructions,
11677 which defy better classification.
11681 '``icmp``' Instruction
11682 ^^^^^^^^^^^^^^^^^^^^^^
11689 <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
11694 The '``icmp``' instruction returns a boolean value or a vector of
11695 boolean values based on comparison of its two integer, integer vector,
11696 pointer, or pointer vector operands.
11701 The '``icmp``' instruction takes three operands. The first operand is
11702 the condition code indicating the kind of comparison to perform. It is
11703 not a value, just a keyword. The possible condition codes are:
11708 #. ``ne``: not equal
11709 #. ``ugt``: unsigned greater than
11710 #. ``uge``: unsigned greater or equal
11711 #. ``ult``: unsigned less than
11712 #. ``ule``: unsigned less or equal
11713 #. ``sgt``: signed greater than
11714 #. ``sge``: signed greater or equal
11715 #. ``slt``: signed less than
11716 #. ``sle``: signed less or equal
11718 The remaining two arguments must be :ref:`integer <t_integer>` or
11719 :ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They
11720 must also be identical types.
11725 The '``icmp``' compares ``op1`` and ``op2`` according to the condition
11726 code given as ``cond``. The comparison performed always yields either an
11727 :ref:`i1 <t_integer>` or vector of ``i1`` result, as follows:
11729 .. _icmp_md_cc_sem:
11731 #. ``eq``: yields ``true`` if the operands are equal, ``false``
11732 otherwise. No sign interpretation is necessary or performed.
11733 #. ``ne``: yields ``true`` if the operands are unequal, ``false``
11734 otherwise. No sign interpretation is necessary or performed.
11735 #. ``ugt``: interprets the operands as unsigned values and yields
11736 ``true`` if ``op1`` is greater than ``op2``.
11737 #. ``uge``: interprets the operands as unsigned values and yields
11738 ``true`` if ``op1`` is greater than or equal to ``op2``.
11739 #. ``ult``: interprets the operands as unsigned values and yields
11740 ``true`` if ``op1`` is less than ``op2``.
11741 #. ``ule``: interprets the operands as unsigned values and yields
11742 ``true`` if ``op1`` is less than or equal to ``op2``.
11743 #. ``sgt``: interprets the operands as signed values and yields ``true``
11744 if ``op1`` is greater than ``op2``.
11745 #. ``sge``: interprets the operands as signed values and yields ``true``
11746 if ``op1`` is greater than or equal to ``op2``.
11747 #. ``slt``: interprets the operands as signed values and yields ``true``
11748 if ``op1`` is less than ``op2``.
11749 #. ``sle``: interprets the operands as signed values and yields ``true``
11750 if ``op1`` is less than or equal to ``op2``.
11752 If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
11753 are compared as if they were integers.
11755 If the operands are integer vectors, then they are compared element by
11756 element. The result is an ``i1`` vector with the same number of elements
11757 as the values being compared. Otherwise, the result is an ``i1``.
11762 .. code-block:: text
11764 <result> = icmp eq i32 4, 5 ; yields: result=false
11765 <result> = icmp ne ptr %X, %X ; yields: result=false
11766 <result> = icmp ult i16 4, 5 ; yields: result=true
11767 <result> = icmp sgt i16 4, 5 ; yields: result=false
11768 <result> = icmp ule i16 -4, 5 ; yields: result=false
11769 <result> = icmp sge i16 4, 5 ; yields: result=false
11773 '``fcmp``' Instruction
11774 ^^^^^^^^^^^^^^^^^^^^^^
11781 <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
11786 The '``fcmp``' instruction returns a boolean value or vector of boolean
11787 values based on comparison of its operands.
11789 If the operands are floating-point scalars, then the result type is a
11790 boolean (:ref:`i1 <t_integer>`).
11792 If the operands are floating-point vectors, then the result type is a
11793 vector of boolean with the same number of elements as the operands being
11799 The '``fcmp``' instruction takes three operands. The first operand is
11800 the condition code indicating the kind of comparison to perform. It is
11801 not a value, just a keyword. The possible condition codes are:
11803 #. ``false``: no comparison, always returns false
11804 #. ``oeq``: ordered and equal
11805 #. ``ogt``: ordered and greater than
11806 #. ``oge``: ordered and greater than or equal
11807 #. ``olt``: ordered and less than
11808 #. ``ole``: ordered and less than or equal
11809 #. ``one``: ordered and not equal
11810 #. ``ord``: ordered (no nans)
11811 #. ``ueq``: unordered or equal
11812 #. ``ugt``: unordered or greater than
11813 #. ``uge``: unordered or greater than or equal
11814 #. ``ult``: unordered or less than
11815 #. ``ule``: unordered or less than or equal
11816 #. ``une``: unordered or not equal
11817 #. ``uno``: unordered (either nans)
11818 #. ``true``: no comparison, always returns true
11820 *Ordered* means that neither operand is a QNAN while *unordered* means
11821 that either operand may be a QNAN.
11823 Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point
11824 <t_floating>` type or a :ref:`vector <t_vector>` of floating-point type.
11825 They must have identical types.
11830 The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the
11831 condition code given as ``cond``. If the operands are vectors, then the
11832 vectors are compared element by element. Each comparison performed
11833 always yields an :ref:`i1 <t_integer>` result, as follows:
11835 #. ``false``: always yields ``false``, regardless of operands.
11836 #. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1``
11837 is equal to ``op2``.
11838 #. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1``
11839 is greater than ``op2``.
11840 #. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1``
11841 is greater than or equal to ``op2``.
11842 #. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1``
11843 is less than ``op2``.
11844 #. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1``
11845 is less than or equal to ``op2``.
11846 #. ``one``: yields ``true`` if both operands are not a QNAN and ``op1``
11847 is not equal to ``op2``.
11848 #. ``ord``: yields ``true`` if both operands are not a QNAN.
11849 #. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is
11851 #. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is
11852 greater than ``op2``.
11853 #. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is
11854 greater than or equal to ``op2``.
11855 #. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is
11857 #. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is
11858 less than or equal to ``op2``.
11859 #. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is
11860 not equal to ``op2``.
11861 #. ``uno``: yields ``true`` if either operand is a QNAN.
11862 #. ``true``: always yields ``true``, regardless of operands.
11864 The ``fcmp`` instruction can also optionally take any number of
11865 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
11866 otherwise unsafe floating-point optimizations.
11868 Any set of fast-math flags are legal on an ``fcmp`` instruction, but the
11869 only flags that have any effect on its semantics are those that allow
11870 assumptions to be made about the values of input arguments; namely
11871 ``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information.
11876 .. code-block:: text
11878 <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false
11879 <result> = fcmp one float 4.0, 5.0 ; yields: result=true
11880 <result> = fcmp olt float 4.0, 5.0 ; yields: result=true
11881 <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false
11885 '``phi``' Instruction
11886 ^^^^^^^^^^^^^^^^^^^^^
11893 <result> = phi [fast-math-flags] <ty> [ <val0>, <label0>], ...
11898 The '``phi``' instruction is used to implement the φ node in the SSA
11899 graph representing the function.
11904 The type of the incoming values is specified with the first type field.
11905 After this, the '``phi``' instruction takes a list of pairs as
11906 arguments, with one pair for each predecessor basic block of the current
11907 block. Only values of :ref:`first class <t_firstclass>` type may be used as
11908 the value arguments to the PHI node. Only labels may be used as the
11911 There must be no non-phi instructions between the start of a basic block
11912 and the PHI instructions: i.e. PHI instructions must be first in a basic
11915 For the purposes of the SSA form, the use of each incoming value is
11916 deemed to occur on the edge from the corresponding predecessor block to
11917 the current block (but after any definition of an '``invoke``'
11918 instruction's return value on the same edge).
11920 The optional ``fast-math-flags`` marker indicates that the phi has one
11921 or more :ref:`fast-math-flags <fastmath>`. These are optimization hints
11922 to enable otherwise unsafe floating-point optimizations. Fast-math-flags
11923 are only valid for phis that return a floating-point scalar or vector
11924 type, or an array (nested to any depth) of floating-point scalar or vector
11930 At runtime, the '``phi``' instruction logically takes on the value
11931 specified by the pair corresponding to the predecessor basic block that
11932 executed just prior to the current block.
11937 .. code-block:: llvm
11939 Loop: ; Infinite loop that counts from 0 on up...
11940 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
11941 %nextindvar = add i32 %indvar, 1
11946 '``select``' Instruction
11947 ^^^^^^^^^^^^^^^^^^^^^^^^
11954 <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty
11956 selty is either i1 or {<N x i1>}
11961 The '``select``' instruction is used to choose one value based on a
11962 condition, without IR-level branching.
11967 The '``select``' instruction requires an 'i1' value or a vector of 'i1'
11968 values indicating the condition, and two values of the same :ref:`first
11969 class <t_firstclass>` type.
11971 #. The optional ``fast-math flags`` marker indicates that the select has one or more
11972 :ref:`fast-math flags <fastmath>`. These are optimization hints to enable
11973 otherwise unsafe floating-point optimizations. Fast-math flags are only valid
11974 for selects that return a floating-point scalar or vector type, or an array
11975 (nested to any depth) of floating-point scalar or vector types.
11980 If the condition is an i1 and it evaluates to 1, the instruction returns
11981 the first value argument; otherwise, it returns the second value
11984 If the condition is a vector of i1, then the value arguments must be
11985 vectors of the same size, and the selection is done element by element.
11987 If the condition is an i1 and the value arguments are vectors of the
11988 same size, then an entire vector is selected.
11993 .. code-block:: llvm
11995 %X = select i1 true, i8 17, i8 42 ; yields i8:17
12000 '``freeze``' Instruction
12001 ^^^^^^^^^^^^^^^^^^^^^^^^
12008 <result> = freeze ty <val> ; yields ty:result
12013 The '``freeze``' instruction is used to stop propagation of
12014 :ref:`undef <undefvalues>` and :ref:`poison <poisonvalues>` values.
12019 The '``freeze``' instruction takes a single argument.
12024 If the argument is ``undef`` or ``poison``, '``freeze``' returns an
12025 arbitrary, but fixed, value of type '``ty``'.
12026 Otherwise, this instruction is a no-op and returns the input argument.
12027 All uses of a value returned by the same '``freeze``' instruction are
12028 guaranteed to always observe the same value, while different '``freeze``'
12029 instructions may yield different values.
12031 While ``undef`` and ``poison`` pointers can be frozen, the result is a
12032 non-dereferenceable pointer. See the
12033 :ref:`Pointer Aliasing Rules <pointeraliasing>` section for more information.
12034 If an aggregate value or vector is frozen, the operand is frozen element-wise.
12035 The padding of an aggregate isn't considered, since it isn't visible
12036 without storing it into memory and loading it with a different type.
12042 .. code-block:: text
12046 %y = add i32 %w, %w ; undef
12047 %z = add i32 %x, %x ; even number because all uses of %x observe
12049 %x2 = freeze i32 %w
12050 %cmp = icmp eq i32 %x, %x2 ; can be true or false
12052 ; example with vectors
12053 %v = <2 x i32> <i32 undef, i32 poison>
12054 %a = extractelement <2 x i32> %v, i32 0 ; undef
12055 %b = extractelement <2 x i32> %v, i32 1 ; poison
12056 %add = add i32 %a, %a ; undef
12058 %v.fr = freeze <2 x i32> %v ; element-wise freeze
12059 %d = extractelement <2 x i32> %v.fr, i32 0 ; not undef
12060 %add.f = add i32 %d, %d ; even number
12062 ; branching on frozen value
12063 %poison = add nsw i1 %k, undef ; poison
12064 %c = freeze i1 %poison
12065 br i1 %c, label %foo, label %bar ; non-deterministic branch to %foo or %bar
12070 '``call``' Instruction
12071 ^^^^^^^^^^^^^^^^^^^^^^
12078 <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] [addrspace(<num>)]
12079 <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] [ operand bundles ]
12084 The '``call``' instruction represents a simple function call.
12089 This instruction requires several arguments:
12091 #. The optional ``tail`` and ``musttail`` markers indicate that the optimizers
12092 should perform tail call optimization. The ``tail`` marker is a hint that
12093 `can be ignored <CodeGenerator.html#tail-call-optimization>`_. The
12094 ``musttail`` marker means that the call must be tail call optimized in order
12095 for the program to be correct. This is true even in the presence of
12096 attributes like "disable-tail-calls". The ``musttail`` marker provides these
12099 #. The call will not cause unbounded stack growth if it is part of a
12100 recursive cycle in the call graph.
12101 #. Arguments with the :ref:`inalloca <attr_inalloca>` or
12102 :ref:`preallocated <attr_preallocated>` attribute are forwarded in place.
12103 #. If the musttail call appears in a function with the ``"thunk"`` attribute
12104 and the caller and callee both have varargs, than any unprototyped
12105 arguments in register or memory are forwarded to the callee. Similarly,
12106 the return value of the callee is returned to the caller's caller, even
12107 if a void return type is in use.
12109 Both markers imply that the callee does not access allocas from the caller.
12110 The ``tail`` marker additionally implies that the callee does not access
12111 varargs from the caller. Calls marked ``musttail`` must obey the following
12114 - The call must immediately precede a :ref:`ret <i_ret>` instruction,
12115 or a pointer bitcast followed by a ret instruction.
12116 - The ret instruction must return the (possibly bitcasted) value
12117 produced by the call, undef, or void.
12118 - The calling conventions of the caller and callee must match.
12119 - The callee must be varargs iff the caller is varargs. Bitcasting a
12120 non-varargs function to the appropriate varargs type is legal so
12121 long as the non-varargs prefixes obey the other rules.
12122 - The return type must not undergo automatic conversion to an `sret` pointer.
12124 In addition, if the calling convention is not `swifttailcc` or `tailcc`:
12126 - All ABI-impacting function attributes, such as sret, byval, inreg,
12127 returned, and inalloca, must match.
12128 - The caller and callee prototypes must match. Pointer types of parameters
12129 or return types may differ in pointee type, but not in address space.
12131 On the other hand, if the calling convention is `swifttailcc` or `swiftcc`:
12133 - Only these ABI-impacting attributes attributes are allowed: sret, byval,
12134 swiftself, and swiftasync.
12135 - Prototypes are not required to match.
12137 Tail call optimization for calls marked ``tail`` is guaranteed to occur if
12138 the following conditions are met:
12140 - Caller and callee both have the calling convention ``fastcc`` or ``tailcc``.
12141 - The call is in tail position (ret immediately follows call and ret
12142 uses value of call or is void).
12143 - Option ``-tailcallopt`` is enabled,
12144 ``llvm::GuaranteedTailCallOpt`` is ``true``, or the calling convention
12146 - `Platform-specific constraints are
12147 met. <CodeGenerator.html#tailcallopt>`_
12149 #. The optional ``notail`` marker indicates that the optimizers should not add
12150 ``tail`` or ``musttail`` markers to the call. It is used to prevent tail
12151 call optimization from being performed on the call.
12153 #. The optional ``fast-math flags`` marker indicates that the call has one or more
12154 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
12155 otherwise unsafe floating-point optimizations. Fast-math flags are only valid
12156 for calls that return a floating-point scalar or vector type, or an array
12157 (nested to any depth) of floating-point scalar or vector types.
12159 #. The optional "cconv" marker indicates which :ref:`calling
12160 convention <callingconv>` the call should use. If none is
12161 specified, the call defaults to using C calling conventions. The
12162 calling convention of the call must match the calling convention of
12163 the target function, or else the behavior is undefined.
12164 #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
12165 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
12167 #. The optional addrspace attribute can be used to indicate the address space
12168 of the called function. If it is not specified, the program address space
12169 from the :ref:`datalayout string<langref_datalayout>` will be used.
12170 #. '``ty``': the type of the call instruction itself which is also the
12171 type of the return value. Functions that return no value are marked
12173 #. '``fnty``': shall be the signature of the function being called. The
12174 argument types must match the types implied by this signature. This
12175 type can be omitted if the function is not varargs.
12176 #. '``fnptrval``': An LLVM value containing a pointer to a function to
12177 be called. In most cases, this is a direct function call, but
12178 indirect ``call``'s are just as possible, calling an arbitrary pointer
12180 #. '``function args``': argument list whose types match the function
12181 signature argument types and parameter attributes. All arguments must
12182 be of :ref:`first class <t_firstclass>` type. If the function signature
12183 indicates the function accepts a variable number of arguments, the
12184 extra arguments can be specified.
12185 #. The optional :ref:`function attributes <fnattrs>` list.
12186 #. The optional :ref:`operand bundles <opbundles>` list.
12191 The '``call``' instruction is used to cause control flow to transfer to
12192 a specified function, with its incoming arguments bound to the specified
12193 values. Upon a '``ret``' instruction in the called function, control
12194 flow continues with the instruction after the function call, and the
12195 return value of the function is bound to the result argument.
12200 .. code-block:: llvm
12202 %retval = call i32 @test(i32 %argc)
12203 call i32 (ptr, ...) @printf(ptr %msg, i32 12, i8 42) ; yields i32
12204 %X = tail call i32 @foo() ; yields i32
12205 %Y = tail call fastcc i32 @foo() ; yields i32
12206 call void %foo(i8 signext 97)
12208 %struct.A = type { i32, i8 }
12209 %r = call %struct.A @foo() ; yields { i32, i8 }
12210 %gr = extractvalue %struct.A %r, 0 ; yields i32
12211 %gr1 = extractvalue %struct.A %r, 1 ; yields i8
12212 %Z = call void @foo() noreturn ; indicates that %foo never returns normally
12213 %ZZ = call zeroext i32 @bar() ; Return value is %zero extended
12215 llvm treats calls to some functions with names and arguments that match
12216 the standard C99 library as being the C99 library functions, and may
12217 perform optimizations or generate code for them under that assumption.
12218 This is something we'd like to change in the future to provide better
12219 support for freestanding environments and non-C-based languages.
12223 '``va_arg``' Instruction
12224 ^^^^^^^^^^^^^^^^^^^^^^^^
12231 <resultval> = va_arg <va_list*> <arglist>, <argty>
12236 The '``va_arg``' instruction is used to access arguments passed through
12237 the "variable argument" area of a function call. It is used to implement
12238 the ``va_arg`` macro in C.
12243 This instruction takes a ``va_list*`` value and the type of the
12244 argument. It returns a value of the specified argument type and
12245 increments the ``va_list`` to point to the next argument. The actual
12246 type of ``va_list`` is target specific.
12251 The '``va_arg``' instruction loads an argument of the specified type
12252 from the specified ``va_list`` and causes the ``va_list`` to point to
12253 the next argument. For more information, see the variable argument
12254 handling :ref:`Intrinsic Functions <int_varargs>`.
12256 It is legal for this instruction to be called in a function which does
12257 not take a variable number of arguments, for example, the ``vfprintf``
12260 ``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic
12261 function <intrinsics>` because it takes a type as an argument.
12266 See the :ref:`variable argument processing <int_varargs>` section.
12268 Note that the code generator does not yet fully support va\_arg on many
12269 targets. Also, it does not currently support va\_arg with aggregate
12270 types on any target.
12274 '``landingpad``' Instruction
12275 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12282 <resultval> = landingpad <resultty> <clause>+
12283 <resultval> = landingpad <resultty> cleanup <clause>*
12285 <clause> := catch <type> <value>
12286 <clause> := filter <array constant type> <array constant>
12291 The '``landingpad``' instruction is used by `LLVM's exception handling
12292 system <ExceptionHandling.html#overview>`_ to specify that a basic block
12293 is a landing pad --- one where the exception lands, and corresponds to the
12294 code found in the ``catch`` portion of a ``try``/``catch`` sequence. It
12295 defines values supplied by the :ref:`personality function <personalityfn>` upon
12296 re-entry to the function. The ``resultval`` has the type ``resultty``.
12302 ``cleanup`` flag indicates that the landing pad block is a cleanup.
12304 A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and
12305 contains the global variable representing the "type" that may be caught
12306 or filtered respectively. Unlike the ``catch`` clause, the ``filter``
12307 clause takes an array constant as its argument. Use
12308 "``[0 x ptr] undef``" for a filter which cannot throw. The
12309 '``landingpad``' instruction must contain *at least* one ``clause`` or
12310 the ``cleanup`` flag.
12315 The '``landingpad``' instruction defines the values which are set by the
12316 :ref:`personality function <personalityfn>` upon re-entry to the function, and
12317 therefore the "result type" of the ``landingpad`` instruction. As with
12318 calling conventions, how the personality function results are
12319 represented in LLVM IR is target specific.
12321 The clauses are applied in order from top to bottom. If two
12322 ``landingpad`` instructions are merged together through inlining, the
12323 clauses from the calling function are appended to the list of clauses.
12324 When the call stack is being unwound due to an exception being thrown,
12325 the exception is compared against each ``clause`` in turn. If it doesn't
12326 match any of the clauses, and the ``cleanup`` flag is not set, then
12327 unwinding continues further up the call stack.
12329 The ``landingpad`` instruction has several restrictions:
12331 - A landing pad block is a basic block which is the unwind destination
12332 of an '``invoke``' instruction.
12333 - A landing pad block must have a '``landingpad``' instruction as its
12334 first non-PHI instruction.
12335 - There can be only one '``landingpad``' instruction within the landing
12337 - A basic block that is not a landing pad block may not include a
12338 '``landingpad``' instruction.
12343 .. code-block:: llvm
12345 ;; A landing pad which can catch an integer.
12346 %res = landingpad { ptr, i32 }
12348 ;; A landing pad that is a cleanup.
12349 %res = landingpad { ptr, i32 }
12351 ;; A landing pad which can catch an integer and can only throw a double.
12352 %res = landingpad { ptr, i32 }
12354 filter [1 x ptr] [ptr @_ZTId]
12358 '``catchpad``' Instruction
12359 ^^^^^^^^^^^^^^^^^^^^^^^^^^
12366 <resultval> = catchpad within <catchswitch> [<args>*]
12371 The '``catchpad``' instruction is used by `LLVM's exception handling
12372 system <ExceptionHandling.html#overview>`_ to specify that a basic block
12373 begins a catch handler --- one where a personality routine attempts to transfer
12374 control to catch an exception.
12379 The ``catchswitch`` operand must always be a token produced by a
12380 :ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This
12381 ensures that each ``catchpad`` has exactly one predecessor block, and it always
12382 terminates in a ``catchswitch``.
12384 The ``args`` correspond to whatever information the personality routine
12385 requires to know if this is an appropriate handler for the exception. Control
12386 will transfer to the ``catchpad`` if this is the first appropriate handler for
12389 The ``resultval`` has the type :ref:`token <t_token>` and is used to match the
12390 ``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH
12396 When the call stack is being unwound due to an exception being thrown, the
12397 exception is compared against the ``args``. If it doesn't match, control will
12398 not reach the ``catchpad`` instruction. The representation of ``args`` is
12399 entirely target and personality function-specific.
12401 Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad``
12402 instruction must be the first non-phi of its parent basic block.
12404 The meaning of the tokens produced and consumed by ``catchpad`` and other "pad"
12405 instructions is described in the
12406 `Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_.
12408 When a ``catchpad`` has been "entered" but not yet "exited" (as
12409 described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
12410 it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
12411 that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
12416 .. code-block:: text
12419 %cs = catchswitch within none [label %handler0] unwind to caller
12420 ;; A catch block which can catch an integer.
12422 %tok = catchpad within %cs [ptr @_ZTIi]
12426 '``cleanuppad``' Instruction
12427 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12434 <resultval> = cleanuppad within <parent> [<args>*]
12439 The '``cleanuppad``' instruction is used by `LLVM's exception handling
12440 system <ExceptionHandling.html#overview>`_ to specify that a basic block
12441 is a cleanup block --- one where a personality routine attempts to
12442 transfer control to run cleanup actions.
12443 The ``args`` correspond to whatever additional
12444 information the :ref:`personality function <personalityfn>` requires to
12445 execute the cleanup.
12446 The ``resultval`` has the type :ref:`token <t_token>` and is used to
12447 match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`.
12448 The ``parent`` argument is the token of the funclet that contains the
12449 ``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet,
12450 this operand may be the token ``none``.
12455 The instruction takes a list of arbitrary values which are interpreted
12456 by the :ref:`personality function <personalityfn>`.
12461 When the call stack is being unwound due to an exception being thrown,
12462 the :ref:`personality function <personalityfn>` transfers control to the
12463 ``cleanuppad`` with the aid of the personality-specific arguments.
12464 As with calling conventions, how the personality function results are
12465 represented in LLVM IR is target specific.
12467 The ``cleanuppad`` instruction has several restrictions:
12469 - A cleanup block is a basic block which is the unwind destination of
12470 an exceptional instruction.
12471 - A cleanup block must have a '``cleanuppad``' instruction as its
12472 first non-PHI instruction.
12473 - There can be only one '``cleanuppad``' instruction within the
12475 - A basic block that is not a cleanup block may not include a
12476 '``cleanuppad``' instruction.
12478 When a ``cleanuppad`` has been "entered" but not yet "exited" (as
12479 described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
12480 it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
12481 that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
12486 .. code-block:: text
12488 %tok = cleanuppad within %cs []
12492 Intrinsic Functions
12493 ===================
12495 LLVM supports the notion of an "intrinsic function". These functions
12496 have well known names and semantics and are required to follow certain
12497 restrictions. Overall, these intrinsics represent an extension mechanism
12498 for the LLVM language that does not require changing all of the
12499 transformations in LLVM when adding to the language (or the bitcode
12500 reader/writer, the parser, etc...).
12502 Intrinsic function names must all start with an "``llvm.``" prefix. This
12503 prefix is reserved in LLVM for intrinsic names; thus, function names may
12504 not begin with this prefix. Intrinsic functions must always be external
12505 functions: you cannot define the body of intrinsic functions. Intrinsic
12506 functions may only be used in call or invoke instructions: it is illegal
12507 to take the address of an intrinsic function. Additionally, because
12508 intrinsic functions are part of the LLVM language, it is required if any
12509 are added that they be documented here.
12511 Some intrinsic functions can be overloaded, i.e., the intrinsic
12512 represents a family of functions that perform the same operation but on
12513 different data types. Because LLVM can represent over 8 million
12514 different integer types, overloading is used commonly to allow an
12515 intrinsic function to operate on any integer type. One or more of the
12516 argument types or the result type can be overloaded to accept any
12517 integer type. Argument types may also be defined as exactly matching a
12518 previous argument's type or the result type. This allows an intrinsic
12519 function which accepts multiple arguments, but needs all of them to be
12520 of the same type, to only be overloaded with respect to a single
12521 argument or the result.
12523 Overloaded intrinsics will have the names of its overloaded argument
12524 types encoded into its function name, each preceded by a period. Only
12525 those types which are overloaded result in a name suffix. Arguments
12526 whose type is matched against another type do not. For example, the
12527 ``llvm.ctpop`` function can take an integer of any width and returns an
12528 integer of exactly the same integer width. This leads to a family of
12529 functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and
12530 ``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is
12531 overloaded, and only one type suffix is required. Because the argument's
12532 type is matched against the return type, it does not require its own
12535 :ref:`Unnamed types <t_opaque>` are encoded as ``s_s``. Overloaded intrinsics
12536 that depend on an unnamed type in one of its overloaded argument types get an
12537 additional ``.<number>`` suffix. This allows differentiating intrinsics with
12538 different unnamed types as arguments. (For example:
12539 ``llvm.ssa.copy.p0s_s.2(%42*)``) The number is tracked in the LLVM module and
12540 it ensures unique names in the module. While linking together two modules, it is
12541 still possible to get a name clash. In that case one of the names will be
12542 changed by getting a new number.
12544 For target developers who are defining intrinsics for back-end code
12545 generation, any intrinsic overloads based solely the distinction between
12546 integer or floating point types should not be relied upon for correct
12547 code generation. In such cases, the recommended approach for target
12548 maintainers when defining intrinsics is to create separate integer and
12549 FP intrinsics rather than rely on overloading. For example, if different
12550 codegen is required for ``llvm.target.foo(<4 x i32>)`` and
12551 ``llvm.target.foo(<4 x float>)`` then these should be split into
12552 different intrinsics.
12554 To learn how to add an intrinsic function, please see the `Extending
12555 LLVM Guide <ExtendingLLVM.html>`_.
12559 Variable Argument Handling Intrinsics
12560 -------------------------------------
12562 Variable argument support is defined in LLVM with the
12563 :ref:`va_arg <i_va_arg>` instruction and these three intrinsic
12564 functions. These functions are related to the similarly named macros
12565 defined in the ``<stdarg.h>`` header file.
12567 All of these functions operate on arguments that use a target-specific
12568 value type "``va_list``". The LLVM assembly language reference manual
12569 does not define what this type is, so all transformations should be
12570 prepared to handle these functions regardless of the type used.
12572 This example shows how the :ref:`va_arg <i_va_arg>` instruction and the
12573 variable argument handling intrinsic functions are used.
12575 .. code-block:: llvm
12577 ; This struct is different for every platform. For most platforms,
12578 ; it is merely a ptr.
12579 %struct.va_list = type { ptr }
12581 ; For Unix x86_64 platforms, va_list is the following struct:
12582 ; %struct.va_list = type { i32, i32, ptr, ptr }
12584 define i32 @test(i32 %X, ...) {
12585 ; Initialize variable argument processing
12586 %ap = alloca %struct.va_list
12587 call void @llvm.va_start(ptr %ap)
12589 ; Read a single integer argument
12590 %tmp = va_arg ptr %ap, i32
12592 ; Demonstrate usage of llvm.va_copy and llvm.va_end
12594 call void @llvm.va_copy(ptr %aq, ptr %ap)
12595 call void @llvm.va_end(ptr %aq)
12597 ; Stop processing of arguments.
12598 call void @llvm.va_end(ptr %ap)
12602 declare void @llvm.va_start(ptr)
12603 declare void @llvm.va_copy(ptr, ptr)
12604 declare void @llvm.va_end(ptr)
12608 '``llvm.va_start``' Intrinsic
12609 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12616 declare void @llvm.va_start(ptr <arglist>)
12621 The '``llvm.va_start``' intrinsic initializes ``<arglist>`` for
12622 subsequent use by ``va_arg``.
12627 The argument is a pointer to a ``va_list`` element to initialize.
12632 The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro
12633 available in C. In a target-dependent way, it initializes the
12634 ``va_list`` element to which the argument points, so that the next call
12635 to ``va_arg`` will produce the first variable argument passed to the
12636 function. Unlike the C ``va_start`` macro, this intrinsic does not need
12637 to know the last argument of the function as the compiler can figure
12640 '``llvm.va_end``' Intrinsic
12641 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12648 declare void @llvm.va_end(ptr <arglist>)
12653 The '``llvm.va_end``' intrinsic destroys ``<arglist>``, which has been
12654 initialized previously with ``llvm.va_start`` or ``llvm.va_copy``.
12659 The argument is a pointer to a ``va_list`` to destroy.
12664 The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro
12665 available in C. In a target-dependent way, it destroys the ``va_list``
12666 element to which the argument points. Calls to
12667 :ref:`llvm.va_start <int_va_start>` and
12668 :ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to
12673 '``llvm.va_copy``' Intrinsic
12674 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12681 declare void @llvm.va_copy(ptr <destarglist>, ptr <srcarglist>)
12686 The '``llvm.va_copy``' intrinsic copies the current argument position
12687 from the source argument list to the destination argument list.
12692 The first argument is a pointer to a ``va_list`` element to initialize.
12693 The second argument is a pointer to a ``va_list`` element to copy from.
12698 The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro
12699 available in C. In a target-dependent way, it copies the source
12700 ``va_list`` element into the destination ``va_list`` element. This
12701 intrinsic is necessary because the `` llvm.va_start`` intrinsic may be
12702 arbitrarily complex and require, for example, memory allocation.
12704 Accurate Garbage Collection Intrinsics
12705 --------------------------------------
12707 LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_
12708 (GC) requires the frontend to generate code containing appropriate intrinsic
12709 calls and select an appropriate GC strategy which knows how to lower these
12710 intrinsics in a manner which is appropriate for the target collector.
12712 These intrinsics allow identification of :ref:`GC roots on the
12713 stack <int_gcroot>`, as well as garbage collector implementations that
12714 require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers.
12715 Frontends for type-safe garbage collected languages should generate
12716 these intrinsics to make use of the LLVM garbage collectors. For more
12717 details, see `Garbage Collection with LLVM <GarbageCollection.html>`_.
12719 LLVM provides an second experimental set of intrinsics for describing garbage
12720 collection safepoints in compiled code. These intrinsics are an alternative
12721 to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for
12722 :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The
12723 differences in approach are covered in the `Garbage Collection with LLVM
12724 <GarbageCollection.html>`_ documentation. The intrinsics themselves are
12725 described in :doc:`Statepoints`.
12729 '``llvm.gcroot``' Intrinsic
12730 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12737 declare void @llvm.gcroot(ptr %ptrloc, ptr %metadata)
12742 The '``llvm.gcroot``' intrinsic declares the existence of a GC root to
12743 the code generator, and allows some metadata to be associated with it.
12748 The first argument specifies the address of a stack object that contains
12749 the root pointer. The second pointer (which must be either a constant or
12750 a global value address) contains the meta-data to be associated with the
12756 At runtime, a call to this intrinsic stores a null pointer into the
12757 "ptrloc" location. At compile-time, the code generator generates
12758 information to allow the runtime to find the pointer at GC safe points.
12759 The '``llvm.gcroot``' intrinsic may only be used in a function which
12760 :ref:`specifies a GC algorithm <gc>`.
12764 '``llvm.gcread``' Intrinsic
12765 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12772 declare ptr @llvm.gcread(ptr %ObjPtr, ptr %Ptr)
12777 The '``llvm.gcread``' intrinsic identifies reads of references from heap
12778 locations, allowing garbage collector implementations that require read
12784 The second argument is the address to read from, which should be an
12785 address allocated from the garbage collector. The first object is a
12786 pointer to the start of the referenced object, if needed by the language
12787 runtime (otherwise null).
12792 The '``llvm.gcread``' intrinsic has the same semantics as a load
12793 instruction, but may be replaced with substantially more complex code by
12794 the garbage collector runtime, as needed. The '``llvm.gcread``'
12795 intrinsic may only be used in a function which :ref:`specifies a GC
12800 '``llvm.gcwrite``' Intrinsic
12801 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12808 declare void @llvm.gcwrite(ptr %P1, ptr %Obj, ptr %P2)
12813 The '``llvm.gcwrite``' intrinsic identifies writes of references to heap
12814 locations, allowing garbage collector implementations that require write
12815 barriers (such as generational or reference counting collectors).
12820 The first argument is the reference to store, the second is the start of
12821 the object to store it to, and the third is the address of the field of
12822 Obj to store to. If the runtime does not require a pointer to the
12823 object, Obj may be null.
12828 The '``llvm.gcwrite``' intrinsic has the same semantics as a store
12829 instruction, but may be replaced with substantially more complex code by
12830 the garbage collector runtime, as needed. The '``llvm.gcwrite``'
12831 intrinsic may only be used in a function which :ref:`specifies a GC
12837 '``llvm.experimental.gc.statepoint``' Intrinsic
12838 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12846 @llvm.experimental.gc.statepoint(i64 <id>, i32 <num patch bytes>,
12847 ptr elementtype(func_type) <target>,
12848 i64 <#call args>, i64 <flags>,
12849 ... (call parameters),
12855 The statepoint intrinsic represents a call which is parse-able by the
12861 The 'id' operand is a constant integer that is reported as the ID
12862 field in the generated stackmap. LLVM does not interpret this
12863 parameter in any way and its meaning is up to the statepoint user to
12864 decide. Note that LLVM is free to duplicate code containing
12865 statepoint calls, and this may transform IR that had a unique 'id' per
12866 lexical call to statepoint to IR that does not.
12868 If 'num patch bytes' is non-zero then the call instruction
12869 corresponding to the statepoint is not emitted and LLVM emits 'num
12870 patch bytes' bytes of nops in its place. LLVM will emit code to
12871 prepare the function arguments and retrieve the function return value
12872 in accordance to the calling convention; the former before the nop
12873 sequence and the latter after the nop sequence. It is expected that
12874 the user will patch over the 'num patch bytes' bytes of nops with a
12875 calling sequence specific to their runtime before executing the
12876 generated machine code. There are no guarantees with respect to the
12877 alignment of the nop sequence. Unlike :doc:`StackMaps` statepoints do
12878 not have a concept of shadow bytes. Note that semantically the
12879 statepoint still represents a call or invoke to 'target', and the nop
12880 sequence after patching is expected to represent an operation
12881 equivalent to a call or invoke to 'target'.
12883 The 'target' operand is the function actually being called. The operand
12884 must have an :ref:`elementtype <attr_elementtype>` attribute specifying
12885 the function type of the target. The target can be specified as either
12886 a symbolic LLVM function, or as an arbitrary Value of pointer type. Note
12887 that the function type must match the signature of the callee and the
12888 types of the 'call parameters' arguments.
12890 The '#call args' operand is the number of arguments to the actual
12891 call. It must exactly match the number of arguments passed in the
12892 'call parameters' variable length section.
12894 The 'flags' operand is used to specify extra information about the
12895 statepoint. This is currently only used to mark certain statepoints
12896 as GC transitions. This operand is a 64-bit integer with the following
12897 layout, where bit 0 is the least significant bit:
12899 +-------+---------------------------------------------------+
12901 +=======+===================================================+
12902 | 0 | Set if the statepoint is a GC transition, cleared |
12904 +-------+---------------------------------------------------+
12905 | 1-63 | Reserved for future use; must be cleared. |
12906 +-------+---------------------------------------------------+
12908 The 'call parameters' arguments are simply the arguments which need to
12909 be passed to the call target. They will be lowered according to the
12910 specified calling convention and otherwise handled like a normal call
12911 instruction. The number of arguments must exactly match what is
12912 specified in '# call args'. The types must match the signature of
12915 The 'call parameter' attributes must be followed by two 'i64 0' constants.
12916 These were originally the length prefixes for 'gc transition parameter' and
12917 'deopt parameter' arguments, but the role of these parameter sets have been
12918 entirely replaced with the corresponding operand bundles. In a future
12919 revision, these now redundant arguments will be removed.
12924 A statepoint is assumed to read and write all memory. As a result,
12925 memory operations can not be reordered past a statepoint. It is
12926 illegal to mark a statepoint as being either 'readonly' or 'readnone'.
12928 Note that legal IR can not perform any memory operation on a 'gc
12929 pointer' argument of the statepoint in a location statically reachable
12930 from the statepoint. Instead, the explicitly relocated value (from a
12931 ``gc.relocate``) must be used.
12933 '``llvm.experimental.gc.result``' Intrinsic
12934 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12942 @llvm.experimental.gc.result(token %statepoint_token)
12947 ``gc.result`` extracts the result of the original call instruction
12948 which was replaced by the ``gc.statepoint``. The ``gc.result``
12949 intrinsic is actually a family of three intrinsics due to an
12950 implementation limitation. Other than the type of the return value,
12951 the semantics are the same.
12956 The first and only argument is the ``gc.statepoint`` which starts
12957 the safepoint sequence of which this ``gc.result`` is a part.
12958 Despite the typing of this as a generic token, *only* the value defined
12959 by a ``gc.statepoint`` is legal here.
12964 The ``gc.result`` represents the return value of the call target of
12965 the ``statepoint``. The type of the ``gc.result`` must exactly match
12966 the type of the target. If the call target returns void, there will
12967 be no ``gc.result``.
12969 A ``gc.result`` is modeled as a 'readnone' pure function. It has no
12970 side effects since it is just a projection of the return value of the
12971 previous call represented by the ``gc.statepoint``.
12973 '``llvm.experimental.gc.relocate``' Intrinsic
12974 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12981 declare <pointer type>
12982 @llvm.experimental.gc.relocate(token %statepoint_token,
12984 i32 %pointer_offset)
12989 A ``gc.relocate`` returns the potentially relocated value of a pointer
12995 The first argument is the ``gc.statepoint`` which starts the
12996 safepoint sequence of which this ``gc.relocation`` is a part.
12997 Despite the typing of this as a generic token, *only* the value defined
12998 by a ``gc.statepoint`` is legal here.
13000 The second and third arguments are both indices into operands of the
13001 corresponding statepoint's :ref:`gc-live <ob_gc_live>` operand bundle.
13003 The second argument is an index which specifies the allocation for the pointer
13004 being relocated. The associated value must be within the object with which the
13005 pointer being relocated is associated. The optimizer is free to change *which*
13006 interior derived pointer is reported, provided that it does not replace an
13007 actual base pointer with another interior derived pointer. Collectors are
13008 allowed to rely on the base pointer operand remaining an actual base pointer if
13011 The third argument is an index which specify the (potentially) derived pointer
13012 being relocated. It is legal for this index to be the same as the second
13013 argument if-and-only-if a base pointer is being relocated.
13018 The return value of ``gc.relocate`` is the potentially relocated value
13019 of the pointer specified by its arguments. It is unspecified how the
13020 value of the returned pointer relates to the argument to the
13021 ``gc.statepoint`` other than that a) it points to the same source
13022 language object with the same offset, and b) the 'based-on'
13023 relationship of the newly relocated pointers is a projection of the
13024 unrelocated pointers. In particular, the integer value of the pointer
13025 returned is unspecified.
13027 A ``gc.relocate`` is modeled as a ``readnone`` pure function. It has no
13028 side effects since it is just a way to extract information about work
13029 done during the actual call modeled by the ``gc.statepoint``.
13031 .. _gc.get.pointer.base:
13033 '``llvm.experimental.gc.get.pointer.base``' Intrinsic
13034 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13041 declare <pointer type>
13042 @llvm.experimental.gc.get.pointer.base(
13043 <pointer type> readnone nocapture %derived_ptr)
13044 nounwind willreturn memory(none)
13049 ``gc.get.pointer.base`` for a derived pointer returns its base pointer.
13054 The only argument is a pointer which is based on some object with
13055 an unknown offset from the base of said object.
13060 This intrinsic is used in the abstract machine model for GC to represent
13061 the base pointer for an arbitrary derived pointer.
13063 This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by
13064 replacing all uses of this callsite with the offset of a derived pointer from
13065 its base pointer value. The replacement is done as part of the lowering to the
13066 explicit statepoint model.
13068 The return pointer type must be the same as the type of the parameter.
13071 '``llvm.experimental.gc.get.pointer.offset``' Intrinsic
13072 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13080 @llvm.experimental.gc.get.pointer.offset(
13081 <pointer type> readnone nocapture %derived_ptr)
13082 nounwind willreturn memory(none)
13087 ``gc.get.pointer.offset`` for a derived pointer returns the offset from its
13093 The only argument is a pointer which is based on some object with
13094 an unknown offset from the base of said object.
13099 This intrinsic is used in the abstract machine model for GC to represent
13100 the offset of an arbitrary derived pointer from its base pointer.
13102 This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by
13103 replacing all uses of this callsite with the offset of a derived pointer from
13104 its base pointer value. The replacement is done as part of the lowering to the
13105 explicit statepoint model.
13107 Basically this call calculates difference between the derived pointer and its
13108 base pointer (see :ref:`gc.get.pointer.base`) both ptrtoint casted. But
13109 this cast done outside the :ref:`RewriteStatepointsForGC` pass could result
13110 in the pointers lost for further lowering from the abstract model to the
13111 explicit physical one.
13113 Code Generator Intrinsics
13114 -------------------------
13116 These intrinsics are provided by LLVM to expose special features that
13117 may only be implemented with code generator support.
13119 '``llvm.returnaddress``' Intrinsic
13120 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13127 declare ptr @llvm.returnaddress(i32 <level>)
13132 The '``llvm.returnaddress``' intrinsic attempts to compute a
13133 target-specific value indicating the return address of the current
13134 function or one of its callers.
13139 The argument to this intrinsic indicates which function to return the
13140 address for. Zero indicates the calling function, one indicates its
13141 caller, etc. The argument is **required** to be a constant integer
13147 The '``llvm.returnaddress``' intrinsic either returns a pointer
13148 indicating the return address of the specified call frame, or zero if it
13149 cannot be identified. The value returned by this intrinsic is likely to
13150 be incorrect or 0 for arguments other than zero, so it should only be
13151 used for debugging purposes.
13153 Note that calling this intrinsic does not prevent function inlining or
13154 other aggressive transformations, so the value returned may not be that
13155 of the obvious source-language caller.
13157 '``llvm.addressofreturnaddress``' Intrinsic
13158 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13165 declare ptr @llvm.addressofreturnaddress()
13170 The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific
13171 pointer to the place in the stack frame where the return address of the
13172 current function is stored.
13177 Note that calling this intrinsic does not prevent function inlining or
13178 other aggressive transformations, so the value returned may not be that
13179 of the obvious source-language caller.
13181 This intrinsic is only implemented for x86 and aarch64.
13183 '``llvm.sponentry``' Intrinsic
13184 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13191 declare ptr @llvm.sponentry()
13196 The '``llvm.sponentry``' intrinsic returns the stack pointer value at
13197 the entry of the current function calling this intrinsic.
13202 Note this intrinsic is only verified on AArch64 and ARM.
13204 '``llvm.frameaddress``' Intrinsic
13205 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13212 declare ptr @llvm.frameaddress(i32 <level>)
13217 The '``llvm.frameaddress``' intrinsic attempts to return the
13218 target-specific frame pointer value for the specified stack frame.
13223 The argument to this intrinsic indicates which function to return the
13224 frame pointer for. Zero indicates the calling function, one indicates
13225 its caller, etc. The argument is **required** to be a constant integer
13231 The '``llvm.frameaddress``' intrinsic either returns a pointer
13232 indicating the frame address of the specified call frame, or zero if it
13233 cannot be identified. The value returned by this intrinsic is likely to
13234 be incorrect or 0 for arguments other than zero, so it should only be
13235 used for debugging purposes.
13237 Note that calling this intrinsic does not prevent function inlining or
13238 other aggressive transformations, so the value returned may not be that
13239 of the obvious source-language caller.
13241 '``llvm.swift.async.context.addr``' Intrinsic
13242 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13249 declare ptr @llvm.swift.async.context.addr()
13254 The '``llvm.swift.async.context.addr``' intrinsic returns a pointer to
13255 the part of the extended frame record containing the asynchronous
13256 context of a Swift execution.
13261 If the caller has a ``swiftasync`` parameter, that argument will initially
13262 be stored at the returned address. If not, it will be initialized to null.
13264 '``llvm.localescape``' and '``llvm.localrecover``' Intrinsics
13265 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13272 declare void @llvm.localescape(...)
13273 declare ptr @llvm.localrecover(ptr %func, ptr %fp, i32 %idx)
13278 The '``llvm.localescape``' intrinsic escapes offsets of a collection of static
13279 allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a
13280 live frame pointer to recover the address of the allocation. The offset is
13281 computed during frame layout of the caller of ``llvm.localescape``.
13286 All arguments to '``llvm.localescape``' must be pointers to static allocas or
13287 casts of static allocas. Each function can only call '``llvm.localescape``'
13288 once, and it can only do so from the entry block.
13290 The ``func`` argument to '``llvm.localrecover``' must be a constant
13291 bitcasted pointer to a function defined in the current module. The code
13292 generator cannot determine the frame allocation offset of functions defined in
13295 The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a
13296 call frame that is currently live. The return value of '``llvm.localaddress``'
13297 is one way to produce such a value, but various runtimes also expose a suitable
13298 pointer in platform-specific ways.
13300 The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to
13301 '``llvm.localescape``' to recover. It is zero-indexed.
13306 These intrinsics allow a group of functions to share access to a set of local
13307 stack allocations of a one parent function. The parent function may call the
13308 '``llvm.localescape``' intrinsic once from the function entry block, and the
13309 child functions can use '``llvm.localrecover``' to access the escaped allocas.
13310 The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where
13311 the escaped allocas are allocated, which would break attempts to use
13312 '``llvm.localrecover``'.
13314 '``llvm.seh.try.begin``' and '``llvm.seh.try.end``' Intrinsics
13315 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13322 declare void @llvm.seh.try.begin()
13323 declare void @llvm.seh.try.end()
13328 The '``llvm.seh.try.begin``' and '``llvm.seh.try.end``' intrinsics mark
13329 the boundary of a _try region for Windows SEH Asynchrous Exception Handling.
13334 When a C-function is compiled with Windows SEH Asynchrous Exception option,
13335 -feh_asynch (aka MSVC -EHa), these two intrinsics are injected to mark _try
13336 boundary and to prevent potential exceptions from being moved across boundary.
13337 Any set of operations can then be confined to the region by reading their leaf
13338 inputs via volatile loads and writing their root outputs via volatile stores.
13340 '``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' Intrinsics
13341 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13348 declare void @llvm.seh.scope.begin()
13349 declare void @llvm.seh.scope.end()
13354 The '``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' intrinsics mark
13355 the boundary of a CPP object lifetime for Windows SEH Asynchrous Exception
13356 Handling (MSVC option -EHa).
13361 LLVM's ordinary exception-handling representation associates EH cleanups and
13362 handlers only with ``invoke``s, which normally correspond only to call sites. To
13363 support arbitrary faulting instructions, it must be possible to recover the current
13364 EH scope for any instruction. Turning every operation in LLVM that could fault
13365 into an ``invoke`` of a new, potentially-throwing intrinsic would require adding a
13366 large number of intrinsics, impede optimization of those operations, and make
13367 compilation slower by introducing many extra basic blocks. These intrinsics can
13368 be used instead to mark the region protected by a cleanup, such as for a local
13369 C++ object with a non-trivial destructor. ``llvm.seh.scope.begin`` is used to mark
13370 the start of the region; it is always called with ``invoke``, with the unwind block
13371 being the desired unwind destination for any potentially-throwing instructions
13372 within the region. `llvm.seh.scope.end` is used to mark when the scope ends
13373 and the EH cleanup is no longer required (e.g. because the destructor is being
13376 .. _int_read_register:
13377 .. _int_read_volatile_register:
13378 .. _int_write_register:
13380 '``llvm.read_register``', '``llvm.read_volatile_register``', and '``llvm.write_register``' Intrinsics
13381 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13388 declare i32 @llvm.read_register.i32(metadata)
13389 declare i64 @llvm.read_register.i64(metadata)
13390 declare i32 @llvm.read_volatile_register.i32(metadata)
13391 declare i64 @llvm.read_volatile_register.i64(metadata)
13392 declare void @llvm.write_register.i32(metadata, i32 @value)
13393 declare void @llvm.write_register.i64(metadata, i64 @value)
13399 The '``llvm.read_register``', '``llvm.read_volatile_register``', and
13400 '``llvm.write_register``' intrinsics provide access to the named register.
13401 The register must be valid on the architecture being compiled to. The type
13402 needs to be compatible with the register being read.
13407 The '``llvm.read_register``' and '``llvm.read_volatile_register``' intrinsics
13408 return the current value of the register, where possible. The
13409 '``llvm.write_register``' intrinsic sets the current value of the register,
13412 A call to '``llvm.read_volatile_register``' is assumed to have side-effects
13413 and possibly return a different value each time (e.g. for a timer register).
13415 This is useful to implement named register global variables that need
13416 to always be mapped to a specific register, as is common practice on
13417 bare-metal programs including OS kernels.
13419 The compiler doesn't check for register availability or use of the used
13420 register in surrounding code, including inline assembly. Because of that,
13421 allocatable registers are not supported.
13423 Warning: So far it only works with the stack pointer on selected
13424 architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of
13425 work is needed to support other registers and even more so, allocatable
13430 '``llvm.stacksave``' Intrinsic
13431 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13438 declare ptr @llvm.stacksave.p0()
13439 declare ptr addrspace(5) @llvm.stacksave.p5()
13444 The '``llvm.stacksave``' intrinsic is used to remember the current state
13445 of the function stack, for use with
13446 :ref:`llvm.stackrestore <int_stackrestore>`. This is useful for
13447 implementing language features like scoped automatic variable sized
13453 This intrinsic returns an opaque pointer value that can be passed to
13454 :ref:`llvm.stackrestore <int_stackrestore>`. When an
13455 ``llvm.stackrestore`` intrinsic is executed with a value saved from
13456 ``llvm.stacksave``, it effectively restores the state of the stack to
13457 the state it was in when the ``llvm.stacksave`` intrinsic executed. In
13458 practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack
13459 that were allocated after the ``llvm.stacksave`` was executed. The
13460 address space should typically be the
13461 :ref:`alloca address space <alloca_addrspace>`.
13463 .. _int_stackrestore:
13465 '``llvm.stackrestore``' Intrinsic
13466 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13473 declare void @llvm.stackrestore.p0(ptr %ptr)
13474 declare void @llvm.stackrestore.p5(ptr addrspace(5) %ptr)
13479 The '``llvm.stackrestore``' intrinsic is used to restore the state of
13480 the function stack to the state it was in when the corresponding
13481 :ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is
13482 useful for implementing language features like scoped automatic
13483 variable sized arrays in C99. The address space should typically be
13484 the :ref:`alloca address space <alloca_addrspace>`.
13489 See the description for :ref:`llvm.stacksave <int_stacksave>`.
13491 .. _int_get_dynamic_area_offset:
13493 '``llvm.get.dynamic.area.offset``' Intrinsic
13494 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13501 declare i32 @llvm.get.dynamic.area.offset.i32()
13502 declare i64 @llvm.get.dynamic.area.offset.i64()
13507 The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to
13508 get the offset from native stack pointer to the address of the most
13509 recent dynamic alloca on the caller's stack. These intrinsics are
13510 intended for use in combination with
13511 :ref:`llvm.stacksave <int_stacksave>` to get a
13512 pointer to the most recent dynamic alloca. This is useful, for example,
13513 for AddressSanitizer's stack unpoisoning routines.
13518 These intrinsics return a non-negative integer value that can be used to
13519 get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>`
13520 on the caller's stack. In particular, for targets where stack grows downwards,
13521 adding this offset to the native stack pointer would get the address of the most
13522 recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more
13523 complicated, because subtracting this value from stack pointer would get the address
13524 one past the end of the most recent dynamic alloca.
13526 Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
13527 returns just a zero, for others, such as PowerPC and PowerPC64, it returns a
13528 compile-time-known constant value.
13530 The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
13531 must match the target's default address space's (address space 0) pointer type.
13533 '``llvm.prefetch``' Intrinsic
13534 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13541 declare void @llvm.prefetch(ptr <address>, i32 <rw>, i32 <locality>, i32 <cache type>)
13546 The '``llvm.prefetch``' intrinsic is a hint to the code generator to
13547 insert a prefetch instruction if supported; otherwise, it is a noop.
13548 Prefetches have no effect on the behavior of the program but can change
13549 its performance characteristics.
13554 ``address`` is the address to be prefetched, ``rw`` is the specifier
13555 determining if the fetch should be for a read (0) or write (1), and
13556 ``locality`` is a temporal locality specifier ranging from (0) - no
13557 locality, to (3) - extremely local keep in cache. The ``cache type``
13558 specifies whether the prefetch is performed on the data (1) or
13559 instruction (0) cache. The ``rw``, ``locality`` and ``cache type``
13560 arguments must be constant integers.
13565 This intrinsic does not modify the behavior of the program. In
13566 particular, prefetches cannot trap and do not produce a value. On
13567 targets that support this intrinsic, the prefetch can provide hints to
13568 the processor cache for better performance.
13570 '``llvm.pcmarker``' Intrinsic
13571 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13578 declare void @llvm.pcmarker(i32 <id>)
13583 The '``llvm.pcmarker``' intrinsic is a method to export a Program
13584 Counter (PC) in a region of code to simulators and other tools. The
13585 method is target specific, but it is expected that the marker will use
13586 exported symbols to transmit the PC of the marker. The marker makes no
13587 guarantees that it will remain with any specific instruction after
13588 optimizations. It is possible that the presence of a marker will inhibit
13589 optimizations. The intended use is to be inserted after optimizations to
13590 allow correlations of simulation runs.
13595 ``id`` is a numerical id identifying the marker.
13600 This intrinsic does not modify the behavior of the program. Backends
13601 that do not support this intrinsic may ignore it.
13603 '``llvm.readcyclecounter``' Intrinsic
13604 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13611 declare i64 @llvm.readcyclecounter()
13616 The '``llvm.readcyclecounter``' intrinsic provides access to the cycle
13617 counter register (or similar low latency, high accuracy clocks) on those
13618 targets that support it. On X86, it should map to RDTSC. On Alpha, it
13619 should map to RPCC. As the backing counters overflow quickly (on the
13620 order of 9 seconds on alpha), this should only be used for small
13626 When directly supported, reading the cycle counter should not modify any
13627 memory. Implementations are allowed to either return an application
13628 specific value or a system wide value. On backends without support, this
13629 is lowered to a constant 0.
13631 Note that runtime support may be conditional on the privilege-level code is
13632 running at and the host platform.
13634 '``llvm.clear_cache``' Intrinsic
13635 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13642 declare void @llvm.clear_cache(ptr, ptr)
13647 The '``llvm.clear_cache``' intrinsic ensures visibility of modifications
13648 in the specified range to the execution unit of the processor. On
13649 targets with non-unified instruction and data cache, the implementation
13650 flushes the instruction cache.
13655 On platforms with coherent instruction and data caches (e.g. x86), this
13656 intrinsic is a nop. On platforms with non-coherent instruction and data
13657 cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate
13658 instructions or a system call, if cache flushing requires special
13661 The default behavior is to emit a call to ``__clear_cache`` from the run
13664 This intrinsic does *not* empty the instruction pipeline. Modifications
13665 of the current function are outside the scope of the intrinsic.
13667 '``llvm.instrprof.increment``' Intrinsic
13668 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13675 declare void @llvm.instrprof.increment(ptr <name>, i64 <hash>,
13676 i32 <num-counters>, i32 <index>)
13681 The '``llvm.instrprof.increment``' intrinsic can be emitted by a
13682 frontend for use with instrumentation based profiling. These will be
13683 lowered by the ``-instrprof`` pass to generate execution counts of a
13684 program at runtime.
13689 The first argument is a pointer to a global variable containing the
13690 name of the entity being instrumented. This should generally be the
13691 (mangled) function name for a set of counters.
13693 The second argument is a hash value that can be used by the consumer
13694 of the profile data to detect changes to the instrumented source, and
13695 the third is the number of counters associated with ``name``. It is an
13696 error if ``hash`` or ``num-counters`` differ between two instances of
13697 ``instrprof.increment`` that refer to the same name.
13699 The last argument refers to which of the counters for ``name`` should
13700 be incremented. It should be a value between 0 and ``num-counters``.
13705 This intrinsic represents an increment of a profiling counter. It will
13706 cause the ``-instrprof`` pass to generate the appropriate data
13707 structures and the code to increment the appropriate value, in a
13708 format that can be written out by a compiler runtime and consumed via
13709 the ``llvm-profdata`` tool.
13711 '``llvm.instrprof.increment.step``' Intrinsic
13712 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13719 declare void @llvm.instrprof.increment.step(ptr <name>, i64 <hash>,
13720 i32 <num-counters>,
13721 i32 <index>, i64 <step>)
13726 The '``llvm.instrprof.increment.step``' intrinsic is an extension to
13727 the '``llvm.instrprof.increment``' intrinsic with an additional fifth
13728 argument to specify the step of the increment.
13732 The first four arguments are the same as '``llvm.instrprof.increment``'
13735 The last argument specifies the value of the increment of the counter variable.
13739 See description of '``llvm.instrprof.increment``' intrinsic.
13741 '``llvm.instrprof.timestamp``' Intrinsic
13742 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13749 declare void @llvm.instrprof.timestamp(i8* <name>, i64 <hash>,
13750 i32 <num-counters>, i32 <index>)
13755 The '``llvm.instrprof.timestamp``' intrinsic is used to implement temporal
13760 The arguments are the same as '``llvm.instrprof.increment``'. The ``index`` is
13761 expected to always be zero.
13765 Similar to the '``llvm.instrprof.increment``' intrinsic, but it stores a
13766 timestamp representing when this function was executed for the first time.
13768 '``llvm.instrprof.cover``' Intrinsic
13769 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13776 declare void @llvm.instrprof.cover(ptr <name>, i64 <hash>,
13777 i32 <num-counters>, i32 <index>)
13782 The '``llvm.instrprof.cover``' intrinsic is used to implement coverage
13787 The arguments are the same as the first four arguments of
13788 '``llvm.instrprof.increment``'.
13792 Similar to the '``llvm.instrprof.increment``' intrinsic, but it stores zero to
13793 the profiling variable to signify that the function has been covered. We store
13794 zero because this is more efficient on some targets.
13796 '``llvm.instrprof.value.profile``' Intrinsic
13797 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13804 declare void @llvm.instrprof.value.profile(ptr <name>, i64 <hash>,
13805 i64 <value>, i32 <value_kind>,
13811 The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a
13812 frontend for use with instrumentation based profiling. This will be
13813 lowered by the ``-instrprof`` pass to find out the target values,
13814 instrumented expressions take in a program at runtime.
13819 The first argument is a pointer to a global variable containing the
13820 name of the entity being instrumented. ``name`` should generally be the
13821 (mangled) function name for a set of counters.
13823 The second argument is a hash value that can be used by the consumer
13824 of the profile data to detect changes to the instrumented source. It
13825 is an error if ``hash`` differs between two instances of
13826 ``llvm.instrprof.*`` that refer to the same name.
13828 The third argument is the value of the expression being profiled. The profiled
13829 expression's value should be representable as an unsigned 64-bit value. The
13830 fourth argument represents the kind of value profiling that is being done. The
13831 supported value profiling kinds are enumerated through the
13832 ``InstrProfValueKind`` type declared in the
13833 ``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the
13834 index of the instrumented expression within ``name``. It should be >= 0.
13839 This intrinsic represents the point where a call to a runtime routine
13840 should be inserted for value profiling of target expressions. ``-instrprof``
13841 pass will generate the appropriate data structures and replace the
13842 ``llvm.instrprof.value.profile`` intrinsic with the call to the profile
13843 runtime library with proper arguments.
13845 '``llvm.thread.pointer``' Intrinsic
13846 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13853 declare ptr @llvm.thread.pointer()
13858 The '``llvm.thread.pointer``' intrinsic returns the value of the thread
13864 The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area
13865 for the current thread. The exact semantics of this value are target
13866 specific: it may point to the start of TLS area, to the end, or somewhere
13867 in the middle. Depending on the target, this intrinsic may read a register,
13868 call a helper function, read from an alternate memory space, or perform
13869 other operations necessary to locate the TLS area. Not all targets support
13872 '``llvm.call.preallocated.setup``' Intrinsic
13873 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13880 declare token @llvm.call.preallocated.setup(i32 %num_args)
13885 The '``llvm.call.preallocated.setup``' intrinsic returns a token which can
13886 be used with a call's ``"preallocated"`` operand bundle to indicate that
13887 certain arguments are allocated and initialized before the call.
13892 The '``llvm.call.preallocated.setup``' intrinsic returns a token which is
13893 associated with at most one call. The token can be passed to
13894 '``@llvm.call.preallocated.arg``' to get a pointer to get that
13895 corresponding argument. The token must be the parameter to a
13896 ``"preallocated"`` operand bundle for the corresponding call.
13898 Nested calls to '``llvm.call.preallocated.setup``' are allowed, but must
13899 be properly nested. e.g.
13901 :: code-block:: llvm
13903 %t1 = call token @llvm.call.preallocated.setup(i32 0)
13904 %t2 = call token @llvm.call.preallocated.setup(i32 0)
13905 call void foo() ["preallocated"(token %t2)]
13906 call void foo() ["preallocated"(token %t1)]
13908 is allowed, but not
13910 :: code-block:: llvm
13912 %t1 = call token @llvm.call.preallocated.setup(i32 0)
13913 %t2 = call token @llvm.call.preallocated.setup(i32 0)
13914 call void foo() ["preallocated"(token %t1)]
13915 call void foo() ["preallocated"(token %t2)]
13917 .. _int_call_preallocated_arg:
13919 '``llvm.call.preallocated.arg``' Intrinsic
13920 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13927 declare ptr @llvm.call.preallocated.arg(token %setup_token, i32 %arg_index)
13932 The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the
13933 corresponding preallocated argument for the preallocated call.
13938 The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the
13939 ``%arg_index``th argument with the ``preallocated`` attribute for
13940 the call associated with the ``%setup_token``, which must be from
13941 '``llvm.call.preallocated.setup``'.
13943 A call to '``llvm.call.preallocated.arg``' must have a call site
13944 ``preallocated`` attribute. The type of the ``preallocated`` attribute must
13945 match the type used by the ``preallocated`` attribute of the corresponding
13946 argument at the preallocated call. The type is used in the case that an
13947 ``llvm.call.preallocated.setup`` does not have a corresponding call (e.g. due
13948 to DCE), where otherwise we cannot know how large the arguments are.
13950 It is undefined behavior if this is called with a token from an
13951 '``llvm.call.preallocated.setup``' if another
13952 '``llvm.call.preallocated.setup``' has already been called or if the
13953 preallocated call corresponding to the '``llvm.call.preallocated.setup``'
13954 has already been called.
13956 .. _int_call_preallocated_teardown:
13958 '``llvm.call.preallocated.teardown``' Intrinsic
13959 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13966 declare ptr @llvm.call.preallocated.teardown(token %setup_token)
13971 The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack
13972 created by a '``llvm.call.preallocated.setup``'.
13977 The token argument must be a '``llvm.call.preallocated.setup``'.
13979 The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack
13980 allocated by the corresponding '``llvm.call.preallocated.setup``'. Exactly
13981 one of this or the preallocated call must be called to prevent stack leaks.
13982 It is undefined behavior to call both a '``llvm.call.preallocated.teardown``'
13983 and the preallocated call for a given '``llvm.call.preallocated.setup``'.
13985 For example, if the stack is allocated for a preallocated call by a
13986 '``llvm.call.preallocated.setup``', then an initializer function called on an
13987 allocated argument throws an exception, there should be a
13988 '``llvm.call.preallocated.teardown``' in the exception handler to prevent
13991 Following the nesting rules in '``llvm.call.preallocated.setup``', nested
13992 calls to '``llvm.call.preallocated.setup``' and
13993 '``llvm.call.preallocated.teardown``' are allowed but must be properly
13999 .. code-block:: llvm
14001 %cs = call token @llvm.call.preallocated.setup(i32 1)
14002 %x = call ptr @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32)
14003 invoke void @constructor(ptr %x) to label %conta unwind label %contb
14005 call void @foo1(ptr preallocated(i32) %x) ["preallocated"(token %cs)]
14008 %s = catchswitch within none [label %catch] unwind to caller
14010 %p = catchpad within %s []
14011 call void @llvm.call.preallocated.teardown(token %cs)
14014 Standard C/C++ Library Intrinsics
14015 ---------------------------------
14017 LLVM provides intrinsics for a few important standard C/C++ library
14018 functions. These intrinsics allow source-language front-ends to pass
14019 information about the alignment of the pointer arguments to the code
14020 generator, providing opportunity for more efficient code generation.
14024 '``llvm.abs.*``' Intrinsic
14025 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14030 This is an overloaded intrinsic. You can use ``llvm.abs`` on any
14031 integer bit width or any vector of integer elements.
14035 declare i32 @llvm.abs.i32(i32 <src>, i1 <is_int_min_poison>)
14036 declare <4 x i32> @llvm.abs.v4i32(<4 x i32> <src>, i1 <is_int_min_poison>)
14041 The '``llvm.abs``' family of intrinsic functions returns the absolute value
14047 The first argument is the value for which the absolute value is to be returned.
14048 This argument may be of any integer type or a vector with integer element type.
14049 The return type must match the first argument type.
14051 The second argument must be a constant and is a flag to indicate whether the
14052 result value of the '``llvm.abs``' intrinsic is a
14053 :ref:`poison value <poisonvalues>` if the argument is statically or dynamically
14054 an ``INT_MIN`` value.
14059 The '``llvm.abs``' intrinsic returns the magnitude (always positive) of the
14060 argument or each element of a vector argument.". If the argument is ``INT_MIN``,
14061 then the result is also ``INT_MIN`` if ``is_int_min_poison == 0`` and
14062 ``poison`` otherwise.
14067 '``llvm.smax.*``' Intrinsic
14068 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14073 This is an overloaded intrinsic. You can use ``@llvm.smax`` on any
14074 integer bit width or any vector of integer elements.
14078 declare i32 @llvm.smax.i32(i32 %a, i32 %b)
14079 declare <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> %b)
14084 Return the larger of ``%a`` and ``%b`` comparing the values as signed integers.
14085 Vector intrinsics operate on a per-element basis. The larger element of ``%a``
14086 and ``%b`` at a given index is returned for that index.
14091 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
14092 integer element type. The argument types must match each other, and the return
14093 type must match the argument type.
14098 '``llvm.smin.*``' Intrinsic
14099 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14104 This is an overloaded intrinsic. You can use ``@llvm.smin`` on any
14105 integer bit width or any vector of integer elements.
14109 declare i32 @llvm.smin.i32(i32 %a, i32 %b)
14110 declare <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> %b)
14115 Return the smaller of ``%a`` and ``%b`` comparing the values as signed integers.
14116 Vector intrinsics operate on a per-element basis. The smaller element of ``%a``
14117 and ``%b`` at a given index is returned for that index.
14122 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
14123 integer element type. The argument types must match each other, and the return
14124 type must match the argument type.
14129 '``llvm.umax.*``' Intrinsic
14130 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14135 This is an overloaded intrinsic. You can use ``@llvm.umax`` on any
14136 integer bit width or any vector of integer elements.
14140 declare i32 @llvm.umax.i32(i32 %a, i32 %b)
14141 declare <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> %b)
14146 Return the larger of ``%a`` and ``%b`` comparing the values as unsigned
14147 integers. Vector intrinsics operate on a per-element basis. The larger element
14148 of ``%a`` and ``%b`` at a given index is returned for that index.
14153 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
14154 integer element type. The argument types must match each other, and the return
14155 type must match the argument type.
14160 '``llvm.umin.*``' Intrinsic
14161 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14166 This is an overloaded intrinsic. You can use ``@llvm.umin`` on any
14167 integer bit width or any vector of integer elements.
14171 declare i32 @llvm.umin.i32(i32 %a, i32 %b)
14172 declare <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> %b)
14177 Return the smaller of ``%a`` and ``%b`` comparing the values as unsigned
14178 integers. Vector intrinsics operate on a per-element basis. The smaller element
14179 of ``%a`` and ``%b`` at a given index is returned for that index.
14184 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
14185 integer element type. The argument types must match each other, and the return
14186 type must match the argument type.
14191 '``llvm.memcpy``' Intrinsic
14192 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14197 This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any
14198 integer bit width and for different address spaces. Not all targets
14199 support all bit widths however.
14203 declare void @llvm.memcpy.p0.p0.i32(ptr <dest>, ptr <src>,
14204 i32 <len>, i1 <isvolatile>)
14205 declare void @llvm.memcpy.p0.p0.i64(ptr <dest>, ptr <src>,
14206 i64 <len>, i1 <isvolatile>)
14211 The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
14212 source location to the destination location.
14214 Note that, unlike the standard libc function, the ``llvm.memcpy.*``
14215 intrinsics do not return a value, takes extra isvolatile
14216 arguments and the pointers can be in specified address spaces.
14221 The first argument is a pointer to the destination, the second is a
14222 pointer to the source. The third argument is an integer argument
14223 specifying the number of bytes to copy, and the fourth is a
14224 boolean indicating a volatile access.
14226 The :ref:`align <attr_align>` parameter attribute can be provided
14227 for the first and second arguments.
14229 If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is
14230 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
14231 very cleanly specified and it is unwise to depend on it.
14236 The '``llvm.memcpy.*``' intrinsics copy a block of memory from the source
14237 location to the destination location, which must either be equal or
14238 non-overlapping. It copies "len" bytes of memory over. If the argument is known
14239 to be aligned to some boundary, this can be specified as an attribute on the
14242 If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
14244 If ``<len>`` is not a well-defined value, the behavior is undefined.
14245 If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined,
14246 otherwise the behavior is undefined.
14248 .. _int_memcpy_inline:
14250 '``llvm.memcpy.inline``' Intrinsic
14251 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14256 This is an overloaded intrinsic. You can use ``llvm.memcpy.inline`` on any
14257 integer bit width and for different address spaces. Not all targets
14258 support all bit widths however.
14262 declare void @llvm.memcpy.inline.p0.p0.i32(ptr <dest>, ptr <src>,
14263 i32 <len>, i1 <isvolatile>)
14264 declare void @llvm.memcpy.inline.p0.p0.i64(ptr <dest>, ptr <src>,
14265 i64 <len>, i1 <isvolatile>)
14270 The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the
14271 source location to the destination location and guarantees that no external
14272 functions are called.
14274 Note that, unlike the standard libc function, the ``llvm.memcpy.inline.*``
14275 intrinsics do not return a value, takes extra isvolatile
14276 arguments and the pointers can be in specified address spaces.
14281 The first argument is a pointer to the destination, the second is a
14282 pointer to the source. The third argument is a constant integer argument
14283 specifying the number of bytes to copy, and the fourth is a
14284 boolean indicating a volatile access.
14286 The :ref:`align <attr_align>` parameter attribute can be provided
14287 for the first and second arguments.
14289 If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy.inline`` call is
14290 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
14291 very cleanly specified and it is unwise to depend on it.
14296 The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the
14297 source location to the destination location, which are not allowed to
14298 overlap. It copies "len" bytes of memory over. If the argument is known
14299 to be aligned to some boundary, this can be specified as an attribute on
14301 The behavior of '``llvm.memcpy.inline.*``' is equivalent to the behavior of
14302 '``llvm.memcpy.*``', but the generated code is guaranteed not to call any
14303 external functions.
14307 '``llvm.memmove``' Intrinsic
14308 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14313 This is an overloaded intrinsic. You can use llvm.memmove on any integer
14314 bit width and for different address space. Not all targets support all
14315 bit widths however.
14319 declare void @llvm.memmove.p0.p0.i32(ptr <dest>, ptr <src>,
14320 i32 <len>, i1 <isvolatile>)
14321 declare void @llvm.memmove.p0.p0.i64(ptr <dest>, ptr <src>,
14322 i64 <len>, i1 <isvolatile>)
14327 The '``llvm.memmove.*``' intrinsics move a block of memory from the
14328 source location to the destination location. It is similar to the
14329 '``llvm.memcpy``' intrinsic but allows the two memory locations to
14332 Note that, unlike the standard libc function, the ``llvm.memmove.*``
14333 intrinsics do not return a value, takes an extra isvolatile
14334 argument and the pointers can be in specified address spaces.
14339 The first argument is a pointer to the destination, the second is a
14340 pointer to the source. The third argument is an integer argument
14341 specifying the number of bytes to copy, and the fourth is a
14342 boolean indicating a volatile access.
14344 The :ref:`align <attr_align>` parameter attribute can be provided
14345 for the first and second arguments.
14347 If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call
14348 is a :ref:`volatile operation <volatile>`. The detailed access behavior is
14349 not very cleanly specified and it is unwise to depend on it.
14354 The '``llvm.memmove.*``' intrinsics copy a block of memory from the
14355 source location to the destination location, which may overlap. It
14356 copies "len" bytes of memory over. If the argument is known to be
14357 aligned to some boundary, this can be specified as an attribute on
14360 If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
14362 If ``<len>`` is not a well-defined value, the behavior is undefined.
14363 If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined,
14364 otherwise the behavior is undefined.
14368 '``llvm.memset.*``' Intrinsics
14369 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14374 This is an overloaded intrinsic. You can use llvm.memset on any integer
14375 bit width and for different address spaces. However, not all targets
14376 support all bit widths.
14380 declare void @llvm.memset.p0.i32(ptr <dest>, i8 <val>,
14381 i32 <len>, i1 <isvolatile>)
14382 declare void @llvm.memset.p0.i64(ptr <dest>, i8 <val>,
14383 i64 <len>, i1 <isvolatile>)
14388 The '``llvm.memset.*``' intrinsics fill a block of memory with a
14389 particular byte value.
14391 Note that, unlike the standard libc function, the ``llvm.memset``
14392 intrinsic does not return a value and takes an extra volatile
14393 argument. Also, the destination can be in an arbitrary address space.
14398 The first argument is a pointer to the destination to fill, the second
14399 is the byte value with which to fill it, the third argument is an
14400 integer argument specifying the number of bytes to fill, and the fourth
14401 is a boolean indicating a volatile access.
14403 The :ref:`align <attr_align>` parameter attribute can be provided
14404 for the first arguments.
14406 If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is
14407 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
14408 very cleanly specified and it is unwise to depend on it.
14413 The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting
14414 at the destination location. If the argument is known to be
14415 aligned to some boundary, this can be specified as an attribute on
14418 If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
14420 If ``<len>`` is not a well-defined value, the behavior is undefined.
14421 If ``<len>`` is not zero, ``<dest>`` should be well-defined, otherwise the
14422 behavior is undefined.
14424 .. _int_memset_inline:
14426 '``llvm.memset.inline``' Intrinsic
14427 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14432 This is an overloaded intrinsic. You can use ``llvm.memset.inline`` on any
14433 integer bit width and for different address spaces. Not all targets
14434 support all bit widths however.
14438 declare void @llvm.memset.inline.p0.p0i8.i32(ptr <dest>, i8 <val>,
14439 i32 <len>, i1 <isvolatile>)
14440 declare void @llvm.memset.inline.p0.p0.i64(ptr <dest>, i8 <val>,
14441 i64 <len>, i1 <isvolatile>)
14446 The '``llvm.memset.inline.*``' intrinsics fill a block of memory with a
14447 particular byte value and guarantees that no external functions are called.
14449 Note that, unlike the standard libc function, the ``llvm.memset.inline.*``
14450 intrinsics do not return a value, take an extra isvolatile argument and the
14451 pointer can be in specified address spaces.
14456 The first argument is a pointer to the destination to fill, the second
14457 is the byte value with which to fill it, the third argument is a constant
14458 integer argument specifying the number of bytes to fill, and the fourth
14459 is a boolean indicating a volatile access.
14461 The :ref:`align <attr_align>` parameter attribute can be provided
14462 for the first argument.
14464 If the ``isvolatile`` parameter is ``true``, the ``llvm.memset.inline`` call is
14465 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
14466 very cleanly specified and it is unwise to depend on it.
14471 The '``llvm.memset.inline.*``' intrinsics fill "len" bytes of memory starting
14472 at the destination location. If the argument is known to be
14473 aligned to some boundary, this can be specified as an attribute on
14476 ``len`` must be a constant expression.
14477 If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
14479 If ``<len>`` is not a well-defined value, the behavior is undefined.
14480 If ``<len>`` is not zero, ``<dest>`` should be well-defined, otherwise the
14481 behavior is undefined.
14483 The behavior of '``llvm.memset.inline.*``' is equivalent to the behavior of
14484 '``llvm.memset.*``', but the generated code is guaranteed not to call any
14485 external functions.
14489 '``llvm.sqrt.*``' Intrinsic
14490 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14495 This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any
14496 floating-point or vector of floating-point type. Not all targets support
14501 declare float @llvm.sqrt.f32(float %Val)
14502 declare double @llvm.sqrt.f64(double %Val)
14503 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
14504 declare fp128 @llvm.sqrt.f128(fp128 %Val)
14505 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
14510 The '``llvm.sqrt``' intrinsics return the square root of the specified value.
14515 The argument and return value are floating-point numbers of the same type.
14520 Return the same value as a corresponding libm '``sqrt``' function but without
14521 trapping or setting ``errno``. For types specified by IEEE-754, the result
14522 matches a conforming libm implementation.
14524 When specified with the fast-math-flag 'afn', the result may be approximated
14525 using a less accurate calculation.
14527 '``llvm.powi.*``' Intrinsic
14528 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14533 This is an overloaded intrinsic. You can use ``llvm.powi`` on any
14534 floating-point or vector of floating-point type. Not all targets support
14537 Generally, the only supported type for the exponent is the one matching
14538 with the C type ``int``.
14542 declare float @llvm.powi.f32.i32(float %Val, i32 %power)
14543 declare double @llvm.powi.f64.i16(double %Val, i16 %power)
14544 declare x86_fp80 @llvm.powi.f80.i32(x86_fp80 %Val, i32 %power)
14545 declare fp128 @llvm.powi.f128.i32(fp128 %Val, i32 %power)
14546 declare ppc_fp128 @llvm.powi.ppcf128.i32(ppc_fp128 %Val, i32 %power)
14551 The '``llvm.powi.*``' intrinsics return the first operand raised to the
14552 specified (positive or negative) power. The order of evaluation of
14553 multiplications is not defined. When a vector of floating-point type is
14554 used, the second argument remains a scalar integer value.
14559 The second argument is an integer power, and the first is a value to
14560 raise to that power.
14565 This function returns the first value raised to the second power with an
14566 unspecified sequence of rounding operations.
14568 '``llvm.sin.*``' Intrinsic
14569 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14574 This is an overloaded intrinsic. You can use ``llvm.sin`` on any
14575 floating-point or vector of floating-point type. Not all targets support
14580 declare float @llvm.sin.f32(float %Val)
14581 declare double @llvm.sin.f64(double %Val)
14582 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
14583 declare fp128 @llvm.sin.f128(fp128 %Val)
14584 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
14589 The '``llvm.sin.*``' intrinsics return the sine of the operand.
14594 The argument and return value are floating-point numbers of the same type.
14599 Return the same value as a corresponding libm '``sin``' function but without
14600 trapping or setting ``errno``.
14602 When specified with the fast-math-flag 'afn', the result may be approximated
14603 using a less accurate calculation.
14605 '``llvm.cos.*``' Intrinsic
14606 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14611 This is an overloaded intrinsic. You can use ``llvm.cos`` on any
14612 floating-point or vector of floating-point type. Not all targets support
14617 declare float @llvm.cos.f32(float %Val)
14618 declare double @llvm.cos.f64(double %Val)
14619 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
14620 declare fp128 @llvm.cos.f128(fp128 %Val)
14621 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
14626 The '``llvm.cos.*``' intrinsics return the cosine of the operand.
14631 The argument and return value are floating-point numbers of the same type.
14636 Return the same value as a corresponding libm '``cos``' function but without
14637 trapping or setting ``errno``.
14639 When specified with the fast-math-flag 'afn', the result may be approximated
14640 using a less accurate calculation.
14642 '``llvm.pow.*``' Intrinsic
14643 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14648 This is an overloaded intrinsic. You can use ``llvm.pow`` on any
14649 floating-point or vector of floating-point type. Not all targets support
14654 declare float @llvm.pow.f32(float %Val, float %Power)
14655 declare double @llvm.pow.f64(double %Val, double %Power)
14656 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
14657 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
14658 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
14663 The '``llvm.pow.*``' intrinsics return the first operand raised to the
14664 specified (positive or negative) power.
14669 The arguments and return value are floating-point numbers of the same type.
14674 Return the same value as a corresponding libm '``pow``' function but without
14675 trapping or setting ``errno``.
14677 When specified with the fast-math-flag 'afn', the result may be approximated
14678 using a less accurate calculation.
14682 '``llvm.exp.*``' Intrinsic
14683 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14688 This is an overloaded intrinsic. You can use ``llvm.exp`` on any
14689 floating-point or vector of floating-point type. Not all targets support
14694 declare float @llvm.exp.f32(float %Val)
14695 declare double @llvm.exp.f64(double %Val)
14696 declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val)
14697 declare fp128 @llvm.exp.f128(fp128 %Val)
14698 declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val)
14703 The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified
14709 The argument and return value are floating-point numbers of the same type.
14714 Return the same value as a corresponding libm '``exp``' function but without
14715 trapping or setting ``errno``.
14717 When specified with the fast-math-flag 'afn', the result may be approximated
14718 using a less accurate calculation.
14722 '``llvm.exp2.*``' Intrinsic
14723 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14728 This is an overloaded intrinsic. You can use ``llvm.exp2`` on any
14729 floating-point or vector of floating-point type. Not all targets support
14734 declare float @llvm.exp2.f32(float %Val)
14735 declare double @llvm.exp2.f64(double %Val)
14736 declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val)
14737 declare fp128 @llvm.exp2.f128(fp128 %Val)
14738 declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val)
14743 The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the
14749 The argument and return value are floating-point numbers of the same type.
14754 Return the same value as a corresponding libm '``exp2``' function but without
14755 trapping or setting ``errno``.
14757 When specified with the fast-math-flag 'afn', the result may be approximated
14758 using a less accurate calculation.
14762 '``llvm.exp10.*``' Intrinsic
14763 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14768 This is an overloaded intrinsic. You can use ``llvm.exp10`` on any
14769 floating-point or vector of floating-point type. Not all targets support
14774 declare float @llvm.exp10.f32(float %Val)
14775 declare double @llvm.exp10.f64(double %Val)
14776 declare x86_fp80 @llvm.exp10.f80(x86_fp80 %Val)
14777 declare fp128 @llvm.exp10.f128(fp128 %Val)
14778 declare ppc_fp128 @llvm.exp10.ppcf128(ppc_fp128 %Val)
14783 The '``llvm.exp10.*``' intrinsics compute the base-10 exponential of the
14789 The argument and return value are floating-point numbers of the same type.
14794 Return the same value as a corresponding libm '``exp10``' function but without
14795 trapping or setting ``errno``.
14797 When specified with the fast-math-flag 'afn', the result may be approximated
14798 using a less accurate calculation.
14801 '``llvm.ldexp.*``' Intrinsic
14802 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14807 This is an overloaded intrinsic. You can use ``llvm.ldexp`` on any
14808 floating point or vector of floating point type. Not all targets support
14813 declare float @llvm.ldexp.f32.i32(float %Val, i32 %Exp)
14814 declare double @llvm.ldexp.f64.i32(double %Val, i32 %Exp)
14815 declare x86_fp80 @llvm.ldexp.f80.i32(x86_fp80 %Val, i32 %Exp)
14816 declare fp128 @llvm.ldexp.f128.i32(fp128 %Val, i32 %Exp)
14817 declare ppc_fp128 @llvm.ldexp.ppcf128.i32(ppc_fp128 %Val, i32 %Exp)
14818 declare <2 x float> @llvm.ldexp.v2f32.v2i32(<2 x float> %Val, <2 x i32> %Exp)
14823 The '``llvm.ldexp.*``' intrinsics perform the ldexp function.
14828 The first argument and the return value are :ref:`floating-point
14829 <t_floating>` or :ref:`vector <t_vector>` of floating-point values of
14830 the same type. The second argument is an integer with the same number
14836 This function multiplies the first argument by 2 raised to the second
14837 argument's power. If the first argument is NaN or infinite, the same
14838 value is returned. If the result underflows a zero with the same sign
14839 is returned. If the result overflows, the result is an infinity with
14844 '``llvm.frexp.*``' Intrinsic
14845 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14850 This is an overloaded intrinsic. You can use ``llvm.frexp`` on any
14851 floating point or vector of floating point type. Not all targets support
14856 declare { float, i32 } @llvm.frexp.f32.i32(float %Val)
14857 declare { double, i32 } @llvm.frexp.f64.i32(double %Val)
14858 declare { x86_fp80, i32 } @llvm.frexp.f80.i32(x86_fp80 %Val)
14859 declare { fp128, i32 } @llvm.frexp.f128.i32(fp128 %Val)
14860 declare { ppc_fp128, i32 } @llvm.frexp.ppcf128.i32(ppc_fp128 %Val)
14861 declare { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float> %Val)
14866 The '``llvm.frexp.*``' intrinsics perform the frexp function.
14871 The argument is a :ref:`floating-point <t_floating>` or
14872 :ref:`vector <t_vector>` of floating-point values. Returns two values
14873 in a struct. The first struct field matches the argument type, and the
14874 second field is an integer or a vector of integer values with the same
14875 number of elements as the argument.
14880 This intrinsic splits a floating point value into a normalized
14881 fractional component and integral exponent.
14883 For a non-zero argument, returns the argument multiplied by some power
14884 of two such that the absolute value of the returned value is in the
14885 range [0.5, 1.0), with the same sign as the argument. The second
14886 result is an integer such that the first result raised to the power of
14887 the second result is the input argument.
14889 If the argument is a zero, returns a zero with the same sign and a 0
14892 If the argument is a NaN, a NaN is returned and the returned exponent
14895 If the argument is an infinity, returns an infinity with the same sign
14896 and an unspecified exponent.
14900 '``llvm.log.*``' Intrinsic
14901 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14906 This is an overloaded intrinsic. You can use ``llvm.log`` on any
14907 floating-point or vector of floating-point type. Not all targets support
14912 declare float @llvm.log.f32(float %Val)
14913 declare double @llvm.log.f64(double %Val)
14914 declare x86_fp80 @llvm.log.f80(x86_fp80 %Val)
14915 declare fp128 @llvm.log.f128(fp128 %Val)
14916 declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val)
14921 The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified
14927 The argument and return value are floating-point numbers of the same type.
14932 Return the same value as a corresponding libm '``log``' function but without
14933 trapping or setting ``errno``.
14935 When specified with the fast-math-flag 'afn', the result may be approximated
14936 using a less accurate calculation.
14940 '``llvm.log10.*``' Intrinsic
14941 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14946 This is an overloaded intrinsic. You can use ``llvm.log10`` on any
14947 floating-point or vector of floating-point type. Not all targets support
14952 declare float @llvm.log10.f32(float %Val)
14953 declare double @llvm.log10.f64(double %Val)
14954 declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val)
14955 declare fp128 @llvm.log10.f128(fp128 %Val)
14956 declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val)
14961 The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the
14967 The argument and return value are floating-point numbers of the same type.
14972 Return the same value as a corresponding libm '``log10``' function but without
14973 trapping or setting ``errno``.
14975 When specified with the fast-math-flag 'afn', the result may be approximated
14976 using a less accurate calculation.
14981 '``llvm.log2.*``' Intrinsic
14982 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14987 This is an overloaded intrinsic. You can use ``llvm.log2`` on any
14988 floating-point or vector of floating-point type. Not all targets support
14993 declare float @llvm.log2.f32(float %Val)
14994 declare double @llvm.log2.f64(double %Val)
14995 declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val)
14996 declare fp128 @llvm.log2.f128(fp128 %Val)
14997 declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val)
15002 The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified
15008 The argument and return value are floating-point numbers of the same type.
15013 Return the same value as a corresponding libm '``log2``' function but without
15014 trapping or setting ``errno``.
15016 When specified with the fast-math-flag 'afn', the result may be approximated
15017 using a less accurate calculation.
15021 '``llvm.fma.*``' Intrinsic
15022 ^^^^^^^^^^^^^^^^^^^^^^^^^^
15027 This is an overloaded intrinsic. You can use ``llvm.fma`` on any
15028 floating-point or vector of floating-point type. Not all targets support
15033 declare float @llvm.fma.f32(float %a, float %b, float %c)
15034 declare double @llvm.fma.f64(double %a, double %b, double %c)
15035 declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c)
15036 declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c)
15037 declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c)
15042 The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation.
15047 The arguments and return value are floating-point numbers of the same type.
15052 Return the same value as a corresponding libm '``fma``' function but without
15053 trapping or setting ``errno``.
15055 When specified with the fast-math-flag 'afn', the result may be approximated
15056 using a less accurate calculation.
15060 '``llvm.fabs.*``' Intrinsic
15061 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15066 This is an overloaded intrinsic. You can use ``llvm.fabs`` on any
15067 floating-point or vector of floating-point type. Not all targets support
15072 declare float @llvm.fabs.f32(float %Val)
15073 declare double @llvm.fabs.f64(double %Val)
15074 declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val)
15075 declare fp128 @llvm.fabs.f128(fp128 %Val)
15076 declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
15081 The '``llvm.fabs.*``' intrinsics return the absolute value of the
15087 The argument and return value are floating-point numbers of the same
15093 This function returns the same values as the libm ``fabs`` functions
15094 would, and handles error conditions in the same way.
15098 '``llvm.minnum.*``' Intrinsic
15099 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15104 This is an overloaded intrinsic. You can use ``llvm.minnum`` on any
15105 floating-point or vector of floating-point type. Not all targets support
15110 declare float @llvm.minnum.f32(float %Val0, float %Val1)
15111 declare double @llvm.minnum.f64(double %Val0, double %Val1)
15112 declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
15113 declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1)
15114 declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
15119 The '``llvm.minnum.*``' intrinsics return the minimum of the two
15126 The arguments and return value are floating-point numbers of the same
15132 Follows the IEEE-754 semantics for minNum, except for handling of
15133 signaling NaNs. This match's the behavior of libm's fmin.
15135 If either operand is a NaN, returns the other non-NaN operand. Returns
15136 NaN only if both operands are NaN. If the operands compare equal,
15137 returns either one of the operands. For example, this means that
15138 fmin(+0.0, -0.0) returns either operand.
15140 Unlike the IEEE-754 2008 behavior, this does not distinguish between
15141 signaling and quiet NaN inputs. If a target's implementation follows
15142 the standard and returns a quiet NaN if either input is a signaling
15143 NaN, the intrinsic lowering is responsible for quieting the inputs to
15144 correctly return the non-NaN input (e.g. by using the equivalent of
15145 ``llvm.canonicalize``).
15149 '``llvm.maxnum.*``' Intrinsic
15150 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15155 This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any
15156 floating-point or vector of floating-point type. Not all targets support
15161 declare float @llvm.maxnum.f32(float %Val0, float %Val1)
15162 declare double @llvm.maxnum.f64(double %Val0, double %Val1)
15163 declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
15164 declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1)
15165 declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
15170 The '``llvm.maxnum.*``' intrinsics return the maximum of the two
15177 The arguments and return value are floating-point numbers of the same
15182 Follows the IEEE-754 semantics for maxNum except for the handling of
15183 signaling NaNs. This matches the behavior of libm's fmax.
15185 If either operand is a NaN, returns the other non-NaN operand. Returns
15186 NaN only if both operands are NaN. If the operands compare equal,
15187 returns either one of the operands. For example, this means that
15188 fmax(+0.0, -0.0) returns either -0.0 or 0.0.
15190 Unlike the IEEE-754 2008 behavior, this does not distinguish between
15191 signaling and quiet NaN inputs. If a target's implementation follows
15192 the standard and returns a quiet NaN if either input is a signaling
15193 NaN, the intrinsic lowering is responsible for quieting the inputs to
15194 correctly return the non-NaN input (e.g. by using the equivalent of
15195 ``llvm.canonicalize``).
15197 '``llvm.minimum.*``' Intrinsic
15198 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15203 This is an overloaded intrinsic. You can use ``llvm.minimum`` on any
15204 floating-point or vector of floating-point type. Not all targets support
15209 declare float @llvm.minimum.f32(float %Val0, float %Val1)
15210 declare double @llvm.minimum.f64(double %Val0, double %Val1)
15211 declare x86_fp80 @llvm.minimum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
15212 declare fp128 @llvm.minimum.f128(fp128 %Val0, fp128 %Val1)
15213 declare ppc_fp128 @llvm.minimum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
15218 The '``llvm.minimum.*``' intrinsics return the minimum of the two
15219 arguments, propagating NaNs and treating -0.0 as less than +0.0.
15225 The arguments and return value are floating-point numbers of the same
15230 If either operand is a NaN, returns NaN. Otherwise returns the lesser
15231 of the two arguments. -0.0 is considered to be less than +0.0 for this
15232 intrinsic. Note that these are the semantics specified in the draft of
15235 '``llvm.maximum.*``' Intrinsic
15236 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15241 This is an overloaded intrinsic. You can use ``llvm.maximum`` on any
15242 floating-point or vector of floating-point type. Not all targets support
15247 declare float @llvm.maximum.f32(float %Val0, float %Val1)
15248 declare double @llvm.maximum.f64(double %Val0, double %Val1)
15249 declare x86_fp80 @llvm.maximum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
15250 declare fp128 @llvm.maximum.f128(fp128 %Val0, fp128 %Val1)
15251 declare ppc_fp128 @llvm.maximum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
15256 The '``llvm.maximum.*``' intrinsics return the maximum of the two
15257 arguments, propagating NaNs and treating -0.0 as less than +0.0.
15263 The arguments and return value are floating-point numbers of the same
15268 If either operand is a NaN, returns NaN. Otherwise returns the greater
15269 of the two arguments. -0.0 is considered to be less than +0.0 for this
15270 intrinsic. Note that these are the semantics specified in the draft of
15275 '``llvm.copysign.*``' Intrinsic
15276 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15281 This is an overloaded intrinsic. You can use ``llvm.copysign`` on any
15282 floating-point or vector of floating-point type. Not all targets support
15287 declare float @llvm.copysign.f32(float %Mag, float %Sgn)
15288 declare double @llvm.copysign.f64(double %Mag, double %Sgn)
15289 declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn)
15290 declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn)
15291 declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn)
15296 The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the
15297 first operand and the sign of the second operand.
15302 The arguments and return value are floating-point numbers of the same
15308 This function returns the same values as the libm ``copysign``
15309 functions would, and handles error conditions in the same way.
15313 '``llvm.floor.*``' Intrinsic
15314 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15319 This is an overloaded intrinsic. You can use ``llvm.floor`` on any
15320 floating-point or vector of floating-point type. Not all targets support
15325 declare float @llvm.floor.f32(float %Val)
15326 declare double @llvm.floor.f64(double %Val)
15327 declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val)
15328 declare fp128 @llvm.floor.f128(fp128 %Val)
15329 declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val)
15334 The '``llvm.floor.*``' intrinsics return the floor of the operand.
15339 The argument and return value are floating-point numbers of the same
15345 This function returns the same values as the libm ``floor`` functions
15346 would, and handles error conditions in the same way.
15350 '``llvm.ceil.*``' Intrinsic
15351 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15356 This is an overloaded intrinsic. You can use ``llvm.ceil`` on any
15357 floating-point or vector of floating-point type. Not all targets support
15362 declare float @llvm.ceil.f32(float %Val)
15363 declare double @llvm.ceil.f64(double %Val)
15364 declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val)
15365 declare fp128 @llvm.ceil.f128(fp128 %Val)
15366 declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val)
15371 The '``llvm.ceil.*``' intrinsics return the ceiling of the operand.
15376 The argument and return value are floating-point numbers of the same
15382 This function returns the same values as the libm ``ceil`` functions
15383 would, and handles error conditions in the same way.
15386 .. _int_llvm_trunc:
15388 '``llvm.trunc.*``' Intrinsic
15389 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15394 This is an overloaded intrinsic. You can use ``llvm.trunc`` on any
15395 floating-point or vector of floating-point type. Not all targets support
15400 declare float @llvm.trunc.f32(float %Val)
15401 declare double @llvm.trunc.f64(double %Val)
15402 declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val)
15403 declare fp128 @llvm.trunc.f128(fp128 %Val)
15404 declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val)
15409 The '``llvm.trunc.*``' intrinsics returns the operand rounded to the
15410 nearest integer not larger in magnitude than the operand.
15415 The argument and return value are floating-point numbers of the same
15421 This function returns the same values as the libm ``trunc`` functions
15422 would, and handles error conditions in the same way.
15426 '``llvm.rint.*``' Intrinsic
15427 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15432 This is an overloaded intrinsic. You can use ``llvm.rint`` on any
15433 floating-point or vector of floating-point type. Not all targets support
15438 declare float @llvm.rint.f32(float %Val)
15439 declare double @llvm.rint.f64(double %Val)
15440 declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val)
15441 declare fp128 @llvm.rint.f128(fp128 %Val)
15442 declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val)
15447 The '``llvm.rint.*``' intrinsics returns the operand rounded to the
15448 nearest integer. It may raise an inexact floating-point exception if the
15449 operand isn't an integer.
15454 The argument and return value are floating-point numbers of the same
15460 This function returns the same values as the libm ``rint`` functions
15461 would, and handles error conditions in the same way.
15465 '``llvm.nearbyint.*``' Intrinsic
15466 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15471 This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any
15472 floating-point or vector of floating-point type. Not all targets support
15477 declare float @llvm.nearbyint.f32(float %Val)
15478 declare double @llvm.nearbyint.f64(double %Val)
15479 declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val)
15480 declare fp128 @llvm.nearbyint.f128(fp128 %Val)
15481 declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val)
15486 The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the
15492 The argument and return value are floating-point numbers of the same
15498 This function returns the same values as the libm ``nearbyint``
15499 functions would, and handles error conditions in the same way.
15503 '``llvm.round.*``' Intrinsic
15504 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15509 This is an overloaded intrinsic. You can use ``llvm.round`` on any
15510 floating-point or vector of floating-point type. Not all targets support
15515 declare float @llvm.round.f32(float %Val)
15516 declare double @llvm.round.f64(double %Val)
15517 declare x86_fp80 @llvm.round.f80(x86_fp80 %Val)
15518 declare fp128 @llvm.round.f128(fp128 %Val)
15519 declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val)
15524 The '``llvm.round.*``' intrinsics returns the operand rounded to the
15530 The argument and return value are floating-point numbers of the same
15536 This function returns the same values as the libm ``round``
15537 functions would, and handles error conditions in the same way.
15541 '``llvm.roundeven.*``' Intrinsic
15542 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15547 This is an overloaded intrinsic. You can use ``llvm.roundeven`` on any
15548 floating-point or vector of floating-point type. Not all targets support
15553 declare float @llvm.roundeven.f32(float %Val)
15554 declare double @llvm.roundeven.f64(double %Val)
15555 declare x86_fp80 @llvm.roundeven.f80(x86_fp80 %Val)
15556 declare fp128 @llvm.roundeven.f128(fp128 %Val)
15557 declare ppc_fp128 @llvm.roundeven.ppcf128(ppc_fp128 %Val)
15562 The '``llvm.roundeven.*``' intrinsics returns the operand rounded to the nearest
15563 integer in floating-point format rounding halfway cases to even (that is, to the
15564 nearest value that is an even integer).
15569 The argument and return value are floating-point numbers of the same type.
15574 This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It
15575 also behaves in the same way as C standard function ``roundeven``, except that
15576 it does not raise floating point exceptions.
15579 '``llvm.lround.*``' Intrinsic
15580 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15585 This is an overloaded intrinsic. You can use ``llvm.lround`` on any
15586 floating-point type. Not all targets support all types however.
15590 declare i32 @llvm.lround.i32.f32(float %Val)
15591 declare i32 @llvm.lround.i32.f64(double %Val)
15592 declare i32 @llvm.lround.i32.f80(float %Val)
15593 declare i32 @llvm.lround.i32.f128(double %Val)
15594 declare i32 @llvm.lround.i32.ppcf128(double %Val)
15596 declare i64 @llvm.lround.i64.f32(float %Val)
15597 declare i64 @llvm.lround.i64.f64(double %Val)
15598 declare i64 @llvm.lround.i64.f80(float %Val)
15599 declare i64 @llvm.lround.i64.f128(double %Val)
15600 declare i64 @llvm.lround.i64.ppcf128(double %Val)
15605 The '``llvm.lround.*``' intrinsics return the operand rounded to the nearest
15606 integer with ties away from zero.
15612 The argument is a floating-point number and the return value is an integer
15618 This function returns the same values as the libm ``lround`` functions
15619 would, but without setting errno. If the rounded value is too large to
15620 be stored in the result type, the return value is a non-deterministic
15621 value (equivalent to `freeze poison`).
15623 '``llvm.llround.*``' Intrinsic
15624 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15629 This is an overloaded intrinsic. You can use ``llvm.llround`` on any
15630 floating-point type. Not all targets support all types however.
15634 declare i64 @llvm.lround.i64.f32(float %Val)
15635 declare i64 @llvm.lround.i64.f64(double %Val)
15636 declare i64 @llvm.lround.i64.f80(float %Val)
15637 declare i64 @llvm.lround.i64.f128(double %Val)
15638 declare i64 @llvm.lround.i64.ppcf128(double %Val)
15643 The '``llvm.llround.*``' intrinsics return the operand rounded to the nearest
15644 integer with ties away from zero.
15649 The argument is a floating-point number and the return value is an integer
15655 This function returns the same values as the libm ``llround``
15656 functions would, but without setting errno. If the rounded value is
15657 too large to be stored in the result type, the return value is a
15658 non-deterministic value (equivalent to `freeze poison`).
15660 '``llvm.lrint.*``' Intrinsic
15661 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15666 This is an overloaded intrinsic. You can use ``llvm.lrint`` on any
15667 floating-point type. Not all targets support all types however.
15671 declare i32 @llvm.lrint.i32.f32(float %Val)
15672 declare i32 @llvm.lrint.i32.f64(double %Val)
15673 declare i32 @llvm.lrint.i32.f80(float %Val)
15674 declare i32 @llvm.lrint.i32.f128(double %Val)
15675 declare i32 @llvm.lrint.i32.ppcf128(double %Val)
15677 declare i64 @llvm.lrint.i64.f32(float %Val)
15678 declare i64 @llvm.lrint.i64.f64(double %Val)
15679 declare i64 @llvm.lrint.i64.f80(float %Val)
15680 declare i64 @llvm.lrint.i64.f128(double %Val)
15681 declare i64 @llvm.lrint.i64.ppcf128(double %Val)
15686 The '``llvm.lrint.*``' intrinsics return the operand rounded to the nearest
15693 The argument is a floating-point number and the return value is an integer
15699 This function returns the same values as the libm ``lrint`` functions
15700 would, but without setting errno. If the rounded value is too large to
15701 be stored in the result type, the return value is a non-deterministic
15702 value (equivalent to `freeze poison`).
15704 '``llvm.llrint.*``' Intrinsic
15705 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15710 This is an overloaded intrinsic. You can use ``llvm.llrint`` on any
15711 floating-point type. Not all targets support all types however.
15715 declare i64 @llvm.llrint.i64.f32(float %Val)
15716 declare i64 @llvm.llrint.i64.f64(double %Val)
15717 declare i64 @llvm.llrint.i64.f80(float %Val)
15718 declare i64 @llvm.llrint.i64.f128(double %Val)
15719 declare i64 @llvm.llrint.i64.ppcf128(double %Val)
15724 The '``llvm.llrint.*``' intrinsics return the operand rounded to the nearest
15730 The argument is a floating-point number and the return value is an integer
15736 This function returns the same values as the libm ``llrint`` functions
15737 would, but without setting errno. If the rounded value is too large to
15738 be stored in the result type, the return value is a non-deterministic
15739 value (equivalent to `freeze poison`).
15741 Bit Manipulation Intrinsics
15742 ---------------------------
15744 LLVM provides intrinsics for a few important bit manipulation
15745 operations. These allow efficient code generation for some algorithms.
15747 .. _int_bitreverse:
15749 '``llvm.bitreverse.*``' Intrinsics
15750 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15755 This is an overloaded intrinsic function. You can use bitreverse on any
15760 declare i16 @llvm.bitreverse.i16(i16 <id>)
15761 declare i32 @llvm.bitreverse.i32(i32 <id>)
15762 declare i64 @llvm.bitreverse.i64(i64 <id>)
15763 declare <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> <id>)
15768 The '``llvm.bitreverse``' family of intrinsics is used to reverse the
15769 bitpattern of an integer value or vector of integer values; for example
15770 ``0b10110110`` becomes ``0b01101101``.
15775 The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit
15776 ``M`` in the input moved to bit ``N-M-1`` in the output. The vector
15777 intrinsics, such as ``llvm.bitreverse.v4i32``, operate on a per-element
15778 basis and the element order is not affected.
15782 '``llvm.bswap.*``' Intrinsics
15783 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15788 This is an overloaded intrinsic function. You can use bswap on any
15789 integer type that is an even number of bytes (i.e. BitWidth % 16 == 0).
15793 declare i16 @llvm.bswap.i16(i16 <id>)
15794 declare i32 @llvm.bswap.i32(i32 <id>)
15795 declare i64 @llvm.bswap.i64(i64 <id>)
15796 declare <4 x i32> @llvm.bswap.v4i32(<4 x i32> <id>)
15801 The '``llvm.bswap``' family of intrinsics is used to byte swap an integer
15802 value or vector of integer values with an even number of bytes (positive
15803 multiple of 16 bits).
15808 The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high
15809 and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32``
15810 intrinsic returns an i32 value that has the four bytes of the input i32
15811 swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the
15812 returned i32 will have its bytes in 3, 2, 1, 0 order. The
15813 ``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this
15814 concept to additional even-byte lengths (6 bytes, 8 bytes and more,
15815 respectively). The vector intrinsics, such as ``llvm.bswap.v4i32``,
15816 operate on a per-element basis and the element order is not affected.
15820 '``llvm.ctpop.*``' Intrinsic
15821 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15826 This is an overloaded intrinsic. You can use llvm.ctpop on any integer
15827 bit width, or on any vector with integer elements. Not all targets
15828 support all bit widths or vector types, however.
15832 declare i8 @llvm.ctpop.i8(i8 <src>)
15833 declare i16 @llvm.ctpop.i16(i16 <src>)
15834 declare i32 @llvm.ctpop.i32(i32 <src>)
15835 declare i64 @llvm.ctpop.i64(i64 <src>)
15836 declare i256 @llvm.ctpop.i256(i256 <src>)
15837 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>)
15842 The '``llvm.ctpop``' family of intrinsics counts the number of bits set
15848 The only argument is the value to be counted. The argument may be of any
15849 integer type, or a vector with integer elements. The return type must
15850 match the argument type.
15855 The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within
15856 each element of a vector.
15860 '``llvm.ctlz.*``' Intrinsic
15861 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15866 This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any
15867 integer bit width, or any vector whose elements are integers. Not all
15868 targets support all bit widths or vector types, however.
15872 declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_poison>)
15873 declare <2 x i37> @llvm.ctlz.v2i37(<2 x i37> <src>, i1 <is_zero_poison>)
15878 The '``llvm.ctlz``' family of intrinsic functions counts the number of
15879 leading zeros in a variable.
15884 The first argument is the value to be counted. This argument may be of
15885 any integer type, or a vector with integer element type. The return
15886 type must match the first argument type.
15888 The second argument is a constant flag that indicates whether the intrinsic
15889 returns a valid result if the first argument is zero. If the first
15890 argument is zero and the second argument is true, the result is poison.
15891 Historically some architectures did not provide a defined result for zero
15892 values as efficiently, and many algorithms are now predicated on avoiding
15898 The '``llvm.ctlz``' intrinsic counts the leading (most significant)
15899 zeros in a variable, or within each element of the vector. If
15900 ``src == 0`` then the result is the size in bits of the type of ``src``
15901 if ``is_zero_poison == 0`` and ``poison`` otherwise. For example,
15902 ``llvm.ctlz(i32 2) = 30``.
15906 '``llvm.cttz.*``' Intrinsic
15907 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15912 This is an overloaded intrinsic. You can use ``llvm.cttz`` on any
15913 integer bit width, or any vector of integer elements. Not all targets
15914 support all bit widths or vector types, however.
15918 declare i42 @llvm.cttz.i42 (i42 <src>, i1 <is_zero_poison>)
15919 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_poison>)
15924 The '``llvm.cttz``' family of intrinsic functions counts the number of
15930 The first argument is the value to be counted. This argument may be of
15931 any integer type, or a vector with integer element type. The return
15932 type must match the first argument type.
15934 The second argument is a constant flag that indicates whether the intrinsic
15935 returns a valid result if the first argument is zero. If the first
15936 argument is zero and the second argument is true, the result is poison.
15937 Historically some architectures did not provide a defined result for zero
15938 values as efficiently, and many algorithms are now predicated on avoiding
15944 The '``llvm.cttz``' intrinsic counts the trailing (least significant)
15945 zeros in a variable, or within each element of a vector. If ``src == 0``
15946 then the result is the size in bits of the type of ``src`` if
15947 ``is_zero_poison == 0`` and ``poison`` otherwise. For example,
15948 ``llvm.cttz(2) = 1``.
15954 '``llvm.fshl.*``' Intrinsic
15955 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15960 This is an overloaded intrinsic. You can use ``llvm.fshl`` on any
15961 integer bit width or any vector of integer elements. Not all targets
15962 support all bit widths or vector types, however.
15966 declare i8 @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c)
15967 declare i64 @llvm.fshl.i64(i64 %a, i64 %b, i64 %c)
15968 declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
15973 The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left:
15974 the first two values are concatenated as { %a : %b } (%a is the most significant
15975 bits of the wide value), the combined value is shifted left, and the most
15976 significant bits are extracted to produce a result that is the same size as the
15977 original arguments. If the first 2 arguments are identical, this is equivalent
15978 to a rotate left operation. For vector types, the operation occurs for each
15979 element of the vector. The shift argument is treated as an unsigned amount
15980 modulo the element size of the arguments.
15985 The first two arguments are the values to be concatenated. The third
15986 argument is the shift amount. The arguments may be any integer type or a
15987 vector with integer element type. All arguments and the return value must
15988 have the same type.
15993 .. code-block:: text
15995 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8)
15996 %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15) ; %r = i8: 128 (0b10000000)
15997 %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11) ; %r = i8: 120 (0b01111000)
15998 %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8) ; %r = i8: 0 (0b00000000)
16002 '``llvm.fshr.*``' Intrinsic
16003 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
16008 This is an overloaded intrinsic. You can use ``llvm.fshr`` on any
16009 integer bit width or any vector of integer elements. Not all targets
16010 support all bit widths or vector types, however.
16014 declare i8 @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c)
16015 declare i64 @llvm.fshr.i64(i64 %a, i64 %b, i64 %c)
16016 declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
16021 The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right:
16022 the first two values are concatenated as { %a : %b } (%a is the most significant
16023 bits of the wide value), the combined value is shifted right, and the least
16024 significant bits are extracted to produce a result that is the same size as the
16025 original arguments. If the first 2 arguments are identical, this is equivalent
16026 to a rotate right operation. For vector types, the operation occurs for each
16027 element of the vector. The shift argument is treated as an unsigned amount
16028 modulo the element size of the arguments.
16033 The first two arguments are the values to be concatenated. The third
16034 argument is the shift amount. The arguments may be any integer type or a
16035 vector with integer element type. All arguments and the return value must
16036 have the same type.
16041 .. code-block:: text
16043 %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8)
16044 %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15) ; %r = i8: 254 (0b11111110)
16045 %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11) ; %r = i8: 225 (0b11100001)
16046 %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8) ; %r = i8: 255 (0b11111111)
16048 Arithmetic with Overflow Intrinsics
16049 -----------------------------------
16051 LLVM provides intrinsics for fast arithmetic overflow checking.
16053 Each of these intrinsics returns a two-element struct. The first
16054 element of this struct contains the result of the corresponding
16055 arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of
16056 the result. Therefore, for example, the first element of the struct
16057 returned by ``llvm.sadd.with.overflow.i32`` is always the same as the
16058 result of a 32-bit ``add`` instruction with the same operands, where
16059 the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag.
16061 The second element of the result is an ``i1`` that is 1 if the
16062 arithmetic operation overflowed and 0 otherwise. An operation
16063 overflows if, for any values of its operands ``A`` and ``B`` and for
16064 any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is
16065 not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is
16066 ``sext`` for signed overflow and ``zext`` for unsigned overflow, and
16067 ``op`` is the underlying arithmetic operation.
16069 The behavior of these intrinsics is well-defined for all argument
16072 '``llvm.sadd.with.overflow.*``' Intrinsics
16073 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16078 This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow``
16079 on any integer bit width or vectors of integers.
16083 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
16084 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
16085 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
16086 declare {<4 x i32>, <4 x i1>} @llvm.sadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
16091 The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
16092 a signed addition of the two arguments, and indicate whether an overflow
16093 occurred during the signed summation.
16098 The arguments (%a and %b) and the first element of the result structure
16099 may be of integer types of any bit width, but they must have the same
16100 bit width. The second element of the result structure must be of type
16101 ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
16107 The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
16108 a signed addition of the two variables. They return a structure --- the
16109 first element of which is the signed summation, and the second element
16110 of which is a bit specifying if the signed summation resulted in an
16116 .. code-block:: llvm
16118 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
16119 %sum = extractvalue {i32, i1} %res, 0
16120 %obit = extractvalue {i32, i1} %res, 1
16121 br i1 %obit, label %overflow, label %normal
16123 '``llvm.uadd.with.overflow.*``' Intrinsics
16124 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16129 This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow``
16130 on any integer bit width or vectors of integers.
16134 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
16135 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
16136 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
16137 declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
16142 The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
16143 an unsigned addition of the two arguments, and indicate whether a carry
16144 occurred during the unsigned summation.
16149 The arguments (%a and %b) and the first element of the result structure
16150 may be of integer types of any bit width, but they must have the same
16151 bit width. The second element of the result structure must be of type
16152 ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
16158 The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
16159 an unsigned addition of the two arguments. They return a structure --- the
16160 first element of which is the sum, and the second element of which is a
16161 bit specifying if the unsigned summation resulted in a carry.
16166 .. code-block:: llvm
16168 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
16169 %sum = extractvalue {i32, i1} %res, 0
16170 %obit = extractvalue {i32, i1} %res, 1
16171 br i1 %obit, label %carry, label %normal
16173 '``llvm.ssub.with.overflow.*``' Intrinsics
16174 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16179 This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow``
16180 on any integer bit width or vectors of integers.
16184 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
16185 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
16186 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
16187 declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
16192 The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
16193 a signed subtraction of the two arguments, and indicate whether an
16194 overflow occurred during the signed subtraction.
16199 The arguments (%a and %b) and the first element of the result structure
16200 may be of integer types of any bit width, but they must have the same
16201 bit width. The second element of the result structure must be of type
16202 ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
16208 The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
16209 a signed subtraction of the two arguments. They return a structure --- the
16210 first element of which is the subtraction, and the second element of
16211 which is a bit specifying if the signed subtraction resulted in an
16217 .. code-block:: llvm
16219 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
16220 %sum = extractvalue {i32, i1} %res, 0
16221 %obit = extractvalue {i32, i1} %res, 1
16222 br i1 %obit, label %overflow, label %normal
16224 '``llvm.usub.with.overflow.*``' Intrinsics
16225 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16230 This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow``
16231 on any integer bit width or vectors of integers.
16235 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
16236 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
16237 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
16238 declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
16243 The '``llvm.usub.with.overflow``' family of intrinsic functions perform
16244 an unsigned subtraction of the two arguments, and indicate whether an
16245 overflow occurred during the unsigned subtraction.
16250 The arguments (%a and %b) and the first element of the result structure
16251 may be of integer types of any bit width, but they must have the same
16252 bit width. The second element of the result structure must be of type
16253 ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
16259 The '``llvm.usub.with.overflow``' family of intrinsic functions perform
16260 an unsigned subtraction of the two arguments. They return a structure ---
16261 the first element of which is the subtraction, and the second element of
16262 which is a bit specifying if the unsigned subtraction resulted in an
16268 .. code-block:: llvm
16270 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
16271 %sum = extractvalue {i32, i1} %res, 0
16272 %obit = extractvalue {i32, i1} %res, 1
16273 br i1 %obit, label %overflow, label %normal
16275 '``llvm.smul.with.overflow.*``' Intrinsics
16276 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16281 This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow``
16282 on any integer bit width or vectors of integers.
16286 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
16287 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
16288 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
16289 declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
16294 The '``llvm.smul.with.overflow``' family of intrinsic functions perform
16295 a signed multiplication of the two arguments, and indicate whether an
16296 overflow occurred during the signed multiplication.
16301 The arguments (%a and %b) and the first element of the result structure
16302 may be of integer types of any bit width, but they must have the same
16303 bit width. The second element of the result structure must be of type
16304 ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
16310 The '``llvm.smul.with.overflow``' family of intrinsic functions perform
16311 a signed multiplication of the two arguments. They return a structure ---
16312 the first element of which is the multiplication, and the second element
16313 of which is a bit specifying if the signed multiplication resulted in an
16319 .. code-block:: llvm
16321 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
16322 %sum = extractvalue {i32, i1} %res, 0
16323 %obit = extractvalue {i32, i1} %res, 1
16324 br i1 %obit, label %overflow, label %normal
16326 '``llvm.umul.with.overflow.*``' Intrinsics
16327 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16332 This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow``
16333 on any integer bit width or vectors of integers.
16337 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
16338 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
16339 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
16340 declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
16345 The '``llvm.umul.with.overflow``' family of intrinsic functions perform
16346 a unsigned multiplication of the two arguments, and indicate whether an
16347 overflow occurred during the unsigned multiplication.
16352 The arguments (%a and %b) and the first element of the result structure
16353 may be of integer types of any bit width, but they must have the same
16354 bit width. The second element of the result structure must be of type
16355 ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
16361 The '``llvm.umul.with.overflow``' family of intrinsic functions perform
16362 an unsigned multiplication of the two arguments. They return a structure ---
16363 the first element of which is the multiplication, and the second
16364 element of which is a bit specifying if the unsigned multiplication
16365 resulted in an overflow.
16370 .. code-block:: llvm
16372 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
16373 %sum = extractvalue {i32, i1} %res, 0
16374 %obit = extractvalue {i32, i1} %res, 1
16375 br i1 %obit, label %overflow, label %normal
16377 Saturation Arithmetic Intrinsics
16378 ---------------------------------
16380 Saturation arithmetic is a version of arithmetic in which operations are
16381 limited to a fixed range between a minimum and maximum value. If the result of
16382 an operation is greater than the maximum value, the result is set (or
16383 "clamped") to this maximum. If it is below the minimum, it is clamped to this
16387 '``llvm.sadd.sat.*``' Intrinsics
16388 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16393 This is an overloaded intrinsic. You can use ``llvm.sadd.sat``
16394 on any integer bit width or vectors of integers.
16398 declare i16 @llvm.sadd.sat.i16(i16 %a, i16 %b)
16399 declare i32 @llvm.sadd.sat.i32(i32 %a, i32 %b)
16400 declare i64 @llvm.sadd.sat.i64(i64 %a, i64 %b)
16401 declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16406 The '``llvm.sadd.sat``' family of intrinsic functions perform signed
16407 saturating addition on the 2 arguments.
16412 The arguments (%a and %b) and the result may be of integer types of any bit
16413 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16414 values that will undergo signed addition.
16419 The maximum value this operation can clamp to is the largest signed value
16420 representable by the bit width of the arguments. The minimum value is the
16421 smallest signed value representable by this bit width.
16427 .. code-block:: llvm
16429 %res = call i4 @llvm.sadd.sat.i4(i4 1, i4 2) ; %res = 3
16430 %res = call i4 @llvm.sadd.sat.i4(i4 5, i4 6) ; %res = 7
16431 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 2) ; %res = -2
16432 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 -5) ; %res = -8
16435 '``llvm.uadd.sat.*``' Intrinsics
16436 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16441 This is an overloaded intrinsic. You can use ``llvm.uadd.sat``
16442 on any integer bit width or vectors of integers.
16446 declare i16 @llvm.uadd.sat.i16(i16 %a, i16 %b)
16447 declare i32 @llvm.uadd.sat.i32(i32 %a, i32 %b)
16448 declare i64 @llvm.uadd.sat.i64(i64 %a, i64 %b)
16449 declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16454 The '``llvm.uadd.sat``' family of intrinsic functions perform unsigned
16455 saturating addition on the 2 arguments.
16460 The arguments (%a and %b) and the result may be of integer types of any bit
16461 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16462 values that will undergo unsigned addition.
16467 The maximum value this operation can clamp to is the largest unsigned value
16468 representable by the bit width of the arguments. Because this is an unsigned
16469 operation, the result will never saturate towards zero.
16475 .. code-block:: llvm
16477 %res = call i4 @llvm.uadd.sat.i4(i4 1, i4 2) ; %res = 3
16478 %res = call i4 @llvm.uadd.sat.i4(i4 5, i4 6) ; %res = 11
16479 %res = call i4 @llvm.uadd.sat.i4(i4 8, i4 8) ; %res = 15
16482 '``llvm.ssub.sat.*``' Intrinsics
16483 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16488 This is an overloaded intrinsic. You can use ``llvm.ssub.sat``
16489 on any integer bit width or vectors of integers.
16493 declare i16 @llvm.ssub.sat.i16(i16 %a, i16 %b)
16494 declare i32 @llvm.ssub.sat.i32(i32 %a, i32 %b)
16495 declare i64 @llvm.ssub.sat.i64(i64 %a, i64 %b)
16496 declare <4 x i32> @llvm.ssub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16501 The '``llvm.ssub.sat``' family of intrinsic functions perform signed
16502 saturating subtraction on the 2 arguments.
16507 The arguments (%a and %b) and the result may be of integer types of any bit
16508 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16509 values that will undergo signed subtraction.
16514 The maximum value this operation can clamp to is the largest signed value
16515 representable by the bit width of the arguments. The minimum value is the
16516 smallest signed value representable by this bit width.
16522 .. code-block:: llvm
16524 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 1) ; %res = 1
16525 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 6) ; %res = -4
16526 %res = call i4 @llvm.ssub.sat.i4(i4 -4, i4 5) ; %res = -8
16527 %res = call i4 @llvm.ssub.sat.i4(i4 4, i4 -5) ; %res = 7
16530 '``llvm.usub.sat.*``' Intrinsics
16531 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16536 This is an overloaded intrinsic. You can use ``llvm.usub.sat``
16537 on any integer bit width or vectors of integers.
16541 declare i16 @llvm.usub.sat.i16(i16 %a, i16 %b)
16542 declare i32 @llvm.usub.sat.i32(i32 %a, i32 %b)
16543 declare i64 @llvm.usub.sat.i64(i64 %a, i64 %b)
16544 declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16549 The '``llvm.usub.sat``' family of intrinsic functions perform unsigned
16550 saturating subtraction on the 2 arguments.
16555 The arguments (%a and %b) and the result may be of integer types of any bit
16556 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16557 values that will undergo unsigned subtraction.
16562 The minimum value this operation can clamp to is 0, which is the smallest
16563 unsigned value representable by the bit width of the unsigned arguments.
16564 Because this is an unsigned operation, the result will never saturate towards
16565 the largest possible value representable by this bit width.
16571 .. code-block:: llvm
16573 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 1) ; %res = 1
16574 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 6) ; %res = 0
16577 '``llvm.sshl.sat.*``' Intrinsics
16578 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16583 This is an overloaded intrinsic. You can use ``llvm.sshl.sat``
16584 on integers or vectors of integers of any bit width.
16588 declare i16 @llvm.sshl.sat.i16(i16 %a, i16 %b)
16589 declare i32 @llvm.sshl.sat.i32(i32 %a, i32 %b)
16590 declare i64 @llvm.sshl.sat.i64(i64 %a, i64 %b)
16591 declare <4 x i32> @llvm.sshl.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16596 The '``llvm.sshl.sat``' family of intrinsic functions perform signed
16597 saturating left shift on the first argument.
16602 The arguments (``%a`` and ``%b``) and the result may be of integer types of any
16603 bit width, but they must have the same bit width. ``%a`` is the value to be
16604 shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or
16605 dynamically) equal to or larger than the integer bit width of the arguments,
16606 the result is a :ref:`poison value <poisonvalues>`. If the arguments are
16607 vectors, each vector element of ``a`` is shifted by the corresponding shift
16614 The maximum value this operation can clamp to is the largest signed value
16615 representable by the bit width of the arguments. The minimum value is the
16616 smallest signed value representable by this bit width.
16622 .. code-block:: llvm
16624 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 1) ; %res = 4
16625 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 2) ; %res = 7
16626 %res = call i4 @llvm.sshl.sat.i4(i4 -5, i4 1) ; %res = -8
16627 %res = call i4 @llvm.sshl.sat.i4(i4 -1, i4 1) ; %res = -2
16630 '``llvm.ushl.sat.*``' Intrinsics
16631 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16636 This is an overloaded intrinsic. You can use ``llvm.ushl.sat``
16637 on integers or vectors of integers of any bit width.
16641 declare i16 @llvm.ushl.sat.i16(i16 %a, i16 %b)
16642 declare i32 @llvm.ushl.sat.i32(i32 %a, i32 %b)
16643 declare i64 @llvm.ushl.sat.i64(i64 %a, i64 %b)
16644 declare <4 x i32> @llvm.ushl.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
16649 The '``llvm.ushl.sat``' family of intrinsic functions perform unsigned
16650 saturating left shift on the first argument.
16655 The arguments (``%a`` and ``%b``) and the result may be of integer types of any
16656 bit width, but they must have the same bit width. ``%a`` is the value to be
16657 shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or
16658 dynamically) equal to or larger than the integer bit width of the arguments,
16659 the result is a :ref:`poison value <poisonvalues>`. If the arguments are
16660 vectors, each vector element of ``a`` is shifted by the corresponding shift
16666 The maximum value this operation can clamp to is the largest unsigned value
16667 representable by the bit width of the arguments.
16673 .. code-block:: llvm
16675 %res = call i4 @llvm.ushl.sat.i4(i4 2, i4 1) ; %res = 4
16676 %res = call i4 @llvm.ushl.sat.i4(i4 3, i4 3) ; %res = 15
16679 Fixed Point Arithmetic Intrinsics
16680 ---------------------------------
16682 A fixed point number represents a real data type for a number that has a fixed
16683 number of digits after a radix point (equivalent to the decimal point '.').
16684 The number of digits after the radix point is referred as the `scale`. These
16685 are useful for representing fractional values to a specific precision. The
16686 following intrinsics perform fixed point arithmetic operations on 2 operands
16687 of the same scale, specified as the third argument.
16689 The ``llvm.*mul.fix`` family of intrinsic functions represents a multiplication
16690 of fixed point numbers through scaled integers. Therefore, fixed point
16691 multiplication can be represented as
16693 .. code-block:: llvm
16695 %result = call i4 @llvm.smul.fix.i4(i4 %a, i4 %b, i32 %scale)
16698 %a2 = sext i4 %a to i8
16699 %b2 = sext i4 %b to i8
16700 %mul = mul nsw nuw i8 %a2, %b2
16701 %scale2 = trunc i32 %scale to i8
16702 %r = ashr i8 %mul, i8 %scale2 ; this is for a target rounding down towards negative infinity
16703 %result = trunc i8 %r to i4
16705 The ``llvm.*div.fix`` family of intrinsic functions represents a division of
16706 fixed point numbers through scaled integers. Fixed point division can be
16709 .. code-block:: llvm
16711 %result call i4 @llvm.sdiv.fix.i4(i4 %a, i4 %b, i32 %scale)
16714 %a2 = sext i4 %a to i8
16715 %b2 = sext i4 %b to i8
16716 %scale2 = trunc i32 %scale to i8
16717 %a3 = shl i8 %a2, %scale2
16718 %r = sdiv i8 %a3, %b2 ; this is for a target rounding towards zero
16719 %result = trunc i8 %r to i4
16721 For each of these functions, if the result cannot be represented exactly with
16722 the provided scale, the result is rounded. Rounding is unspecified since
16723 preferred rounding may vary for different targets. Rounding is specified
16724 through a target hook. Different pipelines should legalize or optimize this
16725 using the rounding specified by this hook if it is provided. Operations like
16726 constant folding, instruction combining, KnownBits, and ValueTracking should
16727 also use this hook, if provided, and not assume the direction of rounding. A
16728 rounded result must always be within one unit of precision from the true
16729 result. That is, the error between the returned result and the true result must
16730 be less than 1/2^(scale).
16733 '``llvm.smul.fix.*``' Intrinsics
16734 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16739 This is an overloaded intrinsic. You can use ``llvm.smul.fix``
16740 on any integer bit width or vectors of integers.
16744 declare i16 @llvm.smul.fix.i16(i16 %a, i16 %b, i32 %scale)
16745 declare i32 @llvm.smul.fix.i32(i32 %a, i32 %b, i32 %scale)
16746 declare i64 @llvm.smul.fix.i64(i64 %a, i64 %b, i32 %scale)
16747 declare <4 x i32> @llvm.smul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16752 The '``llvm.smul.fix``' family of intrinsic functions perform signed
16753 fixed point multiplication on 2 arguments of the same scale.
16758 The arguments (%a and %b) and the result may be of integer types of any bit
16759 width, but they must have the same bit width. The arguments may also work with
16760 int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16761 values that will undergo signed fixed point multiplication. The argument
16762 ``%scale`` represents the scale of both operands, and must be a constant
16768 This operation performs fixed point multiplication on the 2 arguments of a
16769 specified scale. The result will also be returned in the same scale specified
16770 in the third argument.
16772 If the result value cannot be precisely represented in the given scale, the
16773 value is rounded up or down to the closest representable value. The rounding
16774 direction is unspecified.
16776 It is undefined behavior if the result value does not fit within the range of
16777 the fixed point type.
16783 .. code-block:: llvm
16785 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
16786 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
16787 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5)
16789 ; The result in the following could be rounded up to -2 or down to -2.5
16790 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25)
16793 '``llvm.umul.fix.*``' Intrinsics
16794 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16799 This is an overloaded intrinsic. You can use ``llvm.umul.fix``
16800 on any integer bit width or vectors of integers.
16804 declare i16 @llvm.umul.fix.i16(i16 %a, i16 %b, i32 %scale)
16805 declare i32 @llvm.umul.fix.i32(i32 %a, i32 %b, i32 %scale)
16806 declare i64 @llvm.umul.fix.i64(i64 %a, i64 %b, i32 %scale)
16807 declare <4 x i32> @llvm.umul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16812 The '``llvm.umul.fix``' family of intrinsic functions perform unsigned
16813 fixed point multiplication on 2 arguments of the same scale.
16818 The arguments (%a and %b) and the result may be of integer types of any bit
16819 width, but they must have the same bit width. The arguments may also work with
16820 int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16821 values that will undergo unsigned fixed point multiplication. The argument
16822 ``%scale`` represents the scale of both operands, and must be a constant
16828 This operation performs unsigned fixed point multiplication on the 2 arguments of a
16829 specified scale. The result will also be returned in the same scale specified
16830 in the third argument.
16832 If the result value cannot be precisely represented in the given scale, the
16833 value is rounded up or down to the closest representable value. The rounding
16834 direction is unspecified.
16836 It is undefined behavior if the result value does not fit within the range of
16837 the fixed point type.
16843 .. code-block:: llvm
16845 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
16846 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
16848 ; The result in the following could be rounded down to 3.5 or up to 4
16849 %res = call i4 @llvm.umul.fix.i4(i4 15, i4 1, i32 1) ; %res = 7 (or 8) (7.5 x 0.5 = 3.75)
16852 '``llvm.smul.fix.sat.*``' Intrinsics
16853 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16858 This is an overloaded intrinsic. You can use ``llvm.smul.fix.sat``
16859 on any integer bit width or vectors of integers.
16863 declare i16 @llvm.smul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16864 declare i32 @llvm.smul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16865 declare i64 @llvm.smul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16866 declare <4 x i32> @llvm.smul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16871 The '``llvm.smul.fix.sat``' family of intrinsic functions perform signed
16872 fixed point saturating multiplication on 2 arguments of the same scale.
16877 The arguments (%a and %b) and the result may be of integer types of any bit
16878 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16879 values that will undergo signed fixed point multiplication. The argument
16880 ``%scale`` represents the scale of both operands, and must be a constant
16886 This operation performs fixed point multiplication on the 2 arguments of a
16887 specified scale. The result will also be returned in the same scale specified
16888 in the third argument.
16890 If the result value cannot be precisely represented in the given scale, the
16891 value is rounded up or down to the closest representable value. The rounding
16892 direction is unspecified.
16894 The maximum value this operation can clamp to is the largest signed value
16895 representable by the bit width of the first 2 arguments. The minimum value is the
16896 smallest signed value representable by this bit width.
16902 .. code-block:: llvm
16904 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
16905 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
16906 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5)
16908 ; The result in the following could be rounded up to -2 or down to -2.5
16909 %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)
16912 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 0) ; %res = 7
16913 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 4, i32 2) ; %res = 7
16914 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 5, i32 2) ; %res = -8
16915 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 -2, i32 1) ; %res = 7
16917 ; Scale can affect the saturation result
16918 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7)
16919 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2)
16922 '``llvm.umul.fix.sat.*``' Intrinsics
16923 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16928 This is an overloaded intrinsic. You can use ``llvm.umul.fix.sat``
16929 on any integer bit width or vectors of integers.
16933 declare i16 @llvm.umul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16934 declare i32 @llvm.umul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16935 declare i64 @llvm.umul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16936 declare <4 x i32> @llvm.umul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16941 The '``llvm.umul.fix.sat``' family of intrinsic functions perform unsigned
16942 fixed point saturating multiplication on 2 arguments of the same scale.
16947 The arguments (%a and %b) and the result may be of integer types of any bit
16948 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16949 values that will undergo unsigned fixed point multiplication. The argument
16950 ``%scale`` represents the scale of both operands, and must be a constant
16956 This operation performs fixed point multiplication on the 2 arguments of a
16957 specified scale. The result will also be returned in the same scale specified
16958 in the third argument.
16960 If the result value cannot be precisely represented in the given scale, the
16961 value is rounded up or down to the closest representable value. The rounding
16962 direction is unspecified.
16964 The maximum value this operation can clamp to is the largest unsigned value
16965 representable by the bit width of the first 2 arguments. The minimum value is the
16966 smallest unsigned value representable by this bit width (zero).
16972 .. code-block:: llvm
16974 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
16975 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
16977 ; The result in the following could be rounded down to 2 or up to 2.5
16978 %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)
16981 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 2, i32 0) ; %res = 15 (8 x 2 -> clamped to 15)
16982 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 8, i32 2) ; %res = 15 (2 x 2 -> clamped to 3.75)
16984 ; Scale can affect the saturation result
16985 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7)
16986 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2)
16989 '``llvm.sdiv.fix.*``' Intrinsics
16990 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16995 This is an overloaded intrinsic. You can use ``llvm.sdiv.fix``
16996 on any integer bit width or vectors of integers.
17000 declare i16 @llvm.sdiv.fix.i16(i16 %a, i16 %b, i32 %scale)
17001 declare i32 @llvm.sdiv.fix.i32(i32 %a, i32 %b, i32 %scale)
17002 declare i64 @llvm.sdiv.fix.i64(i64 %a, i64 %b, i32 %scale)
17003 declare <4 x i32> @llvm.sdiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
17008 The '``llvm.sdiv.fix``' family of intrinsic functions perform signed
17009 fixed point division on 2 arguments of the same scale.
17014 The arguments (%a and %b) and the result may be of integer types of any bit
17015 width, but they must have the same bit width. The arguments may also work with
17016 int vectors of the same length and int size. ``%a`` and ``%b`` are the two
17017 values that will undergo signed fixed point division. The argument
17018 ``%scale`` represents the scale of both operands, and must be a constant
17024 This operation performs fixed point division on the 2 arguments of a
17025 specified scale. The result will also be returned in the same scale specified
17026 in the third argument.
17028 If the result value cannot be precisely represented in the given scale, the
17029 value is rounded up or down to the closest representable value. The rounding
17030 direction is unspecified.
17032 It is undefined behavior if the result value does not fit within the range of
17033 the fixed point type, or if the second argument is zero.
17039 .. code-block:: llvm
17041 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3)
17042 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5)
17043 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5)
17045 ; The result in the following could be rounded up to 1 or down to 0.5
17046 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75)
17049 '``llvm.udiv.fix.*``' Intrinsics
17050 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17055 This is an overloaded intrinsic. You can use ``llvm.udiv.fix``
17056 on any integer bit width or vectors of integers.
17060 declare i16 @llvm.udiv.fix.i16(i16 %a, i16 %b, i32 %scale)
17061 declare i32 @llvm.udiv.fix.i32(i32 %a, i32 %b, i32 %scale)
17062 declare i64 @llvm.udiv.fix.i64(i64 %a, i64 %b, i32 %scale)
17063 declare <4 x i32> @llvm.udiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
17068 The '``llvm.udiv.fix``' family of intrinsic functions perform unsigned
17069 fixed point division on 2 arguments of the same scale.
17074 The arguments (%a and %b) and the result may be of integer types of any bit
17075 width, but they must have the same bit width. The arguments may also work with
17076 int vectors of the same length and int size. ``%a`` and ``%b`` are the two
17077 values that will undergo unsigned fixed point division. The argument
17078 ``%scale`` represents the scale of both operands, and must be a constant
17084 This operation performs fixed point division on the 2 arguments of a
17085 specified scale. The result will also be returned in the same scale specified
17086 in the third argument.
17088 If the result value cannot be precisely represented in the given scale, the
17089 value is rounded up or down to the closest representable value. The rounding
17090 direction is unspecified.
17092 It is undefined behavior if the result value does not fit within the range of
17093 the fixed point type, or if the second argument is zero.
17099 .. code-block:: llvm
17101 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3)
17102 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5)
17103 %res = call i4 @llvm.udiv.fix.i4(i4 1, i4 -8, i32 4) ; %res = 2 (0.0625 / 0.5 = 0.125)
17105 ; The result in the following could be rounded up to 1 or down to 0.5
17106 %res = call i4 @llvm.udiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75)
17109 '``llvm.sdiv.fix.sat.*``' Intrinsics
17110 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17115 This is an overloaded intrinsic. You can use ``llvm.sdiv.fix.sat``
17116 on any integer bit width or vectors of integers.
17120 declare i16 @llvm.sdiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
17121 declare i32 @llvm.sdiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
17122 declare i64 @llvm.sdiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
17123 declare <4 x i32> @llvm.sdiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
17128 The '``llvm.sdiv.fix.sat``' family of intrinsic functions perform signed
17129 fixed point saturating division on 2 arguments of the same scale.
17134 The arguments (%a and %b) and the result may be of integer types of any bit
17135 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
17136 values that will undergo signed fixed point division. The argument
17137 ``%scale`` represents the scale of both operands, and must be a constant
17143 This operation performs fixed point division on the 2 arguments of a
17144 specified scale. The result will also be returned in the same scale specified
17145 in the third argument.
17147 If the result value cannot be precisely represented in the given scale, the
17148 value is rounded up or down to the closest representable value. The rounding
17149 direction is unspecified.
17151 The maximum value this operation can clamp to is the largest signed value
17152 representable by the bit width of the first 2 arguments. The minimum value is the
17153 smallest signed value representable by this bit width.
17155 It is undefined behavior if the second argument is zero.
17161 .. code-block:: llvm
17163 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3)
17164 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5)
17165 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5)
17167 ; The result in the following could be rounded up to 1 or down to 0.5
17168 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75)
17171 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -8, i4 -1, i32 0) ; %res = 7 (-8 / -1 = 8 => 7)
17172 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 4, i4 2, i32 2) ; %res = 7 (1 / 0.5 = 2 => 1.75)
17173 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -4, i4 1, i32 2) ; %res = -8 (-1 / 0.25 = -4 => -2)
17176 '``llvm.udiv.fix.sat.*``' Intrinsics
17177 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17182 This is an overloaded intrinsic. You can use ``llvm.udiv.fix.sat``
17183 on any integer bit width or vectors of integers.
17187 declare i16 @llvm.udiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
17188 declare i32 @llvm.udiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
17189 declare i64 @llvm.udiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
17190 declare <4 x i32> @llvm.udiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
17195 The '``llvm.udiv.fix.sat``' family of intrinsic functions perform unsigned
17196 fixed point saturating division on 2 arguments of the same scale.
17201 The arguments (%a and %b) and the result may be of integer types of any bit
17202 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
17203 values that will undergo unsigned fixed point division. The argument
17204 ``%scale`` represents the scale of both operands, and must be a constant
17210 This operation performs fixed point division on the 2 arguments of a
17211 specified scale. The result will also be returned in the same scale specified
17212 in the third argument.
17214 If the result value cannot be precisely represented in the given scale, the
17215 value is rounded up or down to the closest representable value. The rounding
17216 direction is unspecified.
17218 The maximum value this operation can clamp to is the largest unsigned value
17219 representable by the bit width of the first 2 arguments. The minimum value is the
17220 smallest unsigned value representable by this bit width (zero).
17222 It is undefined behavior if the second argument is zero.
17227 .. code-block:: llvm
17229 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3)
17230 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5)
17232 ; The result in the following could be rounded down to 0.5 or up to 1
17233 %res = call i4 @llvm.udiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 1 (or 2) (1.5 / 2 = 0.75)
17236 %res = call i4 @llvm.udiv.fix.sat.i4(i4 8, i4 2, i32 2) ; %res = 15 (2 / 0.5 = 4 => 3.75)
17239 Specialised Arithmetic Intrinsics
17240 ---------------------------------
17242 .. _i_intr_llvm_canonicalize:
17244 '``llvm.canonicalize.*``' Intrinsic
17245 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17252 declare float @llvm.canonicalize.f32(float %a)
17253 declare double @llvm.canonicalize.f64(double %b)
17258 The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical
17259 encoding of a floating-point number. This canonicalization is useful for
17260 implementing certain numeric primitives such as frexp. The canonical encoding is
17261 defined by IEEE-754-2008 to be:
17265 2.1.8 canonical encoding: The preferred encoding of a floating-point
17266 representation in a format. Applied to declets, significands of finite
17267 numbers, infinities, and NaNs, especially in decimal formats.
17269 This operation can also be considered equivalent to the IEEE-754-2008
17270 conversion of a floating-point value to the same format. NaNs are handled
17271 according to section 6.2.
17273 Examples of non-canonical encodings:
17275 - x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are
17276 converted to a canonical representation per hardware-specific protocol.
17277 - Many normal decimal floating-point numbers have non-canonical alternative
17279 - Some machines, like GPUs or ARMv7 NEON, do not support subnormal values.
17280 These are treated as non-canonical encodings of zero and will be flushed to
17281 a zero of the same sign by this operation.
17283 Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with
17284 default exception handling must signal an invalid exception, and produce a
17287 This function should always be implementable as multiplication by 1.0, provided
17288 that the compiler does not constant fold the operation. Likewise, division by
17289 1.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with
17290 -0.0 is also sufficient provided that the rounding mode is not -Infinity.
17292 ``@llvm.canonicalize`` must preserve the equality relation. That is:
17294 - ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)``
17295 - ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent
17298 Additionally, the sign of zero must be conserved:
17299 ``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0``
17301 The payload bits of a NaN must be conserved, with two exceptions.
17302 First, environments which use only a single canonical representation of NaN
17303 must perform said canonicalization. Second, SNaNs must be quieted per the
17306 The canonicalization operation may be optimized away if:
17308 - The input is known to be canonical. For example, it was produced by a
17309 floating-point operation that is required by the standard to be canonical.
17310 - The result is consumed only by (or fused with) other floating-point
17311 operations. That is, the bits of the floating-point value are not examined.
17315 '``llvm.fmuladd.*``' Intrinsic
17316 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17323 declare float @llvm.fmuladd.f32(float %a, float %b, float %c)
17324 declare double @llvm.fmuladd.f64(double %a, double %b, double %c)
17329 The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add
17330 expressions that can be fused if the code generator determines that (a) the
17331 target instruction set has support for a fused operation, and (b) that the
17332 fused operation is more efficient than the equivalent, separate pair of mul
17333 and add instructions.
17338 The '``llvm.fmuladd.*``' intrinsics each take three arguments: two
17339 multiplicands, a and b, and an addend c.
17348 %0 = call float @llvm.fmuladd.f32(%a, %b, %c)
17350 is equivalent to the expression a \* b + c, except that it is unspecified
17351 whether rounding will be performed between the multiplication and addition
17352 steps. Fusion is not guaranteed, even if the target platform supports it.
17353 If a fused multiply-add is required, the corresponding
17354 :ref:`llvm.fma <int_fma>` intrinsic function should be used instead.
17355 This never sets errno, just as '``llvm.fma.*``'.
17360 .. code-block:: llvm
17362 %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c
17365 Hardware-Loop Intrinsics
17366 ------------------------
17368 LLVM support several intrinsics to mark a loop as a hardware-loop. They are
17369 hints to the backend which are required to lower these intrinsics further to target
17370 specific instructions, or revert the hardware-loop to a normal loop if target
17371 specific restriction are not met and a hardware-loop can't be generated.
17373 These intrinsics may be modified in the future and are not intended to be used
17374 outside the backend. Thus, front-end and mid-level optimizations should not be
17375 generating these intrinsics.
17378 '``llvm.set.loop.iterations.*``' Intrinsic
17379 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17384 This is an overloaded intrinsic.
17388 declare void @llvm.set.loop.iterations.i32(i32)
17389 declare void @llvm.set.loop.iterations.i64(i64)
17394 The '``llvm.set.loop.iterations.*``' intrinsics are used to specify the
17395 hardware-loop trip count. They are placed in the loop preheader basic block and
17396 are marked as ``IntrNoDuplicate`` to avoid optimizers duplicating these
17402 The integer operand is the loop trip count of the hardware-loop, and thus
17403 not e.g. the loop back-edge taken count.
17408 The '``llvm.set.loop.iterations.*``' intrinsics do not perform any arithmetic
17409 on their operand. It's a hint to the backend that can use this to set up the
17410 hardware-loop count with a target specific instruction, usually a move of this
17411 value to a special register or a hardware-loop instruction.
17414 '``llvm.start.loop.iterations.*``' Intrinsic
17415 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17420 This is an overloaded intrinsic.
17424 declare i32 @llvm.start.loop.iterations.i32(i32)
17425 declare i64 @llvm.start.loop.iterations.i64(i64)
17430 The '``llvm.start.loop.iterations.*``' intrinsics are similar to the
17431 '``llvm.set.loop.iterations.*``' intrinsics, used to specify the
17432 hardware-loop trip count but also produce a value identical to the input
17433 that can be used as the input to the loop. They are placed in the loop
17434 preheader basic block and the output is expected to be the input to the
17435 phi for the induction variable of the loop, decremented by the
17436 '``llvm.loop.decrement.reg.*``'.
17441 The integer operand is the loop trip count of the hardware-loop, and thus
17442 not e.g. the loop back-edge taken count.
17447 The '``llvm.start.loop.iterations.*``' intrinsics do not perform any arithmetic
17448 on their operand. It's a hint to the backend that can use this to set up the
17449 hardware-loop count with a target specific instruction, usually a move of this
17450 value to a special register or a hardware-loop instruction.
17452 '``llvm.test.set.loop.iterations.*``' Intrinsic
17453 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17458 This is an overloaded intrinsic.
17462 declare i1 @llvm.test.set.loop.iterations.i32(i32)
17463 declare i1 @llvm.test.set.loop.iterations.i64(i64)
17468 The '``llvm.test.set.loop.iterations.*``' intrinsics are used to specify the
17469 the loop trip count, and also test that the given count is not zero, allowing
17470 it to control entry to a while-loop. They are placed in the loop preheader's
17471 predecessor basic block, and are marked as ``IntrNoDuplicate`` to avoid
17472 optimizers duplicating these instructions.
17477 The integer operand is the loop trip count of the hardware-loop, and thus
17478 not e.g. the loop back-edge taken count.
17483 The '``llvm.test.set.loop.iterations.*``' intrinsics do not perform any
17484 arithmetic on their operand. It's a hint to the backend that can use this to
17485 set up the hardware-loop count with a target specific instruction, usually a
17486 move of this value to a special register or a hardware-loop instruction.
17487 The result is the conditional value of whether the given count is not zero.
17490 '``llvm.test.start.loop.iterations.*``' Intrinsic
17491 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17496 This is an overloaded intrinsic.
17500 declare {i32, i1} @llvm.test.start.loop.iterations.i32(i32)
17501 declare {i64, i1} @llvm.test.start.loop.iterations.i64(i64)
17506 The '``llvm.test.start.loop.iterations.*``' intrinsics are similar to the
17507 '``llvm.test.set.loop.iterations.*``' and '``llvm.start.loop.iterations.*``'
17508 intrinsics, used to specify the hardware-loop trip count, but also produce a
17509 value identical to the input that can be used as the input to the loop. The
17510 second i1 output controls entry to a while-loop.
17515 The integer operand is the loop trip count of the hardware-loop, and thus
17516 not e.g. the loop back-edge taken count.
17521 The '``llvm.test.start.loop.iterations.*``' intrinsics do not perform any
17522 arithmetic on their operand. It's a hint to the backend that can use this to
17523 set up the hardware-loop count with a target specific instruction, usually a
17524 move of this value to a special register or a hardware-loop instruction.
17525 The result is a pair of the input and a conditional value of whether the
17526 given count is not zero.
17529 '``llvm.loop.decrement.reg.*``' Intrinsic
17530 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17535 This is an overloaded intrinsic.
17539 declare i32 @llvm.loop.decrement.reg.i32(i32, i32)
17540 declare i64 @llvm.loop.decrement.reg.i64(i64, i64)
17545 The '``llvm.loop.decrement.reg.*``' intrinsics are used to lower the loop
17546 iteration counter and return an updated value that will be used in the next
17552 Both arguments must have identical integer types. The first operand is the
17553 loop iteration counter. The second operand is the maximum number of elements
17554 processed in an iteration.
17559 The '``llvm.loop.decrement.reg.*``' intrinsics do an integer ``SUB`` of its
17560 two operands, which is not allowed to wrap. They return the remaining number of
17561 iterations still to be executed, and can be used together with a ``PHI``,
17562 ``ICMP`` and ``BR`` to control the number of loop iterations executed. Any
17563 optimisations are allowed to treat it is a ``SUB``, and it is supported by
17564 SCEV, so it's the backends responsibility to handle cases where it may be
17565 optimised. These intrinsics are marked as ``IntrNoDuplicate`` to avoid
17566 optimizers duplicating these instructions.
17569 '``llvm.loop.decrement.*``' Intrinsic
17570 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17575 This is an overloaded intrinsic.
17579 declare i1 @llvm.loop.decrement.i32(i32)
17580 declare i1 @llvm.loop.decrement.i64(i64)
17585 The HardwareLoops pass allows the loop decrement value to be specified with an
17586 option. It defaults to a loop decrement value of 1, but it can be an unsigned
17587 integer value provided by this option. The '``llvm.loop.decrement.*``'
17588 intrinsics decrement the loop iteration counter with this value, and return a
17589 false predicate if the loop should exit, and true otherwise.
17590 This is emitted if the loop counter is not updated via a ``PHI`` node, which
17591 can also be controlled with an option.
17596 The integer argument is the loop decrement value used to decrement the loop
17602 The '``llvm.loop.decrement.*``' intrinsics do a ``SUB`` of the loop iteration
17603 counter with the given loop decrement value, and return false if the loop
17604 should exit, this ``SUB`` is not allowed to wrap. The result is a condition
17605 that is used by the conditional branch controlling the loop.
17608 Vector Reduction Intrinsics
17609 ---------------------------
17611 Horizontal reductions of vectors can be expressed using the following
17612 intrinsics. Each one takes a vector operand as an input and applies its
17613 respective operation across all elements of the vector, returning a single
17614 scalar result of the same element type.
17616 .. _int_vector_reduce_add:
17618 '``llvm.vector.reduce.add.*``' Intrinsic
17619 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17626 declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a)
17627 declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a)
17632 The '``llvm.vector.reduce.add.*``' intrinsics do an integer ``ADD``
17633 reduction of a vector, returning the result as a scalar. The return type matches
17634 the element-type of the vector input.
17638 The argument to this intrinsic must be a vector of integer values.
17640 .. _int_vector_reduce_fadd:
17642 '``llvm.vector.reduce.fadd.*``' Intrinsic
17643 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17650 declare float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %a)
17651 declare double @llvm.vector.reduce.fadd.v2f64(double %start_value, <2 x double> %a)
17656 The '``llvm.vector.reduce.fadd.*``' intrinsics do a floating-point
17657 ``ADD`` reduction of a vector, returning the result as a scalar. The return type
17658 matches the element-type of the vector input.
17660 If the intrinsic call has the 'reassoc' flag set, then the reduction will not
17661 preserve the associativity of an equivalent scalarized counterpart. Otherwise
17662 the reduction will be *sequential*, thus implying that the operation respects
17663 the associativity of a scalarized reduction. That is, the reduction begins with
17664 the start value and performs an fadd operation with consecutively increasing
17665 vector element indices. See the following pseudocode:
17669 float sequential_fadd(start_value, input_vector)
17670 result = start_value
17671 for i = 0 to length(input_vector)
17672 result = result + input_vector[i]
17678 The first argument to this intrinsic is a scalar start value for the reduction.
17679 The type of the start value matches the element-type of the vector input.
17680 The second argument must be a vector of floating-point values.
17682 To ignore the start value, negative zero (``-0.0``) can be used, as it is
17683 the neutral value of floating point addition.
17690 %unord = call reassoc float @llvm.vector.reduce.fadd.v4f32(float -0.0, <4 x float> %input) ; relaxed reduction
17691 %ord = call float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %input) ; sequential reduction
17694 .. _int_vector_reduce_mul:
17696 '``llvm.vector.reduce.mul.*``' Intrinsic
17697 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17704 declare i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %a)
17705 declare i64 @llvm.vector.reduce.mul.v2i64(<2 x i64> %a)
17710 The '``llvm.vector.reduce.mul.*``' intrinsics do an integer ``MUL``
17711 reduction of a vector, returning the result as a scalar. The return type matches
17712 the element-type of the vector input.
17716 The argument to this intrinsic must be a vector of integer values.
17718 .. _int_vector_reduce_fmul:
17720 '``llvm.vector.reduce.fmul.*``' Intrinsic
17721 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17728 declare float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %a)
17729 declare double @llvm.vector.reduce.fmul.v2f64(double %start_value, <2 x double> %a)
17734 The '``llvm.vector.reduce.fmul.*``' intrinsics do a floating-point
17735 ``MUL`` reduction of a vector, returning the result as a scalar. The return type
17736 matches the element-type of the vector input.
17738 If the intrinsic call has the 'reassoc' flag set, then the reduction will not
17739 preserve the associativity of an equivalent scalarized counterpart. Otherwise
17740 the reduction will be *sequential*, thus implying that the operation respects
17741 the associativity of a scalarized reduction. That is, the reduction begins with
17742 the start value and performs an fmul operation with consecutively increasing
17743 vector element indices. See the following pseudocode:
17747 float sequential_fmul(start_value, input_vector)
17748 result = start_value
17749 for i = 0 to length(input_vector)
17750 result = result * input_vector[i]
17756 The first argument to this intrinsic is a scalar start value for the reduction.
17757 The type of the start value matches the element-type of the vector input.
17758 The second argument must be a vector of floating-point values.
17760 To ignore the start value, one (``1.0``) can be used, as it is the neutral
17761 value of floating point multiplication.
17768 %unord = call reassoc float @llvm.vector.reduce.fmul.v4f32(float 1.0, <4 x float> %input) ; relaxed reduction
17769 %ord = call float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %input) ; sequential reduction
17771 .. _int_vector_reduce_and:
17773 '``llvm.vector.reduce.and.*``' Intrinsic
17774 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17781 declare i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %a)
17786 The '``llvm.vector.reduce.and.*``' intrinsics do a bitwise ``AND``
17787 reduction of a vector, returning the result as a scalar. The return type matches
17788 the element-type of the vector input.
17792 The argument to this intrinsic must be a vector of integer values.
17794 .. _int_vector_reduce_or:
17796 '``llvm.vector.reduce.or.*``' Intrinsic
17797 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17804 declare i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %a)
17809 The '``llvm.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction
17810 of a vector, returning the result as a scalar. The return type matches the
17811 element-type of the vector input.
17815 The argument to this intrinsic must be a vector of integer values.
17817 .. _int_vector_reduce_xor:
17819 '``llvm.vector.reduce.xor.*``' Intrinsic
17820 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17827 declare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %a)
17832 The '``llvm.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR``
17833 reduction of a vector, returning the result as a scalar. The return type matches
17834 the element-type of the vector input.
17838 The argument to this intrinsic must be a vector of integer values.
17840 .. _int_vector_reduce_smax:
17842 '``llvm.vector.reduce.smax.*``' Intrinsic
17843 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17850 declare i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %a)
17855 The '``llvm.vector.reduce.smax.*``' intrinsics do a signed integer
17856 ``MAX`` reduction of a vector, returning the result as a scalar. The return type
17857 matches the element-type of the vector input.
17861 The argument to this intrinsic must be a vector of integer values.
17863 .. _int_vector_reduce_smin:
17865 '``llvm.vector.reduce.smin.*``' Intrinsic
17866 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17873 declare i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %a)
17878 The '``llvm.vector.reduce.smin.*``' intrinsics do a signed integer
17879 ``MIN`` reduction of a vector, returning the result as a scalar. The return type
17880 matches the element-type of the vector input.
17884 The argument to this intrinsic must be a vector of integer values.
17886 .. _int_vector_reduce_umax:
17888 '``llvm.vector.reduce.umax.*``' Intrinsic
17889 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17896 declare i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %a)
17901 The '``llvm.vector.reduce.umax.*``' intrinsics do an unsigned
17902 integer ``MAX`` reduction of a vector, returning the result as a scalar. The
17903 return type matches the element-type of the vector input.
17907 The argument to this intrinsic must be a vector of integer values.
17909 .. _int_vector_reduce_umin:
17911 '``llvm.vector.reduce.umin.*``' Intrinsic
17912 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17919 declare i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %a)
17924 The '``llvm.vector.reduce.umin.*``' intrinsics do an unsigned
17925 integer ``MIN`` reduction of a vector, returning the result as a scalar. The
17926 return type matches the element-type of the vector input.
17930 The argument to this intrinsic must be a vector of integer values.
17932 .. _int_vector_reduce_fmax:
17934 '``llvm.vector.reduce.fmax.*``' Intrinsic
17935 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17942 declare float @llvm.vector.reduce.fmax.v4f32(<4 x float> %a)
17943 declare double @llvm.vector.reduce.fmax.v2f64(<2 x double> %a)
17948 The '``llvm.vector.reduce.fmax.*``' intrinsics do a floating-point
17949 ``MAX`` reduction of a vector, returning the result as a scalar. The return type
17950 matches the element-type of the vector input.
17952 This instruction has the same comparison semantics as the '``llvm.maxnum.*``'
17953 intrinsic. That is, the result will always be a number unless all elements of
17954 the vector are NaN. For a vector with maximum element magnitude 0.0 and
17955 containing both +0.0 and -0.0 elements, the sign of the result is unspecified.
17957 If the intrinsic call has the ``nnan`` fast-math flag, then the operation can
17958 assume that NaNs are not present in the input vector.
17962 The argument to this intrinsic must be a vector of floating-point values.
17964 .. _int_vector_reduce_fmin:
17966 '``llvm.vector.reduce.fmin.*``' Intrinsic
17967 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17971 This is an overloaded intrinsic.
17975 declare float @llvm.vector.reduce.fmin.v4f32(<4 x float> %a)
17976 declare double @llvm.vector.reduce.fmin.v2f64(<2 x double> %a)
17981 The '``llvm.vector.reduce.fmin.*``' intrinsics do a floating-point
17982 ``MIN`` reduction of a vector, returning the result as a scalar. The return type
17983 matches the element-type of the vector input.
17985 This instruction has the same comparison semantics as the '``llvm.minnum.*``'
17986 intrinsic. That is, the result will always be a number unless all elements of
17987 the vector are NaN. For a vector with minimum element magnitude 0.0 and
17988 containing both +0.0 and -0.0 elements, the sign of the result is unspecified.
17990 If the intrinsic call has the ``nnan`` fast-math flag, then the operation can
17991 assume that NaNs are not present in the input vector.
17995 The argument to this intrinsic must be a vector of floating-point values.
17997 .. _int_vector_reduce_fmaximum:
17999 '``llvm.vector.reduce.fmaximum.*``' Intrinsic
18000 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18004 This is an overloaded intrinsic.
18008 declare float @llvm.vector.reduce.fmaximum.v4f32(<4 x float> %a)
18009 declare double @llvm.vector.reduce.fmaximum.v2f64(<2 x double> %a)
18014 The '``llvm.vector.reduce.fmaximum.*``' intrinsics do a floating-point
18015 ``MAX`` reduction of a vector, returning the result as a scalar. The return type
18016 matches the element-type of the vector input.
18018 This instruction has the same comparison semantics as the '``llvm.maximum.*``'
18019 intrinsic. That is, this intrinsic propagates NaNs and +0.0 is considered
18020 greater than -0.0. If any element of the vector is a NaN, the result is NaN.
18024 The argument to this intrinsic must be a vector of floating-point values.
18026 .. _int_vector_reduce_fminimum:
18028 '``llvm.vector.reduce.fminimum.*``' Intrinsic
18029 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18033 This is an overloaded intrinsic.
18037 declare float @llvm.vector.reduce.fminimum.v4f32(<4 x float> %a)
18038 declare double @llvm.vector.reduce.fminimum.v2f64(<2 x double> %a)
18043 The '``llvm.vector.reduce.fminimum.*``' intrinsics do a floating-point
18044 ``MIN`` reduction of a vector, returning the result as a scalar. The return type
18045 matches the element-type of the vector input.
18047 This instruction has the same comparison semantics as the '``llvm.minimum.*``'
18048 intrinsic. That is, this intrinsic propagates NaNs and -0.0 is considered less
18049 than +0.0. If any element of the vector is a NaN, the result is NaN.
18053 The argument to this intrinsic must be a vector of floating-point values.
18055 '``llvm.vector.insert``' Intrinsic
18056 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18060 This is an overloaded intrinsic.
18064 ; Insert fixed type into scalable type
18065 declare <vscale x 4 x float> @llvm.vector.insert.nxv4f32.v4f32(<vscale x 4 x float> %vec, <4 x float> %subvec, i64 <idx>)
18066 declare <vscale x 2 x double> @llvm.vector.insert.nxv2f64.v2f64(<vscale x 2 x double> %vec, <2 x double> %subvec, i64 <idx>)
18068 ; Insert scalable type into scalable type
18069 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>)
18071 ; Insert fixed type into fixed type
18072 declare <4 x double> @llvm.vector.insert.v4f64.v2f64(<4 x double> %vec, <2 x double> %subvec, i64 <idx>)
18077 The '``llvm.vector.insert.*``' intrinsics insert a vector into another vector
18078 starting from a given index. The return type matches the type of the vector we
18079 insert into. Conceptually, this can be used to build a scalable vector out of
18080 non-scalable vectors, however this intrinsic can also be used on purely fixed
18083 Scalable vectors can only be inserted into other scalable vectors.
18088 The ``vec`` is the vector which ``subvec`` will be inserted into.
18089 The ``subvec`` is the vector that will be inserted.
18091 ``idx`` represents the starting element number at which ``subvec`` will be
18092 inserted. ``idx`` must be a constant multiple of ``subvec``'s known minimum
18093 vector length. If ``subvec`` is a scalable vector, ``idx`` is first scaled by
18094 the runtime scaling factor of ``subvec``. The elements of ``vec`` starting at
18095 ``idx`` are overwritten with ``subvec``. Elements ``idx`` through (``idx`` +
18096 num_elements(``subvec``) - 1) must be valid ``vec`` indices. If this condition
18097 cannot be determined statically but is false at runtime, then the result vector
18098 is a :ref:`poison value <poisonvalues>`.
18101 '``llvm.vector.extract``' Intrinsic
18102 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18106 This is an overloaded intrinsic.
18110 ; Extract fixed type from scalable type
18111 declare <4 x float> @llvm.vector.extract.v4f32.nxv4f32(<vscale x 4 x float> %vec, i64 <idx>)
18112 declare <2 x double> @llvm.vector.extract.v2f64.nxv2f64(<vscale x 2 x double> %vec, i64 <idx>)
18114 ; Extract scalable type from scalable type
18115 declare <vscale x 2 x float> @llvm.vector.extract.nxv2f32.nxv4f32(<vscale x 4 x float> %vec, i64 <idx>)
18117 ; Extract fixed type from fixed type
18118 declare <2 x double> @llvm.vector.extract.v2f64.v4f64(<4 x double> %vec, i64 <idx>)
18123 The '``llvm.vector.extract.*``' intrinsics extract a vector from within another
18124 vector starting from a given index. The return type must be explicitly
18125 specified. Conceptually, this can be used to decompose a scalable vector into
18126 non-scalable parts, however this intrinsic can also be used on purely fixed
18129 Scalable vectors can only be extracted from other scalable vectors.
18134 The ``vec`` is the vector from which we will extract a subvector.
18136 The ``idx`` specifies the starting element number within ``vec`` from which a
18137 subvector is extracted. ``idx`` must be a constant multiple of the known-minimum
18138 vector length of the result type. If the result type is a scalable vector,
18139 ``idx`` is first scaled by the result type's runtime scaling factor. Elements
18140 ``idx`` through (``idx`` + num_elements(result_type) - 1) must be valid vector
18141 indices. If this condition cannot be determined statically but is false at
18142 runtime, then the result vector is a :ref:`poison value <poisonvalues>`. The
18143 ``idx`` parameter must be a vector index constant type (for most targets this
18144 will be an integer pointer type).
18146 '``llvm.experimental.vector.reverse``' Intrinsic
18147 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18151 This is an overloaded intrinsic.
18155 declare <2 x i8> @llvm.experimental.vector.reverse.v2i8(<2 x i8> %a)
18156 declare <vscale x 4 x i32> @llvm.experimental.vector.reverse.nxv4i32(<vscale x 4 x i32> %a)
18161 The '``llvm.experimental.vector.reverse.*``' intrinsics reverse a vector.
18162 The intrinsic takes a single vector and returns a vector of matching type but
18163 with the original lane order reversed. These intrinsics work for both fixed
18164 and scalable vectors. While this intrinsic is marked as experimental the
18165 recommended way to express reverse operations for fixed-width vectors is still
18166 to use a shufflevector, as that may allow for more optimization opportunities.
18171 The argument to this intrinsic must be a vector.
18173 '``llvm.experimental.vector.deinterleave2``' Intrinsic
18174 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18178 This is an overloaded intrinsic.
18182 declare {<2 x double>, <2 x double>} @llvm.experimental.vector.deinterleave2.v4f64(<4 x double> %vec1)
18183 declare {<vscale x 4 x i32>, <vscale x 4 x i32>} @llvm.experimental.vector.deinterleave2.nxv8i32(<vscale x 8 x i32> %vec1)
18188 The '``llvm.experimental.vector.deinterleave2``' intrinsic constructs two
18189 vectors by deinterleaving the even and odd lanes of the input vector.
18191 This intrinsic works for both fixed and scalable vectors. While this intrinsic
18192 supports all vector types the recommended way to express this operation for
18193 fixed-width vectors is still to use a shufflevector, as that may allow for more
18194 optimization opportunities.
18198 .. code-block:: text
18200 {<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>}
18205 The argument is a vector whose type corresponds to the logical concatenation of
18206 the two result types.
18208 '``llvm.experimental.vector.interleave2``' Intrinsic
18209 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18213 This is an overloaded intrinsic.
18217 declare <4 x double> @llvm.experimental.vector.interleave2.v4f64(<2 x double> %vec1, <2 x double> %vec2)
18218 declare <vscale x 8 x i32> @llvm.experimental.vector.interleave2.nxv8i32(<vscale x 4 x i32> %vec1, <vscale x 4 x i32> %vec2)
18223 The '``llvm.experimental.vector.interleave2``' intrinsic constructs a vector
18224 by interleaving two input vectors.
18226 This intrinsic works for both fixed and scalable vectors. While this intrinsic
18227 supports all vector types the recommended way to express this operation for
18228 fixed-width vectors is still to use a shufflevector, as that may allow for more
18229 optimization opportunities.
18233 .. code-block:: text
18235 <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>
18239 Both arguments must be vectors of the same type whereby their logical
18240 concatenation matches the result type.
18242 '``llvm.experimental.vector.splice``' Intrinsic
18243 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18247 This is an overloaded intrinsic.
18251 declare <2 x double> @llvm.experimental.vector.splice.v2f64(<2 x double> %vec1, <2 x double> %vec2, i32 %imm)
18252 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)
18257 The '``llvm.experimental.vector.splice.*``' intrinsics construct a vector by
18258 concatenating elements from the first input vector with elements of the second
18259 input vector, returning a vector of the same type as the input vectors. The
18260 signed immediate, modulo the number of elements in the vector, is the index
18261 into the first vector from which to extract the result value. This means
18262 conceptually that for a positive immediate, a vector is extracted from
18263 ``concat(%vec1, %vec2)`` starting at index ``imm``, whereas for a negative
18264 immediate, it extracts ``-imm`` trailing elements from the first vector, and
18265 the remaining elements from ``%vec2``.
18267 These intrinsics work for both fixed and scalable vectors. While this intrinsic
18268 is marked as experimental, the recommended way to express this operation for
18269 fixed-width vectors is still to use a shufflevector, as that may allow for more
18270 optimization opportunities.
18274 .. code-block:: text
18276 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, 1) ==> <B, C, D, E> ; index
18277 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, -3) ==> <B, C, D, E> ; trailing elements
18283 The first two operands are vectors with the same type. The start index is imm
18284 modulo the runtime number of elements in the source vector. For a fixed-width
18285 vector <N x eltty>, imm is a signed integer constant in the range
18286 -N <= imm < N. For a scalable vector <vscale x N x eltty>, imm is a signed
18287 integer constant in the range -X <= imm < X where X=vscale_range_min * N.
18289 '``llvm.experimental.stepvector``' Intrinsic
18290 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18292 This is an overloaded intrinsic. You can use ``llvm.experimental.stepvector``
18293 to generate a vector whose lane values comprise the linear sequence
18294 <0, 1, 2, ...>. It is primarily intended for scalable vectors.
18298 declare <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
18299 declare <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16()
18301 The '``llvm.experimental.stepvector``' intrinsics are used to create vectors
18302 of integers whose elements contain a linear sequence of values starting from 0
18303 with a step of 1. This experimental intrinsic can only be used for vectors
18304 with integer elements that are at least 8 bits in size. If the sequence value
18305 exceeds the allowed limit for the element type then the result for that lane is
18308 These intrinsics work for both fixed and scalable vectors. While this intrinsic
18309 is marked as experimental, the recommended way to express this operation for
18310 fixed-width vectors is still to generate a constant vector instead.
18319 '``llvm.experimental.get.vector.length``' Intrinsic
18320 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18324 This is an overloaded intrinsic.
18328 declare i32 @llvm.experimental.get.vector.length.i32(i32 %cnt, i32 immarg %vf, i1 immarg %scalable)
18329 declare i32 @llvm.experimental.get.vector.length.i64(i64 %cnt, i32 immarg %vf, i1 immarg %scalable)
18334 The '``llvm.experimental.get.vector.length.*``' intrinsics take a number of
18335 elements to process and returns how many of the elements can be processed
18336 with the requested vectorization factor.
18341 The first argument is an unsigned value of any scalar integer type and specifies
18342 the total number of elements to be processed. The second argument is an i32
18343 immediate for the vectorization factor. The third argument indicates if the
18344 vectorization factor should be multiplied by vscale.
18349 Returns a positive i32 value (explicit vector length) that is unknown at compile
18350 time and depends on the hardware specification.
18351 If the result value does not fit in the result type, then the result is
18352 a :ref:`poison value <poisonvalues>`.
18354 This intrinsic is intended to be used by loop vectorization with VP intrinsics
18355 in order to get the number of elements to process on each loop iteration. The
18356 result should be used to decrease the count for the next iteration until the
18357 count reaches zero.
18359 If the count is larger than the number of lanes in the type described by the
18360 last 2 arguments, this intrinsic may return a value less than the number of
18361 lanes implied by the type. The result will be at least as large as the result
18362 will be on any later loop iteration.
18364 This intrinsic will only return 0 if the input count is also 0. A non-zero input
18365 count will produce a non-zero result.
18370 Operations on matrixes requiring shape information (like number of rows/columns
18371 or the memory layout) can be expressed using the matrix intrinsics. These
18372 intrinsics require matrix dimensions to be passed as immediate arguments, and
18373 matrixes are passed and returned as vectors. This means that for a ``R`` x
18374 ``C`` matrix, element ``i`` of column ``j`` is at index ``j * R + i`` in the
18375 corresponding vector, with indices starting at 0. Currently column-major layout
18376 is assumed. The intrinsics support both integer and floating point matrixes.
18379 '``llvm.matrix.transpose.*``' Intrinsic
18380 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18384 This is an overloaded intrinsic.
18388 declare vectorty @llvm.matrix.transpose.*(vectorty %In, i32 <Rows>, i32 <Cols>)
18393 The '``llvm.matrix.transpose.*``' intrinsics treat ``%In`` as a ``<Rows> x
18394 <Cols>`` matrix and return the transposed matrix in the result vector.
18399 The first argument ``%In`` is a vector that corresponds to a ``<Rows> x
18400 <Cols>`` matrix. Thus, arguments ``<Rows>`` and ``<Cols>`` correspond to the
18401 number of rows and columns, respectively, and must be positive, constant
18402 integers. The returned vector must have ``<Rows> * <Cols>`` elements, and have
18403 the same float or integer element type as ``%In``.
18405 '``llvm.matrix.multiply.*``' Intrinsic
18406 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18410 This is an overloaded intrinsic.
18414 declare vectorty @llvm.matrix.multiply.*(vectorty %A, vectorty %B, i32 <OuterRows>, i32 <Inner>, i32 <OuterColumns>)
18419 The '``llvm.matrix.multiply.*``' intrinsics treat ``%A`` as a ``<OuterRows> x
18420 <Inner>`` matrix, ``%B`` as a ``<Inner> x <OuterColumns>`` matrix, and
18421 multiplies them. The result matrix is returned in the result vector.
18426 The first vector argument ``%A`` corresponds to a matrix with ``<OuterRows> *
18427 <Inner>`` elements, and the second argument ``%B`` to a matrix with
18428 ``<Inner> * <OuterColumns>`` elements. Arguments ``<OuterRows>``,
18429 ``<Inner>`` and ``<OuterColumns>`` must be positive, constant integers. The
18430 returned vector must have ``<OuterRows> * <OuterColumns>`` elements.
18431 Vectors ``%A``, ``%B``, and the returned vector all have the same float or
18432 integer element type.
18435 '``llvm.matrix.column.major.load.*``' Intrinsic
18436 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18440 This is an overloaded intrinsic.
18444 declare vectorty @llvm.matrix.column.major.load.*(
18445 ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>)
18450 The '``llvm.matrix.column.major.load.*``' intrinsics load a ``<Rows> x <Cols>``
18451 matrix using a stride of ``%Stride`` to compute the start address of the
18452 different columns. The offset is computed using ``%Stride``'s bitwidth. This
18453 allows for convenient loading of sub matrixes. If ``<IsVolatile>`` is true, the
18454 intrinsic is considered a :ref:`volatile memory access <volatile>`. The result
18455 matrix is returned in the result vector. If the ``%Ptr`` argument is known to
18456 be aligned to some boundary, this can be specified as an attribute on the
18462 The first argument ``%Ptr`` is a pointer type to the returned vector type, and
18463 corresponds to the start address to load from. The second argument ``%Stride``
18464 is a positive, constant integer with ``%Stride >= <Rows>``. ``%Stride`` is used
18465 to compute the column memory addresses. I.e., for a column ``C``, its start
18466 memory addresses is calculated with ``%Ptr + C * %Stride``. The third Argument
18467 ``<IsVolatile>`` is a boolean value. The fourth and fifth arguments,
18468 ``<Rows>`` and ``<Cols>``, correspond to the number of rows and columns,
18469 respectively, and must be positive, constant integers. The returned vector must
18470 have ``<Rows> * <Cols>`` elements.
18472 The :ref:`align <attr_align>` parameter attribute can be provided for the
18473 ``%Ptr`` arguments.
18476 '``llvm.matrix.column.major.store.*``' Intrinsic
18477 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18484 declare void @llvm.matrix.column.major.store.*(
18485 vectorty %In, ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>)
18490 The '``llvm.matrix.column.major.store.*``' intrinsics store the ``<Rows> x
18491 <Cols>`` matrix in ``%In`` to memory using a stride of ``%Stride`` between
18492 columns. The offset is computed using ``%Stride``'s bitwidth. If
18493 ``<IsVolatile>`` is true, the intrinsic is considered a
18494 :ref:`volatile memory access <volatile>`.
18496 If the ``%Ptr`` argument is known to be aligned to some boundary, this can be
18497 specified as an attribute on the argument.
18502 The first argument ``%In`` is a vector that corresponds to a ``<Rows> x
18503 <Cols>`` matrix to be stored to memory. The second argument ``%Ptr`` is a
18504 pointer to the vector type of ``%In``, and is the start address of the matrix
18505 in memory. The third argument ``%Stride`` is a positive, constant integer with
18506 ``%Stride >= <Rows>``. ``%Stride`` is used to compute the column memory
18507 addresses. I.e., for a column ``C``, its start memory addresses is calculated
18508 with ``%Ptr + C * %Stride``. The fourth argument ``<IsVolatile>`` is a boolean
18509 value. The arguments ``<Rows>`` and ``<Cols>`` correspond to the number of rows
18510 and columns, respectively, and must be positive, constant integers.
18512 The :ref:`align <attr_align>` parameter attribute can be provided
18513 for the ``%Ptr`` arguments.
18516 Half Precision Floating-Point Intrinsics
18517 ----------------------------------------
18519 For most target platforms, half precision floating-point is a
18520 storage-only format. This means that it is a dense encoding (in memory)
18521 but does not support computation in the format.
18523 This means that code must first load the half-precision floating-point
18524 value as an i16, then convert it to float with
18525 :ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can
18526 then be performed on the float value (including extending to double
18527 etc). To store the value back to memory, it is first converted to float
18528 if needed, then converted to i16 with
18529 :ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an
18532 .. _int_convert_to_fp16:
18534 '``llvm.convert.to.fp16``' Intrinsic
18535 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18542 declare i16 @llvm.convert.to.fp16.f32(float %a)
18543 declare i16 @llvm.convert.to.fp16.f64(double %a)
18548 The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
18549 conventional floating-point type to half precision floating-point format.
18554 The intrinsic function contains single argument - the value to be
18560 The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
18561 conventional floating-point format to half precision floating-point format. The
18562 return value is an ``i16`` which contains the converted number.
18567 .. code-block:: llvm
18569 %res = call i16 @llvm.convert.to.fp16.f32(float %a)
18570 store i16 %res, i16* @x, align 2
18572 .. _int_convert_from_fp16:
18574 '``llvm.convert.from.fp16``' Intrinsic
18575 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18582 declare float @llvm.convert.from.fp16.f32(i16 %a)
18583 declare double @llvm.convert.from.fp16.f64(i16 %a)
18588 The '``llvm.convert.from.fp16``' intrinsic function performs a
18589 conversion from half precision floating-point format to single precision
18590 floating-point format.
18595 The intrinsic function contains single argument - the value to be
18601 The '``llvm.convert.from.fp16``' intrinsic function performs a
18602 conversion from half single precision floating-point format to single
18603 precision floating-point format. The input half-float value is
18604 represented by an ``i16`` value.
18609 .. code-block:: llvm
18611 %a = load i16, ptr @x, align 2
18612 %res = call float @llvm.convert.from.fp16(i16 %a)
18614 Saturating floating-point to integer conversions
18615 ------------------------------------------------
18617 The ``fptoui`` and ``fptosi`` instructions return a
18618 :ref:`poison value <poisonvalues>` if the rounded-towards-zero value is not
18619 representable by the result type. These intrinsics provide an alternative
18620 conversion, which will saturate towards the smallest and largest representable
18621 integer values instead.
18623 '``llvm.fptoui.sat.*``' Intrinsic
18624 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18629 This is an overloaded intrinsic. You can use ``llvm.fptoui.sat`` on any
18630 floating-point argument type and any integer result type, or vectors thereof.
18631 Not all targets may support all types, however.
18635 declare i32 @llvm.fptoui.sat.i32.f32(float %f)
18636 declare i19 @llvm.fptoui.sat.i19.f64(double %f)
18637 declare <4 x i100> @llvm.fptoui.sat.v4i100.v4f128(<4 x fp128> %f)
18642 This intrinsic converts the argument into an unsigned integer using saturating
18648 The argument may be any floating-point or vector of floating-point type. The
18649 return value may be any integer or vector of integer type. The number of vector
18650 elements in argument and return must be the same.
18655 The conversion to integer is performed subject to the following rules:
18657 - If the argument is any NaN, zero is returned.
18658 - If the argument is smaller than zero (this includes negative infinity),
18660 - If the argument is larger than the largest representable unsigned integer of
18661 the result type (this includes positive infinity), the largest representable
18662 unsigned integer is returned.
18663 - Otherwise, the result of rounding the argument towards zero is returned.
18668 .. code-block:: text
18670 %a = call i8 @llvm.fptoui.sat.i8.f32(float 123.9) ; yields i8: 123
18671 %b = call i8 @llvm.fptoui.sat.i8.f32(float -5.7) ; yields i8: 0
18672 %c = call i8 @llvm.fptoui.sat.i8.f32(float 377.0) ; yields i8: 255
18673 %d = call i8 @llvm.fptoui.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0
18675 '``llvm.fptosi.sat.*``' Intrinsic
18676 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18681 This is an overloaded intrinsic. You can use ``llvm.fptosi.sat`` on any
18682 floating-point argument type and any integer result type, or vectors thereof.
18683 Not all targets may support all types, however.
18687 declare i32 @llvm.fptosi.sat.i32.f32(float %f)
18688 declare i19 @llvm.fptosi.sat.i19.f64(double %f)
18689 declare <4 x i100> @llvm.fptosi.sat.v4i100.v4f128(<4 x fp128> %f)
18694 This intrinsic converts the argument into a signed integer using saturating
18700 The argument may be any floating-point or vector of floating-point type. The
18701 return value may be any integer or vector of integer type. The number of vector
18702 elements in argument and return must be the same.
18707 The conversion to integer is performed subject to the following rules:
18709 - If the argument is any NaN, zero is returned.
18710 - If the argument is smaller than the smallest representable signed integer of
18711 the result type (this includes negative infinity), the smallest
18712 representable signed integer is returned.
18713 - If the argument is larger than the largest representable signed integer of
18714 the result type (this includes positive infinity), the largest representable
18715 signed integer is returned.
18716 - Otherwise, the result of rounding the argument towards zero is returned.
18721 .. code-block:: text
18723 %a = call i8 @llvm.fptosi.sat.i8.f32(float 23.9) ; yields i8: 23
18724 %b = call i8 @llvm.fptosi.sat.i8.f32(float -130.8) ; yields i8: -128
18725 %c = call i8 @llvm.fptosi.sat.i8.f32(float 999.0) ; yields i8: 127
18726 %d = call i8 @llvm.fptosi.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0
18728 Convergence Intrinsics
18729 ----------------------
18731 The LLVM convergence intrinsics for controlling the semantics of ``convergent``
18732 operations, which all start with the ``llvm.experimental.convergence.``
18733 prefix, are described in the :doc:`ConvergentOperations` document.
18735 .. _dbg_intrinsics:
18737 Debugger Intrinsics
18738 -------------------
18740 The LLVM debugger intrinsics (which all start with ``llvm.dbg.``
18741 prefix), are described in the `LLVM Source Level
18742 Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_
18745 Exception Handling Intrinsics
18746 -----------------------------
18748 The LLVM exception handling intrinsics (which all start with
18749 ``llvm.eh.`` prefix), are described in the `LLVM Exception
18750 Handling <ExceptionHandling.html#format-common-intrinsics>`_ document.
18752 Pointer Authentication Intrinsics
18753 ---------------------------------
18755 The LLVM pointer authentication intrinsics (which all start with
18756 ``llvm.ptrauth.`` prefix), are described in the `Pointer Authentication
18757 <PointerAuth.html#intrinsics>`_ document.
18759 .. _int_trampoline:
18761 Trampoline Intrinsics
18762 ---------------------
18764 These intrinsics make it possible to excise one parameter, marked with
18765 the :ref:`nest <nest>` attribute, from a function. The result is a
18766 callable function pointer lacking the nest parameter - the caller does
18767 not need to provide a value for it. Instead, the value to use is stored
18768 in advance in a "trampoline", a block of memory usually allocated on the
18769 stack, which also contains code to splice the nest value into the
18770 argument list. This is used to implement the GCC nested function address
18773 For example, if the function is ``i32 f(ptr nest %c, i32 %x, i32 %y)``
18774 then the resulting function pointer has signature ``i32 (i32, i32)``.
18775 It can be created as follows:
18777 .. code-block:: llvm
18779 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
18780 call ptr @llvm.init.trampoline(ptr %tramp, ptr @f, ptr %nval)
18781 %fp = call ptr @llvm.adjust.trampoline(ptr %tramp)
18783 The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to
18784 ``%val = call i32 %f(ptr %nval, i32 %x, i32 %y)``.
18788 '``llvm.init.trampoline``' Intrinsic
18789 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18796 declare void @llvm.init.trampoline(ptr <tramp>, ptr <func>, ptr <nval>)
18801 This fills the memory pointed to by ``tramp`` with executable code,
18802 turning it into a trampoline.
18807 The ``llvm.init.trampoline`` intrinsic takes three arguments, all
18808 pointers. The ``tramp`` argument must point to a sufficiently large and
18809 sufficiently aligned block of memory; this memory is written to by the
18810 intrinsic. Note that the size and the alignment are target-specific -
18811 LLVM currently provides no portable way of determining them, so a
18812 front-end that generates this intrinsic needs to have some
18813 target-specific knowledge. The ``func`` argument must hold a function.
18818 The block of memory pointed to by ``tramp`` is filled with target
18819 dependent code, turning it into a function. Then ``tramp`` needs to be
18820 passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can
18821 be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new
18822 function's signature is the same as that of ``func`` with any arguments
18823 marked with the ``nest`` attribute removed. At most one such ``nest``
18824 argument is allowed, and it must be of pointer type. Calling the new
18825 function is equivalent to calling ``func`` with the same argument list,
18826 but with ``nval`` used for the missing ``nest`` argument. If, after
18827 calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is
18828 modified, then the effect of any later call to the returned function
18829 pointer is undefined.
18833 '``llvm.adjust.trampoline``' Intrinsic
18834 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18841 declare ptr @llvm.adjust.trampoline(ptr <tramp>)
18846 This performs any required machine-specific adjustment to the address of
18847 a trampoline (passed as ``tramp``).
18852 ``tramp`` must point to a block of memory which already has trampoline
18853 code filled in by a previous call to
18854 :ref:`llvm.init.trampoline <int_it>`.
18859 On some architectures the address of the code to be executed needs to be
18860 different than the address where the trampoline is actually stored. This
18861 intrinsic returns the executable address corresponding to ``tramp``
18862 after performing the required machine specific adjustments. The pointer
18863 returned can then be :ref:`bitcast and executed <int_trampoline>`.
18868 Vector Predication Intrinsics
18869 -----------------------------
18870 VP intrinsics are intended for predicated SIMD/vector code. A typical VP
18871 operation takes a vector mask and an explicit vector length parameter as in:
18875 <W x T> llvm.vp.<opcode>.*(<W x T> %x, <W x T> %y, <W x i1> %mask, i32 %evl)
18877 The vector mask parameter (%mask) always has a vector of `i1` type, for example
18878 `<32 x i1>`. The explicit vector length parameter always has the type `i32` and
18879 is an unsigned integer value. The explicit vector length parameter (%evl) is in
18884 0 <= %evl <= W, where W is the number of vector elements
18886 Note that for :ref:`scalable vector types <t_vector>` ``W`` is the runtime
18887 length of the vector.
18889 The VP intrinsic has undefined behavior if ``%evl > W``. The explicit vector
18890 length (%evl) creates a mask, %EVLmask, with all elements ``0 <= i < %evl`` set
18891 to True, and all other lanes ``%evl <= i < W`` to False. A new mask %M is
18892 calculated with an element-wise AND from %mask and %EVLmask:
18896 M = %mask AND %EVLmask
18898 A vector operation ``<opcode>`` on vectors ``A`` and ``B`` calculates:
18902 A <opcode> B = { A[i] <opcode> B[i] M[i] = True, and
18908 Some targets, such as AVX512, do not support the %evl parameter in hardware.
18909 The use of an effective %evl is discouraged for those targets. The function
18910 ``TargetTransformInfo::hasActiveVectorLength()`` returns true when the target
18911 has native support for %evl.
18915 '``llvm.vp.select.*``' Intrinsics
18916 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18920 This is an overloaded intrinsic.
18924 declare <16 x i32> @llvm.vp.select.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <evl>)
18925 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>)
18930 The '``llvm.vp.select``' intrinsic is used to choose one value based on a
18931 condition vector, without IR-level branching.
18936 The first operand is a vector of ``i1`` and indicates the condition. The
18937 second operand is the value that is selected where the condition vector is
18938 true. The third operand is the value that is selected where the condition
18939 vector is false. The vectors must be of the same size. The fourth operand is
18940 the explicit vector length.
18942 #. The optional ``fast-math flags`` marker indicates that the select has one or
18943 more :ref:`fast-math flags <fastmath>`. These are optimization hints to
18944 enable otherwise unsafe floating-point optimizations. Fast-math flags are
18945 only valid for selects that return a floating-point scalar or vector type,
18946 or an array (nested to any depth) of floating-point scalar or vector types.
18951 The intrinsic selects lanes from the second and third operand depending on a
18954 All result lanes at positions greater or equal than ``%evl`` are undefined.
18955 For all lanes below ``%evl`` where the condition vector is true the lane is
18956 taken from the second operand. Otherwise, the lane is taken from the third
18962 .. code-block:: llvm
18964 %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)
18967 ;; Any result is legal on lanes at and above %evl.
18968 %also.r = select <4 x i1> %cond, <4 x i32> %on_true, <4 x i32> %on_false
18973 '``llvm.vp.merge.*``' Intrinsics
18974 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18978 This is an overloaded intrinsic.
18982 declare <16 x i32> @llvm.vp.merge.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <pivot>)
18983 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>)
18988 The '``llvm.vp.merge``' intrinsic is used to choose one value based on a
18989 condition vector and an index operand, without IR-level branching.
18994 The first operand is a vector of ``i1`` and indicates the condition. The
18995 second operand is the value that is merged where the condition vector is true.
18996 The third operand is the value that is selected where the condition vector is
18997 false or the lane position is greater equal than the pivot. The fourth operand
19000 #. The optional ``fast-math flags`` marker indicates that the merge has one or
19001 more :ref:`fast-math flags <fastmath>`. These are optimization hints to
19002 enable otherwise unsafe floating-point optimizations. Fast-math flags are
19003 only valid for merges that return a floating-point scalar or vector type,
19004 or an array (nested to any depth) of floating-point scalar or vector types.
19009 The intrinsic selects lanes from the second and third operand depending on a
19010 condition vector and pivot value.
19012 For all lanes where the condition vector is true and the lane position is less
19013 than ``%pivot`` the lane is taken from the second operand. Otherwise, the lane
19014 is taken from the third operand.
19019 .. code-block:: llvm
19021 %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)
19024 ;; Lanes at and above %pivot are taken from %on_false
19025 %atfirst = insertelement <4 x i32> undef, i32 %pivot, i32 0
19026 %splat = shufflevector <4 x i32> %atfirst, <4 x i32> poison, <4 x i32> zeroinitializer
19027 %pivotmask = icmp ult <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32> %splat
19028 %mergemask = and <4 x i1> %cond, <4 x i1> %pivotmask
19029 %also.r = select <4 x i1> %mergemask, <4 x i32> %on_true, <4 x i32> %on_false
19035 '``llvm.vp.add.*``' Intrinsics
19036 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19040 This is an overloaded intrinsic.
19044 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>)
19045 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>)
19046 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>)
19051 Predicated integer addition of two vectors of integers.
19057 The first two operands and the result have the same vector of integer type. The
19058 third operand is the vector mask and has the same number of elements as the
19059 result vector type. The fourth operand is the explicit vector length of the
19065 The '``llvm.vp.add``' intrinsic performs integer addition (:ref:`add <i_add>`)
19066 of the first and second vector operand on each enabled lane. The result on
19067 disabled lanes is a :ref:`poison value <poisonvalues>`.
19072 .. code-block:: llvm
19074 %r = call <4 x i32> @llvm.vp.add.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19075 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19077 %t = add <4 x i32> %a, %b
19078 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19082 '``llvm.vp.sub.*``' Intrinsics
19083 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19087 This is an overloaded intrinsic.
19091 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>)
19092 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>)
19093 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>)
19098 Predicated integer subtraction of two vectors of integers.
19104 The first two operands and the result have the same vector of integer type. The
19105 third operand is the vector mask and has the same number of elements as the
19106 result vector type. The fourth operand is the explicit vector length of the
19112 The '``llvm.vp.sub``' intrinsic performs integer subtraction
19113 (:ref:`sub <i_sub>`) of the first and second vector operand on each enabled
19114 lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19119 .. code-block:: llvm
19121 %r = call <4 x i32> @llvm.vp.sub.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19122 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19124 %t = sub <4 x i32> %a, %b
19125 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19131 '``llvm.vp.mul.*``' Intrinsics
19132 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19136 This is an overloaded intrinsic.
19140 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>)
19141 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>)
19142 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>)
19147 Predicated integer multiplication of two vectors of integers.
19153 The first two operands and the result have the same vector of integer type. The
19154 third operand is the vector mask and has the same number of elements as the
19155 result vector type. The fourth operand is the explicit vector length of the
19160 The '``llvm.vp.mul``' intrinsic performs integer multiplication
19161 (:ref:`mul <i_mul>`) of the first and second vector operand on each enabled
19162 lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19167 .. code-block:: llvm
19169 %r = call <4 x i32> @llvm.vp.mul.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19170 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19172 %t = mul <4 x i32> %a, %b
19173 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19178 '``llvm.vp.sdiv.*``' Intrinsics
19179 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19183 This is an overloaded intrinsic.
19187 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>)
19188 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>)
19189 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>)
19194 Predicated, signed division of two vectors of integers.
19200 The first two operands and the result have the same vector of integer type. The
19201 third operand is the vector mask and has the same number of elements as the
19202 result vector type. The fourth operand is the explicit vector length of the
19208 The '``llvm.vp.sdiv``' intrinsic performs signed division (:ref:`sdiv <i_sdiv>`)
19209 of the first and second vector operand on each enabled lane. The result on
19210 disabled lanes is a :ref:`poison value <poisonvalues>`.
19215 .. code-block:: llvm
19217 %r = call <4 x i32> @llvm.vp.sdiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19218 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19220 %t = sdiv <4 x i32> %a, %b
19221 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19226 '``llvm.vp.udiv.*``' Intrinsics
19227 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19231 This is an overloaded intrinsic.
19235 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>)
19236 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>)
19237 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>)
19242 Predicated, unsigned division of two vectors of integers.
19248 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.
19253 The '``llvm.vp.udiv``' intrinsic performs unsigned division
19254 (:ref:`udiv <i_udiv>`) of the first and second vector operand on each enabled
19255 lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19260 .. code-block:: llvm
19262 %r = call <4 x i32> @llvm.vp.udiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19263 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19265 %t = udiv <4 x i32> %a, %b
19266 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19272 '``llvm.vp.srem.*``' Intrinsics
19273 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19277 This is an overloaded intrinsic.
19281 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>)
19282 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>)
19283 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>)
19288 Predicated computations of the signed remainder of two integer vectors.
19294 The first two operands and the result have the same vector of integer type. The
19295 third operand is the vector mask and has the same number of elements as the
19296 result vector type. The fourth operand is the explicit vector length of the
19302 The '``llvm.vp.srem``' intrinsic computes the remainder of the signed division
19303 (:ref:`srem <i_srem>`) of the first and second vector operand on each enabled
19304 lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19309 .. code-block:: llvm
19311 %r = call <4 x i32> @llvm.vp.srem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19312 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19314 %t = srem <4 x i32> %a, %b
19315 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19321 '``llvm.vp.urem.*``' Intrinsics
19322 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19326 This is an overloaded intrinsic.
19330 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>)
19331 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>)
19332 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>)
19337 Predicated computation of the unsigned remainder of two integer vectors.
19343 The first two operands and the result have the same vector of integer type. The
19344 third operand is the vector mask and has the same number of elements as the
19345 result vector type. The fourth operand is the explicit vector length of the
19351 The '``llvm.vp.urem``' intrinsic computes the remainder of the unsigned division
19352 (:ref:`urem <i_urem>`) of the first and second vector operand on each enabled
19353 lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19358 .. code-block:: llvm
19360 %r = call <4 x i32> @llvm.vp.urem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19361 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19363 %t = urem <4 x i32> %a, %b
19364 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19369 '``llvm.vp.ashr.*``' Intrinsics
19370 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19374 This is an overloaded intrinsic.
19378 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>)
19379 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>)
19380 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>)
19385 Vector-predicated arithmetic right-shift.
19391 The first two operands and the result have the same vector of integer type. The
19392 third operand is the vector mask and has the same number of elements as the
19393 result vector type. The fourth operand is the explicit vector length of the
19399 The '``llvm.vp.ashr``' intrinsic computes the arithmetic right shift
19400 (:ref:`ashr <i_ashr>`) of the first operand by the second operand on each
19401 enabled lane. The result on disabled lanes is a
19402 :ref:`poison value <poisonvalues>`.
19407 .. code-block:: llvm
19409 %r = call <4 x i32> @llvm.vp.ashr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19410 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19412 %t = ashr <4 x i32> %a, %b
19413 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19419 '``llvm.vp.lshr.*``' Intrinsics
19420 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19424 This is an overloaded intrinsic.
19428 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>)
19429 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>)
19430 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>)
19435 Vector-predicated logical right-shift.
19441 The first two operands and the result have the same vector of integer type. The
19442 third operand is the vector mask and has the same number of elements as the
19443 result vector type. The fourth operand is the explicit vector length of the
19449 The '``llvm.vp.lshr``' intrinsic computes the logical right shift
19450 (:ref:`lshr <i_lshr>`) of the first operand by the second operand on each
19451 enabled lane. The result on disabled lanes is a
19452 :ref:`poison value <poisonvalues>`.
19457 .. code-block:: llvm
19459 %r = call <4 x i32> @llvm.vp.lshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19460 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19462 %t = lshr <4 x i32> %a, %b
19463 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19468 '``llvm.vp.shl.*``' Intrinsics
19469 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19473 This is an overloaded intrinsic.
19477 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>)
19478 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>)
19479 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>)
19484 Vector-predicated left shift.
19490 The first two operands and the result have the same vector of integer type. The
19491 third operand is the vector mask and has the same number of elements as the
19492 result vector type. The fourth operand is the explicit vector length of the
19498 The '``llvm.vp.shl``' intrinsic computes the left shift (:ref:`shl <i_shl>`) of
19499 the first operand by the second operand on each enabled lane. The result on
19500 disabled lanes is a :ref:`poison value <poisonvalues>`.
19505 .. code-block:: llvm
19507 %r = call <4 x i32> @llvm.vp.shl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19508 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19510 %t = shl <4 x i32> %a, %b
19511 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19516 '``llvm.vp.or.*``' Intrinsics
19517 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19521 This is an overloaded intrinsic.
19525 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>)
19526 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>)
19527 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>)
19532 Vector-predicated or.
19538 The first two operands and the result have the same vector of integer type. The
19539 third operand is the vector mask and has the same number of elements as the
19540 result vector type. The fourth operand is the explicit vector length of the
19546 The '``llvm.vp.or``' intrinsic performs a bitwise or (:ref:`or <i_or>`) of the
19547 first two operands on each enabled lane. The result on disabled lanes is
19548 a :ref:`poison value <poisonvalues>`.
19553 .. code-block:: llvm
19555 %r = call <4 x i32> @llvm.vp.or.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19556 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19558 %t = or <4 x i32> %a, %b
19559 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19564 '``llvm.vp.and.*``' Intrinsics
19565 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19569 This is an overloaded intrinsic.
19573 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>)
19574 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>)
19575 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>)
19580 Vector-predicated and.
19586 The first two operands and the result have the same vector of integer type. The
19587 third operand is the vector mask and has the same number of elements as the
19588 result vector type. The fourth operand is the explicit vector length of the
19594 The '``llvm.vp.and``' intrinsic performs a bitwise and (:ref:`and <i_or>`) of
19595 the first two operands on each enabled lane. The result on disabled lanes is
19596 a :ref:`poison value <poisonvalues>`.
19601 .. code-block:: llvm
19603 %r = call <4 x i32> @llvm.vp.and.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19604 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19606 %t = and <4 x i32> %a, %b
19607 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19612 '``llvm.vp.xor.*``' Intrinsics
19613 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19617 This is an overloaded intrinsic.
19621 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>)
19622 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>)
19623 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>)
19628 Vector-predicated, bitwise xor.
19634 The first two operands and the result have the same vector of integer type. The
19635 third operand is the vector mask and has the same number of elements as the
19636 result vector type. The fourth operand is the explicit vector length of the
19642 The '``llvm.vp.xor``' intrinsic performs a bitwise xor (:ref:`xor <i_xor>`) of
19643 the first two operands on each enabled lane.
19644 The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19649 .. code-block:: llvm
19651 %r = call <4 x i32> @llvm.vp.xor.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19652 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19654 %t = xor <4 x i32> %a, %b
19655 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19659 '``llvm.vp.abs.*``' Intrinsics
19660 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19664 This is an overloaded intrinsic.
19668 declare <16 x i32> @llvm.vp.abs.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>, i1 <is_int_min_poison>)
19669 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>)
19670 declare <256 x i64> @llvm.vp.abs.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>, i1 <is_int_min_poison>)
19675 Predicated abs of a vector of integers.
19681 The first operand and the result have the same vector of integer type. The
19682 second operand is the vector mask and has the same number of elements as the
19683 result vector type. The third operand is the explicit vector length of the
19684 operation. The fourth argument must be a constant and is a flag to indicate
19685 whether the result value of the '``llvm.vp.abs``' intrinsic is a
19686 :ref:`poison value <poisonvalues>` if the argument is statically or dynamically
19687 an ``INT_MIN`` value.
19692 The '``llvm.vp.abs``' intrinsic performs abs (:ref:`abs <int_abs>`) of the first operand on each
19693 enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
19698 .. code-block:: llvm
19700 %r = call <4 x i32> @llvm.vp.abs.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl, i1 false)
19701 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19703 %t = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %a, i1 false)
19704 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19710 '``llvm.vp.smax.*``' Intrinsics
19711 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19715 This is an overloaded intrinsic.
19719 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>)
19720 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>)
19721 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>)
19726 Predicated integer signed maximum of two vectors of integers.
19732 The first two operands and the result have the same vector of integer type. The
19733 third operand is the vector mask and has the same number of elements as the
19734 result vector type. The fourth operand is the explicit vector length of the
19740 The '``llvm.vp.smax``' intrinsic performs integer signed maximum (:ref:`smax <int_smax>`)
19741 of the first and second vector operand on each enabled lane. The result on
19742 disabled lanes is a :ref:`poison value <poisonvalues>`.
19747 .. code-block:: llvm
19749 %r = call <4 x i32> @llvm.vp.smax.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19750 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19752 %t = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> %b)
19753 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19758 '``llvm.vp.smin.*``' Intrinsics
19759 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19763 This is an overloaded intrinsic.
19767 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>)
19768 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>)
19769 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>)
19774 Predicated integer signed minimum of two vectors of integers.
19780 The first two operands and the result have the same vector of integer type. The
19781 third operand is the vector mask and has the same number of elements as the
19782 result vector type. The fourth operand is the explicit vector length of the
19788 The '``llvm.vp.smin``' intrinsic performs integer signed minimum (:ref:`smin <int_smin>`)
19789 of the first and second vector operand on each enabled lane. The result on
19790 disabled lanes is a :ref:`poison value <poisonvalues>`.
19795 .. code-block:: llvm
19797 %r = call <4 x i32> @llvm.vp.smin.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19798 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19800 %t = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> %b)
19801 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19806 '``llvm.vp.umax.*``' Intrinsics
19807 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19811 This is an overloaded intrinsic.
19815 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>)
19816 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>)
19817 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>)
19822 Predicated integer unsigned maximum of two vectors of integers.
19828 The first two operands and the result have the same vector of integer type. The
19829 third operand is the vector mask and has the same number of elements as the
19830 result vector type. The fourth operand is the explicit vector length of the
19836 The '``llvm.vp.umax``' intrinsic performs integer unsigned maximum (:ref:`umax <int_umax>`)
19837 of the first and second vector operand on each enabled lane. The result on
19838 disabled lanes is a :ref:`poison value <poisonvalues>`.
19843 .. code-block:: llvm
19845 %r = call <4 x i32> @llvm.vp.umax.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19846 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19848 %t = call <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> %b)
19849 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19854 '``llvm.vp.umin.*``' Intrinsics
19855 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19859 This is an overloaded intrinsic.
19863 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>)
19864 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>)
19865 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>)
19870 Predicated integer unsigned minimum of two vectors of integers.
19876 The first two operands and the result have the same vector of integer type. The
19877 third operand is the vector mask and has the same number of elements as the
19878 result vector type. The fourth operand is the explicit vector length of the
19884 The '``llvm.vp.umin``' intrinsic performs integer unsigned minimum (:ref:`umin <int_umin>`)
19885 of the first and second vector operand on each enabled lane. The result on
19886 disabled lanes is a :ref:`poison value <poisonvalues>`.
19891 .. code-block:: llvm
19893 %r = call <4 x i32> @llvm.vp.umin.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
19894 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19896 %t = call <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> %b)
19897 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
19900 .. _int_vp_copysign:
19902 '``llvm.vp.copysign.*``' Intrinsics
19903 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19907 This is an overloaded intrinsic.
19911 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>)
19912 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>)
19913 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>)
19918 Predicated floating-point copysign of two vectors of floating-point values.
19924 The first two operands and the result have the same vector of floating-point type. The
19925 third operand is the vector mask and has the same number of elements as the
19926 result vector type. The fourth operand is the explicit vector length of the
19932 The '``llvm.vp.copysign``' intrinsic performs floating-point copysign (:ref:`copysign <int_copysign>`)
19933 of the first and second vector operand on each enabled lane. The result on
19934 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
19935 performed in the default floating-point environment.
19940 .. code-block:: llvm
19942 %r = call <4 x float> @llvm.vp.copysign.v4f32(<4 x float> %mag, <4 x float> %sign, <4 x i1> %mask, i32 %evl)
19943 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19945 %t = call <4 x float> @llvm.copysign.v4f32(<4 x float> %mag, <4 x float> %sign)
19946 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
19951 '``llvm.vp.minnum.*``' Intrinsics
19952 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19956 This is an overloaded intrinsic.
19960 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>)
19961 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>)
19962 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>)
19967 Predicated floating-point IEEE-754 minNum of two vectors of floating-point values.
19973 The first two operands and the result have the same vector of floating-point type. The
19974 third operand is the vector mask and has the same number of elements as the
19975 result vector type. The fourth operand is the explicit vector length of the
19981 The '``llvm.vp.minnum``' intrinsic performs floating-point minimum (:ref:`minnum <i_minnum>`)
19982 of the first and second vector operand on each enabled lane. The result on
19983 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
19984 performed in the default floating-point environment.
19989 .. code-block:: llvm
19991 %r = call <4 x float> @llvm.vp.minnum.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
19992 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19994 %t = call <4 x float> @llvm.minnum.v4f32(<4 x float> %a, <4 x float> %b)
19995 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20000 '``llvm.vp.maxnum.*``' Intrinsics
20001 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20005 This is an overloaded intrinsic.
20009 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>)
20010 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>)
20011 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>)
20016 Predicated floating-point IEEE-754 maxNum of two vectors of floating-point values.
20022 The first two operands and the result have the same vector of floating-point type. The
20023 third operand is the vector mask and has the same number of elements as the
20024 result vector type. The fourth operand is the explicit vector length of the
20030 The '``llvm.vp.maxnum``' intrinsic performs floating-point maximum (:ref:`maxnum <i_maxnum>`)
20031 of the first and second vector operand on each enabled lane. The result on
20032 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20033 performed in the default floating-point environment.
20038 .. code-block:: llvm
20040 %r = call <4 x float> @llvm.vp.maxnum.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
20041 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20043 %t = call <4 x float> @llvm.maxnum.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
20044 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20049 '``llvm.vp.fadd.*``' Intrinsics
20050 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20054 This is an overloaded intrinsic.
20058 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>)
20059 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>)
20060 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>)
20065 Predicated floating-point addition of two vectors of floating-point values.
20071 The first two operands and the result have the same vector of floating-point type. The
20072 third operand is the vector mask and has the same number of elements as the
20073 result vector type. The fourth operand is the explicit vector length of the
20079 The '``llvm.vp.fadd``' intrinsic performs floating-point addition (:ref:`fadd <i_fadd>`)
20080 of the first and second vector operand on each enabled lane. The result on
20081 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20082 performed in the default floating-point environment.
20087 .. code-block:: llvm
20089 %r = call <4 x float> @llvm.vp.fadd.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
20090 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20092 %t = fadd <4 x float> %a, %b
20093 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20098 '``llvm.vp.fsub.*``' Intrinsics
20099 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20103 This is an overloaded intrinsic.
20107 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>)
20108 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>)
20109 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>)
20114 Predicated floating-point subtraction of two vectors of floating-point values.
20120 The first two operands and the result have the same vector of floating-point type. The
20121 third operand is the vector mask and has the same number of elements as the
20122 result vector type. The fourth operand is the explicit vector length of the
20128 The '``llvm.vp.fsub``' intrinsic performs floating-point subtraction (:ref:`fsub <i_fsub>`)
20129 of the first and second vector operand on each enabled lane. The result on
20130 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20131 performed in the default floating-point environment.
20136 .. code-block:: llvm
20138 %r = call <4 x float> @llvm.vp.fsub.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
20139 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20141 %t = fsub <4 x float> %a, %b
20142 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20147 '``llvm.vp.fmul.*``' Intrinsics
20148 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20152 This is an overloaded intrinsic.
20156 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>)
20157 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>)
20158 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>)
20163 Predicated floating-point multiplication of two vectors of floating-point values.
20169 The first two operands and the result have the same vector of floating-point type. The
20170 third operand is the vector mask and has the same number of elements as the
20171 result vector type. The fourth operand is the explicit vector length of the
20177 The '``llvm.vp.fmul``' intrinsic performs floating-point multiplication (:ref:`fmul <i_fmul>`)
20178 of the first and second vector operand on each enabled lane. The result on
20179 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20180 performed in the default floating-point environment.
20185 .. code-block:: llvm
20187 %r = call <4 x float> @llvm.vp.fmul.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
20188 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20190 %t = fmul <4 x float> %a, %b
20191 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20196 '``llvm.vp.fdiv.*``' Intrinsics
20197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20201 This is an overloaded intrinsic.
20205 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>)
20206 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>)
20207 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>)
20212 Predicated floating-point division of two vectors of floating-point values.
20218 The first two operands and the result have the same vector of floating-point type. The
20219 third operand is the vector mask and has the same number of elements as the
20220 result vector type. The fourth operand is the explicit vector length of the
20226 The '``llvm.vp.fdiv``' intrinsic performs floating-point division (:ref:`fdiv <i_fdiv>`)
20227 of the first and second vector operand on each enabled lane. The result on
20228 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20229 performed in the default floating-point environment.
20234 .. code-block:: llvm
20236 %r = call <4 x float> @llvm.vp.fdiv.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
20237 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20239 %t = fdiv <4 x float> %a, %b
20240 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20245 '``llvm.vp.frem.*``' Intrinsics
20246 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20250 This is an overloaded intrinsic.
20254 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>)
20255 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>)
20256 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>)
20261 Predicated floating-point remainder of two vectors of floating-point values.
20267 The first two operands and the result have the same vector of floating-point type. The
20268 third operand is the vector mask and has the same number of elements as the
20269 result vector type. The fourth operand is the explicit vector length of the
20275 The '``llvm.vp.frem``' intrinsic performs floating-point remainder (:ref:`frem <i_frem>`)
20276 of the first and second vector operand on each enabled lane. The result on
20277 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20278 performed in the default floating-point environment.
20283 .. code-block:: llvm
20285 %r = call <4 x float> @llvm.vp.frem.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
20286 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20288 %t = frem <4 x float> %a, %b
20289 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20294 '``llvm.vp.fneg.*``' Intrinsics
20295 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20299 This is an overloaded intrinsic.
20303 declare <16 x float> @llvm.vp.fneg.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
20304 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>)
20305 declare <256 x double> @llvm.vp.fneg.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
20310 Predicated floating-point negation of a vector of floating-point values.
20316 The first operand and the result have the same vector of floating-point type.
20317 The second operand is the vector mask and has the same number of elements as the
20318 result vector type. The third operand is the explicit vector length of the
20324 The '``llvm.vp.fneg``' intrinsic performs floating-point negation (:ref:`fneg <i_fneg>`)
20325 of the first vector operand on each enabled lane. The result on disabled lanes
20326 is a :ref:`poison value <poisonvalues>`.
20331 .. code-block:: llvm
20333 %r = call <4 x float> @llvm.vp.fneg.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
20334 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20336 %t = fneg <4 x float> %a
20337 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20342 '``llvm.vp.fabs.*``' Intrinsics
20343 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20347 This is an overloaded intrinsic.
20351 declare <16 x float> @llvm.vp.fabs.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
20352 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>)
20353 declare <256 x double> @llvm.vp.fabs.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
20358 Predicated floating-point absolute value of a vector of floating-point values.
20364 The first operand and the result have the same vector of floating-point type.
20365 The second operand is the vector mask and has the same number of elements as the
20366 result vector type. The third operand is the explicit vector length of the
20372 The '``llvm.vp.fabs``' intrinsic performs floating-point absolute value
20373 (:ref:`fabs <int_fabs>`) of the first vector operand on each enabled lane. The
20374 result on disabled lanes is a :ref:`poison value <poisonvalues>`.
20379 .. code-block:: llvm
20381 %r = call <4 x float> @llvm.vp.fabs.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
20382 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20384 %t = call <4 x float> @llvm.fabs.v4f32(<4 x float> %a)
20385 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20390 '``llvm.vp.sqrt.*``' Intrinsics
20391 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20395 This is an overloaded intrinsic.
20399 declare <16 x float> @llvm.vp.sqrt.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
20400 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>)
20401 declare <256 x double> @llvm.vp.sqrt.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
20406 Predicated floating-point square root of a vector of floating-point values.
20412 The first operand and the result have the same vector of floating-point type.
20413 The second operand is the vector mask and has the same number of elements as the
20414 result vector type. The third operand is the explicit vector length of the
20420 The '``llvm.vp.sqrt``' intrinsic performs floating-point square root (:ref:`sqrt <int_sqrt>`) of
20421 the first vector operand on each enabled lane. The result on disabled lanes is
20422 a :ref:`poison value <poisonvalues>`. The operation is performed in the default
20423 floating-point environment.
20428 .. code-block:: llvm
20430 %r = call <4 x float> @llvm.vp.sqrt.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
20431 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20433 %t = call <4 x float> @llvm.sqrt.v4f32(<4 x float> %a)
20434 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20439 '``llvm.vp.fma.*``' Intrinsics
20440 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20444 This is an overloaded intrinsic.
20448 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>)
20449 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>)
20450 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>)
20455 Predicated floating-point fused multiply-add of two vectors of floating-point values.
20461 The first three operands and the result have the same vector of floating-point type. The
20462 fourth operand is the vector mask and has the same number of elements as the
20463 result vector type. The fifth operand is the explicit vector length of the
20469 The '``llvm.vp.fma``' intrinsic performs floating-point fused multiply-add (:ref:`llvm.fma <int_fma>`)
20470 of the first, second, and third vector operand on each enabled lane. The result on
20471 disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20472 performed in the default floating-point environment.
20477 .. code-block:: llvm
20479 %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)
20480 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20482 %t = call <4 x float> @llvm.fma(<4 x float> %a, <4 x float> %b, <4 x float> %c)
20483 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20486 .. _int_vp_fmuladd:
20488 '``llvm.vp.fmuladd.*``' Intrinsics
20489 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20493 This is an overloaded intrinsic.
20497 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>)
20498 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>)
20499 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>)
20504 Predicated floating-point multiply-add of two vectors of floating-point values
20505 that can be fused if code generator determines that (a) the target instruction
20506 set has support for a fused operation, and (b) that the fused operation is more
20507 efficient than the equivalent, separate pair of mul and add instructions.
20512 The first three operands and the result have the same vector of floating-point
20513 type. The fourth operand is the vector mask and has the same number of elements
20514 as the result vector type. The fifth operand is the explicit vector length of
20520 The '``llvm.vp.fmuladd``' intrinsic performs floating-point multiply-add (:ref:`llvm.fuladd <int_fmuladd>`)
20521 of the first, second, and third vector operand on each enabled lane. The result
20522 on disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is
20523 performed in the default floating-point environment.
20528 .. code-block:: llvm
20530 %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)
20531 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20533 %t = call <4 x float> @llvm.fmuladd(<4 x float> %a, <4 x float> %b, <4 x float> %c)
20534 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
20537 .. _int_vp_reduce_add:
20539 '``llvm.vp.reduce.add.*``' Intrinsics
20540 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20544 This is an overloaded intrinsic.
20548 declare i32 @llvm.vp.reduce.add.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20549 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>)
20554 Predicated integer ``ADD`` reduction of a vector and a scalar starting value,
20555 returning the result as a scalar.
20560 The first operand is the start value of the reduction, which must be a scalar
20561 integer type equal to the result type. The second operand is the vector on
20562 which the reduction is performed and must be a vector of integer values whose
20563 element type is the result/start type. The third operand is the vector mask and
20564 is a vector of boolean values with the same number of elements as the vector
20565 operand. The fourth operand is the explicit vector length of the operation.
20570 The '``llvm.vp.reduce.add``' intrinsic performs the integer ``ADD`` reduction
20571 (:ref:`llvm.vector.reduce.add <int_vector_reduce_add>`) of the vector operand
20572 ``val`` on each enabled lane, adding it to the scalar ``start_value``. Disabled
20573 lanes are treated as containing the neutral value ``0`` (i.e. having no effect
20574 on the reduction operation). If the vector length is zero, the result is equal
20575 to ``start_value``.
20577 To ignore the start value, the neutral value can be used.
20582 .. code-block:: llvm
20584 %r = call i32 @llvm.vp.reduce.add.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
20585 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20586 ; are treated as though %mask were false for those lanes.
20588 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> zeroinitializer
20589 %reduction = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %masked.a)
20590 %also.r = add i32 %reduction, %start
20593 .. _int_vp_reduce_fadd:
20595 '``llvm.vp.reduce.fadd.*``' Intrinsics
20596 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20600 This is an overloaded intrinsic.
20604 declare float @llvm.vp.reduce.fadd.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>)
20605 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>)
20610 Predicated floating-point ``ADD`` reduction of a vector and a scalar starting
20611 value, returning the result as a scalar.
20616 The first operand is the start value of the reduction, which must be a scalar
20617 floating-point type equal to the result type. The second operand is the vector
20618 on which the reduction is performed and must be a vector of floating-point
20619 values whose element type is the result/start type. The third operand is the
20620 vector mask and is a vector of boolean values with the same number of elements
20621 as the vector operand. The fourth operand is the explicit vector length of the
20627 The '``llvm.vp.reduce.fadd``' intrinsic performs the floating-point ``ADD``
20628 reduction (:ref:`llvm.vector.reduce.fadd <int_vector_reduce_fadd>`) of the
20629 vector operand ``val`` on each enabled lane, adding it to the scalar
20630 ``start_value``. Disabled lanes are treated as containing the neutral value
20631 ``-0.0`` (i.e. having no effect on the reduction operation). If no lanes are
20632 enabled, the resulting value will be equal to ``start_value``.
20634 To ignore the start value, the neutral value can be used.
20636 See the unpredicated version (:ref:`llvm.vector.reduce.fadd
20637 <int_vector_reduce_fadd>`) for more detail on the semantics of the reduction.
20642 .. code-block:: llvm
20644 %r = call float @llvm.vp.reduce.fadd.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
20645 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20646 ; are treated as though %mask were false for those lanes.
20648 %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>
20649 %also.r = call float @llvm.vector.reduce.fadd.v4f32(float %start, <4 x float> %masked.a)
20652 .. _int_vp_reduce_mul:
20654 '``llvm.vp.reduce.mul.*``' Intrinsics
20655 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20659 This is an overloaded intrinsic.
20663 declare i32 @llvm.vp.reduce.mul.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20664 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>)
20669 Predicated integer ``MUL`` reduction of a vector and a scalar starting value,
20670 returning the result as a scalar.
20676 The first operand is the start value of the reduction, which must be a scalar
20677 integer type equal to the result type. The second operand is the vector on
20678 which the reduction is performed and must be a vector of integer values whose
20679 element type is the result/start type. The third operand is the vector mask and
20680 is a vector of boolean values with the same number of elements as the vector
20681 operand. The fourth operand is the explicit vector length of the operation.
20686 The '``llvm.vp.reduce.mul``' intrinsic performs the integer ``MUL`` reduction
20687 (:ref:`llvm.vector.reduce.mul <int_vector_reduce_mul>`) of the vector operand ``val``
20688 on each enabled lane, multiplying it by the scalar ``start_value``. Disabled
20689 lanes are treated as containing the neutral value ``1`` (i.e. having no effect
20690 on the reduction operation). If the vector length is zero, the result is the
20693 To ignore the start value, the neutral value can be used.
20698 .. code-block:: llvm
20700 %r = call i32 @llvm.vp.reduce.mul.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
20701 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20702 ; are treated as though %mask were false for those lanes.
20704 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
20705 %reduction = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %masked.a)
20706 %also.r = mul i32 %reduction, %start
20708 .. _int_vp_reduce_fmul:
20710 '``llvm.vp.reduce.fmul.*``' Intrinsics
20711 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20715 This is an overloaded intrinsic.
20719 declare float @llvm.vp.reduce.fmul.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>)
20720 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>)
20725 Predicated floating-point ``MUL`` reduction of a vector and a scalar starting
20726 value, returning the result as a scalar.
20732 The first operand is the start value of the reduction, which must be a scalar
20733 floating-point type equal to the result type. The second operand is the vector
20734 on which the reduction is performed and must be a vector of floating-point
20735 values whose element type is the result/start type. The third operand is the
20736 vector mask and is a vector of boolean values with the same number of elements
20737 as the vector operand. The fourth operand is the explicit vector length of the
20743 The '``llvm.vp.reduce.fmul``' intrinsic performs the floating-point ``MUL``
20744 reduction (:ref:`llvm.vector.reduce.fmul <int_vector_reduce_fmul>`) of the
20745 vector operand ``val`` on each enabled lane, multiplying it by the scalar
20746 `start_value``. Disabled lanes are treated as containing the neutral value
20747 ``1.0`` (i.e. having no effect on the reduction operation). If no lanes are
20748 enabled, the resulting value will be equal to the starting value.
20750 To ignore the start value, the neutral value can be used.
20752 See the unpredicated version (:ref:`llvm.vector.reduce.fmul
20753 <int_vector_reduce_fmul>`) for more detail on the semantics.
20758 .. code-block:: llvm
20760 %r = call float @llvm.vp.reduce.fmul.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
20761 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20762 ; are treated as though %mask were false for those lanes.
20764 %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>
20765 %also.r = call float @llvm.vector.reduce.fmul.v4f32(float %start, <4 x float> %masked.a)
20768 .. _int_vp_reduce_and:
20770 '``llvm.vp.reduce.and.*``' Intrinsics
20771 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20775 This is an overloaded intrinsic.
20779 declare i32 @llvm.vp.reduce.and.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20780 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>)
20785 Predicated integer ``AND`` reduction of a vector and a scalar starting value,
20786 returning the result as a scalar.
20792 The first operand is the start value of the reduction, which must be a scalar
20793 integer type equal to the result type. The second operand is the vector on
20794 which the reduction is performed and must be a vector of integer values whose
20795 element type is the result/start type. The third operand is the vector mask and
20796 is a vector of boolean values with the same number of elements as the vector
20797 operand. The fourth operand is the explicit vector length of the operation.
20802 The '``llvm.vp.reduce.and``' intrinsic performs the integer ``AND`` reduction
20803 (:ref:`llvm.vector.reduce.and <int_vector_reduce_and>`) of the vector operand
20804 ``val`` on each enabled lane, performing an '``and``' of that with with the
20805 scalar ``start_value``. Disabled lanes are treated as containing the neutral
20806 value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction
20807 operation). If the vector length is zero, the result is the start value.
20809 To ignore the start value, the neutral value can be used.
20814 .. code-block:: llvm
20816 %r = call i32 @llvm.vp.reduce.and.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
20817 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20818 ; are treated as though %mask were false for those lanes.
20820 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
20821 %reduction = call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %masked.a)
20822 %also.r = and i32 %reduction, %start
20825 .. _int_vp_reduce_or:
20827 '``llvm.vp.reduce.or.*``' Intrinsics
20828 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20832 This is an overloaded intrinsic.
20836 declare i32 @llvm.vp.reduce.or.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20837 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>)
20842 Predicated integer ``OR`` reduction of a vector and a scalar starting value,
20843 returning the result as a scalar.
20849 The first operand is the start value of the reduction, which must be a scalar
20850 integer type equal to the result type. The second operand is the vector on
20851 which the reduction is performed and must be a vector of integer values whose
20852 element type is the result/start type. The third operand is the vector mask and
20853 is a vector of boolean values with the same number of elements as the vector
20854 operand. The fourth operand is the explicit vector length of the operation.
20859 The '``llvm.vp.reduce.or``' intrinsic performs the integer ``OR`` reduction
20860 (:ref:`llvm.vector.reduce.or <int_vector_reduce_or>`) of the vector operand
20861 ``val`` on each enabled lane, performing an '``or``' of that with the scalar
20862 ``start_value``. Disabled lanes are treated as containing the neutral value
20863 ``0`` (i.e. having no effect on the reduction operation). If the vector length
20864 is zero, the result is the start value.
20866 To ignore the start value, the neutral value can be used.
20871 .. code-block:: llvm
20873 %r = call i32 @llvm.vp.reduce.or.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
20874 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20875 ; are treated as though %mask were false for those lanes.
20877 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
20878 %reduction = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %masked.a)
20879 %also.r = or i32 %reduction, %start
20881 .. _int_vp_reduce_xor:
20883 '``llvm.vp.reduce.xor.*``' Intrinsics
20884 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20888 This is an overloaded intrinsic.
20892 declare i32 @llvm.vp.reduce.xor.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20893 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>)
20898 Predicated integer ``XOR`` reduction of a vector and a scalar starting value,
20899 returning the result as a scalar.
20905 The first operand is the start value of the reduction, which must be a scalar
20906 integer type equal to the result type. The second operand is the vector on
20907 which the reduction is performed and must be a vector of integer values whose
20908 element type is the result/start type. The third operand is the vector mask and
20909 is a vector of boolean values with the same number of elements as the vector
20910 operand. The fourth operand is the explicit vector length of the operation.
20915 The '``llvm.vp.reduce.xor``' intrinsic performs the integer ``XOR`` reduction
20916 (:ref:`llvm.vector.reduce.xor <int_vector_reduce_xor>`) of the vector operand
20917 ``val`` on each enabled lane, performing an '``xor``' of that with the scalar
20918 ``start_value``. Disabled lanes are treated as containing the neutral value
20919 ``0`` (i.e. having no effect on the reduction operation). If the vector length
20920 is zero, the result is the start value.
20922 To ignore the start value, the neutral value can be used.
20927 .. code-block:: llvm
20929 %r = call i32 @llvm.vp.reduce.xor.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
20930 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20931 ; are treated as though %mask were false for those lanes.
20933 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
20934 %reduction = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %masked.a)
20935 %also.r = xor i32 %reduction, %start
20938 .. _int_vp_reduce_smax:
20940 '``llvm.vp.reduce.smax.*``' Intrinsics
20941 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20945 This is an overloaded intrinsic.
20949 declare i32 @llvm.vp.reduce.smax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
20950 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>)
20955 Predicated signed-integer ``MAX`` reduction of a vector and a scalar starting
20956 value, returning the result as a scalar.
20962 The first operand is the start value of the reduction, which must be a scalar
20963 integer type equal to the result type. The second operand is the vector on
20964 which the reduction is performed and must be a vector of integer values whose
20965 element type is the result/start type. The third operand is the vector mask and
20966 is a vector of boolean values with the same number of elements as the vector
20967 operand. The fourth operand is the explicit vector length of the operation.
20972 The '``llvm.vp.reduce.smax``' intrinsic performs the signed-integer ``MAX``
20973 reduction (:ref:`llvm.vector.reduce.smax <int_vector_reduce_smax>`) of the
20974 vector operand ``val`` on each enabled lane, and taking the maximum of that and
20975 the scalar ``start_value``. Disabled lanes are treated as containing the
20976 neutral value ``INT_MIN`` (i.e. having no effect on the reduction operation).
20977 If the vector length is zero, the result is the start value.
20979 To ignore the start value, the neutral value can be used.
20984 .. code-block:: llvm
20986 %r = call i8 @llvm.vp.reduce.smax.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl)
20987 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
20988 ; are treated as though %mask were false for those lanes.
20990 %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 -128, i8 -128, i8 -128, i8 -128>
20991 %reduction = call i8 @llvm.vector.reduce.smax.v4i8(<4 x i8> %masked.a)
20992 %also.r = call i8 @llvm.smax.i8(i8 %reduction, i8 %start)
20995 .. _int_vp_reduce_smin:
20997 '``llvm.vp.reduce.smin.*``' Intrinsics
20998 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21002 This is an overloaded intrinsic.
21006 declare i32 @llvm.vp.reduce.smin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
21007 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>)
21012 Predicated signed-integer ``MIN`` reduction of a vector and a scalar starting
21013 value, returning the result as a scalar.
21019 The first operand is the start value of the reduction, which must be a scalar
21020 integer type equal to the result type. The second operand is the vector on
21021 which the reduction is performed and must be a vector of integer values whose
21022 element type is the result/start type. The third operand is the vector mask and
21023 is a vector of boolean values with the same number of elements as the vector
21024 operand. The fourth operand is the explicit vector length of the operation.
21029 The '``llvm.vp.reduce.smin``' intrinsic performs the signed-integer ``MIN``
21030 reduction (:ref:`llvm.vector.reduce.smin <int_vector_reduce_smin>`) of the
21031 vector operand ``val`` on each enabled lane, and taking the minimum of that and
21032 the scalar ``start_value``. Disabled lanes are treated as containing the
21033 neutral value ``INT_MAX`` (i.e. having no effect on the reduction operation).
21034 If the vector length is zero, the result is the start value.
21036 To ignore the start value, the neutral value can be used.
21041 .. code-block:: llvm
21043 %r = call i8 @llvm.vp.reduce.smin.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl)
21044 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
21045 ; are treated as though %mask were false for those lanes.
21047 %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 127, i8 127, i8 127, i8 127>
21048 %reduction = call i8 @llvm.vector.reduce.smin.v4i8(<4 x i8> %masked.a)
21049 %also.r = call i8 @llvm.smin.i8(i8 %reduction, i8 %start)
21052 .. _int_vp_reduce_umax:
21054 '``llvm.vp.reduce.umax.*``' Intrinsics
21055 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21059 This is an overloaded intrinsic.
21063 declare i32 @llvm.vp.reduce.umax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
21064 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>)
21069 Predicated unsigned-integer ``MAX`` reduction of a vector and a scalar starting
21070 value, returning the result as a scalar.
21076 The first operand is the start value of the reduction, which must be a scalar
21077 integer type equal to the result type. The second operand is the vector on
21078 which the reduction is performed and must be a vector of integer values whose
21079 element type is the result/start type. The third operand is the vector mask and
21080 is a vector of boolean values with the same number of elements as the vector
21081 operand. The fourth operand is the explicit vector length of the operation.
21086 The '``llvm.vp.reduce.umax``' intrinsic performs the unsigned-integer ``MAX``
21087 reduction (:ref:`llvm.vector.reduce.umax <int_vector_reduce_umax>`) of the
21088 vector operand ``val`` on each enabled lane, and taking the maximum of that and
21089 the scalar ``start_value``. Disabled lanes are treated as containing the
21090 neutral value ``0`` (i.e. having no effect on the reduction operation). If the
21091 vector length is zero, the result is the start value.
21093 To ignore the start value, the neutral value can be used.
21098 .. code-block:: llvm
21100 %r = call i32 @llvm.vp.reduce.umax.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
21101 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
21102 ; are treated as though %mask were false for those lanes.
21104 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
21105 %reduction = call i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %masked.a)
21106 %also.r = call i32 @llvm.umax.i32(i32 %reduction, i32 %start)
21109 .. _int_vp_reduce_umin:
21111 '``llvm.vp.reduce.umin.*``' Intrinsics
21112 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21116 This is an overloaded intrinsic.
21120 declare i32 @llvm.vp.reduce.umin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
21121 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>)
21126 Predicated unsigned-integer ``MIN`` reduction of a vector and a scalar starting
21127 value, returning the result as a scalar.
21133 The first operand is the start value of the reduction, which must be a scalar
21134 integer type equal to the result type. The second operand is the vector on
21135 which the reduction is performed and must be a vector of integer values whose
21136 element type is the result/start type. The third operand is the vector mask and
21137 is a vector of boolean values with the same number of elements as the vector
21138 operand. The fourth operand is the explicit vector length of the operation.
21143 The '``llvm.vp.reduce.umin``' intrinsic performs the unsigned-integer ``MIN``
21144 reduction (:ref:`llvm.vector.reduce.umin <int_vector_reduce_umin>`) of the
21145 vector operand ``val`` on each enabled lane, taking the minimum of that and the
21146 scalar ``start_value``. Disabled lanes are treated as containing the neutral
21147 value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction
21148 operation). If the vector length is zero, the result is the start value.
21150 To ignore the start value, the neutral value can be used.
21155 .. code-block:: llvm
21157 %r = call i32 @llvm.vp.reduce.umin.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
21158 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
21159 ; are treated as though %mask were false for those lanes.
21161 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
21162 %reduction = call i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %masked.a)
21163 %also.r = call i32 @llvm.umin.i32(i32 %reduction, i32 %start)
21166 .. _int_vp_reduce_fmax:
21168 '``llvm.vp.reduce.fmax.*``' Intrinsics
21169 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21173 This is an overloaded intrinsic.
21177 declare float @llvm.vp.reduce.fmax.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>)
21178 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>)
21183 Predicated floating-point ``MAX`` reduction of a vector and a scalar starting
21184 value, returning the result as a scalar.
21190 The first operand is the start value of the reduction, which must be a scalar
21191 floating-point type equal to the result type. The second operand is the vector
21192 on which the reduction is performed and must be a vector of floating-point
21193 values whose element type is the result/start type. The third operand is the
21194 vector mask and is a vector of boolean values with the same number of elements
21195 as the vector operand. The fourth operand is the explicit vector length of the
21201 The '``llvm.vp.reduce.fmax``' intrinsic performs the floating-point ``MAX``
21202 reduction (:ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>`) of the
21203 vector operand ``val`` on each enabled lane, taking the maximum of that and the
21204 scalar ``start_value``. Disabled lanes are treated as containing the neutral
21205 value (i.e. having no effect on the reduction operation). If the vector length
21206 is zero, the result is the start value.
21208 The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
21209 flags are set, the neutral value is ``-QNAN``. If ``nnan`` and ``ninf`` are
21210 both set, then the neutral value is the smallest floating-point value for the
21211 result type. If only ``nnan`` is set then the neutral value is ``-Infinity``.
21213 This instruction has the same comparison semantics as the
21214 :ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>` intrinsic (and thus the
21215 '``llvm.maxnum.*``' intrinsic). That is, the result will always be a number
21216 unless all elements of the vector and the starting value are ``NaN``. For a
21217 vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and
21218 ``-0.0`` elements, the sign of the result is unspecified.
21220 To ignore the start value, the neutral value can be used.
21225 .. code-block:: llvm
21227 %r = call float @llvm.vp.reduce.fmax.v4f32(float %float, <4 x float> %a, <4 x i1> %mask, i32 %evl)
21228 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
21229 ; are treated as though %mask were false for those lanes.
21231 %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN>
21232 %reduction = call float @llvm.vector.reduce.fmax.v4f32(<4 x float> %masked.a)
21233 %also.r = call float @llvm.maxnum.f32(float %reduction, float %start)
21236 .. _int_vp_reduce_fmin:
21238 '``llvm.vp.reduce.fmin.*``' Intrinsics
21239 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21243 This is an overloaded intrinsic.
21247 declare float @llvm.vp.reduce.fmin.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>)
21248 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>)
21253 Predicated floating-point ``MIN`` reduction of a vector and a scalar starting
21254 value, returning the result as a scalar.
21260 The first operand is the start value of the reduction, which must be a scalar
21261 floating-point type equal to the result type. The second operand is the vector
21262 on which the reduction is performed and must be a vector of floating-point
21263 values whose element type is the result/start type. The third operand is the
21264 vector mask and is a vector of boolean values with the same number of elements
21265 as the vector operand. The fourth operand is the explicit vector length of the
21271 The '``llvm.vp.reduce.fmin``' intrinsic performs the floating-point ``MIN``
21272 reduction (:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>`) of the
21273 vector operand ``val`` on each enabled lane, taking the minimum of that and the
21274 scalar ``start_value``. Disabled lanes are treated as containing the neutral
21275 value (i.e. having no effect on the reduction operation). If the vector length
21276 is zero, the result is the start value.
21278 The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
21279 flags are set, the neutral value is ``+QNAN``. If ``nnan`` and ``ninf`` are
21280 both set, then the neutral value is the largest floating-point value for the
21281 result type. If only ``nnan`` is set then the neutral value is ``+Infinity``.
21283 This instruction has the same comparison semantics as the
21284 :ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>` intrinsic (and thus the
21285 '``llvm.minnum.*``' intrinsic). That is, the result will always be a number
21286 unless all elements of the vector and the starting value are ``NaN``. For a
21287 vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and
21288 ``-0.0`` elements, the sign of the result is unspecified.
21290 To ignore the start value, the neutral value can be used.
21295 .. code-block:: llvm
21297 %r = call float @llvm.vp.reduce.fmin.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
21298 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
21299 ; are treated as though %mask were false for those lanes.
21301 %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN>
21302 %reduction = call float @llvm.vector.reduce.fmin.v4f32(<4 x float> %masked.a)
21303 %also.r = call float @llvm.minnum.f32(float %reduction, float %start)
21306 .. _int_get_active_lane_mask:
21308 '``llvm.get.active.lane.mask.*``' Intrinsics
21309 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21313 This is an overloaded intrinsic.
21317 declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %base, i32 %n)
21318 declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 %base, i64 %n)
21319 declare <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 %base, i64 %n)
21320 declare <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 %base, i64 %n)
21326 Create a mask representing active and inactive vector lanes.
21332 Both operands have the same scalar integer type. The result is a vector with
21333 the i1 element type.
21338 The '``llvm.get.active.lane.mask.*``' intrinsics are semantically equivalent
21343 %m[i] = icmp ult (%base + i), %n
21345 where ``%m`` is a vector (mask) of active/inactive lanes with its elements
21346 indexed by ``i``, and ``%base``, ``%n`` are the two arguments to
21347 ``llvm.get.active.lane.mask.*``, ``%icmp`` is an integer compare and ``ult``
21348 the unsigned less-than comparison operator. Overflow cannot occur in
21349 ``(%base + i)`` and its comparison against ``%n`` as it is performed in integer
21350 numbers and not in machine numbers. If ``%n`` is ``0``, then the result is a
21351 poison value. The above is equivalent to:
21355 %m = @llvm.get.active.lane.mask(%base, %n)
21357 This can, for example, be emitted by the loop vectorizer in which case
21358 ``%base`` is the first element of the vector induction variable (VIV) and
21359 ``%n`` is the loop tripcount. Thus, these intrinsics perform an element-wise
21360 less than comparison of VIV with the loop tripcount, producing a mask of
21361 true/false values representing active/inactive vector lanes, except if the VIV
21362 overflows in which case they return false in the lanes where the VIV overflows.
21363 The arguments are scalar types to accommodate scalable vector types, for which
21364 it is unknown what the type of the step vector needs to be that enumerate its
21365 lanes without overflow.
21367 This mask ``%m`` can e.g. be used in masked load/store instructions. These
21368 intrinsics provide a hint to the backend. I.e., for a vector loop, the
21369 back-edge taken count of the original scalar loop is explicit as the second
21376 .. code-block:: llvm
21378 %active.lane.mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 %elem0, i64 429)
21379 %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)
21382 .. _int_experimental_vp_splice:
21384 '``llvm.experimental.vp.splice``' Intrinsic
21385 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21389 This is an overloaded intrinsic.
21393 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)
21394 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)
21399 The '``llvm.experimental.vp.splice.*``' intrinsic is the vector length
21400 predicated version of the '``llvm.experimental.vector.splice.*``' intrinsic.
21405 The result and the first two arguments ``vec1`` and ``vec2`` are vectors with
21406 the same type. The third argument ``imm`` is an immediate signed integer that
21407 indicates the offset index. The fourth argument ``mask`` is a vector mask and
21408 has the same number of elements as the result. The last two arguments ``evl1``
21409 and ``evl2`` are unsigned integers indicating the explicit vector lengths of
21410 ``vec1`` and ``vec2`` respectively. ``imm``, ``evl1`` and ``evl2`` should
21411 respect the following constraints: ``-evl1 <= imm < evl1``, ``0 <= evl1 <= VL``
21412 and ``0 <= evl2 <= VL``, where ``VL`` is the runtime vector factor. If these
21413 constraints are not satisfied the intrinsic has undefined behaviour.
21418 Effectively, this intrinsic concatenates ``vec1[0..evl1-1]`` and
21419 ``vec2[0..evl2-1]`` and creates the result vector by selecting the elements in a
21420 window of size ``evl2``, starting at index ``imm`` (for a positive immediate) of
21421 the concatenated vector. Elements in the result vector beyond ``evl2`` are
21422 ``undef``. If ``imm`` is negative the starting index is ``evl1 + imm``. The result
21423 vector of active vector length ``evl2`` contains ``evl1 - imm`` (``-imm`` for
21424 negative ``imm``) elements from indices ``[imm..evl1 - 1]``
21425 (``[evl1 + imm..evl1 -1]`` for negative ``imm``) of ``vec1`` followed by the
21426 first ``evl2 - (evl1 - imm)`` (``evl2 + imm`` for negative ``imm``) elements of
21427 ``vec2``. If ``evl1 - imm`` (``-imm``) >= ``evl2``, only the first ``evl2``
21428 elements are considered and the remaining are ``undef``. The lanes in the result
21429 vector disabled by ``mask`` are ``poison``.
21434 .. code-block:: text
21436 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, 1, 2, 3) ==> <B, E, F, poison> ; index
21437 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, -2, 3, 2) ==> <B, C, poison, poison> ; trailing elements
21442 '``llvm.vp.load``' Intrinsic
21443 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21447 This is an overloaded intrinsic.
21451 declare <4 x float> @llvm.vp.load.v4f32.p0(ptr %ptr, <4 x i1> %mask, i32 %evl)
21452 declare <vscale x 2 x i16> @llvm.vp.load.nxv2i16.p0(ptr %ptr, <vscale x 2 x i1> %mask, i32 %evl)
21453 declare <8 x float> @llvm.vp.load.v8f32.p1(ptr addrspace(1) %ptr, <8 x i1> %mask, i32 %evl)
21454 declare <vscale x 1 x i64> @llvm.vp.load.nxv1i64.p6(ptr addrspace(6) %ptr, <vscale x 1 x i1> %mask, i32 %evl)
21459 The '``llvm.vp.load.*``' intrinsic is the vector length predicated version of
21460 the :ref:`llvm.masked.load <int_mload>` intrinsic.
21465 The first operand is the base pointer for the load. The second operand is a
21466 vector of boolean values with the same number of elements as the return type.
21467 The third is the explicit vector length of the operation. The return type and
21468 underlying type of the base pointer are the same vector types.
21470 The :ref:`align <attr_align>` parameter attribute can be provided for the first
21476 The '``llvm.vp.load``' intrinsic reads a vector from memory in the same way as
21477 the '``llvm.masked.load``' intrinsic, where the mask is taken from the
21478 combination of the '``mask``' and '``evl``' operands in the usual VP way.
21479 Certain '``llvm.masked.load``' operands do not have corresponding operands in
21480 '``llvm.vp.load``': the '``passthru``' operand is implicitly ``poison``; the
21481 '``alignment``' operand is taken as the ``align`` parameter attribute, if
21482 provided. The default alignment is taken as the ABI alignment of the return
21483 type as specified by the :ref:`datalayout string<langref_datalayout>`.
21488 .. code-block:: text
21490 %r = call <8 x i8> @llvm.vp.load.v8i8.p0(ptr align 2 %ptr, <8 x i1> %mask, i32 %evl)
21491 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21493 %also.r = call <8 x i8> @llvm.masked.load.v8i8.p0(ptr %ptr, i32 2, <8 x i1> %mask, <8 x i8> poison)
21498 '``llvm.vp.store``' Intrinsic
21499 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21503 This is an overloaded intrinsic.
21507 declare void @llvm.vp.store.v4f32.p0(<4 x float> %val, ptr %ptr, <4 x i1> %mask, i32 %evl)
21508 declare void @llvm.vp.store.nxv2i16.p0(<vscale x 2 x i16> %val, ptr %ptr, <vscale x 2 x i1> %mask, i32 %evl)
21509 declare void @llvm.vp.store.v8f32.p1(<8 x float> %val, ptr addrspace(1) %ptr, <8 x i1> %mask, i32 %evl)
21510 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)
21515 The '``llvm.vp.store.*``' intrinsic is the vector length predicated version of
21516 the :ref:`llvm.masked.store <int_mstore>` intrinsic.
21521 The first operand is the vector value to be written to memory. The second
21522 operand is the base pointer for the store. It has the same underlying type as
21523 the value operand. The third operand is a vector of boolean values with the
21524 same number of elements as the return type. The fourth is the explicit vector
21525 length of the operation.
21527 The :ref:`align <attr_align>` parameter attribute can be provided for the
21533 The '``llvm.vp.store``' intrinsic reads a vector from memory in the same way as
21534 the '``llvm.masked.store``' intrinsic, where the mask is taken from the
21535 combination of the '``mask``' and '``evl``' operands in the usual VP way. The
21536 alignment of the operation (corresponding to the '``alignment``' operand of
21537 '``llvm.masked.store``') is specified by the ``align`` parameter attribute (see
21538 above). If it is not provided then the ABI alignment of the type of the
21539 '``value``' operand as specified by the :ref:`datalayout
21540 string<langref_datalayout>` is used instead.
21545 .. code-block:: text
21547 call void @llvm.vp.store.v8i8.p0(<8 x i8> %val, ptr align 4 %ptr, <8 x i1> %mask, i32 %evl)
21548 ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below.
21550 call void @llvm.masked.store.v8i8.p0(<8 x i8> %val, ptr %ptr, i32 4, <8 x i1> %mask)
21553 .. _int_experimental_vp_strided_load:
21555 '``llvm.experimental.vp.strided.load``' Intrinsic
21556 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21560 This is an overloaded intrinsic.
21564 declare <4 x float> @llvm.experimental.vp.strided.load.v4f32.i64(ptr %ptr, i64 %stride, <4 x i1> %mask, i32 %evl)
21565 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)
21570 The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, scalar values from
21571 memory locations evenly spaced apart by '``stride``' number of bytes, starting from '``ptr``'.
21576 The first operand is the base pointer for the load. The second operand is the stride
21577 value expressed in bytes. The third operand is a vector of boolean values
21578 with the same number of elements as the return type. The fourth is the explicit
21579 vector length of the operation. The base pointer underlying type matches the type of the scalar
21580 elements of the return operand.
21582 The :ref:`align <attr_align>` parameter attribute can be provided for the first
21588 The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, multiple scalar
21589 values from memory in the same way as the :ref:`llvm.vp.gather <int_vp_gather>` intrinsic,
21590 where the vector of pointers is in the form:
21592 ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``,
21594 with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed
21595 integer and all arithmetic occurring in the pointer type.
21600 .. code-block:: text
21602 %r = call <8 x i64> @llvm.experimental.vp.strided.load.v8i64.i64(i64* %ptr, i64 %stride, <8 x i64> %mask, i32 %evl)
21603 ;; The operation can also be expressed like this:
21605 %addr = bitcast i64* %ptr to i8*
21606 ;; Create a vector of pointers %addrs in the form:
21607 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...>
21608 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* >
21609 %also.r = call <8 x i64> @llvm.vp.gather.v8i64.v8p0i64(<8 x i64* > %ptrs, <8 x i64> %mask, i32 %evl)
21612 .. _int_experimental_vp_strided_store:
21614 '``llvm.experimental.vp.strided.store``' Intrinsic
21615 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21619 This is an overloaded intrinsic.
21623 declare void @llvm.experimental.vp.strided.store.v4f32.i64(<4 x float> %val, ptr %ptr, i64 %stride, <4 x i1> %mask, i32 %evl)
21624 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)
21629 The '``@llvm.experimental.vp.strided.store``' intrinsic stores the elements of
21630 '``val``' into memory locations evenly spaced apart by '``stride``' number of
21631 bytes, starting from '``ptr``'.
21636 The first operand is the vector value to be written to memory. The second
21637 operand is the base pointer for the store. Its underlying type matches the
21638 scalar element type of the value operand. The third operand is the stride value
21639 expressed in bytes. The fourth operand is a vector of boolean values with the
21640 same number of elements as the return type. The fifth is the explicit vector
21641 length of the operation.
21643 The :ref:`align <attr_align>` parameter attribute can be provided for the
21649 The '``llvm.experimental.vp.strided.store``' intrinsic stores the elements of
21650 '``val``' in the same way as the :ref:`llvm.vp.scatter <int_vp_scatter>` intrinsic,
21651 where the vector of pointers is in the form:
21653 ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``,
21655 with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed
21656 integer and all arithmetic occurring in the pointer type.
21661 .. code-block:: text
21663 call void @llvm.experimental.vp.strided.store.v8i64.i64(<8 x i64> %val, i64* %ptr, i64 %stride, <8 x i1> %mask, i32 %evl)
21664 ;; The operation can also be expressed like this:
21666 %addr = bitcast i64* %ptr to i8*
21667 ;; Create a vector of pointers %addrs in the form:
21668 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...>
21669 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* >
21670 call void @llvm.vp.scatter.v8i64.v8p0i64(<8 x i64> %val, <8 x i64*> %ptrs, <8 x i1> %mask, i32 %evl)
21675 '``llvm.vp.gather``' Intrinsic
21676 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21680 This is an overloaded intrinsic.
21684 declare <4 x double> @llvm.vp.gather.v4f64.v4p0(<4 x ptr> %ptrs, <4 x i1> %mask, i32 %evl)
21685 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)
21686 declare <2 x float> @llvm.vp.gather.v2f32.v2p2(<2 x ptr addrspace(2)> %ptrs, <2 x i1> %mask, i32 %evl)
21687 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)
21692 The '``llvm.vp.gather.*``' intrinsic is the vector length predicated version of
21693 the :ref:`llvm.masked.gather <int_mgather>` intrinsic.
21698 The first operand is a vector of pointers which holds all memory addresses to
21699 read. The second operand is a vector of boolean values with the same number of
21700 elements as the return type. The third is the explicit vector length of the
21701 operation. The return type and underlying type of the vector of pointers are
21702 the same vector types.
21704 The :ref:`align <attr_align>` parameter attribute can be provided for the first
21710 The '``llvm.vp.gather``' intrinsic reads multiple scalar values from memory in
21711 the same way as the '``llvm.masked.gather``' intrinsic, where the mask is taken
21712 from the combination of the '``mask``' and '``evl``' operands in the usual VP
21713 way. Certain '``llvm.masked.gather``' operands do not have corresponding
21714 operands in '``llvm.vp.gather``': the '``passthru``' operand is implicitly
21715 ``poison``; the '``alignment``' operand is taken as the ``align`` parameter, if
21716 provided. The default alignment is taken as the ABI alignment of the source
21717 addresses as specified by the :ref:`datalayout string<langref_datalayout>`.
21722 .. code-block:: text
21724 %r = call <8 x i8> @llvm.vp.gather.v8i8.v8p0(<8 x ptr> align 8 %ptrs, <8 x i1> %mask, i32 %evl)
21725 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21727 %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)
21730 .. _int_vp_scatter:
21732 '``llvm.vp.scatter``' Intrinsic
21733 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21737 This is an overloaded intrinsic.
21741 declare void @llvm.vp.scatter.v4f64.v4p0(<4 x double> %val, <4 x ptr> %ptrs, <4 x i1> %mask, i32 %evl)
21742 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)
21743 declare void @llvm.vp.scatter.v2f32.v2p2(<2 x float> %val, <2 x ptr addrspace(2)> %ptrs, <2 x i1> %mask, i32 %evl)
21744 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)
21749 The '``llvm.vp.scatter.*``' intrinsic is the vector length predicated version of
21750 the :ref:`llvm.masked.scatter <int_mscatter>` intrinsic.
21755 The first operand is a vector value to be written to memory. The second operand
21756 is a vector of pointers, pointing to where the value elements should be stored.
21757 The third operand is a vector of boolean values with the same number of
21758 elements as the return type. The fourth is the explicit vector length of the
21761 The :ref:`align <attr_align>` parameter attribute can be provided for the
21767 The '``llvm.vp.scatter``' intrinsic writes multiple scalar values to memory in
21768 the same way as the '``llvm.masked.scatter``' intrinsic, where the mask is
21769 taken from the combination of the '``mask``' and '``evl``' operands in the
21770 usual VP way. The '``alignment``' operand of the '``llvm.masked.scatter``' does
21771 not have a corresponding operand in '``llvm.vp.scatter``': it is instead
21772 provided via the optional ``align`` parameter attribute on the
21773 vector-of-pointers operand. Otherwise it is taken as the ABI alignment of the
21774 destination addresses as specified by the :ref:`datalayout
21775 string<langref_datalayout>`.
21780 .. code-block:: text
21782 call void @llvm.vp.scatter.v8i8.v8p0(<8 x i8> %val, <8 x ptr> align 1 %ptrs, <8 x i1> %mask, i32 %evl)
21783 ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below.
21785 call void @llvm.masked.scatter.v8i8.v8p0(<8 x i8> %val, <8 x ptr> %ptrs, i32 1, <8 x i1> %mask)
21790 '``llvm.vp.trunc.*``' Intrinsics
21791 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21795 This is an overloaded intrinsic.
21799 declare <16 x i16> @llvm.vp.trunc.v16i16.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
21800 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>)
21805 The '``llvm.vp.trunc``' intrinsic truncates its first operand to the return
21806 type. The operation has a mask and an explicit vector length parameter.
21812 The '``llvm.vp.trunc``' intrinsic takes a value to cast as its first operand.
21813 The return type is the type to cast the value to. Both types must be vector of
21814 :ref:`integer <t_integer>` type. The bit size of the value must be larger than
21815 the bit size of the return type. The second operand is the vector mask. The
21816 return type, the value to cast, and the vector mask have the same number of
21817 elements. The third operand is the explicit vector length of the operation.
21822 The '``llvm.vp.trunc``' intrinsic truncates the high order bits in value and
21823 converts the remaining bits to return type. Since the source size must be larger
21824 than the destination size, '``llvm.vp.trunc``' cannot be a *no-op cast*. It will
21825 always truncate bits. The conversion is performed on lane positions below the
21826 explicit vector length and where the vector mask is true. Masked-off lanes are
21832 .. code-block:: llvm
21834 %r = call <4 x i16> @llvm.vp.trunc.v4i16.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
21835 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21837 %t = trunc <4 x i32> %a to <4 x i16>
21838 %also.r = select <4 x i1> %mask, <4 x i16> %t, <4 x i16> poison
21843 '``llvm.vp.zext.*``' Intrinsics
21844 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21848 This is an overloaded intrinsic.
21852 declare <16 x i32> @llvm.vp.zext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>)
21853 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>)
21858 The '``llvm.vp.zext``' intrinsic zero extends its first operand to the return
21859 type. The operation has a mask and an explicit vector length parameter.
21865 The '``llvm.vp.zext``' intrinsic takes a value to cast as its first operand.
21866 The return type is the type to cast the value to. Both types must be vectors of
21867 :ref:`integer <t_integer>` type. The bit size of the value must be smaller than
21868 the bit size of the return type. The second operand is the vector mask. The
21869 return type, the value to cast, and the vector mask have the same number of
21870 elements. The third operand is the explicit vector length of the operation.
21875 The '``llvm.vp.zext``' intrinsic fill the high order bits of the value with zero
21876 bits until it reaches the size of the return type. When zero extending from i1,
21877 the result will always be either 0 or 1. The conversion is performed on lane
21878 positions below the explicit vector length and where the vector mask is true.
21879 Masked-off lanes are ``poison``.
21884 .. code-block:: llvm
21886 %r = call <4 x i32> @llvm.vp.zext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl)
21887 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21889 %t = zext <4 x i16> %a to <4 x i32>
21890 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
21895 '``llvm.vp.sext.*``' Intrinsics
21896 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21900 This is an overloaded intrinsic.
21904 declare <16 x i32> @llvm.vp.sext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>)
21905 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>)
21910 The '``llvm.vp.sext``' intrinsic sign extends its first operand to the return
21911 type. The operation has a mask and an explicit vector length parameter.
21917 The '``llvm.vp.sext``' intrinsic takes a value to cast as its first operand.
21918 The return type is the type to cast the value to. Both types must be vectors of
21919 :ref:`integer <t_integer>` type. The bit size of the value must be smaller than
21920 the bit size of the return type. The second operand is the vector mask. The
21921 return type, the value to cast, and the vector mask have the same number of
21922 elements. The third operand is the explicit vector length of the operation.
21927 The '``llvm.vp.sext``' intrinsic performs a sign extension by copying the sign
21928 bit (highest order bit) of the value until it reaches the size of the return
21929 type. When sign extending from i1, the result will always be either -1 or 0.
21930 The conversion is performed on lane positions below the explicit vector length
21931 and where the vector mask is true. Masked-off lanes are ``poison``.
21936 .. code-block:: llvm
21938 %r = call <4 x i32> @llvm.vp.sext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl)
21939 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21941 %t = sext <4 x i16> %a to <4 x i32>
21942 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
21945 .. _int_vp_fptrunc:
21947 '``llvm.vp.fptrunc.*``' Intrinsics
21948 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21952 This is an overloaded intrinsic.
21956 declare <16 x float> @llvm.vp.fptrunc.v16f32.v16f64 (<16 x double> <op>, <16 x i1> <mask>, i32 <vector_length>)
21957 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>)
21962 The '``llvm.vp.fptrunc``' intrinsic truncates its first operand to the return
21963 type. The operation has a mask and an explicit vector length parameter.
21969 The '``llvm.vp.fptrunc``' intrinsic takes a value to cast as its first operand.
21970 The return type is the type to cast the value to. Both types must be vector of
21971 :ref:`floating-point <t_floating>` type. The bit size of the value must be
21972 larger than the bit size of the return type. This implies that
21973 '``llvm.vp.fptrunc``' cannot be used to make a *no-op cast*. The second operand
21974 is the vector mask. The return type, the value to cast, and the vector mask have
21975 the same number of elements. The third operand is the explicit vector length of
21981 The '``llvm.vp.fptrunc``' intrinsic casts a ``value`` from a larger
21982 :ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
21983 <t_floating>` type.
21984 This instruction is assumed to execute in the default :ref:`floating-point
21985 environment <floatenv>`. The conversion is performed on lane positions below the
21986 explicit vector length and where the vector mask is true. Masked-off lanes are
21992 .. code-block:: llvm
21994 %r = call <4 x float> @llvm.vp.fptrunc.v4f32.v4f64(<4 x double> %a, <4 x i1> %mask, i32 %evl)
21995 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21997 %t = fptrunc <4 x double> %a to <4 x float>
21998 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22003 '``llvm.vp.fpext.*``' Intrinsics
22004 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22008 This is an overloaded intrinsic.
22012 declare <16 x double> @llvm.vp.fpext.v16f64.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22013 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>)
22018 The '``llvm.vp.fpext``' intrinsic extends its first operand to the return
22019 type. The operation has a mask and an explicit vector length parameter.
22025 The '``llvm.vp.fpext``' intrinsic takes a value to cast as its first operand.
22026 The return type is the type to cast the value to. Both types must be vector of
22027 :ref:`floating-point <t_floating>` type. The bit size of the value must be
22028 smaller than the bit size of the return type. This implies that
22029 '``llvm.vp.fpext``' cannot be used to make a *no-op cast*. The second operand
22030 is the vector mask. The return type, the value to cast, and the vector mask have
22031 the same number of elements. The third operand is the explicit vector length of
22037 The '``llvm.vp.fpext``' intrinsic extends the ``value`` from a smaller
22038 :ref:`floating-point <t_floating>` type to a larger :ref:`floating-point
22039 <t_floating>` type. The '``llvm.vp.fpext``' cannot be used to make a
22040 *no-op cast* because it always changes bits. Use ``bitcast`` to make a
22041 *no-op cast* for a floating-point cast.
22042 The conversion is performed on lane positions below the explicit vector length
22043 and where the vector mask is true. Masked-off lanes are ``poison``.
22048 .. code-block:: llvm
22050 %r = call <4 x double> @llvm.vp.fpext.v4f64.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22051 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22053 %t = fpext <4 x float> %a to <4 x double>
22054 %also.r = select <4 x i1> %mask, <4 x double> %t, <4 x double> poison
22059 '``llvm.vp.fptoui.*``' Intrinsics
22060 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22064 This is an overloaded intrinsic.
22068 declare <16 x i32> @llvm.vp.fptoui.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22069 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>)
22070 declare <256 x i64> @llvm.vp.fptoui.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22075 The '``llvm.vp.fptoui``' intrinsic converts the :ref:`floating-point
22076 <t_floating>` operand to the unsigned integer return type.
22077 The operation has a mask and an explicit vector length parameter.
22083 The '``llvm.vp.fptoui``' intrinsic takes a value to cast as its first operand.
22084 The value to cast must be a vector of :ref:`floating-point <t_floating>` type.
22085 The return type is the type to cast the value to. The return type must be
22086 vector of :ref:`integer <t_integer>` type. The second operand is the vector
22087 mask. The return type, the value to cast, and the vector mask have the same
22088 number of elements. The third operand is the explicit vector length of the
22094 The '``llvm.vp.fptoui``' intrinsic converts its :ref:`floating-point
22095 <t_floating>` operand into the nearest (rounding towards zero) unsigned integer
22096 value where the lane position is below the explicit vector length and the
22097 vector mask is true. Masked-off lanes are ``poison``. On enabled lanes where
22098 conversion takes place and the value cannot fit in the return type, the result
22099 on that lane is a :ref:`poison value <poisonvalues>`.
22104 .. code-block:: llvm
22106 %r = call <4 x i32> @llvm.vp.fptoui.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22107 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22109 %t = fptoui <4 x float> %a to <4 x i32>
22110 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
22115 '``llvm.vp.fptosi.*``' Intrinsics
22116 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22120 This is an overloaded intrinsic.
22124 declare <16 x i32> @llvm.vp.fptosi.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22125 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>)
22126 declare <256 x i64> @llvm.vp.fptosi.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22131 The '``llvm.vp.fptosi``' intrinsic converts the :ref:`floating-point
22132 <t_floating>` operand to the signed integer return type.
22133 The operation has a mask and an explicit vector length parameter.
22139 The '``llvm.vp.fptosi``' intrinsic takes a value to cast as its first operand.
22140 The value to cast must be a vector of :ref:`floating-point <t_floating>` type.
22141 The return type is the type to cast the value to. The return type must be
22142 vector of :ref:`integer <t_integer>` type. The second operand is the vector
22143 mask. The return type, the value to cast, and the vector mask have the same
22144 number of elements. The third operand is the explicit vector length of the
22150 The '``llvm.vp.fptosi``' intrinsic converts its :ref:`floating-point
22151 <t_floating>` operand into the nearest (rounding towards zero) signed integer
22152 value where the lane position is below the explicit vector length and the
22153 vector mask is true. Masked-off lanes are ``poison``. On enabled lanes where
22154 conversion takes place and the value cannot fit in the return type, the result
22155 on that lane is a :ref:`poison value <poisonvalues>`.
22160 .. code-block:: llvm
22162 %r = call <4 x i32> @llvm.vp.fptosi.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22163 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22165 %t = fptosi <4 x float> %a to <4 x i32>
22166 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
22171 '``llvm.vp.uitofp.*``' Intrinsics
22172 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22176 This is an overloaded intrinsic.
22180 declare <16 x float> @llvm.vp.uitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
22181 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>)
22182 declare <256 x double> @llvm.vp.uitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
22187 The '``llvm.vp.uitofp``' intrinsic converts its unsigned integer operand to the
22188 :ref:`floating-point <t_floating>` return type. The operation has a mask and
22189 an explicit vector length parameter.
22195 The '``llvm.vp.uitofp``' intrinsic takes a value to cast as its first operand.
22196 The value to cast must be vector of :ref:`integer <t_integer>` type. The
22197 return type is the type to cast the value to. The return type must be a vector
22198 of :ref:`floating-point <t_floating>` type. The second operand is the vector
22199 mask. The return type, the value to cast, and the vector mask have the same
22200 number of elements. The third operand is the explicit vector length of the
22206 The '``llvm.vp.uitofp``' intrinsic interprets its first operand as an unsigned
22207 integer quantity and converts it to the corresponding floating-point value. If
22208 the value cannot be exactly represented, it is rounded using the default
22209 rounding mode. The conversion is performed on lane positions below the
22210 explicit vector length and where the vector mask is true. Masked-off lanes are
22216 .. code-block:: llvm
22218 %r = call <4 x float> @llvm.vp.uitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
22219 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22221 %t = uitofp <4 x i32> %a to <4 x float>
22222 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22227 '``llvm.vp.sitofp.*``' Intrinsics
22228 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22232 This is an overloaded intrinsic.
22236 declare <16 x float> @llvm.vp.sitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
22237 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>)
22238 declare <256 x double> @llvm.vp.sitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
22243 The '``llvm.vp.sitofp``' intrinsic converts its signed integer operand to the
22244 :ref:`floating-point <t_floating>` return type. The operation has a mask and
22245 an explicit vector length parameter.
22251 The '``llvm.vp.sitofp``' intrinsic takes a value to cast as its first operand.
22252 The value to cast must be vector of :ref:`integer <t_integer>` type. The
22253 return type is the type to cast the value to. The return type must be a vector
22254 of :ref:`floating-point <t_floating>` type. The second operand is the vector
22255 mask. The return type, the value to cast, and the vector mask have the same
22256 number of elements. The third operand is the explicit vector length of the
22262 The '``llvm.vp.sitofp``' intrinsic interprets its first operand as a signed
22263 integer quantity and converts it to the corresponding floating-point value. If
22264 the value cannot be exactly represented, it is rounded using the default
22265 rounding mode. The conversion is performed on lane positions below the
22266 explicit vector length and where the vector mask is true. Masked-off lanes are
22272 .. code-block:: llvm
22274 %r = call <4 x float> @llvm.vp.sitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
22275 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22277 %t = sitofp <4 x i32> %a to <4 x float>
22278 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22281 .. _int_vp_ptrtoint:
22283 '``llvm.vp.ptrtoint.*``' Intrinsics
22284 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22288 This is an overloaded intrinsic.
22292 declare <16 x i8> @llvm.vp.ptrtoint.v16i8.v16p0(<16 x ptr> <op>, <16 x i1> <mask>, i32 <vector_length>)
22293 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>)
22294 declare <256 x i64> @llvm.vp.ptrtoint.v16i64.v16p0(<256 x ptr> <op>, <256 x i1> <mask>, i32 <vector_length>)
22299 The '``llvm.vp.ptrtoint``' intrinsic converts its pointer to the integer return
22300 type. The operation has a mask and an explicit vector length parameter.
22306 The '``llvm.vp.ptrtoint``' intrinsic takes a value to cast as its first operand
22307 , which must be a vector of pointers, and a type to cast it to return type,
22308 which must be a vector of :ref:`integer <t_integer>` type.
22309 The second operand is the vector mask. The return type, the value to cast, and
22310 the vector mask have the same number of elements.
22311 The third operand is the explicit vector length of the operation.
22316 The '``llvm.vp.ptrtoint``' intrinsic converts value to return type by
22317 interpreting the pointer value as an integer and either truncating or zero
22318 extending that value to the size of the integer type.
22319 If ``value`` is smaller than return type, then a zero extension is done. If
22320 ``value`` is larger than return type, then a truncation is done. If they are
22321 the same size, then nothing is done (*no-op cast*) other than a type
22323 The conversion is performed on lane positions below the explicit vector length
22324 and where the vector mask is true. Masked-off lanes are ``poison``.
22329 .. code-block:: llvm
22331 %r = call <4 x i8> @llvm.vp.ptrtoint.v4i8.v4p0i32(<4 x ptr> %a, <4 x i1> %mask, i32 %evl)
22332 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22334 %t = ptrtoint <4 x ptr> %a to <4 x i8>
22335 %also.r = select <4 x i1> %mask, <4 x i8> %t, <4 x i8> poison
22338 .. _int_vp_inttoptr:
22340 '``llvm.vp.inttoptr.*``' Intrinsics
22341 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22345 This is an overloaded intrinsic.
22349 declare <16 x ptr> @llvm.vp.inttoptr.v16p0.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
22350 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>)
22351 declare <256 x ptr> @llvm.vp.inttoptr.v256p0.v256i32 (<256 x i32> <op>, <256 x i1> <mask>, i32 <vector_length>)
22356 The '``llvm.vp.inttoptr``' intrinsic converts its integer value to the point
22357 return type. The operation has a mask and an explicit vector length parameter.
22363 The '``llvm.vp.inttoptr``' intrinsic takes a value to cast as its first operand
22364 , which must be a vector of :ref:`integer <t_integer>` type, and a type to cast
22365 it to return type, which must be a vector of pointers type.
22366 The second operand is the vector mask. The return type, the value to cast, and
22367 the vector mask have the same number of elements.
22368 The third operand is the explicit vector length of the operation.
22373 The '``llvm.vp.inttoptr``' intrinsic converts ``value`` to return type by
22374 applying either a zero extension or a truncation depending on the size of the
22375 integer ``value``. If ``value`` is larger than the size of a pointer, then a
22376 truncation is done. If ``value`` is smaller than the size of a pointer, then a
22377 zero extension is done. If they are the same size, nothing is done (*no-op cast*).
22378 The conversion is performed on lane positions below the explicit vector length
22379 and where the vector mask is true. Masked-off lanes are ``poison``.
22384 .. code-block:: llvm
22386 %r = call <4 x ptr> @llvm.vp.inttoptr.v4p0i32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
22387 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22389 %t = inttoptr <4 x i32> %a to <4 x ptr>
22390 %also.r = select <4 x i1> %mask, <4 x ptr> %t, <4 x ptr> poison
22395 '``llvm.vp.fcmp.*``' Intrinsics
22396 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22400 This is an overloaded intrinsic.
22404 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>)
22405 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>)
22406 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>)
22411 The '``llvm.vp.fcmp``' intrinsic returns a vector of boolean values based on
22412 the comparison of its operands. The operation has a mask and an explicit vector
22419 The '``llvm.vp.fcmp``' intrinsic takes the two values to compare as its first
22420 and second operands. These two values must be vectors of :ref:`floating-point
22421 <t_floating>` types.
22422 The return type is the result of the comparison. The return type must be a
22423 vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask.
22424 The return type, the values to compare, and the vector mask have the same
22425 number of elements. The third operand is the condition code indicating the kind
22426 of comparison to perform. It must be a metadata string with :ref:`one of the
22427 supported floating-point condition code values <fcmp_md_cc>`. The fifth operand
22428 is the explicit vector length of the operation.
22433 The '``llvm.vp.fcmp``' compares its first two operands according to the
22434 condition code given as the third operand. The operands are compared element by
22435 element on each enabled lane, where the the semantics of the comparison are
22436 defined :ref:`according to the condition code <fcmp_md_cc_sem>`. Masked-off
22437 lanes are ``poison``.
22442 .. code-block:: llvm
22444 %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)
22445 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22447 %t = fcmp oeq <4 x float> %a, %b
22448 %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> poison
22453 '``llvm.vp.icmp.*``' Intrinsics
22454 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22458 This is an overloaded intrinsic.
22462 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>)
22463 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>)
22464 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>)
22469 The '``llvm.vp.icmp``' intrinsic returns a vector of boolean values based on
22470 the comparison of its operands. The operation has a mask and an explicit vector
22477 The '``llvm.vp.icmp``' intrinsic takes the two values to compare as its first
22478 and second operands. These two values must be vectors of :ref:`integer
22479 <t_integer>` types.
22480 The return type is the result of the comparison. The return type must be a
22481 vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask.
22482 The return type, the values to compare, and the vector mask have the same
22483 number of elements. The third operand is the condition code indicating the kind
22484 of comparison to perform. It must be a metadata string with :ref:`one of the
22485 supported integer condition code values <icmp_md_cc>`. The fifth operand is the
22486 explicit vector length of the operation.
22491 The '``llvm.vp.icmp``' compares its first two operands according to the
22492 condition code given as the third operand. The operands are compared element by
22493 element on each enabled lane, where the the semantics of the comparison are
22494 defined :ref:`according to the condition code <icmp_md_cc_sem>`. Masked-off
22495 lanes are ``poison``.
22500 .. code-block:: llvm
22502 %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)
22503 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22505 %t = icmp ne <4 x i32> %a, %b
22506 %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> poison
22510 '``llvm.vp.ceil.*``' Intrinsics
22511 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22515 This is an overloaded intrinsic.
22519 declare <16 x float> @llvm.vp.ceil.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22520 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>)
22521 declare <256 x double> @llvm.vp.ceil.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22526 Predicated floating-point ceiling of a vector of floating-point values.
22532 The first operand and the result have the same vector of floating-point type.
22533 The second operand is the vector mask and has the same number of elements as the
22534 result vector type. The third operand is the explicit vector length of the
22540 The '``llvm.vp.ceil``' intrinsic performs floating-point ceiling
22541 (:ref:`ceil <int_ceil>`) of the first vector operand on each enabled lane. The
22542 result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22547 .. code-block:: llvm
22549 %r = call <4 x float> @llvm.vp.ceil.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22550 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22552 %t = call <4 x float> @llvm.ceil.v4f32(<4 x float> %a)
22553 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22557 '``llvm.vp.floor.*``' Intrinsics
22558 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22562 This is an overloaded intrinsic.
22566 declare <16 x float> @llvm.vp.floor.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22567 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>)
22568 declare <256 x double> @llvm.vp.floor.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22573 Predicated floating-point floor of a vector of floating-point values.
22579 The first operand and the result have the same vector of floating-point type.
22580 The second operand is the vector mask and has the same number of elements as the
22581 result vector type. The third operand is the explicit vector length of the
22587 The '``llvm.vp.floor``' intrinsic performs floating-point floor
22588 (:ref:`floor <int_floor>`) of the first vector operand on each enabled lane.
22589 The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22594 .. code-block:: llvm
22596 %r = call <4 x float> @llvm.vp.floor.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22597 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22599 %t = call <4 x float> @llvm.floor.v4f32(<4 x float> %a)
22600 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22604 '``llvm.vp.rint.*``' Intrinsics
22605 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22609 This is an overloaded intrinsic.
22613 declare <16 x float> @llvm.vp.rint.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22614 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>)
22615 declare <256 x double> @llvm.vp.rint.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22620 Predicated floating-point rint of a vector of floating-point values.
22626 The first operand and the result have the same vector of floating-point type.
22627 The second operand is the vector mask and has the same number of elements as the
22628 result vector type. The third operand is the explicit vector length of the
22634 The '``llvm.vp.rint``' intrinsic performs floating-point rint
22635 (:ref:`rint <int_rint>`) of the first vector operand on each enabled lane.
22636 The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22641 .. code-block:: llvm
22643 %r = call <4 x float> @llvm.vp.rint.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22644 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22646 %t = call <4 x float> @llvm.rint.v4f32(<4 x float> %a)
22647 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22649 .. _int_vp_nearbyint:
22651 '``llvm.vp.nearbyint.*``' Intrinsics
22652 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22656 This is an overloaded intrinsic.
22660 declare <16 x float> @llvm.vp.nearbyint.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22661 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>)
22662 declare <256 x double> @llvm.vp.nearbyint.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22667 Predicated floating-point nearbyint of a vector of floating-point values.
22673 The first operand and the result have the same vector of floating-point type.
22674 The second operand is the vector mask and has the same number of elements as the
22675 result vector type. The third operand is the explicit vector length of the
22681 The '``llvm.vp.nearbyint``' intrinsic performs floating-point nearbyint
22682 (:ref:`nearbyint <int_nearbyint>`) of the first vector operand on each enabled lane.
22683 The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22688 .. code-block:: llvm
22690 %r = call <4 x float> @llvm.vp.nearbyint.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22691 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22693 %t = call <4 x float> @llvm.nearbyint.v4f32(<4 x float> %a)
22694 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22698 '``llvm.vp.round.*``' Intrinsics
22699 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22703 This is an overloaded intrinsic.
22707 declare <16 x float> @llvm.vp.round.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22708 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>)
22709 declare <256 x double> @llvm.vp.round.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22714 Predicated floating-point round of a vector of floating-point values.
22720 The first operand and the result have the same vector of floating-point type.
22721 The second operand is the vector mask and has the same number of elements as the
22722 result vector type. The third operand is the explicit vector length of the
22728 The '``llvm.vp.round``' intrinsic performs floating-point round
22729 (:ref:`round <int_round>`) of the first vector operand on each enabled lane.
22730 The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22735 .. code-block:: llvm
22737 %r = call <4 x float> @llvm.vp.round.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22738 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22740 %t = call <4 x float> @llvm.round.v4f32(<4 x float> %a)
22741 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22743 .. _int_vp_roundeven:
22745 '``llvm.vp.roundeven.*``' Intrinsics
22746 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22750 This is an overloaded intrinsic.
22754 declare <16 x float> @llvm.vp.roundeven.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22755 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>)
22756 declare <256 x double> @llvm.vp.roundeven.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22761 Predicated floating-point roundeven of a vector of floating-point values.
22767 The first operand and the result have the same vector of floating-point type.
22768 The second operand is the vector mask and has the same number of elements as the
22769 result vector type. The third operand is the explicit vector length of the
22775 The '``llvm.vp.roundeven``' intrinsic performs floating-point roundeven
22776 (:ref:`roundeven <int_roundeven>`) of the first vector operand on each enabled
22777 lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22782 .. code-block:: llvm
22784 %r = call <4 x float> @llvm.vp.roundeven.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22785 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22787 %t = call <4 x float> @llvm.roundeven.v4f32(<4 x float> %a)
22788 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22790 .. _int_vp_roundtozero:
22792 '``llvm.vp.roundtozero.*``' Intrinsics
22793 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22797 This is an overloaded intrinsic.
22801 declare <16 x float> @llvm.vp.roundtozero.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
22802 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>)
22803 declare <256 x double> @llvm.vp.roundtozero.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
22808 Predicated floating-point round-to-zero of a vector of floating-point values.
22814 The first operand and the result have the same vector of floating-point type.
22815 The second operand is the vector mask and has the same number of elements as the
22816 result vector type. The third operand is the explicit vector length of the
22822 The '``llvm.vp.roundtozero``' intrinsic performs floating-point roundeven
22823 (:ref:`llvm.trunc <int_llvm_trunc>`) of the first vector operand on each enabled lane. The
22824 result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22829 .. code-block:: llvm
22831 %r = call <4 x float> @llvm.vp.roundtozero.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
22832 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22834 %t = call <4 x float> @llvm.trunc.v4f32(<4 x float> %a)
22835 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison
22837 .. _int_vp_bitreverse:
22839 '``llvm.vp.bitreverse.*``' Intrinsics
22840 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22844 This is an overloaded intrinsic.
22848 declare <16 x i32> @llvm.vp.bitreverse.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
22849 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>)
22850 declare <256 x i64> @llvm.vp.bitreverse.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
22855 Predicated bitreverse of a vector of integers.
22861 The first operand and the result have the same vector of integer type. The
22862 second operand is the vector mask and has the same number of elements as the
22863 result vector type. The third operand is the explicit vector length of the
22869 The '``llvm.vp.bitreverse``' intrinsic performs bitreverse (:ref:`bitreverse <int_bitreverse>`) of the first operand on each
22870 enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22875 .. code-block:: llvm
22877 %r = call <4 x i32> @llvm.vp.bitreverse.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
22878 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22880 %t = call <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> %a)
22881 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
22886 '``llvm.vp.bswap.*``' Intrinsics
22887 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22891 This is an overloaded intrinsic.
22895 declare <16 x i32> @llvm.vp.bswap.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
22896 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>)
22897 declare <256 x i64> @llvm.vp.bswap.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
22902 Predicated bswap of a vector of integers.
22908 The first operand and the result have the same vector of integer type. The
22909 second operand is the vector mask and has the same number of elements as the
22910 result vector type. The third operand is the explicit vector length of the
22916 The '``llvm.vp.bswap``' intrinsic performs bswap (:ref:`bswap <int_bswap>`) of the first operand on each
22917 enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22922 .. code-block:: llvm
22924 %r = call <4 x i32> @llvm.vp.bswap.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
22925 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22927 %t = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
22928 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
22933 '``llvm.vp.ctpop.*``' Intrinsics
22934 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22938 This is an overloaded intrinsic.
22942 declare <16 x i32> @llvm.vp.ctpop.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
22943 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>)
22944 declare <256 x i64> @llvm.vp.ctpop.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
22949 Predicated ctpop of a vector of integers.
22955 The first operand and the result have the same vector of integer type. The
22956 second operand is the vector mask and has the same number of elements as the
22957 result vector type. The third operand is the explicit vector length of the
22963 The '``llvm.vp.ctpop``' intrinsic performs ctpop (:ref:`ctpop <int_ctpop>`) of the first operand on each
22964 enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
22969 .. code-block:: llvm
22971 %r = call <4 x i32> @llvm.vp.ctpop.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
22972 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
22974 %t = call <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %a)
22975 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
22980 '``llvm.vp.ctlz.*``' Intrinsics
22981 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22985 This is an overloaded intrinsic.
22989 declare <16 x i32> @llvm.vp.ctlz.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>)
22990 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>)
22991 declare <256 x i64> @llvm.vp.ctlz.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>)
22996 Predicated ctlz of a vector of integers.
23002 The first operand and the result have the same vector of integer type. The
23003 second operand is the vector mask and has the same number of elements as the
23004 result vector type. The third operand is the explicit vector length of the
23010 The '``llvm.vp.ctlz``' intrinsic performs ctlz (:ref:`ctlz <int_ctlz>`) of the first operand on each
23011 enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
23016 .. code-block:: llvm
23018 %r = call <4 x i32> @llvm.vp.ctlz.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl, i1 false)
23019 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
23021 %t = call <4 x i32> @llvm.ctlz.v4i32(<4 x i32> %a, i1 false)
23022 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
23027 '``llvm.vp.cttz.*``' Intrinsics
23028 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23032 This is an overloaded intrinsic.
23036 declare <16 x i32> @llvm.vp.cttz.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>)
23037 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>)
23038 declare <256 x i64> @llvm.vp.cttz.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>)
23043 Predicated cttz of a vector of integers.
23049 The first operand and the result have the same vector of integer type. The
23050 second operand is the vector mask and has the same number of elements as the
23051 result vector type. The third operand is the explicit vector length of the
23057 The '``llvm.vp.cttz``' intrinsic performs cttz (:ref:`cttz <int_cttz>`) of the first operand on each
23058 enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
23063 .. code-block:: llvm
23065 %r = call <4 x i32> @llvm.vp.cttz.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl, i1 false)
23066 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
23068 %t = call <4 x i32> @llvm.cttz.v4i32(<4 x i32> %a, i1 false)
23069 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
23074 '``llvm.vp.fshl.*``' Intrinsics
23075 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23079 This is an overloaded intrinsic.
23083 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>)
23084 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>)
23085 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>)
23090 Predicated fshl of three vectors of integers.
23096 The first three operand and the result have the same vector of integer type. The
23097 fourth operand is the vector mask and has the same number of elements as the
23098 result vector type. The fifth operand is the explicit vector length of the
23104 The '``llvm.vp.fshl``' intrinsic performs fshl (:ref:`fshl <int_fshl>`) of the first, second, and third
23105 vector operand on each enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
23111 .. code-block:: llvm
23113 %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)
23114 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
23116 %t = call <4 x i32> @llvm.fshl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c)
23117 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
23120 '``llvm.vp.fshr.*``' Intrinsics
23121 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23125 This is an overloaded intrinsic.
23129 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>)
23130 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>)
23131 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>)
23136 Predicated fshr of three vectors of integers.
23142 The first three operand and the result have the same vector of integer type. The
23143 fourth operand is the vector mask and has the same number of elements as the
23144 result vector type. The fifth operand is the explicit vector length of the
23150 The '``llvm.vp.fshr``' intrinsic performs fshr (:ref:`fshr <int_fshr>`) of the first, second, and third
23151 vector operand on each enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`.
23157 .. code-block:: llvm
23159 %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)
23160 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
23162 %t = call <4 x i32> @llvm.fshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c)
23163 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison
23165 '``llvm.vp.is.fpclass.*``' Intrinsics
23166 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23170 This is an overloaded intrinsic.
23174 declare <vscale x 2 x i1> @llvm.vp.is.fpclass.nxv2f32(<vscale x 2 x float> <op>, i32 <test>, <vscale x 2 x i1> <mask>, i32 <vector_length>)
23175 declare <2 x i1> @llvm.vp.is.fpclass.v2f16(<2 x half> <op>, i32 <test>, <2 x i1> <mask>, i32 <vector_length>)
23180 Predicated llvm.is.fpclass :ref:`llvm.is.fpclass <llvm.is.fpclass>`
23185 The first operand is a floating-point vector, the result type is a vector of
23186 boolean with the same number of elements as the first argument. The second
23187 operand specifies, which tests to perform :ref:`llvm.is.fpclass <llvm.is.fpclass>`.
23188 The third operand is the vector mask and has the same number of elements as the
23189 result vector type. The fourth operand is the explicit vector length of the
23195 The '``llvm.vp.is.fpclass``' intrinsic performs llvm.is.fpclass (:ref:`llvm.is.fpclass <llvm.is.fpclass>`).
23201 .. code-block:: llvm
23203 %r = call <2 x i1> @llvm.vp.is.fpclass.v2f16(<2 x half> %x, i32 3, <2 x i1> %m, i32 %evl)
23204 %t = call <vscale x 2 x i1> @llvm.vp.is.fpclass.nxv2f16(<vscale x 2 x half> %x, i32 3, <vscale x 2 x i1> %m, i32 %evl)
23206 .. _int_mload_mstore:
23208 Masked Vector Load and Store Intrinsics
23209 ---------------------------------------
23211 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.
23215 '``llvm.masked.load.*``' Intrinsics
23216 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23220 This is an overloaded intrinsic. The loaded data is a vector of any integer, floating-point or pointer data type.
23224 declare <16 x float> @llvm.masked.load.v16f32.p0(ptr <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
23225 declare <2 x double> @llvm.masked.load.v2f64.p0(ptr <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>)
23226 ;; The data is a vector of pointers
23227 declare <8 x ptr> @llvm.masked.load.v8p0.p0(ptr <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x ptr> <passthru>)
23232 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.
23238 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.
23243 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.
23244 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.
23249 %res = call <16 x float> @llvm.masked.load.v16f32.p0(ptr %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru)
23251 ;; The result of the two following instructions is identical aside from potential memory access exception
23252 %loadlal = load <16 x float>, ptr %ptr, align 4
23253 %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru
23257 '``llvm.masked.store.*``' Intrinsics
23258 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23262 This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type.
23266 declare void @llvm.masked.store.v8i32.p0 (<8 x i32> <value>, ptr <ptr>, i32 <alignment>, <8 x i1> <mask>)
23267 declare void @llvm.masked.store.v16f32.p0(<16 x float> <value>, ptr <ptr>, i32 <alignment>, <16 x i1> <mask>)
23268 ;; The data is a vector of pointers
23269 declare void @llvm.masked.store.v8p0.p0 (<8 x ptr> <value>, ptr <ptr>, i32 <alignment>, <8 x i1> <mask>)
23274 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.
23279 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.
23285 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.
23286 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.
23290 call void @llvm.masked.store.v16f32.p0(<16 x float> %value, ptr %ptr, i32 4, <16 x i1> %mask)
23292 ;; The result of the following instructions is identical aside from potential data races and memory access exceptions
23293 %oldval = load <16 x float>, ptr %ptr, align 4
23294 %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval
23295 store <16 x float> %res, ptr %ptr, align 4
23298 Masked Vector Gather and Scatter Intrinsics
23299 -------------------------------------------
23301 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.
23305 '``llvm.masked.gather.*``' Intrinsics
23306 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23310 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.
23314 declare <16 x float> @llvm.masked.gather.v16f32.v16p0(<16 x ptr> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
23315 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>)
23316 declare <8 x ptr> @llvm.masked.gather.v8p0.v8p0(<8 x ptr> <ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x ptr> <passthru>)
23321 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.
23327 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.
23332 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.
23333 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.
23338 %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)
23340 ;; The gather with all-true mask is equivalent to the following instruction sequence
23341 %ptr0 = extractelement <4 x ptr> %ptrs, i32 0
23342 %ptr1 = extractelement <4 x ptr> %ptrs, i32 1
23343 %ptr2 = extractelement <4 x ptr> %ptrs, i32 2
23344 %ptr3 = extractelement <4 x ptr> %ptrs, i32 3
23346 %val0 = load double, ptr %ptr0, align 8
23347 %val1 = load double, ptr %ptr1, align 8
23348 %val2 = load double, ptr %ptr2, align 8
23349 %val3 = load double, ptr %ptr3, align 8
23351 %vec0 = insertelement <4 x double> poison, %val0, 0
23352 %vec01 = insertelement <4 x double> %vec0, %val1, 1
23353 %vec012 = insertelement <4 x double> %vec01, %val2, 2
23354 %vec0123 = insertelement <4 x double> %vec012, %val3, 3
23358 '``llvm.masked.scatter.*``' Intrinsics
23359 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23363 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.
23367 declare void @llvm.masked.scatter.v8i32.v8p0 (<8 x i32> <value>, <8 x ptr> <ptrs>, i32 <alignment>, <8 x i1> <mask>)
23368 declare void @llvm.masked.scatter.v16f32.v16p1(<16 x float> <value>, <16 x ptr addrspace(1)> <ptrs>, i32 <alignment>, <16 x i1> <mask>)
23369 declare void @llvm.masked.scatter.v4p0.v4p0 (<4 x ptr> <value>, <4 x ptr> <ptrs>, i32 <alignment>, <4 x i1> <mask>)
23374 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.
23379 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.
23384 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.
23388 ;; This instruction unconditionally stores data vector in multiple addresses
23389 call @llvm.masked.scatter.v8i32.v8p0(<8 x i32> %value, <8 x ptr> %ptrs, i32 4, <8 x i1> <true, true, .. true>)
23391 ;; It is equivalent to a list of scalar stores
23392 %val0 = extractelement <8 x i32> %value, i32 0
23393 %val1 = extractelement <8 x i32> %value, i32 1
23395 %val7 = extractelement <8 x i32> %value, i32 7
23396 %ptr0 = extractelement <8 x ptr> %ptrs, i32 0
23397 %ptr1 = extractelement <8 x ptr> %ptrs, i32 1
23399 %ptr7 = extractelement <8 x ptr> %ptrs, i32 7
23400 ;; Note: the order of the following stores is important when they overlap:
23401 store i32 %val0, ptr %ptr0, align 4
23402 store i32 %val1, ptr %ptr1, align 4
23404 store i32 %val7, ptr %ptr7, align 4
23407 Masked Vector Expanding Load and Compressing Store Intrinsics
23408 -------------------------------------------------------------
23410 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>`.
23412 .. _int_expandload:
23414 '``llvm.masked.expandload.*``' Intrinsics
23415 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23419 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.
23423 declare <16 x float> @llvm.masked.expandload.v16f32 (ptr <ptr>, <16 x i1> <mask>, <16 x float> <passthru>)
23424 declare <2 x i64> @llvm.masked.expandload.v2i64 (ptr <ptr>, <2 x i1> <mask>, <2 x i64> <passthru>)
23429 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.
23435 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.
23440 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:
23444 // In this loop we load from B and spread the elements into array A.
23445 double *A, B; int *C;
23446 for (int i = 0; i < size; ++i) {
23452 .. code-block:: llvm
23454 ; Load several elements from array B and expand them in a vector.
23455 ; The number of loaded elements is equal to the number of '1' elements in the Mask.
23456 %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(ptr %Bptr, <8 x i1> %Mask, <8 x double> poison)
23457 ; Store the result in A
23458 call void @llvm.masked.store.v8f64.p0(<8 x double> %Tmp, ptr %Aptr, i32 8, <8 x i1> %Mask)
23460 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
23461 %MaskI = bitcast <8 x i1> %Mask to i8
23462 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
23463 %MaskI64 = zext i8 %MaskIPopcnt to i64
23464 %BNextInd = add i64 %BInd, %MaskI64
23467 Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles.
23468 If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load.
23470 .. _int_compressstore:
23472 '``llvm.masked.compressstore.*``' Intrinsics
23473 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23477 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.
23481 declare void @llvm.masked.compressstore.v8i32 (<8 x i32> <value>, ptr <ptr>, <8 x i1> <mask>)
23482 declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, ptr <ptr>, <16 x i1> <mask>)
23487 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.
23492 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.
23498 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:
23502 // In this loop we load elements from A and store them consecutively in B
23503 double *A, B; int *C;
23504 for (int i = 0; i < size; ++i) {
23510 .. code-block:: llvm
23512 ; Load elements from A.
23513 %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0(ptr %Aptr, i32 8, <8 x i1> %Mask, <8 x double> poison)
23514 ; Store all selected elements consecutively in array B
23515 call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, ptr %Bptr, <8 x i1> %Mask)
23517 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
23518 %MaskI = bitcast <8 x i1> %Mask to i8
23519 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
23520 %MaskI64 = zext i8 %MaskIPopcnt to i64
23521 %BNextInd = add i64 %BInd, %MaskI64
23524 Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations.
23530 This class of intrinsics provides information about the
23531 :ref:`lifetime of memory objects <objectlifetime>` and ranges where variables
23536 '``llvm.lifetime.start``' Intrinsic
23537 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23544 declare void @llvm.lifetime.start(i64 <size>, ptr nocapture <ptr>)
23549 The '``llvm.lifetime.start``' intrinsic specifies the start of a memory
23555 The first argument is a constant integer representing the size of the
23556 object, or -1 if it is variable sized. The second argument is a pointer
23562 If ``ptr`` is a stack-allocated object and it points to the first byte of
23563 the object, the object is initially marked as dead.
23564 ``ptr`` is conservatively considered as a non-stack-allocated object if
23565 the stack coloring algorithm that is used in the optimization pipeline cannot
23566 conclude that ``ptr`` is a stack-allocated object.
23568 After '``llvm.lifetime.start``', the stack object that ``ptr`` points is marked
23569 as alive and has an uninitialized value.
23570 The stack object is marked as dead when either
23571 :ref:`llvm.lifetime.end <int_lifeend>` to the alloca is executed or the
23574 After :ref:`llvm.lifetime.end <int_lifeend>` is called,
23575 '``llvm.lifetime.start``' on the stack object can be called again.
23576 The second '``llvm.lifetime.start``' call marks the object as alive, but it
23577 does not change the address of the object.
23579 If ``ptr`` is a non-stack-allocated object, it does not point to the first
23580 byte of the object or it is a stack object that is already alive, it simply
23581 fills all bytes of the object with ``poison``.
23586 '``llvm.lifetime.end``' Intrinsic
23587 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23594 declare void @llvm.lifetime.end(i64 <size>, ptr nocapture <ptr>)
23599 The '``llvm.lifetime.end``' intrinsic specifies the end of a memory object's
23605 The first argument is a constant integer representing the size of the
23606 object, or -1 if it is variable sized. The second argument is a pointer
23612 If ``ptr`` is a stack-allocated object and it points to the first byte of the
23613 object, the object is dead.
23614 ``ptr`` is conservatively considered as a non-stack-allocated object if
23615 the stack coloring algorithm that is used in the optimization pipeline cannot
23616 conclude that ``ptr`` is a stack-allocated object.
23618 Calling ``llvm.lifetime.end`` on an already dead alloca is no-op.
23620 If ``ptr`` is a non-stack-allocated object or it does not point to the first
23621 byte of the object, it is equivalent to simply filling all bytes of the object
23625 '``llvm.invariant.start``' Intrinsic
23626 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23630 This is an overloaded intrinsic. The memory object can belong to any address space.
23634 declare ptr @llvm.invariant.start.p0(i64 <size>, ptr nocapture <ptr>)
23639 The '``llvm.invariant.start``' intrinsic specifies that the contents of
23640 a memory object will not change.
23645 The first argument is a constant integer representing the size of the
23646 object, or -1 if it is variable sized. The second argument is a pointer
23652 This intrinsic indicates that until an ``llvm.invariant.end`` that uses
23653 the return value, the referenced memory location is constant and
23656 '``llvm.invariant.end``' Intrinsic
23657 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23661 This is an overloaded intrinsic. The memory object can belong to any address space.
23665 declare void @llvm.invariant.end.p0(ptr <start>, i64 <size>, ptr nocapture <ptr>)
23670 The '``llvm.invariant.end``' intrinsic specifies that the contents of a
23671 memory object are mutable.
23676 The first argument is the matching ``llvm.invariant.start`` intrinsic.
23677 The second argument is a constant integer representing the size of the
23678 object, or -1 if it is variable sized and the third argument is a
23679 pointer to the object.
23684 This intrinsic indicates that the memory is mutable again.
23686 '``llvm.launder.invariant.group``' Intrinsic
23687 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23691 This is an overloaded intrinsic. The memory object can belong to any address
23692 space. The returned pointer must belong to the same address space as the
23697 declare ptr @llvm.launder.invariant.group.p0(ptr <ptr>)
23702 The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant
23703 established by ``invariant.group`` metadata no longer holds, to obtain a new
23704 pointer value that carries fresh invariant group information. It is an
23705 experimental intrinsic, which means that its semantics might change in the
23712 The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer
23718 Returns another pointer that aliases its argument but which is considered different
23719 for the purposes of ``load``/``store`` ``invariant.group`` metadata.
23720 It does not read any accessible memory and the execution can be speculated.
23722 '``llvm.strip.invariant.group``' Intrinsic
23723 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23727 This is an overloaded intrinsic. The memory object can belong to any address
23728 space. The returned pointer must belong to the same address space as the
23733 declare ptr @llvm.strip.invariant.group.p0(ptr <ptr>)
23738 The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant
23739 established by ``invariant.group`` metadata no longer holds, to obtain a new pointer
23740 value that does not carry the invariant information. It is an experimental
23741 intrinsic, which means that its semantics might change in the future.
23747 The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer
23753 Returns another pointer that aliases its argument but which has no associated
23754 ``invariant.group`` metadata.
23755 It does not read any memory and can be speculated.
23761 Constrained Floating-Point Intrinsics
23762 -------------------------------------
23764 These intrinsics are used to provide special handling of floating-point
23765 operations when specific rounding mode or floating-point exception behavior is
23766 required. By default, LLVM optimization passes assume that the rounding mode is
23767 round-to-nearest and that floating-point exceptions will not be monitored.
23768 Constrained FP intrinsics are used to support non-default rounding modes and
23769 accurately preserve exception behavior without compromising LLVM's ability to
23770 optimize FP code when the default behavior is used.
23772 If any FP operation in a function is constrained then they all must be
23773 constrained. This is required for correct LLVM IR. Optimizations that
23774 move code around can create miscompiles if mixing of constrained and normal
23775 operations is done. The correct way to mix constrained and less constrained
23776 operations is to use the rounding mode and exception handling metadata to
23777 mark constrained intrinsics as having LLVM's default behavior.
23779 Each of these intrinsics corresponds to a normal floating-point operation. The
23780 data arguments and the return value are the same as the corresponding FP
23783 The rounding mode argument is a metadata string specifying what
23784 assumptions, if any, the optimizer can make when transforming constant
23785 values. Some constrained FP intrinsics omit this argument. If required
23786 by the intrinsic, this argument must be one of the following strings:
23795 "round.tonearestaway"
23797 If this argument is "round.dynamic" optimization passes must assume that the
23798 rounding mode is unknown and may change at runtime. No transformations that
23799 depend on rounding mode may be performed in this case.
23801 The other possible values for the rounding mode argument correspond to the
23802 similarly named IEEE rounding modes. If the argument is any of these values
23803 optimization passes may perform transformations as long as they are consistent
23804 with the specified rounding mode.
23806 For example, 'x-0'->'x' is not a valid transformation if the rounding mode is
23807 "round.downward" or "round.dynamic" because if the value of 'x' is +0 then
23808 'x-0' should evaluate to '-0' when rounding downward. However, this
23809 transformation is legal for all other rounding modes.
23811 For values other than "round.dynamic" optimization passes may assume that the
23812 actual runtime rounding mode (as defined in a target-specific manner) matches
23813 the specified rounding mode, but this is not guaranteed. Using a specific
23814 non-dynamic rounding mode which does not match the actual rounding mode at
23815 runtime results in undefined behavior.
23817 The exception behavior argument is a metadata string describing the floating
23818 point exception semantics that required for the intrinsic. This argument
23819 must be one of the following strings:
23827 If this argument is "fpexcept.ignore" optimization passes may assume that the
23828 exception status flags will not be read and that floating-point exceptions will
23829 be masked. This allows transformations to be performed that may change the
23830 exception semantics of the original code. For example, FP operations may be
23831 speculatively executed in this case whereas they must not be for either of the
23832 other possible values of this argument.
23834 If the exception behavior argument is "fpexcept.maytrap" optimization passes
23835 must avoid transformations that may raise exceptions that would not have been
23836 raised by the original code (such as speculatively executing FP operations), but
23837 passes are not required to preserve all exceptions that are implied by the
23838 original code. For example, exceptions may be potentially hidden by constant
23841 If the exception behavior argument is "fpexcept.strict" all transformations must
23842 strictly preserve the floating-point exception semantics of the original code.
23843 Any FP exception that would have been raised by the original code must be raised
23844 by the transformed code, and the transformed code must not raise any FP
23845 exceptions that would not have been raised by the original code. This is the
23846 exception behavior argument that will be used if the code being compiled reads
23847 the FP exception status flags, but this mode can also be used with code that
23848 unmasks FP exceptions.
23850 The number and order of floating-point exceptions is NOT guaranteed. For
23851 example, a series of FP operations that each may raise exceptions may be
23852 vectorized into a single instruction that raises each unique exception a single
23855 Proper :ref:`function attributes <fnattrs>` usage is required for the
23856 constrained intrinsics to function correctly.
23858 All function *calls* done in a function that uses constrained floating
23859 point intrinsics must have the ``strictfp`` attribute either on the
23860 calling instruction or on the declaration or definition of the function
23863 All function *definitions* that use constrained floating point intrinsics
23864 must have the ``strictfp`` attribute.
23866 '``llvm.experimental.constrained.fadd``' Intrinsic
23867 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23875 @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>,
23876 metadata <rounding mode>,
23877 metadata <exception behavior>)
23882 The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its
23889 The first two arguments to the '``llvm.experimental.constrained.fadd``'
23890 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
23891 of floating-point values. Both arguments must have identical types.
23893 The third and fourth arguments specify the rounding mode and exception
23894 behavior as described above.
23899 The value produced is the floating-point sum of the two value operands and has
23900 the same type as the operands.
23903 '``llvm.experimental.constrained.fsub``' Intrinsic
23904 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23912 @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>,
23913 metadata <rounding mode>,
23914 metadata <exception behavior>)
23919 The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference
23920 of its two operands.
23926 The first two arguments to the '``llvm.experimental.constrained.fsub``'
23927 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
23928 of floating-point values. Both arguments must have identical types.
23930 The third and fourth arguments specify the rounding mode and exception
23931 behavior as described above.
23936 The value produced is the floating-point difference of the two value operands
23937 and has the same type as the operands.
23940 '``llvm.experimental.constrained.fmul``' Intrinsic
23941 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23949 @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>,
23950 metadata <rounding mode>,
23951 metadata <exception behavior>)
23956 The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of
23963 The first two arguments to the '``llvm.experimental.constrained.fmul``'
23964 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
23965 of floating-point values. Both arguments must have identical types.
23967 The third and fourth arguments specify the rounding mode and exception
23968 behavior as described above.
23973 The value produced is the floating-point product of the two value operands and
23974 has the same type as the operands.
23977 '``llvm.experimental.constrained.fdiv``' Intrinsic
23978 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23986 @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>,
23987 metadata <rounding mode>,
23988 metadata <exception behavior>)
23993 The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of
24000 The first two arguments to the '``llvm.experimental.constrained.fdiv``'
24001 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
24002 of floating-point values. Both arguments must have identical types.
24004 The third and fourth arguments specify the rounding mode and exception
24005 behavior as described above.
24010 The value produced is the floating-point quotient of the two value operands and
24011 has the same type as the operands.
24014 '``llvm.experimental.constrained.frem``' Intrinsic
24015 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24023 @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>,
24024 metadata <rounding mode>,
24025 metadata <exception behavior>)
24030 The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder
24031 from the division of its two operands.
24037 The first two arguments to the '``llvm.experimental.constrained.frem``'
24038 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
24039 of floating-point values. Both arguments must have identical types.
24041 The third and fourth arguments specify the rounding mode and exception
24042 behavior as described above. The rounding mode argument has no effect, since
24043 the result of frem is never rounded, but the argument is included for
24044 consistency with the other constrained floating-point intrinsics.
24049 The value produced is the floating-point remainder from the division of the two
24050 value operands and has the same type as the operands. The remainder has the
24051 same sign as the dividend.
24053 '``llvm.experimental.constrained.fma``' Intrinsic
24054 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24062 @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>,
24063 metadata <rounding mode>,
24064 metadata <exception behavior>)
24069 The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a
24070 fused-multiply-add operation on its operands.
24075 The first three arguments to the '``llvm.experimental.constrained.fma``'
24076 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector
24077 <t_vector>` of floating-point values. All arguments must have identical types.
24079 The fourth and fifth arguments specify the rounding mode and exception behavior
24080 as described above.
24085 The result produced is the product of the first two operands added to the third
24086 operand computed with infinite precision, and then rounded to the target
24089 '``llvm.experimental.constrained.fptoui``' Intrinsic
24090 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24098 @llvm.experimental.constrained.fptoui(<type> <value>,
24099 metadata <exception behavior>)
24104 The '``llvm.experimental.constrained.fptoui``' intrinsic converts a
24105 floating-point ``value`` to its unsigned integer equivalent of type ``ty2``.
24110 The first argument to the '``llvm.experimental.constrained.fptoui``'
24111 intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
24112 <t_vector>` of floating point values.
24114 The second argument specifies the exception behavior as described above.
24119 The result produced is an unsigned integer converted from the floating
24120 point operand. The value is truncated, so it is rounded towards zero.
24122 '``llvm.experimental.constrained.fptosi``' Intrinsic
24123 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24131 @llvm.experimental.constrained.fptosi(<type> <value>,
24132 metadata <exception behavior>)
24137 The '``llvm.experimental.constrained.fptosi``' intrinsic converts
24138 :ref:`floating-point <t_floating>` ``value`` to type ``ty2``.
24143 The first argument to the '``llvm.experimental.constrained.fptosi``'
24144 intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
24145 <t_vector>` of floating point values.
24147 The second argument specifies the exception behavior as described above.
24152 The result produced is a signed integer converted from the floating
24153 point operand. The value is truncated, so it is rounded towards zero.
24155 '``llvm.experimental.constrained.uitofp``' Intrinsic
24156 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24164 @llvm.experimental.constrained.uitofp(<type> <value>,
24165 metadata <rounding mode>,
24166 metadata <exception behavior>)
24171 The '``llvm.experimental.constrained.uitofp``' intrinsic converts an
24172 unsigned integer ``value`` to a floating-point of type ``ty2``.
24177 The first argument to the '``llvm.experimental.constrained.uitofp``'
24178 intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector
24179 <t_vector>` of integer values.
24181 The second and third arguments specify the rounding mode and exception
24182 behavior as described above.
24187 An inexact floating-point exception will be raised if rounding is required.
24188 Any result produced is a floating point value converted from the input
24191 '``llvm.experimental.constrained.sitofp``' Intrinsic
24192 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24200 @llvm.experimental.constrained.sitofp(<type> <value>,
24201 metadata <rounding mode>,
24202 metadata <exception behavior>)
24207 The '``llvm.experimental.constrained.sitofp``' intrinsic converts a
24208 signed integer ``value`` to a floating-point of type ``ty2``.
24213 The first argument to the '``llvm.experimental.constrained.sitofp``'
24214 intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector
24215 <t_vector>` of integer values.
24217 The second and third arguments specify the rounding mode and exception
24218 behavior as described above.
24223 An inexact floating-point exception will be raised if rounding is required.
24224 Any result produced is a floating point value converted from the input
24227 '``llvm.experimental.constrained.fptrunc``' Intrinsic
24228 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24236 @llvm.experimental.constrained.fptrunc(<type> <value>,
24237 metadata <rounding mode>,
24238 metadata <exception behavior>)
24243 The '``llvm.experimental.constrained.fptrunc``' intrinsic truncates ``value``
24249 The first argument to the '``llvm.experimental.constrained.fptrunc``'
24250 intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
24251 <t_vector>` of floating point values. This argument must be larger in size
24254 The second and third arguments specify the rounding mode and exception
24255 behavior as described above.
24260 The result produced is a floating point value truncated to be smaller in size
24263 '``llvm.experimental.constrained.fpext``' Intrinsic
24264 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24272 @llvm.experimental.constrained.fpext(<type> <value>,
24273 metadata <exception behavior>)
24278 The '``llvm.experimental.constrained.fpext``' intrinsic extends a
24279 floating-point ``value`` to a larger floating-point value.
24284 The first argument to the '``llvm.experimental.constrained.fpext``'
24285 intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
24286 <t_vector>` of floating point values. This argument must be smaller in size
24289 The second argument specifies the exception behavior as described above.
24294 The result produced is a floating point value extended to be larger in size
24295 than the operand. All restrictions that apply to the fpext instruction also
24296 apply to this intrinsic.
24298 '``llvm.experimental.constrained.fcmp``' and '``llvm.experimental.constrained.fcmps``' Intrinsics
24299 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24307 @llvm.experimental.constrained.fcmp(<type> <op1>, <type> <op2>,
24308 metadata <condition code>,
24309 metadata <exception behavior>)
24311 @llvm.experimental.constrained.fcmps(<type> <op1>, <type> <op2>,
24312 metadata <condition code>,
24313 metadata <exception behavior>)
24318 The '``llvm.experimental.constrained.fcmp``' and
24319 '``llvm.experimental.constrained.fcmps``' intrinsics return a boolean
24320 value or vector of boolean values based on comparison of its operands.
24322 If the operands are floating-point scalars, then the result type is a
24323 boolean (:ref:`i1 <t_integer>`).
24325 If the operands are floating-point vectors, then the result type is a
24326 vector of boolean with the same number of elements as the operands being
24329 The '``llvm.experimental.constrained.fcmp``' intrinsic performs a quiet
24330 comparison operation while the '``llvm.experimental.constrained.fcmps``'
24331 intrinsic performs a signaling comparison operation.
24336 The first two arguments to the '``llvm.experimental.constrained.fcmp``'
24337 and '``llvm.experimental.constrained.fcmps``' intrinsics must be
24338 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
24339 of floating-point values. Both arguments must have identical types.
24341 The third argument is the condition code indicating the kind of comparison
24342 to perform. It must be a metadata string with one of the following values:
24346 - "``oeq``": ordered and equal
24347 - "``ogt``": ordered and greater than
24348 - "``oge``": ordered and greater than or equal
24349 - "``olt``": ordered and less than
24350 - "``ole``": ordered and less than or equal
24351 - "``one``": ordered and not equal
24352 - "``ord``": ordered (no nans)
24353 - "``ueq``": unordered or equal
24354 - "``ugt``": unordered or greater than
24355 - "``uge``": unordered or greater than or equal
24356 - "``ult``": unordered or less than
24357 - "``ule``": unordered or less than or equal
24358 - "``une``": unordered or not equal
24359 - "``uno``": unordered (either nans)
24361 *Ordered* means that neither operand is a NAN while *unordered* means
24362 that either operand may be a NAN.
24364 The fourth argument specifies the exception behavior as described above.
24369 ``op1`` and ``op2`` are compared according to the condition code given
24370 as the third argument. If the operands are vectors, then the
24371 vectors are compared element by element. Each comparison performed
24372 always yields an :ref:`i1 <t_integer>` result, as follows:
24374 .. _fcmp_md_cc_sem:
24376 - "``oeq``": yields ``true`` if both operands are not a NAN and ``op1``
24377 is equal to ``op2``.
24378 - "``ogt``": yields ``true`` if both operands are not a NAN and ``op1``
24379 is greater than ``op2``.
24380 - "``oge``": yields ``true`` if both operands are not a NAN and ``op1``
24381 is greater than or equal to ``op2``.
24382 - "``olt``": yields ``true`` if both operands are not a NAN and ``op1``
24383 is less than ``op2``.
24384 - "``ole``": yields ``true`` if both operands are not a NAN and ``op1``
24385 is less than or equal to ``op2``.
24386 - "``one``": yields ``true`` if both operands are not a NAN and ``op1``
24387 is not equal to ``op2``.
24388 - "``ord``": yields ``true`` if both operands are not a NAN.
24389 - "``ueq``": yields ``true`` if either operand is a NAN or ``op1`` is
24391 - "``ugt``": yields ``true`` if either operand is a NAN or ``op1`` is
24392 greater than ``op2``.
24393 - "``uge``": yields ``true`` if either operand is a NAN or ``op1`` is
24394 greater than or equal to ``op2``.
24395 - "``ult``": yields ``true`` if either operand is a NAN or ``op1`` is
24397 - "``ule``": yields ``true`` if either operand is a NAN or ``op1`` is
24398 less than or equal to ``op2``.
24399 - "``une``": yields ``true`` if either operand is a NAN or ``op1`` is
24400 not equal to ``op2``.
24401 - "``uno``": yields ``true`` if either operand is a NAN.
24403 The quiet comparison operation performed by
24404 '``llvm.experimental.constrained.fcmp``' will only raise an exception
24405 if either operand is a SNAN. The signaling comparison operation
24406 performed by '``llvm.experimental.constrained.fcmps``' will raise an
24407 exception if either operand is a NAN (QNAN or SNAN). Such an exception
24408 does not preclude a result being produced (e.g. exception might only
24409 set a flag), therefore the distinction between ordered and unordered
24410 comparisons is also relevant for the
24411 '``llvm.experimental.constrained.fcmps``' intrinsic.
24413 '``llvm.experimental.constrained.fmuladd``' Intrinsic
24414 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24422 @llvm.experimental.constrained.fmuladd(<type> <op1>, <type> <op2>,
24424 metadata <rounding mode>,
24425 metadata <exception behavior>)
24430 The '``llvm.experimental.constrained.fmuladd``' intrinsic represents
24431 multiply-add expressions that can be fused if the code generator determines
24432 that (a) the target instruction set has support for a fused operation,
24433 and (b) that the fused operation is more efficient than the equivalent,
24434 separate pair of mul and add instructions.
24439 The first three arguments to the '``llvm.experimental.constrained.fmuladd``'
24440 intrinsic must be floating-point or vector of floating-point values.
24441 All three arguments must have identical types.
24443 The fourth and fifth arguments specify the rounding mode and exception behavior
24444 as described above.
24453 %0 = call float @llvm.experimental.constrained.fmuladd.f32(%a, %b, %c,
24454 metadata <rounding mode>,
24455 metadata <exception behavior>)
24457 is equivalent to the expression:
24461 %0 = call float @llvm.experimental.constrained.fmul.f32(%a, %b,
24462 metadata <rounding mode>,
24463 metadata <exception behavior>)
24464 %1 = call float @llvm.experimental.constrained.fadd.f32(%0, %c,
24465 metadata <rounding mode>,
24466 metadata <exception behavior>)
24468 except that it is unspecified whether rounding will be performed between the
24469 multiplication and addition steps. Fusion is not guaranteed, even if the target
24470 platform supports it.
24471 If a fused multiply-add is required, the corresponding
24472 :ref:`llvm.experimental.constrained.fma <int_fma>` intrinsic function should be
24474 This never sets errno, just as '``llvm.experimental.constrained.fma.*``'.
24476 Constrained libm-equivalent Intrinsics
24477 --------------------------------------
24479 In addition to the basic floating-point operations for which constrained
24480 intrinsics are described above, there are constrained versions of various
24481 operations which provide equivalent behavior to a corresponding libm function.
24482 These intrinsics allow the precise behavior of these operations with respect to
24483 rounding mode and exception behavior to be controlled.
24485 As with the basic constrained floating-point intrinsics, the rounding mode
24486 and exception behavior arguments only control the behavior of the optimizer.
24487 They do not change the runtime floating-point environment.
24490 '``llvm.experimental.constrained.sqrt``' Intrinsic
24491 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24499 @llvm.experimental.constrained.sqrt(<type> <op1>,
24500 metadata <rounding mode>,
24501 metadata <exception behavior>)
24506 The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root
24507 of the specified value, returning the same value as the libm '``sqrt``'
24508 functions would, but without setting ``errno``.
24513 The first argument and the return type are floating-point numbers of the same
24516 The second and third arguments specify the rounding mode and exception
24517 behavior as described above.
24522 This function returns the nonnegative square root of the specified value.
24523 If the value is less than negative zero, a floating-point exception occurs
24524 and the return value is architecture specific.
24527 '``llvm.experimental.constrained.pow``' Intrinsic
24528 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24536 @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>,
24537 metadata <rounding mode>,
24538 metadata <exception behavior>)
24543 The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand
24544 raised to the (positive or negative) power specified by the second operand.
24549 The first two arguments and the return value are floating-point numbers of the
24550 same type. The second argument specifies the power to which the first argument
24553 The third and fourth arguments specify the rounding mode and exception
24554 behavior as described above.
24559 This function returns the first value raised to the second power,
24560 returning the same values as the libm ``pow`` functions would, and
24561 handles error conditions in the same way.
24564 '``llvm.experimental.constrained.powi``' Intrinsic
24565 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24573 @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>,
24574 metadata <rounding mode>,
24575 metadata <exception behavior>)
24580 The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand
24581 raised to the (positive or negative) power specified by the second operand. The
24582 order of evaluation of multiplications is not defined. When a vector of
24583 floating-point type is used, the second argument remains a scalar integer value.
24589 The first argument and the return value are floating-point numbers of the same
24590 type. The second argument is a 32-bit signed integer specifying the power to
24591 which the first argument should be raised.
24593 The third and fourth arguments specify the rounding mode and exception
24594 behavior as described above.
24599 This function returns the first value raised to the second power with an
24600 unspecified sequence of rounding operations.
24603 '``llvm.experimental.constrained.ldexp``' Intrinsic
24604 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24612 @llvm.experimental.constrained.ldexp(<type0> <op1>, <type1> <op2>,
24613 metadata <rounding mode>,
24614 metadata <exception behavior>)
24619 The '``llvm.experimental.constrained.ldexp``' performs the ldexp function.
24625 The first argument and the return value are :ref:`floating-point
24626 <t_floating>` or :ref:`vector <t_vector>` of floating-point values of
24627 the same type. The second argument is an integer with the same number
24631 The third and fourth arguments specify the rounding mode and exception
24632 behavior as described above.
24637 This function multiplies the first argument by 2 raised to the second
24638 argument's power. If the first argument is NaN or infinite, the same
24639 value is returned. If the result underflows a zero with the same sign
24640 is returned. If the result overflows, the result is an infinity with
24644 '``llvm.experimental.constrained.sin``' Intrinsic
24645 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24653 @llvm.experimental.constrained.sin(<type> <op1>,
24654 metadata <rounding mode>,
24655 metadata <exception behavior>)
24660 The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the
24666 The first argument and the return type are floating-point numbers of the same
24669 The second and third arguments specify the rounding mode and exception
24670 behavior as described above.
24675 This function returns the sine of the specified operand, returning the
24676 same values as the libm ``sin`` functions would, and handles error
24677 conditions in the same way.
24680 '``llvm.experimental.constrained.cos``' Intrinsic
24681 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24689 @llvm.experimental.constrained.cos(<type> <op1>,
24690 metadata <rounding mode>,
24691 metadata <exception behavior>)
24696 The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the
24702 The first argument and the return type are floating-point numbers of the same
24705 The second and third arguments specify the rounding mode and exception
24706 behavior as described above.
24711 This function returns the cosine of the specified operand, returning the
24712 same values as the libm ``cos`` functions would, and handles error
24713 conditions in the same way.
24716 '``llvm.experimental.constrained.exp``' Intrinsic
24717 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24725 @llvm.experimental.constrained.exp(<type> <op1>,
24726 metadata <rounding mode>,
24727 metadata <exception behavior>)
24732 The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e
24733 exponential of the specified value.
24738 The first argument and the return value are floating-point numbers of the same
24741 The second and third arguments specify the rounding mode and exception
24742 behavior as described above.
24747 This function returns the same values as the libm ``exp`` functions
24748 would, and handles error conditions in the same way.
24751 '``llvm.experimental.constrained.exp2``' Intrinsic
24752 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24760 @llvm.experimental.constrained.exp2(<type> <op1>,
24761 metadata <rounding mode>,
24762 metadata <exception behavior>)
24767 The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2
24768 exponential of the specified value.
24774 The first argument and the return value are floating-point numbers of the same
24777 The second and third arguments specify the rounding mode and exception
24778 behavior as described above.
24783 This function returns the same values as the libm ``exp2`` functions
24784 would, and handles error conditions in the same way.
24787 '``llvm.experimental.constrained.log``' Intrinsic
24788 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24796 @llvm.experimental.constrained.log(<type> <op1>,
24797 metadata <rounding mode>,
24798 metadata <exception behavior>)
24803 The '``llvm.experimental.constrained.log``' intrinsic computes the base-e
24804 logarithm of the specified value.
24809 The first argument and the return value are floating-point numbers of the same
24812 The second and third arguments specify the rounding mode and exception
24813 behavior as described above.
24819 This function returns the same values as the libm ``log`` functions
24820 would, and handles error conditions in the same way.
24823 '``llvm.experimental.constrained.log10``' Intrinsic
24824 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24832 @llvm.experimental.constrained.log10(<type> <op1>,
24833 metadata <rounding mode>,
24834 metadata <exception behavior>)
24839 The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10
24840 logarithm of the specified value.
24845 The first argument and the return value are floating-point numbers of the same
24848 The second and third arguments specify the rounding mode and exception
24849 behavior as described above.
24854 This function returns the same values as the libm ``log10`` functions
24855 would, and handles error conditions in the same way.
24858 '``llvm.experimental.constrained.log2``' Intrinsic
24859 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24867 @llvm.experimental.constrained.log2(<type> <op1>,
24868 metadata <rounding mode>,
24869 metadata <exception behavior>)
24874 The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2
24875 logarithm of the specified value.
24880 The first argument and the return value are floating-point numbers of the same
24883 The second and third arguments specify the rounding mode and exception
24884 behavior as described above.
24889 This function returns the same values as the libm ``log2`` functions
24890 would, and handles error conditions in the same way.
24893 '``llvm.experimental.constrained.rint``' Intrinsic
24894 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24902 @llvm.experimental.constrained.rint(<type> <op1>,
24903 metadata <rounding mode>,
24904 metadata <exception behavior>)
24909 The '``llvm.experimental.constrained.rint``' intrinsic returns the first
24910 operand rounded to the nearest integer. It may raise an inexact floating-point
24911 exception if the operand is not an integer.
24916 The first argument and the return value are floating-point numbers of the same
24919 The second and third arguments specify the rounding mode and exception
24920 behavior as described above.
24925 This function returns the same values as the libm ``rint`` functions
24926 would, and handles error conditions in the same way. The rounding mode is
24927 described, not determined, by the rounding mode argument. The actual rounding
24928 mode is determined by the runtime floating-point environment. The rounding
24929 mode argument is only intended as information to the compiler.
24932 '``llvm.experimental.constrained.lrint``' Intrinsic
24933 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24941 @llvm.experimental.constrained.lrint(<fptype> <op1>,
24942 metadata <rounding mode>,
24943 metadata <exception behavior>)
24948 The '``llvm.experimental.constrained.lrint``' intrinsic returns the first
24949 operand rounded to the nearest integer. An inexact floating-point exception
24950 will be raised if the operand is not an integer. An invalid exception is
24951 raised if the result is too large to fit into a supported integer type,
24952 and in this case the result is undefined.
24957 The first argument is a floating-point number. The return value is an
24958 integer type. Not all types are supported on all targets. The supported
24959 types are the same as the ``llvm.lrint`` intrinsic and the ``lrint``
24962 The second and third arguments specify the rounding mode and exception
24963 behavior as described above.
24968 This function returns the same values as the libm ``lrint`` functions
24969 would, and handles error conditions in the same way.
24971 The rounding mode is described, not determined, by the rounding mode
24972 argument. The actual rounding mode is determined by the runtime floating-point
24973 environment. The rounding mode argument is only intended as information
24976 If the runtime floating-point environment is using the default rounding mode
24977 then the results will be the same as the llvm.lrint intrinsic.
24980 '``llvm.experimental.constrained.llrint``' Intrinsic
24981 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24989 @llvm.experimental.constrained.llrint(<fptype> <op1>,
24990 metadata <rounding mode>,
24991 metadata <exception behavior>)
24996 The '``llvm.experimental.constrained.llrint``' intrinsic returns the first
24997 operand rounded to the nearest integer. An inexact floating-point exception
24998 will be raised if the operand is not an integer. An invalid exception is
24999 raised if the result is too large to fit into a supported integer type,
25000 and in this case the result is undefined.
25005 The first argument is a floating-point number. The return value is an
25006 integer type. Not all types are supported on all targets. The supported
25007 types are the same as the ``llvm.llrint`` intrinsic and the ``llrint``
25010 The second and third arguments specify the rounding mode and exception
25011 behavior as described above.
25016 This function returns the same values as the libm ``llrint`` functions
25017 would, and handles error conditions in the same way.
25019 The rounding mode is described, not determined, by the rounding mode
25020 argument. The actual rounding mode is determined by the runtime floating-point
25021 environment. The rounding mode argument is only intended as information
25024 If the runtime floating-point environment is using the default rounding mode
25025 then the results will be the same as the llvm.llrint intrinsic.
25028 '``llvm.experimental.constrained.nearbyint``' Intrinsic
25029 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25037 @llvm.experimental.constrained.nearbyint(<type> <op1>,
25038 metadata <rounding mode>,
25039 metadata <exception behavior>)
25044 The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first
25045 operand rounded to the nearest integer. It will not raise an inexact
25046 floating-point exception if the operand is not an integer.
25052 The first argument and the return value are floating-point numbers of the same
25055 The second and third arguments specify the rounding mode and exception
25056 behavior as described above.
25061 This function returns the same values as the libm ``nearbyint`` functions
25062 would, and handles error conditions in the same way. The rounding mode is
25063 described, not determined, by the rounding mode argument. The actual rounding
25064 mode is determined by the runtime floating-point environment. The rounding
25065 mode argument is only intended as information to the compiler.
25068 '``llvm.experimental.constrained.maxnum``' Intrinsic
25069 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25077 @llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2>
25078 metadata <exception behavior>)
25083 The '``llvm.experimental.constrained.maxnum``' intrinsic returns the maximum
25084 of the two arguments.
25089 The first two arguments and the return value are floating-point numbers
25092 The third argument specifies the exception behavior as described above.
25097 This function follows the IEEE-754 semantics for maxNum.
25100 '``llvm.experimental.constrained.minnum``' Intrinsic
25101 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25109 @llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2>
25110 metadata <exception behavior>)
25115 The '``llvm.experimental.constrained.minnum``' intrinsic returns the minimum
25116 of the two arguments.
25121 The first two arguments and the return value are floating-point numbers
25124 The third argument specifies the exception behavior as described above.
25129 This function follows the IEEE-754 semantics for minNum.
25132 '``llvm.experimental.constrained.maximum``' Intrinsic
25133 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25141 @llvm.experimental.constrained.maximum(<type> <op1>, <type> <op2>
25142 metadata <exception behavior>)
25147 The '``llvm.experimental.constrained.maximum``' intrinsic returns the maximum
25148 of the two arguments, propagating NaNs and treating -0.0 as less than +0.0.
25153 The first two arguments and the return value are floating-point numbers
25156 The third argument specifies the exception behavior as described above.
25161 This function follows semantics specified in the draft of IEEE 754-2018.
25164 '``llvm.experimental.constrained.minimum``' Intrinsic
25165 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25173 @llvm.experimental.constrained.minimum(<type> <op1>, <type> <op2>
25174 metadata <exception behavior>)
25179 The '``llvm.experimental.constrained.minimum``' intrinsic returns the minimum
25180 of the two arguments, propagating NaNs and treating -0.0 as less than +0.0.
25185 The first two arguments and the return value are floating-point numbers
25188 The third argument specifies the exception behavior as described above.
25193 This function follows semantics specified in the draft of IEEE 754-2018.
25196 '``llvm.experimental.constrained.ceil``' Intrinsic
25197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25205 @llvm.experimental.constrained.ceil(<type> <op1>,
25206 metadata <exception behavior>)
25211 The '``llvm.experimental.constrained.ceil``' intrinsic returns the ceiling of the
25217 The first argument and the return value are floating-point numbers of the same
25220 The second argument specifies the exception behavior as described above.
25225 This function returns the same values as the libm ``ceil`` functions
25226 would and handles error conditions in the same way.
25229 '``llvm.experimental.constrained.floor``' Intrinsic
25230 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25238 @llvm.experimental.constrained.floor(<type> <op1>,
25239 metadata <exception behavior>)
25244 The '``llvm.experimental.constrained.floor``' intrinsic returns the floor of the
25250 The first argument and the return value are floating-point numbers of the same
25253 The second argument specifies the exception behavior as described above.
25258 This function returns the same values as the libm ``floor`` functions
25259 would and handles error conditions in the same way.
25262 '``llvm.experimental.constrained.round``' Intrinsic
25263 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25271 @llvm.experimental.constrained.round(<type> <op1>,
25272 metadata <exception behavior>)
25277 The '``llvm.experimental.constrained.round``' intrinsic returns the first
25278 operand rounded to the nearest integer.
25283 The first argument and the return value are floating-point numbers of the same
25286 The second argument specifies the exception behavior as described above.
25291 This function returns the same values as the libm ``round`` functions
25292 would and handles error conditions in the same way.
25295 '``llvm.experimental.constrained.roundeven``' Intrinsic
25296 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25304 @llvm.experimental.constrained.roundeven(<type> <op1>,
25305 metadata <exception behavior>)
25310 The '``llvm.experimental.constrained.roundeven``' intrinsic returns the first
25311 operand rounded to the nearest integer in floating-point format, rounding
25312 halfway cases to even (that is, to the nearest value that is an even integer),
25313 regardless of the current rounding direction.
25318 The first argument and the return value are floating-point numbers of the same
25321 The second argument specifies the exception behavior as described above.
25326 This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It
25327 also behaves in the same way as C standard function ``roundeven`` and can signal
25328 the invalid operation exception for a SNAN operand.
25331 '``llvm.experimental.constrained.lround``' Intrinsic
25332 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25340 @llvm.experimental.constrained.lround(<fptype> <op1>,
25341 metadata <exception behavior>)
25346 The '``llvm.experimental.constrained.lround``' intrinsic returns the first
25347 operand rounded to the nearest integer with ties away from zero. It will
25348 raise an inexact floating-point exception if the operand is not an integer.
25349 An invalid exception is raised if the result is too large to fit into a
25350 supported integer type, and in this case the result is undefined.
25355 The first argument is a floating-point number. The return value is an
25356 integer type. Not all types are supported on all targets. The supported
25357 types are the same as the ``llvm.lround`` intrinsic and the ``lround``
25360 The second argument specifies the exception behavior as described above.
25365 This function returns the same values as the libm ``lround`` functions
25366 would and handles error conditions in the same way.
25369 '``llvm.experimental.constrained.llround``' Intrinsic
25370 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25378 @llvm.experimental.constrained.llround(<fptype> <op1>,
25379 metadata <exception behavior>)
25384 The '``llvm.experimental.constrained.llround``' intrinsic returns the first
25385 operand rounded to the nearest integer with ties away from zero. It will
25386 raise an inexact floating-point exception if the operand is not an integer.
25387 An invalid exception is raised if the result is too large to fit into a
25388 supported integer type, and in this case the result is undefined.
25393 The first argument is a floating-point number. The return value is an
25394 integer type. Not all types are supported on all targets. The supported
25395 types are the same as the ``llvm.llround`` intrinsic and the ``llround``
25398 The second argument specifies the exception behavior as described above.
25403 This function returns the same values as the libm ``llround`` functions
25404 would and handles error conditions in the same way.
25407 '``llvm.experimental.constrained.trunc``' Intrinsic
25408 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25416 @llvm.experimental.constrained.trunc(<type> <op1>,
25417 metadata <exception behavior>)
25422 The '``llvm.experimental.constrained.trunc``' intrinsic returns the first
25423 operand rounded to the nearest integer not larger in magnitude than the
25429 The first argument and the return value are floating-point numbers of the same
25432 The second argument specifies the exception behavior as described above.
25437 This function returns the same values as the libm ``trunc`` functions
25438 would and handles error conditions in the same way.
25440 .. _int_experimental_noalias_scope_decl:
25442 '``llvm.experimental.noalias.scope.decl``' Intrinsic
25443 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25451 declare void @llvm.experimental.noalias.scope.decl(metadata !id.scope.list)
25456 The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a
25457 noalias scope is declared. When the intrinsic is duplicated, a decision must
25458 also be made about the scope: depending on the reason of the duplication,
25459 the scope might need to be duplicated as well.
25465 The ``!id.scope.list`` argument is metadata that is a list of ``noalias``
25466 metadata references. The format is identical to that required for ``noalias``
25467 metadata. This list must have exactly one element.
25472 The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a
25473 noalias scope is declared. When the intrinsic is duplicated, a decision must
25474 also be made about the scope: depending on the reason of the duplication,
25475 the scope might need to be duplicated as well.
25477 For example, when the intrinsic is used inside a loop body, and that loop is
25478 unrolled, the associated noalias scope must also be duplicated. Otherwise, the
25479 noalias property it signifies would spill across loop iterations, whereas it
25480 was only valid within a single iteration.
25482 .. code-block:: llvm
25484 ; This examples shows two possible positions for noalias.decl and how they impact the semantics:
25485 ; If it is outside the loop (Version 1), then %a and %b are noalias across *all* iterations.
25486 ; If it is inside the loop (Version 2), then %a and %b are noalias only within *one* iteration.
25487 declare void @decl_in_loop(ptr %a.base, ptr %b.base) {
25489 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 1: noalias decl outside loop
25493 %a = phi ptr [ %a.base, %entry ], [ %a.inc, %loop ]
25494 %b = phi ptr [ %b.base, %entry ], [ %b.inc, %loop ]
25495 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 2: noalias decl inside loop
25496 %val = load i8, ptr %a, !alias.scope !2
25497 store i8 %val, ptr %b, !noalias !2
25498 %a.inc = getelementptr inbounds i8, ptr %a, i64 1
25499 %b.inc = getelementptr inbounds i8, ptr %b, i64 1
25500 %cond = call i1 @cond()
25501 br i1 %cond, label %loop, label %exit
25507 !0 = !{!0} ; domain
25508 !1 = !{!1, !0} ; scope
25509 !2 = !{!1} ; scope list
25511 Multiple calls to `@llvm.experimental.noalias.scope.decl` for the same scope
25512 are possible, but one should never dominate another. Violations are pointed out
25513 by the verifier as they indicate a problem in either a transformation pass or
25517 Floating Point Environment Manipulation intrinsics
25518 --------------------------------------------------
25520 These functions read or write floating point environment, such as rounding
25521 mode or state of floating point exceptions. Altering the floating point
25522 environment requires special care. See :ref:`Floating Point Environment <floatenv>`.
25524 .. _int_get_rounding:
25526 '``llvm.get.rounding``' Intrinsic
25527 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25534 declare i32 @llvm.get.rounding()
25539 The '``llvm.get.rounding``' intrinsic reads the current rounding mode.
25544 The '``llvm.get.rounding``' intrinsic returns the current rounding mode.
25545 Encoding of the returned values is same as the result of ``FLT_ROUNDS``,
25546 specified by C standard:
25551 1 - to nearest, ties to even
25552 2 - toward positive infinity
25553 3 - toward negative infinity
25554 4 - to nearest, ties away from zero
25556 Other values may be used to represent additional rounding modes, supported by a
25557 target. These values are target-specific.
25559 '``llvm.set.rounding``' Intrinsic
25560 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25567 declare void @llvm.set.rounding(i32 <val>)
25572 The '``llvm.set.rounding``' intrinsic sets current rounding mode.
25577 The argument is the required rounding mode. Encoding of rounding mode is
25578 the same as used by '``llvm.get.rounding``'.
25583 The '``llvm.set.rounding``' intrinsic sets the current rounding mode. It is
25584 similar to C library function 'fesetround', however this intrinsic does not
25585 return any value and uses platform-independent representation of IEEE rounding
25589 '``llvm.get.fpenv``' Intrinsic
25590 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25597 declare <integer_type> @llvm.get.fpenv()
25602 The '``llvm.get.fpenv``' intrinsic returns bits of the current floating-point
25603 environment. The return value type is platform-specific.
25608 The '``llvm.get.fpenv``' intrinsic reads the current floating-point environment
25609 and returns it as an integer value.
25612 '``llvm.set.fpenv``' Intrinsic
25613 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25620 declare void @llvm.set.fpenv(<integer_type> <val>)
25625 The '``llvm.set.fpenv``' intrinsic sets the current floating-point environment.
25630 The argument is an integer representing the new floating-point environment. The
25631 integer type is platform-specific.
25636 The '``llvm.set.fpenv``' intrinsic sets the current floating-point environment
25637 to the state specified by the argument. The state may be previously obtained by a
25638 call to '``llvm.get.fpenv``' or synthesised in a platform-dependent way.
25641 '``llvm.reset.fpenv``' Intrinsic
25642 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25649 declare void @llvm.reset.fpenv()
25654 The '``llvm.reset.fpenv``' intrinsic sets the default floating-point environment.
25659 The '``llvm.reset.fpenv``' intrinsic sets the current floating-point environment
25660 to default state. It is similar to the call 'fesetenv(FE_DFL_ENV)', except it
25661 does not return any value.
25663 .. _int_get_fpmode:
25665 '``llvm.get.fpmode``' Intrinsic
25666 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25671 The '``llvm.get.fpmode``' intrinsic returns bits of the current floating-point
25672 control modes. The return value type is platform-specific.
25676 declare <integer_type> @llvm.get.fpmode()
25681 The '``llvm.get.fpmode``' intrinsic reads the current dynamic floating-point
25682 control modes and returns it as an integer value.
25692 The '``llvm.get.fpmode``' intrinsic reads the current dynamic floating-point
25693 control modes, such as rounding direction, precision, treatment of denormals and
25694 so on. It is similar to the C library function 'fegetmode', however this
25695 function does not store the set of control modes into memory but returns it as
25696 an integer value. Interpretation of the bits in this value is target-dependent.
25698 '``llvm.set.fpmode``' Intrinsic
25699 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25704 The '``llvm.set.fpmode``' intrinsic sets the current floating-point control modes.
25708 declare void @llvm.set.fpmode(<integer_type> <val>)
25713 The '``llvm.set.fpmode``' intrinsic sets the current dynamic floating-point
25719 The argument is a set of floating-point control modes, represented as an integer
25720 value in a target-dependent way.
25725 The '``llvm.set.fpmode``' intrinsic sets the current dynamic floating-point
25726 control modes to the state specified by the argument, which must be obtained by
25727 a call to '``llvm.get.fpmode``' or constructed in a target-specific way. It is
25728 similar to the C library function 'fesetmode', however this function does not
25729 read the set of control modes from memory but gets it as integer value.
25731 '``llvm.reset.fpmode``' Intrinsic
25732 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25739 declare void @llvm.reset.fpmode()
25744 The '``llvm.reset.fpmode``' intrinsic sets the default dynamic floating-point
25755 The '``llvm.reset.fpmode``' intrinsic sets the current dynamic floating-point
25756 environment to default state. It is similar to the C library function call
25757 'fesetmode(FE_DFL_MODE)', however this function does not return any value.
25760 Floating-Point Test Intrinsics
25761 ------------------------------
25763 These functions get properties of floating-point values.
25766 .. _llvm.is.fpclass:
25768 '``llvm.is.fpclass``' Intrinsic
25769 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25776 declare i1 @llvm.is.fpclass(<fptype> <op>, i32 <test>)
25777 declare <N x i1> @llvm.is.fpclass(<vector-fptype> <op>, i32 <test>)
25782 The '``llvm.is.fpclass``' intrinsic returns a boolean value or vector of boolean
25783 values depending on whether the first argument satisfies the test specified by
25784 the second argument.
25786 If the first argument is a floating-point scalar, then the result type is a
25787 boolean (:ref:`i1 <t_integer>`).
25789 If the first argument is a floating-point vector, then the result type is a
25790 vector of boolean with the same number of elements as the first argument.
25795 The first argument to the '``llvm.is.fpclass``' intrinsic must be
25796 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
25797 of floating-point values.
25799 The second argument specifies, which tests to perform. It must be a compile-time
25800 integer constant, each bit in which specifies floating-point class:
25802 +-------+----------------------+
25803 | Bit # | floating-point class |
25804 +=======+======================+
25805 | 0 | Signaling NaN |
25806 +-------+----------------------+
25808 +-------+----------------------+
25809 | 2 | Negative infinity |
25810 +-------+----------------------+
25811 | 3 | Negative normal |
25812 +-------+----------------------+
25813 | 4 | Negative subnormal |
25814 +-------+----------------------+
25815 | 5 | Negative zero |
25816 +-------+----------------------+
25817 | 6 | Positive zero |
25818 +-------+----------------------+
25819 | 7 | Positive subnormal |
25820 +-------+----------------------+
25821 | 8 | Positive normal |
25822 +-------+----------------------+
25823 | 9 | Positive infinity |
25824 +-------+----------------------+
25829 The function checks if ``op`` belongs to any of the floating-point classes
25830 specified by ``test``. If ``op`` is a vector, then the check is made element by
25831 element. Each check yields an :ref:`i1 <t_integer>` result, which is ``true``,
25832 if the element value satisfies the specified test. The argument ``test`` is a
25833 bit mask where each bit specifies floating-point class to test. For example, the
25834 value 0x108 makes test for normal value, - bits 3 and 8 in it are set, which
25835 means that the function returns ``true`` if ``op`` is a positive or negative
25836 normal value. The function never raises floating-point exceptions. The
25837 function does not canonicalize its input value and does not depend
25838 on the floating-point environment. If the floating-point environment
25839 has a zeroing treatment of subnormal input values (such as indicated
25840 by the ``"denormal-fp-math"`` attribute), a subnormal value will be
25841 observed (will not be implicitly treated as zero).
25847 This class of intrinsics is designed to be generic and has no specific
25850 '``llvm.var.annotation``' Intrinsic
25851 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25858 declare void @llvm.var.annotation(ptr <val>, ptr <str>, ptr <str>, i32 <int>)
25863 The '``llvm.var.annotation``' intrinsic.
25868 The first argument is a pointer to a value, the second is a pointer to a
25869 global string, the third is a pointer to a global string which is the
25870 source file name, and the last argument is the line number.
25875 This intrinsic allows annotation of local variables with arbitrary
25876 strings. This can be useful for special purpose optimizations that want
25877 to look for these annotations. These have no other defined use; they are
25878 ignored by code generation and optimization.
25880 '``llvm.ptr.annotation.*``' Intrinsic
25881 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25886 This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a
25887 pointer to an integer of any width. *NOTE* you must specify an address space for
25888 the pointer. The identifier for the default address space is the integer
25893 declare ptr @llvm.ptr.annotation.p0(ptr <val>, ptr <str>, ptr <str>, i32 <int>)
25894 declare ptr @llvm.ptr.annotation.p1(ptr addrspace(1) <val>, ptr <str>, ptr <str>, i32 <int>)
25899 The '``llvm.ptr.annotation``' intrinsic.
25904 The first argument is a pointer to an integer value of arbitrary bitwidth
25905 (result of some expression), the second is a pointer to a global string, the
25906 third is a pointer to a global string which is the source file name, and the
25907 last argument is the line number. It returns the value of the first argument.
25912 This intrinsic allows annotation of a pointer to an integer with arbitrary
25913 strings. This can be useful for special purpose optimizations that want to look
25914 for these annotations. These have no other defined use; transformations preserve
25915 annotations on a best-effort basis but are allowed to replace the intrinsic with
25916 its first argument without breaking semantics and the intrinsic is completely
25917 dropped during instruction selection.
25919 '``llvm.annotation.*``' Intrinsic
25920 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25925 This is an overloaded intrinsic. You can use '``llvm.annotation``' on
25926 any integer bit width.
25930 declare i8 @llvm.annotation.i8(i8 <val>, ptr <str>, ptr <str>, i32 <int>)
25931 declare i16 @llvm.annotation.i16(i16 <val>, ptr <str>, ptr <str>, i32 <int>)
25932 declare i32 @llvm.annotation.i32(i32 <val>, ptr <str>, ptr <str>, i32 <int>)
25933 declare i64 @llvm.annotation.i64(i64 <val>, ptr <str>, ptr <str>, i32 <int>)
25934 declare i256 @llvm.annotation.i256(i256 <val>, ptr <str>, ptr <str>, i32 <int>)
25939 The '``llvm.annotation``' intrinsic.
25944 The first argument is an integer value (result of some expression), the
25945 second is a pointer to a global string, the third is a pointer to a
25946 global string which is the source file name, and the last argument is
25947 the line number. It returns the value of the first argument.
25952 This intrinsic allows annotations to be put on arbitrary expressions with
25953 arbitrary strings. This can be useful for special purpose optimizations that
25954 want to look for these annotations. These have no other defined use;
25955 transformations preserve annotations on a best-effort basis but are allowed to
25956 replace the intrinsic with its first argument without breaking semantics and the
25957 intrinsic is completely dropped during instruction selection.
25959 '``llvm.codeview.annotation``' Intrinsic
25960 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25965 This annotation emits a label at its program point and an associated
25966 ``S_ANNOTATION`` codeview record with some additional string metadata. This is
25967 used to implement MSVC's ``__annotation`` intrinsic. It is marked
25968 ``noduplicate``, so calls to this intrinsic prevent inlining and should be
25969 considered expensive.
25973 declare void @llvm.codeview.annotation(metadata)
25978 The argument should be an MDTuple containing any number of MDStrings.
25980 '``llvm.trap``' Intrinsic
25981 ^^^^^^^^^^^^^^^^^^^^^^^^^
25988 declare void @llvm.trap() cold noreturn nounwind
25993 The '``llvm.trap``' intrinsic.
26003 This intrinsic is lowered to the target dependent trap instruction. If
26004 the target does not have a trap instruction, this intrinsic will be
26005 lowered to a call of the ``abort()`` function.
26007 '``llvm.debugtrap``' Intrinsic
26008 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26015 declare void @llvm.debugtrap() nounwind
26020 The '``llvm.debugtrap``' intrinsic.
26030 This intrinsic is lowered to code which is intended to cause an
26031 execution trap with the intention of requesting the attention of a
26034 '``llvm.ubsantrap``' Intrinsic
26035 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26042 declare void @llvm.ubsantrap(i8 immarg) cold noreturn nounwind
26047 The '``llvm.ubsantrap``' intrinsic.
26052 An integer describing the kind of failure detected.
26057 This intrinsic is lowered to code which is intended to cause an execution trap,
26058 embedding the argument into encoding of that trap somehow to discriminate
26059 crashes if possible.
26061 Equivalent to ``@llvm.trap`` for targets that do not support this behaviour.
26063 '``llvm.stackprotector``' Intrinsic
26064 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26071 declare void @llvm.stackprotector(ptr <guard>, ptr <slot>)
26076 The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it
26077 onto the stack at ``slot``. The stack slot is adjusted to ensure that it
26078 is placed on the stack before local variables.
26083 The ``llvm.stackprotector`` intrinsic requires two pointer arguments.
26084 The first argument is the value loaded from the stack guard
26085 ``@__stack_chk_guard``. The second variable is an ``alloca`` that has
26086 enough space to hold the value of the guard.
26091 This intrinsic causes the prologue/epilogue inserter to force the position of
26092 the ``AllocaInst`` stack slot to be before local variables on the stack. This is
26093 to ensure that if a local variable on the stack is overwritten, it will destroy
26094 the value of the guard. When the function exits, the guard on the stack is
26095 checked against the original guard by ``llvm.stackprotectorcheck``. If they are
26096 different, then ``llvm.stackprotectorcheck`` causes the program to abort by
26097 calling the ``__stack_chk_fail()`` function.
26099 '``llvm.stackguard``' Intrinsic
26100 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26107 declare ptr @llvm.stackguard()
26112 The ``llvm.stackguard`` intrinsic returns the system stack guard value.
26114 It should not be generated by frontends, since it is only for internal usage.
26115 The reason why we create this intrinsic is that we still support IR form Stack
26116 Protector in FastISel.
26126 On some platforms, the value returned by this intrinsic remains unchanged
26127 between loads in the same thread. On other platforms, it returns the same
26128 global variable value, if any, e.g. ``@__stack_chk_guard``.
26130 Currently some platforms have IR-level customized stack guard loading (e.g.
26131 X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be
26134 '``llvm.objectsize``' Intrinsic
26135 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26142 declare i32 @llvm.objectsize.i32(ptr <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
26143 declare i64 @llvm.objectsize.i64(ptr <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
26148 The ``llvm.objectsize`` intrinsic is designed to provide information to the
26149 optimizer to determine whether a) an operation (like memcpy) will overflow a
26150 buffer that corresponds to an object, or b) that a runtime check for overflow
26151 isn't necessary. An object in this context means an allocation of a specific
26152 class, structure, array, or other object.
26157 The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a
26158 pointer to or into the ``object``. The second argument determines whether
26159 ``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size is
26160 unknown. The third argument controls how ``llvm.objectsize`` acts when ``null``
26161 in address space 0 is used as its pointer argument. If it's ``false``,
26162 ``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if
26163 the ``null`` is in a non-zero address space or if ``true`` is given for the
26164 third argument of ``llvm.objectsize``, we assume its size is unknown. The fourth
26165 argument to ``llvm.objectsize`` determines if the value should be evaluated at
26168 The second, third, and fourth arguments only accept constants.
26173 The ``llvm.objectsize`` intrinsic is lowered to a value representing the size of
26174 the object concerned. If the size cannot be determined, ``llvm.objectsize``
26175 returns ``i32/i64 -1 or 0`` (depending on the ``min`` argument).
26177 '``llvm.expect``' Intrinsic
26178 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
26183 This is an overloaded intrinsic. You can use ``llvm.expect`` on any
26188 declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>)
26189 declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
26190 declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
26195 The ``llvm.expect`` intrinsic provides information about expected (the
26196 most probable) value of ``val``, which can be used by optimizers.
26201 The ``llvm.expect`` intrinsic takes two arguments. The first argument is
26202 a value. The second argument is an expected value.
26207 This intrinsic is lowered to the ``val``.
26209 '``llvm.expect.with.probability``' Intrinsic
26210 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26215 This intrinsic is similar to ``llvm.expect``. This is an overloaded intrinsic.
26216 You can use ``llvm.expect.with.probability`` on any integer bit width.
26220 declare i1 @llvm.expect.with.probability.i1(i1 <val>, i1 <expected_val>, double <prob>)
26221 declare i32 @llvm.expect.with.probability.i32(i32 <val>, i32 <expected_val>, double <prob>)
26222 declare i64 @llvm.expect.with.probability.i64(i64 <val>, i64 <expected_val>, double <prob>)
26227 The ``llvm.expect.with.probability`` intrinsic provides information about
26228 expected value of ``val`` with probability(or confidence) ``prob``, which can
26229 be used by optimizers.
26234 The ``llvm.expect.with.probability`` intrinsic takes three arguments. The first
26235 argument is a value. The second argument is an expected value. The third
26236 argument is a probability.
26241 This intrinsic is lowered to the ``val``.
26245 '``llvm.assume``' Intrinsic
26246 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26253 declare void @llvm.assume(i1 %cond)
26258 The ``llvm.assume`` allows the optimizer to assume that the provided
26259 condition is true. This information can then be used in simplifying other parts
26262 More complex assumptions can be encoded as
26263 :ref:`assume operand bundles <assume_opbundles>`.
26268 The argument of the call is the condition which the optimizer may assume is
26274 The intrinsic allows the optimizer to assume that the provided condition is
26275 always true whenever the control flow reaches the intrinsic call. No code is
26276 generated for this intrinsic, and instructions that contribute only to the
26277 provided condition are not used for code generation. If the condition is
26278 violated during execution, the behavior is undefined.
26280 Note that the optimizer might limit the transformations performed on values
26281 used by the ``llvm.assume`` intrinsic in order to preserve the instructions
26282 only used to form the intrinsic's input argument. This might prove undesirable
26283 if the extra information provided by the ``llvm.assume`` intrinsic does not cause
26284 sufficient overall improvement in code quality. For this reason,
26285 ``llvm.assume`` should not be used to document basic mathematical invariants
26286 that the optimizer can otherwise deduce or facts that are of little use to the
26291 '``llvm.ssa.copy``' Intrinsic
26292 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26299 declare type @llvm.ssa.copy(type returned %operand) memory(none)
26304 The first argument is an operand which is used as the returned value.
26309 The ``llvm.ssa.copy`` intrinsic can be used to attach information to
26310 operations by copying them and giving them new names. For example,
26311 the PredicateInfo utility uses it to build Extended SSA form, and
26312 attach various forms of information to operands that dominate specific
26313 uses. It is not meant for general use, only for building temporary
26314 renaming forms that require value splits at certain points.
26318 '``llvm.type.test``' Intrinsic
26319 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26326 declare i1 @llvm.type.test(ptr %ptr, metadata %type) nounwind memory(none)
26332 The first argument is a pointer to be tested. The second argument is a
26333 metadata object representing a :doc:`type identifier <TypeMetadata>`.
26338 The ``llvm.type.test`` intrinsic tests whether the given pointer is associated
26339 with the given type identifier.
26341 .. _type.checked.load:
26343 '``llvm.type.checked.load``' Intrinsic
26344 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26351 declare {ptr, i1} @llvm.type.checked.load(ptr %ptr, i32 %offset, metadata %type) nounwind memory(argmem: read)
26357 The first argument is a pointer from which to load a function pointer. The
26358 second argument is the byte offset from which to load the function pointer. The
26359 third argument is a metadata object representing a :doc:`type identifier
26365 The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a
26366 virtual table pointer using type metadata. This intrinsic is used to implement
26367 control flow integrity in conjunction with virtual call optimization. The
26368 virtual call optimization pass will optimize away ``llvm.type.checked.load``
26369 intrinsics associated with devirtualized calls, thereby removing the type
26370 check in cases where it is not needed to enforce the control flow integrity
26373 If the given pointer is associated with a type metadata identifier, this
26374 function returns true as the second element of its return value. (Note that
26375 the function may also return true if the given pointer is not associated
26376 with a type metadata identifier.) If the function's return value's second
26377 element is true, the following rules apply to the first element:
26379 - If the given pointer is associated with the given type metadata identifier,
26380 it is the function pointer loaded from the given byte offset from the given
26383 - If the given pointer is not associated with the given type metadata
26384 identifier, it is one of the following (the choice of which is unspecified):
26386 1. The function pointer that would have been loaded from an arbitrarily chosen
26387 (through an unspecified mechanism) pointer associated with the type
26390 2. If the function has a non-void return type, a pointer to a function that
26391 returns an unspecified value without causing side effects.
26393 If the function's return value's second element is false, the value of the
26394 first element is undefined.
26396 .. _type.checked.load.relative:
26398 '``llvm.type.checked.load.relative``' Intrinsic
26399 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26406 declare {ptr, i1} @llvm.type.checked.load.relative(ptr %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly
26411 The ``llvm.type.checked.load.relative`` intrinsic loads a relative pointer to a
26412 function from a virtual table pointer using metadata. Otherwise, its semantic is
26413 identical to the ``llvm.type.checked.load`` intrinsic.
26415 A relative pointer is a pointer to an offset to the pointed to value. The
26416 address of the underlying pointer of the relative pointer is obtained by adding
26417 the offset to the address of the offset value.
26419 '``llvm.arithmetic.fence``' Intrinsic
26420 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26428 @llvm.arithmetic.fence(<type> <op>)
26433 The purpose of the ``llvm.arithmetic.fence`` intrinsic
26434 is to prevent the optimizer from performing fast-math optimizations,
26435 particularly reassociation,
26436 between the argument and the expression that contains the argument.
26437 It can be used to preserve the parentheses in the source language.
26442 The ``llvm.arithmetic.fence`` intrinsic takes only one argument.
26443 The argument and the return value are floating-point numbers,
26444 or vector floating-point numbers, of the same type.
26449 This intrinsic returns the value of its operand. The optimizer can optimize
26450 the argument, but the optimizer cannot hoist any component of the operand
26451 to the containing context, and the optimizer cannot move the calculation of
26452 any expression in the containing context into the operand.
26455 '``llvm.donothing``' Intrinsic
26456 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26463 declare void @llvm.donothing() nounwind memory(none)
26468 The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only
26469 three intrinsics (besides ``llvm.experimental.patchpoint`` and
26470 ``llvm.experimental.gc.statepoint``) that can be called with an invoke
26481 This intrinsic does nothing, and it's removed by optimizers and ignored
26484 '``llvm.experimental.deoptimize``' Intrinsic
26485 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26492 declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ]
26497 This intrinsic, together with :ref:`deoptimization operand bundles
26498 <deopt_opbundles>`, allow frontends to express transfer of control and
26499 frame-local state from the currently executing (typically more specialized,
26500 hence faster) version of a function into another (typically more generic, hence
26503 In languages with a fully integrated managed runtime like Java and JavaScript
26504 this intrinsic can be used to implement "uncommon trap" or "side exit" like
26505 functionality. In unmanaged languages like C and C++, this intrinsic can be
26506 used to represent the slow paths of specialized functions.
26512 The intrinsic takes an arbitrary number of arguments, whose meaning is
26513 decided by the :ref:`lowering strategy<deoptimize_lowering>`.
26518 The ``@llvm.experimental.deoptimize`` intrinsic executes an attached
26519 deoptimization continuation (denoted using a :ref:`deoptimization
26520 operand bundle <deopt_opbundles>`) and returns the value returned by
26521 the deoptimization continuation. Defining the semantic properties of
26522 the continuation itself is out of scope of the language reference --
26523 as far as LLVM is concerned, the deoptimization continuation can
26524 invoke arbitrary side effects, including reading from and writing to
26527 Deoptimization continuations expressed using ``"deopt"`` operand bundles always
26528 continue execution to the end of the physical frame containing them, so all
26529 calls to ``@llvm.experimental.deoptimize`` must be in "tail position":
26531 - ``@llvm.experimental.deoptimize`` cannot be invoked.
26532 - The call must immediately precede a :ref:`ret <i_ret>` instruction.
26533 - The ``ret`` instruction must return the value produced by the
26534 ``@llvm.experimental.deoptimize`` call if there is one, or void.
26536 Note that the above restrictions imply that the return type for a call to
26537 ``@llvm.experimental.deoptimize`` will match the return type of its immediate
26540 The inliner composes the ``"deopt"`` continuations of the caller into the
26541 ``"deopt"`` continuations present in the inlinee, and also updates calls to this
26542 intrinsic to return directly from the frame of the function it inlined into.
26544 All declarations of ``@llvm.experimental.deoptimize`` must share the
26545 same calling convention.
26547 .. _deoptimize_lowering:
26552 Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the
26553 symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to
26554 ensure that this symbol is defined). The call arguments to
26555 ``@llvm.experimental.deoptimize`` are lowered as if they were formal
26556 arguments of the specified types, and not as varargs.
26559 '``llvm.experimental.guard``' Intrinsic
26560 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26567 declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ]
26572 This intrinsic, together with :ref:`deoptimization operand bundles
26573 <deopt_opbundles>`, allows frontends to express guards or checks on
26574 optimistic assumptions made during compilation. The semantics of
26575 ``@llvm.experimental.guard`` is defined in terms of
26576 ``@llvm.experimental.deoptimize`` -- its body is defined to be
26579 .. code-block:: text
26581 define void @llvm.experimental.guard(i1 %pred, <args...>) {
26582 %realPred = and i1 %pred, undef
26583 br i1 %realPred, label %continue, label %leave [, !make.implicit !{}]
26586 call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ]
26594 with the optional ``[, !make.implicit !{}]`` present if and only if it
26595 is present on the call site. For more details on ``!make.implicit``,
26596 see :doc:`FaultMaps`.
26598 In words, ``@llvm.experimental.guard`` executes the attached
26599 ``"deopt"`` continuation if (but **not** only if) its first argument
26600 is ``false``. Since the optimizer is allowed to replace the ``undef``
26601 with an arbitrary value, it can optimize guard to fail "spuriously",
26602 i.e. without the original condition being false (hence the "not only
26603 if"); and this allows for "check widening" type optimizations.
26605 ``@llvm.experimental.guard`` cannot be invoked.
26607 After ``@llvm.experimental.guard`` was first added, a more general
26608 formulation was found in ``@llvm.experimental.widenable.condition``.
26609 Support for ``@llvm.experimental.guard`` is slowly being rephrased in
26610 terms of this alternate.
26612 '``llvm.experimental.widenable.condition``' Intrinsic
26613 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26620 declare i1 @llvm.experimental.widenable.condition()
26625 This intrinsic represents a "widenable condition" which is
26626 boolean expressions with the following property: whether this
26627 expression is `true` or `false`, the program is correct and
26630 Together with :ref:`deoptimization operand bundles <deopt_opbundles>`,
26631 ``@llvm.experimental.widenable.condition`` allows frontends to
26632 express guards or checks on optimistic assumptions made during
26633 compilation and represent them as branch instructions on special
26636 While this may appear similar in semantics to `undef`, it is very
26637 different in that an invocation produces a particular, singular
26638 value. It is also intended to be lowered late, and remain available
26639 for specific optimizations and transforms that can benefit from its
26640 special properties.
26650 The intrinsic ``@llvm.experimental.widenable.condition()``
26651 returns either `true` or `false`. For each evaluation of a call
26652 to this intrinsic, the program must be valid and correct both if
26653 it returns `true` and if it returns `false`. This allows
26654 transformation passes to replace evaluations of this intrinsic
26655 with either value whenever one is beneficial.
26657 When used in a branch condition, it allows us to choose between
26658 two alternative correct solutions for the same problem, like
26661 .. code-block:: text
26663 %cond = call i1 @llvm.experimental.widenable.condition()
26664 br i1 %cond, label %solution_1, label %solution_2
26667 ; Apply memory-consuming but fast solution for a task.
26670 ; Cheap in memory but slow solution.
26672 Whether the result of intrinsic's call is `true` or `false`,
26673 it should be correct to pick either solution. We can switch
26674 between them by replacing the result of
26675 ``@llvm.experimental.widenable.condition`` with different
26678 This is how it can be used to represent guards as widenable branches:
26680 .. code-block:: text
26683 ; Unguarded instructions
26684 call void @llvm.experimental.guard(i1 %cond, <args...>) ["deopt"(<deopt_args...>)]
26685 ; Guarded instructions
26687 Can be expressed in an alternative equivalent form of explicit branch using
26688 ``@llvm.experimental.widenable.condition``:
26690 .. code-block:: text
26693 ; Unguarded instructions
26694 %widenable_condition = call i1 @llvm.experimental.widenable.condition()
26695 %guard_condition = and i1 %cond, %widenable_condition
26696 br i1 %guard_condition, label %guarded, label %deopt
26699 ; Guarded instructions
26702 call type @llvm.experimental.deoptimize(<args...>) [ "deopt"(<deopt_args...>) ]
26704 So the block `guarded` is only reachable when `%cond` is `true`,
26705 and it should be valid to go to the block `deopt` whenever `%cond`
26706 is `true` or `false`.
26708 ``@llvm.experimental.widenable.condition`` will never throw, thus
26709 it cannot be invoked.
26714 When ``@llvm.experimental.widenable.condition()`` is used in
26715 condition of a guard represented as explicit branch, it is
26716 legal to widen the guard's condition with any additional
26719 Guard widening looks like replacement of
26721 .. code-block:: text
26723 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
26724 %guard_cond = and i1 %cond, %widenable_cond
26725 br i1 %guard_cond, label %guarded, label %deopt
26729 .. code-block:: text
26731 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
26732 %new_cond = and i1 %any_other_cond, %widenable_cond
26733 %new_guard_cond = and i1 %cond, %new_cond
26734 br i1 %new_guard_cond, label %guarded, label %deopt
26736 for this branch. Here `%any_other_cond` is an arbitrarily chosen
26737 well-defined `i1` value. By making guard widening, we may
26738 impose stricter conditions on `guarded` block and bail to the
26739 deopt when the new condition is not met.
26744 Default lowering strategy is replacing the result of
26745 call of ``@llvm.experimental.widenable.condition`` with
26746 constant `true`. However it is always correct to replace
26747 it with any other `i1` value. Any pass can
26748 freely do it if it can benefit from non-default lowering.
26751 '``llvm.load.relative``' Intrinsic
26752 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26759 declare ptr @llvm.load.relative.iN(ptr %ptr, iN %offset) nounwind memory(argmem: read)
26764 This intrinsic loads a 32-bit value from the address ``%ptr + %offset``,
26765 adds ``%ptr`` to that value and returns it. The constant folder specifically
26766 recognizes the form of this intrinsic and the constant initializers it may
26767 load from; if a loaded constant initializer is known to have the form
26768 ``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``.
26770 LLVM provides that the calculation of such a constant initializer will
26771 not overflow at link time under the medium code model if ``x`` is an
26772 ``unnamed_addr`` function. However, it does not provide this guarantee for
26773 a constant initializer folded into a function body. This intrinsic can be
26774 used to avoid the possibility of overflows when loading from such a constant.
26776 .. _llvm_sideeffect:
26778 '``llvm.sideeffect``' Intrinsic
26779 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26786 declare void @llvm.sideeffect() inaccessiblememonly nounwind willreturn
26791 The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers
26792 treat it as having side effects, so it can be inserted into a loop to
26793 indicate that the loop shouldn't be assumed to terminate (which could
26794 potentially lead to the loop being optimized away entirely), even if it's
26795 an infinite loop with no other side effects.
26805 This intrinsic actually does nothing, but optimizers must assume that it
26806 has externally observable side effects.
26808 '``llvm.is.constant.*``' Intrinsic
26809 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26814 This is an overloaded intrinsic. You can use llvm.is.constant with any argument type.
26818 declare i1 @llvm.is.constant.i32(i32 %operand) nounwind memory(none)
26819 declare i1 @llvm.is.constant.f32(float %operand) nounwind memory(none)
26820 declare i1 @llvm.is.constant.TYPENAME(TYPE %operand) nounwind memory(none)
26825 The '``llvm.is.constant``' intrinsic will return true if the argument
26826 is known to be a manifest compile-time constant. It is guaranteed to
26827 fold to either true or false before generating machine code.
26832 This intrinsic generates no code. If its argument is known to be a
26833 manifest compile-time constant value, then the intrinsic will be
26834 converted to a constant true value. Otherwise, it will be converted to
26835 a constant false value.
26837 In particular, note that if the argument is a constant expression
26838 which refers to a global (the address of which _is_ a constant, but
26839 not manifest during the compile), then the intrinsic evaluates to
26842 The result also intentionally depends on the result of optimization
26843 passes -- e.g., the result can change depending on whether a
26844 function gets inlined or not. A function's parameters are
26845 obviously not constant. However, a call like
26846 ``llvm.is.constant.i32(i32 %param)`` *can* return true after the
26847 function is inlined, if the value passed to the function parameter was
26850 On the other hand, if constant folding is not run, it will never
26851 evaluate to true, even in simple cases.
26855 '``llvm.ptrmask``' Intrinsic
26856 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26863 declare ptrty llvm.ptrmask(ptrty %ptr, intty %mask) speculatable memory(none)
26868 The first argument is a pointer. The second argument is an integer.
26873 The ``llvm.ptrmask`` intrinsic masks out bits of the pointer according to a mask.
26874 This allows stripping data from tagged pointers without converting them to an
26875 integer (ptrtoint/inttoptr). As a consequence, we can preserve more information
26876 to facilitate alias analysis and underlying-object detection.
26881 The result of ``ptrmask(ptr, mask)`` is equivalent to
26882 ``getelementptr ptr, (ptrtoint(ptr) & mask) - ptrtoint(ptr)``. Both the returned
26883 pointer and the first argument are based on the same underlying object (for more
26884 information on the *based on* terminology see
26885 :ref:`the pointer aliasing rules <pointeraliasing>`). If the bitwidth of the
26886 mask argument does not match the pointer size of the target, the mask is
26887 zero-extended or truncated accordingly.
26889 .. _int_threadlocal_address:
26891 '``llvm.threadlocal.address``' Intrinsic
26892 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26899 declare ptr @llvm.threadlocal.address(ptr) nounwind willreturn memory(none)
26904 The first argument is a pointer, which refers to a thread local global.
26909 The address of a thread local global is not a constant, since it depends on
26910 the calling thread. The `llvm.threadlocal.address` intrinsic returns the
26911 address of the given thread local global in the calling thread.
26915 '``llvm.vscale``' Intrinsic
26916 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
26923 declare i32 llvm.vscale.i32()
26924 declare i64 llvm.vscale.i64()
26929 The ``llvm.vscale`` intrinsic returns the value for ``vscale`` in scalable
26930 vectors such as ``<vscale x 16 x i8>``.
26935 ``vscale`` is a positive value that is constant throughout program
26936 execution, but is unknown at compile time.
26937 If the result value does not fit in the result type, then the result is
26938 a :ref:`poison value <poisonvalues>`.
26941 Stack Map Intrinsics
26942 --------------------
26944 LLVM provides experimental intrinsics to support runtime patching
26945 mechanisms commonly desired in dynamic language JITs. These intrinsics
26946 are described in :doc:`StackMaps`.
26948 Element Wise Atomic Memory Intrinsics
26949 -------------------------------------
26951 These intrinsics are similar to the standard library memory intrinsics except
26952 that they perform memory transfer as a sequence of atomic memory accesses.
26954 .. _int_memcpy_element_unordered_atomic:
26956 '``llvm.memcpy.element.unordered.atomic``' Intrinsic
26957 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26962 This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on
26963 any integer bit width and for different address spaces. Not all targets
26964 support all bit widths however.
26968 declare void @llvm.memcpy.element.unordered.atomic.p0.p0.i32(ptr <dest>,
26971 i32 <element_size>)
26972 declare void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr <dest>,
26975 i32 <element_size>)
26980 The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the
26981 '``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated
26982 as arrays with elements that are exactly ``element_size`` bytes, and the copy between
26983 buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations
26984 that are a positive integer multiple of the ``element_size`` in size.
26989 The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>`
26990 intrinsic, with the added constraint that ``len`` is required to be a positive integer
26991 multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
26992 ``element_size``, then the behaviour of the intrinsic is undefined.
26994 ``element_size`` must be a compile-time constant positive power of two no greater than
26995 target-specific atomic access size limit.
26997 For each of the input pointers ``align`` parameter attribute must be specified. It
26998 must be a power of two no less than the ``element_size``. Caller guarantees that
26999 both the source and destination pointers are aligned to that boundary.
27004 The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of
27005 memory from the source location to the destination location. These locations are not
27006 allowed to overlap. The memory copy is performed as a sequence of load/store operations
27007 where each access is guaranteed to be a multiple of ``element_size`` bytes wide and
27008 aligned at an ``element_size`` boundary.
27010 The order of the copy is unspecified. The same value may be read from the source
27011 buffer many times, but only one write is issued to the destination buffer per
27012 element. It is well defined to have concurrent reads and writes to both source and
27013 destination provided those reads and writes are unordered atomic when specified.
27015 This intrinsic does not provide any additional ordering guarantees over those
27016 provided by a set of unordered loads from the source location and stores to the
27022 In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is
27023 lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*'
27024 is replaced with an actual element size. See :ref:`RewriteStatepointsForGC intrinsic
27025 lowering <RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific
27028 Optimizer is allowed to inline memory copy when it's profitable to do so.
27030 '``llvm.memmove.element.unordered.atomic``' Intrinsic
27031 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27036 This is an overloaded intrinsic. You can use
27037 ``llvm.memmove.element.unordered.atomic`` on any integer bit width and for
27038 different address spaces. Not all targets support all bit widths however.
27042 declare void @llvm.memmove.element.unordered.atomic.p0.p0.i32(ptr <dest>,
27045 i32 <element_size>)
27046 declare void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr <dest>,
27049 i32 <element_size>)
27054 The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization
27055 of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and
27056 ``src`` are treated as arrays with elements that are exactly ``element_size``
27057 bytes, and the copy between buffers uses a sequence of
27058 :ref:`unordered atomic <ordering>` load/store operations that are a positive
27059 integer multiple of the ``element_size`` in size.
27064 The first three arguments are the same as they are in the
27065 :ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that
27066 ``len`` is required to be a positive integer multiple of the ``element_size``.
27067 If ``len`` is not a positive integer multiple of ``element_size``, then the
27068 behaviour of the intrinsic is undefined.
27070 ``element_size`` must be a compile-time constant positive power of two no
27071 greater than a target-specific atomic access size limit.
27073 For each of the input pointers the ``align`` parameter attribute must be
27074 specified. It must be a power of two no less than the ``element_size``. Caller
27075 guarantees that both the source and destination pointers are aligned to that
27081 The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes
27082 of memory from the source location to the destination location. These locations
27083 are allowed to overlap. The memory copy is performed as a sequence of load/store
27084 operations where each access is guaranteed to be a multiple of ``element_size``
27085 bytes wide and aligned at an ``element_size`` boundary.
27087 The order of the copy is unspecified. The same value may be read from the source
27088 buffer many times, but only one write is issued to the destination buffer per
27089 element. It is well defined to have concurrent reads and writes to both source
27090 and destination provided those reads and writes are unordered atomic when
27093 This intrinsic does not provide any additional ordering guarantees over those
27094 provided by a set of unordered loads from the source location and stores to the
27100 In the most general case call to the
27101 '``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol
27102 ``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an
27103 actual element size. See :ref:`RewriteStatepointsForGC intrinsic lowering
27104 <RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific
27107 The optimizer is allowed to inline the memory copy when it's profitable to do so.
27109 .. _int_memset_element_unordered_atomic:
27111 '``llvm.memset.element.unordered.atomic``' Intrinsic
27112 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27117 This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on
27118 any integer bit width and for different address spaces. Not all targets
27119 support all bit widths however.
27123 declare void @llvm.memset.element.unordered.atomic.p0.i32(ptr <dest>,
27126 i32 <element_size>)
27127 declare void @llvm.memset.element.unordered.atomic.p0.i64(ptr <dest>,
27130 i32 <element_size>)
27135 The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the
27136 '``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array
27137 with elements that are exactly ``element_size`` bytes, and the assignment to that array
27138 uses uses a sequence of :ref:`unordered atomic <ordering>` store operations
27139 that are a positive integer multiple of the ``element_size`` in size.
27144 The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>`
27145 intrinsic, with the added constraint that ``len`` is required to be a positive integer
27146 multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
27147 ``element_size``, then the behaviour of the intrinsic is undefined.
27149 ``element_size`` must be a compile-time constant positive power of two no greater than
27150 target-specific atomic access size limit.
27152 The ``dest`` input pointer must have the ``align`` parameter attribute specified. It
27153 must be a power of two no less than the ``element_size``. Caller guarantees that
27154 the destination pointer is aligned to that boundary.
27159 The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of
27160 memory starting at the destination location to the given ``value``. The memory is
27161 set with a sequence of store operations where each access is guaranteed to be a
27162 multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary.
27164 The order of the assignment is unspecified. Only one write is issued to the
27165 destination buffer per element. It is well defined to have concurrent reads and
27166 writes to the destination provided those reads and writes are unordered atomic
27169 This intrinsic does not provide any additional ordering guarantees over those
27170 provided by a set of unordered stores to the destination.
27175 In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is
27176 lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*'
27177 is replaced with an actual element size.
27179 The optimizer is allowed to inline the memory assignment when it's profitable to do so.
27181 Objective-C ARC Runtime Intrinsics
27182 ----------------------------------
27184 LLVM provides intrinsics that lower to Objective-C ARC runtime entry points.
27185 LLVM is aware of the semantics of these functions, and optimizes based on that
27186 knowledge. You can read more about the details of Objective-C ARC `here
27187 <https://clang.llvm.org/docs/AutomaticReferenceCounting.html>`_.
27189 '``llvm.objc.autorelease``' Intrinsic
27190 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27196 declare ptr @llvm.objc.autorelease(ptr)
27201 Lowers to a call to `objc_autorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autorelease>`_.
27203 '``llvm.objc.autoreleasePoolPop``' Intrinsic
27204 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27210 declare void @llvm.objc.autoreleasePoolPop(ptr)
27215 Lowers to a call to `objc_autoreleasePoolPop <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpop-void-pool>`_.
27217 '``llvm.objc.autoreleasePoolPush``' Intrinsic
27218 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27224 declare ptr @llvm.objc.autoreleasePoolPush()
27229 Lowers to a call to `objc_autoreleasePoolPush <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpush-void>`_.
27231 '``llvm.objc.autoreleaseReturnValue``' Intrinsic
27232 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27238 declare ptr @llvm.objc.autoreleaseReturnValue(ptr)
27243 Lowers to a call to `objc_autoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue>`_.
27245 '``llvm.objc.copyWeak``' Intrinsic
27246 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27252 declare void @llvm.objc.copyWeak(ptr, ptr)
27257 Lowers to a call to `objc_copyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-copyweak-id-dest-id-src>`_.
27259 '``llvm.objc.destroyWeak``' Intrinsic
27260 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27266 declare void @llvm.objc.destroyWeak(ptr)
27271 Lowers to a call to `objc_destroyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-destroyweak-id-object>`_.
27273 '``llvm.objc.initWeak``' Intrinsic
27274 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27280 declare ptr @llvm.objc.initWeak(ptr, ptr)
27285 Lowers to a call to `objc_initWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-initweak>`_.
27287 '``llvm.objc.loadWeak``' Intrinsic
27288 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27294 declare ptr @llvm.objc.loadWeak(ptr)
27299 Lowers to a call to `objc_loadWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweak>`_.
27301 '``llvm.objc.loadWeakRetained``' Intrinsic
27302 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27308 declare ptr @llvm.objc.loadWeakRetained(ptr)
27313 Lowers to a call to `objc_loadWeakRetained <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweakretained>`_.
27315 '``llvm.objc.moveWeak``' Intrinsic
27316 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27322 declare void @llvm.objc.moveWeak(ptr, ptr)
27327 Lowers to a call to `objc_moveWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-moveweak-id-dest-id-src>`_.
27329 '``llvm.objc.release``' Intrinsic
27330 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27336 declare void @llvm.objc.release(ptr)
27341 Lowers to a call to `objc_release <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-release-id-value>`_.
27343 '``llvm.objc.retain``' Intrinsic
27344 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27350 declare ptr @llvm.objc.retain(ptr)
27355 Lowers to a call to `objc_retain <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>`_.
27357 '``llvm.objc.retainAutorelease``' Intrinsic
27358 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27364 declare ptr @llvm.objc.retainAutorelease(ptr)
27369 Lowers to a call to `objc_retainAutorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautorelease>`_.
27371 '``llvm.objc.retainAutoreleaseReturnValue``' Intrinsic
27372 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27378 declare ptr @llvm.objc.retainAutoreleaseReturnValue(ptr)
27383 Lowers to a call to `objc_retainAutoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasereturnvalue>`_.
27385 '``llvm.objc.retainAutoreleasedReturnValue``' Intrinsic
27386 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27392 declare ptr @llvm.objc.retainAutoreleasedReturnValue(ptr)
27397 Lowers to a call to `objc_retainAutoreleasedReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasedreturnvalue>`_.
27399 '``llvm.objc.retainBlock``' Intrinsic
27400 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27406 declare ptr @llvm.objc.retainBlock(ptr)
27411 Lowers to a call to `objc_retainBlock <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainblock>`_.
27413 '``llvm.objc.storeStrong``' Intrinsic
27414 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27420 declare void @llvm.objc.storeStrong(ptr, ptr)
27425 Lowers to a call to `objc_storeStrong <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-storestrong-id-object-id-value>`_.
27427 '``llvm.objc.storeWeak``' Intrinsic
27428 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27434 declare ptr @llvm.objc.storeWeak(ptr, ptr)
27439 Lowers to a call to `objc_storeWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-storeweak>`_.
27441 Preserving Debug Information Intrinsics
27442 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27444 These intrinsics are used to carry certain debuginfo together with
27445 IR-level operations. For example, it may be desirable to
27446 know the structure/union name and the original user-level field
27447 indices. Such information got lost in IR GetElementPtr instruction
27448 since the IR types are different from debugInfo types and unions
27449 are converted to structs in IR.
27451 '``llvm.preserve.array.access.index``' Intrinsic
27452 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27459 @llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons(<type> base,
27466 The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address
27467 based on array base ``base``, array dimension ``dim`` and the last access index ``index``
27468 into the array. The return type ``ret_type`` is a pointer type to the array element.
27469 The array ``dim`` and ``index`` are preserved which is more robust than
27470 getelementptr instruction which may be subject to compiler transformation.
27471 The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
27472 to provide array or pointer debuginfo type.
27473 The metadata is a ``DICompositeType`` or ``DIDerivedType`` representing the
27474 debuginfo version of ``type``.
27479 The ``base`` is the array base address. The ``dim`` is the array dimension.
27480 The ``base`` is a pointer if ``dim`` equals 0.
27481 The ``index`` is the last access index into the array or pointer.
27483 The ``base`` argument must be annotated with an :ref:`elementtype
27484 <attr_elementtype>` attribute at the call-site. This attribute specifies the
27485 getelementptr element type.
27490 The '``llvm.preserve.array.access.index``' intrinsic produces the same result
27491 as a getelementptr with base ``base`` and access operands ``{dim's 0's, index}``.
27493 '``llvm.preserve.union.access.index``' Intrinsic
27494 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27501 @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(<type> base,
27507 The '``llvm.preserve.union.access.index``' intrinsic carries the debuginfo field index
27508 ``di_index`` and returns the ``base`` address.
27509 The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
27510 to provide union debuginfo type.
27511 The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
27512 The return type ``type`` is the same as the ``base`` type.
27517 The ``base`` is the union base address. The ``di_index`` is the field index in debuginfo.
27522 The '``llvm.preserve.union.access.index``' intrinsic returns the ``base`` address.
27524 '``llvm.preserve.struct.access.index``' Intrinsic
27525 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27532 @llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s(<type> base,
27539 The '``llvm.preserve.struct.access.index``' intrinsic returns the getelementptr address
27540 based on struct base ``base`` and IR struct member index ``gep_index``.
27541 The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
27542 to provide struct debuginfo type.
27543 The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
27544 The return type ``ret_type`` is a pointer type to the structure member.
27549 The ``base`` is the structure base address. The ``gep_index`` is the struct member index
27550 based on IR structures. The ``di_index`` is the struct member index based on debuginfo.
27552 The ``base`` argument must be annotated with an :ref:`elementtype
27553 <attr_elementtype>` attribute at the call-site. This attribute specifies the
27554 getelementptr element type.
27559 The '``llvm.preserve.struct.access.index``' intrinsic produces the same result
27560 as a getelementptr with base ``base`` and access operands ``{0, gep_index}``.
27562 '``llvm.fptrunc.round``' Intrinsic
27563 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27571 @llvm.fptrunc.round(<type> <value>, metadata <rounding mode>)
27576 The '``llvm.fptrunc.round``' intrinsic truncates
27577 :ref:`floating-point <t_floating>` ``value`` to type ``ty2``
27578 with a specified rounding mode.
27583 The '``llvm.fptrunc.round``' intrinsic takes a :ref:`floating-point
27584 <t_floating>` value to cast and a :ref:`floating-point <t_floating>` type
27585 to cast it to. This argument must be larger in size than the result.
27587 The second argument specifies the rounding mode as described in the constrained
27588 intrinsics section.
27589 For this intrinsic, the "round.dynamic" mode is not supported.
27594 The '``llvm.fptrunc.round``' intrinsic casts a ``value`` from a larger
27595 :ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
27596 <t_floating>` type.
27597 This intrinsic is assumed to execute in the default :ref:`floating-point
27598 environment <floatenv>` *except* for the rounding mode.
27599 This intrinsic is not supported on all targets. Some targets may not support
27600 all rounding modes.