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. R11 can be used as a scratch register. Floating-point registers
370 (XMMs/YMMs) are not preserved and need to be saved by the caller.
372 The idea behind this convention is to support calls to runtime functions
373 that have a hot path and a cold path. The hot path is usually a small piece
374 of code that doesn't use many registers. The cold path might need to call out to
375 another function and therefore only needs to preserve the caller-saved
376 registers, which haven't already been saved by the caller. The
377 `PreserveMost` calling convention is very similar to the `cold` calling
378 convention in terms of caller/callee-saved registers, but they are used for
379 different types of function calls. `coldcc` is for function calls that are
380 rarely executed, whereas `preserve_mostcc` function calls are intended to be
381 on the hot path and definitely executed a lot. Furthermore `preserve_mostcc`
382 doesn't prevent the inliner from inlining the function call.
384 This calling convention will be used by a future version of the ObjectiveC
385 runtime and should therefore still be considered experimental at this time.
386 Although this convention was created to optimize certain runtime calls to
387 the ObjectiveC runtime, it is not limited to this runtime and might be used
388 by other runtimes in the future too. The current implementation only
389 supports X86-64, but the intention is to support more architectures in the
391 "``preserve_allcc``" - The `PreserveAll` calling convention
392 This calling convention attempts to make the code in the caller even less
393 intrusive than the `PreserveMost` calling convention. This calling
394 convention also behaves identical to the `C` calling convention on how
395 arguments and return values are passed, but it uses a different set of
396 caller/callee-saved registers. This removes the burden of saving and
397 recovering a large register set before and after the call in the caller. If
398 the arguments are passed in callee-saved registers, then they will be
399 preserved by the callee across the call. This doesn't apply for values
400 returned in callee-saved registers.
402 - On X86-64 the callee preserves all general purpose registers, except for
403 R11. R11 can be used as a scratch register. Furthermore it also preserves
404 all floating-point registers (XMMs/YMMs).
406 The idea behind this convention is to support calls to runtime functions
407 that don't need to call out to any other functions.
409 This calling convention, like the `PreserveMost` calling convention, will be
410 used by a future version of the ObjectiveC runtime and should be considered
411 experimental at this time.
412 "``cxx_fast_tlscc``" - The `CXX_FAST_TLS` calling convention for access functions
413 Clang generates an access function to access C++-style TLS. The access
414 function generally has an entry block, an exit block and an initialization
415 block that is run at the first time. The entry and exit blocks can access
416 a few TLS IR variables, each access will be lowered to a platform-specific
419 This calling convention aims to minimize overhead in the caller by
420 preserving as many registers as possible (all the registers that are
421 preserved on the fast path, composed of the entry and exit blocks).
423 This calling convention behaves identical to the `C` calling convention on
424 how arguments and return values are passed, but it uses a different set of
425 caller/callee-saved registers.
427 Given that each platform has its own lowering sequence, hence its own set
428 of preserved registers, we can't use the existing `PreserveMost`.
430 - On X86-64 the callee preserves all general purpose registers, except for
432 "``tailcc``" - Tail callable calling convention
433 This calling convention ensures that calls in tail position will always be
434 tail call optimized. This calling convention is equivalent to fastcc,
435 except for an additional guarantee that tail calls will be produced
436 whenever possible. `Tail calls can only be optimized when this, the fastcc,
437 the GHC or the HiPE convention is used. <CodeGenerator.html#tail-call-optimization>`_
438 This calling convention does not support varargs and requires the prototype of
439 all callees to exactly match the prototype of the function definition.
440 "``swiftcc``" - This calling convention is used for Swift language.
441 - On X86-64 RCX and R8 are available for additional integer returns, and
442 XMM2 and XMM3 are available for additional FP/vector returns.
443 - On iOS platforms, we use AAPCS-VFP calling convention.
445 This calling convention is like ``swiftcc`` in most respects, but also the
446 callee pops the argument area of the stack so that mandatory tail calls are
447 possible as in ``tailcc``.
448 "``cfguard_checkcc``" - Windows Control Flow Guard (Check mechanism)
449 This calling convention is used for the Control Flow Guard check function,
450 calls to which can be inserted before indirect calls to check that the call
451 target is a valid function address. The check function has no return value,
452 but it will trigger an OS-level error if the address is not a valid target.
453 The set of registers preserved by the check function, and the register
454 containing the target address are architecture-specific.
456 - On X86 the target address is passed in ECX.
457 - On ARM the target address is passed in R0.
458 - On AArch64 the target address is passed in X15.
459 "``cc <n>``" - Numbered convention
460 Any calling convention may be specified by number, allowing
461 target-specific calling conventions to be used. Target specific
462 calling conventions start at 64.
464 More calling conventions can be added/defined on an as-needed basis, to
465 support Pascal conventions or any other well-known target-independent
468 .. _visibilitystyles:
473 All Global Variables and Functions have one of the following visibility
476 "``default``" - Default style
477 On targets that use the ELF object file format, default visibility
478 means that the declaration is visible to other modules and, in
479 shared libraries, means that the declared entity may be overridden.
480 On Darwin, default visibility means that the declaration is visible
481 to other modules. On XCOFF, default visibility means no explicit
482 visibility bit will be set and whether the symbol is visible
483 (i.e "exported") to other modules depends primarily on export lists
484 provided to the linker. Default visibility corresponds to "external
485 linkage" in the language.
486 "``hidden``" - Hidden style
487 Two declarations of an object with hidden visibility refer to the
488 same object if they are in the same shared object. Usually, hidden
489 visibility indicates that the symbol will not be placed into the
490 dynamic symbol table, so no other module (executable or shared
491 library) can reference it directly.
492 "``protected``" - Protected style
493 On ELF, protected visibility indicates that the symbol will be
494 placed in the dynamic symbol table, but that references within the
495 defining module will bind to the local symbol. That is, the symbol
496 cannot be overridden by another module.
498 A symbol with ``internal`` or ``private`` linkage must have ``default``
506 All Global Variables, Functions and Aliases can have one of the following
510 "``dllimport``" causes the compiler to reference a function or variable via
511 a global pointer to a pointer that is set up by the DLL exporting the
512 symbol. On Microsoft Windows targets, the pointer name is formed by
513 combining ``__imp_`` and the function or variable name.
515 On Microsoft Windows targets, "``dllexport``" causes the compiler to provide
516 a global pointer to a pointer in a DLL, so that it can be referenced with the
517 ``dllimport`` attribute. the pointer name is formed by combining ``__imp_``
518 and the function or variable name. On XCOFF targets, ``dllexport`` indicates
519 that the symbol will be made visible to other modules using "exported"
520 visibility and thus placed by the linker in the loader section symbol table.
521 Since this storage class exists for defining a dll interface, the compiler,
522 assembler and linker know it is externally referenced and must refrain from
527 Thread Local Storage Models
528 ---------------------------
530 A variable may be defined as ``thread_local``, which means that it will
531 not be shared by threads (each thread will have a separated copy of the
532 variable). Not all targets support thread-local variables. Optionally, a
533 TLS model may be specified:
536 For variables that are only used within the current shared library.
538 For variables in modules that will not be loaded dynamically.
540 For variables defined in the executable and only used within it.
542 If no explicit model is given, the "general dynamic" model is used.
544 The models correspond to the ELF TLS models; see `ELF Handling For
545 Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for
546 more information on under which circumstances the different models may
547 be used. The target may choose a different TLS model if the specified
548 model is not supported, or if a better choice of model can be made.
550 A model can also be specified in an alias, but then it only governs how
551 the alias is accessed. It will not have any effect in the aliasee.
553 For platforms without linker support of ELF TLS model, the -femulated-tls
554 flag can be used to generate GCC compatible emulated TLS code.
556 .. _runtime_preemption_model:
558 Runtime Preemption Specifiers
559 -----------------------------
561 Global variables, functions and aliases may have an optional runtime preemption
562 specifier. If a preemption specifier isn't given explicitly, then a
563 symbol is assumed to be ``dso_preemptable``.
566 Indicates that the function or variable may be replaced by a symbol from
567 outside the linkage unit at runtime.
570 The compiler may assume that a function or variable marked as ``dso_local``
571 will resolve to a symbol within the same linkage unit. Direct access will
572 be generated even if the definition is not within this compilation unit.
579 LLVM IR allows you to specify both "identified" and "literal" :ref:`structure
580 types <t_struct>`. Literal types are uniqued structurally, but identified types
581 are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used
582 to forward declare a type that is not yet available.
584 An example of an identified structure specification is:
588 %mytype = type { %mytype*, i32 }
590 Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only
591 literal types are uniqued in recent versions of LLVM.
595 Non-Integral Pointer Type
596 -------------------------
598 Note: non-integral pointer types are a work in progress, and they should be
599 considered experimental at this time.
601 LLVM IR optionally allows the frontend to denote pointers in certain address
602 spaces as "non-integral" via the :ref:`datalayout string<langref_datalayout>`.
603 Non-integral pointer types represent pointers that have an *unspecified* bitwise
604 representation; that is, the integral representation may be target dependent or
605 unstable (not backed by a fixed integer).
607 ``inttoptr`` and ``ptrtoint`` instructions have the same semantics as for
608 integral (i.e. normal) pointers in that they convert integers to and from
609 corresponding pointer types, but there are additional implications to be
610 aware of. Because the bit-representation of a non-integral pointer may
611 not be stable, two identical casts of the same operand may or may not
612 return the same value. Said differently, the conversion to or from the
613 non-integral type depends on environmental state in an implementation
616 If the frontend wishes to observe a *particular* value following a cast, the
617 generated IR must fence with the underlying environment in an implementation
618 defined manner. (In practice, this tends to require ``noinline`` routines for
621 From the perspective of the optimizer, ``inttoptr`` and ``ptrtoint`` for
622 non-integral types are analogous to ones on integral types with one
623 key exception: the optimizer may not, in general, insert new dynamic
624 occurrences of such casts. If a new cast is inserted, the optimizer would
625 need to either ensure that a) all possible values are valid, or b)
626 appropriate fencing is inserted. Since the appropriate fencing is
627 implementation defined, the optimizer can't do the latter. The former is
628 challenging as many commonly expected properties, such as
629 ``ptrtoint(v)-ptrtoint(v) == 0``, don't hold for non-integral types.
636 Global variables define regions of memory allocated at compilation time
639 Global variable definitions must be initialized.
641 Global variables in other translation units can also be declared, in which
642 case they don't have an initializer.
644 Global variables can optionally specify a :ref:`linkage type <linkage>`.
646 Either global variable definitions or declarations may have an explicit section
647 to be placed in and may have an optional explicit alignment specified. If there
648 is a mismatch between the explicit or inferred section information for the
649 variable declaration and its definition the resulting behavior is undefined.
651 A variable may be defined as a global ``constant``, which indicates that
652 the contents of the variable will **never** be modified (enabling better
653 optimization, allowing the global data to be placed in the read-only
654 section of an executable, etc). Note that variables that need runtime
655 initialization cannot be marked ``constant`` as there is a store to the
658 LLVM explicitly allows *declarations* of global variables to be marked
659 constant, even if the final definition of the global is not. This
660 capability can be used to enable slightly better optimization of the
661 program, but requires the language definition to guarantee that
662 optimizations based on the 'constantness' are valid for the translation
663 units that do not include the definition.
665 As SSA values, global variables define pointer values that are in scope
666 (i.e. they dominate) all basic blocks in the program. Global variables
667 always define a pointer to their "content" type because they describe a
668 region of memory, and all memory objects in LLVM are accessed through
671 Global variables can be marked with ``unnamed_addr`` which indicates
672 that the address is not significant, only the content. Constants marked
673 like this can be merged with other constants if they have the same
674 initializer. Note that a constant with significant address *can* be
675 merged with a ``unnamed_addr`` constant, the result being a constant
676 whose address is significant.
678 If the ``local_unnamed_addr`` attribute is given, the address is known to
679 not be significant within the module.
681 A global variable may be declared to reside in a target-specific
682 numbered address space. For targets that support them, address spaces
683 may affect how optimizations are performed and/or what target
684 instructions are used to access the variable. The default address space
685 is zero. The address space qualifier must precede any other attributes.
687 LLVM allows an explicit section to be specified for globals. If the
688 target supports it, it will emit globals to the section specified.
689 Additionally, the global can placed in a comdat if the target has the necessary
692 External declarations may have an explicit section specified. Section
693 information is retained in LLVM IR for targets that make use of this
694 information. Attaching section information to an external declaration is an
695 assertion that its definition is located in the specified section. If the
696 definition is located in a different section, the behavior is undefined.
698 By default, global initializers are optimized by assuming that global
699 variables defined within the module are not modified from their
700 initial values before the start of the global initializer. This is
701 true even for variables potentially accessible from outside the
702 module, including those with external linkage or appearing in
703 ``@llvm.used`` or dllexported variables. This assumption may be suppressed
704 by marking the variable with ``externally_initialized``.
706 An explicit alignment may be specified for a global, which must be a
707 power of 2. If not present, or if the alignment is set to zero, the
708 alignment of the global is set by the target to whatever it feels
709 convenient. If an explicit alignment is specified, the global is forced
710 to have exactly that alignment. Targets and optimizers are not allowed
711 to over-align the global if the global has an assigned section. In this
712 case, the extra alignment could be observable: for example, code could
713 assume that the globals are densely packed in their section and try to
714 iterate over them as an array, alignment padding would break this
715 iteration. The maximum alignment is ``1 << 32``.
717 For global variables declarations, as well as definitions that may be
718 replaced at link time (``linkonce``, ``weak``, ``extern_weak`` and ``common``
719 linkage types), LLVM makes no assumptions about the allocation size of the
720 variables, except that they may not overlap. The alignment of a global variable
721 declaration or replaceable definition must not be greater than the alignment of
722 the definition it resolves to.
724 Globals can also have a :ref:`DLL storage class <dllstorageclass>`,
725 an optional :ref:`runtime preemption specifier <runtime_preemption_model>`,
726 an optional :ref:`global attributes <glattrs>` and
727 an optional list of attached :ref:`metadata <metadata>`.
729 Variables and aliases can have a
730 :ref:`Thread Local Storage Model <tls_model>`.
732 :ref:`Scalable vectors <t_vector>` cannot be global variables or members of
733 arrays because their size is unknown at compile time. They are allowed in
734 structs to facilitate intrinsics returning multiple values. Structs containing
735 scalable vectors cannot be used in loads, stores, allocas, or GEPs.
739 @<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility]
740 [DLLStorageClass] [ThreadLocal]
741 [(unnamed_addr|local_unnamed_addr)] [AddrSpace]
742 [ExternallyInitialized]
743 <global | constant> <Type> [<InitializerConstant>]
744 [, section "name"] [, partition "name"]
745 [, comdat [($name)]] [, align <Alignment>]
746 [, no_sanitize_address] [, no_sanitize_hwaddress]
747 [, sanitize_address_dyninit] [, sanitize_memtag]
750 For example, the following defines a global in a numbered address space
751 with an initializer, section, and alignment:
755 @G = addrspace(5) constant float 1.0, section "foo", align 4
757 The following example just declares a global variable
761 @G = external global i32
763 The following example defines a thread-local global with the
764 ``initialexec`` TLS model:
768 @G = thread_local(initialexec) global i32 0, align 4
770 .. _functionstructure:
775 LLVM function definitions consist of the "``define``" keyword, an
776 optional :ref:`linkage type <linkage>`, an optional :ref:`runtime preemption
777 specifier <runtime_preemption_model>`, an optional :ref:`visibility
778 style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`,
779 an optional :ref:`calling convention <callingconv>`,
780 an optional ``unnamed_addr`` attribute, a return type, an optional
781 :ref:`parameter attribute <paramattrs>` for the return type, a function
782 name, a (possibly empty) argument list (each with optional :ref:`parameter
783 attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`,
784 an optional address space, an optional section, an optional partition,
785 an optional alignment, an optional :ref:`comdat <langref_comdats>`,
786 an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`,
787 an optional :ref:`prologue <prologuedata>`,
788 an optional :ref:`personality <personalityfn>`,
789 an optional list of attached :ref:`metadata <metadata>`,
790 an opening curly brace, a list of basic blocks, and a closing curly brace.
794 define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass]
796 <ResultType> @<FunctionName> ([argument list])
797 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs]
798 [section "name"] [partition "name"] [comdat [($name)]] [align N]
799 [gc] [prefix Constant] [prologue Constant] [personality Constant]
802 The argument list is a comma separated sequence of arguments where each
803 argument is of the following form:
807 <type> [parameter Attrs] [name]
809 LLVM function declarations consist of the "``declare``" keyword, an
810 optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style
811 <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an
812 optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr``
813 or ``local_unnamed_addr`` attribute, an optional address space, a return type,
814 an optional :ref:`parameter attribute <paramattrs>` for the return type, a function name, a possibly
815 empty list of arguments, an optional alignment, an optional :ref:`garbage
816 collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional
817 :ref:`prologue <prologuedata>`.
821 declare [linkage] [visibility] [DLLStorageClass]
823 <ResultType> @<FunctionName> ([argument list])
824 [(unnamed_addr|local_unnamed_addr)] [align N] [gc]
825 [prefix Constant] [prologue Constant]
827 A function definition contains a list of basic blocks, forming the CFG (Control
828 Flow Graph) for the function. Each basic block may optionally start with a label
829 (giving the basic block a symbol table entry), contains a list of instructions,
830 and ends with a :ref:`terminator <terminators>` instruction (such as a branch or
831 function return). If an explicit label name is not provided, a block is assigned
832 an implicit numbered label, using the next value from the same counter as used
833 for unnamed temporaries (:ref:`see above<identifiers>`). For example, if a
834 function entry block does not have an explicit label, it will be assigned label
835 "%0", then the first unnamed temporary in that block will be "%1", etc. If a
836 numeric label is explicitly specified, it must match the numeric label that
837 would be used implicitly.
839 The first basic block in a function is special in two ways: it is
840 immediately executed on entrance to the function, and it is not allowed
841 to have predecessor basic blocks (i.e. there can not be any branches to
842 the entry block of a function). Because the block can have no
843 predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`.
845 LLVM allows an explicit section to be specified for functions. If the
846 target supports it, it will emit functions to the section specified.
847 Additionally, the function can be placed in a COMDAT.
849 An explicit alignment may be specified for a function. If not present,
850 or if the alignment is set to zero, the alignment of the function is set
851 by the target to whatever it feels convenient. If an explicit alignment
852 is specified, the function is forced to have at least that much
853 alignment. All alignments must be a power of 2.
855 If the ``unnamed_addr`` attribute is given, the address is known to not
856 be significant and two identical functions can be merged.
858 If the ``local_unnamed_addr`` attribute is given, the address is known to
859 not be significant within the module.
861 If an explicit address space is not given, it will default to the program
862 address space from the :ref:`datalayout string<langref_datalayout>`.
869 Aliases, unlike function or variables, don't create any new data. They
870 are just a new symbol and metadata for an existing position.
872 Aliases have a name and an aliasee that is either a global value or a
875 Aliases may have an optional :ref:`linkage type <linkage>`, an optional
876 :ref:`runtime preemption specifier <runtime_preemption_model>`, an optional
877 :ref:`visibility style <visibility>`, an optional :ref:`DLL storage class
878 <dllstorageclass>` and an optional :ref:`tls model <tls_model>`.
882 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee>
885 The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
886 ``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
887 might not correctly handle dropping a weak symbol that is aliased.
889 Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
890 the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
893 If the ``local_unnamed_addr`` attribute is given, the address is known to
894 not be significant within the module.
896 Since aliases are only a second name, some restrictions apply, of which
897 some can only be checked when producing an object file:
899 * The expression defining the aliasee must be computable at assembly
900 time. Since it is just a name, no relocations can be used.
902 * No alias in the expression can be weak as the possibility of the
903 intermediate alias being overridden cannot be represented in an
906 * No global value in the expression can be a declaration, since that
907 would require a relocation, which is not possible.
909 * If either the alias or the aliasee may be replaced by a symbol outside the
910 module at link time or runtime, any optimization cannot replace the alias with
911 the aliasee, since the behavior may be different. The alias may be used as a
912 name guaranteed to point to the content in the current module.
919 IFuncs, like as aliases, don't create any new data or func. They are just a new
920 symbol that dynamic linker resolves at runtime by calling a resolver function.
922 IFuncs have a name and a resolver that is a function called by dynamic linker
923 that returns address of another function associated with the name.
925 IFunc may have an optional :ref:`linkage type <linkage>` and an optional
926 :ref:`visibility style <visibility>`.
930 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver>
939 Comdat IR provides access to object file COMDAT/section group functionality
940 which represents interrelated sections.
942 Comdats have a name which represents the COMDAT key and a selection kind to
943 provide input on how the linker deduplicates comdats with the same key in two
944 different object files. A comdat must be included or omitted as a unit.
945 Discarding the whole comdat is allowed but discarding a subset is not.
947 A global object may be a member of at most one comdat. Aliases are placed in the
948 same COMDAT that their aliasee computes to, if any.
952 $<Name> = comdat SelectionKind
954 For selection kinds other than ``nodeduplicate``, only one of the duplicate
955 comdats may be retained by the linker and the members of the remaining comdats
956 must be discarded. The following selection kinds are supported:
959 The linker may choose any COMDAT key, the choice is arbitrary.
961 The linker may choose any COMDAT key but the sections must contain the
964 The linker will choose the section containing the largest COMDAT key.
966 No deduplication is performed.
968 The linker may choose any COMDAT key but the sections must contain the
971 - XCOFF and Mach-O don't support COMDATs.
972 - COFF supports all selection kinds. Non-``nodeduplicate`` selection kinds need
973 a non-local linkage COMDAT symbol.
974 - ELF supports ``any`` and ``nodeduplicate``.
975 - WebAssembly only supports ``any``.
977 Here is an example of a COFF COMDAT where a function will only be selected if
978 the COMDAT key's section is the largest:
982 $foo = comdat largest
983 @foo = global i32 2, comdat($foo)
985 define void @bar() comdat($foo) {
989 In a COFF object file, this will create a COMDAT section with selection kind
990 ``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol
991 and another COMDAT section with selection kind
992 ``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT
993 section and contains the contents of the ``@bar`` symbol.
995 As a syntactic sugar the ``$name`` can be omitted if the name is the same as
1001 @foo = global i32 2, comdat
1002 @bar = global i32 3, comdat($foo)
1004 There are some restrictions on the properties of the global object.
1005 It, or an alias to it, must have the same name as the COMDAT group when
1007 The contents and size of this object may be used during link-time to determine
1008 which COMDAT groups get selected depending on the selection kind.
1009 Because the name of the object must match the name of the COMDAT group, the
1010 linkage of the global object must not be local; local symbols can get renamed
1011 if a collision occurs in the symbol table.
1013 The combined use of COMDATS and section attributes may yield surprising results.
1016 .. code-block:: llvm
1020 @g1 = global i32 42, section "sec", comdat($foo)
1021 @g2 = global i32 42, section "sec", comdat($bar)
1023 From the object file perspective, this requires the creation of two sections
1024 with the same name. This is necessary because both globals belong to different
1025 COMDAT groups and COMDATs, at the object file level, are represented by
1028 Note that certain IR constructs like global variables and functions may
1029 create COMDATs in the object file in addition to any which are specified using
1030 COMDAT IR. This arises when the code generator is configured to emit globals
1031 in individual sections (e.g. when `-data-sections` or `-function-sections`
1032 is supplied to `llc`).
1034 .. _namedmetadatastructure:
1039 Named metadata is a collection of metadata. :ref:`Metadata
1040 nodes <metadata>` (but not metadata strings) are the only valid
1041 operands for a named metadata.
1043 #. Named metadata are represented as a string of characters with the
1044 metadata prefix. The rules for metadata names are the same as for
1045 identifiers, but quoted names are not allowed. ``"\xx"`` type escapes
1046 are still valid, which allows any character to be part of a name.
1050 ; Some unnamed metadata nodes, which are referenced by the named metadata.
1055 !name = !{!0, !1, !2}
1059 Parameter Attributes
1060 --------------------
1062 The return type and each parameter of a function type may have a set of
1063 *parameter attributes* associated with them. Parameter attributes are
1064 used to communicate additional information about the result or
1065 parameters of a function. Parameter attributes are considered to be part
1066 of the function, not of the function type, so functions with different
1067 parameter attributes can have the same function type.
1069 Parameter attributes are simple keywords that follow the type specified.
1070 If multiple parameter attributes are needed, they are space separated.
1073 .. code-block:: llvm
1075 declare i32 @printf(ptr noalias nocapture, ...)
1076 declare i32 @atoi(i8 zeroext)
1077 declare signext i8 @returns_signed_char()
1079 Note that any attributes for the function result (``nounwind``,
1080 ``readonly``) come immediately after the argument list.
1082 Currently, only the following parameter attributes are defined:
1085 This indicates to the code generator that the parameter or return
1086 value should be zero-extended to the extent required by the target's
1087 ABI by the caller (for a parameter) or the callee (for a return value).
1089 This indicates to the code generator that the parameter or return
1090 value should be sign-extended to the extent required by the target's
1091 ABI (which is usually 32-bits) by the caller (for a parameter) or
1092 the callee (for a return value).
1094 This indicates that this parameter or return value should be treated
1095 in a special target-dependent fashion while emitting code for
1096 a function call or return (usually, by putting it in a register as
1097 opposed to memory, though some targets use it to distinguish between
1098 two different kinds of registers). Use of this attribute is
1101 This indicates that the pointer parameter should really be passed by
1102 value to the function. The attribute implies that a hidden copy of
1103 the pointee is made between the caller and the callee, so the callee
1104 is unable to modify the value in the caller. This attribute is only
1105 valid on LLVM pointer arguments. It is generally used to pass
1106 structs and arrays by value, but is also valid on pointers to
1107 scalars. The copy is considered to belong to the caller not the
1108 callee (for example, ``readonly`` functions should not write to
1109 ``byval`` parameters). This is not a valid attribute for return
1112 The byval type argument indicates the in-memory value type, and
1113 must be the same as the pointee type of the argument.
1115 The byval attribute also supports specifying an alignment with the
1116 align attribute. It indicates the alignment of the stack slot to
1117 form and the known alignment of the pointer specified to the call
1118 site. If the alignment is not specified, then the code generator
1119 makes a target-specific assumption.
1125 The ``byref`` argument attribute allows specifying the pointee
1126 memory type of an argument. This is similar to ``byval``, but does
1127 not imply a copy is made anywhere, or that the argument is passed
1128 on the stack. This implies the pointer is dereferenceable up to
1129 the storage size of the type.
1131 It is not generally permissible to introduce a write to an
1132 ``byref`` pointer. The pointer may have any address space and may
1135 This is not a valid attribute for return values.
1137 The alignment for an ``byref`` parameter can be explicitly
1138 specified by combining it with the ``align`` attribute, similar to
1139 ``byval``. If the alignment is not specified, then the code generator
1140 makes a target-specific assumption.
1142 This is intended for representing ABI constraints, and is not
1143 intended to be inferred for optimization use.
1145 .. _attr_preallocated:
1147 ``preallocated(<ty>)``
1148 This indicates that the pointer parameter should really be passed by
1149 value to the function, and that the pointer parameter's pointee has
1150 already been initialized before the call instruction. This attribute
1151 is only valid on LLVM pointer arguments. The argument must be the value
1152 returned by the appropriate
1153 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` on non
1154 ``musttail`` calls, or the corresponding caller parameter in ``musttail``
1155 calls, although it is ignored during codegen.
1157 A non ``musttail`` function call with a ``preallocated`` attribute in
1158 any parameter must have a ``"preallocated"`` operand bundle. A ``musttail``
1159 function call cannot have a ``"preallocated"`` operand bundle.
1161 The preallocated attribute requires a type argument, which must be
1162 the same as the pointee type of the argument.
1164 The preallocated attribute also supports specifying an alignment with the
1165 align attribute. It indicates the alignment of the stack slot to
1166 form and the known alignment of the pointer specified to the call
1167 site. If the alignment is not specified, then the code generator
1168 makes a target-specific assumption.
1174 The ``inalloca`` argument attribute allows the caller to take the
1175 address of outgoing stack arguments. An ``inalloca`` argument must
1176 be a pointer to stack memory produced by an ``alloca`` instruction.
1177 The alloca, or argument allocation, must also be tagged with the
1178 inalloca keyword. Only the last argument may have the ``inalloca``
1179 attribute, and that argument is guaranteed to be passed in memory.
1181 An argument allocation may be used by a call at most once because
1182 the call may deallocate it. The ``inalloca`` attribute cannot be
1183 used in conjunction with other attributes that affect argument
1184 storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The
1185 ``inalloca`` attribute also disables LLVM's implicit lowering of
1186 large aggregate return values, which means that frontend authors
1187 must lower them with ``sret`` pointers.
1189 When the call site is reached, the argument allocation must have
1190 been the most recent stack allocation that is still live, or the
1191 behavior is undefined. It is possible to allocate additional stack
1192 space after an argument allocation and before its call site, but it
1193 must be cleared off with :ref:`llvm.stackrestore
1194 <int_stackrestore>`.
1196 The inalloca attribute requires a type argument, which must be the
1197 same as the pointee type of the argument.
1199 See :doc:`InAlloca` for more information on how to use this
1203 This indicates that the pointer parameter specifies the address of a
1204 structure that is the return value of the function in the source
1205 program. This pointer must be guaranteed by the caller to be valid:
1206 loads and stores to the structure may be assumed by the callee not
1207 to trap and to be properly aligned. This is not a valid attribute
1210 The sret type argument specifies the in memory type, which must be
1211 the same as the pointee type of the argument.
1213 .. _attr_elementtype:
1215 ``elementtype(<ty>)``
1217 The ``elementtype`` argument attribute can be used to specify a pointer
1218 element type in a way that is compatible with `opaque pointers
1219 <OpaquePointers.html>`__.
1221 The ``elementtype`` attribute by itself does not carry any specific
1222 semantics. However, certain intrinsics may require this attribute to be
1223 present and assign it particular semantics. This will be documented on
1224 individual intrinsics.
1226 The attribute may only be applied to pointer typed arguments of intrinsic
1227 calls. It cannot be applied to non-intrinsic calls, and cannot be applied
1228 to parameters on function declarations. For non-opaque pointers, the type
1229 passed to ``elementtype`` must match the pointer element type.
1233 ``align <n>`` or ``align(<n>)``
1234 This indicates that the pointer value or vector of pointers has the
1235 specified alignment. If applied to a vector of pointers, *all* pointers
1236 (elements) have the specified alignment. If the pointer value does not have
1237 the specified alignment, :ref:`poison value <poisonvalues>` is returned or
1238 passed instead. The ``align`` attribute should be combined with the
1239 ``noundef`` attribute to ensure a pointer is aligned, or otherwise the
1240 behavior is undefined. Note that ``align 1`` has no effect on non-byval,
1241 non-preallocated arguments.
1243 Note that this attribute has additional semantics when combined with the
1244 ``byval`` or ``preallocated`` attribute, which are documented there.
1249 This indicates that memory locations accessed via pointer values
1250 :ref:`based <pointeraliasing>` on the argument or return value are not also
1251 accessed, during the execution of the function, via pointer values not
1252 *based* on the argument or return value. This guarantee only holds for
1253 memory locations that are *modified*, by any means, during the execution of
1254 the function. The attribute on a return value also has additional semantics
1255 described below. The caller shares the responsibility with the callee for
1256 ensuring that these requirements are met. For further details, please see
1257 the discussion of the NoAlias response in :ref:`alias analysis <Must, May,
1260 Note that this definition of ``noalias`` is intentionally similar
1261 to the definition of ``restrict`` in C99 for function arguments.
1263 For function return values, C99's ``restrict`` is not meaningful,
1264 while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias``
1265 attribute on return values are stronger than the semantics of the attribute
1266 when used on function arguments. On function return values, the ``noalias``
1267 attribute indicates that the function acts like a system memory allocation
1268 function, returning a pointer to allocated storage disjoint from the
1269 storage for any other object accessible to the caller.
1274 This indicates that the callee does not :ref:`capture <pointercapture>` the
1275 pointer. This is not a valid attribute for return values.
1276 This attribute applies only to the particular copy of the pointer passed in
1277 this argument. A caller could pass two copies of the same pointer with one
1278 being annotated nocapture and the other not, and the callee could validly
1279 capture through the non annotated parameter.
1281 .. code-block:: llvm
1283 define void @f(ptr nocapture %a, ptr %b) {
1287 call void @f(ptr @glb, ptr @glb) ; well-defined
1290 This indicates that callee does not free the pointer argument. This is not
1291 a valid attribute for return values.
1296 This indicates that the pointer parameter can be excised using the
1297 :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid
1298 attribute for return values and can only be applied to one parameter.
1301 This indicates that the function always returns the argument as its return
1302 value. This is a hint to the optimizer and code generator used when
1303 generating the caller, allowing value propagation, tail call optimization,
1304 and omission of register saves and restores in some cases; it is not
1305 checked or enforced when generating the callee. The parameter and the
1306 function return type must be valid operands for the
1307 :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for
1308 return values and can only be applied to one parameter.
1311 This indicates that the parameter or return pointer is not null. This
1312 attribute may only be applied to pointer typed parameters. This is not
1313 checked or enforced by LLVM; if the parameter or return pointer is null,
1314 :ref:`poison value <poisonvalues>` is returned or passed instead.
1315 The ``nonnull`` attribute should be combined with the ``noundef`` attribute
1316 to ensure a pointer is not null or otherwise the behavior is undefined.
1318 ``dereferenceable(<n>)``
1319 This indicates that the parameter or return pointer is dereferenceable. This
1320 attribute may only be applied to pointer typed parameters. A pointer that
1321 is dereferenceable can be loaded from speculatively without a risk of
1322 trapping. The number of bytes known to be dereferenceable must be provided
1323 in parentheses. It is legal for the number of bytes to be less than the
1324 size of the pointee type. The ``nonnull`` attribute does not imply
1325 dereferenceability (consider a pointer to one element past the end of an
1326 array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in
1327 ``addrspace(0)`` (which is the default address space), except if the
1328 ``null_pointer_is_valid`` function attribute is present.
1329 ``n`` should be a positive number. The pointer should be well defined,
1330 otherwise it is undefined behavior. This means ``dereferenceable(<n>)``
1331 implies ``noundef``.
1333 ``dereferenceable_or_null(<n>)``
1334 This indicates that the parameter or return value isn't both
1335 non-null and non-dereferenceable (up to ``<n>`` bytes) at the same
1336 time. All non-null pointers tagged with
1337 ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``.
1338 For address space 0 ``dereferenceable_or_null(<n>)`` implies that
1339 a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``,
1340 and in other address spaces ``dereferenceable_or_null(<n>)``
1341 implies that a pointer is at least one of ``dereferenceable(<n>)``
1342 or ``null`` (i.e. it may be both ``null`` and
1343 ``dereferenceable(<n>)``). This attribute may only be applied to
1344 pointer typed parameters.
1347 This indicates that the parameter is the self/context parameter. This is not
1348 a valid attribute for return values and can only be applied to one
1352 This indicates that the parameter is the asynchronous context parameter and
1353 triggers the creation of a target-specific extended frame record to store
1354 this pointer. This is not a valid attribute for return values and can only
1355 be applied to one parameter.
1358 This attribute is motivated to model and optimize Swift error handling. It
1359 can be applied to a parameter with pointer to pointer type or a
1360 pointer-sized alloca. At the call site, the actual argument that corresponds
1361 to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or
1362 the ``swifterror`` parameter of the caller. A ``swifterror`` value (either
1363 the parameter or the alloca) can only be loaded and stored from, or used as
1364 a ``swifterror`` argument. This is not a valid attribute for return values
1365 and can only be applied to one parameter.
1367 These constraints allow the calling convention to optimize access to
1368 ``swifterror`` variables by associating them with a specific register at
1369 call boundaries rather than placing them in memory. Since this does change
1370 the calling convention, a function which uses the ``swifterror`` attribute
1371 on a parameter is not ABI-compatible with one which does not.
1373 These constraints also allow LLVM to assume that a ``swifterror`` argument
1374 does not alias any other memory visible within a function and that a
1375 ``swifterror`` alloca passed as an argument does not escape.
1378 This indicates the parameter is required to be an immediate
1379 value. This must be a trivial immediate integer or floating-point
1380 constant. Undef or constant expressions are not valid. This is
1381 only valid on intrinsic declarations and cannot be applied to a
1382 call site or arbitrary function.
1385 This attribute applies to parameters and return values. If the value
1386 representation contains any undefined or poison bits, the behavior is
1387 undefined. Note that this does not refer to padding introduced by the
1388 type's storage representation.
1391 This indicates the alignment that should be considered by the backend when
1392 assigning this parameter to a stack slot during calling convention
1393 lowering. The enforcement of the specified alignment is target-dependent,
1394 as target-specific calling convention rules may override this value. This
1395 attribute serves the purpose of carrying language specific alignment
1396 information that is not mapped to base types in the backend (for example,
1397 over-alignment specification through language attributes).
1400 The function parameter marked with this attribute is is the alignment in bytes of the
1401 newly allocated block returned by this function. The returned value must either have
1402 the specified alignment or be the null pointer. The return value MAY be more aligned
1403 than the requested alignment, but not less aligned. Invalid (e.g. non-power-of-2)
1404 alignments are permitted for the allocalign parameter, so long as the returned pointer
1405 is null. This attribute may only be applied to integer parameters.
1408 The function parameter marked with this attribute is the pointer
1409 that will be manipulated by the allocator. For a realloc-like
1410 function the pointer will be invalidated upon success (but the
1411 same address may be returned), for a free-like function the
1412 pointer will always be invalidated.
1416 Garbage Collector Strategy Names
1417 --------------------------------
1419 Each function may specify a garbage collector strategy name, which is simply a
1422 .. code-block:: llvm
1424 define void @f() gc "name" { ... }
1426 The supported values of *name* includes those :ref:`built in to LLVM
1427 <builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC
1428 strategy will cause the compiler to alter its output in order to support the
1429 named garbage collection algorithm. Note that LLVM itself does not contain a
1430 garbage collector, this functionality is restricted to generating machine code
1431 which can interoperate with a collector provided externally.
1438 Prefix data is data associated with a function which the code
1439 generator will emit immediately before the function's entrypoint.
1440 The purpose of this feature is to allow frontends to associate
1441 language-specific runtime metadata with specific functions and make it
1442 available through the function pointer while still allowing the
1443 function pointer to be called.
1445 To access the data for a given function, a program may bitcast the
1446 function pointer to a pointer to the constant's type and dereference
1447 index -1. This implies that the IR symbol points just past the end of
1448 the prefix data. For instance, take the example of a function annotated
1449 with a single ``i32``,
1451 .. code-block:: llvm
1453 define void @f() prefix i32 123 { ... }
1455 The prefix data can be referenced as,
1457 .. code-block:: llvm
1459 %a = getelementptr inbounds i32, ptr @f, i32 -1
1460 %b = load i32, ptr %a
1462 Prefix data is laid out as if it were an initializer for a global variable
1463 of the prefix data's type. The function will be placed such that the
1464 beginning of the prefix data is aligned. This means that if the size
1465 of the prefix data is not a multiple of the alignment size, the
1466 function's entrypoint will not be aligned. If alignment of the
1467 function's entrypoint is desired, padding must be added to the prefix
1470 A function may have prefix data but no body. This has similar semantics
1471 to the ``available_externally`` linkage in that the data may be used by the
1472 optimizers but will not be emitted in the object file.
1479 The ``prologue`` attribute allows arbitrary code (encoded as bytes) to
1480 be inserted prior to the function body. This can be used for enabling
1481 function hot-patching and instrumentation.
1483 To maintain the semantics of ordinary function calls, the prologue data must
1484 have a particular format. Specifically, it must begin with a sequence of
1485 bytes which decode to a sequence of machine instructions, valid for the
1486 module's target, which transfer control to the point immediately succeeding
1487 the prologue data, without performing any other visible action. This allows
1488 the inliner and other passes to reason about the semantics of the function
1489 definition without needing to reason about the prologue data. Obviously this
1490 makes the format of the prologue data highly target dependent.
1492 A trivial example of valid prologue data for the x86 architecture is ``i8 144``,
1493 which encodes the ``nop`` instruction:
1495 .. code-block:: text
1497 define void @f() prologue i8 144 { ... }
1499 Generally prologue data can be formed by encoding a relative branch instruction
1500 which skips the metadata, as in this example of valid prologue data for the
1501 x86_64 architecture, where the first two bytes encode ``jmp .+10``:
1503 .. code-block:: text
1505 %0 = type <{ i8, i8, ptr }>
1507 define void @f() prologue %0 <{ i8 235, i8 8, ptr @md}> { ... }
1509 A function may have prologue data but no body. This has similar semantics
1510 to the ``available_externally`` linkage in that the data may be used by the
1511 optimizers but will not be emitted in the object file.
1515 Personality Function
1516 --------------------
1518 The ``personality`` attribute permits functions to specify what function
1519 to use for exception handling.
1526 Attribute groups are groups of attributes that are referenced by objects within
1527 the IR. They are important for keeping ``.ll`` files readable, because a lot of
1528 functions will use the same set of attributes. In the degenerative case of a
1529 ``.ll`` file that corresponds to a single ``.c`` file, the single attribute
1530 group will capture the important command line flags used to build that file.
1532 An attribute group is a module-level object. To use an attribute group, an
1533 object references the attribute group's ID (e.g. ``#37``). An object may refer
1534 to more than one attribute group. In that situation, the attributes from the
1535 different groups are merged.
1537 Here is an example of attribute groups for a function that should always be
1538 inlined, has a stack alignment of 4, and which shouldn't use SSE instructions:
1540 .. code-block:: llvm
1542 ; Target-independent attributes:
1543 attributes #0 = { alwaysinline alignstack=4 }
1545 ; Target-dependent attributes:
1546 attributes #1 = { "no-sse" }
1548 ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse".
1549 define void @f() #0 #1 { ... }
1556 Function attributes are set to communicate additional information about
1557 a function. Function attributes are considered to be part of the
1558 function, not of the function type, so functions with different function
1559 attributes can have the same function type.
1561 Function attributes are simple keywords that follow the type specified.
1562 If multiple attributes are needed, they are space separated. For
1565 .. code-block:: llvm
1567 define void @f() noinline { ... }
1568 define void @f() alwaysinline { ... }
1569 define void @f() alwaysinline optsize { ... }
1570 define void @f() optsize { ... }
1573 This attribute indicates that, when emitting the prologue and
1574 epilogue, the backend should forcibly align the stack pointer.
1575 Specify the desired alignment, which must be a power of two, in
1577 ``"alloc-family"="FAMILY"``
1578 This indicates which "family" an allocator function is part of. To avoid
1579 collisions, the family name should match the mangled name of the primary
1580 allocator function, that is "malloc" for malloc/calloc/realloc/free,
1581 "_Znwm" for ``::operator::new`` and ``::operator::delete``, and
1582 "_ZnwmSt11align_val_t" for aligned ``::operator::new`` and
1583 ``::operator::delete``. Matching malloc/realloc/free calls within a family
1584 can be optimized, but mismatched ones will be left alone.
1585 ``allockind("KIND")``
1586 Describes the behavior of an allocation function. The KIND string contains comma
1587 separated entries from the following options:
1589 * "alloc": the function returns a new block of memory or null.
1590 * "realloc": the function returns a new block of memory or null. If the
1591 result is non-null the memory contents from the start of the block up to
1592 the smaller of the original allocation size and the new allocation size
1593 will match that of the ``allocptr`` argument and the ``allocptr``
1594 argument is invalidated, even if the function returns the same address.
1595 * "free": the function frees the block of memory specified by ``allocptr``.
1596 Functions marked as "free" ``allockind`` must return void.
1597 * "uninitialized": Any newly-allocated memory (either a new block from
1598 a "alloc" function or the enlarged capacity from a "realloc" function)
1599 will be uninitialized.
1600 * "zeroed": Any newly-allocated memory (either a new block from a "alloc"
1601 function or the enlarged capacity from a "realloc" function) will be
1603 * "aligned": the function returns memory aligned according to the
1604 ``allocalign`` parameter.
1606 The first three options are mutually exclusive, and the remaining options
1607 describe more details of how the function behaves. The remaining options
1608 are invalid for "free"-type functions.
1609 ``allocsize(<EltSizeParam>[, <NumEltsParam>])``
1610 This attribute indicates that the annotated function will always return at
1611 least a given number of bytes (or null). Its arguments are zero-indexed
1612 parameter numbers; if one argument is provided, then it's assumed that at
1613 least ``CallSite.Args[EltSizeParam]`` bytes will be available at the
1614 returned pointer. If two are provided, then it's assumed that
1615 ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are
1616 available. The referenced parameters must be integer types. No assumptions
1617 are made about the contents of the returned block of memory.
1619 This attribute indicates that the inliner should attempt to inline
1620 this function into callers whenever possible, ignoring any active
1621 inlining size threshold for this caller.
1623 This indicates that the callee function at a call site should be
1624 recognized as a built-in function, even though the function's declaration
1625 uses the ``nobuiltin`` attribute. This is only valid at call sites for
1626 direct calls to functions that are declared with the ``nobuiltin``
1629 This attribute indicates that this function is rarely called. When
1630 computing edge weights, basic blocks post-dominated by a cold
1631 function call are also considered to be cold; and, thus, given low
1634 In some parallel execution models, there exist operations that cannot be
1635 made control-dependent on any additional values. We call such operations
1636 ``convergent``, and mark them with this attribute.
1638 The ``convergent`` attribute may appear on functions or call/invoke
1639 instructions. When it appears on a function, it indicates that calls to
1640 this function should not be made control-dependent on additional values.
1641 For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so
1642 calls to this intrinsic cannot be made control-dependent on additional
1645 When it appears on a call/invoke, the ``convergent`` attribute indicates
1646 that we should treat the call as though we're calling a convergent
1647 function. This is particularly useful on indirect calls; without this we
1648 may treat such calls as though the target is non-convergent.
1650 The optimizer may remove the ``convergent`` attribute on functions when it
1651 can prove that the function does not execute any convergent operations.
1652 Similarly, the optimizer may remove ``convergent`` on calls/invokes when it
1653 can prove that the call/invoke cannot call a convergent function.
1654 ``disable_sanitizer_instrumentation``
1655 When instrumenting code with sanitizers, it can be important to skip certain
1656 functions to ensure no instrumentation is applied to them.
1658 This attribute is not always similar to absent ``sanitize_<name>``
1659 attributes: depending on the specific sanitizer, code can be inserted into
1660 functions regardless of the ``sanitize_<name>`` attribute to prevent false
1663 ``disable_sanitizer_instrumentation`` disables all kinds of instrumentation,
1664 taking precedence over the ``sanitize_<name>`` attributes and other compiler
1666 ``"dontcall-error"``
1667 This attribute denotes that an error diagnostic should be emitted when a
1668 call of a function with this attribute is not eliminated via optimization.
1669 Front ends can provide optional ``srcloc`` metadata nodes on call sites of
1670 such callees to attach information about where in the source language such a
1671 call came from. A string value can be provided as a note.
1673 This attribute denotes that a warning diagnostic should be emitted when a
1674 call of a function with this attribute is not eliminated via optimization.
1675 Front ends can provide optional ``srcloc`` metadata nodes on call sites of
1676 such callees to attach information about where in the source language such a
1677 call came from. A string value can be provided as a note.
1678 ``fn_ret_thunk_extern``
1679 This attribute tells the code generator that returns from functions should
1680 be replaced with jumps to externally-defined architecture-specific symbols.
1681 For X86, this symbol's identifier is ``__x86_return_thunk``.
1683 This attribute tells the code generator whether the function
1684 should keep the frame pointer. The code generator may emit the frame pointer
1685 even if this attribute says the frame pointer can be eliminated.
1686 The allowed string values are:
1688 * ``"none"`` (default) - the frame pointer can be eliminated.
1689 * ``"non-leaf"`` - the frame pointer should be kept if the function calls
1691 * ``"all"`` - the frame pointer should be kept.
1693 This attribute indicates that this function is a hot spot of the program
1694 execution. The function will be optimized more aggressively and will be
1695 placed into special subsection of the text section to improving locality.
1697 When profile feedback is enabled, this attribute has the precedence over
1698 the profile information. By marking a function ``hot``, users can work
1699 around the cases where the training input does not have good coverage
1700 on all the hot functions.
1701 ``inaccessiblememonly``
1702 This attribute indicates that the function may only access memory that
1703 is not accessible by the module being compiled before return from the
1704 function. This is a weaker form of ``readnone``. If the function reads
1705 or writes other memory, the behavior is undefined.
1707 For clarity, note that such functions are allowed to return new memory
1708 which is ``noalias`` with respect to memory already accessible from
1709 the module. That is, a function can be both ``inaccessiblememonly`` and
1710 have a ``noalias`` return which introduces a new, potentially initialized,
1712 ``inaccessiblemem_or_argmemonly``
1713 This attribute indicates that the function may only access memory that is
1714 either not accessible by the module being compiled, or is pointed to
1715 by its pointer arguments. This is a weaker form of ``argmemonly``. If the
1716 function reads or writes other memory, the behavior is undefined.
1718 This attribute indicates that the source code contained a hint that
1719 inlining this function is desirable (such as the "inline" keyword in
1720 C/C++). It is just a hint; it imposes no requirements on the
1723 This attribute indicates that the function should be added to a
1724 jump-instruction table at code-generation time, and that all address-taken
1725 references to this function should be replaced with a reference to the
1726 appropriate jump-instruction-table function pointer. Note that this creates
1727 a new pointer for the original function, which means that code that depends
1728 on function-pointer identity can break. So, any function annotated with
1729 ``jumptable`` must also be ``unnamed_addr``.
1731 This attribute suggests that optimization passes and code generator
1732 passes make choices that keep the code size of this function as small
1733 as possible and perform optimizations that may sacrifice runtime
1734 performance in order to minimize the size of the generated code.
1736 This attribute disables prologue / epilogue emission for the
1737 function. This can have very system-specific consequences.
1738 ``"no-inline-line-tables"``
1739 When this attribute is set to true, the inliner discards source locations
1740 when inlining code and instead uses the source location of the call site.
1741 Breakpoints set on code that was inlined into the current function will
1742 not fire during the execution of the inlined call sites. If the debugger
1743 stops inside an inlined call site, it will appear to be stopped at the
1744 outermost inlined call site.
1746 When this attribute is set to true, the jump tables and lookup tables that
1747 can be generated from a switch case lowering are disabled.
1749 This indicates that the callee function at a call site is not recognized as
1750 a built-in function. LLVM will retain the original call and not replace it
1751 with equivalent code based on the semantics of the built-in function, unless
1752 the call site uses the ``builtin`` attribute. This is valid at call sites
1753 and on function declarations and definitions.
1755 This attribute indicates that calls to the function cannot be
1756 duplicated. A call to a ``noduplicate`` function may be moved
1757 within its parent function, but may not be duplicated within
1758 its parent function.
1760 A function containing a ``noduplicate`` call may still
1761 be an inlining candidate, provided that the call is not
1762 duplicated by inlining. That implies that the function has
1763 internal linkage and only has one call site, so the original
1764 call is dead after inlining.
1766 This function attribute indicates that the function does not, directly or
1767 transitively, call a memory-deallocation function (``free``, for example)
1768 on a memory allocation which existed before the call.
1770 As a result, uncaptured pointers that are known to be dereferenceable
1771 prior to a call to a function with the ``nofree`` attribute are still
1772 known to be dereferenceable after the call. The capturing condition is
1773 necessary in environments where the function might communicate the
1774 pointer to another thread which then deallocates the memory. Alternatively,
1775 ``nosync`` would ensure such communication cannot happen and even captured
1776 pointers cannot be freed by the function.
1778 A ``nofree`` function is explicitly allowed to free memory which it
1779 allocated or (if not ``nosync``) arrange for another thread to free
1780 memory on it's behalf. As a result, perhaps surprisingly, a ``nofree``
1781 function can return a pointer to a previously deallocated memory object.
1783 Disallows implicit floating-point code. This inhibits optimizations that
1784 use floating-point code and floating-point/SIMD/vector registers for
1785 operations that are not nominally floating-point. LLVM instructions that
1786 perform floating-point operations or require access to floating-point
1787 registers may still cause floating-point code to be generated.
1789 This attribute indicates that the inliner should never inline this
1790 function in any situation. This attribute may not be used together
1791 with the ``alwaysinline`` attribute.
1793 This attribute indicates that calls to this function should never be merged
1794 during optimization. For example, it will prevent tail merging otherwise
1795 identical code sequences that raise an exception or terminate the program.
1796 Tail merging normally reduces the precision of source location information,
1797 making stack traces less useful for debugging. This attribute gives the
1798 user control over the tradeoff between code size and debug information
1801 This attribute suppresses lazy symbol binding for the function. This
1802 may make calls to the function faster, at the cost of extra program
1803 startup time if the function is not called during program startup.
1805 This function attribute prevents instrumentation based profiling, used for
1806 coverage or profile based optimization, from being added to a function. It
1807 also blocks inlining if the caller and callee have different values of this
1810 This function attribute prevents instrumentation based profiling, used for
1811 coverage or profile based optimization, from being added to a function. This
1812 attribute does not restrict inlining, so instrumented instruction could end
1813 up in this function.
1815 This attribute indicates that the code generator should not use a
1816 red zone, even if the target-specific ABI normally permits it.
1817 ``indirect-tls-seg-refs``
1818 This attribute indicates that the code generator should not use
1819 direct TLS access through segment registers, even if the
1820 target-specific ABI normally permits it.
1822 This function attribute indicates that the function never returns
1823 normally, hence through a return instruction. This produces undefined
1824 behavior at runtime if the function ever does dynamically return. Annotated
1825 functions may still raise an exception, i.a., ``nounwind`` is not implied.
1827 This function attribute indicates that the function does not call itself
1828 either directly or indirectly down any possible call path. This produces
1829 undefined behavior at runtime if the function ever does recurse.
1831 .. _langref_willreturn:
1834 This function attribute indicates that a call of this function will
1835 either exhibit undefined behavior or comes back and continues execution
1836 at a point in the existing call stack that includes the current invocation.
1837 Annotated functions may still raise an exception, i.a., ``nounwind`` is not implied.
1838 If an invocation of an annotated function does not return control back
1839 to a point in the call stack, the behavior is undefined.
1841 This function attribute indicates that the function does not communicate
1842 (synchronize) with another thread through memory or other well-defined means.
1843 Synchronization is considered possible in the presence of `atomic` accesses
1844 that enforce an order, thus not "unordered" and "monotonic", `volatile` accesses,
1845 as well as `convergent` function calls. Note that through `convergent` function calls
1846 non-memory communication, e.g., cross-lane operations, are possible and are also
1847 considered synchronization. However `convergent` does not contradict `nosync`.
1848 If an annotated function does ever synchronize with another thread,
1849 the behavior is undefined.
1851 This function attribute indicates that the function never raises an
1852 exception. If the function does raise an exception, its runtime
1853 behavior is undefined. However, functions marked nounwind may still
1854 trap or generate asynchronous exceptions. Exception handling schemes
1855 that are recognized by LLVM to handle asynchronous exceptions, such
1856 as SEH, will still provide their implementation defined semantics.
1857 ``nosanitize_bounds``
1858 This attribute indicates that bounds checking sanitizer instrumentation
1859 is disabled for this function.
1860 ``nosanitize_coverage``
1861 This attribute indicates that SanitizerCoverage instrumentation is disabled
1863 ``null_pointer_is_valid``
1864 If ``null_pointer_is_valid`` is set, then the ``null`` address
1865 in address-space 0 is considered to be a valid address for memory loads and
1866 stores. Any analysis or optimization should not treat dereferencing a
1867 pointer to ``null`` as undefined behavior in this function.
1868 Note: Comparing address of a global variable to ``null`` may still
1869 evaluate to false because of a limitation in querying this attribute inside
1870 constant expressions.
1872 This attribute indicates that this function should be optimized
1873 for maximum fuzzing signal.
1875 This function attribute indicates that most optimization passes will skip
1876 this function, with the exception of interprocedural optimization passes.
1877 Code generation defaults to the "fast" instruction selector.
1878 This attribute cannot be used together with the ``alwaysinline``
1879 attribute; this attribute is also incompatible
1880 with the ``minsize`` attribute and the ``optsize`` attribute.
1882 This attribute requires the ``noinline`` attribute to be specified on
1883 the function as well, so the function is never inlined into any caller.
1884 Only functions with the ``alwaysinline`` attribute are valid
1885 candidates for inlining into the body of this function.
1887 This attribute suggests that optimization passes and code generator
1888 passes make choices that keep the code size of this function low,
1889 and otherwise do optimizations specifically to reduce code size as
1890 long as they do not significantly impact runtime performance.
1891 ``"patchable-function"``
1892 This attribute tells the code generator that the code
1893 generated for this function needs to follow certain conventions that
1894 make it possible for a runtime function to patch over it later.
1895 The exact effect of this attribute depends on its string value,
1896 for which there currently is one legal possibility:
1898 * ``"prologue-short-redirect"`` - This style of patchable
1899 function is intended to support patching a function prologue to
1900 redirect control away from the function in a thread safe
1901 manner. It guarantees that the first instruction of the
1902 function will be large enough to accommodate a short jump
1903 instruction, and will be sufficiently aligned to allow being
1904 fully changed via an atomic compare-and-swap instruction.
1905 While the first requirement can be satisfied by inserting large
1906 enough NOP, LLVM can and will try to re-purpose an existing
1907 instruction (i.e. one that would have to be emitted anyway) as
1908 the patchable instruction larger than a short jump.
1910 ``"prologue-short-redirect"`` is currently only supported on
1913 This attribute by itself does not imply restrictions on
1914 inter-procedural optimizations. All of the semantic effects the
1915 patching may have to be separately conveyed via the linkage type.
1917 This attribute indicates that the function will trigger a guard region
1918 in the end of the stack. It ensures that accesses to the stack must be
1919 no further apart than the size of the guard region to a previous
1920 access of the stack. It takes one required string value, the name of
1921 the stack probing function that will be called.
1923 If a function that has a ``"probe-stack"`` attribute is inlined into
1924 a function with another ``"probe-stack"`` attribute, the resulting
1925 function has the ``"probe-stack"`` attribute of the caller. If a
1926 function that has a ``"probe-stack"`` attribute is inlined into a
1927 function that has no ``"probe-stack"`` attribute at all, the resulting
1928 function has the ``"probe-stack"`` attribute of the callee.
1930 On a function, this attribute indicates that the function computes its
1931 result (or decides to unwind an exception) based strictly on its arguments,
1932 without dereferencing any pointer arguments or otherwise accessing
1933 any mutable state (e.g. memory, control registers, etc) visible outside the
1934 ``readnone`` function. It does not write through any pointer arguments
1935 (including ``byval`` arguments) and never changes any state visible to
1936 callers. This means while it cannot unwind exceptions by calling the ``C++``
1937 exception throwing methods (since they write to memory), there may be
1938 non-``C++`` mechanisms that throw exceptions without writing to LLVM visible
1941 On an argument, this attribute indicates that the function does not
1942 dereference that pointer argument, even though it may read or write the
1943 memory that the pointer points to if accessed through other pointers.
1945 If a readnone function reads or writes memory visible outside the function,
1946 or has other side-effects, the behavior is undefined. If a
1947 function reads from or writes to a readnone pointer argument, the behavior
1950 On a function, this attribute indicates that the function does not write
1951 through any pointer arguments (including ``byval`` arguments) or otherwise
1952 modify any state (e.g. memory, control registers, etc) visible outside the
1953 ``readonly`` function. It may dereference pointer arguments and read
1954 state that may be set in the caller. A readonly function always
1955 returns the same value (or unwinds an exception identically) when
1956 called with the same set of arguments and global state. This means while it
1957 cannot unwind exceptions by calling the ``C++`` exception throwing methods
1958 (since they write to memory), there may be non-``C++`` mechanisms that throw
1959 exceptions without writing to LLVM visible memory.
1961 On an argument, this attribute indicates that the function does not write
1962 through this pointer argument, even though it may write to the memory that
1963 the pointer points to.
1965 If a readonly function writes memory visible outside the function, or has
1966 other side-effects, the behavior is undefined. If a function writes to a
1967 readonly pointer argument, the behavior is undefined.
1968 ``"stack-probe-size"``
1969 This attribute controls the behavior of stack probes: either
1970 the ``"probe-stack"`` attribute, or ABI-required stack probes, if any.
1971 It defines the size of the guard region. It ensures that if the function
1972 may use more stack space than the size of the guard region, stack probing
1973 sequence will be emitted. It takes one required integer value, which
1976 If a function that has a ``"stack-probe-size"`` attribute is inlined into
1977 a function with another ``"stack-probe-size"`` attribute, the resulting
1978 function has the ``"stack-probe-size"`` attribute that has the lower
1979 numeric value. If a function that has a ``"stack-probe-size"`` attribute is
1980 inlined into a function that has no ``"stack-probe-size"`` attribute
1981 at all, the resulting function has the ``"stack-probe-size"`` attribute
1983 ``"no-stack-arg-probe"``
1984 This attribute disables ABI-required stack probes, if any.
1986 On a function, this attribute indicates that the function may write to but
1987 does not read from memory visible outside the ``writeonly`` function.
1989 On an argument, this attribute indicates that the function may write to but
1990 does not read through this pointer argument (even though it may read from
1991 the memory that the pointer points to).
1993 If a writeonly function reads memory visible outside the function or has
1994 other side-effects, the behavior is undefined. If a function reads
1995 from a writeonly pointer argument, the behavior is undefined.
1997 This attribute indicates that the only memory accesses inside function are
1998 loads and stores from objects pointed to by its pointer-typed arguments,
1999 with arbitrary offsets. Or in other words, all memory operations in the
2000 function can refer to memory only using pointers based on its function
2003 Note that ``argmemonly`` can be used together with ``readonly`` attribute
2004 in order to specify that function reads only from its arguments.
2006 If an argmemonly function reads or writes memory other than the pointer
2007 arguments, or has other side-effects, the behavior is undefined.
2009 This attribute indicates that this function can return twice. The C
2010 ``setjmp`` is an example of such a function. The compiler disables
2011 some optimizations (like tail calls) in the caller of these
2014 This attribute indicates that
2015 `SafeStack <https://clang.llvm.org/docs/SafeStack.html>`_
2016 protection is enabled for this function.
2018 If a function that has a ``safestack`` attribute is inlined into a
2019 function that doesn't have a ``safestack`` attribute or which has an
2020 ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting
2021 function will have a ``safestack`` attribute.
2022 ``sanitize_address``
2023 This attribute indicates that AddressSanitizer checks
2024 (dynamic address safety analysis) are enabled for this function.
2026 This attribute indicates that MemorySanitizer checks (dynamic detection
2027 of accesses to uninitialized memory) are enabled for this function.
2029 This attribute indicates that ThreadSanitizer checks
2030 (dynamic thread safety analysis) are enabled for this function.
2031 ``sanitize_hwaddress``
2032 This attribute indicates that HWAddressSanitizer checks
2033 (dynamic address safety analysis based on tagged pointers) are enabled for
2036 This attribute indicates that MemTagSanitizer checks
2037 (dynamic address safety analysis based on Armv8 MTE) are enabled for
2039 ``speculative_load_hardening``
2040 This attribute indicates that
2041 `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_
2042 should be enabled for the function body.
2044 Speculative Load Hardening is a best-effort mitigation against
2045 information leak attacks that make use of control flow
2046 miss-speculation - specifically miss-speculation of whether a branch
2047 is taken or not. Typically vulnerabilities enabling such attacks are
2048 classified as "Spectre variant #1". Notably, this does not attempt to
2049 mitigate against miss-speculation of branch target, classified as
2050 "Spectre variant #2" vulnerabilities.
2052 When inlining, the attribute is sticky. Inlining a function that carries
2053 this attribute will cause the caller to gain the attribute. This is intended
2054 to provide a maximally conservative model where the code in a function
2055 annotated with this attribute will always (even after inlining) end up
2058 This function attribute indicates that the function does not have any
2059 effects besides calculating its result and does not have undefined behavior.
2060 Note that ``speculatable`` is not enough to conclude that along any
2061 particular execution path the number of calls to this function will not be
2062 externally observable. This attribute is only valid on functions
2063 and declarations, not on individual call sites. If a function is
2064 incorrectly marked as speculatable and really does exhibit
2065 undefined behavior, the undefined behavior may be observed even
2066 if the call site is dead code.
2069 This attribute indicates that the function should emit a stack
2070 smashing protector. It is in the form of a "canary" --- a random value
2071 placed on the stack before the local variables that's checked upon
2072 return from the function to see if it has been overwritten. A
2073 heuristic is used to determine if a function needs stack protectors
2074 or not. The heuristic used will enable protectors for functions with:
2076 - Character arrays larger than ``ssp-buffer-size`` (default 8).
2077 - Aggregates containing character arrays larger than ``ssp-buffer-size``.
2078 - Calls to alloca() with variable sizes or constant sizes greater than
2079 ``ssp-buffer-size``.
2081 Variables that are identified as requiring a protector will be arranged
2082 on the stack such that they are adjacent to the stack protector guard.
2084 If a function with an ``ssp`` attribute is inlined into a calling function,
2085 the attribute is not carried over to the calling function.
2088 This attribute indicates that the function should emit a stack smashing
2089 protector. This attribute causes a strong heuristic to be used when
2090 determining if a function needs stack protectors. The strong heuristic
2091 will enable protectors for functions with:
2093 - Arrays of any size and type
2094 - Aggregates containing an array of any size and type.
2095 - Calls to alloca().
2096 - Local variables that have had their address taken.
2098 Variables that are identified as requiring a protector will be arranged
2099 on the stack such that they are adjacent to the stack protector guard.
2100 The specific layout rules are:
2102 #. Large arrays and structures containing large arrays
2103 (``>= ssp-buffer-size``) are closest to the stack protector.
2104 #. Small arrays and structures containing small arrays
2105 (``< ssp-buffer-size``) are 2nd closest to the protector.
2106 #. Variables that have had their address taken are 3rd closest to the
2109 This overrides the ``ssp`` function attribute.
2111 If a function with an ``sspstrong`` attribute is inlined into a calling
2112 function which has an ``ssp`` attribute, the calling function's attribute
2113 will be upgraded to ``sspstrong``.
2116 This attribute indicates that the function should *always* emit a stack
2117 smashing protector. This overrides the ``ssp`` and ``sspstrong`` function
2120 Variables that are identified as requiring a protector will be arranged
2121 on the stack such that they are adjacent to the stack protector guard.
2122 The specific layout rules are:
2124 #. Large arrays and structures containing large arrays
2125 (``>= ssp-buffer-size``) are closest to the stack protector.
2126 #. Small arrays and structures containing small arrays
2127 (``< ssp-buffer-size``) are 2nd closest to the protector.
2128 #. Variables that have had their address taken are 3rd closest to the
2131 If a function with an ``sspreq`` attribute is inlined into a calling
2132 function which has an ``ssp`` or ``sspstrong`` attribute, the calling
2133 function's attribute will be upgraded to ``sspreq``.
2136 This attribute indicates that the function was called from a scope that
2137 requires strict floating-point semantics. LLVM will not attempt any
2138 optimizations that require assumptions about the floating-point rounding
2139 mode or that might alter the state of floating-point status flags that
2140 might otherwise be set or cleared by calling this function. LLVM will
2141 not introduce any new floating-point instructions that may trap.
2143 ``"denormal-fp-math"``
2144 This indicates the denormal (subnormal) handling that may be
2145 assumed for the default floating-point environment. This is a
2146 comma separated pair. The elements may be one of ``"ieee"``,
2147 ``"preserve-sign"``, or ``"positive-zero"``. The first entry
2148 indicates the flushing mode for the result of floating point
2149 operations. The second indicates the handling of denormal inputs
2150 to floating point instructions. For compatibility with older
2151 bitcode, if the second value is omitted, both input and output
2152 modes will assume the same mode.
2154 If this is attribute is not specified, the default is
2157 If the output mode is ``"preserve-sign"``, or ``"positive-zero"``,
2158 denormal outputs may be flushed to zero by standard floating-point
2159 operations. It is not mandated that flushing to zero occurs, but if
2160 a denormal output is flushed to zero, it must respect the sign
2161 mode. Not all targets support all modes. While this indicates the
2162 expected floating point mode the function will be executed with,
2163 this does not make any attempt to ensure the mode is
2164 consistent. User or platform code is expected to set the floating
2165 point mode appropriately before function entry.
2167 If the input mode is ``"preserve-sign"``, or ``"positive-zero"``, a
2168 floating-point operation must treat any input denormal value as
2169 zero. In some situations, if an instruction does not respect this
2170 mode, the input may need to be converted to 0 as if by
2171 ``@llvm.canonicalize`` during lowering for correctness.
2173 ``"denormal-fp-math-f32"``
2174 Same as ``"denormal-fp-math"``, but only controls the behavior of
2175 the 32-bit float type (or vectors of 32-bit floats). If both are
2176 are present, this overrides ``"denormal-fp-math"``. Not all targets
2177 support separately setting the denormal mode per type, and no
2178 attempt is made to diagnose unsupported uses. Currently this
2179 attribute is respected by the AMDGPU and NVPTX backends.
2182 This attribute indicates that the function will delegate to some other
2183 function with a tail call. The prototype of a thunk should not be used for
2184 optimization purposes. The caller is expected to cast the thunk prototype to
2185 match the thunk target prototype.
2187 ``"tls-load-hoist"``
2188 This attribute indicates that the function will try to reduce redundant
2189 tls address calculation by hoisting tls variable.
2191 ``uwtable[(sync|async)]``
2192 This attribute indicates that the ABI being targeted requires that
2193 an unwind table entry be produced for this function even if we can
2194 show that no exceptions passes by it. This is normally the case for
2195 the ELF x86-64 abi, but it can be disabled for some compilation
2196 units. The optional parameter describes what kind of unwind tables
2197 to generate: ``sync`` for normal unwind tables, ``async`` for asynchronous
2198 (instruction precise) unwind tables. Without the parameter, the attribute
2199 ``uwtable`` is equivalent to ``uwtable(async)``.
2201 This attribute indicates that no control-flow check will be performed on
2202 the attributed entity. It disables -fcf-protection=<> for a specific
2203 entity to fine grain the HW control flow protection mechanism. The flag
2204 is target independent and currently appertains to a function or function
2207 This attribute indicates that the ShadowCallStack checks are enabled for
2208 the function. The instrumentation checks that the return address for the
2209 function has not changed between the function prolog and epilog. It is
2210 currently x86_64-specific.
2212 .. _langref_mustprogress:
2215 This attribute indicates that the function is required to return, unwind,
2216 or interact with the environment in an observable way e.g. via a volatile
2217 memory access, I/O, or other synchronization. The ``mustprogress``
2218 attribute is intended to model the requirements of the first section of
2219 [intro.progress] of the C++ Standard. As a consequence, a loop in a
2220 function with the `mustprogress` attribute can be assumed to terminate if
2221 it does not interact with the environment in an observable way, and
2222 terminating loops without side-effects can be removed. If a `mustprogress`
2223 function does not satisfy this contract, the behavior is undefined. This
2224 attribute does not apply transitively to callees, but does apply to call
2225 sites within the function. Note that `willreturn` implies `mustprogress`.
2226 ``"warn-stack-size"="<threshold>"``
2227 This attribute sets a threshold to emit diagnostics once the frame size is
2228 known should the frame size exceed the specified value. It takes one
2229 required integer value, which should be a non-negative integer, and less
2230 than `UINT_MAX`. It's unspecified which threshold will be used when
2231 duplicate definitions are linked together with differing values.
2232 ``vscale_range(<min>[, <max>])``
2233 This attribute indicates the minimum and maximum vscale value for the given
2234 function. The min must be greater than 0. A maximum value of 0 means
2235 unbounded. If the optional max value is omitted then max is set to the
2236 value of min. If the attribute is not present, no assumptions are made
2237 about the range of vscale.
2238 ``"min-legal-vector-width"="<size>"``
2239 This attribute indicates the minimum legal vector width required by the
2240 calling conversion. It is the maximum width of vector arguments and
2241 returnings in the function and functions called by this function. Because
2242 all the vectors are supposed to be legal type for compatibility.
2243 Backends are free to ignore the attribute if they don't need to support
2244 different maximum legal vector types or such information can be inferred by
2247 Call Site Attributes
2248 ----------------------
2250 In addition to function attributes the following call site only
2251 attributes are supported:
2253 ``vector-function-abi-variant``
2254 This attribute can be attached to a :ref:`call <i_call>` to list
2255 the vector functions associated to the function. Notice that the
2256 attribute cannot be attached to a :ref:`invoke <i_invoke>` or a
2257 :ref:`callbr <i_callbr>` instruction. The attribute consists of a
2258 comma separated list of mangled names. The order of the list does
2259 not imply preference (it is logically a set). The compiler is free
2260 to pick any listed vector function of its choosing.
2262 The syntax for the mangled names is as follows:::
2264 _ZGV<isa><mask><vlen><parameters>_<scalar_name>[(<vector_redirection>)]
2266 When present, the attribute informs the compiler that the function
2267 ``<scalar_name>`` has a corresponding vector variant that can be
2268 used to perform the concurrent invocation of ``<scalar_name>`` on
2269 vectors. The shape of the vector function is described by the
2270 tokens between the prefix ``_ZGV`` and the ``<scalar_name>``
2271 token. The standard name of the vector function is
2272 ``_ZGV<isa><mask><vlen><parameters>_<scalar_name>``. When present,
2273 the optional token ``(<vector_redirection>)`` informs the compiler
2274 that a custom name is provided in addition to the standard one
2275 (custom names can be provided for example via the use of ``declare
2276 variant`` in OpenMP 5.0). The declaration of the variant must be
2277 present in the IR Module. The signature of the vector variant is
2278 determined by the rules of the Vector Function ABI (VFABI)
2279 specifications of the target. For Arm and X86, the VFABI can be
2280 found at https://github.com/ARM-software/abi-aa and
2281 https://software.intel.com/content/www/us/en/develop/download/vector-simd-function-abi.html,
2284 For X86 and Arm targets, the values of the tokens in the standard
2285 name are those that are defined in the VFABI. LLVM has an internal
2286 ``<isa>`` token that can be used to create scalar-to-vector
2287 mappings for functions that are not directly associated to any of
2288 the target ISAs (for example, some of the mappings stored in the
2289 TargetLibraryInfo). Valid values for the ``<isa>`` token are:::
2291 <isa>:= b | c | d | e -> X86 SSE, AVX, AVX2, AVX512
2292 | n | s -> Armv8 Advanced SIMD, SVE
2293 | __LLVM__ -> Internal LLVM Vector ISA
2295 For all targets currently supported (x86, Arm and Internal LLVM),
2296 the remaining tokens can have the following values:::
2298 <mask>:= M | N -> mask | no mask
2300 <vlen>:= number -> number of lanes
2301 | x -> VLA (Vector Length Agnostic)
2303 <parameters>:= v -> vector
2304 | l | l <number> -> linear
2305 | R | R <number> -> linear with ref modifier
2306 | L | L <number> -> linear with val modifier
2307 | U | U <number> -> linear with uval modifier
2308 | ls <pos> -> runtime linear
2309 | Rs <pos> -> runtime linear with ref modifier
2310 | Ls <pos> -> runtime linear with val modifier
2311 | Us <pos> -> runtime linear with uval modifier
2314 <scalar_name>:= name of the scalar function
2316 <vector_redirection>:= optional, custom name of the vector function
2318 ``preallocated(<ty>)``
2319 This attribute is required on calls to ``llvm.call.preallocated.arg``
2320 and cannot be used on any other call. See
2321 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` for more
2329 Attributes may be set to communicate additional information about a global variable.
2330 Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable
2331 are grouped into a single :ref:`attribute group <attrgrp>`.
2333 ``no_sanitize_address``
2334 This attribute indicates that the global variable should not have
2335 AddressSanitizer instrumentation applied to it, because it was annotated
2336 with `__attribute__((no_sanitize("address")))`,
2337 `__attribute__((disable_sanitizer_instrumentation))`, or included in the
2338 `-fsanitize-ignorelist` file.
2339 ``no_sanitize_hwaddress``
2340 This attribute indicates that the global variable should not have
2341 HWAddressSanitizer instrumentation applied to it, because it was annotated
2342 with `__attribute__((no_sanitize("hwaddress")))`,
2343 `__attribute__((disable_sanitizer_instrumentation))`, or included in the
2344 `-fsanitize-ignorelist` file.
2346 This attribute indicates that the global variable should have AArch64 memory
2347 tags (MTE) instrumentation applied to it. This attribute causes the
2348 suppression of certain optimisations, like GlobalMerge, as well as ensuring
2349 extra directives are emitted in the assembly and extra bits of metadata are
2350 placed in the object file so that the linker can ensure the accesses are
2351 protected by MTE. This attribute is added by clang when
2352 `-fsanitize=memtag-globals` is provided, as long as the global is not marked
2353 with `__attribute__((no_sanitize("memtag")))`,
2354 `__attribute__((disable_sanitizer_instrumentation))`, or included in the
2355 `-fsanitize-ignorelist` file. The AArch64 Globals Tagging pass may remove
2356 this attribute when it's not possible to tag the global (e.g. it's a TLS
2358 ``sanitize_address_dyninit``
2359 This attribute indicates that the global variable, when instrumented with
2360 AddressSanitizer, should be checked for ODR violations. This attribute is
2361 applied to global variables that are dynamically initialized according to
2369 Operand bundles are tagged sets of SSA values that can be associated
2370 with certain LLVM instructions (currently only ``call`` s and
2371 ``invoke`` s). In a way they are like metadata, but dropping them is
2372 incorrect and will change program semantics.
2376 operand bundle set ::= '[' operand bundle (, operand bundle )* ']'
2377 operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')'
2378 bundle operand ::= SSA value
2379 tag ::= string constant
2381 Operand bundles are **not** part of a function's signature, and a
2382 given function may be called from multiple places with different kinds
2383 of operand bundles. This reflects the fact that the operand bundles
2384 are conceptually a part of the ``call`` (or ``invoke``), not the
2385 callee being dispatched to.
2387 Operand bundles are a generic mechanism intended to support
2388 runtime-introspection-like functionality for managed languages. While
2389 the exact semantics of an operand bundle depend on the bundle tag,
2390 there are certain limitations to how much the presence of an operand
2391 bundle can influence the semantics of a program. These restrictions
2392 are described as the semantics of an "unknown" operand bundle. As
2393 long as the behavior of an operand bundle is describable within these
2394 restrictions, LLVM does not need to have special knowledge of the
2395 operand bundle to not miscompile programs containing it.
2397 - The bundle operands for an unknown operand bundle escape in unknown
2398 ways before control is transferred to the callee or invokee.
2399 - Calls and invokes with operand bundles have unknown read / write
2400 effect on the heap on entry and exit (even if the call target is
2401 ``readnone`` or ``readonly``), unless they're overridden with
2402 callsite specific attributes.
2403 - An operand bundle at a call site cannot change the implementation
2404 of the called function. Inter-procedural optimizations work as
2405 usual as long as they take into account the first two properties.
2407 More specific types of operand bundles are described below.
2409 .. _deopt_opbundles:
2411 Deoptimization Operand Bundles
2412 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2414 Deoptimization operand bundles are characterized by the ``"deopt"``
2415 operand bundle tag. These operand bundles represent an alternate
2416 "safe" continuation for the call site they're attached to, and can be
2417 used by a suitable runtime to deoptimize the compiled frame at the
2418 specified call site. There can be at most one ``"deopt"`` operand
2419 bundle attached to a call site. Exact details of deoptimization is
2420 out of scope for the language reference, but it usually involves
2421 rewriting a compiled frame into a set of interpreted frames.
2423 From the compiler's perspective, deoptimization operand bundles make
2424 the call sites they're attached to at least ``readonly``. They read
2425 through all of their pointer typed operands (even if they're not
2426 otherwise escaped) and the entire visible heap. Deoptimization
2427 operand bundles do not capture their operands except during
2428 deoptimization, in which case control will not be returned to the
2431 The inliner knows how to inline through calls that have deoptimization
2432 operand bundles. Just like inlining through a normal call site
2433 involves composing the normal and exceptional continuations, inlining
2434 through a call site with a deoptimization operand bundle needs to
2435 appropriately compose the "safe" deoptimization continuation. The
2436 inliner does this by prepending the parent's deoptimization
2437 continuation to every deoptimization continuation in the inlined body.
2438 E.g. inlining ``@f`` into ``@g`` in the following example
2440 .. code-block:: llvm
2443 call void @x() ;; no deopt state
2444 call void @y() [ "deopt"(i32 10) ]
2445 call void @y() [ "deopt"(i32 10), "unknown"(ptr null) ]
2450 call void @f() [ "deopt"(i32 20) ]
2456 .. code-block:: llvm
2459 call void @x() ;; still no deopt state
2460 call void @y() [ "deopt"(i32 20, i32 10) ]
2461 call void @y() [ "deopt"(i32 20, i32 10), "unknown"(ptr null) ]
2465 It is the frontend's responsibility to structure or encode the
2466 deoptimization state in a way that syntactically prepending the
2467 caller's deoptimization state to the callee's deoptimization state is
2468 semantically equivalent to composing the caller's deoptimization
2469 continuation after the callee's deoptimization continuation.
2473 Funclet Operand Bundles
2474 ^^^^^^^^^^^^^^^^^^^^^^^
2476 Funclet operand bundles are characterized by the ``"funclet"``
2477 operand bundle tag. These operand bundles indicate that a call site
2478 is within a particular funclet. There can be at most one
2479 ``"funclet"`` operand bundle attached to a call site and it must have
2480 exactly one bundle operand.
2482 If any funclet EH pads have been "entered" but not "exited" (per the
2483 `description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_),
2484 it is undefined behavior to execute a ``call`` or ``invoke`` which:
2486 * does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind
2488 * has a ``"funclet"`` bundle whose operand is not the most-recently-entered
2489 not-yet-exited funclet EH pad.
2491 Similarly, if no funclet EH pads have been entered-but-not-yet-exited,
2492 executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior.
2494 GC Transition Operand Bundles
2495 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2497 GC transition operand bundles are characterized by the
2498 ``"gc-transition"`` operand bundle tag. These operand bundles mark a
2499 call as a transition between a function with one GC strategy to a
2500 function with a different GC strategy. If coordinating the transition
2501 between GC strategies requires additional code generation at the call
2502 site, these bundles may contain any values that are needed by the
2503 generated code. For more details, see :ref:`GC Transitions
2504 <gc_transition_args>`.
2506 The bundle contain an arbitrary list of Values which need to be passed
2507 to GC transition code. They will be lowered and passed as operands to
2508 the appropriate GC_TRANSITION nodes in the selection DAG. It is assumed
2509 that these arguments must be available before and after (but not
2510 necessarily during) the execution of the callee.
2512 .. _assume_opbundles:
2514 Assume Operand Bundles
2515 ^^^^^^^^^^^^^^^^^^^^^^
2517 Operand bundles on an :ref:`llvm.assume <int_assume>` allows representing
2518 assumptions that a :ref:`parameter attribute <paramattrs>` or a
2519 :ref:`function attribute <fnattrs>` holds for a certain value at a certain
2520 location. Operand bundles enable assumptions that are either hard or impossible
2521 to represent as a boolean argument of an :ref:`llvm.assume <int_assume>`.
2523 An assume operand bundle has the form:
2527 "<tag>"([ <holds for value> [, <attribute argument>] ])
2529 * The tag of the operand bundle is usually the name of attribute that can be
2530 assumed to hold. It can also be `ignore`, this tag doesn't contain any
2531 information and should be ignored.
2532 * The first argument if present is the value for which the attribute hold.
2533 * The second argument if present is an argument of the attribute.
2535 If there are no arguments the attribute is a property of the call location.
2539 .. code-block:: llvm
2541 call void @llvm.assume(i1 true) ["align"(ptr %val, i32 8)]
2543 allows the optimizer to assume that at location of call to
2544 :ref:`llvm.assume <int_assume>` ``%val`` has an alignment of at least 8.
2546 .. code-block:: llvm
2548 call void @llvm.assume(i1 %cond) ["cold"(), "nonnull"(ptr %val)]
2550 allows the optimizer to assume that the :ref:`llvm.assume <int_assume>`
2551 call location is cold and that ``%val`` may not be null.
2553 Just like for the argument of :ref:`llvm.assume <int_assume>`, if any of the
2554 provided guarantees are violated at runtime the behavior is undefined.
2556 While attributes expect constant arguments, assume operand bundles may be
2557 provided a dynamic value, for example:
2559 .. code-block:: llvm
2561 call void @llvm.assume(i1 true) ["align"(ptr %val, i32 %align)]
2563 If the operand bundle value violates any requirements on the attribute value,
2564 the behavior is undefined, unless one of the following exceptions applies:
2566 * ``"assume"`` operand bundles may specify a non-power-of-two alignment
2567 (including a zero alignment). If this is the case, then the pointer value
2568 must be a null pointer, otherwise the behavior is undefined.
2570 Even if the assumed property can be encoded as a boolean value, like
2571 ``nonnull``, using operand bundles to express the property can still have
2574 * Attributes that can be expressed via operand bundles are directly the
2575 property that the optimizer uses and cares about. Encoding attributes as
2576 operand bundles removes the need for an instruction sequence that represents
2577 the property (e.g., `icmp ne ptr %p, null` for `nonnull`) and for the
2578 optimizer to deduce the property from that instruction sequence.
2579 * Expressing the property using operand bundles makes it easy to identify the
2580 use of the value as a use in an :ref:`llvm.assume <int_assume>`. This then
2581 simplifies and improves heuristics, e.g., for use "use-sensitive"
2584 .. _ob_preallocated:
2586 Preallocated Operand Bundles
2587 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2589 Preallocated operand bundles are characterized by the ``"preallocated"``
2590 operand bundle tag. These operand bundles allow separation of the allocation
2591 of the call argument memory from the call site. This is necessary to pass
2592 non-trivially copyable objects by value in a way that is compatible with MSVC
2593 on some targets. There can be at most one ``"preallocated"`` operand bundle
2594 attached to a call site and it must have exactly one bundle operand, which is
2595 a token generated by ``@llvm.call.preallocated.setup``. A call with this
2596 operand bundle should not adjust the stack before entering the function, as
2597 that will have been done by one of the ``@llvm.call.preallocated.*`` intrinsics.
2599 .. code-block:: llvm
2601 %foo = type { i64, i32 }
2605 %t = call token @llvm.call.preallocated.setup(i32 1)
2606 %a = call ptr @llvm.call.preallocated.arg(token %t, i32 0) preallocated(%foo)
2608 call void @bar(i32 42, ptr preallocated(%foo) %a) ["preallocated"(token %t)]
2612 GC Live Operand Bundles
2613 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2615 A "gc-live" operand bundle is only valid on a :ref:`gc.statepoint <gc_statepoint>`
2616 intrinsic. The operand bundle must contain every pointer to a garbage collected
2617 object which potentially needs to be updated by the garbage collector.
2619 When lowered, any relocated value will be recorded in the corresponding
2620 :ref:`stackmap entry <statepoint-stackmap-format>`. See the intrinsic description
2621 for further details.
2623 ObjC ARC Attached Call Operand Bundles
2624 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626 A ``"clang.arc.attachedcall"`` operand bundle on a call indicates the call is
2627 implicitly followed by a marker instruction and a call to an ObjC runtime
2628 function that uses the result of the call. The operand bundle takes a mandatory
2629 pointer to the runtime function (``@objc_retainAutoreleasedReturnValue`` or
2630 ``@objc_unsafeClaimAutoreleasedReturnValue``).
2631 The return value of a call with this bundle is used by a call to
2632 ``@llvm.objc.clang.arc.noop.use`` unless the called function's return type is
2633 void, in which case the operand bundle is ignored.
2635 .. code-block:: llvm
2637 ; The marker instruction and a runtime function call are inserted after the call
2639 call ptr @foo() [ "clang.arc.attachedcall"(ptr @objc_retainAutoreleasedReturnValue) ]
2640 call ptr @foo() [ "clang.arc.attachedcall"(ptr @objc_unsafeClaimAutoreleasedReturnValue) ]
2642 The operand bundle is needed to ensure the call is immediately followed by the
2643 marker instruction and the ObjC runtime call in the final output.
2647 Pointer Authentication Operand Bundles
2648 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2650 Pointer Authentication operand bundles are characterized by the
2651 ``"ptrauth"`` operand bundle tag. They are described in the
2652 `Pointer Authentication <PointerAuth.html#operand-bundle>`__ document.
2656 Module-Level Inline Assembly
2657 ----------------------------
2659 Modules may contain "module-level inline asm" blocks, which corresponds
2660 to the GCC "file scope inline asm" blocks. These blocks are internally
2661 concatenated by LLVM and treated as a single unit, but may be separated
2662 in the ``.ll`` file if desired. The syntax is very simple:
2664 .. code-block:: llvm
2666 module asm "inline asm code goes here"
2667 module asm "more can go here"
2669 The strings can contain any character by escaping non-printable
2670 characters. The escape sequence used is simply "\\xx" where "xx" is the
2671 two digit hex code for the number.
2673 Note that the assembly string *must* be parseable by LLVM's integrated assembler
2674 (unless it is disabled), even when emitting a ``.s`` file.
2676 .. _langref_datalayout:
2681 A module may specify a target specific data layout string that specifies
2682 how data is to be laid out in memory. The syntax for the data layout is
2685 .. code-block:: llvm
2687 target datalayout = "layout specification"
2689 The *layout specification* consists of a list of specifications
2690 separated by the minus sign character ('-'). Each specification starts
2691 with a letter and may include other information after the letter to
2692 define some aspect of the data layout. The specifications accepted are
2696 Specifies that the target lays out data in big-endian form. That is,
2697 the bits with the most significance have the lowest address
2700 Specifies that the target lays out data in little-endian form. That
2701 is, the bits with the least significance have the lowest address
2704 Specifies the natural alignment of the stack in bits. Alignment
2705 promotion of stack variables is limited to the natural stack
2706 alignment to avoid dynamic stack realignment. The stack alignment
2707 must be a multiple of 8-bits. If omitted, the natural stack
2708 alignment defaults to "unspecified", which does not prevent any
2709 alignment promotions.
2710 ``P<address space>``
2711 Specifies the address space that corresponds to program memory.
2712 Harvard architectures can use this to specify what space LLVM
2713 should place things such as functions into. If omitted, the
2714 program memory space defaults to the default address space of 0,
2715 which corresponds to a Von Neumann architecture that has code
2716 and data in the same space.
2717 ``G<address space>``
2718 Specifies the address space to be used by default when creating global
2719 variables. If omitted, the globals address space defaults to the default
2721 Note: variable declarations without an address space are always created in
2722 address space 0, this property only affects the default value to be used
2723 when creating globals without additional contextual information (e.g. in
2725 ``A<address space>``
2726 Specifies the address space of objects created by '``alloca``'.
2727 Defaults to the default address space of 0.
2728 ``p[n]:<size>:<abi>[:<pref>][:<idx>]``
2729 This specifies the *size* of a pointer and its ``<abi>`` and
2730 ``<pref>``\erred alignments for address space ``n``. ``<pref>`` is optional
2731 and defaults to ``<abi>``. The fourth parameter ``<idx>`` is the size of the
2732 index that used for address calculation. If not
2733 specified, the default index size is equal to the pointer size. All sizes
2734 are in bits. The address space, ``n``, is optional, and if not specified,
2735 denotes the default address space 0. The value of ``n`` must be
2736 in the range [1,2^23).
2737 ``i<size>:<abi>[:<pref>]``
2738 This specifies the alignment for an integer type of a given bit
2739 ``<size>``. The value of ``<size>`` must be in the range [1,2^23).
2740 ``<pref>`` is optional and defaults to ``<abi>``.
2741 ``v<size>:<abi>[:<pref>]``
2742 This specifies the alignment for a vector type of a given bit
2743 ``<size>``. The value of ``<size>`` must be in the range [1,2^23).
2744 ``<pref>`` is optional and defaults to ``<abi>``.
2745 ``f<size>:<abi>[:<pref>]``
2746 This specifies the alignment for a floating-point type of a given bit
2747 ``<size>``. Only values of ``<size>`` that are supported by the target
2748 will work. 32 (float) and 64 (double) are supported on all targets; 80
2749 or 128 (different flavors of long double) are also supported on some
2750 targets. The value of ``<size>`` must be in the range [1,2^23).
2751 ``<pref>`` is optional and defaults to ``<abi>``.
2752 ``a:<abi>[:<pref>]``
2753 This specifies the alignment for an object of aggregate type.
2754 ``<pref>`` is optional and defaults to ``<abi>``.
2756 This specifies the alignment for function pointers.
2757 The options for ``<type>`` are:
2759 * ``i``: The alignment of function pointers is independent of the alignment
2760 of functions, and is a multiple of ``<abi>``.
2761 * ``n``: The alignment of function pointers is a multiple of the explicit
2762 alignment specified on the function, and is a multiple of ``<abi>``.
2764 If present, specifies that llvm names are mangled in the output. Symbols
2765 prefixed with the mangling escape character ``\01`` are passed through
2766 directly to the assembler without the escape character. The mangling style
2769 * ``e``: ELF mangling: Private symbols get a ``.L`` prefix.
2770 * ``l``: GOFF mangling: Private symbols get a ``@`` prefix.
2771 * ``m``: Mips mangling: Private symbols get a ``$`` prefix.
2772 * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other
2773 symbols get a ``_`` prefix.
2774 * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix.
2775 Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``,
2776 ``__fastcall``, and ``__vectorcall`` have custom mangling that appends
2777 ``@N`` where N is the number of bytes used to pass parameters. C++ symbols
2778 starting with ``?`` are not mangled in any way.
2779 * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C
2780 symbols do not receive a ``_`` prefix.
2781 * ``a``: XCOFF mangling: Private symbols get a ``L..`` prefix.
2782 ``n<size1>:<size2>:<size3>...``
2783 This specifies a set of native integer widths for the target CPU in
2784 bits. For example, it might contain ``n32`` for 32-bit PowerPC,
2785 ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of
2786 this set are considered to support most general arithmetic operations
2788 ``ni:<address space0>:<address space1>:<address space2>...``
2789 This specifies pointer types with the specified address spaces
2790 as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0``
2791 address space cannot be specified as non-integral.
2793 On every specification that takes a ``<abi>:<pref>``, specifying the
2794 ``<pref>`` alignment is optional. If omitted, the preceding ``:``
2795 should be omitted too and ``<pref>`` will be equal to ``<abi>``.
2797 When constructing the data layout for a given target, LLVM starts with a
2798 default set of specifications which are then (possibly) overridden by
2799 the specifications in the ``datalayout`` keyword. The default
2800 specifications are given in this list:
2802 - ``e`` - little endian
2803 - ``p:64:64:64`` - 64-bit pointers with 64-bit alignment.
2804 - ``p[n]:64:64:64`` - Other address spaces are assumed to be the
2805 same as the default address space.
2806 - ``S0`` - natural stack alignment is unspecified
2807 - ``i1:8:8`` - i1 is 8-bit (byte) aligned
2808 - ``i8:8:8`` - i8 is 8-bit (byte) aligned
2809 - ``i16:16:16`` - i16 is 16-bit aligned
2810 - ``i32:32:32`` - i32 is 32-bit aligned
2811 - ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred
2812 alignment of 64-bits
2813 - ``f16:16:16`` - half is 16-bit aligned
2814 - ``f32:32:32`` - float is 32-bit aligned
2815 - ``f64:64:64`` - double is 64-bit aligned
2816 - ``f128:128:128`` - quad is 128-bit aligned
2817 - ``v64:64:64`` - 64-bit vector is 64-bit aligned
2818 - ``v128:128:128`` - 128-bit vector is 128-bit aligned
2819 - ``a:0:64`` - aggregates are 64-bit aligned
2821 When LLVM is determining the alignment for a given type, it uses the
2824 #. If the type sought is an exact match for one of the specifications,
2825 that specification is used.
2826 #. If no match is found, and the type sought is an integer type, then
2827 the smallest integer type that is larger than the bitwidth of the
2828 sought type is used. If none of the specifications are larger than
2829 the bitwidth then the largest integer type is used. For example,
2830 given the default specifications above, the i7 type will use the
2831 alignment of i8 (next largest) while both i65 and i256 will use the
2832 alignment of i64 (largest specified).
2834 The function of the data layout string may not be what you expect.
2835 Notably, this is not a specification from the frontend of what alignment
2836 the code generator should use.
2838 Instead, if specified, the target data layout is required to match what
2839 the ultimate *code generator* expects. This string is used by the
2840 mid-level optimizers to improve code, and this only works if it matches
2841 what the ultimate code generator uses. There is no way to generate IR
2842 that does not embed this target-specific detail into the IR. If you
2843 don't specify the string, the default specifications will be used to
2844 generate a Data Layout and the optimization phases will operate
2845 accordingly and introduce target specificity into the IR with respect to
2846 these default specifications.
2853 A module may specify a target triple string that describes the target
2854 host. The syntax for the target triple is simply:
2856 .. code-block:: llvm
2858 target triple = "x86_64-apple-macosx10.7.0"
2860 The *target triple* string consists of a series of identifiers delimited
2861 by the minus sign character ('-'). The canonical forms are:
2865 ARCHITECTURE-VENDOR-OPERATING_SYSTEM
2866 ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
2868 This information is passed along to the backend so that it generates
2869 code for the proper architecture. It's possible to override this on the
2870 command line with the ``-mtriple`` command line option.
2875 ----------------------
2877 A memory object, or simply object, is a region of a memory space that is
2878 reserved by a memory allocation such as :ref:`alloca <i_alloca>`, heap
2879 allocation calls, and global variable definitions.
2880 Once it is allocated, the bytes stored in the region can only be read or written
2881 through a pointer that is :ref:`based on <pointeraliasing>` the allocation
2883 If a pointer that is not based on the object tries to read or write to the
2884 object, it is undefined behavior.
2886 A lifetime of a memory object is a property that decides its accessibility.
2887 Unless stated otherwise, a memory object is alive since its allocation, and
2888 dead after its deallocation.
2889 It is undefined behavior to access a memory object that isn't alive, but
2890 operations that don't dereference it such as
2891 :ref:`getelementptr <i_getelementptr>`, :ref:`ptrtoint <i_ptrtoint>` and
2892 :ref:`icmp <i_icmp>` return a valid result.
2893 This explains code motion of these instructions across operations that
2894 impact the object's lifetime.
2895 A stack object's lifetime can be explicitly specified using
2896 :ref:`llvm.lifetime.start <int_lifestart>` and
2897 :ref:`llvm.lifetime.end <int_lifeend>` intrinsic function calls.
2899 .. _pointeraliasing:
2901 Pointer Aliasing Rules
2902 ----------------------
2904 Any memory access must be done through a pointer value associated with
2905 an address range of the memory access, otherwise the behavior is
2906 undefined. Pointer values are associated with address ranges according
2907 to the following rules:
2909 - A pointer value is associated with the addresses associated with any
2910 value it is *based* on.
2911 - An address of a global variable is associated with the address range
2912 of the variable's storage.
2913 - The result value of an allocation instruction is associated with the
2914 address range of the allocated storage.
2915 - A null pointer in the default address-space is associated with no
2917 - An :ref:`undef value <undefvalues>` in *any* address-space is
2918 associated with no address.
2919 - An integer constant other than zero or a pointer value returned from
2920 a function not defined within LLVM may be associated with address
2921 ranges allocated through mechanisms other than those provided by
2922 LLVM. Such ranges shall not overlap with any ranges of addresses
2923 allocated by mechanisms provided by LLVM.
2925 A pointer value is *based* on another pointer value according to the
2928 - A pointer value formed from a scalar ``getelementptr`` operation is *based* on
2929 the pointer-typed operand of the ``getelementptr``.
2930 - The pointer in lane *l* of the result of a vector ``getelementptr`` operation
2931 is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand
2932 of the ``getelementptr``.
2933 - The result value of a ``bitcast`` is *based* on the operand of the
2935 - A pointer value formed by an ``inttoptr`` is *based* on all pointer
2936 values that contribute (directly or indirectly) to the computation of
2937 the pointer's value.
2938 - The "*based* on" relationship is transitive.
2940 Note that this definition of *"based"* is intentionally similar to the
2941 definition of *"based"* in C99, though it is slightly weaker.
2943 LLVM IR does not associate types with memory. The result type of a
2944 ``load`` merely indicates the size and alignment of the memory from
2945 which to load, as well as the interpretation of the value. The first
2946 operand type of a ``store`` similarly only indicates the size and
2947 alignment of the store.
2949 Consequently, type-based alias analysis, aka TBAA, aka
2950 ``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR.
2951 :ref:`Metadata <metadata>` may be used to encode additional information
2952 which specialized optimization passes may use to implement type-based
2960 Given a function call and a pointer that is passed as an argument or stored in
2961 the memory before the call, a pointer is *captured* by the call if it makes a
2962 copy of any part of the pointer that outlives the call.
2963 To be precise, a pointer is captured if one or more of the following conditions
2966 1. The call stores any bit of the pointer carrying information into a place,
2967 and the stored bits can be read from the place by the caller after this call
2970 .. code-block:: llvm
2972 @glb = global ptr null
2973 @glb2 = global ptr null
2974 @glb3 = global ptr null
2975 @glbi = global i32 0
2977 define ptr @f(ptr %a, ptr %b, ptr %c, ptr %d, ptr %e) {
2978 store ptr %a, ptr @glb ; %a is captured by this call
2980 store ptr %b, ptr @glb2 ; %b isn't captured because the stored value is overwritten by the store below
2981 store ptr null, ptr @glb2
2983 store ptr %c, ptr @glb3
2984 call void @g() ; If @g makes a copy of %c that outlives this call (@f), %c is captured
2985 store ptr null, ptr @glb3
2987 %i = ptrtoint ptr %d to i64
2988 %j = trunc i64 %i to i32
2989 store i32 %j, ptr @glbi ; %d is captured
2991 ret ptr %e ; %e is captured
2994 2. The call stores any bit of the pointer carrying information into a place,
2995 and the stored bits can be safely read from the place by another thread via
2998 .. code-block:: llvm
3000 @lock = global i1 true
3002 define void @f(ptr %a) {
3003 store ptr %a, ptr* @glb
3004 store atomic i1 false, ptr @lock release ; %a is captured because another thread can safely read @glb
3005 store ptr null, ptr @glb
3009 3. The call's behavior depends on any bit of the pointer carrying information.
3011 .. code-block:: llvm
3015 define void @f(ptr %a) {
3016 %c = icmp eq ptr %a, @glb
3017 br i1 %c, label %BB_EXIT, label %BB_CONTINUE ; escapes %a
3025 4. The pointer is used in a volatile access as its address.
3030 Volatile Memory Accesses
3031 ------------------------
3033 Certain memory accesses, such as :ref:`load <i_load>`'s,
3034 :ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be
3035 marked ``volatile``. The optimizers must not change the number of
3036 volatile operations or change their order of execution relative to other
3037 volatile operations. The optimizers *may* change the order of volatile
3038 operations relative to non-volatile operations. This is not Java's
3039 "volatile" and has no cross-thread synchronization behavior.
3041 A volatile load or store may have additional target-specific semantics.
3042 Any volatile operation can have side effects, and any volatile operation
3043 can read and/or modify state which is not accessible via a regular load
3044 or store in this module. Volatile operations may use addresses which do
3045 not point to memory (like MMIO registers). This means the compiler may
3046 not use a volatile operation to prove a non-volatile access to that
3047 address has defined behavior.
3049 The allowed side-effects for volatile accesses are limited. If a
3050 non-volatile store to a given address would be legal, a volatile
3051 operation may modify the memory at that address. A volatile operation
3052 may not modify any other memory accessible by the module being compiled.
3053 A volatile operation may not call any code in the current module.
3055 The compiler may assume execution will continue after a volatile operation,
3056 so operations which modify memory or may have undefined behavior can be
3057 hoisted past a volatile operation.
3059 As an exception to the preceding rule, the compiler may not assume execution
3060 will continue after a volatile store operation. This restriction is necessary
3061 to support the somewhat common pattern in C of intentionally storing to an
3062 invalid pointer to crash the program. In the future, it might make sense to
3063 allow frontends to control this behavior.
3065 IR-level volatile loads and stores cannot safely be optimized into llvm.memcpy
3066 or llvm.memmove intrinsics even when those intrinsics are flagged volatile.
3067 Likewise, the backend should never split or merge target-legal volatile
3068 load/store instructions. Similarly, IR-level volatile loads and stores cannot
3069 change from integer to floating-point or vice versa.
3071 .. admonition:: Rationale
3073 Platforms may rely on volatile loads and stores of natively supported
3074 data width to be executed as single instruction. For example, in C
3075 this holds for an l-value of volatile primitive type with native
3076 hardware support, but not necessarily for aggregate types. The
3077 frontend upholds these expectations, which are intentionally
3078 unspecified in the IR. The rules above ensure that IR transformations
3079 do not violate the frontend's contract with the language.
3083 Memory Model for Concurrent Operations
3084 --------------------------------------
3086 The LLVM IR does not define any way to start parallel threads of
3087 execution or to register signal handlers. Nonetheless, there are
3088 platform-specific ways to create them, and we define LLVM IR's behavior
3089 in their presence. This model is inspired by the C++0x memory model.
3091 For a more informal introduction to this model, see the :doc:`Atomics`.
3093 We define a *happens-before* partial order as the least partial order
3096 - Is a superset of single-thread program order, and
3097 - When a *synchronizes-with* ``b``, includes an edge from ``a`` to
3098 ``b``. *Synchronizes-with* pairs are introduced by platform-specific
3099 techniques, like pthread locks, thread creation, thread joining,
3100 etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering
3101 Constraints <ordering>`).
3103 Note that program order does not introduce *happens-before* edges
3104 between a thread and signals executing inside that thread.
3106 Every (defined) read operation (load instructions, memcpy, atomic
3107 loads/read-modify-writes, etc.) R reads a series of bytes written by
3108 (defined) write operations (store instructions, atomic
3109 stores/read-modify-writes, memcpy, etc.). For the purposes of this
3110 section, initialized globals are considered to have a write of the
3111 initializer which is atomic and happens before any other read or write
3112 of the memory in question. For each byte of a read R, R\ :sub:`byte`
3113 may see any write to the same byte, except:
3115 - If write\ :sub:`1` happens before write\ :sub:`2`, and
3116 write\ :sub:`2` happens before R\ :sub:`byte`, then
3117 R\ :sub:`byte` does not see write\ :sub:`1`.
3118 - If R\ :sub:`byte` happens before write\ :sub:`3`, then
3119 R\ :sub:`byte` does not see write\ :sub:`3`.
3121 Given that definition, R\ :sub:`byte` is defined as follows:
3123 - If R is volatile, the result is target-dependent. (Volatile is
3124 supposed to give guarantees which can support ``sig_atomic_t`` in
3125 C/C++, and may be used for accesses to addresses that do not behave
3126 like normal memory. It does not generally provide cross-thread
3128 - Otherwise, if there is no write to the same byte that happens before
3129 R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte.
3130 - Otherwise, if R\ :sub:`byte` may see exactly one write,
3131 R\ :sub:`byte` returns the value written by that write.
3132 - Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may
3133 see are atomic, it chooses one of the values written. See the :ref:`Atomic
3134 Memory Ordering Constraints <ordering>` section for additional
3135 constraints on how the choice is made.
3136 - Otherwise R\ :sub:`byte` returns ``undef``.
3138 R returns the value composed of the series of bytes it read. This
3139 implies that some bytes within the value may be ``undef`` **without**
3140 the entire value being ``undef``. Note that this only defines the
3141 semantics of the operation; it doesn't mean that targets will emit more
3142 than one instruction to read the series of bytes.
3144 Note that in cases where none of the atomic intrinsics are used, this
3145 model places only one restriction on IR transformations on top of what
3146 is required for single-threaded execution: introducing a store to a byte
3147 which might not otherwise be stored is not allowed in general.
3148 (Specifically, in the case where another thread might write to and read
3149 from an address, introducing a store can change a load that may see
3150 exactly one write into a load that may see multiple writes.)
3154 Atomic Memory Ordering Constraints
3155 ----------------------------------
3157 Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`,
3158 :ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`,
3159 :ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take
3160 ordering parameters that determine which other atomic instructions on
3161 the same address they *synchronize with*. These semantics are borrowed
3162 from Java and C++0x, but are somewhat more colloquial. If these
3163 descriptions aren't precise enough, check those specs (see spec
3164 references in the :doc:`atomics guide <Atomics>`).
3165 :ref:`fence <i_fence>` instructions treat these orderings somewhat
3166 differently since they don't take an address. See that instruction's
3167 documentation for details.
3169 For a simpler introduction to the ordering constraints, see the
3173 The set of values that can be read is governed by the happens-before
3174 partial order. A value cannot be read unless some operation wrote
3175 it. This is intended to provide a guarantee strong enough to model
3176 Java's non-volatile shared variables. This ordering cannot be
3177 specified for read-modify-write operations; it is not strong enough
3178 to make them atomic in any interesting way.
3180 In addition to the guarantees of ``unordered``, there is a single
3181 total order for modifications by ``monotonic`` operations on each
3182 address. All modification orders must be compatible with the
3183 happens-before order. There is no guarantee that the modification
3184 orders can be combined to a global total order for the whole program
3185 (and this often will not be possible). The read in an atomic
3186 read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and
3187 :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification
3188 order immediately before the value it writes. If one atomic read
3189 happens before another atomic read of the same address, the later
3190 read must see the same value or a later value in the address's
3191 modification order. This disallows reordering of ``monotonic`` (or
3192 stronger) operations on the same address. If an address is written
3193 ``monotonic``-ally by one thread, and other threads ``monotonic``-ally
3194 read that address repeatedly, the other threads must eventually see
3195 the write. This corresponds to the C++0x/C1x
3196 ``memory_order_relaxed``.
3198 In addition to the guarantees of ``monotonic``, a
3199 *synchronizes-with* edge may be formed with a ``release`` operation.
3200 This is intended to model C++'s ``memory_order_acquire``.
3202 In addition to the guarantees of ``monotonic``, if this operation
3203 writes a value which is subsequently read by an ``acquire``
3204 operation, it *synchronizes-with* that operation. (This isn't a
3205 complete description; see the C++0x definition of a release
3206 sequence.) This corresponds to the C++0x/C1x
3207 ``memory_order_release``.
3208 ``acq_rel`` (acquire+release)
3209 Acts as both an ``acquire`` and ``release`` operation on its
3210 address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``.
3211 ``seq_cst`` (sequentially consistent)
3212 In addition to the guarantees of ``acq_rel`` (``acquire`` for an
3213 operation that only reads, ``release`` for an operation that only
3214 writes), there is a global total order on all
3215 sequentially-consistent operations on all addresses, which is
3216 consistent with the *happens-before* partial order and with the
3217 modification orders of all the affected addresses. Each
3218 sequentially-consistent read sees the last preceding write to the
3219 same address in this global order. This corresponds to the C++0x/C1x
3220 ``memory_order_seq_cst`` and Java volatile.
3224 If an atomic operation is marked ``syncscope("singlethread")``, it only
3225 *synchronizes with* and only participates in the seq\_cst total orderings of
3226 other operations running in the same thread (for example, in signal handlers).
3228 If an atomic operation is marked ``syncscope("<target-scope>")``, where
3229 ``<target-scope>`` is a target specific synchronization scope, then it is target
3230 dependent if it *synchronizes with* and participates in the seq\_cst total
3231 orderings of other operations.
3233 Otherwise, an atomic operation that is not marked ``syncscope("singlethread")``
3234 or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the
3235 seq\_cst total orderings of other operations that are not marked
3236 ``syncscope("singlethread")`` or ``syncscope("<target-scope>")``.
3240 Floating-Point Environment
3241 --------------------------
3243 The default LLVM floating-point environment assumes that floating-point
3244 instructions do not have side effects. Results assume the round-to-nearest
3245 rounding mode. No floating-point exception state is maintained in this
3246 environment. Therefore, there is no attempt to create or preserve invalid
3247 operation (SNaN) or division-by-zero exceptions.
3249 The benefit of this exception-free assumption is that floating-point
3250 operations may be speculated freely without any other fast-math relaxations
3251 to the floating-point model.
3253 Code that requires different behavior than this should use the
3254 :ref:`Constrained Floating-Point Intrinsics <constrainedfp>`.
3261 LLVM IR floating-point operations (:ref:`fneg <i_fneg>`, :ref:`fadd <i_fadd>`,
3262 :ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
3263 :ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`), :ref:`phi <i_phi>`,
3264 :ref:`select <i_select>` and :ref:`call <i_call>`
3265 may use the following flags to enable otherwise unsafe
3266 floating-point transformations.
3269 No NaNs - Allow optimizations to assume the arguments and result are not
3270 NaN. If an argument is a nan, or the result would be a nan, it produces
3271 a :ref:`poison value <poisonvalues>` instead.
3274 No Infs - Allow optimizations to assume the arguments and result are not
3275 +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it
3276 produces a :ref:`poison value <poisonvalues>` instead.
3279 No Signed Zeros - Allow optimizations to treat the sign of a zero
3280 argument or result as insignificant. This does not imply that -0.0
3281 is poison and/or guaranteed to not exist in the operation.
3284 Allow Reciprocal - Allow optimizations to use the reciprocal of an
3285 argument rather than perform division.
3288 Allow floating-point contraction (e.g. fusing a multiply followed by an
3289 addition into a fused multiply-and-add). This does not enable reassociating
3290 to form arbitrary contractions. For example, ``(a*b) + (c*d) + e`` can not
3291 be transformed into ``(a*b) + ((c*d) + e)`` to create two fma operations.
3294 Approximate functions - Allow substitution of approximate calculations for
3295 functions (sin, log, sqrt, etc). See floating-point intrinsic definitions
3296 for places where this can apply to LLVM's intrinsic math functions.
3299 Allow reassociation transformations for floating-point instructions.
3300 This may dramatically change results in floating-point.
3303 This flag implies all of the others.
3307 Use-list Order Directives
3308 -------------------------
3310 Use-list directives encode the in-memory order of each use-list, allowing the
3311 order to be recreated. ``<order-indexes>`` is a comma-separated list of
3312 indexes that are assigned to the referenced value's uses. The referenced
3313 value's use-list is immediately sorted by these indexes.
3315 Use-list directives may appear at function scope or global scope. They are not
3316 instructions, and have no effect on the semantics of the IR. When they're at
3317 function scope, they must appear after the terminator of the final basic block.
3319 If basic blocks have their address taken via ``blockaddress()`` expressions,
3320 ``uselistorder_bb`` can be used to reorder their use-lists from outside their
3327 uselistorder <ty> <value>, { <order-indexes> }
3328 uselistorder_bb @function, %block { <order-indexes> }
3334 define void @foo(i32 %arg1, i32 %arg2) {
3336 ; ... instructions ...
3338 ; ... instructions ...
3340 ; At function scope.
3341 uselistorder i32 %arg1, { 1, 0, 2 }
3342 uselistorder label %bb, { 1, 0 }
3346 uselistorder ptr @global, { 1, 2, 0 }
3347 uselistorder i32 7, { 1, 0 }
3348 uselistorder i32 (i32) @bar, { 1, 0 }
3349 uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 }
3351 .. _source_filename:
3356 The *source filename* string is set to the original module identifier,
3357 which will be the name of the compiled source file when compiling from
3358 source through the clang front end, for example. It is then preserved through
3361 This is currently necessary to generate a consistent unique global
3362 identifier for local functions used in profile data, which prepends the
3363 source file name to the local function name.
3365 The syntax for the source file name is simply:
3367 .. code-block:: text
3369 source_filename = "/path/to/source.c"
3376 The LLVM type system is one of the most important features of the
3377 intermediate representation. Being typed enables a number of
3378 optimizations to be performed on the intermediate representation
3379 directly, without having to do extra analyses on the side before the
3380 transformation. A strong type system makes it easier to read the
3381 generated code and enables novel analyses and transformations that are
3382 not feasible to perform on normal three address code representations.
3392 The void type does not represent any value and has no size.
3410 The function type can be thought of as a function signature. It consists of a
3411 return type and a list of formal parameter types. The return type of a function
3412 type is a void type or first class type --- except for :ref:`label <t_label>`
3413 and :ref:`metadata <t_metadata>` types.
3419 <returntype> (<parameter list>)
3421 ...where '``<parameter list>``' is a comma-separated list of type
3422 specifiers. Optionally, the parameter list may include a type ``...``, which
3423 indicates that the function takes a variable number of arguments. Variable
3424 argument functions can access their arguments with the :ref:`variable argument
3425 handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type
3426 except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`.
3430 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3431 | ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` |
3432 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3433 | ``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. |
3434 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3435 | ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values |
3436 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3443 The :ref:`first class <t_firstclass>` types are perhaps the most important.
3444 Values of these types are the only ones which can be produced by
3452 These are the types that are valid in registers from CodeGen's perspective.
3461 The integer type is a very simple type that simply specifies an
3462 arbitrary bit width for the integer type desired. Any bit width from 1
3463 bit to 2\ :sup:`23`\ (about 8 million) can be specified.
3471 The number of bits the integer will occupy is specified by the ``N``
3477 +----------------+------------------------------------------------+
3478 | ``i1`` | a single-bit integer. |
3479 +----------------+------------------------------------------------+
3480 | ``i32`` | a 32-bit integer. |
3481 +----------------+------------------------------------------------+
3482 | ``i1942652`` | a really big integer of over 1 million bits. |
3483 +----------------+------------------------------------------------+
3487 Floating-Point Types
3488 """"""""""""""""""""
3497 - 16-bit floating-point value
3500 - 16-bit "brain" floating-point value (7-bit significand). Provides the
3501 same number of exponent bits as ``float``, so that it matches its dynamic
3502 range, but with greatly reduced precision. Used in Intel's AVX-512 BF16
3503 extensions and Arm's ARMv8.6-A extensions, among others.
3506 - 32-bit floating-point value
3509 - 64-bit floating-point value
3512 - 128-bit floating-point value (113-bit significand)
3515 - 80-bit floating-point value (X87)
3518 - 128-bit floating-point value (two 64-bits)
3520 The binary format of half, float, double, and fp128 correspond to the
3521 IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128
3529 The x86_amx type represents a value held in an AMX tile register on an x86
3530 machine. The operations allowed on it are quite limited. Only few intrinsics
3531 are allowed: stride load and store, zero and dot product. No instruction is
3532 allowed for this type. There are no arguments, arrays, pointers, vectors
3533 or constants of this type.
3547 The x86_mmx type represents a value held in an MMX register on an x86
3548 machine. The operations allowed on it are quite limited: parameters and
3549 return values, load and store, and bitcast. User-specified MMX
3550 instructions are represented as intrinsic or asm calls with arguments
3551 and/or results of this type. There are no arrays, vectors or constants
3568 The pointer type ``ptr`` is used to specify memory locations. Pointers are
3569 commonly used to reference objects in memory.
3571 Pointer types may have an optional address space attribute defining the
3572 numbered address space where the pointed-to object resides. The default
3573 address space is number zero. The semantics of non-zero address spaces
3574 are target-specific. For example, ``ptr addrspace(5)`` is a pointer
3577 Prior to LLVM 15, pointer types also specified a pointee type, such as
3578 ``i8*``, ``[4 x i32]*`` or ``i32 (i32*)*``. In LLVM 15, such "typed
3579 pointers" are still supported under non-default options. See the
3580 `opaque pointers document <OpaquePointers.html>`__ for more information.
3589 A vector type is a simple derived type that represents a vector of
3590 elements. Vector types are used when multiple primitive data are
3591 operated in parallel using a single instruction (SIMD). A vector type
3592 requires a size (number of elements), an underlying primitive data type,
3593 and a scalable property to represent vectors where the exact hardware
3594 vector length is unknown at compile time. Vector types are considered
3595 :ref:`first class <t_firstclass>`.
3599 In general vector elements are laid out in memory in the same way as
3600 :ref:`array types <t_array>`. Such an analogy works fine as long as the vector
3601 elements are byte sized. However, when the elements of the vector aren't byte
3602 sized it gets a bit more complicated. One way to describe the layout is by
3603 describing what happens when a vector such as <N x iM> is bitcasted to an
3604 integer type with N*M bits, and then following the rules for storing such an
3607 A bitcast from a vector type to a scalar integer type will see the elements
3608 being packed together (without padding). The order in which elements are
3609 inserted in the integer depends on endianess. For little endian element zero
3610 is put in the least significant bits of the integer, and for big endian
3611 element zero is put in the most significant bits.
3613 Using a vector such as ``<i4 1, i4 2, i4 3, i4 5>`` as an example, together
3614 with the analogy that we can replace a vector store by a bitcast followed by
3615 an integer store, we get this for big endian:
3617 .. code-block:: llvm
3619 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16
3621 ; Bitcasting from a vector to an integral type can be seen as
3622 ; concatenating the values:
3623 ; %val now has the hexadecimal value 0x1235.
3625 store i16 %val, ptr %ptr
3627 ; In memory the content will be (8-bit addressing):
3629 ; [%ptr + 0]: 00010010 (0x12)
3630 ; [%ptr + 1]: 00110101 (0x35)
3632 The same example for little endian:
3634 .. code-block:: llvm
3636 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16
3638 ; Bitcasting from a vector to an integral type can be seen as
3639 ; concatenating the values:
3640 ; %val now has the hexadecimal value 0x5321.
3642 store i16 %val, ptr %ptr
3644 ; In memory the content will be (8-bit addressing):
3646 ; [%ptr + 0]: 01010011 (0x53)
3647 ; [%ptr + 1]: 00100001 (0x21)
3649 When ``<N*M>`` isn't evenly divisible by the byte size the exact memory layout
3650 is unspecified (just like it is for an integral type of the same size). This
3651 is because different targets could put the padding at different positions when
3652 the type size is smaller than the type's store size.
3658 < <# elements> x <elementtype> > ; Fixed-length vector
3659 < vscale x <# elements> x <elementtype> > ; Scalable vector
3661 The number of elements is a constant integer value larger than 0;
3662 elementtype may be any integer, floating-point or pointer type. Vectors
3663 of size zero are not allowed. For scalable vectors, the total number of
3664 elements is a constant multiple (called vscale) of the specified number
3665 of elements; vscale is a positive integer that is unknown at compile time
3666 and the same hardware-dependent constant for all scalable vectors at run
3667 time. The size of a specific scalable vector type is thus constant within
3668 IR, even if the exact size in bytes cannot be determined until run time.
3672 +------------------------+----------------------------------------------------+
3673 | ``<4 x i32>`` | Vector of 4 32-bit integer values. |
3674 +------------------------+----------------------------------------------------+
3675 | ``<8 x float>`` | Vector of 8 32-bit floating-point values. |
3676 +------------------------+----------------------------------------------------+
3677 | ``<2 x i64>`` | Vector of 2 64-bit integer values. |
3678 +------------------------+----------------------------------------------------+
3679 | ``<4 x ptr>`` | Vector of 4 pointers |
3680 +------------------------+----------------------------------------------------+
3681 | ``<vscale x 4 x i32>`` | Vector with a multiple of 4 32-bit integer values. |
3682 +------------------------+----------------------------------------------------+
3691 The label type represents code labels.
3706 The token type is used when a value is associated with an instruction
3707 but all uses of the value must not attempt to introspect or obscure it.
3708 As such, it is not appropriate to have a :ref:`phi <i_phi>` or
3709 :ref:`select <i_select>` of type token.
3726 The metadata type represents embedded metadata. No derived types may be
3727 created from metadata except for :ref:`function <t_function>` arguments.
3740 Aggregate Types are a subset of derived types that can contain multiple
3741 member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are
3742 aggregate types. :ref:`Vectors <t_vector>` are not considered to be
3752 The array type is a very simple derived type that arranges elements
3753 sequentially in memory. The array type requires a size (number of
3754 elements) and an underlying data type.
3760 [<# elements> x <elementtype>]
3762 The number of elements is a constant integer value; ``elementtype`` may
3763 be any type with a size.
3767 +------------------+--------------------------------------+
3768 | ``[40 x i32]`` | Array of 40 32-bit integer values. |
3769 +------------------+--------------------------------------+
3770 | ``[41 x i32]`` | Array of 41 32-bit integer values. |
3771 +------------------+--------------------------------------+
3772 | ``[4 x i8]`` | Array of 4 8-bit integer values. |
3773 +------------------+--------------------------------------+
3775 Here are some examples of multidimensional arrays:
3777 +-----------------------------+----------------------------------------------------------+
3778 | ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. |
3779 +-----------------------------+----------------------------------------------------------+
3780 | ``[12 x [10 x float]]`` | 12x10 array of single precision floating-point values. |
3781 +-----------------------------+----------------------------------------------------------+
3782 | ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. |
3783 +-----------------------------+----------------------------------------------------------+
3785 There is no restriction on indexing beyond the end of the array implied
3786 by a static type (though there are restrictions on indexing beyond the
3787 bounds of an allocated object in some cases). This means that
3788 single-dimension 'variable sized array' addressing can be implemented in
3789 LLVM with a zero length array type. An implementation of 'pascal style
3790 arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for
3800 The structure type is used to represent a collection of data members
3801 together in memory. The elements of a structure may be any type that has
3804 Structures in memory are accessed using '``load``' and '``store``' by
3805 getting a pointer to a field with the '``getelementptr``' instruction.
3806 Structures in registers are accessed using the '``extractvalue``' and
3807 '``insertvalue``' instructions.
3809 Structures may optionally be "packed" structures, which indicate that
3810 the alignment of the struct is one byte, and that there is no padding
3811 between the elements. In non-packed structs, padding between field types
3812 is inserted as defined by the DataLayout string in the module, which is
3813 required to match what the underlying code generator expects.
3815 Structures can either be "literal" or "identified". A literal structure
3816 is defined inline with other types (e.g. ``[2 x {i32, i32}]``) whereas
3817 identified types are always defined at the top level with a name.
3818 Literal types are uniqued by their contents and can never be recursive
3819 or opaque since there is no way to write one. Identified types can be
3820 recursive, can be opaqued, and are never uniqued.
3826 %T1 = type { <type list> } ; Identified normal struct type
3827 %T2 = type <{ <type list> }> ; Identified packed struct type
3831 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3832 | ``{ i32, i32, i32 }`` | A triple of three ``i32`` values |
3833 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3834 | ``{ float, ptr }`` | A pair, where the first element is a ``float`` and the second element is a :ref:`pointer <t_pointer>`. |
3835 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3836 | ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. |
3837 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3841 Opaque Structure Types
3842 """"""""""""""""""""""
3846 Opaque structure types are used to represent structure types that
3847 do not have a body specified. This corresponds (for example) to the C
3848 notion of a forward declared structure. They can be named (``%X``) or
3860 +--------------+-------------------+
3861 | ``opaque`` | An opaque type. |
3862 +--------------+-------------------+
3869 LLVM has several different basic types of constants. This section
3870 describes them all and their syntax.
3875 **Boolean constants**
3876 The two strings '``true``' and '``false``' are both valid constants
3878 **Integer constants**
3879 Standard integers (such as '4') are constants of the
3880 :ref:`integer <t_integer>` type. Negative numbers may be used with
3882 **Floating-point constants**
3883 Floating-point constants use standard decimal notation (e.g.
3884 123.421), exponential notation (e.g. 1.23421e+2), or a more precise
3885 hexadecimal notation (see below). The assembler requires the exact
3886 decimal value of a floating-point constant. For example, the
3887 assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating
3888 decimal in binary. Floating-point constants must have a
3889 :ref:`floating-point <t_floating>` type.
3890 **Null pointer constants**
3891 The identifier '``null``' is recognized as a null pointer constant
3892 and must be of :ref:`pointer type <t_pointer>`.
3894 The identifier '``none``' is recognized as an empty token constant
3895 and must be of :ref:`token type <t_token>`.
3897 The one non-intuitive notation for constants is the hexadecimal form of
3898 floating-point constants. For example, the form
3899 '``double 0x432ff973cafa8000``' is equivalent to (but harder to read
3900 than) '``double 4.5e+15``'. The only time hexadecimal floating-point
3901 constants are required (and the only time that they are generated by the
3902 disassembler) is when a floating-point constant must be emitted but it
3903 cannot be represented as a decimal floating-point number in a reasonable
3904 number of digits. For example, NaN's, infinities, and other special
3905 values are represented in their IEEE hexadecimal format so that assembly
3906 and disassembly do not cause any bits to change in the constants.
3908 When using the hexadecimal form, constants of types bfloat, half, float, and
3909 double are represented using the 16-digit form shown above (which matches the
3910 IEEE754 representation for double); bfloat, half and float values must, however,
3911 be exactly representable as bfloat, IEEE 754 half, and IEEE 754 single
3912 precision respectively. Hexadecimal format is always used for long double, and
3913 there are three forms of long double. The 80-bit format used by x86 is
3914 represented as ``0xK`` followed by 20 hexadecimal digits. The 128-bit format
3915 used by PowerPC (two adjacent doubles) is represented by ``0xM`` followed by 32
3916 hexadecimal digits. The IEEE 128-bit format is represented by ``0xL`` followed
3917 by 32 hexadecimal digits. Long doubles will only work if they match the long
3918 double format on your target. The IEEE 16-bit format (half precision) is
3919 represented by ``0xH`` followed by 4 hexadecimal digits. The bfloat 16-bit
3920 format is represented by ``0xR`` followed by 4 hexadecimal digits. All
3921 hexadecimal formats are big-endian (sign bit at the left).
3923 There are no constants of type x86_mmx and x86_amx.
3925 .. _complexconstants:
3930 Complex constants are a (potentially recursive) combination of simple
3931 constants and smaller complex constants.
3933 **Structure constants**
3934 Structure constants are represented with notation similar to
3935 structure type definitions (a comma separated list of elements,
3936 surrounded by braces (``{}``)). For example:
3937 "``{ i32 4, float 17.0, ptr @G }``", where "``@G``" is declared as
3938 "``@G = external global i32``". Structure constants must have
3939 :ref:`structure type <t_struct>`, and the number and types of elements
3940 must match those specified by the type.
3942 Array constants are represented with notation similar to array type
3943 definitions (a comma separated list of elements, surrounded by
3944 square brackets (``[]``)). For example:
3945 "``[ i32 42, i32 11, i32 74 ]``". Array constants must have
3946 :ref:`array type <t_array>`, and the number and types of elements must
3947 match those specified by the type. As a special case, character array
3948 constants may also be represented as a double-quoted string using the ``c``
3949 prefix. For example: "``c"Hello World\0A\00"``".
3950 **Vector constants**
3951 Vector constants are represented with notation similar to vector
3952 type definitions (a comma separated list of elements, surrounded by
3953 less-than/greater-than's (``<>``)). For example:
3954 "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants
3955 must have :ref:`vector type <t_vector>`, and the number and types of
3956 elements must match those specified by the type.
3957 **Zero initialization**
3958 The string '``zeroinitializer``' can be used to zero initialize a
3959 value to zero of *any* type, including scalar and
3960 :ref:`aggregate <t_aggregate>` types. This is often used to avoid
3961 having to print large zero initializers (e.g. for large arrays) and
3962 is always exactly equivalent to using explicit zero initializers.
3964 A metadata node is a constant tuple without types. For example:
3965 "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values,
3966 for example: "``!{!0, i32 0, ptr @global, ptr @function, !"str"}``".
3967 Unlike other typed constants that are meant to be interpreted as part of
3968 the instruction stream, metadata is a place to attach additional
3969 information such as debug info.
3971 Global Variable and Function Addresses
3972 --------------------------------------
3974 The addresses of :ref:`global variables <globalvars>` and
3975 :ref:`functions <functionstructure>` are always implicitly valid
3976 (link-time) constants. These constants are explicitly referenced when
3977 the :ref:`identifier for the global <identifiers>` is used and always have
3978 :ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM
3981 .. code-block:: llvm
3985 @Z = global [2 x ptr] [ ptr @X, ptr @Y ]
3992 The string '``undef``' can be used anywhere a constant is expected, and
3993 indicates that the user of the value may receive an unspecified
3994 bit-pattern. Undefined values may be of any type (other than '``label``'
3995 or '``void``') and be used anywhere a constant is permitted.
3999 A '``poison``' value (decribed in the next section) should be used instead of
4000 '``undef``' whenever possible. Poison values are stronger than undef, and
4001 enable more optimizations. Just the existence of '``undef``' blocks certain
4002 optimizations (see the examples below).
4004 Undefined values are useful because they indicate to the compiler that
4005 the program is well defined no matter what value is used. This gives the
4006 compiler more freedom to optimize. Here are some examples of
4007 (potentially surprising) transformations that are valid (in pseudo IR):
4009 .. code-block:: llvm
4019 This is safe because all of the output bits are affected by the undef
4020 bits. Any output bit can have a zero or one depending on the input bits.
4022 .. code-block:: llvm
4030 %A = %X ;; By choosing undef as 0
4031 %B = %X ;; By choosing undef as -1
4036 These logical operations have bits that are not always affected by the
4037 input. For example, if ``%X`` has a zero bit, then the output of the
4038 '``and``' operation will always be a zero for that bit, no matter what
4039 the corresponding bit from the '``undef``' is. As such, it is unsafe to
4040 optimize or assume that the result of the '``and``' is '``undef``'.
4041 However, it is safe to assume that all bits of the '``undef``' could be
4042 0, and optimize the '``and``' to 0. Likewise, it is safe to assume that
4043 all the bits of the '``undef``' operand to the '``or``' could be set,
4044 allowing the '``or``' to be folded to -1.
4046 .. code-block:: llvm
4048 %A = select undef, %X, %Y
4049 %B = select undef, 42, %Y
4050 %C = select %X, %Y, undef
4054 %C = %Y (if %Y is provably not poison; unsafe otherwise)
4060 This set of examples shows that undefined '``select``' (and conditional
4061 branch) conditions can go *either way*, but they have to come from one
4062 of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were
4063 both known to have a clear low bit, then ``%A`` would have to have a
4064 cleared low bit. However, in the ``%C`` example, the optimizer is
4065 allowed to assume that the '``undef``' operand could be the same as
4066 ``%Y`` if ``%Y`` is provably not '``poison``', allowing the whole '``select``'
4067 to be eliminated. This is because '``poison``' is stronger than '``undef``'.
4069 .. code-block:: llvm
4071 %A = xor undef, undef
4088 This example points out that two '``undef``' operands are not
4089 necessarily the same. This can be surprising to people (and also matches
4090 C semantics) where they assume that "``X^X``" is always zero, even if
4091 ``X`` is undefined. This isn't true for a number of reasons, but the
4092 short answer is that an '``undef``' "variable" can arbitrarily change
4093 its value over its "live range". This is true because the variable
4094 doesn't actually *have a live range*. Instead, the value is logically
4095 read from arbitrary registers that happen to be around when needed, so
4096 the value is not necessarily consistent over time. In fact, ``%A`` and
4097 ``%C`` need to have the same semantics or the core LLVM "replace all
4098 uses with" concept would not hold.
4100 To ensure all uses of a given register observe the same value (even if
4101 '``undef``'), the :ref:`freeze instruction <i_freeze>` can be used.
4103 .. code-block:: llvm
4111 These examples show the crucial difference between an *undefined value*
4112 and *undefined behavior*. An undefined value (like '``undef``') is
4113 allowed to have an arbitrary bit-pattern. This means that the ``%A``
4114 operation can be constant folded to '``0``', because the '``undef``'
4115 could be zero, and zero divided by any value is zero.
4116 However, in the second example, we can make a more aggressive
4117 assumption: because the ``undef`` is allowed to be an arbitrary value,
4118 we are allowed to assume that it could be zero. Since a divide by zero
4119 has *undefined behavior*, we are allowed to assume that the operation
4120 does not execute at all. This allows us to delete the divide and all
4121 code after it. Because the undefined operation "can't happen", the
4122 optimizer can assume that it occurs in dead code.
4124 .. code-block:: text
4126 a: store undef -> %X
4127 b: store %X -> undef
4129 a: <deleted> (if the stored value in %X is provably not poison)
4132 A store *of* an undefined value can be assumed to not have any effect;
4133 we can assume that the value is overwritten with bits that happen to
4134 match what was already there. This argument is only valid if the stored value
4135 is provably not ``poison``. However, a store *to* an undefined
4136 location could clobber arbitrary memory, therefore, it has undefined
4139 Branching on an undefined value is undefined behavior.
4140 This explains optimizations that depend on branch conditions to construct
4141 predicates, such as Correlated Value Propagation and Global Value Numbering.
4142 In case of switch instruction, the branch condition should be frozen, otherwise
4143 it is undefined behavior.
4145 .. code-block:: llvm
4148 br undef, BB1, BB2 ; UB
4150 %X = and i32 undef, 255
4151 switch %X, label %ret [ .. ] ; UB
4153 store undef, ptr %ptr
4154 %X = load ptr %ptr ; %X is undef
4155 switch i8 %X, label %ret [ .. ] ; UB
4158 %X = or i8 undef, 255 ; always 255
4159 switch i8 %X, label %ret [ .. ] ; Well-defined
4161 %X = freeze i1 undef
4162 br %X, BB1, BB2 ; Well-defined (non-deterministic jump)
4171 A poison value is a result of an erroneous operation.
4172 In order to facilitate speculative execution, many instructions do not
4173 invoke immediate undefined behavior when provided with illegal operands,
4174 and return a poison value instead.
4175 The string '``poison``' can be used anywhere a constant is expected, and
4176 operations such as :ref:`add <i_add>` with the ``nsw`` flag can produce
4179 Most instructions return '``poison``' when one of their arguments is
4180 '``poison``'. A notable exception is the :ref:`select instruction <i_select>`.
4181 Propagation of poison can be stopped with the
4182 :ref:`freeze instruction <i_freeze>`.
4184 It is correct to replace a poison value with an
4185 :ref:`undef value <undefvalues>` or any value of the type.
4187 This means that immediate undefined behavior occurs if a poison value is
4188 used as an instruction operand that has any values that trigger undefined
4189 behavior. Notably this includes (but is not limited to):
4191 - The pointer operand of a :ref:`load <i_load>`, :ref:`store <i_store>` or
4192 any other pointer dereferencing instruction (independent of address
4194 - The divisor operand of a ``udiv``, ``sdiv``, ``urem`` or ``srem``
4196 - The condition operand of a :ref:`br <i_br>` instruction.
4197 - The callee operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
4199 - The parameter operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
4200 instruction, when the function or invoking call site has a ``noundef``
4201 attribute in the corresponding position.
4202 - The operand of a :ref:`ret <i_ret>` instruction if the function or invoking
4203 call site has a `noundef` attribute in the return value position.
4205 Here are some examples:
4207 .. code-block:: llvm
4210 %poison = sub nuw i32 0, 1 ; Results in a poison value.
4211 %poison2 = sub i32 poison, 1 ; Also results in a poison value.
4212 %still_poison = and i32 %poison, 0 ; 0, but also poison.
4213 %poison_yet_again = getelementptr i32, ptr @h, i32 %still_poison
4214 store i32 0, ptr %poison_yet_again ; Undefined behavior due to
4217 store i32 %poison, ptr @g ; Poison value stored to memory.
4218 %poison3 = load i32, ptr @g ; Poison value loaded back from memory.
4220 %poison4 = load i16, ptr @g ; Returns a poison value.
4221 %poison5 = load i64, ptr @g ; Returns a poison value.
4223 %cmp = icmp slt i32 %poison, 0 ; Returns a poison value.
4224 br i1 %cmp, label %end, label %end ; undefined behavior
4228 .. _welldefinedvalues:
4233 Given a program execution, a value is *well defined* if the value does not
4234 have an undef bit and is not poison in the execution.
4235 An aggregate value or vector is well defined if its elements are well defined.
4236 The padding of an aggregate isn't considered, since it isn't visible
4237 without storing it into memory and loading it with a different type.
4239 A constant of a :ref:`single value <t_single_value>`, non-vector type is well
4240 defined if it is neither '``undef``' constant nor '``poison``' constant.
4241 The result of :ref:`freeze instruction <i_freeze>` is well defined regardless
4246 Addresses of Basic Blocks
4247 -------------------------
4249 ``blockaddress(@function, %block)``
4251 The '``blockaddress``' constant computes the address of the specified
4252 basic block in the specified function.
4254 It always has an ``ptr addrspace(P)`` type, where ``P`` is the address space
4255 of the function containing ``%block`` (usually ``addrspace(0)``).
4257 Taking the address of the entry block is illegal.
4259 This value only has defined behavior when used as an operand to the
4260 ':ref:`indirectbr <i_indirectbr>`' or ':ref:`callbr <i_callbr>`'instruction, or
4261 for comparisons against null. Pointer equality tests between labels addresses
4262 results in undefined behavior --- though, again, comparison against null is ok,
4263 and no label is equal to the null pointer. This may be passed around as an
4264 opaque pointer sized value as long as the bits are not inspected. This
4265 allows ``ptrtoint`` and arithmetic to be performed on these values so
4266 long as the original value is reconstituted before the ``indirectbr`` or
4267 ``callbr`` instruction.
4269 Finally, some targets may provide defined semantics when using the value
4270 as the operand to an inline assembly, but that is target specific.
4272 .. _dso_local_equivalent:
4274 DSO Local Equivalent
4275 --------------------
4277 ``dso_local_equivalent @func``
4279 A '``dso_local_equivalent``' constant represents a function which is
4280 functionally equivalent to a given function, but is always defined in the
4281 current linkage unit. The resulting pointer has the same type as the underlying
4282 function. The resulting pointer is permitted, but not required, to be different
4283 from a pointer to the function, and it may have different values in different
4286 The target function may not have ``extern_weak`` linkage.
4288 ``dso_local_equivalent`` can be implemented as such:
4290 - If the function has local linkage, hidden visibility, or is
4291 ``dso_local``, ``dso_local_equivalent`` can be implemented as simply a pointer
4293 - ``dso_local_equivalent`` can be implemented with a stub that tail-calls the
4294 function. Many targets support relocations that resolve at link time to either
4295 a function or a stub for it, depending on if the function is defined within the
4296 linkage unit; LLVM will use this when available. (This is commonly called a
4297 "PLT stub".) On other targets, the stub may need to be emitted explicitly.
4299 This can be used wherever a ``dso_local`` instance of a function is needed without
4300 needing to explicitly make the original function ``dso_local``. An instance where
4301 this can be used is for static offset calculations between a function and some other
4302 ``dso_local`` symbol. This is especially useful for the Relative VTables C++ ABI,
4303 where dynamic relocations for function pointers in VTables can be replaced with
4304 static relocations for offsets between the VTable and virtual functions which
4305 may not be ``dso_local``.
4307 This is currently only supported for ELF binary formats.
4316 With `Control-Flow Integrity (CFI)
4317 <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, a '``no_cfi``'
4318 constant represents a function reference that does not get replaced with a
4319 reference to the CFI jump table in the ``LowerTypeTests`` pass. These constants
4320 may be useful in low-level programs, such as operating system kernels, which
4321 need to refer to the actual function body.
4325 Constant Expressions
4326 --------------------
4328 Constant expressions are used to allow expressions involving other
4329 constants to be used as constants. Constant expressions may be of any
4330 :ref:`first class <t_firstclass>` type and may involve any LLVM operation
4331 that does not have side effects (e.g. load and call are not supported).
4332 The following is the syntax for constant expressions:
4334 ``trunc (CST to TYPE)``
4335 Perform the :ref:`trunc operation <i_trunc>` on constants.
4336 ``zext (CST to TYPE)``
4337 Perform the :ref:`zext operation <i_zext>` on constants.
4338 ``sext (CST to TYPE)``
4339 Perform the :ref:`sext operation <i_sext>` on constants.
4340 ``fptrunc (CST to TYPE)``
4341 Truncate a floating-point constant to another floating-point type.
4342 The size of CST must be larger than the size of TYPE. Both types
4343 must be floating-point.
4344 ``fpext (CST to TYPE)``
4345 Floating-point extend a constant to another type. The size of CST
4346 must be smaller or equal to the size of TYPE. Both types must be
4348 ``fptoui (CST to TYPE)``
4349 Convert a floating-point constant to the corresponding unsigned
4350 integer constant. TYPE must be a scalar or vector integer type. CST
4351 must be of scalar or vector floating-point type. Both CST and TYPE
4352 must be scalars, or vectors of the same number of elements. If the
4353 value won't fit in the integer type, the result is a
4354 :ref:`poison value <poisonvalues>`.
4355 ``fptosi (CST to TYPE)``
4356 Convert a floating-point constant to the corresponding signed
4357 integer constant. TYPE must be a scalar or vector integer type. CST
4358 must be of scalar or vector floating-point type. Both CST and TYPE
4359 must be scalars, or vectors of the same number of elements. If the
4360 value won't fit in the integer type, the result is a
4361 :ref:`poison value <poisonvalues>`.
4362 ``uitofp (CST to TYPE)``
4363 Convert an unsigned integer constant to the corresponding
4364 floating-point constant. TYPE must be a scalar or vector floating-point
4365 type. CST must be of scalar or vector integer type. Both CST and TYPE must
4366 be scalars, or vectors of the same number of elements.
4367 ``sitofp (CST to TYPE)``
4368 Convert a signed integer constant to the corresponding floating-point
4369 constant. TYPE must be a scalar or vector floating-point type.
4370 CST must be of scalar or vector integer type. Both CST and TYPE must
4371 be scalars, or vectors of the same number of elements.
4372 ``ptrtoint (CST to TYPE)``
4373 Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants.
4374 ``inttoptr (CST to TYPE)``
4375 Perform the :ref:`inttoptr operation <i_inttoptr>` on constants.
4376 This one is *really* dangerous!
4377 ``bitcast (CST to TYPE)``
4378 Convert a constant, CST, to another TYPE.
4379 The constraints of the operands are the same as those for the
4380 :ref:`bitcast instruction <i_bitcast>`.
4381 ``addrspacecast (CST to TYPE)``
4382 Convert a constant pointer or constant vector of pointer, CST, to another
4383 TYPE in a different address space. The constraints of the operands are the
4384 same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`.
4385 ``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)``
4386 Perform the :ref:`getelementptr operation <i_getelementptr>` on
4387 constants. As with the :ref:`getelementptr <i_getelementptr>`
4388 instruction, the index list may have one or more indexes, which are
4389 required to make sense for the type of "pointer to TY".
4390 ``select (COND, VAL1, VAL2)``
4391 Perform the :ref:`select operation <i_select>` on constants.
4392 ``icmp COND (VAL1, VAL2)``
4393 Perform the :ref:`icmp operation <i_icmp>` on constants.
4394 ``fcmp COND (VAL1, VAL2)``
4395 Perform the :ref:`fcmp operation <i_fcmp>` on constants.
4396 ``extractelement (VAL, IDX)``
4397 Perform the :ref:`extractelement operation <i_extractelement>` on
4399 ``insertelement (VAL, ELT, IDX)``
4400 Perform the :ref:`insertelement operation <i_insertelement>` on
4402 ``shufflevector (VEC1, VEC2, IDXMASK)``
4403 Perform the :ref:`shufflevector operation <i_shufflevector>` on
4405 ``extractvalue (VAL, IDX0, IDX1, ...)``
4406 Perform the :ref:`extractvalue operation <i_extractvalue>` on
4407 constants. The index list is interpreted in a similar manner as
4408 indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At
4409 least one index value must be specified.
4410 ``insertvalue (VAL, ELT, IDX0, IDX1, ...)``
4411 Perform the :ref:`insertvalue operation <i_insertvalue>` on constants.
4412 The index list is interpreted in a similar manner as indices in a
4413 ':ref:`getelementptr <i_getelementptr>`' operation. At least one index
4414 value must be specified.
4415 ``OPCODE (LHS, RHS)``
4416 Perform the specified operation of the LHS and RHS constants. OPCODE
4417 may be any of the :ref:`binary <binaryops>` or :ref:`bitwise
4418 binary <bitwiseops>` operations. The constraints on operands are
4419 the same as those for the corresponding instruction (e.g. no bitwise
4420 operations on floating-point values are allowed).
4427 Inline Assembler Expressions
4428 ----------------------------
4430 LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level
4431 Inline Assembly <moduleasm>`) through the use of a special value. This value
4432 represents the inline assembler as a template string (containing the
4433 instructions to emit), a list of operand constraints (stored as a string), a
4434 flag that indicates whether or not the inline asm expression has side effects,
4435 and a flag indicating whether the function containing the asm needs to align its
4436 stack conservatively.
4438 The template string supports argument substitution of the operands using "``$``"
4439 followed by a number, to indicate substitution of the given register/memory
4440 location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also
4441 be used, where ``MODIFIER`` is a target-specific annotation for how to print the
4442 operand (See :ref:`inline-asm-modifiers`).
4444 A literal "``$``" may be included by using "``$$``" in the template. To include
4445 other special characters into the output, the usual "``\XX``" escapes may be
4446 used, just as in other strings. Note that after template substitution, the
4447 resulting assembly string is parsed by LLVM's integrated assembler unless it is
4448 disabled -- even when emitting a ``.s`` file -- and thus must contain assembly
4449 syntax known to LLVM.
4451 LLVM also supports a few more substitutions useful for writing inline assembly:
4453 - ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob.
4454 This substitution is useful when declaring a local label. Many standard
4455 compiler optimizations, such as inlining, may duplicate an inline asm blob.
4456 Adding a blob-unique identifier ensures that the two labels will not conflict
4457 during assembly. This is used to implement `GCC's %= special format
4458 string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_.
4459 - ``${:comment}``: Expands to the comment character of the current target's
4460 assembly dialect. This is usually ``#``, but many targets use other strings,
4461 such as ``;``, ``//``, or ``!``.
4462 - ``${:private}``: Expands to the assembler private label prefix. Labels with
4463 this prefix will not appear in the symbol table of the assembled object.
4464 Typically the prefix is ``L``, but targets may use other strings. ``.L`` is
4467 LLVM's support for inline asm is modeled closely on the requirements of Clang's
4468 GCC-compatible inline-asm support. Thus, the feature-set and the constraint and
4469 modifier codes listed here are similar or identical to those in GCC's inline asm
4470 support. However, to be clear, the syntax of the template and constraint strings
4471 described here is *not* the same as the syntax accepted by GCC and Clang, and,
4472 while most constraint letters are passed through as-is by Clang, some get
4473 translated to other codes when converting from the C source to the LLVM
4476 An example inline assembler expression is:
4478 .. code-block:: llvm
4480 i32 (i32) asm "bswap $0", "=r,r"
4482 Inline assembler expressions may **only** be used as the callee operand
4483 of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction.
4484 Thus, typically we have:
4486 .. code-block:: llvm
4488 %X = call i32 asm "bswap $0", "=r,r"(i32 %Y)
4490 Inline asms with side effects not visible in the constraint list must be
4491 marked as having side effects. This is done through the use of the
4492 '``sideeffect``' keyword, like so:
4494 .. code-block:: llvm
4496 call void asm sideeffect "eieio", ""()
4498 In some cases inline asms will contain code that will not work unless
4499 the stack is aligned in some way, such as calls or SSE instructions on
4500 x86, yet will not contain code that does that alignment within the asm.
4501 The compiler should make conservative assumptions about what the asm
4502 might contain and should generate its usual stack alignment code in the
4503 prologue if the '``alignstack``' keyword is present:
4505 .. code-block:: llvm
4507 call void asm alignstack "eieio", ""()
4509 Inline asms also support using non-standard assembly dialects. The
4510 assumed dialect is ATT. When the '``inteldialect``' keyword is present,
4511 the inline asm is using the Intel dialect. Currently, ATT and Intel are
4512 the only supported dialects. An example is:
4514 .. code-block:: llvm
4516 call void asm inteldialect "eieio", ""()
4518 In the case that the inline asm might unwind the stack,
4519 the '``unwind``' keyword must be used, so that the compiler emits
4520 unwinding information:
4522 .. code-block:: llvm
4524 call void asm unwind "call func", ""()
4526 If the inline asm unwinds the stack and isn't marked with
4527 the '``unwind``' keyword, the behavior is undefined.
4529 If multiple keywords appear, the '``sideeffect``' keyword must come
4530 first, the '``alignstack``' keyword second, the '``inteldialect``' keyword
4531 third and the '``unwind``' keyword last.
4533 Inline Asm Constraint String
4534 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4536 The constraint list is a comma-separated string, each element containing one or
4537 more constraint codes.
4539 For each element in the constraint list an appropriate register or memory
4540 operand will be chosen, and it will be made available to assembly template
4541 string expansion as ``$0`` for the first constraint in the list, ``$1`` for the
4544 There are three different types of constraints, which are distinguished by a
4545 prefix symbol in front of the constraint code: Output, Input, and Clobber. The
4546 constraints must always be given in that order: outputs first, then inputs, then
4547 clobbers. They cannot be intermingled.
4549 There are also three different categories of constraint codes:
4551 - Register constraint. This is either a register class, or a fixed physical
4552 register. This kind of constraint will allocate a register, and if necessary,
4553 bitcast the argument or result to the appropriate type.
4554 - Memory constraint. This kind of constraint is for use with an instruction
4555 taking a memory operand. Different constraints allow for different addressing
4556 modes used by the target.
4557 - Immediate value constraint. This kind of constraint is for an integer or other
4558 immediate value which can be rendered directly into an instruction. The
4559 various target-specific constraints allow the selection of a value in the
4560 proper range for the instruction you wish to use it with.
4565 Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This
4566 indicates that the assembly will write to this operand, and the operand will
4567 then be made available as a return value of the ``asm`` expression. Output
4568 constraints do not consume an argument from the call instruction. (Except, see
4569 below about indirect outputs).
4571 Normally, it is expected that no output locations are written to by the assembly
4572 expression until *all* of the inputs have been read. As such, LLVM may assign
4573 the same register to an output and an input. If this is not safe (e.g. if the
4574 assembly contains two instructions, where the first writes to one output, and
4575 the second reads an input and writes to a second output), then the "``&``"
4576 modifier must be used (e.g. "``=&r``") to specify that the output is an
4577 "early-clobber" output. Marking an output as "early-clobber" ensures that LLVM
4578 will not use the same register for any inputs (other than an input tied to this
4584 Input constraints do not have a prefix -- just the constraint codes. Each input
4585 constraint will consume one argument from the call instruction. It is not
4586 permitted for the asm to write to any input register or memory location (unless
4587 that input is tied to an output). Note also that multiple inputs may all be
4588 assigned to the same register, if LLVM can determine that they necessarily all
4589 contain the same value.
4591 Instead of providing a Constraint Code, input constraints may also "tie"
4592 themselves to an output constraint, by providing an integer as the constraint
4593 string. Tied inputs still consume an argument from the call instruction, and
4594 take up a position in the asm template numbering as is usual -- they will simply
4595 be constrained to always use the same register as the output they've been tied
4596 to. For example, a constraint string of "``=r,0``" says to assign a register for
4597 output, and use that register as an input as well (it being the 0'th
4600 It is permitted to tie an input to an "early-clobber" output. In that case, no
4601 *other* input may share the same register as the input tied to the early-clobber
4602 (even when the other input has the same value).
4604 You may only tie an input to an output which has a register constraint, not a
4605 memory constraint. Only a single input may be tied to an output.
4607 There is also an "interesting" feature which deserves a bit of explanation: if a
4608 register class constraint allocates a register which is too small for the value
4609 type operand provided as input, the input value will be split into multiple
4610 registers, and all of them passed to the inline asm.
4612 However, this feature is often not as useful as you might think.
4614 Firstly, the registers are *not* guaranteed to be consecutive. So, on those
4615 architectures that have instructions which operate on multiple consecutive
4616 instructions, this is not an appropriate way to support them. (e.g. the 32-bit
4617 SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The
4618 hardware then loads into both the named register, and the next register. This
4619 feature of inline asm would not be useful to support that.)
4621 A few of the targets provide a template string modifier allowing explicit access
4622 to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and
4623 ``D``). On such an architecture, you can actually access the second allocated
4624 register (yet, still, not any subsequent ones). But, in that case, you're still
4625 probably better off simply splitting the value into two separate operands, for
4626 clarity. (e.g. see the description of the ``A`` constraint on X86, which,
4627 despite existing only for use with this feature, is not really a good idea to
4630 Indirect inputs and outputs
4631 """""""""""""""""""""""""""
4633 Indirect output or input constraints can be specified by the "``*``" modifier
4634 (which goes after the "``=``" in case of an output). This indicates that the asm
4635 will write to or read from the contents of an *address* provided as an input
4636 argument. (Note that in this way, indirect outputs act more like an *input* than
4637 an output: just like an input, they consume an argument of the call expression,
4638 rather than producing a return value. An indirect output constraint is an
4639 "output" only in that the asm is expected to write to the contents of the input
4640 memory location, instead of just read from it).
4642 This is most typically used for memory constraint, e.g. "``=*m``", to pass the
4643 address of a variable as a value.
4645 It is also possible to use an indirect *register* constraint, but only on output
4646 (e.g. "``=*r``"). This will cause LLVM to allocate a register for an output
4647 value normally, and then, separately emit a store to the address provided as
4648 input, after the provided inline asm. (It's not clear what value this
4649 functionality provides, compared to writing the store explicitly after the asm
4650 statement, and it can only produce worse code, since it bypasses many
4651 optimization passes. I would recommend not using it.)
4653 Call arguments for indirect constraints must have pointer type and must specify
4654 the :ref:`elementtype <attr_elementtype>` attribute to indicate the pointer
4660 A clobber constraint is indicated by a "``~``" prefix. A clobber does not
4661 consume an input operand, nor generate an output. Clobbers cannot use any of the
4662 general constraint code letters -- they may use only explicit register
4663 constraints, e.g. "``~{eax}``". The one exception is that a clobber string of
4664 "``~{memory}``" indicates that the assembly writes to arbitrary undeclared
4665 memory locations -- not only the memory pointed to by a declared indirect
4668 Note that clobbering named registers that are also present in output
4669 constraints is not legal.
4674 A label constraint is indicated by a "``!``" prefix and typically used in the
4675 form ``"!i"``. Instead of consuming call arguments, label constraints consume
4676 indirect destination labels of ``callbr`` instructions.
4678 Label constraints can only be used in conjunction with ``callbr`` and the
4679 number of label constraints must match the number of indirect destination
4680 labels in the ``callbr`` instruction.
4685 After a potential prefix comes constraint code, or codes.
4687 A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character
4688 followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``"
4691 The one and two letter constraint codes are typically chosen to be the same as
4692 GCC's constraint codes.
4694 A single constraint may include one or more than constraint code in it, leaving
4695 it up to LLVM to choose which one to use. This is included mainly for
4696 compatibility with the translation of GCC inline asm coming from clang.
4698 There are two ways to specify alternatives, and either or both may be used in an
4699 inline asm constraint list:
4701 1) Append the codes to each other, making a constraint code set. E.g. "``im``"
4702 or "``{eax}m``". This means "choose any of the options in the set". The
4703 choice of constraint is made independently for each constraint in the
4706 2) Use "``|``" between constraint code sets, creating alternatives. Every
4707 constraint in the constraint list must have the same number of alternative
4708 sets. With this syntax, the same alternative in *all* of the items in the
4709 constraint list will be chosen together.
4711 Putting those together, you might have a two operand constraint string like
4712 ``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then
4713 operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1
4714 may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m.
4716 However, the use of either of the alternatives features is *NOT* recommended, as
4717 LLVM is not able to make an intelligent choice about which one to use. (At the
4718 point it currently needs to choose, not enough information is available to do so
4719 in a smart way.) Thus, it simply tries to make a choice that's most likely to
4720 compile, not one that will be optimal performance. (e.g., given "``rm``", it'll
4721 always choose to use memory, not registers). And, if given multiple registers,
4722 or multiple register classes, it will simply choose the first one. (In fact, it
4723 doesn't currently even ensure explicitly specified physical registers are
4724 unique, so specifying multiple physical registers as alternatives, like
4725 ``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was
4728 Supported Constraint Code List
4729 """"""""""""""""""""""""""""""
4731 The constraint codes are, in general, expected to behave the same way they do in
4732 GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
4733 inline asm code which was supported by GCC. A mismatch in behavior between LLVM
4734 and GCC likely indicates a bug in LLVM.
4736 Some constraint codes are typically supported by all targets:
4738 - ``r``: A register in the target's general purpose register class.
4739 - ``m``: A memory address operand. It is target-specific what addressing modes
4740 are supported, typical examples are register, or register + register offset,
4741 or register + immediate offset (of some target-specific size).
4742 - ``p``: An address operand. Similar to ``m``, but used by "load address"
4743 type instructions without touching memory.
4744 - ``i``: An integer constant (of target-specific width). Allows either a simple
4745 immediate, or a relocatable value.
4746 - ``n``: An integer constant -- *not* including relocatable values.
4747 - ``s``: An integer constant, but allowing *only* relocatable values.
4748 - ``X``: Allows an operand of any kind, no constraint whatsoever. Typically
4749 useful to pass a label for an asm branch or call.
4751 .. FIXME: but that surely isn't actually okay to jump out of an asm
4752 block without telling llvm about the control transfer???)
4754 - ``{register-name}``: Requires exactly the named physical register.
4756 Other constraints are target-specific:
4760 - ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate.
4761 - ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction,
4762 i.e. 0 to 4095 with optional shift by 12.
4763 - ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or
4764 ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12.
4765 - ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a
4766 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register.
4767 - ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a
4768 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register.
4769 - ``M``: An immediate integer for use with the ``MOV`` assembly alias on a
4770 32-bit register. This is a superset of ``K``: in addition to the bitmask
4771 immediate, also allows immediate integers which can be loaded with a single
4772 ``MOVZ`` or ``MOVL`` instruction.
4773 - ``N``: An immediate integer for use with the ``MOV`` assembly alias on a
4774 64-bit register. This is a superset of ``L``.
4775 - ``Q``: Memory address operand must be in a single register (no
4776 offsets). (However, LLVM currently does this for the ``m`` constraint as
4778 - ``r``: A 32 or 64-bit integer register (W* or X*).
4779 - ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register.
4780 - ``x``: Like w, but restricted to registers 0 to 15 inclusive.
4781 - ``y``: Like w, but restricted to SVE vector registers Z0 to Z7 inclusive.
4782 - ``Upl``: One of the low eight SVE predicate registers (P0 to P7)
4783 - ``Upa``: Any of the SVE predicate registers (P0 to P15)
4787 - ``r``: A 32 or 64-bit integer register.
4788 - ``[0-9]v``: The 32-bit VGPR register, number 0-9.
4789 - ``[0-9]s``: The 32-bit SGPR register, number 0-9.
4790 - ``[0-9]a``: The 32-bit AGPR register, number 0-9.
4791 - ``I``: An integer inline constant in the range from -16 to 64.
4792 - ``J``: A 16-bit signed integer constant.
4793 - ``A``: An integer or a floating-point inline constant.
4794 - ``B``: A 32-bit signed integer constant.
4795 - ``C``: A 32-bit unsigned integer constant or an integer inline constant in the range from -16 to 64.
4796 - ``DA``: A 64-bit constant that can be split into two "A" constants.
4797 - ``DB``: A 64-bit constant that can be split into two "B" constants.
4801 - ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address
4802 operand. Treated the same as operand ``m``, at the moment.
4803 - ``Te``: An even general-purpose 32-bit integer register: ``r0,r2,...,r12,r14``
4804 - ``To``: An odd general-purpose 32-bit integer register: ``r1,r3,...,r11``
4806 ARM and ARM's Thumb2 mode:
4808 - ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``)
4809 - ``I``: An immediate integer valid for a data-processing instruction.
4810 - ``J``: An immediate integer between -4095 and 4095.
4811 - ``K``: An immediate integer whose bitwise inverse is valid for a
4812 data-processing instruction. (Can be used with template modifier "``B``" to
4813 print the inverted value).
4814 - ``L``: An immediate integer whose negation is valid for a data-processing
4815 instruction. (Can be used with template modifier "``n``" to print the negated
4817 - ``M``: A power of two or an integer between 0 and 32.
4818 - ``N``: Invalid immediate constraint.
4819 - ``O``: Invalid immediate constraint.
4820 - ``r``: A general-purpose 32-bit integer register (``r0-r15``).
4821 - ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same
4823 - ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode,
4825 - ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
4826 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively.
4827 - ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
4828 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively.
4829 - ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
4830 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively.
4834 - ``I``: An immediate integer between 0 and 255.
4835 - ``J``: An immediate integer between -255 and -1.
4836 - ``K``: An immediate integer between 0 and 255, with optional left-shift by
4838 - ``L``: An immediate integer between -7 and 7.
4839 - ``M``: An immediate integer which is a multiple of 4 between 0 and 1020.
4840 - ``N``: An immediate integer between 0 and 31.
4841 - ``O``: An immediate integer which is a multiple of 4 between -508 and 508.
4842 - ``r``: A low 32-bit GPR register (``r0-r7``).
4843 - ``l``: A low 32-bit GPR register (``r0-r7``).
4844 - ``h``: A high GPR register (``r0-r7``).
4845 - ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
4846 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively.
4847 - ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
4848 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively.
4849 - ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges
4850 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively.
4855 - ``o``, ``v``: A memory address operand, treated the same as constraint ``m``,
4857 - ``r``: A 32 or 64-bit register.
4861 - ``r``: An 8 or 16-bit register.
4865 - ``I``: An immediate signed 16-bit integer.
4866 - ``J``: An immediate integer zero.
4867 - ``K``: An immediate unsigned 16-bit integer.
4868 - ``L``: An immediate 32-bit integer, where the lower 16 bits are 0.
4869 - ``N``: An immediate integer between -65535 and -1.
4870 - ``O``: An immediate signed 15-bit integer.
4871 - ``P``: An immediate integer between 1 and 65535.
4872 - ``m``: A memory address operand. In MIPS-SE mode, allows a base address
4873 register plus 16-bit immediate offset. In MIPS mode, just a base register.
4874 - ``R``: A memory address operand. In MIPS-SE mode, allows a base address
4875 register plus a 9-bit signed offset. In MIPS mode, the same as constraint
4877 - ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or
4878 ``sc`` instruction on the given subtarget (details vary).
4879 - ``r``, ``d``, ``y``: A 32 or 64-bit GPR register.
4880 - ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register
4881 (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w``
4882 argument modifier for compatibility with GCC.
4883 - ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always
4885 - ``l``: The ``lo`` register, 32 or 64-bit.
4890 - ``b``: A 1-bit integer register.
4891 - ``c`` or ``h``: A 16-bit integer register.
4892 - ``r``: A 32-bit integer register.
4893 - ``l`` or ``N``: A 64-bit integer register.
4894 - ``f``: A 32-bit float register.
4895 - ``d``: A 64-bit float register.
4900 - ``I``: An immediate signed 16-bit integer.
4901 - ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits.
4902 - ``K``: An immediate unsigned 16-bit integer.
4903 - ``L``: An immediate signed 16-bit integer, shifted left 16 bits.
4904 - ``M``: An immediate integer greater than 31.
4905 - ``N``: An immediate integer that is an exact power of 2.
4906 - ``O``: The immediate integer constant 0.
4907 - ``P``: An immediate integer constant whose negation is a signed 16-bit
4909 - ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently
4910 treated the same as ``m``.
4911 - ``r``: A 32 or 64-bit integer register.
4912 - ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is:
4914 - ``f``: A 32 or 64-bit float register (``F0-F31``),
4915 - ``v``: For ``4 x f32`` or ``4 x f64`` types, a 128-bit altivec vector
4916 register (``V0-V31``).
4918 - ``y``: Condition register (``CR0-CR7``).
4919 - ``wc``: An individual CR bit in a CR register.
4920 - ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX
4921 register set (overlapping both the floating-point and vector register files).
4922 - ``ws``: A 32 or 64-bit floating-point register, from the full VSX register
4927 - ``A``: An address operand (using a general-purpose register, without an
4929 - ``I``: A 12-bit signed integer immediate operand.
4930 - ``J``: A zero integer immediate operand.
4931 - ``K``: A 5-bit unsigned integer immediate operand.
4932 - ``f``: A 32- or 64-bit floating-point register (requires F or D extension).
4933 - ``r``: A 32- or 64-bit general-purpose register (depending on the platform
4935 - ``vr``: A vector register. (requires V extension).
4936 - ``vm``: A vector register for masking operand. (requires V extension).
4940 - ``I``: An immediate 13-bit signed integer.
4941 - ``r``: A 32-bit integer register.
4942 - ``f``: Any floating-point register on SparcV8, or a floating-point
4943 register in the "low" half of the registers on SparcV9.
4944 - ``e``: Any floating-point register. (Same as ``f`` on SparcV8.)
4948 - ``I``: An immediate unsigned 8-bit integer.
4949 - ``J``: An immediate unsigned 12-bit integer.
4950 - ``K``: An immediate signed 16-bit integer.
4951 - ``L``: An immediate signed 20-bit integer.
4952 - ``M``: An immediate integer 0x7fffffff.
4953 - ``Q``: A memory address operand with a base address and a 12-bit immediate
4954 unsigned displacement.
4955 - ``R``: A memory address operand with a base address, a 12-bit immediate
4956 unsigned displacement, and an index register.
4957 - ``S``: A memory address operand with a base address and a 20-bit immediate
4958 signed displacement.
4959 - ``T``: A memory address operand with a base address, a 20-bit immediate
4960 signed displacement, and an index register.
4961 - ``r`` or ``d``: A 32, 64, or 128-bit integer register.
4962 - ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an
4963 address context evaluates as zero).
4964 - ``h``: A 32-bit value in the high part of a 64bit data register
4966 - ``f``: A 32, 64, or 128-bit floating-point register.
4970 - ``I``: An immediate integer between 0 and 31.
4971 - ``J``: An immediate integer between 0 and 64.
4972 - ``K``: An immediate signed 8-bit integer.
4973 - ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only)
4975 - ``M``: An immediate integer between 0 and 3.
4976 - ``N``: An immediate unsigned 8-bit integer.
4977 - ``O``: An immediate integer between 0 and 127.
4978 - ``e``: An immediate 32-bit signed integer.
4979 - ``Z``: An immediate 32-bit unsigned integer.
4980 - ``o``, ``v``: Treated the same as ``m``, at the moment.
4981 - ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
4982 ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d``
4983 registers, and on X86-64, it is all of the integer registers.
4984 - ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
4985 ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers.
4986 - ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register.
4987 - ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has
4988 existed since i386, and can be accessed without the REX prefix.
4989 - ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register.
4990 - ``y``: A 64-bit MMX register, if MMX is enabled.
4991 - ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector
4992 operand in a SSE register. If AVX is also enabled, can also be a 256-bit
4993 vector operand in an AVX register. If AVX-512 is also enabled, can also be a
4994 512-bit vector operand in an AVX512 register, Otherwise, an error.
4995 - ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error.
4996 - ``A``: Special case: allocates EAX first, then EDX, for a single operand (in
4997 32-bit mode, a 64-bit integer operand will get split into two registers). It
4998 is not recommended to use this constraint, as in 64-bit mode, the 64-bit
4999 operand will get allocated only to RAX -- if two 32-bit operands are needed,
5000 you're better off splitting it yourself, before passing it to the asm
5005 - ``r``: A 32-bit integer register.
5008 .. _inline-asm-modifiers:
5010 Asm template argument modifiers
5011 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5013 In the asm template string, modifiers can be used on the operand reference, like
5016 The modifiers are, in general, expected to behave the same way they do in
5017 GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
5018 inline asm code which was supported by GCC. A mismatch in behavior between LLVM
5019 and GCC likely indicates a bug in LLVM.
5023 - ``c``: Print an immediate integer constant unadorned, without
5024 the target-specific immediate punctuation (e.g. no ``$`` prefix).
5025 - ``n``: Negate and print immediate integer constant unadorned, without the
5026 target-specific immediate punctuation (e.g. no ``$`` prefix).
5027 - ``l``: Print as an unadorned label, without the target-specific label
5028 punctuation (e.g. no ``$`` prefix).
5032 - ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g.,
5033 instead of ``x30``, print ``w30``.
5034 - ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow).
5035 - ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a
5036 ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of
5045 - ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a
5049 - ``y``: Print a VFP single-precision register as an indexed double (e.g. print
5050 as ``d4[1]`` instead of ``s9``)
5051 - ``B``: Bitwise invert and print an immediate integer constant without ``#``
5053 - ``L``: Print the low 16-bits of an immediate integer constant.
5054 - ``M``: Print as a register set suitable for ldm/stm. Also prints *all*
5055 register operands subsequent to the specified one (!), so use carefully.
5056 - ``Q``: Print the low-order register of a register-pair, or the low-order
5057 register of a two-register operand.
5058 - ``R``: Print the high-order register of a register-pair, or the high-order
5059 register of a two-register operand.
5060 - ``H``: Print the second register of a register-pair. (On a big-endian system,
5061 ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent
5064 .. FIXME: H doesn't currently support printing the second register
5065 of a two-register operand.
5067 - ``e``: Print the low doubleword register of a NEON quad register.
5068 - ``f``: Print the high doubleword register of a NEON quad register.
5069 - ``m``: Print the base register of a memory operand without the ``[`` and ``]``
5074 - ``L``: Print the second register of a two-register operand. Requires that it
5075 has been allocated consecutively to the first.
5077 .. FIXME: why is it restricted to consecutive ones? And there's
5078 nothing that ensures that happens, is there?
5080 - ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
5081 nothing. Used to print 'addi' vs 'add' instructions.
5085 No additional modifiers.
5089 - ``X``: Print an immediate integer as hexadecimal
5090 - ``x``: Print the low 16 bits of an immediate integer as hexadecimal.
5091 - ``d``: Print an immediate integer as decimal.
5092 - ``m``: Subtract one and print an immediate integer as decimal.
5093 - ``z``: Print $0 if an immediate zero, otherwise print normally.
5094 - ``L``: Print the low-order register of a two-register operand, or prints the
5095 address of the low-order word of a double-word memory operand.
5097 .. FIXME: L seems to be missing memory operand support.
5099 - ``M``: Print the high-order register of a two-register operand, or prints the
5100 address of the high-order word of a double-word memory operand.
5102 .. FIXME: M seems to be missing memory operand support.
5104 - ``D``: Print the second register of a two-register operand, or prints the
5105 second word of a double-word memory operand. (On a big-endian system, ``D`` is
5106 equivalent to ``L``, and on little-endian system, ``D`` is equivalent to
5108 - ``w``: No effect. Provided for compatibility with GCC which requires this
5109 modifier in order to print MSA registers (``W0-W31``) with the ``f``
5118 - ``L``: Print the second register of a two-register operand. Requires that it
5119 has been allocated consecutively to the first.
5121 .. FIXME: why is it restricted to consecutive ones? And there's
5122 nothing that ensures that happens, is there?
5124 - ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
5125 nothing. Used to print 'addi' vs 'add' instructions.
5126 - ``y``: For a memory operand, prints formatter for a two-register X-form
5127 instruction. (Currently always prints ``r0,OPERAND``).
5128 - ``U``: Prints 'u' if the memory operand is an update form, and nothing
5129 otherwise. (NOTE: LLVM does not support update form, so this will currently
5130 always print nothing)
5131 - ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does
5132 not support indexed form, so this will currently always print nothing)
5136 - ``i``: Print the letter 'i' if the operand is not a register, otherwise print
5137 nothing. Used to print 'addi' vs 'add' instructions, etc.
5138 - ``z``: Print the register ``zero`` if an immediate zero, otherwise print
5147 SystemZ implements only ``n``, and does *not* support any of the other
5148 target-independent modifiers.
5152 - ``c``: Print an unadorned integer or symbol name. (The latter is
5153 target-specific behavior for this typically target-independent modifier).
5154 - ``A``: Print a register name with a '``*``' before it.
5155 - ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory
5157 - ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a
5159 - ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory
5161 - ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory
5163 - ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are
5164 available, otherwise the 32-bit register name; do nothing on a memory operand.
5165 - ``n``: Negate and print an unadorned integer, or, for operands other than an
5166 immediate integer (e.g. a relocatable symbol expression), print a '-' before
5167 the operand. (The behavior for relocatable symbol expressions is a
5168 target-specific behavior for this typically target-independent modifier)
5169 - ``H``: Print a memory reference with additional offset +8.
5170 - ``P``: Print a memory reference used as the argument of a call instruction or
5171 used with explicit base reg and index reg as its offset. So it can not use
5172 additional regs to present the memory reference. (E.g. omit ``(rip)``, even
5173 though it's PC-relative.)
5177 No additional modifiers.
5183 The call instructions that wrap inline asm nodes may have a
5184 "``!srcloc``" MDNode attached to it that contains a list of constant
5185 integers. If present, the code generator will use the integer as the
5186 location cookie value when report errors through the ``LLVMContext``
5187 error reporting mechanisms. This allows a front-end to correlate backend
5188 errors that occur with inline asm back to the source code that produced
5191 .. code-block:: llvm
5193 call void asm sideeffect "something bad", ""(), !srcloc !42
5195 !42 = !{ i32 1234567 }
5197 It is up to the front-end to make sense of the magic numbers it places
5198 in the IR. If the MDNode contains multiple constants, the code generator
5199 will use the one that corresponds to the line of the asm that the error
5207 LLVM IR allows metadata to be attached to instructions and global objects in the
5208 program that can convey extra information about the code to the optimizers and
5209 code generator. One example application of metadata is source-level
5210 debug information. There are two metadata primitives: strings and nodes.
5212 Metadata does not have a type, and is not a value. If referenced from a
5213 ``call`` instruction, it uses the ``metadata`` type.
5215 All metadata are identified in syntax by an exclamation point ('``!``').
5217 .. _metadata-string:
5219 Metadata Nodes and Metadata Strings
5220 -----------------------------------
5222 A metadata string is a string surrounded by double quotes. It can
5223 contain any character by escaping non-printable characters with
5224 "``\xx``" where "``xx``" is the two digit hex code. For example:
5227 Metadata nodes are represented with notation similar to structure
5228 constants (a comma separated list of elements, surrounded by braces and
5229 preceded by an exclamation point). Metadata nodes can have any values as
5230 their operand. For example:
5232 .. code-block:: llvm
5234 !{ !"test\00", i32 10}
5236 Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
5238 .. code-block:: text
5240 !0 = distinct !{!"test\00", i32 10}
5242 ``distinct`` nodes are useful when nodes shouldn't be merged based on their
5243 content. They can also occur when transformations cause uniquing collisions
5244 when metadata operands change.
5246 A :ref:`named metadata <namedmetadatastructure>` is a collection of
5247 metadata nodes, which can be looked up in the module symbol table. For
5250 .. code-block:: llvm
5254 Metadata can be used as function arguments. Here the ``llvm.dbg.value``
5255 intrinsic is using three metadata arguments:
5257 .. code-block:: llvm
5259 call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26)
5261 Metadata can be attached to an instruction. Here metadata ``!21`` is attached
5262 to the ``add`` instruction using the ``!dbg`` identifier:
5264 .. code-block:: llvm
5266 %indvar.next = add i64 %indvar, 1, !dbg !21
5268 Instructions may not have multiple metadata attachments with the same
5271 Metadata can also be attached to a function or a global variable. Here metadata
5272 ``!22`` is attached to the ``f1`` and ``f2`` functions, and the globals ``g1``
5273 and ``g2`` using the ``!dbg`` identifier:
5275 .. code-block:: llvm
5277 declare !dbg !22 void @f1()
5278 define void @f2() !dbg !22 {
5282 @g1 = global i32 0, !dbg !22
5283 @g2 = external global i32, !dbg !22
5285 Unlike instructions, global objects (functions and global variables) may have
5286 multiple metadata attachments with the same identifier.
5288 A transformation is required to drop any metadata attachment that it does not
5289 know or know it can't preserve. Currently there is an exception for metadata
5290 attachment to globals for ``!func_sanitize``, ``!type`` and ``!absolute_symbol`` which can't be
5291 unconditionally dropped unless the global is itself deleted.
5293 Metadata attached to a module using named metadata may not be dropped, with
5294 the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``).
5296 More information about specific metadata nodes recognized by the
5297 optimizers and code generator is found below.
5299 .. _specialized-metadata:
5301 Specialized Metadata Nodes
5302 ^^^^^^^^^^^^^^^^^^^^^^^^^^
5304 Specialized metadata nodes are custom data structures in metadata (as opposed
5305 to generic tuples). Their fields are labelled, and can be specified in any
5308 These aren't inherently debug info centric, but currently all the specialized
5309 metadata nodes are related to debug info.
5316 ``DICompileUnit`` nodes represent a compile unit. The ``enums:``,
5317 ``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples
5318 containing the debug info to be emitted along with the compile unit, regardless
5319 of code optimizations (some nodes are only emitted if there are references to
5320 them from instructions). The ``debugInfoForProfiling:`` field is a boolean
5321 indicating whether or not line-table discriminators are updated to provide
5322 more-accurate debug info for profiling results.
5324 .. code-block:: text
5326 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
5327 isOptimized: true, flags: "-O2", runtimeVersion: 2,
5328 splitDebugFilename: "abc.debug", emissionKind: FullDebug,
5329 enums: !2, retainedTypes: !3, globals: !4, imports: !5,
5330 macros: !6, dwoId: 0x0abcd)
5332 Compile unit descriptors provide the root scope for objects declared in a
5333 specific compilation unit. File descriptors are defined using this scope. These
5334 descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep
5335 track of global variables, type information, and imported entities (declarations
5343 ``DIFile`` nodes represent files. The ``filename:`` can include slashes.
5345 .. code-block:: none
5347 !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir",
5348 checksumkind: CSK_MD5,
5349 checksum: "000102030405060708090a0b0c0d0e0f")
5351 Files are sometimes used in ``scope:`` fields, and are the only valid target
5352 for ``file:`` fields.
5353 Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1, CSK_SHA256}
5360 ``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
5361 ``float``. ``tag:`` defaults to ``DW_TAG_base_type``.
5363 .. code-block:: text
5365 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
5366 encoding: DW_ATE_unsigned_char)
5367 !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
5369 The ``encoding:`` describes the details of the type. Usually it's one of the
5372 .. code-block:: text
5378 DW_ATE_signed_char = 6
5380 DW_ATE_unsigned_char = 8
5382 .. _DISubroutineType:
5387 ``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field
5388 refers to a tuple; the first operand is the return type, while the rest are the
5389 types of the formal arguments in order. If the first operand is ``null``, that
5390 represents a function with no return value (such as ``void foo() {}`` in C++).
5392 .. code-block:: text
5394 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
5395 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
5396 !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char)
5403 ``DIDerivedType`` nodes represent types derived from other types, such as
5406 .. code-block:: text
5408 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
5409 encoding: DW_ATE_unsigned_char)
5410 !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
5413 The following ``tag:`` values are valid:
5415 .. code-block:: text
5418 DW_TAG_pointer_type = 15
5419 DW_TAG_reference_type = 16
5421 DW_TAG_inheritance = 28
5422 DW_TAG_ptr_to_member_type = 31
5423 DW_TAG_const_type = 38
5425 DW_TAG_volatile_type = 53
5426 DW_TAG_restrict_type = 55
5427 DW_TAG_atomic_type = 71
5428 DW_TAG_immutable_type = 75
5430 .. _DIDerivedTypeMember:
5432 ``DW_TAG_member`` is used to define a member of a :ref:`composite type
5433 <DICompositeType>`. The type of the member is the ``baseType:``. The
5434 ``offset:`` is the member's bit offset. If the composite type has an ODR
5435 ``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is
5436 uniqued based only on its ``name:`` and ``scope:``.
5438 ``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:``
5439 field of :ref:`composite types <DICompositeType>` to describe parents and
5442 ``DW_TAG_typedef`` is used to provide a name for the ``baseType:``.
5444 ``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``,
5445 ``DW_TAG_volatile_type``, ``DW_TAG_restrict_type``, ``DW_TAG_atomic_type`` and
5446 ``DW_TAG_immutable_type`` are used to qualify the ``baseType:``.
5448 Note that the ``void *`` type is expressed as a type derived from NULL.
5450 .. _DICompositeType:
5455 ``DICompositeType`` nodes represent types composed of other types, like
5456 structures and unions. ``elements:`` points to a tuple of the composed types.
5458 If the source language supports ODR, the ``identifier:`` field gives the unique
5459 identifier used for type merging between modules. When specified,
5460 :ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member
5461 derived types <DIDerivedTypeMember>` that reference the ODR-type in their
5462 ``scope:`` change uniquing rules.
5464 For a given ``identifier:``, there should only be a single composite type that
5465 does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules
5466 together will unique such definitions at parse time via the ``identifier:``
5467 field, even if the nodes are ``distinct``.
5469 .. code-block:: text
5471 !0 = !DIEnumerator(name: "SixKind", value: 7)
5472 !1 = !DIEnumerator(name: "SevenKind", value: 7)
5473 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
5474 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
5475 line: 2, size: 32, align: 32, identifier: "_M4Enum",
5476 elements: !{!0, !1, !2})
5478 The following ``tag:`` values are valid:
5480 .. code-block:: text
5482 DW_TAG_array_type = 1
5483 DW_TAG_class_type = 2
5484 DW_TAG_enumeration_type = 4
5485 DW_TAG_structure_type = 19
5486 DW_TAG_union_type = 23
5488 For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange
5489 descriptors <DISubrange>`, each representing the range of subscripts at that
5490 level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an
5491 array type is a native packed vector. The optional ``dataLocation`` is a
5492 DIExpression that describes how to get from an object's address to the actual
5493 raw data, if they aren't equivalent. This is only supported for array types,
5494 particularly to describe Fortran arrays, which have an array descriptor in
5495 addition to the array data. Alternatively it can also be DIVariable which
5496 has the address of the actual raw data. The Fortran language supports pointer
5497 arrays which can be attached to actual arrays, this attachment between pointer
5498 and pointee is called association. The optional ``associated`` is a
5499 DIExpression that describes whether the pointer array is currently associated.
5500 The optional ``allocated`` is a DIExpression that describes whether the
5501 allocatable array is currently allocated. The optional ``rank`` is a
5502 DIExpression that describes the rank (number of dimensions) of fortran assumed
5503 rank array (rank is known at runtime).
5505 For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
5506 descriptors <DIEnumerator>`, each representing the definition of an enumeration
5507 value for the set. All enumeration type descriptors are collected in the
5508 ``enums:`` field of the :ref:`compile unit <DICompileUnit>`.
5510 For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and
5511 ``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types
5512 <DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or
5513 ``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with
5514 ``isDefinition: false``.
5521 ``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
5522 :ref:`DICompositeType`.
5524 - ``count: -1`` indicates an empty array.
5525 - ``count: !10`` describes the count with a :ref:`DILocalVariable`.
5526 - ``count: !12`` describes the count with a :ref:`DIGlobalVariable`.
5528 .. code-block:: text
5530 !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0
5531 !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1
5532 !2 = !DISubrange(count: -1) ; empty array.
5534 ; Scopes used in rest of example
5535 !6 = !DIFile(filename: "vla.c", directory: "/path/to/file")
5536 !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6)
5537 !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5)
5539 ; Use of local variable as count value
5540 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
5541 !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9)
5542 !11 = !DISubrange(count: !10, lowerBound: 0)
5544 ; Use of global variable as count value
5545 !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9)
5546 !13 = !DISubrange(count: !12, lowerBound: 0)
5553 ``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
5554 variants of :ref:`DICompositeType`.
5556 .. code-block:: text
5558 !0 = !DIEnumerator(name: "SixKind", value: 7)
5559 !1 = !DIEnumerator(name: "SevenKind", value: 7)
5560 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
5562 DITemplateTypeParameter
5563 """""""""""""""""""""""
5565 ``DITemplateTypeParameter`` nodes represent type parameters to generic source
5566 language constructs. They are used (optionally) in :ref:`DICompositeType` and
5567 :ref:`DISubprogram` ``templateParams:`` fields.
5569 .. code-block:: text
5571 !0 = !DITemplateTypeParameter(name: "Ty", type: !1)
5573 DITemplateValueParameter
5574 """"""""""""""""""""""""
5576 ``DITemplateValueParameter`` nodes represent value parameters to generic source
5577 language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
5578 but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
5579 ``DW_TAG_GNU_template_param_pack``. They are used (optionally) in
5580 :ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields.
5582 .. code-block:: text
5584 !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7)
5589 ``DINamespace`` nodes represent namespaces in the source language.
5591 .. code-block:: text
5593 !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
5595 .. _DIGlobalVariable:
5600 ``DIGlobalVariable`` nodes represent global variables in the source language.
5602 .. code-block:: text
5604 @foo = global i32, !dbg !0
5605 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
5606 !1 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !2,
5607 file: !3, line: 7, type: !4, isLocal: true,
5608 isDefinition: false, declaration: !5)
5611 DIGlobalVariableExpression
5612 """"""""""""""""""""""""""
5614 ``DIGlobalVariableExpression`` nodes tie a :ref:`DIGlobalVariable` together
5615 with a :ref:`DIExpression`.
5617 .. code-block:: text
5619 @lower = global i32, !dbg !0
5620 @upper = global i32, !dbg !1
5621 !0 = !DIGlobalVariableExpression(
5623 expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32)
5625 !1 = !DIGlobalVariableExpression(
5627 expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32)
5629 !2 = !DIGlobalVariable(name: "split64", linkageName: "split64", scope: !3,
5630 file: !4, line: 8, type: !5, declaration: !6)
5632 All global variable expressions should be referenced by the `globals:` field of
5633 a :ref:`compile unit <DICompileUnit>`.
5640 ``DISubprogram`` nodes represent functions from the source language. A distinct
5641 ``DISubprogram`` may be attached to a function definition using ``!dbg``
5642 metadata. A unique ``DISubprogram`` may be attached to a function declaration
5643 used for call site debug info. The ``retainedNodes:`` field is a list of
5644 :ref:`variables <DILocalVariable>` and :ref:`labels <DILabel>` that must be
5645 retained, even if their IR counterparts are optimized out of the IR. The
5646 ``type:`` field must point at an :ref:`DISubroutineType`.
5648 .. _DISubprogramDeclaration:
5650 When ``isDefinition: false``, subprograms describe a declaration in the type
5651 tree as opposed to a definition of a function. If the scope is a composite
5652 type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``,
5653 then the subprogram declaration is uniqued based only on its ``linkageName:``
5656 .. code-block:: text
5658 define void @_Z3foov() !dbg !0 {
5662 !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
5663 file: !2, line: 7, type: !3, isLocal: true,
5664 isDefinition: true, scopeLine: 8,
5666 virtuality: DW_VIRTUALITY_pure_virtual,
5667 virtualIndex: 10, flags: DIFlagPrototyped,
5668 isOptimized: true, unit: !5, templateParams: !6,
5669 declaration: !7, retainedNodes: !8,
5677 ``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
5678 <DISubprogram>`. The line number and column numbers are used to distinguish
5679 two lexical blocks at same depth. They are valid targets for ``scope:``
5682 .. code-block:: text
5684 !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
5686 Usually lexical blocks are ``distinct`` to prevent node merging based on
5689 .. _DILexicalBlockFile:
5694 ``DILexicalBlockFile`` nodes are used to discriminate between sections of a
5695 :ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to
5696 indicate textual inclusion, or the ``discriminator:`` field can be used to
5697 discriminate between control flow within a single block in the source language.
5699 .. code-block:: text
5701 !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35)
5702 !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0)
5703 !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1)
5710 ``DILocation`` nodes represent source debug locations. The ``scope:`` field is
5711 mandatory, and points at an :ref:`DILexicalBlockFile`, an
5712 :ref:`DILexicalBlock`, or an :ref:`DISubprogram`.
5714 .. code-block:: text
5716 !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
5718 .. _DILocalVariable:
5723 ``DILocalVariable`` nodes represent local variables in the source language. If
5724 the ``arg:`` field is set to non-zero, then this variable is a subprogram
5725 parameter, and it will be included in the ``retainedNodes:`` field of its
5726 :ref:`DISubprogram`.
5728 .. code-block:: text
5730 !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7,
5731 type: !3, flags: DIFlagArtificial)
5732 !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7,
5734 !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3)
5741 ``DIExpression`` nodes represent expressions that are inspired by the DWARF
5742 expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>`
5743 (such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the
5744 referenced LLVM variable relates to the source language variable. Debug
5745 intrinsics are interpreted left-to-right: start by pushing the value/address
5746 operand of the intrinsic onto a stack, then repeatedly push and evaluate
5747 opcodes from the DIExpression until the final variable description is produced.
5749 The current supported opcode vocabulary is limited:
5751 - ``DW_OP_deref`` dereferences the top of the expression stack.
5752 - ``DW_OP_plus`` pops the last two entries from the expression stack, adds
5753 them together and appends the result to the expression stack.
5754 - ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts
5755 the last entry from the second last entry and appends the result to the
5757 - ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression.
5758 - ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8``
5759 here, respectively) of the variable fragment from the working expression. Note
5760 that contrary to DW_OP_bit_piece, the offset is describing the location
5761 within the described source variable.
5762 - ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding
5763 (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the
5764 expression stack is to be converted. Maps into a ``DW_OP_convert`` operation
5765 that references a base type constructed from the supplied values.
5766 - ``DW_OP_LLVM_tag_offset, tag_offset`` specifies that a memory tag should be
5767 optionally applied to the pointer. The memory tag is derived from the
5768 given tag offset in an implementation-defined manner.
5769 - ``DW_OP_swap`` swaps top two stack entries.
5770 - ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top
5771 of the stack is treated as an address. The second stack entry is treated as an
5772 address space identifier.
5773 - ``DW_OP_stack_value`` marks a constant value.
5774 - ``DW_OP_LLVM_entry_value, N`` may only appear in MIR and at the
5775 beginning of a ``DIExpression``. In DWARF a ``DBG_VALUE``
5776 instruction binding a ``DIExpression(DW_OP_LLVM_entry_value`` to a
5777 register is lowered to a ``DW_OP_entry_value [reg]``, pushing the
5778 value the register had upon function entry onto the stack. The next
5779 ``(N - 1)`` operations will be part of the ``DW_OP_entry_value``
5780 block argument. For example, ``!DIExpression(DW_OP_LLVM_entry_value,
5781 1, DW_OP_plus_uconst, 123, DW_OP_stack_value)`` specifies an
5782 expression where the entry value of the debug value instruction's
5783 value/address operand is pushed to the stack, and is added
5784 with 123. Due to framework limitations ``N`` can currently only
5787 The operation is introduced by the ``LiveDebugValues`` pass, which
5788 applies it only to function parameters that are unmodified
5789 throughout the function. Support is limited to simple register
5790 location descriptions, or as indirect locations (e.g., when a struct
5791 is passed-by-value to a callee via a pointer to a temporary copy
5792 made in the caller). The entry value op is also introduced by the
5793 ``AsmPrinter`` pass when a call site parameter value
5794 (``DW_AT_call_site_parameter_value``) is represented as entry value
5796 - ``DW_OP_LLVM_arg, N`` is used in debug intrinsics that refer to more than one
5797 value, such as one that calculates the sum of two registers. This is always
5798 used in combination with an ordered list of values, such that
5799 ``DW_OP_LLVM_arg, N`` refers to the ``N``th element in that list. For
5800 example, ``!DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus,
5801 DW_OP_stack_value)`` used with the list ``(%reg1, %reg2)`` would evaluate to
5802 ``%reg1 - reg2``. This list of values should be provided by the containing
5803 intrinsic/instruction.
5804 - ``DW_OP_breg`` (or ``DW_OP_bregx``) represents a content on the provided
5805 signed offset of the specified register. The opcode is only generated by the
5806 ``AsmPrinter`` pass to describe call site parameter value which requires an
5807 expression over two registers.
5808 - ``DW_OP_push_object_address`` pushes the address of the object which can then
5809 serve as a descriptor in subsequent calculation. This opcode can be used to
5810 calculate bounds of fortran allocatable array which has array descriptors.
5811 - ``DW_OP_over`` duplicates the entry currently second in the stack at the top
5812 of the stack. This opcode can be used to calculate bounds of fortran assumed
5813 rank array which has rank known at run time and current dimension number is
5814 implicitly first element of the stack.
5815 - ``DW_OP_LLVM_implicit_pointer`` It specifies the dereferenced value. It can
5816 be used to represent pointer variables which are optimized out but the value
5817 it points to is known. This operator is required as it is different than DWARF
5818 operator DW_OP_implicit_pointer in representation and specification (number
5819 and types of operands) and later can not be used as multiple level.
5821 .. code-block:: text
5825 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !20)
5826 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5,
5828 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
5829 !19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
5830 !20 = !DIExpression(DW_OP_LLVM_implicit_pointer))
5834 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !21)
5835 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5,
5837 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
5838 !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
5839 !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
5840 !21 = !DIExpression(DW_OP_LLVM_implicit_pointer,
5841 DW_OP_LLVM_implicit_pointer))
5843 DWARF specifies three kinds of simple location descriptions: Register, memory,
5844 and implicit location descriptions. Note that a location description is
5845 defined over certain ranges of a program, i.e the location of a variable may
5846 change over the course of the program. Register and memory location
5847 descriptions describe the *concrete location* of a source variable (in the
5848 sense that a debugger might modify its value), whereas *implicit locations*
5849 describe merely the actual *value* of a source variable which might not exist
5850 in registers or in memory (see ``DW_OP_stack_value``).
5852 A ``llvm.dbg.addr`` or ``llvm.dbg.declare`` intrinsic describes an indirect
5853 value (the address) of a source variable. The first operand of the intrinsic
5854 must be an address of some kind. A DIExpression attached to the intrinsic
5855 refines this address to produce a concrete location for the source variable.
5857 A ``llvm.dbg.value`` intrinsic describes the direct value of a source variable.
5858 The first operand of the intrinsic may be a direct or indirect value. A
5859 DIExpression attached to the intrinsic refines the first operand to produce a
5860 direct value. For example, if the first operand is an indirect value, it may be
5861 necessary to insert ``DW_OP_deref`` into the DIExpression in order to produce a
5862 valid debug intrinsic.
5866 A DIExpression is interpreted in the same way regardless of which kind of
5867 debug intrinsic it's attached to.
5869 .. code-block:: text
5871 !0 = !DIExpression(DW_OP_deref)
5872 !1 = !DIExpression(DW_OP_plus_uconst, 3)
5873 !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus)
5874 !2 = !DIExpression(DW_OP_bit_piece, 3, 7)
5875 !3 = !DIExpression(DW_OP_deref, DW_OP_constu, 3, DW_OP_plus, DW_OP_LLVM_fragment, 3, 7)
5876 !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef)
5877 !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value)
5882 ``DIArgList`` nodes hold a list of constant or SSA value references. These are
5883 used in :ref:`debug intrinsics<dbg_intrinsics>` (currently only in
5884 ``llvm.dbg.value``) in combination with a ``DIExpression`` that uses the
5885 ``DW_OP_LLVM_arg`` operator. Because a DIArgList may refer to local values
5886 within a function, it must only be used as a function argument, must always be
5887 inlined, and cannot appear in named metadata.
5889 .. code-block:: text
5891 llvm.dbg.value(metadata !DIArgList(i32 %a, i32 %b),
5893 metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus))
5898 These flags encode various properties of DINodes.
5900 The `ExportSymbols` flag marks a class, struct or union whose members
5901 may be referenced as if they were defined in the containing class or
5902 union. This flag is used to decide whether the DW_AT_export_symbols can
5903 be used for the structure type.
5908 ``DIObjCProperty`` nodes represent Objective-C property nodes.
5910 .. code-block:: text
5912 !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
5913 getter: "getFoo", attributes: 7, type: !2)
5918 ``DIImportedEntity`` nodes represent entities (such as modules) imported into a
5919 compile unit. The ``elements`` field is a list of renamed entities (such as
5920 variables and subprograms) in the imported entity (such as module).
5922 .. code-block:: text
5924 !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
5925 entity: !1, line: 7, elements: !3)
5927 !4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "bar", scope: !0,
5928 entity: !5, line: 7)
5933 ``DIMacro`` nodes represent definition or undefinition of a macro identifiers.
5934 The ``name:`` field is the macro identifier, followed by macro parameters when
5935 defining a function-like macro, and the ``value`` field is the token-string
5936 used to expand the macro identifier.
5938 .. code-block:: text
5940 !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)",
5942 !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo")
5947 ``DIMacroFile`` nodes represent inclusion of source files.
5948 The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that
5949 appear in the included source file.
5951 .. code-block:: text
5953 !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2,
5961 ``DILabel`` nodes represent labels within a :ref:`DISubprogram`. All fields of
5962 a ``DILabel`` are mandatory. The ``scope:`` field must be one of either a
5963 :ref:`DILexicalBlockFile`, a :ref:`DILexicalBlock`, or a :ref:`DISubprogram`.
5964 The ``name:`` field is the label identifier. The ``file:`` field is the
5965 :ref:`DIFile` the label is present in. The ``line:`` field is the source line
5966 within the file where the label is declared.
5968 .. code-block:: text
5970 !2 = !DILabel(scope: !0, name: "foo", file: !1, line: 7)
5975 In LLVM IR, memory does not have types, so LLVM's own type system is not
5976 suitable for doing type based alias analysis (TBAA). Instead, metadata is
5977 added to the IR to describe a type system of a higher level language. This
5978 can be used to implement C/C++ strict type aliasing rules, but it can also
5979 be used to implement custom alias analysis behavior for other languages.
5981 This description of LLVM's TBAA system is broken into two parts:
5982 :ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and
5983 :ref:`Representation<tbaa_node_representation>` talks about the metadata
5984 encoding of various entities.
5986 It is always possible to trace any TBAA node to a "root" TBAA node (details
5987 in the :ref:`Representation<tbaa_node_representation>` section). TBAA
5988 nodes with different roots have an unknown aliasing relationship, and LLVM
5989 conservatively infers ``MayAlias`` between them. The rules mentioned in
5990 this section only pertain to TBAA nodes living under the same root.
5992 .. _tbaa_node_semantics:
5997 The TBAA metadata system, referred to as "struct path TBAA" (not to be
5998 confused with ``tbaa.struct``), consists of the following high level
5999 concepts: *Type Descriptors*, further subdivided into scalar type
6000 descriptors and struct type descriptors; and *Access Tags*.
6002 **Type descriptors** describe the type system of the higher level language
6003 being compiled. **Scalar type descriptors** describe types that do not
6004 contain other types. Each scalar type has a parent type, which must also
6005 be a scalar type or the TBAA root. Via this parent relation, scalar types
6006 within a TBAA root form a tree. **Struct type descriptors** denote types
6007 that contain a sequence of other type descriptors, at known offsets. These
6008 contained type descriptors can either be struct type descriptors themselves
6009 or scalar type descriptors.
6011 **Access tags** are metadata nodes attached to load and store instructions.
6012 Access tags use type descriptors to describe the *location* being accessed
6013 in terms of the type system of the higher level language. Access tags are
6014 tuples consisting of a base type, an access type and an offset. The base
6015 type is a scalar type descriptor or a struct type descriptor, the access
6016 type is a scalar type descriptor, and the offset is a constant integer.
6018 The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two
6021 * If ``BaseTy`` is a struct type, the tag describes a memory access (load
6022 or store) of a value of type ``AccessTy`` contained in the struct type
6023 ``BaseTy`` at offset ``Offset``.
6025 * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and
6026 ``AccessTy`` must be the same; and the access tag describes a scalar
6027 access with scalar type ``AccessTy``.
6029 We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)``
6032 * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is
6033 ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as
6034 described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is
6035 undefined if ``Offset`` is non-zero.
6037 * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)``
6038 is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in
6039 ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted
6040 to be relative within that inner type.
6042 A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)``
6043 aliases a memory access with an access tag ``(BaseTy2, AccessTy2,
6044 Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2,
6045 Offset2)`` via the ``Parent`` relation or vice versa.
6047 As a concrete example, the type descriptor graph for the following program
6053 float f; // offset 4
6057 float f; // offset 0
6058 double d; // offset 4
6059 struct Inner inner_a; // offset 12
6062 void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) {
6063 outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0)
6064 outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12)
6065 outer->inner_a.f = 0.0; // tag2: (OuterStructTy, FloatScalarTy, 16)
6066 *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0)
6069 is (note that in C and C++, ``char`` can be used to access any arbitrary
6072 .. code-block:: text
6075 CharScalarTy = ("char", Root, 0)
6076 FloatScalarTy = ("float", CharScalarTy, 0)
6077 DoubleScalarTy = ("double", CharScalarTy, 0)
6078 IntScalarTy = ("int", CharScalarTy, 0)
6079 InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)}
6080 OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4),
6081 (InnerStructTy, 12)}
6084 with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy,
6085 0)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and
6086 ``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``.
6088 .. _tbaa_node_representation:
6093 The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or
6094 with exactly one ``MDString`` operand.
6096 Scalar type descriptors are represented as an ``MDNode`` s with two
6097 operands. The first operand is an ``MDString`` denoting the name of the
6098 struct type. LLVM does not assign meaning to the value of this operand, it
6099 only cares about it being an ``MDString``. The second operand is an
6100 ``MDNode`` which points to the parent for said scalar type descriptor,
6101 which is either another scalar type descriptor or the TBAA root. Scalar
6102 type descriptors can have an optional third argument, but that must be the
6103 constant integer zero.
6105 Struct type descriptors are represented as ``MDNode`` s with an odd number
6106 of operands greater than 1. The first operand is an ``MDString`` denoting
6107 the name of the struct type. Like in scalar type descriptors the actual
6108 value of this name operand is irrelevant to LLVM. After the name operand,
6109 the struct type descriptors have a sequence of alternating ``MDNode`` and
6110 ``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand,
6111 an ``MDNode``, denotes a contained field, and the 2N th operand, a
6112 ``ConstantInt``, is the offset of the said contained field. The offsets
6113 must be in non-decreasing order.
6115 Access tags are represented as ``MDNode`` s with either 3 or 4 operands.
6116 The first operand is an ``MDNode`` pointing to the node representing the
6117 base type. The second operand is an ``MDNode`` pointing to the node
6118 representing the access type. The third operand is a ``ConstantInt`` that
6119 states the offset of the access. If a fourth field is present, it must be
6120 a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states
6121 that the location being accessed is "constant" (meaning
6122 ``pointsToConstantMemory`` should return true; see `other useful
6123 AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of
6124 the access type and the base type of an access tag must be the same, and
6125 that is the TBAA root of the access tag.
6127 '``tbaa.struct``' Metadata
6128 ^^^^^^^^^^^^^^^^^^^^^^^^^^
6130 The :ref:`llvm.memcpy <int_memcpy>` is often used to implement
6131 aggregate assignment operations in C and similar languages, however it
6132 is defined to copy a contiguous region of memory, which is more than
6133 strictly necessary for aggregate types which contain holes due to
6134 padding. Also, it doesn't contain any TBAA information about the fields
6137 ``!tbaa.struct`` metadata can describe which memory subregions in a
6138 memcpy are padding and what the TBAA tags of the struct are.
6140 The current metadata format is very simple. ``!tbaa.struct`` metadata
6141 nodes are a list of operands which are in conceptual groups of three.
6142 For each group of three, the first operand gives the byte offset of a
6143 field in bytes, the second gives its size in bytes, and the third gives
6146 .. code-block:: llvm
6148 !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 }
6150 This describes a struct with two fields. The first is at offset 0 bytes
6151 with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes
6152 and has size 4 bytes and has tbaa tag !2.
6154 Note that the fields need not be contiguous. In this example, there is a
6155 4 byte gap between the two fields. This gap represents padding which
6156 does not carry useful data and need not be preserved.
6158 '``noalias``' and '``alias.scope``' Metadata
6159 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6161 ``noalias`` and ``alias.scope`` metadata provide the ability to specify generic
6162 noalias memory-access sets. This means that some collection of memory access
6163 instructions (loads, stores, memory-accessing calls, etc.) that carry
6164 ``noalias`` metadata can specifically be specified not to alias with some other
6165 collection of memory access instructions that carry ``alias.scope`` metadata.
6166 Each type of metadata specifies a list of scopes where each scope has an id and
6169 When evaluating an aliasing query, if for some domain, the set
6170 of scopes with that domain in one instruction's ``alias.scope`` list is a
6171 subset of (or equal to) the set of scopes for that domain in another
6172 instruction's ``noalias`` list, then the two memory accesses are assumed not to
6175 Because scopes in one domain don't affect scopes in other domains, separate
6176 domains can be used to compose multiple independent noalias sets. This is
6177 used for example during inlining. As the noalias function parameters are
6178 turned into noalias scope metadata, a new domain is used every time the
6179 function is inlined.
6181 The metadata identifying each domain is itself a list containing one or two
6182 entries. The first entry is the name of the domain. Note that if the name is a
6183 string then it can be combined across functions and translation units. A
6184 self-reference can be used to create globally unique domain names. A
6185 descriptive string may optionally be provided as a second list entry.
6187 The metadata identifying each scope is also itself a list containing two or
6188 three entries. The first entry is the name of the scope. Note that if the name
6189 is a string then it can be combined across functions and translation units. A
6190 self-reference can be used to create globally unique scope names. A metadata
6191 reference to the scope's domain is the second entry. A descriptive string may
6192 optionally be provided as a third list entry.
6196 .. code-block:: llvm
6198 ; Two scope domains:
6202 ; Some scopes in these domains:
6208 !5 = !{!4} ; A list containing only scope !4
6212 ; These two instructions don't alias:
6213 %0 = load float, ptr %c, align 4, !alias.scope !5
6214 store float %0, ptr %arrayidx.i, align 4, !noalias !5
6216 ; These two instructions also don't alias (for domain !1, the set of scopes
6217 ; in the !alias.scope equals that in the !noalias list):
6218 %2 = load float, ptr %c, align 4, !alias.scope !5
6219 store float %2, ptr %arrayidx.i2, align 4, !noalias !6
6221 ; These two instructions may alias (for domain !0, the set of scopes in
6222 ; the !noalias list is not a superset of, or equal to, the scopes in the
6223 ; !alias.scope list):
6224 %2 = load float, ptr %c, align 4, !alias.scope !6
6225 store float %0, ptr %arrayidx.i, align 4, !noalias !7
6227 '``fpmath``' Metadata
6228 ^^^^^^^^^^^^^^^^^^^^^
6230 ``fpmath`` metadata may be attached to any instruction of floating-point
6231 type. It can be used to express the maximum acceptable error in the
6232 result of that instruction, in ULPs, thus potentially allowing the
6233 compiler to use a more efficient but less accurate method of computing
6234 it. ULP is defined as follows:
6236 If ``x`` is a real number that lies between two finite consecutive
6237 floating-point numbers ``a`` and ``b``, without being equal to one
6238 of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the
6239 distance between the two non-equal finite floating-point numbers
6240 nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``.
6242 The metadata node shall consist of a single positive float type number
6243 representing the maximum relative error, for example:
6245 .. code-block:: llvm
6247 !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
6251 '``range``' Metadata
6252 ^^^^^^^^^^^^^^^^^^^^
6254 ``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of
6255 integer types. It expresses the possible ranges the loaded value or the value
6256 returned by the called function at this call site is in. If the loaded or
6257 returned value is not in the specified range, the behavior is undefined. The
6258 ranges are represented with a flattened list of integers. The loaded value or
6259 the value returned is known to be in the union of the ranges defined by each
6260 consecutive pair. Each pair has the following properties:
6262 - The type must match the type loaded by the instruction.
6263 - The pair ``a,b`` represents the range ``[a,b)``.
6264 - Both ``a`` and ``b`` are constants.
6265 - The range is allowed to wrap.
6266 - The range should not represent the full or empty set. That is,
6269 In addition, the pairs must be in signed order of the lower bound and
6270 they must be non-contiguous.
6274 .. code-block:: llvm
6276 %a = load i8, ptr %x, align 1, !range !0 ; Can only be 0 or 1
6277 %b = load i8, ptr %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
6278 %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5
6279 %d = invoke i8 @bar() to label %cont
6280 unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5
6282 !0 = !{ i8 0, i8 2 }
6283 !1 = !{ i8 255, i8 2 }
6284 !2 = !{ i8 0, i8 2, i8 3, i8 6 }
6285 !3 = !{ i8 -2, i8 0, i8 3, i8 6 }
6287 '``absolute_symbol``' Metadata
6288 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6290 ``absolute_symbol`` metadata may be attached to a global variable
6291 declaration. It marks the declaration as a reference to an absolute symbol,
6292 which causes the backend to use absolute relocations for the symbol even
6293 in position independent code, and expresses the possible ranges that the
6294 global variable's *address* (not its value) is in, in the same format as
6295 ``range`` metadata, with the extension that the pair ``all-ones,all-ones``
6296 may be used to represent the full set.
6298 Example (assuming 64-bit pointers):
6300 .. code-block:: llvm
6302 @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256)
6303 @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64)
6306 !0 = !{ i64 0, i64 256 }
6307 !1 = !{ i64 -1, i64 -1 }
6309 '``callees``' Metadata
6310 ^^^^^^^^^^^^^^^^^^^^^^
6312 ``callees`` metadata may be attached to indirect call sites. If ``callees``
6313 metadata is attached to a call site, and any callee is not among the set of
6314 functions provided by the metadata, the behavior is undefined. The intent of
6315 this metadata is to facilitate optimizations such as indirect-call promotion.
6316 For example, in the code below, the call instruction may only target the
6317 ``add`` or ``sub`` functions:
6319 .. code-block:: llvm
6321 %result = call i64 %binop(i64 %x, i64 %y), !callees !0
6324 !0 = !{ptr @add, ptr @sub}
6326 '``callback``' Metadata
6327 ^^^^^^^^^^^^^^^^^^^^^^^
6329 ``callback`` metadata may be attached to a function declaration, or definition.
6330 (Call sites are excluded only due to the lack of a use case.) For ease of
6331 exposition, we'll refer to the function annotated w/ metadata as a broker
6332 function. The metadata describes how the arguments of a call to the broker are
6333 in turn passed to the callback function specified by the metadata. Thus, the
6334 ``callback`` metadata provides a partial description of a call site inside the
6335 broker function with regards to the arguments of a call to the broker. The only
6336 semantic restriction on the broker function itself is that it is not allowed to
6337 inspect or modify arguments referenced in the ``callback`` metadata as
6338 pass-through to the callback function.
6340 The broker is not required to actually invoke the callback function at runtime.
6341 However, the assumptions about not inspecting or modifying arguments that would
6342 be passed to the specified callback function still hold, even if the callback
6343 function is not dynamically invoked. The broker is allowed to invoke the
6344 callback function more than once per invocation of the broker. The broker is
6345 also allowed to invoke (directly or indirectly) the function passed as a
6346 callback through another use. Finally, the broker is also allowed to relay the
6347 callback callee invocation to a different thread.
6349 The metadata is structured as follows: At the outer level, ``callback``
6350 metadata is a list of ``callback`` encodings. Each encoding starts with a
6351 constant ``i64`` which describes the argument position of the callback function
6352 in the call to the broker. The following elements, except the last, describe
6353 what arguments are passed to the callback function. Each element is again an
6354 ``i64`` constant identifying the argument of the broker that is passed through,
6355 or ``i64 -1`` to indicate an unknown or inspected argument. The order in which
6356 they are listed has to be the same in which they are passed to the callback
6357 callee. The last element of the encoding is a boolean which specifies how
6358 variadic arguments of the broker are handled. If it is true, all variadic
6359 arguments of the broker are passed through to the callback function *after* the
6360 arguments encoded explicitly before.
6362 In the code below, the ``pthread_create`` function is marked as a broker
6363 through the ``!callback !1`` metadata. In the example, there is only one
6364 callback encoding, namely ``!2``, associated with the broker. This encoding
6365 identifies the callback function as the second argument of the broker (``i64
6366 2``) and the sole argument of the callback function as the third one of the
6367 broker function (``i64 3``).
6369 .. FIXME why does the llvm-sphinx-docs builder give a highlighting
6370 error if the below is set to highlight as 'llvm', despite that we
6371 have misc.highlighting_failure set?
6373 .. code-block:: text
6375 declare !callback !1 dso_local i32 @pthread_create(ptr, ptr, ptr, ptr)
6378 !2 = !{i64 2, i64 3, i1 false}
6381 Another example is shown below. The callback callee is the second argument of
6382 the ``__kmpc_fork_call`` function (``i64 2``). The callee is given two unknown
6383 values (each identified by a ``i64 -1``) and afterwards all
6384 variadic arguments that are passed to the ``__kmpc_fork_call`` call (due to the
6387 .. FIXME why does the llvm-sphinx-docs builder give a highlighting
6388 error if the below is set to highlight as 'llvm', despite that we
6389 have misc.highlighting_failure set?
6391 .. code-block:: text
6393 declare !callback !0 dso_local void @__kmpc_fork_call(ptr, i32, ptr, ...)
6396 !1 = !{i64 2, i64 -1, i64 -1, i1 true}
6399 '``exclude``' Metadata
6400 ^^^^^^^^^^^^^^^^^^^^^^
6402 ``exclude`` metadata may be attached to a global variable to signify that its
6403 section should not be included in the final executable or shared library. This
6404 option is only valid for global variables with an explicit section targeting ELF
6405 or COFF. This is done using the ``SHF_EXCLUDE`` flag on ELF targets and the
6406 ``IMAGE_SCN_LNK_REMOVE`` and ``IMAGE_SCN_MEM_DISCARDABLE`` flags for COFF
6407 targets. Additionally, this metadata is only used as a flag, so the associated
6408 node must be empty. The explicit section should not conflict with any other
6409 sections that the user does not want removed after linking.
6411 .. code-block:: text
6413 @object = private constant [1 x i8] c"\00", section ".foo" !exclude !0
6418 '``unpredictable``' Metadata
6419 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6421 ``unpredictable`` metadata may be attached to any branch or switch
6422 instruction. It can be used to express the unpredictability of control
6423 flow. Similar to the llvm.expect intrinsic, it may be used to alter
6424 optimizations related to compare and branch instructions. The metadata
6425 is treated as a boolean value; if it exists, it signals that the branch
6426 or switch that it is attached to is completely unpredictable.
6428 .. _md_dereferenceable:
6430 '``dereferenceable``' Metadata
6431 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6433 The existence of the ``!dereferenceable`` metadata on the instruction
6434 tells the optimizer that the value loaded is known to be dereferenceable.
6435 The number of bytes known to be dereferenceable is specified by the integer
6436 value in the metadata node. This is analogous to the ''dereferenceable''
6437 attribute on parameters and return values.
6439 .. _md_dereferenceable_or_null:
6441 '``dereferenceable_or_null``' Metadata
6442 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6444 The existence of the ``!dereferenceable_or_null`` metadata on the
6445 instruction tells the optimizer that the value loaded is known to be either
6446 dereferenceable or null.
6447 The number of bytes known to be dereferenceable is specified by the integer
6448 value in the metadata node. This is analogous to the ''dereferenceable_or_null''
6449 attribute on parameters and return values.
6456 It is sometimes useful to attach information to loop constructs. Currently,
6457 loop metadata is implemented as metadata attached to the branch instruction
6458 in the loop latch block. The loop metadata node is a list of
6459 other metadata nodes, each representing a property of the loop. Usually,
6460 the first item of the property node is a string. For example, the
6461 ``llvm.loop.unroll.count`` suggests an unroll factor to the loop
6464 .. code-block:: llvm
6466 br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0
6469 !1 = !{!"llvm.loop.unroll.enable"}
6470 !2 = !{!"llvm.loop.unroll.count", i32 4}
6472 For legacy reasons, the first item of a loop metadata node must be a
6473 reference to itself. Before the advent of the 'distinct' keyword, this
6474 forced the preservation of otherwise identical metadata nodes. Since
6475 the loop-metadata node can be attached to multiple nodes, the 'distinct'
6476 keyword has become unnecessary.
6478 Prior to the property nodes, one or two ``DILocation`` (debug location)
6479 nodes can be present in the list. The first, if present, identifies the
6480 source-code location where the loop begins. The second, if present,
6481 identifies the source-code location where the loop ends.
6483 Loop metadata nodes cannot be used as unique identifiers. They are
6484 neither persistent for the same loop through transformations nor
6485 necessarily unique to just one loop.
6487 '``llvm.loop.disable_nonforced``'
6488 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6490 This metadata disables all optional loop transformations unless
6491 explicitly instructed using other transformation metadata such as
6492 ``llvm.loop.unroll.enable``. That is, no heuristic will try to determine
6493 whether a transformation is profitable. The purpose is to avoid that the
6494 loop is transformed to a different loop before an explicitly requested
6495 (forced) transformation is applied. For instance, loop fusion can make
6496 other transformations impossible. Mandatory loop canonicalizations such
6497 as loop rotation are still applied.
6499 It is recommended to use this metadata in addition to any llvm.loop.*
6500 transformation directive. Also, any loop should have at most one
6501 directive applied to it (and a sequence of transformations built using
6502 followup-attributes). Otherwise, which transformation will be applied
6503 depends on implementation details such as the pass pipeline order.
6505 See :ref:`transformation-metadata` for details.
6507 '``llvm.loop.vectorize``' and '``llvm.loop.interleave``'
6508 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6510 Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are
6511 used to control per-loop vectorization and interleaving parameters such as
6512 vectorization width and interleave count. These metadata should be used in
6513 conjunction with ``llvm.loop`` loop identification metadata. The
6514 ``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only
6515 optimization hints and the optimizer will only interleave and vectorize loops if
6516 it believes it is safe to do so. The ``llvm.loop.parallel_accesses`` metadata
6517 which contains information about loop-carried memory dependencies can be helpful
6518 in determining the safety of these transformations.
6520 '``llvm.loop.interleave.count``' Metadata
6521 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6523 This metadata suggests an interleave count to the loop interleaver.
6524 The first operand is the string ``llvm.loop.interleave.count`` and the
6525 second operand is an integer specifying the interleave count. For
6528 .. code-block:: llvm
6530 !0 = !{!"llvm.loop.interleave.count", i32 4}
6532 Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving
6533 multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0
6534 then the interleave count will be determined automatically.
6536 '``llvm.loop.vectorize.enable``' Metadata
6537 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6539 This metadata selectively enables or disables vectorization for the loop. The
6540 first operand is the string ``llvm.loop.vectorize.enable`` and the second operand
6541 is a bit. If the bit operand value is 1 vectorization is enabled. A value of
6542 0 disables vectorization:
6544 .. code-block:: llvm
6546 !0 = !{!"llvm.loop.vectorize.enable", i1 0}
6547 !1 = !{!"llvm.loop.vectorize.enable", i1 1}
6549 '``llvm.loop.vectorize.predicate.enable``' Metadata
6550 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6552 This metadata selectively enables or disables creating predicated instructions
6553 for the loop, which can enable folding of the scalar epilogue loop into the
6554 main loop. The first operand is the string
6555 ``llvm.loop.vectorize.predicate.enable`` and the second operand is a bit. If
6556 the bit operand value is 1 vectorization is enabled. A value of 0 disables
6559 .. code-block:: llvm
6561 !0 = !{!"llvm.loop.vectorize.predicate.enable", i1 0}
6562 !1 = !{!"llvm.loop.vectorize.predicate.enable", i1 1}
6564 '``llvm.loop.vectorize.scalable.enable``' Metadata
6565 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6567 This metadata selectively enables or disables scalable vectorization for the
6568 loop, and only has any effect if vectorization for the loop is already enabled.
6569 The first operand is the string ``llvm.loop.vectorize.scalable.enable``
6570 and the second operand is a bit. If the bit operand value is 1 scalable
6571 vectorization is enabled, whereas a value of 0 reverts to the default fixed
6572 width vectorization:
6574 .. code-block:: llvm
6576 !0 = !{!"llvm.loop.vectorize.scalable.enable", i1 0}
6577 !1 = !{!"llvm.loop.vectorize.scalable.enable", i1 1}
6579 '``llvm.loop.vectorize.width``' Metadata
6580 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6582 This metadata sets the target width of the vectorizer. The first
6583 operand is the string ``llvm.loop.vectorize.width`` and the second
6584 operand is an integer specifying the width. For example:
6586 .. code-block:: llvm
6588 !0 = !{!"llvm.loop.vectorize.width", i32 4}
6590 Note that setting ``llvm.loop.vectorize.width`` to 1 disables
6591 vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to
6592 0 or if the loop does not have this metadata the width will be
6593 determined automatically.
6595 '``llvm.loop.vectorize.followup_vectorized``' Metadata
6596 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6598 This metadata defines which loop attributes the vectorized loop will
6599 have. See :ref:`transformation-metadata` for details.
6601 '``llvm.loop.vectorize.followup_epilogue``' Metadata
6602 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6604 This metadata defines which loop attributes the epilogue will have. The
6605 epilogue is not vectorized and is executed when either the vectorized
6606 loop is not known to preserve semantics (because e.g., it processes two
6607 arrays that are found to alias by a runtime check) or for the last
6608 iterations that do not fill a complete set of vector lanes. See
6609 :ref:`Transformation Metadata <transformation-metadata>` for details.
6611 '``llvm.loop.vectorize.followup_all``' Metadata
6612 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6614 Attributes in the metadata will be added to both the vectorized and
6616 See :ref:`Transformation Metadata <transformation-metadata>` for details.
6618 '``llvm.loop.unroll``'
6619 ^^^^^^^^^^^^^^^^^^^^^^
6621 Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling
6622 optimization hints such as the unroll factor. ``llvm.loop.unroll``
6623 metadata should be used in conjunction with ``llvm.loop`` loop
6624 identification metadata. The ``llvm.loop.unroll`` metadata are only
6625 optimization hints and the unrolling will only be performed if the
6626 optimizer believes it is safe to do so.
6628 '``llvm.loop.unroll.count``' Metadata
6629 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6631 This metadata suggests an unroll factor to the loop unroller. The
6632 first operand is the string ``llvm.loop.unroll.count`` and the second
6633 operand is a positive integer specifying the unroll factor. For
6636 .. code-block:: llvm
6638 !0 = !{!"llvm.loop.unroll.count", i32 4}
6640 If the trip count of the loop is less than the unroll count the loop
6641 will be partially unrolled.
6643 '``llvm.loop.unroll.disable``' Metadata
6644 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6646 This metadata disables loop unrolling. The metadata has a single operand
6647 which is the string ``llvm.loop.unroll.disable``. For example:
6649 .. code-block:: llvm
6651 !0 = !{!"llvm.loop.unroll.disable"}
6653 '``llvm.loop.unroll.runtime.disable``' Metadata
6654 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6656 This metadata disables runtime loop unrolling. The metadata has a single
6657 operand which is the string ``llvm.loop.unroll.runtime.disable``. For example:
6659 .. code-block:: llvm
6661 !0 = !{!"llvm.loop.unroll.runtime.disable"}
6663 '``llvm.loop.unroll.enable``' Metadata
6664 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6666 This metadata suggests that the loop should be fully unrolled if the trip count
6667 is known at compile time and partially unrolled if the trip count is not known
6668 at compile time. The metadata has a single operand which is the string
6669 ``llvm.loop.unroll.enable``. For example:
6671 .. code-block:: llvm
6673 !0 = !{!"llvm.loop.unroll.enable"}
6675 '``llvm.loop.unroll.full``' Metadata
6676 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6678 This metadata suggests that the loop should be unrolled fully. The
6679 metadata has a single operand which is the string ``llvm.loop.unroll.full``.
6682 .. code-block:: llvm
6684 !0 = !{!"llvm.loop.unroll.full"}
6686 '``llvm.loop.unroll.followup``' Metadata
6687 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6689 This metadata defines which loop attributes the unrolled loop will have.
6690 See :ref:`Transformation Metadata <transformation-metadata>` for details.
6692 '``llvm.loop.unroll.followup_remainder``' Metadata
6693 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6695 This metadata defines which loop attributes the remainder loop after
6696 partial/runtime unrolling will have. See
6697 :ref:`Transformation Metadata <transformation-metadata>` for details.
6699 '``llvm.loop.unroll_and_jam``'
6700 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6702 This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata
6703 above, but affect the unroll and jam pass. In addition any loop with
6704 ``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will
6705 disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the
6706 unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam
6709 The metadata for unroll and jam otherwise is the same as for ``unroll``.
6710 ``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and
6711 ``llvm.loop.unroll_and_jam.count`` do the same as for unroll.
6712 ``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints
6713 and the normal safety checks will still be performed.
6715 '``llvm.loop.unroll_and_jam.count``' Metadata
6716 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6718 This metadata suggests an unroll and jam factor to use, similarly to
6719 ``llvm.loop.unroll.count``. The first operand is the string
6720 ``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer
6721 specifying the unroll factor. For example:
6723 .. code-block:: llvm
6725 !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4}
6727 If the trip count of the loop is less than the unroll count the loop
6728 will be partially unroll and jammed.
6730 '``llvm.loop.unroll_and_jam.disable``' Metadata
6731 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6733 This metadata disables loop unroll and jamming. The metadata has a single
6734 operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example:
6736 .. code-block:: llvm
6738 !0 = !{!"llvm.loop.unroll_and_jam.disable"}
6740 '``llvm.loop.unroll_and_jam.enable``' Metadata
6741 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6743 This metadata suggests that the loop should be fully unroll and jammed if the
6744 trip count is known at compile time and partially unrolled if the trip count is
6745 not known at compile time. The metadata has a single operand which is the
6746 string ``llvm.loop.unroll_and_jam.enable``. For example:
6748 .. code-block:: llvm
6750 !0 = !{!"llvm.loop.unroll_and_jam.enable"}
6752 '``llvm.loop.unroll_and_jam.followup_outer``' Metadata
6753 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6755 This metadata defines which loop attributes the outer unrolled loop will
6756 have. See :ref:`Transformation Metadata <transformation-metadata>` for
6759 '``llvm.loop.unroll_and_jam.followup_inner``' Metadata
6760 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6762 This metadata defines which loop attributes the inner jammed loop will
6763 have. See :ref:`Transformation Metadata <transformation-metadata>` for
6766 '``llvm.loop.unroll_and_jam.followup_remainder_outer``' Metadata
6767 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6769 This metadata defines which attributes the epilogue of the outer loop
6770 will have. This loop is usually unrolled, meaning there is no such
6771 loop. This attribute will be ignored in this case. See
6772 :ref:`Transformation Metadata <transformation-metadata>` for details.
6774 '``llvm.loop.unroll_and_jam.followup_remainder_inner``' Metadata
6775 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6777 This metadata defines which attributes the inner loop of the epilogue
6778 will have. The outer epilogue will usually be unrolled, meaning there
6779 can be multiple inner remainder loops. See
6780 :ref:`Transformation Metadata <transformation-metadata>` for details.
6782 '``llvm.loop.unroll_and_jam.followup_all``' Metadata
6783 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6785 Attributes specified in the metadata is added to all
6786 ``llvm.loop.unroll_and_jam.*`` loops. See
6787 :ref:`Transformation Metadata <transformation-metadata>` for details.
6789 '``llvm.loop.licm_versioning.disable``' Metadata
6790 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6792 This metadata indicates that the loop should not be versioned for the purpose
6793 of enabling loop-invariant code motion (LICM). The metadata has a single operand
6794 which is the string ``llvm.loop.licm_versioning.disable``. For example:
6796 .. code-block:: llvm
6798 !0 = !{!"llvm.loop.licm_versioning.disable"}
6800 '``llvm.loop.distribute.enable``' Metadata
6801 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6803 Loop distribution allows splitting a loop into multiple loops. Currently,
6804 this is only performed if the entire loop cannot be vectorized due to unsafe
6805 memory dependencies. The transformation will attempt to isolate the unsafe
6806 dependencies into their own loop.
6808 This metadata can be used to selectively enable or disable distribution of the
6809 loop. The first operand is the string ``llvm.loop.distribute.enable`` and the
6810 second operand is a bit. If the bit operand value is 1 distribution is
6811 enabled. A value of 0 disables distribution:
6813 .. code-block:: llvm
6815 !0 = !{!"llvm.loop.distribute.enable", i1 0}
6816 !1 = !{!"llvm.loop.distribute.enable", i1 1}
6818 This metadata should be used in conjunction with ``llvm.loop`` loop
6819 identification metadata.
6821 '``llvm.loop.distribute.followup_coincident``' Metadata
6822 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6824 This metadata defines which attributes extracted loops with no cyclic
6825 dependencies will have (i.e. can be vectorized). See
6826 :ref:`Transformation Metadata <transformation-metadata>` for details.
6828 '``llvm.loop.distribute.followup_sequential``' Metadata
6829 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6831 This metadata defines which attributes the isolated loops with unsafe
6832 memory dependencies will have. See
6833 :ref:`Transformation Metadata <transformation-metadata>` for details.
6835 '``llvm.loop.distribute.followup_fallback``' Metadata
6836 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6838 If loop versioning is necessary, this metadata defined the attributes
6839 the non-distributed fallback version will have. See
6840 :ref:`Transformation Metadata <transformation-metadata>` for details.
6842 '``llvm.loop.distribute.followup_all``' Metadata
6843 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6845 The attributes in this metadata is added to all followup loops of the
6846 loop distribution pass. See
6847 :ref:`Transformation Metadata <transformation-metadata>` for details.
6849 '``llvm.licm.disable``' Metadata
6850 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6852 This metadata indicates that loop-invariant code motion (LICM) should not be
6853 performed on this loop. The metadata has a single operand which is the string
6854 ``llvm.licm.disable``. For example:
6856 .. code-block:: llvm
6858 !0 = !{!"llvm.licm.disable"}
6860 Note that although it operates per loop it isn't given the llvm.loop prefix
6861 as it is not affected by the ``llvm.loop.disable_nonforced`` metadata.
6863 '``llvm.access.group``' Metadata
6864 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6866 ``llvm.access.group`` metadata can be attached to any instruction that
6867 potentially accesses memory. It can point to a single distinct metadata
6868 node, which we call access group. This node represents all memory access
6869 instructions referring to it via ``llvm.access.group``. When an
6870 instruction belongs to multiple access groups, it can also point to a
6871 list of accesses groups, illustrated by the following example.
6873 .. code-block:: llvm
6875 %val = load i32, ptr %arrayidx, !llvm.access.group !0
6881 It is illegal for the list node to be empty since it might be confused
6882 with an access group.
6884 The access group metadata node must be 'distinct' to avoid collapsing
6885 multiple access groups by content. A access group metadata node must
6886 always be empty which can be used to distinguish an access group
6887 metadata node from a list of access groups. Being empty avoids the
6888 situation that the content must be updated which, because metadata is
6889 immutable by design, would required finding and updating all references
6890 to the access group node.
6892 The access group can be used to refer to a memory access instruction
6893 without pointing to it directly (which is not possible in global
6894 metadata). Currently, the only metadata making use of it is
6895 ``llvm.loop.parallel_accesses``.
6897 '``llvm.loop.parallel_accesses``' Metadata
6898 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6900 The ``llvm.loop.parallel_accesses`` metadata refers to one or more
6901 access group metadata nodes (see ``llvm.access.group``). It denotes that
6902 no loop-carried memory dependence exist between it and other instructions
6903 in the loop with this metadata.
6905 Let ``m1`` and ``m2`` be two instructions that both have the
6906 ``llvm.access.group`` metadata to the access group ``g1``, respectively
6907 ``g2`` (which might be identical). If a loop contains both access groups
6908 in its ``llvm.loop.parallel_accesses`` metadata, then the compiler can
6909 assume that there is no dependency between ``m1`` and ``m2`` carried by
6910 this loop. Instructions that belong to multiple access groups are
6911 considered having this property if at least one of the access groups
6912 matches the ``llvm.loop.parallel_accesses`` list.
6914 If all memory-accessing instructions in a loop have
6915 ``llvm.access.group`` metadata that each refer to one of the access
6916 groups of a loop's ``llvm.loop.parallel_accesses`` metadata, then the
6917 loop has no loop carried memory dependences and is considered to be a
6920 Note that if not all memory access instructions belong to an access
6921 group referred to by ``llvm.loop.parallel_accesses``, then the loop must
6922 not be considered trivially parallel. Additional
6923 memory dependence analysis is required to make that determination. As a fail
6924 safe mechanism, this causes loops that were originally parallel to be considered
6925 sequential (if optimization passes that are unaware of the parallel semantics
6926 insert new memory instructions into the loop body).
6928 Example of a loop that is considered parallel due to its correct use of
6929 both ``llvm.access.group`` and ``llvm.loop.parallel_accesses``
6932 .. code-block:: llvm
6936 %val0 = load i32, ptr %arrayidx, !llvm.access.group !1
6938 store i32 %val0, ptr %arrayidx1, !llvm.access.group !1
6940 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
6944 !0 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !1}}
6947 It is also possible to have nested parallel loops:
6949 .. code-block:: llvm
6953 %val1 = load i32, ptr %arrayidx3, !llvm.access.group !4
6955 br label %inner.for.body
6959 %val0 = load i32, ptr %arrayidx1, !llvm.access.group !3
6961 store i32 %val0, ptr %arrayidx2, !llvm.access.group !3
6963 br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1
6967 store i32 %val1, ptr %arrayidx4, !llvm.access.group !4
6969 br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2
6971 outer.for.end: ; preds = %for.body
6973 !1 = distinct !{!1, !{!"llvm.loop.parallel_accesses", !3}} ; metadata for the inner loop
6974 !2 = distinct !{!2, !{!"llvm.loop.parallel_accesses", !3, !4}} ; metadata for the outer loop
6975 !3 = distinct !{} ; access group for instructions in the inner loop (which are implicitly contained in outer loop as well)
6976 !4 = distinct !{} ; access group for instructions in the outer, but not the inner loop
6978 .. _langref_llvm_loop_mustprogress:
6980 '``llvm.loop.mustprogress``' Metadata
6981 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6983 The ``llvm.loop.mustprogress`` metadata indicates that this loop is required to
6984 terminate, unwind, or interact with the environment in an observable way e.g.
6985 via a volatile memory access, I/O, or other synchronization. If such a loop is
6986 not found to interact with the environment in an observable way, the loop may
6987 be removed. This corresponds to the ``mustprogress`` function attribute.
6989 '``irr_loop``' Metadata
6990 ^^^^^^^^^^^^^^^^^^^^^^^
6992 ``irr_loop`` metadata may be attached to the terminator instruction of a basic
6993 block that's an irreducible loop header (note that an irreducible loop has more
6994 than once header basic blocks.) If ``irr_loop`` metadata is attached to the
6995 terminator instruction of a basic block that is not really an irreducible loop
6996 header, the behavior is undefined. The intent of this metadata is to improve the
6997 accuracy of the block frequency propagation. For example, in the code below, the
6998 block ``header0`` may have a loop header weight (relative to the other headers of
6999 the irreducible loop) of 100:
7001 .. code-block:: llvm
7005 br i1 %cmp, label %t1, label %t2, !irr_loop !0
7008 !0 = !{"loop_header_weight", i64 100}
7010 Irreducible loop header weights are typically based on profile data.
7012 .. _md_invariant.group:
7014 '``invariant.group``' Metadata
7015 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7017 The experimental ``invariant.group`` metadata may be attached to
7018 ``load``/``store`` instructions referencing a single metadata with no entries.
7019 The existence of the ``invariant.group`` metadata on the instruction tells
7020 the optimizer that every ``load`` and ``store`` to the same pointer operand
7021 can be assumed to load or store the same
7022 value (but see the ``llvm.launder.invariant.group`` intrinsic which affects
7023 when two pointers are considered the same). Pointers returned by bitcast or
7024 getelementptr with only zero indices are considered the same.
7028 .. code-block:: llvm
7030 @unknownPtr = external global i8
7033 store i8 42, ptr %ptr, !invariant.group !0
7034 call void @foo(ptr %ptr)
7036 %a = load i8, ptr %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change
7037 call void @foo(ptr %ptr)
7039 %newPtr = call ptr @getPointer(ptr %ptr)
7040 %c = load i8, ptr %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr
7042 %unknownValue = load i8, ptr @unknownPtr
7043 store i8 %unknownValue, ptr %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42
7045 call void @foo(ptr %ptr)
7046 %newPtr2 = call ptr @llvm.launder.invariant.group.p0(ptr %ptr)
7047 %d = load i8, ptr %newPtr2, !invariant.group !0 ; Can't step through launder.invariant.group to get value of %ptr
7050 declare void @foo(ptr)
7051 declare ptr @getPointer(ptr)
7052 declare ptr @llvm.launder.invariant.group.p0(ptr)
7056 The invariant.group metadata must be dropped when replacing one pointer by
7057 another based on aliasing information. This is because invariant.group is tied
7058 to the SSA value of the pointer operand.
7060 .. code-block:: llvm
7062 %v = load i8, ptr %x, !invariant.group !0
7063 ; if %x mustalias %y then we can replace the above instruction with
7064 %v = load i8, ptr %y
7066 Note that this is an experimental feature, which means that its semantics might
7067 change in the future.
7072 See :doc:`TypeMetadata`.
7074 '``associated``' Metadata
7075 ^^^^^^^^^^^^^^^^^^^^^^^^^
7077 The ``associated`` metadata may be attached to a global variable definition with
7078 a single argument that references a global object (optionally through an alias).
7080 This metadata lowers to the ELF section flag ``SHF_LINK_ORDER`` which prevents
7081 discarding of the global variable in linker GC unless the referenced object is
7082 also discarded. The linker support for this feature is spotty. For best
7083 compatibility, globals carrying this metadata should:
7085 - Be in ``@llvm.compiler.used``.
7086 - If the referenced global variable is in a comdat, be in the same comdat.
7088 ``!associated`` can not express many-to-one relationship. A global variable with
7089 the metadata should generally not be referenced by a function: the function may
7090 be inlined into other functions, leading to more references to the metadata.
7091 Ideally we would want to keep metadata alive as long as any inline location is
7092 alive, but this many-to-one relationship is not representable. Moreover, if the
7093 metadata is retained while the function is discarded, the linker will report an
7094 error of a relocation referencing a discarded section.
7096 The metadata is often used with an explicit section consisting of valid C
7097 identifiers so that the runtime can find the metadata section with
7098 linker-defined encapsulation symbols ``__start_<section_name>`` and
7099 ``__stop_<section_name>``.
7101 It does not have any effect on non-ELF targets.
7105 .. code-block:: text
7108 @a = global i32 1, comdat $a
7109 @b = internal global i32 2, comdat $a, section "abc", !associated !0
7116 The ``prof`` metadata is used to record profile data in the IR.
7117 The first operand of the metadata node indicates the profile metadata
7118 type. There are currently 3 types:
7119 :ref:`branch_weights<prof_node_branch_weights>`,
7120 :ref:`function_entry_count<prof_node_function_entry_count>`, and
7121 :ref:`VP<prof_node_VP>`.
7123 .. _prof_node_branch_weights:
7128 Branch weight metadata attached to a branch, select, switch or call instruction
7129 represents the likeliness of the associated branch being taken.
7130 For more information, see :doc:`BranchWeightMetadata`.
7132 .. _prof_node_function_entry_count:
7134 function_entry_count
7135 """"""""""""""""""""
7137 Function entry count metadata can be attached to function definitions
7138 to record the number of times the function is called. Used with BFI
7139 information, it is also used to derive the basic block profile count.
7140 For more information, see :doc:`BranchWeightMetadata`.
7147 VP (value profile) metadata can be attached to instructions that have
7148 value profile information. Currently this is indirect calls (where it
7149 records the hottest callees) and calls to memory intrinsics such as memcpy,
7150 memmove, and memset (where it records the hottest byte lengths).
7152 Each VP metadata node contains "VP" string, then a uint32_t value for the value
7153 profiling kind, a uint64_t value for the total number of times the instruction
7154 is executed, followed by uint64_t value and execution count pairs.
7155 The value profiling kind is 0 for indirect call targets and 1 for memory
7156 operations. For indirect call targets, each profile value is a hash
7157 of the callee function name, and for memory operations each value is the
7160 Note that the value counts do not need to add up to the total count
7161 listed in the third operand (in practice only the top hottest values
7162 are tracked and reported).
7164 Indirect call example:
7166 .. code-block:: llvm
7168 call void %f(), !prof !1
7169 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410}
7171 Note that the VP type is 0 (the second operand), which indicates this is
7172 an indirect call value profile data. The third operand indicates that the
7173 indirect call executed 1600 times. The 4th and 6th operands give the
7174 hashes of the 2 hottest target functions' names (this is the same hash used
7175 to represent function names in the profile database), and the 5th and 7th
7176 operands give the execution count that each of the respective prior target
7177 functions was called.
7181 '``annotation``' Metadata
7182 ^^^^^^^^^^^^^^^^^^^^^^^^^
7184 The ``annotation`` metadata can be used to attach a tuple of annotation strings
7185 to any instruction. This metadata does not impact the semantics of the program
7186 and may only be used to provide additional insight about the program and
7187 transformations to users.
7191 .. code-block:: text
7193 %a.addr = alloca ptr, align 8, !annotation !0
7194 !0 = !{!"auto-init"}
7196 '``func_sanitize``' Metadata
7197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7199 The ``func_sanitize`` metadata is used to attach two values for the function
7200 sanitizer instrumentation. The first value is the ubsan function signature.
7201 The second value is the address of the proxy variable which stores the address
7202 of the RTTI descriptor. If :ref:`prologue <prologuedata>` and '``func_sanitize``'
7203 are used at the same time, :ref:`prologue <prologuedata>` is emitted before
7204 '``func_sanitize``' in the output.
7208 .. code-block:: text
7210 @__llvm_rtti_proxy = private unnamed_addr constant ptr @_ZTIFvvE
7211 define void @_Z3funv() !func_sanitize !0 {
7214 !0 = !{i32 846595819, ptr @__llvm_rtti_proxy}
7216 Module Flags Metadata
7217 =====================
7219 Information about the module as a whole is difficult to convey to LLVM's
7220 subsystems. The LLVM IR isn't sufficient to transmit this information.
7221 The ``llvm.module.flags`` named metadata exists in order to facilitate
7222 this. These flags are in the form of key / value pairs --- much like a
7223 dictionary --- making it easy for any subsystem who cares about a flag to
7226 The ``llvm.module.flags`` metadata contains a list of metadata triplets.
7227 Each triplet has the following form:
7229 - The first element is a *behavior* flag, which specifies the behavior
7230 when two (or more) modules are merged together, and it encounters two
7231 (or more) metadata with the same ID. The supported behaviors are
7233 - The second element is a metadata string that is a unique ID for the
7234 metadata. Each module may only have one flag entry for each unique ID (not
7235 including entries with the **Require** behavior).
7236 - The third element is the value of the flag.
7238 When two (or more) modules are merged together, the resulting
7239 ``llvm.module.flags`` metadata is the union of the modules' flags. That is, for
7240 each unique metadata ID string, there will be exactly one entry in the merged
7241 modules ``llvm.module.flags`` metadata table, and the value for that entry will
7242 be determined by the merge behavior flag, as described below. The only exception
7243 is that entries with the *Require* behavior are always preserved.
7245 The following behaviors are supported:
7256 Emits an error if two values disagree, otherwise the resulting value
7257 is that of the operands.
7261 Emits a warning if two values disagree. The result value will be the
7262 operand for the flag from the first module being linked, or the max
7263 if the other module uses **Max** (in which case the resulting flag
7268 Adds a requirement that another module flag be present and have a
7269 specified value after linking is performed. The value must be a
7270 metadata pair, where the first element of the pair is the ID of the
7271 module flag to be restricted, and the second element of the pair is
7272 the value the module flag should be restricted to. This behavior can
7273 be used to restrict the allowable results (via triggering of an
7274 error) of linking IDs with the **Override** behavior.
7278 Uses the specified value, regardless of the behavior or value of the
7279 other module. If both modules specify **Override**, but the values
7280 differ, an error will be emitted.
7284 Appends the two values, which are required to be metadata nodes.
7288 Appends the two values, which are required to be metadata
7289 nodes. However, duplicate entries in the second list are dropped
7290 during the append operation.
7294 Takes the max of the two values, which are required to be integers.
7298 Takes the min of the two values, which are required to be non-negative integers.
7299 An absent module flag is treated as having the value 0.
7301 It is an error for a particular unique flag ID to have multiple behaviors,
7302 except in the case of **Require** (which adds restrictions on another metadata
7303 value) or **Override**.
7305 An example of module flags:
7307 .. code-block:: llvm
7309 !0 = !{ i32 1, !"foo", i32 1 }
7310 !1 = !{ i32 4, !"bar", i32 37 }
7311 !2 = !{ i32 2, !"qux", i32 42 }
7312 !3 = !{ i32 3, !"qux",
7317 !llvm.module.flags = !{ !0, !1, !2, !3 }
7319 - Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior
7320 if two or more ``!"foo"`` flags are seen is to emit an error if their
7321 values are not equal.
7323 - Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The
7324 behavior if two or more ``!"bar"`` flags are seen is to use the value
7327 - Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The
7328 behavior if two or more ``!"qux"`` flags are seen is to emit a
7329 warning if their values are not equal.
7331 - Metadata ``!3`` has the ID ``!"qux"`` and the value:
7337 The behavior is to emit an error if the ``llvm.module.flags`` does not
7338 contain a flag with the ID ``!"foo"`` that has the value '1' after linking is
7341 Synthesized Functions Module Flags Metadata
7342 -------------------------------------------
7344 These metadata specify the default attributes synthesized functions should have.
7345 These metadata are currently respected by a few instrumentation passes, such as
7348 These metadata correspond to a few function attributes with significant code
7349 generation behaviors. Function attributes with just optimization purposes
7350 should not be listed because the performance impact of these synthesized
7353 - "frame-pointer": **Max**. The value can be 0, 1, or 2. A synthesized function
7354 will get the "frame-pointer" function attribute, with value being "none",
7355 "non-leaf", or "all", respectively.
7356 - "function_return_thunk_extern": The synthesized function will get the
7357 ``fn_return_thunk_extern`` function attribute.
7358 - "uwtable": **Max**. The value can be 0, 1, or 2. If the value is 1, a synthesized
7359 function will get the ``uwtable(sync)`` function attribute, if the value is 2,
7360 a synthesized function will get the ``uwtable(async)`` function attribute.
7362 Objective-C Garbage Collection Module Flags Metadata
7363 ----------------------------------------------------
7365 On the Mach-O platform, Objective-C stores metadata about garbage
7366 collection in a special section called "image info". The metadata
7367 consists of a version number and a bitmask specifying what types of
7368 garbage collection are supported (if any) by the file. If two or more
7369 modules are linked together their garbage collection metadata needs to
7370 be merged rather than appended together.
7372 The Objective-C garbage collection module flags metadata consists of the
7373 following key-value pairs:
7382 * - ``Objective-C Version``
7383 - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2.
7385 * - ``Objective-C Image Info Version``
7386 - **[Required]** --- The version of the image info section. Currently
7389 * - ``Objective-C Image Info Section``
7390 - **[Required]** --- The section to place the metadata. Valid values are
7391 ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and
7392 ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for
7393 Objective-C ABI version 2.
7395 * - ``Objective-C Garbage Collection``
7396 - **[Required]** --- Specifies whether garbage collection is supported or
7397 not. Valid values are 0, for no garbage collection, and 2, for garbage
7398 collection supported.
7400 * - ``Objective-C GC Only``
7401 - **[Optional]** --- Specifies that only garbage collection is supported.
7402 If present, its value must be 6. This flag requires that the
7403 ``Objective-C Garbage Collection`` flag have the value 2.
7405 Some important flag interactions:
7407 - If a module with ``Objective-C Garbage Collection`` set to 0 is
7408 merged with a module with ``Objective-C Garbage Collection`` set to
7409 2, then the resulting module has the
7410 ``Objective-C Garbage Collection`` flag set to 0.
7411 - A module with ``Objective-C Garbage Collection`` set to 0 cannot be
7412 merged with a module with ``Objective-C GC Only`` set to 6.
7414 C type width Module Flags Metadata
7415 ----------------------------------
7417 The ARM backend emits a section into each generated object file describing the
7418 options that it was compiled with (in a compiler-independent way) to prevent
7419 linking incompatible objects, and to allow automatic library selection. Some
7420 of these options are not visible at the IR level, namely wchar_t width and enum
7423 To pass this information to the backend, these options are encoded in module
7424 flags metadata, using the following key-value pairs:
7434 - * 0 --- sizeof(wchar_t) == 4
7435 * 1 --- sizeof(wchar_t) == 2
7438 - * 0 --- Enums are at least as large as an ``int``.
7439 * 1 --- Enums are stored in the smallest integer type which can
7440 represent all of its values.
7442 For example, the following metadata section specifies that the module was
7443 compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an
7444 enum is the smallest type which can represent all of its values::
7446 !llvm.module.flags = !{!0, !1}
7447 !0 = !{i32 1, !"short_wchar", i32 1}
7448 !1 = !{i32 1, !"short_enum", i32 0}
7450 LTO Post-Link Module Flags Metadata
7451 -----------------------------------
7453 Some optimisations are only when the entire LTO unit is present in the current
7454 module. This is represented by the ``LTOPostLink`` module flags metadata, which
7455 will be created with a value of ``1`` when LTO linking occurs.
7457 Embedded Objects Names Metadata
7458 ===============================
7460 Offloading compilations need to embed device code into the host section table to
7461 create a fat binary. This metadata node references each global that will be
7462 embedded in the module. The primary use for this is to make referencing these
7463 globals more efficient in the IR. The metadata references nodes containing
7464 pointers to the global to be embedded followed by the section name it will be
7467 !llvm.embedded.objects = !{!0}
7468 !0 = !{ptr @object, !".section"}
7470 Automatic Linker Flags Named Metadata
7471 =====================================
7473 Some targets support embedding of flags to the linker inside individual object
7474 files. Typically this is used in conjunction with language extensions which
7475 allow source files to contain linker command line options, and have these
7476 automatically be transmitted to the linker via object files.
7478 These flags are encoded in the IR using named metadata with the name
7479 ``!llvm.linker.options``. Each operand is expected to be a metadata node
7480 which should be a list of other metadata nodes, each of which should be a
7481 list of metadata strings defining linker options.
7483 For example, the following metadata section specifies two separate sets of
7484 linker options, presumably to link against ``libz`` and the ``Cocoa``
7488 !1 = !{ !"-framework", !"Cocoa" }
7489 !llvm.linker.options = !{ !0, !1 }
7491 The metadata encoding as lists of lists of options, as opposed to a collapsed
7492 list of options, is chosen so that the IR encoding can use multiple option
7493 strings to specify e.g., a single library, while still having that specifier be
7494 preserved as an atomic element that can be recognized by a target specific
7495 assembly writer or object file emitter.
7497 Each individual option is required to be either a valid option for the target's
7498 linker, or an option that is reserved by the target specific assembly writer or
7499 object file emitter. No other aspect of these options is defined by the IR.
7501 Dependent Libs Named Metadata
7502 =============================
7504 Some targets support embedding of strings into object files to indicate
7505 a set of libraries to add to the link. Typically this is used in conjunction
7506 with language extensions which allow source files to explicitly declare the
7507 libraries they depend on, and have these automatically be transmitted to the
7508 linker via object files.
7510 The list is encoded in the IR using named metadata with the name
7511 ``!llvm.dependent-libraries``. Each operand is expected to be a metadata node
7512 which should contain a single string operand.
7514 For example, the following metadata section contains two library specifiers::
7516 !0 = !{!"a library specifier"}
7517 !1 = !{!"another library specifier"}
7518 !llvm.dependent-libraries = !{ !0, !1 }
7520 Each library specifier will be handled independently by the consuming linker.
7521 The effect of the library specifiers are defined by the consuming linker.
7528 Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_
7529 causes the building of a compact summary of the module that is emitted into
7530 the bitcode. The summary is emitted into the LLVM assembly and identified
7531 in syntax by a caret ('``^``').
7533 The summary is parsed into a bitcode output, along with the Module
7534 IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes
7535 of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the
7536 summary entries (just as they currently ignore summary entries in a bitcode
7539 Eventually, the summary will be parsed into a ModuleSummaryIndex object under
7540 the same conditions where summary index is currently built from bitcode.
7541 Specifically, tools that test the Thin Link portion of a ThinLTO compile
7542 (i.e. llvm-lto and llvm-lto2), or when parsing a combined index
7543 for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag
7544 (this part is not yet implemented, use llvm-as to create a bitcode object
7545 before feeding into thin link tools for now).
7547 There are currently 3 types of summary entries in the LLVM assembly:
7548 :ref:`module paths<module_path_summary>`,
7549 :ref:`global values<gv_summary>`, and
7550 :ref:`type identifiers<typeid_summary>`.
7552 .. _module_path_summary:
7554 Module Path Summary Entry
7555 -------------------------
7557 Each module path summary entry lists a module containing global values included
7558 in the summary. For a single IR module there will be one such entry, but
7559 in a combined summary index produced during the thin link, there will be
7560 one module path entry per linked module with summary.
7564 .. code-block:: text
7566 ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418))
7568 The ``path`` field is a string path to the bitcode file, and the ``hash``
7569 field is the 160-bit SHA-1 hash of the IR bitcode contents, used for
7570 incremental builds and caching.
7574 Global Value Summary Entry
7575 --------------------------
7577 Each global value summary entry corresponds to a global value defined or
7578 referenced by a summarized module.
7582 .. code-block:: text
7584 ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831
7586 For declarations, there will not be a summary list. For definitions, a
7587 global value will contain a list of summaries, one per module containing
7588 a definition. There can be multiple entries in a combined summary index
7589 for symbols with weak linkage.
7591 Each ``Summary`` format will depend on whether the global value is a
7592 :ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or
7593 :ref:`alias<alias_summary>`.
7595 .. _function_summary:
7600 If the global value is a function, the ``Summary`` entry will look like:
7602 .. code-block:: text
7604 function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Params]?[, Refs]?
7606 The ``module`` field includes the summary entry id for the module containing
7607 this definition, and the ``flags`` field contains information such as
7608 the linkage type, a flag indicating whether it is legal to import the
7609 definition, whether it is globally live and whether the linker resolved it
7610 to a local definition (the latter two are populated during the thin link).
7611 The ``insts`` field contains the number of IR instructions in the function.
7612 Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`,
7613 :ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`,
7614 :ref:`Params<params_summary>`, :ref:`Refs<refs_summary>`.
7616 .. _variable_summary:
7618 Global Variable Summary
7619 ^^^^^^^^^^^^^^^^^^^^^^^
7621 If the global value is a variable, the ``Summary`` entry will look like:
7623 .. code-block:: text
7625 variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]?
7627 The variable entry contains a subset of the fields in a
7628 :ref:`function summary <function_summary>`, see the descriptions there.
7635 If the global value is an alias, the ``Summary`` entry will look like:
7637 .. code-block:: text
7639 alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2)
7641 The ``module`` and ``flags`` fields are as described for a
7642 :ref:`function summary <function_summary>`. The ``aliasee`` field
7643 contains a reference to the global value summary entry of the aliasee.
7645 .. _funcflags_summary:
7650 The optional ``FuncFlags`` field looks like:
7652 .. code-block:: text
7654 funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0, noUnwind: 1, mayThrow: 0, hasUnknownCall: 0)
7656 If unspecified, flags are assumed to hold the conservative ``false`` value of
7664 The optional ``Calls`` field looks like:
7666 .. code-block:: text
7668 calls: ((Callee)[, (Callee)]*)
7670 where each ``Callee`` looks like:
7672 .. code-block:: text
7674 callee: ^1[, hotness: None]?[, relbf: 0]?
7676 The ``callee`` refers to the summary entry id of the callee. At most one
7677 of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``,
7678 ``Hot``, and ``Critical``), and ``relbf`` (which holds the integer
7679 branch frequency relative to the entry frequency, scaled down by 2^8)
7680 may be specified. The defaults are ``Unknown`` and ``0``, respectively.
7687 The optional ``Params`` is used by ``StackSafety`` and looks like:
7689 .. code-block:: text
7691 Params: ((Param)[, (Param)]*)
7693 where each ``Param`` describes pointer parameter access inside of the
7694 function and looks like:
7696 .. code-block:: text
7698 param: 4, offset: [0, 5][, calls: ((Callee)[, (Callee)]*)]?
7700 where the first ``param`` is the number of the parameter it describes,
7701 ``offset`` is the inclusive range of offsets from the pointer parameter to bytes
7702 which can be accessed by the function. This range does not include accesses by
7703 function calls from ``calls`` list.
7705 where each ``Callee`` describes how parameter is forwarded into other
7706 functions and looks like:
7708 .. code-block:: text
7710 callee: ^3, param: 5, offset: [-3, 3]
7712 The ``callee`` refers to the summary entry id of the callee, ``param`` is
7713 the number of the callee parameter which points into the callers parameter
7714 with offset known to be inside of the ``offset`` range. ``calls`` will be
7715 consumed and removed by thin link stage to update ``Param::offset`` so it
7716 covers all accesses possible by ``calls``.
7718 Pointer parameter without corresponding ``Param`` is considered unsafe and we
7719 assume that access with any offset is possible.
7723 If we have the following function:
7725 .. code-block:: text
7727 define i64 @foo(ptr %0, ptr %1, ptr %2, i8 %3) {
7728 store ptr %1, ptr @x
7729 %5 = getelementptr inbounds i8, ptr %2, i64 5
7730 %6 = load i8, ptr %5
7731 %7 = getelementptr inbounds i8, ptr %2, i8 %3
7732 tail call void @bar(i8 %3, ptr %7)
7733 %8 = load i64, ptr %0
7737 We can expect the record like this:
7739 .. code-block:: text
7741 params: ((param: 0, offset: [0, 7]),(param: 2, offset: [5, 5], calls: ((callee: ^3, param: 1, offset: [-128, 127]))))
7743 The function may access just 8 bytes of the parameter %0 . ``calls`` is empty,
7744 so the parameter is either not used for function calls or ``offset`` already
7745 covers all accesses from nested function calls.
7746 Parameter %1 escapes, so access is unknown.
7747 The function itself can access just a single byte of the parameter %2. Additional
7748 access is possible inside of the ``@bar`` or ``^3``. The function adds signed
7749 offset to the pointer and passes the result as the argument %1 into ``^3``.
7750 This record itself does not tell us how ``^3`` will access the parameter.
7751 Parameter %3 is not a pointer.
7758 The optional ``Refs`` field looks like:
7760 .. code-block:: text
7762 refs: ((Ref)[, (Ref)]*)
7764 where each ``Ref`` contains a reference to the summary id of the referenced
7765 value (e.g. ``^1``).
7767 .. _typeidinfo_summary:
7772 The optional ``TypeIdInfo`` field, used for
7773 `Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
7776 .. code-block:: text
7778 typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]?
7780 These optional fields have the following forms:
7785 .. code-block:: text
7787 typeTests: (TypeIdRef[, TypeIdRef]*)
7789 Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
7790 by summary id or ``GUID``.
7792 TypeTestAssumeVCalls
7793 """"""""""""""""""""
7795 .. code-block:: text
7797 typeTestAssumeVCalls: (VFuncId[, VFuncId]*)
7799 Where each VFuncId has the format:
7801 .. code-block:: text
7803 vFuncId: (TypeIdRef, offset: 16)
7805 Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
7806 by summary id or ``GUID`` preceded by a ``guid:`` tag.
7808 TypeCheckedLoadVCalls
7809 """""""""""""""""""""
7811 .. code-block:: text
7813 typeCheckedLoadVCalls: (VFuncId[, VFuncId]*)
7815 Where each VFuncId has the format described for ``TypeTestAssumeVCalls``.
7817 TypeTestAssumeConstVCalls
7818 """""""""""""""""""""""""
7820 .. code-block:: text
7822 typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*)
7824 Where each ConstVCall has the format:
7826 .. code-block:: text
7828 (VFuncId, args: (Arg[, Arg]*))
7830 and where each VFuncId has the format described for ``TypeTestAssumeVCalls``,
7831 and each Arg is an integer argument number.
7833 TypeCheckedLoadConstVCalls
7834 """"""""""""""""""""""""""
7836 .. code-block:: text
7838 typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*)
7840 Where each ConstVCall has the format described for
7841 ``TypeTestAssumeConstVCalls``.
7845 Type ID Summary Entry
7846 ---------------------
7848 Each type id summary entry corresponds to a type identifier resolution
7849 which is generated during the LTO link portion of the compile when building
7850 with `Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
7851 so these are only present in a combined summary index.
7855 .. code-block:: text
7857 ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778
7859 The ``typeTestRes`` gives the type test resolution ``kind`` (which may
7860 be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and
7861 the ``size-1`` bit width. It is followed by optional flags, which default to 0,
7862 and an optional WpdResolutions (whole program devirtualization resolution)
7863 field that looks like:
7865 .. code-block:: text
7867 wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]*
7869 where each entry is a mapping from the given byte offset to the whole-program
7870 devirtualization resolution WpdRes, that has one of the following formats:
7872 .. code-block:: text
7874 wpdRes: (kind: branchFunnel)
7875 wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi")
7876 wpdRes: (kind: indir)
7878 Additionally, each wpdRes has an optional ``resByArg`` field, which
7879 describes the resolutions for calls with all constant integer arguments:
7881 .. code-block:: text
7883 resByArg: (ResByArg[, ResByArg]*)
7887 .. code-block:: text
7889 args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0])
7891 Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal``
7892 or ``VirtualConstProp``. The ``info`` field is only used if the kind
7893 is ``UniformRetVal`` (indicates the uniform return value), or
7894 ``UniqueRetVal`` (holds the return value associated with the unique vtable
7895 (0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does
7896 not support the use of absolute symbols to store constants.
7898 .. _intrinsicglobalvariables:
7900 Intrinsic Global Variables
7901 ==========================
7903 LLVM has a number of "magic" global variables that contain data that
7904 affect code generation or other IR semantics. These are documented here.
7905 All globals of this sort should have a section specified as
7906 "``llvm.metadata``". This section and all globals that start with
7907 "``llvm.``" are reserved for use by LLVM.
7911 The '``llvm.used``' Global Variable
7912 -----------------------------------
7914 The ``@llvm.used`` global is an array which has
7915 :ref:`appending linkage <linkage_appending>`. This array contains a list of
7916 pointers to named global variables, functions and aliases which may optionally
7917 have a pointer cast formed of bitcast or getelementptr. For example, a legal
7920 .. code-block:: llvm
7925 @llvm.used = appending global [2 x ptr] [
7928 ], section "llvm.metadata"
7930 If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler,
7931 and linker are required to treat the symbol as if there is a reference to the
7932 symbol that it cannot see (which is why they have to be named). For example, if
7933 a variable has internal linkage and no references other than that from the
7934 ``@llvm.used`` list, it cannot be deleted. This is commonly used to represent
7935 references from inline asms and other things the compiler cannot "see", and
7936 corresponds to "``attribute((used))``" in GNU C.
7938 On some targets, the code generator must emit a directive to the
7939 assembler or object file to prevent the assembler and linker from
7940 removing the symbol.
7942 .. _gv_llvmcompilerused:
7944 The '``llvm.compiler.used``' Global Variable
7945 --------------------------------------------
7947 The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used``
7948 directive, except that it only prevents the compiler from touching the
7949 symbol. On targets that support it, this allows an intelligent linker to
7950 optimize references to the symbol without being impeded as it would be
7953 This is a rare construct that should only be used in rare circumstances,
7954 and should not be exposed to source languages.
7956 .. _gv_llvmglobalctors:
7958 The '``llvm.global_ctors``' Global Variable
7959 -------------------------------------------
7961 .. code-block:: llvm
7963 %0 = type { i32, ptr, ptr }
7964 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, ptr @ctor, ptr @data }]
7966 The ``@llvm.global_ctors`` array contains a list of constructor
7967 functions, priorities, and an associated global or function.
7968 The functions referenced by this array will be called in ascending order
7969 of priority (i.e. lowest first) when the module is loaded. The order of
7970 functions with the same priority is not defined.
7972 If the third field is non-null, and points to a global variable
7973 or function, the initializer function will only run if the associated
7974 data from the current module is not discarded.
7975 On ELF the referenced global variable or function must be in a comdat.
7977 .. _llvmglobaldtors:
7979 The '``llvm.global_dtors``' Global Variable
7980 -------------------------------------------
7982 .. code-block:: llvm
7984 %0 = type { i32, ptr, ptr }
7985 @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, ptr @dtor, ptr @data }]
7987 The ``@llvm.global_dtors`` array contains a list of destructor
7988 functions, priorities, and an associated global or function.
7989 The functions referenced by this array will be called in descending
7990 order of priority (i.e. highest first) when the module is unloaded. The
7991 order of functions with the same priority is not defined.
7993 If the third field is non-null, and points to a global variable
7994 or function, the destructor function will only run if the associated
7995 data from the current module is not discarded.
7996 On ELF the referenced global variable or function must be in a comdat.
7998 Instruction Reference
7999 =====================
8001 The LLVM instruction set consists of several different classifications
8002 of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
8003 instructions <binaryops>`, :ref:`bitwise binary
8004 instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
8005 :ref:`other instructions <otherops>`.
8009 Terminator Instructions
8010 -----------------------
8012 As mentioned :ref:`previously <functionstructure>`, every basic block in a
8013 program ends with a "Terminator" instruction, which indicates which
8014 block should be executed after the current block is finished. These
8015 terminator instructions typically yield a '``void``' value: they produce
8016 control flow, not values (the one exception being the
8017 ':ref:`invoke <i_invoke>`' instruction).
8019 The terminator instructions are: ':ref:`ret <i_ret>`',
8020 ':ref:`br <i_br>`', ':ref:`switch <i_switch>`',
8021 ':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`',
8022 ':ref:`callbr <i_callbr>`'
8023 ':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`',
8024 ':ref:`catchret <i_catchret>`',
8025 ':ref:`cleanupret <i_cleanupret>`',
8026 and ':ref:`unreachable <i_unreachable>`'.
8030 '``ret``' Instruction
8031 ^^^^^^^^^^^^^^^^^^^^^
8038 ret <type> <value> ; Return a value from a non-void function
8039 ret void ; Return from void function
8044 The '``ret``' instruction is used to return control flow (and optionally
8045 a value) from a function back to the caller.
8047 There are two forms of the '``ret``' instruction: one that returns a
8048 value and then causes control flow, and one that just causes control
8054 The '``ret``' instruction optionally accepts a single argument, the
8055 return value. The type of the return value must be a ':ref:`first
8056 class <t_firstclass>`' type.
8058 A function is not :ref:`well formed <wellformed>` if it has a non-void
8059 return type and contains a '``ret``' instruction with no return value or
8060 a return value with a type that does not match its type, or if it has a
8061 void return type and contains a '``ret``' instruction with a return
8067 When the '``ret``' instruction is executed, control flow returns back to
8068 the calling function's context. If the caller is a
8069 ":ref:`call <i_call>`" instruction, execution continues at the
8070 instruction after the call. If the caller was an
8071 ":ref:`invoke <i_invoke>`" instruction, execution continues at the
8072 beginning of the "normal" destination block. If the instruction returns
8073 a value, that value shall set the call or invoke instruction's return
8079 .. code-block:: llvm
8081 ret i32 5 ; Return an integer value of 5
8082 ret void ; Return from a void function
8083 ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2
8087 '``br``' Instruction
8088 ^^^^^^^^^^^^^^^^^^^^
8095 br i1 <cond>, label <iftrue>, label <iffalse>
8096 br label <dest> ; Unconditional branch
8101 The '``br``' instruction is used to cause control flow to transfer to a
8102 different basic block in the current function. There are two forms of
8103 this instruction, corresponding to a conditional branch and an
8104 unconditional branch.
8109 The conditional branch form of the '``br``' instruction takes a single
8110 '``i1``' value and two '``label``' values. The unconditional form of the
8111 '``br``' instruction takes a single '``label``' value as a target.
8116 Upon execution of a conditional '``br``' instruction, the '``i1``'
8117 argument is evaluated. If the value is ``true``, control flows to the
8118 '``iftrue``' ``label`` argument. If "cond" is ``false``, control flows
8119 to the '``iffalse``' ``label`` argument.
8120 If '``cond``' is ``poison`` or ``undef``, this instruction has undefined
8126 .. code-block:: llvm
8129 %cond = icmp eq i32 %a, %b
8130 br i1 %cond, label %IfEqual, label %IfUnequal
8138 '``switch``' Instruction
8139 ^^^^^^^^^^^^^^^^^^^^^^^^
8146 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
8151 The '``switch``' instruction is used to transfer control flow to one of
8152 several different places. It is a generalization of the '``br``'
8153 instruction, allowing a branch to occur to one of many possible
8159 The '``switch``' instruction uses three parameters: an integer
8160 comparison value '``value``', a default '``label``' destination, and an
8161 array of pairs of comparison value constants and '``label``'s. The table
8162 is not allowed to contain duplicate constant entries.
8167 The ``switch`` instruction specifies a table of values and destinations.
8168 When the '``switch``' instruction is executed, this table is searched
8169 for the given value. If the value is found, control flow is transferred
8170 to the corresponding destination; otherwise, control flow is transferred
8171 to the default destination.
8172 If '``value``' is ``poison`` or ``undef``, this instruction has undefined
8178 Depending on properties of the target machine and the particular
8179 ``switch`` instruction, this instruction may be code generated in
8180 different ways. For example, it could be generated as a series of
8181 chained conditional branches or with a lookup table.
8186 .. code-block:: llvm
8188 ; Emulate a conditional br instruction
8189 %Val = zext i1 %value to i32
8190 switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
8192 ; Emulate an unconditional br instruction
8193 switch i32 0, label %dest [ ]
8195 ; Implement a jump table:
8196 switch i32 %val, label %otherwise [ i32 0, label %onzero
8198 i32 2, label %ontwo ]
8202 '``indirectbr``' Instruction
8203 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8210 indirectbr ptr <address>, [ label <dest1>, label <dest2>, ... ]
8215 The '``indirectbr``' instruction implements an indirect branch to a
8216 label within the current function, whose address is specified by
8217 "``address``". Address must be derived from a
8218 :ref:`blockaddress <blockaddress>` constant.
8223 The '``address``' argument is the address of the label to jump to. The
8224 rest of the arguments indicate the full set of possible destinations
8225 that the address may point to. Blocks are allowed to occur multiple
8226 times in the destination list, though this isn't particularly useful.
8228 This destination list is required so that dataflow analysis has an
8229 accurate understanding of the CFG.
8234 Control transfers to the block specified in the address argument. All
8235 possible destination blocks must be listed in the label list, otherwise
8236 this instruction has undefined behavior. This implies that jumps to
8237 labels defined in other functions have undefined behavior as well.
8238 If '``address``' is ``poison`` or ``undef``, this instruction has undefined
8244 This is typically implemented with a jump through a register.
8249 .. code-block:: llvm
8251 indirectbr ptr %Addr, [ label %bb1, label %bb2, label %bb3 ]
8255 '``invoke``' Instruction
8256 ^^^^^^^^^^^^^^^^^^^^^^^^
8263 <result> = invoke [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
8264 [operand bundles] to label <normal label> unwind label <exception label>
8269 The '``invoke``' instruction causes control to transfer to a specified
8270 function, with the possibility of control flow transfer to either the
8271 '``normal``' label or the '``exception``' label. If the callee function
8272 returns with the "``ret``" instruction, control flow will return to the
8273 "normal" label. If the callee (or any indirect callees) returns via the
8274 ":ref:`resume <i_resume>`" instruction or other exception handling
8275 mechanism, control is interrupted and continued at the dynamically
8276 nearest "exception" label.
8278 The '``exception``' label is a `landing
8279 pad <ExceptionHandling.html#overview>`_ for the exception. As such,
8280 '``exception``' label is required to have the
8281 ":ref:`landingpad <i_landingpad>`" instruction, which contains the
8282 information about the behavior of the program after unwinding happens,
8283 as its first non-PHI instruction. The restrictions on the
8284 "``landingpad``" instruction's tightly couples it to the "``invoke``"
8285 instruction, so that the important information contained within the
8286 "``landingpad``" instruction can't be lost through normal code motion.
8291 This instruction requires several arguments:
8293 #. The optional "cconv" marker indicates which :ref:`calling
8294 convention <callingconv>` the call should use. If none is
8295 specified, the call defaults to using C calling conventions.
8296 #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
8297 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
8299 #. The optional addrspace attribute can be used to indicate the address space
8300 of the called function. If it is not specified, the program address space
8301 from the :ref:`datalayout string<langref_datalayout>` will be used.
8302 #. '``ty``': the type of the call instruction itself which is also the
8303 type of the return value. Functions that return no value are marked
8305 #. '``fnty``': shall be the signature of the function being invoked. The
8306 argument types must match the types implied by this signature. This
8307 type can be omitted if the function is not varargs.
8308 #. '``fnptrval``': An LLVM value containing a pointer to a function to
8309 be invoked. In most cases, this is a direct function invocation, but
8310 indirect ``invoke``'s are just as possible, calling an arbitrary pointer
8312 #. '``function args``': argument list whose types match the function
8313 signature argument types and parameter attributes. All arguments must
8314 be of :ref:`first class <t_firstclass>` type. If the function signature
8315 indicates the function accepts a variable number of arguments, the
8316 extra arguments can be specified.
8317 #. '``normal label``': the label reached when the called function
8318 executes a '``ret``' instruction.
8319 #. '``exception label``': the label reached when a callee returns via
8320 the :ref:`resume <i_resume>` instruction or other exception handling
8322 #. The optional :ref:`function attributes <fnattrs>` list.
8323 #. The optional :ref:`operand bundles <opbundles>` list.
8328 This instruction is designed to operate as a standard '``call``'
8329 instruction in most regards. The primary difference is that it
8330 establishes an association with a label, which is used by the runtime
8331 library to unwind the stack.
8333 This instruction is used in languages with destructors to ensure that
8334 proper cleanup is performed in the case of either a ``longjmp`` or a
8335 thrown exception. Additionally, this is important for implementation of
8336 '``catch``' clauses in high-level languages that support them.
8338 For the purposes of the SSA form, the definition of the value returned
8339 by the '``invoke``' instruction is deemed to occur on the edge from the
8340 current block to the "normal" label. If the callee unwinds then no
8341 return value is available.
8346 .. code-block:: llvm
8348 %retval = invoke i32 @Test(i32 15) to label %Continue
8349 unwind label %TestCleanup ; i32:retval set
8350 %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue
8351 unwind label %TestCleanup ; i32:retval set
8355 '``callbr``' Instruction
8356 ^^^^^^^^^^^^^^^^^^^^^^^^
8363 <result> = callbr [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
8364 [operand bundles] to label <fallthrough label> [indirect labels]
8369 The '``callbr``' instruction causes control to transfer to a specified
8370 function, with the possibility of control flow transfer to either the
8371 '``fallthrough``' label or one of the '``indirect``' labels.
8373 This instruction should only be used to implement the "goto" feature of gcc
8374 style inline assembly. Any other usage is an error in the IR verifier.
8379 This instruction requires several arguments:
8381 #. The optional "cconv" marker indicates which :ref:`calling
8382 convention <callingconv>` the call should use. If none is
8383 specified, the call defaults to using C calling conventions.
8384 #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
8385 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
8387 #. The optional addrspace attribute can be used to indicate the address space
8388 of the called function. If it is not specified, the program address space
8389 from the :ref:`datalayout string<langref_datalayout>` will be used.
8390 #. '``ty``': the type of the call instruction itself which is also the
8391 type of the return value. Functions that return no value are marked
8393 #. '``fnty``': shall be the signature of the function being called. The
8394 argument types must match the types implied by this signature. This
8395 type can be omitted if the function is not varargs.
8396 #. '``fnptrval``': An LLVM value containing a pointer to a function to
8397 be called. In most cases, this is a direct function call, but
8398 other ``callbr``'s are just as possible, calling an arbitrary pointer
8400 #. '``function args``': argument list whose types match the function
8401 signature argument types and parameter attributes. All arguments must
8402 be of :ref:`first class <t_firstclass>` type. If the function signature
8403 indicates the function accepts a variable number of arguments, the
8404 extra arguments can be specified.
8405 #. '``fallthrough label``': the label reached when the inline assembly's
8406 execution exits the bottom.
8407 #. '``indirect labels``': the labels reached when a callee transfers control
8408 to a location other than the '``fallthrough label``'. Label constraints
8409 refer to these destinations.
8410 #. The optional :ref:`function attributes <fnattrs>` list.
8411 #. The optional :ref:`operand bundles <opbundles>` list.
8416 This instruction is designed to operate as a standard '``call``'
8417 instruction in most regards. The primary difference is that it
8418 establishes an association with additional labels to define where control
8419 flow goes after the call.
8421 The output values of a '``callbr``' instruction are available only to
8422 the '``fallthrough``' block, not to any '``indirect``' blocks(s).
8424 The only use of this today is to implement the "goto" feature of gcc inline
8425 assembly where additional labels can be provided as locations for the inline
8426 assembly to jump to.
8431 .. code-block:: llvm
8433 ; "asm goto" without output constraints.
8434 callbr void asm "", "r,!i"(i32 %x)
8435 to label %fallthrough [label %indirect]
8437 ; "asm goto" with output constraints.
8438 <result> = callbr i32 asm "", "=r,r,!i"(i32 %x)
8439 to label %fallthrough [label %indirect]
8443 '``resume``' Instruction
8444 ^^^^^^^^^^^^^^^^^^^^^^^^
8451 resume <type> <value>
8456 The '``resume``' instruction is a terminator instruction that has no
8462 The '``resume``' instruction requires one argument, which must have the
8463 same type as the result of any '``landingpad``' instruction in the same
8469 The '``resume``' instruction resumes propagation of an existing
8470 (in-flight) exception whose unwinding was interrupted with a
8471 :ref:`landingpad <i_landingpad>` instruction.
8476 .. code-block:: llvm
8478 resume { ptr, i32 } %exn
8482 '``catchswitch``' Instruction
8483 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8490 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller
8491 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default>
8496 The '``catchswitch``' instruction is used by `LLVM's exception handling system
8497 <ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers
8498 that may be executed by the :ref:`EH personality routine <personalityfn>`.
8503 The ``parent`` argument is the token of the funclet that contains the
8504 ``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet,
8505 this operand may be the token ``none``.
8507 The ``default`` argument is the label of another basic block beginning with
8508 either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination
8509 must be a legal target with respect to the ``parent`` links, as described in
8510 the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
8512 The ``handlers`` are a nonempty list of successor blocks that each begin with a
8513 :ref:`catchpad <i_catchpad>` instruction.
8518 Executing this instruction transfers control to one of the successors in
8519 ``handlers``, if appropriate, or continues to unwind via the unwind label if
8522 The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that
8523 it must be both the first non-phi instruction and last instruction in the basic
8524 block. Therefore, it must be the only non-phi instruction in the block.
8529 .. code-block:: text
8532 %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller
8534 %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup
8538 '``catchret``' Instruction
8539 ^^^^^^^^^^^^^^^^^^^^^^^^^^
8546 catchret from <token> to label <normal>
8551 The '``catchret``' instruction is a terminator instruction that has a
8558 The first argument to a '``catchret``' indicates which ``catchpad`` it
8559 exits. It must be a :ref:`catchpad <i_catchpad>`.
8560 The second argument to a '``catchret``' specifies where control will
8566 The '``catchret``' instruction ends an existing (in-flight) exception whose
8567 unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The
8568 :ref:`personality function <personalityfn>` gets a chance to execute arbitrary
8569 code to, for example, destroy the active exception. Control then transfers to
8572 The ``token`` argument must be a token produced by a ``catchpad`` instruction.
8573 If the specified ``catchpad`` is not the most-recently-entered not-yet-exited
8574 funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
8575 the ``catchret``'s behavior is undefined.
8580 .. code-block:: text
8582 catchret from %catch to label %continue
8586 '``cleanupret``' Instruction
8587 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8594 cleanupret from <value> unwind label <continue>
8595 cleanupret from <value> unwind to caller
8600 The '``cleanupret``' instruction is a terminator instruction that has
8601 an optional successor.
8607 The '``cleanupret``' instruction requires one argument, which indicates
8608 which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`.
8609 If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited
8610 funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
8611 the ``cleanupret``'s behavior is undefined.
8613 The '``cleanupret``' instruction also has an optional successor, ``continue``,
8614 which must be the label of another basic block beginning with either a
8615 ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must
8616 be a legal target with respect to the ``parent`` links, as described in the
8617 `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
8622 The '``cleanupret``' instruction indicates to the
8623 :ref:`personality function <personalityfn>` that one
8624 :ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended.
8625 It transfers control to ``continue`` or unwinds out of the function.
8630 .. code-block:: text
8632 cleanupret from %cleanup unwind to caller
8633 cleanupret from %cleanup unwind label %continue
8637 '``unreachable``' Instruction
8638 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8650 The '``unreachable``' instruction has no defined semantics. This
8651 instruction is used to inform the optimizer that a particular portion of
8652 the code is not reachable. This can be used to indicate that the code
8653 after a no-return function cannot be reached, and other facts.
8658 The '``unreachable``' instruction has no defined semantics.
8665 Unary operators require a single operand, execute an operation on
8666 it, and produce a single value. The operand might represent multiple
8667 data, as is the case with the :ref:`vector <t_vector>` data type. The
8668 result value has the same type as its operand.
8672 '``fneg``' Instruction
8673 ^^^^^^^^^^^^^^^^^^^^^^
8680 <result> = fneg [fast-math flags]* <ty> <op1> ; yields ty:result
8685 The '``fneg``' instruction returns the negation of its operand.
8690 The argument to the '``fneg``' instruction must be a
8691 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
8692 floating-point values.
8697 The value produced is a copy of the operand with its sign bit flipped.
8698 This instruction can also take any number of :ref:`fast-math
8699 flags <fastmath>`, which are optimization hints to enable otherwise
8700 unsafe floating-point optimizations:
8705 .. code-block:: text
8707 <result> = fneg float %val ; yields float:result = -%var
8714 Binary operators are used to do most of the computation in a program.
8715 They require two operands of the same type, execute an operation on
8716 them, and produce a single value. The operands might represent multiple
8717 data, as is the case with the :ref:`vector <t_vector>` data type. The
8718 result value has the same type as its operands.
8720 There are several different binary operators:
8724 '``add``' Instruction
8725 ^^^^^^^^^^^^^^^^^^^^^
8732 <result> = add <ty> <op1>, <op2> ; yields ty:result
8733 <result> = add nuw <ty> <op1>, <op2> ; yields ty:result
8734 <result> = add nsw <ty> <op1>, <op2> ; yields ty:result
8735 <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result
8740 The '``add``' instruction returns the sum of its two operands.
8745 The two arguments to the '``add``' instruction must be
8746 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
8747 arguments must have identical types.
8752 The value produced is the integer sum of the two operands.
8754 If the sum has unsigned overflow, the result returned is the
8755 mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
8758 Because LLVM integers use a two's complement representation, this
8759 instruction is appropriate for both signed and unsigned integers.
8761 ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
8762 respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
8763 result value of the ``add`` is a :ref:`poison value <poisonvalues>` if
8764 unsigned and/or signed overflow, respectively, occurs.
8769 .. code-block:: text
8771 <result> = add i32 4, %var ; yields i32:result = 4 + %var
8775 '``fadd``' Instruction
8776 ^^^^^^^^^^^^^^^^^^^^^^
8783 <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
8788 The '``fadd``' instruction returns the sum of its two operands.
8793 The two arguments to the '``fadd``' instruction must be
8794 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
8795 floating-point values. Both arguments must have identical types.
8800 The value produced is the floating-point sum of the two operands.
8801 This instruction is assumed to execute in the default :ref:`floating-point
8802 environment <floatenv>`.
8803 This instruction can also take any number of :ref:`fast-math
8804 flags <fastmath>`, which are optimization hints to enable otherwise
8805 unsafe floating-point optimizations:
8810 .. code-block:: text
8812 <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var
8816 '``sub``' Instruction
8817 ^^^^^^^^^^^^^^^^^^^^^
8824 <result> = sub <ty> <op1>, <op2> ; yields ty:result
8825 <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result
8826 <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result
8827 <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result
8832 The '``sub``' instruction returns the difference of its two operands.
8834 Note that the '``sub``' instruction is used to represent the '``neg``'
8835 instruction present in most other intermediate representations.
8840 The two arguments to the '``sub``' instruction must be
8841 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
8842 arguments must have identical types.
8847 The value produced is the integer difference of the two operands.
8849 If the difference has unsigned overflow, the result returned is the
8850 mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
8853 Because LLVM integers use a two's complement representation, this
8854 instruction is appropriate for both signed and unsigned integers.
8856 ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
8857 respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
8858 result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if
8859 unsigned and/or signed overflow, respectively, occurs.
8864 .. code-block:: text
8866 <result> = sub i32 4, %var ; yields i32:result = 4 - %var
8867 <result> = sub i32 0, %val ; yields i32:result = -%var
8871 '``fsub``' Instruction
8872 ^^^^^^^^^^^^^^^^^^^^^^
8879 <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
8884 The '``fsub``' instruction returns the difference of its two operands.
8889 The two arguments to the '``fsub``' instruction must be
8890 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
8891 floating-point values. Both arguments must have identical types.
8896 The value produced is the floating-point difference of the two operands.
8897 This instruction is assumed to execute in the default :ref:`floating-point
8898 environment <floatenv>`.
8899 This instruction can also take any number of :ref:`fast-math
8900 flags <fastmath>`, which are optimization hints to enable otherwise
8901 unsafe floating-point optimizations:
8906 .. code-block:: text
8908 <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var
8909 <result> = fsub float -0.0, %val ; yields float:result = -%var
8913 '``mul``' Instruction
8914 ^^^^^^^^^^^^^^^^^^^^^
8921 <result> = mul <ty> <op1>, <op2> ; yields ty:result
8922 <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result
8923 <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result
8924 <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result
8929 The '``mul``' instruction returns the product of its two operands.
8934 The two arguments to the '``mul``' instruction must be
8935 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
8936 arguments must have identical types.
8941 The value produced is the integer product of the two operands.
8943 If the result of the multiplication has unsigned overflow, the result
8944 returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the
8945 bit width of the result.
8947 Because LLVM integers use a two's complement representation, and the
8948 result is the same width as the operands, this instruction returns the
8949 correct result for both signed and unsigned integers. If a full product
8950 (e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be
8951 sign-extended or zero-extended as appropriate to the width of the full
8954 ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
8955 respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
8956 result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if
8957 unsigned and/or signed overflow, respectively, occurs.
8962 .. code-block:: text
8964 <result> = mul i32 4, %var ; yields i32:result = 4 * %var
8968 '``fmul``' Instruction
8969 ^^^^^^^^^^^^^^^^^^^^^^
8976 <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
8981 The '``fmul``' instruction returns the product of its two operands.
8986 The two arguments to the '``fmul``' instruction must be
8987 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
8988 floating-point values. Both arguments must have identical types.
8993 The value produced is the floating-point product of the two operands.
8994 This instruction is assumed to execute in the default :ref:`floating-point
8995 environment <floatenv>`.
8996 This instruction can also take any number of :ref:`fast-math
8997 flags <fastmath>`, which are optimization hints to enable otherwise
8998 unsafe floating-point optimizations:
9003 .. code-block:: text
9005 <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var
9009 '``udiv``' Instruction
9010 ^^^^^^^^^^^^^^^^^^^^^^
9017 <result> = udiv <ty> <op1>, <op2> ; yields ty:result
9018 <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result
9023 The '``udiv``' instruction returns the quotient of its two operands.
9028 The two arguments to the '``udiv``' instruction must be
9029 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9030 arguments must have identical types.
9035 The value produced is the unsigned integer quotient of the two operands.
9037 Note that unsigned integer division and signed integer division are
9038 distinct operations; for signed integer division, use '``sdiv``'.
9040 Division by zero is undefined behavior. For vectors, if any element
9041 of the divisor is zero, the operation has undefined behavior.
9044 If the ``exact`` keyword is present, the result value of the ``udiv`` is
9045 a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as
9046 such, "((a udiv exact b) mul b) == a").
9051 .. code-block:: text
9053 <result> = udiv i32 4, %var ; yields i32:result = 4 / %var
9057 '``sdiv``' Instruction
9058 ^^^^^^^^^^^^^^^^^^^^^^
9065 <result> = sdiv <ty> <op1>, <op2> ; yields ty:result
9066 <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result
9071 The '``sdiv``' instruction returns the quotient of its two operands.
9076 The two arguments to the '``sdiv``' instruction must be
9077 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9078 arguments must have identical types.
9083 The value produced is the signed integer quotient of the two operands
9084 rounded towards zero.
9086 Note that signed integer division and unsigned integer division are
9087 distinct operations; for unsigned integer division, use '``udiv``'.
9089 Division by zero is undefined behavior. For vectors, if any element
9090 of the divisor is zero, the operation has undefined behavior.
9091 Overflow also leads to undefined behavior; this is a rare case, but can
9092 occur, for example, by doing a 32-bit division of -2147483648 by -1.
9094 If the ``exact`` keyword is present, the result value of the ``sdiv`` is
9095 a :ref:`poison value <poisonvalues>` if the result would be rounded.
9100 .. code-block:: text
9102 <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var
9106 '``fdiv``' Instruction
9107 ^^^^^^^^^^^^^^^^^^^^^^
9114 <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
9119 The '``fdiv``' instruction returns the quotient of its two operands.
9124 The two arguments to the '``fdiv``' instruction must be
9125 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9126 floating-point values. Both arguments must have identical types.
9131 The value produced is the floating-point quotient of the two operands.
9132 This instruction is assumed to execute in the default :ref:`floating-point
9133 environment <floatenv>`.
9134 This instruction can also take any number of :ref:`fast-math
9135 flags <fastmath>`, which are optimization hints to enable otherwise
9136 unsafe floating-point optimizations:
9141 .. code-block:: text
9143 <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var
9147 '``urem``' Instruction
9148 ^^^^^^^^^^^^^^^^^^^^^^
9155 <result> = urem <ty> <op1>, <op2> ; yields ty:result
9160 The '``urem``' instruction returns the remainder from the unsigned
9161 division of its two arguments.
9166 The two arguments to the '``urem``' instruction must be
9167 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9168 arguments must have identical types.
9173 This instruction returns the unsigned integer *remainder* of a division.
9174 This instruction always performs an unsigned division to get the
9177 Note that unsigned integer remainder and signed integer remainder are
9178 distinct operations; for signed integer remainder, use '``srem``'.
9180 Taking the remainder of a division by zero is undefined behavior.
9181 For vectors, if any element of the divisor is zero, the operation has
9187 .. code-block:: text
9189 <result> = urem i32 4, %var ; yields i32:result = 4 % %var
9193 '``srem``' Instruction
9194 ^^^^^^^^^^^^^^^^^^^^^^
9201 <result> = srem <ty> <op1>, <op2> ; yields ty:result
9206 The '``srem``' instruction returns the remainder from the signed
9207 division of its two operands. This instruction can also take
9208 :ref:`vector <t_vector>` versions of the values in which case the elements
9214 The two arguments to the '``srem``' instruction must be
9215 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9216 arguments must have identical types.
9221 This instruction returns the *remainder* of a division (where the result
9222 is either zero or has the same sign as the dividend, ``op1``), not the
9223 *modulo* operator (where the result is either zero or has the same sign
9224 as the divisor, ``op2``) of a value. For more information about the
9225 difference, see `The Math
9226 Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a
9227 table of how this is implemented in various languages, please see
9229 operation <http://en.wikipedia.org/wiki/Modulo_operation>`_.
9231 Note that signed integer remainder and unsigned integer remainder are
9232 distinct operations; for unsigned integer remainder, use '``urem``'.
9234 Taking the remainder of a division by zero is undefined behavior.
9235 For vectors, if any element of the divisor is zero, the operation has
9237 Overflow also leads to undefined behavior; this is a rare case, but can
9238 occur, for example, by taking the remainder of a 32-bit division of
9239 -2147483648 by -1. (The remainder doesn't actually overflow, but this
9240 rule lets srem be implemented using instructions that return both the
9241 result of the division and the remainder.)
9246 .. code-block:: text
9248 <result> = srem i32 4, %var ; yields i32:result = 4 % %var
9252 '``frem``' Instruction
9253 ^^^^^^^^^^^^^^^^^^^^^^
9260 <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
9265 The '``frem``' instruction returns the remainder from the division of
9271 The two arguments to the '``frem``' instruction must be
9272 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
9273 floating-point values. Both arguments must have identical types.
9278 The value produced is the floating-point remainder of the two operands.
9279 This is the same output as a libm '``fmod``' function, but without any
9280 possibility of setting ``errno``. The remainder has the same sign as the
9282 This instruction is assumed to execute in the default :ref:`floating-point
9283 environment <floatenv>`.
9284 This instruction can also take any number of :ref:`fast-math
9285 flags <fastmath>`, which are optimization hints to enable otherwise
9286 unsafe floating-point optimizations:
9291 .. code-block:: text
9293 <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var
9297 Bitwise Binary Operations
9298 -------------------------
9300 Bitwise binary operators are used to do various forms of bit-twiddling
9301 in a program. They are generally very efficient instructions and can
9302 commonly be strength reduced from other instructions. They require two
9303 operands of the same type, execute an operation on them, and produce a
9304 single value. The resulting value is the same type as its operands.
9308 '``shl``' Instruction
9309 ^^^^^^^^^^^^^^^^^^^^^
9316 <result> = shl <ty> <op1>, <op2> ; yields ty:result
9317 <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result
9318 <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result
9319 <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result
9324 The '``shl``' instruction returns the first operand shifted to the left
9325 a specified number of bits.
9330 Both arguments to the '``shl``' instruction must be the same
9331 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
9332 '``op2``' is treated as an unsigned value.
9337 The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`,
9338 where ``n`` is the width of the result. If ``op2`` is (statically or
9339 dynamically) equal to or larger than the number of bits in
9340 ``op1``, this instruction returns a :ref:`poison value <poisonvalues>`.
9341 If the arguments are vectors, each vector element of ``op1`` is shifted
9342 by the corresponding shift amount in ``op2``.
9344 If the ``nuw`` keyword is present, then the shift produces a poison
9345 value if it shifts out any non-zero bits.
9346 If the ``nsw`` keyword is present, then the shift produces a poison
9347 value if it shifts out any bits that disagree with the resultant sign bit.
9352 .. code-block:: text
9354 <result> = shl i32 4, %var ; yields i32: 4 << %var
9355 <result> = shl i32 4, 2 ; yields i32: 16
9356 <result> = shl i32 1, 10 ; yields i32: 1024
9357 <result> = shl i32 1, 32 ; undefined
9358 <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4>
9363 '``lshr``' Instruction
9364 ^^^^^^^^^^^^^^^^^^^^^^
9371 <result> = lshr <ty> <op1>, <op2> ; yields ty:result
9372 <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result
9377 The '``lshr``' instruction (logical shift right) returns the first
9378 operand shifted to the right a specified number of bits with zero fill.
9383 Both arguments to the '``lshr``' instruction must be the same
9384 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
9385 '``op2``' is treated as an unsigned value.
9390 This instruction always performs a logical shift right operation. The
9391 most significant bits of the result will be filled with zero bits after
9392 the shift. If ``op2`` is (statically or dynamically) equal to or larger
9393 than the number of bits in ``op1``, this instruction returns a :ref:`poison
9394 value <poisonvalues>`. If the arguments are vectors, each vector element
9395 of ``op1`` is shifted by the corresponding shift amount in ``op2``.
9397 If the ``exact`` keyword is present, the result value of the ``lshr`` is
9398 a poison value if any of the bits shifted out are non-zero.
9403 .. code-block:: text
9405 <result> = lshr i32 4, 1 ; yields i32:result = 2
9406 <result> = lshr i32 4, 2 ; yields i32:result = 1
9407 <result> = lshr i8 4, 3 ; yields i8:result = 0
9408 <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F
9409 <result> = lshr i32 1, 32 ; undefined
9410 <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1>
9414 '``ashr``' Instruction
9415 ^^^^^^^^^^^^^^^^^^^^^^
9422 <result> = ashr <ty> <op1>, <op2> ; yields ty:result
9423 <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result
9428 The '``ashr``' instruction (arithmetic shift right) returns the first
9429 operand shifted to the right a specified number of bits with sign
9435 Both arguments to the '``ashr``' instruction must be the same
9436 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
9437 '``op2``' is treated as an unsigned value.
9442 This instruction always performs an arithmetic shift right operation,
9443 The most significant bits of the result will be filled with the sign bit
9444 of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger
9445 than the number of bits in ``op1``, this instruction returns a :ref:`poison
9446 value <poisonvalues>`. If the arguments are vectors, each vector element
9447 of ``op1`` is shifted by the corresponding shift amount in ``op2``.
9449 If the ``exact`` keyword is present, the result value of the ``ashr`` is
9450 a poison value if any of the bits shifted out are non-zero.
9455 .. code-block:: text
9457 <result> = ashr i32 4, 1 ; yields i32:result = 2
9458 <result> = ashr i32 4, 2 ; yields i32:result = 1
9459 <result> = ashr i8 4, 3 ; yields i8:result = 0
9460 <result> = ashr i8 -2, 1 ; yields i8:result = -1
9461 <result> = ashr i32 1, 32 ; undefined
9462 <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0>
9466 '``and``' Instruction
9467 ^^^^^^^^^^^^^^^^^^^^^
9474 <result> = and <ty> <op1>, <op2> ; yields ty:result
9479 The '``and``' instruction returns the bitwise logical and of its two
9485 The two arguments to the '``and``' instruction must be
9486 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9487 arguments must have identical types.
9492 The truth table used for the '``and``' instruction is:
9509 .. code-block:: text
9511 <result> = and i32 4, %var ; yields i32:result = 4 & %var
9512 <result> = and i32 15, 40 ; yields i32:result = 8
9513 <result> = and i32 4, 8 ; yields i32:result = 0
9517 '``or``' Instruction
9518 ^^^^^^^^^^^^^^^^^^^^
9525 <result> = or <ty> <op1>, <op2> ; yields ty:result
9530 The '``or``' instruction returns the bitwise logical inclusive or of its
9536 The two arguments to the '``or``' instruction must be
9537 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9538 arguments must have identical types.
9543 The truth table used for the '``or``' instruction is:
9562 <result> = or i32 4, %var ; yields i32:result = 4 | %var
9563 <result> = or i32 15, 40 ; yields i32:result = 47
9564 <result> = or i32 4, 8 ; yields i32:result = 12
9568 '``xor``' Instruction
9569 ^^^^^^^^^^^^^^^^^^^^^
9576 <result> = xor <ty> <op1>, <op2> ; yields ty:result
9581 The '``xor``' instruction returns the bitwise logical exclusive or of
9582 its two operands. The ``xor`` is used to implement the "one's
9583 complement" operation, which is the "~" operator in C.
9588 The two arguments to the '``xor``' instruction must be
9589 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
9590 arguments must have identical types.
9595 The truth table used for the '``xor``' instruction is:
9612 .. code-block:: text
9614 <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var
9615 <result> = xor i32 15, 40 ; yields i32:result = 39
9616 <result> = xor i32 4, 8 ; yields i32:result = 12
9617 <result> = xor i32 %V, -1 ; yields i32:result = ~%V
9622 LLVM supports several instructions to represent vector operations in a
9623 target-independent manner. These instructions cover the element-access
9624 and vector-specific operations needed to process vectors effectively.
9625 While LLVM does directly support these vector operations, many
9626 sophisticated algorithms will want to use target-specific intrinsics to
9627 take full advantage of a specific target.
9629 .. _i_extractelement:
9631 '``extractelement``' Instruction
9632 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9639 <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty>
9640 <result> = extractelement <vscale x n x <ty>> <val>, <ty2> <idx> ; yields <ty>
9645 The '``extractelement``' instruction extracts a single scalar element
9646 from a vector at a specified index.
9651 The first operand of an '``extractelement``' instruction is a value of
9652 :ref:`vector <t_vector>` type. The second operand is an index indicating
9653 the position from which to extract the element. The index may be a
9654 variable of any integer type.
9659 The result is a scalar of the same type as the element type of ``val``.
9660 Its value is the value at position ``idx`` of ``val``. If ``idx``
9661 exceeds the length of ``val`` for a fixed-length vector, the result is a
9662 :ref:`poison value <poisonvalues>`. For a scalable vector, if the value
9663 of ``idx`` exceeds the runtime length of the vector, the result is a
9664 :ref:`poison value <poisonvalues>`.
9669 .. code-block:: text
9671 <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32
9673 .. _i_insertelement:
9675 '``insertelement``' Instruction
9676 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9683 <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>>
9684 <result> = insertelement <vscale x n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <vscale x n x <ty>>
9689 The '``insertelement``' instruction inserts a scalar element into a
9690 vector at a specified index.
9695 The first operand of an '``insertelement``' instruction is a value of
9696 :ref:`vector <t_vector>` type. The second operand is a scalar value whose
9697 type must equal the element type of the first operand. The third operand
9698 is an index indicating the position at which to insert the value. The
9699 index may be a variable of any integer type.
9704 The result is a vector of the same type as ``val``. Its element values
9705 are those of ``val`` except at position ``idx``, where it gets the value
9706 ``elt``. If ``idx`` exceeds the length of ``val`` for a fixed-length vector,
9707 the result is a :ref:`poison value <poisonvalues>`. For a scalable vector,
9708 if the value of ``idx`` exceeds the runtime length of the vector, the result
9709 is a :ref:`poison value <poisonvalues>`.
9714 .. code-block:: text
9716 <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32>
9718 .. _i_shufflevector:
9720 '``shufflevector``' Instruction
9721 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9728 <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>>
9729 <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>>
9734 The '``shufflevector``' instruction constructs a permutation of elements
9735 from two input vectors, returning a vector with the same element type as
9736 the input and length that is the same as the shuffle mask.
9741 The first two operands of a '``shufflevector``' instruction are vectors
9742 with the same type. The third argument is a shuffle mask vector constant
9743 whose element type is ``i32``. The mask vector elements must be constant
9744 integers or ``undef`` values. The result of the instruction is a vector
9745 whose length is the same as the shuffle mask and whose element type is the
9746 same as the element type of the first two operands.
9751 The elements of the two input vectors are numbered from left to right
9752 across both of the vectors. For each element of the result vector, the
9753 shuffle mask selects an element from one of the input vectors to copy
9754 to the result. Non-negative elements in the mask represent an index
9755 into the concatenated pair of input vectors.
9757 If the shuffle mask is undefined, the result vector is undefined. If
9758 the shuffle mask selects an undefined element from one of the input
9759 vectors, the resulting element is undefined. An undefined element
9760 in the mask vector specifies that the resulting element is undefined.
9761 An undefined element in the mask vector prevents a poisoned vector
9762 element from propagating.
9764 For scalable vectors, the only valid mask values at present are
9765 ``zeroinitializer`` and ``undef``, since we cannot write all indices as
9766 literals for a vector with a length unknown at compile time.
9771 .. code-block:: text
9773 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
9774 <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32>
9775 <result> = shufflevector <4 x i32> %v1, <4 x i32> undef,
9776 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle.
9777 <result> = shufflevector <8 x i32> %v1, <8 x i32> undef,
9778 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32>
9779 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
9780 <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32>
9782 Aggregate Operations
9783 --------------------
9785 LLVM supports several instructions for working with
9786 :ref:`aggregate <t_aggregate>` values.
9790 '``extractvalue``' Instruction
9791 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9798 <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
9803 The '``extractvalue``' instruction extracts the value of a member field
9804 from an :ref:`aggregate <t_aggregate>` value.
9809 The first operand of an '``extractvalue``' instruction is a value of
9810 :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are
9811 constant indices to specify which value to extract in a similar manner
9812 as indices in a '``getelementptr``' instruction.
9814 The major differences to ``getelementptr`` indexing are:
9816 - Since the value being indexed is not a pointer, the first index is
9817 omitted and assumed to be zero.
9818 - At least one index must be specified.
9819 - Not only struct indices but also array indices must be in bounds.
9824 The result is the value at the position in the aggregate specified by
9830 .. code-block:: text
9832 <result> = extractvalue {i32, float} %agg, 0 ; yields i32
9836 '``insertvalue``' Instruction
9837 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9844 <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type>
9849 The '``insertvalue``' instruction inserts a value into a member field in
9850 an :ref:`aggregate <t_aggregate>` value.
9855 The first operand of an '``insertvalue``' instruction is a value of
9856 :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is
9857 a first-class value to insert. The following operands are constant
9858 indices indicating the position at which to insert the value in a
9859 similar manner as indices in a '``extractvalue``' instruction. The value
9860 to insert must have the same type as the value identified by the
9866 The result is an aggregate of the same type as ``val``. Its value is
9867 that of ``val`` except that the value at the position specified by the
9868 indices is that of ``elt``.
9873 .. code-block:: llvm
9875 %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef}
9876 %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val}
9877 %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}}
9881 Memory Access and Addressing Operations
9882 ---------------------------------------
9884 A key design point of an SSA-based representation is how it represents
9885 memory. In LLVM, no memory locations are in SSA form, which makes things
9886 very simple. This section describes how to read, write, and allocate
9891 '``alloca``' Instruction
9892 ^^^^^^^^^^^^^^^^^^^^^^^^
9899 <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result
9904 The '``alloca``' instruction allocates memory on the stack frame of the
9905 currently executing function, to be automatically released when this
9906 function returns to its caller. If the address space is not explicitly
9907 specified, the object is allocated in the alloca address space from the
9908 :ref:`datalayout string<langref_datalayout>`.
9913 The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements``
9914 bytes of memory on the runtime stack, returning a pointer of the
9915 appropriate type to the program. If "NumElements" is specified, it is
9916 the number of elements allocated, otherwise "NumElements" is defaulted
9917 to be one. If a constant alignment is specified, the value result of the
9918 allocation is guaranteed to be aligned to at least that boundary. The
9919 alignment may not be greater than ``1 << 32``. If not specified, or if
9920 zero, the target can choose to align the allocation on any convenient
9921 boundary compatible with the type.
9923 '``type``' may be any sized type.
9928 Memory is allocated; a pointer is returned. The allocated memory is
9929 uninitialized, and loading from uninitialized memory produces an undefined
9930 value. The operation itself is undefined if there is insufficient stack
9931 space for the allocation.'``alloca``'d memory is automatically released
9932 when the function returns. The '``alloca``' instruction is commonly used
9933 to represent automatic variables that must have an address available. When
9934 the function returns (either with the ``ret`` or ``resume`` instructions),
9935 the memory is reclaimed. Allocating zero bytes is legal, but the returned
9936 pointer may not be unique. The order in which memory is allocated (ie.,
9937 which way the stack grows) is not specified.
9939 Note that '``alloca``' outside of the alloca address space from the
9940 :ref:`datalayout string<langref_datalayout>` is meaningful only if the
9941 target has assigned it a semantics.
9943 If the returned pointer is used by :ref:`llvm.lifetime.start <int_lifestart>`,
9944 the returned object is initially dead.
9945 See :ref:`llvm.lifetime.start <int_lifestart>` and
9946 :ref:`llvm.lifetime.end <int_lifeend>` for the precise semantics of
9947 lifetime-manipulating intrinsics.
9952 .. code-block:: llvm
9954 %ptr = alloca i32 ; yields ptr
9955 %ptr = alloca i32, i32 4 ; yields ptr
9956 %ptr = alloca i32, i32 4, align 1024 ; yields ptr
9957 %ptr = alloca i32, align 1024 ; yields ptr
9961 '``load``' Instruction
9962 ^^^^^^^^^^^^^^^^^^^^^^
9969 <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>]
9970 <result> = load atomic [volatile] <ty>, ptr <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>]
9971 !<nontemp_node> = !{ i32 1 }
9973 !<deref_bytes_node> = !{ i64 <dereferenceable_bytes> }
9974 !<align_node> = !{ i64 <value_alignment> }
9979 The '``load``' instruction is used to read from memory.
9984 The argument to the ``load`` instruction specifies the memory address from which
9985 to load. The type specified must be a :ref:`first class <t_firstclass>` type of
9986 known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If
9987 the ``load`` is marked as ``volatile``, then the optimizer is not allowed to
9988 modify the number or order of execution of this ``load`` with other
9989 :ref:`volatile operations <volatile>`.
9991 If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering
9992 <ordering>` and optional ``syncscope("<target-scope>")`` argument. The
9993 ``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions.
9994 Atomic loads produce :ref:`defined <memmodel>` results when they may see
9995 multiple atomic stores. The type of the pointee must be an integer, pointer, or
9996 floating-point type whose bit width is a power of two greater than or equal to
9997 eight and less than or equal to a target-specific size limit. ``align`` must be
9998 explicitly specified on atomic loads, and the load has undefined behavior if the
9999 alignment is not set to a value which is at least the size in bytes of the
10000 pointee. ``!nontemporal`` does not have any defined semantics for atomic loads.
10002 The optional constant ``align`` argument specifies the alignment of the
10003 operation (that is, the alignment of the memory address). A value of 0
10004 or an omitted ``align`` argument means that the operation has the ABI
10005 alignment for the target. It is the responsibility of the code emitter
10006 to ensure that the alignment information is correct. Overestimating the
10007 alignment results in undefined behavior. Underestimating the alignment
10008 may produce less efficient code. An alignment of 1 is always safe. The
10009 maximum possible alignment is ``1 << 32``. An alignment value higher
10010 than the size of the loaded type implies memory up to the alignment
10011 value bytes can be safely loaded without trapping in the default
10012 address space. Access of the high bytes can interfere with debugging
10013 tools, so should not be accessed if the function has the
10014 ``sanitize_thread`` or ``sanitize_address`` attributes.
10016 The optional ``!nontemporal`` metadata must reference a single
10017 metadata name ``<nontemp_node>`` corresponding to a metadata node with one
10018 ``i32`` entry of value 1. The existence of the ``!nontemporal``
10019 metadata on the instruction tells the optimizer and code generator
10020 that this load is not expected to be reused in the cache. The code
10021 generator may select special instructions to save cache bandwidth, such
10022 as the ``MOVNT`` instruction on x86.
10024 The optional ``!invariant.load`` metadata must reference a single
10025 metadata name ``<empty_node>`` corresponding to a metadata node with no
10026 entries. If a load instruction tagged with the ``!invariant.load``
10027 metadata is executed, the memory location referenced by the load has
10028 to contain the same value at all points in the program where the
10029 memory location is dereferenceable; otherwise, the behavior is
10032 The optional ``!invariant.group`` metadata must reference a single metadata name
10033 ``<empty_node>`` corresponding to a metadata node with no entries.
10034 See ``invariant.group`` metadata :ref:`invariant.group <md_invariant.group>`.
10036 The optional ``!nonnull`` metadata must reference a single
10037 metadata name ``<empty_node>`` corresponding to a metadata node with no
10038 entries. The existence of the ``!nonnull`` metadata on the
10039 instruction tells the optimizer that the value loaded is known to
10040 never be null. If the value is null at runtime, the behavior is undefined.
10041 This is analogous to the ``nonnull`` attribute on parameters and return
10042 values. This metadata can only be applied to loads of a pointer type.
10044 The optional ``!dereferenceable`` metadata must reference a single metadata
10045 name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
10047 See ``dereferenceable`` metadata :ref:`dereferenceable <md_dereferenceable>`.
10049 The optional ``!dereferenceable_or_null`` metadata must reference a single
10050 metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
10052 See ``dereferenceable_or_null`` metadata :ref:`dereferenceable_or_null
10053 <md_dereferenceable_or_null>`.
10055 The optional ``!align`` metadata must reference a single metadata name
10056 ``<align_node>`` corresponding to a metadata node with one ``i64`` entry.
10057 The existence of the ``!align`` metadata on the instruction tells the
10058 optimizer that the value loaded is known to be aligned to a boundary specified
10059 by the integer value in the metadata node. The alignment must be a power of 2.
10060 This is analogous to the ''align'' attribute on parameters and return values.
10061 This metadata can only be applied to loads of a pointer type. If the returned
10062 value is not appropriately aligned at runtime, the behavior is undefined.
10064 The optional ``!noundef`` metadata must reference a single metadata name
10065 ``<empty_node>`` corresponding to a node with no entries. The existence of
10066 ``!noundef`` metadata on the instruction tells the optimizer that the value
10067 loaded is known to be :ref:`well defined <welldefinedvalues>`.
10068 If the value isn't well defined, the behavior is undefined.
10073 The location of memory pointed to is loaded. If the value being loaded
10074 is of scalar type then the number of bytes read does not exceed the
10075 minimum number of bytes needed to hold all bits of the type. For
10076 example, loading an ``i24`` reads at most three bytes. When loading a
10077 value of a type like ``i20`` with a size that is not an integral number
10078 of bytes, the result is undefined if the value was not originally
10079 written using a store of the same type.
10080 If the value being loaded is of aggregate type, the bytes that correspond to
10081 padding may be accessed but are ignored, because it is impossible to observe
10082 padding from the loaded aggregate value.
10083 If ``<pointer>`` is not a well-defined value, the behavior is undefined.
10088 .. code-block:: llvm
10090 %ptr = alloca i32 ; yields ptr
10091 store i32 3, ptr %ptr ; yields void
10092 %val = load i32, ptr %ptr ; yields i32:val = i32 3
10096 '``store``' Instruction
10097 ^^^^^^^^^^^^^^^^^^^^^^^
10104 store [volatile] <ty> <value>, ptr <pointer>[, align <alignment>][, !nontemporal !<nontemp_node>][, !invariant.group !<empty_node>] ; yields void
10105 store atomic [volatile] <ty> <value>, ptr <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>] ; yields void
10106 !<nontemp_node> = !{ i32 1 }
10107 !<empty_node> = !{}
10112 The '``store``' instruction is used to write to memory.
10117 There are two arguments to the ``store`` instruction: a value to store and an
10118 address at which to store it. The type of the ``<pointer>`` operand must be a
10119 pointer to the :ref:`first class <t_firstclass>` type of the ``<value>``
10120 operand. If the ``store`` is marked as ``volatile``, then the optimizer is not
10121 allowed to modify the number or order of execution of this ``store`` with other
10122 :ref:`volatile operations <volatile>`. Only values of :ref:`first class
10123 <t_firstclass>` types of known size (i.e. not containing an :ref:`opaque
10124 structural type <t_opaque>`) can be stored.
10126 If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering
10127 <ordering>` and optional ``syncscope("<target-scope>")`` argument. The
10128 ``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions.
10129 Atomic loads produce :ref:`defined <memmodel>` results when they may see
10130 multiple atomic stores. The type of the pointee must be an integer, pointer, or
10131 floating-point type whose bit width is a power of two greater than or equal to
10132 eight and less than or equal to a target-specific size limit. ``align`` must be
10133 explicitly specified on atomic stores, and the store has undefined behavior if
10134 the alignment is not set to a value which is at least the size in bytes of the
10135 pointee. ``!nontemporal`` does not have any defined semantics for atomic stores.
10137 The optional constant ``align`` argument specifies the alignment of the
10138 operation (that is, the alignment of the memory address). A value of 0
10139 or an omitted ``align`` argument means that the operation has the ABI
10140 alignment for the target. It is the responsibility of the code emitter
10141 to ensure that the alignment information is correct. Overestimating the
10142 alignment results in undefined behavior. Underestimating the
10143 alignment may produce less efficient code. An alignment of 1 is always
10144 safe. The maximum possible alignment is ``1 << 32``. An alignment
10145 value higher than the size of the stored type implies memory up to the
10146 alignment value bytes can be stored to without trapping in the default
10147 address space. Storing to the higher bytes however may result in data
10148 races if another thread can access the same address. Introducing a
10149 data race is not allowed. Storing to the extra bytes is not allowed
10150 even in situations where a data race is known to not exist if the
10151 function has the ``sanitize_address`` attribute.
10153 The optional ``!nontemporal`` metadata must reference a single metadata
10154 name ``<nontemp_node>`` corresponding to a metadata node with one ``i32`` entry
10155 of value 1. The existence of the ``!nontemporal`` metadata on the instruction
10156 tells the optimizer and code generator that this load is not expected to
10157 be reused in the cache. The code generator may select special
10158 instructions to save cache bandwidth, such as the ``MOVNT`` instruction on
10161 The optional ``!invariant.group`` metadata must reference a
10162 single metadata name ``<empty_node>``. See ``invariant.group`` metadata.
10167 The contents of memory are updated to contain ``<value>`` at the
10168 location specified by the ``<pointer>`` operand. If ``<value>`` is
10169 of scalar type then the number of bytes written does not exceed the
10170 minimum number of bytes needed to hold all bits of the type. For
10171 example, storing an ``i24`` writes at most three bytes. When writing a
10172 value of a type like ``i20`` with a size that is not an integral number
10173 of bytes, it is unspecified what happens to the extra bits that do not
10174 belong to the type, but they will typically be overwritten.
10175 If ``<value>`` is of aggregate type, padding is filled with
10176 :ref:`undef <undefvalues>`.
10177 If ``<pointer>`` is not a well-defined value, the behavior is undefined.
10182 .. code-block:: llvm
10184 %ptr = alloca i32 ; yields ptr
10185 store i32 3, ptr %ptr ; yields void
10186 %val = load i32, ptr %ptr ; yields i32:val = i32 3
10190 '``fence``' Instruction
10191 ^^^^^^^^^^^^^^^^^^^^^^^
10198 fence [syncscope("<target-scope>")] <ordering> ; yields void
10203 The '``fence``' instruction is used to introduce happens-before edges
10204 between operations.
10209 '``fence``' instructions take an :ref:`ordering <ordering>` argument which
10210 defines what *synchronizes-with* edges they add. They can only be given
10211 ``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings.
10216 A fence A which has (at least) ``release`` ordering semantics
10217 *synchronizes with* a fence B with (at least) ``acquire`` ordering
10218 semantics if and only if there exist atomic operations X and Y, both
10219 operating on some atomic object M, such that A is sequenced before X, X
10220 modifies M (either directly or through some side effect of a sequence
10221 headed by X), Y is sequenced before B, and Y observes M. This provides a
10222 *happens-before* dependency between A and B. Rather than an explicit
10223 ``fence``, one (but not both) of the atomic operations X or Y might
10224 provide a ``release`` or ``acquire`` (resp.) ordering constraint and
10225 still *synchronize-with* the explicit ``fence`` and establish the
10226 *happens-before* edge.
10228 A ``fence`` which has ``seq_cst`` ordering, in addition to having both
10229 ``acquire`` and ``release`` semantics specified above, participates in
10230 the global program order of other ``seq_cst`` operations and/or fences.
10232 A ``fence`` instruction can also take an optional
10233 ":ref:`syncscope <syncscope>`" argument.
10238 .. code-block:: text
10240 fence acquire ; yields void
10241 fence syncscope("singlethread") seq_cst ; yields void
10242 fence syncscope("agent") seq_cst ; yields void
10246 '``cmpxchg``' Instruction
10247 ^^^^^^^^^^^^^^^^^^^^^^^^^
10254 cmpxchg [weak] [volatile] ptr <pointer>, <ty> <cmp>, <ty> <new> [syncscope("<target-scope>")] <success ordering> <failure ordering>[, align <alignment>] ; yields { ty, i1 }
10259 The '``cmpxchg``' instruction is used to atomically modify memory. It
10260 loads a value in memory and compares it to a given value. If they are
10261 equal, it tries to store a new value into the memory.
10266 There are three arguments to the '``cmpxchg``' instruction: an address
10267 to operate on, a value to compare to the value currently be at that
10268 address, and a new value to place at that address if the compared values
10269 are equal. The type of '<cmp>' must be an integer or pointer type whose
10270 bit width is a power of two greater than or equal to eight and less
10271 than or equal to a target-specific size limit. '<cmp>' and '<new>' must
10272 have the same type, and the type of '<pointer>' must be a pointer to
10273 that type. If the ``cmpxchg`` is marked as ``volatile``, then the
10274 optimizer is not allowed to modify the number or order of execution of
10275 this ``cmpxchg`` with other :ref:`volatile operations <volatile>`.
10277 The success and failure :ref:`ordering <ordering>` arguments specify how this
10278 ``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters
10279 must be at least ``monotonic``, the failure ordering cannot be either
10280 ``release`` or ``acq_rel``.
10282 A ``cmpxchg`` instruction can also take an optional
10283 ":ref:`syncscope <syncscope>`" argument.
10285 The instruction can take an optional ``align`` attribute.
10286 The alignment must be a power of two greater or equal to the size of the
10287 `<value>` type. If unspecified, the alignment is assumed to be equal to the
10288 size of the '<value>' type. Note that this default alignment assumption is
10289 different from the alignment used for the load/store instructions when align
10292 The pointer passed into cmpxchg must have alignment greater than or
10293 equal to the size in memory of the operand.
10298 The contents of memory at the location specified by the '``<pointer>``' operand
10299 is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is
10300 written to the location. The original value at the location is returned,
10301 together with a flag indicating success (true) or failure (false).
10303 If the cmpxchg operation is marked as ``weak`` then a spurious failure is
10304 permitted: the operation may not write ``<new>`` even if the comparison
10307 If the cmpxchg operation is strong (the default), the i1 value is 1 if and only
10308 if the value loaded equals ``cmp``.
10310 A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of
10311 identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic
10312 load with an ordering parameter determined the second ordering parameter.
10317 .. code-block:: llvm
10320 %orig = load atomic i32, ptr %ptr unordered, align 4 ; yields i32
10324 %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop]
10325 %squared = mul i32 %cmp, %cmp
10326 %val_success = cmpxchg ptr %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 }
10327 %value_loaded = extractvalue { i32, i1 } %val_success, 0
10328 %success = extractvalue { i32, i1 } %val_success, 1
10329 br i1 %success, label %done, label %loop
10336 '``atomicrmw``' Instruction
10337 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10344 atomicrmw [volatile] <operation> ptr <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering>[, align <alignment>] ; yields ty
10349 The '``atomicrmw``' instruction is used to atomically modify memory.
10354 There are three arguments to the '``atomicrmw``' instruction: an
10355 operation to apply, an address whose value to modify, an argument to the
10356 operation. The operation must be one of the following keywords:
10374 For most of these operations, the type of '<value>' must be an integer
10375 type whose bit width is a power of two greater than or equal to eight
10376 and less than or equal to a target-specific size limit. For xchg, this
10377 may also be a floating point or a pointer type with the same size constraints
10378 as integers. For fadd/fsub/fmax/fmin, this must be a floating point type. The
10379 type of the '``<pointer>``' operand must be a pointer to that type. If
10380 the ``atomicrmw`` is marked as ``volatile``, then the optimizer is not
10381 allowed to modify the number or order of execution of this
10382 ``atomicrmw`` with other :ref:`volatile operations <volatile>`.
10384 The instruction can take an optional ``align`` attribute.
10385 The alignment must be a power of two greater or equal to the size of the
10386 `<value>` type. If unspecified, the alignment is assumed to be equal to the
10387 size of the '<value>' type. Note that this default alignment assumption is
10388 different from the alignment used for the load/store instructions when align
10391 A ``atomicrmw`` instruction can also take an optional
10392 ":ref:`syncscope <syncscope>`" argument.
10397 The contents of memory at the location specified by the '``<pointer>``'
10398 operand are atomically read, modified, and written back. The original
10399 value at the location is returned. The modification is specified by the
10400 operation argument:
10402 - xchg: ``*ptr = val``
10403 - add: ``*ptr = *ptr + val``
10404 - sub: ``*ptr = *ptr - val``
10405 - and: ``*ptr = *ptr & val``
10406 - nand: ``*ptr = ~(*ptr & val)``
10407 - or: ``*ptr = *ptr | val``
10408 - xor: ``*ptr = *ptr ^ val``
10409 - max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison)
10410 - min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison)
10411 - umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned comparison)
10412 - umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned comparison)
10413 - fadd: ``*ptr = *ptr + val`` (using floating point arithmetic)
10414 - fsub: ``*ptr = *ptr - val`` (using floating point arithmetic)
10415 - fmax: ``*ptr = maxnum(*ptr, val)`` (match the `llvm.maxnum.*`` intrinsic)
10416 - fmin: ``*ptr = minnum(*ptr, val)`` (match the `llvm.minnum.*`` intrinsic)
10421 .. code-block:: llvm
10423 %old = atomicrmw add ptr %ptr, i32 1 acquire ; yields i32
10425 .. _i_getelementptr:
10427 '``getelementptr``' Instruction
10428 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10435 <result> = getelementptr <ty>, ptr <ptrval>{, [inrange] <ty> <idx>}*
10436 <result> = getelementptr inbounds <ty>, ptr <ptrval>{, [inrange] <ty> <idx>}*
10437 <result> = getelementptr <ty>, <N x ptr> <ptrval>, [inrange] <vector index type> <idx>
10442 The '``getelementptr``' instruction is used to get the address of a
10443 subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs
10444 address calculation only and does not access memory. The instruction can also
10445 be used to calculate a vector of such addresses.
10450 The first argument is always a type used as the basis for the calculations.
10451 The second argument is always a pointer or a vector of pointers, and is the
10452 base address to start from. The remaining arguments are indices
10453 that indicate which of the elements of the aggregate object are indexed.
10454 The interpretation of each index is dependent on the type being indexed
10455 into. The first index always indexes the pointer value given as the
10456 second argument, the second index indexes a value of the type pointed to
10457 (not necessarily the value directly pointed to, since the first index
10458 can be non-zero), etc. The first type indexed into must be a pointer
10459 value, subsequent types can be arrays, vectors, and structs. Note that
10460 subsequent types being indexed into can never be pointers, since that
10461 would require loading the pointer before continuing calculation.
10463 The type of each index argument depends on the type it is indexing into.
10464 When indexing into a (optionally packed) structure, only ``i32`` integer
10465 **constants** are allowed (when using a vector of indices they must all
10466 be the **same** ``i32`` integer constant). When indexing into an array,
10467 pointer or vector, integers of any width are allowed, and they are not
10468 required to be constant. These integers are treated as signed values
10471 For example, let's consider a C code fragment and how it gets compiled
10487 int *foo(struct ST *s) {
10488 return &s[1].Z.B[5][13];
10491 The LLVM code generated by Clang is:
10493 .. code-block:: llvm
10495 %struct.RT = type { i8, [10 x [20 x i32]], i8 }
10496 %struct.ST = type { i32, double, %struct.RT }
10498 define ptr @foo(ptr %s) nounwind uwtable readnone optsize ssp {
10500 %arrayidx = getelementptr inbounds %struct.ST, ptr %s, i64 1, i32 2, i32 1, i64 5, i64 13
10507 In the example above, the first index is indexing into the
10508 '``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``'
10509 = '``{ i32, double, %struct.RT }``' type, a structure. The second index
10510 indexes into the third element of the structure, yielding a
10511 '``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another
10512 structure. The third index indexes into the second element of the
10513 structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two
10514 dimensions of the array are subscripted into, yielding an '``i32``'
10515 type. The '``getelementptr``' instruction returns a pointer to this
10518 Note that it is perfectly legal to index partially through a structure,
10519 returning a pointer to an inner element. Because of this, the LLVM code
10520 for the given testcase is equivalent to:
10522 .. code-block:: llvm
10524 define ptr @foo(ptr %s) {
10525 %t1 = getelementptr %struct.ST, ptr %s, i32 1
10526 %t2 = getelementptr %struct.ST, ptr %t1, i32 0, i32 2
10527 %t3 = getelementptr %struct.RT, ptr %t2, i32 0, i32 1
10528 %t4 = getelementptr [10 x [20 x i32]], ptr %t3, i32 0, i32 5
10529 %t5 = getelementptr [20 x i32], ptr %t4, i32 0, i32 13
10533 If the ``inbounds`` keyword is present, the result value of the
10534 ``getelementptr`` is a :ref:`poison value <poisonvalues>` if one of the
10535 following rules is violated:
10537 * The base pointer has an *in bounds* address of an allocated object, which
10538 means that it points into an allocated object, or to its end. The only
10539 *in bounds* address for a null pointer in the default address-space is the
10540 null pointer itself.
10541 * If the type of an index is larger than the pointer index type, the
10542 truncation to the pointer index type preserves the signed value.
10543 * The multiplication of an index by the type size does not wrap the pointer
10544 index type in a signed sense (``nsw``).
10545 * The successive addition of offsets (without adding the base address) does
10546 not wrap the pointer index type in a signed sense (``nsw``).
10547 * The successive addition of the current address, interpreted as an unsigned
10548 number, and an offset, interpreted as a signed number, does not wrap the
10549 unsigned address space and remains *in bounds* of the allocated object.
10550 As a corollary, if the added offset is non-negative, the addition does not
10551 wrap in an unsigned sense (``nuw``).
10552 * In cases where the base is a vector of pointers, the ``inbounds`` keyword
10553 applies to each of the computations element-wise.
10555 These rules are based on the assumption that no allocated object may cross
10556 the unsigned address space boundary, and no allocated object may be larger
10557 than half the pointer index type space.
10559 If the ``inbounds`` keyword is not present, the offsets are added to the
10560 base address with silently-wrapping two's complement arithmetic. If the
10561 offsets have a different width from the pointer, they are sign-extended
10562 or truncated to the width of the pointer. The result value of the
10563 ``getelementptr`` may be outside the object pointed to by the base
10564 pointer. The result value may not necessarily be used to access memory
10565 though, even if it happens to point into allocated storage. See the
10566 :ref:`Pointer Aliasing Rules <pointeraliasing>` section for more
10569 If the ``inrange`` keyword is present before any index, loading from or
10570 storing to any pointer derived from the ``getelementptr`` has undefined
10571 behavior if the load or store would access memory outside of the bounds of
10572 the element selected by the index marked as ``inrange``. The result of a
10573 pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations
10574 involving memory) involving a pointer derived from a ``getelementptr`` with
10575 the ``inrange`` keyword is undefined, with the exception of comparisons
10576 in the case where both operands are in the range of the element selected
10577 by the ``inrange`` keyword, inclusive of the address one past the end of
10578 that element. Note that the ``inrange`` keyword is currently only allowed
10579 in constant ``getelementptr`` expressions.
10581 The getelementptr instruction is often confusing. For some more insight
10582 into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`.
10587 .. code-block:: llvm
10589 %aptr = getelementptr {i32, [12 x i8]}, ptr %saptr, i64 0, i32 1
10590 %vptr = getelementptr {i32, <2 x i8>}, ptr %svptr, i64 0, i32 1, i32 1
10591 %eptr = getelementptr [12 x i8], ptr %aptr, i64 0, i32 1
10592 %iptr = getelementptr [10 x i32], ptr @arr, i16 0, i16 0
10594 Vector of pointers:
10595 """""""""""""""""""
10597 The ``getelementptr`` returns a vector of pointers, instead of a single address,
10598 when one or more of its arguments is a vector. In such cases, all vector
10599 arguments should have the same number of elements, and every scalar argument
10600 will be effectively broadcast into a vector during address calculation.
10602 .. code-block:: llvm
10604 ; All arguments are vectors:
10605 ; A[i] = ptrs[i] + offsets[i]*sizeof(i8)
10606 %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets
10608 ; Add the same scalar offset to each pointer of a vector:
10609 ; A[i] = ptrs[i] + offset*sizeof(i8)
10610 %A = getelementptr i8, <4 x ptr> %ptrs, i64 %offset
10612 ; Add distinct offsets to the same pointer:
10613 ; A[i] = ptr + offsets[i]*sizeof(i8)
10614 %A = getelementptr i8, ptr %ptr, <4 x i64> %offsets
10616 ; In all cases described above the type of the result is <4 x ptr>
10618 The two following instructions are equivalent:
10620 .. code-block:: llvm
10622 getelementptr %struct.ST, <4 x ptr> %s, <4 x i64> %ind1,
10623 <4 x i32> <i32 2, i32 2, i32 2, i32 2>,
10624 <4 x i32> <i32 1, i32 1, i32 1, i32 1>,
10626 <4 x i64> <i64 13, i64 13, i64 13, i64 13>
10628 getelementptr %struct.ST, <4 x ptr> %s, <4 x i64> %ind1,
10629 i32 2, i32 1, <4 x i32> %ind4, i64 13
10631 Let's look at the C code, where the vector version of ``getelementptr``
10636 // Let's assume that we vectorize the following loop:
10637 double *A, *B; int *C;
10638 for (int i = 0; i < size; ++i) {
10642 .. code-block:: llvm
10644 ; get pointers for 8 elements from array B
10645 %ptrs = getelementptr double, ptr %B, <8 x i32> %C
10646 ; load 8 elements from array B into A
10647 %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x ptr> %ptrs,
10648 i32 8, <8 x i1> %mask, <8 x double> %passthru)
10650 Conversion Operations
10651 ---------------------
10653 The instructions in this category are the conversion instructions
10654 (casting) which all take a single operand and a type. They perform
10655 various bit conversions on the operand.
10659 '``trunc .. to``' Instruction
10660 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10667 <result> = trunc <ty> <value> to <ty2> ; yields ty2
10672 The '``trunc``' instruction truncates its operand to the type ``ty2``.
10677 The '``trunc``' instruction takes a value to trunc, and a type to trunc
10678 it to. Both types must be of :ref:`integer <t_integer>` types, or vectors
10679 of the same number of integers. The bit size of the ``value`` must be
10680 larger than the bit size of the destination type, ``ty2``. Equal sized
10681 types are not allowed.
10686 The '``trunc``' instruction truncates the high order bits in ``value``
10687 and converts the remaining bits to ``ty2``. Since the source size must
10688 be larger than the destination size, ``trunc`` cannot be a *no-op cast*.
10689 It will always truncate bits.
10694 .. code-block:: llvm
10696 %X = trunc i32 257 to i8 ; yields i8:1
10697 %Y = trunc i32 123 to i1 ; yields i1:true
10698 %Z = trunc i32 122 to i1 ; yields i1:false
10699 %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7>
10703 '``zext .. to``' Instruction
10704 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10711 <result> = zext <ty> <value> to <ty2> ; yields ty2
10716 The '``zext``' instruction zero extends its operand to type ``ty2``.
10721 The '``zext``' instruction takes a value to cast, and a type to cast it
10722 to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
10723 the same number of integers. The bit size of the ``value`` must be
10724 smaller than the bit size of the destination type, ``ty2``.
10729 The ``zext`` fills the high order bits of the ``value`` with zero bits
10730 until it reaches the size of the destination type, ``ty2``.
10732 When zero extending from i1, the result will always be either 0 or 1.
10737 .. code-block:: llvm
10739 %X = zext i32 257 to i64 ; yields i64:257
10740 %Y = zext i1 true to i32 ; yields i32:1
10741 %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
10745 '``sext .. to``' Instruction
10746 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10753 <result> = sext <ty> <value> to <ty2> ; yields ty2
10758 The '``sext``' sign extends ``value`` to the type ``ty2``.
10763 The '``sext``' instruction takes a value to cast, and a type to cast it
10764 to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
10765 the same number of integers. The bit size of the ``value`` must be
10766 smaller than the bit size of the destination type, ``ty2``.
10771 The '``sext``' instruction performs a sign extension by copying the sign
10772 bit (highest order bit) of the ``value`` until it reaches the bit size
10773 of the type ``ty2``.
10775 When sign extending from i1, the extension always results in -1 or 0.
10780 .. code-block:: llvm
10782 %X = sext i8 -1 to i16 ; yields i16 :65535
10783 %Y = sext i1 true to i32 ; yields i32:-1
10784 %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
10786 '``fptrunc .. to``' Instruction
10787 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10794 <result> = fptrunc <ty> <value> to <ty2> ; yields ty2
10799 The '``fptrunc``' instruction truncates ``value`` to type ``ty2``.
10804 The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>`
10805 value to cast and a :ref:`floating-point <t_floating>` type to cast it to.
10806 The size of ``value`` must be larger than the size of ``ty2``. This
10807 implies that ``fptrunc`` cannot be used to make a *no-op cast*.
10812 The '``fptrunc``' instruction casts a ``value`` from a larger
10813 :ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
10814 <t_floating>` type.
10815 This instruction is assumed to execute in the default :ref:`floating-point
10816 environment <floatenv>`.
10821 .. code-block:: llvm
10823 %X = fptrunc double 16777217.0 to float ; yields float:16777216.0
10824 %Y = fptrunc double 1.0E+300 to half ; yields half:+infinity
10826 '``fpext .. to``' Instruction
10827 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10834 <result> = fpext <ty> <value> to <ty2> ; yields ty2
10839 The '``fpext``' extends a floating-point ``value`` to a larger floating-point
10845 The '``fpext``' instruction takes a :ref:`floating-point <t_floating>`
10846 ``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it
10847 to. The source type must be smaller than the destination type.
10852 The '``fpext``' instruction extends the ``value`` from a smaller
10853 :ref:`floating-point <t_floating>` type to a larger :ref:`floating-point
10854 <t_floating>` type. The ``fpext`` cannot be used to make a
10855 *no-op cast* because it always changes bits. Use ``bitcast`` to make a
10856 *no-op cast* for a floating-point cast.
10861 .. code-block:: llvm
10863 %X = fpext float 3.125 to double ; yields double:3.125000e+00
10864 %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000
10866 '``fptoui .. to``' Instruction
10867 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10874 <result> = fptoui <ty> <value> to <ty2> ; yields ty2
10879 The '``fptoui``' converts a floating-point ``value`` to its unsigned
10880 integer equivalent of type ``ty2``.
10885 The '``fptoui``' instruction takes a value to cast, which must be a
10886 scalar or vector :ref:`floating-point <t_floating>` value, and a type to
10887 cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
10888 ``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
10889 type with the same number of elements as ``ty``
10894 The '``fptoui``' instruction converts its :ref:`floating-point
10895 <t_floating>` operand into the nearest (rounding towards zero)
10896 unsigned integer value. If the value cannot fit in ``ty2``, the result
10897 is a :ref:`poison value <poisonvalues>`.
10902 .. code-block:: llvm
10904 %X = fptoui double 123.0 to i32 ; yields i32:123
10905 %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1
10906 %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1
10908 '``fptosi .. to``' Instruction
10909 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10916 <result> = fptosi <ty> <value> to <ty2> ; yields ty2
10921 The '``fptosi``' instruction converts :ref:`floating-point <t_floating>`
10922 ``value`` to type ``ty2``.
10927 The '``fptosi``' instruction takes a value to cast, which must be a
10928 scalar or vector :ref:`floating-point <t_floating>` value, and a type to
10929 cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
10930 ``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
10931 type with the same number of elements as ``ty``
10936 The '``fptosi``' instruction converts its :ref:`floating-point
10937 <t_floating>` operand into the nearest (rounding towards zero)
10938 signed integer value. If the value cannot fit in ``ty2``, the result
10939 is a :ref:`poison value <poisonvalues>`.
10944 .. code-block:: llvm
10946 %X = fptosi double -123.0 to i32 ; yields i32:-123
10947 %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1
10948 %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1
10950 '``uitofp .. to``' Instruction
10951 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10958 <result> = uitofp <ty> <value> to <ty2> ; yields ty2
10963 The '``uitofp``' instruction regards ``value`` as an unsigned integer
10964 and converts that value to the ``ty2`` type.
10969 The '``uitofp``' instruction takes a value to cast, which must be a
10970 scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
10971 ``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
10972 ``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
10973 type with the same number of elements as ``ty``
10978 The '``uitofp``' instruction interprets its operand as an unsigned
10979 integer quantity and converts it to the corresponding floating-point
10980 value. If the value cannot be exactly represented, it is rounded using
10981 the default rounding mode.
10987 .. code-block:: llvm
10989 %X = uitofp i32 257 to float ; yields float:257.0
10990 %Y = uitofp i8 -1 to double ; yields double:255.0
10992 '``sitofp .. to``' Instruction
10993 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11000 <result> = sitofp <ty> <value> to <ty2> ; yields ty2
11005 The '``sitofp``' instruction regards ``value`` as a signed integer and
11006 converts that value to the ``ty2`` type.
11011 The '``sitofp``' instruction takes a value to cast, which must be a
11012 scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
11013 ``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
11014 ``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
11015 type with the same number of elements as ``ty``
11020 The '``sitofp``' instruction interprets its operand as a signed integer
11021 quantity and converts it to the corresponding floating-point value. If the
11022 value cannot be exactly represented, it is rounded using the default rounding
11028 .. code-block:: llvm
11030 %X = sitofp i32 257 to float ; yields float:257.0
11031 %Y = sitofp i8 -1 to double ; yields double:-1.0
11035 '``ptrtoint .. to``' Instruction
11036 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11043 <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2
11048 The '``ptrtoint``' instruction converts the pointer or a vector of
11049 pointers ``value`` to the integer (or vector of integers) type ``ty2``.
11054 The '``ptrtoint``' instruction takes a ``value`` to cast, which must be
11055 a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
11056 type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
11057 a vector of integers type.
11062 The '``ptrtoint``' instruction converts ``value`` to integer type
11063 ``ty2`` by interpreting the pointer value as an integer and either
11064 truncating or zero extending that value to the size of the integer type.
11065 If ``value`` is smaller than ``ty2`` then a zero extension is done. If
11066 ``value`` is larger than ``ty2`` then a truncation is done. If they are
11067 the same size, then nothing is done (*no-op cast*) other than a type
11073 .. code-block:: llvm
11075 %X = ptrtoint ptr %P to i8 ; yields truncation on 32-bit architecture
11076 %Y = ptrtoint ptr %P to i64 ; yields zero extension on 32-bit architecture
11077 %Z = ptrtoint <4 x ptr> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
11081 '``inttoptr .. to``' Instruction
11082 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11089 <result> = inttoptr <ty> <value> to <ty2>[, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>] ; yields ty2
11094 The '``inttoptr``' instruction converts an integer ``value`` to a
11095 pointer type, ``ty2``.
11100 The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to
11101 cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>`
11104 The optional ``!dereferenceable`` metadata must reference a single metadata
11105 name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
11107 See ``dereferenceable`` metadata.
11109 The optional ``!dereferenceable_or_null`` metadata must reference a single
11110 metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
11112 See ``dereferenceable_or_null`` metadata.
11117 The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by
11118 applying either a zero extension or a truncation depending on the size
11119 of the integer ``value``. If ``value`` is larger than the size of a
11120 pointer then a truncation is done. If ``value`` is smaller than the size
11121 of a pointer then a zero extension is done. If they are the same size,
11122 nothing is done (*no-op cast*).
11127 .. code-block:: llvm
11129 %X = inttoptr i32 255 to ptr ; yields zero extension on 64-bit architecture
11130 %Y = inttoptr i32 255 to ptr ; yields no-op on 32-bit architecture
11131 %Z = inttoptr i64 0 to ptr ; yields truncation on 32-bit architecture
11132 %Z = inttoptr <4 x i32> %G to <4 x ptr>; yields truncation of vector G to four pointers
11136 '``bitcast .. to``' Instruction
11137 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11144 <result> = bitcast <ty> <value> to <ty2> ; yields ty2
11149 The '``bitcast``' instruction converts ``value`` to type ``ty2`` without
11155 The '``bitcast``' instruction takes a value to cast, which must be a
11156 non-aggregate first class value, and a type to cast it to, which must
11157 also be a non-aggregate :ref:`first class <t_firstclass>` type. The
11158 bit sizes of ``value`` and the destination type, ``ty2``, must be
11159 identical. If the source type is a pointer, the destination type must
11160 also be a pointer of the same size. This instruction supports bitwise
11161 conversion of vectors to integers and to vectors of other types (as
11162 long as they have the same size).
11167 The '``bitcast``' instruction converts ``value`` to type ``ty2``. It
11168 is always a *no-op cast* because no bits change with this
11169 conversion. The conversion is done as if the ``value`` had been stored
11170 to memory and read back as type ``ty2``. Pointer (or vector of
11171 pointers) types may only be converted to other pointer (or vector of
11172 pointers) types with the same address space through this instruction.
11173 To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>`
11174 or :ref:`ptrtoint <i_ptrtoint>` instructions first.
11176 There is a caveat for bitcasts involving vector types in relation to
11177 endianess. For example ``bitcast <2 x i8> <value> to i16`` puts element zero
11178 of the vector in the least significant bits of the i16 for little-endian while
11179 element zero ends up in the most significant bits for big-endian.
11184 .. code-block:: text
11186 %X = bitcast i8 255 to i8 ; yields i8 :-1
11187 %Y = bitcast i32* %x to i16* ; yields i16*:%x
11188 %Z = bitcast <2 x i32> %V to i64; ; yields i64: %V (depends on endianess)
11189 %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
11191 .. _i_addrspacecast:
11193 '``addrspacecast .. to``' Instruction
11194 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11201 <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2
11206 The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in
11207 address space ``n`` to type ``pty2`` in address space ``m``.
11212 The '``addrspacecast``' instruction takes a pointer or vector of pointer value
11213 to cast and a pointer type to cast it to, which must have a different
11219 The '``addrspacecast``' instruction converts the pointer value
11220 ``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex
11221 value modification, depending on the target and the address space
11222 pair. Pointer conversions within the same address space must be
11223 performed with the ``bitcast`` instruction. Note that if the address space
11224 conversion is legal then both result and operand refer to the same memory
11230 .. code-block:: llvm
11232 %X = addrspacecast ptr %x to ptr addrspace(1)
11233 %Y = addrspacecast ptr addrspace(1) %y to ptr addrspace(2)
11234 %Z = addrspacecast <4 x ptr> %z to <4 x ptr addrspace(3)>
11241 The instructions in this category are the "miscellaneous" instructions,
11242 which defy better classification.
11246 '``icmp``' Instruction
11247 ^^^^^^^^^^^^^^^^^^^^^^
11254 <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
11259 The '``icmp``' instruction returns a boolean value or a vector of
11260 boolean values based on comparison of its two integer, integer vector,
11261 pointer, or pointer vector operands.
11266 The '``icmp``' instruction takes three operands. The first operand is
11267 the condition code indicating the kind of comparison to perform. It is
11268 not a value, just a keyword. The possible condition codes are:
11273 #. ``ne``: not equal
11274 #. ``ugt``: unsigned greater than
11275 #. ``uge``: unsigned greater or equal
11276 #. ``ult``: unsigned less than
11277 #. ``ule``: unsigned less or equal
11278 #. ``sgt``: signed greater than
11279 #. ``sge``: signed greater or equal
11280 #. ``slt``: signed less than
11281 #. ``sle``: signed less or equal
11283 The remaining two arguments must be :ref:`integer <t_integer>` or
11284 :ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They
11285 must also be identical types.
11290 The '``icmp``' compares ``op1`` and ``op2`` according to the condition
11291 code given as ``cond``. The comparison performed always yields either an
11292 :ref:`i1 <t_integer>` or vector of ``i1`` result, as follows:
11294 .. _icmp_md_cc_sem:
11296 #. ``eq``: yields ``true`` if the operands are equal, ``false``
11297 otherwise. No sign interpretation is necessary or performed.
11298 #. ``ne``: yields ``true`` if the operands are unequal, ``false``
11299 otherwise. No sign interpretation is necessary or performed.
11300 #. ``ugt``: interprets the operands as unsigned values and yields
11301 ``true`` if ``op1`` is greater than ``op2``.
11302 #. ``uge``: interprets the operands as unsigned values and yields
11303 ``true`` if ``op1`` is greater than or equal to ``op2``.
11304 #. ``ult``: interprets the operands as unsigned values and yields
11305 ``true`` if ``op1`` is less than ``op2``.
11306 #. ``ule``: interprets the operands as unsigned values and yields
11307 ``true`` if ``op1`` is less than or equal to ``op2``.
11308 #. ``sgt``: interprets the operands as signed values and yields ``true``
11309 if ``op1`` is greater than ``op2``.
11310 #. ``sge``: interprets the operands as signed values and yields ``true``
11311 if ``op1`` is greater than or equal to ``op2``.
11312 #. ``slt``: interprets the operands as signed values and yields ``true``
11313 if ``op1`` is less than ``op2``.
11314 #. ``sle``: interprets the operands as signed values and yields ``true``
11315 if ``op1`` is less than or equal to ``op2``.
11317 If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
11318 are compared as if they were integers.
11320 If the operands are integer vectors, then they are compared element by
11321 element. The result is an ``i1`` vector with the same number of elements
11322 as the values being compared. Otherwise, the result is an ``i1``.
11327 .. code-block:: text
11329 <result> = icmp eq i32 4, 5 ; yields: result=false
11330 <result> = icmp ne ptr %X, %X ; yields: result=false
11331 <result> = icmp ult i16 4, 5 ; yields: result=true
11332 <result> = icmp sgt i16 4, 5 ; yields: result=false
11333 <result> = icmp ule i16 -4, 5 ; yields: result=false
11334 <result> = icmp sge i16 4, 5 ; yields: result=false
11338 '``fcmp``' Instruction
11339 ^^^^^^^^^^^^^^^^^^^^^^
11346 <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
11351 The '``fcmp``' instruction returns a boolean value or vector of boolean
11352 values based on comparison of its operands.
11354 If the operands are floating-point scalars, then the result type is a
11355 boolean (:ref:`i1 <t_integer>`).
11357 If the operands are floating-point vectors, then the result type is a
11358 vector of boolean with the same number of elements as the operands being
11364 The '``fcmp``' instruction takes three operands. The first operand is
11365 the condition code indicating the kind of comparison to perform. It is
11366 not a value, just a keyword. The possible condition codes are:
11368 #. ``false``: no comparison, always returns false
11369 #. ``oeq``: ordered and equal
11370 #. ``ogt``: ordered and greater than
11371 #. ``oge``: ordered and greater than or equal
11372 #. ``olt``: ordered and less than
11373 #. ``ole``: ordered and less than or equal
11374 #. ``one``: ordered and not equal
11375 #. ``ord``: ordered (no nans)
11376 #. ``ueq``: unordered or equal
11377 #. ``ugt``: unordered or greater than
11378 #. ``uge``: unordered or greater than or equal
11379 #. ``ult``: unordered or less than
11380 #. ``ule``: unordered or less than or equal
11381 #. ``une``: unordered or not equal
11382 #. ``uno``: unordered (either nans)
11383 #. ``true``: no comparison, always returns true
11385 *Ordered* means that neither operand is a QNAN while *unordered* means
11386 that either operand may be a QNAN.
11388 Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point
11389 <t_floating>` type or a :ref:`vector <t_vector>` of floating-point type.
11390 They must have identical types.
11395 The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the
11396 condition code given as ``cond``. If the operands are vectors, then the
11397 vectors are compared element by element. Each comparison performed
11398 always yields an :ref:`i1 <t_integer>` result, as follows:
11400 #. ``false``: always yields ``false``, regardless of operands.
11401 #. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1``
11402 is equal to ``op2``.
11403 #. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1``
11404 is greater than ``op2``.
11405 #. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1``
11406 is greater than or equal to ``op2``.
11407 #. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1``
11408 is less than ``op2``.
11409 #. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1``
11410 is less than or equal to ``op2``.
11411 #. ``one``: yields ``true`` if both operands are not a QNAN and ``op1``
11412 is not equal to ``op2``.
11413 #. ``ord``: yields ``true`` if both operands are not a QNAN.
11414 #. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is
11416 #. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is
11417 greater than ``op2``.
11418 #. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is
11419 greater than or equal to ``op2``.
11420 #. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is
11422 #. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is
11423 less than or equal to ``op2``.
11424 #. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is
11425 not equal to ``op2``.
11426 #. ``uno``: yields ``true`` if either operand is a QNAN.
11427 #. ``true``: always yields ``true``, regardless of operands.
11429 The ``fcmp`` instruction can also optionally take any number of
11430 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
11431 otherwise unsafe floating-point optimizations.
11433 Any set of fast-math flags are legal on an ``fcmp`` instruction, but the
11434 only flags that have any effect on its semantics are those that allow
11435 assumptions to be made about the values of input arguments; namely
11436 ``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information.
11441 .. code-block:: text
11443 <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false
11444 <result> = fcmp one float 4.0, 5.0 ; yields: result=true
11445 <result> = fcmp olt float 4.0, 5.0 ; yields: result=true
11446 <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false
11450 '``phi``' Instruction
11451 ^^^^^^^^^^^^^^^^^^^^^
11458 <result> = phi [fast-math-flags] <ty> [ <val0>, <label0>], ...
11463 The '``phi``' instruction is used to implement the φ node in the SSA
11464 graph representing the function.
11469 The type of the incoming values is specified with the first type field.
11470 After this, the '``phi``' instruction takes a list of pairs as
11471 arguments, with one pair for each predecessor basic block of the current
11472 block. Only values of :ref:`first class <t_firstclass>` type may be used as
11473 the value arguments to the PHI node. Only labels may be used as the
11476 There must be no non-phi instructions between the start of a basic block
11477 and the PHI instructions: i.e. PHI instructions must be first in a basic
11480 For the purposes of the SSA form, the use of each incoming value is
11481 deemed to occur on the edge from the corresponding predecessor block to
11482 the current block (but after any definition of an '``invoke``'
11483 instruction's return value on the same edge).
11485 The optional ``fast-math-flags`` marker indicates that the phi has one
11486 or more :ref:`fast-math-flags <fastmath>`. These are optimization hints
11487 to enable otherwise unsafe floating-point optimizations. Fast-math-flags
11488 are only valid for phis that return a floating-point scalar or vector
11489 type, or an array (nested to any depth) of floating-point scalar or vector
11495 At runtime, the '``phi``' instruction logically takes on the value
11496 specified by the pair corresponding to the predecessor basic block that
11497 executed just prior to the current block.
11502 .. code-block:: llvm
11504 Loop: ; Infinite loop that counts from 0 on up...
11505 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
11506 %nextindvar = add i32 %indvar, 1
11511 '``select``' Instruction
11512 ^^^^^^^^^^^^^^^^^^^^^^^^
11519 <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty
11521 selty is either i1 or {<N x i1>}
11526 The '``select``' instruction is used to choose one value based on a
11527 condition, without IR-level branching.
11532 The '``select``' instruction requires an 'i1' value or a vector of 'i1'
11533 values indicating the condition, and two values of the same :ref:`first
11534 class <t_firstclass>` type.
11536 #. The optional ``fast-math flags`` marker indicates that the select has one or more
11537 :ref:`fast-math flags <fastmath>`. These are optimization hints to enable
11538 otherwise unsafe floating-point optimizations. Fast-math flags are only valid
11539 for selects that return a floating-point scalar or vector type, or an array
11540 (nested to any depth) of floating-point scalar or vector types.
11545 If the condition is an i1 and it evaluates to 1, the instruction returns
11546 the first value argument; otherwise, it returns the second value
11549 If the condition is a vector of i1, then the value arguments must be
11550 vectors of the same size, and the selection is done element by element.
11552 If the condition is an i1 and the value arguments are vectors of the
11553 same size, then an entire vector is selected.
11558 .. code-block:: llvm
11560 %X = select i1 true, i8 17, i8 42 ; yields i8:17
11565 '``freeze``' Instruction
11566 ^^^^^^^^^^^^^^^^^^^^^^^^
11573 <result> = freeze ty <val> ; yields ty:result
11578 The '``freeze``' instruction is used to stop propagation of
11579 :ref:`undef <undefvalues>` and :ref:`poison <poisonvalues>` values.
11584 The '``freeze``' instruction takes a single argument.
11589 If the argument is ``undef`` or ``poison``, '``freeze``' returns an
11590 arbitrary, but fixed, value of type '``ty``'.
11591 Otherwise, this instruction is a no-op and returns the input argument.
11592 All uses of a value returned by the same '``freeze``' instruction are
11593 guaranteed to always observe the same value, while different '``freeze``'
11594 instructions may yield different values.
11596 While ``undef`` and ``poison`` pointers can be frozen, the result is a
11597 non-dereferenceable pointer. See the
11598 :ref:`Pointer Aliasing Rules <pointeraliasing>` section for more information.
11599 If an aggregate value or vector is frozen, the operand is frozen element-wise.
11600 The padding of an aggregate isn't considered, since it isn't visible
11601 without storing it into memory and loading it with a different type.
11607 .. code-block:: text
11611 %y = add i32 %w, %w ; undef
11612 %z = add i32 %x, %x ; even number because all uses of %x observe
11614 %x2 = freeze i32 %w
11615 %cmp = icmp eq i32 %x, %x2 ; can be true or false
11617 ; example with vectors
11618 %v = <2 x i32> <i32 undef, i32 poison>
11619 %a = extractelement <2 x i32> %v, i32 0 ; undef
11620 %b = extractelement <2 x i32> %v, i32 1 ; poison
11621 %add = add i32 %a, %a ; undef
11623 %v.fr = freeze <2 x i32> %v ; element-wise freeze
11624 %d = extractelement <2 x i32> %v.fr, i32 0 ; not undef
11625 %add.f = add i32 %d, %d ; even number
11627 ; branching on frozen value
11628 %poison = add nsw i1 %k, undef ; poison
11629 %c = freeze i1 %poison
11630 br i1 %c, label %foo, label %bar ; non-deterministic branch to %foo or %bar
11635 '``call``' Instruction
11636 ^^^^^^^^^^^^^^^^^^^^^^
11643 <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] [addrspace(<num>)]
11644 <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] [ operand bundles ]
11649 The '``call``' instruction represents a simple function call.
11654 This instruction requires several arguments:
11656 #. The optional ``tail`` and ``musttail`` markers indicate that the optimizers
11657 should perform tail call optimization. The ``tail`` marker is a hint that
11658 `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker
11659 means that the call must be tail call optimized in order for the program to
11660 be correct. This is true even in the presence of attributes like
11661 "disable-tail-calls". The ``musttail`` marker provides these guarantees:
11663 #. The call will not cause unbounded stack growth if it is part of a
11664 recursive cycle in the call graph.
11665 #. Arguments with the :ref:`inalloca <attr_inalloca>` or
11666 :ref:`preallocated <attr_preallocated>` attribute are forwarded in place.
11667 #. If the musttail call appears in a function with the ``"thunk"`` attribute
11668 and the caller and callee both have varargs, than any unprototyped
11669 arguments in register or memory are forwarded to the callee. Similarly,
11670 the return value of the callee is returned to the caller's caller, even
11671 if a void return type is in use.
11673 Both markers imply that the callee does not access allocas from the caller.
11674 The ``tail`` marker additionally implies that the callee does not access
11675 varargs from the caller. Calls marked ``musttail`` must obey the following
11678 - The call must immediately precede a :ref:`ret <i_ret>` instruction,
11679 or a pointer bitcast followed by a ret instruction.
11680 - The ret instruction must return the (possibly bitcasted) value
11681 produced by the call, undef, or void.
11682 - The calling conventions of the caller and callee must match.
11683 - The callee must be varargs iff the caller is varargs. Bitcasting a
11684 non-varargs function to the appropriate varargs type is legal so
11685 long as the non-varargs prefixes obey the other rules.
11686 - The return type must not undergo automatic conversion to an `sret` pointer.
11688 In addition, if the calling convention is not `swifttailcc` or `tailcc`:
11690 - All ABI-impacting function attributes, such as sret, byval, inreg,
11691 returned, and inalloca, must match.
11692 - The caller and callee prototypes must match. Pointer types of parameters
11693 or return types may differ in pointee type, but not in address space.
11695 On the other hand, if the calling convention is `swifttailcc` or `swiftcc`:
11697 - Only these ABI-impacting attributes attributes are allowed: sret, byval,
11698 swiftself, and swiftasync.
11699 - Prototypes are not required to match.
11701 Tail call optimization for calls marked ``tail`` is guaranteed to occur if
11702 the following conditions are met:
11704 - Caller and callee both have the calling convention ``fastcc`` or ``tailcc``.
11705 - The call is in tail position (ret immediately follows call and ret
11706 uses value of call or is void).
11707 - Option ``-tailcallopt`` is enabled,
11708 ``llvm::GuaranteedTailCallOpt`` is ``true``, or the calling convention
11710 - `Platform-specific constraints are
11711 met. <CodeGenerator.html#tailcallopt>`_
11713 #. The optional ``notail`` marker indicates that the optimizers should not add
11714 ``tail`` or ``musttail`` markers to the call. It is used to prevent tail
11715 call optimization from being performed on the call.
11717 #. The optional ``fast-math flags`` marker indicates that the call has one or more
11718 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
11719 otherwise unsafe floating-point optimizations. Fast-math flags are only valid
11720 for calls that return a floating-point scalar or vector type, or an array
11721 (nested to any depth) of floating-point scalar or vector types.
11723 #. The optional "cconv" marker indicates which :ref:`calling
11724 convention <callingconv>` the call should use. If none is
11725 specified, the call defaults to using C calling conventions. The
11726 calling convention of the call must match the calling convention of
11727 the target function, or else the behavior is undefined.
11728 #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
11729 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
11731 #. The optional addrspace attribute can be used to indicate the address space
11732 of the called function. If it is not specified, the program address space
11733 from the :ref:`datalayout string<langref_datalayout>` will be used.
11734 #. '``ty``': the type of the call instruction itself which is also the
11735 type of the return value. Functions that return no value are marked
11737 #. '``fnty``': shall be the signature of the function being called. The
11738 argument types must match the types implied by this signature. This
11739 type can be omitted if the function is not varargs.
11740 #. '``fnptrval``': An LLVM value containing a pointer to a function to
11741 be called. In most cases, this is a direct function call, but
11742 indirect ``call``'s are just as possible, calling an arbitrary pointer
11744 #. '``function args``': argument list whose types match the function
11745 signature argument types and parameter attributes. All arguments must
11746 be of :ref:`first class <t_firstclass>` type. If the function signature
11747 indicates the function accepts a variable number of arguments, the
11748 extra arguments can be specified.
11749 #. The optional :ref:`function attributes <fnattrs>` list.
11750 #. The optional :ref:`operand bundles <opbundles>` list.
11755 The '``call``' instruction is used to cause control flow to transfer to
11756 a specified function, with its incoming arguments bound to the specified
11757 values. Upon a '``ret``' instruction in the called function, control
11758 flow continues with the instruction after the function call, and the
11759 return value of the function is bound to the result argument.
11764 .. code-block:: llvm
11766 %retval = call i32 @test(i32 %argc)
11767 call i32 (ptr, ...) @printf(ptr %msg, i32 12, i8 42) ; yields i32
11768 %X = tail call i32 @foo() ; yields i32
11769 %Y = tail call fastcc i32 @foo() ; yields i32
11770 call void %foo(i8 signext 97)
11772 %struct.A = type { i32, i8 }
11773 %r = call %struct.A @foo() ; yields { i32, i8 }
11774 %gr = extractvalue %struct.A %r, 0 ; yields i32
11775 %gr1 = extractvalue %struct.A %r, 1 ; yields i8
11776 %Z = call void @foo() noreturn ; indicates that %foo never returns normally
11777 %ZZ = call zeroext i32 @bar() ; Return value is %zero extended
11779 llvm treats calls to some functions with names and arguments that match
11780 the standard C99 library as being the C99 library functions, and may
11781 perform optimizations or generate code for them under that assumption.
11782 This is something we'd like to change in the future to provide better
11783 support for freestanding environments and non-C-based languages.
11787 '``va_arg``' Instruction
11788 ^^^^^^^^^^^^^^^^^^^^^^^^
11795 <resultval> = va_arg <va_list*> <arglist>, <argty>
11800 The '``va_arg``' instruction is used to access arguments passed through
11801 the "variable argument" area of a function call. It is used to implement
11802 the ``va_arg`` macro in C.
11807 This instruction takes a ``va_list*`` value and the type of the
11808 argument. It returns a value of the specified argument type and
11809 increments the ``va_list`` to point to the next argument. The actual
11810 type of ``va_list`` is target specific.
11815 The '``va_arg``' instruction loads an argument of the specified type
11816 from the specified ``va_list`` and causes the ``va_list`` to point to
11817 the next argument. For more information, see the variable argument
11818 handling :ref:`Intrinsic Functions <int_varargs>`.
11820 It is legal for this instruction to be called in a function which does
11821 not take a variable number of arguments, for example, the ``vfprintf``
11824 ``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic
11825 function <intrinsics>` because it takes a type as an argument.
11830 See the :ref:`variable argument processing <int_varargs>` section.
11832 Note that the code generator does not yet fully support va\_arg on many
11833 targets. Also, it does not currently support va\_arg with aggregate
11834 types on any target.
11838 '``landingpad``' Instruction
11839 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11846 <resultval> = landingpad <resultty> <clause>+
11847 <resultval> = landingpad <resultty> cleanup <clause>*
11849 <clause> := catch <type> <value>
11850 <clause> := filter <array constant type> <array constant>
11855 The '``landingpad``' instruction is used by `LLVM's exception handling
11856 system <ExceptionHandling.html#overview>`_ to specify that a basic block
11857 is a landing pad --- one where the exception lands, and corresponds to the
11858 code found in the ``catch`` portion of a ``try``/``catch`` sequence. It
11859 defines values supplied by the :ref:`personality function <personalityfn>` upon
11860 re-entry to the function. The ``resultval`` has the type ``resultty``.
11866 ``cleanup`` flag indicates that the landing pad block is a cleanup.
11868 A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and
11869 contains the global variable representing the "type" that may be caught
11870 or filtered respectively. Unlike the ``catch`` clause, the ``filter``
11871 clause takes an array constant as its argument. Use
11872 "``[0 x ptr] undef``" for a filter which cannot throw. The
11873 '``landingpad``' instruction must contain *at least* one ``clause`` or
11874 the ``cleanup`` flag.
11879 The '``landingpad``' instruction defines the values which are set by the
11880 :ref:`personality function <personalityfn>` upon re-entry to the function, and
11881 therefore the "result type" of the ``landingpad`` instruction. As with
11882 calling conventions, how the personality function results are
11883 represented in LLVM IR is target specific.
11885 The clauses are applied in order from top to bottom. If two
11886 ``landingpad`` instructions are merged together through inlining, the
11887 clauses from the calling function are appended to the list of clauses.
11888 When the call stack is being unwound due to an exception being thrown,
11889 the exception is compared against each ``clause`` in turn. If it doesn't
11890 match any of the clauses, and the ``cleanup`` flag is not set, then
11891 unwinding continues further up the call stack.
11893 The ``landingpad`` instruction has several restrictions:
11895 - A landing pad block is a basic block which is the unwind destination
11896 of an '``invoke``' instruction.
11897 - A landing pad block must have a '``landingpad``' instruction as its
11898 first non-PHI instruction.
11899 - There can be only one '``landingpad``' instruction within the landing
11901 - A basic block that is not a landing pad block may not include a
11902 '``landingpad``' instruction.
11907 .. code-block:: llvm
11909 ;; A landing pad which can catch an integer.
11910 %res = landingpad { ptr, i32 }
11912 ;; A landing pad that is a cleanup.
11913 %res = landingpad { ptr, i32 }
11915 ;; A landing pad which can catch an integer and can only throw a double.
11916 %res = landingpad { ptr, i32 }
11918 filter [1 x ptr] [ptr @_ZTId]
11922 '``catchpad``' Instruction
11923 ^^^^^^^^^^^^^^^^^^^^^^^^^^
11930 <resultval> = catchpad within <catchswitch> [<args>*]
11935 The '``catchpad``' instruction is used by `LLVM's exception handling
11936 system <ExceptionHandling.html#overview>`_ to specify that a basic block
11937 begins a catch handler --- one where a personality routine attempts to transfer
11938 control to catch an exception.
11943 The ``catchswitch`` operand must always be a token produced by a
11944 :ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This
11945 ensures that each ``catchpad`` has exactly one predecessor block, and it always
11946 terminates in a ``catchswitch``.
11948 The ``args`` correspond to whatever information the personality routine
11949 requires to know if this is an appropriate handler for the exception. Control
11950 will transfer to the ``catchpad`` if this is the first appropriate handler for
11953 The ``resultval`` has the type :ref:`token <t_token>` and is used to match the
11954 ``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH
11960 When the call stack is being unwound due to an exception being thrown, the
11961 exception is compared against the ``args``. If it doesn't match, control will
11962 not reach the ``catchpad`` instruction. The representation of ``args`` is
11963 entirely target and personality function-specific.
11965 Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad``
11966 instruction must be the first non-phi of its parent basic block.
11968 The meaning of the tokens produced and consumed by ``catchpad`` and other "pad"
11969 instructions is described in the
11970 `Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_.
11972 When a ``catchpad`` has been "entered" but not yet "exited" (as
11973 described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
11974 it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
11975 that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
11980 .. code-block:: text
11983 %cs = catchswitch within none [label %handler0] unwind to caller
11984 ;; A catch block which can catch an integer.
11986 %tok = catchpad within %cs [ptr @_ZTIi]
11990 '``cleanuppad``' Instruction
11991 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11998 <resultval> = cleanuppad within <parent> [<args>*]
12003 The '``cleanuppad``' instruction is used by `LLVM's exception handling
12004 system <ExceptionHandling.html#overview>`_ to specify that a basic block
12005 is a cleanup block --- one where a personality routine attempts to
12006 transfer control to run cleanup actions.
12007 The ``args`` correspond to whatever additional
12008 information the :ref:`personality function <personalityfn>` requires to
12009 execute the cleanup.
12010 The ``resultval`` has the type :ref:`token <t_token>` and is used to
12011 match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`.
12012 The ``parent`` argument is the token of the funclet that contains the
12013 ``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet,
12014 this operand may be the token ``none``.
12019 The instruction takes a list of arbitrary values which are interpreted
12020 by the :ref:`personality function <personalityfn>`.
12025 When the call stack is being unwound due to an exception being thrown,
12026 the :ref:`personality function <personalityfn>` transfers control to the
12027 ``cleanuppad`` with the aid of the personality-specific arguments.
12028 As with calling conventions, how the personality function results are
12029 represented in LLVM IR is target specific.
12031 The ``cleanuppad`` instruction has several restrictions:
12033 - A cleanup block is a basic block which is the unwind destination of
12034 an exceptional instruction.
12035 - A cleanup block must have a '``cleanuppad``' instruction as its
12036 first non-PHI instruction.
12037 - There can be only one '``cleanuppad``' instruction within the
12039 - A basic block that is not a cleanup block may not include a
12040 '``cleanuppad``' instruction.
12042 When a ``cleanuppad`` has been "entered" but not yet "exited" (as
12043 described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
12044 it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
12045 that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
12050 .. code-block:: text
12052 %tok = cleanuppad within %cs []
12056 Intrinsic Functions
12057 ===================
12059 LLVM supports the notion of an "intrinsic function". These functions
12060 have well known names and semantics and are required to follow certain
12061 restrictions. Overall, these intrinsics represent an extension mechanism
12062 for the LLVM language that does not require changing all of the
12063 transformations in LLVM when adding to the language (or the bitcode
12064 reader/writer, the parser, etc...).
12066 Intrinsic function names must all start with an "``llvm.``" prefix. This
12067 prefix is reserved in LLVM for intrinsic names; thus, function names may
12068 not begin with this prefix. Intrinsic functions must always be external
12069 functions: you cannot define the body of intrinsic functions. Intrinsic
12070 functions may only be used in call or invoke instructions: it is illegal
12071 to take the address of an intrinsic function. Additionally, because
12072 intrinsic functions are part of the LLVM language, it is required if any
12073 are added that they be documented here.
12075 Some intrinsic functions can be overloaded, i.e., the intrinsic
12076 represents a family of functions that perform the same operation but on
12077 different data types. Because LLVM can represent over 8 million
12078 different integer types, overloading is used commonly to allow an
12079 intrinsic function to operate on any integer type. One or more of the
12080 argument types or the result type can be overloaded to accept any
12081 integer type. Argument types may also be defined as exactly matching a
12082 previous argument's type or the result type. This allows an intrinsic
12083 function which accepts multiple arguments, but needs all of them to be
12084 of the same type, to only be overloaded with respect to a single
12085 argument or the result.
12087 Overloaded intrinsics will have the names of its overloaded argument
12088 types encoded into its function name, each preceded by a period. Only
12089 those types which are overloaded result in a name suffix. Arguments
12090 whose type is matched against another type do not. For example, the
12091 ``llvm.ctpop`` function can take an integer of any width and returns an
12092 integer of exactly the same integer width. This leads to a family of
12093 functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and
12094 ``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is
12095 overloaded, and only one type suffix is required. Because the argument's
12096 type is matched against the return type, it does not require its own
12099 :ref:`Unnamed types <t_opaque>` are encoded as ``s_s``. Overloaded intrinsics
12100 that depend on an unnamed type in one of its overloaded argument types get an
12101 additional ``.<number>`` suffix. This allows differentiating intrinsics with
12102 different unnamed types as arguments. (For example:
12103 ``llvm.ssa.copy.p0s_s.2(%42*)``) The number is tracked in the LLVM module and
12104 it ensures unique names in the module. While linking together two modules, it is
12105 still possible to get a name clash. In that case one of the names will be
12106 changed by getting a new number.
12108 For target developers who are defining intrinsics for back-end code
12109 generation, any intrinsic overloads based solely the distinction between
12110 integer or floating point types should not be relied upon for correct
12111 code generation. In such cases, the recommended approach for target
12112 maintainers when defining intrinsics is to create separate integer and
12113 FP intrinsics rather than rely on overloading. For example, if different
12114 codegen is required for ``llvm.target.foo(<4 x i32>)`` and
12115 ``llvm.target.foo(<4 x float>)`` then these should be split into
12116 different intrinsics.
12118 To learn how to add an intrinsic function, please see the `Extending
12119 LLVM Guide <ExtendingLLVM.html>`_.
12123 Variable Argument Handling Intrinsics
12124 -------------------------------------
12126 Variable argument support is defined in LLVM with the
12127 :ref:`va_arg <i_va_arg>` instruction and these three intrinsic
12128 functions. These functions are related to the similarly named macros
12129 defined in the ``<stdarg.h>`` header file.
12131 All of these functions operate on arguments that use a target-specific
12132 value type "``va_list``". The LLVM assembly language reference manual
12133 does not define what this type is, so all transformations should be
12134 prepared to handle these functions regardless of the type used.
12136 This example shows how the :ref:`va_arg <i_va_arg>` instruction and the
12137 variable argument handling intrinsic functions are used.
12139 .. code-block:: llvm
12141 ; This struct is different for every platform. For most platforms,
12142 ; it is merely a ptr.
12143 %struct.va_list = type { ptr }
12145 ; For Unix x86_64 platforms, va_list is the following struct:
12146 ; %struct.va_list = type { i32, i32, ptr, ptr }
12148 define i32 @test(i32 %X, ...) {
12149 ; Initialize variable argument processing
12150 %ap = alloca %struct.va_list
12151 call void @llvm.va_start(ptr %ap)
12153 ; Read a single integer argument
12154 %tmp = va_arg ptr %ap, i32
12156 ; Demonstrate usage of llvm.va_copy and llvm.va_end
12158 call void @llvm.va_copy(ptr %aq, ptr %ap)
12159 call void @llvm.va_end(ptr %aq)
12161 ; Stop processing of arguments.
12162 call void @llvm.va_end(ptr %ap)
12166 declare void @llvm.va_start(ptr)
12167 declare void @llvm.va_copy(ptr, ptr)
12168 declare void @llvm.va_end(ptr)
12172 '``llvm.va_start``' Intrinsic
12173 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12180 declare void @llvm.va_start(ptr <arglist>)
12185 The '``llvm.va_start``' intrinsic initializes ``<arglist>`` for
12186 subsequent use by ``va_arg``.
12191 The argument is a pointer to a ``va_list`` element to initialize.
12196 The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro
12197 available in C. In a target-dependent way, it initializes the
12198 ``va_list`` element to which the argument points, so that the next call
12199 to ``va_arg`` will produce the first variable argument passed to the
12200 function. Unlike the C ``va_start`` macro, this intrinsic does not need
12201 to know the last argument of the function as the compiler can figure
12204 '``llvm.va_end``' Intrinsic
12205 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12212 declare void @llvm.va_end(ptr <arglist>)
12217 The '``llvm.va_end``' intrinsic destroys ``<arglist>``, which has been
12218 initialized previously with ``llvm.va_start`` or ``llvm.va_copy``.
12223 The argument is a pointer to a ``va_list`` to destroy.
12228 The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro
12229 available in C. In a target-dependent way, it destroys the ``va_list``
12230 element to which the argument points. Calls to
12231 :ref:`llvm.va_start <int_va_start>` and
12232 :ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to
12237 '``llvm.va_copy``' Intrinsic
12238 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12245 declare void @llvm.va_copy(ptr <destarglist>, ptr <srcarglist>)
12250 The '``llvm.va_copy``' intrinsic copies the current argument position
12251 from the source argument list to the destination argument list.
12256 The first argument is a pointer to a ``va_list`` element to initialize.
12257 The second argument is a pointer to a ``va_list`` element to copy from.
12262 The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro
12263 available in C. In a target-dependent way, it copies the source
12264 ``va_list`` element into the destination ``va_list`` element. This
12265 intrinsic is necessary because the `` llvm.va_start`` intrinsic may be
12266 arbitrarily complex and require, for example, memory allocation.
12268 Accurate Garbage Collection Intrinsics
12269 --------------------------------------
12271 LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_
12272 (GC) requires the frontend to generate code containing appropriate intrinsic
12273 calls and select an appropriate GC strategy which knows how to lower these
12274 intrinsics in a manner which is appropriate for the target collector.
12276 These intrinsics allow identification of :ref:`GC roots on the
12277 stack <int_gcroot>`, as well as garbage collector implementations that
12278 require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers.
12279 Frontends for type-safe garbage collected languages should generate
12280 these intrinsics to make use of the LLVM garbage collectors. For more
12281 details, see `Garbage Collection with LLVM <GarbageCollection.html>`_.
12283 LLVM provides an second experimental set of intrinsics for describing garbage
12284 collection safepoints in compiled code. These intrinsics are an alternative
12285 to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for
12286 :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The
12287 differences in approach are covered in the `Garbage Collection with LLVM
12288 <GarbageCollection.html>`_ documentation. The intrinsics themselves are
12289 described in :doc:`Statepoints`.
12293 '``llvm.gcroot``' Intrinsic
12294 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12301 declare void @llvm.gcroot(ptr %ptrloc, ptr %metadata)
12306 The '``llvm.gcroot``' intrinsic declares the existence of a GC root to
12307 the code generator, and allows some metadata to be associated with it.
12312 The first argument specifies the address of a stack object that contains
12313 the root pointer. The second pointer (which must be either a constant or
12314 a global value address) contains the meta-data to be associated with the
12320 At runtime, a call to this intrinsic stores a null pointer into the
12321 "ptrloc" location. At compile-time, the code generator generates
12322 information to allow the runtime to find the pointer at GC safe points.
12323 The '``llvm.gcroot``' intrinsic may only be used in a function which
12324 :ref:`specifies a GC algorithm <gc>`.
12328 '``llvm.gcread``' Intrinsic
12329 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12336 declare ptr @llvm.gcread(ptr %ObjPtr, ptr %Ptr)
12341 The '``llvm.gcread``' intrinsic identifies reads of references from heap
12342 locations, allowing garbage collector implementations that require read
12348 The second argument is the address to read from, which should be an
12349 address allocated from the garbage collector. The first object is a
12350 pointer to the start of the referenced object, if needed by the language
12351 runtime (otherwise null).
12356 The '``llvm.gcread``' intrinsic has the same semantics as a load
12357 instruction, but may be replaced with substantially more complex code by
12358 the garbage collector runtime, as needed. The '``llvm.gcread``'
12359 intrinsic may only be used in a function which :ref:`specifies a GC
12364 '``llvm.gcwrite``' Intrinsic
12365 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12372 declare void @llvm.gcwrite(ptr %P1, ptr %Obj, ptr %P2)
12377 The '``llvm.gcwrite``' intrinsic identifies writes of references to heap
12378 locations, allowing garbage collector implementations that require write
12379 barriers (such as generational or reference counting collectors).
12384 The first argument is the reference to store, the second is the start of
12385 the object to store it to, and the third is the address of the field of
12386 Obj to store to. If the runtime does not require a pointer to the
12387 object, Obj may be null.
12392 The '``llvm.gcwrite``' intrinsic has the same semantics as a store
12393 instruction, but may be replaced with substantially more complex code by
12394 the garbage collector runtime, as needed. The '``llvm.gcwrite``'
12395 intrinsic may only be used in a function which :ref:`specifies a GC
12401 'llvm.experimental.gc.statepoint' Intrinsic
12402 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12410 @llvm.experimental.gc.statepoint(i64 <id>, i32 <num patch bytes>,
12411 ptr elementtype(func_type) <target>,
12412 i64 <#call args>, i64 <flags>,
12413 ... (call parameters),
12419 The statepoint intrinsic represents a call which is parse-able by the
12425 The 'id' operand is a constant integer that is reported as the ID
12426 field in the generated stackmap. LLVM does not interpret this
12427 parameter in any way and its meaning is up to the statepoint user to
12428 decide. Note that LLVM is free to duplicate code containing
12429 statepoint calls, and this may transform IR that had a unique 'id' per
12430 lexical call to statepoint to IR that does not.
12432 If 'num patch bytes' is non-zero then the call instruction
12433 corresponding to the statepoint is not emitted and LLVM emits 'num
12434 patch bytes' bytes of nops in its place. LLVM will emit code to
12435 prepare the function arguments and retrieve the function return value
12436 in accordance to the calling convention; the former before the nop
12437 sequence and the latter after the nop sequence. It is expected that
12438 the user will patch over the 'num patch bytes' bytes of nops with a
12439 calling sequence specific to their runtime before executing the
12440 generated machine code. There are no guarantees with respect to the
12441 alignment of the nop sequence. Unlike :doc:`StackMaps` statepoints do
12442 not have a concept of shadow bytes. Note that semantically the
12443 statepoint still represents a call or invoke to 'target', and the nop
12444 sequence after patching is expected to represent an operation
12445 equivalent to a call or invoke to 'target'.
12447 The 'target' operand is the function actually being called. The operand
12448 must have an :ref:`elementtype <attr_elementtype>` attribute specifying
12449 the function type of the target. The target can be specified as either
12450 a symbolic LLVM function, or as an arbitrary Value of pointer type. Note
12451 that the function type must match the signature of the callee and the
12452 types of the 'call parameters' arguments.
12454 The '#call args' operand is the number of arguments to the actual
12455 call. It must exactly match the number of arguments passed in the
12456 'call parameters' variable length section.
12458 The 'flags' operand is used to specify extra information about the
12459 statepoint. This is currently only used to mark certain statepoints
12460 as GC transitions. This operand is a 64-bit integer with the following
12461 layout, where bit 0 is the least significant bit:
12463 +-------+---------------------------------------------------+
12465 +=======+===================================================+
12466 | 0 | Set if the statepoint is a GC transition, cleared |
12468 +-------+---------------------------------------------------+
12469 | 1-63 | Reserved for future use; must be cleared. |
12470 +-------+---------------------------------------------------+
12472 The 'call parameters' arguments are simply the arguments which need to
12473 be passed to the call target. They will be lowered according to the
12474 specified calling convention and otherwise handled like a normal call
12475 instruction. The number of arguments must exactly match what is
12476 specified in '# call args'. The types must match the signature of
12479 The 'call parameter' attributes must be followed by two 'i64 0' constants.
12480 These were originally the length prefixes for 'gc transition parameter' and
12481 'deopt parameter' arguments, but the role of these parameter sets have been
12482 entirely replaced with the corresponding operand bundles. In a future
12483 revision, these now redundant arguments will be removed.
12488 A statepoint is assumed to read and write all memory. As a result,
12489 memory operations can not be reordered past a statepoint. It is
12490 illegal to mark a statepoint as being either 'readonly' or 'readnone'.
12492 Note that legal IR can not perform any memory operation on a 'gc
12493 pointer' argument of the statepoint in a location statically reachable
12494 from the statepoint. Instead, the explicitly relocated value (from a
12495 ``gc.relocate``) must be used.
12497 'llvm.experimental.gc.result' Intrinsic
12498 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12506 @llvm.experimental.gc.result(token %statepoint_token)
12511 ``gc.result`` extracts the result of the original call instruction
12512 which was replaced by the ``gc.statepoint``. The ``gc.result``
12513 intrinsic is actually a family of three intrinsics due to an
12514 implementation limitation. Other than the type of the return value,
12515 the semantics are the same.
12520 The first and only argument is the ``gc.statepoint`` which starts
12521 the safepoint sequence of which this ``gc.result`` is a part.
12522 Despite the typing of this as a generic token, *only* the value defined
12523 by a ``gc.statepoint`` is legal here.
12528 The ``gc.result`` represents the return value of the call target of
12529 the ``statepoint``. The type of the ``gc.result`` must exactly match
12530 the type of the target. If the call target returns void, there will
12531 be no ``gc.result``.
12533 A ``gc.result`` is modeled as a 'readnone' pure function. It has no
12534 side effects since it is just a projection of the return value of the
12535 previous call represented by the ``gc.statepoint``.
12537 'llvm.experimental.gc.relocate' Intrinsic
12538 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12545 declare <pointer type>
12546 @llvm.experimental.gc.relocate(token %statepoint_token,
12548 i32 %pointer_offset)
12553 A ``gc.relocate`` returns the potentially relocated value of a pointer
12559 The first argument is the ``gc.statepoint`` which starts the
12560 safepoint sequence of which this ``gc.relocation`` is a part.
12561 Despite the typing of this as a generic token, *only* the value defined
12562 by a ``gc.statepoint`` is legal here.
12564 The second and third arguments are both indices into operands of the
12565 corresponding statepoint's :ref:`gc-live <ob_gc_live>` operand bundle.
12567 The second argument is an index which specifies the allocation for the pointer
12568 being relocated. The associated value must be within the object with which the
12569 pointer being relocated is associated. The optimizer is free to change *which*
12570 interior derived pointer is reported, provided that it does not replace an
12571 actual base pointer with another interior derived pointer. Collectors are
12572 allowed to rely on the base pointer operand remaining an actual base pointer if
12575 The third argument is an index which specify the (potentially) derived pointer
12576 being relocated. It is legal for this index to be the same as the second
12577 argument if-and-only-if a base pointer is being relocated.
12582 The return value of ``gc.relocate`` is the potentially relocated value
12583 of the pointer specified by its arguments. It is unspecified how the
12584 value of the returned pointer relates to the argument to the
12585 ``gc.statepoint`` other than that a) it points to the same source
12586 language object with the same offset, and b) the 'based-on'
12587 relationship of the newly relocated pointers is a projection of the
12588 unrelocated pointers. In particular, the integer value of the pointer
12589 returned is unspecified.
12591 A ``gc.relocate`` is modeled as a ``readnone`` pure function. It has no
12592 side effects since it is just a way to extract information about work
12593 done during the actual call modeled by the ``gc.statepoint``.
12595 .. _gc.get.pointer.base:
12597 'llvm.experimental.gc.get.pointer.base' Intrinsic
12598 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12605 declare <pointer type>
12606 @llvm.experimental.gc.get.pointer.base(
12607 <pointer type> readnone nocapture %derived_ptr)
12608 nounwind readnone willreturn
12613 ``gc.get.pointer.base`` for a derived pointer returns its base pointer.
12618 The only argument is a pointer which is based on some object with
12619 an unknown offset from the base of said object.
12624 This intrinsic is used in the abstract machine model for GC to represent
12625 the base pointer for an arbitrary derived pointer.
12627 This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by
12628 replacing all uses of this callsite with the offset of a derived pointer from
12629 its base pointer value. The replacement is done as part of the lowering to the
12630 explicit statepoint model.
12632 The return pointer type must be the same as the type of the parameter.
12635 'llvm.experimental.gc.get.pointer.offset' Intrinsic
12636 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12644 @llvm.experimental.gc.get.pointer.offset(
12645 <pointer type> readnone nocapture %derived_ptr)
12646 nounwind readnone willreturn
12651 ``gc.get.pointer.offset`` for a derived pointer returns the offset from its
12657 The only argument is a pointer which is based on some object with
12658 an unknown offset from the base of said object.
12663 This intrinsic is used in the abstract machine model for GC to represent
12664 the offset of an arbitrary derived pointer from its base pointer.
12666 This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by
12667 replacing all uses of this callsite with the offset of a derived pointer from
12668 its base pointer value. The replacement is done as part of the lowering to the
12669 explicit statepoint model.
12671 Basically this call calculates difference between the derived pointer and its
12672 base pointer (see :ref:`gc.get.pointer.base`) both ptrtoint casted. But
12673 this cast done outside the :ref:`RewriteStatepointsForGC` pass could result
12674 in the pointers lost for further lowering from the abstract model to the
12675 explicit physical one.
12677 Code Generator Intrinsics
12678 -------------------------
12680 These intrinsics are provided by LLVM to expose special features that
12681 may only be implemented with code generator support.
12683 '``llvm.returnaddress``' Intrinsic
12684 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12691 declare ptr @llvm.returnaddress(i32 <level>)
12696 The '``llvm.returnaddress``' intrinsic attempts to compute a
12697 target-specific value indicating the return address of the current
12698 function or one of its callers.
12703 The argument to this intrinsic indicates which function to return the
12704 address for. Zero indicates the calling function, one indicates its
12705 caller, etc. The argument is **required** to be a constant integer
12711 The '``llvm.returnaddress``' intrinsic either returns a pointer
12712 indicating the return address of the specified call frame, or zero if it
12713 cannot be identified. The value returned by this intrinsic is likely to
12714 be incorrect or 0 for arguments other than zero, so it should only be
12715 used for debugging purposes.
12717 Note that calling this intrinsic does not prevent function inlining or
12718 other aggressive transformations, so the value returned may not be that
12719 of the obvious source-language caller.
12721 '``llvm.addressofreturnaddress``' Intrinsic
12722 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12729 declare ptr @llvm.addressofreturnaddress()
12734 The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific
12735 pointer to the place in the stack frame where the return address of the
12736 current function is stored.
12741 Note that calling this intrinsic does not prevent function inlining or
12742 other aggressive transformations, so the value returned may not be that
12743 of the obvious source-language caller.
12745 This intrinsic is only implemented for x86 and aarch64.
12747 '``llvm.sponentry``' Intrinsic
12748 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12755 declare ptr @llvm.sponentry()
12760 The '``llvm.sponentry``' intrinsic returns the stack pointer value at
12761 the entry of the current function calling this intrinsic.
12766 Note this intrinsic is only verified on AArch64 and ARM.
12768 '``llvm.frameaddress``' Intrinsic
12769 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12776 declare ptr @llvm.frameaddress(i32 <level>)
12781 The '``llvm.frameaddress``' intrinsic attempts to return the
12782 target-specific frame pointer value for the specified stack frame.
12787 The argument to this intrinsic indicates which function to return the
12788 frame pointer for. Zero indicates the calling function, one indicates
12789 its caller, etc. The argument is **required** to be a constant integer
12795 The '``llvm.frameaddress``' intrinsic either returns a pointer
12796 indicating the frame address of the specified call frame, or zero if it
12797 cannot be identified. The value returned by this intrinsic is likely to
12798 be incorrect or 0 for arguments other than zero, so it should only be
12799 used for debugging purposes.
12801 Note that calling this intrinsic does not prevent function inlining or
12802 other aggressive transformations, so the value returned may not be that
12803 of the obvious source-language caller.
12805 '``llvm.swift.async.context.addr``' Intrinsic
12806 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12813 declare ptr @llvm.swift.async.context.addr()
12818 The '``llvm.swift.async.context.addr``' intrinsic returns a pointer to
12819 the part of the extended frame record containing the asynchronous
12820 context of a Swift execution.
12825 If the caller has a ``swiftasync`` parameter, that argument will initially
12826 be stored at the returned address. If not, it will be initialized to null.
12828 '``llvm.localescape``' and '``llvm.localrecover``' Intrinsics
12829 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12836 declare void @llvm.localescape(...)
12837 declare ptr @llvm.localrecover(ptr %func, ptr %fp, i32 %idx)
12842 The '``llvm.localescape``' intrinsic escapes offsets of a collection of static
12843 allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a
12844 live frame pointer to recover the address of the allocation. The offset is
12845 computed during frame layout of the caller of ``llvm.localescape``.
12850 All arguments to '``llvm.localescape``' must be pointers to static allocas or
12851 casts of static allocas. Each function can only call '``llvm.localescape``'
12852 once, and it can only do so from the entry block.
12854 The ``func`` argument to '``llvm.localrecover``' must be a constant
12855 bitcasted pointer to a function defined in the current module. The code
12856 generator cannot determine the frame allocation offset of functions defined in
12859 The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a
12860 call frame that is currently live. The return value of '``llvm.localaddress``'
12861 is one way to produce such a value, but various runtimes also expose a suitable
12862 pointer in platform-specific ways.
12864 The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to
12865 '``llvm.localescape``' to recover. It is zero-indexed.
12870 These intrinsics allow a group of functions to share access to a set of local
12871 stack allocations of a one parent function. The parent function may call the
12872 '``llvm.localescape``' intrinsic once from the function entry block, and the
12873 child functions can use '``llvm.localrecover``' to access the escaped allocas.
12874 The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where
12875 the escaped allocas are allocated, which would break attempts to use
12876 '``llvm.localrecover``'.
12878 '``llvm.seh.try.begin``' and '``llvm.seh.try.end``' Intrinsics
12879 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12886 declare void @llvm.seh.try.begin()
12887 declare void @llvm.seh.try.end()
12892 The '``llvm.seh.try.begin``' and '``llvm.seh.try.end``' intrinsics mark
12893 the boundary of a _try region for Windows SEH Asynchrous Exception Handling.
12898 When a C-function is compiled with Windows SEH Asynchrous Exception option,
12899 -feh_asynch (aka MSVC -EHa), these two intrinsics are injected to mark _try
12900 boundary and to prevent potential exceptions from being moved across boundary.
12901 Any set of operations can then be confined to the region by reading their leaf
12902 inputs via volatile loads and writing their root outputs via volatile stores.
12904 '``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' Intrinsics
12905 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12912 declare void @llvm.seh.scope.begin()
12913 declare void @llvm.seh.scope.end()
12918 The '``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' intrinsics mark
12919 the boundary of a CPP object lifetime for Windows SEH Asynchrous Exception
12920 Handling (MSVC option -EHa).
12925 LLVM's ordinary exception-handling representation associates EH cleanups and
12926 handlers only with ``invoke``s, which normally correspond only to call sites. To
12927 support arbitrary faulting instructions, it must be possible to recover the current
12928 EH scope for any instruction. Turning every operation in LLVM that could fault
12929 into an ``invoke`` of a new, potentially-throwing intrinsic would require adding a
12930 large number of intrinsics, impede optimization of those operations, and make
12931 compilation slower by introducing many extra basic blocks. These intrinsics can
12932 be used instead to mark the region protected by a cleanup, such as for a local
12933 C++ object with a non-trivial destructor. ``llvm.seh.scope.begin`` is used to mark
12934 the start of the region; it is always called with ``invoke``, with the unwind block
12935 being the desired unwind destination for any potentially-throwing instructions
12936 within the region. `llvm.seh.scope.end` is used to mark when the scope ends
12937 and the EH cleanup is no longer required (e.g. because the destructor is being
12940 .. _int_read_register:
12941 .. _int_read_volatile_register:
12942 .. _int_write_register:
12944 '``llvm.read_register``', '``llvm.read_volatile_register``', and '``llvm.write_register``' Intrinsics
12945 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12952 declare i32 @llvm.read_register.i32(metadata)
12953 declare i64 @llvm.read_register.i64(metadata)
12954 declare i32 @llvm.read_volatile_register.i32(metadata)
12955 declare i64 @llvm.read_volatile_register.i64(metadata)
12956 declare void @llvm.write_register.i32(metadata, i32 @value)
12957 declare void @llvm.write_register.i64(metadata, i64 @value)
12963 The '``llvm.read_register``', '``llvm.read_volatile_register``', and
12964 '``llvm.write_register``' intrinsics provide access to the named register.
12965 The register must be valid on the architecture being compiled to. The type
12966 needs to be compatible with the register being read.
12971 The '``llvm.read_register``' and '``llvm.read_volatile_register``' intrinsics
12972 return the current value of the register, where possible. The
12973 '``llvm.write_register``' intrinsic sets the current value of the register,
12976 A call to '``llvm.read_volatile_register``' is assumed to have side-effects
12977 and possibly return a different value each time (e.g. for a timer register).
12979 This is useful to implement named register global variables that need
12980 to always be mapped to a specific register, as is common practice on
12981 bare-metal programs including OS kernels.
12983 The compiler doesn't check for register availability or use of the used
12984 register in surrounding code, including inline assembly. Because of that,
12985 allocatable registers are not supported.
12987 Warning: So far it only works with the stack pointer on selected
12988 architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of
12989 work is needed to support other registers and even more so, allocatable
12994 '``llvm.stacksave``' Intrinsic
12995 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13002 declare ptr @llvm.stacksave()
13007 The '``llvm.stacksave``' intrinsic is used to remember the current state
13008 of the function stack, for use with
13009 :ref:`llvm.stackrestore <int_stackrestore>`. This is useful for
13010 implementing language features like scoped automatic variable sized
13016 This intrinsic returns an opaque pointer value that can be passed to
13017 :ref:`llvm.stackrestore <int_stackrestore>`. When an
13018 ``llvm.stackrestore`` intrinsic is executed with a value saved from
13019 ``llvm.stacksave``, it effectively restores the state of the stack to
13020 the state it was in when the ``llvm.stacksave`` intrinsic executed. In
13021 practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that
13022 were allocated after the ``llvm.stacksave`` was executed.
13024 .. _int_stackrestore:
13026 '``llvm.stackrestore``' Intrinsic
13027 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13034 declare void @llvm.stackrestore(ptr %ptr)
13039 The '``llvm.stackrestore``' intrinsic is used to restore the state of
13040 the function stack to the state it was in when the corresponding
13041 :ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is
13042 useful for implementing language features like scoped automatic variable
13043 sized arrays in C99.
13048 See the description for :ref:`llvm.stacksave <int_stacksave>`.
13050 .. _int_get_dynamic_area_offset:
13052 '``llvm.get.dynamic.area.offset``' Intrinsic
13053 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13060 declare i32 @llvm.get.dynamic.area.offset.i32()
13061 declare i64 @llvm.get.dynamic.area.offset.i64()
13066 The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to
13067 get the offset from native stack pointer to the address of the most
13068 recent dynamic alloca on the caller's stack. These intrinsics are
13069 intended for use in combination with
13070 :ref:`llvm.stacksave <int_stacksave>` to get a
13071 pointer to the most recent dynamic alloca. This is useful, for example,
13072 for AddressSanitizer's stack unpoisoning routines.
13077 These intrinsics return a non-negative integer value that can be used to
13078 get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>`
13079 on the caller's stack. In particular, for targets where stack grows downwards,
13080 adding this offset to the native stack pointer would get the address of the most
13081 recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more
13082 complicated, because subtracting this value from stack pointer would get the address
13083 one past the end of the most recent dynamic alloca.
13085 Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
13086 returns just a zero, for others, such as PowerPC and PowerPC64, it returns a
13087 compile-time-known constant value.
13089 The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
13090 must match the target's default address space's (address space 0) pointer type.
13092 '``llvm.prefetch``' Intrinsic
13093 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13100 declare void @llvm.prefetch(ptr <address>, i32 <rw>, i32 <locality>, i32 <cache type>)
13105 The '``llvm.prefetch``' intrinsic is a hint to the code generator to
13106 insert a prefetch instruction if supported; otherwise, it is a noop.
13107 Prefetches have no effect on the behavior of the program but can change
13108 its performance characteristics.
13113 ``address`` is the address to be prefetched, ``rw`` is the specifier
13114 determining if the fetch should be for a read (0) or write (1), and
13115 ``locality`` is a temporal locality specifier ranging from (0) - no
13116 locality, to (3) - extremely local keep in cache. The ``cache type``
13117 specifies whether the prefetch is performed on the data (1) or
13118 instruction (0) cache. The ``rw``, ``locality`` and ``cache type``
13119 arguments must be constant integers.
13124 This intrinsic does not modify the behavior of the program. In
13125 particular, prefetches cannot trap and do not produce a value. On
13126 targets that support this intrinsic, the prefetch can provide hints to
13127 the processor cache for better performance.
13129 '``llvm.pcmarker``' Intrinsic
13130 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13137 declare void @llvm.pcmarker(i32 <id>)
13142 The '``llvm.pcmarker``' intrinsic is a method to export a Program
13143 Counter (PC) in a region of code to simulators and other tools. The
13144 method is target specific, but it is expected that the marker will use
13145 exported symbols to transmit the PC of the marker. The marker makes no
13146 guarantees that it will remain with any specific instruction after
13147 optimizations. It is possible that the presence of a marker will inhibit
13148 optimizations. The intended use is to be inserted after optimizations to
13149 allow correlations of simulation runs.
13154 ``id`` is a numerical id identifying the marker.
13159 This intrinsic does not modify the behavior of the program. Backends
13160 that do not support this intrinsic may ignore it.
13162 '``llvm.readcyclecounter``' Intrinsic
13163 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13170 declare i64 @llvm.readcyclecounter()
13175 The '``llvm.readcyclecounter``' intrinsic provides access to the cycle
13176 counter register (or similar low latency, high accuracy clocks) on those
13177 targets that support it. On X86, it should map to RDTSC. On Alpha, it
13178 should map to RPCC. As the backing counters overflow quickly (on the
13179 order of 9 seconds on alpha), this should only be used for small
13185 When directly supported, reading the cycle counter should not modify any
13186 memory. Implementations are allowed to either return an application
13187 specific value or a system wide value. On backends without support, this
13188 is lowered to a constant 0.
13190 Note that runtime support may be conditional on the privilege-level code is
13191 running at and the host platform.
13193 '``llvm.clear_cache``' Intrinsic
13194 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13201 declare void @llvm.clear_cache(ptr, ptr)
13206 The '``llvm.clear_cache``' intrinsic ensures visibility of modifications
13207 in the specified range to the execution unit of the processor. On
13208 targets with non-unified instruction and data cache, the implementation
13209 flushes the instruction cache.
13214 On platforms with coherent instruction and data caches (e.g. x86), this
13215 intrinsic is a nop. On platforms with non-coherent instruction and data
13216 cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate
13217 instructions or a system call, if cache flushing requires special
13220 The default behavior is to emit a call to ``__clear_cache`` from the run
13223 This intrinsic does *not* empty the instruction pipeline. Modifications
13224 of the current function are outside the scope of the intrinsic.
13226 '``llvm.instrprof.increment``' Intrinsic
13227 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13234 declare void @llvm.instrprof.increment(ptr <name>, i64 <hash>,
13235 i32 <num-counters>, i32 <index>)
13240 The '``llvm.instrprof.increment``' intrinsic can be emitted by a
13241 frontend for use with instrumentation based profiling. These will be
13242 lowered by the ``-instrprof`` pass to generate execution counts of a
13243 program at runtime.
13248 The first argument is a pointer to a global variable containing the
13249 name of the entity being instrumented. This should generally be the
13250 (mangled) function name for a set of counters.
13252 The second argument is a hash value that can be used by the consumer
13253 of the profile data to detect changes to the instrumented source, and
13254 the third is the number of counters associated with ``name``. It is an
13255 error if ``hash`` or ``num-counters`` differ between two instances of
13256 ``instrprof.increment`` that refer to the same name.
13258 The last argument refers to which of the counters for ``name`` should
13259 be incremented. It should be a value between 0 and ``num-counters``.
13264 This intrinsic represents an increment of a profiling counter. It will
13265 cause the ``-instrprof`` pass to generate the appropriate data
13266 structures and the code to increment the appropriate value, in a
13267 format that can be written out by a compiler runtime and consumed via
13268 the ``llvm-profdata`` tool.
13270 '``llvm.instrprof.increment.step``' Intrinsic
13271 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13278 declare void @llvm.instrprof.increment.step(ptr <name>, i64 <hash>,
13279 i32 <num-counters>,
13280 i32 <index>, i64 <step>)
13285 The '``llvm.instrprof.increment.step``' intrinsic is an extension to
13286 the '``llvm.instrprof.increment``' intrinsic with an additional fifth
13287 argument to specify the step of the increment.
13291 The first four arguments are the same as '``llvm.instrprof.increment``'
13294 The last argument specifies the value of the increment of the counter variable.
13298 See description of '``llvm.instrprof.increment``' intrinsic.
13300 '``llvm.instrprof.cover``' Intrinsic
13301 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13308 declare void @llvm.instrprof.cover(ptr <name>, i64 <hash>,
13309 i32 <num-counters>, i32 <index>)
13314 The '``llvm.instrprof.cover``' intrinsic is used to implement coverage
13319 The arguments are the same as the first four arguments of
13320 '``llvm.instrprof.increment``'.
13324 Similar to the '``llvm.instrprof.increment``' intrinsic, but it stores zero to
13325 the profiling variable to signify that the function has been covered. We store
13326 zero because this is more efficient on some targets.
13328 '``llvm.instrprof.value.profile``' Intrinsic
13329 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13336 declare void @llvm.instrprof.value.profile(ptr <name>, i64 <hash>,
13337 i64 <value>, i32 <value_kind>,
13343 The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a
13344 frontend for use with instrumentation based profiling. This will be
13345 lowered by the ``-instrprof`` pass to find out the target values,
13346 instrumented expressions take in a program at runtime.
13351 The first argument is a pointer to a global variable containing the
13352 name of the entity being instrumented. ``name`` should generally be the
13353 (mangled) function name for a set of counters.
13355 The second argument is a hash value that can be used by the consumer
13356 of the profile data to detect changes to the instrumented source. It
13357 is an error if ``hash`` differs between two instances of
13358 ``llvm.instrprof.*`` that refer to the same name.
13360 The third argument is the value of the expression being profiled. The profiled
13361 expression's value should be representable as an unsigned 64-bit value. The
13362 fourth argument represents the kind of value profiling that is being done. The
13363 supported value profiling kinds are enumerated through the
13364 ``InstrProfValueKind`` type declared in the
13365 ``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the
13366 index of the instrumented expression within ``name``. It should be >= 0.
13371 This intrinsic represents the point where a call to a runtime routine
13372 should be inserted for value profiling of target expressions. ``-instrprof``
13373 pass will generate the appropriate data structures and replace the
13374 ``llvm.instrprof.value.profile`` intrinsic with the call to the profile
13375 runtime library with proper arguments.
13377 '``llvm.thread.pointer``' Intrinsic
13378 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13385 declare ptr @llvm.thread.pointer()
13390 The '``llvm.thread.pointer``' intrinsic returns the value of the thread
13396 The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area
13397 for the current thread. The exact semantics of this value are target
13398 specific: it may point to the start of TLS area, to the end, or somewhere
13399 in the middle. Depending on the target, this intrinsic may read a register,
13400 call a helper function, read from an alternate memory space, or perform
13401 other operations necessary to locate the TLS area. Not all targets support
13404 '``llvm.call.preallocated.setup``' Intrinsic
13405 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13412 declare token @llvm.call.preallocated.setup(i32 %num_args)
13417 The '``llvm.call.preallocated.setup``' intrinsic returns a token which can
13418 be used with a call's ``"preallocated"`` operand bundle to indicate that
13419 certain arguments are allocated and initialized before the call.
13424 The '``llvm.call.preallocated.setup``' intrinsic returns a token which is
13425 associated with at most one call. The token can be passed to
13426 '``@llvm.call.preallocated.arg``' to get a pointer to get that
13427 corresponding argument. The token must be the parameter to a
13428 ``"preallocated"`` operand bundle for the corresponding call.
13430 Nested calls to '``llvm.call.preallocated.setup``' are allowed, but must
13431 be properly nested. e.g.
13433 :: code-block:: llvm
13435 %t1 = call token @llvm.call.preallocated.setup(i32 0)
13436 %t2 = call token @llvm.call.preallocated.setup(i32 0)
13437 call void foo() ["preallocated"(token %t2)]
13438 call void foo() ["preallocated"(token %t1)]
13440 is allowed, but not
13442 :: code-block:: llvm
13444 %t1 = call token @llvm.call.preallocated.setup(i32 0)
13445 %t2 = call token @llvm.call.preallocated.setup(i32 0)
13446 call void foo() ["preallocated"(token %t1)]
13447 call void foo() ["preallocated"(token %t2)]
13449 .. _int_call_preallocated_arg:
13451 '``llvm.call.preallocated.arg``' Intrinsic
13452 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13459 declare ptr @llvm.call.preallocated.arg(token %setup_token, i32 %arg_index)
13464 The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the
13465 corresponding preallocated argument for the preallocated call.
13470 The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the
13471 ``%arg_index``th argument with the ``preallocated`` attribute for
13472 the call associated with the ``%setup_token``, which must be from
13473 '``llvm.call.preallocated.setup``'.
13475 A call to '``llvm.call.preallocated.arg``' must have a call site
13476 ``preallocated`` attribute. The type of the ``preallocated`` attribute must
13477 match the type used by the ``preallocated`` attribute of the corresponding
13478 argument at the preallocated call. The type is used in the case that an
13479 ``llvm.call.preallocated.setup`` does not have a corresponding call (e.g. due
13480 to DCE), where otherwise we cannot know how large the arguments are.
13482 It is undefined behavior if this is called with a token from an
13483 '``llvm.call.preallocated.setup``' if another
13484 '``llvm.call.preallocated.setup``' has already been called or if the
13485 preallocated call corresponding to the '``llvm.call.preallocated.setup``'
13486 has already been called.
13488 .. _int_call_preallocated_teardown:
13490 '``llvm.call.preallocated.teardown``' Intrinsic
13491 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13498 declare ptr @llvm.call.preallocated.teardown(token %setup_token)
13503 The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack
13504 created by a '``llvm.call.preallocated.setup``'.
13509 The token argument must be a '``llvm.call.preallocated.setup``'.
13511 The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack
13512 allocated by the corresponding '``llvm.call.preallocated.setup``'. Exactly
13513 one of this or the preallocated call must be called to prevent stack leaks.
13514 It is undefined behavior to call both a '``llvm.call.preallocated.teardown``'
13515 and the preallocated call for a given '``llvm.call.preallocated.setup``'.
13517 For example, if the stack is allocated for a preallocated call by a
13518 '``llvm.call.preallocated.setup``', then an initializer function called on an
13519 allocated argument throws an exception, there should be a
13520 '``llvm.call.preallocated.teardown``' in the exception handler to prevent
13523 Following the nesting rules in '``llvm.call.preallocated.setup``', nested
13524 calls to '``llvm.call.preallocated.setup``' and
13525 '``llvm.call.preallocated.teardown``' are allowed but must be properly
13531 .. code-block:: llvm
13533 %cs = call token @llvm.call.preallocated.setup(i32 1)
13534 %x = call ptr @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32)
13535 invoke void @constructor(ptr %x) to label %conta unwind label %contb
13537 call void @foo1(ptr preallocated(i32) %x) ["preallocated"(token %cs)]
13540 %s = catchswitch within none [label %catch] unwind to caller
13542 %p = catchpad within %s []
13543 call void @llvm.call.preallocated.teardown(token %cs)
13546 Standard C/C++ Library Intrinsics
13547 ---------------------------------
13549 LLVM provides intrinsics for a few important standard C/C++ library
13550 functions. These intrinsics allow source-language front-ends to pass
13551 information about the alignment of the pointer arguments to the code
13552 generator, providing opportunity for more efficient code generation.
13555 '``llvm.abs.*``' Intrinsic
13556 ^^^^^^^^^^^^^^^^^^^^^^^^^^
13561 This is an overloaded intrinsic. You can use ``llvm.abs`` on any
13562 integer bit width or any vector of integer elements.
13566 declare i32 @llvm.abs.i32(i32 <src>, i1 <is_int_min_poison>)
13567 declare <4 x i32> @llvm.abs.v4i32(<4 x i32> <src>, i1 <is_int_min_poison>)
13572 The '``llvm.abs``' family of intrinsic functions returns the absolute value
13578 The first argument is the value for which the absolute value is to be returned.
13579 This argument may be of any integer type or a vector with integer element type.
13580 The return type must match the first argument type.
13582 The second argument must be a constant and is a flag to indicate whether the
13583 result value of the '``llvm.abs``' intrinsic is a
13584 :ref:`poison value <poisonvalues>` if the argument is statically or dynamically
13585 an ``INT_MIN`` value.
13590 The '``llvm.abs``' intrinsic returns the magnitude (always positive) of the
13591 argument or each element of a vector argument.". If the argument is ``INT_MIN``,
13592 then the result is also ``INT_MIN`` if ``is_int_min_poison == 0`` and
13593 ``poison`` otherwise.
13596 '``llvm.smax.*``' Intrinsic
13597 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
13602 This is an overloaded intrinsic. You can use ``@llvm.smax`` on any
13603 integer bit width or any vector of integer elements.
13607 declare i32 @llvm.smax.i32(i32 %a, i32 %b)
13608 declare <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> %b)
13613 Return the larger of ``%a`` and ``%b`` comparing the values as signed integers.
13614 Vector intrinsics operate on a per-element basis. The larger element of ``%a``
13615 and ``%b`` at a given index is returned for that index.
13620 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
13621 integer element type. The argument types must match each other, and the return
13622 type must match the argument type.
13625 '``llvm.smin.*``' Intrinsic
13626 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
13631 This is an overloaded intrinsic. You can use ``@llvm.smin`` on any
13632 integer bit width or any vector of integer elements.
13636 declare i32 @llvm.smin.i32(i32 %a, i32 %b)
13637 declare <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> %b)
13642 Return the smaller of ``%a`` and ``%b`` comparing the values as signed integers.
13643 Vector intrinsics operate on a per-element basis. The smaller element of ``%a``
13644 and ``%b`` at a given index is returned for that index.
13649 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
13650 integer element type. The argument types must match each other, and the return
13651 type must match the argument type.
13654 '``llvm.umax.*``' Intrinsic
13655 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
13660 This is an overloaded intrinsic. You can use ``@llvm.umax`` on any
13661 integer bit width or any vector of integer elements.
13665 declare i32 @llvm.umax.i32(i32 %a, i32 %b)
13666 declare <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> %b)
13671 Return the larger of ``%a`` and ``%b`` comparing the values as unsigned
13672 integers. Vector intrinsics operate on a per-element basis. The larger element
13673 of ``%a`` and ``%b`` at a given index is returned for that index.
13678 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
13679 integer element type. The argument types must match each other, and the return
13680 type must match the argument type.
13683 '``llvm.umin.*``' Intrinsic
13684 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
13689 This is an overloaded intrinsic. You can use ``@llvm.umin`` on any
13690 integer bit width or any vector of integer elements.
13694 declare i32 @llvm.umin.i32(i32 %a, i32 %b)
13695 declare <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> %b)
13700 Return the smaller of ``%a`` and ``%b`` comparing the values as unsigned
13701 integers. Vector intrinsics operate on a per-element basis. The smaller element
13702 of ``%a`` and ``%b`` at a given index is returned for that index.
13707 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
13708 integer element type. The argument types must match each other, and the return
13709 type must match the argument type.
13714 '``llvm.memcpy``' Intrinsic
13715 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
13720 This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any
13721 integer bit width and for different address spaces. Not all targets
13722 support all bit widths however.
13726 declare void @llvm.memcpy.p0.p0.i32(ptr <dest>, ptr <src>,
13727 i32 <len>, i1 <isvolatile>)
13728 declare void @llvm.memcpy.p0.p0.i64(ptr <dest>, ptr <src>,
13729 i64 <len>, i1 <isvolatile>)
13734 The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
13735 source location to the destination location.
13737 Note that, unlike the standard libc function, the ``llvm.memcpy.*``
13738 intrinsics do not return a value, takes extra isvolatile
13739 arguments and the pointers can be in specified address spaces.
13744 The first argument is a pointer to the destination, the second is a
13745 pointer to the source. The third argument is an integer argument
13746 specifying the number of bytes to copy, and the fourth is a
13747 boolean indicating a volatile access.
13749 The :ref:`align <attr_align>` parameter attribute can be provided
13750 for the first and second arguments.
13752 If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is
13753 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
13754 very cleanly specified and it is unwise to depend on it.
13759 The '``llvm.memcpy.*``' intrinsics copy a block of memory from the source
13760 location to the destination location, which must either be equal or
13761 non-overlapping. It copies "len" bytes of memory over. If the argument is known
13762 to be aligned to some boundary, this can be specified as an attribute on the
13765 If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
13767 If ``<len>`` is not a well-defined value, the behavior is undefined.
13768 If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined,
13769 otherwise the behavior is undefined.
13771 .. _int_memcpy_inline:
13773 '``llvm.memcpy.inline``' Intrinsic
13774 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13779 This is an overloaded intrinsic. You can use ``llvm.memcpy.inline`` on any
13780 integer bit width and for different address spaces. Not all targets
13781 support all bit widths however.
13785 declare void @llvm.memcpy.inline.p0.p0.i32(ptr <dest>, ptr <src>,
13786 i32 <len>, i1 <isvolatile>)
13787 declare void @llvm.memcpy.inline.p0.p0.i64(ptr <dest>, ptr <src>,
13788 i64 <len>, i1 <isvolatile>)
13793 The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the
13794 source location to the destination location and guarantees that no external
13795 functions are called.
13797 Note that, unlike the standard libc function, the ``llvm.memcpy.inline.*``
13798 intrinsics do not return a value, takes extra isvolatile
13799 arguments and the pointers can be in specified address spaces.
13804 The first argument is a pointer to the destination, the second is a
13805 pointer to the source. The third argument is a constant integer argument
13806 specifying the number of bytes to copy, and the fourth is a
13807 boolean indicating a volatile access.
13809 The :ref:`align <attr_align>` parameter attribute can be provided
13810 for the first and second arguments.
13812 If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy.inline`` call is
13813 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
13814 very cleanly specified and it is unwise to depend on it.
13819 The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the
13820 source location to the destination location, which are not allowed to
13821 overlap. It copies "len" bytes of memory over. If the argument is known
13822 to be aligned to some boundary, this can be specified as an attribute on
13824 The behavior of '``llvm.memcpy.inline.*``' is equivalent to the behavior of
13825 '``llvm.memcpy.*``', but the generated code is guaranteed not to call any
13826 external functions.
13830 '``llvm.memmove``' Intrinsic
13831 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13836 This is an overloaded intrinsic. You can use llvm.memmove on any integer
13837 bit width and for different address space. Not all targets support all
13838 bit widths however.
13842 declare void @llvm.memmove.p0.p0.i32(ptr <dest>, ptr <src>,
13843 i32 <len>, i1 <isvolatile>)
13844 declare void @llvm.memmove.p0.p0.i64(ptr <dest>, ptr <src>,
13845 i64 <len>, i1 <isvolatile>)
13850 The '``llvm.memmove.*``' intrinsics move a block of memory from the
13851 source location to the destination location. It is similar to the
13852 '``llvm.memcpy``' intrinsic but allows the two memory locations to
13855 Note that, unlike the standard libc function, the ``llvm.memmove.*``
13856 intrinsics do not return a value, takes an extra isvolatile
13857 argument and the pointers can be in specified address spaces.
13862 The first argument is a pointer to the destination, the second is a
13863 pointer to the source. The third argument is an integer argument
13864 specifying the number of bytes to copy, and the fourth is a
13865 boolean indicating a volatile access.
13867 The :ref:`align <attr_align>` parameter attribute can be provided
13868 for the first and second arguments.
13870 If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call
13871 is a :ref:`volatile operation <volatile>`. The detailed access behavior is
13872 not very cleanly specified and it is unwise to depend on it.
13877 The '``llvm.memmove.*``' intrinsics copy a block of memory from the
13878 source location to the destination location, which may overlap. It
13879 copies "len" bytes of memory over. If the argument is known to be
13880 aligned to some boundary, this can be specified as an attribute on
13883 If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
13885 If ``<len>`` is not a well-defined value, the behavior is undefined.
13886 If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined,
13887 otherwise the behavior is undefined.
13891 '``llvm.memset.*``' Intrinsics
13892 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13897 This is an overloaded intrinsic. You can use llvm.memset on any integer
13898 bit width and for different address spaces. However, not all targets
13899 support all bit widths.
13903 declare void @llvm.memset.p0.i32(ptr <dest>, i8 <val>,
13904 i32 <len>, i1 <isvolatile>)
13905 declare void @llvm.memset.p0.i64(ptr <dest>, i8 <val>,
13906 i64 <len>, i1 <isvolatile>)
13911 The '``llvm.memset.*``' intrinsics fill a block of memory with a
13912 particular byte value.
13914 Note that, unlike the standard libc function, the ``llvm.memset``
13915 intrinsic does not return a value and takes an extra volatile
13916 argument. Also, the destination can be in an arbitrary address space.
13921 The first argument is a pointer to the destination to fill, the second
13922 is the byte value with which to fill it, the third argument is an
13923 integer argument specifying the number of bytes to fill, and the fourth
13924 is a boolean indicating a volatile access.
13926 The :ref:`align <attr_align>` parameter attribute can be provided
13927 for the first arguments.
13929 If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is
13930 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
13931 very cleanly specified and it is unwise to depend on it.
13936 The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting
13937 at the destination location. If the argument is known to be
13938 aligned to some boundary, this can be specified as an attribute on
13941 If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
13943 If ``<len>`` is not a well-defined value, the behavior is undefined.
13944 If ``<len>`` is not zero, ``<dest>`` should be well-defined, otherwise the
13945 behavior is undefined.
13947 .. _int_memset_inline:
13949 '``llvm.memset.inline``' Intrinsic
13950 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13955 This is an overloaded intrinsic. You can use ``llvm.memset.inline`` on any
13956 integer bit width and for different address spaces. Not all targets
13957 support all bit widths however.
13961 declare void @llvm.memset.inline.p0.p0i8.i32(ptr <dest>, i8 <val>,
13962 i32 <len>, i1 <isvolatile>)
13963 declare void @llvm.memset.inline.p0.p0.i64(ptr <dest>, i8 <val>,
13964 i64 <len>, i1 <isvolatile>)
13969 The '``llvm.memset.inline.*``' intrinsics fill a block of memory with a
13970 particular byte value and guarantees that no external functions are called.
13972 Note that, unlike the standard libc function, the ``llvm.memset.inline.*``
13973 intrinsics do not return a value, take an extra isvolatile argument and the
13974 pointer can be in specified address spaces.
13979 The first argument is a pointer to the destination to fill, the second
13980 is the byte value with which to fill it, the third argument is a constant
13981 integer argument specifying the number of bytes to fill, and the fourth
13982 is a boolean indicating a volatile access.
13984 The :ref:`align <attr_align>` parameter attribute can be provided
13985 for the first argument.
13987 If the ``isvolatile`` parameter is ``true``, the ``llvm.memset.inline`` call is
13988 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
13989 very cleanly specified and it is unwise to depend on it.
13994 The '``llvm.memset.inline.*``' intrinsics fill "len" bytes of memory starting
13995 at the destination location. If the argument is known to be
13996 aligned to some boundary, this can be specified as an attribute on
13999 ``len`` must be a constant expression.
14000 If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to
14002 If ``<len>`` is not a well-defined value, the behavior is undefined.
14003 If ``<len>`` is not zero, ``<dest>`` should be well-defined, otherwise the
14004 behavior is undefined.
14006 The behavior of '``llvm.memset.inline.*``' is equivalent to the behavior of
14007 '``llvm.memset.*``', but the generated code is guaranteed not to call any
14008 external functions.
14010 '``llvm.sqrt.*``' Intrinsic
14011 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14016 This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any
14017 floating-point or vector of floating-point type. Not all targets support
14022 declare float @llvm.sqrt.f32(float %Val)
14023 declare double @llvm.sqrt.f64(double %Val)
14024 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
14025 declare fp128 @llvm.sqrt.f128(fp128 %Val)
14026 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
14031 The '``llvm.sqrt``' intrinsics return the square root of the specified value.
14036 The argument and return value are floating-point numbers of the same type.
14041 Return the same value as a corresponding libm '``sqrt``' function but without
14042 trapping or setting ``errno``. For types specified by IEEE-754, the result
14043 matches a conforming libm implementation.
14045 When specified with the fast-math-flag 'afn', the result may be approximated
14046 using a less accurate calculation.
14048 '``llvm.powi.*``' Intrinsic
14049 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14054 This is an overloaded intrinsic. You can use ``llvm.powi`` on any
14055 floating-point or vector of floating-point type. Not all targets support
14058 Generally, the only supported type for the exponent is the one matching
14059 with the C type ``int``.
14063 declare float @llvm.powi.f32.i32(float %Val, i32 %power)
14064 declare double @llvm.powi.f64.i16(double %Val, i16 %power)
14065 declare x86_fp80 @llvm.powi.f80.i32(x86_fp80 %Val, i32 %power)
14066 declare fp128 @llvm.powi.f128.i32(fp128 %Val, i32 %power)
14067 declare ppc_fp128 @llvm.powi.ppcf128.i32(ppc_fp128 %Val, i32 %power)
14072 The '``llvm.powi.*``' intrinsics return the first operand raised to the
14073 specified (positive or negative) power. The order of evaluation of
14074 multiplications is not defined. When a vector of floating-point type is
14075 used, the second argument remains a scalar integer value.
14080 The second argument is an integer power, and the first is a value to
14081 raise to that power.
14086 This function returns the first value raised to the second power with an
14087 unspecified sequence of rounding operations.
14089 '``llvm.sin.*``' Intrinsic
14090 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14095 This is an overloaded intrinsic. You can use ``llvm.sin`` on any
14096 floating-point or vector of floating-point type. Not all targets support
14101 declare float @llvm.sin.f32(float %Val)
14102 declare double @llvm.sin.f64(double %Val)
14103 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
14104 declare fp128 @llvm.sin.f128(fp128 %Val)
14105 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
14110 The '``llvm.sin.*``' intrinsics return the sine of the operand.
14115 The argument and return value are floating-point numbers of the same type.
14120 Return the same value as a corresponding libm '``sin``' function but without
14121 trapping or setting ``errno``.
14123 When specified with the fast-math-flag 'afn', the result may be approximated
14124 using a less accurate calculation.
14126 '``llvm.cos.*``' Intrinsic
14127 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14132 This is an overloaded intrinsic. You can use ``llvm.cos`` on any
14133 floating-point or vector of floating-point type. Not all targets support
14138 declare float @llvm.cos.f32(float %Val)
14139 declare double @llvm.cos.f64(double %Val)
14140 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
14141 declare fp128 @llvm.cos.f128(fp128 %Val)
14142 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
14147 The '``llvm.cos.*``' intrinsics return the cosine of the operand.
14152 The argument and return value are floating-point numbers of the same type.
14157 Return the same value as a corresponding libm '``cos``' function but without
14158 trapping or setting ``errno``.
14160 When specified with the fast-math-flag 'afn', the result may be approximated
14161 using a less accurate calculation.
14163 '``llvm.pow.*``' Intrinsic
14164 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14169 This is an overloaded intrinsic. You can use ``llvm.pow`` on any
14170 floating-point or vector of floating-point type. Not all targets support
14175 declare float @llvm.pow.f32(float %Val, float %Power)
14176 declare double @llvm.pow.f64(double %Val, double %Power)
14177 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
14178 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
14179 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
14184 The '``llvm.pow.*``' intrinsics return the first operand raised to the
14185 specified (positive or negative) power.
14190 The arguments and return value are floating-point numbers of the same type.
14195 Return the same value as a corresponding libm '``pow``' function but without
14196 trapping or setting ``errno``.
14198 When specified with the fast-math-flag 'afn', the result may be approximated
14199 using a less accurate calculation.
14201 '``llvm.exp.*``' Intrinsic
14202 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14207 This is an overloaded intrinsic. You can use ``llvm.exp`` on any
14208 floating-point or vector of floating-point type. Not all targets support
14213 declare float @llvm.exp.f32(float %Val)
14214 declare double @llvm.exp.f64(double %Val)
14215 declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val)
14216 declare fp128 @llvm.exp.f128(fp128 %Val)
14217 declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val)
14222 The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified
14228 The argument and return value are floating-point numbers of the same type.
14233 Return the same value as a corresponding libm '``exp``' function but without
14234 trapping or setting ``errno``.
14236 When specified with the fast-math-flag 'afn', the result may be approximated
14237 using a less accurate calculation.
14239 '``llvm.exp2.*``' Intrinsic
14240 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14245 This is an overloaded intrinsic. You can use ``llvm.exp2`` on any
14246 floating-point or vector of floating-point type. Not all targets support
14251 declare float @llvm.exp2.f32(float %Val)
14252 declare double @llvm.exp2.f64(double %Val)
14253 declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val)
14254 declare fp128 @llvm.exp2.f128(fp128 %Val)
14255 declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val)
14260 The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the
14266 The argument and return value are floating-point numbers of the same type.
14271 Return the same value as a corresponding libm '``exp2``' function but without
14272 trapping or setting ``errno``.
14274 When specified with the fast-math-flag 'afn', the result may be approximated
14275 using a less accurate calculation.
14277 '``llvm.log.*``' Intrinsic
14278 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14283 This is an overloaded intrinsic. You can use ``llvm.log`` on any
14284 floating-point or vector of floating-point type. Not all targets support
14289 declare float @llvm.log.f32(float %Val)
14290 declare double @llvm.log.f64(double %Val)
14291 declare x86_fp80 @llvm.log.f80(x86_fp80 %Val)
14292 declare fp128 @llvm.log.f128(fp128 %Val)
14293 declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val)
14298 The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified
14304 The argument and return value are floating-point numbers of the same type.
14309 Return the same value as a corresponding libm '``log``' function but without
14310 trapping or setting ``errno``.
14312 When specified with the fast-math-flag 'afn', the result may be approximated
14313 using a less accurate calculation.
14315 '``llvm.log10.*``' Intrinsic
14316 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14321 This is an overloaded intrinsic. You can use ``llvm.log10`` on any
14322 floating-point or vector of floating-point type. Not all targets support
14327 declare float @llvm.log10.f32(float %Val)
14328 declare double @llvm.log10.f64(double %Val)
14329 declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val)
14330 declare fp128 @llvm.log10.f128(fp128 %Val)
14331 declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val)
14336 The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the
14342 The argument and return value are floating-point numbers of the same type.
14347 Return the same value as a corresponding libm '``log10``' function but without
14348 trapping or setting ``errno``.
14350 When specified with the fast-math-flag 'afn', the result may be approximated
14351 using a less accurate calculation.
14353 '``llvm.log2.*``' Intrinsic
14354 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14359 This is an overloaded intrinsic. You can use ``llvm.log2`` on any
14360 floating-point or vector of floating-point type. Not all targets support
14365 declare float @llvm.log2.f32(float %Val)
14366 declare double @llvm.log2.f64(double %Val)
14367 declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val)
14368 declare fp128 @llvm.log2.f128(fp128 %Val)
14369 declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val)
14374 The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified
14380 The argument and return value are floating-point numbers of the same type.
14385 Return the same value as a corresponding libm '``log2``' function but without
14386 trapping or setting ``errno``.
14388 When specified with the fast-math-flag 'afn', the result may be approximated
14389 using a less accurate calculation.
14393 '``llvm.fma.*``' Intrinsic
14394 ^^^^^^^^^^^^^^^^^^^^^^^^^^
14399 This is an overloaded intrinsic. You can use ``llvm.fma`` on any
14400 floating-point or vector of floating-point type. Not all targets support
14405 declare float @llvm.fma.f32(float %a, float %b, float %c)
14406 declare double @llvm.fma.f64(double %a, double %b, double %c)
14407 declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c)
14408 declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c)
14409 declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c)
14414 The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation.
14419 The arguments and return value are floating-point numbers of the same type.
14424 Return the same value as a corresponding libm '``fma``' function but without
14425 trapping or setting ``errno``.
14427 When specified with the fast-math-flag 'afn', the result may be approximated
14428 using a less accurate calculation.
14430 '``llvm.fabs.*``' Intrinsic
14431 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14436 This is an overloaded intrinsic. You can use ``llvm.fabs`` on any
14437 floating-point or vector of floating-point type. Not all targets support
14442 declare float @llvm.fabs.f32(float %Val)
14443 declare double @llvm.fabs.f64(double %Val)
14444 declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val)
14445 declare fp128 @llvm.fabs.f128(fp128 %Val)
14446 declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
14451 The '``llvm.fabs.*``' intrinsics return the absolute value of the
14457 The argument and return value are floating-point numbers of the same
14463 This function returns the same values as the libm ``fabs`` functions
14464 would, and handles error conditions in the same way.
14466 '``llvm.minnum.*``' Intrinsic
14467 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14472 This is an overloaded intrinsic. You can use ``llvm.minnum`` on any
14473 floating-point or vector of floating-point type. Not all targets support
14478 declare float @llvm.minnum.f32(float %Val0, float %Val1)
14479 declare double @llvm.minnum.f64(double %Val0, double %Val1)
14480 declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
14481 declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1)
14482 declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
14487 The '``llvm.minnum.*``' intrinsics return the minimum of the two
14494 The arguments and return value are floating-point numbers of the same
14500 Follows the IEEE-754 semantics for minNum, except for handling of
14501 signaling NaNs. This match's the behavior of libm's fmin.
14503 If either operand is a NaN, returns the other non-NaN operand. Returns
14504 NaN only if both operands are NaN. The returned NaN is always
14505 quiet. If the operands compare equal, returns a value that compares
14506 equal to both operands. This means that fmin(+/-0.0, +/-0.0) could
14507 return either -0.0 or 0.0.
14509 Unlike the IEEE-754 2008 behavior, this does not distinguish between
14510 signaling and quiet NaN inputs. If a target's implementation follows
14511 the standard and returns a quiet NaN if either input is a signaling
14512 NaN, the intrinsic lowering is responsible for quieting the inputs to
14513 correctly return the non-NaN input (e.g. by using the equivalent of
14514 ``llvm.canonicalize``).
14517 '``llvm.maxnum.*``' Intrinsic
14518 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14523 This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any
14524 floating-point or vector of floating-point type. Not all targets support
14529 declare float @llvm.maxnum.f32(float %Val0, float %Val1)
14530 declare double @llvm.maxnum.f64(double %Val0, double %Val1)
14531 declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
14532 declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1)
14533 declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
14538 The '``llvm.maxnum.*``' intrinsics return the maximum of the two
14545 The arguments and return value are floating-point numbers of the same
14550 Follows the IEEE-754 semantics for maxNum except for the handling of
14551 signaling NaNs. This matches the behavior of libm's fmax.
14553 If either operand is a NaN, returns the other non-NaN operand. Returns
14554 NaN only if both operands are NaN. The returned NaN is always
14555 quiet. If the operands compare equal, returns a value that compares
14556 equal to both operands. This means that fmax(+/-0.0, +/-0.0) could
14557 return either -0.0 or 0.0.
14559 Unlike the IEEE-754 2008 behavior, this does not distinguish between
14560 signaling and quiet NaN inputs. If a target's implementation follows
14561 the standard and returns a quiet NaN if either input is a signaling
14562 NaN, the intrinsic lowering is responsible for quieting the inputs to
14563 correctly return the non-NaN input (e.g. by using the equivalent of
14564 ``llvm.canonicalize``).
14566 '``llvm.minimum.*``' Intrinsic
14567 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14572 This is an overloaded intrinsic. You can use ``llvm.minimum`` on any
14573 floating-point or vector of floating-point type. Not all targets support
14578 declare float @llvm.minimum.f32(float %Val0, float %Val1)
14579 declare double @llvm.minimum.f64(double %Val0, double %Val1)
14580 declare x86_fp80 @llvm.minimum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
14581 declare fp128 @llvm.minimum.f128(fp128 %Val0, fp128 %Val1)
14582 declare ppc_fp128 @llvm.minimum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
14587 The '``llvm.minimum.*``' intrinsics return the minimum of the two
14588 arguments, propagating NaNs and treating -0.0 as less than +0.0.
14594 The arguments and return value are floating-point numbers of the same
14599 If either operand is a NaN, returns NaN. Otherwise returns the lesser
14600 of the two arguments. -0.0 is considered to be less than +0.0 for this
14601 intrinsic. Note that these are the semantics specified in the draft of
14604 '``llvm.maximum.*``' Intrinsic
14605 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14610 This is an overloaded intrinsic. You can use ``llvm.maximum`` on any
14611 floating-point or vector of floating-point type. Not all targets support
14616 declare float @llvm.maximum.f32(float %Val0, float %Val1)
14617 declare double @llvm.maximum.f64(double %Val0, double %Val1)
14618 declare x86_fp80 @llvm.maximum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
14619 declare fp128 @llvm.maximum.f128(fp128 %Val0, fp128 %Val1)
14620 declare ppc_fp128 @llvm.maximum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
14625 The '``llvm.maximum.*``' intrinsics return the maximum of the two
14626 arguments, propagating NaNs and treating -0.0 as less than +0.0.
14632 The arguments and return value are floating-point numbers of the same
14637 If either operand is a NaN, returns NaN. Otherwise returns the greater
14638 of the two arguments. -0.0 is considered to be less than +0.0 for this
14639 intrinsic. Note that these are the semantics specified in the draft of
14642 '``llvm.copysign.*``' Intrinsic
14643 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14648 This is an overloaded intrinsic. You can use ``llvm.copysign`` on any
14649 floating-point or vector of floating-point type. Not all targets support
14654 declare float @llvm.copysign.f32(float %Mag, float %Sgn)
14655 declare double @llvm.copysign.f64(double %Mag, double %Sgn)
14656 declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn)
14657 declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn)
14658 declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn)
14663 The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the
14664 first operand and the sign of the second operand.
14669 The arguments and return value are floating-point numbers of the same
14675 This function returns the same values as the libm ``copysign``
14676 functions would, and handles error conditions in the same way.
14678 '``llvm.floor.*``' Intrinsic
14679 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14684 This is an overloaded intrinsic. You can use ``llvm.floor`` on any
14685 floating-point or vector of floating-point type. Not all targets support
14690 declare float @llvm.floor.f32(float %Val)
14691 declare double @llvm.floor.f64(double %Val)
14692 declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val)
14693 declare fp128 @llvm.floor.f128(fp128 %Val)
14694 declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val)
14699 The '``llvm.floor.*``' intrinsics return the floor of the operand.
14704 The argument and return value are floating-point numbers of the same
14710 This function returns the same values as the libm ``floor`` functions
14711 would, and handles error conditions in the same way.
14713 '``llvm.ceil.*``' Intrinsic
14714 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14719 This is an overloaded intrinsic. You can use ``llvm.ceil`` on any
14720 floating-point or vector of floating-point type. Not all targets support
14725 declare float @llvm.ceil.f32(float %Val)
14726 declare double @llvm.ceil.f64(double %Val)
14727 declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val)
14728 declare fp128 @llvm.ceil.f128(fp128 %Val)
14729 declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val)
14734 The '``llvm.ceil.*``' intrinsics return the ceiling of the operand.
14739 The argument and return value are floating-point numbers of the same
14745 This function returns the same values as the libm ``ceil`` functions
14746 would, and handles error conditions in the same way.
14748 '``llvm.trunc.*``' Intrinsic
14749 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14754 This is an overloaded intrinsic. You can use ``llvm.trunc`` on any
14755 floating-point or vector of floating-point type. Not all targets support
14760 declare float @llvm.trunc.f32(float %Val)
14761 declare double @llvm.trunc.f64(double %Val)
14762 declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val)
14763 declare fp128 @llvm.trunc.f128(fp128 %Val)
14764 declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val)
14769 The '``llvm.trunc.*``' intrinsics returns the operand rounded to the
14770 nearest integer not larger in magnitude than the operand.
14775 The argument and return value are floating-point numbers of the same
14781 This function returns the same values as the libm ``trunc`` functions
14782 would, and handles error conditions in the same way.
14784 '``llvm.rint.*``' Intrinsic
14785 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
14790 This is an overloaded intrinsic. You can use ``llvm.rint`` on any
14791 floating-point or vector of floating-point type. Not all targets support
14796 declare float @llvm.rint.f32(float %Val)
14797 declare double @llvm.rint.f64(double %Val)
14798 declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val)
14799 declare fp128 @llvm.rint.f128(fp128 %Val)
14800 declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val)
14805 The '``llvm.rint.*``' intrinsics returns the operand rounded to the
14806 nearest integer. It may raise an inexact floating-point exception if the
14807 operand isn't an integer.
14812 The argument and return value are floating-point numbers of the same
14818 This function returns the same values as the libm ``rint`` functions
14819 would, and handles error conditions in the same way.
14821 '``llvm.nearbyint.*``' Intrinsic
14822 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14827 This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any
14828 floating-point or vector of floating-point type. Not all targets support
14833 declare float @llvm.nearbyint.f32(float %Val)
14834 declare double @llvm.nearbyint.f64(double %Val)
14835 declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val)
14836 declare fp128 @llvm.nearbyint.f128(fp128 %Val)
14837 declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val)
14842 The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the
14848 The argument and return value are floating-point numbers of the same
14854 This function returns the same values as the libm ``nearbyint``
14855 functions would, and handles error conditions in the same way.
14857 '``llvm.round.*``' Intrinsic
14858 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14863 This is an overloaded intrinsic. You can use ``llvm.round`` on any
14864 floating-point or vector of floating-point type. Not all targets support
14869 declare float @llvm.round.f32(float %Val)
14870 declare double @llvm.round.f64(double %Val)
14871 declare x86_fp80 @llvm.round.f80(x86_fp80 %Val)
14872 declare fp128 @llvm.round.f128(fp128 %Val)
14873 declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val)
14878 The '``llvm.round.*``' intrinsics returns the operand rounded to the
14884 The argument and return value are floating-point numbers of the same
14890 This function returns the same values as the libm ``round``
14891 functions would, and handles error conditions in the same way.
14893 '``llvm.roundeven.*``' Intrinsic
14894 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14899 This is an overloaded intrinsic. You can use ``llvm.roundeven`` on any
14900 floating-point or vector of floating-point type. Not all targets support
14905 declare float @llvm.roundeven.f32(float %Val)
14906 declare double @llvm.roundeven.f64(double %Val)
14907 declare x86_fp80 @llvm.roundeven.f80(x86_fp80 %Val)
14908 declare fp128 @llvm.roundeven.f128(fp128 %Val)
14909 declare ppc_fp128 @llvm.roundeven.ppcf128(ppc_fp128 %Val)
14914 The '``llvm.roundeven.*``' intrinsics returns the operand rounded to the nearest
14915 integer in floating-point format rounding halfway cases to even (that is, to the
14916 nearest value that is an even integer).
14921 The argument and return value are floating-point numbers of the same type.
14926 This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It
14927 also behaves in the same way as C standard function ``roundeven``, except that
14928 it does not raise floating point exceptions.
14931 '``llvm.lround.*``' Intrinsic
14932 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14937 This is an overloaded intrinsic. You can use ``llvm.lround`` on any
14938 floating-point type. Not all targets support all types however.
14942 declare i32 @llvm.lround.i32.f32(float %Val)
14943 declare i32 @llvm.lround.i32.f64(double %Val)
14944 declare i32 @llvm.lround.i32.f80(float %Val)
14945 declare i32 @llvm.lround.i32.f128(double %Val)
14946 declare i32 @llvm.lround.i32.ppcf128(double %Val)
14948 declare i64 @llvm.lround.i64.f32(float %Val)
14949 declare i64 @llvm.lround.i64.f64(double %Val)
14950 declare i64 @llvm.lround.i64.f80(float %Val)
14951 declare i64 @llvm.lround.i64.f128(double %Val)
14952 declare i64 @llvm.lround.i64.ppcf128(double %Val)
14957 The '``llvm.lround.*``' intrinsics return the operand rounded to the nearest
14958 integer with ties away from zero.
14964 The argument is a floating-point number and the return value is an integer
14970 This function returns the same values as the libm ``lround``
14971 functions would, but without setting errno.
14973 '``llvm.llround.*``' Intrinsic
14974 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14979 This is an overloaded intrinsic. You can use ``llvm.llround`` on any
14980 floating-point type. Not all targets support all types however.
14984 declare i64 @llvm.lround.i64.f32(float %Val)
14985 declare i64 @llvm.lround.i64.f64(double %Val)
14986 declare i64 @llvm.lround.i64.f80(float %Val)
14987 declare i64 @llvm.lround.i64.f128(double %Val)
14988 declare i64 @llvm.lround.i64.ppcf128(double %Val)
14993 The '``llvm.llround.*``' intrinsics return the operand rounded to the nearest
14994 integer with ties away from zero.
14999 The argument is a floating-point number and the return value is an integer
15005 This function returns the same values as the libm ``llround``
15006 functions would, but without setting errno.
15008 '``llvm.lrint.*``' Intrinsic
15009 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15014 This is an overloaded intrinsic. You can use ``llvm.lrint`` on any
15015 floating-point type. Not all targets support all types however.
15019 declare i32 @llvm.lrint.i32.f32(float %Val)
15020 declare i32 @llvm.lrint.i32.f64(double %Val)
15021 declare i32 @llvm.lrint.i32.f80(float %Val)
15022 declare i32 @llvm.lrint.i32.f128(double %Val)
15023 declare i32 @llvm.lrint.i32.ppcf128(double %Val)
15025 declare i64 @llvm.lrint.i64.f32(float %Val)
15026 declare i64 @llvm.lrint.i64.f64(double %Val)
15027 declare i64 @llvm.lrint.i64.f80(float %Val)
15028 declare i64 @llvm.lrint.i64.f128(double %Val)
15029 declare i64 @llvm.lrint.i64.ppcf128(double %Val)
15034 The '``llvm.lrint.*``' intrinsics return the operand rounded to the nearest
15041 The argument is a floating-point number and the return value is an integer
15047 This function returns the same values as the libm ``lrint``
15048 functions would, but without setting errno.
15050 '``llvm.llrint.*``' Intrinsic
15051 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15056 This is an overloaded intrinsic. You can use ``llvm.llrint`` on any
15057 floating-point type. Not all targets support all types however.
15061 declare i64 @llvm.llrint.i64.f32(float %Val)
15062 declare i64 @llvm.llrint.i64.f64(double %Val)
15063 declare i64 @llvm.llrint.i64.f80(float %Val)
15064 declare i64 @llvm.llrint.i64.f128(double %Val)
15065 declare i64 @llvm.llrint.i64.ppcf128(double %Val)
15070 The '``llvm.llrint.*``' intrinsics return the operand rounded to the nearest
15076 The argument is a floating-point number and the return value is an integer
15082 This function returns the same values as the libm ``llrint``
15083 functions would, but without setting errno.
15085 Bit Manipulation Intrinsics
15086 ---------------------------
15088 LLVM provides intrinsics for a few important bit manipulation
15089 operations. These allow efficient code generation for some algorithms.
15091 '``llvm.bitreverse.*``' Intrinsics
15092 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15097 This is an overloaded intrinsic function. You can use bitreverse on any
15102 declare i16 @llvm.bitreverse.i16(i16 <id>)
15103 declare i32 @llvm.bitreverse.i32(i32 <id>)
15104 declare i64 @llvm.bitreverse.i64(i64 <id>)
15105 declare <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> <id>)
15110 The '``llvm.bitreverse``' family of intrinsics is used to reverse the
15111 bitpattern of an integer value or vector of integer values; for example
15112 ``0b10110110`` becomes ``0b01101101``.
15117 The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit
15118 ``M`` in the input moved to bit ``N-M-1`` in the output. The vector
15119 intrinsics, such as ``llvm.bitreverse.v4i32``, operate on a per-element
15120 basis and the element order is not affected.
15122 '``llvm.bswap.*``' Intrinsics
15123 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15128 This is an overloaded intrinsic function. You can use bswap on any
15129 integer type that is an even number of bytes (i.e. BitWidth % 16 == 0).
15133 declare i16 @llvm.bswap.i16(i16 <id>)
15134 declare i32 @llvm.bswap.i32(i32 <id>)
15135 declare i64 @llvm.bswap.i64(i64 <id>)
15136 declare <4 x i32> @llvm.bswap.v4i32(<4 x i32> <id>)
15141 The '``llvm.bswap``' family of intrinsics is used to byte swap an integer
15142 value or vector of integer values with an even number of bytes (positive
15143 multiple of 16 bits).
15148 The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high
15149 and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32``
15150 intrinsic returns an i32 value that has the four bytes of the input i32
15151 swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the
15152 returned i32 will have its bytes in 3, 2, 1, 0 order. The
15153 ``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this
15154 concept to additional even-byte lengths (6 bytes, 8 bytes and more,
15155 respectively). The vector intrinsics, such as ``llvm.bswap.v4i32``,
15156 operate on a per-element basis and the element order is not affected.
15158 '``llvm.ctpop.*``' Intrinsic
15159 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15164 This is an overloaded intrinsic. You can use llvm.ctpop on any integer
15165 bit width, or on any vector with integer elements. Not all targets
15166 support all bit widths or vector types, however.
15170 declare i8 @llvm.ctpop.i8(i8 <src>)
15171 declare i16 @llvm.ctpop.i16(i16 <src>)
15172 declare i32 @llvm.ctpop.i32(i32 <src>)
15173 declare i64 @llvm.ctpop.i64(i64 <src>)
15174 declare i256 @llvm.ctpop.i256(i256 <src>)
15175 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>)
15180 The '``llvm.ctpop``' family of intrinsics counts the number of bits set
15186 The only argument is the value to be counted. The argument may be of any
15187 integer type, or a vector with integer elements. The return type must
15188 match the argument type.
15193 The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within
15194 each element of a vector.
15196 '``llvm.ctlz.*``' Intrinsic
15197 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15202 This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any
15203 integer bit width, or any vector whose elements are integers. Not all
15204 targets support all bit widths or vector types, however.
15208 declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_poison>)
15209 declare <2 x i37> @llvm.ctlz.v2i37(<2 x i37> <src>, i1 <is_zero_poison>)
15214 The '``llvm.ctlz``' family of intrinsic functions counts the number of
15215 leading zeros in a variable.
15220 The first argument is the value to be counted. This argument may be of
15221 any integer type, or a vector with integer element type. The return
15222 type must match the first argument type.
15224 The second argument is a constant flag that indicates whether the intrinsic
15225 returns a valid result if the first argument is zero. If the first
15226 argument is zero and the second argument is true, the result is poison.
15227 Historically some architectures did not provide a defined result for zero
15228 values as efficiently, and many algorithms are now predicated on avoiding
15234 The '``llvm.ctlz``' intrinsic counts the leading (most significant)
15235 zeros in a variable, or within each element of the vector. If
15236 ``src == 0`` then the result is the size in bits of the type of ``src``
15237 if ``is_zero_poison == 0`` and ``poison`` otherwise. For example,
15238 ``llvm.ctlz(i32 2) = 30``.
15240 '``llvm.cttz.*``' Intrinsic
15241 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15246 This is an overloaded intrinsic. You can use ``llvm.cttz`` on any
15247 integer bit width, or any vector of integer elements. Not all targets
15248 support all bit widths or vector types, however.
15252 declare i42 @llvm.cttz.i42 (i42 <src>, i1 <is_zero_poison>)
15253 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_poison>)
15258 The '``llvm.cttz``' family of intrinsic functions counts the number of
15264 The first argument is the value to be counted. This argument may be of
15265 any integer type, or a vector with integer element type. The return
15266 type must match the first argument type.
15268 The second argument is a constant flag that indicates whether the intrinsic
15269 returns a valid result if the first argument is zero. If the first
15270 argument is zero and the second argument is true, the result is poison.
15271 Historically some architectures did not provide a defined result for zero
15272 values as efficiently, and many algorithms are now predicated on avoiding
15278 The '``llvm.cttz``' intrinsic counts the trailing (least significant)
15279 zeros in a variable, or within each element of a vector. If ``src == 0``
15280 then the result is the size in bits of the type of ``src`` if
15281 ``is_zero_poison == 0`` and ``poison`` otherwise. For example,
15282 ``llvm.cttz(2) = 1``.
15286 '``llvm.fshl.*``' Intrinsic
15287 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15292 This is an overloaded intrinsic. You can use ``llvm.fshl`` on any
15293 integer bit width or any vector of integer elements. Not all targets
15294 support all bit widths or vector types, however.
15298 declare i8 @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c)
15299 declare i67 @llvm.fshl.i67(i67 %a, i67 %b, i67 %c)
15300 declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
15305 The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left:
15306 the first two values are concatenated as { %a : %b } (%a is the most significant
15307 bits of the wide value), the combined value is shifted left, and the most
15308 significant bits are extracted to produce a result that is the same size as the
15309 original arguments. If the first 2 arguments are identical, this is equivalent
15310 to a rotate left operation. For vector types, the operation occurs for each
15311 element of the vector. The shift argument is treated as an unsigned amount
15312 modulo the element size of the arguments.
15317 The first two arguments are the values to be concatenated. The third
15318 argument is the shift amount. The arguments may be any integer type or a
15319 vector with integer element type. All arguments and the return value must
15320 have the same type.
15325 .. code-block:: text
15327 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8)
15328 %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15) ; %r = i8: 128 (0b10000000)
15329 %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11) ; %r = i8: 120 (0b01111000)
15330 %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8) ; %r = i8: 0 (0b00000000)
15332 '``llvm.fshr.*``' Intrinsic
15333 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
15338 This is an overloaded intrinsic. You can use ``llvm.fshr`` on any
15339 integer bit width or any vector of integer elements. Not all targets
15340 support all bit widths or vector types, however.
15344 declare i8 @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c)
15345 declare i67 @llvm.fshr.i67(i67 %a, i67 %b, i67 %c)
15346 declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
15351 The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right:
15352 the first two values are concatenated as { %a : %b } (%a is the most significant
15353 bits of the wide value), the combined value is shifted right, and the least
15354 significant bits are extracted to produce a result that is the same size as the
15355 original arguments. If the first 2 arguments are identical, this is equivalent
15356 to a rotate right operation. For vector types, the operation occurs for each
15357 element of the vector. The shift argument is treated as an unsigned amount
15358 modulo the element size of the arguments.
15363 The first two arguments are the values to be concatenated. The third
15364 argument is the shift amount. The arguments may be any integer type or a
15365 vector with integer element type. All arguments and the return value must
15366 have the same type.
15371 .. code-block:: text
15373 %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8)
15374 %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15) ; %r = i8: 254 (0b11111110)
15375 %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11) ; %r = i8: 225 (0b11100001)
15376 %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8) ; %r = i8: 255 (0b11111111)
15378 Arithmetic with Overflow Intrinsics
15379 -----------------------------------
15381 LLVM provides intrinsics for fast arithmetic overflow checking.
15383 Each of these intrinsics returns a two-element struct. The first
15384 element of this struct contains the result of the corresponding
15385 arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of
15386 the result. Therefore, for example, the first element of the struct
15387 returned by ``llvm.sadd.with.overflow.i32`` is always the same as the
15388 result of a 32-bit ``add`` instruction with the same operands, where
15389 the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag.
15391 The second element of the result is an ``i1`` that is 1 if the
15392 arithmetic operation overflowed and 0 otherwise. An operation
15393 overflows if, for any values of its operands ``A`` and ``B`` and for
15394 any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is
15395 not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is
15396 ``sext`` for signed overflow and ``zext`` for unsigned overflow, and
15397 ``op`` is the underlying arithmetic operation.
15399 The behavior of these intrinsics is well-defined for all argument
15402 '``llvm.sadd.with.overflow.*``' Intrinsics
15403 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15408 This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow``
15409 on any integer bit width or vectors of integers.
15413 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
15414 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
15415 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
15416 declare {<4 x i32>, <4 x i1>} @llvm.sadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15421 The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
15422 a signed addition of the two arguments, and indicate whether an overflow
15423 occurred during the signed summation.
15428 The arguments (%a and %b) and the first element of the result structure
15429 may be of integer types of any bit width, but they must have the same
15430 bit width. The second element of the result structure must be of type
15431 ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
15437 The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
15438 a signed addition of the two variables. They return a structure --- the
15439 first element of which is the signed summation, and the second element
15440 of which is a bit specifying if the signed summation resulted in an
15446 .. code-block:: llvm
15448 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
15449 %sum = extractvalue {i32, i1} %res, 0
15450 %obit = extractvalue {i32, i1} %res, 1
15451 br i1 %obit, label %overflow, label %normal
15453 '``llvm.uadd.with.overflow.*``' Intrinsics
15454 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15459 This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow``
15460 on any integer bit width or vectors of integers.
15464 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
15465 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
15466 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
15467 declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15472 The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
15473 an unsigned addition of the two arguments, and indicate whether a carry
15474 occurred during the unsigned summation.
15479 The arguments (%a and %b) and the first element of the result structure
15480 may be of integer types of any bit width, but they must have the same
15481 bit width. The second element of the result structure must be of type
15482 ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
15488 The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
15489 an unsigned addition of the two arguments. They return a structure --- the
15490 first element of which is the sum, and the second element of which is a
15491 bit specifying if the unsigned summation resulted in a carry.
15496 .. code-block:: llvm
15498 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
15499 %sum = extractvalue {i32, i1} %res, 0
15500 %obit = extractvalue {i32, i1} %res, 1
15501 br i1 %obit, label %carry, label %normal
15503 '``llvm.ssub.with.overflow.*``' Intrinsics
15504 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15509 This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow``
15510 on any integer bit width or vectors of integers.
15514 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
15515 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
15516 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
15517 declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15522 The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
15523 a signed subtraction of the two arguments, and indicate whether an
15524 overflow occurred during the signed subtraction.
15529 The arguments (%a and %b) and the first element of the result structure
15530 may be of integer types of any bit width, but they must have the same
15531 bit width. The second element of the result structure must be of type
15532 ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
15538 The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
15539 a signed subtraction of the two arguments. They return a structure --- the
15540 first element of which is the subtraction, and the second element of
15541 which is a bit specifying if the signed subtraction resulted in an
15547 .. code-block:: llvm
15549 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
15550 %sum = extractvalue {i32, i1} %res, 0
15551 %obit = extractvalue {i32, i1} %res, 1
15552 br i1 %obit, label %overflow, label %normal
15554 '``llvm.usub.with.overflow.*``' Intrinsics
15555 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15560 This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow``
15561 on any integer bit width or vectors of integers.
15565 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
15566 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
15567 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
15568 declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15573 The '``llvm.usub.with.overflow``' family of intrinsic functions perform
15574 an unsigned subtraction of the two arguments, and indicate whether an
15575 overflow occurred during the unsigned subtraction.
15580 The arguments (%a and %b) and the first element of the result structure
15581 may be of integer types of any bit width, but they must have the same
15582 bit width. The second element of the result structure must be of type
15583 ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
15589 The '``llvm.usub.with.overflow``' family of intrinsic functions perform
15590 an unsigned subtraction of the two arguments. They return a structure ---
15591 the first element of which is the subtraction, and the second element of
15592 which is a bit specifying if the unsigned subtraction resulted in an
15598 .. code-block:: llvm
15600 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
15601 %sum = extractvalue {i32, i1} %res, 0
15602 %obit = extractvalue {i32, i1} %res, 1
15603 br i1 %obit, label %overflow, label %normal
15605 '``llvm.smul.with.overflow.*``' Intrinsics
15606 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15611 This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow``
15612 on any integer bit width or vectors of integers.
15616 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
15617 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
15618 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
15619 declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15624 The '``llvm.smul.with.overflow``' family of intrinsic functions perform
15625 a signed multiplication of the two arguments, and indicate whether an
15626 overflow occurred during the signed multiplication.
15631 The arguments (%a and %b) and the first element of the result structure
15632 may be of integer types of any bit width, but they must have the same
15633 bit width. The second element of the result structure must be of type
15634 ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
15640 The '``llvm.smul.with.overflow``' family of intrinsic functions perform
15641 a signed multiplication of the two arguments. They return a structure ---
15642 the first element of which is the multiplication, and the second element
15643 of which is a bit specifying if the signed multiplication resulted in an
15649 .. code-block:: llvm
15651 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
15652 %sum = extractvalue {i32, i1} %res, 0
15653 %obit = extractvalue {i32, i1} %res, 1
15654 br i1 %obit, label %overflow, label %normal
15656 '``llvm.umul.with.overflow.*``' Intrinsics
15657 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15662 This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow``
15663 on any integer bit width or vectors of integers.
15667 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
15668 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
15669 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
15670 declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
15675 The '``llvm.umul.with.overflow``' family of intrinsic functions perform
15676 a unsigned multiplication of the two arguments, and indicate whether an
15677 overflow occurred during the unsigned multiplication.
15682 The arguments (%a and %b) and the first element of the result structure
15683 may be of integer types of any bit width, but they must have the same
15684 bit width. The second element of the result structure must be of type
15685 ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
15691 The '``llvm.umul.with.overflow``' family of intrinsic functions perform
15692 an unsigned multiplication of the two arguments. They return a structure ---
15693 the first element of which is the multiplication, and the second
15694 element of which is a bit specifying if the unsigned multiplication
15695 resulted in an overflow.
15700 .. code-block:: llvm
15702 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
15703 %sum = extractvalue {i32, i1} %res, 0
15704 %obit = extractvalue {i32, i1} %res, 1
15705 br i1 %obit, label %overflow, label %normal
15707 Saturation Arithmetic Intrinsics
15708 ---------------------------------
15710 Saturation arithmetic is a version of arithmetic in which operations are
15711 limited to a fixed range between a minimum and maximum value. If the result of
15712 an operation is greater than the maximum value, the result is set (or
15713 "clamped") to this maximum. If it is below the minimum, it is clamped to this
15717 '``llvm.sadd.sat.*``' Intrinsics
15718 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15723 This is an overloaded intrinsic. You can use ``llvm.sadd.sat``
15724 on any integer bit width or vectors of integers.
15728 declare i16 @llvm.sadd.sat.i16(i16 %a, i16 %b)
15729 declare i32 @llvm.sadd.sat.i32(i32 %a, i32 %b)
15730 declare i64 @llvm.sadd.sat.i64(i64 %a, i64 %b)
15731 declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
15736 The '``llvm.sadd.sat``' family of intrinsic functions perform signed
15737 saturating addition on the 2 arguments.
15742 The arguments (%a and %b) and the result may be of integer types of any bit
15743 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
15744 values that will undergo signed addition.
15749 The maximum value this operation can clamp to is the largest signed value
15750 representable by the bit width of the arguments. The minimum value is the
15751 smallest signed value representable by this bit width.
15757 .. code-block:: llvm
15759 %res = call i4 @llvm.sadd.sat.i4(i4 1, i4 2) ; %res = 3
15760 %res = call i4 @llvm.sadd.sat.i4(i4 5, i4 6) ; %res = 7
15761 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 2) ; %res = -2
15762 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 -5) ; %res = -8
15765 '``llvm.uadd.sat.*``' Intrinsics
15766 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15771 This is an overloaded intrinsic. You can use ``llvm.uadd.sat``
15772 on any integer bit width or vectors of integers.
15776 declare i16 @llvm.uadd.sat.i16(i16 %a, i16 %b)
15777 declare i32 @llvm.uadd.sat.i32(i32 %a, i32 %b)
15778 declare i64 @llvm.uadd.sat.i64(i64 %a, i64 %b)
15779 declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
15784 The '``llvm.uadd.sat``' family of intrinsic functions perform unsigned
15785 saturating addition on the 2 arguments.
15790 The arguments (%a and %b) and the result may be of integer types of any bit
15791 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
15792 values that will undergo unsigned addition.
15797 The maximum value this operation can clamp to is the largest unsigned value
15798 representable by the bit width of the arguments. Because this is an unsigned
15799 operation, the result will never saturate towards zero.
15805 .. code-block:: llvm
15807 %res = call i4 @llvm.uadd.sat.i4(i4 1, i4 2) ; %res = 3
15808 %res = call i4 @llvm.uadd.sat.i4(i4 5, i4 6) ; %res = 11
15809 %res = call i4 @llvm.uadd.sat.i4(i4 8, i4 8) ; %res = 15
15812 '``llvm.ssub.sat.*``' Intrinsics
15813 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15818 This is an overloaded intrinsic. You can use ``llvm.ssub.sat``
15819 on any integer bit width or vectors of integers.
15823 declare i16 @llvm.ssub.sat.i16(i16 %a, i16 %b)
15824 declare i32 @llvm.ssub.sat.i32(i32 %a, i32 %b)
15825 declare i64 @llvm.ssub.sat.i64(i64 %a, i64 %b)
15826 declare <4 x i32> @llvm.ssub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
15831 The '``llvm.ssub.sat``' family of intrinsic functions perform signed
15832 saturating subtraction on the 2 arguments.
15837 The arguments (%a and %b) and the result may be of integer types of any bit
15838 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
15839 values that will undergo signed subtraction.
15844 The maximum value this operation can clamp to is the largest signed value
15845 representable by the bit width of the arguments. The minimum value is the
15846 smallest signed value representable by this bit width.
15852 .. code-block:: llvm
15854 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 1) ; %res = 1
15855 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 6) ; %res = -4
15856 %res = call i4 @llvm.ssub.sat.i4(i4 -4, i4 5) ; %res = -8
15857 %res = call i4 @llvm.ssub.sat.i4(i4 4, i4 -5) ; %res = 7
15860 '``llvm.usub.sat.*``' Intrinsics
15861 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15866 This is an overloaded intrinsic. You can use ``llvm.usub.sat``
15867 on any integer bit width or vectors of integers.
15871 declare i16 @llvm.usub.sat.i16(i16 %a, i16 %b)
15872 declare i32 @llvm.usub.sat.i32(i32 %a, i32 %b)
15873 declare i64 @llvm.usub.sat.i64(i64 %a, i64 %b)
15874 declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
15879 The '``llvm.usub.sat``' family of intrinsic functions perform unsigned
15880 saturating subtraction on the 2 arguments.
15885 The arguments (%a and %b) and the result may be of integer types of any bit
15886 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
15887 values that will undergo unsigned subtraction.
15892 The minimum value this operation can clamp to is 0, which is the smallest
15893 unsigned value representable by the bit width of the unsigned arguments.
15894 Because this is an unsigned operation, the result will never saturate towards
15895 the largest possible value representable by this bit width.
15901 .. code-block:: llvm
15903 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 1) ; %res = 1
15904 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 6) ; %res = 0
15907 '``llvm.sshl.sat.*``' Intrinsics
15908 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15913 This is an overloaded intrinsic. You can use ``llvm.sshl.sat``
15914 on integers or vectors of integers of any bit width.
15918 declare i16 @llvm.sshl.sat.i16(i16 %a, i16 %b)
15919 declare i32 @llvm.sshl.sat.i32(i32 %a, i32 %b)
15920 declare i64 @llvm.sshl.sat.i64(i64 %a, i64 %b)
15921 declare <4 x i32> @llvm.sshl.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
15926 The '``llvm.sshl.sat``' family of intrinsic functions perform signed
15927 saturating left shift on the first argument.
15932 The arguments (``%a`` and ``%b``) and the result may be of integer types of any
15933 bit width, but they must have the same bit width. ``%a`` is the value to be
15934 shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or
15935 dynamically) equal to or larger than the integer bit width of the arguments,
15936 the result is a :ref:`poison value <poisonvalues>`. If the arguments are
15937 vectors, each vector element of ``a`` is shifted by the corresponding shift
15944 The maximum value this operation can clamp to is the largest signed value
15945 representable by the bit width of the arguments. The minimum value is the
15946 smallest signed value representable by this bit width.
15952 .. code-block:: llvm
15954 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 1) ; %res = 4
15955 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 2) ; %res = 7
15956 %res = call i4 @llvm.sshl.sat.i4(i4 -5, i4 1) ; %res = -8
15957 %res = call i4 @llvm.sshl.sat.i4(i4 -1, i4 1) ; %res = -2
15960 '``llvm.ushl.sat.*``' Intrinsics
15961 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15966 This is an overloaded intrinsic. You can use ``llvm.ushl.sat``
15967 on integers or vectors of integers of any bit width.
15971 declare i16 @llvm.ushl.sat.i16(i16 %a, i16 %b)
15972 declare i32 @llvm.ushl.sat.i32(i32 %a, i32 %b)
15973 declare i64 @llvm.ushl.sat.i64(i64 %a, i64 %b)
15974 declare <4 x i32> @llvm.ushl.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
15979 The '``llvm.ushl.sat``' family of intrinsic functions perform unsigned
15980 saturating left shift on the first argument.
15985 The arguments (``%a`` and ``%b``) and the result may be of integer types of any
15986 bit width, but they must have the same bit width. ``%a`` is the value to be
15987 shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or
15988 dynamically) equal to or larger than the integer bit width of the arguments,
15989 the result is a :ref:`poison value <poisonvalues>`. If the arguments are
15990 vectors, each vector element of ``a`` is shifted by the corresponding shift
15996 The maximum value this operation can clamp to is the largest unsigned value
15997 representable by the bit width of the arguments.
16003 .. code-block:: llvm
16005 %res = call i4 @llvm.ushl.sat.i4(i4 2, i4 1) ; %res = 4
16006 %res = call i4 @llvm.ushl.sat.i4(i4 3, i4 3) ; %res = 15
16009 Fixed Point Arithmetic Intrinsics
16010 ---------------------------------
16012 A fixed point number represents a real data type for a number that has a fixed
16013 number of digits after a radix point (equivalent to the decimal point '.').
16014 The number of digits after the radix point is referred as the `scale`. These
16015 are useful for representing fractional values to a specific precision. The
16016 following intrinsics perform fixed point arithmetic operations on 2 operands
16017 of the same scale, specified as the third argument.
16019 The ``llvm.*mul.fix`` family of intrinsic functions represents a multiplication
16020 of fixed point numbers through scaled integers. Therefore, fixed point
16021 multiplication can be represented as
16023 .. code-block:: llvm
16025 %result = call i4 @llvm.smul.fix.i4(i4 %a, i4 %b, i32 %scale)
16028 %a2 = sext i4 %a to i8
16029 %b2 = sext i4 %b to i8
16030 %mul = mul nsw nuw i8 %a2, %b2
16031 %scale2 = trunc i32 %scale to i8
16032 %r = ashr i8 %mul, i8 %scale2 ; this is for a target rounding down towards negative infinity
16033 %result = trunc i8 %r to i4
16035 The ``llvm.*div.fix`` family of intrinsic functions represents a division of
16036 fixed point numbers through scaled integers. Fixed point division can be
16039 .. code-block:: llvm
16041 %result call i4 @llvm.sdiv.fix.i4(i4 %a, i4 %b, i32 %scale)
16044 %a2 = sext i4 %a to i8
16045 %b2 = sext i4 %b to i8
16046 %scale2 = trunc i32 %scale to i8
16047 %a3 = shl i8 %a2, %scale2
16048 %r = sdiv i8 %a3, %b2 ; this is for a target rounding towards zero
16049 %result = trunc i8 %r to i4
16051 For each of these functions, if the result cannot be represented exactly with
16052 the provided scale, the result is rounded. Rounding is unspecified since
16053 preferred rounding may vary for different targets. Rounding is specified
16054 through a target hook. Different pipelines should legalize or optimize this
16055 using the rounding specified by this hook if it is provided. Operations like
16056 constant folding, instruction combining, KnownBits, and ValueTracking should
16057 also use this hook, if provided, and not assume the direction of rounding. A
16058 rounded result must always be within one unit of precision from the true
16059 result. That is, the error between the returned result and the true result must
16060 be less than 1/2^(scale).
16063 '``llvm.smul.fix.*``' Intrinsics
16064 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16069 This is an overloaded intrinsic. You can use ``llvm.smul.fix``
16070 on any integer bit width or vectors of integers.
16074 declare i16 @llvm.smul.fix.i16(i16 %a, i16 %b, i32 %scale)
16075 declare i32 @llvm.smul.fix.i32(i32 %a, i32 %b, i32 %scale)
16076 declare i64 @llvm.smul.fix.i64(i64 %a, i64 %b, i32 %scale)
16077 declare <4 x i32> @llvm.smul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16082 The '``llvm.smul.fix``' family of intrinsic functions perform signed
16083 fixed point multiplication on 2 arguments of the same scale.
16088 The arguments (%a and %b) and the result may be of integer types of any bit
16089 width, but they must have the same bit width. The arguments may also work with
16090 int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16091 values that will undergo signed fixed point multiplication. The argument
16092 ``%scale`` represents the scale of both operands, and must be a constant
16098 This operation performs fixed point multiplication on the 2 arguments of a
16099 specified scale. The result will also be returned in the same scale specified
16100 in the third argument.
16102 If the result value cannot be precisely represented in the given scale, the
16103 value is rounded up or down to the closest representable value. The rounding
16104 direction is unspecified.
16106 It is undefined behavior if the result value does not fit within the range of
16107 the fixed point type.
16113 .. code-block:: llvm
16115 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
16116 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
16117 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5)
16119 ; The result in the following could be rounded up to -2 or down to -2.5
16120 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25)
16123 '``llvm.umul.fix.*``' Intrinsics
16124 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16129 This is an overloaded intrinsic. You can use ``llvm.umul.fix``
16130 on any integer bit width or vectors of integers.
16134 declare i16 @llvm.umul.fix.i16(i16 %a, i16 %b, i32 %scale)
16135 declare i32 @llvm.umul.fix.i32(i32 %a, i32 %b, i32 %scale)
16136 declare i64 @llvm.umul.fix.i64(i64 %a, i64 %b, i32 %scale)
16137 declare <4 x i32> @llvm.umul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16142 The '``llvm.umul.fix``' family of intrinsic functions perform unsigned
16143 fixed point multiplication on 2 arguments of the same scale.
16148 The arguments (%a and %b) and the result may be of integer types of any bit
16149 width, but they must have the same bit width. The arguments may also work with
16150 int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16151 values that will undergo unsigned fixed point multiplication. The argument
16152 ``%scale`` represents the scale of both operands, and must be a constant
16158 This operation performs unsigned fixed point multiplication on the 2 arguments of a
16159 specified scale. The result will also be returned in the same scale specified
16160 in the third argument.
16162 If the result value cannot be precisely represented in the given scale, the
16163 value is rounded up or down to the closest representable value. The rounding
16164 direction is unspecified.
16166 It is undefined behavior if the result value does not fit within the range of
16167 the fixed point type.
16173 .. code-block:: llvm
16175 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
16176 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
16178 ; The result in the following could be rounded down to 3.5 or up to 4
16179 %res = call i4 @llvm.umul.fix.i4(i4 15, i4 1, i32 1) ; %res = 7 (or 8) (7.5 x 0.5 = 3.75)
16182 '``llvm.smul.fix.sat.*``' Intrinsics
16183 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16188 This is an overloaded intrinsic. You can use ``llvm.smul.fix.sat``
16189 on any integer bit width or vectors of integers.
16193 declare i16 @llvm.smul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16194 declare i32 @llvm.smul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16195 declare i64 @llvm.smul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16196 declare <4 x i32> @llvm.smul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16201 The '``llvm.smul.fix.sat``' family of intrinsic functions perform signed
16202 fixed point saturating multiplication on 2 arguments of the same scale.
16207 The arguments (%a and %b) and the result may be of integer types of any bit
16208 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16209 values that will undergo signed fixed point multiplication. The argument
16210 ``%scale`` represents the scale of both operands, and must be a constant
16216 This operation performs fixed point multiplication on the 2 arguments of a
16217 specified scale. The result will also be returned in the same scale specified
16218 in the third argument.
16220 If the result value cannot be precisely represented in the given scale, the
16221 value is rounded up or down to the closest representable value. The rounding
16222 direction is unspecified.
16224 The maximum value this operation can clamp to is the largest signed value
16225 representable by the bit width of the first 2 arguments. The minimum value is the
16226 smallest signed value representable by this bit width.
16232 .. code-block:: llvm
16234 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
16235 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
16236 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5)
16238 ; The result in the following could be rounded up to -2 or down to -2.5
16239 %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)
16242 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 0) ; %res = 7
16243 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 4, i32 2) ; %res = 7
16244 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 5, i32 2) ; %res = -8
16245 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 -2, i32 1) ; %res = 7
16247 ; Scale can affect the saturation result
16248 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7)
16249 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2)
16252 '``llvm.umul.fix.sat.*``' Intrinsics
16253 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16258 This is an overloaded intrinsic. You can use ``llvm.umul.fix.sat``
16259 on any integer bit width or vectors of integers.
16263 declare i16 @llvm.umul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16264 declare i32 @llvm.umul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16265 declare i64 @llvm.umul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16266 declare <4 x i32> @llvm.umul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16271 The '``llvm.umul.fix.sat``' family of intrinsic functions perform unsigned
16272 fixed point saturating multiplication on 2 arguments of the same scale.
16277 The arguments (%a and %b) and the result may be of integer types of any bit
16278 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16279 values that will undergo unsigned fixed point multiplication. The argument
16280 ``%scale`` represents the scale of both operands, and must be a constant
16286 This operation performs fixed point multiplication on the 2 arguments of a
16287 specified scale. The result will also be returned in the same scale specified
16288 in the third argument.
16290 If the result value cannot be precisely represented in the given scale, the
16291 value is rounded up or down to the closest representable value. The rounding
16292 direction is unspecified.
16294 The maximum value this operation can clamp to is the largest unsigned value
16295 representable by the bit width of the first 2 arguments. The minimum value is the
16296 smallest unsigned value representable by this bit width (zero).
16302 .. code-block:: llvm
16304 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
16305 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
16307 ; The result in the following could be rounded down to 2 or up to 2.5
16308 %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)
16311 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 2, i32 0) ; %res = 15 (8 x 2 -> clamped to 15)
16312 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 8, i32 2) ; %res = 15 (2 x 2 -> clamped to 3.75)
16314 ; Scale can affect the saturation result
16315 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7)
16316 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2)
16319 '``llvm.sdiv.fix.*``' Intrinsics
16320 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16325 This is an overloaded intrinsic. You can use ``llvm.sdiv.fix``
16326 on any integer bit width or vectors of integers.
16330 declare i16 @llvm.sdiv.fix.i16(i16 %a, i16 %b, i32 %scale)
16331 declare i32 @llvm.sdiv.fix.i32(i32 %a, i32 %b, i32 %scale)
16332 declare i64 @llvm.sdiv.fix.i64(i64 %a, i64 %b, i32 %scale)
16333 declare <4 x i32> @llvm.sdiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16338 The '``llvm.sdiv.fix``' family of intrinsic functions perform signed
16339 fixed point division on 2 arguments of the same scale.
16344 The arguments (%a and %b) and the result may be of integer types of any bit
16345 width, but they must have the same bit width. The arguments may also work with
16346 int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16347 values that will undergo signed fixed point division. The argument
16348 ``%scale`` represents the scale of both operands, and must be a constant
16354 This operation performs fixed point division on the 2 arguments of a
16355 specified scale. The result will also be returned in the same scale specified
16356 in the third argument.
16358 If the result value cannot be precisely represented in the given scale, the
16359 value is rounded up or down to the closest representable value. The rounding
16360 direction is unspecified.
16362 It is undefined behavior if the result value does not fit within the range of
16363 the fixed point type, or if the second argument is zero.
16369 .. code-block:: llvm
16371 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3)
16372 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5)
16373 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5)
16375 ; The result in the following could be rounded up to 1 or down to 0.5
16376 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75)
16379 '``llvm.udiv.fix.*``' Intrinsics
16380 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16385 This is an overloaded intrinsic. You can use ``llvm.udiv.fix``
16386 on any integer bit width or vectors of integers.
16390 declare i16 @llvm.udiv.fix.i16(i16 %a, i16 %b, i32 %scale)
16391 declare i32 @llvm.udiv.fix.i32(i32 %a, i32 %b, i32 %scale)
16392 declare i64 @llvm.udiv.fix.i64(i64 %a, i64 %b, i32 %scale)
16393 declare <4 x i32> @llvm.udiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16398 The '``llvm.udiv.fix``' family of intrinsic functions perform unsigned
16399 fixed point division on 2 arguments of the same scale.
16404 The arguments (%a and %b) and the result may be of integer types of any bit
16405 width, but they must have the same bit width. The arguments may also work with
16406 int vectors of the same length and int size. ``%a`` and ``%b`` are the two
16407 values that will undergo unsigned fixed point division. The argument
16408 ``%scale`` represents the scale of both operands, and must be a constant
16414 This operation performs fixed point division on the 2 arguments of a
16415 specified scale. The result will also be returned in the same scale specified
16416 in the third argument.
16418 If the result value cannot be precisely represented in the given scale, the
16419 value is rounded up or down to the closest representable value. The rounding
16420 direction is unspecified.
16422 It is undefined behavior if the result value does not fit within the range of
16423 the fixed point type, or if the second argument is zero.
16429 .. code-block:: llvm
16431 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3)
16432 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5)
16433 %res = call i4 @llvm.udiv.fix.i4(i4 1, i4 -8, i32 4) ; %res = 2 (0.0625 / 0.5 = 0.125)
16435 ; The result in the following could be rounded up to 1 or down to 0.5
16436 %res = call i4 @llvm.udiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75)
16439 '``llvm.sdiv.fix.sat.*``' Intrinsics
16440 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16445 This is an overloaded intrinsic. You can use ``llvm.sdiv.fix.sat``
16446 on any integer bit width or vectors of integers.
16450 declare i16 @llvm.sdiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16451 declare i32 @llvm.sdiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16452 declare i64 @llvm.sdiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16453 declare <4 x i32> @llvm.sdiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16458 The '``llvm.sdiv.fix.sat``' family of intrinsic functions perform signed
16459 fixed point saturating division on 2 arguments of the same scale.
16464 The arguments (%a and %b) and the result may be of integer types of any bit
16465 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16466 values that will undergo signed fixed point division. The argument
16467 ``%scale`` represents the scale of both operands, and must be a constant
16473 This operation performs fixed point division on the 2 arguments of a
16474 specified scale. The result will also be returned in the same scale specified
16475 in the third argument.
16477 If the result value cannot be precisely represented in the given scale, the
16478 value is rounded up or down to the closest representable value. The rounding
16479 direction is unspecified.
16481 The maximum value this operation can clamp to is the largest signed value
16482 representable by the bit width of the first 2 arguments. The minimum value is the
16483 smallest signed value representable by this bit width.
16485 It is undefined behavior if the second argument is zero.
16491 .. code-block:: llvm
16493 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3)
16494 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5)
16495 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5)
16497 ; The result in the following could be rounded up to 1 or down to 0.5
16498 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75)
16501 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -8, i4 -1, i32 0) ; %res = 7 (-8 / -1 = 8 => 7)
16502 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 4, i4 2, i32 2) ; %res = 7 (1 / 0.5 = 2 => 1.75)
16503 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -4, i4 1, i32 2) ; %res = -8 (-1 / 0.25 = -4 => -2)
16506 '``llvm.udiv.fix.sat.*``' Intrinsics
16507 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16512 This is an overloaded intrinsic. You can use ``llvm.udiv.fix.sat``
16513 on any integer bit width or vectors of integers.
16517 declare i16 @llvm.udiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
16518 declare i32 @llvm.udiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
16519 declare i64 @llvm.udiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
16520 declare <4 x i32> @llvm.udiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
16525 The '``llvm.udiv.fix.sat``' family of intrinsic functions perform unsigned
16526 fixed point saturating division on 2 arguments of the same scale.
16531 The arguments (%a and %b) and the result may be of integer types of any bit
16532 width, but they must have the same bit width. ``%a`` and ``%b`` are the two
16533 values that will undergo unsigned fixed point division. The argument
16534 ``%scale`` represents the scale of both operands, and must be a constant
16540 This operation performs fixed point division on the 2 arguments of a
16541 specified scale. The result will also be returned in the same scale specified
16542 in the third argument.
16544 If the result value cannot be precisely represented in the given scale, the
16545 value is rounded up or down to the closest representable value. The rounding
16546 direction is unspecified.
16548 The maximum value this operation can clamp to is the largest unsigned value
16549 representable by the bit width of the first 2 arguments. The minimum value is the
16550 smallest unsigned value representable by this bit width (zero).
16552 It is undefined behavior if the second argument is zero.
16557 .. code-block:: llvm
16559 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3)
16560 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5)
16562 ; The result in the following could be rounded down to 0.5 or up to 1
16563 %res = call i4 @llvm.udiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 1 (or 2) (1.5 / 2 = 0.75)
16566 %res = call i4 @llvm.udiv.fix.sat.i4(i4 8, i4 2, i32 2) ; %res = 15 (2 / 0.5 = 4 => 3.75)
16569 Specialised Arithmetic Intrinsics
16570 ---------------------------------
16572 .. _i_intr_llvm_canonicalize:
16574 '``llvm.canonicalize.*``' Intrinsic
16575 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16582 declare float @llvm.canonicalize.f32(float %a)
16583 declare double @llvm.canonicalize.f64(double %b)
16588 The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical
16589 encoding of a floating-point number. This canonicalization is useful for
16590 implementing certain numeric primitives such as frexp. The canonical encoding is
16591 defined by IEEE-754-2008 to be:
16595 2.1.8 canonical encoding: The preferred encoding of a floating-point
16596 representation in a format. Applied to declets, significands of finite
16597 numbers, infinities, and NaNs, especially in decimal formats.
16599 This operation can also be considered equivalent to the IEEE-754-2008
16600 conversion of a floating-point value to the same format. NaNs are handled
16601 according to section 6.2.
16603 Examples of non-canonical encodings:
16605 - x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are
16606 converted to a canonical representation per hardware-specific protocol.
16607 - Many normal decimal floating-point numbers have non-canonical alternative
16609 - Some machines, like GPUs or ARMv7 NEON, do not support subnormal values.
16610 These are treated as non-canonical encodings of zero and will be flushed to
16611 a zero of the same sign by this operation.
16613 Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with
16614 default exception handling must signal an invalid exception, and produce a
16617 This function should always be implementable as multiplication by 1.0, provided
16618 that the compiler does not constant fold the operation. Likewise, division by
16619 1.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with
16620 -0.0 is also sufficient provided that the rounding mode is not -Infinity.
16622 ``@llvm.canonicalize`` must preserve the equality relation. That is:
16624 - ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)``
16625 - ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to
16628 Additionally, the sign of zero must be conserved:
16629 ``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0``
16631 The payload bits of a NaN must be conserved, with two exceptions.
16632 First, environments which use only a single canonical representation of NaN
16633 must perform said canonicalization. Second, SNaNs must be quieted per the
16636 The canonicalization operation may be optimized away if:
16638 - The input is known to be canonical. For example, it was produced by a
16639 floating-point operation that is required by the standard to be canonical.
16640 - The result is consumed only by (or fused with) other floating-point
16641 operations. That is, the bits of the floating-point value are not examined.
16643 '``llvm.fmuladd.*``' Intrinsic
16644 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16651 declare float @llvm.fmuladd.f32(float %a, float %b, float %c)
16652 declare double @llvm.fmuladd.f64(double %a, double %b, double %c)
16657 The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add
16658 expressions that can be fused if the code generator determines that (a) the
16659 target instruction set has support for a fused operation, and (b) that the
16660 fused operation is more efficient than the equivalent, separate pair of mul
16661 and add instructions.
16666 The '``llvm.fmuladd.*``' intrinsics each take three arguments: two
16667 multiplicands, a and b, and an addend c.
16676 %0 = call float @llvm.fmuladd.f32(%a, %b, %c)
16678 is equivalent to the expression a \* b + c, except that it is unspecified
16679 whether rounding will be performed between the multiplication and addition
16680 steps. Fusion is not guaranteed, even if the target platform supports it.
16681 If a fused multiply-add is required, the corresponding
16682 :ref:`llvm.fma <int_fma>` intrinsic function should be used instead.
16683 This never sets errno, just as '``llvm.fma.*``'.
16688 .. code-block:: llvm
16690 %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c
16693 Hardware-Loop Intrinsics
16694 ------------------------
16696 LLVM support several intrinsics to mark a loop as a hardware-loop. They are
16697 hints to the backend which are required to lower these intrinsics further to target
16698 specific instructions, or revert the hardware-loop to a normal loop if target
16699 specific restriction are not met and a hardware-loop can't be generated.
16701 These intrinsics may be modified in the future and are not intended to be used
16702 outside the backend. Thus, front-end and mid-level optimizations should not be
16703 generating these intrinsics.
16706 '``llvm.set.loop.iterations.*``' Intrinsic
16707 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16712 This is an overloaded intrinsic.
16716 declare void @llvm.set.loop.iterations.i32(i32)
16717 declare void @llvm.set.loop.iterations.i64(i64)
16722 The '``llvm.set.loop.iterations.*``' intrinsics are used to specify the
16723 hardware-loop trip count. They are placed in the loop preheader basic block and
16724 are marked as ``IntrNoDuplicate`` to avoid optimizers duplicating these
16730 The integer operand is the loop trip count of the hardware-loop, and thus
16731 not e.g. the loop back-edge taken count.
16736 The '``llvm.set.loop.iterations.*``' intrinsics do not perform any arithmetic
16737 on their operand. It's a hint to the backend that can use this to set up the
16738 hardware-loop count with a target specific instruction, usually a move of this
16739 value to a special register or a hardware-loop instruction.
16742 '``llvm.start.loop.iterations.*``' Intrinsic
16743 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16748 This is an overloaded intrinsic.
16752 declare i32 @llvm.start.loop.iterations.i32(i32)
16753 declare i64 @llvm.start.loop.iterations.i64(i64)
16758 The '``llvm.start.loop.iterations.*``' intrinsics are similar to the
16759 '``llvm.set.loop.iterations.*``' intrinsics, used to specify the
16760 hardware-loop trip count but also produce a value identical to the input
16761 that can be used as the input to the loop. They are placed in the loop
16762 preheader basic block and the output is expected to be the input to the
16763 phi for the induction variable of the loop, decremented by the
16764 '``llvm.loop.decrement.reg.*``'.
16769 The integer operand is the loop trip count of the hardware-loop, and thus
16770 not e.g. the loop back-edge taken count.
16775 The '``llvm.start.loop.iterations.*``' intrinsics do not perform any arithmetic
16776 on their operand. It's a hint to the backend that can use this to set up the
16777 hardware-loop count with a target specific instruction, usually a move of this
16778 value to a special register or a hardware-loop instruction.
16780 '``llvm.test.set.loop.iterations.*``' Intrinsic
16781 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16786 This is an overloaded intrinsic.
16790 declare i1 @llvm.test.set.loop.iterations.i32(i32)
16791 declare i1 @llvm.test.set.loop.iterations.i64(i64)
16796 The '``llvm.test.set.loop.iterations.*``' intrinsics are used to specify the
16797 the loop trip count, and also test that the given count is not zero, allowing
16798 it to control entry to a while-loop. They are placed in the loop preheader's
16799 predecessor basic block, and are marked as ``IntrNoDuplicate`` to avoid
16800 optimizers duplicating these instructions.
16805 The integer operand is the loop trip count of the hardware-loop, and thus
16806 not e.g. the loop back-edge taken count.
16811 The '``llvm.test.set.loop.iterations.*``' intrinsics do not perform any
16812 arithmetic on their operand. It's a hint to the backend that can use this to
16813 set up the hardware-loop count with a target specific instruction, usually a
16814 move of this value to a special register or a hardware-loop instruction.
16815 The result is the conditional value of whether the given count is not zero.
16818 '``llvm.test.start.loop.iterations.*``' Intrinsic
16819 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16824 This is an overloaded intrinsic.
16828 declare {i32, i1} @llvm.test.start.loop.iterations.i32(i32)
16829 declare {i64, i1} @llvm.test.start.loop.iterations.i64(i64)
16834 The '``llvm.test.start.loop.iterations.*``' intrinsics are similar to the
16835 '``llvm.test.set.loop.iterations.*``' and '``llvm.start.loop.iterations.*``'
16836 intrinsics, used to specify the hardware-loop trip count, but also produce a
16837 value identical to the input that can be used as the input to the loop. The
16838 second i1 output controls entry to a while-loop.
16843 The integer operand is the loop trip count of the hardware-loop, and thus
16844 not e.g. the loop back-edge taken count.
16849 The '``llvm.test.start.loop.iterations.*``' intrinsics do not perform any
16850 arithmetic on their operand. It's a hint to the backend that can use this to
16851 set up the hardware-loop count with a target specific instruction, usually a
16852 move of this value to a special register or a hardware-loop instruction.
16853 The result is a pair of the input and a conditional value of whether the
16854 given count is not zero.
16857 '``llvm.loop.decrement.reg.*``' Intrinsic
16858 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16863 This is an overloaded intrinsic.
16867 declare i32 @llvm.loop.decrement.reg.i32(i32, i32)
16868 declare i64 @llvm.loop.decrement.reg.i64(i64, i64)
16873 The '``llvm.loop.decrement.reg.*``' intrinsics are used to lower the loop
16874 iteration counter and return an updated value that will be used in the next
16880 Both arguments must have identical integer types. The first operand is the
16881 loop iteration counter. The second operand is the maximum number of elements
16882 processed in an iteration.
16887 The '``llvm.loop.decrement.reg.*``' intrinsics do an integer ``SUB`` of its
16888 two operands, which is not allowed to wrap. They return the remaining number of
16889 iterations still to be executed, and can be used together with a ``PHI``,
16890 ``ICMP`` and ``BR`` to control the number of loop iterations executed. Any
16891 optimisations are allowed to treat it is a ``SUB``, and it is supported by
16892 SCEV, so it's the backends responsibility to handle cases where it may be
16893 optimised. These intrinsics are marked as ``IntrNoDuplicate`` to avoid
16894 optimizers duplicating these instructions.
16897 '``llvm.loop.decrement.*``' Intrinsic
16898 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16903 This is an overloaded intrinsic.
16907 declare i1 @llvm.loop.decrement.i32(i32)
16908 declare i1 @llvm.loop.decrement.i64(i64)
16913 The HardwareLoops pass allows the loop decrement value to be specified with an
16914 option. It defaults to a loop decrement value of 1, but it can be an unsigned
16915 integer value provided by this option. The '``llvm.loop.decrement.*``'
16916 intrinsics decrement the loop iteration counter with this value, and return a
16917 false predicate if the loop should exit, and true otherwise.
16918 This is emitted if the loop counter is not updated via a ``PHI`` node, which
16919 can also be controlled with an option.
16924 The integer argument is the loop decrement value used to decrement the loop
16930 The '``llvm.loop.decrement.*``' intrinsics do a ``SUB`` of the loop iteration
16931 counter with the given loop decrement value, and return false if the loop
16932 should exit, this ``SUB`` is not allowed to wrap. The result is a condition
16933 that is used by the conditional branch controlling the loop.
16936 Vector Reduction Intrinsics
16937 ---------------------------
16939 Horizontal reductions of vectors can be expressed using the following
16940 intrinsics. Each one takes a vector operand as an input and applies its
16941 respective operation across all elements of the vector, returning a single
16942 scalar result of the same element type.
16944 .. _int_vector_reduce_add:
16946 '``llvm.vector.reduce.add.*``' Intrinsic
16947 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16954 declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a)
16955 declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a)
16960 The '``llvm.vector.reduce.add.*``' intrinsics do an integer ``ADD``
16961 reduction of a vector, returning the result as a scalar. The return type matches
16962 the element-type of the vector input.
16966 The argument to this intrinsic must be a vector of integer values.
16968 .. _int_vector_reduce_fadd:
16970 '``llvm.vector.reduce.fadd.*``' Intrinsic
16971 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16978 declare float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %a)
16979 declare double @llvm.vector.reduce.fadd.v2f64(double %start_value, <2 x double> %a)
16984 The '``llvm.vector.reduce.fadd.*``' intrinsics do a floating-point
16985 ``ADD`` reduction of a vector, returning the result as a scalar. The return type
16986 matches the element-type of the vector input.
16988 If the intrinsic call has the 'reassoc' flag set, then the reduction will not
16989 preserve the associativity of an equivalent scalarized counterpart. Otherwise
16990 the reduction will be *sequential*, thus implying that the operation respects
16991 the associativity of a scalarized reduction. That is, the reduction begins with
16992 the start value and performs an fadd operation with consecutively increasing
16993 vector element indices. See the following pseudocode:
16997 float sequential_fadd(start_value, input_vector)
16998 result = start_value
16999 for i = 0 to length(input_vector)
17000 result = result + input_vector[i]
17006 The first argument to this intrinsic is a scalar start value for the reduction.
17007 The type of the start value matches the element-type of the vector input.
17008 The second argument must be a vector of floating-point values.
17010 To ignore the start value, negative zero (``-0.0``) can be used, as it is
17011 the neutral value of floating point addition.
17018 %unord = call reassoc float @llvm.vector.reduce.fadd.v4f32(float -0.0, <4 x float> %input) ; relaxed reduction
17019 %ord = call float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %input) ; sequential reduction
17022 .. _int_vector_reduce_mul:
17024 '``llvm.vector.reduce.mul.*``' Intrinsic
17025 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17032 declare i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %a)
17033 declare i64 @llvm.vector.reduce.mul.v2i64(<2 x i64> %a)
17038 The '``llvm.vector.reduce.mul.*``' intrinsics do an integer ``MUL``
17039 reduction of a vector, returning the result as a scalar. The return type matches
17040 the element-type of the vector input.
17044 The argument to this intrinsic must be a vector of integer values.
17046 .. _int_vector_reduce_fmul:
17048 '``llvm.vector.reduce.fmul.*``' Intrinsic
17049 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17056 declare float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %a)
17057 declare double @llvm.vector.reduce.fmul.v2f64(double %start_value, <2 x double> %a)
17062 The '``llvm.vector.reduce.fmul.*``' intrinsics do a floating-point
17063 ``MUL`` reduction of a vector, returning the result as a scalar. The return type
17064 matches the element-type of the vector input.
17066 If the intrinsic call has the 'reassoc' flag set, then the reduction will not
17067 preserve the associativity of an equivalent scalarized counterpart. Otherwise
17068 the reduction will be *sequential*, thus implying that the operation respects
17069 the associativity of a scalarized reduction. That is, the reduction begins with
17070 the start value and performs an fmul operation with consecutively increasing
17071 vector element indices. See the following pseudocode:
17075 float sequential_fmul(start_value, input_vector)
17076 result = start_value
17077 for i = 0 to length(input_vector)
17078 result = result * input_vector[i]
17084 The first argument to this intrinsic is a scalar start value for the reduction.
17085 The type of the start value matches the element-type of the vector input.
17086 The second argument must be a vector of floating-point values.
17088 To ignore the start value, one (``1.0``) can be used, as it is the neutral
17089 value of floating point multiplication.
17096 %unord = call reassoc float @llvm.vector.reduce.fmul.v4f32(float 1.0, <4 x float> %input) ; relaxed reduction
17097 %ord = call float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %input) ; sequential reduction
17099 .. _int_vector_reduce_and:
17101 '``llvm.vector.reduce.and.*``' Intrinsic
17102 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17109 declare i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %a)
17114 The '``llvm.vector.reduce.and.*``' intrinsics do a bitwise ``AND``
17115 reduction of a vector, returning the result as a scalar. The return type matches
17116 the element-type of the vector input.
17120 The argument to this intrinsic must be a vector of integer values.
17122 .. _int_vector_reduce_or:
17124 '``llvm.vector.reduce.or.*``' Intrinsic
17125 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17132 declare i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %a)
17137 The '``llvm.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction
17138 of a vector, returning the result as a scalar. The return type matches the
17139 element-type of the vector input.
17143 The argument to this intrinsic must be a vector of integer values.
17145 .. _int_vector_reduce_xor:
17147 '``llvm.vector.reduce.xor.*``' Intrinsic
17148 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17155 declare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %a)
17160 The '``llvm.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR``
17161 reduction of a vector, returning the result as a scalar. The return type matches
17162 the element-type of the vector input.
17166 The argument to this intrinsic must be a vector of integer values.
17168 .. _int_vector_reduce_smax:
17170 '``llvm.vector.reduce.smax.*``' Intrinsic
17171 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17178 declare i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %a)
17183 The '``llvm.vector.reduce.smax.*``' intrinsics do a signed integer
17184 ``MAX`` reduction of a vector, returning the result as a scalar. The return type
17185 matches the element-type of the vector input.
17189 The argument to this intrinsic must be a vector of integer values.
17191 .. _int_vector_reduce_smin:
17193 '``llvm.vector.reduce.smin.*``' Intrinsic
17194 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17201 declare i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %a)
17206 The '``llvm.vector.reduce.smin.*``' intrinsics do a signed integer
17207 ``MIN`` reduction of a vector, returning the result as a scalar. The return type
17208 matches the element-type of the vector input.
17212 The argument to this intrinsic must be a vector of integer values.
17214 .. _int_vector_reduce_umax:
17216 '``llvm.vector.reduce.umax.*``' Intrinsic
17217 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17224 declare i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %a)
17229 The '``llvm.vector.reduce.umax.*``' intrinsics do an unsigned
17230 integer ``MAX`` reduction of a vector, returning the result as a scalar. The
17231 return type matches the element-type of the vector input.
17235 The argument to this intrinsic must be a vector of integer values.
17237 .. _int_vector_reduce_umin:
17239 '``llvm.vector.reduce.umin.*``' Intrinsic
17240 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17247 declare i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %a)
17252 The '``llvm.vector.reduce.umin.*``' intrinsics do an unsigned
17253 integer ``MIN`` reduction of a vector, returning the result as a scalar. The
17254 return type matches the element-type of the vector input.
17258 The argument to this intrinsic must be a vector of integer values.
17260 .. _int_vector_reduce_fmax:
17262 '``llvm.vector.reduce.fmax.*``' Intrinsic
17263 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17270 declare float @llvm.vector.reduce.fmax.v4f32(<4 x float> %a)
17271 declare double @llvm.vector.reduce.fmax.v2f64(<2 x double> %a)
17276 The '``llvm.vector.reduce.fmax.*``' intrinsics do a floating-point
17277 ``MAX`` reduction of a vector, returning the result as a scalar. The return type
17278 matches the element-type of the vector input.
17280 This instruction has the same comparison semantics as the '``llvm.maxnum.*``'
17281 intrinsic. That is, the result will always be a number unless all elements of
17282 the vector are NaN. For a vector with maximum element magnitude 0.0 and
17283 containing both +0.0 and -0.0 elements, the sign of the result is unspecified.
17285 If the intrinsic call has the ``nnan`` fast-math flag, then the operation can
17286 assume that NaNs are not present in the input vector.
17290 The argument to this intrinsic must be a vector of floating-point values.
17292 .. _int_vector_reduce_fmin:
17294 '``llvm.vector.reduce.fmin.*``' Intrinsic
17295 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17299 This is an overloaded intrinsic.
17303 declare float @llvm.vector.reduce.fmin.v4f32(<4 x float> %a)
17304 declare double @llvm.vector.reduce.fmin.v2f64(<2 x double> %a)
17309 The '``llvm.vector.reduce.fmin.*``' intrinsics do a floating-point
17310 ``MIN`` reduction of a vector, returning the result as a scalar. The return type
17311 matches the element-type of the vector input.
17313 This instruction has the same comparison semantics as the '``llvm.minnum.*``'
17314 intrinsic. That is, the result will always be a number unless all elements of
17315 the vector are NaN. For a vector with minimum element magnitude 0.0 and
17316 containing both +0.0 and -0.0 elements, the sign of the result is unspecified.
17318 If the intrinsic call has the ``nnan`` fast-math flag, then the operation can
17319 assume that NaNs are not present in the input vector.
17323 The argument to this intrinsic must be a vector of floating-point values.
17325 '``llvm.vector.insert``' Intrinsic
17326 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17330 This is an overloaded intrinsic.
17334 ; Insert fixed type into scalable type
17335 declare <vscale x 4 x float> @llvm.vector.insert.nxv4f32.v4f32(<vscale x 4 x float> %vec, <4 x float> %subvec, i64 <idx>)
17336 declare <vscale x 2 x double> @llvm.vector.insert.nxv2f64.v2f64(<vscale x 2 x double> %vec, <2 x double> %subvec, i64 <idx>)
17338 ; Insert scalable type into scalable type
17339 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>)
17341 ; Insert fixed type into fixed type
17342 declare <4 x double> @llvm.vector.insert.v4f64.v2f64(<4 x double> %vec, <2 x double> %subvec, i64 <idx>)
17347 The '``llvm.vector.insert.*``' intrinsics insert a vector into another vector
17348 starting from a given index. The return type matches the type of the vector we
17349 insert into. Conceptually, this can be used to build a scalable vector out of
17350 non-scalable vectors, however this intrinsic can also be used on purely fixed
17353 Scalable vectors can only be inserted into other scalable vectors.
17358 The ``vec`` is the vector which ``subvec`` will be inserted into.
17359 The ``subvec`` is the vector that will be inserted.
17361 ``idx`` represents the starting element number at which ``subvec`` will be
17362 inserted. ``idx`` must be a constant multiple of ``subvec``'s known minimum
17363 vector length. If ``subvec`` is a scalable vector, ``idx`` is first scaled by
17364 the runtime scaling factor of ``subvec``. The elements of ``vec`` starting at
17365 ``idx`` are overwritten with ``subvec``. Elements ``idx`` through (``idx`` +
17366 num_elements(``subvec``) - 1) must be valid ``vec`` indices. If this condition
17367 cannot be determined statically but is false at runtime, then the result vector
17368 is a :ref:`poison value <poisonvalues>`.
17371 '``llvm.vector.extract``' Intrinsic
17372 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17376 This is an overloaded intrinsic.
17380 ; Extract fixed type from scalable type
17381 declare <4 x float> @llvm.vector.extract.v4f32.nxv4f32(<vscale x 4 x float> %vec, i64 <idx>)
17382 declare <2 x double> @llvm.vector.extract.v2f64.nxv2f64(<vscale x 2 x double> %vec, i64 <idx>)
17384 ; Extract scalable type from scalable type
17385 declare <vscale x 2 x float> @llvm.vector.extract.nxv2f32.nxv4f32(<vscale x 4 x float> %vec, i64 <idx>)
17387 ; Extract fixed type from fixed type
17388 declare <2 x double> @llvm.vector.extract.v2f64.v4f64(<4 x double> %vec, i64 <idx>)
17393 The '``llvm.vector.extract.*``' intrinsics extract a vector from within another
17394 vector starting from a given index. The return type must be explicitly
17395 specified. Conceptually, this can be used to decompose a scalable vector into
17396 non-scalable parts, however this intrinsic can also be used on purely fixed
17399 Scalable vectors can only be extracted from other scalable vectors.
17404 The ``vec`` is the vector from which we will extract a subvector.
17406 The ``idx`` specifies the starting element number within ``vec`` from which a
17407 subvector is extracted. ``idx`` must be a constant multiple of the known-minimum
17408 vector length of the result type. If the result type is a scalable vector,
17409 ``idx`` is first scaled by the result type's runtime scaling factor. Elements
17410 ``idx`` through (``idx`` + num_elements(result_type) - 1) must be valid vector
17411 indices. If this condition cannot be determined statically but is false at
17412 runtime, then the result vector is a :ref:`poison value <poisonvalues>`. The
17413 ``idx`` parameter must be a vector index constant type (for most targets this
17414 will be an integer pointer type).
17416 '``llvm.experimental.vector.reverse``' Intrinsic
17417 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17421 This is an overloaded intrinsic.
17425 declare <2 x i8> @llvm.experimental.vector.reverse.v2i8(<2 x i8> %a)
17426 declare <vscale x 4 x i32> @llvm.experimental.vector.reverse.nxv4i32(<vscale x 4 x i32> %a)
17431 The '``llvm.experimental.vector.reverse.*``' intrinsics reverse a vector.
17432 The intrinsic takes a single vector and returns a vector of matching type but
17433 with the original lane order reversed. These intrinsics work for both fixed
17434 and scalable vectors. While this intrinsic is marked as experimental the
17435 recommended way to express reverse operations for fixed-width vectors is still
17436 to use a shufflevector, as that may allow for more optimization opportunities.
17441 The argument to this intrinsic must be a vector.
17443 '``llvm.experimental.vector.splice``' Intrinsic
17444 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17448 This is an overloaded intrinsic.
17452 declare <2 x double> @llvm.experimental.vector.splice.v2f64(<2 x double> %vec1, <2 x double> %vec2, i32 %imm)
17453 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)
17458 The '``llvm.experimental.vector.splice.*``' intrinsics construct a vector by
17459 concatenating elements from the first input vector with elements of the second
17460 input vector, returning a vector of the same type as the input vectors. The
17461 signed immediate, modulo the number of elements in the vector, is the index
17462 into the first vector from which to extract the result value. This means
17463 conceptually that for a positive immediate, a vector is extracted from
17464 ``concat(%vec1, %vec2)`` starting at index ``imm``, whereas for a negative
17465 immediate, it extracts ``-imm`` trailing elements from the first vector, and
17466 the remaining elements from ``%vec2``.
17468 These intrinsics work for both fixed and scalable vectors. While this intrinsic
17469 is marked as experimental, the recommended way to express this operation for
17470 fixed-width vectors is still to use a shufflevector, as that may allow for more
17471 optimization opportunities.
17475 .. code-block:: text
17477 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, 1) ==> <B, C, D, E> ; index
17478 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, -3) ==> <B, C, D, E> ; trailing elements
17484 The first two operands are vectors with the same type. The start index is imm
17485 modulo the runtime number of elements in the source vector. For a fixed-width
17486 vector <N x eltty>, imm is a signed integer constant in the range
17487 -N <= imm < N. For a scalable vector <vscale x N x eltty>, imm is a signed
17488 integer constant in the range -X <= imm < X where X=vscale_range_min * N.
17490 '``llvm.experimental.stepvector``' Intrinsic
17491 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17493 This is an overloaded intrinsic. You can use ``llvm.experimental.stepvector``
17494 to generate a vector whose lane values comprise the linear sequence
17495 <0, 1, 2, ...>. It is primarily intended for scalable vectors.
17499 declare <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
17500 declare <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16()
17502 The '``llvm.experimental.stepvector``' intrinsics are used to create vectors
17503 of integers whose elements contain a linear sequence of values starting from 0
17504 with a step of 1. This experimental intrinsic can only be used for vectors
17505 with integer elements that are at least 8 bits in size. If the sequence value
17506 exceeds the allowed limit for the element type then the result for that lane is
17509 These intrinsics work for both fixed and scalable vectors. While this intrinsic
17510 is marked as experimental, the recommended way to express this operation for
17511 fixed-width vectors is still to generate a constant vector instead.
17523 Operations on matrixes requiring shape information (like number of rows/columns
17524 or the memory layout) can be expressed using the matrix intrinsics. These
17525 intrinsics require matrix dimensions to be passed as immediate arguments, and
17526 matrixes are passed and returned as vectors. This means that for a ``R`` x
17527 ``C`` matrix, element ``i`` of column ``j`` is at index ``j * R + i`` in the
17528 corresponding vector, with indices starting at 0. Currently column-major layout
17529 is assumed. The intrinsics support both integer and floating point matrixes.
17532 '``llvm.matrix.transpose.*``' Intrinsic
17533 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17537 This is an overloaded intrinsic.
17541 declare vectorty @llvm.matrix.transpose.*(vectorty %In, i32 <Rows>, i32 <Cols>)
17546 The '``llvm.matrix.transpose.*``' intrinsics treat ``%In`` as a ``<Rows> x
17547 <Cols>`` matrix and return the transposed matrix in the result vector.
17552 The first argument ``%In`` is a vector that corresponds to a ``<Rows> x
17553 <Cols>`` matrix. Thus, arguments ``<Rows>`` and ``<Cols>`` correspond to the
17554 number of rows and columns, respectively, and must be positive, constant
17555 integers. The returned vector must have ``<Rows> * <Cols>`` elements, and have
17556 the same float or integer element type as ``%In``.
17558 '``llvm.matrix.multiply.*``' Intrinsic
17559 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17563 This is an overloaded intrinsic.
17567 declare vectorty @llvm.matrix.multiply.*(vectorty %A, vectorty %B, i32 <OuterRows>, i32 <Inner>, i32 <OuterColumns>)
17572 The '``llvm.matrix.multiply.*``' intrinsics treat ``%A`` as a ``<OuterRows> x
17573 <Inner>`` matrix, ``%B`` as a ``<Inner> x <OuterColumns>`` matrix, and
17574 multiplies them. The result matrix is returned in the result vector.
17579 The first vector argument ``%A`` corresponds to a matrix with ``<OuterRows> *
17580 <Inner>`` elements, and the second argument ``%B`` to a matrix with
17581 ``<Inner> * <OuterColumns>`` elements. Arguments ``<OuterRows>``,
17582 ``<Inner>`` and ``<OuterColumns>`` must be positive, constant integers. The
17583 returned vector must have ``<OuterRows> * <OuterColumns>`` elements.
17584 Vectors ``%A``, ``%B``, and the returned vector all have the same float or
17585 integer element type.
17588 '``llvm.matrix.column.major.load.*``' Intrinsic
17589 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17593 This is an overloaded intrinsic.
17597 declare vectorty @llvm.matrix.column.major.load.*(
17598 ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>)
17603 The '``llvm.matrix.column.major.load.*``' intrinsics load a ``<Rows> x <Cols>``
17604 matrix using a stride of ``%Stride`` to compute the start address of the
17605 different columns. The offset is computed using ``%Stride``'s bitwidth. This
17606 allows for convenient loading of sub matrixes. If ``<IsVolatile>`` is true, the
17607 intrinsic is considered a :ref:`volatile memory access <volatile>`. The result
17608 matrix is returned in the result vector. If the ``%Ptr`` argument is known to
17609 be aligned to some boundary, this can be specified as an attribute on the
17615 The first argument ``%Ptr`` is a pointer type to the returned vector type, and
17616 corresponds to the start address to load from. The second argument ``%Stride``
17617 is a positive, constant integer with ``%Stride >= <Rows>``. ``%Stride`` is used
17618 to compute the column memory addresses. I.e., for a column ``C``, its start
17619 memory addresses is calculated with ``%Ptr + C * %Stride``. The third Argument
17620 ``<IsVolatile>`` is a boolean value. The fourth and fifth arguments,
17621 ``<Rows>`` and ``<Cols>``, correspond to the number of rows and columns,
17622 respectively, and must be positive, constant integers. The returned vector must
17623 have ``<Rows> * <Cols>`` elements.
17625 The :ref:`align <attr_align>` parameter attribute can be provided for the
17626 ``%Ptr`` arguments.
17629 '``llvm.matrix.column.major.store.*``' Intrinsic
17630 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17637 declare void @llvm.matrix.column.major.store.*(
17638 vectorty %In, ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>)
17643 The '``llvm.matrix.column.major.store.*``' intrinsics store the ``<Rows> x
17644 <Cols>`` matrix in ``%In`` to memory using a stride of ``%Stride`` between
17645 columns. The offset is computed using ``%Stride``'s bitwidth. If
17646 ``<IsVolatile>`` is true, the intrinsic is considered a
17647 :ref:`volatile memory access <volatile>`.
17649 If the ``%Ptr`` argument is known to be aligned to some boundary, this can be
17650 specified as an attribute on the argument.
17655 The first argument ``%In`` is a vector that corresponds to a ``<Rows> x
17656 <Cols>`` matrix to be stored to memory. The second argument ``%Ptr`` is a
17657 pointer to the vector type of ``%In``, and is the start address of the matrix
17658 in memory. The third argument ``%Stride`` is a positive, constant integer with
17659 ``%Stride >= <Rows>``. ``%Stride`` is used to compute the column memory
17660 addresses. I.e., for a column ``C``, its start memory addresses is calculated
17661 with ``%Ptr + C * %Stride``. The fourth argument ``<IsVolatile>`` is a boolean
17662 value. The arguments ``<Rows>`` and ``<Cols>`` correspond to the number of rows
17663 and columns, respectively, and must be positive, constant integers.
17665 The :ref:`align <attr_align>` parameter attribute can be provided
17666 for the ``%Ptr`` arguments.
17669 Half Precision Floating-Point Intrinsics
17670 ----------------------------------------
17672 For most target platforms, half precision floating-point is a
17673 storage-only format. This means that it is a dense encoding (in memory)
17674 but does not support computation in the format.
17676 This means that code must first load the half-precision floating-point
17677 value as an i16, then convert it to float with
17678 :ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can
17679 then be performed on the float value (including extending to double
17680 etc). To store the value back to memory, it is first converted to float
17681 if needed, then converted to i16 with
17682 :ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an
17685 .. _int_convert_to_fp16:
17687 '``llvm.convert.to.fp16``' Intrinsic
17688 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17695 declare i16 @llvm.convert.to.fp16.f32(float %a)
17696 declare i16 @llvm.convert.to.fp16.f64(double %a)
17701 The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
17702 conventional floating-point type to half precision floating-point format.
17707 The intrinsic function contains single argument - the value to be
17713 The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
17714 conventional floating-point format to half precision floating-point format. The
17715 return value is an ``i16`` which contains the converted number.
17720 .. code-block:: llvm
17722 %res = call i16 @llvm.convert.to.fp16.f32(float %a)
17723 store i16 %res, i16* @x, align 2
17725 .. _int_convert_from_fp16:
17727 '``llvm.convert.from.fp16``' Intrinsic
17728 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17735 declare float @llvm.convert.from.fp16.f32(i16 %a)
17736 declare double @llvm.convert.from.fp16.f64(i16 %a)
17741 The '``llvm.convert.from.fp16``' intrinsic function performs a
17742 conversion from half precision floating-point format to single precision
17743 floating-point format.
17748 The intrinsic function contains single argument - the value to be
17754 The '``llvm.convert.from.fp16``' intrinsic function performs a
17755 conversion from half single precision floating-point format to single
17756 precision floating-point format. The input half-float value is
17757 represented by an ``i16`` value.
17762 .. code-block:: llvm
17764 %a = load i16, ptr @x, align 2
17765 %res = call float @llvm.convert.from.fp16(i16 %a)
17767 Saturating floating-point to integer conversions
17768 ------------------------------------------------
17770 The ``fptoui`` and ``fptosi`` instructions return a
17771 :ref:`poison value <poisonvalues>` if the rounded-towards-zero value is not
17772 representable by the result type. These intrinsics provide an alternative
17773 conversion, which will saturate towards the smallest and largest representable
17774 integer values instead.
17776 '``llvm.fptoui.sat.*``' Intrinsic
17777 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17782 This is an overloaded intrinsic. You can use ``llvm.fptoui.sat`` on any
17783 floating-point argument type and any integer result type, or vectors thereof.
17784 Not all targets may support all types, however.
17788 declare i32 @llvm.fptoui.sat.i32.f32(float %f)
17789 declare i19 @llvm.fptoui.sat.i19.f64(double %f)
17790 declare <4 x i100> @llvm.fptoui.sat.v4i100.v4f128(<4 x fp128> %f)
17795 This intrinsic converts the argument into an unsigned integer using saturating
17801 The argument may be any floating-point or vector of floating-point type. The
17802 return value may be any integer or vector of integer type. The number of vector
17803 elements in argument and return must be the same.
17808 The conversion to integer is performed subject to the following rules:
17810 - If the argument is any NaN, zero is returned.
17811 - If the argument is smaller than zero (this includes negative infinity),
17813 - If the argument is larger than the largest representable unsigned integer of
17814 the result type (this includes positive infinity), the largest representable
17815 unsigned integer is returned.
17816 - Otherwise, the result of rounding the argument towards zero is returned.
17821 .. code-block:: text
17823 %a = call i8 @llvm.fptoui.sat.i8.f32(float 123.9) ; yields i8: 123
17824 %b = call i8 @llvm.fptoui.sat.i8.f32(float -5.7) ; yields i8: 0
17825 %c = call i8 @llvm.fptoui.sat.i8.f32(float 377.0) ; yields i8: 255
17826 %d = call i8 @llvm.fptoui.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0
17828 '``llvm.fptosi.sat.*``' Intrinsic
17829 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17834 This is an overloaded intrinsic. You can use ``llvm.fptosi.sat`` on any
17835 floating-point argument type and any integer result type, or vectors thereof.
17836 Not all targets may support all types, however.
17840 declare i32 @llvm.fptosi.sat.i32.f32(float %f)
17841 declare i19 @llvm.fptosi.sat.i19.f64(double %f)
17842 declare <4 x i100> @llvm.fptosi.sat.v4i100.v4f128(<4 x fp128> %f)
17847 This intrinsic converts the argument into a signed integer using saturating
17853 The argument may be any floating-point or vector of floating-point type. The
17854 return value may be any integer or vector of integer type. The number of vector
17855 elements in argument and return must be the same.
17860 The conversion to integer is performed subject to the following rules:
17862 - If the argument is any NaN, zero is returned.
17863 - If the argument is smaller than the smallest representable signed integer of
17864 the result type (this includes negative infinity), the smallest
17865 representable signed integer is returned.
17866 - If the argument is larger than the largest representable signed integer of
17867 the result type (this includes positive infinity), the largest representable
17868 signed integer is returned.
17869 - Otherwise, the result of rounding the argument towards zero is returned.
17874 .. code-block:: text
17876 %a = call i8 @llvm.fptosi.sat.i8.f32(float 23.9) ; yields i8: 23
17877 %b = call i8 @llvm.fptosi.sat.i8.f32(float -130.8) ; yields i8: -128
17878 %c = call i8 @llvm.fptosi.sat.i8.f32(float 999.0) ; yields i8: 127
17879 %d = call i8 @llvm.fptosi.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0
17881 .. _dbg_intrinsics:
17883 Debugger Intrinsics
17884 -------------------
17886 The LLVM debugger intrinsics (which all start with ``llvm.dbg.``
17887 prefix), are described in the `LLVM Source Level
17888 Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_
17891 Exception Handling Intrinsics
17892 -----------------------------
17894 The LLVM exception handling intrinsics (which all start with
17895 ``llvm.eh.`` prefix), are described in the `LLVM Exception
17896 Handling <ExceptionHandling.html#format-common-intrinsics>`_ document.
17898 Pointer Authentication Intrinsics
17899 ---------------------------------
17901 The LLVM pointer authentication intrinsics (which all start with
17902 ``llvm.ptrauth.`` prefix), are described in the `Pointer Authentication
17903 <PointerAuth.html#intrinsics>`_ document.
17905 .. _int_trampoline:
17907 Trampoline Intrinsics
17908 ---------------------
17910 These intrinsics make it possible to excise one parameter, marked with
17911 the :ref:`nest <nest>` attribute, from a function. The result is a
17912 callable function pointer lacking the nest parameter - the caller does
17913 not need to provide a value for it. Instead, the value to use is stored
17914 in advance in a "trampoline", a block of memory usually allocated on the
17915 stack, which also contains code to splice the nest value into the
17916 argument list. This is used to implement the GCC nested function address
17919 For example, if the function is ``i32 f(ptr nest %c, i32 %x, i32 %y)``
17920 then the resulting function pointer has signature ``i32 (i32, i32)``.
17921 It can be created as follows:
17923 .. code-block:: llvm
17925 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
17926 call ptr @llvm.init.trampoline(ptr %tramp, ptr @f, ptr %nval)
17927 %fp = call ptr @llvm.adjust.trampoline(ptr %tramp)
17929 The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to
17930 ``%val = call i32 %f(ptr %nval, i32 %x, i32 %y)``.
17934 '``llvm.init.trampoline``' Intrinsic
17935 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17942 declare void @llvm.init.trampoline(ptr <tramp>, ptr <func>, ptr <nval>)
17947 This fills the memory pointed to by ``tramp`` with executable code,
17948 turning it into a trampoline.
17953 The ``llvm.init.trampoline`` intrinsic takes three arguments, all
17954 pointers. The ``tramp`` argument must point to a sufficiently large and
17955 sufficiently aligned block of memory; this memory is written to by the
17956 intrinsic. Note that the size and the alignment are target-specific -
17957 LLVM currently provides no portable way of determining them, so a
17958 front-end that generates this intrinsic needs to have some
17959 target-specific knowledge. The ``func`` argument must hold a function.
17964 The block of memory pointed to by ``tramp`` is filled with target
17965 dependent code, turning it into a function. Then ``tramp`` needs to be
17966 passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can
17967 be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new
17968 function's signature is the same as that of ``func`` with any arguments
17969 marked with the ``nest`` attribute removed. At most one such ``nest``
17970 argument is allowed, and it must be of pointer type. Calling the new
17971 function is equivalent to calling ``func`` with the same argument list,
17972 but with ``nval`` used for the missing ``nest`` argument. If, after
17973 calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is
17974 modified, then the effect of any later call to the returned function
17975 pointer is undefined.
17979 '``llvm.adjust.trampoline``' Intrinsic
17980 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17987 declare ptr @llvm.adjust.trampoline(ptr <tramp>)
17992 This performs any required machine-specific adjustment to the address of
17993 a trampoline (passed as ``tramp``).
17998 ``tramp`` must point to a block of memory which already has trampoline
17999 code filled in by a previous call to
18000 :ref:`llvm.init.trampoline <int_it>`.
18005 On some architectures the address of the code to be executed needs to be
18006 different than the address where the trampoline is actually stored. This
18007 intrinsic returns the executable address corresponding to ``tramp``
18008 after performing the required machine specific adjustments. The pointer
18009 returned can then be :ref:`bitcast and executed <int_trampoline>`.
18014 Vector Predication Intrinsics
18015 -----------------------------
18016 VP intrinsics are intended for predicated SIMD/vector code. A typical VP
18017 operation takes a vector mask and an explicit vector length parameter as in:
18021 <W x T> llvm.vp.<opcode>.*(<W x T> %x, <W x T> %y, <W x i1> %mask, i32 %evl)
18023 The vector mask parameter (%mask) always has a vector of `i1` type, for example
18024 `<32 x i1>`. The explicit vector length parameter always has the type `i32` and
18025 is an unsigned integer value. The explicit vector length parameter (%evl) is in
18030 0 <= %evl <= W, where W is the number of vector elements
18032 Note that for :ref:`scalable vector types <t_vector>` ``W`` is the runtime
18033 length of the vector.
18035 The VP intrinsic has undefined behavior if ``%evl > W``. The explicit vector
18036 length (%evl) creates a mask, %EVLmask, with all elements ``0 <= i < %evl`` set
18037 to True, and all other lanes ``%evl <= i < W`` to False. A new mask %M is
18038 calculated with an element-wise AND from %mask and %EVLmask:
18042 M = %mask AND %EVLmask
18044 A vector operation ``<opcode>`` on vectors ``A`` and ``B`` calculates:
18048 A <opcode> B = { A[i] <opcode> B[i] M[i] = True, and
18054 Some targets, such as AVX512, do not support the %evl parameter in hardware.
18055 The use of an effective %evl is discouraged for those targets. The function
18056 ``TargetTransformInfo::hasActiveVectorLength()`` returns true when the target
18057 has native support for %evl.
18061 '``llvm.vp.select.*``' Intrinsics
18062 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18066 This is an overloaded intrinsic.
18070 declare <16 x i32> @llvm.vp.select.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <evl>)
18071 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>)
18076 The '``llvm.vp.select``' intrinsic is used to choose one value based on a
18077 condition vector, without IR-level branching.
18082 The first operand is a vector of ``i1`` and indicates the condition. The
18083 second operand is the value that is selected where the condition vector is
18084 true. The third operand is the value that is selected where the condition
18085 vector is false. The vectors must be of the same size. The fourth operand is
18086 the explicit vector length.
18088 #. The optional ``fast-math flags`` marker indicates that the select has one or
18089 more :ref:`fast-math flags <fastmath>`. These are optimization hints to
18090 enable otherwise unsafe floating-point optimizations. Fast-math flags are
18091 only valid for selects that return a floating-point scalar or vector type,
18092 or an array (nested to any depth) of floating-point scalar or vector types.
18097 The intrinsic selects lanes from the second and third operand depending on a
18100 All result lanes at positions greater or equal than ``%evl`` are undefined.
18101 For all lanes below ``%evl`` where the condition vector is true the lane is
18102 taken from the second operand. Otherwise, the lane is taken from the third
18108 .. code-block:: llvm
18110 %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)
18113 ;; Any result is legal on lanes at and above %evl.
18114 %also.r = select <4 x i1> %cond, <4 x i32> %on_true, <4 x i32> %on_false
18119 '``llvm.vp.merge.*``' Intrinsics
18120 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18124 This is an overloaded intrinsic.
18128 declare <16 x i32> @llvm.vp.merge.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <pivot>)
18129 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>)
18134 The '``llvm.vp.merge``' intrinsic is used to choose one value based on a
18135 condition vector and an index operand, without IR-level branching.
18140 The first operand is a vector of ``i1`` and indicates the condition. The
18141 second operand is the value that is merged where the condition vector is true.
18142 The third operand is the value that is selected where the condition vector is
18143 false or the lane position is greater equal than the pivot. The fourth operand
18146 #. The optional ``fast-math flags`` marker indicates that the merge has one or
18147 more :ref:`fast-math flags <fastmath>`. These are optimization hints to
18148 enable otherwise unsafe floating-point optimizations. Fast-math flags are
18149 only valid for merges that return a floating-point scalar or vector type,
18150 or an array (nested to any depth) of floating-point scalar or vector types.
18155 The intrinsic selects lanes from the second and third operand depending on a
18156 condition vector and pivot value.
18158 For all lanes where the condition vector is true and the lane position is less
18159 than ``%pivot`` the lane is taken from the second operand. Otherwise, the lane
18160 is taken from the third operand.
18165 .. code-block:: llvm
18167 %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)
18170 ;; Lanes at and above %pivot are taken from %on_false
18171 %atfirst = insertelement <4 x i32> undef, i32 %pivot, i32 0
18172 %splat = shufflevector <4 x i32> %atfirst, <4 x i32> poison, <4 x i32> zeroinitializer
18173 %pivotmask = icmp ult <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32> %splat
18174 %mergemask = and <4 x i1> %cond, <4 x i1> %pivotmask
18175 %also.r = select <4 x i1> %mergemask, <4 x i32> %on_true, <4 x i32> %on_false
18181 '``llvm.vp.add.*``' Intrinsics
18182 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18186 This is an overloaded intrinsic.
18190 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>)
18191 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>)
18192 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>)
18197 Predicated integer addition of two vectors of integers.
18203 The first two operands and the result have the same vector of integer type. The
18204 third operand is the vector mask and has the same number of elements as the
18205 result vector type. The fourth operand is the explicit vector length of the
18211 The '``llvm.vp.add``' intrinsic performs integer addition (:ref:`add <i_add>`)
18212 of the first and second vector operand on each enabled lane. The result on
18213 disabled lanes is undefined.
18218 .. code-block:: llvm
18220 %r = call <4 x i32> @llvm.vp.add.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18221 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18223 %t = add <4 x i32> %a, %b
18224 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18228 '``llvm.vp.sub.*``' Intrinsics
18229 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18233 This is an overloaded intrinsic.
18237 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>)
18238 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>)
18239 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>)
18244 Predicated integer subtraction of two vectors of integers.
18250 The first two operands and the result have the same vector of integer type. The
18251 third operand is the vector mask and has the same number of elements as the
18252 result vector type. The fourth operand is the explicit vector length of the
18258 The '``llvm.vp.sub``' intrinsic performs integer subtraction
18259 (:ref:`sub <i_sub>`) of the first and second vector operand on each enabled
18260 lane. The result on disabled lanes is undefined.
18265 .. code-block:: llvm
18267 %r = call <4 x i32> @llvm.vp.sub.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18268 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18270 %t = sub <4 x i32> %a, %b
18271 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18277 '``llvm.vp.mul.*``' Intrinsics
18278 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18282 This is an overloaded intrinsic.
18286 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>)
18287 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>)
18288 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>)
18293 Predicated integer multiplication of two vectors of integers.
18299 The first two operands and the result have the same vector of integer type. The
18300 third operand is the vector mask and has the same number of elements as the
18301 result vector type. The fourth operand is the explicit vector length of the
18306 The '``llvm.vp.mul``' intrinsic performs integer multiplication
18307 (:ref:`mul <i_mul>`) of the first and second vector operand on each enabled
18308 lane. The result on disabled lanes is undefined.
18313 .. code-block:: llvm
18315 %r = call <4 x i32> @llvm.vp.mul.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18316 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18318 %t = mul <4 x i32> %a, %b
18319 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18324 '``llvm.vp.sdiv.*``' Intrinsics
18325 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18329 This is an overloaded intrinsic.
18333 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>)
18334 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>)
18335 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>)
18340 Predicated, signed division of two vectors of integers.
18346 The first two operands and the result have the same vector of integer type. The
18347 third operand is the vector mask and has the same number of elements as the
18348 result vector type. The fourth operand is the explicit vector length of the
18354 The '``llvm.vp.sdiv``' intrinsic performs signed division (:ref:`sdiv <i_sdiv>`)
18355 of the first and second vector operand on each enabled lane. The result on
18356 disabled lanes is undefined.
18361 .. code-block:: llvm
18363 %r = call <4 x i32> @llvm.vp.sdiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18364 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18366 %t = sdiv <4 x i32> %a, %b
18367 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18372 '``llvm.vp.udiv.*``' Intrinsics
18373 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18377 This is an overloaded intrinsic.
18381 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>)
18382 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>)
18383 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>)
18388 Predicated, unsigned division of two vectors of integers.
18394 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.
18399 The '``llvm.vp.udiv``' intrinsic performs unsigned division
18400 (:ref:`udiv <i_udiv>`) of the first and second vector operand on each enabled
18401 lane. The result on disabled lanes is undefined.
18406 .. code-block:: llvm
18408 %r = call <4 x i32> @llvm.vp.udiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18409 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18411 %t = udiv <4 x i32> %a, %b
18412 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18418 '``llvm.vp.srem.*``' Intrinsics
18419 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18423 This is an overloaded intrinsic.
18427 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>)
18428 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>)
18429 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>)
18434 Predicated computations of the signed remainder of two integer vectors.
18440 The first two operands and the result have the same vector of integer type. The
18441 third operand is the vector mask and has the same number of elements as the
18442 result vector type. The fourth operand is the explicit vector length of the
18448 The '``llvm.vp.srem``' intrinsic computes the remainder of the signed division
18449 (:ref:`srem <i_srem>`) of the first and second vector operand on each enabled
18450 lane. The result on disabled lanes is undefined.
18455 .. code-block:: llvm
18457 %r = call <4 x i32> @llvm.vp.srem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18458 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18460 %t = srem <4 x i32> %a, %b
18461 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18467 '``llvm.vp.urem.*``' Intrinsics
18468 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18472 This is an overloaded intrinsic.
18476 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>)
18477 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>)
18478 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>)
18483 Predicated computation of the unsigned remainder of two integer vectors.
18489 The first two operands and the result have the same vector of integer type. The
18490 third operand is the vector mask and has the same number of elements as the
18491 result vector type. The fourth operand is the explicit vector length of the
18497 The '``llvm.vp.urem``' intrinsic computes the remainder of the unsigned division
18498 (:ref:`urem <i_urem>`) of the first and second vector operand on each enabled
18499 lane. The result on disabled lanes is undefined.
18504 .. code-block:: llvm
18506 %r = call <4 x i32> @llvm.vp.urem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18507 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18509 %t = urem <4 x i32> %a, %b
18510 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18515 '``llvm.vp.ashr.*``' Intrinsics
18516 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18520 This is an overloaded intrinsic.
18524 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>)
18525 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>)
18526 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>)
18531 Vector-predicated arithmetic right-shift.
18537 The first two operands and the result have the same vector of integer type. The
18538 third operand is the vector mask and has the same number of elements as the
18539 result vector type. The fourth operand is the explicit vector length of the
18545 The '``llvm.vp.ashr``' intrinsic computes the arithmetic right shift
18546 (:ref:`ashr <i_ashr>`) of the first operand by the second operand on each
18547 enabled lane. The result on disabled lanes is undefined.
18552 .. code-block:: llvm
18554 %r = call <4 x i32> @llvm.vp.ashr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18555 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18557 %t = ashr <4 x i32> %a, %b
18558 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18564 '``llvm.vp.lshr.*``' Intrinsics
18565 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18569 This is an overloaded intrinsic.
18573 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>)
18574 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>)
18575 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>)
18580 Vector-predicated logical right-shift.
18586 The first two operands and the result have the same vector of integer type. The
18587 third operand is the vector mask and has the same number of elements as the
18588 result vector type. The fourth operand is the explicit vector length of the
18594 The '``llvm.vp.lshr``' intrinsic computes the logical right shift
18595 (:ref:`lshr <i_lshr>`) of the first operand by the second operand on each
18596 enabled lane. The result on disabled lanes is undefined.
18601 .. code-block:: llvm
18603 %r = call <4 x i32> @llvm.vp.lshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18604 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18606 %t = lshr <4 x i32> %a, %b
18607 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18612 '``llvm.vp.shl.*``' Intrinsics
18613 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18617 This is an overloaded intrinsic.
18621 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>)
18622 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>)
18623 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>)
18628 Vector-predicated left shift.
18634 The first two operands and the result have the same vector of integer type. The
18635 third operand is the vector mask and has the same number of elements as the
18636 result vector type. The fourth operand is the explicit vector length of the
18642 The '``llvm.vp.shl``' intrinsic computes the left shift (:ref:`shl <i_shl>`) of
18643 the first operand by the second operand on each enabled lane. The result on
18644 disabled lanes is undefined.
18649 .. code-block:: llvm
18651 %r = call <4 x i32> @llvm.vp.shl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18652 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18654 %t = shl <4 x i32> %a, %b
18655 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18660 '``llvm.vp.or.*``' Intrinsics
18661 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18665 This is an overloaded intrinsic.
18669 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>)
18670 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>)
18671 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>)
18676 Vector-predicated or.
18682 The first two operands and the result have the same vector of integer type. The
18683 third operand is the vector mask and has the same number of elements as the
18684 result vector type. The fourth operand is the explicit vector length of the
18690 The '``llvm.vp.or``' intrinsic performs a bitwise or (:ref:`or <i_or>`) of the
18691 first two operands on each enabled lane. The result on disabled lanes is
18697 .. code-block:: llvm
18699 %r = call <4 x i32> @llvm.vp.or.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18700 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18702 %t = or <4 x i32> %a, %b
18703 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18708 '``llvm.vp.and.*``' Intrinsics
18709 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18713 This is an overloaded intrinsic.
18717 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>)
18718 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>)
18719 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>)
18724 Vector-predicated and.
18730 The first two operands and the result have the same vector of integer type. The
18731 third operand is the vector mask and has the same number of elements as the
18732 result vector type. The fourth operand is the explicit vector length of the
18738 The '``llvm.vp.and``' intrinsic performs a bitwise and (:ref:`and <i_or>`) of
18739 the first two operands on each enabled lane. The result on disabled lanes is
18745 .. code-block:: llvm
18747 %r = call <4 x i32> @llvm.vp.and.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18748 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18750 %t = and <4 x i32> %a, %b
18751 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18756 '``llvm.vp.xor.*``' Intrinsics
18757 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18761 This is an overloaded intrinsic.
18765 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>)
18766 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>)
18767 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>)
18772 Vector-predicated, bitwise xor.
18778 The first two operands and the result have the same vector of integer type. The
18779 third operand is the vector mask and has the same number of elements as the
18780 result vector type. The fourth operand is the explicit vector length of the
18786 The '``llvm.vp.xor``' intrinsic performs a bitwise xor (:ref:`xor <i_xor>`) of
18787 the first two operands on each enabled lane.
18788 The result on disabled lanes is undefined.
18793 .. code-block:: llvm
18795 %r = call <4 x i32> @llvm.vp.xor.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl)
18796 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18798 %t = xor <4 x i32> %a, %b
18799 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
18804 '``llvm.vp.fadd.*``' Intrinsics
18805 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18809 This is an overloaded intrinsic.
18813 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>)
18814 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>)
18815 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>)
18820 Predicated floating-point addition of two vectors of floating-point values.
18826 The first two operands and the result have the same vector of floating-point type. The
18827 third operand is the vector mask and has the same number of elements as the
18828 result vector type. The fourth operand is the explicit vector length of the
18834 The '``llvm.vp.fadd``' intrinsic performs floating-point addition (:ref:`fadd <i_fadd>`)
18835 of the first and second vector operand on each enabled lane. The result on
18836 disabled lanes is undefined. The operation is performed in the default
18837 floating-point environment.
18842 .. code-block:: llvm
18844 %r = call <4 x float> @llvm.vp.fadd.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
18845 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18847 %t = fadd <4 x float> %a, %b
18848 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
18853 '``llvm.vp.fsub.*``' Intrinsics
18854 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18858 This is an overloaded intrinsic.
18862 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>)
18863 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>)
18864 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>)
18869 Predicated floating-point subtraction of two vectors of floating-point values.
18875 The first two operands and the result have the same vector of floating-point type. The
18876 third operand is the vector mask and has the same number of elements as the
18877 result vector type. The fourth operand is the explicit vector length of the
18883 The '``llvm.vp.fsub``' intrinsic performs floating-point subtraction (:ref:`fsub <i_fsub>`)
18884 of the first and second vector operand on each enabled lane. The result on
18885 disabled lanes is undefined. The operation is performed in the default
18886 floating-point environment.
18891 .. code-block:: llvm
18893 %r = call <4 x float> @llvm.vp.fsub.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
18894 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18896 %t = fsub <4 x float> %a, %b
18897 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
18902 '``llvm.vp.fmul.*``' Intrinsics
18903 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18907 This is an overloaded intrinsic.
18911 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>)
18912 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>)
18913 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>)
18918 Predicated floating-point multiplication of two vectors of floating-point values.
18924 The first two operands and the result have the same vector of floating-point type. The
18925 third operand is the vector mask and has the same number of elements as the
18926 result vector type. The fourth operand is the explicit vector length of the
18932 The '``llvm.vp.fmul``' intrinsic performs floating-point multiplication (:ref:`fmul <i_fmul>`)
18933 of the first and second vector operand on each enabled lane. The result on
18934 disabled lanes is undefined. The operation is performed in the default
18935 floating-point environment.
18940 .. code-block:: llvm
18942 %r = call <4 x float> @llvm.vp.fmul.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
18943 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18945 %t = fmul <4 x float> %a, %b
18946 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
18951 '``llvm.vp.fdiv.*``' Intrinsics
18952 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18956 This is an overloaded intrinsic.
18960 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>)
18961 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>)
18962 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>)
18967 Predicated floating-point division of two vectors of floating-point values.
18973 The first two operands and the result have the same vector of floating-point type. The
18974 third operand is the vector mask and has the same number of elements as the
18975 result vector type. The fourth operand is the explicit vector length of the
18981 The '``llvm.vp.fdiv``' intrinsic performs floating-point division (:ref:`fdiv <i_fdiv>`)
18982 of the first and second vector operand on each enabled lane. The result on
18983 disabled lanes is undefined. The operation is performed in the default
18984 floating-point environment.
18989 .. code-block:: llvm
18991 %r = call <4 x float> @llvm.vp.fdiv.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
18992 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
18994 %t = fdiv <4 x float> %a, %b
18995 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
19000 '``llvm.vp.frem.*``' Intrinsics
19001 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19005 This is an overloaded intrinsic.
19009 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>)
19010 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>)
19011 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>)
19016 Predicated floating-point remainder of two vectors of floating-point values.
19022 The first two operands and the result have the same vector of floating-point type. The
19023 third operand is the vector mask and has the same number of elements as the
19024 result vector type. The fourth operand is the explicit vector length of the
19030 The '``llvm.vp.frem``' intrinsic performs floating-point remainder (:ref:`frem <i_frem>`)
19031 of the first and second vector operand on each enabled lane. The result on
19032 disabled lanes is undefined. The operation is performed in the default
19033 floating-point environment.
19038 .. code-block:: llvm
19040 %r = call <4 x float> @llvm.vp.frem.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl)
19041 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19043 %t = frem <4 x float> %a, %b
19044 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
19049 '``llvm.vp.fneg.*``' Intrinsics
19050 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19054 This is an overloaded intrinsic.
19058 declare <16 x float> @llvm.vp.fneg.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
19059 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>)
19060 declare <256 x double> @llvm.vp.fneg.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
19065 Predicated floating-point negation of a vector of floating-point values.
19071 The first operand and the result have the same vector of floating-point type.
19072 The second operand is the vector mask and has the same number of elements as the
19073 result vector type. The third operand is the explicit vector length of the
19079 The '``llvm.vp.fneg``' intrinsic performs floating-point negation (:ref:`fneg <i_fneg>`)
19080 of the first vector operand on each enabled lane. The result on disabled lanes
19086 .. code-block:: llvm
19088 %r = call <4 x float> @llvm.vp.fneg.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
19089 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19091 %t = fneg <4 x float> %a
19092 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
19097 '``llvm.vp.fma.*``' Intrinsics
19098 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19102 This is an overloaded intrinsic.
19106 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>)
19107 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>)
19108 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>)
19113 Predicated floating-point fused multiply-add of two vectors of floating-point values.
19119 The first three operands and the result have the same vector of floating-point type. The
19120 fourth operand is the vector mask and has the same number of elements as the
19121 result vector type. The fifth operand is the explicit vector length of the
19127 The '``llvm.vp.fma``' intrinsic performs floating-point fused multiply-add (:ref:`llvm.fma <int_fma>`)
19128 of the first, second, and third vector operand on each enabled lane. The result on
19129 disabled lanes is undefined. The operation is performed in the default
19130 floating-point environment.
19135 .. code-block:: llvm
19137 %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)
19138 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19140 %t = call <4 x float> @llvm.fma(<4 x float> %a, <4 x float> %b, <4 x float> %c)
19141 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
19144 .. _int_vp_reduce_add:
19146 '``llvm.vp.reduce.add.*``' Intrinsics
19147 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19151 This is an overloaded intrinsic.
19155 declare i32 @llvm.vp.reduce.add.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19156 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>)
19161 Predicated integer ``ADD`` reduction of a vector and a scalar starting value,
19162 returning the result as a scalar.
19167 The first operand is the start value of the reduction, which must be a scalar
19168 integer type equal to the result type. The second operand is the vector on
19169 which the reduction is performed and must be a vector of integer values whose
19170 element type is the result/start type. The third operand is the vector mask and
19171 is a vector of boolean values with the same number of elements as the vector
19172 operand. The fourth operand is the explicit vector length of the operation.
19177 The '``llvm.vp.reduce.add``' intrinsic performs the integer ``ADD`` reduction
19178 (:ref:`llvm.vector.reduce.add <int_vector_reduce_add>`) of the vector operand
19179 ``val`` on each enabled lane, adding it to the scalar ``start_value``. Disabled
19180 lanes are treated as containing the neutral value ``0`` (i.e. having no effect
19181 on the reduction operation). If the vector length is zero, the result is equal
19182 to ``start_value``.
19184 To ignore the start value, the neutral value can be used.
19189 .. code-block:: llvm
19191 %r = call i32 @llvm.vp.reduce.add.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19192 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19193 ; are treated as though %mask were false for those lanes.
19195 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> zeroinitializer
19196 %reduction = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %masked.a)
19197 %also.r = add i32 %reduction, %start
19200 .. _int_vp_reduce_fadd:
19202 '``llvm.vp.reduce.fadd.*``' Intrinsics
19203 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19207 This is an overloaded intrinsic.
19211 declare float @llvm.vp.reduce.fadd.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>)
19212 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>)
19217 Predicated floating-point ``ADD`` reduction of a vector and a scalar starting
19218 value, returning the result as a scalar.
19223 The first operand is the start value of the reduction, which must be a scalar
19224 floating-point type equal to the result type. The second operand is the vector
19225 on which the reduction is performed and must be a vector of floating-point
19226 values whose element type is the result/start type. The third operand is the
19227 vector mask and is a vector of boolean values with the same number of elements
19228 as the vector operand. The fourth operand is the explicit vector length of the
19234 The '``llvm.vp.reduce.fadd``' intrinsic performs the floating-point ``ADD``
19235 reduction (:ref:`llvm.vector.reduce.fadd <int_vector_reduce_fadd>`) of the
19236 vector operand ``val`` on each enabled lane, adding it to the scalar
19237 ``start_value``. Disabled lanes are treated as containing the neutral value
19238 ``-0.0`` (i.e. having no effect on the reduction operation). If no lanes are
19239 enabled, the resulting value will be equal to ``start_value``.
19241 To ignore the start value, the neutral value can be used.
19243 See the unpredicated version (:ref:`llvm.vector.reduce.fadd
19244 <int_vector_reduce_fadd>`) for more detail on the semantics of the reduction.
19249 .. code-block:: llvm
19251 %r = call float @llvm.vp.reduce.fadd.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
19252 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19253 ; are treated as though %mask were false for those lanes.
19255 %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>
19256 %also.r = call float @llvm.vector.reduce.fadd.v4f32(float %start, <4 x float> %masked.a)
19259 .. _int_vp_reduce_mul:
19261 '``llvm.vp.reduce.mul.*``' Intrinsics
19262 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19266 This is an overloaded intrinsic.
19270 declare i32 @llvm.vp.reduce.mul.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19271 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>)
19276 Predicated integer ``MUL`` reduction of a vector and a scalar starting value,
19277 returning the result as a scalar.
19283 The first operand is the start value of the reduction, which must be a scalar
19284 integer type equal to the result type. The second operand is the vector on
19285 which the reduction is performed and must be a vector of integer values whose
19286 element type is the result/start type. The third operand is the vector mask and
19287 is a vector of boolean values with the same number of elements as the vector
19288 operand. The fourth operand is the explicit vector length of the operation.
19293 The '``llvm.vp.reduce.mul``' intrinsic performs the integer ``MUL`` reduction
19294 (:ref:`llvm.vector.reduce.mul <int_vector_reduce_mul>`) of the vector operand ``val``
19295 on each enabled lane, multiplying it by the scalar ``start_value``. Disabled
19296 lanes are treated as containing the neutral value ``1`` (i.e. having no effect
19297 on the reduction operation). If the vector length is zero, the result is the
19300 To ignore the start value, the neutral value can be used.
19305 .. code-block:: llvm
19307 %r = call i32 @llvm.vp.reduce.mul.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19308 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19309 ; are treated as though %mask were false for those lanes.
19311 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
19312 %reduction = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %masked.a)
19313 %also.r = mul i32 %reduction, %start
19315 .. _int_vp_reduce_fmul:
19317 '``llvm.vp.reduce.fmul.*``' Intrinsics
19318 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19322 This is an overloaded intrinsic.
19326 declare float @llvm.vp.reduce.fmul.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>)
19327 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>)
19332 Predicated floating-point ``MUL`` reduction of a vector and a scalar starting
19333 value, returning the result as a scalar.
19339 The first operand is the start value of the reduction, which must be a scalar
19340 floating-point type equal to the result type. The second operand is the vector
19341 on which the reduction is performed and must be a vector of floating-point
19342 values whose element type is the result/start type. The third operand is the
19343 vector mask and is a vector of boolean values with the same number of elements
19344 as the vector operand. The fourth operand is the explicit vector length of the
19350 The '``llvm.vp.reduce.fmul``' intrinsic performs the floating-point ``MUL``
19351 reduction (:ref:`llvm.vector.reduce.fmul <int_vector_reduce_fmul>`) of the
19352 vector operand ``val`` on each enabled lane, multiplying it by the scalar
19353 `start_value``. Disabled lanes are treated as containing the neutral value
19354 ``1.0`` (i.e. having no effect on the reduction operation). If no lanes are
19355 enabled, the resulting value will be equal to the starting value.
19357 To ignore the start value, the neutral value can be used.
19359 See the unpredicated version (:ref:`llvm.vector.reduce.fmul
19360 <int_vector_reduce_fmul>`) for more detail on the semantics.
19365 .. code-block:: llvm
19367 %r = call float @llvm.vp.reduce.fmul.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
19368 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19369 ; are treated as though %mask were false for those lanes.
19371 %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>
19372 %also.r = call float @llvm.vector.reduce.fmul.v4f32(float %start, <4 x float> %masked.a)
19375 .. _int_vp_reduce_and:
19377 '``llvm.vp.reduce.and.*``' Intrinsics
19378 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19382 This is an overloaded intrinsic.
19386 declare i32 @llvm.vp.reduce.and.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19387 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>)
19392 Predicated integer ``AND`` reduction of a vector and a scalar starting value,
19393 returning the result as a scalar.
19399 The first operand is the start value of the reduction, which must be a scalar
19400 integer type equal to the result type. The second operand is the vector on
19401 which the reduction is performed and must be a vector of integer values whose
19402 element type is the result/start type. The third operand is the vector mask and
19403 is a vector of boolean values with the same number of elements as the vector
19404 operand. The fourth operand is the explicit vector length of the operation.
19409 The '``llvm.vp.reduce.and``' intrinsic performs the integer ``AND`` reduction
19410 (:ref:`llvm.vector.reduce.and <int_vector_reduce_and>`) of the vector operand
19411 ``val`` on each enabled lane, performing an '``and``' of that with with the
19412 scalar ``start_value``. Disabled lanes are treated as containing the neutral
19413 value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction
19414 operation). If the vector length is zero, the result is the start value.
19416 To ignore the start value, the neutral value can be used.
19421 .. code-block:: llvm
19423 %r = call i32 @llvm.vp.reduce.and.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19424 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19425 ; are treated as though %mask were false for those lanes.
19427 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
19428 %reduction = call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %masked.a)
19429 %also.r = and i32 %reduction, %start
19432 .. _int_vp_reduce_or:
19434 '``llvm.vp.reduce.or.*``' Intrinsics
19435 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19439 This is an overloaded intrinsic.
19443 declare i32 @llvm.vp.reduce.or.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19444 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>)
19449 Predicated integer ``OR`` reduction of a vector and a scalar starting value,
19450 returning the result as a scalar.
19456 The first operand is the start value of the reduction, which must be a scalar
19457 integer type equal to the result type. The second operand is the vector on
19458 which the reduction is performed and must be a vector of integer values whose
19459 element type is the result/start type. The third operand is the vector mask and
19460 is a vector of boolean values with the same number of elements as the vector
19461 operand. The fourth operand is the explicit vector length of the operation.
19466 The '``llvm.vp.reduce.or``' intrinsic performs the integer ``OR`` reduction
19467 (:ref:`llvm.vector.reduce.or <int_vector_reduce_or>`) of the vector operand
19468 ``val`` on each enabled lane, performing an '``or``' of that with the scalar
19469 ``start_value``. Disabled lanes are treated as containing the neutral value
19470 ``0`` (i.e. having no effect on the reduction operation). If the vector length
19471 is zero, the result is the start value.
19473 To ignore the start value, the neutral value can be used.
19478 .. code-block:: llvm
19480 %r = call i32 @llvm.vp.reduce.or.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19481 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19482 ; are treated as though %mask were false for those lanes.
19484 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
19485 %reduction = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %masked.a)
19486 %also.r = or i32 %reduction, %start
19488 .. _int_vp_reduce_xor:
19490 '``llvm.vp.reduce.xor.*``' Intrinsics
19491 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19495 This is an overloaded intrinsic.
19499 declare i32 @llvm.vp.reduce.xor.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19500 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>)
19505 Predicated integer ``XOR`` reduction of a vector and a scalar starting value,
19506 returning the result as a scalar.
19512 The first operand is the start value of the reduction, which must be a scalar
19513 integer type equal to the result type. The second operand is the vector on
19514 which the reduction is performed and must be a vector of integer values whose
19515 element type is the result/start type. The third operand is the vector mask and
19516 is a vector of boolean values with the same number of elements as the vector
19517 operand. The fourth operand is the explicit vector length of the operation.
19522 The '``llvm.vp.reduce.xor``' intrinsic performs the integer ``XOR`` reduction
19523 (:ref:`llvm.vector.reduce.xor <int_vector_reduce_xor>`) of the vector operand
19524 ``val`` on each enabled lane, performing an '``xor``' of that with the scalar
19525 ``start_value``. Disabled lanes are treated as containing the neutral value
19526 ``0`` (i.e. having no effect on the reduction operation). If the vector length
19527 is zero, the result is the start value.
19529 To ignore the start value, the neutral value can be used.
19534 .. code-block:: llvm
19536 %r = call i32 @llvm.vp.reduce.xor.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19537 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19538 ; are treated as though %mask were false for those lanes.
19540 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
19541 %reduction = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %masked.a)
19542 %also.r = xor i32 %reduction, %start
19545 .. _int_vp_reduce_smax:
19547 '``llvm.vp.reduce.smax.*``' Intrinsics
19548 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19552 This is an overloaded intrinsic.
19556 declare i32 @llvm.vp.reduce.smax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19557 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>)
19562 Predicated signed-integer ``MAX`` reduction of a vector and a scalar starting
19563 value, returning the result as a scalar.
19569 The first operand is the start value of the reduction, which must be a scalar
19570 integer type equal to the result type. The second operand is the vector on
19571 which the reduction is performed and must be a vector of integer values whose
19572 element type is the result/start type. The third operand is the vector mask and
19573 is a vector of boolean values with the same number of elements as the vector
19574 operand. The fourth operand is the explicit vector length of the operation.
19579 The '``llvm.vp.reduce.smax``' intrinsic performs the signed-integer ``MAX``
19580 reduction (:ref:`llvm.vector.reduce.smax <int_vector_reduce_smax>`) of the
19581 vector operand ``val`` on each enabled lane, and taking the maximum of that and
19582 the scalar ``start_value``. Disabled lanes are treated as containing the
19583 neutral value ``INT_MIN`` (i.e. having no effect on the reduction operation).
19584 If the vector length is zero, the result is the start value.
19586 To ignore the start value, the neutral value can be used.
19591 .. code-block:: llvm
19593 %r = call i8 @llvm.vp.reduce.smax.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl)
19594 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19595 ; are treated as though %mask were false for those lanes.
19597 %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 -128, i8 -128, i8 -128, i8 -128>
19598 %reduction = call i8 @llvm.vector.reduce.smax.v4i8(<4 x i8> %masked.a)
19599 %also.r = call i8 @llvm.smax.i8(i8 %reduction, i8 %start)
19602 .. _int_vp_reduce_smin:
19604 '``llvm.vp.reduce.smin.*``' Intrinsics
19605 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19609 This is an overloaded intrinsic.
19613 declare i32 @llvm.vp.reduce.smin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19614 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>)
19619 Predicated signed-integer ``MIN`` reduction of a vector and a scalar starting
19620 value, returning the result as a scalar.
19626 The first operand is the start value of the reduction, which must be a scalar
19627 integer type equal to the result type. The second operand is the vector on
19628 which the reduction is performed and must be a vector of integer values whose
19629 element type is the result/start type. The third operand is the vector mask and
19630 is a vector of boolean values with the same number of elements as the vector
19631 operand. The fourth operand is the explicit vector length of the operation.
19636 The '``llvm.vp.reduce.smin``' intrinsic performs the signed-integer ``MIN``
19637 reduction (:ref:`llvm.vector.reduce.smin <int_vector_reduce_smin>`) of the
19638 vector operand ``val`` on each enabled lane, and taking the minimum of that and
19639 the scalar ``start_value``. Disabled lanes are treated as containing the
19640 neutral value ``INT_MAX`` (i.e. having no effect on the reduction operation).
19641 If the vector length is zero, the result is the start value.
19643 To ignore the start value, the neutral value can be used.
19648 .. code-block:: llvm
19650 %r = call i8 @llvm.vp.reduce.smin.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl)
19651 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19652 ; are treated as though %mask were false for those lanes.
19654 %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 127, i8 127, i8 127, i8 127>
19655 %reduction = call i8 @llvm.vector.reduce.smin.v4i8(<4 x i8> %masked.a)
19656 %also.r = call i8 @llvm.smin.i8(i8 %reduction, i8 %start)
19659 .. _int_vp_reduce_umax:
19661 '``llvm.vp.reduce.umax.*``' Intrinsics
19662 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19666 This is an overloaded intrinsic.
19670 declare i32 @llvm.vp.reduce.umax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19671 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>)
19676 Predicated unsigned-integer ``MAX`` reduction of a vector and a scalar starting
19677 value, returning the result as a scalar.
19683 The first operand is the start value of the reduction, which must be a scalar
19684 integer type equal to the result type. The second operand is the vector on
19685 which the reduction is performed and must be a vector of integer values whose
19686 element type is the result/start type. The third operand is the vector mask and
19687 is a vector of boolean values with the same number of elements as the vector
19688 operand. The fourth operand is the explicit vector length of the operation.
19693 The '``llvm.vp.reduce.umax``' intrinsic performs the unsigned-integer ``MAX``
19694 reduction (:ref:`llvm.vector.reduce.umax <int_vector_reduce_umax>`) of the
19695 vector operand ``val`` on each enabled lane, and taking the maximum of that and
19696 the scalar ``start_value``. Disabled lanes are treated as containing the
19697 neutral value ``0`` (i.e. having no effect on the reduction operation). If the
19698 vector length is zero, the result is the start value.
19700 To ignore the start value, the neutral value can be used.
19705 .. code-block:: llvm
19707 %r = call i32 @llvm.vp.reduce.umax.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19708 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19709 ; are treated as though %mask were false for those lanes.
19711 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
19712 %reduction = call i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %masked.a)
19713 %also.r = call i32 @llvm.umax.i32(i32 %reduction, i32 %start)
19716 .. _int_vp_reduce_umin:
19718 '``llvm.vp.reduce.umin.*``' Intrinsics
19719 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19723 This is an overloaded intrinsic.
19727 declare i32 @llvm.vp.reduce.umin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>)
19728 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>)
19733 Predicated unsigned-integer ``MIN`` reduction of a vector and a scalar starting
19734 value, returning the result as a scalar.
19740 The first operand is the start value of the reduction, which must be a scalar
19741 integer type equal to the result type. The second operand is the vector on
19742 which the reduction is performed and must be a vector of integer values whose
19743 element type is the result/start type. The third operand is the vector mask and
19744 is a vector of boolean values with the same number of elements as the vector
19745 operand. The fourth operand is the explicit vector length of the operation.
19750 The '``llvm.vp.reduce.umin``' intrinsic performs the unsigned-integer ``MIN``
19751 reduction (:ref:`llvm.vector.reduce.umin <int_vector_reduce_umin>`) of the
19752 vector operand ``val`` on each enabled lane, taking the minimum of that and the
19753 scalar ``start_value``. Disabled lanes are treated as containing the neutral
19754 value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction
19755 operation). If the vector length is zero, the result is the start value.
19757 To ignore the start value, the neutral value can be used.
19762 .. code-block:: llvm
19764 %r = call i32 @llvm.vp.reduce.umin.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl)
19765 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19766 ; are treated as though %mask were false for those lanes.
19768 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
19769 %reduction = call i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %masked.a)
19770 %also.r = call i32 @llvm.umin.i32(i32 %reduction, i32 %start)
19773 .. _int_vp_reduce_fmax:
19775 '``llvm.vp.reduce.fmax.*``' Intrinsics
19776 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19780 This is an overloaded intrinsic.
19784 declare float @llvm.vp.reduce.fmax.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>)
19785 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>)
19790 Predicated floating-point ``MAX`` reduction of a vector and a scalar starting
19791 value, returning the result as a scalar.
19797 The first operand is the start value of the reduction, which must be a scalar
19798 floating-point type equal to the result type. The second operand is the vector
19799 on which the reduction is performed and must be a vector of floating-point
19800 values whose element type is the result/start type. The third operand is the
19801 vector mask and is a vector of boolean values with the same number of elements
19802 as the vector operand. The fourth operand is the explicit vector length of the
19808 The '``llvm.vp.reduce.fmax``' intrinsic performs the floating-point ``MAX``
19809 reduction (:ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>`) of the
19810 vector operand ``val`` on each enabled lane, taking the maximum of that and the
19811 scalar ``start_value``. Disabled lanes are treated as containing the neutral
19812 value (i.e. having no effect on the reduction operation). If the vector length
19813 is zero, the result is the start value.
19815 The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
19816 flags are set, the neutral value is ``-QNAN``. If ``nnan`` and ``ninf`` are
19817 both set, then the neutral value is the smallest floating-point value for the
19818 result type. If only ``nnan`` is set then the neutral value is ``-Infinity``.
19820 This instruction has the same comparison semantics as the
19821 :ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>` intrinsic (and thus the
19822 '``llvm.maxnum.*``' intrinsic). That is, the result will always be a number
19823 unless all elements of the vector and the starting value are ``NaN``. For a
19824 vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and
19825 ``-0.0`` elements, the sign of the result is unspecified.
19827 To ignore the start value, the neutral value can be used.
19832 .. code-block:: llvm
19834 %r = call float @llvm.vp.reduce.fmax.v4f32(float %float, <4 x float> %a, <4 x i1> %mask, i32 %evl)
19835 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19836 ; are treated as though %mask were false for those lanes.
19838 %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN>
19839 %reduction = call float @llvm.vector.reduce.fmax.v4f32(<4 x float> %masked.a)
19840 %also.r = call float @llvm.maxnum.f32(float %reduction, float %start)
19843 .. _int_vp_reduce_fmin:
19845 '``llvm.vp.reduce.fmin.*``' Intrinsics
19846 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19850 This is an overloaded intrinsic.
19854 declare float @llvm.vp.reduce.fmin.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>)
19855 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>)
19860 Predicated floating-point ``MIN`` reduction of a vector and a scalar starting
19861 value, returning the result as a scalar.
19867 The first operand is the start value of the reduction, which must be a scalar
19868 floating-point type equal to the result type. The second operand is the vector
19869 on which the reduction is performed and must be a vector of floating-point
19870 values whose element type is the result/start type. The third operand is the
19871 vector mask and is a vector of boolean values with the same number of elements
19872 as the vector operand. The fourth operand is the explicit vector length of the
19878 The '``llvm.vp.reduce.fmin``' intrinsic performs the floating-point ``MIN``
19879 reduction (:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>`) of the
19880 vector operand ``val`` on each enabled lane, taking the minimum of that and the
19881 scalar ``start_value``. Disabled lanes are treated as containing the neutral
19882 value (i.e. having no effect on the reduction operation). If the vector length
19883 is zero, the result is the start value.
19885 The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no
19886 flags are set, the neutral value is ``+QNAN``. If ``nnan`` and ``ninf`` are
19887 both set, then the neutral value is the largest floating-point value for the
19888 result type. If only ``nnan`` is set then the neutral value is ``+Infinity``.
19890 This instruction has the same comparison semantics as the
19891 :ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>` intrinsic (and thus the
19892 '``llvm.minnum.*``' intrinsic). That is, the result will always be a number
19893 unless all elements of the vector and the starting value are ``NaN``. For a
19894 vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and
19895 ``-0.0`` elements, the sign of the result is unspecified.
19897 To ignore the start value, the neutral value can be used.
19902 .. code-block:: llvm
19904 %r = call float @llvm.vp.reduce.fmin.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl)
19905 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl
19906 ; are treated as though %mask were false for those lanes.
19908 %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN>
19909 %reduction = call float @llvm.vector.reduce.fmin.v4f32(<4 x float> %masked.a)
19910 %also.r = call float @llvm.minnum.f32(float %reduction, float %start)
19913 .. _int_get_active_lane_mask:
19915 '``llvm.get.active.lane.mask.*``' Intrinsics
19916 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19920 This is an overloaded intrinsic.
19924 declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %base, i32 %n)
19925 declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 %base, i64 %n)
19926 declare <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 %base, i64 %n)
19927 declare <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 %base, i64 %n)
19933 Create a mask representing active and inactive vector lanes.
19939 Both operands have the same scalar integer type. The result is a vector with
19940 the i1 element type.
19945 The '``llvm.get.active.lane.mask.*``' intrinsics are semantically equivalent
19950 %m[i] = icmp ult (%base + i), %n
19952 where ``%m`` is a vector (mask) of active/inactive lanes with its elements
19953 indexed by ``i``, and ``%base``, ``%n`` are the two arguments to
19954 ``llvm.get.active.lane.mask.*``, ``%icmp`` is an integer compare and ``ult``
19955 the unsigned less-than comparison operator. Overflow cannot occur in
19956 ``(%base + i)`` and its comparison against ``%n`` as it is performed in integer
19957 numbers and not in machine numbers. If ``%n`` is ``0``, then the result is a
19958 poison value. The above is equivalent to:
19962 %m = @llvm.get.active.lane.mask(%base, %n)
19964 This can, for example, be emitted by the loop vectorizer in which case
19965 ``%base`` is the first element of the vector induction variable (VIV) and
19966 ``%n`` is the loop tripcount. Thus, these intrinsics perform an element-wise
19967 less than comparison of VIV with the loop tripcount, producing a mask of
19968 true/false values representing active/inactive vector lanes, except if the VIV
19969 overflows in which case they return false in the lanes where the VIV overflows.
19970 The arguments are scalar types to accommodate scalable vector types, for which
19971 it is unknown what the type of the step vector needs to be that enumerate its
19972 lanes without overflow.
19974 This mask ``%m`` can e.g. be used in masked load/store instructions. These
19975 intrinsics provide a hint to the backend. I.e., for a vector loop, the
19976 back-edge taken count of the original scalar loop is explicit as the second
19983 .. code-block:: llvm
19985 %active.lane.mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 %elem0, i64 429)
19986 %wide.masked.load = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %3, i32 4, <4 x i1> %active.lane.mask, <4 x i32> undef)
19989 .. _int_experimental_vp_splice:
19991 '``llvm.experimental.vp.splice``' Intrinsic
19992 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19996 This is an overloaded intrinsic.
20000 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)
20001 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)
20006 The '``llvm.experimental.vp.splice.*``' intrinsic is the vector length
20007 predicated version of the '``llvm.experimental.vector.splice.*``' intrinsic.
20012 The result and the first two arguments ``vec1`` and ``vec2`` are vectors with
20013 the same type. The third argument ``imm`` is an immediate signed integer that
20014 indicates the offset index. The fourth argument ``mask`` is a vector mask and
20015 has the same number of elements as the result. The last two arguments ``evl1``
20016 and ``evl2`` are unsigned integers indicating the explicit vector lengths of
20017 ``vec1`` and ``vec2`` respectively. ``imm``, ``evl1`` and ``evl2`` should
20018 respect the following constraints: ``-evl1 <= imm < evl1``, ``0 <= evl1 <= VL``
20019 and ``0 <= evl2 <= VL``, where ``VL`` is the runtime vector factor. If these
20020 constraints are not satisfied the intrinsic has undefined behaviour.
20025 Effectively, this intrinsic concatenates ``vec1[0..evl1-1]`` and
20026 ``vec2[0..evl2-1]`` and creates the result vector by selecting the elements in a
20027 window of size ``evl2``, starting at index ``imm`` (for a positive immediate) of
20028 the concatenated vector. Elements in the result vector beyond ``evl2`` are
20029 ``undef``. If ``imm`` is negative the starting index is ``evl1 + imm``. The result
20030 vector of active vector length ``evl2`` contains ``evl1 - imm`` (``-imm`` for
20031 negative ``imm``) elements from indices ``[imm..evl1 - 1]``
20032 (``[evl1 + imm..evl1 -1]`` for negative ``imm``) of ``vec1`` followed by the
20033 first ``evl2 - (evl1 - imm)`` (``evl2 + imm`` for negative ``imm``) elements of
20034 ``vec2``. If ``evl1 - imm`` (``-imm``) >= ``evl2``, only the first ``evl2``
20035 elements are considered and the remaining are ``undef``. The lanes in the result
20036 vector disabled by ``mask`` are ``undef``.
20041 .. code-block:: text
20043 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, 1, 2, 3) ==> <B, E, F, undef> ; index
20044 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, -2, 3, 2) ==> <B, C, undef, undef> ; trailing elements
20049 '``llvm.vp.load``' Intrinsic
20050 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20054 This is an overloaded intrinsic.
20058 declare <4 x float> @llvm.vp.load.v4f32.p0(ptr %ptr, <4 x i1> %mask, i32 %evl)
20059 declare <vscale x 2 x i16> @llvm.vp.load.nxv2i16.p0(ptr %ptr, <vscale x 2 x i1> %mask, i32 %evl)
20060 declare <8 x float> @llvm.vp.load.v8f32.p1(ptr addrspace(1) %ptr, <8 x i1> %mask, i32 %evl)
20061 declare <vscale x 1 x i64> @llvm.vp.load.nxv1i64.p6(ptr addrspace(6) %ptr, <vscale x 1 x i1> %mask, i32 %evl)
20066 The '``llvm.vp.load.*``' intrinsic is the vector length predicated version of
20067 the :ref:`llvm.masked.load <int_mload>` intrinsic.
20072 The first operand is the base pointer for the load. The second operand is a
20073 vector of boolean values with the same number of elements as the return type.
20074 The third is the explicit vector length of the operation. The return type and
20075 underlying type of the base pointer are the same vector types.
20077 The :ref:`align <attr_align>` parameter attribute can be provided for the first
20083 The '``llvm.vp.load``' intrinsic reads a vector from memory in the same way as
20084 the '``llvm.masked.load``' intrinsic, where the mask is taken from the
20085 combination of the '``mask``' and '``evl``' operands in the usual VP way.
20086 Certain '``llvm.masked.load``' operands do not have corresponding operands in
20087 '``llvm.vp.load``': the '``passthru``' operand is implicitly ``undef``; the
20088 '``alignment``' operand is taken as the ``align`` parameter attribute, if
20089 provided. The default alignment is taken as the ABI alignment of the return
20090 type as specified by the :ref:`datalayout string<langref_datalayout>`.
20095 .. code-block:: text
20097 %r = call <8 x i8> @llvm.vp.load.v8i8.p0(ptr align 2 %ptr, <8 x i1> %mask, i32 %evl)
20098 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20100 %also.r = call <8 x i8> @llvm.masked.load.v8i8.p0(ptr %ptr, i32 2, <8 x i1> %mask, <8 x i8> undef)
20105 '``llvm.vp.store``' Intrinsic
20106 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20110 This is an overloaded intrinsic.
20114 declare void @llvm.vp.store.v4f32.p0(<4 x float> %val, ptr %ptr, <4 x i1> %mask, i32 %evl)
20115 declare void @llvm.vp.store.nxv2i16.p0(<vscale x 2 x i16> %val, ptr %ptr, <vscale x 2 x i1> %mask, i32 %evl)
20116 declare void @llvm.vp.store.v8f32.p1(<8 x float> %val, ptr addrspace(1) %ptr, <8 x i1> %mask, i32 %evl)
20117 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)
20122 The '``llvm.vp.store.*``' intrinsic is the vector length predicated version of
20123 the :ref:`llvm.masked.store <int_mstore>` intrinsic.
20128 The first operand is the vector value to be written to memory. The second
20129 operand is the base pointer for the store. It has the same underlying type as
20130 the value operand. The third operand is a vector of boolean values with the
20131 same number of elements as the return type. The fourth is the explicit vector
20132 length of the operation.
20134 The :ref:`align <attr_align>` parameter attribute can be provided for the
20140 The '``llvm.vp.store``' intrinsic reads a vector from memory in the same way as
20141 the '``llvm.masked.store``' intrinsic, where the mask is taken from the
20142 combination of the '``mask``' and '``evl``' operands in the usual VP way. The
20143 alignment of the operation (corresponding to the '``alignment``' operand of
20144 '``llvm.masked.store``') is specified by the ``align`` parameter attribute (see
20145 above). If it is not provided then the ABI alignment of the type of the
20146 '``value``' operand as specified by the :ref:`datalayout
20147 string<langref_datalayout>` is used instead.
20152 .. code-block:: text
20154 call void @llvm.vp.store.v8i8.p0(<8 x i8> %val, ptr align 4 %ptr, <8 x i1> %mask, i32 %evl)
20155 ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below.
20157 call void @llvm.masked.store.v8i8.p0(<8 x i8> %val, ptr %ptr, i32 4, <8 x i1> %mask)
20160 .. _int_experimental_vp_strided_load:
20162 '``llvm.experimental.vp.strided.load``' Intrinsic
20163 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20167 This is an overloaded intrinsic.
20171 declare <4 x float> @llvm.experimental.vp.strided.load.v4f32.i64(ptr %ptr, i64 %stride, <4 x i1> %mask, i32 %evl)
20172 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)
20177 The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, scalar values from
20178 memory locations evenly spaced apart by '``stride``' number of bytes, starting from '``ptr``'.
20183 The first operand is the base pointer for the load. The second operand is the stride
20184 value expressed in bytes. The third operand is a vector of boolean values
20185 with the same number of elements as the return type. The fourth is the explicit
20186 vector length of the operation. The base pointer underlying type matches the type of the scalar
20187 elements of the return operand.
20189 The :ref:`align <attr_align>` parameter attribute can be provided for the first
20195 The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, multiple scalar
20196 values from memory in the same way as the :ref:`llvm.vp.gather <int_vp_gather>` intrinsic,
20197 where the vector of pointers is in the form:
20199 ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``,
20201 with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed
20202 integer and all arithmetic occurring in the pointer type.
20207 .. code-block:: text
20209 %r = call <8 x i64> @llvm.experimental.vp.strided.load.v8i64.i64(i64* %ptr, i64 %stride, <8 x i64> %mask, i32 %evl)
20210 ;; The operation can also be expressed like this:
20212 %addr = bitcast i64* %ptr to i8*
20213 ;; Create a vector of pointers %addrs in the form:
20214 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...>
20215 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* >
20216 %also.r = call <8 x i64> @llvm.vp.gather.v8i64.v8p0i64(<8 x i64* > %ptrs, <8 x i64> %mask, i32 %evl)
20219 .. _int_experimental_vp_strided_store:
20221 '``llvm.experimental.vp.strided.store``' Intrinsic
20222 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20226 This is an overloaded intrinsic.
20230 declare void @llvm.experimental.vp.strided.store.v4f32.i64(<4 x float> %val, ptr %ptr, i64 %stride, <4 x i1> %mask, i32 %evl)
20231 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)
20236 The '``@llvm.experimental.vp.strided.store``' intrinsic stores the elements of
20237 '``val``' into memory locations evenly spaced apart by '``stride``' number of
20238 bytes, starting from '``ptr``'.
20243 The first operand is the vector value to be written to memory. The second
20244 operand is the base pointer for the store. Its underlying type matches the
20245 scalar element type of the value operand. The third operand is the stride value
20246 expressed in bytes. The fourth operand is a vector of boolean values with the
20247 same number of elements as the return type. The fifth is the explicit vector
20248 length of the operation.
20250 The :ref:`align <attr_align>` parameter attribute can be provided for the
20256 The '``llvm.experimental.vp.strided.store``' intrinsic stores the elements of
20257 '``val``' in the same way as the :ref:`llvm.vp.scatter <int_vp_scatter>` intrinsic,
20258 where the vector of pointers is in the form:
20260 ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``,
20262 with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed
20263 integer and all arithmetic occurring in the pointer type.
20268 .. code-block:: text
20270 call void @llvm.experimental.vp.strided.store.v8i64.i64(<8 x i64> %val, i64* %ptr, i64 %stride, <8 x i1> %mask, i32 %evl)
20271 ;; The operation can also be expressed like this:
20273 %addr = bitcast i64* %ptr to i8*
20274 ;; Create a vector of pointers %addrs in the form:
20275 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...>
20276 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* >
20277 call void @llvm.vp.scatter.v8i64.v8p0i64(<8 x i64> %val, <8 x i64*> %ptrs, <8 x i1> %mask, i32 %evl)
20282 '``llvm.vp.gather``' Intrinsic
20283 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20287 This is an overloaded intrinsic.
20291 declare <4 x double> @llvm.vp.gather.v4f64.v4p0(<4 x ptr> %ptrs, <4 x i1> %mask, i32 %evl)
20292 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)
20293 declare <2 x float> @llvm.vp.gather.v2f32.v2p2(<2 x ptr addrspace(2)> %ptrs, <2 x i1> %mask, i32 %evl)
20294 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)
20299 The '``llvm.vp.gather.*``' intrinsic is the vector length predicated version of
20300 the :ref:`llvm.masked.gather <int_mgather>` intrinsic.
20305 The first operand is a vector of pointers which holds all memory addresses to
20306 read. The second operand is a vector of boolean values with the same number of
20307 elements as the return type. The third is the explicit vector length of the
20308 operation. The return type and underlying type of the vector of pointers are
20309 the same vector types.
20311 The :ref:`align <attr_align>` parameter attribute can be provided for the first
20317 The '``llvm.vp.gather``' intrinsic reads multiple scalar values from memory in
20318 the same way as the '``llvm.masked.gather``' intrinsic, where the mask is taken
20319 from the combination of the '``mask``' and '``evl``' operands in the usual VP
20320 way. Certain '``llvm.masked.gather``' operands do not have corresponding
20321 operands in '``llvm.vp.gather``': the '``passthru``' operand is implicitly
20322 ``undef``; the '``alignment``' operand is taken as the ``align`` parameter, if
20323 provided. The default alignment is taken as the ABI alignment of the source
20324 addresses as specified by the :ref:`datalayout string<langref_datalayout>`.
20329 .. code-block:: text
20331 %r = call <8 x i8> @llvm.vp.gather.v8i8.v8p0(<8 x ptr> align 8 %ptrs, <8 x i1> %mask, i32 %evl)
20332 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20334 %also.r = call <8 x i8> @llvm.masked.gather.v8i8.v8p0(<8 x ptr> %ptrs, i32 8, <8 x i1> %mask, <8 x i8> undef)
20337 .. _int_vp_scatter:
20339 '``llvm.vp.scatter``' Intrinsic
20340 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20344 This is an overloaded intrinsic.
20348 declare void @llvm.vp.scatter.v4f64.v4p0(<4 x double> %val, <4 x ptr> %ptrs, <4 x i1> %mask, i32 %evl)
20349 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)
20350 declare void @llvm.vp.scatter.v2f32.v2p2(<2 x float> %val, <2 x ptr addrspace(2)> %ptrs, <2 x i1> %mask, i32 %evl)
20351 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)
20356 The '``llvm.vp.scatter.*``' intrinsic is the vector length predicated version of
20357 the :ref:`llvm.masked.scatter <int_mscatter>` intrinsic.
20362 The first operand is a vector value to be written to memory. The second operand
20363 is a vector of pointers, pointing to where the value elements should be stored.
20364 The third operand is a vector of boolean values with the same number of
20365 elements as the return type. The fourth is the explicit vector length of the
20368 The :ref:`align <attr_align>` parameter attribute can be provided for the
20374 The '``llvm.vp.scatter``' intrinsic writes multiple scalar values to memory in
20375 the same way as the '``llvm.masked.scatter``' intrinsic, where the mask is
20376 taken from the combination of the '``mask``' and '``evl``' operands in the
20377 usual VP way. The '``alignment``' operand of the '``llvm.masked.scatter``' does
20378 not have a corresponding operand in '``llvm.vp.scatter``': it is instead
20379 provided via the optional ``align`` parameter attribute on the
20380 vector-of-pointers operand. Otherwise it is taken as the ABI alignment of the
20381 destination addresses as specified by the :ref:`datalayout
20382 string<langref_datalayout>`.
20387 .. code-block:: text
20389 call void @llvm.vp.scatter.v8i8.v8p0(<8 x i8> %val, <8 x ptr> align 1 %ptrs, <8 x i1> %mask, i32 %evl)
20390 ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below.
20392 call void @llvm.masked.scatter.v8i8.v8p0(<8 x i8> %val, <8 x ptr> %ptrs, i32 1, <8 x i1> %mask)
20397 '``llvm.vp.trunc.*``' Intrinsics
20398 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20402 This is an overloaded intrinsic.
20406 declare <16 x i16> @llvm.vp.trunc.v16i16.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
20407 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>)
20412 The '``llvm.vp.trunc``' intrinsic truncates its first operand to the return
20413 type. The operation has a mask and an explicit vector length parameter.
20419 The '``llvm.vp.trunc``' intrinsic takes a value to cast as its first operand.
20420 The return type is the type to cast the value to. Both types must be vector of
20421 :ref:`integer <t_integer>` type. The bit size of the value must be larger than
20422 the bit size of the return type. The second operand is the vector mask. The
20423 return type, the value to cast, and the vector mask have the same number of
20424 elements. The third operand is the explicit vector length of the operation.
20429 The '``llvm.vp.trunc``' intrinsic truncates the high order bits in value and
20430 converts the remaining bits to return type. Since the source size must be larger
20431 than the destination size, '``llvm.vp.trunc``' cannot be a *no-op cast*. It will
20432 always truncate bits. The conversion is performed on lane positions below the
20433 explicit vector length and where the vector mask is true. Masked-off lanes are
20439 .. code-block:: llvm
20441 %r = call <4 x i16> @llvm.vp.trunc.v4i16.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
20442 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20444 %t = trunc <4 x i32> %a to <4 x i16>
20445 %also.r = select <4 x i1> %mask, <4 x i16> %t, <4 x i16> undef
20450 '``llvm.vp.zext.*``' Intrinsics
20451 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20455 This is an overloaded intrinsic.
20459 declare <16 x i32> @llvm.vp.zext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>)
20460 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>)
20465 The '``llvm.vp.zext``' intrinsic zero extends its first operand to the return
20466 type. The operation has a mask and an explicit vector length parameter.
20472 The '``llvm.vp.zext``' intrinsic takes a value to cast as its first operand.
20473 The return type is the type to cast the value to. Both types must be vectors of
20474 :ref:`integer <t_integer>` type. The bit size of the value must be smaller than
20475 the bit size of the return type. The second operand is the vector mask. The
20476 return type, the value to cast, and the vector mask have the same number of
20477 elements. The third operand is the explicit vector length of the operation.
20482 The '``llvm.vp.zext``' intrinsic fill the high order bits of the value with zero
20483 bits until it reaches the size of the return type. When zero extending from i1,
20484 the result will always be either 0 or 1. The conversion is performed on lane
20485 positions below the explicit vector length and where the vector mask is true.
20486 Masked-off lanes are undefined.
20491 .. code-block:: llvm
20493 %r = call <4 x i32> @llvm.vp.zext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl)
20494 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20496 %t = zext <4 x i16> %a to <4 x i32>
20497 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
20502 '``llvm.vp.sext.*``' Intrinsics
20503 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20507 This is an overloaded intrinsic.
20511 declare <16 x i32> @llvm.vp.sext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>)
20512 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>)
20517 The '``llvm.vp.sext``' intrinsic sign extends its first operand to the return
20518 type. The operation has a mask and an explicit vector length parameter.
20524 The '``llvm.vp.sext``' intrinsic takes a value to cast as its first operand.
20525 The return type is the type to cast the value to. Both types must be vectors of
20526 :ref:`integer <t_integer>` type. The bit size of the value must be smaller than
20527 the bit size of the return type. The second operand is the vector mask. The
20528 return type, the value to cast, and the vector mask have the same number of
20529 elements. The third operand is the explicit vector length of the operation.
20534 The '``llvm.vp.sext``' intrinsic performs a sign extension by copying the sign
20535 bit (highest order bit) of the value until it reaches the size of the return
20536 type. When sign extending from i1, the result will always be either -1 or 0.
20537 The conversion is performed on lane positions below the explicit vector length
20538 and where the vector mask is true. Masked-off lanes are undefined.
20543 .. code-block:: llvm
20545 %r = call <4 x i32> @llvm.vp.sext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl)
20546 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20548 %t = sext <4 x i16> %a to <4 x i32>
20549 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
20552 .. _int_vp_fptrunc:
20554 '``llvm.vp.fptrunc.*``' Intrinsics
20555 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20559 This is an overloaded intrinsic.
20563 declare <16 x float> @llvm.vp.fptrunc.v16f32.v16f64 (<16 x double> <op>, <16 x i1> <mask>, i32 <vector_length>)
20564 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>)
20569 The '``llvm.vp.fptrunc``' intrinsic truncates its first operand to the return
20570 type. The operation has a mask and an explicit vector length parameter.
20576 The '``llvm.vp.fptrunc``' intrinsic takes a value to cast as its first operand.
20577 The return type is the type to cast the value to. Both types must be vector of
20578 :ref:`floating-point <t_floating>` type. The bit size of the value must be
20579 larger than the bit size of the return type. This implies that
20580 '``llvm.vp.fptrunc``' cannot be used to make a *no-op cast*. The second operand
20581 is the vector mask. The return type, the value to cast, and the vector mask have
20582 the same number of elements. The third operand is the explicit vector length of
20588 The '``llvm.vp.fptrunc``' intrinsic casts a ``value`` from a larger
20589 :ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
20590 <t_floating>` type.
20591 This instruction is assumed to execute in the default :ref:`floating-point
20592 environment <floatenv>`. The conversion is performed on lane positions below the
20593 explicit vector length and where the vector mask is true. Masked-off lanes are
20599 .. code-block:: llvm
20601 %r = call <4 x float> @llvm.vp.fptrunc.v4f32.v4f64(<4 x double> %a, <4 x i1> %mask, i32 %evl)
20602 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20604 %t = fptrunc <4 x double> %a to <4 x float>
20605 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
20610 '``llvm.vp.fpext.*``' Intrinsics
20611 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20615 This is an overloaded intrinsic.
20619 declare <16 x double> @llvm.vp.fpext.v16f64.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
20620 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>)
20625 The '``llvm.vp.fpext``' intrinsic extends its first operand to the return
20626 type. The operation has a mask and an explicit vector length parameter.
20632 The '``llvm.vp.fpext``' intrinsic takes a value to cast as its first operand.
20633 The return type is the type to cast the value to. Both types must be vector of
20634 :ref:`floating-point <t_floating>` type. The bit size of the value must be
20635 smaller than the bit size of the return type. This implies that
20636 '``llvm.vp.fpext``' cannot be used to make a *no-op cast*. The second operand
20637 is the vector mask. The return type, the value to cast, and the vector mask have
20638 the same number of elements. The third operand is the explicit vector length of
20644 The '``llvm.vp.fpext``' intrinsic extends the ``value`` from a smaller
20645 :ref:`floating-point <t_floating>` type to a larger :ref:`floating-point
20646 <t_floating>` type. The '``llvm.vp.fpext``' cannot be used to make a
20647 *no-op cast* because it always changes bits. Use ``bitcast`` to make a
20648 *no-op cast* for a floating-point cast.
20649 The conversion is performed on lane positions below the explicit vector length
20650 and where the vector mask is true. Masked-off lanes are undefined.
20655 .. code-block:: llvm
20657 %r = call <4 x double> @llvm.vp.fpext.v4f64.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
20658 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20660 %t = fpext <4 x float> %a to <4 x double>
20661 %also.r = select <4 x i1> %mask, <4 x double> %t, <4 x double> undef
20666 '``llvm.vp.fptoui.*``' Intrinsics
20667 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20671 This is an overloaded intrinsic.
20675 declare <16 x i32> @llvm.vp.fptoui.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
20676 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>)
20677 declare <256 x i64> @llvm.vp.fptoui.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
20682 The '``llvm.vp.fptoui``' intrinsic converts the :ref:`floating-point
20683 <t_floating>` operand to the unsigned integer return type.
20684 The operation has a mask and an explicit vector length parameter.
20690 The '``llvm.vp.fptoui``' intrinsic takes a value to cast as its first operand.
20691 The value to cast must be a vector of :ref:`floating-point <t_floating>` type.
20692 The return type is the type to cast the value to. The return type must be
20693 vector of :ref:`integer <t_integer>` type. The second operand is the vector
20694 mask. The return type, the value to cast, and the vector mask have the same
20695 number of elements. The third operand is the explicit vector length of the
20701 The '``llvm.vp.fptoui``' intrinsic converts its :ref:`floating-point
20702 <t_floating>` operand into the nearest (rounding towards zero) unsigned integer
20703 value where the lane position is below the explicit vector length and the
20704 vector mask is true. Masked-off lanes are undefined. On enabled lanes where
20705 conversion takes place and the value cannot fit in the return type, the result
20706 on that lane is a :ref:`poison value <poisonvalues>`.
20711 .. code-block:: llvm
20713 %r = call <4 x i32> @llvm.vp.fptoui.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
20714 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20716 %t = fptoui <4 x float> %a to <4 x i32>
20717 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
20722 '``llvm.vp.fptosi.*``' Intrinsics
20723 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20727 This is an overloaded intrinsic.
20731 declare <16 x i32> @llvm.vp.fptosi.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>)
20732 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>)
20733 declare <256 x i64> @llvm.vp.fptosi.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>)
20738 The '``llvm.vp.fptosi``' intrinsic converts the :ref:`floating-point
20739 <t_floating>` operand to the signed integer return type.
20740 The operation has a mask and an explicit vector length parameter.
20746 The '``llvm.vp.fptosi``' intrinsic takes a value to cast as its first operand.
20747 The value to cast must be a vector of :ref:`floating-point <t_floating>` type.
20748 The return type is the type to cast the value to. The return type must be
20749 vector of :ref:`integer <t_integer>` type. The second operand is the vector
20750 mask. The return type, the value to cast, and the vector mask have the same
20751 number of elements. The third operand is the explicit vector length of the
20757 The '``llvm.vp.fptosi``' intrinsic converts its :ref:`floating-point
20758 <t_floating>` operand into the nearest (rounding towards zero) signed integer
20759 value where the lane position is below the explicit vector length and the
20760 vector mask is true. Masked-off lanes are undefined. On enabled lanes where
20761 conversion takes place and the value cannot fit in the return type, the result
20762 on that lane is a :ref:`poison value <poisonvalues>`.
20767 .. code-block:: llvm
20769 %r = call <4 x i32> @llvm.vp.fptosi.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl)
20770 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20772 %t = fptosi <4 x float> %a to <4 x i32>
20773 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef
20778 '``llvm.vp.uitofp.*``' Intrinsics
20779 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20783 This is an overloaded intrinsic.
20787 declare <16 x float> @llvm.vp.uitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
20788 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>)
20789 declare <256 x double> @llvm.vp.uitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
20794 The '``llvm.vp.uitofp``' intrinsic converts its unsigned integer operand to the
20795 :ref:`floating-point <t_floating>` return type. The operation has a mask and
20796 an explicit vector length parameter.
20802 The '``llvm.vp.uitofp``' intrinsic takes a value to cast as its first operand.
20803 The value to cast must be vector of :ref:`integer <t_integer>` type. The
20804 return type is the type to cast the value to. The return type must be a vector
20805 of :ref:`floating-point <t_floating>` type. The second operand is the vector
20806 mask. The return type, the value to cast, and the vector mask have the same
20807 number of elements. The third operand is the explicit vector length of the
20813 The '``llvm.vp.uitofp``' intrinsic interprets its first operand as an unsigned
20814 integer quantity and converts it to the corresponding floating-point value. If
20815 the value cannot be exactly represented, it is rounded using the default
20816 rounding mode. The conversion is performed on lane positions below the
20817 explicit vector length and where the vector mask is true. Masked-off lanes are
20823 .. code-block:: llvm
20825 %r = call <4 x float> @llvm.vp.uitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
20826 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20828 %t = uitofp <4 x i32> %a to <4 x float>
20829 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
20834 '``llvm.vp.sitofp.*``' Intrinsics
20835 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20839 This is an overloaded intrinsic.
20843 declare <16 x float> @llvm.vp.sitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
20844 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>)
20845 declare <256 x double> @llvm.vp.sitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>)
20850 The '``llvm.vp.sitofp``' intrinsic converts its signed integer operand to the
20851 :ref:`floating-point <t_floating>` return type. The operation has a mask and
20852 an explicit vector length parameter.
20858 The '``llvm.vp.sitofp``' intrinsic takes a value to cast as its first operand.
20859 The value to cast must be vector of :ref:`integer <t_integer>` type. The
20860 return type is the type to cast the value to. The return type must be a vector
20861 of :ref:`floating-point <t_floating>` type. The second operand is the vector
20862 mask. The return type, the value to cast, and the vector mask have the same
20863 number of elements. The third operand is the explicit vector length of the
20869 The '``llvm.vp.sitofp``' intrinsic interprets its first operand as a signed
20870 integer quantity and converts it to the corresponding floating-point value. If
20871 the value cannot be exactly represented, it is rounded using the default
20872 rounding mode. The conversion is performed on lane positions below the
20873 explicit vector length and where the vector mask is true. Masked-off lanes are
20879 .. code-block:: llvm
20881 %r = call <4 x float> @llvm.vp.sitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
20882 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20884 %t = sitofp <4 x i32> %a to <4 x float>
20885 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef
20888 .. _int_vp_ptrtoint:
20890 '``llvm.vp.ptrtoint.*``' Intrinsics
20891 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20895 This is an overloaded intrinsic.
20899 declare <16 x i8> @llvm.vp.ptrtoint.v16i8.v16p0(<16 x ptr> <op>, <16 x i1> <mask>, i32 <vector_length>)
20900 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>)
20901 declare <256 x i64> @llvm.vp.ptrtoint.v16i64.v16p0(<256 x ptr> <op>, <256 x i1> <mask>, i32 <vector_length>)
20906 The '``llvm.vp.ptrtoint``' intrinsic converts its pointer to the integer return
20907 type. The operation has a mask and an explicit vector length parameter.
20913 The '``llvm.vp.ptrtoint``' intrinsic takes a value to cast as its first operand
20914 , which must be a vector of pointers, and a type to cast it to return type,
20915 which must be a vector of :ref:`integer <t_integer>` type.
20916 The second operand is the vector mask. The return type, the value to cast, and
20917 the vector mask have the same number of elements.
20918 The third operand is the explicit vector length of the operation.
20923 The '``llvm.vp.ptrtoint``' intrinsic converts value to return type by
20924 interpreting the pointer value as an integer and either truncating or zero
20925 extending that value to the size of the integer type.
20926 If ``value`` is smaller than return type, then a zero extension is done. If
20927 ``value`` is larger than return type, then a truncation is done. If they are
20928 the same size, then nothing is done (*no-op cast*) other than a type
20930 The conversion is performed on lane positions below the explicit vector length
20931 and where the vector mask is true. Masked-off lanes are undefined.
20936 .. code-block:: llvm
20938 %r = call <4 x i8> @llvm.vp.ptrtoint.v4i8.v4p0i32(<4 x ptr> %a, <4 x i1> %mask, i32 %evl)
20939 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20941 %t = ptrtoint <4 x ptr> %a to <4 x i8>
20942 %also.r = select <4 x i1> %mask, <4 x i8> %t, <4 x i8> undef
20945 .. _int_vp_inttoptr:
20947 '``llvm.vp.inttoptr.*``' Intrinsics
20948 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20952 This is an overloaded intrinsic.
20956 declare <16 x ptr> @llvm.vp.inttoptr.v16p0.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>)
20957 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>)
20958 declare <256 x ptr> @llvm.vp.inttoptr.v256p0.v256i32 (<256 x i32> <op>, <256 x i1> <mask>, i32 <vector_length>)
20963 The '``llvm.vp.inttoptr``' intrinsic converts its integer value to the point
20964 return type. The operation has a mask and an explicit vector length parameter.
20970 The '``llvm.vp.inttoptr``' intrinsic takes a value to cast as its first operand
20971 , which must be a vector of :ref:`integer <t_integer>` type, and a type to cast
20972 it to return type, which must be a vector of pointers type.
20973 The second operand is the vector mask. The return type, the value to cast, and
20974 the vector mask have the same number of elements.
20975 The third operand is the explicit vector length of the operation.
20980 The '``llvm.vp.inttoptr``' intrinsic converts ``value`` to return type by
20981 applying either a zero extension or a truncation depending on the size of the
20982 integer ``value``. If ``value`` is larger than the size of a pointer, then a
20983 truncation is done. If ``value`` is smaller than the size of a pointer, then a
20984 zero extension is done. If they are the same size, nothing is done (*no-op cast*).
20985 The conversion is performed on lane positions below the explicit vector length
20986 and where the vector mask is true. Masked-off lanes are undefined.
20991 .. code-block:: llvm
20993 %r = call <4 x ptr> @llvm.vp.inttoptr.v4p0i32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl)
20994 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
20996 %t = inttoptr <4 x i32> %a to <4 x ptr>
20997 %also.r = select <4 x i1> %mask, <4 x ptr> %t, <4 x ptr> undef
21002 '``llvm.vp.fcmp.*``' Intrinsics
21003 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21007 This is an overloaded intrinsic.
21011 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>)
21012 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>)
21013 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>)
21018 The '``llvm.vp.fcmp``' intrinsic returns a vector of boolean values based on
21019 the comparison of its operands. The operation has a mask and an explicit vector
21026 The '``llvm.vp.fcmp``' intrinsic takes the two values to compare as its first
21027 and second operands. These two values must be vectors of :ref:`floating-point
21028 <t_floating>` types.
21029 The return type is the result of the comparison. The return type must be a
21030 vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask.
21031 The return type, the values to compare, and the vector mask have the same
21032 number of elements. The third operand is the condition code indicating the kind
21033 of comparison to perform. It must be a metadata string with :ref:`one of the
21034 supported floating-point condition code values <fcmp_md_cc>`. The fifth operand
21035 is the explicit vector length of the operation.
21040 The '``llvm.vp.fcmp``' compares its first two operands according to the
21041 condition code given as the third operand. The operands are compared element by
21042 element on each enabled lane, where the the semantics of the comparison are
21043 defined :ref:`according to the condition code <fcmp_md_cc_sem>`. Masked-off
21044 lanes are undefined.
21049 .. code-block:: llvm
21051 %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)
21052 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21054 %t = fcmp oeq <4 x float> %a, %b
21055 %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> undef
21060 '``llvm.vp.icmp.*``' Intrinsics
21061 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21065 This is an overloaded intrinsic.
21069 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>)
21070 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>)
21071 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>)
21076 The '``llvm.vp.icmp``' intrinsic returns a vector of boolean values based on
21077 the comparison of its operands. The operation has a mask and an explicit vector
21084 The '``llvm.vp.icmp``' intrinsic takes the two values to compare as its first
21085 and second operands. These two values must be vectors of :ref:`integer
21086 <t_integer>` types.
21087 The return type is the result of the comparison. The return type must be a
21088 vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask.
21089 The return type, the values to compare, and the vector mask have the same
21090 number of elements. The third operand is the condition code indicating the kind
21091 of comparison to perform. It must be a metadata string with :ref:`one of the
21092 supported integer condition code values <icmp_md_cc>`. The fifth operand is the
21093 explicit vector length of the operation.
21098 The '``llvm.vp.icmp``' compares its first two operands according to the
21099 condition code given as the third operand. The operands are compared element by
21100 element on each enabled lane, where the the semantics of the comparison are
21101 defined :ref:`according to the condition code <icmp_md_cc_sem>`. Masked-off
21102 lanes are undefined.
21107 .. code-block:: llvm
21109 %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)
21110 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
21112 %t = icmp ne <4 x i32> %a, %b
21113 %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> undef
21116 .. _int_mload_mstore:
21118 Masked Vector Load and Store Intrinsics
21119 ---------------------------------------
21121 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.
21125 '``llvm.masked.load.*``' Intrinsics
21126 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21130 This is an overloaded intrinsic. The loaded data is a vector of any integer, floating-point or pointer data type.
21134 declare <16 x float> @llvm.masked.load.v16f32.p0(ptr <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
21135 declare <2 x double> @llvm.masked.load.v2f64.p0(ptr <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>)
21136 ;; The data is a vector of pointers
21137 declare <8 x ptr> @llvm.masked.load.v8p0.p0(ptr <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x ptr> <passthru>)
21142 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.
21148 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.
21153 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.
21154 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.
21159 %res = call <16 x float> @llvm.masked.load.v16f32.p0(ptr %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru)
21161 ;; The result of the two following instructions is identical aside from potential memory access exception
21162 %loadlal = load <16 x float>, ptr %ptr, align 4
21163 %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru
21167 '``llvm.masked.store.*``' Intrinsics
21168 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21172 This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type.
21176 declare void @llvm.masked.store.v8i32.p0 (<8 x i32> <value>, ptr <ptr>, i32 <alignment>, <8 x i1> <mask>)
21177 declare void @llvm.masked.store.v16f32.p0(<16 x float> <value>, ptr <ptr>, i32 <alignment>, <16 x i1> <mask>)
21178 ;; The data is a vector of pointers
21179 declare void @llvm.masked.store.v8p0.p0 (<8 x ptr> <value>, ptr <ptr>, i32 <alignment>, <8 x i1> <mask>)
21184 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.
21189 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.
21195 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.
21196 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.
21200 call void @llvm.masked.store.v16f32.p0(<16 x float> %value, ptr %ptr, i32 4, <16 x i1> %mask)
21202 ;; The result of the following instructions is identical aside from potential data races and memory access exceptions
21203 %oldval = load <16 x float>, ptr %ptr, align 4
21204 %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval
21205 store <16 x float> %res, ptr %ptr, align 4
21208 Masked Vector Gather and Scatter Intrinsics
21209 -------------------------------------------
21211 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.
21215 '``llvm.masked.gather.*``' Intrinsics
21216 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21220 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.
21224 declare <16 x float> @llvm.masked.gather.v16f32.v16p0(<16 x ptr> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
21225 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>)
21226 declare <8 x ptr> @llvm.masked.gather.v8p0.v8p0(<8 x ptr> <ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x ptr> <passthru>)
21231 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.
21237 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.
21242 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.
21243 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.
21248 %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> undef)
21250 ;; The gather with all-true mask is equivalent to the following instruction sequence
21251 %ptr0 = extractelement <4 x ptr> %ptrs, i32 0
21252 %ptr1 = extractelement <4 x ptr> %ptrs, i32 1
21253 %ptr2 = extractelement <4 x ptr> %ptrs, i32 2
21254 %ptr3 = extractelement <4 x ptr> %ptrs, i32 3
21256 %val0 = load double, ptr %ptr0, align 8
21257 %val1 = load double, ptr %ptr1, align 8
21258 %val2 = load double, ptr %ptr2, align 8
21259 %val3 = load double, ptr %ptr3, align 8
21261 %vec0 = insertelement <4 x double>undef, %val0, 0
21262 %vec01 = insertelement <4 x double>%vec0, %val1, 1
21263 %vec012 = insertelement <4 x double>%vec01, %val2, 2
21264 %vec0123 = insertelement <4 x double>%vec012, %val3, 3
21268 '``llvm.masked.scatter.*``' Intrinsics
21269 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21273 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.
21277 declare void @llvm.masked.scatter.v8i32.v8p0 (<8 x i32> <value>, <8 x ptr> <ptrs>, i32 <alignment>, <8 x i1> <mask>)
21278 declare void @llvm.masked.scatter.v16f32.v16p1(<16 x float> <value>, <16 x ptr addrspace(1)> <ptrs>, i32 <alignment>, <16 x i1> <mask>)
21279 declare void @llvm.masked.scatter.v4p0.v4p0 (<4 x ptr> <value>, <4 x ptr> <ptrs>, i32 <alignment>, <4 x i1> <mask>)
21284 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.
21289 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.
21294 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.
21298 ;; This instruction unconditionally stores data vector in multiple addresses
21299 call @llvm.masked.scatter.v8i32.v8p0(<8 x i32> %value, <8 x ptr> %ptrs, i32 4, <8 x i1> <true, true, .. true>)
21301 ;; It is equivalent to a list of scalar stores
21302 %val0 = extractelement <8 x i32> %value, i32 0
21303 %val1 = extractelement <8 x i32> %value, i32 1
21305 %val7 = extractelement <8 x i32> %value, i32 7
21306 %ptr0 = extractelement <8 x ptr> %ptrs, i32 0
21307 %ptr1 = extractelement <8 x ptr> %ptrs, i32 1
21309 %ptr7 = extractelement <8 x ptr> %ptrs, i32 7
21310 ;; Note: the order of the following stores is important when they overlap:
21311 store i32 %val0, ptr %ptr0, align 4
21312 store i32 %val1, ptr %ptr1, align 4
21314 store i32 %val7, ptr %ptr7, align 4
21317 Masked Vector Expanding Load and Compressing Store Intrinsics
21318 -------------------------------------------------------------
21320 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>`.
21322 .. _int_expandload:
21324 '``llvm.masked.expandload.*``' Intrinsics
21325 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21329 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.
21333 declare <16 x float> @llvm.masked.expandload.v16f32 (ptr <ptr>, <16 x i1> <mask>, <16 x float> <passthru>)
21334 declare <2 x i64> @llvm.masked.expandload.v2i64 (ptr <ptr>, <2 x i1> <mask>, <2 x i64> <passthru>)
21339 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.
21345 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.
21350 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:
21354 // In this loop we load from B and spread the elements into array A.
21355 double *A, B; int *C;
21356 for (int i = 0; i < size; ++i) {
21362 .. code-block:: llvm
21364 ; Load several elements from array B and expand them in a vector.
21365 ; The number of loaded elements is equal to the number of '1' elements in the Mask.
21366 %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(ptr %Bptr, <8 x i1> %Mask, <8 x double> undef)
21367 ; Store the result in A
21368 call void @llvm.masked.store.v8f64.p0(<8 x double> %Tmp, ptr %Aptr, i32 8, <8 x i1> %Mask)
21370 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
21371 %MaskI = bitcast <8 x i1> %Mask to i8
21372 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
21373 %MaskI64 = zext i8 %MaskIPopcnt to i64
21374 %BNextInd = add i64 %BInd, %MaskI64
21377 Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles.
21378 If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load.
21380 .. _int_compressstore:
21382 '``llvm.masked.compressstore.*``' Intrinsics
21383 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21387 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.
21391 declare void @llvm.masked.compressstore.v8i32 (<8 x i32> <value>, ptr <ptr>, <8 x i1> <mask>)
21392 declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, ptr <ptr>, <16 x i1> <mask>)
21397 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.
21402 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.
21408 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:
21412 // In this loop we load elements from A and store them consecutively in B
21413 double *A, B; int *C;
21414 for (int i = 0; i < size; ++i) {
21420 .. code-block:: llvm
21422 ; Load elements from A.
21423 %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0(ptr %Aptr, i32 8, <8 x i1> %Mask, <8 x double> undef)
21424 ; Store all selected elements consecutively in array B
21425 call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, ptr %Bptr, <8 x i1> %Mask)
21427 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
21428 %MaskI = bitcast <8 x i1> %Mask to i8
21429 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
21430 %MaskI64 = zext i8 %MaskIPopcnt to i64
21431 %BNextInd = add i64 %BInd, %MaskI64
21434 Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations.
21440 This class of intrinsics provides information about the
21441 :ref:`lifetime of memory objects <objectlifetime>` and ranges where variables
21446 '``llvm.lifetime.start``' Intrinsic
21447 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21454 declare void @llvm.lifetime.start(i64 <size>, ptr nocapture <ptr>)
21459 The '``llvm.lifetime.start``' intrinsic specifies the start of a memory
21465 The first argument is a constant integer representing the size of the
21466 object, or -1 if it is variable sized. The second argument is a pointer
21472 If ``ptr`` is a stack-allocated object and it points to the first byte of
21473 the object, the object is initially marked as dead.
21474 ``ptr`` is conservatively considered as a non-stack-allocated object if
21475 the stack coloring algorithm that is used in the optimization pipeline cannot
21476 conclude that ``ptr`` is a stack-allocated object.
21478 After '``llvm.lifetime.start``', the stack object that ``ptr`` points is marked
21479 as alive and has an uninitialized value.
21480 The stack object is marked as dead when either
21481 :ref:`llvm.lifetime.end <int_lifeend>` to the alloca is executed or the
21484 After :ref:`llvm.lifetime.end <int_lifeend>` is called,
21485 '``llvm.lifetime.start``' on the stack object can be called again.
21486 The second '``llvm.lifetime.start``' call marks the object as alive, but it
21487 does not change the address of the object.
21489 If ``ptr`` is a non-stack-allocated object, it does not point to the first
21490 byte of the object or it is a stack object that is already alive, it simply
21491 fills all bytes of the object with ``poison``.
21496 '``llvm.lifetime.end``' Intrinsic
21497 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21504 declare void @llvm.lifetime.end(i64 <size>, ptr nocapture <ptr>)
21509 The '``llvm.lifetime.end``' intrinsic specifies the end of a memory object's
21515 The first argument is a constant integer representing the size of the
21516 object, or -1 if it is variable sized. The second argument is a pointer
21522 If ``ptr`` is a stack-allocated object and it points to the first byte of the
21523 object, the object is dead.
21524 ``ptr`` is conservatively considered as a non-stack-allocated object if
21525 the stack coloring algorithm that is used in the optimization pipeline cannot
21526 conclude that ``ptr`` is a stack-allocated object.
21528 Calling ``llvm.lifetime.end`` on an already dead alloca is no-op.
21530 If ``ptr`` is a non-stack-allocated object or it does not point to the first
21531 byte of the object, it is equivalent to simply filling all bytes of the object
21535 '``llvm.invariant.start``' Intrinsic
21536 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21540 This is an overloaded intrinsic. The memory object can belong to any address space.
21544 declare ptr @llvm.invariant.start.p0(i64 <size>, ptr nocapture <ptr>)
21549 The '``llvm.invariant.start``' intrinsic specifies that the contents of
21550 a memory object will not change.
21555 The first argument is a constant integer representing the size of the
21556 object, or -1 if it is variable sized. The second argument is a pointer
21562 This intrinsic indicates that until an ``llvm.invariant.end`` that uses
21563 the return value, the referenced memory location is constant and
21566 '``llvm.invariant.end``' Intrinsic
21567 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21571 This is an overloaded intrinsic. The memory object can belong to any address space.
21575 declare void @llvm.invariant.end.p0(ptr <start>, i64 <size>, ptr nocapture <ptr>)
21580 The '``llvm.invariant.end``' intrinsic specifies that the contents of a
21581 memory object are mutable.
21586 The first argument is the matching ``llvm.invariant.start`` intrinsic.
21587 The second argument is a constant integer representing the size of the
21588 object, or -1 if it is variable sized and the third argument is a
21589 pointer to the object.
21594 This intrinsic indicates that the memory is mutable again.
21596 '``llvm.launder.invariant.group``' Intrinsic
21597 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21601 This is an overloaded intrinsic. The memory object can belong to any address
21602 space. The returned pointer must belong to the same address space as the
21607 declare ptr @llvm.launder.invariant.group.p0(ptr <ptr>)
21612 The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant
21613 established by ``invariant.group`` metadata no longer holds, to obtain a new
21614 pointer value that carries fresh invariant group information. It is an
21615 experimental intrinsic, which means that its semantics might change in the
21622 The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer
21628 Returns another pointer that aliases its argument but which is considered different
21629 for the purposes of ``load``/``store`` ``invariant.group`` metadata.
21630 It does not read any accessible memory and the execution can be speculated.
21632 '``llvm.strip.invariant.group``' Intrinsic
21633 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21637 This is an overloaded intrinsic. The memory object can belong to any address
21638 space. The returned pointer must belong to the same address space as the
21643 declare ptr @llvm.strip.invariant.group.p0(ptr <ptr>)
21648 The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant
21649 established by ``invariant.group`` metadata no longer holds, to obtain a new pointer
21650 value that does not carry the invariant information. It is an experimental
21651 intrinsic, which means that its semantics might change in the future.
21657 The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer
21663 Returns another pointer that aliases its argument but which has no associated
21664 ``invariant.group`` metadata.
21665 It does not read any memory and can be speculated.
21671 Constrained Floating-Point Intrinsics
21672 -------------------------------------
21674 These intrinsics are used to provide special handling of floating-point
21675 operations when specific rounding mode or floating-point exception behavior is
21676 required. By default, LLVM optimization passes assume that the rounding mode is
21677 round-to-nearest and that floating-point exceptions will not be monitored.
21678 Constrained FP intrinsics are used to support non-default rounding modes and
21679 accurately preserve exception behavior without compromising LLVM's ability to
21680 optimize FP code when the default behavior is used.
21682 If any FP operation in a function is constrained then they all must be
21683 constrained. This is required for correct LLVM IR. Optimizations that
21684 move code around can create miscompiles if mixing of constrained and normal
21685 operations is done. The correct way to mix constrained and less constrained
21686 operations is to use the rounding mode and exception handling metadata to
21687 mark constrained intrinsics as having LLVM's default behavior.
21689 Each of these intrinsics corresponds to a normal floating-point operation. The
21690 data arguments and the return value are the same as the corresponding FP
21693 The rounding mode argument is a metadata string specifying what
21694 assumptions, if any, the optimizer can make when transforming constant
21695 values. Some constrained FP intrinsics omit this argument. If required
21696 by the intrinsic, this argument must be one of the following strings:
21705 "round.tonearestaway"
21707 If this argument is "round.dynamic" optimization passes must assume that the
21708 rounding mode is unknown and may change at runtime. No transformations that
21709 depend on rounding mode may be performed in this case.
21711 The other possible values for the rounding mode argument correspond to the
21712 similarly named IEEE rounding modes. If the argument is any of these values
21713 optimization passes may perform transformations as long as they are consistent
21714 with the specified rounding mode.
21716 For example, 'x-0'->'x' is not a valid transformation if the rounding mode is
21717 "round.downward" or "round.dynamic" because if the value of 'x' is +0 then
21718 'x-0' should evaluate to '-0' when rounding downward. However, this
21719 transformation is legal for all other rounding modes.
21721 For values other than "round.dynamic" optimization passes may assume that the
21722 actual runtime rounding mode (as defined in a target-specific manner) matches
21723 the specified rounding mode, but this is not guaranteed. Using a specific
21724 non-dynamic rounding mode which does not match the actual rounding mode at
21725 runtime results in undefined behavior.
21727 The exception behavior argument is a metadata string describing the floating
21728 point exception semantics that required for the intrinsic. This argument
21729 must be one of the following strings:
21737 If this argument is "fpexcept.ignore" optimization passes may assume that the
21738 exception status flags will not be read and that floating-point exceptions will
21739 be masked. This allows transformations to be performed that may change the
21740 exception semantics of the original code. For example, FP operations may be
21741 speculatively executed in this case whereas they must not be for either of the
21742 other possible values of this argument.
21744 If the exception behavior argument is "fpexcept.maytrap" optimization passes
21745 must avoid transformations that may raise exceptions that would not have been
21746 raised by the original code (such as speculatively executing FP operations), but
21747 passes are not required to preserve all exceptions that are implied by the
21748 original code. For example, exceptions may be potentially hidden by constant
21751 If the exception behavior argument is "fpexcept.strict" all transformations must
21752 strictly preserve the floating-point exception semantics of the original code.
21753 Any FP exception that would have been raised by the original code must be raised
21754 by the transformed code, and the transformed code must not raise any FP
21755 exceptions that would not have been raised by the original code. This is the
21756 exception behavior argument that will be used if the code being compiled reads
21757 the FP exception status flags, but this mode can also be used with code that
21758 unmasks FP exceptions.
21760 The number and order of floating-point exceptions is NOT guaranteed. For
21761 example, a series of FP operations that each may raise exceptions may be
21762 vectorized into a single instruction that raises each unique exception a single
21765 Proper :ref:`function attributes <fnattrs>` usage is required for the
21766 constrained intrinsics to function correctly.
21768 All function *calls* done in a function that uses constrained floating
21769 point intrinsics must have the ``strictfp`` attribute.
21771 All function *definitions* that use constrained floating point intrinsics
21772 must have the ``strictfp`` attribute.
21774 '``llvm.experimental.constrained.fadd``' Intrinsic
21775 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21783 @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>,
21784 metadata <rounding mode>,
21785 metadata <exception behavior>)
21790 The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its
21797 The first two arguments to the '``llvm.experimental.constrained.fadd``'
21798 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
21799 of floating-point values. Both arguments must have identical types.
21801 The third and fourth arguments specify the rounding mode and exception
21802 behavior as described above.
21807 The value produced is the floating-point sum of the two value operands and has
21808 the same type as the operands.
21811 '``llvm.experimental.constrained.fsub``' Intrinsic
21812 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21820 @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>,
21821 metadata <rounding mode>,
21822 metadata <exception behavior>)
21827 The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference
21828 of its two operands.
21834 The first two arguments to the '``llvm.experimental.constrained.fsub``'
21835 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
21836 of floating-point values. Both arguments must have identical types.
21838 The third and fourth arguments specify the rounding mode and exception
21839 behavior as described above.
21844 The value produced is the floating-point difference of the two value operands
21845 and has the same type as the operands.
21848 '``llvm.experimental.constrained.fmul``' Intrinsic
21849 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21857 @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>,
21858 metadata <rounding mode>,
21859 metadata <exception behavior>)
21864 The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of
21871 The first two arguments to the '``llvm.experimental.constrained.fmul``'
21872 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
21873 of floating-point values. Both arguments must have identical types.
21875 The third and fourth arguments specify the rounding mode and exception
21876 behavior as described above.
21881 The value produced is the floating-point product of the two value operands and
21882 has the same type as the operands.
21885 '``llvm.experimental.constrained.fdiv``' Intrinsic
21886 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21894 @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>,
21895 metadata <rounding mode>,
21896 metadata <exception behavior>)
21901 The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of
21908 The first two arguments to the '``llvm.experimental.constrained.fdiv``'
21909 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
21910 of floating-point values. Both arguments must have identical types.
21912 The third and fourth arguments specify the rounding mode and exception
21913 behavior as described above.
21918 The value produced is the floating-point quotient of the two value operands and
21919 has the same type as the operands.
21922 '``llvm.experimental.constrained.frem``' Intrinsic
21923 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21931 @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>,
21932 metadata <rounding mode>,
21933 metadata <exception behavior>)
21938 The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder
21939 from the division of its two operands.
21945 The first two arguments to the '``llvm.experimental.constrained.frem``'
21946 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
21947 of floating-point values. Both arguments must have identical types.
21949 The third and fourth arguments specify the rounding mode and exception
21950 behavior as described above. The rounding mode argument has no effect, since
21951 the result of frem is never rounded, but the argument is included for
21952 consistency with the other constrained floating-point intrinsics.
21957 The value produced is the floating-point remainder from the division of the two
21958 value operands and has the same type as the operands. The remainder has the
21959 same sign as the dividend.
21961 '``llvm.experimental.constrained.fma``' Intrinsic
21962 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21970 @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>,
21971 metadata <rounding mode>,
21972 metadata <exception behavior>)
21977 The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a
21978 fused-multiply-add operation on its operands.
21983 The first three arguments to the '``llvm.experimental.constrained.fma``'
21984 intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector
21985 <t_vector>` of floating-point values. All arguments must have identical types.
21987 The fourth and fifth arguments specify the rounding mode and exception behavior
21988 as described above.
21993 The result produced is the product of the first two operands added to the third
21994 operand computed with infinite precision, and then rounded to the target
21997 '``llvm.experimental.constrained.fptoui``' Intrinsic
21998 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22006 @llvm.experimental.constrained.fptoui(<type> <value>,
22007 metadata <exception behavior>)
22012 The '``llvm.experimental.constrained.fptoui``' intrinsic converts a
22013 floating-point ``value`` to its unsigned integer equivalent of type ``ty2``.
22018 The first argument to the '``llvm.experimental.constrained.fptoui``'
22019 intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
22020 <t_vector>` of floating point values.
22022 The second argument specifies the exception behavior as described above.
22027 The result produced is an unsigned integer converted from the floating
22028 point operand. The value is truncated, so it is rounded towards zero.
22030 '``llvm.experimental.constrained.fptosi``' Intrinsic
22031 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22039 @llvm.experimental.constrained.fptosi(<type> <value>,
22040 metadata <exception behavior>)
22045 The '``llvm.experimental.constrained.fptosi``' intrinsic converts
22046 :ref:`floating-point <t_floating>` ``value`` to type ``ty2``.
22051 The first argument to the '``llvm.experimental.constrained.fptosi``'
22052 intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
22053 <t_vector>` of floating point values.
22055 The second argument specifies the exception behavior as described above.
22060 The result produced is a signed integer converted from the floating
22061 point operand. The value is truncated, so it is rounded towards zero.
22063 '``llvm.experimental.constrained.uitofp``' Intrinsic
22064 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22072 @llvm.experimental.constrained.uitofp(<type> <value>,
22073 metadata <rounding mode>,
22074 metadata <exception behavior>)
22079 The '``llvm.experimental.constrained.uitofp``' intrinsic converts an
22080 unsigned integer ``value`` to a floating-point of type ``ty2``.
22085 The first argument to the '``llvm.experimental.constrained.uitofp``'
22086 intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector
22087 <t_vector>` of integer values.
22089 The second and third arguments specify the rounding mode and exception
22090 behavior as described above.
22095 An inexact floating-point exception will be raised if rounding is required.
22096 Any result produced is a floating point value converted from the input
22099 '``llvm.experimental.constrained.sitofp``' Intrinsic
22100 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22108 @llvm.experimental.constrained.sitofp(<type> <value>,
22109 metadata <rounding mode>,
22110 metadata <exception behavior>)
22115 The '``llvm.experimental.constrained.sitofp``' intrinsic converts a
22116 signed integer ``value`` to a floating-point of type ``ty2``.
22121 The first argument to the '``llvm.experimental.constrained.sitofp``'
22122 intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector
22123 <t_vector>` of integer values.
22125 The second and third arguments specify the rounding mode and exception
22126 behavior as described above.
22131 An inexact floating-point exception will be raised if rounding is required.
22132 Any result produced is a floating point value converted from the input
22135 '``llvm.experimental.constrained.fptrunc``' Intrinsic
22136 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22144 @llvm.experimental.constrained.fptrunc(<type> <value>,
22145 metadata <rounding mode>,
22146 metadata <exception behavior>)
22151 The '``llvm.experimental.constrained.fptrunc``' intrinsic truncates ``value``
22157 The first argument to the '``llvm.experimental.constrained.fptrunc``'
22158 intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
22159 <t_vector>` of floating point values. This argument must be larger in size
22162 The second and third arguments specify the rounding mode and exception
22163 behavior as described above.
22168 The result produced is a floating point value truncated to be smaller in size
22171 '``llvm.experimental.constrained.fpext``' Intrinsic
22172 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22180 @llvm.experimental.constrained.fpext(<type> <value>,
22181 metadata <exception behavior>)
22186 The '``llvm.experimental.constrained.fpext``' intrinsic extends a
22187 floating-point ``value`` to a larger floating-point value.
22192 The first argument to the '``llvm.experimental.constrained.fpext``'
22193 intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
22194 <t_vector>` of floating point values. This argument must be smaller in size
22197 The second argument specifies the exception behavior as described above.
22202 The result produced is a floating point value extended to be larger in size
22203 than the operand. All restrictions that apply to the fpext instruction also
22204 apply to this intrinsic.
22206 '``llvm.experimental.constrained.fcmp``' and '``llvm.experimental.constrained.fcmps``' Intrinsics
22207 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22215 @llvm.experimental.constrained.fcmp(<type> <op1>, <type> <op2>,
22216 metadata <condition code>,
22217 metadata <exception behavior>)
22219 @llvm.experimental.constrained.fcmps(<type> <op1>, <type> <op2>,
22220 metadata <condition code>,
22221 metadata <exception behavior>)
22226 The '``llvm.experimental.constrained.fcmp``' and
22227 '``llvm.experimental.constrained.fcmps``' intrinsics return a boolean
22228 value or vector of boolean values based on comparison of its operands.
22230 If the operands are floating-point scalars, then the result type is a
22231 boolean (:ref:`i1 <t_integer>`).
22233 If the operands are floating-point vectors, then the result type is a
22234 vector of boolean with the same number of elements as the operands being
22237 The '``llvm.experimental.constrained.fcmp``' intrinsic performs a quiet
22238 comparison operation while the '``llvm.experimental.constrained.fcmps``'
22239 intrinsic performs a signaling comparison operation.
22244 The first two arguments to the '``llvm.experimental.constrained.fcmp``'
22245 and '``llvm.experimental.constrained.fcmps``' intrinsics must be
22246 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
22247 of floating-point values. Both arguments must have identical types.
22249 The third argument is the condition code indicating the kind of comparison
22250 to perform. It must be a metadata string with one of the following values:
22254 - "``oeq``": ordered and equal
22255 - "``ogt``": ordered and greater than
22256 - "``oge``": ordered and greater than or equal
22257 - "``olt``": ordered and less than
22258 - "``ole``": ordered and less than or equal
22259 - "``one``": ordered and not equal
22260 - "``ord``": ordered (no nans)
22261 - "``ueq``": unordered or equal
22262 - "``ugt``": unordered or greater than
22263 - "``uge``": unordered or greater than or equal
22264 - "``ult``": unordered or less than
22265 - "``ule``": unordered or less than or equal
22266 - "``une``": unordered or not equal
22267 - "``uno``": unordered (either nans)
22269 *Ordered* means that neither operand is a NAN while *unordered* means
22270 that either operand may be a NAN.
22272 The fourth argument specifies the exception behavior as described above.
22277 ``op1`` and ``op2`` are compared according to the condition code given
22278 as the third argument. If the operands are vectors, then the
22279 vectors are compared element by element. Each comparison performed
22280 always yields an :ref:`i1 <t_integer>` result, as follows:
22282 .. _fcmp_md_cc_sem:
22284 - "``oeq``": yields ``true`` if both operands are not a NAN and ``op1``
22285 is equal to ``op2``.
22286 - "``ogt``": yields ``true`` if both operands are not a NAN and ``op1``
22287 is greater than ``op2``.
22288 - "``oge``": yields ``true`` if both operands are not a NAN and ``op1``
22289 is greater than or equal to ``op2``.
22290 - "``olt``": yields ``true`` if both operands are not a NAN and ``op1``
22291 is less than ``op2``.
22292 - "``ole``": yields ``true`` if both operands are not a NAN and ``op1``
22293 is less than or equal to ``op2``.
22294 - "``one``": yields ``true`` if both operands are not a NAN and ``op1``
22295 is not equal to ``op2``.
22296 - "``ord``": yields ``true`` if both operands are not a NAN.
22297 - "``ueq``": yields ``true`` if either operand is a NAN or ``op1`` is
22299 - "``ugt``": yields ``true`` if either operand is a NAN or ``op1`` is
22300 greater than ``op2``.
22301 - "``uge``": yields ``true`` if either operand is a NAN or ``op1`` is
22302 greater than or equal to ``op2``.
22303 - "``ult``": yields ``true`` if either operand is a NAN or ``op1`` is
22305 - "``ule``": yields ``true`` if either operand is a NAN or ``op1`` is
22306 less than or equal to ``op2``.
22307 - "``une``": yields ``true`` if either operand is a NAN or ``op1`` is
22308 not equal to ``op2``.
22309 - "``uno``": yields ``true`` if either operand is a NAN.
22311 The quiet comparison operation performed by
22312 '``llvm.experimental.constrained.fcmp``' will only raise an exception
22313 if either operand is a SNAN. The signaling comparison operation
22314 performed by '``llvm.experimental.constrained.fcmps``' will raise an
22315 exception if either operand is a NAN (QNAN or SNAN). Such an exception
22316 does not preclude a result being produced (e.g. exception might only
22317 set a flag), therefore the distinction between ordered and unordered
22318 comparisons is also relevant for the
22319 '``llvm.experimental.constrained.fcmps``' intrinsic.
22321 '``llvm.experimental.constrained.fmuladd``' Intrinsic
22322 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22330 @llvm.experimental.constrained.fmuladd(<type> <op1>, <type> <op2>,
22332 metadata <rounding mode>,
22333 metadata <exception behavior>)
22338 The '``llvm.experimental.constrained.fmuladd``' intrinsic represents
22339 multiply-add expressions that can be fused if the code generator determines
22340 that (a) the target instruction set has support for a fused operation,
22341 and (b) that the fused operation is more efficient than the equivalent,
22342 separate pair of mul and add instructions.
22347 The first three arguments to the '``llvm.experimental.constrained.fmuladd``'
22348 intrinsic must be floating-point or vector of floating-point values.
22349 All three arguments must have identical types.
22351 The fourth and fifth arguments specify the rounding mode and exception behavior
22352 as described above.
22361 %0 = call float @llvm.experimental.constrained.fmuladd.f32(%a, %b, %c,
22362 metadata <rounding mode>,
22363 metadata <exception behavior>)
22365 is equivalent to the expression:
22369 %0 = call float @llvm.experimental.constrained.fmul.f32(%a, %b,
22370 metadata <rounding mode>,
22371 metadata <exception behavior>)
22372 %1 = call float @llvm.experimental.constrained.fadd.f32(%0, %c,
22373 metadata <rounding mode>,
22374 metadata <exception behavior>)
22376 except that it is unspecified whether rounding will be performed between the
22377 multiplication and addition steps. Fusion is not guaranteed, even if the target
22378 platform supports it.
22379 If a fused multiply-add is required, the corresponding
22380 :ref:`llvm.experimental.constrained.fma <int_fma>` intrinsic function should be
22382 This never sets errno, just as '``llvm.experimental.constrained.fma.*``'.
22384 Constrained libm-equivalent Intrinsics
22385 --------------------------------------
22387 In addition to the basic floating-point operations for which constrained
22388 intrinsics are described above, there are constrained versions of various
22389 operations which provide equivalent behavior to a corresponding libm function.
22390 These intrinsics allow the precise behavior of these operations with respect to
22391 rounding mode and exception behavior to be controlled.
22393 As with the basic constrained floating-point intrinsics, the rounding mode
22394 and exception behavior arguments only control the behavior of the optimizer.
22395 They do not change the runtime floating-point environment.
22398 '``llvm.experimental.constrained.sqrt``' Intrinsic
22399 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22407 @llvm.experimental.constrained.sqrt(<type> <op1>,
22408 metadata <rounding mode>,
22409 metadata <exception behavior>)
22414 The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root
22415 of the specified value, returning the same value as the libm '``sqrt``'
22416 functions would, but without setting ``errno``.
22421 The first argument and the return type are floating-point numbers of the same
22424 The second and third arguments specify the rounding mode and exception
22425 behavior as described above.
22430 This function returns the nonnegative square root of the specified value.
22431 If the value is less than negative zero, a floating-point exception occurs
22432 and the return value is architecture specific.
22435 '``llvm.experimental.constrained.pow``' Intrinsic
22436 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22444 @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>,
22445 metadata <rounding mode>,
22446 metadata <exception behavior>)
22451 The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand
22452 raised to the (positive or negative) power specified by the second operand.
22457 The first two arguments and the return value are floating-point numbers of the
22458 same type. The second argument specifies the power to which the first argument
22461 The third and fourth arguments specify the rounding mode and exception
22462 behavior as described above.
22467 This function returns the first value raised to the second power,
22468 returning the same values as the libm ``pow`` functions would, and
22469 handles error conditions in the same way.
22472 '``llvm.experimental.constrained.powi``' Intrinsic
22473 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22481 @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>,
22482 metadata <rounding mode>,
22483 metadata <exception behavior>)
22488 The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand
22489 raised to the (positive or negative) power specified by the second operand. The
22490 order of evaluation of multiplications is not defined. When a vector of
22491 floating-point type is used, the second argument remains a scalar integer value.
22497 The first argument and the return value are floating-point numbers of the same
22498 type. The second argument is a 32-bit signed integer specifying the power to
22499 which the first argument should be raised.
22501 The third and fourth arguments specify the rounding mode and exception
22502 behavior as described above.
22507 This function returns the first value raised to the second power with an
22508 unspecified sequence of rounding operations.
22511 '``llvm.experimental.constrained.sin``' Intrinsic
22512 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22520 @llvm.experimental.constrained.sin(<type> <op1>,
22521 metadata <rounding mode>,
22522 metadata <exception behavior>)
22527 The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the
22533 The first argument and the return type are floating-point numbers of the same
22536 The second and third arguments specify the rounding mode and exception
22537 behavior as described above.
22542 This function returns the sine of the specified operand, returning the
22543 same values as the libm ``sin`` functions would, and handles error
22544 conditions in the same way.
22547 '``llvm.experimental.constrained.cos``' Intrinsic
22548 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22556 @llvm.experimental.constrained.cos(<type> <op1>,
22557 metadata <rounding mode>,
22558 metadata <exception behavior>)
22563 The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the
22569 The first argument and the return type are floating-point numbers of the same
22572 The second and third arguments specify the rounding mode and exception
22573 behavior as described above.
22578 This function returns the cosine of the specified operand, returning the
22579 same values as the libm ``cos`` functions would, and handles error
22580 conditions in the same way.
22583 '``llvm.experimental.constrained.exp``' Intrinsic
22584 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22592 @llvm.experimental.constrained.exp(<type> <op1>,
22593 metadata <rounding mode>,
22594 metadata <exception behavior>)
22599 The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e
22600 exponential of the specified value.
22605 The first argument and the return value are floating-point numbers of the same
22608 The second and third arguments specify the rounding mode and exception
22609 behavior as described above.
22614 This function returns the same values as the libm ``exp`` functions
22615 would, and handles error conditions in the same way.
22618 '``llvm.experimental.constrained.exp2``' Intrinsic
22619 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22627 @llvm.experimental.constrained.exp2(<type> <op1>,
22628 metadata <rounding mode>,
22629 metadata <exception behavior>)
22634 The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2
22635 exponential of the specified value.
22641 The first argument and the return value are floating-point numbers of the same
22644 The second and third arguments specify the rounding mode and exception
22645 behavior as described above.
22650 This function returns the same values as the libm ``exp2`` functions
22651 would, and handles error conditions in the same way.
22654 '``llvm.experimental.constrained.log``' Intrinsic
22655 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22663 @llvm.experimental.constrained.log(<type> <op1>,
22664 metadata <rounding mode>,
22665 metadata <exception behavior>)
22670 The '``llvm.experimental.constrained.log``' intrinsic computes the base-e
22671 logarithm of the specified value.
22676 The first argument and the return value are floating-point numbers of the same
22679 The second and third arguments specify the rounding mode and exception
22680 behavior as described above.
22686 This function returns the same values as the libm ``log`` functions
22687 would, and handles error conditions in the same way.
22690 '``llvm.experimental.constrained.log10``' Intrinsic
22691 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22699 @llvm.experimental.constrained.log10(<type> <op1>,
22700 metadata <rounding mode>,
22701 metadata <exception behavior>)
22706 The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10
22707 logarithm of the specified value.
22712 The first argument and the return value are floating-point numbers of the same
22715 The second and third arguments specify the rounding mode and exception
22716 behavior as described above.
22721 This function returns the same values as the libm ``log10`` functions
22722 would, and handles error conditions in the same way.
22725 '``llvm.experimental.constrained.log2``' Intrinsic
22726 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22734 @llvm.experimental.constrained.log2(<type> <op1>,
22735 metadata <rounding mode>,
22736 metadata <exception behavior>)
22741 The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2
22742 logarithm of the specified value.
22747 The first argument and the return value are floating-point numbers of the same
22750 The second and third arguments specify the rounding mode and exception
22751 behavior as described above.
22756 This function returns the same values as the libm ``log2`` functions
22757 would, and handles error conditions in the same way.
22760 '``llvm.experimental.constrained.rint``' Intrinsic
22761 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22769 @llvm.experimental.constrained.rint(<type> <op1>,
22770 metadata <rounding mode>,
22771 metadata <exception behavior>)
22776 The '``llvm.experimental.constrained.rint``' intrinsic returns the first
22777 operand rounded to the nearest integer. It may raise an inexact floating-point
22778 exception if the operand is not an integer.
22783 The first argument and the return value are floating-point numbers of the same
22786 The second and third arguments specify the rounding mode and exception
22787 behavior as described above.
22792 This function returns the same values as the libm ``rint`` functions
22793 would, and handles error conditions in the same way. The rounding mode is
22794 described, not determined, by the rounding mode argument. The actual rounding
22795 mode is determined by the runtime floating-point environment. The rounding
22796 mode argument is only intended as information to the compiler.
22799 '``llvm.experimental.constrained.lrint``' Intrinsic
22800 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22808 @llvm.experimental.constrained.lrint(<fptype> <op1>,
22809 metadata <rounding mode>,
22810 metadata <exception behavior>)
22815 The '``llvm.experimental.constrained.lrint``' intrinsic returns the first
22816 operand rounded to the nearest integer. An inexact floating-point exception
22817 will be raised if the operand is not an integer. An invalid exception is
22818 raised if the result is too large to fit into a supported integer type,
22819 and in this case the result is undefined.
22824 The first argument is a floating-point number. The return value is an
22825 integer type. Not all types are supported on all targets. The supported
22826 types are the same as the ``llvm.lrint`` intrinsic and the ``lrint``
22829 The second and third arguments specify the rounding mode and exception
22830 behavior as described above.
22835 This function returns the same values as the libm ``lrint`` functions
22836 would, and handles error conditions in the same way.
22838 The rounding mode is described, not determined, by the rounding mode
22839 argument. The actual rounding mode is determined by the runtime floating-point
22840 environment. The rounding mode argument is only intended as information
22843 If the runtime floating-point environment is using the default rounding mode
22844 then the results will be the same as the llvm.lrint intrinsic.
22847 '``llvm.experimental.constrained.llrint``' Intrinsic
22848 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22856 @llvm.experimental.constrained.llrint(<fptype> <op1>,
22857 metadata <rounding mode>,
22858 metadata <exception behavior>)
22863 The '``llvm.experimental.constrained.llrint``' intrinsic returns the first
22864 operand rounded to the nearest integer. An inexact floating-point exception
22865 will be raised if the operand is not an integer. An invalid exception is
22866 raised if the result is too large to fit into a supported integer type,
22867 and in this case the result is undefined.
22872 The first argument is a floating-point number. The return value is an
22873 integer type. Not all types are supported on all targets. The supported
22874 types are the same as the ``llvm.llrint`` intrinsic and the ``llrint``
22877 The second and third arguments specify the rounding mode and exception
22878 behavior as described above.
22883 This function returns the same values as the libm ``llrint`` functions
22884 would, and handles error conditions in the same way.
22886 The rounding mode is described, not determined, by the rounding mode
22887 argument. The actual rounding mode is determined by the runtime floating-point
22888 environment. The rounding mode argument is only intended as information
22891 If the runtime floating-point environment is using the default rounding mode
22892 then the results will be the same as the llvm.llrint intrinsic.
22895 '``llvm.experimental.constrained.nearbyint``' Intrinsic
22896 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22904 @llvm.experimental.constrained.nearbyint(<type> <op1>,
22905 metadata <rounding mode>,
22906 metadata <exception behavior>)
22911 The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first
22912 operand rounded to the nearest integer. It will not raise an inexact
22913 floating-point exception if the operand is not an integer.
22919 The first argument and the return value are floating-point numbers of the same
22922 The second and third arguments specify the rounding mode and exception
22923 behavior as described above.
22928 This function returns the same values as the libm ``nearbyint`` functions
22929 would, and handles error conditions in the same way. The rounding mode is
22930 described, not determined, by the rounding mode argument. The actual rounding
22931 mode is determined by the runtime floating-point environment. The rounding
22932 mode argument is only intended as information to the compiler.
22935 '``llvm.experimental.constrained.maxnum``' Intrinsic
22936 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22944 @llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2>
22945 metadata <exception behavior>)
22950 The '``llvm.experimental.constrained.maxnum``' intrinsic returns the maximum
22951 of the two arguments.
22956 The first two arguments and the return value are floating-point numbers
22959 The third argument specifies the exception behavior as described above.
22964 This function follows the IEEE-754 semantics for maxNum.
22967 '``llvm.experimental.constrained.minnum``' Intrinsic
22968 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22976 @llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2>
22977 metadata <exception behavior>)
22982 The '``llvm.experimental.constrained.minnum``' intrinsic returns the minimum
22983 of the two arguments.
22988 The first two arguments and the return value are floating-point numbers
22991 The third argument specifies the exception behavior as described above.
22996 This function follows the IEEE-754 semantics for minNum.
22999 '``llvm.experimental.constrained.maximum``' Intrinsic
23000 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23008 @llvm.experimental.constrained.maximum(<type> <op1>, <type> <op2>
23009 metadata <exception behavior>)
23014 The '``llvm.experimental.constrained.maximum``' intrinsic returns the maximum
23015 of the two arguments, propagating NaNs and treating -0.0 as less than +0.0.
23020 The first two arguments and the return value are floating-point numbers
23023 The third argument specifies the exception behavior as described above.
23028 This function follows semantics specified in the draft of IEEE 754-2018.
23031 '``llvm.experimental.constrained.minimum``' Intrinsic
23032 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23040 @llvm.experimental.constrained.minimum(<type> <op1>, <type> <op2>
23041 metadata <exception behavior>)
23046 The '``llvm.experimental.constrained.minimum``' intrinsic returns the minimum
23047 of the two arguments, propagating NaNs and treating -0.0 as less than +0.0.
23052 The first two arguments and the return value are floating-point numbers
23055 The third argument specifies the exception behavior as described above.
23060 This function follows semantics specified in the draft of IEEE 754-2018.
23063 '``llvm.experimental.constrained.ceil``' Intrinsic
23064 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23072 @llvm.experimental.constrained.ceil(<type> <op1>,
23073 metadata <exception behavior>)
23078 The '``llvm.experimental.constrained.ceil``' intrinsic returns the ceiling of the
23084 The first argument and the return value are floating-point numbers of the same
23087 The second argument specifies the exception behavior as described above.
23092 This function returns the same values as the libm ``ceil`` functions
23093 would and handles error conditions in the same way.
23096 '``llvm.experimental.constrained.floor``' Intrinsic
23097 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23105 @llvm.experimental.constrained.floor(<type> <op1>,
23106 metadata <exception behavior>)
23111 The '``llvm.experimental.constrained.floor``' intrinsic returns the floor of the
23117 The first argument and the return value are floating-point numbers of the same
23120 The second argument specifies the exception behavior as described above.
23125 This function returns the same values as the libm ``floor`` functions
23126 would and handles error conditions in the same way.
23129 '``llvm.experimental.constrained.round``' Intrinsic
23130 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23138 @llvm.experimental.constrained.round(<type> <op1>,
23139 metadata <exception behavior>)
23144 The '``llvm.experimental.constrained.round``' intrinsic returns the first
23145 operand rounded to the nearest integer.
23150 The first argument and the return value are floating-point numbers of the same
23153 The second argument specifies the exception behavior as described above.
23158 This function returns the same values as the libm ``round`` functions
23159 would and handles error conditions in the same way.
23162 '``llvm.experimental.constrained.roundeven``' Intrinsic
23163 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23171 @llvm.experimental.constrained.roundeven(<type> <op1>,
23172 metadata <exception behavior>)
23177 The '``llvm.experimental.constrained.roundeven``' intrinsic returns the first
23178 operand rounded to the nearest integer in floating-point format, rounding
23179 halfway cases to even (that is, to the nearest value that is an even integer),
23180 regardless of the current rounding direction.
23185 The first argument and the return value are floating-point numbers of the same
23188 The second argument specifies the exception behavior as described above.
23193 This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It
23194 also behaves in the same way as C standard function ``roundeven`` and can signal
23195 the invalid operation exception for a SNAN operand.
23198 '``llvm.experimental.constrained.lround``' Intrinsic
23199 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23207 @llvm.experimental.constrained.lround(<fptype> <op1>,
23208 metadata <exception behavior>)
23213 The '``llvm.experimental.constrained.lround``' intrinsic returns the first
23214 operand rounded to the nearest integer with ties away from zero. It will
23215 raise an inexact floating-point exception if the operand is not an integer.
23216 An invalid exception is raised if the result is too large to fit into a
23217 supported integer type, and in this case the result is undefined.
23222 The first argument is a floating-point number. The return value is an
23223 integer type. Not all types are supported on all targets. The supported
23224 types are the same as the ``llvm.lround`` intrinsic and the ``lround``
23227 The second argument specifies the exception behavior as described above.
23232 This function returns the same values as the libm ``lround`` functions
23233 would and handles error conditions in the same way.
23236 '``llvm.experimental.constrained.llround``' Intrinsic
23237 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23245 @llvm.experimental.constrained.llround(<fptype> <op1>,
23246 metadata <exception behavior>)
23251 The '``llvm.experimental.constrained.llround``' intrinsic returns the first
23252 operand rounded to the nearest integer with ties away from zero. It will
23253 raise an inexact floating-point exception if the operand is not an integer.
23254 An invalid exception is raised if the result is too large to fit into a
23255 supported integer type, and in this case the result is undefined.
23260 The first argument is a floating-point number. The return value is an
23261 integer type. Not all types are supported on all targets. The supported
23262 types are the same as the ``llvm.llround`` intrinsic and the ``llround``
23265 The second argument specifies the exception behavior as described above.
23270 This function returns the same values as the libm ``llround`` functions
23271 would and handles error conditions in the same way.
23274 '``llvm.experimental.constrained.trunc``' Intrinsic
23275 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23283 @llvm.experimental.constrained.trunc(<type> <op1>,
23284 metadata <exception behavior>)
23289 The '``llvm.experimental.constrained.trunc``' intrinsic returns the first
23290 operand rounded to the nearest integer not larger in magnitude than the
23296 The first argument and the return value are floating-point numbers of the same
23299 The second argument specifies the exception behavior as described above.
23304 This function returns the same values as the libm ``trunc`` functions
23305 would and handles error conditions in the same way.
23307 .. _int_experimental_noalias_scope_decl:
23309 '``llvm.experimental.noalias.scope.decl``' Intrinsic
23310 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23318 declare void @llvm.experimental.noalias.scope.decl(metadata !id.scope.list)
23323 The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a
23324 noalias scope is declared. When the intrinsic is duplicated, a decision must
23325 also be made about the scope: depending on the reason of the duplication,
23326 the scope might need to be duplicated as well.
23332 The ``!id.scope.list`` argument is metadata that is a list of ``noalias``
23333 metadata references. The format is identical to that required for ``noalias``
23334 metadata. This list must have exactly one element.
23339 The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a
23340 noalias scope is declared. When the intrinsic is duplicated, a decision must
23341 also be made about the scope: depending on the reason of the duplication,
23342 the scope might need to be duplicated as well.
23344 For example, when the intrinsic is used inside a loop body, and that loop is
23345 unrolled, the associated noalias scope must also be duplicated. Otherwise, the
23346 noalias property it signifies would spill across loop iterations, whereas it
23347 was only valid within a single iteration.
23349 .. code-block:: llvm
23351 ; This examples shows two possible positions for noalias.decl and how they impact the semantics:
23352 ; If it is outside the loop (Version 1), then %a and %b are noalias across *all* iterations.
23353 ; If it is inside the loop (Version 2), then %a and %b are noalias only within *one* iteration.
23354 declare void @decl_in_loop(ptr %a.base, ptr %b.base) {
23356 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 1: noalias decl outside loop
23360 %a = phi ptr [ %a.base, %entry ], [ %a.inc, %loop ]
23361 %b = phi ptr [ %b.base, %entry ], [ %b.inc, %loop ]
23362 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 2: noalias decl inside loop
23363 %val = load i8, ptr %a, !alias.scope !2
23364 store i8 %val, ptr %b, !noalias !2
23365 %a.inc = getelementptr inbounds i8, ptr %a, i64 1
23366 %b.inc = getelementptr inbounds i8, ptr %b, i64 1
23367 %cond = call i1 @cond()
23368 br i1 %cond, label %loop, label %exit
23374 !0 = !{!0} ; domain
23375 !1 = !{!1, !0} ; scope
23376 !2 = !{!1} ; scope list
23378 Multiple calls to `@llvm.experimental.noalias.scope.decl` for the same scope
23379 are possible, but one should never dominate another. Violations are pointed out
23380 by the verifier as they indicate a problem in either a transformation pass or
23384 Floating Point Environment Manipulation intrinsics
23385 --------------------------------------------------
23387 These functions read or write floating point environment, such as rounding
23388 mode or state of floating point exceptions. Altering the floating point
23389 environment requires special care. See :ref:`Floating Point Environment <floatenv>`.
23391 '``llvm.flt.rounds``' Intrinsic
23392 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23399 declare i32 @llvm.flt.rounds()
23404 The '``llvm.flt.rounds``' intrinsic reads the current rounding mode.
23409 The '``llvm.flt.rounds``' intrinsic returns the current rounding mode.
23410 Encoding of the returned values is same as the result of ``FLT_ROUNDS``,
23411 specified by C standard:
23416 1 - to nearest, ties to even
23417 2 - toward positive infinity
23418 3 - toward negative infinity
23419 4 - to nearest, ties away from zero
23421 Other values may be used to represent additional rounding modes, supported by a
23422 target. These values are target-specific.
23425 '``llvm.set.rounding``' Intrinsic
23426 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23433 declare void @llvm.set.rounding(i32 <val>)
23438 The '``llvm.set.rounding``' intrinsic sets current rounding mode.
23443 The argument is the required rounding mode. Encoding of rounding mode is
23444 the same as used by '``llvm.flt.rounds``'.
23449 The '``llvm.set.rounding``' intrinsic sets the current rounding mode. It is
23450 similar to C library function 'fesetround', however this intrinsic does not
23451 return any value and uses platform-independent representation of IEEE rounding
23455 Floating-Point Test Intrinsics
23456 ------------------------------
23458 These functions get properties of floating-point values.
23461 '``llvm.is.fpclass``' Intrinsic
23462 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23469 declare i1 @llvm.is.fpclass(<fptype> <op>, i32 <test>)
23470 declare <N x i1> @llvm.is.fpclass(<vector-fptype> <op>, i32 <test>)
23475 The '``llvm.is.fpclass``' intrinsic returns a boolean value or vector of boolean
23476 values depending on whether the first argument satisfies the test specified by
23477 the second argument.
23479 If the first argument is a floating-point scalar, then the result type is a
23480 boolean (:ref:`i1 <t_integer>`).
23482 If the first argument is a floating-point vector, then the result type is a
23483 vector of boolean with the same number of elements as the first argument.
23488 The first argument to the '``llvm.is.fpclass``' intrinsic must be
23489 :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
23490 of floating-point values.
23492 The second argument specifies, which tests to perform. It must be a compile-time
23493 integer constant, each bit in which specifies floating-point class:
23495 +-------+----------------------+
23496 | Bit # | floating-point class |
23497 +=======+======================+
23498 | 0 | Signaling NaN |
23499 +-------+----------------------+
23501 +-------+----------------------+
23502 | 2 | Negative infinity |
23503 +-------+----------------------+
23504 | 3 | Negative normal |
23505 +-------+----------------------+
23506 | 4 | Negative subnormal |
23507 +-------+----------------------+
23508 | 5 | Negative zero |
23509 +-------+----------------------+
23510 | 6 | Positive zero |
23511 +-------+----------------------+
23512 | 7 | Positive subnormal |
23513 +-------+----------------------+
23514 | 8 | Positive normal |
23515 +-------+----------------------+
23516 | 9 | Positive infinity |
23517 +-------+----------------------+
23522 The function checks if ``op`` belongs to any of the floating-point classes
23523 specified by ``test``. If ``op`` is a vector, then the check is made element by
23524 element. Each check yields an :ref:`i1 <t_integer>` result, which is ``true``,
23525 if the element value satisfies the specified test. The argument ``test`` is a
23526 bit mask where each bit specifies floating-point class to test. For example, the
23527 value 0x108 makes test for normal value, - bits 3 and 8 in it are set, which
23528 means that the function returns ``true`` if ``op`` is a positive or negative
23529 normal value. The function never raises floating-point exceptions.
23535 This class of intrinsics is designed to be generic and has no specific
23538 '``llvm.var.annotation``' Intrinsic
23539 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23546 declare void @llvm.var.annotation(ptr <val>, ptr <str>, ptr <str>, i32 <int>)
23551 The '``llvm.var.annotation``' intrinsic.
23556 The first argument is a pointer to a value, the second is a pointer to a
23557 global string, the third is a pointer to a global string which is the
23558 source file name, and the last argument is the line number.
23563 This intrinsic allows annotation of local variables with arbitrary
23564 strings. This can be useful for special purpose optimizations that want
23565 to look for these annotations. These have no other defined use; they are
23566 ignored by code generation and optimization.
23568 '``llvm.ptr.annotation.*``' Intrinsic
23569 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23574 This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a
23575 pointer to an integer of any width. *NOTE* you must specify an address space for
23576 the pointer. The identifier for the default address space is the integer
23581 declare ptr @llvm.ptr.annotation.p0(ptr <val>, ptr <str>, ptr <str>, i32 <int>)
23582 declare ptr @llvm.ptr.annotation.p1(ptr addrspace(1) <val>, ptr <str>, ptr <str>, i32 <int>)
23587 The '``llvm.ptr.annotation``' intrinsic.
23592 The first argument is a pointer to an integer value of arbitrary bitwidth
23593 (result of some expression), the second is a pointer to a global string, the
23594 third is a pointer to a global string which is the source file name, and the
23595 last argument is the line number. It returns the value of the first argument.
23600 This intrinsic allows annotation of a pointer to an integer with arbitrary
23601 strings. This can be useful for special purpose optimizations that want to look
23602 for these annotations. These have no other defined use; transformations preserve
23603 annotations on a best-effort basis but are allowed to replace the intrinsic with
23604 its first argument without breaking semantics and the intrinsic is completely
23605 dropped during instruction selection.
23607 '``llvm.annotation.*``' Intrinsic
23608 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23613 This is an overloaded intrinsic. You can use '``llvm.annotation``' on
23614 any integer bit width.
23618 declare i8 @llvm.annotation.i8(i8 <val>, ptr <str>, ptr <str>, i32 <int>)
23619 declare i16 @llvm.annotation.i16(i16 <val>, ptr <str>, ptr <str>, i32 <int>)
23620 declare i32 @llvm.annotation.i32(i32 <val>, ptr <str>, ptr <str>, i32 <int>)
23621 declare i64 @llvm.annotation.i64(i64 <val>, ptr <str>, ptr <str>, i32 <int>)
23622 declare i256 @llvm.annotation.i256(i256 <val>, ptr <str>, ptr <str>, i32 <int>)
23627 The '``llvm.annotation``' intrinsic.
23632 The first argument is an integer value (result of some expression), the
23633 second is a pointer to a global string, the third is a pointer to a
23634 global string which is the source file name, and the last argument is
23635 the line number. It returns the value of the first argument.
23640 This intrinsic allows annotations to be put on arbitrary expressions with
23641 arbitrary strings. This can be useful for special purpose optimizations that
23642 want to look for these annotations. These have no other defined use;
23643 transformations preserve annotations on a best-effort basis but are allowed to
23644 replace the intrinsic with its first argument without breaking semantics and the
23645 intrinsic is completely dropped during instruction selection.
23647 '``llvm.codeview.annotation``' Intrinsic
23648 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23653 This annotation emits a label at its program point and an associated
23654 ``S_ANNOTATION`` codeview record with some additional string metadata. This is
23655 used to implement MSVC's ``__annotation`` intrinsic. It is marked
23656 ``noduplicate``, so calls to this intrinsic prevent inlining and should be
23657 considered expensive.
23661 declare void @llvm.codeview.annotation(metadata)
23666 The argument should be an MDTuple containing any number of MDStrings.
23668 '``llvm.trap``' Intrinsic
23669 ^^^^^^^^^^^^^^^^^^^^^^^^^
23676 declare void @llvm.trap() cold noreturn nounwind
23681 The '``llvm.trap``' intrinsic.
23691 This intrinsic is lowered to the target dependent trap instruction. If
23692 the target does not have a trap instruction, this intrinsic will be
23693 lowered to a call of the ``abort()`` function.
23695 '``llvm.debugtrap``' Intrinsic
23696 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23703 declare void @llvm.debugtrap() nounwind
23708 The '``llvm.debugtrap``' intrinsic.
23718 This intrinsic is lowered to code which is intended to cause an
23719 execution trap with the intention of requesting the attention of a
23722 '``llvm.ubsantrap``' Intrinsic
23723 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23730 declare void @llvm.ubsantrap(i8 immarg) cold noreturn nounwind
23735 The '``llvm.ubsantrap``' intrinsic.
23740 An integer describing the kind of failure detected.
23745 This intrinsic is lowered to code which is intended to cause an execution trap,
23746 embedding the argument into encoding of that trap somehow to discriminate
23747 crashes if possible.
23749 Equivalent to ``@llvm.trap`` for targets that do not support this behaviour.
23751 '``llvm.stackprotector``' Intrinsic
23752 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23759 declare void @llvm.stackprotector(ptr <guard>, ptr <slot>)
23764 The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it
23765 onto the stack at ``slot``. The stack slot is adjusted to ensure that it
23766 is placed on the stack before local variables.
23771 The ``llvm.stackprotector`` intrinsic requires two pointer arguments.
23772 The first argument is the value loaded from the stack guard
23773 ``@__stack_chk_guard``. The second variable is an ``alloca`` that has
23774 enough space to hold the value of the guard.
23779 This intrinsic causes the prologue/epilogue inserter to force the position of
23780 the ``AllocaInst`` stack slot to be before local variables on the stack. This is
23781 to ensure that if a local variable on the stack is overwritten, it will destroy
23782 the value of the guard. When the function exits, the guard on the stack is
23783 checked against the original guard by ``llvm.stackprotectorcheck``. If they are
23784 different, then ``llvm.stackprotectorcheck`` causes the program to abort by
23785 calling the ``__stack_chk_fail()`` function.
23787 '``llvm.stackguard``' Intrinsic
23788 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23795 declare ptr @llvm.stackguard()
23800 The ``llvm.stackguard`` intrinsic returns the system stack guard value.
23802 It should not be generated by frontends, since it is only for internal usage.
23803 The reason why we create this intrinsic is that we still support IR form Stack
23804 Protector in FastISel.
23814 On some platforms, the value returned by this intrinsic remains unchanged
23815 between loads in the same thread. On other platforms, it returns the same
23816 global variable value, if any, e.g. ``@__stack_chk_guard``.
23818 Currently some platforms have IR-level customized stack guard loading (e.g.
23819 X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be
23822 '``llvm.objectsize``' Intrinsic
23823 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23830 declare i32 @llvm.objectsize.i32(ptr <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
23831 declare i64 @llvm.objectsize.i64(ptr <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
23836 The ``llvm.objectsize`` intrinsic is designed to provide information to the
23837 optimizer to determine whether a) an operation (like memcpy) will overflow a
23838 buffer that corresponds to an object, or b) that a runtime check for overflow
23839 isn't necessary. An object in this context means an allocation of a specific
23840 class, structure, array, or other object.
23845 The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a
23846 pointer to or into the ``object``. The second argument determines whether
23847 ``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size is
23848 unknown. The third argument controls how ``llvm.objectsize`` acts when ``null``
23849 in address space 0 is used as its pointer argument. If it's ``false``,
23850 ``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if
23851 the ``null`` is in a non-zero address space or if ``true`` is given for the
23852 third argument of ``llvm.objectsize``, we assume its size is unknown. The fourth
23853 argument to ``llvm.objectsize`` determines if the value should be evaluated at
23856 The second, third, and fourth arguments only accept constants.
23861 The ``llvm.objectsize`` intrinsic is lowered to a value representing the size of
23862 the object concerned. If the size cannot be determined, ``llvm.objectsize``
23863 returns ``i32/i64 -1 or 0`` (depending on the ``min`` argument).
23865 '``llvm.expect``' Intrinsic
23866 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
23871 This is an overloaded intrinsic. You can use ``llvm.expect`` on any
23876 declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>)
23877 declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
23878 declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
23883 The ``llvm.expect`` intrinsic provides information about expected (the
23884 most probable) value of ``val``, which can be used by optimizers.
23889 The ``llvm.expect`` intrinsic takes two arguments. The first argument is
23890 a value. The second argument is an expected value.
23895 This intrinsic is lowered to the ``val``.
23897 '``llvm.expect.with.probability``' Intrinsic
23898 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23903 This intrinsic is similar to ``llvm.expect``. This is an overloaded intrinsic.
23904 You can use ``llvm.expect.with.probability`` on any integer bit width.
23908 declare i1 @llvm.expect.with.probability.i1(i1 <val>, i1 <expected_val>, double <prob>)
23909 declare i32 @llvm.expect.with.probability.i32(i32 <val>, i32 <expected_val>, double <prob>)
23910 declare i64 @llvm.expect.with.probability.i64(i64 <val>, i64 <expected_val>, double <prob>)
23915 The ``llvm.expect.with.probability`` intrinsic provides information about
23916 expected value of ``val`` with probability(or confidence) ``prob``, which can
23917 be used by optimizers.
23922 The ``llvm.expect.with.probability`` intrinsic takes three arguments. The first
23923 argument is a value. The second argument is an expected value. The third
23924 argument is a probability.
23929 This intrinsic is lowered to the ``val``.
23933 '``llvm.assume``' Intrinsic
23934 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23941 declare void @llvm.assume(i1 %cond)
23946 The ``llvm.assume`` allows the optimizer to assume that the provided
23947 condition is true. This information can then be used in simplifying other parts
23950 More complex assumptions can be encoded as
23951 :ref:`assume operand bundles <assume_opbundles>`.
23956 The argument of the call is the condition which the optimizer may assume is
23962 The intrinsic allows the optimizer to assume that the provided condition is
23963 always true whenever the control flow reaches the intrinsic call. No code is
23964 generated for this intrinsic, and instructions that contribute only to the
23965 provided condition are not used for code generation. If the condition is
23966 violated during execution, the behavior is undefined.
23968 Note that the optimizer might limit the transformations performed on values
23969 used by the ``llvm.assume`` intrinsic in order to preserve the instructions
23970 only used to form the intrinsic's input argument. This might prove undesirable
23971 if the extra information provided by the ``llvm.assume`` intrinsic does not cause
23972 sufficient overall improvement in code quality. For this reason,
23973 ``llvm.assume`` should not be used to document basic mathematical invariants
23974 that the optimizer can otherwise deduce or facts that are of little use to the
23979 '``llvm.ssa.copy``' Intrinsic
23980 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23987 declare type @llvm.ssa.copy(type %operand) returned(1) readnone
23992 The first argument is an operand which is used as the returned value.
23997 The ``llvm.ssa.copy`` intrinsic can be used to attach information to
23998 operations by copying them and giving them new names. For example,
23999 the PredicateInfo utility uses it to build Extended SSA form, and
24000 attach various forms of information to operands that dominate specific
24001 uses. It is not meant for general use, only for building temporary
24002 renaming forms that require value splits at certain points.
24006 '``llvm.type.test``' Intrinsic
24007 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24014 declare i1 @llvm.type.test(ptr %ptr, metadata %type) nounwind readnone
24020 The first argument is a pointer to be tested. The second argument is a
24021 metadata object representing a :doc:`type identifier <TypeMetadata>`.
24026 The ``llvm.type.test`` intrinsic tests whether the given pointer is associated
24027 with the given type identifier.
24029 .. _type.checked.load:
24031 '``llvm.type.checked.load``' Intrinsic
24032 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24039 declare {ptr, i1} @llvm.type.checked.load(ptr %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly
24045 The first argument is a pointer from which to load a function pointer. The
24046 second argument is the byte offset from which to load the function pointer. The
24047 third argument is a metadata object representing a :doc:`type identifier
24053 The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a
24054 virtual table pointer using type metadata. This intrinsic is used to implement
24055 control flow integrity in conjunction with virtual call optimization. The
24056 virtual call optimization pass will optimize away ``llvm.type.checked.load``
24057 intrinsics associated with devirtualized calls, thereby removing the type
24058 check in cases where it is not needed to enforce the control flow integrity
24061 If the given pointer is associated with a type metadata identifier, this
24062 function returns true as the second element of its return value. (Note that
24063 the function may also return true if the given pointer is not associated
24064 with a type metadata identifier.) If the function's return value's second
24065 element is true, the following rules apply to the first element:
24067 - If the given pointer is associated with the given type metadata identifier,
24068 it is the function pointer loaded from the given byte offset from the given
24071 - If the given pointer is not associated with the given type metadata
24072 identifier, it is one of the following (the choice of which is unspecified):
24074 1. The function pointer that would have been loaded from an arbitrarily chosen
24075 (through an unspecified mechanism) pointer associated with the type
24078 2. If the function has a non-void return type, a pointer to a function that
24079 returns an unspecified value without causing side effects.
24081 If the function's return value's second element is false, the value of the
24082 first element is undefined.
24085 '``llvm.arithmetic.fence``' Intrinsic
24086 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24094 @llvm.arithmetic.fence(<type> <op>)
24099 The purpose of the ``llvm.arithmetic.fence`` intrinsic
24100 is to prevent the optimizer from performing fast-math optimizations,
24101 particularly reassociation,
24102 between the argument and the expression that contains the argument.
24103 It can be used to preserve the parentheses in the source language.
24108 The ``llvm.arithmetic.fence`` intrinsic takes only one argument.
24109 The argument and the return value are floating-point numbers,
24110 or vector floating-point numbers, of the same type.
24115 This intrinsic returns the value of its operand. The optimizer can optimize
24116 the argument, but the optimizer cannot hoist any component of the operand
24117 to the containing context, and the optimizer cannot move the calculation of
24118 any expression in the containing context into the operand.
24121 '``llvm.donothing``' Intrinsic
24122 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24129 declare void @llvm.donothing() nounwind readnone
24134 The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only
24135 three intrinsics (besides ``llvm.experimental.patchpoint`` and
24136 ``llvm.experimental.gc.statepoint``) that can be called with an invoke
24147 This intrinsic does nothing, and it's removed by optimizers and ignored
24150 '``llvm.experimental.deoptimize``' Intrinsic
24151 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24158 declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ]
24163 This intrinsic, together with :ref:`deoptimization operand bundles
24164 <deopt_opbundles>`, allow frontends to express transfer of control and
24165 frame-local state from the currently executing (typically more specialized,
24166 hence faster) version of a function into another (typically more generic, hence
24169 In languages with a fully integrated managed runtime like Java and JavaScript
24170 this intrinsic can be used to implement "uncommon trap" or "side exit" like
24171 functionality. In unmanaged languages like C and C++, this intrinsic can be
24172 used to represent the slow paths of specialized functions.
24178 The intrinsic takes an arbitrary number of arguments, whose meaning is
24179 decided by the :ref:`lowering strategy<deoptimize_lowering>`.
24184 The ``@llvm.experimental.deoptimize`` intrinsic executes an attached
24185 deoptimization continuation (denoted using a :ref:`deoptimization
24186 operand bundle <deopt_opbundles>`) and returns the value returned by
24187 the deoptimization continuation. Defining the semantic properties of
24188 the continuation itself is out of scope of the language reference --
24189 as far as LLVM is concerned, the deoptimization continuation can
24190 invoke arbitrary side effects, including reading from and writing to
24193 Deoptimization continuations expressed using ``"deopt"`` operand bundles always
24194 continue execution to the end of the physical frame containing them, so all
24195 calls to ``@llvm.experimental.deoptimize`` must be in "tail position":
24197 - ``@llvm.experimental.deoptimize`` cannot be invoked.
24198 - The call must immediately precede a :ref:`ret <i_ret>` instruction.
24199 - The ``ret`` instruction must return the value produced by the
24200 ``@llvm.experimental.deoptimize`` call if there is one, or void.
24202 Note that the above restrictions imply that the return type for a call to
24203 ``@llvm.experimental.deoptimize`` will match the return type of its immediate
24206 The inliner composes the ``"deopt"`` continuations of the caller into the
24207 ``"deopt"`` continuations present in the inlinee, and also updates calls to this
24208 intrinsic to return directly from the frame of the function it inlined into.
24210 All declarations of ``@llvm.experimental.deoptimize`` must share the
24211 same calling convention.
24213 .. _deoptimize_lowering:
24218 Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the
24219 symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to
24220 ensure that this symbol is defined). The call arguments to
24221 ``@llvm.experimental.deoptimize`` are lowered as if they were formal
24222 arguments of the specified types, and not as varargs.
24225 '``llvm.experimental.guard``' Intrinsic
24226 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24233 declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ]
24238 This intrinsic, together with :ref:`deoptimization operand bundles
24239 <deopt_opbundles>`, allows frontends to express guards or checks on
24240 optimistic assumptions made during compilation. The semantics of
24241 ``@llvm.experimental.guard`` is defined in terms of
24242 ``@llvm.experimental.deoptimize`` -- its body is defined to be
24245 .. code-block:: text
24247 define void @llvm.experimental.guard(i1 %pred, <args...>) {
24248 %realPred = and i1 %pred, undef
24249 br i1 %realPred, label %continue, label %leave [, !make.implicit !{}]
24252 call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ]
24260 with the optional ``[, !make.implicit !{}]`` present if and only if it
24261 is present on the call site. For more details on ``!make.implicit``,
24262 see :doc:`FaultMaps`.
24264 In words, ``@llvm.experimental.guard`` executes the attached
24265 ``"deopt"`` continuation if (but **not** only if) its first argument
24266 is ``false``. Since the optimizer is allowed to replace the ``undef``
24267 with an arbitrary value, it can optimize guard to fail "spuriously",
24268 i.e. without the original condition being false (hence the "not only
24269 if"); and this allows for "check widening" type optimizations.
24271 ``@llvm.experimental.guard`` cannot be invoked.
24273 After ``@llvm.experimental.guard`` was first added, a more general
24274 formulation was found in ``@llvm.experimental.widenable.condition``.
24275 Support for ``@llvm.experimental.guard`` is slowly being rephrased in
24276 terms of this alternate.
24278 '``llvm.experimental.widenable.condition``' Intrinsic
24279 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24286 declare i1 @llvm.experimental.widenable.condition()
24291 This intrinsic represents a "widenable condition" which is
24292 boolean expressions with the following property: whether this
24293 expression is `true` or `false`, the program is correct and
24296 Together with :ref:`deoptimization operand bundles <deopt_opbundles>`,
24297 ``@llvm.experimental.widenable.condition`` allows frontends to
24298 express guards or checks on optimistic assumptions made during
24299 compilation and represent them as branch instructions on special
24302 While this may appear similar in semantics to `undef`, it is very
24303 different in that an invocation produces a particular, singular
24304 value. It is also intended to be lowered late, and remain available
24305 for specific optimizations and transforms that can benefit from its
24306 special properties.
24316 The intrinsic ``@llvm.experimental.widenable.condition()``
24317 returns either `true` or `false`. For each evaluation of a call
24318 to this intrinsic, the program must be valid and correct both if
24319 it returns `true` and if it returns `false`. This allows
24320 transformation passes to replace evaluations of this intrinsic
24321 with either value whenever one is beneficial.
24323 When used in a branch condition, it allows us to choose between
24324 two alternative correct solutions for the same problem, like
24327 .. code-block:: text
24329 %cond = call i1 @llvm.experimental.widenable.condition()
24330 br i1 %cond, label %solution_1, label %solution_2
24333 ; Apply memory-consuming but fast solution for a task.
24336 ; Cheap in memory but slow solution.
24338 Whether the result of intrinsic's call is `true` or `false`,
24339 it should be correct to pick either solution. We can switch
24340 between them by replacing the result of
24341 ``@llvm.experimental.widenable.condition`` with different
24344 This is how it can be used to represent guards as widenable branches:
24346 .. code-block:: text
24349 ; Unguarded instructions
24350 call void @llvm.experimental.guard(i1 %cond, <args...>) ["deopt"(<deopt_args...>)]
24351 ; Guarded instructions
24353 Can be expressed in an alternative equivalent form of explicit branch using
24354 ``@llvm.experimental.widenable.condition``:
24356 .. code-block:: text
24359 ; Unguarded instructions
24360 %widenable_condition = call i1 @llvm.experimental.widenable.condition()
24361 %guard_condition = and i1 %cond, %widenable_condition
24362 br i1 %guard_condition, label %guarded, label %deopt
24365 ; Guarded instructions
24368 call type @llvm.experimental.deoptimize(<args...>) [ "deopt"(<deopt_args...>) ]
24370 So the block `guarded` is only reachable when `%cond` is `true`,
24371 and it should be valid to go to the block `deopt` whenever `%cond`
24372 is `true` or `false`.
24374 ``@llvm.experimental.widenable.condition`` will never throw, thus
24375 it cannot be invoked.
24380 When ``@llvm.experimental.widenable.condition()`` is used in
24381 condition of a guard represented as explicit branch, it is
24382 legal to widen the guard's condition with any additional
24385 Guard widening looks like replacement of
24387 .. code-block:: text
24389 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
24390 %guard_cond = and i1 %cond, %widenable_cond
24391 br i1 %guard_cond, label %guarded, label %deopt
24395 .. code-block:: text
24397 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
24398 %new_cond = and i1 %any_other_cond, %widenable_cond
24399 %new_guard_cond = and i1 %cond, %new_cond
24400 br i1 %new_guard_cond, label %guarded, label %deopt
24402 for this branch. Here `%any_other_cond` is an arbitrarily chosen
24403 well-defined `i1` value. By making guard widening, we may
24404 impose stricter conditions on `guarded` block and bail to the
24405 deopt when the new condition is not met.
24410 Default lowering strategy is replacing the result of
24411 call of ``@llvm.experimental.widenable.condition`` with
24412 constant `true`. However it is always correct to replace
24413 it with any other `i1` value. Any pass can
24414 freely do it if it can benefit from non-default lowering.
24417 '``llvm.load.relative``' Intrinsic
24418 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24425 declare ptr @llvm.load.relative.iN(ptr %ptr, iN %offset) argmemonly nounwind readonly
24430 This intrinsic loads a 32-bit value from the address ``%ptr + %offset``,
24431 adds ``%ptr`` to that value and returns it. The constant folder specifically
24432 recognizes the form of this intrinsic and the constant initializers it may
24433 load from; if a loaded constant initializer is known to have the form
24434 ``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``.
24436 LLVM provides that the calculation of such a constant initializer will
24437 not overflow at link time under the medium code model if ``x`` is an
24438 ``unnamed_addr`` function. However, it does not provide this guarantee for
24439 a constant initializer folded into a function body. This intrinsic can be
24440 used to avoid the possibility of overflows when loading from such a constant.
24442 .. _llvm_sideeffect:
24444 '``llvm.sideeffect``' Intrinsic
24445 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24452 declare void @llvm.sideeffect() inaccessiblememonly nounwind willreturn
24457 The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers
24458 treat it as having side effects, so it can be inserted into a loop to
24459 indicate that the loop shouldn't be assumed to terminate (which could
24460 potentially lead to the loop being optimized away entirely), even if it's
24461 an infinite loop with no other side effects.
24471 This intrinsic actually does nothing, but optimizers must assume that it
24472 has externally observable side effects.
24474 '``llvm.is.constant.*``' Intrinsic
24475 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24480 This is an overloaded intrinsic. You can use llvm.is.constant with any argument type.
24484 declare i1 @llvm.is.constant.i32(i32 %operand) nounwind readnone
24485 declare i1 @llvm.is.constant.f32(float %operand) nounwind readnone
24486 declare i1 @llvm.is.constant.TYPENAME(TYPE %operand) nounwind readnone
24491 The '``llvm.is.constant``' intrinsic will return true if the argument
24492 is known to be a manifest compile-time constant. It is guaranteed to
24493 fold to either true or false before generating machine code.
24498 This intrinsic generates no code. If its argument is known to be a
24499 manifest compile-time constant value, then the intrinsic will be
24500 converted to a constant true value. Otherwise, it will be converted to
24501 a constant false value.
24503 In particular, note that if the argument is a constant expression
24504 which refers to a global (the address of which _is_ a constant, but
24505 not manifest during the compile), then the intrinsic evaluates to
24508 The result also intentionally depends on the result of optimization
24509 passes -- e.g., the result can change depending on whether a
24510 function gets inlined or not. A function's parameters are
24511 obviously not constant. However, a call like
24512 ``llvm.is.constant.i32(i32 %param)`` *can* return true after the
24513 function is inlined, if the value passed to the function parameter was
24516 On the other hand, if constant folding is not run, it will never
24517 evaluate to true, even in simple cases.
24521 '``llvm.ptrmask``' Intrinsic
24522 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24529 declare ptrty llvm.ptrmask(ptrty %ptr, intty %mask) readnone speculatable
24534 The first argument is a pointer. The second argument is an integer.
24539 The ``llvm.ptrmask`` intrinsic masks out bits of the pointer according to a mask.
24540 This allows stripping data from tagged pointers without converting them to an
24541 integer (ptrtoint/inttoptr). As a consequence, we can preserve more information
24542 to facilitate alias analysis and underlying-object detection.
24547 The result of ``ptrmask(ptr, mask)`` is equivalent to
24548 ``getelementptr ptr, (ptrtoint(ptr) & mask) - ptrtoint(ptr)``. Both the returned
24549 pointer and the first argument are based on the same underlying object (for more
24550 information on the *based on* terminology see
24551 :ref:`the pointer aliasing rules <pointeraliasing>`). If the bitwidth of the
24552 mask argument does not match the pointer size of the target, the mask is
24553 zero-extended or truncated accordingly.
24555 .. _int_threadlocal_address:
24557 '``llvm.threadlocal.address``' Intrinsic
24558 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24565 declare ptr @llvm.threadlocal.address(ptr) nounwind readnone willreturn
24570 The first argument is a pointer, which refers to a thread local global.
24575 The address of a thread local global is not a constant, since it depends on
24576 the calling thread. The `llvm.threadlocal.address` intrinsic returns the
24577 address of the given thread local global in the calling thread.
24581 '``llvm.vscale``' Intrinsic
24582 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
24589 declare i32 llvm.vscale.i32()
24590 declare i64 llvm.vscale.i64()
24595 The ``llvm.vscale`` intrinsic returns the value for ``vscale`` in scalable
24596 vectors such as ``<vscale x 16 x i8>``.
24601 ``vscale`` is a positive value that is constant throughout program
24602 execution, but is unknown at compile time.
24603 If the result value does not fit in the result type, then the result is
24604 a :ref:`poison value <poisonvalues>`.
24607 Stack Map Intrinsics
24608 --------------------
24610 LLVM provides experimental intrinsics to support runtime patching
24611 mechanisms commonly desired in dynamic language JITs. These intrinsics
24612 are described in :doc:`StackMaps`.
24614 Element Wise Atomic Memory Intrinsics
24615 -------------------------------------
24617 These intrinsics are similar to the standard library memory intrinsics except
24618 that they perform memory transfer as a sequence of atomic memory accesses.
24620 .. _int_memcpy_element_unordered_atomic:
24622 '``llvm.memcpy.element.unordered.atomic``' Intrinsic
24623 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24628 This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on
24629 any integer bit width and for different address spaces. Not all targets
24630 support all bit widths however.
24634 declare void @llvm.memcpy.element.unordered.atomic.p0.p0.i32(ptr <dest>,
24637 i32 <element_size>)
24638 declare void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr <dest>,
24641 i32 <element_size>)
24646 The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the
24647 '``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated
24648 as arrays with elements that are exactly ``element_size`` bytes, and the copy between
24649 buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations
24650 that are a positive integer multiple of the ``element_size`` in size.
24655 The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>`
24656 intrinsic, with the added constraint that ``len`` is required to be a positive integer
24657 multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
24658 ``element_size``, then the behaviour of the intrinsic is undefined.
24660 ``element_size`` must be a compile-time constant positive power of two no greater than
24661 target-specific atomic access size limit.
24663 For each of the input pointers ``align`` parameter attribute must be specified. It
24664 must be a power of two no less than the ``element_size``. Caller guarantees that
24665 both the source and destination pointers are aligned to that boundary.
24670 The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of
24671 memory from the source location to the destination location. These locations are not
24672 allowed to overlap. The memory copy is performed as a sequence of load/store operations
24673 where each access is guaranteed to be a multiple of ``element_size`` bytes wide and
24674 aligned at an ``element_size`` boundary.
24676 The order of the copy is unspecified. The same value may be read from the source
24677 buffer many times, but only one write is issued to the destination buffer per
24678 element. It is well defined to have concurrent reads and writes to both source and
24679 destination provided those reads and writes are unordered atomic when specified.
24681 This intrinsic does not provide any additional ordering guarantees over those
24682 provided by a set of unordered loads from the source location and stores to the
24688 In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is
24689 lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*'
24690 is replaced with an actual element size. See :ref:`RewriteStatepointsForGC intrinsic
24691 lowering <RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific
24694 Optimizer is allowed to inline memory copy when it's profitable to do so.
24696 '``llvm.memmove.element.unordered.atomic``' Intrinsic
24697 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24702 This is an overloaded intrinsic. You can use
24703 ``llvm.memmove.element.unordered.atomic`` on any integer bit width and for
24704 different address spaces. Not all targets support all bit widths however.
24708 declare void @llvm.memmove.element.unordered.atomic.p0.p0.i32(ptr <dest>,
24711 i32 <element_size>)
24712 declare void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr <dest>,
24715 i32 <element_size>)
24720 The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization
24721 of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and
24722 ``src`` are treated as arrays with elements that are exactly ``element_size``
24723 bytes, and the copy between buffers uses a sequence of
24724 :ref:`unordered atomic <ordering>` load/store operations that are a positive
24725 integer multiple of the ``element_size`` in size.
24730 The first three arguments are the same as they are in the
24731 :ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that
24732 ``len`` is required to be a positive integer multiple of the ``element_size``.
24733 If ``len`` is not a positive integer multiple of ``element_size``, then the
24734 behaviour of the intrinsic is undefined.
24736 ``element_size`` must be a compile-time constant positive power of two no
24737 greater than a target-specific atomic access size limit.
24739 For each of the input pointers the ``align`` parameter attribute must be
24740 specified. It must be a power of two no less than the ``element_size``. Caller
24741 guarantees that both the source and destination pointers are aligned to that
24747 The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes
24748 of memory from the source location to the destination location. These locations
24749 are allowed to overlap. The memory copy is performed as a sequence of load/store
24750 operations where each access is guaranteed to be a multiple of ``element_size``
24751 bytes wide and aligned at an ``element_size`` boundary.
24753 The order of the copy is unspecified. The same value may be read from the source
24754 buffer many times, but only one write is issued to the destination buffer per
24755 element. It is well defined to have concurrent reads and writes to both source
24756 and destination provided those reads and writes are unordered atomic when
24759 This intrinsic does not provide any additional ordering guarantees over those
24760 provided by a set of unordered loads from the source location and stores to the
24766 In the most general case call to the
24767 '``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol
24768 ``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an
24769 actual element size. See :ref:`RewriteStatepointsForGC intrinsic lowering
24770 <RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific
24773 The optimizer is allowed to inline the memory copy when it's profitable to do so.
24775 .. _int_memset_element_unordered_atomic:
24777 '``llvm.memset.element.unordered.atomic``' Intrinsic
24778 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24783 This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on
24784 any integer bit width and for different address spaces. Not all targets
24785 support all bit widths however.
24789 declare void @llvm.memset.element.unordered.atomic.p0.i32(ptr <dest>,
24792 i32 <element_size>)
24793 declare void @llvm.memset.element.unordered.atomic.p0.i64(ptr <dest>,
24796 i32 <element_size>)
24801 The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the
24802 '``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array
24803 with elements that are exactly ``element_size`` bytes, and the assignment to that array
24804 uses uses a sequence of :ref:`unordered atomic <ordering>` store operations
24805 that are a positive integer multiple of the ``element_size`` in size.
24810 The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>`
24811 intrinsic, with the added constraint that ``len`` is required to be a positive integer
24812 multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
24813 ``element_size``, then the behaviour of the intrinsic is undefined.
24815 ``element_size`` must be a compile-time constant positive power of two no greater than
24816 target-specific atomic access size limit.
24818 The ``dest`` input pointer must have the ``align`` parameter attribute specified. It
24819 must be a power of two no less than the ``element_size``. Caller guarantees that
24820 the destination pointer is aligned to that boundary.
24825 The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of
24826 memory starting at the destination location to the given ``value``. The memory is
24827 set with a sequence of store operations where each access is guaranteed to be a
24828 multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary.
24830 The order of the assignment is unspecified. Only one write is issued to the
24831 destination buffer per element. It is well defined to have concurrent reads and
24832 writes to the destination provided those reads and writes are unordered atomic
24835 This intrinsic does not provide any additional ordering guarantees over those
24836 provided by a set of unordered stores to the destination.
24841 In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is
24842 lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*'
24843 is replaced with an actual element size.
24845 The optimizer is allowed to inline the memory assignment when it's profitable to do so.
24847 Objective-C ARC Runtime Intrinsics
24848 ----------------------------------
24850 LLVM provides intrinsics that lower to Objective-C ARC runtime entry points.
24851 LLVM is aware of the semantics of these functions, and optimizes based on that
24852 knowledge. You can read more about the details of Objective-C ARC `here
24853 <https://clang.llvm.org/docs/AutomaticReferenceCounting.html>`_.
24855 '``llvm.objc.autorelease``' Intrinsic
24856 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24862 declare ptr @llvm.objc.autorelease(ptr)
24867 Lowers to a call to `objc_autorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autorelease>`_.
24869 '``llvm.objc.autoreleasePoolPop``' Intrinsic
24870 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24876 declare void @llvm.objc.autoreleasePoolPop(ptr)
24881 Lowers to a call to `objc_autoreleasePoolPop <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpop-void-pool>`_.
24883 '``llvm.objc.autoreleasePoolPush``' Intrinsic
24884 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24890 declare ptr @llvm.objc.autoreleasePoolPush()
24895 Lowers to a call to `objc_autoreleasePoolPush <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpush-void>`_.
24897 '``llvm.objc.autoreleaseReturnValue``' Intrinsic
24898 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24904 declare ptr @llvm.objc.autoreleaseReturnValue(ptr)
24909 Lowers to a call to `objc_autoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue>`_.
24911 '``llvm.objc.copyWeak``' Intrinsic
24912 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24918 declare void @llvm.objc.copyWeak(ptr, ptr)
24923 Lowers to a call to `objc_copyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-copyweak-id-dest-id-src>`_.
24925 '``llvm.objc.destroyWeak``' Intrinsic
24926 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24932 declare void @llvm.objc.destroyWeak(ptr)
24937 Lowers to a call to `objc_destroyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-destroyweak-id-object>`_.
24939 '``llvm.objc.initWeak``' Intrinsic
24940 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24946 declare ptr @llvm.objc.initWeak(ptr, ptr)
24951 Lowers to a call to `objc_initWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-initweak>`_.
24953 '``llvm.objc.loadWeak``' Intrinsic
24954 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24960 declare ptr @llvm.objc.loadWeak(ptr)
24965 Lowers to a call to `objc_loadWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweak>`_.
24967 '``llvm.objc.loadWeakRetained``' Intrinsic
24968 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24974 declare ptr @llvm.objc.loadWeakRetained(ptr)
24979 Lowers to a call to `objc_loadWeakRetained <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweakretained>`_.
24981 '``llvm.objc.moveWeak``' Intrinsic
24982 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24988 declare void @llvm.objc.moveWeak(ptr, ptr)
24993 Lowers to a call to `objc_moveWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-moveweak-id-dest-id-src>`_.
24995 '``llvm.objc.release``' Intrinsic
24996 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25002 declare void @llvm.objc.release(ptr)
25007 Lowers to a call to `objc_release <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-release-id-value>`_.
25009 '``llvm.objc.retain``' Intrinsic
25010 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25016 declare ptr @llvm.objc.retain(ptr)
25021 Lowers to a call to `objc_retain <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>`_.
25023 '``llvm.objc.retainAutorelease``' Intrinsic
25024 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25030 declare ptr @llvm.objc.retainAutorelease(ptr)
25035 Lowers to a call to `objc_retainAutorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautorelease>`_.
25037 '``llvm.objc.retainAutoreleaseReturnValue``' Intrinsic
25038 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25044 declare ptr @llvm.objc.retainAutoreleaseReturnValue(ptr)
25049 Lowers to a call to `objc_retainAutoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasereturnvalue>`_.
25051 '``llvm.objc.retainAutoreleasedReturnValue``' Intrinsic
25052 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25058 declare ptr @llvm.objc.retainAutoreleasedReturnValue(ptr)
25063 Lowers to a call to `objc_retainAutoreleasedReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasedreturnvalue>`_.
25065 '``llvm.objc.retainBlock``' Intrinsic
25066 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25072 declare ptr @llvm.objc.retainBlock(ptr)
25077 Lowers to a call to `objc_retainBlock <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainblock>`_.
25079 '``llvm.objc.storeStrong``' Intrinsic
25080 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25086 declare void @llvm.objc.storeStrong(ptr, ptr)
25091 Lowers to a call to `objc_storeStrong <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-storestrong-id-object-id-value>`_.
25093 '``llvm.objc.storeWeak``' Intrinsic
25094 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25100 declare ptr @llvm.objc.storeWeak(ptr, ptr)
25105 Lowers to a call to `objc_storeWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-storeweak>`_.
25107 Preserving Debug Information Intrinsics
25108 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25110 These intrinsics are used to carry certain debuginfo together with
25111 IR-level operations. For example, it may be desirable to
25112 know the structure/union name and the original user-level field
25113 indices. Such information got lost in IR GetElementPtr instruction
25114 since the IR types are different from debugInfo types and unions
25115 are converted to structs in IR.
25117 '``llvm.preserve.array.access.index``' Intrinsic
25118 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25125 @llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons(<type> base,
25132 The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address
25133 based on array base ``base``, array dimension ``dim`` and the last access index ``index``
25134 into the array. The return type ``ret_type`` is a pointer type to the array element.
25135 The array ``dim`` and ``index`` are preserved which is more robust than
25136 getelementptr instruction which may be subject to compiler transformation.
25137 The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
25138 to provide array or pointer debuginfo type.
25139 The metadata is a ``DICompositeType`` or ``DIDerivedType`` representing the
25140 debuginfo version of ``type``.
25145 The ``base`` is the array base address. The ``dim`` is the array dimension.
25146 The ``base`` is a pointer if ``dim`` equals 0.
25147 The ``index`` is the last access index into the array or pointer.
25149 The ``base`` argument must be annotated with an :ref:`elementtype
25150 <attr_elementtype>` attribute at the call-site. This attribute specifies the
25151 getelementptr element type.
25156 The '``llvm.preserve.array.access.index``' intrinsic produces the same result
25157 as a getelementptr with base ``base`` and access operands ``{dim's 0's, index}``.
25159 '``llvm.preserve.union.access.index``' Intrinsic
25160 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25167 @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(<type> base,
25173 The '``llvm.preserve.union.access.index``' intrinsic carries the debuginfo field index
25174 ``di_index`` and returns the ``base`` address.
25175 The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
25176 to provide union debuginfo type.
25177 The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
25178 The return type ``type`` is the same as the ``base`` type.
25183 The ``base`` is the union base address. The ``di_index`` is the field index in debuginfo.
25188 The '``llvm.preserve.union.access.index``' intrinsic returns the ``base`` address.
25190 '``llvm.preserve.struct.access.index``' Intrinsic
25191 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25198 @llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s(<type> base,
25205 The '``llvm.preserve.struct.access.index``' intrinsic returns the getelementptr address
25206 based on struct base ``base`` and IR struct member index ``gep_index``.
25207 The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction
25208 to provide struct debuginfo type.
25209 The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``.
25210 The return type ``ret_type`` is a pointer type to the structure member.
25215 The ``base`` is the structure base address. The ``gep_index`` is the struct member index
25216 based on IR structures. The ``di_index`` is the struct member index based on debuginfo.
25218 The ``base`` argument must be annotated with an :ref:`elementtype
25219 <attr_elementtype>` attribute at the call-site. This attribute specifies the
25220 getelementptr element type.
25225 The '``llvm.preserve.struct.access.index``' intrinsic produces the same result
25226 as a getelementptr with base ``base`` and access operands ``{0, gep_index}``.
25228 '``llvm.fptrunc.round``' Intrinsic
25229 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25237 @llvm.fptrunc.round(<type> <value>, metadata <rounding mode>)
25242 The '``llvm.fptrunc.round``' intrinsic truncates
25243 :ref:`floating-point <t_floating>` ``value`` to type ``ty2``
25244 with a specified rounding mode.
25249 The '``llvm.fptrunc.round``' intrinsic takes a :ref:`floating-point
25250 <t_floating>` value to cast and a :ref:`floating-point <t_floating>` type
25251 to cast it to. This argument must be larger in size than the result.
25253 The second argument specifies the rounding mode as described in the constrained
25254 intrinsics section.
25255 For this intrinsic, the "round.dynamic" mode is not supported.
25260 The '``llvm.fptrunc.round``' intrinsic casts a ``value`` from a larger
25261 :ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
25262 <t_floating>` type.
25263 This intrinsic is assumed to execute in the default :ref:`floating-point
25264 environment <floatenv>` *except* for the rounding mode.
25265 This intrinsic is not supported on all targets. Some targets may not support
25266 all rounding modes.