1============================== 2LLVM Language Reference Manual 3============================== 4 5.. contents:: 6 :local: 7 :depth: 3 8 9Abstract 10======== 11 12This document is a reference manual for the LLVM assembly language. LLVM 13is a Static Single Assignment (SSA) based representation that provides 14type safety, low-level operations, flexibility, and the capability of 15representing 'all' high-level languages cleanly. It is the common code 16representation used throughout all phases of the LLVM compilation 17strategy. 18 19Introduction 20============ 21 22The LLVM code representation is designed to be used in three different 23forms: as an in-memory compiler IR, as an on-disk bitcode representation 24(suitable for fast loading by a Just-In-Time compiler), and as a human 25readable assembly language representation. This allows LLVM to provide a 26powerful intermediate representation for efficient compiler 27transformations and analysis, while providing a natural means to debug 28and visualize the transformations. The three different forms of LLVM are 29all equivalent. This document describes the human readable 30representation and notation. 31 32The LLVM representation aims to be light-weight and low-level while 33being expressive, typed, and extensible at the same time. It aims to be 34a "universal IR" of sorts, by being at a low enough level that 35high-level ideas may be cleanly mapped to it (similar to how 36microprocessors are "universal IR's", allowing many source languages to 37be mapped to them). By providing type information, LLVM can be used as 38the target of optimizations: for example, through pointer analysis, it 39can be proven that a C automatic variable is never accessed outside of 40the current function, allowing it to be promoted to a simple SSA value 41instead of a memory location. 42 43.. _wellformed: 44 45Well-Formedness 46--------------- 47 48It is important to note that this document describes 'well formed' LLVM 49assembly language. There is a difference between what the parser accepts 50and what is considered 'well formed'. For example, the following 51instruction is syntactically okay, but not well formed: 52 53.. code-block:: llvm 54 55 %x = add i32 1, %x 56 57because the definition of ``%x`` does not dominate all of its uses. The 58LLVM infrastructure provides a verification pass that may be used to 59verify that an LLVM module is well formed. This pass is automatically 60run by the parser after parsing input assembly and by the optimizer 61before it outputs bitcode. The violations pointed out by the verifier 62pass indicate bugs in transformation passes or input to the parser. 63 64.. _identifiers: 65 66Identifiers 67=========== 68 69LLVM identifiers come in two basic types: global and local. Global 70identifiers (functions, global variables) begin with the ``'@'`` 71character. Local identifiers (register names, types) begin with the 72``'%'`` character. Additionally, there are three different formats for 73identifiers, for different purposes: 74 75#. Named values are represented as a string of characters with their 76 prefix. For example, ``%foo``, ``@DivisionByZero``, 77 ``%a.really.long.identifier``. The actual regular expression used is 78 '``[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*``'. Identifiers that require other 79 characters in their names can be surrounded with quotes. Special 80 characters may be escaped using ``"\xx"`` where ``xx`` is the ASCII 81 code for the character in hexadecimal. In this way, any character can 82 be used in a name value, even quotes themselves. The ``"\01"`` prefix 83 can be used on global values to suppress mangling. 84#. Unnamed values are represented as an unsigned numeric value with 85 their prefix. For example, ``%12``, ``@2``, ``%44``. 86#. Constants, which are described in the section Constants_ below. 87 88LLVM requires that values start with a prefix for two reasons: Compilers 89don't need to worry about name clashes with reserved words, and the set 90of reserved words may be expanded in the future without penalty. 91Additionally, unnamed identifiers allow a compiler to quickly come up 92with a temporary variable without having to avoid symbol table 93conflicts. 94 95Reserved words in LLVM are very similar to reserved words in other 96languages. There are keywords for different opcodes ('``add``', 97'``bitcast``', '``ret``', etc...), for primitive type names ('``void``', 98'``i32``', etc...), and others. These reserved words cannot conflict 99with variable names, because none of them start with a prefix character 100(``'%'`` or ``'@'``). 101 102Here is an example of LLVM code to multiply the integer variable 103'``%X``' by 8: 104 105The easy way: 106 107.. code-block:: llvm 108 109 %result = mul i32 %X, 8 110 111After strength reduction: 112 113.. code-block:: llvm 114 115 %result = shl i32 %X, 3 116 117And the hard way: 118 119.. code-block:: llvm 120 121 %0 = add i32 %X, %X ; yields i32:%0 122 %1 = add i32 %0, %0 ; yields i32:%1 123 %result = add i32 %1, %1 124 125This last way of multiplying ``%X`` by 8 illustrates several important 126lexical features of LLVM: 127 128#. Comments are delimited with a '``;``' and go until the end of line. 129#. Unnamed temporaries are created when the result of a computation is 130 not assigned to a named value. 131#. Unnamed temporaries are numbered sequentially (using a per-function 132 incrementing counter, starting with 0). Note that basic blocks and unnamed 133 function parameters are included in this numbering. For example, if the 134 entry basic block is not given a label name and all function parameters are 135 named, then it will get number 0. 136 137It also shows a convention that we follow in this document. When 138demonstrating instructions, we will follow an instruction with a comment 139that defines the type and name of value produced. 140 141High Level Structure 142==================== 143 144Module Structure 145---------------- 146 147LLVM programs are composed of ``Module``'s, each of which is a 148translation unit of the input programs. Each module consists of 149functions, global variables, and symbol table entries. Modules may be 150combined together with the LLVM linker, which merges function (and 151global variable) definitions, resolves forward declarations, and merges 152symbol table entries. Here is an example of the "hello world" module: 153 154.. code-block:: llvm 155 156 ; Declare the string constant as a global constant. 157 @.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00" 158 159 ; External declaration of the puts function 160 declare i32 @puts(ptr nocapture) nounwind 161 162 ; Definition of main function 163 define i32 @main() { 164 ; Call puts function to write out the string to stdout. 165 call i32 @puts(ptr @.str) 166 ret i32 0 167 } 168 169 ; Named metadata 170 !0 = !{i32 42, null, !"string"} 171 !foo = !{!0} 172 173This 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``". 177 178In general, a module is made up of a list of global values (where both 179functions and global variables are global values). Global values are 180represented by a pointer to a memory location (in this case, a pointer 181to an array of char, and a pointer to a function), and have one of the 182following :ref:`linkage types <linkage>`. 183 184.. _linkage: 185 186Linkage Types 187------------- 188 189All Global Variables and Functions have one of the following types of 190linkage: 191 192``private`` 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. 199``internal`` 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. 213``linkonce`` 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. 226``weak`` 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" 230 in C source code. 231``common`` 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 239 common linkage. 240 241.. _linkage_appending: 242 243``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 249 .o files are linked. 250 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. 254 255``extern_weak`` 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. 267``external`` 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. 271 272It is illegal for a global variable or function *declaration* to have any 273linkage type other than ``external`` or ``extern_weak``. 274 275.. _callingconv: 276 277Calling Conventions 278------------------- 279 280LLVM :ref:`functions <functionstructure>`, :ref:`calls <i_call>` and 281:ref:`invokes <i_invoke>` can all have an optional calling convention 282specified for the call. The calling convention of any pair of dynamic 283caller/callee must match, or the behavior of the program is undefined. 284The following calling conventions are supported by LLVM, and more may be 285added in the future: 286 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 311 calls for inlining. 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 321 limitations: 322 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. 327 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 345 bit). 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. 367 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. 371 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. 383 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 390 future. 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. 401 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). 405 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. 408 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 417 sequence. 418 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). 422 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. 426 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`. 429 430 - On X86-64 the callee preserves all general purpose registers, except for 431 RDI and RAX. 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. 444"``swifttailcc``" 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. 455 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. 463 464More calling conventions can be added/defined on an as-needed basis, to 465support Pascal conventions or any other well-known target-independent 466convention. 467 468.. _visibilitystyles: 469 470Visibility Styles 471----------------- 472 473All Global Variables and Functions have one of the following visibility 474styles: 475 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. 497 498A symbol with ``internal`` or ``private`` linkage must have ``default`` 499visibility. 500 501.. _dllstorageclass: 502 503DLL Storage Classes 504------------------- 505 506All Global Variables, Functions and Aliases can have one of the following 507DLL storage class: 508 509``dllimport`` 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. 514``dllexport`` 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 523 deleting the symbol. 524 525A symbol with ``internal`` or ``private`` linkage cannot have a DLL storage 526class. 527 528.. _tls_model: 529 530Thread Local Storage Models 531--------------------------- 532 533A variable may be defined as ``thread_local``, which means that it will 534not be shared by threads (each thread will have a separated copy of the 535variable). Not all targets support thread-local variables. Optionally, a 536TLS model may be specified: 537 538``localdynamic`` 539 For variables that are only used within the current shared library. 540``initialexec`` 541 For variables in modules that will not be loaded dynamically. 542``localexec`` 543 For variables defined in the executable and only used within it. 544 545If no explicit model is given, the "general dynamic" model is used. 546 547The models correspond to the ELF TLS models; see `ELF Handling For 548Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for 549more information on under which circumstances the different models may 550be used. The target may choose a different TLS model if the specified 551model is not supported, or if a better choice of model can be made. 552 553A model can also be specified in an alias, but then it only governs how 554the alias is accessed. It will not have any effect in the aliasee. 555 556For platforms without linker support of ELF TLS model, the -femulated-tls 557flag can be used to generate GCC compatible emulated TLS code. 558 559.. _runtime_preemption_model: 560 561Runtime Preemption Specifiers 562----------------------------- 563 564Global variables, functions and aliases may have an optional runtime preemption 565specifier. If a preemption specifier isn't given explicitly, then a 566symbol is assumed to be ``dso_preemptable``. 567 568``dso_preemptable`` 569 Indicates that the function or variable may be replaced by a symbol from 570 outside the linkage unit at runtime. 571 572``dso_local`` 573 The compiler may assume that a function or variable marked as ``dso_local`` 574 will resolve to a symbol within the same linkage unit. Direct access will 575 be generated even if the definition is not within this compilation unit. 576 577.. _namedtypes: 578 579Structure Types 580--------------- 581 582LLVM IR allows you to specify both "identified" and "literal" :ref:`structure 583types <t_struct>`. Literal types are uniqued structurally, but identified types 584are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used 585to forward declare a type that is not yet available. 586 587An example of an identified structure specification is: 588 589.. code-block:: llvm 590 591 %mytype = type { %mytype*, i32 } 592 593Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only 594literal types are uniqued in recent versions of LLVM. 595 596.. _nointptrtype: 597 598Non-Integral Pointer Type 599------------------------- 600 601Note: non-integral pointer types are a work in progress, and they should be 602considered experimental at this time. 603 604LLVM IR optionally allows the frontend to denote pointers in certain address 605spaces as "non-integral" via the :ref:`datalayout string<langref_datalayout>`. 606Non-integral pointer types represent pointers that have an *unspecified* bitwise 607representation; that is, the integral representation may be target dependent or 608unstable (not backed by a fixed integer). 609 610``inttoptr`` and ``ptrtoint`` instructions have the same semantics as for 611integral (i.e. normal) pointers in that they convert integers to and from 612corresponding pointer types, but there are additional implications to be 613aware of. Because the bit-representation of a non-integral pointer may 614not be stable, two identical casts of the same operand may or may not 615return the same value. Said differently, the conversion to or from the 616non-integral type depends on environmental state in an implementation 617defined manner. 618 619If the frontend wishes to observe a *particular* value following a cast, the 620generated IR must fence with the underlying environment in an implementation 621defined manner. (In practice, this tends to require ``noinline`` routines for 622such operations.) 623 624From the perspective of the optimizer, ``inttoptr`` and ``ptrtoint`` for 625non-integral types are analogous to ones on integral types with one 626key exception: the optimizer may not, in general, insert new dynamic 627occurrences of such casts. If a new cast is inserted, the optimizer would 628need to either ensure that a) all possible values are valid, or b) 629appropriate fencing is inserted. Since the appropriate fencing is 630implementation defined, the optimizer can't do the latter. The former is 631challenging as many commonly expected properties, such as 632``ptrtoint(v)-ptrtoint(v) == 0``, don't hold for non-integral types. 633 634.. _globalvars: 635 636Global Variables 637---------------- 638 639Global variables define regions of memory allocated at compilation time 640instead of run-time. 641 642Global variable definitions must be initialized. 643 644Global variables in other translation units can also be declared, in which 645case they don't have an initializer. 646 647Global variables can optionally specify a :ref:`linkage type <linkage>`. 648 649Either global variable definitions or declarations may have an explicit section 650to be placed in and may have an optional explicit alignment specified. If there 651is a mismatch between the explicit or inferred section information for the 652variable declaration and its definition the resulting behavior is undefined. 653 654A variable may be defined as a global ``constant``, which indicates that 655the contents of the variable will **never** be modified (enabling better 656optimization, allowing the global data to be placed in the read-only 657section of an executable, etc). Note that variables that need runtime 658initialization cannot be marked ``constant`` as there is a store to the 659variable. 660 661LLVM explicitly allows *declarations* of global variables to be marked 662constant, even if the final definition of the global is not. This 663capability can be used to enable slightly better optimization of the 664program, but requires the language definition to guarantee that 665optimizations based on the 'constantness' are valid for the translation 666units that do not include the definition. 667 668As SSA values, global variables define pointer values that are in scope 669(i.e. they dominate) all basic blocks in the program. Global variables 670always define a pointer to their "content" type because they describe a 671region of memory, and all memory objects in LLVM are accessed through 672pointers. 673 674Global variables can be marked with ``unnamed_addr`` which indicates 675that the address is not significant, only the content. Constants marked 676like this can be merged with other constants if they have the same 677initializer. Note that a constant with significant address *can* be 678merged with a ``unnamed_addr`` constant, the result being a constant 679whose address is significant. 680 681If the ``local_unnamed_addr`` attribute is given, the address is known to 682not be significant within the module. 683 684A global variable may be declared to reside in a target-specific 685numbered address space. For targets that support them, address spaces 686may affect how optimizations are performed and/or what target 687instructions are used to access the variable. The default address space 688is zero. The address space qualifier must precede any other attributes. 689 690LLVM allows an explicit section to be specified for globals. If the 691target supports it, it will emit globals to the section specified. 692Additionally, the global can placed in a comdat if the target has the necessary 693support. 694 695External declarations may have an explicit section specified. Section 696information is retained in LLVM IR for targets that make use of this 697information. Attaching section information to an external declaration is an 698assertion that its definition is located in the specified section. If the 699definition is located in a different section, the behavior is undefined. 700 701By default, global initializers are optimized by assuming that global 702variables defined within the module are not modified from their 703initial values before the start of the global initializer. This is 704true even for variables potentially accessible from outside the 705module, including those with external linkage or appearing in 706``@llvm.used`` or dllexported variables. This assumption may be suppressed 707by marking the variable with ``externally_initialized``. 708 709An explicit alignment may be specified for a global, which must be a 710power of 2. If not present, or if the alignment is set to zero, the 711alignment of the global is set by the target to whatever it feels 712convenient. If an explicit alignment is specified, the global is forced 713to have exactly that alignment. Targets and optimizers are not allowed 714to over-align the global if the global has an assigned section. In this 715case, the extra alignment could be observable: for example, code could 716assume that the globals are densely packed in their section and try to 717iterate over them as an array, alignment padding would break this 718iteration. The maximum alignment is ``1 << 32``. 719 720For global variables declarations, as well as definitions that may be 721replaced at link time (``linkonce``, ``weak``, ``extern_weak`` and ``common`` 722linkage types), LLVM makes no assumptions about the allocation size of the 723variables, except that they may not overlap. The alignment of a global variable 724declaration or replaceable definition must not be greater than the alignment of 725the definition it resolves to. 726 727Globals can also have a :ref:`DLL storage class <dllstorageclass>`, 728an optional :ref:`runtime preemption specifier <runtime_preemption_model>`, 729an optional :ref:`global attributes <glattrs>` and 730an optional list of attached :ref:`metadata <metadata>`. 731 732Variables and aliases can have a 733:ref:`Thread Local Storage Model <tls_model>`. 734 735:ref:`Scalable vectors <t_vector>` cannot be global variables or members of 736arrays because their size is unknown at compile time. They are allowed in 737structs to facilitate intrinsics returning multiple values. Structs containing 738scalable vectors cannot be used in loads, stores, allocas, or GEPs. 739 740Syntax:: 741 742 @<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility] 743 [DLLStorageClass] [ThreadLocal] 744 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] 745 [ExternallyInitialized] 746 <global | constant> <Type> [<InitializerConstant>] 747 [, section "name"] [, partition "name"] 748 [, comdat [($name)]] [, align <Alignment>] 749 [, no_sanitize_address] [, no_sanitize_hwaddress] 750 [, sanitize_address_dyninit] [, sanitize_memtag] 751 (, !name !N)* 752 753For example, the following defines a global in a numbered address space 754with an initializer, section, and alignment: 755 756.. code-block:: llvm 757 758 @G = addrspace(5) constant float 1.0, section "foo", align 4 759 760The following example just declares a global variable 761 762.. code-block:: llvm 763 764 @G = external global i32 765 766The following example defines a thread-local global with the 767``initialexec`` TLS model: 768 769.. code-block:: llvm 770 771 @G = thread_local(initialexec) global i32 0, align 4 772 773.. _functionstructure: 774 775Functions 776--------- 777 778LLVM function definitions consist of the "``define``" keyword, an 779optional :ref:`linkage type <linkage>`, an optional :ref:`runtime preemption 780specifier <runtime_preemption_model>`, an optional :ref:`visibility 781style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, 782an optional :ref:`calling convention <callingconv>`, 783an optional ``unnamed_addr`` attribute, a return type, an optional 784:ref:`parameter attribute <paramattrs>` for the return type, a function 785name, a (possibly empty) argument list (each with optional :ref:`parameter 786attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`, 787an optional address space, an optional section, an optional partition, 788an optional alignment, an optional :ref:`comdat <langref_comdats>`, 789an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`, 790an optional :ref:`prologue <prologuedata>`, 791an optional :ref:`personality <personalityfn>`, 792an optional list of attached :ref:`metadata <metadata>`, 793an opening curly brace, a list of basic blocks, and a closing curly brace. 794 795Syntax:: 796 797 define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass] 798 [cconv] [ret attrs] 799 <ResultType> @<FunctionName> ([argument list]) 800 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs] 801 [section "name"] [partition "name"] [comdat [($name)]] [align N] 802 [gc] [prefix Constant] [prologue Constant] [personality Constant] 803 (!name !N)* { ... } 804 805The argument list is a comma separated sequence of arguments where each 806argument is of the following form: 807 808Syntax:: 809 810 <type> [parameter Attrs] [name] 811 812LLVM function declarations consist of the "``declare``" keyword, an 813optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style 814<visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an 815optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr`` 816or ``local_unnamed_addr`` attribute, an optional address space, a return type, 817an optional :ref:`parameter attribute <paramattrs>` for the return type, a function name, a possibly 818empty list of arguments, an optional alignment, an optional :ref:`garbage 819collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional 820:ref:`prologue <prologuedata>`. 821 822Syntax:: 823 824 declare [linkage] [visibility] [DLLStorageClass] 825 [cconv] [ret attrs] 826 <ResultType> @<FunctionName> ([argument list]) 827 [(unnamed_addr|local_unnamed_addr)] [align N] [gc] 828 [prefix Constant] [prologue Constant] 829 830A function definition contains a list of basic blocks, forming the CFG (Control 831Flow Graph) for the function. Each basic block may optionally start with a label 832(giving the basic block a symbol table entry), contains a list of instructions, 833and ends with a :ref:`terminator <terminators>` instruction (such as a branch or 834function return). If an explicit label name is not provided, a block is assigned 835an implicit numbered label, using the next value from the same counter as used 836for unnamed temporaries (:ref:`see above<identifiers>`). For example, if a 837function entry block does not have an explicit label, it will be assigned label 838"%0", then the first unnamed temporary in that block will be "%1", etc. If a 839numeric label is explicitly specified, it must match the numeric label that 840would be used implicitly. 841 842The first basic block in a function is special in two ways: it is 843immediately executed on entrance to the function, and it is not allowed 844to have predecessor basic blocks (i.e. there can not be any branches to 845the entry block of a function). Because the block can have no 846predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`. 847 848LLVM allows an explicit section to be specified for functions. If the 849target supports it, it will emit functions to the section specified. 850Additionally, the function can be placed in a COMDAT. 851 852An explicit alignment may be specified for a function. If not present, 853or if the alignment is set to zero, the alignment of the function is set 854by the target to whatever it feels convenient. If an explicit alignment 855is specified, the function is forced to have at least that much 856alignment. All alignments must be a power of 2. 857 858If the ``unnamed_addr`` attribute is given, the address is known to not 859be significant and two identical functions can be merged. 860 861If the ``local_unnamed_addr`` attribute is given, the address is known to 862not be significant within the module. 863 864If an explicit address space is not given, it will default to the program 865address space from the :ref:`datalayout string<langref_datalayout>`. 866 867.. _langref_aliases: 868 869Aliases 870------- 871 872Aliases, unlike function or variables, don't create any new data. They 873are just a new symbol and metadata for an existing position. 874 875Aliases have a name and an aliasee that is either a global value or a 876constant expression. 877 878Aliases may have an optional :ref:`linkage type <linkage>`, an optional 879:ref:`runtime preemption specifier <runtime_preemption_model>`, an optional 880:ref:`visibility style <visibility>`, an optional :ref:`DLL storage class 881<dllstorageclass>` and an optional :ref:`tls model <tls_model>`. 882 883Syntax:: 884 885 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee> 886 [, partition "name"] 887 888The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``, 889``linkonce_odr``, ``weak_odr``, ``external``, ``available_externally``. Note 890that some system linkers might not correctly handle dropping a weak symbol that 891is aliased. 892 893Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as 894the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point 895to the same content. 896 897If the ``local_unnamed_addr`` attribute is given, the address is known to 898not be significant within the module. 899 900Since aliases are only a second name, some restrictions apply, of which 901some can only be checked when producing an object file: 902 903* The expression defining the aliasee must be computable at assembly 904 time. Since it is just a name, no relocations can be used. 905 906* No alias in the expression can be weak as the possibility of the 907 intermediate alias being overridden cannot be represented in an 908 object file. 909 910* If the alias has the ``available_externally`` linkage, the aliasee must be an 911 ``available_externally`` global value; otherwise the aliasee can be an 912 expression but no global value in the expression can be a declaration, since 913 that would require a relocation, which is not possible. 914 915* If either the alias or the aliasee may be replaced by a symbol outside the 916 module at link time or runtime, any optimization cannot replace the alias with 917 the aliasee, since the behavior may be different. The alias may be used as a 918 name guaranteed to point to the content in the current module. 919 920.. _langref_ifunc: 921 922IFuncs 923------- 924 925IFuncs, like as aliases, don't create any new data or func. They are just a new 926symbol that dynamic linker resolves at runtime by calling a resolver function. 927 928IFuncs have a name and a resolver that is a function called by dynamic linker 929that returns address of another function associated with the name. 930 931IFunc may have an optional :ref:`linkage type <linkage>` and an optional 932:ref:`visibility style <visibility>`. 933 934Syntax:: 935 936 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver> 937 [, partition "name"] 938 939 940.. _langref_comdats: 941 942Comdats 943------- 944 945Comdat IR provides access to object file COMDAT/section group functionality 946which represents interrelated sections. 947 948Comdats have a name which represents the COMDAT key and a selection kind to 949provide input on how the linker deduplicates comdats with the same key in two 950different object files. A comdat must be included or omitted as a unit. 951Discarding the whole comdat is allowed but discarding a subset is not. 952 953A global object may be a member of at most one comdat. Aliases are placed in the 954same COMDAT that their aliasee computes to, if any. 955 956Syntax:: 957 958 $<Name> = comdat SelectionKind 959 960For selection kinds other than ``nodeduplicate``, only one of the duplicate 961comdats may be retained by the linker and the members of the remaining comdats 962must be discarded. The following selection kinds are supported: 963 964``any`` 965 The linker may choose any COMDAT key, the choice is arbitrary. 966``exactmatch`` 967 The linker may choose any COMDAT key but the sections must contain the 968 same data. 969``largest`` 970 The linker will choose the section containing the largest COMDAT key. 971``nodeduplicate`` 972 No deduplication is performed. 973``samesize`` 974 The linker may choose any COMDAT key but the sections must contain the 975 same amount of data. 976 977- XCOFF and Mach-O don't support COMDATs. 978- COFF supports all selection kinds. Non-``nodeduplicate`` selection kinds need 979 a non-local linkage COMDAT symbol. 980- ELF supports ``any`` and ``nodeduplicate``. 981- WebAssembly only supports ``any``. 982 983Here is an example of a COFF COMDAT where a function will only be selected if 984the COMDAT key's section is the largest: 985 986.. code-block:: text 987 988 $foo = comdat largest 989 @foo = global i32 2, comdat($foo) 990 991 define void @bar() comdat($foo) { 992 ret void 993 } 994 995In a COFF object file, this will create a COMDAT section with selection kind 996``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol 997and another COMDAT section with selection kind 998``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT 999section and contains the contents of the ``@bar`` symbol. 1000 1001As a syntactic sugar the ``$name`` can be omitted if the name is the same as 1002the global name: 1003 1004.. code-block:: llvm 1005 1006 $foo = comdat any 1007 @foo = global i32 2, comdat 1008 @bar = global i32 3, comdat($foo) 1009 1010There are some restrictions on the properties of the global object. 1011It, or an alias to it, must have the same name as the COMDAT group when 1012targeting COFF. 1013The contents and size of this object may be used during link-time to determine 1014which COMDAT groups get selected depending on the selection kind. 1015Because the name of the object must match the name of the COMDAT group, the 1016linkage of the global object must not be local; local symbols can get renamed 1017if a collision occurs in the symbol table. 1018 1019The combined use of COMDATS and section attributes may yield surprising results. 1020For example: 1021 1022.. code-block:: llvm 1023 1024 $foo = comdat any 1025 $bar = comdat any 1026 @g1 = global i32 42, section "sec", comdat($foo) 1027 @g2 = global i32 42, section "sec", comdat($bar) 1028 1029From the object file perspective, this requires the creation of two sections 1030with the same name. This is necessary because both globals belong to different 1031COMDAT groups and COMDATs, at the object file level, are represented by 1032sections. 1033 1034Note that certain IR constructs like global variables and functions may 1035create COMDATs in the object file in addition to any which are specified using 1036COMDAT IR. This arises when the code generator is configured to emit globals 1037in individual sections (e.g. when `-data-sections` or `-function-sections` 1038is supplied to `llc`). 1039 1040.. _namedmetadatastructure: 1041 1042Named Metadata 1043-------------- 1044 1045Named metadata is a collection of metadata. :ref:`Metadata 1046nodes <metadata>` (but not metadata strings) are the only valid 1047operands for a named metadata. 1048 1049#. Named metadata are represented as a string of characters with the 1050 metadata prefix. The rules for metadata names are the same as for 1051 identifiers, but quoted names are not allowed. ``"\xx"`` type escapes 1052 are still valid, which allows any character to be part of a name. 1053 1054Syntax:: 1055 1056 ; Some unnamed metadata nodes, which are referenced by the named metadata. 1057 !0 = !{!"zero"} 1058 !1 = !{!"one"} 1059 !2 = !{!"two"} 1060 ; A named metadata. 1061 !name = !{!0, !1, !2} 1062 1063.. _paramattrs: 1064 1065Parameter Attributes 1066-------------------- 1067 1068The return type and each parameter of a function type may have a set of 1069*parameter attributes* associated with them. Parameter attributes are 1070used to communicate additional information about the result or 1071parameters of a function. Parameter attributes are considered to be part 1072of the function, not of the function type, so functions with different 1073parameter attributes can have the same function type. 1074 1075Parameter attributes are simple keywords that follow the type specified. 1076If multiple parameter attributes are needed, they are space separated. 1077For example: 1078 1079.. code-block:: llvm 1080 1081 declare i32 @printf(ptr noalias nocapture, ...) 1082 declare i32 @atoi(i8 zeroext) 1083 declare signext i8 @returns_signed_char() 1084 1085Note that any attributes for the function result (``nounwind``, 1086``readonly``) come immediately after the argument list. 1087 1088Currently, only the following parameter attributes are defined: 1089 1090``zeroext`` 1091 This indicates to the code generator that the parameter or return 1092 value should be zero-extended to the extent required by the target's 1093 ABI by the caller (for a parameter) or the callee (for a return value). 1094``signext`` 1095 This indicates to the code generator that the parameter or return 1096 value should be sign-extended to the extent required by the target's 1097 ABI (which is usually 32-bits) by the caller (for a parameter) or 1098 the callee (for a return value). 1099``inreg`` 1100 This indicates that this parameter or return value should be treated 1101 in a special target-dependent fashion while emitting code for 1102 a function call or return (usually, by putting it in a register as 1103 opposed to memory, though some targets use it to distinguish between 1104 two different kinds of registers). Use of this attribute is 1105 target-specific. 1106``byval(<ty>)`` 1107 This indicates that the pointer parameter should really be passed by 1108 value to the function. The attribute implies that a hidden copy of 1109 the pointee is made between the caller and the callee, so the callee 1110 is unable to modify the value in the caller. This attribute is only 1111 valid on LLVM pointer arguments. It is generally used to pass 1112 structs and arrays by value, but is also valid on pointers to 1113 scalars. The copy is considered to belong to the caller not the 1114 callee (for example, ``readonly`` functions should not write to 1115 ``byval`` parameters). This is not a valid attribute for return 1116 values. 1117 1118 The byval type argument indicates the in-memory value type, and 1119 must be the same as the pointee type of the argument. 1120 1121 The byval attribute also supports specifying an alignment with the 1122 align attribute. It indicates the alignment of the stack slot to 1123 form and the known alignment of the pointer specified to the call 1124 site. If the alignment is not specified, then the code generator 1125 makes a target-specific assumption. 1126 1127.. _attr_byref: 1128 1129``byref(<ty>)`` 1130 1131 The ``byref`` argument attribute allows specifying the pointee 1132 memory type of an argument. This is similar to ``byval``, but does 1133 not imply a copy is made anywhere, or that the argument is passed 1134 on the stack. This implies the pointer is dereferenceable up to 1135 the storage size of the type. 1136 1137 It is not generally permissible to introduce a write to an 1138 ``byref`` pointer. The pointer may have any address space and may 1139 be read only. 1140 1141 This is not a valid attribute for return values. 1142 1143 The alignment for an ``byref`` parameter can be explicitly 1144 specified by combining it with the ``align`` attribute, similar to 1145 ``byval``. If the alignment is not specified, then the code generator 1146 makes a target-specific assumption. 1147 1148 This is intended for representing ABI constraints, and is not 1149 intended to be inferred for optimization use. 1150 1151.. _attr_preallocated: 1152 1153``preallocated(<ty>)`` 1154 This indicates that the pointer parameter should really be passed by 1155 value to the function, and that the pointer parameter's pointee has 1156 already been initialized before the call instruction. This attribute 1157 is only valid on LLVM pointer arguments. The argument must be the value 1158 returned by the appropriate 1159 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` on non 1160 ``musttail`` calls, or the corresponding caller parameter in ``musttail`` 1161 calls, although it is ignored during codegen. 1162 1163 A non ``musttail`` function call with a ``preallocated`` attribute in 1164 any parameter must have a ``"preallocated"`` operand bundle. A ``musttail`` 1165 function call cannot have a ``"preallocated"`` operand bundle. 1166 1167 The preallocated attribute requires a type argument, which must be 1168 the same as the pointee type of the argument. 1169 1170 The preallocated attribute also supports specifying an alignment with the 1171 align attribute. It indicates the alignment of the stack slot to 1172 form and the known alignment of the pointer specified to the call 1173 site. If the alignment is not specified, then the code generator 1174 makes a target-specific assumption. 1175 1176.. _attr_inalloca: 1177 1178``inalloca(<ty>)`` 1179 1180 The ``inalloca`` argument attribute allows the caller to take the 1181 address of outgoing stack arguments. An ``inalloca`` argument must 1182 be a pointer to stack memory produced by an ``alloca`` instruction. 1183 The alloca, or argument allocation, must also be tagged with the 1184 inalloca keyword. Only the last argument may have the ``inalloca`` 1185 attribute, and that argument is guaranteed to be passed in memory. 1186 1187 An argument allocation may be used by a call at most once because 1188 the call may deallocate it. The ``inalloca`` attribute cannot be 1189 used in conjunction with other attributes that affect argument 1190 storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The 1191 ``inalloca`` attribute also disables LLVM's implicit lowering of 1192 large aggregate return values, which means that frontend authors 1193 must lower them with ``sret`` pointers. 1194 1195 When the call site is reached, the argument allocation must have 1196 been the most recent stack allocation that is still live, or the 1197 behavior is undefined. It is possible to allocate additional stack 1198 space after an argument allocation and before its call site, but it 1199 must be cleared off with :ref:`llvm.stackrestore 1200 <int_stackrestore>`. 1201 1202 The inalloca attribute requires a type argument, which must be the 1203 same as the pointee type of the argument. 1204 1205 See :doc:`InAlloca` for more information on how to use this 1206 attribute. 1207 1208``sret(<ty>)`` 1209 This indicates that the pointer parameter specifies the address of a 1210 structure that is the return value of the function in the source 1211 program. This pointer must be guaranteed by the caller to be valid: 1212 loads and stores to the structure may be assumed by the callee not 1213 to trap and to be properly aligned. This is not a valid attribute 1214 for return values. 1215 1216 The sret type argument specifies the in memory type, which must be 1217 the same as the pointee type of the argument. 1218 1219.. _attr_elementtype: 1220 1221``elementtype(<ty>)`` 1222 1223 The ``elementtype`` argument attribute can be used to specify a pointer 1224 element type in a way that is compatible with `opaque pointers 1225 <OpaquePointers.html>`__. 1226 1227 The ``elementtype`` attribute by itself does not carry any specific 1228 semantics. However, certain intrinsics may require this attribute to be 1229 present and assign it particular semantics. This will be documented on 1230 individual intrinsics. 1231 1232 The attribute may only be applied to pointer typed arguments of intrinsic 1233 calls. It cannot be applied to non-intrinsic calls, and cannot be applied 1234 to parameters on function declarations. For non-opaque pointers, the type 1235 passed to ``elementtype`` must match the pointer element type. 1236 1237.. _attr_align: 1238 1239``align <n>`` or ``align(<n>)`` 1240 This indicates that the pointer value or vector of pointers has the 1241 specified alignment. If applied to a vector of pointers, *all* pointers 1242 (elements) have the specified alignment. If the pointer value does not have 1243 the specified alignment, :ref:`poison value <poisonvalues>` is returned or 1244 passed instead. The ``align`` attribute should be combined with the 1245 ``noundef`` attribute to ensure a pointer is aligned, or otherwise the 1246 behavior is undefined. Note that ``align 1`` has no effect on non-byval, 1247 non-preallocated arguments. 1248 1249 Note that this attribute has additional semantics when combined with the 1250 ``byval`` or ``preallocated`` attribute, which are documented there. 1251 1252.. _noalias: 1253 1254``noalias`` 1255 This indicates that memory locations accessed via pointer values 1256 :ref:`based <pointeraliasing>` on the argument or return value are not also 1257 accessed, during the execution of the function, via pointer values not 1258 *based* on the argument or return value. This guarantee only holds for 1259 memory locations that are *modified*, by any means, during the execution of 1260 the function. The attribute on a return value also has additional semantics 1261 described below. The caller shares the responsibility with the callee for 1262 ensuring that these requirements are met. For further details, please see 1263 the discussion of the NoAlias response in :ref:`alias analysis <Must, May, 1264 or No>`. 1265 1266 Note that this definition of ``noalias`` is intentionally similar 1267 to the definition of ``restrict`` in C99 for function arguments. 1268 1269 For function return values, C99's ``restrict`` is not meaningful, 1270 while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias`` 1271 attribute on return values are stronger than the semantics of the attribute 1272 when used on function arguments. On function return values, the ``noalias`` 1273 attribute indicates that the function acts like a system memory allocation 1274 function, returning a pointer to allocated storage disjoint from the 1275 storage for any other object accessible to the caller. 1276 1277.. _nocapture: 1278 1279``nocapture`` 1280 This indicates that the callee does not :ref:`capture <pointercapture>` the 1281 pointer. This is not a valid attribute for return values. 1282 This attribute applies only to the particular copy of the pointer passed in 1283 this argument. A caller could pass two copies of the same pointer with one 1284 being annotated nocapture and the other not, and the callee could validly 1285 capture through the non annotated parameter. 1286 1287.. code-block:: llvm 1288 1289 define void @f(ptr nocapture %a, ptr %b) { 1290 ; (capture %b) 1291 } 1292 1293 call void @f(ptr @glb, ptr @glb) ; well-defined 1294 1295``nofree`` 1296 This indicates that callee does not free the pointer argument. This is not 1297 a valid attribute for return values. 1298 1299.. _nest: 1300 1301``nest`` 1302 This indicates that the pointer parameter can be excised using the 1303 :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid 1304 attribute for return values and can only be applied to one parameter. 1305 1306``returned`` 1307 This indicates that the function always returns the argument as its return 1308 value. This is a hint to the optimizer and code generator used when 1309 generating the caller, allowing value propagation, tail call optimization, 1310 and omission of register saves and restores in some cases; it is not 1311 checked or enforced when generating the callee. The parameter and the 1312 function return type must be valid operands for the 1313 :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for 1314 return values and can only be applied to one parameter. 1315 1316``nonnull`` 1317 This indicates that the parameter or return pointer is not null. This 1318 attribute may only be applied to pointer typed parameters. This is not 1319 checked or enforced by LLVM; if the parameter or return pointer is null, 1320 :ref:`poison value <poisonvalues>` is returned or passed instead. 1321 The ``nonnull`` attribute should be combined with the ``noundef`` attribute 1322 to ensure a pointer is not null or otherwise the behavior is undefined. 1323 1324``dereferenceable(<n>)`` 1325 This indicates that the parameter or return pointer is dereferenceable. This 1326 attribute may only be applied to pointer typed parameters. A pointer that 1327 is dereferenceable can be loaded from speculatively without a risk of 1328 trapping. The number of bytes known to be dereferenceable must be provided 1329 in parentheses. It is legal for the number of bytes to be less than the 1330 size of the pointee type. The ``nonnull`` attribute does not imply 1331 dereferenceability (consider a pointer to one element past the end of an 1332 array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in 1333 ``addrspace(0)`` (which is the default address space), except if the 1334 ``null_pointer_is_valid`` function attribute is present. 1335 ``n`` should be a positive number. The pointer should be well defined, 1336 otherwise it is undefined behavior. This means ``dereferenceable(<n>)`` 1337 implies ``noundef``. 1338 1339``dereferenceable_or_null(<n>)`` 1340 This indicates that the parameter or return value isn't both 1341 non-null and non-dereferenceable (up to ``<n>`` bytes) at the same 1342 time. All non-null pointers tagged with 1343 ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``. 1344 For address space 0 ``dereferenceable_or_null(<n>)`` implies that 1345 a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``, 1346 and in other address spaces ``dereferenceable_or_null(<n>)`` 1347 implies that a pointer is at least one of ``dereferenceable(<n>)`` 1348 or ``null`` (i.e. it may be both ``null`` and 1349 ``dereferenceable(<n>)``). This attribute may only be applied to 1350 pointer typed parameters. 1351 1352``swiftself`` 1353 This indicates that the parameter is the self/context parameter. This is not 1354 a valid attribute for return values and can only be applied to one 1355 parameter. 1356 1357``swiftasync`` 1358 This indicates that the parameter is the asynchronous context parameter and 1359 triggers the creation of a target-specific extended frame record to store 1360 this pointer. This is not a valid attribute for return values and can only 1361 be applied to one parameter. 1362 1363``swifterror`` 1364 This attribute is motivated to model and optimize Swift error handling. It 1365 can be applied to a parameter with pointer to pointer type or a 1366 pointer-sized alloca. At the call site, the actual argument that corresponds 1367 to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or 1368 the ``swifterror`` parameter of the caller. A ``swifterror`` value (either 1369 the parameter or the alloca) can only be loaded and stored from, or used as 1370 a ``swifterror`` argument. This is not a valid attribute for return values 1371 and can only be applied to one parameter. 1372 1373 These constraints allow the calling convention to optimize access to 1374 ``swifterror`` variables by associating them with a specific register at 1375 call boundaries rather than placing them in memory. Since this does change 1376 the calling convention, a function which uses the ``swifterror`` attribute 1377 on a parameter is not ABI-compatible with one which does not. 1378 1379 These constraints also allow LLVM to assume that a ``swifterror`` argument 1380 does not alias any other memory visible within a function and that a 1381 ``swifterror`` alloca passed as an argument does not escape. 1382 1383``immarg`` 1384 This indicates the parameter is required to be an immediate 1385 value. This must be a trivial immediate integer or floating-point 1386 constant. Undef or constant expressions are not valid. This is 1387 only valid on intrinsic declarations and cannot be applied to a 1388 call site or arbitrary function. 1389 1390``noundef`` 1391 This attribute applies to parameters and return values. If the value 1392 representation contains any undefined or poison bits, the behavior is 1393 undefined. Note that this does not refer to padding introduced by the 1394 type's storage representation. 1395 1396``alignstack(<n>)`` 1397 This indicates the alignment that should be considered by the backend when 1398 assigning this parameter to a stack slot during calling convention 1399 lowering. The enforcement of the specified alignment is target-dependent, 1400 as target-specific calling convention rules may override this value. This 1401 attribute serves the purpose of carrying language specific alignment 1402 information that is not mapped to base types in the backend (for example, 1403 over-alignment specification through language attributes). 1404 1405``allocalign`` 1406 The function parameter marked with this attribute is is the alignment in bytes of the 1407 newly allocated block returned by this function. The returned value must either have 1408 the specified alignment or be the null pointer. The return value MAY be more aligned 1409 than the requested alignment, but not less aligned. Invalid (e.g. non-power-of-2) 1410 alignments are permitted for the allocalign parameter, so long as the returned pointer 1411 is null. This attribute may only be applied to integer parameters. 1412 1413``allocptr`` 1414 The function parameter marked with this attribute is the pointer 1415 that will be manipulated by the allocator. For a realloc-like 1416 function the pointer will be invalidated upon success (but the 1417 same address may be returned), for a free-like function the 1418 pointer will always be invalidated. 1419 1420``readnone`` 1421 This attribute indicates that the function does not dereference that 1422 pointer argument, even though it may read or write the memory that the 1423 pointer points to if accessed through other pointers. 1424 1425 If a function reads from or writes to a readnone pointer argument, the 1426 behavior is undefined. 1427 1428``readonly`` 1429 This attribute indicates that the function does not write through this 1430 pointer argument, even though it may write to the memory that the pointer 1431 points to. 1432 1433 If a function writes to a readonly pointer argument, the behavior is 1434 undefined. 1435 1436``writeonly`` 1437 This attribute indicates that the function may write to, but does not read 1438 through this pointer argument (even though it may read from the memory that 1439 the pointer points to). 1440 1441 If a function reads from a writeonly pointer argument, the behavior is 1442 undefined. 1443 1444.. _gc: 1445 1446Garbage Collector Strategy Names 1447-------------------------------- 1448 1449Each function may specify a garbage collector strategy name, which is simply a 1450string: 1451 1452.. code-block:: llvm 1453 1454 define void @f() gc "name" { ... } 1455 1456The supported values of *name* includes those :ref:`built in to LLVM 1457<builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC 1458strategy will cause the compiler to alter its output in order to support the 1459named garbage collection algorithm. Note that LLVM itself does not contain a 1460garbage collector, this functionality is restricted to generating machine code 1461which can interoperate with a collector provided externally. 1462 1463.. _prefixdata: 1464 1465Prefix Data 1466----------- 1467 1468Prefix data is data associated with a function which the code 1469generator will emit immediately before the function's entrypoint. 1470The purpose of this feature is to allow frontends to associate 1471language-specific runtime metadata with specific functions and make it 1472available through the function pointer while still allowing the 1473function pointer to be called. 1474 1475To access the data for a given function, a program may bitcast the 1476function pointer to a pointer to the constant's type and dereference 1477index -1. This implies that the IR symbol points just past the end of 1478the prefix data. For instance, take the example of a function annotated 1479with a single ``i32``, 1480 1481.. code-block:: llvm 1482 1483 define void @f() prefix i32 123 { ... } 1484 1485The prefix data can be referenced as, 1486 1487.. code-block:: llvm 1488 1489 %a = getelementptr inbounds i32, ptr @f, i32 -1 1490 %b = load i32, ptr %a 1491 1492Prefix data is laid out as if it were an initializer for a global variable 1493of the prefix data's type. The function will be placed such that the 1494beginning of the prefix data is aligned. This means that if the size 1495of the prefix data is not a multiple of the alignment size, the 1496function's entrypoint will not be aligned. If alignment of the 1497function's entrypoint is desired, padding must be added to the prefix 1498data. 1499 1500A function may have prefix data but no body. This has similar semantics 1501to the ``available_externally`` linkage in that the data may be used by the 1502optimizers but will not be emitted in the object file. 1503 1504.. _prologuedata: 1505 1506Prologue Data 1507------------- 1508 1509The ``prologue`` attribute allows arbitrary code (encoded as bytes) to 1510be inserted prior to the function body. This can be used for enabling 1511function hot-patching and instrumentation. 1512 1513To maintain the semantics of ordinary function calls, the prologue data must 1514have a particular format. Specifically, it must begin with a sequence of 1515bytes which decode to a sequence of machine instructions, valid for the 1516module's target, which transfer control to the point immediately succeeding 1517the prologue data, without performing any other visible action. This allows 1518the inliner and other passes to reason about the semantics of the function 1519definition without needing to reason about the prologue data. Obviously this 1520makes the format of the prologue data highly target dependent. 1521 1522A trivial example of valid prologue data for the x86 architecture is ``i8 144``, 1523which encodes the ``nop`` instruction: 1524 1525.. code-block:: text 1526 1527 define void @f() prologue i8 144 { ... } 1528 1529Generally prologue data can be formed by encoding a relative branch instruction 1530which skips the metadata, as in this example of valid prologue data for the 1531x86_64 architecture, where the first two bytes encode ``jmp .+10``: 1532 1533.. code-block:: text 1534 1535 %0 = type <{ i8, i8, ptr }> 1536 1537 define void @f() prologue %0 <{ i8 235, i8 8, ptr @md}> { ... } 1538 1539A function may have prologue data but no body. This has similar semantics 1540to the ``available_externally`` linkage in that the data may be used by the 1541optimizers but will not be emitted in the object file. 1542 1543.. _personalityfn: 1544 1545Personality Function 1546-------------------- 1547 1548The ``personality`` attribute permits functions to specify what function 1549to use for exception handling. 1550 1551.. _attrgrp: 1552 1553Attribute Groups 1554---------------- 1555 1556Attribute groups are groups of attributes that are referenced by objects within 1557the IR. They are important for keeping ``.ll`` files readable, because a lot of 1558functions will use the same set of attributes. In the degenerative case of a 1559``.ll`` file that corresponds to a single ``.c`` file, the single attribute 1560group will capture the important command line flags used to build that file. 1561 1562An attribute group is a module-level object. To use an attribute group, an 1563object references the attribute group's ID (e.g. ``#37``). An object may refer 1564to more than one attribute group. In that situation, the attributes from the 1565different groups are merged. 1566 1567Here is an example of attribute groups for a function that should always be 1568inlined, has a stack alignment of 4, and which shouldn't use SSE instructions: 1569 1570.. code-block:: llvm 1571 1572 ; Target-independent attributes: 1573 attributes #0 = { alwaysinline alignstack=4 } 1574 1575 ; Target-dependent attributes: 1576 attributes #1 = { "no-sse" } 1577 1578 ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse". 1579 define void @f() #0 #1 { ... } 1580 1581.. _fnattrs: 1582 1583Function Attributes 1584------------------- 1585 1586Function attributes are set to communicate additional information about 1587a function. Function attributes are considered to be part of the 1588function, not of the function type, so functions with different function 1589attributes can have the same function type. 1590 1591Function attributes are simple keywords that follow the type specified. 1592If multiple attributes are needed, they are space separated. For 1593example: 1594 1595.. code-block:: llvm 1596 1597 define void @f() noinline { ... } 1598 define void @f() alwaysinline { ... } 1599 define void @f() alwaysinline optsize { ... } 1600 define void @f() optsize { ... } 1601 1602``alignstack(<n>)`` 1603 This attribute indicates that, when emitting the prologue and 1604 epilogue, the backend should forcibly align the stack pointer. 1605 Specify the desired alignment, which must be a power of two, in 1606 parentheses. 1607``"alloc-family"="FAMILY"`` 1608 This indicates which "family" an allocator function is part of. To avoid 1609 collisions, the family name should match the mangled name of the primary 1610 allocator function, that is "malloc" for malloc/calloc/realloc/free, 1611 "_Znwm" for ``::operator::new`` and ``::operator::delete``, and 1612 "_ZnwmSt11align_val_t" for aligned ``::operator::new`` and 1613 ``::operator::delete``. Matching malloc/realloc/free calls within a family 1614 can be optimized, but mismatched ones will be left alone. 1615``allockind("KIND")`` 1616 Describes the behavior of an allocation function. The KIND string contains comma 1617 separated entries from the following options: 1618 1619 * "alloc": the function returns a new block of memory or null. 1620 * "realloc": the function returns a new block of memory or null. If the 1621 result is non-null the memory contents from the start of the block up to 1622 the smaller of the original allocation size and the new allocation size 1623 will match that of the ``allocptr`` argument and the ``allocptr`` 1624 argument is invalidated, even if the function returns the same address. 1625 * "free": the function frees the block of memory specified by ``allocptr``. 1626 Functions marked as "free" ``allockind`` must return void. 1627 * "uninitialized": Any newly-allocated memory (either a new block from 1628 a "alloc" function or the enlarged capacity from a "realloc" function) 1629 will be uninitialized. 1630 * "zeroed": Any newly-allocated memory (either a new block from a "alloc" 1631 function or the enlarged capacity from a "realloc" function) will be 1632 zeroed. 1633 * "aligned": the function returns memory aligned according to the 1634 ``allocalign`` parameter. 1635 1636 The first three options are mutually exclusive, and the remaining options 1637 describe more details of how the function behaves. The remaining options 1638 are invalid for "free"-type functions. 1639``allocsize(<EltSizeParam>[, <NumEltsParam>])`` 1640 This attribute indicates that the annotated function will always return at 1641 least a given number of bytes (or null). Its arguments are zero-indexed 1642 parameter numbers; if one argument is provided, then it's assumed that at 1643 least ``CallSite.Args[EltSizeParam]`` bytes will be available at the 1644 returned pointer. If two are provided, then it's assumed that 1645 ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are 1646 available. The referenced parameters must be integer types. No assumptions 1647 are made about the contents of the returned block of memory. 1648``alwaysinline`` 1649 This attribute indicates that the inliner should attempt to inline 1650 this function into callers whenever possible, ignoring any active 1651 inlining size threshold for this caller. 1652``builtin`` 1653 This indicates that the callee function at a call site should be 1654 recognized as a built-in function, even though the function's declaration 1655 uses the ``nobuiltin`` attribute. This is only valid at call sites for 1656 direct calls to functions that are declared with the ``nobuiltin`` 1657 attribute. 1658``cold`` 1659 This attribute indicates that this function is rarely called. When 1660 computing edge weights, basic blocks post-dominated by a cold 1661 function call are also considered to be cold; and, thus, given low 1662 weight. 1663``convergent`` 1664 In some parallel execution models, there exist operations that cannot be 1665 made control-dependent on any additional values. We call such operations 1666 ``convergent``, and mark them with this attribute. 1667 1668 The ``convergent`` attribute may appear on functions or call/invoke 1669 instructions. When it appears on a function, it indicates that calls to 1670 this function should not be made control-dependent on additional values. 1671 For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so 1672 calls to this intrinsic cannot be made control-dependent on additional 1673 values. 1674 1675 When it appears on a call/invoke, the ``convergent`` attribute indicates 1676 that we should treat the call as though we're calling a convergent 1677 function. This is particularly useful on indirect calls; without this we 1678 may treat such calls as though the target is non-convergent. 1679 1680 The optimizer may remove the ``convergent`` attribute on functions when it 1681 can prove that the function does not execute any convergent operations. 1682 Similarly, the optimizer may remove ``convergent`` on calls/invokes when it 1683 can prove that the call/invoke cannot call a convergent function. 1684``disable_sanitizer_instrumentation`` 1685 When instrumenting code with sanitizers, it can be important to skip certain 1686 functions to ensure no instrumentation is applied to them. 1687 1688 This attribute is not always similar to absent ``sanitize_<name>`` 1689 attributes: depending on the specific sanitizer, code can be inserted into 1690 functions regardless of the ``sanitize_<name>`` attribute to prevent false 1691 positive reports. 1692 1693 ``disable_sanitizer_instrumentation`` disables all kinds of instrumentation, 1694 taking precedence over the ``sanitize_<name>`` attributes and other compiler 1695 flags. 1696``"dontcall-error"`` 1697 This attribute denotes that an error diagnostic should be emitted when a 1698 call of a function with this attribute is not eliminated via optimization. 1699 Front ends can provide optional ``srcloc`` metadata nodes on call sites of 1700 such callees to attach information about where in the source language such a 1701 call came from. A string value can be provided as a note. 1702``"dontcall-warn"`` 1703 This attribute denotes that a warning diagnostic should be emitted when a 1704 call of a function with this attribute is not eliminated via optimization. 1705 Front ends can provide optional ``srcloc`` metadata nodes on call sites of 1706 such callees to attach information about where in the source language such a 1707 call came from. A string value can be provided as a note. 1708``fn_ret_thunk_extern`` 1709 This attribute tells the code generator that returns from functions should 1710 be replaced with jumps to externally-defined architecture-specific symbols. 1711 For X86, this symbol's identifier is ``__x86_return_thunk``. 1712``"frame-pointer"`` 1713 This attribute tells the code generator whether the function 1714 should keep the frame pointer. The code generator may emit the frame pointer 1715 even if this attribute says the frame pointer can be eliminated. 1716 The allowed string values are: 1717 1718 * ``"none"`` (default) - the frame pointer can be eliminated. 1719 * ``"non-leaf"`` - the frame pointer should be kept if the function calls 1720 other functions. 1721 * ``"all"`` - the frame pointer should be kept. 1722``hot`` 1723 This attribute indicates that this function is a hot spot of the program 1724 execution. The function will be optimized more aggressively and will be 1725 placed into special subsection of the text section to improving locality. 1726 1727 When profile feedback is enabled, this attribute has the precedence over 1728 the profile information. By marking a function ``hot``, users can work 1729 around the cases where the training input does not have good coverage 1730 on all the hot functions. 1731``inlinehint`` 1732 This attribute indicates that the source code contained a hint that 1733 inlining this function is desirable (such as the "inline" keyword in 1734 C/C++). It is just a hint; it imposes no requirements on the 1735 inliner. 1736``jumptable`` 1737 This attribute indicates that the function should be added to a 1738 jump-instruction table at code-generation time, and that all address-taken 1739 references to this function should be replaced with a reference to the 1740 appropriate jump-instruction-table function pointer. Note that this creates 1741 a new pointer for the original function, which means that code that depends 1742 on function-pointer identity can break. So, any function annotated with 1743 ``jumptable`` must also be ``unnamed_addr``. 1744``memory(...)`` 1745 This attribute specifies the possible memory effects of the call-site or 1746 function. It allows specifying the possible access kinds (``none``, 1747 ``read``, ``write``, or ``readwrite``) for the possible memory location 1748 kinds (``argmem``, ``inaccessiblemem``, as well as a default). It is best 1749 understood by example: 1750 1751 - ``memory(none)``: Does not access any memory. 1752 - ``memory(read)``: May read (but not write) any memory. 1753 - ``memory(write)``: May write (but not read) any memory. 1754 - ``memory(readwrite)``: May read or write any memory. 1755 - ``memory(argmem: read)``: May only read argument memory. 1756 - ``memory(argmem: read, inaccessiblemem: write)``: May only read argument 1757 memory and only write inaccessible memory. 1758 - ``memory(read, argmem: readwrite)``: May read any memory (default mode) 1759 and additionally write argument memory. 1760 - ``memory(readwrite, argmem: none)``: May access any memory apart from 1761 argument memory. 1762 1763 The supported memory location kinds are: 1764 1765 - ``argmem``: This refers to accesses that are based on pointer arguments 1766 to the function. 1767 - ``inaccessiblemem``: This refers to accesses to memory which is not 1768 accessible by the current module (before return from the function -- an 1769 allocator function may return newly accessible memory while only 1770 accessing inaccessible memory itself). Inaccessible memory is often used 1771 to model control dependencies of intrinsics. 1772 - The default access kind (specified without a location prefix) applies to 1773 all locations that haven't been specified explicitly, including those that 1774 don't currently have a dedicated location kind (e.g. accesses to globals 1775 or captured pointers). 1776 1777 If the ``memory`` attribute is not specified, then ``memory(readwrite)`` 1778 is implied (all memory effects are possible). 1779 1780 The memory effects of a call can be computed as 1781 ``CallSiteEffects & (FunctionEffects | OperandBundleEffects)``. Thus, the 1782 call-site annotation takes precedence over the potential effects described 1783 by either the function annotation or the operand bundles. 1784``minsize`` 1785 This attribute suggests that optimization passes and code generator 1786 passes make choices that keep the code size of this function as small 1787 as possible and perform optimizations that may sacrifice runtime 1788 performance in order to minimize the size of the generated code. 1789``naked`` 1790 This attribute disables prologue / epilogue emission for the 1791 function. This can have very system-specific consequences. 1792``"no-inline-line-tables"`` 1793 When this attribute is set to true, the inliner discards source locations 1794 when inlining code and instead uses the source location of the call site. 1795 Breakpoints set on code that was inlined into the current function will 1796 not fire during the execution of the inlined call sites. If the debugger 1797 stops inside an inlined call site, it will appear to be stopped at the 1798 outermost inlined call site. 1799``no-jump-tables`` 1800 When this attribute is set to true, the jump tables and lookup tables that 1801 can be generated from a switch case lowering are disabled. 1802``nobuiltin`` 1803 This indicates that the callee function at a call site is not recognized as 1804 a built-in function. LLVM will retain the original call and not replace it 1805 with equivalent code based on the semantics of the built-in function, unless 1806 the call site uses the ``builtin`` attribute. This is valid at call sites 1807 and on function declarations and definitions. 1808``nocallback`` 1809 This attribute indicates that the function is only allowed to jump back into 1810 caller's module by a return or an exception, and is not allowed to jump back 1811 by invoking a callback function, a direct, possibly transitive, external 1812 function call, use of ``longjmp``, or other means. It is a compiler hint that 1813 is used at module level to improve dataflow analysis, dropped during linking, 1814 and has no effect on functions defined in the current module. 1815``noduplicate`` 1816 This attribute indicates that calls to the function cannot be 1817 duplicated. A call to a ``noduplicate`` function may be moved 1818 within its parent function, but may not be duplicated within 1819 its parent function. 1820 1821 A function containing a ``noduplicate`` call may still 1822 be an inlining candidate, provided that the call is not 1823 duplicated by inlining. That implies that the function has 1824 internal linkage and only has one call site, so the original 1825 call is dead after inlining. 1826``nofree`` 1827 This function attribute indicates that the function does not, directly or 1828 transitively, call a memory-deallocation function (``free``, for example) 1829 on a memory allocation which existed before the call. 1830 1831 As a result, uncaptured pointers that are known to be dereferenceable 1832 prior to a call to a function with the ``nofree`` attribute are still 1833 known to be dereferenceable after the call. The capturing condition is 1834 necessary in environments where the function might communicate the 1835 pointer to another thread which then deallocates the memory. Alternatively, 1836 ``nosync`` would ensure such communication cannot happen and even captured 1837 pointers cannot be freed by the function. 1838 1839 A ``nofree`` function is explicitly allowed to free memory which it 1840 allocated or (if not ``nosync``) arrange for another thread to free 1841 memory on it's behalf. As a result, perhaps surprisingly, a ``nofree`` 1842 function can return a pointer to a previously deallocated memory object. 1843``noimplicitfloat`` 1844 Disallows implicit floating-point code. This inhibits optimizations that 1845 use floating-point code and floating-point registers for operations that are 1846 not nominally floating-point. LLVM instructions that perform floating-point 1847 operations or require access to floating-point registers may still cause 1848 floating-point code to be generated. 1849 1850 Also inhibits optimizations that create SIMD/vector code and registers from 1851 scalar code such as vectorization or memcpy/memset optimization. This 1852 includes integer vectors. Vector instructions present in IR may still cause 1853 vector code to be generated. 1854``noinline`` 1855 This attribute indicates that the inliner should never inline this 1856 function in any situation. This attribute may not be used together 1857 with the ``alwaysinline`` attribute. 1858``nomerge`` 1859 This attribute indicates that calls to this function should never be merged 1860 during optimization. For example, it will prevent tail merging otherwise 1861 identical code sequences that raise an exception or terminate the program. 1862 Tail merging normally reduces the precision of source location information, 1863 making stack traces less useful for debugging. This attribute gives the 1864 user control over the tradeoff between code size and debug information 1865 precision. 1866``nonlazybind`` 1867 This attribute suppresses lazy symbol binding for the function. This 1868 may make calls to the function faster, at the cost of extra program 1869 startup time if the function is not called during program startup. 1870``noprofile`` 1871 This function attribute prevents instrumentation based profiling, used for 1872 coverage or profile based optimization, from being added to a function. It 1873 also blocks inlining if the caller and callee have different values of this 1874 attribute. 1875``skipprofile`` 1876 This function attribute prevents instrumentation based profiling, used for 1877 coverage or profile based optimization, from being added to a function. This 1878 attribute does not restrict inlining, so instrumented instruction could end 1879 up in this function. 1880``noredzone`` 1881 This attribute indicates that the code generator should not use a 1882 red zone, even if the target-specific ABI normally permits it. 1883``indirect-tls-seg-refs`` 1884 This attribute indicates that the code generator should not use 1885 direct TLS access through segment registers, even if the 1886 target-specific ABI normally permits it. 1887``noreturn`` 1888 This function attribute indicates that the function never returns 1889 normally, hence through a return instruction. This produces undefined 1890 behavior at runtime if the function ever does dynamically return. Annotated 1891 functions may still raise an exception, i.a., ``nounwind`` is not implied. 1892``norecurse`` 1893 This function attribute indicates that the function does not call itself 1894 either directly or indirectly down any possible call path. This produces 1895 undefined behavior at runtime if the function ever does recurse. 1896 1897.. _langref_willreturn: 1898 1899``willreturn`` 1900 This function attribute indicates that a call of this function will 1901 either exhibit undefined behavior or comes back and continues execution 1902 at a point in the existing call stack that includes the current invocation. 1903 Annotated functions may still raise an exception, i.a., ``nounwind`` is not implied. 1904 If an invocation of an annotated function does not return control back 1905 to a point in the call stack, the behavior is undefined. 1906``nosync`` 1907 This function attribute indicates that the function does not communicate 1908 (synchronize) with another thread through memory or other well-defined means. 1909 Synchronization is considered possible in the presence of `atomic` accesses 1910 that enforce an order, thus not "unordered" and "monotonic", `volatile` accesses, 1911 as well as `convergent` function calls. Note that through `convergent` function calls 1912 non-memory communication, e.g., cross-lane operations, are possible and are also 1913 considered synchronization. However `convergent` does not contradict `nosync`. 1914 If an annotated function does ever synchronize with another thread, 1915 the behavior is undefined. 1916``nounwind`` 1917 This function attribute indicates that the function never raises an 1918 exception. If the function does raise an exception, its runtime 1919 behavior is undefined. However, functions marked nounwind may still 1920 trap or generate asynchronous exceptions. Exception handling schemes 1921 that are recognized by LLVM to handle asynchronous exceptions, such 1922 as SEH, will still provide their implementation defined semantics. 1923``nosanitize_bounds`` 1924 This attribute indicates that bounds checking sanitizer instrumentation 1925 is disabled for this function. 1926``nosanitize_coverage`` 1927 This attribute indicates that SanitizerCoverage instrumentation is disabled 1928 for this function. 1929``null_pointer_is_valid`` 1930 If ``null_pointer_is_valid`` is set, then the ``null`` address 1931 in address-space 0 is considered to be a valid address for memory loads and 1932 stores. Any analysis or optimization should not treat dereferencing a 1933 pointer to ``null`` as undefined behavior in this function. 1934 Note: Comparing address of a global variable to ``null`` may still 1935 evaluate to false because of a limitation in querying this attribute inside 1936 constant expressions. 1937``optforfuzzing`` 1938 This attribute indicates that this function should be optimized 1939 for maximum fuzzing signal. 1940``optnone`` 1941 This function attribute indicates that most optimization passes will skip 1942 this function, with the exception of interprocedural optimization passes. 1943 Code generation defaults to the "fast" instruction selector. 1944 This attribute cannot be used together with the ``alwaysinline`` 1945 attribute; this attribute is also incompatible 1946 with the ``minsize`` attribute and the ``optsize`` attribute. 1947 1948 This attribute requires the ``noinline`` attribute to be specified on 1949 the function as well, so the function is never inlined into any caller. 1950 Only functions with the ``alwaysinline`` attribute are valid 1951 candidates for inlining into the body of this function. 1952``optsize`` 1953 This attribute suggests that optimization passes and code generator 1954 passes make choices that keep the code size of this function low, 1955 and otherwise do optimizations specifically to reduce code size as 1956 long as they do not significantly impact runtime performance. 1957``"patchable-function"`` 1958 This attribute tells the code generator that the code 1959 generated for this function needs to follow certain conventions that 1960 make it possible for a runtime function to patch over it later. 1961 The exact effect of this attribute depends on its string value, 1962 for which there currently is one legal possibility: 1963 1964 * ``"prologue-short-redirect"`` - This style of patchable 1965 function is intended to support patching a function prologue to 1966 redirect control away from the function in a thread safe 1967 manner. It guarantees that the first instruction of the 1968 function will be large enough to accommodate a short jump 1969 instruction, and will be sufficiently aligned to allow being 1970 fully changed via an atomic compare-and-swap instruction. 1971 While the first requirement can be satisfied by inserting large 1972 enough NOP, LLVM can and will try to re-purpose an existing 1973 instruction (i.e. one that would have to be emitted anyway) as 1974 the patchable instruction larger than a short jump. 1975 1976 ``"prologue-short-redirect"`` is currently only supported on 1977 x86-64. 1978 1979 This attribute by itself does not imply restrictions on 1980 inter-procedural optimizations. All of the semantic effects the 1981 patching may have to be separately conveyed via the linkage type. 1982``"probe-stack"`` 1983 This attribute indicates that the function will trigger a guard region 1984 in the end of the stack. It ensures that accesses to the stack must be 1985 no further apart than the size of the guard region to a previous 1986 access of the stack. It takes one required string value, the name of 1987 the stack probing function that will be called. 1988 1989 If a function that has a ``"probe-stack"`` attribute is inlined into 1990 a function with another ``"probe-stack"`` attribute, the resulting 1991 function has the ``"probe-stack"`` attribute of the caller. If a 1992 function that has a ``"probe-stack"`` attribute is inlined into a 1993 function that has no ``"probe-stack"`` attribute at all, the resulting 1994 function has the ``"probe-stack"`` attribute of the callee. 1995``"stack-probe-size"`` 1996 This attribute controls the behavior of stack probes: either 1997 the ``"probe-stack"`` attribute, or ABI-required stack probes, if any. 1998 It defines the size of the guard region. It ensures that if the function 1999 may use more stack space than the size of the guard region, stack probing 2000 sequence will be emitted. It takes one required integer value, which 2001 is 4096 by default. 2002 2003 If a function that has a ``"stack-probe-size"`` attribute is inlined into 2004 a function with another ``"stack-probe-size"`` attribute, the resulting 2005 function has the ``"stack-probe-size"`` attribute that has the lower 2006 numeric value. If a function that has a ``"stack-probe-size"`` attribute is 2007 inlined into a function that has no ``"stack-probe-size"`` attribute 2008 at all, the resulting function has the ``"stack-probe-size"`` attribute 2009 of the callee. 2010``"no-stack-arg-probe"`` 2011 This attribute disables ABI-required stack probes, if any. 2012``returns_twice`` 2013 This attribute indicates that this function can return twice. The C 2014 ``setjmp`` is an example of such a function. The compiler disables 2015 some optimizations (like tail calls) in the caller of these 2016 functions. 2017``safestack`` 2018 This attribute indicates that 2019 `SafeStack <https://clang.llvm.org/docs/SafeStack.html>`_ 2020 protection is enabled for this function. 2021 2022 If a function that has a ``safestack`` attribute is inlined into a 2023 function that doesn't have a ``safestack`` attribute or which has an 2024 ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting 2025 function will have a ``safestack`` attribute. 2026``sanitize_address`` 2027 This attribute indicates that AddressSanitizer checks 2028 (dynamic address safety analysis) are enabled for this function. 2029``sanitize_memory`` 2030 This attribute indicates that MemorySanitizer checks (dynamic detection 2031 of accesses to uninitialized memory) are enabled for this function. 2032``sanitize_thread`` 2033 This attribute indicates that ThreadSanitizer checks 2034 (dynamic thread safety analysis) are enabled for this function. 2035``sanitize_hwaddress`` 2036 This attribute indicates that HWAddressSanitizer checks 2037 (dynamic address safety analysis based on tagged pointers) are enabled for 2038 this function. 2039``sanitize_memtag`` 2040 This attribute indicates that MemTagSanitizer checks 2041 (dynamic address safety analysis based on Armv8 MTE) are enabled for 2042 this function. 2043``speculative_load_hardening`` 2044 This attribute indicates that 2045 `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_ 2046 should be enabled for the function body. 2047 2048 Speculative Load Hardening is a best-effort mitigation against 2049 information leak attacks that make use of control flow 2050 miss-speculation - specifically miss-speculation of whether a branch 2051 is taken or not. Typically vulnerabilities enabling such attacks are 2052 classified as "Spectre variant #1". Notably, this does not attempt to 2053 mitigate against miss-speculation of branch target, classified as 2054 "Spectre variant #2" vulnerabilities. 2055 2056 When inlining, the attribute is sticky. Inlining a function that carries 2057 this attribute will cause the caller to gain the attribute. This is intended 2058 to provide a maximally conservative model where the code in a function 2059 annotated with this attribute will always (even after inlining) end up 2060 hardened. 2061``speculatable`` 2062 This function attribute indicates that the function does not have any 2063 effects besides calculating its result and does not have undefined behavior. 2064 Note that ``speculatable`` is not enough to conclude that along any 2065 particular execution path the number of calls to this function will not be 2066 externally observable. This attribute is only valid on functions 2067 and declarations, not on individual call sites. If a function is 2068 incorrectly marked as speculatable and really does exhibit 2069 undefined behavior, the undefined behavior may be observed even 2070 if the call site is dead code. 2071 2072``ssp`` 2073 This attribute indicates that the function should emit a stack 2074 smashing protector. It is in the form of a "canary" --- a random value 2075 placed on the stack before the local variables that's checked upon 2076 return from the function to see if it has been overwritten. A 2077 heuristic is used to determine if a function needs stack protectors 2078 or not. The heuristic used will enable protectors for functions with: 2079 2080 - Character arrays larger than ``ssp-buffer-size`` (default 8). 2081 - Aggregates containing character arrays larger than ``ssp-buffer-size``. 2082 - Calls to alloca() with variable sizes or constant sizes greater than 2083 ``ssp-buffer-size``. 2084 2085 Variables that are identified as requiring a protector will be arranged 2086 on the stack such that they are adjacent to the stack protector guard. 2087 2088 If a function with an ``ssp`` attribute is inlined into a calling function, 2089 the attribute is not carried over to the calling function. 2090 2091``sspstrong`` 2092 This attribute indicates that the function should emit a stack smashing 2093 protector. This attribute causes a strong heuristic to be used when 2094 determining if a function needs stack protectors. The strong heuristic 2095 will enable protectors for functions with: 2096 2097 - Arrays of any size and type 2098 - Aggregates containing an array of any size and type. 2099 - Calls to alloca(). 2100 - Local variables that have had their address taken. 2101 2102 Variables that are identified as requiring a protector will be arranged 2103 on the stack such that they are adjacent to the stack protector guard. 2104 The specific layout rules are: 2105 2106 #. Large arrays and structures containing large arrays 2107 (``>= ssp-buffer-size``) are closest to the stack protector. 2108 #. Small arrays and structures containing small arrays 2109 (``< ssp-buffer-size``) are 2nd closest to the protector. 2110 #. Variables that have had their address taken are 3rd closest to the 2111 protector. 2112 2113 This overrides the ``ssp`` function attribute. 2114 2115 If a function with an ``sspstrong`` attribute is inlined into a calling 2116 function which has an ``ssp`` attribute, the calling function's attribute 2117 will be upgraded to ``sspstrong``. 2118 2119``sspreq`` 2120 This attribute indicates that the function should *always* emit a stack 2121 smashing protector. This overrides the ``ssp`` and ``sspstrong`` function 2122 attributes. 2123 2124 Variables that are identified as requiring a protector will be arranged 2125 on the stack such that they are adjacent to the stack protector guard. 2126 The specific layout rules are: 2127 2128 #. Large arrays and structures containing large arrays 2129 (``>= ssp-buffer-size``) are closest to the stack protector. 2130 #. Small arrays and structures containing small arrays 2131 (``< ssp-buffer-size``) are 2nd closest to the protector. 2132 #. Variables that have had their address taken are 3rd closest to the 2133 protector. 2134 2135 If a function with an ``sspreq`` attribute is inlined into a calling 2136 function which has an ``ssp`` or ``sspstrong`` attribute, the calling 2137 function's attribute will be upgraded to ``sspreq``. 2138 2139``strictfp`` 2140 This attribute indicates that the function was called from a scope that 2141 requires strict floating-point semantics. LLVM will not attempt any 2142 optimizations that require assumptions about the floating-point rounding 2143 mode or that might alter the state of floating-point status flags that 2144 might otherwise be set or cleared by calling this function. LLVM will 2145 not introduce any new floating-point instructions that may trap. 2146 2147``"denormal-fp-math"`` 2148 This indicates the denormal (subnormal) handling that may be 2149 assumed for the default floating-point environment. This is a 2150 comma separated pair. The elements may be one of ``"ieee"``, 2151 ``"preserve-sign"``, or ``"positive-zero"``. The first entry 2152 indicates the flushing mode for the result of floating point 2153 operations. The second indicates the handling of denormal inputs 2154 to floating point instructions. For compatibility with older 2155 bitcode, if the second value is omitted, both input and output 2156 modes will assume the same mode. 2157 2158 If this is attribute is not specified, the default is 2159 ``"ieee,ieee"``. 2160 2161 If the output mode is ``"preserve-sign"``, or ``"positive-zero"``, 2162 denormal outputs may be flushed to zero by standard floating-point 2163 operations. It is not mandated that flushing to zero occurs, but if 2164 a denormal output is flushed to zero, it must respect the sign 2165 mode. Not all targets support all modes. While this indicates the 2166 expected floating point mode the function will be executed with, 2167 this does not make any attempt to ensure the mode is 2168 consistent. User or platform code is expected to set the floating 2169 point mode appropriately before function entry. 2170 2171 If the input mode is ``"preserve-sign"``, or ``"positive-zero"``, a 2172 floating-point operation must treat any input denormal value as 2173 zero. In some situations, if an instruction does not respect this 2174 mode, the input may need to be converted to 0 as if by 2175 ``@llvm.canonicalize`` during lowering for correctness. 2176 2177``"denormal-fp-math-f32"`` 2178 Same as ``"denormal-fp-math"``, but only controls the behavior of 2179 the 32-bit float type (or vectors of 32-bit floats). If both are 2180 are present, this overrides ``"denormal-fp-math"``. Not all targets 2181 support separately setting the denormal mode per type, and no 2182 attempt is made to diagnose unsupported uses. Currently this 2183 attribute is respected by the AMDGPU and NVPTX backends. 2184 2185``"thunk"`` 2186 This attribute indicates that the function will delegate to some other 2187 function with a tail call. The prototype of a thunk should not be used for 2188 optimization purposes. The caller is expected to cast the thunk prototype to 2189 match the thunk target prototype. 2190 2191``"tls-load-hoist"`` 2192 This attribute indicates that the function will try to reduce redundant 2193 tls address calculation by hoisting tls variable. 2194 2195``uwtable[(sync|async)]`` 2196 This attribute indicates that the ABI being targeted requires that 2197 an unwind table entry be produced for this function even if we can 2198 show that no exceptions passes by it. This is normally the case for 2199 the ELF x86-64 abi, but it can be disabled for some compilation 2200 units. The optional parameter describes what kind of unwind tables 2201 to generate: ``sync`` for normal unwind tables, ``async`` for asynchronous 2202 (instruction precise) unwind tables. Without the parameter, the attribute 2203 ``uwtable`` is equivalent to ``uwtable(async)``. 2204``nocf_check`` 2205 This attribute indicates that no control-flow check will be performed on 2206 the attributed entity. It disables -fcf-protection=<> for a specific 2207 entity to fine grain the HW control flow protection mechanism. The flag 2208 is target independent and currently appertains to a function or function 2209 pointer. 2210``shadowcallstack`` 2211 This attribute indicates that the ShadowCallStack checks are enabled for 2212 the function. The instrumentation checks that the return address for the 2213 function has not changed between the function prolog and epilog. It is 2214 currently x86_64-specific. 2215 2216.. _langref_mustprogress: 2217 2218``mustprogress`` 2219 This attribute indicates that the function is required to return, unwind, 2220 or interact with the environment in an observable way e.g. via a volatile 2221 memory access, I/O, or other synchronization. The ``mustprogress`` 2222 attribute is intended to model the requirements of the first section of 2223 [intro.progress] of the C++ Standard. As a consequence, a loop in a 2224 function with the `mustprogress` attribute can be assumed to terminate if 2225 it does not interact with the environment in an observable way, and 2226 terminating loops without side-effects can be removed. If a `mustprogress` 2227 function does not satisfy this contract, the behavior is undefined. This 2228 attribute does not apply transitively to callees, but does apply to call 2229 sites within the function. Note that `willreturn` implies `mustprogress`. 2230``"warn-stack-size"="<threshold>"`` 2231 This attribute sets a threshold to emit diagnostics once the frame size is 2232 known should the frame size exceed the specified value. It takes one 2233 required integer value, which should be a non-negative integer, and less 2234 than `UINT_MAX`. It's unspecified which threshold will be used when 2235 duplicate definitions are linked together with differing values. 2236``vscale_range(<min>[, <max>])`` 2237 This attribute indicates the minimum and maximum vscale value for the given 2238 function. The min must be greater than 0. A maximum value of 0 means 2239 unbounded. If the optional max value is omitted then max is set to the 2240 value of min. If the attribute is not present, no assumptions are made 2241 about the range of vscale. 2242``"nooutline"`` 2243 This attribute indicates that outlining passes should not modify the 2244 function. 2245 2246Call Site Attributes 2247---------------------- 2248 2249In addition to function attributes the following call site only 2250attributes are supported: 2251 2252``vector-function-abi-variant`` 2253 This attribute can be attached to a :ref:`call <i_call>` to list 2254 the vector functions associated to the function. Notice that the 2255 attribute cannot be attached to a :ref:`invoke <i_invoke>` or a 2256 :ref:`callbr <i_callbr>` instruction. The attribute consists of a 2257 comma separated list of mangled names. The order of the list does 2258 not imply preference (it is logically a set). The compiler is free 2259 to pick any listed vector function of its choosing. 2260 2261 The syntax for the mangled names is as follows::: 2262 2263 _ZGV<isa><mask><vlen><parameters>_<scalar_name>[(<vector_redirection>)] 2264 2265 When present, the attribute informs the compiler that the function 2266 ``<scalar_name>`` has a corresponding vector variant that can be 2267 used to perform the concurrent invocation of ``<scalar_name>`` on 2268 vectors. The shape of the vector function is described by the 2269 tokens between the prefix ``_ZGV`` and the ``<scalar_name>`` 2270 token. The standard name of the vector function is 2271 ``_ZGV<isa><mask><vlen><parameters>_<scalar_name>``. When present, 2272 the optional token ``(<vector_redirection>)`` informs the compiler 2273 that a custom name is provided in addition to the standard one 2274 (custom names can be provided for example via the use of ``declare 2275 variant`` in OpenMP 5.0). The declaration of the variant must be 2276 present in the IR Module. The signature of the vector variant is 2277 determined by the rules of the Vector Function ABI (VFABI) 2278 specifications of the target. For Arm and X86, the VFABI can be 2279 found at https://github.com/ARM-software/abi-aa and 2280 https://software.intel.com/content/www/us/en/develop/download/vector-simd-function-abi.html, 2281 respectively. 2282 2283 For X86 and Arm targets, the values of the tokens in the standard 2284 name are those that are defined in the VFABI. LLVM has an internal 2285 ``<isa>`` token that can be used to create scalar-to-vector 2286 mappings for functions that are not directly associated to any of 2287 the target ISAs (for example, some of the mappings stored in the 2288 TargetLibraryInfo). Valid values for the ``<isa>`` token are::: 2289 2290 <isa>:= b | c | d | e -> X86 SSE, AVX, AVX2, AVX512 2291 | n | s -> Armv8 Advanced SIMD, SVE 2292 | __LLVM__ -> Internal LLVM Vector ISA 2293 2294 For all targets currently supported (x86, Arm and Internal LLVM), 2295 the remaining tokens can have the following values::: 2296 2297 <mask>:= M | N -> mask | no mask 2298 2299 <vlen>:= number -> number of lanes 2300 | x -> VLA (Vector Length Agnostic) 2301 2302 <parameters>:= v -> vector 2303 | l | l <number> -> linear 2304 | R | R <number> -> linear with ref modifier 2305 | L | L <number> -> linear with val modifier 2306 | U | U <number> -> linear with uval modifier 2307 | ls <pos> -> runtime linear 2308 | Rs <pos> -> runtime linear with ref modifier 2309 | Ls <pos> -> runtime linear with val modifier 2310 | Us <pos> -> runtime linear with uval modifier 2311 | u -> uniform 2312 2313 <scalar_name>:= name of the scalar function 2314 2315 <vector_redirection>:= optional, custom name of the vector function 2316 2317``preallocated(<ty>)`` 2318 This attribute is required on calls to ``llvm.call.preallocated.arg`` 2319 and cannot be used on any other call. See 2320 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` for more 2321 details. 2322 2323.. _glattrs: 2324 2325Global Attributes 2326----------------- 2327 2328Attributes may be set to communicate additional information about a global variable. 2329Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable 2330are grouped into a single :ref:`attribute group <attrgrp>`. 2331 2332``no_sanitize_address`` 2333 This attribute indicates that the global variable should not have 2334 AddressSanitizer instrumentation applied to it, because it was annotated 2335 with `__attribute__((no_sanitize("address")))`, 2336 `__attribute__((disable_sanitizer_instrumentation))`, or included in the 2337 `-fsanitize-ignorelist` file. 2338``no_sanitize_hwaddress`` 2339 This attribute indicates that the global variable should not have 2340 HWAddressSanitizer instrumentation applied to it, because it was annotated 2341 with `__attribute__((no_sanitize("hwaddress")))`, 2342 `__attribute__((disable_sanitizer_instrumentation))`, or included in the 2343 `-fsanitize-ignorelist` file. 2344``sanitize_memtag`` 2345 This attribute indicates that the global variable should have AArch64 memory 2346 tags (MTE) instrumentation applied to it. This attribute causes the 2347 suppression of certain optimisations, like GlobalMerge, as well as ensuring 2348 extra directives are emitted in the assembly and extra bits of metadata are 2349 placed in the object file so that the linker can ensure the accesses are 2350 protected by MTE. This attribute is added by clang when 2351 `-fsanitize=memtag-globals` is provided, as long as the global is not marked 2352 with `__attribute__((no_sanitize("memtag")))`, 2353 `__attribute__((disable_sanitizer_instrumentation))`, or included in the 2354 `-fsanitize-ignorelist` file. The AArch64 Globals Tagging pass may remove 2355 this attribute when it's not possible to tag the global (e.g. it's a TLS 2356 variable). 2357``sanitize_address_dyninit`` 2358 This attribute indicates that the global variable, when instrumented with 2359 AddressSanitizer, should be checked for ODR violations. This attribute is 2360 applied to global variables that are dynamically initialized according to 2361 C++ rules. 2362 2363.. _opbundles: 2364 2365Operand Bundles 2366--------------- 2367 2368Operand bundles are tagged sets of SSA values that can be associated 2369with certain LLVM instructions (currently only ``call`` s and 2370``invoke`` s). In a way they are like metadata, but dropping them is 2371incorrect and will change program semantics. 2372 2373Syntax:: 2374 2375 operand bundle set ::= '[' operand bundle (, operand bundle )* ']' 2376 operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')' 2377 bundle operand ::= SSA value 2378 tag ::= string constant 2379 2380Operand bundles are **not** part of a function's signature, and a 2381given function may be called from multiple places with different kinds 2382of operand bundles. This reflects the fact that the operand bundles 2383are conceptually a part of the ``call`` (or ``invoke``), not the 2384callee being dispatched to. 2385 2386Operand bundles are a generic mechanism intended to support 2387runtime-introspection-like functionality for managed languages. While 2388the exact semantics of an operand bundle depend on the bundle tag, 2389there are certain limitations to how much the presence of an operand 2390bundle can influence the semantics of a program. These restrictions 2391are described as the semantics of an "unknown" operand bundle. As 2392long as the behavior of an operand bundle is describable within these 2393restrictions, LLVM does not need to have special knowledge of the 2394operand bundle to not miscompile programs containing it. 2395 2396- The bundle operands for an unknown operand bundle escape in unknown 2397 ways before control is transferred to the callee or invokee. 2398- Calls and invokes with operand bundles have unknown read / write 2399 effect on the heap on entry and exit (even if the call target is 2400 ``readnone`` or ``readonly``), unless they're overridden with 2401 callsite specific attributes. 2402- An operand bundle at a call site cannot change the implementation 2403 of the called function. Inter-procedural optimizations work as 2404 usual as long as they take into account the first two properties. 2405 2406More specific types of operand bundles are described below. 2407 2408.. _deopt_opbundles: 2409 2410Deoptimization Operand Bundles 2411^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2412 2413Deoptimization operand bundles are characterized by the ``"deopt"`` 2414operand bundle tag. These operand bundles represent an alternate 2415"safe" continuation for the call site they're attached to, and can be 2416used by a suitable runtime to deoptimize the compiled frame at the 2417specified call site. There can be at most one ``"deopt"`` operand 2418bundle attached to a call site. Exact details of deoptimization is 2419out of scope for the language reference, but it usually involves 2420rewriting a compiled frame into a set of interpreted frames. 2421 2422From the compiler's perspective, deoptimization operand bundles make 2423the call sites they're attached to at least ``readonly``. They read 2424through all of their pointer typed operands (even if they're not 2425otherwise escaped) and the entire visible heap. Deoptimization 2426operand bundles do not capture their operands except during 2427deoptimization, in which case control will not be returned to the 2428compiled frame. 2429 2430The inliner knows how to inline through calls that have deoptimization 2431operand bundles. Just like inlining through a normal call site 2432involves composing the normal and exceptional continuations, inlining 2433through a call site with a deoptimization operand bundle needs to 2434appropriately compose the "safe" deoptimization continuation. The 2435inliner does this by prepending the parent's deoptimization 2436continuation to every deoptimization continuation in the inlined body. 2437E.g. inlining ``@f`` into ``@g`` in the following example 2438 2439.. code-block:: llvm 2440 2441 define void @f() { 2442 call void @x() ;; no deopt state 2443 call void @y() [ "deopt"(i32 10) ] 2444 call void @y() [ "deopt"(i32 10), "unknown"(ptr null) ] 2445 ret void 2446 } 2447 2448 define void @g() { 2449 call void @f() [ "deopt"(i32 20) ] 2450 ret void 2451 } 2452 2453will result in 2454 2455.. code-block:: llvm 2456 2457 define void @g() { 2458 call void @x() ;; still no deopt state 2459 call void @y() [ "deopt"(i32 20, i32 10) ] 2460 call void @y() [ "deopt"(i32 20, i32 10), "unknown"(ptr null) ] 2461 ret void 2462 } 2463 2464It is the frontend's responsibility to structure or encode the 2465deoptimization state in a way that syntactically prepending the 2466caller's deoptimization state to the callee's deoptimization state is 2467semantically equivalent to composing the caller's deoptimization 2468continuation after the callee's deoptimization continuation. 2469 2470.. _ob_funclet: 2471 2472Funclet Operand Bundles 2473^^^^^^^^^^^^^^^^^^^^^^^ 2474 2475Funclet operand bundles are characterized by the ``"funclet"`` 2476operand bundle tag. These operand bundles indicate that a call site 2477is within a particular funclet. There can be at most one 2478``"funclet"`` operand bundle attached to a call site and it must have 2479exactly one bundle operand. 2480 2481If any funclet EH pads have been "entered" but not "exited" (per the 2482`description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_), 2483it is undefined behavior to execute a ``call`` or ``invoke`` which: 2484 2485* does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind 2486 intrinsic, or 2487* has a ``"funclet"`` bundle whose operand is not the most-recently-entered 2488 not-yet-exited funclet EH pad. 2489 2490Similarly, if no funclet EH pads have been entered-but-not-yet-exited, 2491executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior. 2492 2493GC Transition Operand Bundles 2494^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2495 2496GC transition operand bundles are characterized by the 2497``"gc-transition"`` operand bundle tag. These operand bundles mark a 2498call as a transition between a function with one GC strategy to a 2499function with a different GC strategy. If coordinating the transition 2500between GC strategies requires additional code generation at the call 2501site, these bundles may contain any values that are needed by the 2502generated code. For more details, see :ref:`GC Transitions 2503<gc_transition_args>`. 2504 2505The bundle contain an arbitrary list of Values which need to be passed 2506to GC transition code. They will be lowered and passed as operands to 2507the appropriate GC_TRANSITION nodes in the selection DAG. It is assumed 2508that these arguments must be available before and after (but not 2509necessarily during) the execution of the callee. 2510 2511.. _assume_opbundles: 2512 2513Assume Operand Bundles 2514^^^^^^^^^^^^^^^^^^^^^^ 2515 2516Operand bundles on an :ref:`llvm.assume <int_assume>` allows representing 2517assumptions, such as that a :ref:`parameter attribute <paramattrs>` or a 2518:ref:`function attribute <fnattrs>` holds for a certain value at a certain 2519location. Operand bundles enable assumptions that are either hard or impossible 2520to represent as a boolean argument of an :ref:`llvm.assume <int_assume>`. 2521 2522An assume operand bundle has the form: 2523 2524:: 2525 2526 "<tag>"([ <arguments>] ]) 2527 2528In the case of function or parameter attributes, the operand bundle has the 2529restricted form: 2530 2531:: 2532 2533 "<tag>"([ <holds for value> [, <attribute argument>] ]) 2534 2535* The tag of the operand bundle is usually the name of attribute that can be 2536 assumed to hold. It can also be `ignore`, this tag doesn't contain any 2537 information and should be ignored. 2538* The first argument if present is the value for which the attribute hold. 2539* The second argument if present is an argument of the attribute. 2540 2541If there are no arguments the attribute is a property of the call location. 2542 2543For example: 2544 2545.. code-block:: llvm 2546 2547 call void @llvm.assume(i1 true) ["align"(ptr %val, i32 8)] 2548 2549allows the optimizer to assume that at location of call to 2550:ref:`llvm.assume <int_assume>` ``%val`` has an alignment of at least 8. 2551 2552.. code-block:: llvm 2553 2554 call void @llvm.assume(i1 %cond) ["cold"(), "nonnull"(ptr %val)] 2555 2556allows the optimizer to assume that the :ref:`llvm.assume <int_assume>` 2557call location is cold and that ``%val`` may not be null. 2558 2559Just like for the argument of :ref:`llvm.assume <int_assume>`, if any of the 2560provided guarantees are violated at runtime the behavior is undefined. 2561 2562While attributes expect constant arguments, assume operand bundles may be 2563provided a dynamic value, for example: 2564 2565.. code-block:: llvm 2566 2567 call void @llvm.assume(i1 true) ["align"(ptr %val, i32 %align)] 2568 2569If the operand bundle value violates any requirements on the attribute value, 2570the behavior is undefined, unless one of the following exceptions applies: 2571 2572* ``"align"`` operand bundles may specify a non-power-of-two alignment 2573 (including a zero alignment). If this is the case, then the pointer value 2574 must be a null pointer, otherwise the behavior is undefined. 2575 2576In addition to allowing operand bundles encoding function and parameter 2577attributes, an assume operand bundle my also encode a ``separate_storage`` 2578operand bundle. This has the form: 2579 2580.. code-block:: llvm 2581 2582 separate_storage(<val1>, <val2>)`` 2583 2584This indicates that no pointer :ref:`based <pointeraliasing>` on one of its 2585arguments can alias any pointer based on the other. 2586 2587Even if the assumed property can be encoded as a boolean value, like 2588``nonnull``, using operand bundles to express the property can still have 2589benefits: 2590 2591* Attributes that can be expressed via operand bundles are directly the 2592 property that the optimizer uses and cares about. Encoding attributes as 2593 operand bundles removes the need for an instruction sequence that represents 2594 the property (e.g., `icmp ne ptr %p, null` for `nonnull`) and for the 2595 optimizer to deduce the property from that instruction sequence. 2596* Expressing the property using operand bundles makes it easy to identify the 2597 use of the value as a use in an :ref:`llvm.assume <int_assume>`. This then 2598 simplifies and improves heuristics, e.g., for use "use-sensitive" 2599 optimizations. 2600 2601.. _ob_preallocated: 2602 2603Preallocated Operand Bundles 2604^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2605 2606Preallocated operand bundles are characterized by the ``"preallocated"`` 2607operand bundle tag. These operand bundles allow separation of the allocation 2608of the call argument memory from the call site. This is necessary to pass 2609non-trivially copyable objects by value in a way that is compatible with MSVC 2610on some targets. There can be at most one ``"preallocated"`` operand bundle 2611attached to a call site and it must have exactly one bundle operand, which is 2612a token generated by ``@llvm.call.preallocated.setup``. A call with this 2613operand bundle should not adjust the stack before entering the function, as 2614that will have been done by one of the ``@llvm.call.preallocated.*`` intrinsics. 2615 2616.. code-block:: llvm 2617 2618 %foo = type { i64, i32 } 2619 2620 ... 2621 2622 %t = call token @llvm.call.preallocated.setup(i32 1) 2623 %a = call ptr @llvm.call.preallocated.arg(token %t, i32 0) preallocated(%foo) 2624 ; initialize %b 2625 call void @bar(i32 42, ptr preallocated(%foo) %a) ["preallocated"(token %t)] 2626 2627.. _ob_gc_live: 2628 2629GC Live Operand Bundles 2630^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2631 2632A "gc-live" operand bundle is only valid on a :ref:`gc.statepoint <gc_statepoint>` 2633intrinsic. The operand bundle must contain every pointer to a garbage collected 2634object which potentially needs to be updated by the garbage collector. 2635 2636When lowered, any relocated value will be recorded in the corresponding 2637:ref:`stackmap entry <statepoint-stackmap-format>`. See the intrinsic description 2638for further details. 2639 2640ObjC ARC Attached Call Operand Bundles 2641^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2642 2643A ``"clang.arc.attachedcall"`` operand bundle on a call indicates the call is 2644implicitly followed by a marker instruction and a call to an ObjC runtime 2645function that uses the result of the call. The operand bundle takes a mandatory 2646pointer to the runtime function (``@objc_retainAutoreleasedReturnValue`` or 2647``@objc_unsafeClaimAutoreleasedReturnValue``). 2648The return value of a call with this bundle is used by a call to 2649``@llvm.objc.clang.arc.noop.use`` unless the called function's return type is 2650void, in which case the operand bundle is ignored. 2651 2652.. code-block:: llvm 2653 2654 ; The marker instruction and a runtime function call are inserted after the call 2655 ; to @foo. 2656 call ptr @foo() [ "clang.arc.attachedcall"(ptr @objc_retainAutoreleasedReturnValue) ] 2657 call ptr @foo() [ "clang.arc.attachedcall"(ptr @objc_unsafeClaimAutoreleasedReturnValue) ] 2658 2659The operand bundle is needed to ensure the call is immediately followed by the 2660marker instruction and the ObjC runtime call in the final output. 2661 2662.. _ob_ptrauth: 2663 2664Pointer Authentication Operand Bundles 2665^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2666 2667Pointer Authentication operand bundles are characterized by the 2668``"ptrauth"`` operand bundle tag. They are described in the 2669`Pointer Authentication <PointerAuth.html#operand-bundle>`__ document. 2670 2671.. _ob_kcfi: 2672 2673KCFI Operand Bundles 2674^^^^^^^^^^^^^^^^^^^^ 2675 2676A ``"kcfi"`` operand bundle on an indirect call indicates that the call will 2677be preceded by a runtime type check, which validates that the call target is 2678prefixed with a :ref:`type identifier<md_kcfi_type>` that matches the operand 2679bundle attribute. For example: 2680 2681.. code-block:: llvm 2682 2683 call void %0() ["kcfi"(i32 1234)] 2684 2685Clang emits KCFI operand bundles and the necessary metadata with 2686``-fsanitize=kcfi``. 2687 2688.. _moduleasm: 2689 2690Module-Level Inline Assembly 2691---------------------------- 2692 2693Modules may contain "module-level inline asm" blocks, which corresponds 2694to the GCC "file scope inline asm" blocks. These blocks are internally 2695concatenated by LLVM and treated as a single unit, but may be separated 2696in the ``.ll`` file if desired. The syntax is very simple: 2697 2698.. code-block:: llvm 2699 2700 module asm "inline asm code goes here" 2701 module asm "more can go here" 2702 2703The strings can contain any character by escaping non-printable 2704characters. The escape sequence used is simply "\\xx" where "xx" is the 2705two digit hex code for the number. 2706 2707Note that the assembly string *must* be parseable by LLVM's integrated assembler 2708(unless it is disabled), even when emitting a ``.s`` file. 2709 2710.. _langref_datalayout: 2711 2712Data Layout 2713----------- 2714 2715A module may specify a target specific data layout string that specifies 2716how data is to be laid out in memory. The syntax for the data layout is 2717simply: 2718 2719.. code-block:: llvm 2720 2721 target datalayout = "layout specification" 2722 2723The *layout specification* consists of a list of specifications 2724separated by the minus sign character ('-'). Each specification starts 2725with a letter and may include other information after the letter to 2726define some aspect of the data layout. The specifications accepted are 2727as follows: 2728 2729``E`` 2730 Specifies that the target lays out data in big-endian form. That is, 2731 the bits with the most significance have the lowest address 2732 location. 2733``e`` 2734 Specifies that the target lays out data in little-endian form. That 2735 is, the bits with the least significance have the lowest address 2736 location. 2737``S<size>`` 2738 Specifies the natural alignment of the stack in bits. Alignment 2739 promotion of stack variables is limited to the natural stack 2740 alignment to avoid dynamic stack realignment. The stack alignment 2741 must be a multiple of 8-bits. If omitted, the natural stack 2742 alignment defaults to "unspecified", which does not prevent any 2743 alignment promotions. 2744``P<address space>`` 2745 Specifies the address space that corresponds to program memory. 2746 Harvard architectures can use this to specify what space LLVM 2747 should place things such as functions into. If omitted, the 2748 program memory space defaults to the default address space of 0, 2749 which corresponds to a Von Neumann architecture that has code 2750 and data in the same space. 2751``G<address space>`` 2752 Specifies the address space to be used by default when creating global 2753 variables. If omitted, the globals address space defaults to the default 2754 address space 0. 2755 Note: variable declarations without an address space are always created in 2756 address space 0, this property only affects the default value to be used 2757 when creating globals without additional contextual information (e.g. in 2758 LLVM passes). 2759``A<address space>`` 2760 Specifies the address space of objects created by '``alloca``'. 2761 Defaults to the default address space of 0. 2762``p[n]:<size>:<abi>[:<pref>][:<idx>]`` 2763 This specifies the *size* of a pointer and its ``<abi>`` and 2764 ``<pref>``\erred alignments for address space ``n``. ``<pref>`` is optional 2765 and defaults to ``<abi>``. The fourth parameter ``<idx>`` is the size of the 2766 index that used for address calculation. If not 2767 specified, the default index size is equal to the pointer size. All sizes 2768 are in bits. The address space, ``n``, is optional, and if not specified, 2769 denotes the default address space 0. The value of ``n`` must be 2770 in the range [1,2^23). 2771``i<size>:<abi>[:<pref>]`` 2772 This specifies the alignment for an integer type of a given bit 2773 ``<size>``. The value of ``<size>`` must be in the range [1,2^23). 2774 ``<pref>`` is optional and defaults to ``<abi>``. 2775 For ``i8``, the ``<abi>`` value must equal 8, 2776 that is, ``i8`` must be naturally aligned. 2777``v<size>:<abi>[:<pref>]`` 2778 This specifies the alignment for a vector type of a given bit 2779 ``<size>``. The value of ``<size>`` must be in the range [1,2^23). 2780 ``<pref>`` is optional and defaults to ``<abi>``. 2781``f<size>:<abi>[:<pref>]`` 2782 This specifies the alignment for a floating-point type of a given bit 2783 ``<size>``. Only values of ``<size>`` that are supported by the target 2784 will work. 32 (float) and 64 (double) are supported on all targets; 80 2785 or 128 (different flavors of long double) are also supported on some 2786 targets. The value of ``<size>`` must be in the range [1,2^23). 2787 ``<pref>`` is optional and defaults to ``<abi>``. 2788``a:<abi>[:<pref>]`` 2789 This specifies the alignment for an object of aggregate type. 2790 ``<pref>`` is optional and defaults to ``<abi>``. 2791``F<type><abi>`` 2792 This specifies the alignment for function pointers. 2793 The options for ``<type>`` are: 2794 2795 * ``i``: The alignment of function pointers is independent of the alignment 2796 of functions, and is a multiple of ``<abi>``. 2797 * ``n``: The alignment of function pointers is a multiple of the explicit 2798 alignment specified on the function, and is a multiple of ``<abi>``. 2799``m:<mangling>`` 2800 If present, specifies that llvm names are mangled in the output. Symbols 2801 prefixed with the mangling escape character ``\01`` are passed through 2802 directly to the assembler without the escape character. The mangling style 2803 options are 2804 2805 * ``e``: ELF mangling: Private symbols get a ``.L`` prefix. 2806 * ``l``: GOFF mangling: Private symbols get a ``@`` prefix. 2807 * ``m``: Mips mangling: Private symbols get a ``$`` prefix. 2808 * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other 2809 symbols get a ``_`` prefix. 2810 * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix. 2811 Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``, 2812 ``__fastcall``, and ``__vectorcall`` have custom mangling that appends 2813 ``@N`` where N is the number of bytes used to pass parameters. C++ symbols 2814 starting with ``?`` are not mangled in any way. 2815 * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C 2816 symbols do not receive a ``_`` prefix. 2817 * ``a``: XCOFF mangling: Private symbols get a ``L..`` prefix. 2818``n<size1>:<size2>:<size3>...`` 2819 This specifies a set of native integer widths for the target CPU in 2820 bits. For example, it might contain ``n32`` for 32-bit PowerPC, 2821 ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of 2822 this set are considered to support most general arithmetic operations 2823 efficiently. 2824``ni:<address space0>:<address space1>:<address space2>...`` 2825 This specifies pointer types with the specified address spaces 2826 as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0`` 2827 address space cannot be specified as non-integral. 2828 2829On every specification that takes a ``<abi>:<pref>``, specifying the 2830``<pref>`` alignment is optional. If omitted, the preceding ``:`` 2831should be omitted too and ``<pref>`` will be equal to ``<abi>``. 2832 2833When constructing the data layout for a given target, LLVM starts with a 2834default set of specifications which are then (possibly) overridden by 2835the specifications in the ``datalayout`` keyword. The default 2836specifications are given in this list: 2837 2838- ``e`` - little endian 2839- ``p:64:64:64`` - 64-bit pointers with 64-bit alignment. 2840- ``p[n]:64:64:64`` - Other address spaces are assumed to be the 2841 same as the default address space. 2842- ``S0`` - natural stack alignment is unspecified 2843- ``i1:8:8`` - i1 is 8-bit (byte) aligned 2844- ``i8:8:8`` - i8 is 8-bit (byte) aligned as mandated 2845- ``i16:16:16`` - i16 is 16-bit aligned 2846- ``i32:32:32`` - i32 is 32-bit aligned 2847- ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred 2848 alignment of 64-bits 2849- ``f16:16:16`` - half is 16-bit aligned 2850- ``f32:32:32`` - float is 32-bit aligned 2851- ``f64:64:64`` - double is 64-bit aligned 2852- ``f128:128:128`` - quad is 128-bit aligned 2853- ``v64:64:64`` - 64-bit vector is 64-bit aligned 2854- ``v128:128:128`` - 128-bit vector is 128-bit aligned 2855- ``a:0:64`` - aggregates are 64-bit aligned 2856 2857When LLVM is determining the alignment for a given type, it uses the 2858following rules: 2859 2860#. If the type sought is an exact match for one of the specifications, 2861 that specification is used. 2862#. If no match is found, and the type sought is an integer type, then 2863 the smallest integer type that is larger than the bitwidth of the 2864 sought type is used. If none of the specifications are larger than 2865 the bitwidth then the largest integer type is used. For example, 2866 given the default specifications above, the i7 type will use the 2867 alignment of i8 (next largest) while both i65 and i256 will use the 2868 alignment of i64 (largest specified). 2869 2870The function of the data layout string may not be what you expect. 2871Notably, this is not a specification from the frontend of what alignment 2872the code generator should use. 2873 2874Instead, if specified, the target data layout is required to match what 2875the ultimate *code generator* expects. This string is used by the 2876mid-level optimizers to improve code, and this only works if it matches 2877what the ultimate code generator uses. There is no way to generate IR 2878that does not embed this target-specific detail into the IR. If you 2879don't specify the string, the default specifications will be used to 2880generate a Data Layout and the optimization phases will operate 2881accordingly and introduce target specificity into the IR with respect to 2882these default specifications. 2883 2884.. _langref_triple: 2885 2886Target Triple 2887------------- 2888 2889A module may specify a target triple string that describes the target 2890host. The syntax for the target triple is simply: 2891 2892.. code-block:: llvm 2893 2894 target triple = "x86_64-apple-macosx10.7.0" 2895 2896The *target triple* string consists of a series of identifiers delimited 2897by the minus sign character ('-'). The canonical forms are: 2898 2899:: 2900 2901 ARCHITECTURE-VENDOR-OPERATING_SYSTEM 2902 ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT 2903 2904This information is passed along to the backend so that it generates 2905code for the proper architecture. It's possible to override this on the 2906command line with the ``-mtriple`` command line option. 2907 2908.. _objectlifetime: 2909 2910Object Lifetime 2911---------------------- 2912 2913A memory object, or simply object, is a region of a memory space that is 2914reserved by a memory allocation such as :ref:`alloca <i_alloca>`, heap 2915allocation calls, and global variable definitions. 2916Once it is allocated, the bytes stored in the region can only be read or written 2917through a pointer that is :ref:`based on <pointeraliasing>` the allocation 2918value. 2919If a pointer that is not based on the object tries to read or write to the 2920object, it is undefined behavior. 2921 2922A lifetime of a memory object is a property that decides its accessibility. 2923Unless stated otherwise, a memory object is alive since its allocation, and 2924dead after its deallocation. 2925It is undefined behavior to access a memory object that isn't alive, but 2926operations that don't dereference it such as 2927:ref:`getelementptr <i_getelementptr>`, :ref:`ptrtoint <i_ptrtoint>` and 2928:ref:`icmp <i_icmp>` return a valid result. 2929This explains code motion of these instructions across operations that 2930impact the object's lifetime. 2931A stack object's lifetime can be explicitly specified using 2932:ref:`llvm.lifetime.start <int_lifestart>` and 2933:ref:`llvm.lifetime.end <int_lifeend>` intrinsic function calls. 2934 2935.. _pointeraliasing: 2936 2937Pointer Aliasing Rules 2938---------------------- 2939 2940Any memory access must be done through a pointer value associated with 2941an address range of the memory access, otherwise the behavior is 2942undefined. Pointer values are associated with address ranges according 2943to the following rules: 2944 2945- A pointer value is associated with the addresses associated with any 2946 value it is *based* on. 2947- An address of a global variable is associated with the address range 2948 of the variable's storage. 2949- The result value of an allocation instruction is associated with the 2950 address range of the allocated storage. 2951- A null pointer in the default address-space is associated with no 2952 address. 2953- An :ref:`undef value <undefvalues>` in *any* address-space is 2954 associated with no address. 2955- An integer constant other than zero or a pointer value returned from 2956 a function not defined within LLVM may be associated with address 2957 ranges allocated through mechanisms other than those provided by 2958 LLVM. Such ranges shall not overlap with any ranges of addresses 2959 allocated by mechanisms provided by LLVM. 2960 2961A pointer value is *based* on another pointer value according to the 2962following rules: 2963 2964- A pointer value formed from a scalar ``getelementptr`` operation is *based* on 2965 the pointer-typed operand of the ``getelementptr``. 2966- The pointer in lane *l* of the result of a vector ``getelementptr`` operation 2967 is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand 2968 of the ``getelementptr``. 2969- The result value of a ``bitcast`` is *based* on the operand of the 2970 ``bitcast``. 2971- A pointer value formed by an ``inttoptr`` is *based* on all pointer 2972 values that contribute (directly or indirectly) to the computation of 2973 the pointer's value. 2974- The "*based* on" relationship is transitive. 2975 2976Note that this definition of *"based"* is intentionally similar to the 2977definition of *"based"* in C99, though it is slightly weaker. 2978 2979LLVM IR does not associate types with memory. The result type of a 2980``load`` merely indicates the size and alignment of the memory from 2981which to load, as well as the interpretation of the value. The first 2982operand type of a ``store`` similarly only indicates the size and 2983alignment of the store. 2984 2985Consequently, type-based alias analysis, aka TBAA, aka 2986``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR. 2987:ref:`Metadata <metadata>` may be used to encode additional information 2988which specialized optimization passes may use to implement type-based 2989alias analysis. 2990 2991.. _pointercapture: 2992 2993Pointer Capture 2994--------------- 2995 2996Given a function call and a pointer that is passed as an argument or stored in 2997the memory before the call, a pointer is *captured* by the call if it makes a 2998copy of any part of the pointer that outlives the call. 2999To be precise, a pointer is captured if one or more of the following conditions 3000hold: 3001 30021. The call stores any bit of the pointer carrying information into a place, 3003 and the stored bits can be read from the place by the caller after this call 3004 exits. 3005 3006.. code-block:: llvm 3007 3008 @glb = global ptr null 3009 @glb2 = global ptr null 3010 @glb3 = global ptr null 3011 @glbi = global i32 0 3012 3013 define ptr @f(ptr %a, ptr %b, ptr %c, ptr %d, ptr %e) { 3014 store ptr %a, ptr @glb ; %a is captured by this call 3015 3016 store ptr %b, ptr @glb2 ; %b isn't captured because the stored value is overwritten by the store below 3017 store ptr null, ptr @glb2 3018 3019 store ptr %c, ptr @glb3 3020 call void @g() ; If @g makes a copy of %c that outlives this call (@f), %c is captured 3021 store ptr null, ptr @glb3 3022 3023 %i = ptrtoint ptr %d to i64 3024 %j = trunc i64 %i to i32 3025 store i32 %j, ptr @glbi ; %d is captured 3026 3027 ret ptr %e ; %e is captured 3028 } 3029 30302. The call stores any bit of the pointer carrying information into a place, 3031 and the stored bits can be safely read from the place by another thread via 3032 synchronization. 3033 3034.. code-block:: llvm 3035 3036 @lock = global i1 true 3037 3038 define void @f(ptr %a) { 3039 store ptr %a, ptr* @glb 3040 store atomic i1 false, ptr @lock release ; %a is captured because another thread can safely read @glb 3041 store ptr null, ptr @glb 3042 ret void 3043 } 3044 30453. The call's behavior depends on any bit of the pointer carrying information. 3046 3047.. code-block:: llvm 3048 3049 @glb = global i8 0 3050 3051 define void @f(ptr %a) { 3052 %c = icmp eq ptr %a, @glb 3053 br i1 %c, label %BB_EXIT, label %BB_CONTINUE ; escapes %a 3054 BB_EXIT: 3055 call void @exit() 3056 unreachable 3057 BB_CONTINUE: 3058 ret void 3059 } 3060 30614. The pointer is used in a volatile access as its address. 3062 3063 3064.. _volatile: 3065 3066Volatile Memory Accesses 3067------------------------ 3068 3069Certain memory accesses, such as :ref:`load <i_load>`'s, 3070:ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be 3071marked ``volatile``. The optimizers must not change the number of 3072volatile operations or change their order of execution relative to other 3073volatile operations. The optimizers *may* change the order of volatile 3074operations relative to non-volatile operations. This is not Java's 3075"volatile" and has no cross-thread synchronization behavior. 3076 3077A volatile load or store may have additional target-specific semantics. 3078Any volatile operation can have side effects, and any volatile operation 3079can read and/or modify state which is not accessible via a regular load 3080or store in this module. Volatile operations may use addresses which do 3081not point to memory (like MMIO registers). This means the compiler may 3082not use a volatile operation to prove a non-volatile access to that 3083address has defined behavior. 3084 3085The allowed side-effects for volatile accesses are limited. If a 3086non-volatile store to a given address would be legal, a volatile 3087operation may modify the memory at that address. A volatile operation 3088may not modify any other memory accessible by the module being compiled. 3089A volatile operation may not call any code in the current module. 3090 3091In general (without target specific context), the address space of a 3092volatile operation may not be changed. Different address spaces may 3093have different trapping behavior when dereferencing an invalid 3094pointer. 3095 3096The compiler may assume execution will continue after a volatile operation, 3097so operations which modify memory or may have undefined behavior can be 3098hoisted past a volatile operation. 3099 3100As an exception to the preceding rule, the compiler may not assume execution 3101will continue after a volatile store operation. This restriction is necessary 3102to support the somewhat common pattern in C of intentionally storing to an 3103invalid pointer to crash the program. In the future, it might make sense to 3104allow frontends to control this behavior. 3105 3106IR-level volatile loads and stores cannot safely be optimized into llvm.memcpy 3107or llvm.memmove intrinsics even when those intrinsics are flagged volatile. 3108Likewise, the backend should never split or merge target-legal volatile 3109load/store instructions. Similarly, IR-level volatile loads and stores cannot 3110change from integer to floating-point or vice versa. 3111 3112.. admonition:: Rationale 3113 3114 Platforms may rely on volatile loads and stores of natively supported 3115 data width to be executed as single instruction. For example, in C 3116 this holds for an l-value of volatile primitive type with native 3117 hardware support, but not necessarily for aggregate types. The 3118 frontend upholds these expectations, which are intentionally 3119 unspecified in the IR. The rules above ensure that IR transformations 3120 do not violate the frontend's contract with the language. 3121 3122.. _memmodel: 3123 3124Memory Model for Concurrent Operations 3125-------------------------------------- 3126 3127The LLVM IR does not define any way to start parallel threads of 3128execution or to register signal handlers. Nonetheless, there are 3129platform-specific ways to create them, and we define LLVM IR's behavior 3130in their presence. This model is inspired by the C++0x memory model. 3131 3132For a more informal introduction to this model, see the :doc:`Atomics`. 3133 3134We define a *happens-before* partial order as the least partial order 3135that 3136 3137- Is a superset of single-thread program order, and 3138- When a *synchronizes-with* ``b``, includes an edge from ``a`` to 3139 ``b``. *Synchronizes-with* pairs are introduced by platform-specific 3140 techniques, like pthread locks, thread creation, thread joining, 3141 etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering 3142 Constraints <ordering>`). 3143 3144Note that program order does not introduce *happens-before* edges 3145between a thread and signals executing inside that thread. 3146 3147Every (defined) read operation (load instructions, memcpy, atomic 3148loads/read-modify-writes, etc.) R reads a series of bytes written by 3149(defined) write operations (store instructions, atomic 3150stores/read-modify-writes, memcpy, etc.). For the purposes of this 3151section, initialized globals are considered to have a write of the 3152initializer which is atomic and happens before any other read or write 3153of the memory in question. For each byte of a read R, R\ :sub:`byte` 3154may see any write to the same byte, except: 3155 3156- If write\ :sub:`1` happens before write\ :sub:`2`, and 3157 write\ :sub:`2` happens before R\ :sub:`byte`, then 3158 R\ :sub:`byte` does not see write\ :sub:`1`. 3159- If R\ :sub:`byte` happens before write\ :sub:`3`, then 3160 R\ :sub:`byte` does not see write\ :sub:`3`. 3161 3162Given that definition, R\ :sub:`byte` is defined as follows: 3163 3164- If R is volatile, the result is target-dependent. (Volatile is 3165 supposed to give guarantees which can support ``sig_atomic_t`` in 3166 C/C++, and may be used for accesses to addresses that do not behave 3167 like normal memory. It does not generally provide cross-thread 3168 synchronization.) 3169- Otherwise, if there is no write to the same byte that happens before 3170 R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte. 3171- Otherwise, if R\ :sub:`byte` may see exactly one write, 3172 R\ :sub:`byte` returns the value written by that write. 3173- Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may 3174 see are atomic, it chooses one of the values written. See the :ref:`Atomic 3175 Memory Ordering Constraints <ordering>` section for additional 3176 constraints on how the choice is made. 3177- Otherwise R\ :sub:`byte` returns ``undef``. 3178 3179R returns the value composed of the series of bytes it read. This 3180implies that some bytes within the value may be ``undef`` **without** 3181the entire value being ``undef``. Note that this only defines the 3182semantics of the operation; it doesn't mean that targets will emit more 3183than one instruction to read the series of bytes. 3184 3185Note that in cases where none of the atomic intrinsics are used, this 3186model places only one restriction on IR transformations on top of what 3187is required for single-threaded execution: introducing a store to a byte 3188which might not otherwise be stored is not allowed in general. 3189(Specifically, in the case where another thread might write to and read 3190from an address, introducing a store can change a load that may see 3191exactly one write into a load that may see multiple writes.) 3192 3193.. _ordering: 3194 3195Atomic Memory Ordering Constraints 3196---------------------------------- 3197 3198Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`, 3199:ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`, 3200:ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take 3201ordering parameters that determine which other atomic instructions on 3202the same address they *synchronize with*. These semantics are borrowed 3203from Java and C++0x, but are somewhat more colloquial. If these 3204descriptions aren't precise enough, check those specs (see spec 3205references in the :doc:`atomics guide <Atomics>`). 3206:ref:`fence <i_fence>` instructions treat these orderings somewhat 3207differently since they don't take an address. See that instruction's 3208documentation for details. 3209 3210For a simpler introduction to the ordering constraints, see the 3211:doc:`Atomics`. 3212 3213``unordered`` 3214 The set of values that can be read is governed by the happens-before 3215 partial order. A value cannot be read unless some operation wrote 3216 it. This is intended to provide a guarantee strong enough to model 3217 Java's non-volatile shared variables. This ordering cannot be 3218 specified for read-modify-write operations; it is not strong enough 3219 to make them atomic in any interesting way. 3220``monotonic`` 3221 In addition to the guarantees of ``unordered``, there is a single 3222 total order for modifications by ``monotonic`` operations on each 3223 address. All modification orders must be compatible with the 3224 happens-before order. There is no guarantee that the modification 3225 orders can be combined to a global total order for the whole program 3226 (and this often will not be possible). The read in an atomic 3227 read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and 3228 :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification 3229 order immediately before the value it writes. If one atomic read 3230 happens before another atomic read of the same address, the later 3231 read must see the same value or a later value in the address's 3232 modification order. This disallows reordering of ``monotonic`` (or 3233 stronger) operations on the same address. If an address is written 3234 ``monotonic``-ally by one thread, and other threads ``monotonic``-ally 3235 read that address repeatedly, the other threads must eventually see 3236 the write. This corresponds to the C++0x/C1x 3237 ``memory_order_relaxed``. 3238``acquire`` 3239 In addition to the guarantees of ``monotonic``, a 3240 *synchronizes-with* edge may be formed with a ``release`` operation. 3241 This is intended to model C++'s ``memory_order_acquire``. 3242``release`` 3243 In addition to the guarantees of ``monotonic``, if this operation 3244 writes a value which is subsequently read by an ``acquire`` 3245 operation, it *synchronizes-with* that operation. (This isn't a 3246 complete description; see the C++0x definition of a release 3247 sequence.) This corresponds to the C++0x/C1x 3248 ``memory_order_release``. 3249``acq_rel`` (acquire+release) 3250 Acts as both an ``acquire`` and ``release`` operation on its 3251 address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``. 3252``seq_cst`` (sequentially consistent) 3253 In addition to the guarantees of ``acq_rel`` (``acquire`` for an 3254 operation that only reads, ``release`` for an operation that only 3255 writes), there is a global total order on all 3256 sequentially-consistent operations on all addresses, which is 3257 consistent with the *happens-before* partial order and with the 3258 modification orders of all the affected addresses. Each 3259 sequentially-consistent read sees the last preceding write to the 3260 same address in this global order. This corresponds to the C++0x/C1x 3261 ``memory_order_seq_cst`` and Java volatile. 3262 3263.. _syncscope: 3264 3265If an atomic operation is marked ``syncscope("singlethread")``, it only 3266*synchronizes with* and only participates in the seq\_cst total orderings of 3267other operations running in the same thread (for example, in signal handlers). 3268 3269If an atomic operation is marked ``syncscope("<target-scope>")``, where 3270``<target-scope>`` is a target specific synchronization scope, then it is target 3271dependent if it *synchronizes with* and participates in the seq\_cst total 3272orderings of other operations. 3273 3274Otherwise, an atomic operation that is not marked ``syncscope("singlethread")`` 3275or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the 3276seq\_cst total orderings of other operations that are not marked 3277``syncscope("singlethread")`` or ``syncscope("<target-scope>")``. 3278 3279.. _floatenv: 3280 3281Floating-Point Environment 3282-------------------------- 3283 3284The default LLVM floating-point environment assumes that floating-point 3285instructions do not have side effects. Results assume the round-to-nearest 3286rounding mode. No floating-point exception state is maintained in this 3287environment. Therefore, there is no attempt to create or preserve invalid 3288operation (SNaN) or division-by-zero exceptions. 3289 3290The benefit of this exception-free assumption is that floating-point 3291operations may be speculated freely without any other fast-math relaxations 3292to the floating-point model. 3293 3294Code that requires different behavior than this should use the 3295:ref:`Constrained Floating-Point Intrinsics <constrainedfp>`. 3296 3297.. _fastmath: 3298 3299Fast-Math Flags 3300--------------- 3301 3302LLVM IR floating-point operations (:ref:`fneg <i_fneg>`, :ref:`fadd <i_fadd>`, 3303:ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`, 3304:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`), :ref:`phi <i_phi>`, 3305:ref:`select <i_select>` and :ref:`call <i_call>` 3306may use the following flags to enable otherwise unsafe 3307floating-point transformations. 3308 3309``nnan`` 3310 No NaNs - Allow optimizations to assume the arguments and result are not 3311 NaN. If an argument is a nan, or the result would be a nan, it produces 3312 a :ref:`poison value <poisonvalues>` instead. 3313 3314``ninf`` 3315 No Infs - Allow optimizations to assume the arguments and result are not 3316 +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it 3317 produces a :ref:`poison value <poisonvalues>` instead. 3318 3319``nsz`` 3320 No Signed Zeros - Allow optimizations to treat the sign of a zero 3321 argument or zero result as insignificant. This does not imply that -0.0 3322 is poison and/or guaranteed to not exist in the operation. 3323 3324``arcp`` 3325 Allow Reciprocal - Allow optimizations to use the reciprocal of an 3326 argument rather than perform division. 3327 3328``contract`` 3329 Allow floating-point contraction (e.g. fusing a multiply followed by an 3330 addition into a fused multiply-and-add). This does not enable reassociating 3331 to form arbitrary contractions. For example, ``(a*b) + (c*d) + e`` can not 3332 be transformed into ``(a*b) + ((c*d) + e)`` to create two fma operations. 3333 3334``afn`` 3335 Approximate functions - Allow substitution of approximate calculations for 3336 functions (sin, log, sqrt, etc). See floating-point intrinsic definitions 3337 for places where this can apply to LLVM's intrinsic math functions. 3338 3339``reassoc`` 3340 Allow reassociation transformations for floating-point instructions. 3341 This may dramatically change results in floating-point. 3342 3343``fast`` 3344 This flag implies all of the others. 3345 3346.. _uselistorder: 3347 3348Use-list Order Directives 3349------------------------- 3350 3351Use-list directives encode the in-memory order of each use-list, allowing the 3352order to be recreated. ``<order-indexes>`` is a comma-separated list of 3353indexes that are assigned to the referenced value's uses. The referenced 3354value's use-list is immediately sorted by these indexes. 3355 3356Use-list directives may appear at function scope or global scope. They are not 3357instructions, and have no effect on the semantics of the IR. When they're at 3358function scope, they must appear after the terminator of the final basic block. 3359 3360If basic blocks have their address taken via ``blockaddress()`` expressions, 3361``uselistorder_bb`` can be used to reorder their use-lists from outside their 3362function's scope. 3363 3364:Syntax: 3365 3366:: 3367 3368 uselistorder <ty> <value>, { <order-indexes> } 3369 uselistorder_bb @function, %block { <order-indexes> } 3370 3371:Examples: 3372 3373:: 3374 3375 define void @foo(i32 %arg1, i32 %arg2) { 3376 entry: 3377 ; ... instructions ... 3378 bb: 3379 ; ... instructions ... 3380 3381 ; At function scope. 3382 uselistorder i32 %arg1, { 1, 0, 2 } 3383 uselistorder label %bb, { 1, 0 } 3384 } 3385 3386 ; At global scope. 3387 uselistorder ptr @global, { 1, 2, 0 } 3388 uselistorder i32 7, { 1, 0 } 3389 uselistorder i32 (i32) @bar, { 1, 0 } 3390 uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 } 3391 3392.. _source_filename: 3393 3394Source Filename 3395--------------- 3396 3397The *source filename* string is set to the original module identifier, 3398which will be the name of the compiled source file when compiling from 3399source through the clang front end, for example. It is then preserved through 3400the IR and bitcode. 3401 3402This is currently necessary to generate a consistent unique global 3403identifier for local functions used in profile data, which prepends the 3404source file name to the local function name. 3405 3406The syntax for the source file name is simply: 3407 3408.. code-block:: text 3409 3410 source_filename = "/path/to/source.c" 3411 3412.. _typesystem: 3413 3414Type System 3415=========== 3416 3417The LLVM type system is one of the most important features of the 3418intermediate representation. Being typed enables a number of 3419optimizations to be performed on the intermediate representation 3420directly, without having to do extra analyses on the side before the 3421transformation. A strong type system makes it easier to read the 3422generated code and enables novel analyses and transformations that are 3423not feasible to perform on normal three address code representations. 3424 3425.. _t_void: 3426 3427Void Type 3428--------- 3429 3430:Overview: 3431 3432 3433The void type does not represent any value and has no size. 3434 3435:Syntax: 3436 3437 3438:: 3439 3440 void 3441 3442 3443.. _t_function: 3444 3445Function Type 3446------------- 3447 3448:Overview: 3449 3450 3451The function type can be thought of as a function signature. It consists of a 3452return type and a list of formal parameter types. The return type of a function 3453type is a void type or first class type --- except for :ref:`label <t_label>` 3454and :ref:`metadata <t_metadata>` types. 3455 3456:Syntax: 3457 3458:: 3459 3460 <returntype> (<parameter list>) 3461 3462...where '``<parameter list>``' is a comma-separated list of type 3463specifiers. Optionally, the parameter list may include a type ``...``, which 3464indicates that the function takes a variable number of arguments. Variable 3465argument functions can access their arguments with the :ref:`variable argument 3466handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type 3467except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`. 3468 3469:Examples: 3470 3471+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3472| ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` | 3473+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3474| ``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. | 3475+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3476| ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values | 3477+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3478 3479.. _t_firstclass: 3480 3481First Class Types 3482----------------- 3483 3484The :ref:`first class <t_firstclass>` types are perhaps the most important. 3485Values of these types are the only ones which can be produced by 3486instructions. 3487 3488.. _t_single_value: 3489 3490Single Value Types 3491^^^^^^^^^^^^^^^^^^ 3492 3493These are the types that are valid in registers from CodeGen's perspective. 3494 3495.. _t_integer: 3496 3497Integer Type 3498"""""""""""" 3499 3500:Overview: 3501 3502The integer type is a very simple type that simply specifies an 3503arbitrary bit width for the integer type desired. Any bit width from 1 3504bit to 2\ :sup:`23`\ (about 8 million) can be specified. 3505 3506:Syntax: 3507 3508:: 3509 3510 iN 3511 3512The number of bits the integer will occupy is specified by the ``N`` 3513value. 3514 3515Examples: 3516********* 3517 3518+----------------+------------------------------------------------+ 3519| ``i1`` | a single-bit integer. | 3520+----------------+------------------------------------------------+ 3521| ``i32`` | a 32-bit integer. | 3522+----------------+------------------------------------------------+ 3523| ``i1942652`` | a really big integer of over 1 million bits. | 3524+----------------+------------------------------------------------+ 3525 3526.. _t_floating: 3527 3528Floating-Point Types 3529"""""""""""""""""""" 3530 3531.. list-table:: 3532 :header-rows: 1 3533 3534 * - Type 3535 - Description 3536 3537 * - ``half`` 3538 - 16-bit floating-point value 3539 3540 * - ``bfloat`` 3541 - 16-bit "brain" floating-point value (7-bit significand). Provides the 3542 same number of exponent bits as ``float``, so that it matches its dynamic 3543 range, but with greatly reduced precision. Used in Intel's AVX-512 BF16 3544 extensions and Arm's ARMv8.6-A extensions, among others. 3545 3546 * - ``float`` 3547 - 32-bit floating-point value 3548 3549 * - ``double`` 3550 - 64-bit floating-point value 3551 3552 * - ``fp128`` 3553 - 128-bit floating-point value (113-bit significand) 3554 3555 * - ``x86_fp80`` 3556 - 80-bit floating-point value (X87) 3557 3558 * - ``ppc_fp128`` 3559 - 128-bit floating-point value (two 64-bits) 3560 3561The binary format of half, float, double, and fp128 correspond to the 3562IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128 3563respectively. 3564 3565X86_amx Type 3566"""""""""""" 3567 3568:Overview: 3569 3570The x86_amx type represents a value held in an AMX tile register on an x86 3571machine. The operations allowed on it are quite limited. Only few intrinsics 3572are allowed: stride load and store, zero and dot product. No instruction is 3573allowed for this type. There are no arguments, arrays, pointers, vectors 3574or constants of this type. 3575 3576:Syntax: 3577 3578:: 3579 3580 x86_amx 3581 3582 3583X86_mmx Type 3584"""""""""""" 3585 3586:Overview: 3587 3588The x86_mmx type represents a value held in an MMX register on an x86 3589machine. The operations allowed on it are quite limited: parameters and 3590return values, load and store, and bitcast. User-specified MMX 3591instructions are represented as intrinsic or asm calls with arguments 3592and/or results of this type. There are no arrays, vectors or constants 3593of this type. 3594 3595:Syntax: 3596 3597:: 3598 3599 x86_mmx 3600 3601 3602.. _t_pointer: 3603 3604Pointer Type 3605"""""""""""" 3606 3607:Overview: 3608 3609The pointer type ``ptr`` is used to specify memory locations. Pointers are 3610commonly used to reference objects in memory. 3611 3612Pointer types may have an optional address space attribute defining 3613the numbered address space where the pointed-to object resides. For 3614example, ``ptr addrspace(5)`` is a pointer to address space 5. 3615In addition to integer constants, ``addrspace`` can also reference one of the 3616address spaces defined in the :ref:`datalayout string<langref_datalayout>`. 3617``addrspace("A")`` will use the alloca address space, ``addrspace("G")`` 3618the default globals address space and ``addrspace("P")`` the program address 3619space. 3620 3621The default address space is number zero. 3622 3623The semantics of non-zero address spaces are target-specific. Memory 3624access through a non-dereferenceable pointer is undefined behavior in 3625any address space. Pointers with the bit-value 0 are only assumed to 3626be non-dereferenceable in address space 0, unless the function is 3627marked with the ``null_pointer_is_valid`` attribute. 3628 3629If an object can be proven accessible through a pointer with a 3630different address space, the access may be modified to use that 3631address space. Exceptions apply if the operation is ``volatile``. 3632 3633Prior to LLVM 15, pointer types also specified a pointee type, such as 3634``i8*``, ``[4 x i32]*`` or ``i32 (i32*)*``. In LLVM 15, such "typed 3635pointers" are still supported under non-default options. See the 3636`opaque pointers document <OpaquePointers.html>`__ for more information. 3637 3638.. _t_target_type: 3639 3640Target Extension Type 3641""""""""""""""""""""" 3642 3643:Overview: 3644 3645Target extension types represent types that must be preserved through 3646optimization, but are otherwise generally opaque to the compiler. They may be 3647used as function parameters or arguments, and in :ref:`phi <i_phi>` or 3648:ref:`select <i_select>` instructions. Some types may be also used in 3649:ref:`alloca <i_alloca>` instructions or as global values, and correspondingly 3650it is legal to use :ref:`load <i_load>` and :ref:`store <i_store>` instructions 3651on them. Full semantics for these types are defined by the target. 3652 3653The only constants that target extension types may have are ``zeroinitializer``, 3654``undef``, and ``poison``. Other possible values for target extension types may 3655arise from target-specific intrinsics and functions. 3656 3657These types cannot be converted to other types. As such, it is not legal to use 3658them in :ref:`bitcast <i_bitcast>` instructions (as a source or target type), 3659nor is it legal to use them in :ref:`ptrtoint <i_ptrtoint>` or 3660:ref:`inttoptr <i_inttoptr>` instructions. Similarly, they are not legal to use 3661in an :ref:`icmp <i_icmp>` instruction. 3662 3663Target extension types have a name and optional type or integer parameters. The 3664meanings of name and parameters are defined by the target. When being defined in 3665LLVM IR, all of the type parameters must precede all of the integer parameters. 3666 3667Specific target extension types are registered with LLVM as having specific 3668properties. These properties can be used to restrict the type from appearing in 3669certain contexts, such as being the type of a global variable or having a 3670``zeroinitializer`` constant be valid. A complete list of type properties may be 3671found in the documentation for ``llvm::TargetExtType::Property`` (`doxygen 3672<https://llvm.org/doxygen/classllvm_1_1TargetExtType.html>`_). 3673 3674:Syntax: 3675 3676.. code-block:: llvm 3677 3678 target("label") 3679 target("label", void) 3680 target("label", void, i32) 3681 target("label", 0, 1, 2) 3682 target("label", void, i32, 0, 1, 2) 3683 3684 3685.. _t_vector: 3686 3687Vector Type 3688""""""""""" 3689 3690:Overview: 3691 3692A vector type is a simple derived type that represents a vector of 3693elements. Vector types are used when multiple primitive data are 3694operated in parallel using a single instruction (SIMD). A vector type 3695requires a size (number of elements), an underlying primitive data type, 3696and a scalable property to represent vectors where the exact hardware 3697vector length is unknown at compile time. Vector types are considered 3698:ref:`first class <t_firstclass>`. 3699 3700:Memory Layout: 3701 3702In general vector elements are laid out in memory in the same way as 3703:ref:`array types <t_array>`. Such an analogy works fine as long as the vector 3704elements are byte sized. However, when the elements of the vector aren't byte 3705sized it gets a bit more complicated. One way to describe the layout is by 3706describing what happens when a vector such as <N x iM> is bitcasted to an 3707integer type with N*M bits, and then following the rules for storing such an 3708integer to memory. 3709 3710A bitcast from a vector type to a scalar integer type will see the elements 3711being packed together (without padding). The order in which elements are 3712inserted in the integer depends on endianess. For little endian element zero 3713is put in the least significant bits of the integer, and for big endian 3714element zero is put in the most significant bits. 3715 3716Using a vector such as ``<i4 1, i4 2, i4 3, i4 5>`` as an example, together 3717with the analogy that we can replace a vector store by a bitcast followed by 3718an integer store, we get this for big endian: 3719 3720.. code-block:: llvm 3721 3722 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16 3723 3724 ; Bitcasting from a vector to an integral type can be seen as 3725 ; concatenating the values: 3726 ; %val now has the hexadecimal value 0x1235. 3727 3728 store i16 %val, ptr %ptr 3729 3730 ; In memory the content will be (8-bit addressing): 3731 ; 3732 ; [%ptr + 0]: 00010010 (0x12) 3733 ; [%ptr + 1]: 00110101 (0x35) 3734 3735The same example for little endian: 3736 3737.. code-block:: llvm 3738 3739 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16 3740 3741 ; Bitcasting from a vector to an integral type can be seen as 3742 ; concatenating the values: 3743 ; %val now has the hexadecimal value 0x5321. 3744 3745 store i16 %val, ptr %ptr 3746 3747 ; In memory the content will be (8-bit addressing): 3748 ; 3749 ; [%ptr + 0]: 01010011 (0x53) 3750 ; [%ptr + 1]: 00100001 (0x21) 3751 3752When ``<N*M>`` isn't evenly divisible by the byte size the exact memory layout 3753is unspecified (just like it is for an integral type of the same size). This 3754is because different targets could put the padding at different positions when 3755the type size is smaller than the type's store size. 3756 3757:Syntax: 3758 3759:: 3760 3761 < <# elements> x <elementtype> > ; Fixed-length vector 3762 < vscale x <# elements> x <elementtype> > ; Scalable vector 3763 3764The number of elements is a constant integer value larger than 0; 3765elementtype may be any integer, floating-point or pointer type. Vectors 3766of size zero are not allowed. For scalable vectors, the total number of 3767elements is a constant multiple (called vscale) of the specified number 3768of elements; vscale is a positive integer that is unknown at compile time 3769and the same hardware-dependent constant for all scalable vectors at run 3770time. The size of a specific scalable vector type is thus constant within 3771IR, even if the exact size in bytes cannot be determined until run time. 3772 3773:Examples: 3774 3775+------------------------+----------------------------------------------------+ 3776| ``<4 x i32>`` | Vector of 4 32-bit integer values. | 3777+------------------------+----------------------------------------------------+ 3778| ``<8 x float>`` | Vector of 8 32-bit floating-point values. | 3779+------------------------+----------------------------------------------------+ 3780| ``<2 x i64>`` | Vector of 2 64-bit integer values. | 3781+------------------------+----------------------------------------------------+ 3782| ``<4 x ptr>`` | Vector of 4 pointers | 3783+------------------------+----------------------------------------------------+ 3784| ``<vscale x 4 x i32>`` | Vector with a multiple of 4 32-bit integer values. | 3785+------------------------+----------------------------------------------------+ 3786 3787.. _t_label: 3788 3789Label Type 3790^^^^^^^^^^ 3791 3792:Overview: 3793 3794The label type represents code labels. 3795 3796:Syntax: 3797 3798:: 3799 3800 label 3801 3802.. _t_token: 3803 3804Token Type 3805^^^^^^^^^^ 3806 3807:Overview: 3808 3809The token type is used when a value is associated with an instruction 3810but all uses of the value must not attempt to introspect or obscure it. 3811As such, it is not appropriate to have a :ref:`phi <i_phi>` or 3812:ref:`select <i_select>` of type token. 3813 3814:Syntax: 3815 3816:: 3817 3818 token 3819 3820 3821 3822.. _t_metadata: 3823 3824Metadata Type 3825^^^^^^^^^^^^^ 3826 3827:Overview: 3828 3829The metadata type represents embedded metadata. No derived types may be 3830created from metadata except for :ref:`function <t_function>` arguments. 3831 3832:Syntax: 3833 3834:: 3835 3836 metadata 3837 3838.. _t_aggregate: 3839 3840Aggregate Types 3841^^^^^^^^^^^^^^^ 3842 3843Aggregate Types are a subset of derived types that can contain multiple 3844member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are 3845aggregate types. :ref:`Vectors <t_vector>` are not considered to be 3846aggregate types. 3847 3848.. _t_array: 3849 3850Array Type 3851"""""""""" 3852 3853:Overview: 3854 3855The array type is a very simple derived type that arranges elements 3856sequentially in memory. The array type requires a size (number of 3857elements) and an underlying data type. 3858 3859:Syntax: 3860 3861:: 3862 3863 [<# elements> x <elementtype>] 3864 3865The number of elements is a constant integer value; ``elementtype`` may 3866be any type with a size. 3867 3868:Examples: 3869 3870+------------------+--------------------------------------+ 3871| ``[40 x i32]`` | Array of 40 32-bit integer values. | 3872+------------------+--------------------------------------+ 3873| ``[41 x i32]`` | Array of 41 32-bit integer values. | 3874+------------------+--------------------------------------+ 3875| ``[4 x i8]`` | Array of 4 8-bit integer values. | 3876+------------------+--------------------------------------+ 3877 3878Here are some examples of multidimensional arrays: 3879 3880+-----------------------------+----------------------------------------------------------+ 3881| ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. | 3882+-----------------------------+----------------------------------------------------------+ 3883| ``[12 x [10 x float]]`` | 12x10 array of single precision floating-point values. | 3884+-----------------------------+----------------------------------------------------------+ 3885| ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. | 3886+-----------------------------+----------------------------------------------------------+ 3887 3888There is no restriction on indexing beyond the end of the array implied 3889by a static type (though there are restrictions on indexing beyond the 3890bounds of an allocated object in some cases). This means that 3891single-dimension 'variable sized array' addressing can be implemented in 3892LLVM with a zero length array type. An implementation of 'pascal style 3893arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for 3894example. 3895 3896.. _t_struct: 3897 3898Structure Type 3899"""""""""""""" 3900 3901:Overview: 3902 3903The structure type is used to represent a collection of data members 3904together in memory. The elements of a structure may be any type that has 3905a size. 3906 3907Structures in memory are accessed using '``load``' and '``store``' by 3908getting a pointer to a field with the '``getelementptr``' instruction. 3909Structures in registers are accessed using the '``extractvalue``' and 3910'``insertvalue``' instructions. 3911 3912Structures may optionally be "packed" structures, which indicate that 3913the alignment of the struct is one byte, and that there is no padding 3914between the elements. In non-packed structs, padding between field types 3915is inserted as defined by the DataLayout string in the module, which is 3916required to match what the underlying code generator expects. 3917 3918Structures can either be "literal" or "identified". A literal structure 3919is defined inline with other types (e.g. ``[2 x {i32, i32}]``) whereas 3920identified types are always defined at the top level with a name. 3921Literal types are uniqued by their contents and can never be recursive 3922or opaque since there is no way to write one. Identified types can be 3923recursive, can be opaqued, and are never uniqued. 3924 3925:Syntax: 3926 3927:: 3928 3929 %T1 = type { <type list> } ; Identified normal struct type 3930 %T2 = type <{ <type list> }> ; Identified packed struct type 3931 3932:Examples: 3933 3934+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3935| ``{ i32, i32, i32 }`` | A triple of three ``i32`` values | 3936+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3937| ``{ float, ptr }`` | A pair, where the first element is a ``float`` and the second element is a :ref:`pointer <t_pointer>`. | 3938+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3939| ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. | 3940+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3941 3942.. _t_opaque: 3943 3944Opaque Structure Types 3945"""""""""""""""""""""" 3946 3947:Overview: 3948 3949Opaque structure types are used to represent structure types that 3950do not have a body specified. This corresponds (for example) to the C 3951notion of a forward declared structure. They can be named (``%X``) or 3952unnamed (``%52``). 3953 3954:Syntax: 3955 3956:: 3957 3958 %X = type opaque 3959 %52 = type opaque 3960 3961:Examples: 3962 3963+--------------+-------------------+ 3964| ``opaque`` | An opaque type. | 3965+--------------+-------------------+ 3966 3967.. _constants: 3968 3969Constants 3970========= 3971 3972LLVM has several different basic types of constants. This section 3973describes them all and their syntax. 3974 3975Simple Constants 3976---------------- 3977 3978**Boolean constants** 3979 The two strings '``true``' and '``false``' are both valid constants 3980 of the ``i1`` type. 3981**Integer constants** 3982 Standard integers (such as '4') are constants of the 3983 :ref:`integer <t_integer>` type. Negative numbers may be used with 3984 integer types. 3985**Floating-point constants** 3986 Floating-point constants use standard decimal notation (e.g. 3987 123.421), exponential notation (e.g. 1.23421e+2), or a more precise 3988 hexadecimal notation (see below). The assembler requires the exact 3989 decimal value of a floating-point constant. For example, the 3990 assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating 3991 decimal in binary. Floating-point constants must have a 3992 :ref:`floating-point <t_floating>` type. 3993**Null pointer constants** 3994 The identifier '``null``' is recognized as a null pointer constant 3995 and must be of :ref:`pointer type <t_pointer>`. 3996**Token constants** 3997 The identifier '``none``' is recognized as an empty token constant 3998 and must be of :ref:`token type <t_token>`. 3999 4000The one non-intuitive notation for constants is the hexadecimal form of 4001floating-point constants. For example, the form 4002'``double 0x432ff973cafa8000``' is equivalent to (but harder to read 4003than) '``double 4.5e+15``'. The only time hexadecimal floating-point 4004constants are required (and the only time that they are generated by the 4005disassembler) is when a floating-point constant must be emitted but it 4006cannot be represented as a decimal floating-point number in a reasonable 4007number of digits. For example, NaN's, infinities, and other special 4008values are represented in their IEEE hexadecimal format so that assembly 4009and disassembly do not cause any bits to change in the constants. 4010 4011When using the hexadecimal form, constants of types bfloat, half, float, and 4012double are represented using the 16-digit form shown above (which matches the 4013IEEE754 representation for double); bfloat, half and float values must, however, 4014be exactly representable as bfloat, IEEE 754 half, and IEEE 754 single 4015precision respectively. Hexadecimal format is always used for long double, and 4016there are three forms of long double. The 80-bit format used by x86 is 4017represented as ``0xK`` followed by 20 hexadecimal digits. The 128-bit format 4018used by PowerPC (two adjacent doubles) is represented by ``0xM`` followed by 32 4019hexadecimal digits. The IEEE 128-bit format is represented by ``0xL`` followed 4020by 32 hexadecimal digits. Long doubles will only work if they match the long 4021double format on your target. The IEEE 16-bit format (half precision) is 4022represented by ``0xH`` followed by 4 hexadecimal digits. The bfloat 16-bit 4023format is represented by ``0xR`` followed by 4 hexadecimal digits. All 4024hexadecimal formats are big-endian (sign bit at the left). 4025 4026There are no constants of type x86_mmx and x86_amx. 4027 4028.. _complexconstants: 4029 4030Complex Constants 4031----------------- 4032 4033Complex constants are a (potentially recursive) combination of simple 4034constants and smaller complex constants. 4035 4036**Structure constants** 4037 Structure constants are represented with notation similar to 4038 structure type definitions (a comma separated list of elements, 4039 surrounded by braces (``{}``)). For example: 4040 "``{ i32 4, float 17.0, ptr @G }``", where "``@G``" is declared as 4041 "``@G = external global i32``". Structure constants must have 4042 :ref:`structure type <t_struct>`, and the number and types of elements 4043 must match those specified by the type. 4044**Array constants** 4045 Array constants are represented with notation similar to array type 4046 definitions (a comma separated list of elements, surrounded by 4047 square brackets (``[]``)). For example: 4048 "``[ i32 42, i32 11, i32 74 ]``". Array constants must have 4049 :ref:`array type <t_array>`, and the number and types of elements must 4050 match those specified by the type. As a special case, character array 4051 constants may also be represented as a double-quoted string using the ``c`` 4052 prefix. For example: "``c"Hello World\0A\00"``". 4053**Vector constants** 4054 Vector constants are represented with notation similar to vector 4055 type definitions (a comma separated list of elements, surrounded by 4056 less-than/greater-than's (``<>``)). For example: 4057 "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants 4058 must have :ref:`vector type <t_vector>`, and the number and types of 4059 elements must match those specified by the type. 4060**Zero initialization** 4061 The string '``zeroinitializer``' can be used to zero initialize a 4062 value to zero of *any* type, including scalar and 4063 :ref:`aggregate <t_aggregate>` types. This is often used to avoid 4064 having to print large zero initializers (e.g. for large arrays) and 4065 is always exactly equivalent to using explicit zero initializers. 4066**Metadata node** 4067 A metadata node is a constant tuple without types. For example: 4068 "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values, 4069 for example: "``!{!0, i32 0, ptr @global, ptr @function, !"str"}``". 4070 Unlike other typed constants that are meant to be interpreted as part of 4071 the instruction stream, metadata is a place to attach additional 4072 information such as debug info. 4073 4074Global Variable and Function Addresses 4075-------------------------------------- 4076 4077The addresses of :ref:`global variables <globalvars>` and 4078:ref:`functions <functionstructure>` are always implicitly valid 4079(link-time) constants. These constants are explicitly referenced when 4080the :ref:`identifier for the global <identifiers>` is used and always have 4081:ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM 4082file: 4083 4084.. code-block:: llvm 4085 4086 @X = global i32 17 4087 @Y = global i32 42 4088 @Z = global [2 x ptr] [ ptr @X, ptr @Y ] 4089 4090.. _undefvalues: 4091 4092Undefined Values 4093---------------- 4094 4095The string '``undef``' can be used anywhere a constant is expected, and 4096indicates that the user of the value may receive an unspecified 4097bit-pattern. Undefined values may be of any type (other than '``label``' 4098or '``void``') and be used anywhere a constant is permitted. 4099 4100.. note:: 4101 4102 A '``poison``' value (decribed in the next section) should be used instead of 4103 '``undef``' whenever possible. Poison values are stronger than undef, and 4104 enable more optimizations. Just the existence of '``undef``' blocks certain 4105 optimizations (see the examples below). 4106 4107Undefined values are useful because they indicate to the compiler that 4108the program is well defined no matter what value is used. This gives the 4109compiler more freedom to optimize. Here are some examples of 4110(potentially surprising) transformations that are valid (in pseudo IR): 4111 4112.. code-block:: llvm 4113 4114 %A = add %X, undef 4115 %B = sub %X, undef 4116 %C = xor %X, undef 4117 Safe: 4118 %A = undef 4119 %B = undef 4120 %C = undef 4121 4122This is safe because all of the output bits are affected by the undef 4123bits. Any output bit can have a zero or one depending on the input bits. 4124 4125.. code-block:: llvm 4126 4127 %A = or %X, undef 4128 %B = and %X, undef 4129 Safe: 4130 %A = -1 4131 %B = 0 4132 Safe: 4133 %A = %X ;; By choosing undef as 0 4134 %B = %X ;; By choosing undef as -1 4135 Unsafe: 4136 %A = undef 4137 %B = undef 4138 4139These logical operations have bits that are not always affected by the 4140input. For example, if ``%X`` has a zero bit, then the output of the 4141'``and``' operation will always be a zero for that bit, no matter what 4142the corresponding bit from the '``undef``' is. As such, it is unsafe to 4143optimize or assume that the result of the '``and``' is '``undef``'. 4144However, it is safe to assume that all bits of the '``undef``' could be 41450, and optimize the '``and``' to 0. Likewise, it is safe to assume that 4146all the bits of the '``undef``' operand to the '``or``' could be set, 4147allowing the '``or``' to be folded to -1. 4148 4149.. code-block:: llvm 4150 4151 %A = select undef, %X, %Y 4152 %B = select undef, 42, %Y 4153 %C = select %X, %Y, undef 4154 Safe: 4155 %A = %X (or %Y) 4156 %B = 42 (or %Y) 4157 %C = %Y (if %Y is provably not poison; unsafe otherwise) 4158 Unsafe: 4159 %A = undef 4160 %B = undef 4161 %C = undef 4162 4163This set of examples shows that undefined '``select``' (and conditional 4164branch) conditions can go *either way*, but they have to come from one 4165of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were 4166both known to have a clear low bit, then ``%A`` would have to have a 4167cleared low bit. However, in the ``%C`` example, the optimizer is 4168allowed to assume that the '``undef``' operand could be the same as 4169``%Y`` if ``%Y`` is provably not '``poison``', allowing the whole '``select``' 4170to be eliminated. This is because '``poison``' is stronger than '``undef``'. 4171 4172.. code-block:: llvm 4173 4174 %A = xor undef, undef 4175 4176 %B = undef 4177 %C = xor %B, %B 4178 4179 %D = undef 4180 %E = icmp slt %D, 4 4181 %F = icmp gte %D, 4 4182 4183 Safe: 4184 %A = undef 4185 %B = undef 4186 %C = undef 4187 %D = undef 4188 %E = undef 4189 %F = undef 4190 4191This example points out that two '``undef``' operands are not 4192necessarily the same. This can be surprising to people (and also matches 4193C semantics) where they assume that "``X^X``" is always zero, even if 4194``X`` is undefined. This isn't true for a number of reasons, but the 4195short answer is that an '``undef``' "variable" can arbitrarily change 4196its value over its "live range". This is true because the variable 4197doesn't actually *have a live range*. Instead, the value is logically 4198read from arbitrary registers that happen to be around when needed, so 4199the value is not necessarily consistent over time. In fact, ``%A`` and 4200``%C`` need to have the same semantics or the core LLVM "replace all 4201uses with" concept would not hold. 4202 4203To ensure all uses of a given register observe the same value (even if 4204'``undef``'), the :ref:`freeze instruction <i_freeze>` can be used. 4205 4206.. code-block:: llvm 4207 4208 %A = sdiv undef, %X 4209 %B = sdiv %X, undef 4210 Safe: 4211 %A = 0 4212 b: unreachable 4213 4214These examples show the crucial difference between an *undefined value* 4215and *undefined behavior*. An undefined value (like '``undef``') is 4216allowed to have an arbitrary bit-pattern. This means that the ``%A`` 4217operation can be constant folded to '``0``', because the '``undef``' 4218could be zero, and zero divided by any value is zero. 4219However, in the second example, we can make a more aggressive 4220assumption: because the ``undef`` is allowed to be an arbitrary value, 4221we are allowed to assume that it could be zero. Since a divide by zero 4222has *undefined behavior*, we are allowed to assume that the operation 4223does not execute at all. This allows us to delete the divide and all 4224code after it. Because the undefined operation "can't happen", the 4225optimizer can assume that it occurs in dead code. 4226 4227.. code-block:: text 4228 4229 a: store undef -> %X 4230 b: store %X -> undef 4231 Safe: 4232 a: <deleted> (if the stored value in %X is provably not poison) 4233 b: unreachable 4234 4235A store *of* an undefined value can be assumed to not have any effect; 4236we can assume that the value is overwritten with bits that happen to 4237match what was already there. This argument is only valid if the stored value 4238is provably not ``poison``. However, a store *to* an undefined 4239location could clobber arbitrary memory, therefore, it has undefined 4240behavior. 4241 4242Branching on an undefined value is undefined behavior. 4243This explains optimizations that depend on branch conditions to construct 4244predicates, such as Correlated Value Propagation and Global Value Numbering. 4245In case of switch instruction, the branch condition should be frozen, otherwise 4246it is undefined behavior. 4247 4248.. code-block:: llvm 4249 4250 Unsafe: 4251 br undef, BB1, BB2 ; UB 4252 4253 %X = and i32 undef, 255 4254 switch %X, label %ret [ .. ] ; UB 4255 4256 store undef, ptr %ptr 4257 %X = load ptr %ptr ; %X is undef 4258 switch i8 %X, label %ret [ .. ] ; UB 4259 4260 Safe: 4261 %X = or i8 undef, 255 ; always 255 4262 switch i8 %X, label %ret [ .. ] ; Well-defined 4263 4264 %X = freeze i1 undef 4265 br %X, BB1, BB2 ; Well-defined (non-deterministic jump) 4266 4267 4268 4269.. _poisonvalues: 4270 4271Poison Values 4272------------- 4273 4274A poison value is a result of an erroneous operation. 4275In order to facilitate speculative execution, many instructions do not 4276invoke immediate undefined behavior when provided with illegal operands, 4277and return a poison value instead. 4278The string '``poison``' can be used anywhere a constant is expected, and 4279operations such as :ref:`add <i_add>` with the ``nsw`` flag can produce 4280a poison value. 4281 4282Most instructions return '``poison``' when one of their arguments is 4283'``poison``'. A notable exception is the :ref:`select instruction <i_select>`. 4284Propagation of poison can be stopped with the 4285:ref:`freeze instruction <i_freeze>`. 4286 4287It is correct to replace a poison value with an 4288:ref:`undef value <undefvalues>` or any value of the type. 4289 4290This means that immediate undefined behavior occurs if a poison value is 4291used as an instruction operand that has any values that trigger undefined 4292behavior. Notably this includes (but is not limited to): 4293 4294- The pointer operand of a :ref:`load <i_load>`, :ref:`store <i_store>` or 4295 any other pointer dereferencing instruction (independent of address 4296 space). 4297- The divisor operand of a ``udiv``, ``sdiv``, ``urem`` or ``srem`` 4298 instruction. 4299- The condition operand of a :ref:`br <i_br>` instruction. 4300- The callee operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 4301 instruction. 4302- The parameter operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 4303 instruction, when the function or invoking call site has a ``noundef`` 4304 attribute in the corresponding position. 4305- The operand of a :ref:`ret <i_ret>` instruction if the function or invoking 4306 call site has a `noundef` attribute in the return value position. 4307 4308Here are some examples: 4309 4310.. code-block:: llvm 4311 4312 entry: 4313 %poison = sub nuw i32 0, 1 ; Results in a poison value. 4314 %poison2 = sub i32 poison, 1 ; Also results in a poison value. 4315 %still_poison = and i32 %poison, 0 ; 0, but also poison. 4316 %poison_yet_again = getelementptr i32, ptr @h, i32 %still_poison 4317 store i32 0, ptr %poison_yet_again ; Undefined behavior due to 4318 ; store to poison. 4319 4320 store i32 %poison, ptr @g ; Poison value stored to memory. 4321 %poison3 = load i32, ptr @g ; Poison value loaded back from memory. 4322 4323 %poison4 = load i16, ptr @g ; Returns a poison value. 4324 %poison5 = load i64, ptr @g ; Returns a poison value. 4325 4326 %cmp = icmp slt i32 %poison, 0 ; Returns a poison value. 4327 br i1 %cmp, label %end, label %end ; undefined behavior 4328 4329 end: 4330 4331.. _welldefinedvalues: 4332 4333Well-Defined Values 4334------------------- 4335 4336Given a program execution, a value is *well defined* if the value does not 4337have an undef bit and is not poison in the execution. 4338An aggregate value or vector is well defined if its elements are well defined. 4339The padding of an aggregate isn't considered, since it isn't visible 4340without storing it into memory and loading it with a different type. 4341 4342A constant of a :ref:`single value <t_single_value>`, non-vector type is well 4343defined if it is neither '``undef``' constant nor '``poison``' constant. 4344The result of :ref:`freeze instruction <i_freeze>` is well defined regardless 4345of its operand. 4346 4347.. _blockaddress: 4348 4349Addresses of Basic Blocks 4350------------------------- 4351 4352``blockaddress(@function, %block)`` 4353 4354The '``blockaddress``' constant computes the address of the specified 4355basic block in the specified function. 4356 4357It always has an ``ptr addrspace(P)`` type, where ``P`` is the address space 4358of the function containing ``%block`` (usually ``addrspace(0)``). 4359 4360Taking the address of the entry block is illegal. 4361 4362This value only has defined behavior when used as an operand to the 4363':ref:`indirectbr <i_indirectbr>`' or for comparisons against null. Pointer 4364equality tests between labels addresses results in undefined behavior --- 4365though, again, comparison against null is ok, and no label is equal to the null 4366pointer. This may be passed around as an opaque pointer sized value as long as 4367the bits are not inspected. This allows ``ptrtoint`` and arithmetic to be 4368performed on these values so long as the original value is reconstituted before 4369the ``indirectbr`` instruction. 4370 4371Finally, some targets may provide defined semantics when using the value 4372as the operand to an inline assembly, but that is target specific. 4373 4374.. _dso_local_equivalent: 4375 4376DSO Local Equivalent 4377-------------------- 4378 4379``dso_local_equivalent @func`` 4380 4381A '``dso_local_equivalent``' constant represents a function which is 4382functionally equivalent to a given function, but is always defined in the 4383current linkage unit. The resulting pointer has the same type as the underlying 4384function. The resulting pointer is permitted, but not required, to be different 4385from a pointer to the function, and it may have different values in different 4386translation units. 4387 4388The target function may not have ``extern_weak`` linkage. 4389 4390``dso_local_equivalent`` can be implemented as such: 4391 4392- If the function has local linkage, hidden visibility, or is 4393 ``dso_local``, ``dso_local_equivalent`` can be implemented as simply a pointer 4394 to the function. 4395- ``dso_local_equivalent`` can be implemented with a stub that tail-calls the 4396 function. Many targets support relocations that resolve at link time to either 4397 a function or a stub for it, depending on if the function is defined within the 4398 linkage unit; LLVM will use this when available. (This is commonly called a 4399 "PLT stub".) On other targets, the stub may need to be emitted explicitly. 4400 4401This can be used wherever a ``dso_local`` instance of a function is needed without 4402needing to explicitly make the original function ``dso_local``. An instance where 4403this can be used is for static offset calculations between a function and some other 4404``dso_local`` symbol. This is especially useful for the Relative VTables C++ ABI, 4405where dynamic relocations for function pointers in VTables can be replaced with 4406static relocations for offsets between the VTable and virtual functions which 4407may not be ``dso_local``. 4408 4409This is currently only supported for ELF binary formats. 4410 4411.. _no_cfi: 4412 4413No CFI 4414------ 4415 4416``no_cfi @func`` 4417 4418With `Control-Flow Integrity (CFI) 4419<https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, a '``no_cfi``' 4420constant represents a function reference that does not get replaced with a 4421reference to the CFI jump table in the ``LowerTypeTests`` pass. These constants 4422may be useful in low-level programs, such as operating system kernels, which 4423need to refer to the actual function body. 4424 4425.. _constantexprs: 4426 4427Constant Expressions 4428-------------------- 4429 4430Constant expressions are used to allow expressions involving other 4431constants to be used as constants. Constant expressions may be of any 4432:ref:`first class <t_firstclass>` type and may involve any LLVM operation 4433that does not have side effects (e.g. load and call are not supported). 4434The following is the syntax for constant expressions: 4435 4436``trunc (CST to TYPE)`` 4437 Perform the :ref:`trunc operation <i_trunc>` on constants. 4438``zext (CST to TYPE)`` 4439 Perform the :ref:`zext operation <i_zext>` on constants. 4440``sext (CST to TYPE)`` 4441 Perform the :ref:`sext operation <i_sext>` on constants. 4442``fptrunc (CST to TYPE)`` 4443 Truncate a floating-point constant to another floating-point type. 4444 The size of CST must be larger than the size of TYPE. Both types 4445 must be floating-point. 4446``fpext (CST to TYPE)`` 4447 Floating-point extend a constant to another type. The size of CST 4448 must be smaller or equal to the size of TYPE. Both types must be 4449 floating-point. 4450``fptoui (CST to TYPE)`` 4451 Convert a floating-point constant to the corresponding unsigned 4452 integer constant. TYPE must be a scalar or vector integer type. CST 4453 must be of scalar or vector floating-point type. Both CST and TYPE 4454 must be scalars, or vectors of the same number of elements. If the 4455 value won't fit in the integer type, the result is a 4456 :ref:`poison value <poisonvalues>`. 4457``fptosi (CST to TYPE)`` 4458 Convert a floating-point constant to the corresponding signed 4459 integer constant. TYPE must be a scalar or vector integer type. CST 4460 must be of scalar or vector floating-point type. Both CST and TYPE 4461 must be scalars, or vectors of the same number of elements. If the 4462 value won't fit in the integer type, the result is a 4463 :ref:`poison value <poisonvalues>`. 4464``uitofp (CST to TYPE)`` 4465 Convert an unsigned integer constant to the corresponding 4466 floating-point constant. TYPE must be a scalar or vector floating-point 4467 type. CST must be of scalar or vector integer type. Both CST and TYPE must 4468 be scalars, or vectors of the same number of elements. 4469``sitofp (CST to TYPE)`` 4470 Convert a signed integer constant to the corresponding floating-point 4471 constant. TYPE must be a scalar or vector floating-point type. 4472 CST must be of scalar or vector integer type. Both CST and TYPE must 4473 be scalars, or vectors of the same number of elements. 4474``ptrtoint (CST to TYPE)`` 4475 Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants. 4476``inttoptr (CST to TYPE)`` 4477 Perform the :ref:`inttoptr operation <i_inttoptr>` on constants. 4478 This one is *really* dangerous! 4479``bitcast (CST to TYPE)`` 4480 Convert a constant, CST, to another TYPE. 4481 The constraints of the operands are the same as those for the 4482 :ref:`bitcast instruction <i_bitcast>`. 4483``addrspacecast (CST to TYPE)`` 4484 Convert a constant pointer or constant vector of pointer, CST, to another 4485 TYPE in a different address space. The constraints of the operands are the 4486 same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`. 4487``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)`` 4488 Perform the :ref:`getelementptr operation <i_getelementptr>` on 4489 constants. As with the :ref:`getelementptr <i_getelementptr>` 4490 instruction, the index list may have one or more indexes, which are 4491 required to make sense for the type of "pointer to TY". 4492``select (COND, VAL1, VAL2)`` 4493 Perform the :ref:`select operation <i_select>` on constants. 4494``icmp COND (VAL1, VAL2)`` 4495 Perform the :ref:`icmp operation <i_icmp>` on constants. 4496``fcmp COND (VAL1, VAL2)`` 4497 Perform the :ref:`fcmp operation <i_fcmp>` on constants. 4498``extractelement (VAL, IDX)`` 4499 Perform the :ref:`extractelement operation <i_extractelement>` on 4500 constants. 4501``insertelement (VAL, ELT, IDX)`` 4502 Perform the :ref:`insertelement operation <i_insertelement>` on 4503 constants. 4504``shufflevector (VEC1, VEC2, IDXMASK)`` 4505 Perform the :ref:`shufflevector operation <i_shufflevector>` on 4506 constants. 4507``extractvalue (VAL, IDX0, IDX1, ...)`` 4508 Perform the :ref:`extractvalue operation <i_extractvalue>` on 4509 constants. The index list is interpreted in a similar manner as 4510 indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At 4511 least one index value must be specified. 4512``insertvalue (VAL, ELT, IDX0, IDX1, ...)`` 4513 Perform the :ref:`insertvalue operation <i_insertvalue>` on constants. 4514 The index list is interpreted in a similar manner as indices in a 4515 ':ref:`getelementptr <i_getelementptr>`' operation. At least one index 4516 value must be specified. 4517``OPCODE (LHS, RHS)`` 4518 Perform the specified operation of the LHS and RHS constants. OPCODE 4519 may be any of the :ref:`binary <binaryops>` or :ref:`bitwise 4520 binary <bitwiseops>` operations. The constraints on operands are 4521 the same as those for the corresponding instruction (e.g. no bitwise 4522 operations on floating-point values are allowed). 4523 4524Other Values 4525============ 4526 4527.. _inlineasmexprs: 4528 4529Inline Assembler Expressions 4530---------------------------- 4531 4532LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level 4533Inline Assembly <moduleasm>`) through the use of a special value. This value 4534represents the inline assembler as a template string (containing the 4535instructions to emit), a list of operand constraints (stored as a string), a 4536flag that indicates whether or not the inline asm expression has side effects, 4537and a flag indicating whether the function containing the asm needs to align its 4538stack conservatively. 4539 4540The template string supports argument substitution of the operands using "``$``" 4541followed by a number, to indicate substitution of the given register/memory 4542location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also 4543be used, where ``MODIFIER`` is a target-specific annotation for how to print the 4544operand (See :ref:`inline-asm-modifiers`). 4545 4546A literal "``$``" may be included by using "``$$``" in the template. To include 4547other special characters into the output, the usual "``\XX``" escapes may be 4548used, just as in other strings. Note that after template substitution, the 4549resulting assembly string is parsed by LLVM's integrated assembler unless it is 4550disabled -- even when emitting a ``.s`` file -- and thus must contain assembly 4551syntax known to LLVM. 4552 4553LLVM also supports a few more substitutions useful for writing inline assembly: 4554 4555- ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob. 4556 This substitution is useful when declaring a local label. Many standard 4557 compiler optimizations, such as inlining, may duplicate an inline asm blob. 4558 Adding a blob-unique identifier ensures that the two labels will not conflict 4559 during assembly. This is used to implement `GCC's %= special format 4560 string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_. 4561- ``${:comment}``: Expands to the comment character of the current target's 4562 assembly dialect. This is usually ``#``, but many targets use other strings, 4563 such as ``;``, ``//``, or ``!``. 4564- ``${:private}``: Expands to the assembler private label prefix. Labels with 4565 this prefix will not appear in the symbol table of the assembled object. 4566 Typically the prefix is ``L``, but targets may use other strings. ``.L`` is 4567 relatively popular. 4568 4569LLVM's support for inline asm is modeled closely on the requirements of Clang's 4570GCC-compatible inline-asm support. Thus, the feature-set and the constraint and 4571modifier codes listed here are similar or identical to those in GCC's inline asm 4572support. However, to be clear, the syntax of the template and constraint strings 4573described here is *not* the same as the syntax accepted by GCC and Clang, and, 4574while most constraint letters are passed through as-is by Clang, some get 4575translated to other codes when converting from the C source to the LLVM 4576assembly. 4577 4578An example inline assembler expression is: 4579 4580.. code-block:: llvm 4581 4582 i32 (i32) asm "bswap $0", "=r,r" 4583 4584Inline assembler expressions may **only** be used as the callee operand 4585of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction. 4586Thus, typically we have: 4587 4588.. code-block:: llvm 4589 4590 %X = call i32 asm "bswap $0", "=r,r"(i32 %Y) 4591 4592Inline asms with side effects not visible in the constraint list must be 4593marked as having side effects. This is done through the use of the 4594'``sideeffect``' keyword, like so: 4595 4596.. code-block:: llvm 4597 4598 call void asm sideeffect "eieio", ""() 4599 4600In some cases inline asms will contain code that will not work unless 4601the stack is aligned in some way, such as calls or SSE instructions on 4602x86, yet will not contain code that does that alignment within the asm. 4603The compiler should make conservative assumptions about what the asm 4604might contain and should generate its usual stack alignment code in the 4605prologue if the '``alignstack``' keyword is present: 4606 4607.. code-block:: llvm 4608 4609 call void asm alignstack "eieio", ""() 4610 4611Inline asms also support using non-standard assembly dialects. The 4612assumed dialect is ATT. When the '``inteldialect``' keyword is present, 4613the inline asm is using the Intel dialect. Currently, ATT and Intel are 4614the only supported dialects. An example is: 4615 4616.. code-block:: llvm 4617 4618 call void asm inteldialect "eieio", ""() 4619 4620In the case that the inline asm might unwind the stack, 4621the '``unwind``' keyword must be used, so that the compiler emits 4622unwinding information: 4623 4624.. code-block:: llvm 4625 4626 call void asm unwind "call func", ""() 4627 4628If the inline asm unwinds the stack and isn't marked with 4629the '``unwind``' keyword, the behavior is undefined. 4630 4631If multiple keywords appear, the '``sideeffect``' keyword must come 4632first, the '``alignstack``' keyword second, the '``inteldialect``' keyword 4633third and the '``unwind``' keyword last. 4634 4635Inline Asm Constraint String 4636^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4637 4638The constraint list is a comma-separated string, each element containing one or 4639more constraint codes. 4640 4641For each element in the constraint list an appropriate register or memory 4642operand will be chosen, and it will be made available to assembly template 4643string expansion as ``$0`` for the first constraint in the list, ``$1`` for the 4644second, etc. 4645 4646There are three different types of constraints, which are distinguished by a 4647prefix symbol in front of the constraint code: Output, Input, and Clobber. The 4648constraints must always be given in that order: outputs first, then inputs, then 4649clobbers. They cannot be intermingled. 4650 4651There are also three different categories of constraint codes: 4652 4653- Register constraint. This is either a register class, or a fixed physical 4654 register. This kind of constraint will allocate a register, and if necessary, 4655 bitcast the argument or result to the appropriate type. 4656- Memory constraint. This kind of constraint is for use with an instruction 4657 taking a memory operand. Different constraints allow for different addressing 4658 modes used by the target. 4659- Immediate value constraint. This kind of constraint is for an integer or other 4660 immediate value which can be rendered directly into an instruction. The 4661 various target-specific constraints allow the selection of a value in the 4662 proper range for the instruction you wish to use it with. 4663 4664Output constraints 4665"""""""""""""""""" 4666 4667Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This 4668indicates that the assembly will write to this operand, and the operand will 4669then be made available as a return value of the ``asm`` expression. Output 4670constraints do not consume an argument from the call instruction. (Except, see 4671below about indirect outputs). 4672 4673Normally, it is expected that no output locations are written to by the assembly 4674expression until *all* of the inputs have been read. As such, LLVM may assign 4675the same register to an output and an input. If this is not safe (e.g. if the 4676assembly contains two instructions, where the first writes to one output, and 4677the second reads an input and writes to a second output), then the "``&``" 4678modifier must be used (e.g. "``=&r``") to specify that the output is an 4679"early-clobber" output. Marking an output as "early-clobber" ensures that LLVM 4680will not use the same register for any inputs (other than an input tied to this 4681output). 4682 4683Input constraints 4684""""""""""""""""" 4685 4686Input constraints do not have a prefix -- just the constraint codes. Each input 4687constraint will consume one argument from the call instruction. It is not 4688permitted for the asm to write to any input register or memory location (unless 4689that input is tied to an output). Note also that multiple inputs may all be 4690assigned to the same register, if LLVM can determine that they necessarily all 4691contain the same value. 4692 4693Instead of providing a Constraint Code, input constraints may also "tie" 4694themselves to an output constraint, by providing an integer as the constraint 4695string. Tied inputs still consume an argument from the call instruction, and 4696take up a position in the asm template numbering as is usual -- they will simply 4697be constrained to always use the same register as the output they've been tied 4698to. For example, a constraint string of "``=r,0``" says to assign a register for 4699output, and use that register as an input as well (it being the 0'th 4700constraint). 4701 4702It is permitted to tie an input to an "early-clobber" output. In that case, no 4703*other* input may share the same register as the input tied to the early-clobber 4704(even when the other input has the same value). 4705 4706You may only tie an input to an output which has a register constraint, not a 4707memory constraint. Only a single input may be tied to an output. 4708 4709There is also an "interesting" feature which deserves a bit of explanation: if a 4710register class constraint allocates a register which is too small for the value 4711type operand provided as input, the input value will be split into multiple 4712registers, and all of them passed to the inline asm. 4713 4714However, this feature is often not as useful as you might think. 4715 4716Firstly, the registers are *not* guaranteed to be consecutive. So, on those 4717architectures that have instructions which operate on multiple consecutive 4718instructions, this is not an appropriate way to support them. (e.g. the 32-bit 4719SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The 4720hardware then loads into both the named register, and the next register. This 4721feature of inline asm would not be useful to support that.) 4722 4723A few of the targets provide a template string modifier allowing explicit access 4724to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and 4725``D``). On such an architecture, you can actually access the second allocated 4726register (yet, still, not any subsequent ones). But, in that case, you're still 4727probably better off simply splitting the value into two separate operands, for 4728clarity. (e.g. see the description of the ``A`` constraint on X86, which, 4729despite existing only for use with this feature, is not really a good idea to 4730use) 4731 4732Indirect inputs and outputs 4733""""""""""""""""""""""""""" 4734 4735Indirect output or input constraints can be specified by the "``*``" modifier 4736(which goes after the "``=``" in case of an output). This indicates that the asm 4737will write to or read from the contents of an *address* provided as an input 4738argument. (Note that in this way, indirect outputs act more like an *input* than 4739an output: just like an input, they consume an argument of the call expression, 4740rather than producing a return value. An indirect output constraint is an 4741"output" only in that the asm is expected to write to the contents of the input 4742memory location, instead of just read from it). 4743 4744This is most typically used for memory constraint, e.g. "``=*m``", to pass the 4745address of a variable as a value. 4746 4747It is also possible to use an indirect *register* constraint, but only on output 4748(e.g. "``=*r``"). This will cause LLVM to allocate a register for an output 4749value normally, and then, separately emit a store to the address provided as 4750input, after the provided inline asm. (It's not clear what value this 4751functionality provides, compared to writing the store explicitly after the asm 4752statement, and it can only produce worse code, since it bypasses many 4753optimization passes. I would recommend not using it.) 4754 4755Call arguments for indirect constraints must have pointer type and must specify 4756the :ref:`elementtype <attr_elementtype>` attribute to indicate the pointer 4757element type. 4758 4759Clobber constraints 4760""""""""""""""""""" 4761 4762A clobber constraint is indicated by a "``~``" prefix. A clobber does not 4763consume an input operand, nor generate an output. Clobbers cannot use any of the 4764general constraint code letters -- they may use only explicit register 4765constraints, e.g. "``~{eax}``". The one exception is that a clobber string of 4766"``~{memory}``" indicates that the assembly writes to arbitrary undeclared 4767memory locations -- not only the memory pointed to by a declared indirect 4768output. 4769 4770Note that clobbering named registers that are also present in output 4771constraints is not legal. 4772 4773Label constraints 4774""""""""""""""""" 4775 4776A label constraint is indicated by a "``!``" prefix and typically used in the 4777form ``"!i"``. Instead of consuming call arguments, label constraints consume 4778indirect destination labels of ``callbr`` instructions. 4779 4780Label constraints can only be used in conjunction with ``callbr`` and the 4781number of label constraints must match the number of indirect destination 4782labels in the ``callbr`` instruction. 4783 4784 4785Constraint Codes 4786"""""""""""""""" 4787After a potential prefix comes constraint code, or codes. 4788 4789A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character 4790followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``" 4791(e.g. "``{eax}``"). 4792 4793The one and two letter constraint codes are typically chosen to be the same as 4794GCC's constraint codes. 4795 4796A single constraint may include one or more than constraint code in it, leaving 4797it up to LLVM to choose which one to use. This is included mainly for 4798compatibility with the translation of GCC inline asm coming from clang. 4799 4800There are two ways to specify alternatives, and either or both may be used in an 4801inline asm constraint list: 4802 48031) Append the codes to each other, making a constraint code set. E.g. "``im``" 4804 or "``{eax}m``". This means "choose any of the options in the set". The 4805 choice of constraint is made independently for each constraint in the 4806 constraint list. 4807 48082) Use "``|``" between constraint code sets, creating alternatives. Every 4809 constraint in the constraint list must have the same number of alternative 4810 sets. With this syntax, the same alternative in *all* of the items in the 4811 constraint list will be chosen together. 4812 4813Putting those together, you might have a two operand constraint string like 4814``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then 4815operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1 4816may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m. 4817 4818However, the use of either of the alternatives features is *NOT* recommended, as 4819LLVM is not able to make an intelligent choice about which one to use. (At the 4820point it currently needs to choose, not enough information is available to do so 4821in a smart way.) Thus, it simply tries to make a choice that's most likely to 4822compile, not one that will be optimal performance. (e.g., given "``rm``", it'll 4823always choose to use memory, not registers). And, if given multiple registers, 4824or multiple register classes, it will simply choose the first one. (In fact, it 4825doesn't currently even ensure explicitly specified physical registers are 4826unique, so specifying multiple physical registers as alternatives, like 4827``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was 4828intended.) 4829 4830Supported Constraint Code List 4831"""""""""""""""""""""""""""""" 4832 4833The constraint codes are, in general, expected to behave the same way they do in 4834GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C 4835inline asm code which was supported by GCC. A mismatch in behavior between LLVM 4836and GCC likely indicates a bug in LLVM. 4837 4838Some constraint codes are typically supported by all targets: 4839 4840- ``r``: A register in the target's general purpose register class. 4841- ``m``: A memory address operand. It is target-specific what addressing modes 4842 are supported, typical examples are register, or register + register offset, 4843 or register + immediate offset (of some target-specific size). 4844- ``p``: An address operand. Similar to ``m``, but used by "load address" 4845 type instructions without touching memory. 4846- ``i``: An integer constant (of target-specific width). Allows either a simple 4847 immediate, or a relocatable value. 4848- ``n``: An integer constant -- *not* including relocatable values. 4849- ``s``: An integer constant, but allowing *only* relocatable values. 4850- ``X``: Allows an operand of any kind, no constraint whatsoever. Typically 4851 useful to pass a label for an asm branch or call. 4852 4853 .. FIXME: but that surely isn't actually okay to jump out of an asm 4854 block without telling llvm about the control transfer???) 4855 4856- ``{register-name}``: Requires exactly the named physical register. 4857 4858Other constraints are target-specific: 4859 4860AArch64: 4861 4862- ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate. 4863- ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction, 4864 i.e. 0 to 4095 with optional shift by 12. 4865- ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or 4866 ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12. 4867- ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a 4868 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register. 4869- ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a 4870 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register. 4871- ``M``: An immediate integer for use with the ``MOV`` assembly alias on a 4872 32-bit register. This is a superset of ``K``: in addition to the bitmask 4873 immediate, also allows immediate integers which can be loaded with a single 4874 ``MOVZ`` or ``MOVL`` instruction. 4875- ``N``: An immediate integer for use with the ``MOV`` assembly alias on a 4876 64-bit register. This is a superset of ``L``. 4877- ``Q``: Memory address operand must be in a single register (no 4878 offsets). (However, LLVM currently does this for the ``m`` constraint as 4879 well.) 4880- ``r``: A 32 or 64-bit integer register (W* or X*). 4881- ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register. 4882- ``x``: Like w, but restricted to registers 0 to 15 inclusive. 4883- ``y``: Like w, but restricted to SVE vector registers Z0 to Z7 inclusive. 4884- ``Upl``: One of the low eight SVE predicate registers (P0 to P7) 4885- ``Upa``: Any of the SVE predicate registers (P0 to P15) 4886 4887AMDGPU: 4888 4889- ``r``: A 32 or 64-bit integer register. 4890- ``[0-9]v``: The 32-bit VGPR register, number 0-9. 4891- ``[0-9]s``: The 32-bit SGPR register, number 0-9. 4892- ``[0-9]a``: The 32-bit AGPR register, number 0-9. 4893- ``I``: An integer inline constant in the range from -16 to 64. 4894- ``J``: A 16-bit signed integer constant. 4895- ``A``: An integer or a floating-point inline constant. 4896- ``B``: A 32-bit signed integer constant. 4897- ``C``: A 32-bit unsigned integer constant or an integer inline constant in the range from -16 to 64. 4898- ``DA``: A 64-bit constant that can be split into two "A" constants. 4899- ``DB``: A 64-bit constant that can be split into two "B" constants. 4900 4901All ARM modes: 4902 4903- ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address 4904 operand. Treated the same as operand ``m``, at the moment. 4905- ``Te``: An even general-purpose 32-bit integer register: ``r0,r2,...,r12,r14`` 4906- ``To``: An odd general-purpose 32-bit integer register: ``r1,r3,...,r11`` 4907 4908ARM and ARM's Thumb2 mode: 4909 4910- ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``) 4911- ``I``: An immediate integer valid for a data-processing instruction. 4912- ``J``: An immediate integer between -4095 and 4095. 4913- ``K``: An immediate integer whose bitwise inverse is valid for a 4914 data-processing instruction. (Can be used with template modifier "``B``" to 4915 print the inverted value). 4916- ``L``: An immediate integer whose negation is valid for a data-processing 4917 instruction. (Can be used with template modifier "``n``" to print the negated 4918 value). 4919- ``M``: A power of two or an integer between 0 and 32. 4920- ``N``: Invalid immediate constraint. 4921- ``O``: Invalid immediate constraint. 4922- ``r``: A general-purpose 32-bit integer register (``r0-r15``). 4923- ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same 4924 as ``r``. 4925- ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode, 4926 invalid. 4927- ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4928 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively. 4929- ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4930 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively. 4931- ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4932 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively. 4933 4934ARM's Thumb1 mode: 4935 4936- ``I``: An immediate integer between 0 and 255. 4937- ``J``: An immediate integer between -255 and -1. 4938- ``K``: An immediate integer between 0 and 255, with optional left-shift by 4939 some amount. 4940- ``L``: An immediate integer between -7 and 7. 4941- ``M``: An immediate integer which is a multiple of 4 between 0 and 1020. 4942- ``N``: An immediate integer between 0 and 31. 4943- ``O``: An immediate integer which is a multiple of 4 between -508 and 508. 4944- ``r``: A low 32-bit GPR register (``r0-r7``). 4945- ``l``: A low 32-bit GPR register (``r0-r7``). 4946- ``h``: A high GPR register (``r0-r7``). 4947- ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4948 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively. 4949- ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4950 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively. 4951- ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4952 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively. 4953 4954Hexagon: 4955 4956- ``o``, ``v``: A memory address operand, treated the same as constraint ``m``, 4957 at the moment. 4958- ``r``: A 32 or 64-bit register. 4959 4960LoongArch: 4961 4962- ``f``: A floating-point register (if available). 4963- ``k``: A memory operand whose address is formed by a base register and 4964 (optionally scaled) index register. 4965- ``l``: A signed 16-bit constant. 4966- ``m``: A memory operand whose address is formed by a base register and 4967 offset that is suitable for use in instructions with the same addressing 4968 mode as st.w and ld.w. 4969- ``I``: A signed 12-bit constant (for arithmetic instructions). 4970- ``J``: An immediate integer zero. 4971- ``K``: An unsigned 12-bit constant (for logic instructions). 4972- ``ZB``: An address that is held in a general-purpose register. The offset 4973 is zero. 4974- ``ZC``: A memory operand whose address is formed by a base register and 4975 offset that is suitable for use in instructions with the same addressing 4976 mode as ll.w and sc.w. 4977 4978MSP430: 4979 4980- ``r``: An 8 or 16-bit register. 4981 4982MIPS: 4983 4984- ``I``: An immediate signed 16-bit integer. 4985- ``J``: An immediate integer zero. 4986- ``K``: An immediate unsigned 16-bit integer. 4987- ``L``: An immediate 32-bit integer, where the lower 16 bits are 0. 4988- ``N``: An immediate integer between -65535 and -1. 4989- ``O``: An immediate signed 15-bit integer. 4990- ``P``: An immediate integer between 1 and 65535. 4991- ``m``: A memory address operand. In MIPS-SE mode, allows a base address 4992 register plus 16-bit immediate offset. In MIPS mode, just a base register. 4993- ``R``: A memory address operand. In MIPS-SE mode, allows a base address 4994 register plus a 9-bit signed offset. In MIPS mode, the same as constraint 4995 ``m``. 4996- ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or 4997 ``sc`` instruction on the given subtarget (details vary). 4998- ``r``, ``d``, ``y``: A 32 or 64-bit GPR register. 4999- ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register 5000 (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w`` 5001 argument modifier for compatibility with GCC. 5002- ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always 5003 ``25``). 5004- ``l``: The ``lo`` register, 32 or 64-bit. 5005- ``x``: Invalid. 5006 5007NVPTX: 5008 5009- ``b``: A 1-bit integer register. 5010- ``c`` or ``h``: A 16-bit integer register. 5011- ``r``: A 32-bit integer register. 5012- ``l`` or ``N``: A 64-bit integer register. 5013- ``f``: A 32-bit float register. 5014- ``d``: A 64-bit float register. 5015 5016 5017PowerPC: 5018 5019- ``I``: An immediate signed 16-bit integer. 5020- ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits. 5021- ``K``: An immediate unsigned 16-bit integer. 5022- ``L``: An immediate signed 16-bit integer, shifted left 16 bits. 5023- ``M``: An immediate integer greater than 31. 5024- ``N``: An immediate integer that is an exact power of 2. 5025- ``O``: The immediate integer constant 0. 5026- ``P``: An immediate integer constant whose negation is a signed 16-bit 5027 constant. 5028- ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently 5029 treated the same as ``m``. 5030- ``r``: A 32 or 64-bit integer register. 5031- ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is: 5032 ``R1-R31``). 5033- ``f``: A 32 or 64-bit float register (``F0-F31``), 5034- ``v``: For ``4 x f32`` or ``4 x f64`` types, a 128-bit altivec vector 5035 register (``V0-V31``). 5036 5037- ``y``: Condition register (``CR0-CR7``). 5038- ``wc``: An individual CR bit in a CR register. 5039- ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX 5040 register set (overlapping both the floating-point and vector register files). 5041- ``ws``: A 32 or 64-bit floating-point register, from the full VSX register 5042 set. 5043 5044RISC-V: 5045 5046- ``A``: An address operand (using a general-purpose register, without an 5047 offset). 5048- ``I``: A 12-bit signed integer immediate operand. 5049- ``J``: A zero integer immediate operand. 5050- ``K``: A 5-bit unsigned integer immediate operand. 5051- ``f``: A 32- or 64-bit floating-point register (requires F or D extension). 5052- ``r``: A 32- or 64-bit general-purpose register (depending on the platform 5053 ``XLEN``). 5054- ``vr``: A vector register. (requires V extension). 5055- ``vm``: A vector register for masking operand. (requires V extension). 5056 5057Sparc: 5058 5059- ``I``: An immediate 13-bit signed integer. 5060- ``r``: A 32-bit integer register. 5061- ``f``: Any floating-point register on SparcV8, or a floating-point 5062 register in the "low" half of the registers on SparcV9. 5063- ``e``: Any floating-point register. (Same as ``f`` on SparcV8.) 5064 5065SystemZ: 5066 5067- ``I``: An immediate unsigned 8-bit integer. 5068- ``J``: An immediate unsigned 12-bit integer. 5069- ``K``: An immediate signed 16-bit integer. 5070- ``L``: An immediate signed 20-bit integer. 5071- ``M``: An immediate integer 0x7fffffff. 5072- ``Q``: A memory address operand with a base address and a 12-bit immediate 5073 unsigned displacement. 5074- ``R``: A memory address operand with a base address, a 12-bit immediate 5075 unsigned displacement, and an index register. 5076- ``S``: A memory address operand with a base address and a 20-bit immediate 5077 signed displacement. 5078- ``T``: A memory address operand with a base address, a 20-bit immediate 5079 signed displacement, and an index register. 5080- ``r`` or ``d``: A 32, 64, or 128-bit integer register. 5081- ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an 5082 address context evaluates as zero). 5083- ``h``: A 32-bit value in the high part of a 64bit data register 5084 (LLVM-specific) 5085- ``f``: A 32, 64, or 128-bit floating-point register. 5086 5087X86: 5088 5089- ``I``: An immediate integer between 0 and 31. 5090- ``J``: An immediate integer between 0 and 64. 5091- ``K``: An immediate signed 8-bit integer. 5092- ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only) 5093 0xffffffff. 5094- ``M``: An immediate integer between 0 and 3. 5095- ``N``: An immediate unsigned 8-bit integer. 5096- ``O``: An immediate integer between 0 and 127. 5097- ``e``: An immediate 32-bit signed integer. 5098- ``Z``: An immediate 32-bit unsigned integer. 5099- ``o``, ``v``: Treated the same as ``m``, at the moment. 5100- ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit 5101 ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d`` 5102 registers, and on X86-64, it is all of the integer registers. 5103- ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit 5104 ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers. 5105- ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register. 5106- ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has 5107 existed since i386, and can be accessed without the REX prefix. 5108- ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register. 5109- ``y``: A 64-bit MMX register, if MMX is enabled. 5110- ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector 5111 operand in a SSE register. If AVX is also enabled, can also be a 256-bit 5112 vector operand in an AVX register. If AVX-512 is also enabled, can also be a 5113 512-bit vector operand in an AVX512 register, Otherwise, an error. 5114- ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error. 5115- ``A``: Special case: allocates EAX first, then EDX, for a single operand (in 5116 32-bit mode, a 64-bit integer operand will get split into two registers). It 5117 is not recommended to use this constraint, as in 64-bit mode, the 64-bit 5118 operand will get allocated only to RAX -- if two 32-bit operands are needed, 5119 you're better off splitting it yourself, before passing it to the asm 5120 statement. 5121 5122XCore: 5123 5124- ``r``: A 32-bit integer register. 5125 5126 5127.. _inline-asm-modifiers: 5128 5129Asm template argument modifiers 5130^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5131 5132In the asm template string, modifiers can be used on the operand reference, like 5133"``${0:n}``". 5134 5135The modifiers are, in general, expected to behave the same way they do in 5136GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C 5137inline asm code which was supported by GCC. A mismatch in behavior between LLVM 5138and GCC likely indicates a bug in LLVM. 5139 5140Target-independent: 5141 5142- ``c``: Print an immediate integer constant unadorned, without 5143 the target-specific immediate punctuation (e.g. no ``$`` prefix). 5144- ``n``: Negate and print immediate integer constant unadorned, without the 5145 target-specific immediate punctuation (e.g. no ``$`` prefix). 5146- ``l``: Print as an unadorned label, without the target-specific label 5147 punctuation (e.g. no ``$`` prefix). 5148 5149AArch64: 5150 5151- ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g., 5152 instead of ``x30``, print ``w30``. 5153- ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow). 5154- ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a 5155 ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of 5156 ``v*``. 5157 5158AMDGPU: 5159 5160- ``r``: No effect. 5161 5162ARM: 5163 5164- ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a 5165 register). 5166- ``P``: No effect. 5167- ``q``: No effect. 5168- ``y``: Print a VFP single-precision register as an indexed double (e.g. print 5169 as ``d4[1]`` instead of ``s9``) 5170- ``B``: Bitwise invert and print an immediate integer constant without ``#`` 5171 prefix. 5172- ``L``: Print the low 16-bits of an immediate integer constant. 5173- ``M``: Print as a register set suitable for ldm/stm. Also prints *all* 5174 register operands subsequent to the specified one (!), so use carefully. 5175- ``Q``: Print the low-order register of a register-pair, or the low-order 5176 register of a two-register operand. 5177- ``R``: Print the high-order register of a register-pair, or the high-order 5178 register of a two-register operand. 5179- ``H``: Print the second register of a register-pair. (On a big-endian system, 5180 ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent 5181 to ``R``.) 5182 5183 .. FIXME: H doesn't currently support printing the second register 5184 of a two-register operand. 5185 5186- ``e``: Print the low doubleword register of a NEON quad register. 5187- ``f``: Print the high doubleword register of a NEON quad register. 5188- ``m``: Print the base register of a memory operand without the ``[`` and ``]`` 5189 adornment. 5190 5191Hexagon: 5192 5193- ``L``: Print the second register of a two-register operand. Requires that it 5194 has been allocated consecutively to the first. 5195 5196 .. FIXME: why is it restricted to consecutive ones? And there's 5197 nothing that ensures that happens, is there? 5198 5199- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise 5200 nothing. Used to print 'addi' vs 'add' instructions. 5201 5202LoongArch: 5203 5204- ``z``: Print $zero register if operand is zero, otherwise print it normally. 5205 5206MSP430: 5207 5208No additional modifiers. 5209 5210MIPS: 5211 5212- ``X``: Print an immediate integer as hexadecimal 5213- ``x``: Print the low 16 bits of an immediate integer as hexadecimal. 5214- ``d``: Print an immediate integer as decimal. 5215- ``m``: Subtract one and print an immediate integer as decimal. 5216- ``z``: Print $0 if an immediate zero, otherwise print normally. 5217- ``L``: Print the low-order register of a two-register operand, or prints the 5218 address of the low-order word of a double-word memory operand. 5219 5220 .. FIXME: L seems to be missing memory operand support. 5221 5222- ``M``: Print the high-order register of a two-register operand, or prints the 5223 address of the high-order word of a double-word memory operand. 5224 5225 .. FIXME: M seems to be missing memory operand support. 5226 5227- ``D``: Print the second register of a two-register operand, or prints the 5228 second word of a double-word memory operand. (On a big-endian system, ``D`` is 5229 equivalent to ``L``, and on little-endian system, ``D`` is equivalent to 5230 ``M``.) 5231- ``w``: No effect. Provided for compatibility with GCC which requires this 5232 modifier in order to print MSA registers (``W0-W31``) with the ``f`` 5233 constraint. 5234 5235NVPTX: 5236 5237- ``r``: No effect. 5238 5239PowerPC: 5240 5241- ``L``: Print the second register of a two-register operand. Requires that it 5242 has been allocated consecutively to the first. 5243 5244 .. FIXME: why is it restricted to consecutive ones? And there's 5245 nothing that ensures that happens, is there? 5246 5247- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise 5248 nothing. Used to print 'addi' vs 'add' instructions. 5249- ``y``: For a memory operand, prints formatter for a two-register X-form 5250 instruction. (Currently always prints ``r0,OPERAND``). 5251- ``U``: Prints 'u' if the memory operand is an update form, and nothing 5252 otherwise. (NOTE: LLVM does not support update form, so this will currently 5253 always print nothing) 5254- ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does 5255 not support indexed form, so this will currently always print nothing) 5256 5257RISC-V: 5258 5259- ``i``: Print the letter 'i' if the operand is not a register, otherwise print 5260 nothing. Used to print 'addi' vs 'add' instructions, etc. 5261- ``z``: Print the register ``zero`` if an immediate zero, otherwise print 5262 normally. 5263 5264Sparc: 5265 5266- ``r``: No effect. 5267 5268SystemZ: 5269 5270SystemZ implements only ``n``, and does *not* support any of the other 5271target-independent modifiers. 5272 5273X86: 5274 5275- ``c``: Print an unadorned integer or symbol name. (The latter is 5276 target-specific behavior for this typically target-independent modifier). 5277- ``A``: Print a register name with a '``*``' before it. 5278- ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory 5279 operand. 5280- ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a 5281 memory operand. 5282- ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory 5283 operand. 5284- ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory 5285 operand. 5286- ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are 5287 available, otherwise the 32-bit register name; do nothing on a memory operand. 5288- ``n``: Negate and print an unadorned integer, or, for operands other than an 5289 immediate integer (e.g. a relocatable symbol expression), print a '-' before 5290 the operand. (The behavior for relocatable symbol expressions is a 5291 target-specific behavior for this typically target-independent modifier) 5292- ``H``: Print a memory reference with additional offset +8. 5293- ``P``: Print a memory reference used as the argument of a call instruction or 5294 used with explicit base reg and index reg as its offset. So it can not use 5295 additional regs to present the memory reference. (E.g. omit ``(rip)``, even 5296 though it's PC-relative.) 5297 5298XCore: 5299 5300No additional modifiers. 5301 5302 5303Inline Asm Metadata 5304^^^^^^^^^^^^^^^^^^^ 5305 5306The call instructions that wrap inline asm nodes may have a 5307"``!srcloc``" MDNode attached to it that contains a list of constant 5308integers. If present, the code generator will use the integer as the 5309location cookie value when report errors through the ``LLVMContext`` 5310error reporting mechanisms. This allows a front-end to correlate backend 5311errors that occur with inline asm back to the source code that produced 5312it. For example: 5313 5314.. code-block:: llvm 5315 5316 call void asm sideeffect "something bad", ""(), !srcloc !42 5317 ... 5318 !42 = !{ i32 1234567 } 5319 5320It is up to the front-end to make sense of the magic numbers it places 5321in the IR. If the MDNode contains multiple constants, the code generator 5322will use the one that corresponds to the line of the asm that the error 5323occurs on. 5324 5325.. _metadata: 5326 5327Metadata 5328======== 5329 5330LLVM IR allows metadata to be attached to instructions and global objects in the 5331program that can convey extra information about the code to the optimizers and 5332code generator. One example application of metadata is source-level 5333debug information. There are two metadata primitives: strings and nodes. 5334 5335Metadata does not have a type, and is not a value. If referenced from a 5336``call`` instruction, it uses the ``metadata`` type. 5337 5338All metadata are identified in syntax by an exclamation point ('``!``'). 5339 5340.. _metadata-string: 5341 5342Metadata Nodes and Metadata Strings 5343----------------------------------- 5344 5345A metadata string is a string surrounded by double quotes. It can 5346contain any character by escaping non-printable characters with 5347"``\xx``" where "``xx``" is the two digit hex code. For example: 5348"``!"test\00"``". 5349 5350Metadata nodes are represented with notation similar to structure 5351constants (a comma separated list of elements, surrounded by braces and 5352preceded by an exclamation point). Metadata nodes can have any values as 5353their operand. For example: 5354 5355.. code-block:: llvm 5356 5357 !{ !"test\00", i32 10} 5358 5359Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example: 5360 5361.. code-block:: text 5362 5363 !0 = distinct !{!"test\00", i32 10} 5364 5365``distinct`` nodes are useful when nodes shouldn't be merged based on their 5366content. They can also occur when transformations cause uniquing collisions 5367when metadata operands change. 5368 5369A :ref:`named metadata <namedmetadatastructure>` is a collection of 5370metadata nodes, which can be looked up in the module symbol table. For 5371example: 5372 5373.. code-block:: llvm 5374 5375 !foo = !{!4, !3} 5376 5377Metadata can be used as function arguments. Here the ``llvm.dbg.value`` 5378intrinsic is using three metadata arguments: 5379 5380.. code-block:: llvm 5381 5382 call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26) 5383 5384Metadata can be attached to an instruction. Here metadata ``!21`` is attached 5385to the ``add`` instruction using the ``!dbg`` identifier: 5386 5387.. code-block:: llvm 5388 5389 %indvar.next = add i64 %indvar, 1, !dbg !21 5390 5391Instructions may not have multiple metadata attachments with the same 5392identifier. 5393 5394Metadata can also be attached to a function or a global variable. Here metadata 5395``!22`` is attached to the ``f1`` and ``f2`` functions, and the globals ``g1`` 5396and ``g2`` using the ``!dbg`` identifier: 5397 5398.. code-block:: llvm 5399 5400 declare !dbg !22 void @f1() 5401 define void @f2() !dbg !22 { 5402 ret void 5403 } 5404 5405 @g1 = global i32 0, !dbg !22 5406 @g2 = external global i32, !dbg !22 5407 5408Unlike instructions, global objects (functions and global variables) may have 5409multiple metadata attachments with the same identifier. 5410 5411A transformation is required to drop any metadata attachment that it 5412does not know or know it can't preserve. Currently there is an 5413exception for metadata attachment to globals for ``!func_sanitize``, 5414``!type``, ``!absolute_symbol`` and ``!associated`` which can't be 5415unconditionally dropped unless the global is itself deleted. 5416 5417Metadata attached to a module using named metadata may not be dropped, with 5418the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``). 5419 5420More information about specific metadata nodes recognized by the 5421optimizers and code generator is found below. 5422 5423.. _specialized-metadata: 5424 5425Specialized Metadata Nodes 5426^^^^^^^^^^^^^^^^^^^^^^^^^^ 5427 5428Specialized metadata nodes are custom data structures in metadata (as opposed 5429to generic tuples). Their fields are labelled, and can be specified in any 5430order. 5431 5432These aren't inherently debug info centric, but currently all the specialized 5433metadata nodes are related to debug info. 5434 5435.. _DICompileUnit: 5436 5437DICompileUnit 5438""""""""""""" 5439 5440``DICompileUnit`` nodes represent a compile unit. The ``enums:``, 5441``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples 5442containing the debug info to be emitted along with the compile unit, regardless 5443of code optimizations (some nodes are only emitted if there are references to 5444them from instructions). The ``debugInfoForProfiling:`` field is a boolean 5445indicating whether or not line-table discriminators are updated to provide 5446more-accurate debug info for profiling results. 5447 5448.. code-block:: text 5449 5450 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", 5451 isOptimized: true, flags: "-O2", runtimeVersion: 2, 5452 splitDebugFilename: "abc.debug", emissionKind: FullDebug, 5453 enums: !2, retainedTypes: !3, globals: !4, imports: !5, 5454 macros: !6, dwoId: 0x0abcd) 5455 5456Compile unit descriptors provide the root scope for objects declared in a 5457specific compilation unit. File descriptors are defined using this scope. These 5458descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep 5459track of global variables, type information, and imported entities (declarations 5460and namespaces). 5461 5462.. _DIFile: 5463 5464DIFile 5465"""""" 5466 5467``DIFile`` nodes represent files. The ``filename:`` can include slashes. 5468 5469.. code-block:: none 5470 5471 !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir", 5472 checksumkind: CSK_MD5, 5473 checksum: "000102030405060708090a0b0c0d0e0f") 5474 5475Files are sometimes used in ``scope:`` fields, and are the only valid target 5476for ``file:`` fields. 5477Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1, CSK_SHA256} 5478 5479.. _DIBasicType: 5480 5481DIBasicType 5482""""""""""" 5483 5484``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and 5485``float``. ``tag:`` defaults to ``DW_TAG_base_type``. 5486 5487.. code-block:: text 5488 5489 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8, 5490 encoding: DW_ATE_unsigned_char) 5491 !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)") 5492 5493The ``encoding:`` describes the details of the type. Usually it's one of the 5494following: 5495 5496.. code-block:: text 5497 5498 DW_ATE_address = 1 5499 DW_ATE_boolean = 2 5500 DW_ATE_float = 4 5501 DW_ATE_signed = 5 5502 DW_ATE_signed_char = 6 5503 DW_ATE_unsigned = 7 5504 DW_ATE_unsigned_char = 8 5505 5506.. _DISubroutineType: 5507 5508DISubroutineType 5509"""""""""""""""" 5510 5511``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field 5512refers to a tuple; the first operand is the return type, while the rest are the 5513types of the formal arguments in order. If the first operand is ``null``, that 5514represents a function with no return value (such as ``void foo() {}`` in C++). 5515 5516.. code-block:: text 5517 5518 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed) 5519 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char) 5520 !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char) 5521 5522.. _DIDerivedType: 5523 5524DIDerivedType 5525""""""""""""" 5526 5527``DIDerivedType`` nodes represent types derived from other types, such as 5528qualified types. 5529 5530.. code-block:: text 5531 5532 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8, 5533 encoding: DW_ATE_unsigned_char) 5534 !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32, 5535 align: 32) 5536 5537The following ``tag:`` values are valid: 5538 5539.. code-block:: text 5540 5541 DW_TAG_member = 13 5542 DW_TAG_pointer_type = 15 5543 DW_TAG_reference_type = 16 5544 DW_TAG_typedef = 22 5545 DW_TAG_inheritance = 28 5546 DW_TAG_ptr_to_member_type = 31 5547 DW_TAG_const_type = 38 5548 DW_TAG_friend = 42 5549 DW_TAG_volatile_type = 53 5550 DW_TAG_restrict_type = 55 5551 DW_TAG_atomic_type = 71 5552 DW_TAG_immutable_type = 75 5553 5554.. _DIDerivedTypeMember: 5555 5556``DW_TAG_member`` is used to define a member of a :ref:`composite type 5557<DICompositeType>`. The type of the member is the ``baseType:``. The 5558``offset:`` is the member's bit offset. If the composite type has an ODR 5559``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is 5560uniqued based only on its ``name:`` and ``scope:``. 5561 5562``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:`` 5563field of :ref:`composite types <DICompositeType>` to describe parents and 5564friends. 5565 5566``DW_TAG_typedef`` is used to provide a name for the ``baseType:``. 5567 5568``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``, 5569``DW_TAG_volatile_type``, ``DW_TAG_restrict_type``, ``DW_TAG_atomic_type`` and 5570``DW_TAG_immutable_type`` are used to qualify the ``baseType:``. 5571 5572Note that the ``void *`` type is expressed as a type derived from NULL. 5573 5574.. _DICompositeType: 5575 5576DICompositeType 5577""""""""""""""" 5578 5579``DICompositeType`` nodes represent types composed of other types, like 5580structures and unions. ``elements:`` points to a tuple of the composed types. 5581 5582If the source language supports ODR, the ``identifier:`` field gives the unique 5583identifier used for type merging between modules. When specified, 5584:ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member 5585derived types <DIDerivedTypeMember>` that reference the ODR-type in their 5586``scope:`` change uniquing rules. 5587 5588For a given ``identifier:``, there should only be a single composite type that 5589does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules 5590together will unique such definitions at parse time via the ``identifier:`` 5591field, even if the nodes are ``distinct``. 5592 5593.. code-block:: text 5594 5595 !0 = !DIEnumerator(name: "SixKind", value: 7) 5596 !1 = !DIEnumerator(name: "SevenKind", value: 7) 5597 !2 = !DIEnumerator(name: "NegEightKind", value: -8) 5598 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12, 5599 line: 2, size: 32, align: 32, identifier: "_M4Enum", 5600 elements: !{!0, !1, !2}) 5601 5602The following ``tag:`` values are valid: 5603 5604.. code-block:: text 5605 5606 DW_TAG_array_type = 1 5607 DW_TAG_class_type = 2 5608 DW_TAG_enumeration_type = 4 5609 DW_TAG_structure_type = 19 5610 DW_TAG_union_type = 23 5611 5612For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange 5613descriptors <DISubrange>`, each representing the range of subscripts at that 5614level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an 5615array type is a native packed vector. The optional ``dataLocation`` is a 5616DIExpression that describes how to get from an object's address to the actual 5617raw data, if they aren't equivalent. This is only supported for array types, 5618particularly to describe Fortran arrays, which have an array descriptor in 5619addition to the array data. Alternatively it can also be DIVariable which 5620has the address of the actual raw data. The Fortran language supports pointer 5621arrays which can be attached to actual arrays, this attachment between pointer 5622and pointee is called association. The optional ``associated`` is a 5623DIExpression that describes whether the pointer array is currently associated. 5624The optional ``allocated`` is a DIExpression that describes whether the 5625allocatable array is currently allocated. The optional ``rank`` is a 5626DIExpression that describes the rank (number of dimensions) of fortran assumed 5627rank array (rank is known at runtime). 5628 5629For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator 5630descriptors <DIEnumerator>`, each representing the definition of an enumeration 5631value for the set. All enumeration type descriptors are collected in the 5632``enums:`` field of the :ref:`compile unit <DICompileUnit>`. 5633 5634For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and 5635``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types 5636<DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or 5637``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with 5638``isDefinition: false``. 5639 5640.. _DISubrange: 5641 5642DISubrange 5643"""""""""" 5644 5645``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of 5646:ref:`DICompositeType`. 5647 5648- ``count: -1`` indicates an empty array. 5649- ``count: !10`` describes the count with a :ref:`DILocalVariable`. 5650- ``count: !12`` describes the count with a :ref:`DIGlobalVariable`. 5651 5652.. code-block:: text 5653 5654 !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0 5655 !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1 5656 !2 = !DISubrange(count: -1) ; empty array. 5657 5658 ; Scopes used in rest of example 5659 !6 = !DIFile(filename: "vla.c", directory: "/path/to/file") 5660 !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6) 5661 !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5) 5662 5663 ; Use of local variable as count value 5664 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 5665 !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9) 5666 !11 = !DISubrange(count: !10, lowerBound: 0) 5667 5668 ; Use of global variable as count value 5669 !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9) 5670 !13 = !DISubrange(count: !12, lowerBound: 0) 5671 5672.. _DIEnumerator: 5673 5674DIEnumerator 5675"""""""""""" 5676 5677``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type`` 5678variants of :ref:`DICompositeType`. 5679 5680.. code-block:: text 5681 5682 !0 = !DIEnumerator(name: "SixKind", value: 7) 5683 !1 = !DIEnumerator(name: "SevenKind", value: 7) 5684 !2 = !DIEnumerator(name: "NegEightKind", value: -8) 5685 5686DITemplateTypeParameter 5687""""""""""""""""""""""" 5688 5689``DITemplateTypeParameter`` nodes represent type parameters to generic source 5690language constructs. They are used (optionally) in :ref:`DICompositeType` and 5691:ref:`DISubprogram` ``templateParams:`` fields. 5692 5693.. code-block:: text 5694 5695 !0 = !DITemplateTypeParameter(name: "Ty", type: !1) 5696 5697DITemplateValueParameter 5698"""""""""""""""""""""""" 5699 5700``DITemplateValueParameter`` nodes represent value parameters to generic source 5701language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``, 5702but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or 5703``DW_TAG_GNU_template_param_pack``. They are used (optionally) in 5704:ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields. 5705 5706.. code-block:: text 5707 5708 !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7) 5709 5710DINamespace 5711""""""""""" 5712 5713``DINamespace`` nodes represent namespaces in the source language. 5714 5715.. code-block:: text 5716 5717 !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7) 5718 5719.. _DIGlobalVariable: 5720 5721DIGlobalVariable 5722"""""""""""""""" 5723 5724``DIGlobalVariable`` nodes represent global variables in the source language. 5725 5726.. code-block:: text 5727 5728 @foo = global i32, !dbg !0 5729 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 5730 !1 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !2, 5731 file: !3, line: 7, type: !4, isLocal: true, 5732 isDefinition: false, declaration: !5) 5733 5734 5735DIGlobalVariableExpression 5736"""""""""""""""""""""""""" 5737 5738``DIGlobalVariableExpression`` nodes tie a :ref:`DIGlobalVariable` together 5739with a :ref:`DIExpression`. 5740 5741.. code-block:: text 5742 5743 @lower = global i32, !dbg !0 5744 @upper = global i32, !dbg !1 5745 !0 = !DIGlobalVariableExpression( 5746 var: !2, 5747 expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32) 5748 ) 5749 !1 = !DIGlobalVariableExpression( 5750 var: !2, 5751 expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32) 5752 ) 5753 !2 = !DIGlobalVariable(name: "split64", linkageName: "split64", scope: !3, 5754 file: !4, line: 8, type: !5, declaration: !6) 5755 5756All global variable expressions should be referenced by the `globals:` field of 5757a :ref:`compile unit <DICompileUnit>`. 5758 5759.. _DISubprogram: 5760 5761DISubprogram 5762"""""""""""" 5763 5764``DISubprogram`` nodes represent functions from the source language. A distinct 5765``DISubprogram`` may be attached to a function definition using ``!dbg`` 5766metadata. A unique ``DISubprogram`` may be attached to a function declaration 5767used for call site debug info. The ``retainedNodes:`` field is a list of 5768:ref:`variables <DILocalVariable>` and :ref:`labels <DILabel>` that must be 5769retained, even if their IR counterparts are optimized out of the IR. The 5770``type:`` field must point at an :ref:`DISubroutineType`. 5771 5772.. _DISubprogramDeclaration: 5773 5774When ``isDefinition: false``, subprograms describe a declaration in the type 5775tree as opposed to a definition of a function. If the scope is a composite 5776type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``, 5777then the subprogram declaration is uniqued based only on its ``linkageName:`` 5778and ``scope:``. 5779 5780.. code-block:: text 5781 5782 define void @_Z3foov() !dbg !0 { 5783 ... 5784 } 5785 5786 !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1, 5787 file: !2, line: 7, type: !3, isLocal: true, 5788 isDefinition: true, scopeLine: 8, 5789 containingType: !4, 5790 virtuality: DW_VIRTUALITY_pure_virtual, 5791 virtualIndex: 10, flags: DIFlagPrototyped, 5792 isOptimized: true, unit: !5, templateParams: !6, 5793 declaration: !7, retainedNodes: !8, 5794 thrownTypes: !9) 5795 5796.. _DILexicalBlock: 5797 5798DILexicalBlock 5799"""""""""""""" 5800 5801``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram 5802<DISubprogram>`. The line number and column numbers are used to distinguish 5803two lexical blocks at same depth. They are valid targets for ``scope:`` 5804fields. 5805 5806.. code-block:: text 5807 5808 !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35) 5809 5810Usually lexical blocks are ``distinct`` to prevent node merging based on 5811operands. 5812 5813.. _DILexicalBlockFile: 5814 5815DILexicalBlockFile 5816"""""""""""""""""" 5817 5818``DILexicalBlockFile`` nodes are used to discriminate between sections of a 5819:ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to 5820indicate textual inclusion, or the ``discriminator:`` field can be used to 5821discriminate between control flow within a single block in the source language. 5822 5823.. code-block:: text 5824 5825 !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35) 5826 !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0) 5827 !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1) 5828 5829.. _DILocation: 5830 5831DILocation 5832"""""""""" 5833 5834``DILocation`` nodes represent source debug locations. The ``scope:`` field is 5835mandatory, and points at an :ref:`DILexicalBlockFile`, an 5836:ref:`DILexicalBlock`, or an :ref:`DISubprogram`. 5837 5838.. code-block:: text 5839 5840 !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2) 5841 5842.. _DILocalVariable: 5843 5844DILocalVariable 5845""""""""""""""" 5846 5847``DILocalVariable`` nodes represent local variables in the source language. If 5848the ``arg:`` field is set to non-zero, then this variable is a subprogram 5849parameter, and it will be included in the ``retainedNodes:`` field of its 5850:ref:`DISubprogram`. 5851 5852.. code-block:: text 5853 5854 !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7, 5855 type: !3, flags: DIFlagArtificial) 5856 !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7, 5857 type: !3) 5858 !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3) 5859 5860.. _DIExpression: 5861 5862DIExpression 5863"""""""""""" 5864 5865``DIExpression`` nodes represent expressions that are inspired by the DWARF 5866expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>` 5867(such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the 5868referenced LLVM variable relates to the source language variable. Debug 5869intrinsics are interpreted left-to-right: start by pushing the value/address 5870operand of the intrinsic onto a stack, then repeatedly push and evaluate 5871opcodes from the DIExpression until the final variable description is produced. 5872 5873The current supported opcode vocabulary is limited: 5874 5875- ``DW_OP_deref`` dereferences the top of the expression stack. 5876- ``DW_OP_plus`` pops the last two entries from the expression stack, adds 5877 them together and appends the result to the expression stack. 5878- ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts 5879 the last entry from the second last entry and appends the result to the 5880 expression stack. 5881- ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression. 5882- ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8`` 5883 here, respectively) of the variable fragment from the working expression. Note 5884 that contrary to DW_OP_bit_piece, the offset is describing the location 5885 within the described source variable. 5886- ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding 5887 (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the 5888 expression stack is to be converted. Maps into a ``DW_OP_convert`` operation 5889 that references a base type constructed from the supplied values. 5890- ``DW_OP_LLVM_tag_offset, tag_offset`` specifies that a memory tag should be 5891 optionally applied to the pointer. The memory tag is derived from the 5892 given tag offset in an implementation-defined manner. 5893- ``DW_OP_swap`` swaps top two stack entries. 5894- ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top 5895 of the stack is treated as an address. The second stack entry is treated as an 5896 address space identifier. 5897- ``DW_OP_stack_value`` marks a constant value. 5898- ``DW_OP_LLVM_entry_value, N`` may only appear in MIR and at the 5899 beginning of a ``DIExpression``. In DWARF a ``DBG_VALUE`` 5900 instruction binding a ``DIExpression(DW_OP_LLVM_entry_value`` to a 5901 register is lowered to a ``DW_OP_entry_value [reg]``, pushing the 5902 value the register had upon function entry onto the stack. The next 5903 ``(N - 1)`` operations will be part of the ``DW_OP_entry_value`` 5904 block argument. For example, ``!DIExpression(DW_OP_LLVM_entry_value, 5905 1, DW_OP_plus_uconst, 123, DW_OP_stack_value)`` specifies an 5906 expression where the entry value of the debug value instruction's 5907 value/address operand is pushed to the stack, and is added 5908 with 123. Due to framework limitations ``N`` can currently only 5909 be 1. 5910 5911 The operation is introduced by the ``LiveDebugValues`` pass, which 5912 applies it only to function parameters that are unmodified 5913 throughout the function. Support is limited to simple register 5914 location descriptions, or as indirect locations (e.g., when a struct 5915 is passed-by-value to a callee via a pointer to a temporary copy 5916 made in the caller). The entry value op is also introduced by the 5917 ``AsmPrinter`` pass when a call site parameter value 5918 (``DW_AT_call_site_parameter_value``) is represented as entry value 5919 of the parameter. 5920- ``DW_OP_LLVM_arg, N`` is used in debug intrinsics that refer to more than one 5921 value, such as one that calculates the sum of two registers. This is always 5922 used in combination with an ordered list of values, such that 5923 ``DW_OP_LLVM_arg, N`` refers to the ``N``\ :sup:`th` element in that list. For 5924 example, ``!DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus, 5925 DW_OP_stack_value)`` used with the list ``(%reg1, %reg2)`` would evaluate to 5926 ``%reg1 - reg2``. This list of values should be provided by the containing 5927 intrinsic/instruction. 5928- ``DW_OP_breg`` (or ``DW_OP_bregx``) represents a content on the provided 5929 signed offset of the specified register. The opcode is only generated by the 5930 ``AsmPrinter`` pass to describe call site parameter value which requires an 5931 expression over two registers. 5932- ``DW_OP_push_object_address`` pushes the address of the object which can then 5933 serve as a descriptor in subsequent calculation. This opcode can be used to 5934 calculate bounds of fortran allocatable array which has array descriptors. 5935- ``DW_OP_over`` duplicates the entry currently second in the stack at the top 5936 of the stack. This opcode can be used to calculate bounds of fortran assumed 5937 rank array which has rank known at run time and current dimension number is 5938 implicitly first element of the stack. 5939- ``DW_OP_LLVM_implicit_pointer`` It specifies the dereferenced value. It can 5940 be used to represent pointer variables which are optimized out but the value 5941 it points to is known. This operator is required as it is different than DWARF 5942 operator DW_OP_implicit_pointer in representation and specification (number 5943 and types of operands) and later can not be used as multiple level. 5944 5945.. code-block:: text 5946 5947 IR for "*ptr = 4;" 5948 -------------- 5949 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !20) 5950 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5, 5951 type: !18) 5952 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64) 5953 !19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 5954 !20 = !DIExpression(DW_OP_LLVM_implicit_pointer)) 5955 5956 IR for "**ptr = 4;" 5957 -------------- 5958 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !21) 5959 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5, 5960 type: !18) 5961 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64) 5962 !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64) 5963 !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 5964 !21 = !DIExpression(DW_OP_LLVM_implicit_pointer, 5965 DW_OP_LLVM_implicit_pointer)) 5966 5967DWARF specifies three kinds of simple location descriptions: Register, memory, 5968and implicit location descriptions. Note that a location description is 5969defined over certain ranges of a program, i.e the location of a variable may 5970change over the course of the program. Register and memory location 5971descriptions describe the *concrete location* of a source variable (in the 5972sense that a debugger might modify its value), whereas *implicit locations* 5973describe merely the actual *value* of a source variable which might not exist 5974in registers or in memory (see ``DW_OP_stack_value``). 5975 5976A ``llvm.dbg.addr`` or ``llvm.dbg.declare`` intrinsic describes an indirect 5977value (the address) of a source variable. The first operand of the intrinsic 5978must be an address of some kind. A DIExpression attached to the intrinsic 5979refines this address to produce a concrete location for the source variable. 5980 5981A ``llvm.dbg.value`` intrinsic describes the direct value of a source variable. 5982The first operand of the intrinsic may be a direct or indirect value. A 5983DIExpression attached to the intrinsic refines the first operand to produce a 5984direct value. For example, if the first operand is an indirect value, it may be 5985necessary to insert ``DW_OP_deref`` into the DIExpression in order to produce a 5986valid debug intrinsic. 5987 5988.. note:: 5989 5990 A DIExpression is interpreted in the same way regardless of which kind of 5991 debug intrinsic it's attached to. 5992 5993.. code-block:: text 5994 5995 !0 = !DIExpression(DW_OP_deref) 5996 !1 = !DIExpression(DW_OP_plus_uconst, 3) 5997 !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus) 5998 !2 = !DIExpression(DW_OP_bit_piece, 3, 7) 5999 !3 = !DIExpression(DW_OP_deref, DW_OP_constu, 3, DW_OP_plus, DW_OP_LLVM_fragment, 3, 7) 6000 !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef) 6001 !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value) 6002 6003DIAssignID 6004"""""""""""" 6005 6006``DIAssignID`` nodes have no operands and are always distinct. They are used to 6007link together `@llvm.dbg.assign` intrinsics (:ref:`debug 6008intrinsics<dbg_intrinsics>`) and instructions that store in IR. See `Debug Info 6009Assignment Tracking <AssignmentTracking.html>`_ for more info. 6010 6011.. code-block:: llvm 6012 6013 store i32 %a, ptr %a.addr, align 4, !DIAssignID !2 6014 llvm.dbg.assign(metadata %a, metadata !1, metadata !DIExpression(), !2, metadata %a.addr, metadata !DIExpression()), !dbg !3 6015 6016 !2 = distinct !DIAssignID() 6017 6018DIArgList 6019"""""""""""" 6020 6021``DIArgList`` nodes hold a list of constant or SSA value references. These are 6022used in :ref:`debug intrinsics<dbg_intrinsics>` (currently only in 6023``llvm.dbg.value``) in combination with a ``DIExpression`` that uses the 6024``DW_OP_LLVM_arg`` operator. Because a DIArgList may refer to local values 6025within a function, it must only be used as a function argument, must always be 6026inlined, and cannot appear in named metadata. 6027 6028.. code-block:: text 6029 6030 llvm.dbg.value(metadata !DIArgList(i32 %a, i32 %b), 6031 metadata !16, 6032 metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus)) 6033 6034DIFlags 6035""""""""""""""" 6036 6037These flags encode various properties of DINodes. 6038 6039The `ExportSymbols` flag marks a class, struct or union whose members 6040may be referenced as if they were defined in the containing class or 6041union. This flag is used to decide whether the DW_AT_export_symbols can 6042be used for the structure type. 6043 6044DIObjCProperty 6045"""""""""""""" 6046 6047``DIObjCProperty`` nodes represent Objective-C property nodes. 6048 6049.. code-block:: text 6050 6051 !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo", 6052 getter: "getFoo", attributes: 7, type: !2) 6053 6054DIImportedEntity 6055"""""""""""""""" 6056 6057``DIImportedEntity`` nodes represent entities (such as modules) imported into a 6058compile unit. The ``elements`` field is a list of renamed entities (such as 6059variables and subprograms) in the imported entity (such as module). 6060 6061.. code-block:: text 6062 6063 !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0, 6064 entity: !1, line: 7, elements: !3) 6065 !3 = !{!4} 6066 !4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "bar", scope: !0, 6067 entity: !5, line: 7) 6068 6069DIMacro 6070""""""" 6071 6072``DIMacro`` nodes represent definition or undefinition of a macro identifiers. 6073The ``name:`` field is the macro identifier, followed by macro parameters when 6074defining a function-like macro, and the ``value`` field is the token-string 6075used to expand the macro identifier. 6076 6077.. code-block:: text 6078 6079 !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)", 6080 value: "((x) + 1)") 6081 !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo") 6082 6083DIMacroFile 6084""""""""""" 6085 6086``DIMacroFile`` nodes represent inclusion of source files. 6087The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that 6088appear in the included source file. 6089 6090.. code-block:: text 6091 6092 !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2, 6093 nodes: !3) 6094 6095.. _DILabel: 6096 6097DILabel 6098""""""" 6099 6100``DILabel`` nodes represent labels within a :ref:`DISubprogram`. All fields of 6101a ``DILabel`` are mandatory. The ``scope:`` field must be one of either a 6102:ref:`DILexicalBlockFile`, a :ref:`DILexicalBlock`, or a :ref:`DISubprogram`. 6103The ``name:`` field is the label identifier. The ``file:`` field is the 6104:ref:`DIFile` the label is present in. The ``line:`` field is the source line 6105within the file where the label is declared. 6106 6107.. code-block:: text 6108 6109 !2 = !DILabel(scope: !0, name: "foo", file: !1, line: 7) 6110 6111'``tbaa``' Metadata 6112^^^^^^^^^^^^^^^^^^^ 6113 6114In LLVM IR, memory does not have types, so LLVM's own type system is not 6115suitable for doing type based alias analysis (TBAA). Instead, metadata is 6116added to the IR to describe a type system of a higher level language. This 6117can be used to implement C/C++ strict type aliasing rules, but it can also 6118be used to implement custom alias analysis behavior for other languages. 6119 6120This description of LLVM's TBAA system is broken into two parts: 6121:ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and 6122:ref:`Representation<tbaa_node_representation>` talks about the metadata 6123encoding of various entities. 6124 6125It is always possible to trace any TBAA node to a "root" TBAA node (details 6126in the :ref:`Representation<tbaa_node_representation>` section). TBAA 6127nodes with different roots have an unknown aliasing relationship, and LLVM 6128conservatively infers ``MayAlias`` between them. The rules mentioned in 6129this section only pertain to TBAA nodes living under the same root. 6130 6131.. _tbaa_node_semantics: 6132 6133Semantics 6134""""""""" 6135 6136The TBAA metadata system, referred to as "struct path TBAA" (not to be 6137confused with ``tbaa.struct``), consists of the following high level 6138concepts: *Type Descriptors*, further subdivided into scalar type 6139descriptors and struct type descriptors; and *Access Tags*. 6140 6141**Type descriptors** describe the type system of the higher level language 6142being compiled. **Scalar type descriptors** describe types that do not 6143contain other types. Each scalar type has a parent type, which must also 6144be a scalar type or the TBAA root. Via this parent relation, scalar types 6145within a TBAA root form a tree. **Struct type descriptors** denote types 6146that contain a sequence of other type descriptors, at known offsets. These 6147contained type descriptors can either be struct type descriptors themselves 6148or scalar type descriptors. 6149 6150**Access tags** are metadata nodes attached to load and store instructions. 6151Access tags use type descriptors to describe the *location* being accessed 6152in terms of the type system of the higher level language. Access tags are 6153tuples consisting of a base type, an access type and an offset. The base 6154type is a scalar type descriptor or a struct type descriptor, the access 6155type is a scalar type descriptor, and the offset is a constant integer. 6156 6157The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two 6158things: 6159 6160 * If ``BaseTy`` is a struct type, the tag describes a memory access (load 6161 or store) of a value of type ``AccessTy`` contained in the struct type 6162 ``BaseTy`` at offset ``Offset``. 6163 6164 * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and 6165 ``AccessTy`` must be the same; and the access tag describes a scalar 6166 access with scalar type ``AccessTy``. 6167 6168We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)`` 6169tuples this way: 6170 6171 * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is 6172 ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as 6173 described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is 6174 undefined if ``Offset`` is non-zero. 6175 6176 * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)`` 6177 is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in 6178 ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted 6179 to be relative within that inner type. 6180 6181A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)`` 6182aliases a memory access with an access tag ``(BaseTy2, AccessTy2, 6183Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2, 6184Offset2)`` via the ``Parent`` relation or vice versa. 6185 6186As a concrete example, the type descriptor graph for the following program 6187 6188.. code-block:: c 6189 6190 struct Inner { 6191 int i; // offset 0 6192 float f; // offset 4 6193 }; 6194 6195 struct Outer { 6196 float f; // offset 0 6197 double d; // offset 4 6198 struct Inner inner_a; // offset 12 6199 }; 6200 6201 void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) { 6202 outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0) 6203 outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12) 6204 outer->inner_a.f = 0.0; // tag2: (OuterStructTy, FloatScalarTy, 16) 6205 *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0) 6206 } 6207 6208is (note that in C and C++, ``char`` can be used to access any arbitrary 6209type): 6210 6211.. code-block:: text 6212 6213 Root = "TBAA Root" 6214 CharScalarTy = ("char", Root, 0) 6215 FloatScalarTy = ("float", CharScalarTy, 0) 6216 DoubleScalarTy = ("double", CharScalarTy, 0) 6217 IntScalarTy = ("int", CharScalarTy, 0) 6218 InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)} 6219 OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4), 6220 (InnerStructTy, 12)} 6221 6222 6223with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy, 62240)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and 6225``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``. 6226 6227.. _tbaa_node_representation: 6228 6229Representation 6230"""""""""""""" 6231 6232The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or 6233with exactly one ``MDString`` operand. 6234 6235Scalar type descriptors are represented as an ``MDNode`` s with two 6236operands. The first operand is an ``MDString`` denoting the name of the 6237struct type. LLVM does not assign meaning to the value of this operand, it 6238only cares about it being an ``MDString``. The second operand is an 6239``MDNode`` which points to the parent for said scalar type descriptor, 6240which is either another scalar type descriptor or the TBAA root. Scalar 6241type descriptors can have an optional third argument, but that must be the 6242constant integer zero. 6243 6244Struct type descriptors are represented as ``MDNode`` s with an odd number 6245of operands greater than 1. The first operand is an ``MDString`` denoting 6246the name of the struct type. Like in scalar type descriptors the actual 6247value of this name operand is irrelevant to LLVM. After the name operand, 6248the struct type descriptors have a sequence of alternating ``MDNode`` and 6249``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand, 6250an ``MDNode``, denotes a contained field, and the 2N th operand, a 6251``ConstantInt``, is the offset of the said contained field. The offsets 6252must be in non-decreasing order. 6253 6254Access tags are represented as ``MDNode`` s with either 3 or 4 operands. 6255The first operand is an ``MDNode`` pointing to the node representing the 6256base type. The second operand is an ``MDNode`` pointing to the node 6257representing the access type. The third operand is a ``ConstantInt`` that 6258states the offset of the access. If a fourth field is present, it must be 6259a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states 6260that the location being accessed is "constant" (meaning 6261``pointsToConstantMemory`` should return true; see `other useful 6262AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of 6263the access type and the base type of an access tag must be the same, and 6264that is the TBAA root of the access tag. 6265 6266'``tbaa.struct``' Metadata 6267^^^^^^^^^^^^^^^^^^^^^^^^^^ 6268 6269The :ref:`llvm.memcpy <int_memcpy>` is often used to implement 6270aggregate assignment operations in C and similar languages, however it 6271is defined to copy a contiguous region of memory, which is more than 6272strictly necessary for aggregate types which contain holes due to 6273padding. Also, it doesn't contain any TBAA information about the fields 6274of the aggregate. 6275 6276``!tbaa.struct`` metadata can describe which memory subregions in a 6277memcpy are padding and what the TBAA tags of the struct are. 6278 6279The current metadata format is very simple. ``!tbaa.struct`` metadata 6280nodes are a list of operands which are in conceptual groups of three. 6281For each group of three, the first operand gives the byte offset of a 6282field in bytes, the second gives its size in bytes, and the third gives 6283its tbaa tag. e.g.: 6284 6285.. code-block:: llvm 6286 6287 !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 } 6288 6289This describes a struct with two fields. The first is at offset 0 bytes 6290with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes 6291and has size 4 bytes and has tbaa tag !2. 6292 6293Note that the fields need not be contiguous. In this example, there is a 62944 byte gap between the two fields. This gap represents padding which 6295does not carry useful data and need not be preserved. 6296 6297'``noalias``' and '``alias.scope``' Metadata 6298^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6299 6300``noalias`` and ``alias.scope`` metadata provide the ability to specify generic 6301noalias memory-access sets. This means that some collection of memory access 6302instructions (loads, stores, memory-accessing calls, etc.) that carry 6303``noalias`` metadata can specifically be specified not to alias with some other 6304collection of memory access instructions that carry ``alias.scope`` metadata. 6305Each type of metadata specifies a list of scopes where each scope has an id and 6306a domain. 6307 6308When evaluating an aliasing query, if for some domain, the set 6309of scopes with that domain in one instruction's ``alias.scope`` list is a 6310subset of (or equal to) the set of scopes for that domain in another 6311instruction's ``noalias`` list, then the two memory accesses are assumed not to 6312alias. 6313 6314Because scopes in one domain don't affect scopes in other domains, separate 6315domains can be used to compose multiple independent noalias sets. This is 6316used for example during inlining. As the noalias function parameters are 6317turned into noalias scope metadata, a new domain is used every time the 6318function is inlined. 6319 6320The metadata identifying each domain is itself a list containing one or two 6321entries. The first entry is the name of the domain. Note that if the name is a 6322string then it can be combined across functions and translation units. A 6323self-reference can be used to create globally unique domain names. A 6324descriptive string may optionally be provided as a second list entry. 6325 6326The metadata identifying each scope is also itself a list containing two or 6327three entries. The first entry is the name of the scope. Note that if the name 6328is a string then it can be combined across functions and translation units. A 6329self-reference can be used to create globally unique scope names. A metadata 6330reference to the scope's domain is the second entry. A descriptive string may 6331optionally be provided as a third list entry. 6332 6333For example, 6334 6335.. code-block:: llvm 6336 6337 ; Two scope domains: 6338 !0 = !{!0} 6339 !1 = !{!1} 6340 6341 ; Some scopes in these domains: 6342 !2 = !{!2, !0} 6343 !3 = !{!3, !0} 6344 !4 = !{!4, !1} 6345 6346 ; Some scope lists: 6347 !5 = !{!4} ; A list containing only scope !4 6348 !6 = !{!4, !3, !2} 6349 !7 = !{!3} 6350 6351 ; These two instructions don't alias: 6352 %0 = load float, ptr %c, align 4, !alias.scope !5 6353 store float %0, ptr %arrayidx.i, align 4, !noalias !5 6354 6355 ; These two instructions also don't alias (for domain !1, the set of scopes 6356 ; in the !alias.scope equals that in the !noalias list): 6357 %2 = load float, ptr %c, align 4, !alias.scope !5 6358 store float %2, ptr %arrayidx.i2, align 4, !noalias !6 6359 6360 ; These two instructions may alias (for domain !0, the set of scopes in 6361 ; the !noalias list is not a superset of, or equal to, the scopes in the 6362 ; !alias.scope list): 6363 %2 = load float, ptr %c, align 4, !alias.scope !6 6364 store float %0, ptr %arrayidx.i, align 4, !noalias !7 6365 6366'``fpmath``' Metadata 6367^^^^^^^^^^^^^^^^^^^^^ 6368 6369``fpmath`` metadata may be attached to any instruction of floating-point 6370type. It can be used to express the maximum acceptable error in the 6371result of that instruction, in ULPs, thus potentially allowing the 6372compiler to use a more efficient but less accurate method of computing 6373it. ULP is defined as follows: 6374 6375 If ``x`` is a real number that lies between two finite consecutive 6376 floating-point numbers ``a`` and ``b``, without being equal to one 6377 of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the 6378 distance between the two non-equal finite floating-point numbers 6379 nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``. 6380 6381The metadata node shall consist of a single positive float type number 6382representing the maximum relative error, for example: 6383 6384.. code-block:: llvm 6385 6386 !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs 6387 6388.. _range-metadata: 6389 6390'``range``' Metadata 6391^^^^^^^^^^^^^^^^^^^^ 6392 6393``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of 6394integer types. It expresses the possible ranges the loaded value or the value 6395returned by the called function at this call site is in. If the loaded or 6396returned value is not in the specified range, a poison value is returned 6397instead. The ranges are represented with a flattened list of integers. The 6398loaded value or the value returned is known to be in the union of the ranges 6399defined by each consecutive pair. Each pair has the following properties: 6400 6401- The type must match the type loaded by the instruction. 6402- The pair ``a,b`` represents the range ``[a,b)``. 6403- Both ``a`` and ``b`` are constants. 6404- The range is allowed to wrap. 6405- The range should not represent the full or empty set. That is, 6406 ``a!=b``. 6407 6408In addition, the pairs must be in signed order of the lower bound and 6409they must be non-contiguous. 6410 6411Examples: 6412 6413.. code-block:: llvm 6414 6415 %a = load i8, ptr %x, align 1, !range !0 ; Can only be 0 or 1 6416 %b = load i8, ptr %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1 6417 %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5 6418 %d = invoke i8 @bar() to label %cont 6419 unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5 6420 ... 6421 !0 = !{ i8 0, i8 2 } 6422 !1 = !{ i8 255, i8 2 } 6423 !2 = !{ i8 0, i8 2, i8 3, i8 6 } 6424 !3 = !{ i8 -2, i8 0, i8 3, i8 6 } 6425 6426'``absolute_symbol``' Metadata 6427^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6428 6429``absolute_symbol`` metadata may be attached to a global variable 6430declaration. It marks the declaration as a reference to an absolute symbol, 6431which causes the backend to use absolute relocations for the symbol even 6432in position independent code, and expresses the possible ranges that the 6433global variable's *address* (not its value) is in, in the same format as 6434``range`` metadata, with the extension that the pair ``all-ones,all-ones`` 6435may be used to represent the full set. 6436 6437Example (assuming 64-bit pointers): 6438 6439.. code-block:: llvm 6440 6441 @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256) 6442 @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64) 6443 6444 ... 6445 !0 = !{ i64 0, i64 256 } 6446 !1 = !{ i64 -1, i64 -1 } 6447 6448'``callees``' Metadata 6449^^^^^^^^^^^^^^^^^^^^^^ 6450 6451``callees`` metadata may be attached to indirect call sites. If ``callees`` 6452metadata is attached to a call site, and any callee is not among the set of 6453functions provided by the metadata, the behavior is undefined. The intent of 6454this metadata is to facilitate optimizations such as indirect-call promotion. 6455For example, in the code below, the call instruction may only target the 6456``add`` or ``sub`` functions: 6457 6458.. code-block:: llvm 6459 6460 %result = call i64 %binop(i64 %x, i64 %y), !callees !0 6461 6462 ... 6463 !0 = !{ptr @add, ptr @sub} 6464 6465'``callback``' Metadata 6466^^^^^^^^^^^^^^^^^^^^^^^ 6467 6468``callback`` metadata may be attached to a function declaration, or definition. 6469(Call sites are excluded only due to the lack of a use case.) For ease of 6470exposition, we'll refer to the function annotated w/ metadata as a broker 6471function. The metadata describes how the arguments of a call to the broker are 6472in turn passed to the callback function specified by the metadata. Thus, the 6473``callback`` metadata provides a partial description of a call site inside the 6474broker function with regards to the arguments of a call to the broker. The only 6475semantic restriction on the broker function itself is that it is not allowed to 6476inspect or modify arguments referenced in the ``callback`` metadata as 6477pass-through to the callback function. 6478 6479The broker is not required to actually invoke the callback function at runtime. 6480However, the assumptions about not inspecting or modifying arguments that would 6481be passed to the specified callback function still hold, even if the callback 6482function is not dynamically invoked. The broker is allowed to invoke the 6483callback function more than once per invocation of the broker. The broker is 6484also allowed to invoke (directly or indirectly) the function passed as a 6485callback through another use. Finally, the broker is also allowed to relay the 6486callback callee invocation to a different thread. 6487 6488The metadata is structured as follows: At the outer level, ``callback`` 6489metadata is a list of ``callback`` encodings. Each encoding starts with a 6490constant ``i64`` which describes the argument position of the callback function 6491in the call to the broker. The following elements, except the last, describe 6492what arguments are passed to the callback function. Each element is again an 6493``i64`` constant identifying the argument of the broker that is passed through, 6494or ``i64 -1`` to indicate an unknown or inspected argument. The order in which 6495they are listed has to be the same in which they are passed to the callback 6496callee. The last element of the encoding is a boolean which specifies how 6497variadic arguments of the broker are handled. If it is true, all variadic 6498arguments of the broker are passed through to the callback function *after* the 6499arguments encoded explicitly before. 6500 6501In the code below, the ``pthread_create`` function is marked as a broker 6502through the ``!callback !1`` metadata. In the example, there is only one 6503callback encoding, namely ``!2``, associated with the broker. This encoding 6504identifies the callback function as the second argument of the broker (``i64 65052``) and the sole argument of the callback function as the third one of the 6506broker function (``i64 3``). 6507 6508.. FIXME why does the llvm-sphinx-docs builder give a highlighting 6509 error if the below is set to highlight as 'llvm', despite that we 6510 have misc.highlighting_failure set? 6511 6512.. code-block:: text 6513 6514 declare !callback !1 dso_local i32 @pthread_create(ptr, ptr, ptr, ptr) 6515 6516 ... 6517 !2 = !{i64 2, i64 3, i1 false} 6518 !1 = !{!2} 6519 6520Another example is shown below. The callback callee is the second argument of 6521the ``__kmpc_fork_call`` function (``i64 2``). The callee is given two unknown 6522values (each identified by a ``i64 -1``) and afterwards all 6523variadic arguments that are passed to the ``__kmpc_fork_call`` call (due to the 6524final ``i1 true``). 6525 6526.. FIXME why does the llvm-sphinx-docs builder give a highlighting 6527 error if the below is set to highlight as 'llvm', despite that we 6528 have misc.highlighting_failure set? 6529 6530.. code-block:: text 6531 6532 declare !callback !0 dso_local void @__kmpc_fork_call(ptr, i32, ptr, ...) 6533 6534 ... 6535 !1 = !{i64 2, i64 -1, i64 -1, i1 true} 6536 !0 = !{!1} 6537 6538'``exclude``' Metadata 6539^^^^^^^^^^^^^^^^^^^^^^ 6540 6541``exclude`` metadata may be attached to a global variable to signify that its 6542section should not be included in the final executable or shared library. This 6543option is only valid for global variables with an explicit section targeting ELF 6544or COFF. This is done using the ``SHF_EXCLUDE`` flag on ELF targets and the 6545``IMAGE_SCN_LNK_REMOVE`` and ``IMAGE_SCN_MEM_DISCARDABLE`` flags for COFF 6546targets. Additionally, this metadata is only used as a flag, so the associated 6547node must be empty. The explicit section should not conflict with any other 6548sections that the user does not want removed after linking. 6549 6550.. code-block:: text 6551 6552 @object = private constant [1 x i8] c"\00", section ".foo" !exclude !0 6553 6554 ... 6555 !0 = !{} 6556 6557'``unpredictable``' Metadata 6558^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6559 6560``unpredictable`` metadata may be attached to any branch or switch 6561instruction. It can be used to express the unpredictability of control 6562flow. Similar to the llvm.expect intrinsic, it may be used to alter 6563optimizations related to compare and branch instructions. The metadata 6564is treated as a boolean value; if it exists, it signals that the branch 6565or switch that it is attached to is completely unpredictable. 6566 6567.. _md_dereferenceable: 6568 6569'``dereferenceable``' Metadata 6570^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6571 6572The existence of the ``!dereferenceable`` metadata on the instruction 6573tells the optimizer that the value loaded is known to be dereferenceable. 6574The number of bytes known to be dereferenceable is specified by the integer 6575value in the metadata node. This is analogous to the ''dereferenceable'' 6576attribute on parameters and return values. 6577 6578.. _md_dereferenceable_or_null: 6579 6580'``dereferenceable_or_null``' Metadata 6581^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6582 6583The existence of the ``!dereferenceable_or_null`` metadata on the 6584instruction tells the optimizer that the value loaded is known to be either 6585dereferenceable or null. 6586The number of bytes known to be dereferenceable is specified by the integer 6587value in the metadata node. This is analogous to the ''dereferenceable_or_null'' 6588attribute on parameters and return values. 6589 6590.. _llvm.loop: 6591 6592'``llvm.loop``' 6593^^^^^^^^^^^^^^^ 6594 6595It is sometimes useful to attach information to loop constructs. Currently, 6596loop metadata is implemented as metadata attached to the branch instruction 6597in the loop latch block. The loop metadata node is a list of 6598other metadata nodes, each representing a property of the loop. Usually, 6599the first item of the property node is a string. For example, the 6600``llvm.loop.unroll.count`` suggests an unroll factor to the loop 6601unroller: 6602 6603.. code-block:: llvm 6604 6605 br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0 6606 ... 6607 !0 = !{!0, !1, !2} 6608 !1 = !{!"llvm.loop.unroll.enable"} 6609 !2 = !{!"llvm.loop.unroll.count", i32 4} 6610 6611For legacy reasons, the first item of a loop metadata node must be a 6612reference to itself. Before the advent of the 'distinct' keyword, this 6613forced the preservation of otherwise identical metadata nodes. Since 6614the loop-metadata node can be attached to multiple nodes, the 'distinct' 6615keyword has become unnecessary. 6616 6617Prior to the property nodes, one or two ``DILocation`` (debug location) 6618nodes can be present in the list. The first, if present, identifies the 6619source-code location where the loop begins. The second, if present, 6620identifies the source-code location where the loop ends. 6621 6622Loop metadata nodes cannot be used as unique identifiers. They are 6623neither persistent for the same loop through transformations nor 6624necessarily unique to just one loop. 6625 6626'``llvm.loop.disable_nonforced``' 6627^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6628 6629This metadata disables all optional loop transformations unless 6630explicitly instructed using other transformation metadata such as 6631``llvm.loop.unroll.enable``. That is, no heuristic will try to determine 6632whether a transformation is profitable. The purpose is to avoid that the 6633loop is transformed to a different loop before an explicitly requested 6634(forced) transformation is applied. For instance, loop fusion can make 6635other transformations impossible. Mandatory loop canonicalizations such 6636as loop rotation are still applied. 6637 6638It is recommended to use this metadata in addition to any llvm.loop.* 6639transformation directive. Also, any loop should have at most one 6640directive applied to it (and a sequence of transformations built using 6641followup-attributes). Otherwise, which transformation will be applied 6642depends on implementation details such as the pass pipeline order. 6643 6644See :ref:`transformation-metadata` for details. 6645 6646'``llvm.loop.vectorize``' and '``llvm.loop.interleave``' 6647^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6648 6649Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are 6650used to control per-loop vectorization and interleaving parameters such as 6651vectorization width and interleave count. These metadata should be used in 6652conjunction with ``llvm.loop`` loop identification metadata. The 6653``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only 6654optimization hints and the optimizer will only interleave and vectorize loops if 6655it believes it is safe to do so. The ``llvm.loop.parallel_accesses`` metadata 6656which contains information about loop-carried memory dependencies can be helpful 6657in determining the safety of these transformations. 6658 6659'``llvm.loop.interleave.count``' Metadata 6660^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6661 6662This metadata suggests an interleave count to the loop interleaver. 6663The first operand is the string ``llvm.loop.interleave.count`` and the 6664second operand is an integer specifying the interleave count. For 6665example: 6666 6667.. code-block:: llvm 6668 6669 !0 = !{!"llvm.loop.interleave.count", i32 4} 6670 6671Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving 6672multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0 6673then the interleave count will be determined automatically. 6674 6675'``llvm.loop.vectorize.enable``' Metadata 6676^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6677 6678This metadata selectively enables or disables vectorization for the loop. The 6679first operand is the string ``llvm.loop.vectorize.enable`` and the second operand 6680is a bit. If the bit operand value is 1 vectorization is enabled. A value of 66810 disables vectorization: 6682 6683.. code-block:: llvm 6684 6685 !0 = !{!"llvm.loop.vectorize.enable", i1 0} 6686 !1 = !{!"llvm.loop.vectorize.enable", i1 1} 6687 6688'``llvm.loop.vectorize.predicate.enable``' Metadata 6689^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6690 6691This metadata selectively enables or disables creating predicated instructions 6692for the loop, which can enable folding of the scalar epilogue loop into the 6693main loop. The first operand is the string 6694``llvm.loop.vectorize.predicate.enable`` and the second operand is a bit. If 6695the bit operand value is 1 vectorization is enabled. A value of 0 disables 6696vectorization: 6697 6698.. code-block:: llvm 6699 6700 !0 = !{!"llvm.loop.vectorize.predicate.enable", i1 0} 6701 !1 = !{!"llvm.loop.vectorize.predicate.enable", i1 1} 6702 6703'``llvm.loop.vectorize.scalable.enable``' Metadata 6704^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6705 6706This metadata selectively enables or disables scalable vectorization for the 6707loop, and only has any effect if vectorization for the loop is already enabled. 6708The first operand is the string ``llvm.loop.vectorize.scalable.enable`` 6709and the second operand is a bit. If the bit operand value is 1 scalable 6710vectorization is enabled, whereas a value of 0 reverts to the default fixed 6711width vectorization: 6712 6713.. code-block:: llvm 6714 6715 !0 = !{!"llvm.loop.vectorize.scalable.enable", i1 0} 6716 !1 = !{!"llvm.loop.vectorize.scalable.enable", i1 1} 6717 6718'``llvm.loop.vectorize.width``' Metadata 6719^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6720 6721This metadata sets the target width of the vectorizer. The first 6722operand is the string ``llvm.loop.vectorize.width`` and the second 6723operand is an integer specifying the width. For example: 6724 6725.. code-block:: llvm 6726 6727 !0 = !{!"llvm.loop.vectorize.width", i32 4} 6728 6729Note that setting ``llvm.loop.vectorize.width`` to 1 disables 6730vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to 67310 or if the loop does not have this metadata the width will be 6732determined automatically. 6733 6734'``llvm.loop.vectorize.followup_vectorized``' Metadata 6735^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6736 6737This metadata defines which loop attributes the vectorized loop will 6738have. See :ref:`transformation-metadata` for details. 6739 6740'``llvm.loop.vectorize.followup_epilogue``' Metadata 6741^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6742 6743This metadata defines which loop attributes the epilogue will have. The 6744epilogue is not vectorized and is executed when either the vectorized 6745loop is not known to preserve semantics (because e.g., it processes two 6746arrays that are found to alias by a runtime check) or for the last 6747iterations that do not fill a complete set of vector lanes. See 6748:ref:`Transformation Metadata <transformation-metadata>` for details. 6749 6750'``llvm.loop.vectorize.followup_all``' Metadata 6751^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6752 6753Attributes in the metadata will be added to both the vectorized and 6754epilogue loop. 6755See :ref:`Transformation Metadata <transformation-metadata>` for details. 6756 6757'``llvm.loop.unroll``' 6758^^^^^^^^^^^^^^^^^^^^^^ 6759 6760Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling 6761optimization hints such as the unroll factor. ``llvm.loop.unroll`` 6762metadata should be used in conjunction with ``llvm.loop`` loop 6763identification metadata. The ``llvm.loop.unroll`` metadata are only 6764optimization hints and the unrolling will only be performed if the 6765optimizer believes it is safe to do so. 6766 6767'``llvm.loop.unroll.count``' Metadata 6768^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6769 6770This metadata suggests an unroll factor to the loop unroller. The 6771first operand is the string ``llvm.loop.unroll.count`` and the second 6772operand is a positive integer specifying the unroll factor. For 6773example: 6774 6775.. code-block:: llvm 6776 6777 !0 = !{!"llvm.loop.unroll.count", i32 4} 6778 6779If the trip count of the loop is less than the unroll count the loop 6780will be partially unrolled. 6781 6782'``llvm.loop.unroll.disable``' Metadata 6783^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6784 6785This metadata disables loop unrolling. The metadata has a single operand 6786which is the string ``llvm.loop.unroll.disable``. For example: 6787 6788.. code-block:: llvm 6789 6790 !0 = !{!"llvm.loop.unroll.disable"} 6791 6792'``llvm.loop.unroll.runtime.disable``' Metadata 6793^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6794 6795This metadata disables runtime loop unrolling. The metadata has a single 6796operand which is the string ``llvm.loop.unroll.runtime.disable``. For example: 6797 6798.. code-block:: llvm 6799 6800 !0 = !{!"llvm.loop.unroll.runtime.disable"} 6801 6802'``llvm.loop.unroll.enable``' Metadata 6803^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6804 6805This metadata suggests that the loop should be fully unrolled if the trip count 6806is known at compile time and partially unrolled if the trip count is not known 6807at compile time. The metadata has a single operand which is the string 6808``llvm.loop.unroll.enable``. For example: 6809 6810.. code-block:: llvm 6811 6812 !0 = !{!"llvm.loop.unroll.enable"} 6813 6814'``llvm.loop.unroll.full``' Metadata 6815^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6816 6817This metadata suggests that the loop should be unrolled fully. The 6818metadata has a single operand which is the string ``llvm.loop.unroll.full``. 6819For example: 6820 6821.. code-block:: llvm 6822 6823 !0 = !{!"llvm.loop.unroll.full"} 6824 6825'``llvm.loop.unroll.followup``' Metadata 6826^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6827 6828This metadata defines which loop attributes the unrolled loop will have. 6829See :ref:`Transformation Metadata <transformation-metadata>` for details. 6830 6831'``llvm.loop.unroll.followup_remainder``' Metadata 6832^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6833 6834This metadata defines which loop attributes the remainder loop after 6835partial/runtime unrolling will have. See 6836:ref:`Transformation Metadata <transformation-metadata>` for details. 6837 6838'``llvm.loop.unroll_and_jam``' 6839^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6840 6841This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata 6842above, but affect the unroll and jam pass. In addition any loop with 6843``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will 6844disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the 6845unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam 6846too.) 6847 6848The metadata for unroll and jam otherwise is the same as for ``unroll``. 6849``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and 6850``llvm.loop.unroll_and_jam.count`` do the same as for unroll. 6851``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints 6852and the normal safety checks will still be performed. 6853 6854'``llvm.loop.unroll_and_jam.count``' Metadata 6855^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6856 6857This metadata suggests an unroll and jam factor to use, similarly to 6858``llvm.loop.unroll.count``. The first operand is the string 6859``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer 6860specifying the unroll factor. For example: 6861 6862.. code-block:: llvm 6863 6864 !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4} 6865 6866If the trip count of the loop is less than the unroll count the loop 6867will be partially unroll and jammed. 6868 6869'``llvm.loop.unroll_and_jam.disable``' Metadata 6870^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6871 6872This metadata disables loop unroll and jamming. The metadata has a single 6873operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example: 6874 6875.. code-block:: llvm 6876 6877 !0 = !{!"llvm.loop.unroll_and_jam.disable"} 6878 6879'``llvm.loop.unroll_and_jam.enable``' Metadata 6880^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6881 6882This metadata suggests that the loop should be fully unroll and jammed if the 6883trip count is known at compile time and partially unrolled if the trip count is 6884not known at compile time. The metadata has a single operand which is the 6885string ``llvm.loop.unroll_and_jam.enable``. For example: 6886 6887.. code-block:: llvm 6888 6889 !0 = !{!"llvm.loop.unroll_and_jam.enable"} 6890 6891'``llvm.loop.unroll_and_jam.followup_outer``' Metadata 6892^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6893 6894This metadata defines which loop attributes the outer unrolled loop will 6895have. See :ref:`Transformation Metadata <transformation-metadata>` for 6896details. 6897 6898'``llvm.loop.unroll_and_jam.followup_inner``' Metadata 6899^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6900 6901This metadata defines which loop attributes the inner jammed loop will 6902have. See :ref:`Transformation Metadata <transformation-metadata>` for 6903details. 6904 6905'``llvm.loop.unroll_and_jam.followup_remainder_outer``' Metadata 6906^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6907 6908This metadata defines which attributes the epilogue of the outer loop 6909will have. This loop is usually unrolled, meaning there is no such 6910loop. This attribute will be ignored in this case. See 6911:ref:`Transformation Metadata <transformation-metadata>` for details. 6912 6913'``llvm.loop.unroll_and_jam.followup_remainder_inner``' Metadata 6914^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6915 6916This metadata defines which attributes the inner loop of the epilogue 6917will have. The outer epilogue will usually be unrolled, meaning there 6918can be multiple inner remainder loops. See 6919:ref:`Transformation Metadata <transformation-metadata>` for details. 6920 6921'``llvm.loop.unroll_and_jam.followup_all``' Metadata 6922^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6923 6924Attributes specified in the metadata is added to all 6925``llvm.loop.unroll_and_jam.*`` loops. See 6926:ref:`Transformation Metadata <transformation-metadata>` for details. 6927 6928'``llvm.loop.licm_versioning.disable``' Metadata 6929^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6930 6931This metadata indicates that the loop should not be versioned for the purpose 6932of enabling loop-invariant code motion (LICM). The metadata has a single operand 6933which is the string ``llvm.loop.licm_versioning.disable``. For example: 6934 6935.. code-block:: llvm 6936 6937 !0 = !{!"llvm.loop.licm_versioning.disable"} 6938 6939'``llvm.loop.distribute.enable``' Metadata 6940^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6941 6942Loop distribution allows splitting a loop into multiple loops. Currently, 6943this is only performed if the entire loop cannot be vectorized due to unsafe 6944memory dependencies. The transformation will attempt to isolate the unsafe 6945dependencies into their own loop. 6946 6947This metadata can be used to selectively enable or disable distribution of the 6948loop. The first operand is the string ``llvm.loop.distribute.enable`` and the 6949second operand is a bit. If the bit operand value is 1 distribution is 6950enabled. A value of 0 disables distribution: 6951 6952.. code-block:: llvm 6953 6954 !0 = !{!"llvm.loop.distribute.enable", i1 0} 6955 !1 = !{!"llvm.loop.distribute.enable", i1 1} 6956 6957This metadata should be used in conjunction with ``llvm.loop`` loop 6958identification metadata. 6959 6960'``llvm.loop.distribute.followup_coincident``' Metadata 6961^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6962 6963This metadata defines which attributes extracted loops with no cyclic 6964dependencies will have (i.e. can be vectorized). See 6965:ref:`Transformation Metadata <transformation-metadata>` for details. 6966 6967'``llvm.loop.distribute.followup_sequential``' Metadata 6968^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6969 6970This metadata defines which attributes the isolated loops with unsafe 6971memory dependencies will have. See 6972:ref:`Transformation Metadata <transformation-metadata>` for details. 6973 6974'``llvm.loop.distribute.followup_fallback``' Metadata 6975^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6976 6977If loop versioning is necessary, this metadata defined the attributes 6978the non-distributed fallback version will have. See 6979:ref:`Transformation Metadata <transformation-metadata>` for details. 6980 6981'``llvm.loop.distribute.followup_all``' Metadata 6982^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6983 6984The attributes in this metadata is added to all followup loops of the 6985loop distribution pass. See 6986:ref:`Transformation Metadata <transformation-metadata>` for details. 6987 6988'``llvm.licm.disable``' Metadata 6989^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6990 6991This metadata indicates that loop-invariant code motion (LICM) should not be 6992performed on this loop. The metadata has a single operand which is the string 6993``llvm.licm.disable``. For example: 6994 6995.. code-block:: llvm 6996 6997 !0 = !{!"llvm.licm.disable"} 6998 6999Note that although it operates per loop it isn't given the llvm.loop prefix 7000as it is not affected by the ``llvm.loop.disable_nonforced`` metadata. 7001 7002'``llvm.access.group``' Metadata 7003^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7004 7005``llvm.access.group`` metadata can be attached to any instruction that 7006potentially accesses memory. It can point to a single distinct metadata 7007node, which we call access group. This node represents all memory access 7008instructions referring to it via ``llvm.access.group``. When an 7009instruction belongs to multiple access groups, it can also point to a 7010list of accesses groups, illustrated by the following example. 7011 7012.. code-block:: llvm 7013 7014 %val = load i32, ptr %arrayidx, !llvm.access.group !0 7015 ... 7016 !0 = !{!1, !2} 7017 !1 = distinct !{} 7018 !2 = distinct !{} 7019 7020It is illegal for the list node to be empty since it might be confused 7021with an access group. 7022 7023The access group metadata node must be 'distinct' to avoid collapsing 7024multiple access groups by content. A access group metadata node must 7025always be empty which can be used to distinguish an access group 7026metadata node from a list of access groups. Being empty avoids the 7027situation that the content must be updated which, because metadata is 7028immutable by design, would required finding and updating all references 7029to the access group node. 7030 7031The access group can be used to refer to a memory access instruction 7032without pointing to it directly (which is not possible in global 7033metadata). Currently, the only metadata making use of it is 7034``llvm.loop.parallel_accesses``. 7035 7036'``llvm.loop.parallel_accesses``' Metadata 7037^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7038 7039The ``llvm.loop.parallel_accesses`` metadata refers to one or more 7040access group metadata nodes (see ``llvm.access.group``). It denotes that 7041no loop-carried memory dependence exist between it and other instructions 7042in the loop with this metadata. 7043 7044Let ``m1`` and ``m2`` be two instructions that both have the 7045``llvm.access.group`` metadata to the access group ``g1``, respectively 7046``g2`` (which might be identical). If a loop contains both access groups 7047in its ``llvm.loop.parallel_accesses`` metadata, then the compiler can 7048assume that there is no dependency between ``m1`` and ``m2`` carried by 7049this loop. Instructions that belong to multiple access groups are 7050considered having this property if at least one of the access groups 7051matches the ``llvm.loop.parallel_accesses`` list. 7052 7053If all memory-accessing instructions in a loop have 7054``llvm.access.group`` metadata that each refer to one of the access 7055groups of a loop's ``llvm.loop.parallel_accesses`` metadata, then the 7056loop has no loop carried memory dependences and is considered to be a 7057parallel loop. 7058 7059Note that if not all memory access instructions belong to an access 7060group referred to by ``llvm.loop.parallel_accesses``, then the loop must 7061not be considered trivially parallel. Additional 7062memory dependence analysis is required to make that determination. As a fail 7063safe mechanism, this causes loops that were originally parallel to be considered 7064sequential (if optimization passes that are unaware of the parallel semantics 7065insert new memory instructions into the loop body). 7066 7067Example of a loop that is considered parallel due to its correct use of 7068both ``llvm.access.group`` and ``llvm.loop.parallel_accesses`` 7069metadata types. 7070 7071.. code-block:: llvm 7072 7073 for.body: 7074 ... 7075 %val0 = load i32, ptr %arrayidx, !llvm.access.group !1 7076 ... 7077 store i32 %val0, ptr %arrayidx1, !llvm.access.group !1 7078 ... 7079 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0 7080 7081 for.end: 7082 ... 7083 !0 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !1}} 7084 !1 = distinct !{} 7085 7086It is also possible to have nested parallel loops: 7087 7088.. code-block:: llvm 7089 7090 outer.for.body: 7091 ... 7092 %val1 = load i32, ptr %arrayidx3, !llvm.access.group !4 7093 ... 7094 br label %inner.for.body 7095 7096 inner.for.body: 7097 ... 7098 %val0 = load i32, ptr %arrayidx1, !llvm.access.group !3 7099 ... 7100 store i32 %val0, ptr %arrayidx2, !llvm.access.group !3 7101 ... 7102 br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1 7103 7104 inner.for.end: 7105 ... 7106 store i32 %val1, ptr %arrayidx4, !llvm.access.group !4 7107 ... 7108 br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2 7109 7110 outer.for.end: ; preds = %for.body 7111 ... 7112 !1 = distinct !{!1, !{!"llvm.loop.parallel_accesses", !3}} ; metadata for the inner loop 7113 !2 = distinct !{!2, !{!"llvm.loop.parallel_accesses", !3, !4}} ; metadata for the outer loop 7114 !3 = distinct !{} ; access group for instructions in the inner loop (which are implicitly contained in outer loop as well) 7115 !4 = distinct !{} ; access group for instructions in the outer, but not the inner loop 7116 7117.. _langref_llvm_loop_mustprogress: 7118 7119'``llvm.loop.mustprogress``' Metadata 7120^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7121 7122The ``llvm.loop.mustprogress`` metadata indicates that this loop is required to 7123terminate, unwind, or interact with the environment in an observable way e.g. 7124via a volatile memory access, I/O, or other synchronization. If such a loop is 7125not found to interact with the environment in an observable way, the loop may 7126be removed. This corresponds to the ``mustprogress`` function attribute. 7127 7128'``irr_loop``' Metadata 7129^^^^^^^^^^^^^^^^^^^^^^^ 7130 7131``irr_loop`` metadata may be attached to the terminator instruction of a basic 7132block that's an irreducible loop header (note that an irreducible loop has more 7133than once header basic blocks.) If ``irr_loop`` metadata is attached to the 7134terminator instruction of a basic block that is not really an irreducible loop 7135header, the behavior is undefined. The intent of this metadata is to improve the 7136accuracy of the block frequency propagation. For example, in the code below, the 7137block ``header0`` may have a loop header weight (relative to the other headers of 7138the irreducible loop) of 100: 7139 7140.. code-block:: llvm 7141 7142 header0: 7143 ... 7144 br i1 %cmp, label %t1, label %t2, !irr_loop !0 7145 7146 ... 7147 !0 = !{"loop_header_weight", i64 100} 7148 7149Irreducible loop header weights are typically based on profile data. 7150 7151.. _md_invariant.group: 7152 7153'``invariant.group``' Metadata 7154^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7155 7156The experimental ``invariant.group`` metadata may be attached to 7157``load``/``store`` instructions referencing a single metadata with no entries. 7158The existence of the ``invariant.group`` metadata on the instruction tells 7159the optimizer that every ``load`` and ``store`` to the same pointer operand 7160can be assumed to load or store the same 7161value (but see the ``llvm.launder.invariant.group`` intrinsic which affects 7162when two pointers are considered the same). Pointers returned by bitcast or 7163getelementptr with only zero indices are considered the same. 7164 7165Examples: 7166 7167.. code-block:: llvm 7168 7169 @unknownPtr = external global i8 7170 ... 7171 %ptr = alloca i8 7172 store i8 42, ptr %ptr, !invariant.group !0 7173 call void @foo(ptr %ptr) 7174 7175 %a = load i8, ptr %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change 7176 call void @foo(ptr %ptr) 7177 7178 %newPtr = call ptr @getPointer(ptr %ptr) 7179 %c = load i8, ptr %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr 7180 7181 %unknownValue = load i8, ptr @unknownPtr 7182 store i8 %unknownValue, ptr %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42 7183 7184 call void @foo(ptr %ptr) 7185 %newPtr2 = call ptr @llvm.launder.invariant.group.p0(ptr %ptr) 7186 %d = load i8, ptr %newPtr2, !invariant.group !0 ; Can't step through launder.invariant.group to get value of %ptr 7187 7188 ... 7189 declare void @foo(ptr) 7190 declare ptr @getPointer(ptr) 7191 declare ptr @llvm.launder.invariant.group.p0(ptr) 7192 7193 !0 = !{} 7194 7195The invariant.group metadata must be dropped when replacing one pointer by 7196another based on aliasing information. This is because invariant.group is tied 7197to the SSA value of the pointer operand. 7198 7199.. code-block:: llvm 7200 7201 %v = load i8, ptr %x, !invariant.group !0 7202 ; if %x mustalias %y then we can replace the above instruction with 7203 %v = load i8, ptr %y 7204 7205Note that this is an experimental feature, which means that its semantics might 7206change in the future. 7207 7208'``type``' Metadata 7209^^^^^^^^^^^^^^^^^^^ 7210 7211See :doc:`TypeMetadata`. 7212 7213'``associated``' Metadata 7214^^^^^^^^^^^^^^^^^^^^^^^^^ 7215 7216The ``associated`` metadata may be attached to a global variable definition with 7217a single argument that references a global object (optionally through an alias). 7218 7219This metadata lowers to the ELF section flag ``SHF_LINK_ORDER`` which prevents 7220discarding of the global variable in linker GC unless the referenced object is 7221also discarded. The linker support for this feature is spotty. For best 7222compatibility, globals carrying this metadata should: 7223 7224- Be in ``@llvm.compiler.used``. 7225- If the referenced global variable is in a comdat, be in the same comdat. 7226 7227``!associated`` can not express many-to-one relationship. A global variable with 7228the metadata should generally not be referenced by a function: the function may 7229be inlined into other functions, leading to more references to the metadata. 7230Ideally we would want to keep metadata alive as long as any inline location is 7231alive, but this many-to-one relationship is not representable. Moreover, if the 7232metadata is retained while the function is discarded, the linker will report an 7233error of a relocation referencing a discarded section. 7234 7235The metadata is often used with an explicit section consisting of valid C 7236identifiers so that the runtime can find the metadata section with 7237linker-defined encapsulation symbols ``__start_<section_name>`` and 7238``__stop_<section_name>``. 7239 7240It does not have any effect on non-ELF targets. 7241 7242Example: 7243 7244.. code-block:: text 7245 7246 $a = comdat any 7247 @a = global i32 1, comdat $a 7248 @b = internal global i32 2, comdat $a, section "abc", !associated !0 7249 !0 = !{ptr @a} 7250 7251 7252'``prof``' Metadata 7253^^^^^^^^^^^^^^^^^^^ 7254 7255The ``prof`` metadata is used to record profile data in the IR. 7256The first operand of the metadata node indicates the profile metadata 7257type. There are currently 3 types: 7258:ref:`branch_weights<prof_node_branch_weights>`, 7259:ref:`function_entry_count<prof_node_function_entry_count>`, and 7260:ref:`VP<prof_node_VP>`. 7261 7262.. _prof_node_branch_weights: 7263 7264branch_weights 7265"""""""""""""" 7266 7267Branch weight metadata attached to a branch, select, switch or call instruction 7268represents the likeliness of the associated branch being taken. 7269For more information, see :doc:`BranchWeightMetadata`. 7270 7271.. _prof_node_function_entry_count: 7272 7273function_entry_count 7274"""""""""""""""""""" 7275 7276Function entry count metadata can be attached to function definitions 7277to record the number of times the function is called. Used with BFI 7278information, it is also used to derive the basic block profile count. 7279For more information, see :doc:`BranchWeightMetadata`. 7280 7281.. _prof_node_VP: 7282 7283VP 7284"" 7285 7286VP (value profile) metadata can be attached to instructions that have 7287value profile information. Currently this is indirect calls (where it 7288records the hottest callees) and calls to memory intrinsics such as memcpy, 7289memmove, and memset (where it records the hottest byte lengths). 7290 7291Each VP metadata node contains "VP" string, then a uint32_t value for the value 7292profiling kind, a uint64_t value for the total number of times the instruction 7293is executed, followed by uint64_t value and execution count pairs. 7294The value profiling kind is 0 for indirect call targets and 1 for memory 7295operations. For indirect call targets, each profile value is a hash 7296of the callee function name, and for memory operations each value is the 7297byte length. 7298 7299Note that the value counts do not need to add up to the total count 7300listed in the third operand (in practice only the top hottest values 7301are tracked and reported). 7302 7303Indirect call example: 7304 7305.. code-block:: llvm 7306 7307 call void %f(), !prof !1 7308 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410} 7309 7310Note that the VP type is 0 (the second operand), which indicates this is 7311an indirect call value profile data. The third operand indicates that the 7312indirect call executed 1600 times. The 4th and 6th operands give the 7313hashes of the 2 hottest target functions' names (this is the same hash used 7314to represent function names in the profile database), and the 5th and 7th 7315operands give the execution count that each of the respective prior target 7316functions was called. 7317 7318.. _md_annotation: 7319 7320'``annotation``' Metadata 7321^^^^^^^^^^^^^^^^^^^^^^^^^ 7322 7323The ``annotation`` metadata can be used to attach a tuple of annotation strings 7324to any instruction. This metadata does not impact the semantics of the program 7325and may only be used to provide additional insight about the program and 7326transformations to users. 7327 7328Example: 7329 7330.. code-block:: text 7331 7332 %a.addr = alloca ptr, align 8, !annotation !0 7333 !0 = !{!"auto-init"} 7334 7335'``func_sanitize``' Metadata 7336^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7337 7338The ``func_sanitize`` metadata is used to attach two values for the function 7339sanitizer instrumentation. The first value is the ubsan function signature. 7340The second value is the address of the proxy variable which stores the address 7341of the RTTI descriptor. If :ref:`prologue <prologuedata>` and '``func_sanitize``' 7342are used at the same time, :ref:`prologue <prologuedata>` is emitted before 7343'``func_sanitize``' in the output. 7344 7345Example: 7346 7347.. code-block:: text 7348 7349 @__llvm_rtti_proxy = private unnamed_addr constant ptr @_ZTIFvvE 7350 define void @_Z3funv() !func_sanitize !0 { 7351 return void 7352 } 7353 !0 = !{i32 846595819, ptr @__llvm_rtti_proxy} 7354 7355.. _md_kcfi_type: 7356 7357'``kcfi_type``' Metadata 7358^^^^^^^^^^^^^^^^^^^^^^^^ 7359 7360The ``kcfi_type`` metadata can be used to attach a type identifier to 7361functions that can be called indirectly. The type data is emitted before the 7362function entry in the assembly. Indirect calls with the :ref:`kcfi operand 7363bundle<ob_kcfi>` will emit a check that compares the type identifier to the 7364metadata. 7365 7366Example: 7367 7368.. code-block:: text 7369 7370 define dso_local i32 @f() !kcfi_type !0 { 7371 ret i32 0 7372 } 7373 !0 = !{i32 12345678} 7374 7375Clang emits ``kcfi_type`` metadata nodes for address-taken functions with 7376``-fsanitize=kcfi``. 7377 7378Module Flags Metadata 7379===================== 7380 7381Information about the module as a whole is difficult to convey to LLVM's 7382subsystems. The LLVM IR isn't sufficient to transmit this information. 7383The ``llvm.module.flags`` named metadata exists in order to facilitate 7384this. These flags are in the form of key / value pairs --- much like a 7385dictionary --- making it easy for any subsystem who cares about a flag to 7386look it up. 7387 7388The ``llvm.module.flags`` metadata contains a list of metadata triplets. 7389Each triplet has the following form: 7390 7391- The first element is a *behavior* flag, which specifies the behavior 7392 when two (or more) modules are merged together, and it encounters two 7393 (or more) metadata with the same ID. The supported behaviors are 7394 described below. 7395- The second element is a metadata string that is a unique ID for the 7396 metadata. Each module may only have one flag entry for each unique ID (not 7397 including entries with the **Require** behavior). 7398- The third element is the value of the flag. 7399 7400When two (or more) modules are merged together, the resulting 7401``llvm.module.flags`` metadata is the union of the modules' flags. That is, for 7402each unique metadata ID string, there will be exactly one entry in the merged 7403modules ``llvm.module.flags`` metadata table, and the value for that entry will 7404be determined by the merge behavior flag, as described below. The only exception 7405is that entries with the *Require* behavior are always preserved. 7406 7407The following behaviors are supported: 7408 7409.. list-table:: 7410 :header-rows: 1 7411 :widths: 10 90 7412 7413 * - Value 7414 - Behavior 7415 7416 * - 1 7417 - **Error** 7418 Emits an error if two values disagree, otherwise the resulting value 7419 is that of the operands. 7420 7421 * - 2 7422 - **Warning** 7423 Emits a warning if two values disagree. The result value will be the 7424 operand for the flag from the first module being linked, or the max 7425 if the other module uses **Max** (in which case the resulting flag 7426 will be **Max**). 7427 7428 * - 3 7429 - **Require** 7430 Adds a requirement that another module flag be present and have a 7431 specified value after linking is performed. The value must be a 7432 metadata pair, where the first element of the pair is the ID of the 7433 module flag to be restricted, and the second element of the pair is 7434 the value the module flag should be restricted to. This behavior can 7435 be used to restrict the allowable results (via triggering of an 7436 error) of linking IDs with the **Override** behavior. 7437 7438 * - 4 7439 - **Override** 7440 Uses the specified value, regardless of the behavior or value of the 7441 other module. If both modules specify **Override**, but the values 7442 differ, an error will be emitted. 7443 7444 * - 5 7445 - **Append** 7446 Appends the two values, which are required to be metadata nodes. 7447 7448 * - 6 7449 - **AppendUnique** 7450 Appends the two values, which are required to be metadata 7451 nodes. However, duplicate entries in the second list are dropped 7452 during the append operation. 7453 7454 * - 7 7455 - **Max** 7456 Takes the max of the two values, which are required to be integers. 7457 7458 * - 8 7459 - **Min** 7460 Takes the min of the two values, which are required to be non-negative integers. 7461 An absent module flag is treated as having the value 0. 7462 7463It is an error for a particular unique flag ID to have multiple behaviors, 7464except in the case of **Require** (which adds restrictions on another metadata 7465value) or **Override**. 7466 7467An example of module flags: 7468 7469.. code-block:: llvm 7470 7471 !0 = !{ i32 1, !"foo", i32 1 } 7472 !1 = !{ i32 4, !"bar", i32 37 } 7473 !2 = !{ i32 2, !"qux", i32 42 } 7474 !3 = !{ i32 3, !"qux", 7475 !{ 7476 !"foo", i32 1 7477 } 7478 } 7479 !llvm.module.flags = !{ !0, !1, !2, !3 } 7480 7481- Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior 7482 if two or more ``!"foo"`` flags are seen is to emit an error if their 7483 values are not equal. 7484 7485- Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The 7486 behavior if two or more ``!"bar"`` flags are seen is to use the value 7487 '37'. 7488 7489- Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The 7490 behavior if two or more ``!"qux"`` flags are seen is to emit a 7491 warning if their values are not equal. 7492 7493- Metadata ``!3`` has the ID ``!"qux"`` and the value: 7494 7495 :: 7496 7497 !{ !"foo", i32 1 } 7498 7499 The behavior is to emit an error if the ``llvm.module.flags`` does not 7500 contain a flag with the ID ``!"foo"`` that has the value '1' after linking is 7501 performed. 7502 7503Synthesized Functions Module Flags Metadata 7504------------------------------------------- 7505 7506These metadata specify the default attributes synthesized functions should have. 7507These metadata are currently respected by a few instrumentation passes, such as 7508sanitizers. 7509 7510These metadata correspond to a few function attributes with significant code 7511generation behaviors. Function attributes with just optimization purposes 7512should not be listed because the performance impact of these synthesized 7513functions is small. 7514 7515- "frame-pointer": **Max**. The value can be 0, 1, or 2. A synthesized function 7516 will get the "frame-pointer" function attribute, with value being "none", 7517 "non-leaf", or "all", respectively. 7518- "function_return_thunk_extern": The synthesized function will get the 7519 ``fn_return_thunk_extern`` function attribute. 7520- "uwtable": **Max**. The value can be 0, 1, or 2. If the value is 1, a synthesized 7521 function will get the ``uwtable(sync)`` function attribute, if the value is 2, 7522 a synthesized function will get the ``uwtable(async)`` function attribute. 7523 7524Objective-C Garbage Collection Module Flags Metadata 7525---------------------------------------------------- 7526 7527On the Mach-O platform, Objective-C stores metadata about garbage 7528collection in a special section called "image info". The metadata 7529consists of a version number and a bitmask specifying what types of 7530garbage collection are supported (if any) by the file. If two or more 7531modules are linked together their garbage collection metadata needs to 7532be merged rather than appended together. 7533 7534The Objective-C garbage collection module flags metadata consists of the 7535following key-value pairs: 7536 7537.. list-table:: 7538 :header-rows: 1 7539 :widths: 30 70 7540 7541 * - Key 7542 - Value 7543 7544 * - ``Objective-C Version`` 7545 - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2. 7546 7547 * - ``Objective-C Image Info Version`` 7548 - **[Required]** --- The version of the image info section. Currently 7549 always 0. 7550 7551 * - ``Objective-C Image Info Section`` 7552 - **[Required]** --- The section to place the metadata. Valid values are 7553 ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and 7554 ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for 7555 Objective-C ABI version 2. 7556 7557 * - ``Objective-C Garbage Collection`` 7558 - **[Required]** --- Specifies whether garbage collection is supported or 7559 not. Valid values are 0, for no garbage collection, and 2, for garbage 7560 collection supported. 7561 7562 * - ``Objective-C GC Only`` 7563 - **[Optional]** --- Specifies that only garbage collection is supported. 7564 If present, its value must be 6. This flag requires that the 7565 ``Objective-C Garbage Collection`` flag have the value 2. 7566 7567Some important flag interactions: 7568 7569- If a module with ``Objective-C Garbage Collection`` set to 0 is 7570 merged with a module with ``Objective-C Garbage Collection`` set to 7571 2, then the resulting module has the 7572 ``Objective-C Garbage Collection`` flag set to 0. 7573- A module with ``Objective-C Garbage Collection`` set to 0 cannot be 7574 merged with a module with ``Objective-C GC Only`` set to 6. 7575 7576C type width Module Flags Metadata 7577---------------------------------- 7578 7579The ARM backend emits a section into each generated object file describing the 7580options that it was compiled with (in a compiler-independent way) to prevent 7581linking incompatible objects, and to allow automatic library selection. Some 7582of these options are not visible at the IR level, namely wchar_t width and enum 7583width. 7584 7585To pass this information to the backend, these options are encoded in module 7586flags metadata, using the following key-value pairs: 7587 7588.. list-table:: 7589 :header-rows: 1 7590 :widths: 30 70 7591 7592 * - Key 7593 - Value 7594 7595 * - short_wchar 7596 - * 0 --- sizeof(wchar_t) == 4 7597 * 1 --- sizeof(wchar_t) == 2 7598 7599 * - short_enum 7600 - * 0 --- Enums are at least as large as an ``int``. 7601 * 1 --- Enums are stored in the smallest integer type which can 7602 represent all of its values. 7603 7604For example, the following metadata section specifies that the module was 7605compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an 7606enum is the smallest type which can represent all of its values:: 7607 7608 !llvm.module.flags = !{!0, !1} 7609 !0 = !{i32 1, !"short_wchar", i32 1} 7610 !1 = !{i32 1, !"short_enum", i32 0} 7611 7612LTO Post-Link Module Flags Metadata 7613----------------------------------- 7614 7615Some optimisations are only when the entire LTO unit is present in the current 7616module. This is represented by the ``LTOPostLink`` module flags metadata, which 7617will be created with a value of ``1`` when LTO linking occurs. 7618 7619Embedded Objects Names Metadata 7620=============================== 7621 7622Offloading compilations need to embed device code into the host section table to 7623create a fat binary. This metadata node references each global that will be 7624embedded in the module. The primary use for this is to make referencing these 7625globals more efficient in the IR. The metadata references nodes containing 7626pointers to the global to be embedded followed by the section name it will be 7627stored at:: 7628 7629 !llvm.embedded.objects = !{!0} 7630 !0 = !{ptr @object, !".section"} 7631 7632Automatic Linker Flags Named Metadata 7633===================================== 7634 7635Some targets support embedding of flags to the linker inside individual object 7636files. Typically this is used in conjunction with language extensions which 7637allow source files to contain linker command line options, and have these 7638automatically be transmitted to the linker via object files. 7639 7640These flags are encoded in the IR using named metadata with the name 7641``!llvm.linker.options``. Each operand is expected to be a metadata node 7642which should be a list of other metadata nodes, each of which should be a 7643list of metadata strings defining linker options. 7644 7645For example, the following metadata section specifies two separate sets of 7646linker options, presumably to link against ``libz`` and the ``Cocoa`` 7647framework:: 7648 7649 !0 = !{ !"-lz" } 7650 !1 = !{ !"-framework", !"Cocoa" } 7651 !llvm.linker.options = !{ !0, !1 } 7652 7653The metadata encoding as lists of lists of options, as opposed to a collapsed 7654list of options, is chosen so that the IR encoding can use multiple option 7655strings to specify e.g., a single library, while still having that specifier be 7656preserved as an atomic element that can be recognized by a target specific 7657assembly writer or object file emitter. 7658 7659Each individual option is required to be either a valid option for the target's 7660linker, or an option that is reserved by the target specific assembly writer or 7661object file emitter. No other aspect of these options is defined by the IR. 7662 7663Dependent Libs Named Metadata 7664============================= 7665 7666Some targets support embedding of strings into object files to indicate 7667a set of libraries to add to the link. Typically this is used in conjunction 7668with language extensions which allow source files to explicitly declare the 7669libraries they depend on, and have these automatically be transmitted to the 7670linker via object files. 7671 7672The list is encoded in the IR using named metadata with the name 7673``!llvm.dependent-libraries``. Each operand is expected to be a metadata node 7674which should contain a single string operand. 7675 7676For example, the following metadata section contains two library specifiers:: 7677 7678 !0 = !{!"a library specifier"} 7679 !1 = !{!"another library specifier"} 7680 !llvm.dependent-libraries = !{ !0, !1 } 7681 7682Each library specifier will be handled independently by the consuming linker. 7683The effect of the library specifiers are defined by the consuming linker. 7684 7685.. _summary: 7686 7687ThinLTO Summary 7688=============== 7689 7690Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_ 7691causes the building of a compact summary of the module that is emitted into 7692the bitcode. The summary is emitted into the LLVM assembly and identified 7693in syntax by a caret ('``^``'). 7694 7695The summary is parsed into a bitcode output, along with the Module 7696IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes 7697of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the 7698summary entries (just as they currently ignore summary entries in a bitcode 7699input file). 7700 7701Eventually, the summary will be parsed into a ModuleSummaryIndex object under 7702the same conditions where summary index is currently built from bitcode. 7703Specifically, tools that test the Thin Link portion of a ThinLTO compile 7704(i.e. llvm-lto and llvm-lto2), or when parsing a combined index 7705for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag 7706(this part is not yet implemented, use llvm-as to create a bitcode object 7707before feeding into thin link tools for now). 7708 7709There are currently 3 types of summary entries in the LLVM assembly: 7710:ref:`module paths<module_path_summary>`, 7711:ref:`global values<gv_summary>`, and 7712:ref:`type identifiers<typeid_summary>`. 7713 7714.. _module_path_summary: 7715 7716Module Path Summary Entry 7717------------------------- 7718 7719Each module path summary entry lists a module containing global values included 7720in the summary. For a single IR module there will be one such entry, but 7721in a combined summary index produced during the thin link, there will be 7722one module path entry per linked module with summary. 7723 7724Example: 7725 7726.. code-block:: text 7727 7728 ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418)) 7729 7730The ``path`` field is a string path to the bitcode file, and the ``hash`` 7731field is the 160-bit SHA-1 hash of the IR bitcode contents, used for 7732incremental builds and caching. 7733 7734.. _gv_summary: 7735 7736Global Value Summary Entry 7737-------------------------- 7738 7739Each global value summary entry corresponds to a global value defined or 7740referenced by a summarized module. 7741 7742Example: 7743 7744.. code-block:: text 7745 7746 ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831 7747 7748For declarations, there will not be a summary list. For definitions, a 7749global value will contain a list of summaries, one per module containing 7750a definition. There can be multiple entries in a combined summary index 7751for symbols with weak linkage. 7752 7753Each ``Summary`` format will depend on whether the global value is a 7754:ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or 7755:ref:`alias<alias_summary>`. 7756 7757.. _function_summary: 7758 7759Function Summary 7760^^^^^^^^^^^^^^^^ 7761 7762If the global value is a function, the ``Summary`` entry will look like: 7763 7764.. code-block:: text 7765 7766 function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Params]?[, Refs]? 7767 7768The ``module`` field includes the summary entry id for the module containing 7769this definition, and the ``flags`` field contains information such as 7770the linkage type, a flag indicating whether it is legal to import the 7771definition, whether it is globally live and whether the linker resolved it 7772to a local definition (the latter two are populated during the thin link). 7773The ``insts`` field contains the number of IR instructions in the function. 7774Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`, 7775:ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`, 7776:ref:`Params<params_summary>`, :ref:`Refs<refs_summary>`. 7777 7778.. _variable_summary: 7779 7780Global Variable Summary 7781^^^^^^^^^^^^^^^^^^^^^^^ 7782 7783If the global value is a variable, the ``Summary`` entry will look like: 7784 7785.. code-block:: text 7786 7787 variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]? 7788 7789The variable entry contains a subset of the fields in a 7790:ref:`function summary <function_summary>`, see the descriptions there. 7791 7792.. _alias_summary: 7793 7794Alias Summary 7795^^^^^^^^^^^^^ 7796 7797If the global value is an alias, the ``Summary`` entry will look like: 7798 7799.. code-block:: text 7800 7801 alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2) 7802 7803The ``module`` and ``flags`` fields are as described for a 7804:ref:`function summary <function_summary>`. The ``aliasee`` field 7805contains a reference to the global value summary entry of the aliasee. 7806 7807.. _funcflags_summary: 7808 7809Function Flags 7810^^^^^^^^^^^^^^ 7811 7812The optional ``FuncFlags`` field looks like: 7813 7814.. code-block:: text 7815 7816 funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0, noUnwind: 1, mayThrow: 0, hasUnknownCall: 0) 7817 7818If unspecified, flags are assumed to hold the conservative ``false`` value of 7819``0``. 7820 7821.. _calls_summary: 7822 7823Calls 7824^^^^^ 7825 7826The optional ``Calls`` field looks like: 7827 7828.. code-block:: text 7829 7830 calls: ((Callee)[, (Callee)]*) 7831 7832where each ``Callee`` looks like: 7833 7834.. code-block:: text 7835 7836 callee: ^1[, hotness: None]?[, relbf: 0]? 7837 7838The ``callee`` refers to the summary entry id of the callee. At most one 7839of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``, 7840``Hot``, and ``Critical``), and ``relbf`` (which holds the integer 7841branch frequency relative to the entry frequency, scaled down by 2^8) 7842may be specified. The defaults are ``Unknown`` and ``0``, respectively. 7843 7844.. _params_summary: 7845 7846Params 7847^^^^^^ 7848 7849The optional ``Params`` is used by ``StackSafety`` and looks like: 7850 7851.. code-block:: text 7852 7853 Params: ((Param)[, (Param)]*) 7854 7855where each ``Param`` describes pointer parameter access inside of the 7856function and looks like: 7857 7858.. code-block:: text 7859 7860 param: 4, offset: [0, 5][, calls: ((Callee)[, (Callee)]*)]? 7861 7862where the first ``param`` is the number of the parameter it describes, 7863``offset`` is the inclusive range of offsets from the pointer parameter to bytes 7864which can be accessed by the function. This range does not include accesses by 7865function calls from ``calls`` list. 7866 7867where each ``Callee`` describes how parameter is forwarded into other 7868functions and looks like: 7869 7870.. code-block:: text 7871 7872 callee: ^3, param: 5, offset: [-3, 3] 7873 7874The ``callee`` refers to the summary entry id of the callee, ``param`` is 7875the number of the callee parameter which points into the callers parameter 7876with offset known to be inside of the ``offset`` range. ``calls`` will be 7877consumed and removed by thin link stage to update ``Param::offset`` so it 7878covers all accesses possible by ``calls``. 7879 7880Pointer parameter without corresponding ``Param`` is considered unsafe and we 7881assume that access with any offset is possible. 7882 7883Example: 7884 7885If we have the following function: 7886 7887.. code-block:: text 7888 7889 define i64 @foo(ptr %0, ptr %1, ptr %2, i8 %3) { 7890 store ptr %1, ptr @x 7891 %5 = getelementptr inbounds i8, ptr %2, i64 5 7892 %6 = load i8, ptr %5 7893 %7 = getelementptr inbounds i8, ptr %2, i8 %3 7894 tail call void @bar(i8 %3, ptr %7) 7895 %8 = load i64, ptr %0 7896 ret i64 %8 7897 } 7898 7899We can expect the record like this: 7900 7901.. code-block:: text 7902 7903 params: ((param: 0, offset: [0, 7]),(param: 2, offset: [5, 5], calls: ((callee: ^3, param: 1, offset: [-128, 127])))) 7904 7905The function may access just 8 bytes of the parameter %0 . ``calls`` is empty, 7906so the parameter is either not used for function calls or ``offset`` already 7907covers all accesses from nested function calls. 7908Parameter %1 escapes, so access is unknown. 7909The function itself can access just a single byte of the parameter %2. Additional 7910access is possible inside of the ``@bar`` or ``^3``. The function adds signed 7911offset to the pointer and passes the result as the argument %1 into ``^3``. 7912This record itself does not tell us how ``^3`` will access the parameter. 7913Parameter %3 is not a pointer. 7914 7915.. _refs_summary: 7916 7917Refs 7918^^^^ 7919 7920The optional ``Refs`` field looks like: 7921 7922.. code-block:: text 7923 7924 refs: ((Ref)[, (Ref)]*) 7925 7926where each ``Ref`` contains a reference to the summary id of the referenced 7927value (e.g. ``^1``). 7928 7929.. _typeidinfo_summary: 7930 7931TypeIdInfo 7932^^^^^^^^^^ 7933 7934The optional ``TypeIdInfo`` field, used for 7935`Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, 7936looks like: 7937 7938.. code-block:: text 7939 7940 typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]? 7941 7942These optional fields have the following forms: 7943 7944TypeTests 7945""""""""" 7946 7947.. code-block:: text 7948 7949 typeTests: (TypeIdRef[, TypeIdRef]*) 7950 7951Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>` 7952by summary id or ``GUID``. 7953 7954TypeTestAssumeVCalls 7955"""""""""""""""""""" 7956 7957.. code-block:: text 7958 7959 typeTestAssumeVCalls: (VFuncId[, VFuncId]*) 7960 7961Where each VFuncId has the format: 7962 7963.. code-block:: text 7964 7965 vFuncId: (TypeIdRef, offset: 16) 7966 7967Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>` 7968by summary id or ``GUID`` preceded by a ``guid:`` tag. 7969 7970TypeCheckedLoadVCalls 7971""""""""""""""""""""" 7972 7973.. code-block:: text 7974 7975 typeCheckedLoadVCalls: (VFuncId[, VFuncId]*) 7976 7977Where each VFuncId has the format described for ``TypeTestAssumeVCalls``. 7978 7979TypeTestAssumeConstVCalls 7980""""""""""""""""""""""""" 7981 7982.. code-block:: text 7983 7984 typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*) 7985 7986Where each ConstVCall has the format: 7987 7988.. code-block:: text 7989 7990 (VFuncId, args: (Arg[, Arg]*)) 7991 7992and where each VFuncId has the format described for ``TypeTestAssumeVCalls``, 7993and each Arg is an integer argument number. 7994 7995TypeCheckedLoadConstVCalls 7996"""""""""""""""""""""""""" 7997 7998.. code-block:: text 7999 8000 typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*) 8001 8002Where each ConstVCall has the format described for 8003``TypeTestAssumeConstVCalls``. 8004 8005.. _typeid_summary: 8006 8007Type ID Summary Entry 8008--------------------- 8009 8010Each type id summary entry corresponds to a type identifier resolution 8011which is generated during the LTO link portion of the compile when building 8012with `Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, 8013so these are only present in a combined summary index. 8014 8015Example: 8016 8017.. code-block:: text 8018 8019 ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778 8020 8021The ``typeTestRes`` gives the type test resolution ``kind`` (which may 8022be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and 8023the ``size-1`` bit width. It is followed by optional flags, which default to 0, 8024and an optional WpdResolutions (whole program devirtualization resolution) 8025field that looks like: 8026 8027.. code-block:: text 8028 8029 wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]* 8030 8031where each entry is a mapping from the given byte offset to the whole-program 8032devirtualization resolution WpdRes, that has one of the following formats: 8033 8034.. code-block:: text 8035 8036 wpdRes: (kind: branchFunnel) 8037 wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi") 8038 wpdRes: (kind: indir) 8039 8040Additionally, each wpdRes has an optional ``resByArg`` field, which 8041describes the resolutions for calls with all constant integer arguments: 8042 8043.. code-block:: text 8044 8045 resByArg: (ResByArg[, ResByArg]*) 8046 8047where ResByArg is: 8048 8049.. code-block:: text 8050 8051 args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0]) 8052 8053Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal`` 8054or ``VirtualConstProp``. The ``info`` field is only used if the kind 8055is ``UniformRetVal`` (indicates the uniform return value), or 8056``UniqueRetVal`` (holds the return value associated with the unique vtable 8057(0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does 8058not support the use of absolute symbols to store constants. 8059 8060.. _intrinsicglobalvariables: 8061 8062Intrinsic Global Variables 8063========================== 8064 8065LLVM has a number of "magic" global variables that contain data that 8066affect code generation or other IR semantics. These are documented here. 8067All globals of this sort should have a section specified as 8068"``llvm.metadata``". This section and all globals that start with 8069"``llvm.``" are reserved for use by LLVM. 8070 8071.. _gv_llvmused: 8072 8073The '``llvm.used``' Global Variable 8074----------------------------------- 8075 8076The ``@llvm.used`` global is an array which has 8077:ref:`appending linkage <linkage_appending>`. This array contains a list of 8078pointers to named global variables, functions and aliases which may optionally 8079have a pointer cast formed of bitcast or getelementptr. For example, a legal 8080use of it is: 8081 8082.. code-block:: llvm 8083 8084 @X = global i8 4 8085 @Y = global i32 123 8086 8087 @llvm.used = appending global [2 x ptr] [ 8088 ptr @X, 8089 ptr @Y 8090 ], section "llvm.metadata" 8091 8092If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler, 8093and linker are required to treat the symbol as if there is a reference to the 8094symbol that it cannot see (which is why they have to be named). For example, if 8095a variable has internal linkage and no references other than that from the 8096``@llvm.used`` list, it cannot be deleted. This is commonly used to represent 8097references from inline asms and other things the compiler cannot "see", and 8098corresponds to "``attribute((used))``" in GNU C. 8099 8100On some targets, the code generator must emit a directive to the 8101assembler or object file to prevent the assembler and linker from 8102removing the symbol. 8103 8104.. _gv_llvmcompilerused: 8105 8106The '``llvm.compiler.used``' Global Variable 8107-------------------------------------------- 8108 8109The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used`` 8110directive, except that it only prevents the compiler from touching the 8111symbol. On targets that support it, this allows an intelligent linker to 8112optimize references to the symbol without being impeded as it would be 8113by ``@llvm.used``. 8114 8115This is a rare construct that should only be used in rare circumstances, 8116and should not be exposed to source languages. 8117 8118.. _gv_llvmglobalctors: 8119 8120The '``llvm.global_ctors``' Global Variable 8121------------------------------------------- 8122 8123.. code-block:: llvm 8124 8125 %0 = type { i32, ptr, ptr } 8126 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, ptr @ctor, ptr @data }] 8127 8128The ``@llvm.global_ctors`` array contains a list of constructor 8129functions, priorities, and an associated global or function. 8130The functions referenced by this array will be called in ascending order 8131of priority (i.e. lowest first) when the module is loaded. The order of 8132functions with the same priority is not defined. 8133 8134If the third field is non-null, and points to a global variable 8135or function, the initializer function will only run if the associated 8136data from the current module is not discarded. 8137On ELF the referenced global variable or function must be in a comdat. 8138 8139.. _llvmglobaldtors: 8140 8141The '``llvm.global_dtors``' Global Variable 8142------------------------------------------- 8143 8144.. code-block:: llvm 8145 8146 %0 = type { i32, ptr, ptr } 8147 @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, ptr @dtor, ptr @data }] 8148 8149The ``@llvm.global_dtors`` array contains a list of destructor 8150functions, priorities, and an associated global or function. 8151The functions referenced by this array will be called in descending 8152order of priority (i.e. highest first) when the module is unloaded. The 8153order of functions with the same priority is not defined. 8154 8155If the third field is non-null, and points to a global variable 8156or function, the destructor function will only run if the associated 8157data from the current module is not discarded. 8158On ELF the referenced global variable or function must be in a comdat. 8159 8160Instruction Reference 8161===================== 8162 8163The LLVM instruction set consists of several different classifications 8164of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary 8165instructions <binaryops>`, :ref:`bitwise binary 8166instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and 8167:ref:`other instructions <otherops>`. 8168 8169.. _terminators: 8170 8171Terminator Instructions 8172----------------------- 8173 8174As mentioned :ref:`previously <functionstructure>`, every basic block in a 8175program ends with a "Terminator" instruction, which indicates which 8176block should be executed after the current block is finished. These 8177terminator instructions typically yield a '``void``' value: they produce 8178control flow, not values (the one exception being the 8179':ref:`invoke <i_invoke>`' instruction). 8180 8181The terminator instructions are: ':ref:`ret <i_ret>`', 8182':ref:`br <i_br>`', ':ref:`switch <i_switch>`', 8183':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`', 8184':ref:`callbr <i_callbr>`' 8185':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`', 8186':ref:`catchret <i_catchret>`', 8187':ref:`cleanupret <i_cleanupret>`', 8188and ':ref:`unreachable <i_unreachable>`'. 8189 8190.. _i_ret: 8191 8192'``ret``' Instruction 8193^^^^^^^^^^^^^^^^^^^^^ 8194 8195Syntax: 8196""""""" 8197 8198:: 8199 8200 ret <type> <value> ; Return a value from a non-void function 8201 ret void ; Return from void function 8202 8203Overview: 8204""""""""" 8205 8206The '``ret``' instruction is used to return control flow (and optionally 8207a value) from a function back to the caller. 8208 8209There are two forms of the '``ret``' instruction: one that returns a 8210value and then causes control flow, and one that just causes control 8211flow to occur. 8212 8213Arguments: 8214"""""""""" 8215 8216The '``ret``' instruction optionally accepts a single argument, the 8217return value. The type of the return value must be a ':ref:`first 8218class <t_firstclass>`' type. 8219 8220A function is not :ref:`well formed <wellformed>` if it has a non-void 8221return type and contains a '``ret``' instruction with no return value or 8222a return value with a type that does not match its type, or if it has a 8223void return type and contains a '``ret``' instruction with a return 8224value. 8225 8226Semantics: 8227"""""""""" 8228 8229When the '``ret``' instruction is executed, control flow returns back to 8230the calling function's context. If the caller is a 8231":ref:`call <i_call>`" instruction, execution continues at the 8232instruction after the call. If the caller was an 8233":ref:`invoke <i_invoke>`" instruction, execution continues at the 8234beginning of the "normal" destination block. If the instruction returns 8235a value, that value shall set the call or invoke instruction's return 8236value. 8237 8238Example: 8239"""""""" 8240 8241.. code-block:: llvm 8242 8243 ret i32 5 ; Return an integer value of 5 8244 ret void ; Return from a void function 8245 ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2 8246 8247.. _i_br: 8248 8249'``br``' Instruction 8250^^^^^^^^^^^^^^^^^^^^ 8251 8252Syntax: 8253""""""" 8254 8255:: 8256 8257 br i1 <cond>, label <iftrue>, label <iffalse> 8258 br label <dest> ; Unconditional branch 8259 8260Overview: 8261""""""""" 8262 8263The '``br``' instruction is used to cause control flow to transfer to a 8264different basic block in the current function. There are two forms of 8265this instruction, corresponding to a conditional branch and an 8266unconditional branch. 8267 8268Arguments: 8269"""""""""" 8270 8271The conditional branch form of the '``br``' instruction takes a single 8272'``i1``' value and two '``label``' values. The unconditional form of the 8273'``br``' instruction takes a single '``label``' value as a target. 8274 8275Semantics: 8276"""""""""" 8277 8278Upon execution of a conditional '``br``' instruction, the '``i1``' 8279argument is evaluated. If the value is ``true``, control flows to the 8280'``iftrue``' ``label`` argument. If "cond" is ``false``, control flows 8281to the '``iffalse``' ``label`` argument. 8282If '``cond``' is ``poison`` or ``undef``, this instruction has undefined 8283behavior. 8284 8285Example: 8286"""""""" 8287 8288.. code-block:: llvm 8289 8290 Test: 8291 %cond = icmp eq i32 %a, %b 8292 br i1 %cond, label %IfEqual, label %IfUnequal 8293 IfEqual: 8294 ret i32 1 8295 IfUnequal: 8296 ret i32 0 8297 8298.. _i_switch: 8299 8300'``switch``' Instruction 8301^^^^^^^^^^^^^^^^^^^^^^^^ 8302 8303Syntax: 8304""""""" 8305 8306:: 8307 8308 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] 8309 8310Overview: 8311""""""""" 8312 8313The '``switch``' instruction is used to transfer control flow to one of 8314several different places. It is a generalization of the '``br``' 8315instruction, allowing a branch to occur to one of many possible 8316destinations. 8317 8318Arguments: 8319"""""""""" 8320 8321The '``switch``' instruction uses three parameters: an integer 8322comparison value '``value``', a default '``label``' destination, and an 8323array of pairs of comparison value constants and '``label``'s. The table 8324is not allowed to contain duplicate constant entries. 8325 8326Semantics: 8327"""""""""" 8328 8329The ``switch`` instruction specifies a table of values and destinations. 8330When the '``switch``' instruction is executed, this table is searched 8331for the given value. If the value is found, control flow is transferred 8332to the corresponding destination; otherwise, control flow is transferred 8333to the default destination. 8334If '``value``' is ``poison`` or ``undef``, this instruction has undefined 8335behavior. 8336 8337Implementation: 8338""""""""""""""" 8339 8340Depending on properties of the target machine and the particular 8341``switch`` instruction, this instruction may be code generated in 8342different ways. For example, it could be generated as a series of 8343chained conditional branches or with a lookup table. 8344 8345Example: 8346"""""""" 8347 8348.. code-block:: llvm 8349 8350 ; Emulate a conditional br instruction 8351 %Val = zext i1 %value to i32 8352 switch i32 %Val, label %truedest [ i32 0, label %falsedest ] 8353 8354 ; Emulate an unconditional br instruction 8355 switch i32 0, label %dest [ ] 8356 8357 ; Implement a jump table: 8358 switch i32 %val, label %otherwise [ i32 0, label %onzero 8359 i32 1, label %onone 8360 i32 2, label %ontwo ] 8361 8362.. _i_indirectbr: 8363 8364'``indirectbr``' Instruction 8365^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8366 8367Syntax: 8368""""""" 8369 8370:: 8371 8372 indirectbr ptr <address>, [ label <dest1>, label <dest2>, ... ] 8373 8374Overview: 8375""""""""" 8376 8377The '``indirectbr``' instruction implements an indirect branch to a 8378label within the current function, whose address is specified by 8379"``address``". Address must be derived from a 8380:ref:`blockaddress <blockaddress>` constant. 8381 8382Arguments: 8383"""""""""" 8384 8385The '``address``' argument is the address of the label to jump to. The 8386rest of the arguments indicate the full set of possible destinations 8387that the address may point to. Blocks are allowed to occur multiple 8388times in the destination list, though this isn't particularly useful. 8389 8390This destination list is required so that dataflow analysis has an 8391accurate understanding of the CFG. 8392 8393Semantics: 8394"""""""""" 8395 8396Control transfers to the block specified in the address argument. All 8397possible destination blocks must be listed in the label list, otherwise 8398this instruction has undefined behavior. This implies that jumps to 8399labels defined in other functions have undefined behavior as well. 8400If '``address``' is ``poison`` or ``undef``, this instruction has undefined 8401behavior. 8402 8403Implementation: 8404""""""""""""""" 8405 8406This is typically implemented with a jump through a register. 8407 8408Example: 8409"""""""" 8410 8411.. code-block:: llvm 8412 8413 indirectbr ptr %Addr, [ label %bb1, label %bb2, label %bb3 ] 8414 8415.. _i_invoke: 8416 8417'``invoke``' Instruction 8418^^^^^^^^^^^^^^^^^^^^^^^^ 8419 8420Syntax: 8421""""""" 8422 8423:: 8424 8425 <result> = invoke [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] 8426 [operand bundles] to label <normal label> unwind label <exception label> 8427 8428Overview: 8429""""""""" 8430 8431The '``invoke``' instruction causes control to transfer to a specified 8432function, with the possibility of control flow transfer to either the 8433'``normal``' label or the '``exception``' label. If the callee function 8434returns with the "``ret``" instruction, control flow will return to the 8435"normal" label. If the callee (or any indirect callees) returns via the 8436":ref:`resume <i_resume>`" instruction or other exception handling 8437mechanism, control is interrupted and continued at the dynamically 8438nearest "exception" label. 8439 8440The '``exception``' label is a `landing 8441pad <ExceptionHandling.html#overview>`_ for the exception. As such, 8442'``exception``' label is required to have the 8443":ref:`landingpad <i_landingpad>`" instruction, which contains the 8444information about the behavior of the program after unwinding happens, 8445as its first non-PHI instruction. The restrictions on the 8446"``landingpad``" instruction's tightly couples it to the "``invoke``" 8447instruction, so that the important information contained within the 8448"``landingpad``" instruction can't be lost through normal code motion. 8449 8450Arguments: 8451"""""""""" 8452 8453This instruction requires several arguments: 8454 8455#. The optional "cconv" marker indicates which :ref:`calling 8456 convention <callingconv>` the call should use. If none is 8457 specified, the call defaults to using C calling conventions. 8458#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 8459 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 8460 are valid here. 8461#. The optional addrspace attribute can be used to indicate the address space 8462 of the called function. If it is not specified, the program address space 8463 from the :ref:`datalayout string<langref_datalayout>` will be used. 8464#. '``ty``': the type of the call instruction itself which is also the 8465 type of the return value. Functions that return no value are marked 8466 ``void``. 8467#. '``fnty``': shall be the signature of the function being invoked. The 8468 argument types must match the types implied by this signature. This 8469 type can be omitted if the function is not varargs. 8470#. '``fnptrval``': An LLVM value containing a pointer to a function to 8471 be invoked. In most cases, this is a direct function invocation, but 8472 indirect ``invoke``'s are just as possible, calling an arbitrary pointer 8473 to function value. 8474#. '``function args``': argument list whose types match the function 8475 signature argument types and parameter attributes. All arguments must 8476 be of :ref:`first class <t_firstclass>` type. If the function signature 8477 indicates the function accepts a variable number of arguments, the 8478 extra arguments can be specified. 8479#. '``normal label``': the label reached when the called function 8480 executes a '``ret``' instruction. 8481#. '``exception label``': the label reached when a callee returns via 8482 the :ref:`resume <i_resume>` instruction or other exception handling 8483 mechanism. 8484#. The optional :ref:`function attributes <fnattrs>` list. 8485#. The optional :ref:`operand bundles <opbundles>` list. 8486 8487Semantics: 8488"""""""""" 8489 8490This instruction is designed to operate as a standard '``call``' 8491instruction in most regards. The primary difference is that it 8492establishes an association with a label, which is used by the runtime 8493library to unwind the stack. 8494 8495This instruction is used in languages with destructors to ensure that 8496proper cleanup is performed in the case of either a ``longjmp`` or a 8497thrown exception. Additionally, this is important for implementation of 8498'``catch``' clauses in high-level languages that support them. 8499 8500For the purposes of the SSA form, the definition of the value returned 8501by the '``invoke``' instruction is deemed to occur on the edge from the 8502current block to the "normal" label. If the callee unwinds then no 8503return value is available. 8504 8505Example: 8506"""""""" 8507 8508.. code-block:: llvm 8509 8510 %retval = invoke i32 @Test(i32 15) to label %Continue 8511 unwind label %TestCleanup ; i32:retval set 8512 %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue 8513 unwind label %TestCleanup ; i32:retval set 8514 8515.. _i_callbr: 8516 8517'``callbr``' Instruction 8518^^^^^^^^^^^^^^^^^^^^^^^^ 8519 8520Syntax: 8521""""""" 8522 8523:: 8524 8525 <result> = callbr [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] 8526 [operand bundles] to label <fallthrough label> [indirect labels] 8527 8528Overview: 8529""""""""" 8530 8531The '``callbr``' instruction causes control to transfer to a specified 8532function, with the possibility of control flow transfer to either the 8533'``fallthrough``' label or one of the '``indirect``' labels. 8534 8535This instruction should only be used to implement the "goto" feature of gcc 8536style inline assembly. Any other usage is an error in the IR verifier. 8537 8538Arguments: 8539"""""""""" 8540 8541This instruction requires several arguments: 8542 8543#. The optional "cconv" marker indicates which :ref:`calling 8544 convention <callingconv>` the call should use. If none is 8545 specified, the call defaults to using C calling conventions. 8546#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 8547 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 8548 are valid here. 8549#. The optional addrspace attribute can be used to indicate the address space 8550 of the called function. If it is not specified, the program address space 8551 from the :ref:`datalayout string<langref_datalayout>` will be used. 8552#. '``ty``': the type of the call instruction itself which is also the 8553 type of the return value. Functions that return no value are marked 8554 ``void``. 8555#. '``fnty``': shall be the signature of the function being called. The 8556 argument types must match the types implied by this signature. This 8557 type can be omitted if the function is not varargs. 8558#. '``fnptrval``': An LLVM value containing a pointer to a function to 8559 be called. In most cases, this is a direct function call, but 8560 other ``callbr``'s are just as possible, calling an arbitrary pointer 8561 to function value. 8562#. '``function args``': argument list whose types match the function 8563 signature argument types and parameter attributes. All arguments must 8564 be of :ref:`first class <t_firstclass>` type. If the function signature 8565 indicates the function accepts a variable number of arguments, the 8566 extra arguments can be specified. 8567#. '``fallthrough label``': the label reached when the inline assembly's 8568 execution exits the bottom. 8569#. '``indirect labels``': the labels reached when a callee transfers control 8570 to a location other than the '``fallthrough label``'. Label constraints 8571 refer to these destinations. 8572#. The optional :ref:`function attributes <fnattrs>` list. 8573#. The optional :ref:`operand bundles <opbundles>` list. 8574 8575Semantics: 8576"""""""""" 8577 8578This instruction is designed to operate as a standard '``call``' 8579instruction in most regards. The primary difference is that it 8580establishes an association with additional labels to define where control 8581flow goes after the call. 8582 8583The output values of a '``callbr``' instruction are available only to 8584the '``fallthrough``' block, not to any '``indirect``' blocks(s). 8585 8586The only use of this today is to implement the "goto" feature of gcc inline 8587assembly where additional labels can be provided as locations for the inline 8588assembly to jump to. 8589 8590Example: 8591"""""""" 8592 8593.. code-block:: llvm 8594 8595 ; "asm goto" without output constraints. 8596 callbr void asm "", "r,!i"(i32 %x) 8597 to label %fallthrough [label %indirect] 8598 8599 ; "asm goto" with output constraints. 8600 <result> = callbr i32 asm "", "=r,r,!i"(i32 %x) 8601 to label %fallthrough [label %indirect] 8602 8603.. _i_resume: 8604 8605'``resume``' Instruction 8606^^^^^^^^^^^^^^^^^^^^^^^^ 8607 8608Syntax: 8609""""""" 8610 8611:: 8612 8613 resume <type> <value> 8614 8615Overview: 8616""""""""" 8617 8618The '``resume``' instruction is a terminator instruction that has no 8619successors. 8620 8621Arguments: 8622"""""""""" 8623 8624The '``resume``' instruction requires one argument, which must have the 8625same type as the result of any '``landingpad``' instruction in the same 8626function. 8627 8628Semantics: 8629"""""""""" 8630 8631The '``resume``' instruction resumes propagation of an existing 8632(in-flight) exception whose unwinding was interrupted with a 8633:ref:`landingpad <i_landingpad>` instruction. 8634 8635Example: 8636"""""""" 8637 8638.. code-block:: llvm 8639 8640 resume { ptr, i32 } %exn 8641 8642.. _i_catchswitch: 8643 8644'``catchswitch``' Instruction 8645^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8646 8647Syntax: 8648""""""" 8649 8650:: 8651 8652 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller 8653 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default> 8654 8655Overview: 8656""""""""" 8657 8658The '``catchswitch``' instruction is used by `LLVM's exception handling system 8659<ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers 8660that may be executed by the :ref:`EH personality routine <personalityfn>`. 8661 8662Arguments: 8663"""""""""" 8664 8665The ``parent`` argument is the token of the funclet that contains the 8666``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet, 8667this operand may be the token ``none``. 8668 8669The ``default`` argument is the label of another basic block beginning with 8670either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination 8671must be a legal target with respect to the ``parent`` links, as described in 8672the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_. 8673 8674The ``handlers`` are a nonempty list of successor blocks that each begin with a 8675:ref:`catchpad <i_catchpad>` instruction. 8676 8677Semantics: 8678"""""""""" 8679 8680Executing this instruction transfers control to one of the successors in 8681``handlers``, if appropriate, or continues to unwind via the unwind label if 8682present. 8683 8684The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that 8685it must be both the first non-phi instruction and last instruction in the basic 8686block. Therefore, it must be the only non-phi instruction in the block. 8687 8688Example: 8689"""""""" 8690 8691.. code-block:: text 8692 8693 dispatch1: 8694 %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller 8695 dispatch2: 8696 %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup 8697 8698.. _i_catchret: 8699 8700'``catchret``' Instruction 8701^^^^^^^^^^^^^^^^^^^^^^^^^^ 8702 8703Syntax: 8704""""""" 8705 8706:: 8707 8708 catchret from <token> to label <normal> 8709 8710Overview: 8711""""""""" 8712 8713The '``catchret``' instruction is a terminator instruction that has a 8714single successor. 8715 8716 8717Arguments: 8718"""""""""" 8719 8720The first argument to a '``catchret``' indicates which ``catchpad`` it 8721exits. It must be a :ref:`catchpad <i_catchpad>`. 8722The second argument to a '``catchret``' specifies where control will 8723transfer to next. 8724 8725Semantics: 8726"""""""""" 8727 8728The '``catchret``' instruction ends an existing (in-flight) exception whose 8729unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The 8730:ref:`personality function <personalityfn>` gets a chance to execute arbitrary 8731code to, for example, destroy the active exception. Control then transfers to 8732``normal``. 8733 8734The ``token`` argument must be a token produced by a ``catchpad`` instruction. 8735If the specified ``catchpad`` is not the most-recently-entered not-yet-exited 8736funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 8737the ``catchret``'s behavior is undefined. 8738 8739Example: 8740"""""""" 8741 8742.. code-block:: text 8743 8744 catchret from %catch to label %continue 8745 8746.. _i_cleanupret: 8747 8748'``cleanupret``' Instruction 8749^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8750 8751Syntax: 8752""""""" 8753 8754:: 8755 8756 cleanupret from <value> unwind label <continue> 8757 cleanupret from <value> unwind to caller 8758 8759Overview: 8760""""""""" 8761 8762The '``cleanupret``' instruction is a terminator instruction that has 8763an optional successor. 8764 8765 8766Arguments: 8767"""""""""" 8768 8769The '``cleanupret``' instruction requires one argument, which indicates 8770which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`. 8771If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited 8772funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 8773the ``cleanupret``'s behavior is undefined. 8774 8775The '``cleanupret``' instruction also has an optional successor, ``continue``, 8776which must be the label of another basic block beginning with either a 8777``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must 8778be a legal target with respect to the ``parent`` links, as described in the 8779`exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_. 8780 8781Semantics: 8782"""""""""" 8783 8784The '``cleanupret``' instruction indicates to the 8785:ref:`personality function <personalityfn>` that one 8786:ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended. 8787It transfers control to ``continue`` or unwinds out of the function. 8788 8789Example: 8790"""""""" 8791 8792.. code-block:: text 8793 8794 cleanupret from %cleanup unwind to caller 8795 cleanupret from %cleanup unwind label %continue 8796 8797.. _i_unreachable: 8798 8799'``unreachable``' Instruction 8800^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8801 8802Syntax: 8803""""""" 8804 8805:: 8806 8807 unreachable 8808 8809Overview: 8810""""""""" 8811 8812The '``unreachable``' instruction has no defined semantics. This 8813instruction is used to inform the optimizer that a particular portion of 8814the code is not reachable. This can be used to indicate that the code 8815after a no-return function cannot be reached, and other facts. 8816 8817Semantics: 8818"""""""""" 8819 8820The '``unreachable``' instruction has no defined semantics. 8821 8822.. _unaryops: 8823 8824Unary Operations 8825----------------- 8826 8827Unary operators require a single operand, execute an operation on 8828it, and produce a single value. The operand might represent multiple 8829data, as is the case with the :ref:`vector <t_vector>` data type. The 8830result value has the same type as its operand. 8831 8832.. _i_fneg: 8833 8834'``fneg``' Instruction 8835^^^^^^^^^^^^^^^^^^^^^^ 8836 8837Syntax: 8838""""""" 8839 8840:: 8841 8842 <result> = fneg [fast-math flags]* <ty> <op1> ; yields ty:result 8843 8844Overview: 8845""""""""" 8846 8847The '``fneg``' instruction returns the negation of its operand. 8848 8849Arguments: 8850"""""""""" 8851 8852The argument to the '``fneg``' instruction must be a 8853:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8854floating-point values. 8855 8856Semantics: 8857"""""""""" 8858 8859The value produced is a copy of the operand with its sign bit flipped. 8860This instruction can also take any number of :ref:`fast-math 8861flags <fastmath>`, which are optimization hints to enable otherwise 8862unsafe floating-point optimizations: 8863 8864Example: 8865"""""""" 8866 8867.. code-block:: text 8868 8869 <result> = fneg float %val ; yields float:result = -%var 8870 8871.. _binaryops: 8872 8873Binary Operations 8874----------------- 8875 8876Binary operators are used to do most of the computation in a program. 8877They require two operands of the same type, execute an operation on 8878them, and produce a single value. The operands might represent multiple 8879data, as is the case with the :ref:`vector <t_vector>` data type. The 8880result value has the same type as its operands. 8881 8882There are several different binary operators: 8883 8884.. _i_add: 8885 8886'``add``' Instruction 8887^^^^^^^^^^^^^^^^^^^^^ 8888 8889Syntax: 8890""""""" 8891 8892:: 8893 8894 <result> = add <ty> <op1>, <op2> ; yields ty:result 8895 <result> = add nuw <ty> <op1>, <op2> ; yields ty:result 8896 <result> = add nsw <ty> <op1>, <op2> ; yields ty:result 8897 <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result 8898 8899Overview: 8900""""""""" 8901 8902The '``add``' instruction returns the sum of its two operands. 8903 8904Arguments: 8905"""""""""" 8906 8907The two arguments to the '``add``' instruction must be 8908:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8909arguments must have identical types. 8910 8911Semantics: 8912"""""""""" 8913 8914The value produced is the integer sum of the two operands. 8915 8916If the sum has unsigned overflow, the result returned is the 8917mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of 8918the result. 8919 8920Because LLVM integers use a two's complement representation, this 8921instruction is appropriate for both signed and unsigned integers. 8922 8923``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 8924respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 8925result value of the ``add`` is a :ref:`poison value <poisonvalues>` if 8926unsigned and/or signed overflow, respectively, occurs. 8927 8928Example: 8929"""""""" 8930 8931.. code-block:: text 8932 8933 <result> = add i32 4, %var ; yields i32:result = 4 + %var 8934 8935.. _i_fadd: 8936 8937'``fadd``' Instruction 8938^^^^^^^^^^^^^^^^^^^^^^ 8939 8940Syntax: 8941""""""" 8942 8943:: 8944 8945 <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8946 8947Overview: 8948""""""""" 8949 8950The '``fadd``' instruction returns the sum of its two operands. 8951 8952Arguments: 8953"""""""""" 8954 8955The two arguments to the '``fadd``' instruction must be 8956:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8957floating-point values. Both arguments must have identical types. 8958 8959Semantics: 8960"""""""""" 8961 8962The value produced is the floating-point sum of the two operands. 8963This instruction is assumed to execute in the default :ref:`floating-point 8964environment <floatenv>`. 8965This instruction can also take any number of :ref:`fast-math 8966flags <fastmath>`, which are optimization hints to enable otherwise 8967unsafe floating-point optimizations: 8968 8969Example: 8970"""""""" 8971 8972.. code-block:: text 8973 8974 <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var 8975 8976.. _i_sub: 8977 8978'``sub``' Instruction 8979^^^^^^^^^^^^^^^^^^^^^ 8980 8981Syntax: 8982""""""" 8983 8984:: 8985 8986 <result> = sub <ty> <op1>, <op2> ; yields ty:result 8987 <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result 8988 <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result 8989 <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result 8990 8991Overview: 8992""""""""" 8993 8994The '``sub``' instruction returns the difference of its two operands. 8995 8996Note that the '``sub``' instruction is used to represent the '``neg``' 8997instruction present in most other intermediate representations. 8998 8999Arguments: 9000"""""""""" 9001 9002The two arguments to the '``sub``' instruction must be 9003:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9004arguments must have identical types. 9005 9006Semantics: 9007"""""""""" 9008 9009The value produced is the integer difference of the two operands. 9010 9011If the difference has unsigned overflow, the result returned is the 9012mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of 9013the result. 9014 9015Because LLVM integers use a two's complement representation, this 9016instruction is appropriate for both signed and unsigned integers. 9017 9018``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 9019respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 9020result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if 9021unsigned and/or signed overflow, respectively, occurs. 9022 9023Example: 9024"""""""" 9025 9026.. code-block:: text 9027 9028 <result> = sub i32 4, %var ; yields i32:result = 4 - %var 9029 <result> = sub i32 0, %val ; yields i32:result = -%var 9030 9031.. _i_fsub: 9032 9033'``fsub``' Instruction 9034^^^^^^^^^^^^^^^^^^^^^^ 9035 9036Syntax: 9037""""""" 9038 9039:: 9040 9041 <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 9042 9043Overview: 9044""""""""" 9045 9046The '``fsub``' instruction returns the difference of its two operands. 9047 9048Arguments: 9049"""""""""" 9050 9051The two arguments to the '``fsub``' instruction must be 9052:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 9053floating-point values. Both arguments must have identical types. 9054 9055Semantics: 9056"""""""""" 9057 9058The value produced is the floating-point difference of the two operands. 9059This instruction is assumed to execute in the default :ref:`floating-point 9060environment <floatenv>`. 9061This instruction can also take any number of :ref:`fast-math 9062flags <fastmath>`, which are optimization hints to enable otherwise 9063unsafe floating-point optimizations: 9064 9065Example: 9066"""""""" 9067 9068.. code-block:: text 9069 9070 <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var 9071 <result> = fsub float -0.0, %val ; yields float:result = -%var 9072 9073.. _i_mul: 9074 9075'``mul``' Instruction 9076^^^^^^^^^^^^^^^^^^^^^ 9077 9078Syntax: 9079""""""" 9080 9081:: 9082 9083 <result> = mul <ty> <op1>, <op2> ; yields ty:result 9084 <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result 9085 <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result 9086 <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result 9087 9088Overview: 9089""""""""" 9090 9091The '``mul``' instruction returns the product of its two operands. 9092 9093Arguments: 9094"""""""""" 9095 9096The two arguments to the '``mul``' instruction must be 9097:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9098arguments must have identical types. 9099 9100Semantics: 9101"""""""""" 9102 9103The value produced is the integer product of the two operands. 9104 9105If the result of the multiplication has unsigned overflow, the result 9106returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the 9107bit width of the result. 9108 9109Because LLVM integers use a two's complement representation, and the 9110result is the same width as the operands, this instruction returns the 9111correct result for both signed and unsigned integers. If a full product 9112(e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be 9113sign-extended or zero-extended as appropriate to the width of the full 9114product. 9115 9116``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 9117respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 9118result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if 9119unsigned and/or signed overflow, respectively, occurs. 9120 9121Example: 9122"""""""" 9123 9124.. code-block:: text 9125 9126 <result> = mul i32 4, %var ; yields i32:result = 4 * %var 9127 9128.. _i_fmul: 9129 9130'``fmul``' Instruction 9131^^^^^^^^^^^^^^^^^^^^^^ 9132 9133Syntax: 9134""""""" 9135 9136:: 9137 9138 <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 9139 9140Overview: 9141""""""""" 9142 9143The '``fmul``' instruction returns the product of its two operands. 9144 9145Arguments: 9146"""""""""" 9147 9148The two arguments to the '``fmul``' instruction must be 9149:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 9150floating-point values. Both arguments must have identical types. 9151 9152Semantics: 9153"""""""""" 9154 9155The value produced is the floating-point product of the two operands. 9156This instruction is assumed to execute in the default :ref:`floating-point 9157environment <floatenv>`. 9158This instruction can also take any number of :ref:`fast-math 9159flags <fastmath>`, which are optimization hints to enable otherwise 9160unsafe floating-point optimizations: 9161 9162Example: 9163"""""""" 9164 9165.. code-block:: text 9166 9167 <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var 9168 9169.. _i_udiv: 9170 9171'``udiv``' Instruction 9172^^^^^^^^^^^^^^^^^^^^^^ 9173 9174Syntax: 9175""""""" 9176 9177:: 9178 9179 <result> = udiv <ty> <op1>, <op2> ; yields ty:result 9180 <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result 9181 9182Overview: 9183""""""""" 9184 9185The '``udiv``' instruction returns the quotient of its two operands. 9186 9187Arguments: 9188"""""""""" 9189 9190The two arguments to the '``udiv``' instruction must be 9191:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9192arguments must have identical types. 9193 9194Semantics: 9195"""""""""" 9196 9197The value produced is the unsigned integer quotient of the two operands. 9198 9199Note that unsigned integer division and signed integer division are 9200distinct operations; for signed integer division, use '``sdiv``'. 9201 9202Division by zero is undefined behavior. For vectors, if any element 9203of the divisor is zero, the operation has undefined behavior. 9204 9205 9206If the ``exact`` keyword is present, the result value of the ``udiv`` is 9207a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as 9208such, "((a udiv exact b) mul b) == a"). 9209 9210Example: 9211"""""""" 9212 9213.. code-block:: text 9214 9215 <result> = udiv i32 4, %var ; yields i32:result = 4 / %var 9216 9217.. _i_sdiv: 9218 9219'``sdiv``' Instruction 9220^^^^^^^^^^^^^^^^^^^^^^ 9221 9222Syntax: 9223""""""" 9224 9225:: 9226 9227 <result> = sdiv <ty> <op1>, <op2> ; yields ty:result 9228 <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result 9229 9230Overview: 9231""""""""" 9232 9233The '``sdiv``' instruction returns the quotient of its two operands. 9234 9235Arguments: 9236"""""""""" 9237 9238The two arguments to the '``sdiv``' instruction must be 9239:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9240arguments must have identical types. 9241 9242Semantics: 9243"""""""""" 9244 9245The value produced is the signed integer quotient of the two operands 9246rounded towards zero. 9247 9248Note that signed integer division and unsigned integer division are 9249distinct operations; for unsigned integer division, use '``udiv``'. 9250 9251Division by zero is undefined behavior. For vectors, if any element 9252of the divisor is zero, the operation has undefined behavior. 9253Overflow also leads to undefined behavior; this is a rare case, but can 9254occur, for example, by doing a 32-bit division of -2147483648 by -1. 9255 9256If the ``exact`` keyword is present, the result value of the ``sdiv`` is 9257a :ref:`poison value <poisonvalues>` if the result would be rounded. 9258 9259Example: 9260"""""""" 9261 9262.. code-block:: text 9263 9264 <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var 9265 9266.. _i_fdiv: 9267 9268'``fdiv``' Instruction 9269^^^^^^^^^^^^^^^^^^^^^^ 9270 9271Syntax: 9272""""""" 9273 9274:: 9275 9276 <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 9277 9278Overview: 9279""""""""" 9280 9281The '``fdiv``' instruction returns the quotient of its two operands. 9282 9283Arguments: 9284"""""""""" 9285 9286The two arguments to the '``fdiv``' instruction must be 9287:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 9288floating-point values. Both arguments must have identical types. 9289 9290Semantics: 9291"""""""""" 9292 9293The value produced is the floating-point quotient of the two operands. 9294This instruction is assumed to execute in the default :ref:`floating-point 9295environment <floatenv>`. 9296This instruction can also take any number of :ref:`fast-math 9297flags <fastmath>`, which are optimization hints to enable otherwise 9298unsafe floating-point optimizations: 9299 9300Example: 9301"""""""" 9302 9303.. code-block:: text 9304 9305 <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var 9306 9307.. _i_urem: 9308 9309'``urem``' Instruction 9310^^^^^^^^^^^^^^^^^^^^^^ 9311 9312Syntax: 9313""""""" 9314 9315:: 9316 9317 <result> = urem <ty> <op1>, <op2> ; yields ty:result 9318 9319Overview: 9320""""""""" 9321 9322The '``urem``' instruction returns the remainder from the unsigned 9323division of its two arguments. 9324 9325Arguments: 9326"""""""""" 9327 9328The two arguments to the '``urem``' instruction must be 9329:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9330arguments must have identical types. 9331 9332Semantics: 9333"""""""""" 9334 9335This instruction returns the unsigned integer *remainder* of a division. 9336This instruction always performs an unsigned division to get the 9337remainder. 9338 9339Note that unsigned integer remainder and signed integer remainder are 9340distinct operations; for signed integer remainder, use '``srem``'. 9341 9342Taking the remainder of a division by zero is undefined behavior. 9343For vectors, if any element of the divisor is zero, the operation has 9344undefined behavior. 9345 9346Example: 9347"""""""" 9348 9349.. code-block:: text 9350 9351 <result> = urem i32 4, %var ; yields i32:result = 4 % %var 9352 9353.. _i_srem: 9354 9355'``srem``' Instruction 9356^^^^^^^^^^^^^^^^^^^^^^ 9357 9358Syntax: 9359""""""" 9360 9361:: 9362 9363 <result> = srem <ty> <op1>, <op2> ; yields ty:result 9364 9365Overview: 9366""""""""" 9367 9368The '``srem``' instruction returns the remainder from the signed 9369division of its two operands. This instruction can also take 9370:ref:`vector <t_vector>` versions of the values in which case the elements 9371must be integers. 9372 9373Arguments: 9374"""""""""" 9375 9376The two arguments to the '``srem``' instruction must be 9377:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9378arguments must have identical types. 9379 9380Semantics: 9381"""""""""" 9382 9383This instruction returns the *remainder* of a division (where the result 9384is either zero or has the same sign as the dividend, ``op1``), not the 9385*modulo* operator (where the result is either zero or has the same sign 9386as the divisor, ``op2``) of a value. For more information about the 9387difference, see `The Math 9388Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a 9389table of how this is implemented in various languages, please see 9390`Wikipedia: modulo 9391operation <http://en.wikipedia.org/wiki/Modulo_operation>`_. 9392 9393Note that signed integer remainder and unsigned integer remainder are 9394distinct operations; for unsigned integer remainder, use '``urem``'. 9395 9396Taking the remainder of a division by zero is undefined behavior. 9397For vectors, if any element of the divisor is zero, the operation has 9398undefined behavior. 9399Overflow also leads to undefined behavior; this is a rare case, but can 9400occur, for example, by taking the remainder of a 32-bit division of 9401-2147483648 by -1. (The remainder doesn't actually overflow, but this 9402rule lets srem be implemented using instructions that return both the 9403result of the division and the remainder.) 9404 9405Example: 9406"""""""" 9407 9408.. code-block:: text 9409 9410 <result> = srem i32 4, %var ; yields i32:result = 4 % %var 9411 9412.. _i_frem: 9413 9414'``frem``' Instruction 9415^^^^^^^^^^^^^^^^^^^^^^ 9416 9417Syntax: 9418""""""" 9419 9420:: 9421 9422 <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 9423 9424Overview: 9425""""""""" 9426 9427The '``frem``' instruction returns the remainder from the division of 9428its two operands. 9429 9430Arguments: 9431"""""""""" 9432 9433The two arguments to the '``frem``' instruction must be 9434:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 9435floating-point values. Both arguments must have identical types. 9436 9437Semantics: 9438"""""""""" 9439 9440The value produced is the floating-point remainder of the two operands. 9441This is the same output as a libm '``fmod``' function, but without any 9442possibility of setting ``errno``. The remainder has the same sign as the 9443dividend. 9444This instruction is assumed to execute in the default :ref:`floating-point 9445environment <floatenv>`. 9446This instruction can also take any number of :ref:`fast-math 9447flags <fastmath>`, which are optimization hints to enable otherwise 9448unsafe floating-point optimizations: 9449 9450Example: 9451"""""""" 9452 9453.. code-block:: text 9454 9455 <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var 9456 9457.. _bitwiseops: 9458 9459Bitwise Binary Operations 9460------------------------- 9461 9462Bitwise binary operators are used to do various forms of bit-twiddling 9463in a program. They are generally very efficient instructions and can 9464commonly be strength reduced from other instructions. They require two 9465operands of the same type, execute an operation on them, and produce a 9466single value. The resulting value is the same type as its operands. 9467 9468.. _i_shl: 9469 9470'``shl``' Instruction 9471^^^^^^^^^^^^^^^^^^^^^ 9472 9473Syntax: 9474""""""" 9475 9476:: 9477 9478 <result> = shl <ty> <op1>, <op2> ; yields ty:result 9479 <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result 9480 <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result 9481 <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result 9482 9483Overview: 9484""""""""" 9485 9486The '``shl``' instruction returns the first operand shifted to the left 9487a specified number of bits. 9488 9489Arguments: 9490"""""""""" 9491 9492Both arguments to the '``shl``' instruction must be the same 9493:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 9494'``op2``' is treated as an unsigned value. 9495 9496Semantics: 9497"""""""""" 9498 9499The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`, 9500where ``n`` is the width of the result. If ``op2`` is (statically or 9501dynamically) equal to or larger than the number of bits in 9502``op1``, this instruction returns a :ref:`poison value <poisonvalues>`. 9503If the arguments are vectors, each vector element of ``op1`` is shifted 9504by the corresponding shift amount in ``op2``. 9505 9506If the ``nuw`` keyword is present, then the shift produces a poison 9507value if it shifts out any non-zero bits. 9508If the ``nsw`` keyword is present, then the shift produces a poison 9509value if it shifts out any bits that disagree with the resultant sign bit. 9510 9511Example: 9512"""""""" 9513 9514.. code-block:: text 9515 9516 <result> = shl i32 4, %var ; yields i32: 4 << %var 9517 <result> = shl i32 4, 2 ; yields i32: 16 9518 <result> = shl i32 1, 10 ; yields i32: 1024 9519 <result> = shl i32 1, 32 ; undefined 9520 <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4> 9521 9522.. _i_lshr: 9523 9524 9525'``lshr``' Instruction 9526^^^^^^^^^^^^^^^^^^^^^^ 9527 9528Syntax: 9529""""""" 9530 9531:: 9532 9533 <result> = lshr <ty> <op1>, <op2> ; yields ty:result 9534 <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result 9535 9536Overview: 9537""""""""" 9538 9539The '``lshr``' instruction (logical shift right) returns the first 9540operand shifted to the right a specified number of bits with zero fill. 9541 9542Arguments: 9543"""""""""" 9544 9545Both arguments to the '``lshr``' instruction must be the same 9546:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 9547'``op2``' is treated as an unsigned value. 9548 9549Semantics: 9550"""""""""" 9551 9552This instruction always performs a logical shift right operation. The 9553most significant bits of the result will be filled with zero bits after 9554the shift. If ``op2`` is (statically or dynamically) equal to or larger 9555than the number of bits in ``op1``, this instruction returns a :ref:`poison 9556value <poisonvalues>`. If the arguments are vectors, each vector element 9557of ``op1`` is shifted by the corresponding shift amount in ``op2``. 9558 9559If the ``exact`` keyword is present, the result value of the ``lshr`` is 9560a poison value if any of the bits shifted out are non-zero. 9561 9562Example: 9563"""""""" 9564 9565.. code-block:: text 9566 9567 <result> = lshr i32 4, 1 ; yields i32:result = 2 9568 <result> = lshr i32 4, 2 ; yields i32:result = 1 9569 <result> = lshr i8 4, 3 ; yields i8:result = 0 9570 <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F 9571 <result> = lshr i32 1, 32 ; undefined 9572 <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1> 9573 9574.. _i_ashr: 9575 9576'``ashr``' Instruction 9577^^^^^^^^^^^^^^^^^^^^^^ 9578 9579Syntax: 9580""""""" 9581 9582:: 9583 9584 <result> = ashr <ty> <op1>, <op2> ; yields ty:result 9585 <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result 9586 9587Overview: 9588""""""""" 9589 9590The '``ashr``' instruction (arithmetic shift right) returns the first 9591operand shifted to the right a specified number of bits with sign 9592extension. 9593 9594Arguments: 9595"""""""""" 9596 9597Both arguments to the '``ashr``' instruction must be the same 9598:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 9599'``op2``' is treated as an unsigned value. 9600 9601Semantics: 9602"""""""""" 9603 9604This instruction always performs an arithmetic shift right operation, 9605The most significant bits of the result will be filled with the sign bit 9606of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger 9607than the number of bits in ``op1``, this instruction returns a :ref:`poison 9608value <poisonvalues>`. If the arguments are vectors, each vector element 9609of ``op1`` is shifted by the corresponding shift amount in ``op2``. 9610 9611If the ``exact`` keyword is present, the result value of the ``ashr`` is 9612a poison value if any of the bits shifted out are non-zero. 9613 9614Example: 9615"""""""" 9616 9617.. code-block:: text 9618 9619 <result> = ashr i32 4, 1 ; yields i32:result = 2 9620 <result> = ashr i32 4, 2 ; yields i32:result = 1 9621 <result> = ashr i8 4, 3 ; yields i8:result = 0 9622 <result> = ashr i8 -2, 1 ; yields i8:result = -1 9623 <result> = ashr i32 1, 32 ; undefined 9624 <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0> 9625 9626.. _i_and: 9627 9628'``and``' Instruction 9629^^^^^^^^^^^^^^^^^^^^^ 9630 9631Syntax: 9632""""""" 9633 9634:: 9635 9636 <result> = and <ty> <op1>, <op2> ; yields ty:result 9637 9638Overview: 9639""""""""" 9640 9641The '``and``' instruction returns the bitwise logical and of its two 9642operands. 9643 9644Arguments: 9645"""""""""" 9646 9647The two arguments to the '``and``' instruction must be 9648:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9649arguments must have identical types. 9650 9651Semantics: 9652"""""""""" 9653 9654The truth table used for the '``and``' instruction is: 9655 9656+-----+-----+-----+ 9657| In0 | In1 | Out | 9658+-----+-----+-----+ 9659| 0 | 0 | 0 | 9660+-----+-----+-----+ 9661| 0 | 1 | 0 | 9662+-----+-----+-----+ 9663| 1 | 0 | 0 | 9664+-----+-----+-----+ 9665| 1 | 1 | 1 | 9666+-----+-----+-----+ 9667 9668Example: 9669"""""""" 9670 9671.. code-block:: text 9672 9673 <result> = and i32 4, %var ; yields i32:result = 4 & %var 9674 <result> = and i32 15, 40 ; yields i32:result = 8 9675 <result> = and i32 4, 8 ; yields i32:result = 0 9676 9677.. _i_or: 9678 9679'``or``' Instruction 9680^^^^^^^^^^^^^^^^^^^^ 9681 9682Syntax: 9683""""""" 9684 9685:: 9686 9687 <result> = or <ty> <op1>, <op2> ; yields ty:result 9688 9689Overview: 9690""""""""" 9691 9692The '``or``' instruction returns the bitwise logical inclusive or of its 9693two operands. 9694 9695Arguments: 9696"""""""""" 9697 9698The two arguments to the '``or``' instruction must be 9699:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9700arguments must have identical types. 9701 9702Semantics: 9703"""""""""" 9704 9705The truth table used for the '``or``' instruction is: 9706 9707+-----+-----+-----+ 9708| In0 | In1 | Out | 9709+-----+-----+-----+ 9710| 0 | 0 | 0 | 9711+-----+-----+-----+ 9712| 0 | 1 | 1 | 9713+-----+-----+-----+ 9714| 1 | 0 | 1 | 9715+-----+-----+-----+ 9716| 1 | 1 | 1 | 9717+-----+-----+-----+ 9718 9719Example: 9720"""""""" 9721 9722:: 9723 9724 <result> = or i32 4, %var ; yields i32:result = 4 | %var 9725 <result> = or i32 15, 40 ; yields i32:result = 47 9726 <result> = or i32 4, 8 ; yields i32:result = 12 9727 9728.. _i_xor: 9729 9730'``xor``' Instruction 9731^^^^^^^^^^^^^^^^^^^^^ 9732 9733Syntax: 9734""""""" 9735 9736:: 9737 9738 <result> = xor <ty> <op1>, <op2> ; yields ty:result 9739 9740Overview: 9741""""""""" 9742 9743The '``xor``' instruction returns the bitwise logical exclusive or of 9744its two operands. The ``xor`` is used to implement the "one's 9745complement" operation, which is the "~" operator in C. 9746 9747Arguments: 9748"""""""""" 9749 9750The two arguments to the '``xor``' instruction must be 9751:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9752arguments must have identical types. 9753 9754Semantics: 9755"""""""""" 9756 9757The truth table used for the '``xor``' instruction is: 9758 9759+-----+-----+-----+ 9760| In0 | In1 | Out | 9761+-----+-----+-----+ 9762| 0 | 0 | 0 | 9763+-----+-----+-----+ 9764| 0 | 1 | 1 | 9765+-----+-----+-----+ 9766| 1 | 0 | 1 | 9767+-----+-----+-----+ 9768| 1 | 1 | 0 | 9769+-----+-----+-----+ 9770 9771Example: 9772"""""""" 9773 9774.. code-block:: text 9775 9776 <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var 9777 <result> = xor i32 15, 40 ; yields i32:result = 39 9778 <result> = xor i32 4, 8 ; yields i32:result = 12 9779 <result> = xor i32 %V, -1 ; yields i32:result = ~%V 9780 9781Vector Operations 9782----------------- 9783 9784LLVM supports several instructions to represent vector operations in a 9785target-independent manner. These instructions cover the element-access 9786and vector-specific operations needed to process vectors effectively. 9787While LLVM does directly support these vector operations, many 9788sophisticated algorithms will want to use target-specific intrinsics to 9789take full advantage of a specific target. 9790 9791.. _i_extractelement: 9792 9793'``extractelement``' Instruction 9794^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9795 9796Syntax: 9797""""""" 9798 9799:: 9800 9801 <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty> 9802 <result> = extractelement <vscale x n x <ty>> <val>, <ty2> <idx> ; yields <ty> 9803 9804Overview: 9805""""""""" 9806 9807The '``extractelement``' instruction extracts a single scalar element 9808from a vector at a specified index. 9809 9810Arguments: 9811"""""""""" 9812 9813The first operand of an '``extractelement``' instruction is a value of 9814:ref:`vector <t_vector>` type. The second operand is an index indicating 9815the position from which to extract the element. The index may be a 9816variable of any integer type, and will be treated as an unsigned integer. 9817 9818Semantics: 9819"""""""""" 9820 9821The result is a scalar of the same type as the element type of ``val``. 9822Its value is the value at position ``idx`` of ``val``. If ``idx`` 9823exceeds the length of ``val`` for a fixed-length vector, the result is a 9824:ref:`poison value <poisonvalues>`. For a scalable vector, if the value 9825of ``idx`` exceeds the runtime length of the vector, the result is a 9826:ref:`poison value <poisonvalues>`. 9827 9828Example: 9829"""""""" 9830 9831.. code-block:: text 9832 9833 <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32 9834 9835.. _i_insertelement: 9836 9837'``insertelement``' Instruction 9838^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9839 9840Syntax: 9841""""""" 9842 9843:: 9844 9845 <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>> 9846 <result> = insertelement <vscale x n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <vscale x n x <ty>> 9847 9848Overview: 9849""""""""" 9850 9851The '``insertelement``' instruction inserts a scalar element into a 9852vector at a specified index. 9853 9854Arguments: 9855"""""""""" 9856 9857The first operand of an '``insertelement``' instruction is a value of 9858:ref:`vector <t_vector>` type. The second operand is a scalar value whose 9859type must equal the element type of the first operand. The third operand 9860is an index indicating the position at which to insert the value. The 9861index may be a variable of any integer type, and will be treated as an 9862unsigned integer. 9863 9864Semantics: 9865"""""""""" 9866 9867The result is a vector of the same type as ``val``. Its element values 9868are those of ``val`` except at position ``idx``, where it gets the value 9869``elt``. If ``idx`` exceeds the length of ``val`` for a fixed-length vector, 9870the result is a :ref:`poison value <poisonvalues>`. For a scalable vector, 9871if the value of ``idx`` exceeds the runtime length of the vector, the result 9872is a :ref:`poison value <poisonvalues>`. 9873 9874Example: 9875"""""""" 9876 9877.. code-block:: text 9878 9879 <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32> 9880 9881.. _i_shufflevector: 9882 9883'``shufflevector``' Instruction 9884^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9885 9886Syntax: 9887""""""" 9888 9889:: 9890 9891 <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>> 9892 <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>> 9893 9894Overview: 9895""""""""" 9896 9897The '``shufflevector``' instruction constructs a permutation of elements 9898from two input vectors, returning a vector with the same element type as 9899the input and length that is the same as the shuffle mask. 9900 9901Arguments: 9902"""""""""" 9903 9904The first two operands of a '``shufflevector``' instruction are vectors 9905with the same type. The third argument is a shuffle mask vector constant 9906whose element type is ``i32``. The mask vector elements must be constant 9907integers or ``undef`` values. The result of the instruction is a vector 9908whose length is the same as the shuffle mask and whose element type is the 9909same as the element type of the first two operands. 9910 9911Semantics: 9912"""""""""" 9913 9914The elements of the two input vectors are numbered from left to right 9915across both of the vectors. For each element of the result vector, the 9916shuffle mask selects an element from one of the input vectors to copy 9917to the result. Non-negative elements in the mask represent an index 9918into the concatenated pair of input vectors. 9919 9920If the shuffle mask is undefined, the result vector is undefined. If 9921the shuffle mask selects an undefined element from one of the input 9922vectors, the resulting element is undefined. An undefined element 9923in the mask vector specifies that the resulting element is undefined. 9924An undefined element in the mask vector prevents a poisoned vector 9925element from propagating. 9926 9927For scalable vectors, the only valid mask values at present are 9928``zeroinitializer`` and ``undef``, since we cannot write all indices as 9929literals for a vector with a length unknown at compile time. 9930 9931Example: 9932"""""""" 9933 9934.. code-block:: text 9935 9936 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2, 9937 <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32> 9938 <result> = shufflevector <4 x i32> %v1, <4 x i32> undef, 9939 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle. 9940 <result> = shufflevector <8 x i32> %v1, <8 x i32> undef, 9941 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> 9942 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2, 9943 <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32> 9944 9945Aggregate Operations 9946-------------------- 9947 9948LLVM supports several instructions for working with 9949:ref:`aggregate <t_aggregate>` values. 9950 9951.. _i_extractvalue: 9952 9953'``extractvalue``' Instruction 9954^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9955 9956Syntax: 9957""""""" 9958 9959:: 9960 9961 <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}* 9962 9963Overview: 9964""""""""" 9965 9966The '``extractvalue``' instruction extracts the value of a member field 9967from an :ref:`aggregate <t_aggregate>` value. 9968 9969Arguments: 9970"""""""""" 9971 9972The first operand of an '``extractvalue``' instruction is a value of 9973:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are 9974constant indices to specify which value to extract in a similar manner 9975as indices in a '``getelementptr``' instruction. 9976 9977The major differences to ``getelementptr`` indexing are: 9978 9979- Since the value being indexed is not a pointer, the first index is 9980 omitted and assumed to be zero. 9981- At least one index must be specified. 9982- Not only struct indices but also array indices must be in bounds. 9983 9984Semantics: 9985"""""""""" 9986 9987The result is the value at the position in the aggregate specified by 9988the index operands. 9989 9990Example: 9991"""""""" 9992 9993.. code-block:: text 9994 9995 <result> = extractvalue {i32, float} %agg, 0 ; yields i32 9996 9997.. _i_insertvalue: 9998 9999'``insertvalue``' Instruction 10000^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10001 10002Syntax: 10003""""""" 10004 10005:: 10006 10007 <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type> 10008 10009Overview: 10010""""""""" 10011 10012The '``insertvalue``' instruction inserts a value into a member field in 10013an :ref:`aggregate <t_aggregate>` value. 10014 10015Arguments: 10016"""""""""" 10017 10018The first operand of an '``insertvalue``' instruction is a value of 10019:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is 10020a first-class value to insert. The following operands are constant 10021indices indicating the position at which to insert the value in a 10022similar manner as indices in a '``extractvalue``' instruction. The value 10023to insert must have the same type as the value identified by the 10024indices. 10025 10026Semantics: 10027"""""""""" 10028 10029The result is an aggregate of the same type as ``val``. Its value is 10030that of ``val`` except that the value at the position specified by the 10031indices is that of ``elt``. 10032 10033Example: 10034"""""""" 10035 10036.. code-block:: llvm 10037 10038 %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef} 10039 %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val} 10040 %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}} 10041 10042.. _memoryops: 10043 10044Memory Access and Addressing Operations 10045--------------------------------------- 10046 10047A key design point of an SSA-based representation is how it represents 10048memory. In LLVM, no memory locations are in SSA form, which makes things 10049very simple. This section describes how to read, write, and allocate 10050memory in LLVM. 10051 10052.. _i_alloca: 10053 10054'``alloca``' Instruction 10055^^^^^^^^^^^^^^^^^^^^^^^^ 10056 10057Syntax: 10058""""""" 10059 10060:: 10061 10062 <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result 10063 10064Overview: 10065""""""""" 10066 10067The '``alloca``' instruction allocates memory on the stack frame of the 10068currently executing function, to be automatically released when this 10069function returns to its caller. If the address space is not explicitly 10070specified, the object is allocated in the alloca address space from the 10071:ref:`datalayout string<langref_datalayout>`. 10072 10073Arguments: 10074"""""""""" 10075 10076The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements`` 10077bytes of memory on the runtime stack, returning a pointer of the 10078appropriate type to the program. If "NumElements" is specified, it is 10079the number of elements allocated, otherwise "NumElements" is defaulted 10080to be one. If a constant alignment is specified, the value result of the 10081allocation is guaranteed to be aligned to at least that boundary. The 10082alignment may not be greater than ``1 << 32``. If not specified, or if 10083zero, the target can choose to align the allocation on any convenient 10084boundary compatible with the type. 10085 10086'``type``' may be any sized type. 10087 10088Semantics: 10089"""""""""" 10090 10091Memory is allocated; a pointer is returned. The allocated memory is 10092uninitialized, and loading from uninitialized memory produces an undefined 10093value. The operation itself is undefined if there is insufficient stack 10094space for the allocation.'``alloca``'d memory is automatically released 10095when the function returns. The '``alloca``' instruction is commonly used 10096to represent automatic variables that must have an address available. When 10097the function returns (either with the ``ret`` or ``resume`` instructions), 10098the memory is reclaimed. Allocating zero bytes is legal, but the returned 10099pointer may not be unique. The order in which memory is allocated (ie., 10100which way the stack grows) is not specified. 10101 10102Note that '``alloca``' outside of the alloca address space from the 10103:ref:`datalayout string<langref_datalayout>` is meaningful only if the 10104target has assigned it a semantics. 10105 10106If the returned pointer is used by :ref:`llvm.lifetime.start <int_lifestart>`, 10107the returned object is initially dead. 10108See :ref:`llvm.lifetime.start <int_lifestart>` and 10109:ref:`llvm.lifetime.end <int_lifeend>` for the precise semantics of 10110lifetime-manipulating intrinsics. 10111 10112Example: 10113"""""""" 10114 10115.. code-block:: llvm 10116 10117 %ptr = alloca i32 ; yields ptr 10118 %ptr = alloca i32, i32 4 ; yields ptr 10119 %ptr = alloca i32, i32 4, align 1024 ; yields ptr 10120 %ptr = alloca i32, align 1024 ; yields ptr 10121 10122.. _i_load: 10123 10124'``load``' Instruction 10125^^^^^^^^^^^^^^^^^^^^^^ 10126 10127Syntax: 10128""""""" 10129 10130:: 10131 10132 <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>] 10133 <result> = load atomic [volatile] <ty>, ptr <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>] 10134 !<nontemp_node> = !{ i32 1 } 10135 !<empty_node> = !{} 10136 !<deref_bytes_node> = !{ i64 <dereferenceable_bytes> } 10137 !<align_node> = !{ i64 <value_alignment> } 10138 10139Overview: 10140""""""""" 10141 10142The '``load``' instruction is used to read from memory. 10143 10144Arguments: 10145"""""""""" 10146 10147The argument to the ``load`` instruction specifies the memory address from which 10148to load. The type specified must be a :ref:`first class <t_firstclass>` type of 10149known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If 10150the ``load`` is marked as ``volatile``, then the optimizer is not allowed to 10151modify the number or order of execution of this ``load`` with other 10152:ref:`volatile operations <volatile>`. 10153 10154If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering 10155<ordering>` and optional ``syncscope("<target-scope>")`` argument. The 10156``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions. 10157Atomic loads produce :ref:`defined <memmodel>` results when they may see 10158multiple atomic stores. The type of the pointee must be an integer, pointer, or 10159floating-point type whose bit width is a power of two greater than or equal to 10160eight and less than or equal to a target-specific size limit. ``align`` must be 10161explicitly specified on atomic loads, and the load has undefined behavior if the 10162alignment is not set to a value which is at least the size in bytes of the 10163pointee. ``!nontemporal`` does not have any defined semantics for atomic loads. 10164 10165The optional constant ``align`` argument specifies the alignment of the 10166operation (that is, the alignment of the memory address). A value of 0 10167or an omitted ``align`` argument means that the operation has the ABI 10168alignment for the target. It is the responsibility of the code emitter 10169to ensure that the alignment information is correct. Overestimating the 10170alignment results in undefined behavior. Underestimating the alignment 10171may produce less efficient code. An alignment of 1 is always safe. The 10172maximum possible alignment is ``1 << 32``. An alignment value higher 10173than the size of the loaded type implies memory up to the alignment 10174value bytes can be safely loaded without trapping in the default 10175address space. Access of the high bytes can interfere with debugging 10176tools, so should not be accessed if the function has the 10177``sanitize_thread`` or ``sanitize_address`` attributes. 10178 10179The optional ``!nontemporal`` metadata must reference a single 10180metadata name ``<nontemp_node>`` corresponding to a metadata node with one 10181``i32`` entry of value 1. The existence of the ``!nontemporal`` 10182metadata on the instruction tells the optimizer and code generator 10183that this load is not expected to be reused in the cache. The code 10184generator may select special instructions to save cache bandwidth, such 10185as the ``MOVNT`` instruction on x86. 10186 10187The optional ``!invariant.load`` metadata must reference a single 10188metadata name ``<empty_node>`` corresponding to a metadata node with no 10189entries. If a load instruction tagged with the ``!invariant.load`` 10190metadata is executed, the memory location referenced by the load has 10191to contain the same value at all points in the program where the 10192memory location is dereferenceable; otherwise, the behavior is 10193undefined. 10194 10195The optional ``!invariant.group`` metadata must reference a single metadata name 10196 ``<empty_node>`` corresponding to a metadata node with no entries. 10197 See ``invariant.group`` metadata :ref:`invariant.group <md_invariant.group>`. 10198 10199The optional ``!nonnull`` metadata must reference a single 10200metadata name ``<empty_node>`` corresponding to a metadata node with no 10201entries. The existence of the ``!nonnull`` metadata on the 10202instruction tells the optimizer that the value loaded is known to 10203never be null. If the value is null at runtime, a poison value is returned 10204instead. This is analogous to the ``nonnull`` attribute on parameters and 10205return values. This metadata can only be applied to loads of a pointer type. 10206 10207The optional ``!dereferenceable`` metadata must reference a single metadata 10208name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64`` 10209entry. 10210See ``dereferenceable`` metadata :ref:`dereferenceable <md_dereferenceable>`. 10211 10212The optional ``!dereferenceable_or_null`` metadata must reference a single 10213metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one 10214``i64`` entry. 10215See ``dereferenceable_or_null`` metadata :ref:`dereferenceable_or_null 10216<md_dereferenceable_or_null>`. 10217 10218The optional ``!align`` metadata must reference a single metadata name 10219``<align_node>`` corresponding to a metadata node with one ``i64`` entry. 10220The existence of the ``!align`` metadata on the instruction tells the 10221optimizer that the value loaded is known to be aligned to a boundary specified 10222by the integer value in the metadata node. The alignment must be a power of 2. 10223This is analogous to the ''align'' attribute on parameters and return values. 10224This metadata can only be applied to loads of a pointer type. If the returned 10225value is not appropriately aligned at runtime, a poison value is returned 10226instead. 10227 10228The optional ``!noundef`` metadata must reference a single metadata name 10229``<empty_node>`` corresponding to a node with no entries. The existence of 10230``!noundef`` metadata on the instruction tells the optimizer that the value 10231loaded is known to be :ref:`well defined <welldefinedvalues>`. 10232If the value isn't well defined, the behavior is undefined. If the ``!noundef`` 10233metadata is combined with poison-generating metadata like ``!nonnull``, 10234violation of that metadata constraint will also result in undefined behavior. 10235 10236Semantics: 10237"""""""""" 10238 10239The location of memory pointed to is loaded. If the value being loaded 10240is of scalar type then the number of bytes read does not exceed the 10241minimum number of bytes needed to hold all bits of the type. For 10242example, loading an ``i24`` reads at most three bytes. When loading a 10243value of a type like ``i20`` with a size that is not an integral number 10244of bytes, the result is undefined if the value was not originally 10245written using a store of the same type. 10246If the value being loaded is of aggregate type, the bytes that correspond to 10247padding may be accessed but are ignored, because it is impossible to observe 10248padding from the loaded aggregate value. 10249If ``<pointer>`` is not a well-defined value, the behavior is undefined. 10250 10251Examples: 10252""""""""" 10253 10254.. code-block:: llvm 10255 10256 %ptr = alloca i32 ; yields ptr 10257 store i32 3, ptr %ptr ; yields void 10258 %val = load i32, ptr %ptr ; yields i32:val = i32 3 10259 10260.. _i_store: 10261 10262'``store``' Instruction 10263^^^^^^^^^^^^^^^^^^^^^^^ 10264 10265Syntax: 10266""""""" 10267 10268:: 10269 10270 store [volatile] <ty> <value>, ptr <pointer>[, align <alignment>][, !nontemporal !<nontemp_node>][, !invariant.group !<empty_node>] ; yields void 10271 store atomic [volatile] <ty> <value>, ptr <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>] ; yields void 10272 !<nontemp_node> = !{ i32 1 } 10273 !<empty_node> = !{} 10274 10275Overview: 10276""""""""" 10277 10278The '``store``' instruction is used to write to memory. 10279 10280Arguments: 10281"""""""""" 10282 10283There are two arguments to the ``store`` instruction: a value to store and an 10284address at which to store it. The type of the ``<pointer>`` operand must be a 10285pointer to the :ref:`first class <t_firstclass>` type of the ``<value>`` 10286operand. If the ``store`` is marked as ``volatile``, then the optimizer is not 10287allowed to modify the number or order of execution of this ``store`` with other 10288:ref:`volatile operations <volatile>`. Only values of :ref:`first class 10289<t_firstclass>` types of known size (i.e. not containing an :ref:`opaque 10290structural type <t_opaque>`) can be stored. 10291 10292If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering 10293<ordering>` and optional ``syncscope("<target-scope>")`` argument. The 10294``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions. 10295Atomic loads produce :ref:`defined <memmodel>` results when they may see 10296multiple atomic stores. The type of the pointee must be an integer, pointer, or 10297floating-point type whose bit width is a power of two greater than or equal to 10298eight and less than or equal to a target-specific size limit. ``align`` must be 10299explicitly specified on atomic stores, and the store has undefined behavior if 10300the alignment is not set to a value which is at least the size in bytes of the 10301pointee. ``!nontemporal`` does not have any defined semantics for atomic stores. 10302 10303The optional constant ``align`` argument specifies the alignment of the 10304operation (that is, the alignment of the memory address). A value of 0 10305or an omitted ``align`` argument means that the operation has the ABI 10306alignment for the target. It is the responsibility of the code emitter 10307to ensure that the alignment information is correct. Overestimating the 10308alignment results in undefined behavior. Underestimating the 10309alignment may produce less efficient code. An alignment of 1 is always 10310safe. The maximum possible alignment is ``1 << 32``. An alignment 10311value higher than the size of the stored type implies memory up to the 10312alignment value bytes can be stored to without trapping in the default 10313address space. Storing to the higher bytes however may result in data 10314races if another thread can access the same address. Introducing a 10315data race is not allowed. Storing to the extra bytes is not allowed 10316even in situations where a data race is known to not exist if the 10317function has the ``sanitize_address`` attribute. 10318 10319The optional ``!nontemporal`` metadata must reference a single metadata 10320name ``<nontemp_node>`` corresponding to a metadata node with one ``i32`` entry 10321of value 1. The existence of the ``!nontemporal`` metadata on the instruction 10322tells the optimizer and code generator that this load is not expected to 10323be reused in the cache. The code generator may select special 10324instructions to save cache bandwidth, such as the ``MOVNT`` instruction on 10325x86. 10326 10327The optional ``!invariant.group`` metadata must reference a 10328single metadata name ``<empty_node>``. See ``invariant.group`` metadata. 10329 10330Semantics: 10331"""""""""" 10332 10333The contents of memory are updated to contain ``<value>`` at the 10334location specified by the ``<pointer>`` operand. If ``<value>`` is 10335of scalar type then the number of bytes written does not exceed the 10336minimum number of bytes needed to hold all bits of the type. For 10337example, storing an ``i24`` writes at most three bytes. When writing a 10338value of a type like ``i20`` with a size that is not an integral number 10339of bytes, it is unspecified what happens to the extra bits that do not 10340belong to the type, but they will typically be overwritten. 10341If ``<value>`` is of aggregate type, padding is filled with 10342:ref:`undef <undefvalues>`. 10343If ``<pointer>`` is not a well-defined value, the behavior is undefined. 10344 10345Example: 10346"""""""" 10347 10348.. code-block:: llvm 10349 10350 %ptr = alloca i32 ; yields ptr 10351 store i32 3, ptr %ptr ; yields void 10352 %val = load i32, ptr %ptr ; yields i32:val = i32 3 10353 10354.. _i_fence: 10355 10356'``fence``' Instruction 10357^^^^^^^^^^^^^^^^^^^^^^^ 10358 10359Syntax: 10360""""""" 10361 10362:: 10363 10364 fence [syncscope("<target-scope>")] <ordering> ; yields void 10365 10366Overview: 10367""""""""" 10368 10369The '``fence``' instruction is used to introduce happens-before edges 10370between operations. 10371 10372Arguments: 10373"""""""""" 10374 10375'``fence``' instructions take an :ref:`ordering <ordering>` argument which 10376defines what *synchronizes-with* edges they add. They can only be given 10377``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings. 10378 10379Semantics: 10380"""""""""" 10381 10382A fence A which has (at least) ``release`` ordering semantics 10383*synchronizes with* a fence B with (at least) ``acquire`` ordering 10384semantics if and only if there exist atomic operations X and Y, both 10385operating on some atomic object M, such that A is sequenced before X, X 10386modifies M (either directly or through some side effect of a sequence 10387headed by X), Y is sequenced before B, and Y observes M. This provides a 10388*happens-before* dependency between A and B. Rather than an explicit 10389``fence``, one (but not both) of the atomic operations X or Y might 10390provide a ``release`` or ``acquire`` (resp.) ordering constraint and 10391still *synchronize-with* the explicit ``fence`` and establish the 10392*happens-before* edge. 10393 10394A ``fence`` which has ``seq_cst`` ordering, in addition to having both 10395``acquire`` and ``release`` semantics specified above, participates in 10396the global program order of other ``seq_cst`` operations and/or fences. 10397 10398A ``fence`` instruction can also take an optional 10399":ref:`syncscope <syncscope>`" argument. 10400 10401Example: 10402"""""""" 10403 10404.. code-block:: text 10405 10406 fence acquire ; yields void 10407 fence syncscope("singlethread") seq_cst ; yields void 10408 fence syncscope("agent") seq_cst ; yields void 10409 10410.. _i_cmpxchg: 10411 10412'``cmpxchg``' Instruction 10413^^^^^^^^^^^^^^^^^^^^^^^^^ 10414 10415Syntax: 10416""""""" 10417 10418:: 10419 10420 cmpxchg [weak] [volatile] ptr <pointer>, <ty> <cmp>, <ty> <new> [syncscope("<target-scope>")] <success ordering> <failure ordering>[, align <alignment>] ; yields { ty, i1 } 10421 10422Overview: 10423""""""""" 10424 10425The '``cmpxchg``' instruction is used to atomically modify memory. It 10426loads a value in memory and compares it to a given value. If they are 10427equal, it tries to store a new value into the memory. 10428 10429Arguments: 10430"""""""""" 10431 10432There are three arguments to the '``cmpxchg``' instruction: an address 10433to operate on, a value to compare to the value currently be at that 10434address, and a new value to place at that address if the compared values 10435are equal. The type of '<cmp>' must be an integer or pointer type whose 10436bit width is a power of two greater than or equal to eight and less 10437than or equal to a target-specific size limit. '<cmp>' and '<new>' must 10438have the same type, and the type of '<pointer>' must be a pointer to 10439that type. If the ``cmpxchg`` is marked as ``volatile``, then the 10440optimizer is not allowed to modify the number or order of execution of 10441this ``cmpxchg`` with other :ref:`volatile operations <volatile>`. 10442 10443The success and failure :ref:`ordering <ordering>` arguments specify how this 10444``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters 10445must be at least ``monotonic``, the failure ordering cannot be either 10446``release`` or ``acq_rel``. 10447 10448A ``cmpxchg`` instruction can also take an optional 10449":ref:`syncscope <syncscope>`" argument. 10450 10451The instruction can take an optional ``align`` attribute. 10452The alignment must be a power of two greater or equal to the size of the 10453`<value>` type. If unspecified, the alignment is assumed to be equal to the 10454size of the '<value>' type. Note that this default alignment assumption is 10455different from the alignment used for the load/store instructions when align 10456isn't specified. 10457 10458The pointer passed into cmpxchg must have alignment greater than or 10459equal to the size in memory of the operand. 10460 10461Semantics: 10462"""""""""" 10463 10464The contents of memory at the location specified by the '``<pointer>``' operand 10465is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is 10466written to the location. The original value at the location is returned, 10467together with a flag indicating success (true) or failure (false). 10468 10469If the cmpxchg operation is marked as ``weak`` then a spurious failure is 10470permitted: the operation may not write ``<new>`` even if the comparison 10471matched. 10472 10473If the cmpxchg operation is strong (the default), the i1 value is 1 if and only 10474if the value loaded equals ``cmp``. 10475 10476A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of 10477identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic 10478load with an ordering parameter determined the second ordering parameter. 10479 10480Example: 10481"""""""" 10482 10483.. code-block:: llvm 10484 10485 entry: 10486 %orig = load atomic i32, ptr %ptr unordered, align 4 ; yields i32 10487 br label %loop 10488 10489 loop: 10490 %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop] 10491 %squared = mul i32 %cmp, %cmp 10492 %val_success = cmpxchg ptr %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 } 10493 %value_loaded = extractvalue { i32, i1 } %val_success, 0 10494 %success = extractvalue { i32, i1 } %val_success, 1 10495 br i1 %success, label %done, label %loop 10496 10497 done: 10498 ... 10499 10500.. _i_atomicrmw: 10501 10502'``atomicrmw``' Instruction 10503^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10504 10505Syntax: 10506""""""" 10507 10508:: 10509 10510 atomicrmw [volatile] <operation> ptr <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering>[, align <alignment>] ; yields ty 10511 10512Overview: 10513""""""""" 10514 10515The '``atomicrmw``' instruction is used to atomically modify memory. 10516 10517Arguments: 10518"""""""""" 10519 10520There are three arguments to the '``atomicrmw``' instruction: an 10521operation to apply, an address whose value to modify, an argument to the 10522operation. The operation must be one of the following keywords: 10523 10524- xchg 10525- add 10526- sub 10527- and 10528- nand 10529- or 10530- xor 10531- max 10532- min 10533- umax 10534- umin 10535- fadd 10536- fsub 10537- fmax 10538- fmin 10539- uinc_wrap 10540- udec_wrap 10541 10542For most of these operations, the type of '<value>' must be an integer 10543type whose bit width is a power of two greater than or equal to eight 10544and less than or equal to a target-specific size limit. For xchg, this 10545may also be a floating point or a pointer type with the same size constraints 10546as integers. For fadd/fsub/fmax/fmin, this must be a floating point type. The 10547type of the '``<pointer>``' operand must be a pointer to that type. If 10548the ``atomicrmw`` is marked as ``volatile``, then the optimizer is not 10549allowed to modify the number or order of execution of this 10550``atomicrmw`` with other :ref:`volatile operations <volatile>`. 10551 10552The instruction can take an optional ``align`` attribute. 10553The alignment must be a power of two greater or equal to the size of the 10554`<value>` type. If unspecified, the alignment is assumed to be equal to the 10555size of the '<value>' type. Note that this default alignment assumption is 10556different from the alignment used for the load/store instructions when align 10557isn't specified. 10558 10559A ``atomicrmw`` instruction can also take an optional 10560":ref:`syncscope <syncscope>`" argument. 10561 10562Semantics: 10563"""""""""" 10564 10565The contents of memory at the location specified by the '``<pointer>``' 10566operand are atomically read, modified, and written back. The original 10567value at the location is returned. The modification is specified by the 10568operation argument: 10569 10570- xchg: ``*ptr = val`` 10571- add: ``*ptr = *ptr + val`` 10572- sub: ``*ptr = *ptr - val`` 10573- and: ``*ptr = *ptr & val`` 10574- nand: ``*ptr = ~(*ptr & val)`` 10575- or: ``*ptr = *ptr | val`` 10576- xor: ``*ptr = *ptr ^ val`` 10577- max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison) 10578- min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison) 10579- umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned comparison) 10580- umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned comparison) 10581- fadd: ``*ptr = *ptr + val`` (using floating point arithmetic) 10582- fsub: ``*ptr = *ptr - val`` (using floating point arithmetic) 10583- fmax: ``*ptr = maxnum(*ptr, val)`` (match the `llvm.maxnum.*`` intrinsic) 10584- fmin: ``*ptr = minnum(*ptr, val)`` (match the `llvm.minnum.*`` intrinsic) 10585- uinc_wrap: ``*ptr = (*ptr u>= val) ? 0 : (*ptr + 1)`` (increment value with wraparound to zero when incremented above input value) 10586- udec_wrap: ``*ptr = ((*ptr == 0) || (*ptr u> val)) ? val : (*ptr - 1)`` (decrement with wraparound to input value when decremented below zero). 10587 10588 10589Example: 10590"""""""" 10591 10592.. code-block:: llvm 10593 10594 %old = atomicrmw add ptr %ptr, i32 1 acquire ; yields i32 10595 10596.. _i_getelementptr: 10597 10598'``getelementptr``' Instruction 10599^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10600 10601Syntax: 10602""""""" 10603 10604:: 10605 10606 <result> = getelementptr <ty>, ptr <ptrval>{, [inrange] <ty> <idx>}* 10607 <result> = getelementptr inbounds <ty>, ptr <ptrval>{, [inrange] <ty> <idx>}* 10608 <result> = getelementptr <ty>, <N x ptr> <ptrval>, [inrange] <vector index type> <idx> 10609 10610Overview: 10611""""""""" 10612 10613The '``getelementptr``' instruction is used to get the address of a 10614subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs 10615address calculation only and does not access memory. The instruction can also 10616be used to calculate a vector of such addresses. 10617 10618Arguments: 10619"""""""""" 10620 10621The first argument is always a type used as the basis for the calculations. 10622The second argument is always a pointer or a vector of pointers, and is the 10623base address to start from. The remaining arguments are indices 10624that indicate which of the elements of the aggregate object are indexed. 10625The interpretation of each index is dependent on the type being indexed 10626into. The first index always indexes the pointer value given as the 10627second argument, the second index indexes a value of the type pointed to 10628(not necessarily the value directly pointed to, since the first index 10629can be non-zero), etc. The first type indexed into must be a pointer 10630value, subsequent types can be arrays, vectors, and structs. Note that 10631subsequent types being indexed into can never be pointers, since that 10632would require loading the pointer before continuing calculation. 10633 10634The type of each index argument depends on the type it is indexing into. 10635When indexing into a (optionally packed) structure, only ``i32`` integer 10636**constants** are allowed (when using a vector of indices they must all 10637be the **same** ``i32`` integer constant). When indexing into an array, 10638pointer or vector, integers of any width are allowed, and they are not 10639required to be constant. These integers are treated as signed values 10640where relevant. 10641 10642For example, let's consider a C code fragment and how it gets compiled 10643to LLVM: 10644 10645.. code-block:: c 10646 10647 struct RT { 10648 char A; 10649 int B[10][20]; 10650 char C; 10651 }; 10652 struct ST { 10653 int X; 10654 double Y; 10655 struct RT Z; 10656 }; 10657 10658 int *foo(struct ST *s) { 10659 return &s[1].Z.B[5][13]; 10660 } 10661 10662The LLVM code generated by Clang is: 10663 10664.. code-block:: llvm 10665 10666 %struct.RT = type { i8, [10 x [20 x i32]], i8 } 10667 %struct.ST = type { i32, double, %struct.RT } 10668 10669 define ptr @foo(ptr %s) nounwind uwtable readnone optsize ssp { 10670 entry: 10671 %arrayidx = getelementptr inbounds %struct.ST, ptr %s, i64 1, i32 2, i32 1, i64 5, i64 13 10672 ret ptr %arrayidx 10673 } 10674 10675Semantics: 10676"""""""""" 10677 10678In the example above, the first index is indexing into the 10679'``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``' 10680= '``{ i32, double, %struct.RT }``' type, a structure. The second index 10681indexes into the third element of the structure, yielding a 10682'``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another 10683structure. The third index indexes into the second element of the 10684structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two 10685dimensions of the array are subscripted into, yielding an '``i32``' 10686type. The '``getelementptr``' instruction returns a pointer to this 10687element. 10688 10689Note that it is perfectly legal to index partially through a structure, 10690returning a pointer to an inner element. Because of this, the LLVM code 10691for the given testcase is equivalent to: 10692 10693.. code-block:: llvm 10694 10695 define ptr @foo(ptr %s) { 10696 %t1 = getelementptr %struct.ST, ptr %s, i32 1 10697 %t2 = getelementptr %struct.ST, ptr %t1, i32 0, i32 2 10698 %t3 = getelementptr %struct.RT, ptr %t2, i32 0, i32 1 10699 %t4 = getelementptr [10 x [20 x i32]], ptr %t3, i32 0, i32 5 10700 %t5 = getelementptr [20 x i32], ptr %t4, i32 0, i32 13 10701 ret ptr %t5 10702 } 10703 10704If the ``inbounds`` keyword is present, the result value of the 10705``getelementptr`` is a :ref:`poison value <poisonvalues>` if one of the 10706following rules is violated: 10707 10708* The base pointer has an *in bounds* address of an allocated object, which 10709 means that it points into an allocated object, or to its end. The only 10710 *in bounds* address for a null pointer in the default address-space is the 10711 null pointer itself. 10712* If the type of an index is larger than the pointer index type, the 10713 truncation to the pointer index type preserves the signed value. 10714* The multiplication of an index by the type size does not wrap the pointer 10715 index type in a signed sense (``nsw``). 10716* The successive addition of offsets (without adding the base address) does 10717 not wrap the pointer index type in a signed sense (``nsw``). 10718* The successive addition of the current address, interpreted as an unsigned 10719 number, and an offset, interpreted as a signed number, does not wrap the 10720 unsigned address space and remains *in bounds* of the allocated object. 10721 As a corollary, if the added offset is non-negative, the addition does not 10722 wrap in an unsigned sense (``nuw``). 10723* In cases where the base is a vector of pointers, the ``inbounds`` keyword 10724 applies to each of the computations element-wise. 10725 10726These rules are based on the assumption that no allocated object may cross 10727the unsigned address space boundary, and no allocated object may be larger 10728than half the pointer index type space. 10729 10730If the ``inbounds`` keyword is not present, the offsets are added to the 10731base address with silently-wrapping two's complement arithmetic. If the 10732offsets have a different width from the pointer, they are sign-extended 10733or truncated to the width of the pointer. The result value of the 10734``getelementptr`` may be outside the object pointed to by the base 10735pointer. The result value may not necessarily be used to access memory 10736though, even if it happens to point into allocated storage. See the 10737:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more 10738information. 10739 10740If the ``inrange`` keyword is present before any index, loading from or 10741storing to any pointer derived from the ``getelementptr`` has undefined 10742behavior if the load or store would access memory outside of the bounds of 10743the element selected by the index marked as ``inrange``. The result of a 10744pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations 10745involving memory) involving a pointer derived from a ``getelementptr`` with 10746the ``inrange`` keyword is undefined, with the exception of comparisons 10747in the case where both operands are in the range of the element selected 10748by the ``inrange`` keyword, inclusive of the address one past the end of 10749that element. Note that the ``inrange`` keyword is currently only allowed 10750in constant ``getelementptr`` expressions. 10751 10752The getelementptr instruction is often confusing. For some more insight 10753into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`. 10754 10755Example: 10756"""""""" 10757 10758.. code-block:: llvm 10759 10760 %aptr = getelementptr {i32, [12 x i8]}, ptr %saptr, i64 0, i32 1 10761 %vptr = getelementptr {i32, <2 x i8>}, ptr %svptr, i64 0, i32 1, i32 1 10762 %eptr = getelementptr [12 x i8], ptr %aptr, i64 0, i32 1 10763 %iptr = getelementptr [10 x i32], ptr @arr, i16 0, i16 0 10764 10765Vector of pointers: 10766""""""""""""""""""" 10767 10768The ``getelementptr`` returns a vector of pointers, instead of a single address, 10769when one or more of its arguments is a vector. In such cases, all vector 10770arguments should have the same number of elements, and every scalar argument 10771will be effectively broadcast into a vector during address calculation. 10772 10773.. code-block:: llvm 10774 10775 ; All arguments are vectors: 10776 ; A[i] = ptrs[i] + offsets[i]*sizeof(i8) 10777 %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets 10778 10779 ; Add the same scalar offset to each pointer of a vector: 10780 ; A[i] = ptrs[i] + offset*sizeof(i8) 10781 %A = getelementptr i8, <4 x ptr> %ptrs, i64 %offset 10782 10783 ; Add distinct offsets to the same pointer: 10784 ; A[i] = ptr + offsets[i]*sizeof(i8) 10785 %A = getelementptr i8, ptr %ptr, <4 x i64> %offsets 10786 10787 ; In all cases described above the type of the result is <4 x ptr> 10788 10789The two following instructions are equivalent: 10790 10791.. code-block:: llvm 10792 10793 getelementptr %struct.ST, <4 x ptr> %s, <4 x i64> %ind1, 10794 <4 x i32> <i32 2, i32 2, i32 2, i32 2>, 10795 <4 x i32> <i32 1, i32 1, i32 1, i32 1>, 10796 <4 x i32> %ind4, 10797 <4 x i64> <i64 13, i64 13, i64 13, i64 13> 10798 10799 getelementptr %struct.ST, <4 x ptr> %s, <4 x i64> %ind1, 10800 i32 2, i32 1, <4 x i32> %ind4, i64 13 10801 10802Let's look at the C code, where the vector version of ``getelementptr`` 10803makes sense: 10804 10805.. code-block:: c 10806 10807 // Let's assume that we vectorize the following loop: 10808 double *A, *B; int *C; 10809 for (int i = 0; i < size; ++i) { 10810 A[i] = B[C[i]]; 10811 } 10812 10813.. code-block:: llvm 10814 10815 ; get pointers for 8 elements from array B 10816 %ptrs = getelementptr double, ptr %B, <8 x i32> %C 10817 ; load 8 elements from array B into A 10818 %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x ptr> %ptrs, 10819 i32 8, <8 x i1> %mask, <8 x double> %passthru) 10820 10821Conversion Operations 10822--------------------- 10823 10824The instructions in this category are the conversion instructions 10825(casting) which all take a single operand and a type. They perform 10826various bit conversions on the operand. 10827 10828.. _i_trunc: 10829 10830'``trunc .. to``' Instruction 10831^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10832 10833Syntax: 10834""""""" 10835 10836:: 10837 10838 <result> = trunc <ty> <value> to <ty2> ; yields ty2 10839 10840Overview: 10841""""""""" 10842 10843The '``trunc``' instruction truncates its operand to the type ``ty2``. 10844 10845Arguments: 10846"""""""""" 10847 10848The '``trunc``' instruction takes a value to trunc, and a type to trunc 10849it to. Both types must be of :ref:`integer <t_integer>` types, or vectors 10850of the same number of integers. The bit size of the ``value`` must be 10851larger than the bit size of the destination type, ``ty2``. Equal sized 10852types are not allowed. 10853 10854Semantics: 10855"""""""""" 10856 10857The '``trunc``' instruction truncates the high order bits in ``value`` 10858and converts the remaining bits to ``ty2``. Since the source size must 10859be larger than the destination size, ``trunc`` cannot be a *no-op cast*. 10860It will always truncate bits. 10861 10862Example: 10863"""""""" 10864 10865.. code-block:: llvm 10866 10867 %X = trunc i32 257 to i8 ; yields i8:1 10868 %Y = trunc i32 123 to i1 ; yields i1:true 10869 %Z = trunc i32 122 to i1 ; yields i1:false 10870 %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7> 10871 10872.. _i_zext: 10873 10874'``zext .. to``' Instruction 10875^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10876 10877Syntax: 10878""""""" 10879 10880:: 10881 10882 <result> = zext <ty> <value> to <ty2> ; yields ty2 10883 10884Overview: 10885""""""""" 10886 10887The '``zext``' instruction zero extends its operand to type ``ty2``. 10888 10889Arguments: 10890"""""""""" 10891 10892The '``zext``' instruction takes a value to cast, and a type to cast it 10893to. Both types must be of :ref:`integer <t_integer>` types, or vectors of 10894the same number of integers. The bit size of the ``value`` must be 10895smaller than the bit size of the destination type, ``ty2``. 10896 10897Semantics: 10898"""""""""" 10899 10900The ``zext`` fills the high order bits of the ``value`` with zero bits 10901until it reaches the size of the destination type, ``ty2``. 10902 10903When zero extending from i1, the result will always be either 0 or 1. 10904 10905Example: 10906"""""""" 10907 10908.. code-block:: llvm 10909 10910 %X = zext i32 257 to i64 ; yields i64:257 10911 %Y = zext i1 true to i32 ; yields i32:1 10912 %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7> 10913 10914.. _i_sext: 10915 10916'``sext .. to``' Instruction 10917^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10918 10919Syntax: 10920""""""" 10921 10922:: 10923 10924 <result> = sext <ty> <value> to <ty2> ; yields ty2 10925 10926Overview: 10927""""""""" 10928 10929The '``sext``' sign extends ``value`` to the type ``ty2``. 10930 10931Arguments: 10932"""""""""" 10933 10934The '``sext``' instruction takes a value to cast, and a type to cast it 10935to. Both types must be of :ref:`integer <t_integer>` types, or vectors of 10936the same number of integers. The bit size of the ``value`` must be 10937smaller than the bit size of the destination type, ``ty2``. 10938 10939Semantics: 10940"""""""""" 10941 10942The '``sext``' instruction performs a sign extension by copying the sign 10943bit (highest order bit) of the ``value`` until it reaches the bit size 10944of the type ``ty2``. 10945 10946When sign extending from i1, the extension always results in -1 or 0. 10947 10948Example: 10949"""""""" 10950 10951.. code-block:: llvm 10952 10953 %X = sext i8 -1 to i16 ; yields i16 :65535 10954 %Y = sext i1 true to i32 ; yields i32:-1 10955 %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7> 10956 10957'``fptrunc .. to``' Instruction 10958^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10959 10960Syntax: 10961""""""" 10962 10963:: 10964 10965 <result> = fptrunc <ty> <value> to <ty2> ; yields ty2 10966 10967Overview: 10968""""""""" 10969 10970The '``fptrunc``' instruction truncates ``value`` to type ``ty2``. 10971 10972Arguments: 10973"""""""""" 10974 10975The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>` 10976value to cast and a :ref:`floating-point <t_floating>` type to cast it to. 10977The size of ``value`` must be larger than the size of ``ty2``. This 10978implies that ``fptrunc`` cannot be used to make a *no-op cast*. 10979 10980Semantics: 10981"""""""""" 10982 10983The '``fptrunc``' instruction casts a ``value`` from a larger 10984:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point 10985<t_floating>` type. 10986This instruction is assumed to execute in the default :ref:`floating-point 10987environment <floatenv>`. 10988 10989Example: 10990"""""""" 10991 10992.. code-block:: llvm 10993 10994 %X = fptrunc double 16777217.0 to float ; yields float:16777216.0 10995 %Y = fptrunc double 1.0E+300 to half ; yields half:+infinity 10996 10997'``fpext .. to``' Instruction 10998^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10999 11000Syntax: 11001""""""" 11002 11003:: 11004 11005 <result> = fpext <ty> <value> to <ty2> ; yields ty2 11006 11007Overview: 11008""""""""" 11009 11010The '``fpext``' extends a floating-point ``value`` to a larger floating-point 11011value. 11012 11013Arguments: 11014"""""""""" 11015 11016The '``fpext``' instruction takes a :ref:`floating-point <t_floating>` 11017``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it 11018to. The source type must be smaller than the destination type. 11019 11020Semantics: 11021"""""""""" 11022 11023The '``fpext``' instruction extends the ``value`` from a smaller 11024:ref:`floating-point <t_floating>` type to a larger :ref:`floating-point 11025<t_floating>` type. The ``fpext`` cannot be used to make a 11026*no-op cast* because it always changes bits. Use ``bitcast`` to make a 11027*no-op cast* for a floating-point cast. 11028 11029Example: 11030"""""""" 11031 11032.. code-block:: llvm 11033 11034 %X = fpext float 3.125 to double ; yields double:3.125000e+00 11035 %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000 11036 11037'``fptoui .. to``' Instruction 11038^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11039 11040Syntax: 11041""""""" 11042 11043:: 11044 11045 <result> = fptoui <ty> <value> to <ty2> ; yields ty2 11046 11047Overview: 11048""""""""" 11049 11050The '``fptoui``' converts a floating-point ``value`` to its unsigned 11051integer equivalent of type ``ty2``. 11052 11053Arguments: 11054"""""""""" 11055 11056The '``fptoui``' instruction takes a value to cast, which must be a 11057scalar or vector :ref:`floating-point <t_floating>` value, and a type to 11058cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If 11059``ty`` is a vector floating-point type, ``ty2`` must be a vector integer 11060type with the same number of elements as ``ty`` 11061 11062Semantics: 11063"""""""""" 11064 11065The '``fptoui``' instruction converts its :ref:`floating-point 11066<t_floating>` operand into the nearest (rounding towards zero) 11067unsigned integer value. If the value cannot fit in ``ty2``, the result 11068is a :ref:`poison value <poisonvalues>`. 11069 11070Example: 11071"""""""" 11072 11073.. code-block:: llvm 11074 11075 %X = fptoui double 123.0 to i32 ; yields i32:123 11076 %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1 11077 %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1 11078 11079'``fptosi .. to``' Instruction 11080^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11081 11082Syntax: 11083""""""" 11084 11085:: 11086 11087 <result> = fptosi <ty> <value> to <ty2> ; yields ty2 11088 11089Overview: 11090""""""""" 11091 11092The '``fptosi``' instruction converts :ref:`floating-point <t_floating>` 11093``value`` to type ``ty2``. 11094 11095Arguments: 11096"""""""""" 11097 11098The '``fptosi``' instruction takes a value to cast, which must be a 11099scalar or vector :ref:`floating-point <t_floating>` value, and a type to 11100cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If 11101``ty`` is a vector floating-point type, ``ty2`` must be a vector integer 11102type with the same number of elements as ``ty`` 11103 11104Semantics: 11105"""""""""" 11106 11107The '``fptosi``' instruction converts its :ref:`floating-point 11108<t_floating>` operand into the nearest (rounding towards zero) 11109signed integer value. If the value cannot fit in ``ty2``, the result 11110is a :ref:`poison value <poisonvalues>`. 11111 11112Example: 11113"""""""" 11114 11115.. code-block:: llvm 11116 11117 %X = fptosi double -123.0 to i32 ; yields i32:-123 11118 %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1 11119 %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1 11120 11121'``uitofp .. to``' Instruction 11122^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11123 11124Syntax: 11125""""""" 11126 11127:: 11128 11129 <result> = uitofp <ty> <value> to <ty2> ; yields ty2 11130 11131Overview: 11132""""""""" 11133 11134The '``uitofp``' instruction regards ``value`` as an unsigned integer 11135and converts that value to the ``ty2`` type. 11136 11137Arguments: 11138"""""""""" 11139 11140The '``uitofp``' instruction takes a value to cast, which must be a 11141scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to 11142``ty2``, which must be an :ref:`floating-point <t_floating>` type. If 11143``ty`` is a vector integer type, ``ty2`` must be a vector floating-point 11144type with the same number of elements as ``ty`` 11145 11146Semantics: 11147"""""""""" 11148 11149The '``uitofp``' instruction interprets its operand as an unsigned 11150integer quantity and converts it to the corresponding floating-point 11151value. If the value cannot be exactly represented, it is rounded using 11152the default rounding mode. 11153 11154 11155Example: 11156"""""""" 11157 11158.. code-block:: llvm 11159 11160 %X = uitofp i32 257 to float ; yields float:257.0 11161 %Y = uitofp i8 -1 to double ; yields double:255.0 11162 11163'``sitofp .. to``' Instruction 11164^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11165 11166Syntax: 11167""""""" 11168 11169:: 11170 11171 <result> = sitofp <ty> <value> to <ty2> ; yields ty2 11172 11173Overview: 11174""""""""" 11175 11176The '``sitofp``' instruction regards ``value`` as a signed integer and 11177converts that value to the ``ty2`` type. 11178 11179Arguments: 11180"""""""""" 11181 11182The '``sitofp``' instruction takes a value to cast, which must be a 11183scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to 11184``ty2``, which must be an :ref:`floating-point <t_floating>` type. If 11185``ty`` is a vector integer type, ``ty2`` must be a vector floating-point 11186type with the same number of elements as ``ty`` 11187 11188Semantics: 11189"""""""""" 11190 11191The '``sitofp``' instruction interprets its operand as a signed integer 11192quantity and converts it to the corresponding floating-point value. If the 11193value cannot be exactly represented, it is rounded using the default rounding 11194mode. 11195 11196Example: 11197"""""""" 11198 11199.. code-block:: llvm 11200 11201 %X = sitofp i32 257 to float ; yields float:257.0 11202 %Y = sitofp i8 -1 to double ; yields double:-1.0 11203 11204.. _i_ptrtoint: 11205 11206'``ptrtoint .. to``' Instruction 11207^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11208 11209Syntax: 11210""""""" 11211 11212:: 11213 11214 <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2 11215 11216Overview: 11217""""""""" 11218 11219The '``ptrtoint``' instruction converts the pointer or a vector of 11220pointers ``value`` to the integer (or vector of integers) type ``ty2``. 11221 11222Arguments: 11223"""""""""" 11224 11225The '``ptrtoint``' instruction takes a ``value`` to cast, which must be 11226a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a 11227type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or 11228a vector of integers type. 11229 11230Semantics: 11231"""""""""" 11232 11233The '``ptrtoint``' instruction converts ``value`` to integer type 11234``ty2`` by interpreting the pointer value as an integer and either 11235truncating or zero extending that value to the size of the integer type. 11236If ``value`` is smaller than ``ty2`` then a zero extension is done. If 11237``value`` is larger than ``ty2`` then a truncation is done. If they are 11238the same size, then nothing is done (*no-op cast*) other than a type 11239change. 11240 11241Example: 11242"""""""" 11243 11244.. code-block:: llvm 11245 11246 %X = ptrtoint ptr %P to i8 ; yields truncation on 32-bit architecture 11247 %Y = ptrtoint ptr %P to i64 ; yields zero extension on 32-bit architecture 11248 %Z = ptrtoint <4 x ptr> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture 11249 11250.. _i_inttoptr: 11251 11252'``inttoptr .. to``' Instruction 11253^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11254 11255Syntax: 11256""""""" 11257 11258:: 11259 11260 <result> = inttoptr <ty> <value> to <ty2>[, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>] ; yields ty2 11261 11262Overview: 11263""""""""" 11264 11265The '``inttoptr``' instruction converts an integer ``value`` to a 11266pointer type, ``ty2``. 11267 11268Arguments: 11269"""""""""" 11270 11271The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to 11272cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>` 11273type. 11274 11275The optional ``!dereferenceable`` metadata must reference a single metadata 11276name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64`` 11277entry. 11278See ``dereferenceable`` metadata. 11279 11280The optional ``!dereferenceable_or_null`` metadata must reference a single 11281metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one 11282``i64`` entry. 11283See ``dereferenceable_or_null`` metadata. 11284 11285Semantics: 11286"""""""""" 11287 11288The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by 11289applying either a zero extension or a truncation depending on the size 11290of the integer ``value``. If ``value`` is larger than the size of a 11291pointer then a truncation is done. If ``value`` is smaller than the size 11292of a pointer then a zero extension is done. If they are the same size, 11293nothing is done (*no-op cast*). 11294 11295Example: 11296"""""""" 11297 11298.. code-block:: llvm 11299 11300 %X = inttoptr i32 255 to ptr ; yields zero extension on 64-bit architecture 11301 %Y = inttoptr i32 255 to ptr ; yields no-op on 32-bit architecture 11302 %Z = inttoptr i64 0 to ptr ; yields truncation on 32-bit architecture 11303 %Z = inttoptr <4 x i32> %G to <4 x ptr>; yields truncation of vector G to four pointers 11304 11305.. _i_bitcast: 11306 11307'``bitcast .. to``' Instruction 11308^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11309 11310Syntax: 11311""""""" 11312 11313:: 11314 11315 <result> = bitcast <ty> <value> to <ty2> ; yields ty2 11316 11317Overview: 11318""""""""" 11319 11320The '``bitcast``' instruction converts ``value`` to type ``ty2`` without 11321changing any bits. 11322 11323Arguments: 11324"""""""""" 11325 11326The '``bitcast``' instruction takes a value to cast, which must be a 11327non-aggregate first class value, and a type to cast it to, which must 11328also be a non-aggregate :ref:`first class <t_firstclass>` type. The 11329bit sizes of ``value`` and the destination type, ``ty2``, must be 11330identical. If the source type is a pointer, the destination type must 11331also be a pointer of the same size. This instruction supports bitwise 11332conversion of vectors to integers and to vectors of other types (as 11333long as they have the same size). 11334 11335Semantics: 11336"""""""""" 11337 11338The '``bitcast``' instruction converts ``value`` to type ``ty2``. It 11339is always a *no-op cast* because no bits change with this 11340conversion. The conversion is done as if the ``value`` had been stored 11341to memory and read back as type ``ty2``. Pointer (or vector of 11342pointers) types may only be converted to other pointer (or vector of 11343pointers) types with the same address space through this instruction. 11344To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>` 11345or :ref:`ptrtoint <i_ptrtoint>` instructions first. 11346 11347There is a caveat for bitcasts involving vector types in relation to 11348endianess. For example ``bitcast <2 x i8> <value> to i16`` puts element zero 11349of the vector in the least significant bits of the i16 for little-endian while 11350element zero ends up in the most significant bits for big-endian. 11351 11352Example: 11353"""""""" 11354 11355.. code-block:: text 11356 11357 %X = bitcast i8 255 to i8 ; yields i8 :-1 11358 %Y = bitcast i32* %x to i16* ; yields i16*:%x 11359 %Z = bitcast <2 x i32> %V to i64; ; yields i64: %V (depends on endianess) 11360 %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*> 11361 11362.. _i_addrspacecast: 11363 11364'``addrspacecast .. to``' Instruction 11365^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11366 11367Syntax: 11368""""""" 11369 11370:: 11371 11372 <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2 11373 11374Overview: 11375""""""""" 11376 11377The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in 11378address space ``n`` to type ``pty2`` in address space ``m``. 11379 11380Arguments: 11381"""""""""" 11382 11383The '``addrspacecast``' instruction takes a pointer or vector of pointer value 11384to cast and a pointer type to cast it to, which must have a different 11385address space. 11386 11387Semantics: 11388"""""""""" 11389 11390The '``addrspacecast``' instruction converts the pointer value 11391``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex 11392value modification, depending on the target and the address space 11393pair. Pointer conversions within the same address space must be 11394performed with the ``bitcast`` instruction. Note that if the address 11395space conversion produces a dereferenceable result then both result 11396and operand refer to the same memory location. The conversion must 11397have no side effects, and must not capture the value of the pointer. 11398 11399If the source is :ref:`poison <poisonvalues>`, the result is 11400:ref:`poison <poisonvalues>`. 11401 11402If the source is not :ref:`poison <poisonvalues>`, and both source and 11403destination are :ref:`integral pointers <nointptrtype>`, and the 11404result pointer is dereferenceable, the cast is assumed to be 11405reversible (i.e. casting the result back to the original address space 11406should yield the original bit pattern). 11407 11408Example: 11409"""""""" 11410 11411.. code-block:: llvm 11412 11413 %X = addrspacecast ptr %x to ptr addrspace(1) 11414 %Y = addrspacecast ptr addrspace(1) %y to ptr addrspace(2) 11415 %Z = addrspacecast <4 x ptr> %z to <4 x ptr addrspace(3)> 11416 11417.. _otherops: 11418 11419Other Operations 11420---------------- 11421 11422The instructions in this category are the "miscellaneous" instructions, 11423which defy better classification. 11424 11425.. _i_icmp: 11426 11427'``icmp``' Instruction 11428^^^^^^^^^^^^^^^^^^^^^^ 11429 11430Syntax: 11431""""""" 11432 11433:: 11434 11435 <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result 11436 11437Overview: 11438""""""""" 11439 11440The '``icmp``' instruction returns a boolean value or a vector of 11441boolean values based on comparison of its two integer, integer vector, 11442pointer, or pointer vector operands. 11443 11444Arguments: 11445"""""""""" 11446 11447The '``icmp``' instruction takes three operands. The first operand is 11448the condition code indicating the kind of comparison to perform. It is 11449not a value, just a keyword. The possible condition codes are: 11450 11451.. _icmp_md_cc: 11452 11453#. ``eq``: equal 11454#. ``ne``: not equal 11455#. ``ugt``: unsigned greater than 11456#. ``uge``: unsigned greater or equal 11457#. ``ult``: unsigned less than 11458#. ``ule``: unsigned less or equal 11459#. ``sgt``: signed greater than 11460#. ``sge``: signed greater or equal 11461#. ``slt``: signed less than 11462#. ``sle``: signed less or equal 11463 11464The remaining two arguments must be :ref:`integer <t_integer>` or 11465:ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They 11466must also be identical types. 11467 11468Semantics: 11469"""""""""" 11470 11471The '``icmp``' compares ``op1`` and ``op2`` according to the condition 11472code given as ``cond``. The comparison performed always yields either an 11473:ref:`i1 <t_integer>` or vector of ``i1`` result, as follows: 11474 11475.. _icmp_md_cc_sem: 11476 11477#. ``eq``: yields ``true`` if the operands are equal, ``false`` 11478 otherwise. No sign interpretation is necessary or performed. 11479#. ``ne``: yields ``true`` if the operands are unequal, ``false`` 11480 otherwise. No sign interpretation is necessary or performed. 11481#. ``ugt``: interprets the operands as unsigned values and yields 11482 ``true`` if ``op1`` is greater than ``op2``. 11483#. ``uge``: interprets the operands as unsigned values and yields 11484 ``true`` if ``op1`` is greater than or equal to ``op2``. 11485#. ``ult``: interprets the operands as unsigned values and yields 11486 ``true`` if ``op1`` is less than ``op2``. 11487#. ``ule``: interprets the operands as unsigned values and yields 11488 ``true`` if ``op1`` is less than or equal to ``op2``. 11489#. ``sgt``: interprets the operands as signed values and yields ``true`` 11490 if ``op1`` is greater than ``op2``. 11491#. ``sge``: interprets the operands as signed values and yields ``true`` 11492 if ``op1`` is greater than or equal to ``op2``. 11493#. ``slt``: interprets the operands as signed values and yields ``true`` 11494 if ``op1`` is less than ``op2``. 11495#. ``sle``: interprets the operands as signed values and yields ``true`` 11496 if ``op1`` is less than or equal to ``op2``. 11497 11498If the operands are :ref:`pointer <t_pointer>` typed, the pointer values 11499are compared as if they were integers. 11500 11501If the operands are integer vectors, then they are compared element by 11502element. The result is an ``i1`` vector with the same number of elements 11503as the values being compared. Otherwise, the result is an ``i1``. 11504 11505Example: 11506"""""""" 11507 11508.. code-block:: text 11509 11510 <result> = icmp eq i32 4, 5 ; yields: result=false 11511 <result> = icmp ne ptr %X, %X ; yields: result=false 11512 <result> = icmp ult i16 4, 5 ; yields: result=true 11513 <result> = icmp sgt i16 4, 5 ; yields: result=false 11514 <result> = icmp ule i16 -4, 5 ; yields: result=false 11515 <result> = icmp sge i16 4, 5 ; yields: result=false 11516 11517.. _i_fcmp: 11518 11519'``fcmp``' Instruction 11520^^^^^^^^^^^^^^^^^^^^^^ 11521 11522Syntax: 11523""""""" 11524 11525:: 11526 11527 <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result 11528 11529Overview: 11530""""""""" 11531 11532The '``fcmp``' instruction returns a boolean value or vector of boolean 11533values based on comparison of its operands. 11534 11535If the operands are floating-point scalars, then the result type is a 11536boolean (:ref:`i1 <t_integer>`). 11537 11538If the operands are floating-point vectors, then the result type is a 11539vector of boolean with the same number of elements as the operands being 11540compared. 11541 11542Arguments: 11543"""""""""" 11544 11545The '``fcmp``' instruction takes three operands. The first operand is 11546the condition code indicating the kind of comparison to perform. It is 11547not a value, just a keyword. The possible condition codes are: 11548 11549#. ``false``: no comparison, always returns false 11550#. ``oeq``: ordered and equal 11551#. ``ogt``: ordered and greater than 11552#. ``oge``: ordered and greater than or equal 11553#. ``olt``: ordered and less than 11554#. ``ole``: ordered and less than or equal 11555#. ``one``: ordered and not equal 11556#. ``ord``: ordered (no nans) 11557#. ``ueq``: unordered or equal 11558#. ``ugt``: unordered or greater than 11559#. ``uge``: unordered or greater than or equal 11560#. ``ult``: unordered or less than 11561#. ``ule``: unordered or less than or equal 11562#. ``une``: unordered or not equal 11563#. ``uno``: unordered (either nans) 11564#. ``true``: no comparison, always returns true 11565 11566*Ordered* means that neither operand is a QNAN while *unordered* means 11567that either operand may be a QNAN. 11568 11569Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point 11570<t_floating>` type or a :ref:`vector <t_vector>` of floating-point type. 11571They must have identical types. 11572 11573Semantics: 11574"""""""""" 11575 11576The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the 11577condition code given as ``cond``. If the operands are vectors, then the 11578vectors are compared element by element. Each comparison performed 11579always yields an :ref:`i1 <t_integer>` result, as follows: 11580 11581#. ``false``: always yields ``false``, regardless of operands. 11582#. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1`` 11583 is equal to ``op2``. 11584#. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1`` 11585 is greater than ``op2``. 11586#. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1`` 11587 is greater than or equal to ``op2``. 11588#. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1`` 11589 is less than ``op2``. 11590#. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1`` 11591 is less than or equal to ``op2``. 11592#. ``one``: yields ``true`` if both operands are not a QNAN and ``op1`` 11593 is not equal to ``op2``. 11594#. ``ord``: yields ``true`` if both operands are not a QNAN. 11595#. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is 11596 equal to ``op2``. 11597#. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is 11598 greater than ``op2``. 11599#. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is 11600 greater than or equal to ``op2``. 11601#. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is 11602 less than ``op2``. 11603#. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is 11604 less than or equal to ``op2``. 11605#. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is 11606 not equal to ``op2``. 11607#. ``uno``: yields ``true`` if either operand is a QNAN. 11608#. ``true``: always yields ``true``, regardless of operands. 11609 11610The ``fcmp`` instruction can also optionally take any number of 11611:ref:`fast-math flags <fastmath>`, which are optimization hints to enable 11612otherwise unsafe floating-point optimizations. 11613 11614Any set of fast-math flags are legal on an ``fcmp`` instruction, but the 11615only flags that have any effect on its semantics are those that allow 11616assumptions to be made about the values of input arguments; namely 11617``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information. 11618 11619Example: 11620"""""""" 11621 11622.. code-block:: text 11623 11624 <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false 11625 <result> = fcmp one float 4.0, 5.0 ; yields: result=true 11626 <result> = fcmp olt float 4.0, 5.0 ; yields: result=true 11627 <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false 11628 11629.. _i_phi: 11630 11631'``phi``' Instruction 11632^^^^^^^^^^^^^^^^^^^^^ 11633 11634Syntax: 11635""""""" 11636 11637:: 11638 11639 <result> = phi [fast-math-flags] <ty> [ <val0>, <label0>], ... 11640 11641Overview: 11642""""""""" 11643 11644The '``phi``' instruction is used to implement the φ node in the SSA 11645graph representing the function. 11646 11647Arguments: 11648"""""""""" 11649 11650The type of the incoming values is specified with the first type field. 11651After this, the '``phi``' instruction takes a list of pairs as 11652arguments, with one pair for each predecessor basic block of the current 11653block. Only values of :ref:`first class <t_firstclass>` type may be used as 11654the value arguments to the PHI node. Only labels may be used as the 11655label arguments. 11656 11657There must be no non-phi instructions between the start of a basic block 11658and the PHI instructions: i.e. PHI instructions must be first in a basic 11659block. 11660 11661For the purposes of the SSA form, the use of each incoming value is 11662deemed to occur on the edge from the corresponding predecessor block to 11663the current block (but after any definition of an '``invoke``' 11664instruction's return value on the same edge). 11665 11666The optional ``fast-math-flags`` marker indicates that the phi has one 11667or more :ref:`fast-math-flags <fastmath>`. These are optimization hints 11668to enable otherwise unsafe floating-point optimizations. Fast-math-flags 11669are only valid for phis that return a floating-point scalar or vector 11670type, or an array (nested to any depth) of floating-point scalar or vector 11671types. 11672 11673Semantics: 11674"""""""""" 11675 11676At runtime, the '``phi``' instruction logically takes on the value 11677specified by the pair corresponding to the predecessor basic block that 11678executed just prior to the current block. 11679 11680Example: 11681"""""""" 11682 11683.. code-block:: llvm 11684 11685 Loop: ; Infinite loop that counts from 0 on up... 11686 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ] 11687 %nextindvar = add i32 %indvar, 1 11688 br label %Loop 11689 11690.. _i_select: 11691 11692'``select``' Instruction 11693^^^^^^^^^^^^^^^^^^^^^^^^ 11694 11695Syntax: 11696""""""" 11697 11698:: 11699 11700 <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty 11701 11702 selty is either i1 or {<N x i1>} 11703 11704Overview: 11705""""""""" 11706 11707The '``select``' instruction is used to choose one value based on a 11708condition, without IR-level branching. 11709 11710Arguments: 11711"""""""""" 11712 11713The '``select``' instruction requires an 'i1' value or a vector of 'i1' 11714values indicating the condition, and two values of the same :ref:`first 11715class <t_firstclass>` type. 11716 11717#. The optional ``fast-math flags`` marker indicates that the select has one or more 11718 :ref:`fast-math flags <fastmath>`. These are optimization hints to enable 11719 otherwise unsafe floating-point optimizations. Fast-math flags are only valid 11720 for selects that return a floating-point scalar or vector type, or an array 11721 (nested to any depth) of floating-point scalar or vector types. 11722 11723Semantics: 11724"""""""""" 11725 11726If the condition is an i1 and it evaluates to 1, the instruction returns 11727the first value argument; otherwise, it returns the second value 11728argument. 11729 11730If the condition is a vector of i1, then the value arguments must be 11731vectors of the same size, and the selection is done element by element. 11732 11733If the condition is an i1 and the value arguments are vectors of the 11734same size, then an entire vector is selected. 11735 11736Example: 11737"""""""" 11738 11739.. code-block:: llvm 11740 11741 %X = select i1 true, i8 17, i8 42 ; yields i8:17 11742 11743 11744.. _i_freeze: 11745 11746'``freeze``' Instruction 11747^^^^^^^^^^^^^^^^^^^^^^^^ 11748 11749Syntax: 11750""""""" 11751 11752:: 11753 11754 <result> = freeze ty <val> ; yields ty:result 11755 11756Overview: 11757""""""""" 11758 11759The '``freeze``' instruction is used to stop propagation of 11760:ref:`undef <undefvalues>` and :ref:`poison <poisonvalues>` values. 11761 11762Arguments: 11763"""""""""" 11764 11765The '``freeze``' instruction takes a single argument. 11766 11767Semantics: 11768"""""""""" 11769 11770If the argument is ``undef`` or ``poison``, '``freeze``' returns an 11771arbitrary, but fixed, value of type '``ty``'. 11772Otherwise, this instruction is a no-op and returns the input argument. 11773All uses of a value returned by the same '``freeze``' instruction are 11774guaranteed to always observe the same value, while different '``freeze``' 11775instructions may yield different values. 11776 11777While ``undef`` and ``poison`` pointers can be frozen, the result is a 11778non-dereferenceable pointer. See the 11779:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more information. 11780If an aggregate value or vector is frozen, the operand is frozen element-wise. 11781The padding of an aggregate isn't considered, since it isn't visible 11782without storing it into memory and loading it with a different type. 11783 11784 11785Example: 11786"""""""" 11787 11788.. code-block:: text 11789 11790 %w = i32 undef 11791 %x = freeze i32 %w 11792 %y = add i32 %w, %w ; undef 11793 %z = add i32 %x, %x ; even number because all uses of %x observe 11794 ; the same value 11795 %x2 = freeze i32 %w 11796 %cmp = icmp eq i32 %x, %x2 ; can be true or false 11797 11798 ; example with vectors 11799 %v = <2 x i32> <i32 undef, i32 poison> 11800 %a = extractelement <2 x i32> %v, i32 0 ; undef 11801 %b = extractelement <2 x i32> %v, i32 1 ; poison 11802 %add = add i32 %a, %a ; undef 11803 11804 %v.fr = freeze <2 x i32> %v ; element-wise freeze 11805 %d = extractelement <2 x i32> %v.fr, i32 0 ; not undef 11806 %add.f = add i32 %d, %d ; even number 11807 11808 ; branching on frozen value 11809 %poison = add nsw i1 %k, undef ; poison 11810 %c = freeze i1 %poison 11811 br i1 %c, label %foo, label %bar ; non-deterministic branch to %foo or %bar 11812 11813 11814.. _i_call: 11815 11816'``call``' Instruction 11817^^^^^^^^^^^^^^^^^^^^^^ 11818 11819Syntax: 11820""""""" 11821 11822:: 11823 11824 <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] [addrspace(<num>)] 11825 <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] [ operand bundles ] 11826 11827Overview: 11828""""""""" 11829 11830The '``call``' instruction represents a simple function call. 11831 11832Arguments: 11833"""""""""" 11834 11835This instruction requires several arguments: 11836 11837#. The optional ``tail`` and ``musttail`` markers indicate that the optimizers 11838 should perform tail call optimization. The ``tail`` marker is a hint that 11839 `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker 11840 means that the call must be tail call optimized in order for the program to 11841 be correct. This is true even in the presence of attributes like 11842 "disable-tail-calls". The ``musttail`` marker provides these guarantees: 11843 11844 #. The call will not cause unbounded stack growth if it is part of a 11845 recursive cycle in the call graph. 11846 #. Arguments with the :ref:`inalloca <attr_inalloca>` or 11847 :ref:`preallocated <attr_preallocated>` attribute are forwarded in place. 11848 #. If the musttail call appears in a function with the ``"thunk"`` attribute 11849 and the caller and callee both have varargs, than any unprototyped 11850 arguments in register or memory are forwarded to the callee. Similarly, 11851 the return value of the callee is returned to the caller's caller, even 11852 if a void return type is in use. 11853 11854 Both markers imply that the callee does not access allocas from the caller. 11855 The ``tail`` marker additionally implies that the callee does not access 11856 varargs from the caller. Calls marked ``musttail`` must obey the following 11857 additional rules: 11858 11859 - The call must immediately precede a :ref:`ret <i_ret>` instruction, 11860 or a pointer bitcast followed by a ret instruction. 11861 - The ret instruction must return the (possibly bitcasted) value 11862 produced by the call, undef, or void. 11863 - The calling conventions of the caller and callee must match. 11864 - The callee must be varargs iff the caller is varargs. Bitcasting a 11865 non-varargs function to the appropriate varargs type is legal so 11866 long as the non-varargs prefixes obey the other rules. 11867 - The return type must not undergo automatic conversion to an `sret` pointer. 11868 11869 In addition, if the calling convention is not `swifttailcc` or `tailcc`: 11870 11871 - All ABI-impacting function attributes, such as sret, byval, inreg, 11872 returned, and inalloca, must match. 11873 - The caller and callee prototypes must match. Pointer types of parameters 11874 or return types may differ in pointee type, but not in address space. 11875 11876 On the other hand, if the calling convention is `swifttailcc` or `swiftcc`: 11877 11878 - Only these ABI-impacting attributes attributes are allowed: sret, byval, 11879 swiftself, and swiftasync. 11880 - Prototypes are not required to match. 11881 11882 Tail call optimization for calls marked ``tail`` is guaranteed to occur if 11883 the following conditions are met: 11884 11885 - Caller and callee both have the calling convention ``fastcc`` or ``tailcc``. 11886 - The call is in tail position (ret immediately follows call and ret 11887 uses value of call or is void). 11888 - Option ``-tailcallopt`` is enabled, 11889 ``llvm::GuaranteedTailCallOpt`` is ``true``, or the calling convention 11890 is ``tailcc`` 11891 - `Platform-specific constraints are 11892 met. <CodeGenerator.html#tailcallopt>`_ 11893 11894#. The optional ``notail`` marker indicates that the optimizers should not add 11895 ``tail`` or ``musttail`` markers to the call. It is used to prevent tail 11896 call optimization from being performed on the call. 11897 11898#. The optional ``fast-math flags`` marker indicates that the call has one or more 11899 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable 11900 otherwise unsafe floating-point optimizations. Fast-math flags are only valid 11901 for calls that return a floating-point scalar or vector type, or an array 11902 (nested to any depth) of floating-point scalar or vector types. 11903 11904#. The optional "cconv" marker indicates which :ref:`calling 11905 convention <callingconv>` the call should use. If none is 11906 specified, the call defaults to using C calling conventions. The 11907 calling convention of the call must match the calling convention of 11908 the target function, or else the behavior is undefined. 11909#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 11910 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 11911 are valid here. 11912#. The optional addrspace attribute can be used to indicate the address space 11913 of the called function. If it is not specified, the program address space 11914 from the :ref:`datalayout string<langref_datalayout>` will be used. 11915#. '``ty``': the type of the call instruction itself which is also the 11916 type of the return value. Functions that return no value are marked 11917 ``void``. 11918#. '``fnty``': shall be the signature of the function being called. The 11919 argument types must match the types implied by this signature. This 11920 type can be omitted if the function is not varargs. 11921#. '``fnptrval``': An LLVM value containing a pointer to a function to 11922 be called. In most cases, this is a direct function call, but 11923 indirect ``call``'s are just as possible, calling an arbitrary pointer 11924 to function value. 11925#. '``function args``': argument list whose types match the function 11926 signature argument types and parameter attributes. All arguments must 11927 be of :ref:`first class <t_firstclass>` type. If the function signature 11928 indicates the function accepts a variable number of arguments, the 11929 extra arguments can be specified. 11930#. The optional :ref:`function attributes <fnattrs>` list. 11931#. The optional :ref:`operand bundles <opbundles>` list. 11932 11933Semantics: 11934"""""""""" 11935 11936The '``call``' instruction is used to cause control flow to transfer to 11937a specified function, with its incoming arguments bound to the specified 11938values. Upon a '``ret``' instruction in the called function, control 11939flow continues with the instruction after the function call, and the 11940return value of the function is bound to the result argument. 11941 11942Example: 11943"""""""" 11944 11945.. code-block:: llvm 11946 11947 %retval = call i32 @test(i32 %argc) 11948 call i32 (ptr, ...) @printf(ptr %msg, i32 12, i8 42) ; yields i32 11949 %X = tail call i32 @foo() ; yields i32 11950 %Y = tail call fastcc i32 @foo() ; yields i32 11951 call void %foo(i8 signext 97) 11952 11953 %struct.A = type { i32, i8 } 11954 %r = call %struct.A @foo() ; yields { i32, i8 } 11955 %gr = extractvalue %struct.A %r, 0 ; yields i32 11956 %gr1 = extractvalue %struct.A %r, 1 ; yields i8 11957 %Z = call void @foo() noreturn ; indicates that %foo never returns normally 11958 %ZZ = call zeroext i32 @bar() ; Return value is %zero extended 11959 11960llvm treats calls to some functions with names and arguments that match 11961the standard C99 library as being the C99 library functions, and may 11962perform optimizations or generate code for them under that assumption. 11963This is something we'd like to change in the future to provide better 11964support for freestanding environments and non-C-based languages. 11965 11966.. _i_va_arg: 11967 11968'``va_arg``' Instruction 11969^^^^^^^^^^^^^^^^^^^^^^^^ 11970 11971Syntax: 11972""""""" 11973 11974:: 11975 11976 <resultval> = va_arg <va_list*> <arglist>, <argty> 11977 11978Overview: 11979""""""""" 11980 11981The '``va_arg``' instruction is used to access arguments passed through 11982the "variable argument" area of a function call. It is used to implement 11983the ``va_arg`` macro in C. 11984 11985Arguments: 11986"""""""""" 11987 11988This instruction takes a ``va_list*`` value and the type of the 11989argument. It returns a value of the specified argument type and 11990increments the ``va_list`` to point to the next argument. The actual 11991type of ``va_list`` is target specific. 11992 11993Semantics: 11994"""""""""" 11995 11996The '``va_arg``' instruction loads an argument of the specified type 11997from the specified ``va_list`` and causes the ``va_list`` to point to 11998the next argument. For more information, see the variable argument 11999handling :ref:`Intrinsic Functions <int_varargs>`. 12000 12001It is legal for this instruction to be called in a function which does 12002not take a variable number of arguments, for example, the ``vfprintf`` 12003function. 12004 12005``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic 12006function <intrinsics>` because it takes a type as an argument. 12007 12008Example: 12009"""""""" 12010 12011See the :ref:`variable argument processing <int_varargs>` section. 12012 12013Note that the code generator does not yet fully support va\_arg on many 12014targets. Also, it does not currently support va\_arg with aggregate 12015types on any target. 12016 12017.. _i_landingpad: 12018 12019'``landingpad``' Instruction 12020^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12021 12022Syntax: 12023""""""" 12024 12025:: 12026 12027 <resultval> = landingpad <resultty> <clause>+ 12028 <resultval> = landingpad <resultty> cleanup <clause>* 12029 12030 <clause> := catch <type> <value> 12031 <clause> := filter <array constant type> <array constant> 12032 12033Overview: 12034""""""""" 12035 12036The '``landingpad``' instruction is used by `LLVM's exception handling 12037system <ExceptionHandling.html#overview>`_ to specify that a basic block 12038is a landing pad --- one where the exception lands, and corresponds to the 12039code found in the ``catch`` portion of a ``try``/``catch`` sequence. It 12040defines values supplied by the :ref:`personality function <personalityfn>` upon 12041re-entry to the function. The ``resultval`` has the type ``resultty``. 12042 12043Arguments: 12044"""""""""" 12045 12046The optional 12047``cleanup`` flag indicates that the landing pad block is a cleanup. 12048 12049A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and 12050contains the global variable representing the "type" that may be caught 12051or filtered respectively. Unlike the ``catch`` clause, the ``filter`` 12052clause takes an array constant as its argument. Use 12053"``[0 x ptr] undef``" for a filter which cannot throw. The 12054'``landingpad``' instruction must contain *at least* one ``clause`` or 12055the ``cleanup`` flag. 12056 12057Semantics: 12058"""""""""" 12059 12060The '``landingpad``' instruction defines the values which are set by the 12061:ref:`personality function <personalityfn>` upon re-entry to the function, and 12062therefore the "result type" of the ``landingpad`` instruction. As with 12063calling conventions, how the personality function results are 12064represented in LLVM IR is target specific. 12065 12066The clauses are applied in order from top to bottom. If two 12067``landingpad`` instructions are merged together through inlining, the 12068clauses from the calling function are appended to the list of clauses. 12069When the call stack is being unwound due to an exception being thrown, 12070the exception is compared against each ``clause`` in turn. If it doesn't 12071match any of the clauses, and the ``cleanup`` flag is not set, then 12072unwinding continues further up the call stack. 12073 12074The ``landingpad`` instruction has several restrictions: 12075 12076- A landing pad block is a basic block which is the unwind destination 12077 of an '``invoke``' instruction. 12078- A landing pad block must have a '``landingpad``' instruction as its 12079 first non-PHI instruction. 12080- There can be only one '``landingpad``' instruction within the landing 12081 pad block. 12082- A basic block that is not a landing pad block may not include a 12083 '``landingpad``' instruction. 12084 12085Example: 12086"""""""" 12087 12088.. code-block:: llvm 12089 12090 ;; A landing pad which can catch an integer. 12091 %res = landingpad { ptr, i32 } 12092 catch ptr @_ZTIi 12093 ;; A landing pad that is a cleanup. 12094 %res = landingpad { ptr, i32 } 12095 cleanup 12096 ;; A landing pad which can catch an integer and can only throw a double. 12097 %res = landingpad { ptr, i32 } 12098 catch ptr @_ZTIi 12099 filter [1 x ptr] [ptr @_ZTId] 12100 12101.. _i_catchpad: 12102 12103'``catchpad``' Instruction 12104^^^^^^^^^^^^^^^^^^^^^^^^^^ 12105 12106Syntax: 12107""""""" 12108 12109:: 12110 12111 <resultval> = catchpad within <catchswitch> [<args>*] 12112 12113Overview: 12114""""""""" 12115 12116The '``catchpad``' instruction is used by `LLVM's exception handling 12117system <ExceptionHandling.html#overview>`_ to specify that a basic block 12118begins a catch handler --- one where a personality routine attempts to transfer 12119control to catch an exception. 12120 12121Arguments: 12122"""""""""" 12123 12124The ``catchswitch`` operand must always be a token produced by a 12125:ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This 12126ensures that each ``catchpad`` has exactly one predecessor block, and it always 12127terminates in a ``catchswitch``. 12128 12129The ``args`` correspond to whatever information the personality routine 12130requires to know if this is an appropriate handler for the exception. Control 12131will transfer to the ``catchpad`` if this is the first appropriate handler for 12132the exception. 12133 12134The ``resultval`` has the type :ref:`token <t_token>` and is used to match the 12135``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH 12136pads. 12137 12138Semantics: 12139"""""""""" 12140 12141When the call stack is being unwound due to an exception being thrown, the 12142exception is compared against the ``args``. If it doesn't match, control will 12143not reach the ``catchpad`` instruction. The representation of ``args`` is 12144entirely target and personality function-specific. 12145 12146Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad`` 12147instruction must be the first non-phi of its parent basic block. 12148 12149The meaning of the tokens produced and consumed by ``catchpad`` and other "pad" 12150instructions is described in the 12151`Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_. 12152 12153When a ``catchpad`` has been "entered" but not yet "exited" (as 12154described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 12155it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 12156that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`. 12157 12158Example: 12159"""""""" 12160 12161.. code-block:: text 12162 12163 dispatch: 12164 %cs = catchswitch within none [label %handler0] unwind to caller 12165 ;; A catch block which can catch an integer. 12166 handler0: 12167 %tok = catchpad within %cs [ptr @_ZTIi] 12168 12169.. _i_cleanuppad: 12170 12171'``cleanuppad``' Instruction 12172^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12173 12174Syntax: 12175""""""" 12176 12177:: 12178 12179 <resultval> = cleanuppad within <parent> [<args>*] 12180 12181Overview: 12182""""""""" 12183 12184The '``cleanuppad``' instruction is used by `LLVM's exception handling 12185system <ExceptionHandling.html#overview>`_ to specify that a basic block 12186is a cleanup block --- one where a personality routine attempts to 12187transfer control to run cleanup actions. 12188The ``args`` correspond to whatever additional 12189information the :ref:`personality function <personalityfn>` requires to 12190execute the cleanup. 12191The ``resultval`` has the type :ref:`token <t_token>` and is used to 12192match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`. 12193The ``parent`` argument is the token of the funclet that contains the 12194``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet, 12195this operand may be the token ``none``. 12196 12197Arguments: 12198"""""""""" 12199 12200The instruction takes a list of arbitrary values which are interpreted 12201by the :ref:`personality function <personalityfn>`. 12202 12203Semantics: 12204"""""""""" 12205 12206When the call stack is being unwound due to an exception being thrown, 12207the :ref:`personality function <personalityfn>` transfers control to the 12208``cleanuppad`` with the aid of the personality-specific arguments. 12209As with calling conventions, how the personality function results are 12210represented in LLVM IR is target specific. 12211 12212The ``cleanuppad`` instruction has several restrictions: 12213 12214- A cleanup block is a basic block which is the unwind destination of 12215 an exceptional instruction. 12216- A cleanup block must have a '``cleanuppad``' instruction as its 12217 first non-PHI instruction. 12218- There can be only one '``cleanuppad``' instruction within the 12219 cleanup block. 12220- A basic block that is not a cleanup block may not include a 12221 '``cleanuppad``' instruction. 12222 12223When a ``cleanuppad`` has been "entered" but not yet "exited" (as 12224described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 12225it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 12226that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`. 12227 12228Example: 12229"""""""" 12230 12231.. code-block:: text 12232 12233 %tok = cleanuppad within %cs [] 12234 12235.. _intrinsics: 12236 12237Intrinsic Functions 12238=================== 12239 12240LLVM supports the notion of an "intrinsic function". These functions 12241have well known names and semantics and are required to follow certain 12242restrictions. Overall, these intrinsics represent an extension mechanism 12243for the LLVM language that does not require changing all of the 12244transformations in LLVM when adding to the language (or the bitcode 12245reader/writer, the parser, etc...). 12246 12247Intrinsic function names must all start with an "``llvm.``" prefix. This 12248prefix is reserved in LLVM for intrinsic names; thus, function names may 12249not begin with this prefix. Intrinsic functions must always be external 12250functions: you cannot define the body of intrinsic functions. Intrinsic 12251functions may only be used in call or invoke instructions: it is illegal 12252to take the address of an intrinsic function. Additionally, because 12253intrinsic functions are part of the LLVM language, it is required if any 12254are added that they be documented here. 12255 12256Some intrinsic functions can be overloaded, i.e., the intrinsic 12257represents a family of functions that perform the same operation but on 12258different data types. Because LLVM can represent over 8 million 12259different integer types, overloading is used commonly to allow an 12260intrinsic function to operate on any integer type. One or more of the 12261argument types or the result type can be overloaded to accept any 12262integer type. Argument types may also be defined as exactly matching a 12263previous argument's type or the result type. This allows an intrinsic 12264function which accepts multiple arguments, but needs all of them to be 12265of the same type, to only be overloaded with respect to a single 12266argument or the result. 12267 12268Overloaded intrinsics will have the names of its overloaded argument 12269types encoded into its function name, each preceded by a period. Only 12270those types which are overloaded result in a name suffix. Arguments 12271whose type is matched against another type do not. For example, the 12272``llvm.ctpop`` function can take an integer of any width and returns an 12273integer of exactly the same integer width. This leads to a family of 12274functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and 12275``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is 12276overloaded, and only one type suffix is required. Because the argument's 12277type is matched against the return type, it does not require its own 12278name suffix. 12279 12280:ref:`Unnamed types <t_opaque>` are encoded as ``s_s``. Overloaded intrinsics 12281that depend on an unnamed type in one of its overloaded argument types get an 12282additional ``.<number>`` suffix. This allows differentiating intrinsics with 12283different unnamed types as arguments. (For example: 12284``llvm.ssa.copy.p0s_s.2(%42*)``) The number is tracked in the LLVM module and 12285it ensures unique names in the module. While linking together two modules, it is 12286still possible to get a name clash. In that case one of the names will be 12287changed by getting a new number. 12288 12289For target developers who are defining intrinsics for back-end code 12290generation, any intrinsic overloads based solely the distinction between 12291integer or floating point types should not be relied upon for correct 12292code generation. In such cases, the recommended approach for target 12293maintainers when defining intrinsics is to create separate integer and 12294FP intrinsics rather than rely on overloading. For example, if different 12295codegen is required for ``llvm.target.foo(<4 x i32>)`` and 12296``llvm.target.foo(<4 x float>)`` then these should be split into 12297different intrinsics. 12298 12299To learn how to add an intrinsic function, please see the `Extending 12300LLVM Guide <ExtendingLLVM.html>`_. 12301 12302.. _int_varargs: 12303 12304Variable Argument Handling Intrinsics 12305------------------------------------- 12306 12307Variable argument support is defined in LLVM with the 12308:ref:`va_arg <i_va_arg>` instruction and these three intrinsic 12309functions. These functions are related to the similarly named macros 12310defined in the ``<stdarg.h>`` header file. 12311 12312All of these functions operate on arguments that use a target-specific 12313value type "``va_list``". The LLVM assembly language reference manual 12314does not define what this type is, so all transformations should be 12315prepared to handle these functions regardless of the type used. 12316 12317This example shows how the :ref:`va_arg <i_va_arg>` instruction and the 12318variable argument handling intrinsic functions are used. 12319 12320.. code-block:: llvm 12321 12322 ; This struct is different for every platform. For most platforms, 12323 ; it is merely a ptr. 12324 %struct.va_list = type { ptr } 12325 12326 ; For Unix x86_64 platforms, va_list is the following struct: 12327 ; %struct.va_list = type { i32, i32, ptr, ptr } 12328 12329 define i32 @test(i32 %X, ...) { 12330 ; Initialize variable argument processing 12331 %ap = alloca %struct.va_list 12332 call void @llvm.va_start(ptr %ap) 12333 12334 ; Read a single integer argument 12335 %tmp = va_arg ptr %ap, i32 12336 12337 ; Demonstrate usage of llvm.va_copy and llvm.va_end 12338 %aq = alloca ptr 12339 call void @llvm.va_copy(ptr %aq, ptr %ap) 12340 call void @llvm.va_end(ptr %aq) 12341 12342 ; Stop processing of arguments. 12343 call void @llvm.va_end(ptr %ap) 12344 ret i32 %tmp 12345 } 12346 12347 declare void @llvm.va_start(ptr) 12348 declare void @llvm.va_copy(ptr, ptr) 12349 declare void @llvm.va_end(ptr) 12350 12351.. _int_va_start: 12352 12353'``llvm.va_start``' Intrinsic 12354^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12355 12356Syntax: 12357""""""" 12358 12359:: 12360 12361 declare void @llvm.va_start(ptr <arglist>) 12362 12363Overview: 12364""""""""" 12365 12366The '``llvm.va_start``' intrinsic initializes ``<arglist>`` for 12367subsequent use by ``va_arg``. 12368 12369Arguments: 12370"""""""""" 12371 12372The argument is a pointer to a ``va_list`` element to initialize. 12373 12374Semantics: 12375"""""""""" 12376 12377The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro 12378available in C. In a target-dependent way, it initializes the 12379``va_list`` element to which the argument points, so that the next call 12380to ``va_arg`` will produce the first variable argument passed to the 12381function. Unlike the C ``va_start`` macro, this intrinsic does not need 12382to know the last argument of the function as the compiler can figure 12383that out. 12384 12385'``llvm.va_end``' Intrinsic 12386^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12387 12388Syntax: 12389""""""" 12390 12391:: 12392 12393 declare void @llvm.va_end(ptr <arglist>) 12394 12395Overview: 12396""""""""" 12397 12398The '``llvm.va_end``' intrinsic destroys ``<arglist>``, which has been 12399initialized previously with ``llvm.va_start`` or ``llvm.va_copy``. 12400 12401Arguments: 12402"""""""""" 12403 12404The argument is a pointer to a ``va_list`` to destroy. 12405 12406Semantics: 12407"""""""""" 12408 12409The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro 12410available in C. In a target-dependent way, it destroys the ``va_list`` 12411element to which the argument points. Calls to 12412:ref:`llvm.va_start <int_va_start>` and 12413:ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to 12414``llvm.va_end``. 12415 12416.. _int_va_copy: 12417 12418'``llvm.va_copy``' Intrinsic 12419^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12420 12421Syntax: 12422""""""" 12423 12424:: 12425 12426 declare void @llvm.va_copy(ptr <destarglist>, ptr <srcarglist>) 12427 12428Overview: 12429""""""""" 12430 12431The '``llvm.va_copy``' intrinsic copies the current argument position 12432from the source argument list to the destination argument list. 12433 12434Arguments: 12435"""""""""" 12436 12437The first argument is a pointer to a ``va_list`` element to initialize. 12438The second argument is a pointer to a ``va_list`` element to copy from. 12439 12440Semantics: 12441"""""""""" 12442 12443The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro 12444available in C. In a target-dependent way, it copies the source 12445``va_list`` element into the destination ``va_list`` element. This 12446intrinsic is necessary because the `` llvm.va_start`` intrinsic may be 12447arbitrarily complex and require, for example, memory allocation. 12448 12449Accurate Garbage Collection Intrinsics 12450-------------------------------------- 12451 12452LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_ 12453(GC) requires the frontend to generate code containing appropriate intrinsic 12454calls and select an appropriate GC strategy which knows how to lower these 12455intrinsics in a manner which is appropriate for the target collector. 12456 12457These intrinsics allow identification of :ref:`GC roots on the 12458stack <int_gcroot>`, as well as garbage collector implementations that 12459require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. 12460Frontends for type-safe garbage collected languages should generate 12461these intrinsics to make use of the LLVM garbage collectors. For more 12462details, see `Garbage Collection with LLVM <GarbageCollection.html>`_. 12463 12464LLVM provides an second experimental set of intrinsics for describing garbage 12465collection safepoints in compiled code. These intrinsics are an alternative 12466to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for 12467:ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The 12468differences in approach are covered in the `Garbage Collection with LLVM 12469<GarbageCollection.html>`_ documentation. The intrinsics themselves are 12470described in :doc:`Statepoints`. 12471 12472.. _int_gcroot: 12473 12474'``llvm.gcroot``' Intrinsic 12475^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12476 12477Syntax: 12478""""""" 12479 12480:: 12481 12482 declare void @llvm.gcroot(ptr %ptrloc, ptr %metadata) 12483 12484Overview: 12485""""""""" 12486 12487The '``llvm.gcroot``' intrinsic declares the existence of a GC root to 12488the code generator, and allows some metadata to be associated with it. 12489 12490Arguments: 12491"""""""""" 12492 12493The first argument specifies the address of a stack object that contains 12494the root pointer. The second pointer (which must be either a constant or 12495a global value address) contains the meta-data to be associated with the 12496root. 12497 12498Semantics: 12499"""""""""" 12500 12501At runtime, a call to this intrinsic stores a null pointer into the 12502"ptrloc" location. At compile-time, the code generator generates 12503information to allow the runtime to find the pointer at GC safe points. 12504The '``llvm.gcroot``' intrinsic may only be used in a function which 12505:ref:`specifies a GC algorithm <gc>`. 12506 12507.. _int_gcread: 12508 12509'``llvm.gcread``' Intrinsic 12510^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12511 12512Syntax: 12513""""""" 12514 12515:: 12516 12517 declare ptr @llvm.gcread(ptr %ObjPtr, ptr %Ptr) 12518 12519Overview: 12520""""""""" 12521 12522The '``llvm.gcread``' intrinsic identifies reads of references from heap 12523locations, allowing garbage collector implementations that require read 12524barriers. 12525 12526Arguments: 12527"""""""""" 12528 12529The second argument is the address to read from, which should be an 12530address allocated from the garbage collector. The first object is a 12531pointer to the start of the referenced object, if needed by the language 12532runtime (otherwise null). 12533 12534Semantics: 12535"""""""""" 12536 12537The '``llvm.gcread``' intrinsic has the same semantics as a load 12538instruction, but may be replaced with substantially more complex code by 12539the garbage collector runtime, as needed. The '``llvm.gcread``' 12540intrinsic may only be used in a function which :ref:`specifies a GC 12541algorithm <gc>`. 12542 12543.. _int_gcwrite: 12544 12545'``llvm.gcwrite``' Intrinsic 12546^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12547 12548Syntax: 12549""""""" 12550 12551:: 12552 12553 declare void @llvm.gcwrite(ptr %P1, ptr %Obj, ptr %P2) 12554 12555Overview: 12556""""""""" 12557 12558The '``llvm.gcwrite``' intrinsic identifies writes of references to heap 12559locations, allowing garbage collector implementations that require write 12560barriers (such as generational or reference counting collectors). 12561 12562Arguments: 12563"""""""""" 12564 12565The first argument is the reference to store, the second is the start of 12566the object to store it to, and the third is the address of the field of 12567Obj to store to. If the runtime does not require a pointer to the 12568object, Obj may be null. 12569 12570Semantics: 12571"""""""""" 12572 12573The '``llvm.gcwrite``' intrinsic has the same semantics as a store 12574instruction, but may be replaced with substantially more complex code by 12575the garbage collector runtime, as needed. The '``llvm.gcwrite``' 12576intrinsic may only be used in a function which :ref:`specifies a GC 12577algorithm <gc>`. 12578 12579 12580.. _gc_statepoint: 12581 12582'``llvm.experimental.gc.statepoint``' Intrinsic 12583^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12584 12585Syntax: 12586""""""" 12587 12588:: 12589 12590 declare token 12591 @llvm.experimental.gc.statepoint(i64 <id>, i32 <num patch bytes>, 12592 ptr elementtype(func_type) <target>, 12593 i64 <#call args>, i64 <flags>, 12594 ... (call parameters), 12595 i64 0, i64 0) 12596 12597Overview: 12598""""""""" 12599 12600The statepoint intrinsic represents a call which is parse-able by the 12601runtime. 12602 12603Operands: 12604""""""""" 12605 12606The 'id' operand is a constant integer that is reported as the ID 12607field in the generated stackmap. LLVM does not interpret this 12608parameter in any way and its meaning is up to the statepoint user to 12609decide. Note that LLVM is free to duplicate code containing 12610statepoint calls, and this may transform IR that had a unique 'id' per 12611lexical call to statepoint to IR that does not. 12612 12613If 'num patch bytes' is non-zero then the call instruction 12614corresponding to the statepoint is not emitted and LLVM emits 'num 12615patch bytes' bytes of nops in its place. LLVM will emit code to 12616prepare the function arguments and retrieve the function return value 12617in accordance to the calling convention; the former before the nop 12618sequence and the latter after the nop sequence. It is expected that 12619the user will patch over the 'num patch bytes' bytes of nops with a 12620calling sequence specific to their runtime before executing the 12621generated machine code. There are no guarantees with respect to the 12622alignment of the nop sequence. Unlike :doc:`StackMaps` statepoints do 12623not have a concept of shadow bytes. Note that semantically the 12624statepoint still represents a call or invoke to 'target', and the nop 12625sequence after patching is expected to represent an operation 12626equivalent to a call or invoke to 'target'. 12627 12628The 'target' operand is the function actually being called. The operand 12629must have an :ref:`elementtype <attr_elementtype>` attribute specifying 12630the function type of the target. The target can be specified as either 12631a symbolic LLVM function, or as an arbitrary Value of pointer type. Note 12632that the function type must match the signature of the callee and the 12633types of the 'call parameters' arguments. 12634 12635The '#call args' operand is the number of arguments to the actual 12636call. It must exactly match the number of arguments passed in the 12637'call parameters' variable length section. 12638 12639The 'flags' operand is used to specify extra information about the 12640statepoint. This is currently only used to mark certain statepoints 12641as GC transitions. This operand is a 64-bit integer with the following 12642layout, where bit 0 is the least significant bit: 12643 12644 +-------+---------------------------------------------------+ 12645 | Bit # | Usage | 12646 +=======+===================================================+ 12647 | 0 | Set if the statepoint is a GC transition, cleared | 12648 | | otherwise. | 12649 +-------+---------------------------------------------------+ 12650 | 1-63 | Reserved for future use; must be cleared. | 12651 +-------+---------------------------------------------------+ 12652 12653The 'call parameters' arguments are simply the arguments which need to 12654be passed to the call target. They will be lowered according to the 12655specified calling convention and otherwise handled like a normal call 12656instruction. The number of arguments must exactly match what is 12657specified in '# call args'. The types must match the signature of 12658'target'. 12659 12660The 'call parameter' attributes must be followed by two 'i64 0' constants. 12661These were originally the length prefixes for 'gc transition parameter' and 12662'deopt parameter' arguments, but the role of these parameter sets have been 12663entirely replaced with the corresponding operand bundles. In a future 12664revision, these now redundant arguments will be removed. 12665 12666Semantics: 12667"""""""""" 12668 12669A statepoint is assumed to read and write all memory. As a result, 12670memory operations can not be reordered past a statepoint. It is 12671illegal to mark a statepoint as being either 'readonly' or 'readnone'. 12672 12673Note that legal IR can not perform any memory operation on a 'gc 12674pointer' argument of the statepoint in a location statically reachable 12675from the statepoint. Instead, the explicitly relocated value (from a 12676``gc.relocate``) must be used. 12677 12678'``llvm.experimental.gc.result``' Intrinsic 12679^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12680 12681Syntax: 12682""""""" 12683 12684:: 12685 12686 declare type 12687 @llvm.experimental.gc.result(token %statepoint_token) 12688 12689Overview: 12690""""""""" 12691 12692``gc.result`` extracts the result of the original call instruction 12693which was replaced by the ``gc.statepoint``. The ``gc.result`` 12694intrinsic is actually a family of three intrinsics due to an 12695implementation limitation. Other than the type of the return value, 12696the semantics are the same. 12697 12698Operands: 12699""""""""" 12700 12701The first and only argument is the ``gc.statepoint`` which starts 12702the safepoint sequence of which this ``gc.result`` is a part. 12703Despite the typing of this as a generic token, *only* the value defined 12704by a ``gc.statepoint`` is legal here. 12705 12706Semantics: 12707"""""""""" 12708 12709The ``gc.result`` represents the return value of the call target of 12710the ``statepoint``. The type of the ``gc.result`` must exactly match 12711the type of the target. If the call target returns void, there will 12712be no ``gc.result``. 12713 12714A ``gc.result`` is modeled as a 'readnone' pure function. It has no 12715side effects since it is just a projection of the return value of the 12716previous call represented by the ``gc.statepoint``. 12717 12718'``llvm.experimental.gc.relocate``' Intrinsic 12719^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12720 12721Syntax: 12722""""""" 12723 12724:: 12725 12726 declare <pointer type> 12727 @llvm.experimental.gc.relocate(token %statepoint_token, 12728 i32 %base_offset, 12729 i32 %pointer_offset) 12730 12731Overview: 12732""""""""" 12733 12734A ``gc.relocate`` returns the potentially relocated value of a pointer 12735at the safepoint. 12736 12737Operands: 12738""""""""" 12739 12740The first argument is the ``gc.statepoint`` which starts the 12741safepoint sequence of which this ``gc.relocation`` is a part. 12742Despite the typing of this as a generic token, *only* the value defined 12743by a ``gc.statepoint`` is legal here. 12744 12745The second and third arguments are both indices into operands of the 12746corresponding statepoint's :ref:`gc-live <ob_gc_live>` operand bundle. 12747 12748The second argument is an index which specifies the allocation for the pointer 12749being relocated. The associated value must be within the object with which the 12750pointer being relocated is associated. The optimizer is free to change *which* 12751interior derived pointer is reported, provided that it does not replace an 12752actual base pointer with another interior derived pointer. Collectors are 12753allowed to rely on the base pointer operand remaining an actual base pointer if 12754so constructed. 12755 12756The third argument is an index which specify the (potentially) derived pointer 12757being relocated. It is legal for this index to be the same as the second 12758argument if-and-only-if a base pointer is being relocated. 12759 12760Semantics: 12761"""""""""" 12762 12763The return value of ``gc.relocate`` is the potentially relocated value 12764of the pointer specified by its arguments. It is unspecified how the 12765value of the returned pointer relates to the argument to the 12766``gc.statepoint`` other than that a) it points to the same source 12767language object with the same offset, and b) the 'based-on' 12768relationship of the newly relocated pointers is a projection of the 12769unrelocated pointers. In particular, the integer value of the pointer 12770returned is unspecified. 12771 12772A ``gc.relocate`` is modeled as a ``readnone`` pure function. It has no 12773side effects since it is just a way to extract information about work 12774done during the actual call modeled by the ``gc.statepoint``. 12775 12776.. _gc.get.pointer.base: 12777 12778'``llvm.experimental.gc.get.pointer.base``' Intrinsic 12779^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12780 12781Syntax: 12782""""""" 12783 12784:: 12785 12786 declare <pointer type> 12787 @llvm.experimental.gc.get.pointer.base( 12788 <pointer type> readnone nocapture %derived_ptr) 12789 nounwind readnone willreturn 12790 12791Overview: 12792""""""""" 12793 12794``gc.get.pointer.base`` for a derived pointer returns its base pointer. 12795 12796Operands: 12797""""""""" 12798 12799The only argument is a pointer which is based on some object with 12800an unknown offset from the base of said object. 12801 12802Semantics: 12803"""""""""" 12804 12805This intrinsic is used in the abstract machine model for GC to represent 12806the base pointer for an arbitrary derived pointer. 12807 12808This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by 12809replacing all uses of this callsite with the offset of a derived pointer from 12810its base pointer value. The replacement is done as part of the lowering to the 12811explicit statepoint model. 12812 12813The return pointer type must be the same as the type of the parameter. 12814 12815 12816'``llvm.experimental.gc.get.pointer.offset``' Intrinsic 12817^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12818 12819Syntax: 12820""""""" 12821 12822:: 12823 12824 declare i64 12825 @llvm.experimental.gc.get.pointer.offset( 12826 <pointer type> readnone nocapture %derived_ptr) 12827 nounwind readnone willreturn 12828 12829Overview: 12830""""""""" 12831 12832``gc.get.pointer.offset`` for a derived pointer returns the offset from its 12833base pointer. 12834 12835Operands: 12836""""""""" 12837 12838The only argument is a pointer which is based on some object with 12839an unknown offset from the base of said object. 12840 12841Semantics: 12842"""""""""" 12843 12844This intrinsic is used in the abstract machine model for GC to represent 12845the offset of an arbitrary derived pointer from its base pointer. 12846 12847This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by 12848replacing all uses of this callsite with the offset of a derived pointer from 12849its base pointer value. The replacement is done as part of the lowering to the 12850explicit statepoint model. 12851 12852Basically this call calculates difference between the derived pointer and its 12853base pointer (see :ref:`gc.get.pointer.base`) both ptrtoint casted. But 12854this cast done outside the :ref:`RewriteStatepointsForGC` pass could result 12855in the pointers lost for further lowering from the abstract model to the 12856explicit physical one. 12857 12858Code Generator Intrinsics 12859------------------------- 12860 12861These intrinsics are provided by LLVM to expose special features that 12862may only be implemented with code generator support. 12863 12864'``llvm.returnaddress``' Intrinsic 12865^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12866 12867Syntax: 12868""""""" 12869 12870:: 12871 12872 declare ptr @llvm.returnaddress(i32 <level>) 12873 12874Overview: 12875""""""""" 12876 12877The '``llvm.returnaddress``' intrinsic attempts to compute a 12878target-specific value indicating the return address of the current 12879function or one of its callers. 12880 12881Arguments: 12882"""""""""" 12883 12884The argument to this intrinsic indicates which function to return the 12885address for. Zero indicates the calling function, one indicates its 12886caller, etc. The argument is **required** to be a constant integer 12887value. 12888 12889Semantics: 12890"""""""""" 12891 12892The '``llvm.returnaddress``' intrinsic either returns a pointer 12893indicating the return address of the specified call frame, or zero if it 12894cannot be identified. The value returned by this intrinsic is likely to 12895be incorrect or 0 for arguments other than zero, so it should only be 12896used for debugging purposes. 12897 12898Note that calling this intrinsic does not prevent function inlining or 12899other aggressive transformations, so the value returned may not be that 12900of the obvious source-language caller. 12901 12902'``llvm.addressofreturnaddress``' Intrinsic 12903^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12904 12905Syntax: 12906""""""" 12907 12908:: 12909 12910 declare ptr @llvm.addressofreturnaddress() 12911 12912Overview: 12913""""""""" 12914 12915The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific 12916pointer to the place in the stack frame where the return address of the 12917current function is stored. 12918 12919Semantics: 12920"""""""""" 12921 12922Note that calling this intrinsic does not prevent function inlining or 12923other aggressive transformations, so the value returned may not be that 12924of the obvious source-language caller. 12925 12926This intrinsic is only implemented for x86 and aarch64. 12927 12928'``llvm.sponentry``' Intrinsic 12929^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12930 12931Syntax: 12932""""""" 12933 12934:: 12935 12936 declare ptr @llvm.sponentry() 12937 12938Overview: 12939""""""""" 12940 12941The '``llvm.sponentry``' intrinsic returns the stack pointer value at 12942the entry of the current function calling this intrinsic. 12943 12944Semantics: 12945"""""""""" 12946 12947Note this intrinsic is only verified on AArch64 and ARM. 12948 12949'``llvm.frameaddress``' Intrinsic 12950^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12951 12952Syntax: 12953""""""" 12954 12955:: 12956 12957 declare ptr @llvm.frameaddress(i32 <level>) 12958 12959Overview: 12960""""""""" 12961 12962The '``llvm.frameaddress``' intrinsic attempts to return the 12963target-specific frame pointer value for the specified stack frame. 12964 12965Arguments: 12966"""""""""" 12967 12968The argument to this intrinsic indicates which function to return the 12969frame pointer for. Zero indicates the calling function, one indicates 12970its caller, etc. The argument is **required** to be a constant integer 12971value. 12972 12973Semantics: 12974"""""""""" 12975 12976The '``llvm.frameaddress``' intrinsic either returns a pointer 12977indicating the frame address of the specified call frame, or zero if it 12978cannot be identified. The value returned by this intrinsic is likely to 12979be incorrect or 0 for arguments other than zero, so it should only be 12980used for debugging purposes. 12981 12982Note that calling this intrinsic does not prevent function inlining or 12983other aggressive transformations, so the value returned may not be that 12984of the obvious source-language caller. 12985 12986'``llvm.swift.async.context.addr``' Intrinsic 12987^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12988 12989Syntax: 12990""""""" 12991 12992:: 12993 12994 declare ptr @llvm.swift.async.context.addr() 12995 12996Overview: 12997""""""""" 12998 12999The '``llvm.swift.async.context.addr``' intrinsic returns a pointer to 13000the part of the extended frame record containing the asynchronous 13001context of a Swift execution. 13002 13003Semantics: 13004"""""""""" 13005 13006If the caller has a ``swiftasync`` parameter, that argument will initially 13007be stored at the returned address. If not, it will be initialized to null. 13008 13009'``llvm.localescape``' and '``llvm.localrecover``' Intrinsics 13010^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13011 13012Syntax: 13013""""""" 13014 13015:: 13016 13017 declare void @llvm.localescape(...) 13018 declare ptr @llvm.localrecover(ptr %func, ptr %fp, i32 %idx) 13019 13020Overview: 13021""""""""" 13022 13023The '``llvm.localescape``' intrinsic escapes offsets of a collection of static 13024allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a 13025live frame pointer to recover the address of the allocation. The offset is 13026computed during frame layout of the caller of ``llvm.localescape``. 13027 13028Arguments: 13029"""""""""" 13030 13031All arguments to '``llvm.localescape``' must be pointers to static allocas or 13032casts of static allocas. Each function can only call '``llvm.localescape``' 13033once, and it can only do so from the entry block. 13034 13035The ``func`` argument to '``llvm.localrecover``' must be a constant 13036bitcasted pointer to a function defined in the current module. The code 13037generator cannot determine the frame allocation offset of functions defined in 13038other modules. 13039 13040The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a 13041call frame that is currently live. The return value of '``llvm.localaddress``' 13042is one way to produce such a value, but various runtimes also expose a suitable 13043pointer in platform-specific ways. 13044 13045The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to 13046'``llvm.localescape``' to recover. It is zero-indexed. 13047 13048Semantics: 13049"""""""""" 13050 13051These intrinsics allow a group of functions to share access to a set of local 13052stack allocations of a one parent function. The parent function may call the 13053'``llvm.localescape``' intrinsic once from the function entry block, and the 13054child functions can use '``llvm.localrecover``' to access the escaped allocas. 13055The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where 13056the escaped allocas are allocated, which would break attempts to use 13057'``llvm.localrecover``'. 13058 13059'``llvm.seh.try.begin``' and '``llvm.seh.try.end``' Intrinsics 13060^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13061 13062Syntax: 13063""""""" 13064 13065:: 13066 13067 declare void @llvm.seh.try.begin() 13068 declare void @llvm.seh.try.end() 13069 13070Overview: 13071""""""""" 13072 13073The '``llvm.seh.try.begin``' and '``llvm.seh.try.end``' intrinsics mark 13074the boundary of a _try region for Windows SEH Asynchrous Exception Handling. 13075 13076Semantics: 13077"""""""""" 13078 13079When a C-function is compiled with Windows SEH Asynchrous Exception option, 13080-feh_asynch (aka MSVC -EHa), these two intrinsics are injected to mark _try 13081boundary and to prevent potential exceptions from being moved across boundary. 13082Any set of operations can then be confined to the region by reading their leaf 13083inputs via volatile loads and writing their root outputs via volatile stores. 13084 13085'``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' Intrinsics 13086^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13087 13088Syntax: 13089""""""" 13090 13091:: 13092 13093 declare void @llvm.seh.scope.begin() 13094 declare void @llvm.seh.scope.end() 13095 13096Overview: 13097""""""""" 13098 13099The '``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' intrinsics mark 13100the boundary of a CPP object lifetime for Windows SEH Asynchrous Exception 13101Handling (MSVC option -EHa). 13102 13103Semantics: 13104"""""""""" 13105 13106LLVM's ordinary exception-handling representation associates EH cleanups and 13107handlers only with ``invoke``s, which normally correspond only to call sites. To 13108support arbitrary faulting instructions, it must be possible to recover the current 13109EH scope for any instruction. Turning every operation in LLVM that could fault 13110into an ``invoke`` of a new, potentially-throwing intrinsic would require adding a 13111large number of intrinsics, impede optimization of those operations, and make 13112compilation slower by introducing many extra basic blocks. These intrinsics can 13113be used instead to mark the region protected by a cleanup, such as for a local 13114C++ object with a non-trivial destructor. ``llvm.seh.scope.begin`` is used to mark 13115the start of the region; it is always called with ``invoke``, with the unwind block 13116being the desired unwind destination for any potentially-throwing instructions 13117within the region. `llvm.seh.scope.end` is used to mark when the scope ends 13118and the EH cleanup is no longer required (e.g. because the destructor is being 13119called). 13120 13121.. _int_read_register: 13122.. _int_read_volatile_register: 13123.. _int_write_register: 13124 13125'``llvm.read_register``', '``llvm.read_volatile_register``', and '``llvm.write_register``' Intrinsics 13126^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13127 13128Syntax: 13129""""""" 13130 13131:: 13132 13133 declare i32 @llvm.read_register.i32(metadata) 13134 declare i64 @llvm.read_register.i64(metadata) 13135 declare i32 @llvm.read_volatile_register.i32(metadata) 13136 declare i64 @llvm.read_volatile_register.i64(metadata) 13137 declare void @llvm.write_register.i32(metadata, i32 @value) 13138 declare void @llvm.write_register.i64(metadata, i64 @value) 13139 !0 = !{!"sp\00"} 13140 13141Overview: 13142""""""""" 13143 13144The '``llvm.read_register``', '``llvm.read_volatile_register``', and 13145'``llvm.write_register``' intrinsics provide access to the named register. 13146The register must be valid on the architecture being compiled to. The type 13147needs to be compatible with the register being read. 13148 13149Semantics: 13150"""""""""" 13151 13152The '``llvm.read_register``' and '``llvm.read_volatile_register``' intrinsics 13153return the current value of the register, where possible. The 13154'``llvm.write_register``' intrinsic sets the current value of the register, 13155where possible. 13156 13157A call to '``llvm.read_volatile_register``' is assumed to have side-effects 13158and possibly return a different value each time (e.g. for a timer register). 13159 13160This is useful to implement named register global variables that need 13161to always be mapped to a specific register, as is common practice on 13162bare-metal programs including OS kernels. 13163 13164The compiler doesn't check for register availability or use of the used 13165register in surrounding code, including inline assembly. Because of that, 13166allocatable registers are not supported. 13167 13168Warning: So far it only works with the stack pointer on selected 13169architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of 13170work is needed to support other registers and even more so, allocatable 13171registers. 13172 13173.. _int_stacksave: 13174 13175'``llvm.stacksave``' Intrinsic 13176^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13177 13178Syntax: 13179""""""" 13180 13181:: 13182 13183 declare ptr @llvm.stacksave() 13184 13185Overview: 13186""""""""" 13187 13188The '``llvm.stacksave``' intrinsic is used to remember the current state 13189of the function stack, for use with 13190:ref:`llvm.stackrestore <int_stackrestore>`. This is useful for 13191implementing language features like scoped automatic variable sized 13192arrays in C99. 13193 13194Semantics: 13195"""""""""" 13196 13197This intrinsic returns an opaque pointer value that can be passed to 13198:ref:`llvm.stackrestore <int_stackrestore>`. When an 13199``llvm.stackrestore`` intrinsic is executed with a value saved from 13200``llvm.stacksave``, it effectively restores the state of the stack to 13201the state it was in when the ``llvm.stacksave`` intrinsic executed. In 13202practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that 13203were allocated after the ``llvm.stacksave`` was executed. 13204 13205.. _int_stackrestore: 13206 13207'``llvm.stackrestore``' Intrinsic 13208^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13209 13210Syntax: 13211""""""" 13212 13213:: 13214 13215 declare void @llvm.stackrestore(ptr %ptr) 13216 13217Overview: 13218""""""""" 13219 13220The '``llvm.stackrestore``' intrinsic is used to restore the state of 13221the function stack to the state it was in when the corresponding 13222:ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is 13223useful for implementing language features like scoped automatic variable 13224sized arrays in C99. 13225 13226Semantics: 13227"""""""""" 13228 13229See the description for :ref:`llvm.stacksave <int_stacksave>`. 13230 13231.. _int_get_dynamic_area_offset: 13232 13233'``llvm.get.dynamic.area.offset``' Intrinsic 13234^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13235 13236Syntax: 13237""""""" 13238 13239:: 13240 13241 declare i32 @llvm.get.dynamic.area.offset.i32() 13242 declare i64 @llvm.get.dynamic.area.offset.i64() 13243 13244Overview: 13245""""""""" 13246 13247 The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to 13248 get the offset from native stack pointer to the address of the most 13249 recent dynamic alloca on the caller's stack. These intrinsics are 13250 intended for use in combination with 13251 :ref:`llvm.stacksave <int_stacksave>` to get a 13252 pointer to the most recent dynamic alloca. This is useful, for example, 13253 for AddressSanitizer's stack unpoisoning routines. 13254 13255Semantics: 13256"""""""""" 13257 13258 These intrinsics return a non-negative integer value that can be used to 13259 get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>` 13260 on the caller's stack. In particular, for targets where stack grows downwards, 13261 adding this offset to the native stack pointer would get the address of the most 13262 recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more 13263 complicated, because subtracting this value from stack pointer would get the address 13264 one past the end of the most recent dynamic alloca. 13265 13266 Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>` 13267 returns just a zero, for others, such as PowerPC and PowerPC64, it returns a 13268 compile-time-known constant value. 13269 13270 The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>` 13271 must match the target's default address space's (address space 0) pointer type. 13272 13273'``llvm.prefetch``' Intrinsic 13274^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13275 13276Syntax: 13277""""""" 13278 13279:: 13280 13281 declare void @llvm.prefetch(ptr <address>, i32 <rw>, i32 <locality>, i32 <cache type>) 13282 13283Overview: 13284""""""""" 13285 13286The '``llvm.prefetch``' intrinsic is a hint to the code generator to 13287insert a prefetch instruction if supported; otherwise, it is a noop. 13288Prefetches have no effect on the behavior of the program but can change 13289its performance characteristics. 13290 13291Arguments: 13292"""""""""" 13293 13294``address`` is the address to be prefetched, ``rw`` is the specifier 13295determining if the fetch should be for a read (0) or write (1), and 13296``locality`` is a temporal locality specifier ranging from (0) - no 13297locality, to (3) - extremely local keep in cache. The ``cache type`` 13298specifies whether the prefetch is performed on the data (1) or 13299instruction (0) cache. The ``rw``, ``locality`` and ``cache type`` 13300arguments must be constant integers. 13301 13302Semantics: 13303"""""""""" 13304 13305This intrinsic does not modify the behavior of the program. In 13306particular, prefetches cannot trap and do not produce a value. On 13307targets that support this intrinsic, the prefetch can provide hints to 13308the processor cache for better performance. 13309 13310'``llvm.pcmarker``' Intrinsic 13311^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13312 13313Syntax: 13314""""""" 13315 13316:: 13317 13318 declare void @llvm.pcmarker(i32 <id>) 13319 13320Overview: 13321""""""""" 13322 13323The '``llvm.pcmarker``' intrinsic is a method to export a Program 13324Counter (PC) in a region of code to simulators and other tools. The 13325method is target specific, but it is expected that the marker will use 13326exported symbols to transmit the PC of the marker. The marker makes no 13327guarantees that it will remain with any specific instruction after 13328optimizations. It is possible that the presence of a marker will inhibit 13329optimizations. The intended use is to be inserted after optimizations to 13330allow correlations of simulation runs. 13331 13332Arguments: 13333"""""""""" 13334 13335``id`` is a numerical id identifying the marker. 13336 13337Semantics: 13338"""""""""" 13339 13340This intrinsic does not modify the behavior of the program. Backends 13341that do not support this intrinsic may ignore it. 13342 13343'``llvm.readcyclecounter``' Intrinsic 13344^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13345 13346Syntax: 13347""""""" 13348 13349:: 13350 13351 declare i64 @llvm.readcyclecounter() 13352 13353Overview: 13354""""""""" 13355 13356The '``llvm.readcyclecounter``' intrinsic provides access to the cycle 13357counter register (or similar low latency, high accuracy clocks) on those 13358targets that support it. On X86, it should map to RDTSC. On Alpha, it 13359should map to RPCC. As the backing counters overflow quickly (on the 13360order of 9 seconds on alpha), this should only be used for small 13361timings. 13362 13363Semantics: 13364"""""""""" 13365 13366When directly supported, reading the cycle counter should not modify any 13367memory. Implementations are allowed to either return an application 13368specific value or a system wide value. On backends without support, this 13369is lowered to a constant 0. 13370 13371Note that runtime support may be conditional on the privilege-level code is 13372running at and the host platform. 13373 13374'``llvm.clear_cache``' Intrinsic 13375^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13376 13377Syntax: 13378""""""" 13379 13380:: 13381 13382 declare void @llvm.clear_cache(ptr, ptr) 13383 13384Overview: 13385""""""""" 13386 13387The '``llvm.clear_cache``' intrinsic ensures visibility of modifications 13388in the specified range to the execution unit of the processor. On 13389targets with non-unified instruction and data cache, the implementation 13390flushes the instruction cache. 13391 13392Semantics: 13393"""""""""" 13394 13395On platforms with coherent instruction and data caches (e.g. x86), this 13396intrinsic is a nop. On platforms with non-coherent instruction and data 13397cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate 13398instructions or a system call, if cache flushing requires special 13399privileges. 13400 13401The default behavior is to emit a call to ``__clear_cache`` from the run 13402time library. 13403 13404This intrinsic does *not* empty the instruction pipeline. Modifications 13405of the current function are outside the scope of the intrinsic. 13406 13407'``llvm.instrprof.increment``' Intrinsic 13408^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13409 13410Syntax: 13411""""""" 13412 13413:: 13414 13415 declare void @llvm.instrprof.increment(ptr <name>, i64 <hash>, 13416 i32 <num-counters>, i32 <index>) 13417 13418Overview: 13419""""""""" 13420 13421The '``llvm.instrprof.increment``' intrinsic can be emitted by a 13422frontend for use with instrumentation based profiling. These will be 13423lowered by the ``-instrprof`` pass to generate execution counts of a 13424program at runtime. 13425 13426Arguments: 13427"""""""""" 13428 13429The first argument is a pointer to a global variable containing the 13430name of the entity being instrumented. This should generally be the 13431(mangled) function name for a set of counters. 13432 13433The second argument is a hash value that can be used by the consumer 13434of the profile data to detect changes to the instrumented source, and 13435the third is the number of counters associated with ``name``. It is an 13436error if ``hash`` or ``num-counters`` differ between two instances of 13437``instrprof.increment`` that refer to the same name. 13438 13439The last argument refers to which of the counters for ``name`` should 13440be incremented. It should be a value between 0 and ``num-counters``. 13441 13442Semantics: 13443"""""""""" 13444 13445This intrinsic represents an increment of a profiling counter. It will 13446cause the ``-instrprof`` pass to generate the appropriate data 13447structures and the code to increment the appropriate value, in a 13448format that can be written out by a compiler runtime and consumed via 13449the ``llvm-profdata`` tool. 13450 13451'``llvm.instrprof.increment.step``' Intrinsic 13452^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13453 13454Syntax: 13455""""""" 13456 13457:: 13458 13459 declare void @llvm.instrprof.increment.step(ptr <name>, i64 <hash>, 13460 i32 <num-counters>, 13461 i32 <index>, i64 <step>) 13462 13463Overview: 13464""""""""" 13465 13466The '``llvm.instrprof.increment.step``' intrinsic is an extension to 13467the '``llvm.instrprof.increment``' intrinsic with an additional fifth 13468argument to specify the step of the increment. 13469 13470Arguments: 13471"""""""""" 13472The first four arguments are the same as '``llvm.instrprof.increment``' 13473intrinsic. 13474 13475The last argument specifies the value of the increment of the counter variable. 13476 13477Semantics: 13478"""""""""" 13479See description of '``llvm.instrprof.increment``' intrinsic. 13480 13481'``llvm.instrprof.cover``' Intrinsic 13482^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13483 13484Syntax: 13485""""""" 13486 13487:: 13488 13489 declare void @llvm.instrprof.cover(ptr <name>, i64 <hash>, 13490 i32 <num-counters>, i32 <index>) 13491 13492Overview: 13493""""""""" 13494 13495The '``llvm.instrprof.cover``' intrinsic is used to implement coverage 13496instrumentation. 13497 13498Arguments: 13499"""""""""" 13500The arguments are the same as the first four arguments of 13501'``llvm.instrprof.increment``'. 13502 13503Semantics: 13504"""""""""" 13505Similar to the '``llvm.instrprof.increment``' intrinsic, but it stores zero to 13506the profiling variable to signify that the function has been covered. We store 13507zero because this is more efficient on some targets. 13508 13509'``llvm.instrprof.value.profile``' Intrinsic 13510^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13511 13512Syntax: 13513""""""" 13514 13515:: 13516 13517 declare void @llvm.instrprof.value.profile(ptr <name>, i64 <hash>, 13518 i64 <value>, i32 <value_kind>, 13519 i32 <index>) 13520 13521Overview: 13522""""""""" 13523 13524The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a 13525frontend for use with instrumentation based profiling. This will be 13526lowered by the ``-instrprof`` pass to find out the target values, 13527instrumented expressions take in a program at runtime. 13528 13529Arguments: 13530"""""""""" 13531 13532The first argument is a pointer to a global variable containing the 13533name of the entity being instrumented. ``name`` should generally be the 13534(mangled) function name for a set of counters. 13535 13536The second argument is a hash value that can be used by the consumer 13537of the profile data to detect changes to the instrumented source. It 13538is an error if ``hash`` differs between two instances of 13539``llvm.instrprof.*`` that refer to the same name. 13540 13541The third argument is the value of the expression being profiled. The profiled 13542expression's value should be representable as an unsigned 64-bit value. The 13543fourth argument represents the kind of value profiling that is being done. The 13544supported value profiling kinds are enumerated through the 13545``InstrProfValueKind`` type declared in the 13546``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the 13547index of the instrumented expression within ``name``. It should be >= 0. 13548 13549Semantics: 13550"""""""""" 13551 13552This intrinsic represents the point where a call to a runtime routine 13553should be inserted for value profiling of target expressions. ``-instrprof`` 13554pass will generate the appropriate data structures and replace the 13555``llvm.instrprof.value.profile`` intrinsic with the call to the profile 13556runtime library with proper arguments. 13557 13558'``llvm.thread.pointer``' Intrinsic 13559^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13560 13561Syntax: 13562""""""" 13563 13564:: 13565 13566 declare ptr @llvm.thread.pointer() 13567 13568Overview: 13569""""""""" 13570 13571The '``llvm.thread.pointer``' intrinsic returns the value of the thread 13572pointer. 13573 13574Semantics: 13575"""""""""" 13576 13577The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area 13578for the current thread. The exact semantics of this value are target 13579specific: it may point to the start of TLS area, to the end, or somewhere 13580in the middle. Depending on the target, this intrinsic may read a register, 13581call a helper function, read from an alternate memory space, or perform 13582other operations necessary to locate the TLS area. Not all targets support 13583this intrinsic. 13584 13585'``llvm.call.preallocated.setup``' Intrinsic 13586^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13587 13588Syntax: 13589""""""" 13590 13591:: 13592 13593 declare token @llvm.call.preallocated.setup(i32 %num_args) 13594 13595Overview: 13596""""""""" 13597 13598The '``llvm.call.preallocated.setup``' intrinsic returns a token which can 13599be used with a call's ``"preallocated"`` operand bundle to indicate that 13600certain arguments are allocated and initialized before the call. 13601 13602Semantics: 13603"""""""""" 13604 13605The '``llvm.call.preallocated.setup``' intrinsic returns a token which is 13606associated with at most one call. The token can be passed to 13607'``@llvm.call.preallocated.arg``' to get a pointer to get that 13608corresponding argument. The token must be the parameter to a 13609``"preallocated"`` operand bundle for the corresponding call. 13610 13611Nested calls to '``llvm.call.preallocated.setup``' are allowed, but must 13612be properly nested. e.g. 13613 13614:: code-block:: llvm 13615 13616 %t1 = call token @llvm.call.preallocated.setup(i32 0) 13617 %t2 = call token @llvm.call.preallocated.setup(i32 0) 13618 call void foo() ["preallocated"(token %t2)] 13619 call void foo() ["preallocated"(token %t1)] 13620 13621is allowed, but not 13622 13623:: code-block:: llvm 13624 13625 %t1 = call token @llvm.call.preallocated.setup(i32 0) 13626 %t2 = call token @llvm.call.preallocated.setup(i32 0) 13627 call void foo() ["preallocated"(token %t1)] 13628 call void foo() ["preallocated"(token %t2)] 13629 13630.. _int_call_preallocated_arg: 13631 13632'``llvm.call.preallocated.arg``' Intrinsic 13633^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13634 13635Syntax: 13636""""""" 13637 13638:: 13639 13640 declare ptr @llvm.call.preallocated.arg(token %setup_token, i32 %arg_index) 13641 13642Overview: 13643""""""""" 13644 13645The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the 13646corresponding preallocated argument for the preallocated call. 13647 13648Semantics: 13649"""""""""" 13650 13651The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the 13652``%arg_index``th argument with the ``preallocated`` attribute for 13653the call associated with the ``%setup_token``, which must be from 13654'``llvm.call.preallocated.setup``'. 13655 13656A call to '``llvm.call.preallocated.arg``' must have a call site 13657``preallocated`` attribute. The type of the ``preallocated`` attribute must 13658match the type used by the ``preallocated`` attribute of the corresponding 13659argument at the preallocated call. The type is used in the case that an 13660``llvm.call.preallocated.setup`` does not have a corresponding call (e.g. due 13661to DCE), where otherwise we cannot know how large the arguments are. 13662 13663It is undefined behavior if this is called with a token from an 13664'``llvm.call.preallocated.setup``' if another 13665'``llvm.call.preallocated.setup``' has already been called or if the 13666preallocated call corresponding to the '``llvm.call.preallocated.setup``' 13667has already been called. 13668 13669.. _int_call_preallocated_teardown: 13670 13671'``llvm.call.preallocated.teardown``' Intrinsic 13672^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13673 13674Syntax: 13675""""""" 13676 13677:: 13678 13679 declare ptr @llvm.call.preallocated.teardown(token %setup_token) 13680 13681Overview: 13682""""""""" 13683 13684The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack 13685created by a '``llvm.call.preallocated.setup``'. 13686 13687Semantics: 13688"""""""""" 13689 13690The token argument must be a '``llvm.call.preallocated.setup``'. 13691 13692The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack 13693allocated by the corresponding '``llvm.call.preallocated.setup``'. Exactly 13694one of this or the preallocated call must be called to prevent stack leaks. 13695It is undefined behavior to call both a '``llvm.call.preallocated.teardown``' 13696and the preallocated call for a given '``llvm.call.preallocated.setup``'. 13697 13698For example, if the stack is allocated for a preallocated call by a 13699'``llvm.call.preallocated.setup``', then an initializer function called on an 13700allocated argument throws an exception, there should be a 13701'``llvm.call.preallocated.teardown``' in the exception handler to prevent 13702stack leaks. 13703 13704Following the nesting rules in '``llvm.call.preallocated.setup``', nested 13705calls to '``llvm.call.preallocated.setup``' and 13706'``llvm.call.preallocated.teardown``' are allowed but must be properly 13707nested. 13708 13709Example: 13710"""""""" 13711 13712.. code-block:: llvm 13713 13714 %cs = call token @llvm.call.preallocated.setup(i32 1) 13715 %x = call ptr @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32) 13716 invoke void @constructor(ptr %x) to label %conta unwind label %contb 13717 conta: 13718 call void @foo1(ptr preallocated(i32) %x) ["preallocated"(token %cs)] 13719 ret void 13720 contb: 13721 %s = catchswitch within none [label %catch] unwind to caller 13722 catch: 13723 %p = catchpad within %s [] 13724 call void @llvm.call.preallocated.teardown(token %cs) 13725 ret void 13726 13727Standard C/C++ Library Intrinsics 13728--------------------------------- 13729 13730LLVM provides intrinsics for a few important standard C/C++ library 13731functions. These intrinsics allow source-language front-ends to pass 13732information about the alignment of the pointer arguments to the code 13733generator, providing opportunity for more efficient code generation. 13734 13735.. _int_abs: 13736 13737'``llvm.abs.*``' Intrinsic 13738^^^^^^^^^^^^^^^^^^^^^^^^^^ 13739 13740Syntax: 13741""""""" 13742 13743This is an overloaded intrinsic. You can use ``llvm.abs`` on any 13744integer bit width or any vector of integer elements. 13745 13746:: 13747 13748 declare i32 @llvm.abs.i32(i32 <src>, i1 <is_int_min_poison>) 13749 declare <4 x i32> @llvm.abs.v4i32(<4 x i32> <src>, i1 <is_int_min_poison>) 13750 13751Overview: 13752""""""""" 13753 13754The '``llvm.abs``' family of intrinsic functions returns the absolute value 13755of an argument. 13756 13757Arguments: 13758"""""""""" 13759 13760The first argument is the value for which the absolute value is to be returned. 13761This argument may be of any integer type or a vector with integer element type. 13762The return type must match the first argument type. 13763 13764The second argument must be a constant and is a flag to indicate whether the 13765result value of the '``llvm.abs``' intrinsic is a 13766:ref:`poison value <poisonvalues>` if the argument is statically or dynamically 13767an ``INT_MIN`` value. 13768 13769Semantics: 13770"""""""""" 13771 13772The '``llvm.abs``' intrinsic returns the magnitude (always positive) of the 13773argument or each element of a vector argument.". If the argument is ``INT_MIN``, 13774then the result is also ``INT_MIN`` if ``is_int_min_poison == 0`` and 13775``poison`` otherwise. 13776 13777 13778.. _int_smax: 13779 13780'``llvm.smax.*``' Intrinsic 13781^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13782 13783Syntax: 13784""""""" 13785 13786This is an overloaded intrinsic. You can use ``@llvm.smax`` on any 13787integer bit width or any vector of integer elements. 13788 13789:: 13790 13791 declare i32 @llvm.smax.i32(i32 %a, i32 %b) 13792 declare <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> %b) 13793 13794Overview: 13795""""""""" 13796 13797Return the larger of ``%a`` and ``%b`` comparing the values as signed integers. 13798Vector intrinsics operate on a per-element basis. The larger element of ``%a`` 13799and ``%b`` at a given index is returned for that index. 13800 13801Arguments: 13802"""""""""" 13803 13804The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13805integer element type. The argument types must match each other, and the return 13806type must match the argument type. 13807 13808 13809.. _int_smin: 13810 13811'``llvm.smin.*``' Intrinsic 13812^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13813 13814Syntax: 13815""""""" 13816 13817This is an overloaded intrinsic. You can use ``@llvm.smin`` on any 13818integer bit width or any vector of integer elements. 13819 13820:: 13821 13822 declare i32 @llvm.smin.i32(i32 %a, i32 %b) 13823 declare <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> %b) 13824 13825Overview: 13826""""""""" 13827 13828Return the smaller of ``%a`` and ``%b`` comparing the values as signed integers. 13829Vector intrinsics operate on a per-element basis. The smaller element of ``%a`` 13830and ``%b`` at a given index is returned for that index. 13831 13832Arguments: 13833"""""""""" 13834 13835The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13836integer element type. The argument types must match each other, and the return 13837type must match the argument type. 13838 13839 13840.. _int_umax: 13841 13842'``llvm.umax.*``' Intrinsic 13843^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13844 13845Syntax: 13846""""""" 13847 13848This is an overloaded intrinsic. You can use ``@llvm.umax`` on any 13849integer bit width or any vector of integer elements. 13850 13851:: 13852 13853 declare i32 @llvm.umax.i32(i32 %a, i32 %b) 13854 declare <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> %b) 13855 13856Overview: 13857""""""""" 13858 13859Return the larger of ``%a`` and ``%b`` comparing the values as unsigned 13860integers. Vector intrinsics operate on a per-element basis. The larger element 13861of ``%a`` and ``%b`` at a given index is returned for that index. 13862 13863Arguments: 13864"""""""""" 13865 13866The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13867integer element type. The argument types must match each other, and the return 13868type must match the argument type. 13869 13870 13871.. _int_umin: 13872 13873'``llvm.umin.*``' Intrinsic 13874^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13875 13876Syntax: 13877""""""" 13878 13879This is an overloaded intrinsic. You can use ``@llvm.umin`` on any 13880integer bit width or any vector of integer elements. 13881 13882:: 13883 13884 declare i32 @llvm.umin.i32(i32 %a, i32 %b) 13885 declare <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> %b) 13886 13887Overview: 13888""""""""" 13889 13890Return the smaller of ``%a`` and ``%b`` comparing the values as unsigned 13891integers. Vector intrinsics operate on a per-element basis. The smaller element 13892of ``%a`` and ``%b`` at a given index is returned for that index. 13893 13894Arguments: 13895"""""""""" 13896 13897The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13898integer element type. The argument types must match each other, and the return 13899type must match the argument type. 13900 13901 13902.. _int_memcpy: 13903 13904'``llvm.memcpy``' Intrinsic 13905^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13906 13907Syntax: 13908""""""" 13909 13910This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any 13911integer bit width and for different address spaces. Not all targets 13912support all bit widths however. 13913 13914:: 13915 13916 declare void @llvm.memcpy.p0.p0.i32(ptr <dest>, ptr <src>, 13917 i32 <len>, i1 <isvolatile>) 13918 declare void @llvm.memcpy.p0.p0.i64(ptr <dest>, ptr <src>, 13919 i64 <len>, i1 <isvolatile>) 13920 13921Overview: 13922""""""""" 13923 13924The '``llvm.memcpy.*``' intrinsics copy a block of memory from the 13925source location to the destination location. 13926 13927Note that, unlike the standard libc function, the ``llvm.memcpy.*`` 13928intrinsics do not return a value, takes extra isvolatile 13929arguments and the pointers can be in specified address spaces. 13930 13931Arguments: 13932"""""""""" 13933 13934The first argument is a pointer to the destination, the second is a 13935pointer to the source. The third argument is an integer argument 13936specifying the number of bytes to copy, and the fourth is a 13937boolean indicating a volatile access. 13938 13939The :ref:`align <attr_align>` parameter attribute can be provided 13940for the first and second arguments. 13941 13942If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is 13943a :ref:`volatile operation <volatile>`. The detailed access behavior is not 13944very cleanly specified and it is unwise to depend on it. 13945 13946Semantics: 13947"""""""""" 13948 13949The '``llvm.memcpy.*``' intrinsics copy a block of memory from the source 13950location to the destination location, which must either be equal or 13951non-overlapping. It copies "len" bytes of memory over. If the argument is known 13952to be aligned to some boundary, this can be specified as an attribute on the 13953argument. 13954 13955If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 13956the arguments. 13957If ``<len>`` is not a well-defined value, the behavior is undefined. 13958If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined, 13959otherwise the behavior is undefined. 13960 13961.. _int_memcpy_inline: 13962 13963'``llvm.memcpy.inline``' Intrinsic 13964^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13965 13966Syntax: 13967""""""" 13968 13969This is an overloaded intrinsic. You can use ``llvm.memcpy.inline`` on any 13970integer bit width and for different address spaces. Not all targets 13971support all bit widths however. 13972 13973:: 13974 13975 declare void @llvm.memcpy.inline.p0.p0.i32(ptr <dest>, ptr <src>, 13976 i32 <len>, i1 <isvolatile>) 13977 declare void @llvm.memcpy.inline.p0.p0.i64(ptr <dest>, ptr <src>, 13978 i64 <len>, i1 <isvolatile>) 13979 13980Overview: 13981""""""""" 13982 13983The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the 13984source location to the destination location and guarantees that no external 13985functions are called. 13986 13987Note that, unlike the standard libc function, the ``llvm.memcpy.inline.*`` 13988intrinsics do not return a value, takes extra isvolatile 13989arguments and the pointers can be in specified address spaces. 13990 13991Arguments: 13992"""""""""" 13993 13994The first argument is a pointer to the destination, the second is a 13995pointer to the source. The third argument is a constant integer argument 13996specifying the number of bytes to copy, and the fourth is a 13997boolean indicating a volatile access. 13998 13999The :ref:`align <attr_align>` parameter attribute can be provided 14000for the first and second arguments. 14001 14002If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy.inline`` call is 14003a :ref:`volatile operation <volatile>`. The detailed access behavior is not 14004very cleanly specified and it is unwise to depend on it. 14005 14006Semantics: 14007"""""""""" 14008 14009The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the 14010source location to the destination location, which are not allowed to 14011overlap. It copies "len" bytes of memory over. If the argument is known 14012to be aligned to some boundary, this can be specified as an attribute on 14013the argument. 14014The behavior of '``llvm.memcpy.inline.*``' is equivalent to the behavior of 14015'``llvm.memcpy.*``', but the generated code is guaranteed not to call any 14016external functions. 14017 14018.. _int_memmove: 14019 14020'``llvm.memmove``' Intrinsic 14021^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14022 14023Syntax: 14024""""""" 14025 14026This is an overloaded intrinsic. You can use llvm.memmove on any integer 14027bit width and for different address space. Not all targets support all 14028bit widths however. 14029 14030:: 14031 14032 declare void @llvm.memmove.p0.p0.i32(ptr <dest>, ptr <src>, 14033 i32 <len>, i1 <isvolatile>) 14034 declare void @llvm.memmove.p0.p0.i64(ptr <dest>, ptr <src>, 14035 i64 <len>, i1 <isvolatile>) 14036 14037Overview: 14038""""""""" 14039 14040The '``llvm.memmove.*``' intrinsics move a block of memory from the 14041source location to the destination location. It is similar to the 14042'``llvm.memcpy``' intrinsic but allows the two memory locations to 14043overlap. 14044 14045Note that, unlike the standard libc function, the ``llvm.memmove.*`` 14046intrinsics do not return a value, takes an extra isvolatile 14047argument and the pointers can be in specified address spaces. 14048 14049Arguments: 14050"""""""""" 14051 14052The first argument is a pointer to the destination, the second is a 14053pointer to the source. The third argument is an integer argument 14054specifying the number of bytes to copy, and the fourth is a 14055boolean indicating a volatile access. 14056 14057The :ref:`align <attr_align>` parameter attribute can be provided 14058for the first and second arguments. 14059 14060If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call 14061is a :ref:`volatile operation <volatile>`. The detailed access behavior is 14062not very cleanly specified and it is unwise to depend on it. 14063 14064Semantics: 14065"""""""""" 14066 14067The '``llvm.memmove.*``' intrinsics copy a block of memory from the 14068source location to the destination location, which may overlap. It 14069copies "len" bytes of memory over. If the argument is known to be 14070aligned to some boundary, this can be specified as an attribute on 14071the argument. 14072 14073If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 14074the arguments. 14075If ``<len>`` is not a well-defined value, the behavior is undefined. 14076If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined, 14077otherwise the behavior is undefined. 14078 14079.. _int_memset: 14080 14081'``llvm.memset.*``' Intrinsics 14082^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14083 14084Syntax: 14085""""""" 14086 14087This is an overloaded intrinsic. You can use llvm.memset on any integer 14088bit width and for different address spaces. However, not all targets 14089support all bit widths. 14090 14091:: 14092 14093 declare void @llvm.memset.p0.i32(ptr <dest>, i8 <val>, 14094 i32 <len>, i1 <isvolatile>) 14095 declare void @llvm.memset.p0.i64(ptr <dest>, i8 <val>, 14096 i64 <len>, i1 <isvolatile>) 14097 14098Overview: 14099""""""""" 14100 14101The '``llvm.memset.*``' intrinsics fill a block of memory with a 14102particular byte value. 14103 14104Note that, unlike the standard libc function, the ``llvm.memset`` 14105intrinsic does not return a value and takes an extra volatile 14106argument. Also, the destination can be in an arbitrary address space. 14107 14108Arguments: 14109"""""""""" 14110 14111The first argument is a pointer to the destination to fill, the second 14112is the byte value with which to fill it, the third argument is an 14113integer argument specifying the number of bytes to fill, and the fourth 14114is a boolean indicating a volatile access. 14115 14116The :ref:`align <attr_align>` parameter attribute can be provided 14117for the first arguments. 14118 14119If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is 14120a :ref:`volatile operation <volatile>`. The detailed access behavior is not 14121very cleanly specified and it is unwise to depend on it. 14122 14123Semantics: 14124"""""""""" 14125 14126The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting 14127at the destination location. If the argument is known to be 14128aligned to some boundary, this can be specified as an attribute on 14129the argument. 14130 14131If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 14132the arguments. 14133If ``<len>`` is not a well-defined value, the behavior is undefined. 14134If ``<len>`` is not zero, ``<dest>`` should be well-defined, otherwise the 14135behavior is undefined. 14136 14137.. _int_memset_inline: 14138 14139'``llvm.memset.inline``' Intrinsic 14140^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14141 14142Syntax: 14143""""""" 14144 14145This is an overloaded intrinsic. You can use ``llvm.memset.inline`` on any 14146integer bit width and for different address spaces. Not all targets 14147support all bit widths however. 14148 14149:: 14150 14151 declare void @llvm.memset.inline.p0.p0i8.i32(ptr <dest>, i8 <val>, 14152 i32 <len>, i1 <isvolatile>) 14153 declare void @llvm.memset.inline.p0.p0.i64(ptr <dest>, i8 <val>, 14154 i64 <len>, i1 <isvolatile>) 14155 14156Overview: 14157""""""""" 14158 14159The '``llvm.memset.inline.*``' intrinsics fill a block of memory with a 14160particular byte value and guarantees that no external functions are called. 14161 14162Note that, unlike the standard libc function, the ``llvm.memset.inline.*`` 14163intrinsics do not return a value, take an extra isvolatile argument and the 14164pointer can be in specified address spaces. 14165 14166Arguments: 14167"""""""""" 14168 14169The first argument is a pointer to the destination to fill, the second 14170is the byte value with which to fill it, the third argument is a constant 14171integer argument specifying the number of bytes to fill, and the fourth 14172is a boolean indicating a volatile access. 14173 14174The :ref:`align <attr_align>` parameter attribute can be provided 14175for the first argument. 14176 14177If the ``isvolatile`` parameter is ``true``, the ``llvm.memset.inline`` call is 14178a :ref:`volatile operation <volatile>`. The detailed access behavior is not 14179very cleanly specified and it is unwise to depend on it. 14180 14181Semantics: 14182"""""""""" 14183 14184The '``llvm.memset.inline.*``' intrinsics fill "len" bytes of memory starting 14185at the destination location. If the argument is known to be 14186aligned to some boundary, this can be specified as an attribute on 14187the argument. 14188 14189``len`` must be a constant expression. 14190If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 14191the arguments. 14192If ``<len>`` is not a well-defined value, the behavior is undefined. 14193If ``<len>`` is not zero, ``<dest>`` should be well-defined, otherwise the 14194behavior is undefined. 14195 14196The behavior of '``llvm.memset.inline.*``' is equivalent to the behavior of 14197'``llvm.memset.*``', but the generated code is guaranteed not to call any 14198external functions. 14199 14200.. _int_sqrt: 14201 14202'``llvm.sqrt.*``' Intrinsic 14203^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14204 14205Syntax: 14206""""""" 14207 14208This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any 14209floating-point or vector of floating-point type. Not all targets support 14210all types however. 14211 14212:: 14213 14214 declare float @llvm.sqrt.f32(float %Val) 14215 declare double @llvm.sqrt.f64(double %Val) 14216 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val) 14217 declare fp128 @llvm.sqrt.f128(fp128 %Val) 14218 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val) 14219 14220Overview: 14221""""""""" 14222 14223The '``llvm.sqrt``' intrinsics return the square root of the specified value. 14224 14225Arguments: 14226"""""""""" 14227 14228The argument and return value are floating-point numbers of the same type. 14229 14230Semantics: 14231"""""""""" 14232 14233Return the same value as a corresponding libm '``sqrt``' function but without 14234trapping or setting ``errno``. For types specified by IEEE-754, the result 14235matches a conforming libm implementation. 14236 14237When specified with the fast-math-flag 'afn', the result may be approximated 14238using a less accurate calculation. 14239 14240'``llvm.powi.*``' Intrinsic 14241^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14242 14243Syntax: 14244""""""" 14245 14246This is an overloaded intrinsic. You can use ``llvm.powi`` on any 14247floating-point or vector of floating-point type. Not all targets support 14248all types however. 14249 14250Generally, the only supported type for the exponent is the one matching 14251with the C type ``int``. 14252 14253:: 14254 14255 declare float @llvm.powi.f32.i32(float %Val, i32 %power) 14256 declare double @llvm.powi.f64.i16(double %Val, i16 %power) 14257 declare x86_fp80 @llvm.powi.f80.i32(x86_fp80 %Val, i32 %power) 14258 declare fp128 @llvm.powi.f128.i32(fp128 %Val, i32 %power) 14259 declare ppc_fp128 @llvm.powi.ppcf128.i32(ppc_fp128 %Val, i32 %power) 14260 14261Overview: 14262""""""""" 14263 14264The '``llvm.powi.*``' intrinsics return the first operand raised to the 14265specified (positive or negative) power. The order of evaluation of 14266multiplications is not defined. When a vector of floating-point type is 14267used, the second argument remains a scalar integer value. 14268 14269Arguments: 14270"""""""""" 14271 14272The second argument is an integer power, and the first is a value to 14273raise to that power. 14274 14275Semantics: 14276"""""""""" 14277 14278This function returns the first value raised to the second power with an 14279unspecified sequence of rounding operations. 14280 14281'``llvm.sin.*``' Intrinsic 14282^^^^^^^^^^^^^^^^^^^^^^^^^^ 14283 14284Syntax: 14285""""""" 14286 14287This is an overloaded intrinsic. You can use ``llvm.sin`` on any 14288floating-point or vector of floating-point type. Not all targets support 14289all types however. 14290 14291:: 14292 14293 declare float @llvm.sin.f32(float %Val) 14294 declare double @llvm.sin.f64(double %Val) 14295 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val) 14296 declare fp128 @llvm.sin.f128(fp128 %Val) 14297 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val) 14298 14299Overview: 14300""""""""" 14301 14302The '``llvm.sin.*``' intrinsics return the sine of the operand. 14303 14304Arguments: 14305"""""""""" 14306 14307The argument and return value are floating-point numbers of the same type. 14308 14309Semantics: 14310"""""""""" 14311 14312Return the same value as a corresponding libm '``sin``' function but without 14313trapping or setting ``errno``. 14314 14315When specified with the fast-math-flag 'afn', the result may be approximated 14316using a less accurate calculation. 14317 14318'``llvm.cos.*``' Intrinsic 14319^^^^^^^^^^^^^^^^^^^^^^^^^^ 14320 14321Syntax: 14322""""""" 14323 14324This is an overloaded intrinsic. You can use ``llvm.cos`` on any 14325floating-point or vector of floating-point type. Not all targets support 14326all types however. 14327 14328:: 14329 14330 declare float @llvm.cos.f32(float %Val) 14331 declare double @llvm.cos.f64(double %Val) 14332 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val) 14333 declare fp128 @llvm.cos.f128(fp128 %Val) 14334 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val) 14335 14336Overview: 14337""""""""" 14338 14339The '``llvm.cos.*``' intrinsics return the cosine of the operand. 14340 14341Arguments: 14342"""""""""" 14343 14344The argument and return value are floating-point numbers of the same type. 14345 14346Semantics: 14347"""""""""" 14348 14349Return the same value as a corresponding libm '``cos``' function but without 14350trapping or setting ``errno``. 14351 14352When specified with the fast-math-flag 'afn', the result may be approximated 14353using a less accurate calculation. 14354 14355'``llvm.pow.*``' Intrinsic 14356^^^^^^^^^^^^^^^^^^^^^^^^^^ 14357 14358Syntax: 14359""""""" 14360 14361This is an overloaded intrinsic. You can use ``llvm.pow`` on any 14362floating-point or vector of floating-point type. Not all targets support 14363all types however. 14364 14365:: 14366 14367 declare float @llvm.pow.f32(float %Val, float %Power) 14368 declare double @llvm.pow.f64(double %Val, double %Power) 14369 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power) 14370 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power) 14371 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power) 14372 14373Overview: 14374""""""""" 14375 14376The '``llvm.pow.*``' intrinsics return the first operand raised to the 14377specified (positive or negative) power. 14378 14379Arguments: 14380"""""""""" 14381 14382The arguments and return value are floating-point numbers of the same type. 14383 14384Semantics: 14385"""""""""" 14386 14387Return the same value as a corresponding libm '``pow``' function but without 14388trapping or setting ``errno``. 14389 14390When specified with the fast-math-flag 'afn', the result may be approximated 14391using a less accurate calculation. 14392 14393'``llvm.exp.*``' Intrinsic 14394^^^^^^^^^^^^^^^^^^^^^^^^^^ 14395 14396Syntax: 14397""""""" 14398 14399This is an overloaded intrinsic. You can use ``llvm.exp`` on any 14400floating-point or vector of floating-point type. Not all targets support 14401all types however. 14402 14403:: 14404 14405 declare float @llvm.exp.f32(float %Val) 14406 declare double @llvm.exp.f64(double %Val) 14407 declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val) 14408 declare fp128 @llvm.exp.f128(fp128 %Val) 14409 declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val) 14410 14411Overview: 14412""""""""" 14413 14414The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified 14415value. 14416 14417Arguments: 14418"""""""""" 14419 14420The argument and return value are floating-point numbers of the same type. 14421 14422Semantics: 14423"""""""""" 14424 14425Return the same value as a corresponding libm '``exp``' function but without 14426trapping or setting ``errno``. 14427 14428When specified with the fast-math-flag 'afn', the result may be approximated 14429using a less accurate calculation. 14430 14431'``llvm.exp2.*``' Intrinsic 14432^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14433 14434Syntax: 14435""""""" 14436 14437This is an overloaded intrinsic. You can use ``llvm.exp2`` on any 14438floating-point or vector of floating-point type. Not all targets support 14439all types however. 14440 14441:: 14442 14443 declare float @llvm.exp2.f32(float %Val) 14444 declare double @llvm.exp2.f64(double %Val) 14445 declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val) 14446 declare fp128 @llvm.exp2.f128(fp128 %Val) 14447 declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val) 14448 14449Overview: 14450""""""""" 14451 14452The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the 14453specified value. 14454 14455Arguments: 14456"""""""""" 14457 14458The argument and return value are floating-point numbers of the same type. 14459 14460Semantics: 14461"""""""""" 14462 14463Return the same value as a corresponding libm '``exp2``' function but without 14464trapping or setting ``errno``. 14465 14466When specified with the fast-math-flag 'afn', the result may be approximated 14467using a less accurate calculation. 14468 14469'``llvm.log.*``' Intrinsic 14470^^^^^^^^^^^^^^^^^^^^^^^^^^ 14471 14472Syntax: 14473""""""" 14474 14475This is an overloaded intrinsic. You can use ``llvm.log`` on any 14476floating-point or vector of floating-point type. Not all targets support 14477all types however. 14478 14479:: 14480 14481 declare float @llvm.log.f32(float %Val) 14482 declare double @llvm.log.f64(double %Val) 14483 declare x86_fp80 @llvm.log.f80(x86_fp80 %Val) 14484 declare fp128 @llvm.log.f128(fp128 %Val) 14485 declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val) 14486 14487Overview: 14488""""""""" 14489 14490The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified 14491value. 14492 14493Arguments: 14494"""""""""" 14495 14496The argument and return value are floating-point numbers of the same type. 14497 14498Semantics: 14499"""""""""" 14500 14501Return the same value as a corresponding libm '``log``' function but without 14502trapping or setting ``errno``. 14503 14504When specified with the fast-math-flag 'afn', the result may be approximated 14505using a less accurate calculation. 14506 14507'``llvm.log10.*``' Intrinsic 14508^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14509 14510Syntax: 14511""""""" 14512 14513This is an overloaded intrinsic. You can use ``llvm.log10`` on any 14514floating-point or vector of floating-point type. Not all targets support 14515all types however. 14516 14517:: 14518 14519 declare float @llvm.log10.f32(float %Val) 14520 declare double @llvm.log10.f64(double %Val) 14521 declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val) 14522 declare fp128 @llvm.log10.f128(fp128 %Val) 14523 declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val) 14524 14525Overview: 14526""""""""" 14527 14528The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the 14529specified value. 14530 14531Arguments: 14532"""""""""" 14533 14534The argument and return value are floating-point numbers of the same type. 14535 14536Semantics: 14537"""""""""" 14538 14539Return the same value as a corresponding libm '``log10``' function but without 14540trapping or setting ``errno``. 14541 14542When specified with the fast-math-flag 'afn', the result may be approximated 14543using a less accurate calculation. 14544 14545'``llvm.log2.*``' Intrinsic 14546^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14547 14548Syntax: 14549""""""" 14550 14551This is an overloaded intrinsic. You can use ``llvm.log2`` on any 14552floating-point or vector of floating-point type. Not all targets support 14553all types however. 14554 14555:: 14556 14557 declare float @llvm.log2.f32(float %Val) 14558 declare double @llvm.log2.f64(double %Val) 14559 declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val) 14560 declare fp128 @llvm.log2.f128(fp128 %Val) 14561 declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val) 14562 14563Overview: 14564""""""""" 14565 14566The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified 14567value. 14568 14569Arguments: 14570"""""""""" 14571 14572The argument and return value are floating-point numbers of the same type. 14573 14574Semantics: 14575"""""""""" 14576 14577Return the same value as a corresponding libm '``log2``' function but without 14578trapping or setting ``errno``. 14579 14580When specified with the fast-math-flag 'afn', the result may be approximated 14581using a less accurate calculation. 14582 14583.. _int_fma: 14584 14585'``llvm.fma.*``' Intrinsic 14586^^^^^^^^^^^^^^^^^^^^^^^^^^ 14587 14588Syntax: 14589""""""" 14590 14591This is an overloaded intrinsic. You can use ``llvm.fma`` on any 14592floating-point or vector of floating-point type. Not all targets support 14593all types however. 14594 14595:: 14596 14597 declare float @llvm.fma.f32(float %a, float %b, float %c) 14598 declare double @llvm.fma.f64(double %a, double %b, double %c) 14599 declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c) 14600 declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c) 14601 declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c) 14602 14603Overview: 14604""""""""" 14605 14606The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation. 14607 14608Arguments: 14609"""""""""" 14610 14611The arguments and return value are floating-point numbers of the same type. 14612 14613Semantics: 14614"""""""""" 14615 14616Return the same value as a corresponding libm '``fma``' function but without 14617trapping or setting ``errno``. 14618 14619When specified with the fast-math-flag 'afn', the result may be approximated 14620using a less accurate calculation. 14621 14622.. _int_fabs: 14623 14624'``llvm.fabs.*``' Intrinsic 14625^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14626 14627Syntax: 14628""""""" 14629 14630This is an overloaded intrinsic. You can use ``llvm.fabs`` on any 14631floating-point or vector of floating-point type. Not all targets support 14632all types however. 14633 14634:: 14635 14636 declare float @llvm.fabs.f32(float %Val) 14637 declare double @llvm.fabs.f64(double %Val) 14638 declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val) 14639 declare fp128 @llvm.fabs.f128(fp128 %Val) 14640 declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val) 14641 14642Overview: 14643""""""""" 14644 14645The '``llvm.fabs.*``' intrinsics return the absolute value of the 14646operand. 14647 14648Arguments: 14649"""""""""" 14650 14651The argument and return value are floating-point numbers of the same 14652type. 14653 14654Semantics: 14655"""""""""" 14656 14657This function returns the same values as the libm ``fabs`` functions 14658would, and handles error conditions in the same way. 14659 14660.. _i_minnum: 14661 14662'``llvm.minnum.*``' Intrinsic 14663^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14664 14665Syntax: 14666""""""" 14667 14668This is an overloaded intrinsic. You can use ``llvm.minnum`` on any 14669floating-point or vector of floating-point type. Not all targets support 14670all types however. 14671 14672:: 14673 14674 declare float @llvm.minnum.f32(float %Val0, float %Val1) 14675 declare double @llvm.minnum.f64(double %Val0, double %Val1) 14676 declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14677 declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1) 14678 declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14679 14680Overview: 14681""""""""" 14682 14683The '``llvm.minnum.*``' intrinsics return the minimum of the two 14684arguments. 14685 14686 14687Arguments: 14688"""""""""" 14689 14690The arguments and return value are floating-point numbers of the same 14691type. 14692 14693Semantics: 14694"""""""""" 14695 14696Follows the IEEE-754 semantics for minNum, except for handling of 14697signaling NaNs. This match's the behavior of libm's fmin. 14698 14699If either operand is a NaN, returns the other non-NaN operand. Returns 14700NaN only if both operands are NaN. The returned NaN is always 14701quiet. If the operands compare equal, returns a value that compares 14702equal to both operands. This means that fmin(+/-0.0, +/-0.0) could 14703return either -0.0 or 0.0. 14704 14705Unlike the IEEE-754 2008 behavior, this does not distinguish between 14706signaling and quiet NaN inputs. If a target's implementation follows 14707the standard and returns a quiet NaN if either input is a signaling 14708NaN, the intrinsic lowering is responsible for quieting the inputs to 14709correctly return the non-NaN input (e.g. by using the equivalent of 14710``llvm.canonicalize``). 14711 14712.. _i_maxnum: 14713 14714'``llvm.maxnum.*``' Intrinsic 14715^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14716 14717Syntax: 14718""""""" 14719 14720This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any 14721floating-point or vector of floating-point type. Not all targets support 14722all types however. 14723 14724:: 14725 14726 declare float @llvm.maxnum.f32(float %Val0, float %Val1) 14727 declare double @llvm.maxnum.f64(double %Val0, double %Val1) 14728 declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14729 declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1) 14730 declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14731 14732Overview: 14733""""""""" 14734 14735The '``llvm.maxnum.*``' intrinsics return the maximum of the two 14736arguments. 14737 14738 14739Arguments: 14740"""""""""" 14741 14742The arguments and return value are floating-point numbers of the same 14743type. 14744 14745Semantics: 14746"""""""""" 14747Follows the IEEE-754 semantics for maxNum except for the handling of 14748signaling NaNs. This matches the behavior of libm's fmax. 14749 14750If either operand is a NaN, returns the other non-NaN operand. Returns 14751NaN only if both operands are NaN. The returned NaN is always 14752quiet. If the operands compare equal, returns a value that compares 14753equal to both operands. This means that fmax(+/-0.0, +/-0.0) could 14754return either -0.0 or 0.0. 14755 14756Unlike the IEEE-754 2008 behavior, this does not distinguish between 14757signaling and quiet NaN inputs. If a target's implementation follows 14758the standard and returns a quiet NaN if either input is a signaling 14759NaN, the intrinsic lowering is responsible for quieting the inputs to 14760correctly return the non-NaN input (e.g. by using the equivalent of 14761``llvm.canonicalize``). 14762 14763'``llvm.minimum.*``' Intrinsic 14764^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14765 14766Syntax: 14767""""""" 14768 14769This is an overloaded intrinsic. You can use ``llvm.minimum`` on any 14770floating-point or vector of floating-point type. Not all targets support 14771all types however. 14772 14773:: 14774 14775 declare float @llvm.minimum.f32(float %Val0, float %Val1) 14776 declare double @llvm.minimum.f64(double %Val0, double %Val1) 14777 declare x86_fp80 @llvm.minimum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14778 declare fp128 @llvm.minimum.f128(fp128 %Val0, fp128 %Val1) 14779 declare ppc_fp128 @llvm.minimum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14780 14781Overview: 14782""""""""" 14783 14784The '``llvm.minimum.*``' intrinsics return the minimum of the two 14785arguments, propagating NaNs and treating -0.0 as less than +0.0. 14786 14787 14788Arguments: 14789"""""""""" 14790 14791The arguments and return value are floating-point numbers of the same 14792type. 14793 14794Semantics: 14795"""""""""" 14796If either operand is a NaN, returns NaN. Otherwise returns the lesser 14797of the two arguments. -0.0 is considered to be less than +0.0 for this 14798intrinsic. Note that these are the semantics specified in the draft of 14799IEEE 754-2018. 14800 14801'``llvm.maximum.*``' Intrinsic 14802^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14803 14804Syntax: 14805""""""" 14806 14807This is an overloaded intrinsic. You can use ``llvm.maximum`` on any 14808floating-point or vector of floating-point type. Not all targets support 14809all types however. 14810 14811:: 14812 14813 declare float @llvm.maximum.f32(float %Val0, float %Val1) 14814 declare double @llvm.maximum.f64(double %Val0, double %Val1) 14815 declare x86_fp80 @llvm.maximum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14816 declare fp128 @llvm.maximum.f128(fp128 %Val0, fp128 %Val1) 14817 declare ppc_fp128 @llvm.maximum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14818 14819Overview: 14820""""""""" 14821 14822The '``llvm.maximum.*``' intrinsics return the maximum of the two 14823arguments, propagating NaNs and treating -0.0 as less than +0.0. 14824 14825 14826Arguments: 14827"""""""""" 14828 14829The arguments and return value are floating-point numbers of the same 14830type. 14831 14832Semantics: 14833"""""""""" 14834If either operand is a NaN, returns NaN. Otherwise returns the greater 14835of the two arguments. -0.0 is considered to be less than +0.0 for this 14836intrinsic. Note that these are the semantics specified in the draft of 14837IEEE 754-2018. 14838 14839.. _int_copysign: 14840 14841'``llvm.copysign.*``' Intrinsic 14842^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14843 14844Syntax: 14845""""""" 14846 14847This is an overloaded intrinsic. You can use ``llvm.copysign`` on any 14848floating-point or vector of floating-point type. Not all targets support 14849all types however. 14850 14851:: 14852 14853 declare float @llvm.copysign.f32(float %Mag, float %Sgn) 14854 declare double @llvm.copysign.f64(double %Mag, double %Sgn) 14855 declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn) 14856 declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn) 14857 declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn) 14858 14859Overview: 14860""""""""" 14861 14862The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the 14863first operand and the sign of the second operand. 14864 14865Arguments: 14866"""""""""" 14867 14868The arguments and return value are floating-point numbers of the same 14869type. 14870 14871Semantics: 14872"""""""""" 14873 14874This function returns the same values as the libm ``copysign`` 14875functions would, and handles error conditions in the same way. 14876 14877.. _int_floor: 14878 14879'``llvm.floor.*``' Intrinsic 14880^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14881 14882Syntax: 14883""""""" 14884 14885This is an overloaded intrinsic. You can use ``llvm.floor`` on any 14886floating-point or vector of floating-point type. Not all targets support 14887all types however. 14888 14889:: 14890 14891 declare float @llvm.floor.f32(float %Val) 14892 declare double @llvm.floor.f64(double %Val) 14893 declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val) 14894 declare fp128 @llvm.floor.f128(fp128 %Val) 14895 declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val) 14896 14897Overview: 14898""""""""" 14899 14900The '``llvm.floor.*``' intrinsics return the floor of the operand. 14901 14902Arguments: 14903"""""""""" 14904 14905The argument and return value are floating-point numbers of the same 14906type. 14907 14908Semantics: 14909"""""""""" 14910 14911This function returns the same values as the libm ``floor`` functions 14912would, and handles error conditions in the same way. 14913 14914.. _int_ceil: 14915 14916'``llvm.ceil.*``' Intrinsic 14917^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14918 14919Syntax: 14920""""""" 14921 14922This is an overloaded intrinsic. You can use ``llvm.ceil`` on any 14923floating-point or vector of floating-point type. Not all targets support 14924all types however. 14925 14926:: 14927 14928 declare float @llvm.ceil.f32(float %Val) 14929 declare double @llvm.ceil.f64(double %Val) 14930 declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val) 14931 declare fp128 @llvm.ceil.f128(fp128 %Val) 14932 declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val) 14933 14934Overview: 14935""""""""" 14936 14937The '``llvm.ceil.*``' intrinsics return the ceiling of the operand. 14938 14939Arguments: 14940"""""""""" 14941 14942The argument and return value are floating-point numbers of the same 14943type. 14944 14945Semantics: 14946"""""""""" 14947 14948This function returns the same values as the libm ``ceil`` functions 14949would, and handles error conditions in the same way. 14950 14951 14952.. _int_llvm_trunc: 14953 14954'``llvm.trunc.*``' Intrinsic 14955^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14956 14957Syntax: 14958""""""" 14959 14960This is an overloaded intrinsic. You can use ``llvm.trunc`` on any 14961floating-point or vector of floating-point type. Not all targets support 14962all types however. 14963 14964:: 14965 14966 declare float @llvm.trunc.f32(float %Val) 14967 declare double @llvm.trunc.f64(double %Val) 14968 declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val) 14969 declare fp128 @llvm.trunc.f128(fp128 %Val) 14970 declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val) 14971 14972Overview: 14973""""""""" 14974 14975The '``llvm.trunc.*``' intrinsics returns the operand rounded to the 14976nearest integer not larger in magnitude than the operand. 14977 14978Arguments: 14979"""""""""" 14980 14981The argument and return value are floating-point numbers of the same 14982type. 14983 14984Semantics: 14985"""""""""" 14986 14987This function returns the same values as the libm ``trunc`` functions 14988would, and handles error conditions in the same way. 14989 14990.. _int_rint: 14991 14992'``llvm.rint.*``' Intrinsic 14993^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14994 14995Syntax: 14996""""""" 14997 14998This is an overloaded intrinsic. You can use ``llvm.rint`` on any 14999floating-point or vector of floating-point type. Not all targets support 15000all types however. 15001 15002:: 15003 15004 declare float @llvm.rint.f32(float %Val) 15005 declare double @llvm.rint.f64(double %Val) 15006 declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val) 15007 declare fp128 @llvm.rint.f128(fp128 %Val) 15008 declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val) 15009 15010Overview: 15011""""""""" 15012 15013The '``llvm.rint.*``' intrinsics returns the operand rounded to the 15014nearest integer. It may raise an inexact floating-point exception if the 15015operand isn't an integer. 15016 15017Arguments: 15018"""""""""" 15019 15020The argument and return value are floating-point numbers of the same 15021type. 15022 15023Semantics: 15024"""""""""" 15025 15026This function returns the same values as the libm ``rint`` functions 15027would, and handles error conditions in the same way. 15028 15029.. _int_nearbyint: 15030 15031'``llvm.nearbyint.*``' Intrinsic 15032^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15033 15034Syntax: 15035""""""" 15036 15037This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any 15038floating-point or vector of floating-point type. Not all targets support 15039all types however. 15040 15041:: 15042 15043 declare float @llvm.nearbyint.f32(float %Val) 15044 declare double @llvm.nearbyint.f64(double %Val) 15045 declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val) 15046 declare fp128 @llvm.nearbyint.f128(fp128 %Val) 15047 declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val) 15048 15049Overview: 15050""""""""" 15051 15052The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the 15053nearest integer. 15054 15055Arguments: 15056"""""""""" 15057 15058The argument and return value are floating-point numbers of the same 15059type. 15060 15061Semantics: 15062"""""""""" 15063 15064This function returns the same values as the libm ``nearbyint`` 15065functions would, and handles error conditions in the same way. 15066 15067.. _int_round: 15068 15069'``llvm.round.*``' Intrinsic 15070^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15071 15072Syntax: 15073""""""" 15074 15075This is an overloaded intrinsic. You can use ``llvm.round`` on any 15076floating-point or vector of floating-point type. Not all targets support 15077all types however. 15078 15079:: 15080 15081 declare float @llvm.round.f32(float %Val) 15082 declare double @llvm.round.f64(double %Val) 15083 declare x86_fp80 @llvm.round.f80(x86_fp80 %Val) 15084 declare fp128 @llvm.round.f128(fp128 %Val) 15085 declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val) 15086 15087Overview: 15088""""""""" 15089 15090The '``llvm.round.*``' intrinsics returns the operand rounded to the 15091nearest integer. 15092 15093Arguments: 15094"""""""""" 15095 15096The argument and return value are floating-point numbers of the same 15097type. 15098 15099Semantics: 15100"""""""""" 15101 15102This function returns the same values as the libm ``round`` 15103functions would, and handles error conditions in the same way. 15104 15105.. _int_roundeven: 15106 15107'``llvm.roundeven.*``' Intrinsic 15108^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15109 15110Syntax: 15111""""""" 15112 15113This is an overloaded intrinsic. You can use ``llvm.roundeven`` on any 15114floating-point or vector of floating-point type. Not all targets support 15115all types however. 15116 15117:: 15118 15119 declare float @llvm.roundeven.f32(float %Val) 15120 declare double @llvm.roundeven.f64(double %Val) 15121 declare x86_fp80 @llvm.roundeven.f80(x86_fp80 %Val) 15122 declare fp128 @llvm.roundeven.f128(fp128 %Val) 15123 declare ppc_fp128 @llvm.roundeven.ppcf128(ppc_fp128 %Val) 15124 15125Overview: 15126""""""""" 15127 15128The '``llvm.roundeven.*``' intrinsics returns the operand rounded to the nearest 15129integer in floating-point format rounding halfway cases to even (that is, to the 15130nearest value that is an even integer). 15131 15132Arguments: 15133"""""""""" 15134 15135The argument and return value are floating-point numbers of the same type. 15136 15137Semantics: 15138"""""""""" 15139 15140This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It 15141also behaves in the same way as C standard function ``roundeven``, except that 15142it does not raise floating point exceptions. 15143 15144 15145'``llvm.lround.*``' Intrinsic 15146^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15147 15148Syntax: 15149""""""" 15150 15151This is an overloaded intrinsic. You can use ``llvm.lround`` on any 15152floating-point type. Not all targets support all types however. 15153 15154:: 15155 15156 declare i32 @llvm.lround.i32.f32(float %Val) 15157 declare i32 @llvm.lround.i32.f64(double %Val) 15158 declare i32 @llvm.lround.i32.f80(float %Val) 15159 declare i32 @llvm.lround.i32.f128(double %Val) 15160 declare i32 @llvm.lround.i32.ppcf128(double %Val) 15161 15162 declare i64 @llvm.lround.i64.f32(float %Val) 15163 declare i64 @llvm.lround.i64.f64(double %Val) 15164 declare i64 @llvm.lround.i64.f80(float %Val) 15165 declare i64 @llvm.lround.i64.f128(double %Val) 15166 declare i64 @llvm.lround.i64.ppcf128(double %Val) 15167 15168Overview: 15169""""""""" 15170 15171The '``llvm.lround.*``' intrinsics return the operand rounded to the nearest 15172integer with ties away from zero. 15173 15174 15175Arguments: 15176"""""""""" 15177 15178The argument is a floating-point number and the return value is an integer 15179type. 15180 15181Semantics: 15182"""""""""" 15183 15184This function returns the same values as the libm ``lround`` functions 15185would, but without setting errno. If the rounded value is too large to 15186be stored in the result type, the return value is a non-deterministic 15187value (equivalent to `freeze poison`). 15188 15189'``llvm.llround.*``' Intrinsic 15190^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15191 15192Syntax: 15193""""""" 15194 15195This is an overloaded intrinsic. You can use ``llvm.llround`` on any 15196floating-point type. Not all targets support all types however. 15197 15198:: 15199 15200 declare i64 @llvm.lround.i64.f32(float %Val) 15201 declare i64 @llvm.lround.i64.f64(double %Val) 15202 declare i64 @llvm.lround.i64.f80(float %Val) 15203 declare i64 @llvm.lround.i64.f128(double %Val) 15204 declare i64 @llvm.lround.i64.ppcf128(double %Val) 15205 15206Overview: 15207""""""""" 15208 15209The '``llvm.llround.*``' intrinsics return the operand rounded to the nearest 15210integer with ties away from zero. 15211 15212Arguments: 15213"""""""""" 15214 15215The argument is a floating-point number and the return value is an integer 15216type. 15217 15218Semantics: 15219"""""""""" 15220 15221This function returns the same values as the libm ``llround`` 15222functions would, but without setting errno. If the rounded value is 15223too large to be stored in the result type, the return value is a 15224non-deterministic value (equivalent to `freeze poison`). 15225 15226'``llvm.lrint.*``' Intrinsic 15227^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15228 15229Syntax: 15230""""""" 15231 15232This is an overloaded intrinsic. You can use ``llvm.lrint`` on any 15233floating-point type. Not all targets support all types however. 15234 15235:: 15236 15237 declare i32 @llvm.lrint.i32.f32(float %Val) 15238 declare i32 @llvm.lrint.i32.f64(double %Val) 15239 declare i32 @llvm.lrint.i32.f80(float %Val) 15240 declare i32 @llvm.lrint.i32.f128(double %Val) 15241 declare i32 @llvm.lrint.i32.ppcf128(double %Val) 15242 15243 declare i64 @llvm.lrint.i64.f32(float %Val) 15244 declare i64 @llvm.lrint.i64.f64(double %Val) 15245 declare i64 @llvm.lrint.i64.f80(float %Val) 15246 declare i64 @llvm.lrint.i64.f128(double %Val) 15247 declare i64 @llvm.lrint.i64.ppcf128(double %Val) 15248 15249Overview: 15250""""""""" 15251 15252The '``llvm.lrint.*``' intrinsics return the operand rounded to the nearest 15253integer. 15254 15255 15256Arguments: 15257"""""""""" 15258 15259The argument is a floating-point number and the return value is an integer 15260type. 15261 15262Semantics: 15263"""""""""" 15264 15265This function returns the same values as the libm ``lrint`` functions 15266would, but without setting errno. If the rounded value is too large to 15267be stored in the result type, the return value is a non-deterministic 15268value (equivalent to `freeze poison`). 15269 15270'``llvm.llrint.*``' Intrinsic 15271^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15272 15273Syntax: 15274""""""" 15275 15276This is an overloaded intrinsic. You can use ``llvm.llrint`` on any 15277floating-point type. Not all targets support all types however. 15278 15279:: 15280 15281 declare i64 @llvm.llrint.i64.f32(float %Val) 15282 declare i64 @llvm.llrint.i64.f64(double %Val) 15283 declare i64 @llvm.llrint.i64.f80(float %Val) 15284 declare i64 @llvm.llrint.i64.f128(double %Val) 15285 declare i64 @llvm.llrint.i64.ppcf128(double %Val) 15286 15287Overview: 15288""""""""" 15289 15290The '``llvm.llrint.*``' intrinsics return the operand rounded to the nearest 15291integer. 15292 15293Arguments: 15294"""""""""" 15295 15296The argument is a floating-point number and the return value is an integer 15297type. 15298 15299Semantics: 15300"""""""""" 15301 15302This function returns the same values as the libm ``llrint`` functions 15303would, but without setting errno. If the rounded value is too large to 15304be stored in the result type, the return value is a non-deterministic 15305value (equivalent to `freeze poison`). 15306 15307Bit Manipulation Intrinsics 15308--------------------------- 15309 15310LLVM provides intrinsics for a few important bit manipulation 15311operations. These allow efficient code generation for some algorithms. 15312 15313.. _int_bitreverse: 15314 15315'``llvm.bitreverse.*``' Intrinsics 15316^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15317 15318Syntax: 15319""""""" 15320 15321This is an overloaded intrinsic function. You can use bitreverse on any 15322integer type. 15323 15324:: 15325 15326 declare i16 @llvm.bitreverse.i16(i16 <id>) 15327 declare i32 @llvm.bitreverse.i32(i32 <id>) 15328 declare i64 @llvm.bitreverse.i64(i64 <id>) 15329 declare <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> <id>) 15330 15331Overview: 15332""""""""" 15333 15334The '``llvm.bitreverse``' family of intrinsics is used to reverse the 15335bitpattern of an integer value or vector of integer values; for example 15336``0b10110110`` becomes ``0b01101101``. 15337 15338Semantics: 15339"""""""""" 15340 15341The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit 15342``M`` in the input moved to bit ``N-M-1`` in the output. The vector 15343intrinsics, such as ``llvm.bitreverse.v4i32``, operate on a per-element 15344basis and the element order is not affected. 15345 15346.. _int_bswap: 15347 15348'``llvm.bswap.*``' Intrinsics 15349^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15350 15351Syntax: 15352""""""" 15353 15354This is an overloaded intrinsic function. You can use bswap on any 15355integer type that is an even number of bytes (i.e. BitWidth % 16 == 0). 15356 15357:: 15358 15359 declare i16 @llvm.bswap.i16(i16 <id>) 15360 declare i32 @llvm.bswap.i32(i32 <id>) 15361 declare i64 @llvm.bswap.i64(i64 <id>) 15362 declare <4 x i32> @llvm.bswap.v4i32(<4 x i32> <id>) 15363 15364Overview: 15365""""""""" 15366 15367The '``llvm.bswap``' family of intrinsics is used to byte swap an integer 15368value or vector of integer values with an even number of bytes (positive 15369multiple of 16 bits). 15370 15371Semantics: 15372"""""""""" 15373 15374The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high 15375and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32`` 15376intrinsic returns an i32 value that has the four bytes of the input i32 15377swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the 15378returned i32 will have its bytes in 3, 2, 1, 0 order. The 15379``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this 15380concept to additional even-byte lengths (6 bytes, 8 bytes and more, 15381respectively). The vector intrinsics, such as ``llvm.bswap.v4i32``, 15382operate on a per-element basis and the element order is not affected. 15383 15384.. _int_ctpop: 15385 15386'``llvm.ctpop.*``' Intrinsic 15387^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15388 15389Syntax: 15390""""""" 15391 15392This is an overloaded intrinsic. You can use llvm.ctpop on any integer 15393bit width, or on any vector with integer elements. Not all targets 15394support all bit widths or vector types, however. 15395 15396:: 15397 15398 declare i8 @llvm.ctpop.i8(i8 <src>) 15399 declare i16 @llvm.ctpop.i16(i16 <src>) 15400 declare i32 @llvm.ctpop.i32(i32 <src>) 15401 declare i64 @llvm.ctpop.i64(i64 <src>) 15402 declare i256 @llvm.ctpop.i256(i256 <src>) 15403 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>) 15404 15405Overview: 15406""""""""" 15407 15408The '``llvm.ctpop``' family of intrinsics counts the number of bits set 15409in a value. 15410 15411Arguments: 15412"""""""""" 15413 15414The only argument is the value to be counted. The argument may be of any 15415integer type, or a vector with integer elements. The return type must 15416match the argument type. 15417 15418Semantics: 15419"""""""""" 15420 15421The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within 15422each element of a vector. 15423 15424.. _int_ctlz: 15425 15426'``llvm.ctlz.*``' Intrinsic 15427^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15428 15429Syntax: 15430""""""" 15431 15432This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any 15433integer bit width, or any vector whose elements are integers. Not all 15434targets support all bit widths or vector types, however. 15435 15436:: 15437 15438 declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_poison>) 15439 declare <2 x i37> @llvm.ctlz.v2i37(<2 x i37> <src>, i1 <is_zero_poison>) 15440 15441Overview: 15442""""""""" 15443 15444The '``llvm.ctlz``' family of intrinsic functions counts the number of 15445leading zeros in a variable. 15446 15447Arguments: 15448"""""""""" 15449 15450The first argument is the value to be counted. This argument may be of 15451any integer type, or a vector with integer element type. The return 15452type must match the first argument type. 15453 15454The second argument is a constant flag that indicates whether the intrinsic 15455returns a valid result if the first argument is zero. If the first 15456argument is zero and the second argument is true, the result is poison. 15457Historically some architectures did not provide a defined result for zero 15458values as efficiently, and many algorithms are now predicated on avoiding 15459zero-value inputs. 15460 15461Semantics: 15462"""""""""" 15463 15464The '``llvm.ctlz``' intrinsic counts the leading (most significant) 15465zeros in a variable, or within each element of the vector. If 15466``src == 0`` then the result is the size in bits of the type of ``src`` 15467if ``is_zero_poison == 0`` and ``poison`` otherwise. For example, 15468``llvm.ctlz(i32 2) = 30``. 15469 15470.. _int_cttz: 15471 15472'``llvm.cttz.*``' Intrinsic 15473^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15474 15475Syntax: 15476""""""" 15477 15478This is an overloaded intrinsic. You can use ``llvm.cttz`` on any 15479integer bit width, or any vector of integer elements. Not all targets 15480support all bit widths or vector types, however. 15481 15482:: 15483 15484 declare i42 @llvm.cttz.i42 (i42 <src>, i1 <is_zero_poison>) 15485 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_poison>) 15486 15487Overview: 15488""""""""" 15489 15490The '``llvm.cttz``' family of intrinsic functions counts the number of 15491trailing zeros. 15492 15493Arguments: 15494"""""""""" 15495 15496The first argument is the value to be counted. This argument may be of 15497any integer type, or a vector with integer element type. The return 15498type must match the first argument type. 15499 15500The second argument is a constant flag that indicates whether the intrinsic 15501returns a valid result if the first argument is zero. If the first 15502argument is zero and the second argument is true, the result is poison. 15503Historically some architectures did not provide a defined result for zero 15504values as efficiently, and many algorithms are now predicated on avoiding 15505zero-value inputs. 15506 15507Semantics: 15508"""""""""" 15509 15510The '``llvm.cttz``' intrinsic counts the trailing (least significant) 15511zeros in a variable, or within each element of a vector. If ``src == 0`` 15512then the result is the size in bits of the type of ``src`` if 15513``is_zero_poison == 0`` and ``poison`` otherwise. For example, 15514``llvm.cttz(2) = 1``. 15515 15516.. _int_overflow: 15517 15518.. _int_fshl: 15519 15520'``llvm.fshl.*``' Intrinsic 15521^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15522 15523Syntax: 15524""""""" 15525 15526This is an overloaded intrinsic. You can use ``llvm.fshl`` on any 15527integer bit width or any vector of integer elements. Not all targets 15528support all bit widths or vector types, however. 15529 15530:: 15531 15532 declare i8 @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c) 15533 declare i67 @llvm.fshl.i67(i67 %a, i67 %b, i67 %c) 15534 declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) 15535 15536Overview: 15537""""""""" 15538 15539The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left: 15540the first two values are concatenated as { %a : %b } (%a is the most significant 15541bits of the wide value), the combined value is shifted left, and the most 15542significant bits are extracted to produce a result that is the same size as the 15543original arguments. If the first 2 arguments are identical, this is equivalent 15544to a rotate left operation. For vector types, the operation occurs for each 15545element of the vector. The shift argument is treated as an unsigned amount 15546modulo the element size of the arguments. 15547 15548Arguments: 15549"""""""""" 15550 15551The first two arguments are the values to be concatenated. The third 15552argument is the shift amount. The arguments may be any integer type or a 15553vector with integer element type. All arguments and the return value must 15554have the same type. 15555 15556Example: 15557"""""""" 15558 15559.. code-block:: text 15560 15561 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8) 15562 %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15) ; %r = i8: 128 (0b10000000) 15563 %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11) ; %r = i8: 120 (0b01111000) 15564 %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8) ; %r = i8: 0 (0b00000000) 15565 15566.. _int_fshr: 15567 15568'``llvm.fshr.*``' Intrinsic 15569^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15570 15571Syntax: 15572""""""" 15573 15574This is an overloaded intrinsic. You can use ``llvm.fshr`` on any 15575integer bit width or any vector of integer elements. Not all targets 15576support all bit widths or vector types, however. 15577 15578:: 15579 15580 declare i8 @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c) 15581 declare i67 @llvm.fshr.i67(i67 %a, i67 %b, i67 %c) 15582 declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) 15583 15584Overview: 15585""""""""" 15586 15587The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right: 15588the first two values are concatenated as { %a : %b } (%a is the most significant 15589bits of the wide value), the combined value is shifted right, and the least 15590significant bits are extracted to produce a result that is the same size as the 15591original arguments. If the first 2 arguments are identical, this is equivalent 15592to a rotate right operation. For vector types, the operation occurs for each 15593element of the vector. The shift argument is treated as an unsigned amount 15594modulo the element size of the arguments. 15595 15596Arguments: 15597"""""""""" 15598 15599The first two arguments are the values to be concatenated. The third 15600argument is the shift amount. The arguments may be any integer type or a 15601vector with integer element type. All arguments and the return value must 15602have the same type. 15603 15604Example: 15605"""""""" 15606 15607.. code-block:: text 15608 15609 %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8) 15610 %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15) ; %r = i8: 254 (0b11111110) 15611 %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11) ; %r = i8: 225 (0b11100001) 15612 %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8) ; %r = i8: 255 (0b11111111) 15613 15614Arithmetic with Overflow Intrinsics 15615----------------------------------- 15616 15617LLVM provides intrinsics for fast arithmetic overflow checking. 15618 15619Each of these intrinsics returns a two-element struct. The first 15620element of this struct contains the result of the corresponding 15621arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of 15622the result. Therefore, for example, the first element of the struct 15623returned by ``llvm.sadd.with.overflow.i32`` is always the same as the 15624result of a 32-bit ``add`` instruction with the same operands, where 15625the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag. 15626 15627The second element of the result is an ``i1`` that is 1 if the 15628arithmetic operation overflowed and 0 otherwise. An operation 15629overflows if, for any values of its operands ``A`` and ``B`` and for 15630any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is 15631not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is 15632``sext`` for signed overflow and ``zext`` for unsigned overflow, and 15633``op`` is the underlying arithmetic operation. 15634 15635The behavior of these intrinsics is well-defined for all argument 15636values. 15637 15638'``llvm.sadd.with.overflow.*``' Intrinsics 15639^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15640 15641Syntax: 15642""""""" 15643 15644This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow`` 15645on any integer bit width or vectors of integers. 15646 15647:: 15648 15649 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b) 15650 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) 15651 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b) 15652 declare {<4 x i32>, <4 x i1>} @llvm.sadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15653 15654Overview: 15655""""""""" 15656 15657The '``llvm.sadd.with.overflow``' family of intrinsic functions perform 15658a signed addition of the two arguments, and indicate whether an overflow 15659occurred during the signed summation. 15660 15661Arguments: 15662"""""""""" 15663 15664The arguments (%a and %b) and the first element of the result structure 15665may be of integer types of any bit width, but they must have the same 15666bit width. The second element of the result structure must be of type 15667``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 15668addition. 15669 15670Semantics: 15671"""""""""" 15672 15673The '``llvm.sadd.with.overflow``' family of intrinsic functions perform 15674a signed addition of the two variables. They return a structure --- the 15675first element of which is the signed summation, and the second element 15676of which is a bit specifying if the signed summation resulted in an 15677overflow. 15678 15679Examples: 15680""""""""" 15681 15682.. code-block:: llvm 15683 15684 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) 15685 %sum = extractvalue {i32, i1} %res, 0 15686 %obit = extractvalue {i32, i1} %res, 1 15687 br i1 %obit, label %overflow, label %normal 15688 15689'``llvm.uadd.with.overflow.*``' Intrinsics 15690^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15691 15692Syntax: 15693""""""" 15694 15695This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow`` 15696on any integer bit width or vectors of integers. 15697 15698:: 15699 15700 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b) 15701 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) 15702 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b) 15703 declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15704 15705Overview: 15706""""""""" 15707 15708The '``llvm.uadd.with.overflow``' family of intrinsic functions perform 15709an unsigned addition of the two arguments, and indicate whether a carry 15710occurred during the unsigned summation. 15711 15712Arguments: 15713"""""""""" 15714 15715The arguments (%a and %b) and the first element of the result structure 15716may be of integer types of any bit width, but they must have the same 15717bit width. The second element of the result structure must be of type 15718``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 15719addition. 15720 15721Semantics: 15722"""""""""" 15723 15724The '``llvm.uadd.with.overflow``' family of intrinsic functions perform 15725an unsigned addition of the two arguments. They return a structure --- the 15726first element of which is the sum, and the second element of which is a 15727bit specifying if the unsigned summation resulted in a carry. 15728 15729Examples: 15730""""""""" 15731 15732.. code-block:: llvm 15733 15734 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) 15735 %sum = extractvalue {i32, i1} %res, 0 15736 %obit = extractvalue {i32, i1} %res, 1 15737 br i1 %obit, label %carry, label %normal 15738 15739'``llvm.ssub.with.overflow.*``' Intrinsics 15740^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15741 15742Syntax: 15743""""""" 15744 15745This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow`` 15746on any integer bit width or vectors of integers. 15747 15748:: 15749 15750 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b) 15751 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) 15752 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b) 15753 declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15754 15755Overview: 15756""""""""" 15757 15758The '``llvm.ssub.with.overflow``' family of intrinsic functions perform 15759a signed subtraction of the two arguments, and indicate whether an 15760overflow occurred during the signed subtraction. 15761 15762Arguments: 15763"""""""""" 15764 15765The arguments (%a and %b) and the first element of the result structure 15766may be of integer types of any bit width, but they must have the same 15767bit width. The second element of the result structure must be of type 15768``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 15769subtraction. 15770 15771Semantics: 15772"""""""""" 15773 15774The '``llvm.ssub.with.overflow``' family of intrinsic functions perform 15775a signed subtraction of the two arguments. They return a structure --- the 15776first element of which is the subtraction, and the second element of 15777which is a bit specifying if the signed subtraction resulted in an 15778overflow. 15779 15780Examples: 15781""""""""" 15782 15783.. code-block:: llvm 15784 15785 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) 15786 %sum = extractvalue {i32, i1} %res, 0 15787 %obit = extractvalue {i32, i1} %res, 1 15788 br i1 %obit, label %overflow, label %normal 15789 15790'``llvm.usub.with.overflow.*``' Intrinsics 15791^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15792 15793Syntax: 15794""""""" 15795 15796This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow`` 15797on any integer bit width or vectors of integers. 15798 15799:: 15800 15801 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b) 15802 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) 15803 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b) 15804 declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15805 15806Overview: 15807""""""""" 15808 15809The '``llvm.usub.with.overflow``' family of intrinsic functions perform 15810an unsigned subtraction of the two arguments, and indicate whether an 15811overflow occurred during the unsigned subtraction. 15812 15813Arguments: 15814"""""""""" 15815 15816The arguments (%a and %b) and the first element of the result structure 15817may be of integer types of any bit width, but they must have the same 15818bit width. The second element of the result structure must be of type 15819``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 15820subtraction. 15821 15822Semantics: 15823"""""""""" 15824 15825The '``llvm.usub.with.overflow``' family of intrinsic functions perform 15826an unsigned subtraction of the two arguments. They return a structure --- 15827the first element of which is the subtraction, and the second element of 15828which is a bit specifying if the unsigned subtraction resulted in an 15829overflow. 15830 15831Examples: 15832""""""""" 15833 15834.. code-block:: llvm 15835 15836 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) 15837 %sum = extractvalue {i32, i1} %res, 0 15838 %obit = extractvalue {i32, i1} %res, 1 15839 br i1 %obit, label %overflow, label %normal 15840 15841'``llvm.smul.with.overflow.*``' Intrinsics 15842^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15843 15844Syntax: 15845""""""" 15846 15847This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow`` 15848on any integer bit width or vectors of integers. 15849 15850:: 15851 15852 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b) 15853 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) 15854 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b) 15855 declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15856 15857Overview: 15858""""""""" 15859 15860The '``llvm.smul.with.overflow``' family of intrinsic functions perform 15861a signed multiplication of the two arguments, and indicate whether an 15862overflow occurred during the signed multiplication. 15863 15864Arguments: 15865"""""""""" 15866 15867The arguments (%a and %b) and the first element of the result structure 15868may be of integer types of any bit width, but they must have the same 15869bit width. The second element of the result structure must be of type 15870``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 15871multiplication. 15872 15873Semantics: 15874"""""""""" 15875 15876The '``llvm.smul.with.overflow``' family of intrinsic functions perform 15877a signed multiplication of the two arguments. They return a structure --- 15878the first element of which is the multiplication, and the second element 15879of which is a bit specifying if the signed multiplication resulted in an 15880overflow. 15881 15882Examples: 15883""""""""" 15884 15885.. code-block:: llvm 15886 15887 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) 15888 %sum = extractvalue {i32, i1} %res, 0 15889 %obit = extractvalue {i32, i1} %res, 1 15890 br i1 %obit, label %overflow, label %normal 15891 15892'``llvm.umul.with.overflow.*``' Intrinsics 15893^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15894 15895Syntax: 15896""""""" 15897 15898This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow`` 15899on any integer bit width or vectors of integers. 15900 15901:: 15902 15903 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b) 15904 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) 15905 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b) 15906 declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15907 15908Overview: 15909""""""""" 15910 15911The '``llvm.umul.with.overflow``' family of intrinsic functions perform 15912a unsigned multiplication of the two arguments, and indicate whether an 15913overflow occurred during the unsigned multiplication. 15914 15915Arguments: 15916"""""""""" 15917 15918The arguments (%a and %b) and the first element of the result structure 15919may be of integer types of any bit width, but they must have the same 15920bit width. The second element of the result structure must be of type 15921``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 15922multiplication. 15923 15924Semantics: 15925"""""""""" 15926 15927The '``llvm.umul.with.overflow``' family of intrinsic functions perform 15928an unsigned multiplication of the two arguments. They return a structure --- 15929the first element of which is the multiplication, and the second 15930element of which is a bit specifying if the unsigned multiplication 15931resulted in an overflow. 15932 15933Examples: 15934""""""""" 15935 15936.. code-block:: llvm 15937 15938 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) 15939 %sum = extractvalue {i32, i1} %res, 0 15940 %obit = extractvalue {i32, i1} %res, 1 15941 br i1 %obit, label %overflow, label %normal 15942 15943Saturation Arithmetic Intrinsics 15944--------------------------------- 15945 15946Saturation arithmetic is a version of arithmetic in which operations are 15947limited to a fixed range between a minimum and maximum value. If the result of 15948an operation is greater than the maximum value, the result is set (or 15949"clamped") to this maximum. If it is below the minimum, it is clamped to this 15950minimum. 15951 15952 15953'``llvm.sadd.sat.*``' Intrinsics 15954^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15955 15956Syntax 15957""""""" 15958 15959This is an overloaded intrinsic. You can use ``llvm.sadd.sat`` 15960on any integer bit width or vectors of integers. 15961 15962:: 15963 15964 declare i16 @llvm.sadd.sat.i16(i16 %a, i16 %b) 15965 declare i32 @llvm.sadd.sat.i32(i32 %a, i32 %b) 15966 declare i64 @llvm.sadd.sat.i64(i64 %a, i64 %b) 15967 declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15968 15969Overview 15970""""""""" 15971 15972The '``llvm.sadd.sat``' family of intrinsic functions perform signed 15973saturating addition on the 2 arguments. 15974 15975Arguments 15976"""""""""" 15977 15978The arguments (%a and %b) and the result may be of integer types of any bit 15979width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15980values that will undergo signed addition. 15981 15982Semantics: 15983"""""""""" 15984 15985The maximum value this operation can clamp to is the largest signed value 15986representable by the bit width of the arguments. The minimum value is the 15987smallest signed value representable by this bit width. 15988 15989 15990Examples 15991""""""""" 15992 15993.. code-block:: llvm 15994 15995 %res = call i4 @llvm.sadd.sat.i4(i4 1, i4 2) ; %res = 3 15996 %res = call i4 @llvm.sadd.sat.i4(i4 5, i4 6) ; %res = 7 15997 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 2) ; %res = -2 15998 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 -5) ; %res = -8 15999 16000 16001'``llvm.uadd.sat.*``' Intrinsics 16002^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16003 16004Syntax 16005""""""" 16006 16007This is an overloaded intrinsic. You can use ``llvm.uadd.sat`` 16008on any integer bit width or vectors of integers. 16009 16010:: 16011 16012 declare i16 @llvm.uadd.sat.i16(i16 %a, i16 %b) 16013 declare i32 @llvm.uadd.sat.i32(i32 %a, i32 %b) 16014 declare i64 @llvm.uadd.sat.i64(i64 %a, i64 %b) 16015 declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 16016 16017Overview 16018""""""""" 16019 16020The '``llvm.uadd.sat``' family of intrinsic functions perform unsigned 16021saturating addition on the 2 arguments. 16022 16023Arguments 16024"""""""""" 16025 16026The arguments (%a and %b) and the result may be of integer types of any bit 16027width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16028values that will undergo unsigned addition. 16029 16030Semantics: 16031"""""""""" 16032 16033The maximum value this operation can clamp to is the largest unsigned value 16034representable by the bit width of the arguments. Because this is an unsigned 16035operation, the result will never saturate towards zero. 16036 16037 16038Examples 16039""""""""" 16040 16041.. code-block:: llvm 16042 16043 %res = call i4 @llvm.uadd.sat.i4(i4 1, i4 2) ; %res = 3 16044 %res = call i4 @llvm.uadd.sat.i4(i4 5, i4 6) ; %res = 11 16045 %res = call i4 @llvm.uadd.sat.i4(i4 8, i4 8) ; %res = 15 16046 16047 16048'``llvm.ssub.sat.*``' Intrinsics 16049^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16050 16051Syntax 16052""""""" 16053 16054This is an overloaded intrinsic. You can use ``llvm.ssub.sat`` 16055on any integer bit width or vectors of integers. 16056 16057:: 16058 16059 declare i16 @llvm.ssub.sat.i16(i16 %a, i16 %b) 16060 declare i32 @llvm.ssub.sat.i32(i32 %a, i32 %b) 16061 declare i64 @llvm.ssub.sat.i64(i64 %a, i64 %b) 16062 declare <4 x i32> @llvm.ssub.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 16063 16064Overview 16065""""""""" 16066 16067The '``llvm.ssub.sat``' family of intrinsic functions perform signed 16068saturating subtraction on the 2 arguments. 16069 16070Arguments 16071"""""""""" 16072 16073The arguments (%a and %b) and the result may be of integer types of any bit 16074width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16075values that will undergo signed subtraction. 16076 16077Semantics: 16078"""""""""" 16079 16080The maximum value this operation can clamp to is the largest signed value 16081representable by the bit width of the arguments. The minimum value is the 16082smallest signed value representable by this bit width. 16083 16084 16085Examples 16086""""""""" 16087 16088.. code-block:: llvm 16089 16090 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 1) ; %res = 1 16091 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 6) ; %res = -4 16092 %res = call i4 @llvm.ssub.sat.i4(i4 -4, i4 5) ; %res = -8 16093 %res = call i4 @llvm.ssub.sat.i4(i4 4, i4 -5) ; %res = 7 16094 16095 16096'``llvm.usub.sat.*``' Intrinsics 16097^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16098 16099Syntax 16100""""""" 16101 16102This is an overloaded intrinsic. You can use ``llvm.usub.sat`` 16103on any integer bit width or vectors of integers. 16104 16105:: 16106 16107 declare i16 @llvm.usub.sat.i16(i16 %a, i16 %b) 16108 declare i32 @llvm.usub.sat.i32(i32 %a, i32 %b) 16109 declare i64 @llvm.usub.sat.i64(i64 %a, i64 %b) 16110 declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 16111 16112Overview 16113""""""""" 16114 16115The '``llvm.usub.sat``' family of intrinsic functions perform unsigned 16116saturating subtraction on the 2 arguments. 16117 16118Arguments 16119"""""""""" 16120 16121The arguments (%a and %b) and the result may be of integer types of any bit 16122width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16123values that will undergo unsigned subtraction. 16124 16125Semantics: 16126"""""""""" 16127 16128The minimum value this operation can clamp to is 0, which is the smallest 16129unsigned value representable by the bit width of the unsigned arguments. 16130Because this is an unsigned operation, the result will never saturate towards 16131the largest possible value representable by this bit width. 16132 16133 16134Examples 16135""""""""" 16136 16137.. code-block:: llvm 16138 16139 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 1) ; %res = 1 16140 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 6) ; %res = 0 16141 16142 16143'``llvm.sshl.sat.*``' Intrinsics 16144^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16145 16146Syntax 16147""""""" 16148 16149This is an overloaded intrinsic. You can use ``llvm.sshl.sat`` 16150on integers or vectors of integers of any bit width. 16151 16152:: 16153 16154 declare i16 @llvm.sshl.sat.i16(i16 %a, i16 %b) 16155 declare i32 @llvm.sshl.sat.i32(i32 %a, i32 %b) 16156 declare i64 @llvm.sshl.sat.i64(i64 %a, i64 %b) 16157 declare <4 x i32> @llvm.sshl.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 16158 16159Overview 16160""""""""" 16161 16162The '``llvm.sshl.sat``' family of intrinsic functions perform signed 16163saturating left shift on the first argument. 16164 16165Arguments 16166"""""""""" 16167 16168The arguments (``%a`` and ``%b``) and the result may be of integer types of any 16169bit width, but they must have the same bit width. ``%a`` is the value to be 16170shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or 16171dynamically) equal to or larger than the integer bit width of the arguments, 16172the result is a :ref:`poison value <poisonvalues>`. If the arguments are 16173vectors, each vector element of ``a`` is shifted by the corresponding shift 16174amount in ``b``. 16175 16176 16177Semantics: 16178"""""""""" 16179 16180The maximum value this operation can clamp to is the largest signed value 16181representable by the bit width of the arguments. The minimum value is the 16182smallest signed value representable by this bit width. 16183 16184 16185Examples 16186""""""""" 16187 16188.. code-block:: llvm 16189 16190 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 1) ; %res = 4 16191 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 2) ; %res = 7 16192 %res = call i4 @llvm.sshl.sat.i4(i4 -5, i4 1) ; %res = -8 16193 %res = call i4 @llvm.sshl.sat.i4(i4 -1, i4 1) ; %res = -2 16194 16195 16196'``llvm.ushl.sat.*``' Intrinsics 16197^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16198 16199Syntax 16200""""""" 16201 16202This is an overloaded intrinsic. You can use ``llvm.ushl.sat`` 16203on integers or vectors of integers of any bit width. 16204 16205:: 16206 16207 declare i16 @llvm.ushl.sat.i16(i16 %a, i16 %b) 16208 declare i32 @llvm.ushl.sat.i32(i32 %a, i32 %b) 16209 declare i64 @llvm.ushl.sat.i64(i64 %a, i64 %b) 16210 declare <4 x i32> @llvm.ushl.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 16211 16212Overview 16213""""""""" 16214 16215The '``llvm.ushl.sat``' family of intrinsic functions perform unsigned 16216saturating left shift on the first argument. 16217 16218Arguments 16219"""""""""" 16220 16221The arguments (``%a`` and ``%b``) and the result may be of integer types of any 16222bit width, but they must have the same bit width. ``%a`` is the value to be 16223shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or 16224dynamically) equal to or larger than the integer bit width of the arguments, 16225the result is a :ref:`poison value <poisonvalues>`. If the arguments are 16226vectors, each vector element of ``a`` is shifted by the corresponding shift 16227amount in ``b``. 16228 16229Semantics: 16230"""""""""" 16231 16232The maximum value this operation can clamp to is the largest unsigned value 16233representable by the bit width of the arguments. 16234 16235 16236Examples 16237""""""""" 16238 16239.. code-block:: llvm 16240 16241 %res = call i4 @llvm.ushl.sat.i4(i4 2, i4 1) ; %res = 4 16242 %res = call i4 @llvm.ushl.sat.i4(i4 3, i4 3) ; %res = 15 16243 16244 16245Fixed Point Arithmetic Intrinsics 16246--------------------------------- 16247 16248A fixed point number represents a real data type for a number that has a fixed 16249number of digits after a radix point (equivalent to the decimal point '.'). 16250The number of digits after the radix point is referred as the `scale`. These 16251are useful for representing fractional values to a specific precision. The 16252following intrinsics perform fixed point arithmetic operations on 2 operands 16253of the same scale, specified as the third argument. 16254 16255The ``llvm.*mul.fix`` family of intrinsic functions represents a multiplication 16256of fixed point numbers through scaled integers. Therefore, fixed point 16257multiplication can be represented as 16258 16259.. code-block:: llvm 16260 16261 %result = call i4 @llvm.smul.fix.i4(i4 %a, i4 %b, i32 %scale) 16262 16263 ; Expands to 16264 %a2 = sext i4 %a to i8 16265 %b2 = sext i4 %b to i8 16266 %mul = mul nsw nuw i8 %a2, %b2 16267 %scale2 = trunc i32 %scale to i8 16268 %r = ashr i8 %mul, i8 %scale2 ; this is for a target rounding down towards negative infinity 16269 %result = trunc i8 %r to i4 16270 16271The ``llvm.*div.fix`` family of intrinsic functions represents a division of 16272fixed point numbers through scaled integers. Fixed point division can be 16273represented as: 16274 16275.. code-block:: llvm 16276 16277 %result call i4 @llvm.sdiv.fix.i4(i4 %a, i4 %b, i32 %scale) 16278 16279 ; Expands to 16280 %a2 = sext i4 %a to i8 16281 %b2 = sext i4 %b to i8 16282 %scale2 = trunc i32 %scale to i8 16283 %a3 = shl i8 %a2, %scale2 16284 %r = sdiv i8 %a3, %b2 ; this is for a target rounding towards zero 16285 %result = trunc i8 %r to i4 16286 16287For each of these functions, if the result cannot be represented exactly with 16288the provided scale, the result is rounded. Rounding is unspecified since 16289preferred rounding may vary for different targets. Rounding is specified 16290through a target hook. Different pipelines should legalize or optimize this 16291using the rounding specified by this hook if it is provided. Operations like 16292constant folding, instruction combining, KnownBits, and ValueTracking should 16293also use this hook, if provided, and not assume the direction of rounding. A 16294rounded result must always be within one unit of precision from the true 16295result. That is, the error between the returned result and the true result must 16296be less than 1/2^(scale). 16297 16298 16299'``llvm.smul.fix.*``' Intrinsics 16300^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16301 16302Syntax 16303""""""" 16304 16305This is an overloaded intrinsic. You can use ``llvm.smul.fix`` 16306on any integer bit width or vectors of integers. 16307 16308:: 16309 16310 declare i16 @llvm.smul.fix.i16(i16 %a, i16 %b, i32 %scale) 16311 declare i32 @llvm.smul.fix.i32(i32 %a, i32 %b, i32 %scale) 16312 declare i64 @llvm.smul.fix.i64(i64 %a, i64 %b, i32 %scale) 16313 declare <4 x i32> @llvm.smul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16314 16315Overview 16316""""""""" 16317 16318The '``llvm.smul.fix``' family of intrinsic functions perform signed 16319fixed point multiplication on 2 arguments of the same scale. 16320 16321Arguments 16322"""""""""" 16323 16324The arguments (%a and %b) and the result may be of integer types of any bit 16325width, but they must have the same bit width. The arguments may also work with 16326int vectors of the same length and int size. ``%a`` and ``%b`` are the two 16327values that will undergo signed fixed point multiplication. The argument 16328``%scale`` represents the scale of both operands, and must be a constant 16329integer. 16330 16331Semantics: 16332"""""""""" 16333 16334This operation performs fixed point multiplication on the 2 arguments of a 16335specified scale. The result will also be returned in the same scale specified 16336in the third argument. 16337 16338If the result value cannot be precisely represented in the given scale, the 16339value is rounded up or down to the closest representable value. The rounding 16340direction is unspecified. 16341 16342It is undefined behavior if the result value does not fit within the range of 16343the fixed point type. 16344 16345 16346Examples 16347""""""""" 16348 16349.. code-block:: llvm 16350 16351 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 16352 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 16353 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5) 16354 16355 ; The result in the following could be rounded up to -2 or down to -2.5 16356 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25) 16357 16358 16359'``llvm.umul.fix.*``' Intrinsics 16360^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16361 16362Syntax 16363""""""" 16364 16365This is an overloaded intrinsic. You can use ``llvm.umul.fix`` 16366on any integer bit width or vectors of integers. 16367 16368:: 16369 16370 declare i16 @llvm.umul.fix.i16(i16 %a, i16 %b, i32 %scale) 16371 declare i32 @llvm.umul.fix.i32(i32 %a, i32 %b, i32 %scale) 16372 declare i64 @llvm.umul.fix.i64(i64 %a, i64 %b, i32 %scale) 16373 declare <4 x i32> @llvm.umul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16374 16375Overview 16376""""""""" 16377 16378The '``llvm.umul.fix``' family of intrinsic functions perform unsigned 16379fixed point multiplication on 2 arguments of the same scale. 16380 16381Arguments 16382"""""""""" 16383 16384The arguments (%a and %b) and the result may be of integer types of any bit 16385width, but they must have the same bit width. The arguments may also work with 16386int vectors of the same length and int size. ``%a`` and ``%b`` are the two 16387values that will undergo unsigned fixed point multiplication. The argument 16388``%scale`` represents the scale of both operands, and must be a constant 16389integer. 16390 16391Semantics: 16392"""""""""" 16393 16394This operation performs unsigned fixed point multiplication on the 2 arguments of a 16395specified scale. The result will also be returned in the same scale specified 16396in the third argument. 16397 16398If the result value cannot be precisely represented in the given scale, the 16399value is rounded up or down to the closest representable value. The rounding 16400direction is unspecified. 16401 16402It is undefined behavior if the result value does not fit within the range of 16403the fixed point type. 16404 16405 16406Examples 16407""""""""" 16408 16409.. code-block:: llvm 16410 16411 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 16412 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 16413 16414 ; The result in the following could be rounded down to 3.5 or up to 4 16415 %res = call i4 @llvm.umul.fix.i4(i4 15, i4 1, i32 1) ; %res = 7 (or 8) (7.5 x 0.5 = 3.75) 16416 16417 16418'``llvm.smul.fix.sat.*``' Intrinsics 16419^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16420 16421Syntax 16422""""""" 16423 16424This is an overloaded intrinsic. You can use ``llvm.smul.fix.sat`` 16425on any integer bit width or vectors of integers. 16426 16427:: 16428 16429 declare i16 @llvm.smul.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16430 declare i32 @llvm.smul.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16431 declare i64 @llvm.smul.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16432 declare <4 x i32> @llvm.smul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16433 16434Overview 16435""""""""" 16436 16437The '``llvm.smul.fix.sat``' family of intrinsic functions perform signed 16438fixed point saturating multiplication on 2 arguments of the same scale. 16439 16440Arguments 16441"""""""""" 16442 16443The arguments (%a and %b) and the result may be of integer types of any bit 16444width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16445values that will undergo signed fixed point multiplication. The argument 16446``%scale`` represents the scale of both operands, and must be a constant 16447integer. 16448 16449Semantics: 16450"""""""""" 16451 16452This operation performs fixed point multiplication on the 2 arguments of a 16453specified scale. The result will also be returned in the same scale specified 16454in the third argument. 16455 16456If the result value cannot be precisely represented in the given scale, the 16457value is rounded up or down to the closest representable value. The rounding 16458direction is unspecified. 16459 16460The maximum value this operation can clamp to is the largest signed value 16461representable by the bit width of the first 2 arguments. The minimum value is the 16462smallest signed value representable by this bit width. 16463 16464 16465Examples 16466""""""""" 16467 16468.. code-block:: llvm 16469 16470 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 16471 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 16472 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5) 16473 16474 ; The result in the following could be rounded up to -2 or down to -2.5 16475 %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) 16476 16477 ; Saturation 16478 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 0) ; %res = 7 16479 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 4, i32 2) ; %res = 7 16480 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 5, i32 2) ; %res = -8 16481 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 -2, i32 1) ; %res = 7 16482 16483 ; Scale can affect the saturation result 16484 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7) 16485 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2) 16486 16487 16488'``llvm.umul.fix.sat.*``' Intrinsics 16489^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16490 16491Syntax 16492""""""" 16493 16494This is an overloaded intrinsic. You can use ``llvm.umul.fix.sat`` 16495on any integer bit width or vectors of integers. 16496 16497:: 16498 16499 declare i16 @llvm.umul.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16500 declare i32 @llvm.umul.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16501 declare i64 @llvm.umul.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16502 declare <4 x i32> @llvm.umul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16503 16504Overview 16505""""""""" 16506 16507The '``llvm.umul.fix.sat``' family of intrinsic functions perform unsigned 16508fixed point saturating multiplication on 2 arguments of the same scale. 16509 16510Arguments 16511"""""""""" 16512 16513The arguments (%a and %b) and the result may be of integer types of any bit 16514width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16515values that will undergo unsigned fixed point multiplication. The argument 16516``%scale`` represents the scale of both operands, and must be a constant 16517integer. 16518 16519Semantics: 16520"""""""""" 16521 16522This operation performs fixed point multiplication on the 2 arguments of a 16523specified scale. The result will also be returned in the same scale specified 16524in the third argument. 16525 16526If the result value cannot be precisely represented in the given scale, the 16527value is rounded up or down to the closest representable value. The rounding 16528direction is unspecified. 16529 16530The maximum value this operation can clamp to is the largest unsigned value 16531representable by the bit width of the first 2 arguments. The minimum value is the 16532smallest unsigned value representable by this bit width (zero). 16533 16534 16535Examples 16536""""""""" 16537 16538.. code-block:: llvm 16539 16540 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 16541 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 16542 16543 ; The result in the following could be rounded down to 2 or up to 2.5 16544 %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) 16545 16546 ; Saturation 16547 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 2, i32 0) ; %res = 15 (8 x 2 -> clamped to 15) 16548 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 8, i32 2) ; %res = 15 (2 x 2 -> clamped to 3.75) 16549 16550 ; Scale can affect the saturation result 16551 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7) 16552 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2) 16553 16554 16555'``llvm.sdiv.fix.*``' Intrinsics 16556^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16557 16558Syntax 16559""""""" 16560 16561This is an overloaded intrinsic. You can use ``llvm.sdiv.fix`` 16562on any integer bit width or vectors of integers. 16563 16564:: 16565 16566 declare i16 @llvm.sdiv.fix.i16(i16 %a, i16 %b, i32 %scale) 16567 declare i32 @llvm.sdiv.fix.i32(i32 %a, i32 %b, i32 %scale) 16568 declare i64 @llvm.sdiv.fix.i64(i64 %a, i64 %b, i32 %scale) 16569 declare <4 x i32> @llvm.sdiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16570 16571Overview 16572""""""""" 16573 16574The '``llvm.sdiv.fix``' family of intrinsic functions perform signed 16575fixed point division on 2 arguments of the same scale. 16576 16577Arguments 16578"""""""""" 16579 16580The arguments (%a and %b) and the result may be of integer types of any bit 16581width, but they must have the same bit width. The arguments may also work with 16582int vectors of the same length and int size. ``%a`` and ``%b`` are the two 16583values that will undergo signed fixed point division. The argument 16584``%scale`` represents the scale of both operands, and must be a constant 16585integer. 16586 16587Semantics: 16588"""""""""" 16589 16590This operation performs fixed point division on the 2 arguments of a 16591specified scale. The result will also be returned in the same scale specified 16592in the third argument. 16593 16594If the result value cannot be precisely represented in the given scale, the 16595value is rounded up or down to the closest representable value. The rounding 16596direction is unspecified. 16597 16598It is undefined behavior if the result value does not fit within the range of 16599the fixed point type, or if the second argument is zero. 16600 16601 16602Examples 16603""""""""" 16604 16605.. code-block:: llvm 16606 16607 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16608 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16609 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5) 16610 16611 ; The result in the following could be rounded up to 1 or down to 0.5 16612 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 16613 16614 16615'``llvm.udiv.fix.*``' Intrinsics 16616^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16617 16618Syntax 16619""""""" 16620 16621This is an overloaded intrinsic. You can use ``llvm.udiv.fix`` 16622on any integer bit width or vectors of integers. 16623 16624:: 16625 16626 declare i16 @llvm.udiv.fix.i16(i16 %a, i16 %b, i32 %scale) 16627 declare i32 @llvm.udiv.fix.i32(i32 %a, i32 %b, i32 %scale) 16628 declare i64 @llvm.udiv.fix.i64(i64 %a, i64 %b, i32 %scale) 16629 declare <4 x i32> @llvm.udiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16630 16631Overview 16632""""""""" 16633 16634The '``llvm.udiv.fix``' family of intrinsic functions perform unsigned 16635fixed point division on 2 arguments of the same scale. 16636 16637Arguments 16638"""""""""" 16639 16640The arguments (%a and %b) and the result may be of integer types of any bit 16641width, but they must have the same bit width. The arguments may also work with 16642int vectors of the same length and int size. ``%a`` and ``%b`` are the two 16643values that will undergo unsigned fixed point division. The argument 16644``%scale`` represents the scale of both operands, and must be a constant 16645integer. 16646 16647Semantics: 16648"""""""""" 16649 16650This operation performs fixed point division on the 2 arguments of a 16651specified scale. The result will also be returned in the same scale specified 16652in the third argument. 16653 16654If the result value cannot be precisely represented in the given scale, the 16655value is rounded up or down to the closest representable value. The rounding 16656direction is unspecified. 16657 16658It is undefined behavior if the result value does not fit within the range of 16659the fixed point type, or if the second argument is zero. 16660 16661 16662Examples 16663""""""""" 16664 16665.. code-block:: llvm 16666 16667 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16668 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16669 %res = call i4 @llvm.udiv.fix.i4(i4 1, i4 -8, i32 4) ; %res = 2 (0.0625 / 0.5 = 0.125) 16670 16671 ; The result in the following could be rounded up to 1 or down to 0.5 16672 %res = call i4 @llvm.udiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 16673 16674 16675'``llvm.sdiv.fix.sat.*``' Intrinsics 16676^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16677 16678Syntax 16679""""""" 16680 16681This is an overloaded intrinsic. You can use ``llvm.sdiv.fix.sat`` 16682on any integer bit width or vectors of integers. 16683 16684:: 16685 16686 declare i16 @llvm.sdiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16687 declare i32 @llvm.sdiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16688 declare i64 @llvm.sdiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16689 declare <4 x i32> @llvm.sdiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16690 16691Overview 16692""""""""" 16693 16694The '``llvm.sdiv.fix.sat``' family of intrinsic functions perform signed 16695fixed point saturating division on 2 arguments of the same scale. 16696 16697Arguments 16698"""""""""" 16699 16700The arguments (%a and %b) and the result may be of integer types of any bit 16701width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16702values that will undergo signed fixed point division. The argument 16703``%scale`` represents the scale of both operands, and must be a constant 16704integer. 16705 16706Semantics: 16707"""""""""" 16708 16709This operation performs fixed point division on the 2 arguments of a 16710specified scale. The result will also be returned in the same scale specified 16711in the third argument. 16712 16713If the result value cannot be precisely represented in the given scale, the 16714value is rounded up or down to the closest representable value. The rounding 16715direction is unspecified. 16716 16717The maximum value this operation can clamp to is the largest signed value 16718representable by the bit width of the first 2 arguments. The minimum value is the 16719smallest signed value representable by this bit width. 16720 16721It is undefined behavior if the second argument is zero. 16722 16723 16724Examples 16725""""""""" 16726 16727.. code-block:: llvm 16728 16729 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16730 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16731 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5) 16732 16733 ; The result in the following could be rounded up to 1 or down to 0.5 16734 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 16735 16736 ; Saturation 16737 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -8, i4 -1, i32 0) ; %res = 7 (-8 / -1 = 8 => 7) 16738 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 4, i4 2, i32 2) ; %res = 7 (1 / 0.5 = 2 => 1.75) 16739 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -4, i4 1, i32 2) ; %res = -8 (-1 / 0.25 = -4 => -2) 16740 16741 16742'``llvm.udiv.fix.sat.*``' Intrinsics 16743^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16744 16745Syntax 16746""""""" 16747 16748This is an overloaded intrinsic. You can use ``llvm.udiv.fix.sat`` 16749on any integer bit width or vectors of integers. 16750 16751:: 16752 16753 declare i16 @llvm.udiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16754 declare i32 @llvm.udiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16755 declare i64 @llvm.udiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16756 declare <4 x i32> @llvm.udiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16757 16758Overview 16759""""""""" 16760 16761The '``llvm.udiv.fix.sat``' family of intrinsic functions perform unsigned 16762fixed point saturating division on 2 arguments of the same scale. 16763 16764Arguments 16765"""""""""" 16766 16767The arguments (%a and %b) and the result may be of integer types of any bit 16768width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16769values that will undergo unsigned fixed point division. The argument 16770``%scale`` represents the scale of both operands, and must be a constant 16771integer. 16772 16773Semantics: 16774"""""""""" 16775 16776This operation performs fixed point division on the 2 arguments of a 16777specified scale. The result will also be returned in the same scale specified 16778in the third argument. 16779 16780If the result value cannot be precisely represented in the given scale, the 16781value is rounded up or down to the closest representable value. The rounding 16782direction is unspecified. 16783 16784The maximum value this operation can clamp to is the largest unsigned value 16785representable by the bit width of the first 2 arguments. The minimum value is the 16786smallest unsigned value representable by this bit width (zero). 16787 16788It is undefined behavior if the second argument is zero. 16789 16790Examples 16791""""""""" 16792 16793.. code-block:: llvm 16794 16795 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16796 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16797 16798 ; The result in the following could be rounded down to 0.5 or up to 1 16799 %res = call i4 @llvm.udiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 1 (or 2) (1.5 / 2 = 0.75) 16800 16801 ; Saturation 16802 %res = call i4 @llvm.udiv.fix.sat.i4(i4 8, i4 2, i32 2) ; %res = 15 (2 / 0.5 = 4 => 3.75) 16803 16804 16805Specialised Arithmetic Intrinsics 16806--------------------------------- 16807 16808.. _i_intr_llvm_canonicalize: 16809 16810'``llvm.canonicalize.*``' Intrinsic 16811^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16812 16813Syntax: 16814""""""" 16815 16816:: 16817 16818 declare float @llvm.canonicalize.f32(float %a) 16819 declare double @llvm.canonicalize.f64(double %b) 16820 16821Overview: 16822""""""""" 16823 16824The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical 16825encoding of a floating-point number. This canonicalization is useful for 16826implementing certain numeric primitives such as frexp. The canonical encoding is 16827defined by IEEE-754-2008 to be: 16828 16829:: 16830 16831 2.1.8 canonical encoding: The preferred encoding of a floating-point 16832 representation in a format. Applied to declets, significands of finite 16833 numbers, infinities, and NaNs, especially in decimal formats. 16834 16835This operation can also be considered equivalent to the IEEE-754-2008 16836conversion of a floating-point value to the same format. NaNs are handled 16837according to section 6.2. 16838 16839Examples of non-canonical encodings: 16840 16841- x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are 16842 converted to a canonical representation per hardware-specific protocol. 16843- Many normal decimal floating-point numbers have non-canonical alternative 16844 encodings. 16845- Some machines, like GPUs or ARMv7 NEON, do not support subnormal values. 16846 These are treated as non-canonical encodings of zero and will be flushed to 16847 a zero of the same sign by this operation. 16848 16849Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with 16850default exception handling must signal an invalid exception, and produce a 16851quiet NaN result. 16852 16853This function should always be implementable as multiplication by 1.0, provided 16854that the compiler does not constant fold the operation. Likewise, division by 168551.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with 16856-0.0 is also sufficient provided that the rounding mode is not -Infinity. 16857 16858``@llvm.canonicalize`` must preserve the equality relation. That is: 16859 16860- ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)`` 16861- ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent 16862 to ``(x == y)`` 16863 16864Additionally, the sign of zero must be conserved: 16865``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0`` 16866 16867The payload bits of a NaN must be conserved, with two exceptions. 16868First, environments which use only a single canonical representation of NaN 16869must perform said canonicalization. Second, SNaNs must be quieted per the 16870usual methods. 16871 16872The canonicalization operation may be optimized away if: 16873 16874- The input is known to be canonical. For example, it was produced by a 16875 floating-point operation that is required by the standard to be canonical. 16876- The result is consumed only by (or fused with) other floating-point 16877 operations. That is, the bits of the floating-point value are not examined. 16878 16879.. _int_fmuladd: 16880 16881'``llvm.fmuladd.*``' Intrinsic 16882^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16883 16884Syntax: 16885""""""" 16886 16887:: 16888 16889 declare float @llvm.fmuladd.f32(float %a, float %b, float %c) 16890 declare double @llvm.fmuladd.f64(double %a, double %b, double %c) 16891 16892Overview: 16893""""""""" 16894 16895The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add 16896expressions that can be fused if the code generator determines that (a) the 16897target instruction set has support for a fused operation, and (b) that the 16898fused operation is more efficient than the equivalent, separate pair of mul 16899and add instructions. 16900 16901Arguments: 16902"""""""""" 16903 16904The '``llvm.fmuladd.*``' intrinsics each take three arguments: two 16905multiplicands, a and b, and an addend c. 16906 16907Semantics: 16908"""""""""" 16909 16910The expression: 16911 16912:: 16913 16914 %0 = call float @llvm.fmuladd.f32(%a, %b, %c) 16915 16916is equivalent to the expression a \* b + c, except that it is unspecified 16917whether rounding will be performed between the multiplication and addition 16918steps. Fusion is not guaranteed, even if the target platform supports it. 16919If a fused multiply-add is required, the corresponding 16920:ref:`llvm.fma <int_fma>` intrinsic function should be used instead. 16921This never sets errno, just as '``llvm.fma.*``'. 16922 16923Examples: 16924""""""""" 16925 16926.. code-block:: llvm 16927 16928 %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c 16929 16930 16931Hardware-Loop Intrinsics 16932------------------------ 16933 16934LLVM support several intrinsics to mark a loop as a hardware-loop. They are 16935hints to the backend which are required to lower these intrinsics further to target 16936specific instructions, or revert the hardware-loop to a normal loop if target 16937specific restriction are not met and a hardware-loop can't be generated. 16938 16939These intrinsics may be modified in the future and are not intended to be used 16940outside the backend. Thus, front-end and mid-level optimizations should not be 16941generating these intrinsics. 16942 16943 16944'``llvm.set.loop.iterations.*``' Intrinsic 16945^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16946 16947Syntax: 16948""""""" 16949 16950This is an overloaded intrinsic. 16951 16952:: 16953 16954 declare void @llvm.set.loop.iterations.i32(i32) 16955 declare void @llvm.set.loop.iterations.i64(i64) 16956 16957Overview: 16958""""""""" 16959 16960The '``llvm.set.loop.iterations.*``' intrinsics are used to specify the 16961hardware-loop trip count. They are placed in the loop preheader basic block and 16962are marked as ``IntrNoDuplicate`` to avoid optimizers duplicating these 16963instructions. 16964 16965Arguments: 16966"""""""""" 16967 16968The integer operand is the loop trip count of the hardware-loop, and thus 16969not e.g. the loop back-edge taken count. 16970 16971Semantics: 16972"""""""""" 16973 16974The '``llvm.set.loop.iterations.*``' intrinsics do not perform any arithmetic 16975on their operand. It's a hint to the backend that can use this to set up the 16976hardware-loop count with a target specific instruction, usually a move of this 16977value to a special register or a hardware-loop instruction. 16978 16979 16980'``llvm.start.loop.iterations.*``' Intrinsic 16981^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16982 16983Syntax: 16984""""""" 16985 16986This is an overloaded intrinsic. 16987 16988:: 16989 16990 declare i32 @llvm.start.loop.iterations.i32(i32) 16991 declare i64 @llvm.start.loop.iterations.i64(i64) 16992 16993Overview: 16994""""""""" 16995 16996The '``llvm.start.loop.iterations.*``' intrinsics are similar to the 16997'``llvm.set.loop.iterations.*``' intrinsics, used to specify the 16998hardware-loop trip count but also produce a value identical to the input 16999that can be used as the input to the loop. They are placed in the loop 17000preheader basic block and the output is expected to be the input to the 17001phi for the induction variable of the loop, decremented by the 17002'``llvm.loop.decrement.reg.*``'. 17003 17004Arguments: 17005"""""""""" 17006 17007The integer operand is the loop trip count of the hardware-loop, and thus 17008not e.g. the loop back-edge taken count. 17009 17010Semantics: 17011"""""""""" 17012 17013The '``llvm.start.loop.iterations.*``' intrinsics do not perform any arithmetic 17014on their operand. It's a hint to the backend that can use this to set up the 17015hardware-loop count with a target specific instruction, usually a move of this 17016value to a special register or a hardware-loop instruction. 17017 17018'``llvm.test.set.loop.iterations.*``' Intrinsic 17019^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17020 17021Syntax: 17022""""""" 17023 17024This is an overloaded intrinsic. 17025 17026:: 17027 17028 declare i1 @llvm.test.set.loop.iterations.i32(i32) 17029 declare i1 @llvm.test.set.loop.iterations.i64(i64) 17030 17031Overview: 17032""""""""" 17033 17034The '``llvm.test.set.loop.iterations.*``' intrinsics are used to specify the 17035the loop trip count, and also test that the given count is not zero, allowing 17036it to control entry to a while-loop. They are placed in the loop preheader's 17037predecessor basic block, and are marked as ``IntrNoDuplicate`` to avoid 17038optimizers duplicating these instructions. 17039 17040Arguments: 17041"""""""""" 17042 17043The integer operand is the loop trip count of the hardware-loop, and thus 17044not e.g. the loop back-edge taken count. 17045 17046Semantics: 17047"""""""""" 17048 17049The '``llvm.test.set.loop.iterations.*``' intrinsics do not perform any 17050arithmetic on their operand. It's a hint to the backend that can use this to 17051set up the hardware-loop count with a target specific instruction, usually a 17052move of this value to a special register or a hardware-loop instruction. 17053The result is the conditional value of whether the given count is not zero. 17054 17055 17056'``llvm.test.start.loop.iterations.*``' Intrinsic 17057^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17058 17059Syntax: 17060""""""" 17061 17062This is an overloaded intrinsic. 17063 17064:: 17065 17066 declare {i32, i1} @llvm.test.start.loop.iterations.i32(i32) 17067 declare {i64, i1} @llvm.test.start.loop.iterations.i64(i64) 17068 17069Overview: 17070""""""""" 17071 17072The '``llvm.test.start.loop.iterations.*``' intrinsics are similar to the 17073'``llvm.test.set.loop.iterations.*``' and '``llvm.start.loop.iterations.*``' 17074intrinsics, used to specify the hardware-loop trip count, but also produce a 17075value identical to the input that can be used as the input to the loop. The 17076second i1 output controls entry to a while-loop. 17077 17078Arguments: 17079"""""""""" 17080 17081The integer operand is the loop trip count of the hardware-loop, and thus 17082not e.g. the loop back-edge taken count. 17083 17084Semantics: 17085"""""""""" 17086 17087The '``llvm.test.start.loop.iterations.*``' intrinsics do not perform any 17088arithmetic on their operand. It's a hint to the backend that can use this to 17089set up the hardware-loop count with a target specific instruction, usually a 17090move of this value to a special register or a hardware-loop instruction. 17091The result is a pair of the input and a conditional value of whether the 17092given count is not zero. 17093 17094 17095'``llvm.loop.decrement.reg.*``' Intrinsic 17096^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17097 17098Syntax: 17099""""""" 17100 17101This is an overloaded intrinsic. 17102 17103:: 17104 17105 declare i32 @llvm.loop.decrement.reg.i32(i32, i32) 17106 declare i64 @llvm.loop.decrement.reg.i64(i64, i64) 17107 17108Overview: 17109""""""""" 17110 17111The '``llvm.loop.decrement.reg.*``' intrinsics are used to lower the loop 17112iteration counter and return an updated value that will be used in the next 17113loop test check. 17114 17115Arguments: 17116"""""""""" 17117 17118Both arguments must have identical integer types. The first operand is the 17119loop iteration counter. The second operand is the maximum number of elements 17120processed in an iteration. 17121 17122Semantics: 17123"""""""""" 17124 17125The '``llvm.loop.decrement.reg.*``' intrinsics do an integer ``SUB`` of its 17126two operands, which is not allowed to wrap. They return the remaining number of 17127iterations still to be executed, and can be used together with a ``PHI``, 17128``ICMP`` and ``BR`` to control the number of loop iterations executed. Any 17129optimisations are allowed to treat it is a ``SUB``, and it is supported by 17130SCEV, so it's the backends responsibility to handle cases where it may be 17131optimised. These intrinsics are marked as ``IntrNoDuplicate`` to avoid 17132optimizers duplicating these instructions. 17133 17134 17135'``llvm.loop.decrement.*``' Intrinsic 17136^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17137 17138Syntax: 17139""""""" 17140 17141This is an overloaded intrinsic. 17142 17143:: 17144 17145 declare i1 @llvm.loop.decrement.i32(i32) 17146 declare i1 @llvm.loop.decrement.i64(i64) 17147 17148Overview: 17149""""""""" 17150 17151The HardwareLoops pass allows the loop decrement value to be specified with an 17152option. It defaults to a loop decrement value of 1, but it can be an unsigned 17153integer value provided by this option. The '``llvm.loop.decrement.*``' 17154intrinsics decrement the loop iteration counter with this value, and return a 17155false predicate if the loop should exit, and true otherwise. 17156This is emitted if the loop counter is not updated via a ``PHI`` node, which 17157can also be controlled with an option. 17158 17159Arguments: 17160"""""""""" 17161 17162The integer argument is the loop decrement value used to decrement the loop 17163iteration counter. 17164 17165Semantics: 17166"""""""""" 17167 17168The '``llvm.loop.decrement.*``' intrinsics do a ``SUB`` of the loop iteration 17169counter with the given loop decrement value, and return false if the loop 17170should exit, this ``SUB`` is not allowed to wrap. The result is a condition 17171that is used by the conditional branch controlling the loop. 17172 17173 17174Vector Reduction Intrinsics 17175--------------------------- 17176 17177Horizontal reductions of vectors can be expressed using the following 17178intrinsics. Each one takes a vector operand as an input and applies its 17179respective operation across all elements of the vector, returning a single 17180scalar result of the same element type. 17181 17182.. _int_vector_reduce_add: 17183 17184'``llvm.vector.reduce.add.*``' Intrinsic 17185^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17186 17187Syntax: 17188""""""" 17189 17190:: 17191 17192 declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a) 17193 declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a) 17194 17195Overview: 17196""""""""" 17197 17198The '``llvm.vector.reduce.add.*``' intrinsics do an integer ``ADD`` 17199reduction of a vector, returning the result as a scalar. The return type matches 17200the element-type of the vector input. 17201 17202Arguments: 17203"""""""""" 17204The argument to this intrinsic must be a vector of integer values. 17205 17206.. _int_vector_reduce_fadd: 17207 17208'``llvm.vector.reduce.fadd.*``' Intrinsic 17209^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17210 17211Syntax: 17212""""""" 17213 17214:: 17215 17216 declare float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %a) 17217 declare double @llvm.vector.reduce.fadd.v2f64(double %start_value, <2 x double> %a) 17218 17219Overview: 17220""""""""" 17221 17222The '``llvm.vector.reduce.fadd.*``' intrinsics do a floating-point 17223``ADD`` reduction of a vector, returning the result as a scalar. The return type 17224matches the element-type of the vector input. 17225 17226If the intrinsic call has the 'reassoc' flag set, then the reduction will not 17227preserve the associativity of an equivalent scalarized counterpart. Otherwise 17228the reduction will be *sequential*, thus implying that the operation respects 17229the associativity of a scalarized reduction. That is, the reduction begins with 17230the start value and performs an fadd operation with consecutively increasing 17231vector element indices. See the following pseudocode: 17232 17233:: 17234 17235 float sequential_fadd(start_value, input_vector) 17236 result = start_value 17237 for i = 0 to length(input_vector) 17238 result = result + input_vector[i] 17239 return result 17240 17241 17242Arguments: 17243"""""""""" 17244The first argument to this intrinsic is a scalar start value for the reduction. 17245The type of the start value matches the element-type of the vector input. 17246The second argument must be a vector of floating-point values. 17247 17248To ignore the start value, negative zero (``-0.0``) can be used, as it is 17249the neutral value of floating point addition. 17250 17251Examples: 17252""""""""" 17253 17254:: 17255 17256 %unord = call reassoc float @llvm.vector.reduce.fadd.v4f32(float -0.0, <4 x float> %input) ; relaxed reduction 17257 %ord = call float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %input) ; sequential reduction 17258 17259 17260.. _int_vector_reduce_mul: 17261 17262'``llvm.vector.reduce.mul.*``' Intrinsic 17263^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17264 17265Syntax: 17266""""""" 17267 17268:: 17269 17270 declare i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %a) 17271 declare i64 @llvm.vector.reduce.mul.v2i64(<2 x i64> %a) 17272 17273Overview: 17274""""""""" 17275 17276The '``llvm.vector.reduce.mul.*``' intrinsics do an integer ``MUL`` 17277reduction of a vector, returning the result as a scalar. The return type matches 17278the element-type of the vector input. 17279 17280Arguments: 17281"""""""""" 17282The argument to this intrinsic must be a vector of integer values. 17283 17284.. _int_vector_reduce_fmul: 17285 17286'``llvm.vector.reduce.fmul.*``' Intrinsic 17287^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17288 17289Syntax: 17290""""""" 17291 17292:: 17293 17294 declare float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %a) 17295 declare double @llvm.vector.reduce.fmul.v2f64(double %start_value, <2 x double> %a) 17296 17297Overview: 17298""""""""" 17299 17300The '``llvm.vector.reduce.fmul.*``' intrinsics do a floating-point 17301``MUL`` reduction of a vector, returning the result as a scalar. The return type 17302matches the element-type of the vector input. 17303 17304If the intrinsic call has the 'reassoc' flag set, then the reduction will not 17305preserve the associativity of an equivalent scalarized counterpart. Otherwise 17306the reduction will be *sequential*, thus implying that the operation respects 17307the associativity of a scalarized reduction. That is, the reduction begins with 17308the start value and performs an fmul operation with consecutively increasing 17309vector element indices. See the following pseudocode: 17310 17311:: 17312 17313 float sequential_fmul(start_value, input_vector) 17314 result = start_value 17315 for i = 0 to length(input_vector) 17316 result = result * input_vector[i] 17317 return result 17318 17319 17320Arguments: 17321"""""""""" 17322The first argument to this intrinsic is a scalar start value for the reduction. 17323The type of the start value matches the element-type of the vector input. 17324The second argument must be a vector of floating-point values. 17325 17326To ignore the start value, one (``1.0``) can be used, as it is the neutral 17327value of floating point multiplication. 17328 17329Examples: 17330""""""""" 17331 17332:: 17333 17334 %unord = call reassoc float @llvm.vector.reduce.fmul.v4f32(float 1.0, <4 x float> %input) ; relaxed reduction 17335 %ord = call float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %input) ; sequential reduction 17336 17337.. _int_vector_reduce_and: 17338 17339'``llvm.vector.reduce.and.*``' Intrinsic 17340^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17341 17342Syntax: 17343""""""" 17344 17345:: 17346 17347 declare i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %a) 17348 17349Overview: 17350""""""""" 17351 17352The '``llvm.vector.reduce.and.*``' intrinsics do a bitwise ``AND`` 17353reduction of a vector, returning the result as a scalar. The return type matches 17354the element-type of the vector input. 17355 17356Arguments: 17357"""""""""" 17358The argument to this intrinsic must be a vector of integer values. 17359 17360.. _int_vector_reduce_or: 17361 17362'``llvm.vector.reduce.or.*``' Intrinsic 17363^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17364 17365Syntax: 17366""""""" 17367 17368:: 17369 17370 declare i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %a) 17371 17372Overview: 17373""""""""" 17374 17375The '``llvm.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction 17376of a vector, returning the result as a scalar. The return type matches the 17377element-type of the vector input. 17378 17379Arguments: 17380"""""""""" 17381The argument to this intrinsic must be a vector of integer values. 17382 17383.. _int_vector_reduce_xor: 17384 17385'``llvm.vector.reduce.xor.*``' Intrinsic 17386^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17387 17388Syntax: 17389""""""" 17390 17391:: 17392 17393 declare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %a) 17394 17395Overview: 17396""""""""" 17397 17398The '``llvm.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR`` 17399reduction of a vector, returning the result as a scalar. The return type matches 17400the element-type of the vector input. 17401 17402Arguments: 17403"""""""""" 17404The argument to this intrinsic must be a vector of integer values. 17405 17406.. _int_vector_reduce_smax: 17407 17408'``llvm.vector.reduce.smax.*``' Intrinsic 17409^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17410 17411Syntax: 17412""""""" 17413 17414:: 17415 17416 declare i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %a) 17417 17418Overview: 17419""""""""" 17420 17421The '``llvm.vector.reduce.smax.*``' intrinsics do a signed integer 17422``MAX`` reduction of a vector, returning the result as a scalar. The return type 17423matches the element-type of the vector input. 17424 17425Arguments: 17426"""""""""" 17427The argument to this intrinsic must be a vector of integer values. 17428 17429.. _int_vector_reduce_smin: 17430 17431'``llvm.vector.reduce.smin.*``' Intrinsic 17432^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17433 17434Syntax: 17435""""""" 17436 17437:: 17438 17439 declare i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %a) 17440 17441Overview: 17442""""""""" 17443 17444The '``llvm.vector.reduce.smin.*``' intrinsics do a signed integer 17445``MIN`` reduction of a vector, returning the result as a scalar. The return type 17446matches the element-type of the vector input. 17447 17448Arguments: 17449"""""""""" 17450The argument to this intrinsic must be a vector of integer values. 17451 17452.. _int_vector_reduce_umax: 17453 17454'``llvm.vector.reduce.umax.*``' Intrinsic 17455^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17456 17457Syntax: 17458""""""" 17459 17460:: 17461 17462 declare i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %a) 17463 17464Overview: 17465""""""""" 17466 17467The '``llvm.vector.reduce.umax.*``' intrinsics do an unsigned 17468integer ``MAX`` reduction of a vector, returning the result as a scalar. The 17469return type matches the element-type of the vector input. 17470 17471Arguments: 17472"""""""""" 17473The argument to this intrinsic must be a vector of integer values. 17474 17475.. _int_vector_reduce_umin: 17476 17477'``llvm.vector.reduce.umin.*``' Intrinsic 17478^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17479 17480Syntax: 17481""""""" 17482 17483:: 17484 17485 declare i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %a) 17486 17487Overview: 17488""""""""" 17489 17490The '``llvm.vector.reduce.umin.*``' intrinsics do an unsigned 17491integer ``MIN`` reduction of a vector, returning the result as a scalar. The 17492return type matches the element-type of the vector input. 17493 17494Arguments: 17495"""""""""" 17496The argument to this intrinsic must be a vector of integer values. 17497 17498.. _int_vector_reduce_fmax: 17499 17500'``llvm.vector.reduce.fmax.*``' Intrinsic 17501^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17502 17503Syntax: 17504""""""" 17505 17506:: 17507 17508 declare float @llvm.vector.reduce.fmax.v4f32(<4 x float> %a) 17509 declare double @llvm.vector.reduce.fmax.v2f64(<2 x double> %a) 17510 17511Overview: 17512""""""""" 17513 17514The '``llvm.vector.reduce.fmax.*``' intrinsics do a floating-point 17515``MAX`` reduction of a vector, returning the result as a scalar. The return type 17516matches the element-type of the vector input. 17517 17518This instruction has the same comparison semantics as the '``llvm.maxnum.*``' 17519intrinsic. That is, the result will always be a number unless all elements of 17520the vector are NaN. For a vector with maximum element magnitude 0.0 and 17521containing both +0.0 and -0.0 elements, the sign of the result is unspecified. 17522 17523If the intrinsic call has the ``nnan`` fast-math flag, then the operation can 17524assume that NaNs are not present in the input vector. 17525 17526Arguments: 17527"""""""""" 17528The argument to this intrinsic must be a vector of floating-point values. 17529 17530.. _int_vector_reduce_fmin: 17531 17532'``llvm.vector.reduce.fmin.*``' Intrinsic 17533^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17534 17535Syntax: 17536""""""" 17537This is an overloaded intrinsic. 17538 17539:: 17540 17541 declare float @llvm.vector.reduce.fmin.v4f32(<4 x float> %a) 17542 declare double @llvm.vector.reduce.fmin.v2f64(<2 x double> %a) 17543 17544Overview: 17545""""""""" 17546 17547The '``llvm.vector.reduce.fmin.*``' intrinsics do a floating-point 17548``MIN`` reduction of a vector, returning the result as a scalar. The return type 17549matches the element-type of the vector input. 17550 17551This instruction has the same comparison semantics as the '``llvm.minnum.*``' 17552intrinsic. That is, the result will always be a number unless all elements of 17553the vector are NaN. For a vector with minimum element magnitude 0.0 and 17554containing both +0.0 and -0.0 elements, the sign of the result is unspecified. 17555 17556If the intrinsic call has the ``nnan`` fast-math flag, then the operation can 17557assume that NaNs are not present in the input vector. 17558 17559Arguments: 17560"""""""""" 17561The argument to this intrinsic must be a vector of floating-point values. 17562 17563'``llvm.vector.insert``' Intrinsic 17564^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17565 17566Syntax: 17567""""""" 17568This is an overloaded intrinsic. 17569 17570:: 17571 17572 ; Insert fixed type into scalable type 17573 declare <vscale x 4 x float> @llvm.vector.insert.nxv4f32.v4f32(<vscale x 4 x float> %vec, <4 x float> %subvec, i64 <idx>) 17574 declare <vscale x 2 x double> @llvm.vector.insert.nxv2f64.v2f64(<vscale x 2 x double> %vec, <2 x double> %subvec, i64 <idx>) 17575 17576 ; Insert scalable type into scalable type 17577 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>) 17578 17579 ; Insert fixed type into fixed type 17580 declare <4 x double> @llvm.vector.insert.v4f64.v2f64(<4 x double> %vec, <2 x double> %subvec, i64 <idx>) 17581 17582Overview: 17583""""""""" 17584 17585The '``llvm.vector.insert.*``' intrinsics insert a vector into another vector 17586starting from a given index. The return type matches the type of the vector we 17587insert into. Conceptually, this can be used to build a scalable vector out of 17588non-scalable vectors, however this intrinsic can also be used on purely fixed 17589types. 17590 17591Scalable vectors can only be inserted into other scalable vectors. 17592 17593Arguments: 17594"""""""""" 17595 17596The ``vec`` is the vector which ``subvec`` will be inserted into. 17597The ``subvec`` is the vector that will be inserted. 17598 17599``idx`` represents the starting element number at which ``subvec`` will be 17600inserted. ``idx`` must be a constant multiple of ``subvec``'s known minimum 17601vector length. If ``subvec`` is a scalable vector, ``idx`` is first scaled by 17602the runtime scaling factor of ``subvec``. The elements of ``vec`` starting at 17603``idx`` are overwritten with ``subvec``. Elements ``idx`` through (``idx`` + 17604num_elements(``subvec``) - 1) must be valid ``vec`` indices. If this condition 17605cannot be determined statically but is false at runtime, then the result vector 17606is a :ref:`poison value <poisonvalues>`. 17607 17608 17609'``llvm.vector.extract``' Intrinsic 17610^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17611 17612Syntax: 17613""""""" 17614This is an overloaded intrinsic. 17615 17616:: 17617 17618 ; Extract fixed type from scalable type 17619 declare <4 x float> @llvm.vector.extract.v4f32.nxv4f32(<vscale x 4 x float> %vec, i64 <idx>) 17620 declare <2 x double> @llvm.vector.extract.v2f64.nxv2f64(<vscale x 2 x double> %vec, i64 <idx>) 17621 17622 ; Extract scalable type from scalable type 17623 declare <vscale x 2 x float> @llvm.vector.extract.nxv2f32.nxv4f32(<vscale x 4 x float> %vec, i64 <idx>) 17624 17625 ; Extract fixed type from fixed type 17626 declare <2 x double> @llvm.vector.extract.v2f64.v4f64(<4 x double> %vec, i64 <idx>) 17627 17628Overview: 17629""""""""" 17630 17631The '``llvm.vector.extract.*``' intrinsics extract a vector from within another 17632vector starting from a given index. The return type must be explicitly 17633specified. Conceptually, this can be used to decompose a scalable vector into 17634non-scalable parts, however this intrinsic can also be used on purely fixed 17635types. 17636 17637Scalable vectors can only be extracted from other scalable vectors. 17638 17639Arguments: 17640"""""""""" 17641 17642The ``vec`` is the vector from which we will extract a subvector. 17643 17644The ``idx`` specifies the starting element number within ``vec`` from which a 17645subvector is extracted. ``idx`` must be a constant multiple of the known-minimum 17646vector length of the result type. If the result type is a scalable vector, 17647``idx`` is first scaled by the result type's runtime scaling factor. Elements 17648``idx`` through (``idx`` + num_elements(result_type) - 1) must be valid vector 17649indices. If this condition cannot be determined statically but is false at 17650runtime, then the result vector is a :ref:`poison value <poisonvalues>`. The 17651``idx`` parameter must be a vector index constant type (for most targets this 17652will be an integer pointer type). 17653 17654'``llvm.experimental.vector.reverse``' Intrinsic 17655^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17656 17657Syntax: 17658""""""" 17659This is an overloaded intrinsic. 17660 17661:: 17662 17663 declare <2 x i8> @llvm.experimental.vector.reverse.v2i8(<2 x i8> %a) 17664 declare <vscale x 4 x i32> @llvm.experimental.vector.reverse.nxv4i32(<vscale x 4 x i32> %a) 17665 17666Overview: 17667""""""""" 17668 17669The '``llvm.experimental.vector.reverse.*``' intrinsics reverse a vector. 17670The intrinsic takes a single vector and returns a vector of matching type but 17671with the original lane order reversed. These intrinsics work for both fixed 17672and scalable vectors. While this intrinsic is marked as experimental the 17673recommended way to express reverse operations for fixed-width vectors is still 17674to use a shufflevector, as that may allow for more optimization opportunities. 17675 17676Arguments: 17677"""""""""" 17678 17679The argument to this intrinsic must be a vector. 17680 17681'``llvm.experimental.vector.splice``' Intrinsic 17682^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17683 17684Syntax: 17685""""""" 17686This is an overloaded intrinsic. 17687 17688:: 17689 17690 declare <2 x double> @llvm.experimental.vector.splice.v2f64(<2 x double> %vec1, <2 x double> %vec2, i32 %imm) 17691 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) 17692 17693Overview: 17694""""""""" 17695 17696The '``llvm.experimental.vector.splice.*``' intrinsics construct a vector by 17697concatenating elements from the first input vector with elements of the second 17698input vector, returning a vector of the same type as the input vectors. The 17699signed immediate, modulo the number of elements in the vector, is the index 17700into the first vector from which to extract the result value. This means 17701conceptually that for a positive immediate, a vector is extracted from 17702``concat(%vec1, %vec2)`` starting at index ``imm``, whereas for a negative 17703immediate, it extracts ``-imm`` trailing elements from the first vector, and 17704the remaining elements from ``%vec2``. 17705 17706These intrinsics work for both fixed and scalable vectors. While this intrinsic 17707is marked as experimental, the recommended way to express this operation for 17708fixed-width vectors is still to use a shufflevector, as that may allow for more 17709optimization opportunities. 17710 17711For example: 17712 17713.. code-block:: text 17714 17715 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, 1) ==> <B, C, D, E> ; index 17716 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, -3) ==> <B, C, D, E> ; trailing elements 17717 17718 17719Arguments: 17720"""""""""" 17721 17722The first two operands are vectors with the same type. The start index is imm 17723modulo the runtime number of elements in the source vector. For a fixed-width 17724vector <N x eltty>, imm is a signed integer constant in the range 17725-N <= imm < N. For a scalable vector <vscale x N x eltty>, imm is a signed 17726integer constant in the range -X <= imm < X where X=vscale_range_min * N. 17727 17728'``llvm.experimental.stepvector``' Intrinsic 17729^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17730 17731This is an overloaded intrinsic. You can use ``llvm.experimental.stepvector`` 17732to generate a vector whose lane values comprise the linear sequence 17733<0, 1, 2, ...>. It is primarily intended for scalable vectors. 17734 17735:: 17736 17737 declare <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32() 17738 declare <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16() 17739 17740The '``llvm.experimental.stepvector``' intrinsics are used to create vectors 17741of integers whose elements contain a linear sequence of values starting from 0 17742with a step of 1. This experimental intrinsic can only be used for vectors 17743with integer elements that are at least 8 bits in size. If the sequence value 17744exceeds the allowed limit for the element type then the result for that lane is 17745undefined. 17746 17747These intrinsics work for both fixed and scalable vectors. While this intrinsic 17748is marked as experimental, the recommended way to express this operation for 17749fixed-width vectors is still to generate a constant vector instead. 17750 17751 17752Arguments: 17753"""""""""" 17754 17755None. 17756 17757 17758Matrix Intrinsics 17759----------------- 17760 17761Operations on matrixes requiring shape information (like number of rows/columns 17762or the memory layout) can be expressed using the matrix intrinsics. These 17763intrinsics require matrix dimensions to be passed as immediate arguments, and 17764matrixes are passed and returned as vectors. This means that for a ``R`` x 17765``C`` matrix, element ``i`` of column ``j`` is at index ``j * R + i`` in the 17766corresponding vector, with indices starting at 0. Currently column-major layout 17767is assumed. The intrinsics support both integer and floating point matrixes. 17768 17769 17770'``llvm.matrix.transpose.*``' Intrinsic 17771^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17772 17773Syntax: 17774""""""" 17775This is an overloaded intrinsic. 17776 17777:: 17778 17779 declare vectorty @llvm.matrix.transpose.*(vectorty %In, i32 <Rows>, i32 <Cols>) 17780 17781Overview: 17782""""""""" 17783 17784The '``llvm.matrix.transpose.*``' intrinsics treat ``%In`` as a ``<Rows> x 17785<Cols>`` matrix and return the transposed matrix in the result vector. 17786 17787Arguments: 17788"""""""""" 17789 17790The first argument ``%In`` is a vector that corresponds to a ``<Rows> x 17791<Cols>`` matrix. Thus, arguments ``<Rows>`` and ``<Cols>`` correspond to the 17792number of rows and columns, respectively, and must be positive, constant 17793integers. The returned vector must have ``<Rows> * <Cols>`` elements, and have 17794the same float or integer element type as ``%In``. 17795 17796'``llvm.matrix.multiply.*``' Intrinsic 17797^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17798 17799Syntax: 17800""""""" 17801This is an overloaded intrinsic. 17802 17803:: 17804 17805 declare vectorty @llvm.matrix.multiply.*(vectorty %A, vectorty %B, i32 <OuterRows>, i32 <Inner>, i32 <OuterColumns>) 17806 17807Overview: 17808""""""""" 17809 17810The '``llvm.matrix.multiply.*``' intrinsics treat ``%A`` as a ``<OuterRows> x 17811<Inner>`` matrix, ``%B`` as a ``<Inner> x <OuterColumns>`` matrix, and 17812multiplies them. The result matrix is returned in the result vector. 17813 17814Arguments: 17815"""""""""" 17816 17817The first vector argument ``%A`` corresponds to a matrix with ``<OuterRows> * 17818<Inner>`` elements, and the second argument ``%B`` to a matrix with 17819``<Inner> * <OuterColumns>`` elements. Arguments ``<OuterRows>``, 17820``<Inner>`` and ``<OuterColumns>`` must be positive, constant integers. The 17821returned vector must have ``<OuterRows> * <OuterColumns>`` elements. 17822Vectors ``%A``, ``%B``, and the returned vector all have the same float or 17823integer element type. 17824 17825 17826'``llvm.matrix.column.major.load.*``' Intrinsic 17827^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17828 17829Syntax: 17830""""""" 17831This is an overloaded intrinsic. 17832 17833:: 17834 17835 declare vectorty @llvm.matrix.column.major.load.*( 17836 ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>) 17837 17838Overview: 17839""""""""" 17840 17841The '``llvm.matrix.column.major.load.*``' intrinsics load a ``<Rows> x <Cols>`` 17842matrix using a stride of ``%Stride`` to compute the start address of the 17843different columns. The offset is computed using ``%Stride``'s bitwidth. This 17844allows for convenient loading of sub matrixes. If ``<IsVolatile>`` is true, the 17845intrinsic is considered a :ref:`volatile memory access <volatile>`. The result 17846matrix is returned in the result vector. If the ``%Ptr`` argument is known to 17847be aligned to some boundary, this can be specified as an attribute on the 17848argument. 17849 17850Arguments: 17851"""""""""" 17852 17853The first argument ``%Ptr`` is a pointer type to the returned vector type, and 17854corresponds to the start address to load from. The second argument ``%Stride`` 17855is a positive, constant integer with ``%Stride >= <Rows>``. ``%Stride`` is used 17856to compute the column memory addresses. I.e., for a column ``C``, its start 17857memory addresses is calculated with ``%Ptr + C * %Stride``. The third Argument 17858``<IsVolatile>`` is a boolean value. The fourth and fifth arguments, 17859``<Rows>`` and ``<Cols>``, correspond to the number of rows and columns, 17860respectively, and must be positive, constant integers. The returned vector must 17861have ``<Rows> * <Cols>`` elements. 17862 17863The :ref:`align <attr_align>` parameter attribute can be provided for the 17864``%Ptr`` arguments. 17865 17866 17867'``llvm.matrix.column.major.store.*``' Intrinsic 17868^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17869 17870Syntax: 17871""""""" 17872 17873:: 17874 17875 declare void @llvm.matrix.column.major.store.*( 17876 vectorty %In, ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>) 17877 17878Overview: 17879""""""""" 17880 17881The '``llvm.matrix.column.major.store.*``' intrinsics store the ``<Rows> x 17882<Cols>`` matrix in ``%In`` to memory using a stride of ``%Stride`` between 17883columns. The offset is computed using ``%Stride``'s bitwidth. If 17884``<IsVolatile>`` is true, the intrinsic is considered a 17885:ref:`volatile memory access <volatile>`. 17886 17887If the ``%Ptr`` argument is known to be aligned to some boundary, this can be 17888specified as an attribute on the argument. 17889 17890Arguments: 17891"""""""""" 17892 17893The first argument ``%In`` is a vector that corresponds to a ``<Rows> x 17894<Cols>`` matrix to be stored to memory. The second argument ``%Ptr`` is a 17895pointer to the vector type of ``%In``, and is the start address of the matrix 17896in memory. The third argument ``%Stride`` is a positive, constant integer with 17897``%Stride >= <Rows>``. ``%Stride`` is used to compute the column memory 17898addresses. I.e., for a column ``C``, its start memory addresses is calculated 17899with ``%Ptr + C * %Stride``. The fourth argument ``<IsVolatile>`` is a boolean 17900value. The arguments ``<Rows>`` and ``<Cols>`` correspond to the number of rows 17901and columns, respectively, and must be positive, constant integers. 17902 17903The :ref:`align <attr_align>` parameter attribute can be provided 17904for the ``%Ptr`` arguments. 17905 17906 17907Half Precision Floating-Point Intrinsics 17908---------------------------------------- 17909 17910For most target platforms, half precision floating-point is a 17911storage-only format. This means that it is a dense encoding (in memory) 17912but does not support computation in the format. 17913 17914This means that code must first load the half-precision floating-point 17915value as an i16, then convert it to float with 17916:ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can 17917then be performed on the float value (including extending to double 17918etc). To store the value back to memory, it is first converted to float 17919if needed, then converted to i16 with 17920:ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an 17921i16 value. 17922 17923.. _int_convert_to_fp16: 17924 17925'``llvm.convert.to.fp16``' Intrinsic 17926^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17927 17928Syntax: 17929""""""" 17930 17931:: 17932 17933 declare i16 @llvm.convert.to.fp16.f32(float %a) 17934 declare i16 @llvm.convert.to.fp16.f64(double %a) 17935 17936Overview: 17937""""""""" 17938 17939The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a 17940conventional floating-point type to half precision floating-point format. 17941 17942Arguments: 17943"""""""""" 17944 17945The intrinsic function contains single argument - the value to be 17946converted. 17947 17948Semantics: 17949"""""""""" 17950 17951The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a 17952conventional floating-point format to half precision floating-point format. The 17953return value is an ``i16`` which contains the converted number. 17954 17955Examples: 17956""""""""" 17957 17958.. code-block:: llvm 17959 17960 %res = call i16 @llvm.convert.to.fp16.f32(float %a) 17961 store i16 %res, i16* @x, align 2 17962 17963.. _int_convert_from_fp16: 17964 17965'``llvm.convert.from.fp16``' Intrinsic 17966^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17967 17968Syntax: 17969""""""" 17970 17971:: 17972 17973 declare float @llvm.convert.from.fp16.f32(i16 %a) 17974 declare double @llvm.convert.from.fp16.f64(i16 %a) 17975 17976Overview: 17977""""""""" 17978 17979The '``llvm.convert.from.fp16``' intrinsic function performs a 17980conversion from half precision floating-point format to single precision 17981floating-point format. 17982 17983Arguments: 17984"""""""""" 17985 17986The intrinsic function contains single argument - the value to be 17987converted. 17988 17989Semantics: 17990"""""""""" 17991 17992The '``llvm.convert.from.fp16``' intrinsic function performs a 17993conversion from half single precision floating-point format to single 17994precision floating-point format. The input half-float value is 17995represented by an ``i16`` value. 17996 17997Examples: 17998""""""""" 17999 18000.. code-block:: llvm 18001 18002 %a = load i16, ptr @x, align 2 18003 %res = call float @llvm.convert.from.fp16(i16 %a) 18004 18005Saturating floating-point to integer conversions 18006------------------------------------------------ 18007 18008The ``fptoui`` and ``fptosi`` instructions return a 18009:ref:`poison value <poisonvalues>` if the rounded-towards-zero value is not 18010representable by the result type. These intrinsics provide an alternative 18011conversion, which will saturate towards the smallest and largest representable 18012integer values instead. 18013 18014'``llvm.fptoui.sat.*``' Intrinsic 18015^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18016 18017Syntax: 18018""""""" 18019 18020This is an overloaded intrinsic. You can use ``llvm.fptoui.sat`` on any 18021floating-point argument type and any integer result type, or vectors thereof. 18022Not all targets may support all types, however. 18023 18024:: 18025 18026 declare i32 @llvm.fptoui.sat.i32.f32(float %f) 18027 declare i19 @llvm.fptoui.sat.i19.f64(double %f) 18028 declare <4 x i100> @llvm.fptoui.sat.v4i100.v4f128(<4 x fp128> %f) 18029 18030Overview: 18031""""""""" 18032 18033This intrinsic converts the argument into an unsigned integer using saturating 18034semantics. 18035 18036Arguments: 18037"""""""""" 18038 18039The argument may be any floating-point or vector of floating-point type. The 18040return value may be any integer or vector of integer type. The number of vector 18041elements in argument and return must be the same. 18042 18043Semantics: 18044"""""""""" 18045 18046The conversion to integer is performed subject to the following rules: 18047 18048- If the argument is any NaN, zero is returned. 18049- If the argument is smaller than zero (this includes negative infinity), 18050 zero is returned. 18051- If the argument is larger than the largest representable unsigned integer of 18052 the result type (this includes positive infinity), the largest representable 18053 unsigned integer is returned. 18054- Otherwise, the result of rounding the argument towards zero is returned. 18055 18056Example: 18057"""""""" 18058 18059.. code-block:: text 18060 18061 %a = call i8 @llvm.fptoui.sat.i8.f32(float 123.9) ; yields i8: 123 18062 %b = call i8 @llvm.fptoui.sat.i8.f32(float -5.7) ; yields i8: 0 18063 %c = call i8 @llvm.fptoui.sat.i8.f32(float 377.0) ; yields i8: 255 18064 %d = call i8 @llvm.fptoui.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0 18065 18066'``llvm.fptosi.sat.*``' Intrinsic 18067^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18068 18069Syntax: 18070""""""" 18071 18072This is an overloaded intrinsic. You can use ``llvm.fptosi.sat`` on any 18073floating-point argument type and any integer result type, or vectors thereof. 18074Not all targets may support all types, however. 18075 18076:: 18077 18078 declare i32 @llvm.fptosi.sat.i32.f32(float %f) 18079 declare i19 @llvm.fptosi.sat.i19.f64(double %f) 18080 declare <4 x i100> @llvm.fptosi.sat.v4i100.v4f128(<4 x fp128> %f) 18081 18082Overview: 18083""""""""" 18084 18085This intrinsic converts the argument into a signed integer using saturating 18086semantics. 18087 18088Arguments: 18089"""""""""" 18090 18091The argument may be any floating-point or vector of floating-point type. The 18092return value may be any integer or vector of integer type. The number of vector 18093elements in argument and return must be the same. 18094 18095Semantics: 18096"""""""""" 18097 18098The conversion to integer is performed subject to the following rules: 18099 18100- If the argument is any NaN, zero is returned. 18101- If the argument is smaller than the smallest representable signed integer of 18102 the result type (this includes negative infinity), the smallest 18103 representable signed integer is returned. 18104- If the argument is larger than the largest representable signed integer of 18105 the result type (this includes positive infinity), the largest representable 18106 signed integer is returned. 18107- Otherwise, the result of rounding the argument towards zero is returned. 18108 18109Example: 18110"""""""" 18111 18112.. code-block:: text 18113 18114 %a = call i8 @llvm.fptosi.sat.i8.f32(float 23.9) ; yields i8: 23 18115 %b = call i8 @llvm.fptosi.sat.i8.f32(float -130.8) ; yields i8: -128 18116 %c = call i8 @llvm.fptosi.sat.i8.f32(float 999.0) ; yields i8: 127 18117 %d = call i8 @llvm.fptosi.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0 18118 18119.. _dbg_intrinsics: 18120 18121Debugger Intrinsics 18122------------------- 18123 18124The LLVM debugger intrinsics (which all start with ``llvm.dbg.`` 18125prefix), are described in the `LLVM Source Level 18126Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_ 18127document. 18128 18129Exception Handling Intrinsics 18130----------------------------- 18131 18132The LLVM exception handling intrinsics (which all start with 18133``llvm.eh.`` prefix), are described in the `LLVM Exception 18134Handling <ExceptionHandling.html#format-common-intrinsics>`_ document. 18135 18136Pointer Authentication Intrinsics 18137--------------------------------- 18138 18139The LLVM pointer authentication intrinsics (which all start with 18140``llvm.ptrauth.`` prefix), are described in the `Pointer Authentication 18141<PointerAuth.html#intrinsics>`_ document. 18142 18143.. _int_trampoline: 18144 18145Trampoline Intrinsics 18146--------------------- 18147 18148These intrinsics make it possible to excise one parameter, marked with 18149the :ref:`nest <nest>` attribute, from a function. The result is a 18150callable function pointer lacking the nest parameter - the caller does 18151not need to provide a value for it. Instead, the value to use is stored 18152in advance in a "trampoline", a block of memory usually allocated on the 18153stack, which also contains code to splice the nest value into the 18154argument list. This is used to implement the GCC nested function address 18155extension. 18156 18157For example, if the function is ``i32 f(ptr nest %c, i32 %x, i32 %y)`` 18158then the resulting function pointer has signature ``i32 (i32, i32)``. 18159It can be created as follows: 18160 18161.. code-block:: llvm 18162 18163 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86 18164 call ptr @llvm.init.trampoline(ptr %tramp, ptr @f, ptr %nval) 18165 %fp = call ptr @llvm.adjust.trampoline(ptr %tramp) 18166 18167The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to 18168``%val = call i32 %f(ptr %nval, i32 %x, i32 %y)``. 18169 18170.. _int_it: 18171 18172'``llvm.init.trampoline``' Intrinsic 18173^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18174 18175Syntax: 18176""""""" 18177 18178:: 18179 18180 declare void @llvm.init.trampoline(ptr <tramp>, ptr <func>, ptr <nval>) 18181 18182Overview: 18183""""""""" 18184 18185This fills the memory pointed to by ``tramp`` with executable code, 18186turning it into a trampoline. 18187 18188Arguments: 18189"""""""""" 18190 18191The ``llvm.init.trampoline`` intrinsic takes three arguments, all 18192pointers. The ``tramp`` argument must point to a sufficiently large and 18193sufficiently aligned block of memory; this memory is written to by the 18194intrinsic. Note that the size and the alignment are target-specific - 18195LLVM currently provides no portable way of determining them, so a 18196front-end that generates this intrinsic needs to have some 18197target-specific knowledge. The ``func`` argument must hold a function. 18198 18199Semantics: 18200"""""""""" 18201 18202The block of memory pointed to by ``tramp`` is filled with target 18203dependent code, turning it into a function. Then ``tramp`` needs to be 18204passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can 18205be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new 18206function's signature is the same as that of ``func`` with any arguments 18207marked with the ``nest`` attribute removed. At most one such ``nest`` 18208argument is allowed, and it must be of pointer type. Calling the new 18209function is equivalent to calling ``func`` with the same argument list, 18210but with ``nval`` used for the missing ``nest`` argument. If, after 18211calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is 18212modified, then the effect of any later call to the returned function 18213pointer is undefined. 18214 18215.. _int_at: 18216 18217'``llvm.adjust.trampoline``' Intrinsic 18218^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18219 18220Syntax: 18221""""""" 18222 18223:: 18224 18225 declare ptr @llvm.adjust.trampoline(ptr <tramp>) 18226 18227Overview: 18228""""""""" 18229 18230This performs any required machine-specific adjustment to the address of 18231a trampoline (passed as ``tramp``). 18232 18233Arguments: 18234"""""""""" 18235 18236``tramp`` must point to a block of memory which already has trampoline 18237code filled in by a previous call to 18238:ref:`llvm.init.trampoline <int_it>`. 18239 18240Semantics: 18241"""""""""" 18242 18243On some architectures the address of the code to be executed needs to be 18244different than the address where the trampoline is actually stored. This 18245intrinsic returns the executable address corresponding to ``tramp`` 18246after performing the required machine specific adjustments. The pointer 18247returned can then be :ref:`bitcast and executed <int_trampoline>`. 18248 18249 18250.. _int_vp: 18251 18252Vector Predication Intrinsics 18253----------------------------- 18254VP intrinsics are intended for predicated SIMD/vector code. A typical VP 18255operation takes a vector mask and an explicit vector length parameter as in: 18256 18257:: 18258 18259 <W x T> llvm.vp.<opcode>.*(<W x T> %x, <W x T> %y, <W x i1> %mask, i32 %evl) 18260 18261The vector mask parameter (%mask) always has a vector of `i1` type, for example 18262`<32 x i1>`. The explicit vector length parameter always has the type `i32` and 18263is an unsigned integer value. The explicit vector length parameter (%evl) is in 18264the range: 18265 18266:: 18267 18268 0 <= %evl <= W, where W is the number of vector elements 18269 18270Note that for :ref:`scalable vector types <t_vector>` ``W`` is the runtime 18271length of the vector. 18272 18273The VP intrinsic has undefined behavior if ``%evl > W``. The explicit vector 18274length (%evl) creates a mask, %EVLmask, with all elements ``0 <= i < %evl`` set 18275to True, and all other lanes ``%evl <= i < W`` to False. A new mask %M is 18276calculated with an element-wise AND from %mask and %EVLmask: 18277 18278:: 18279 18280 M = %mask AND %EVLmask 18281 18282A vector operation ``<opcode>`` on vectors ``A`` and ``B`` calculates: 18283 18284:: 18285 18286 A <opcode> B = { A[i] <opcode> B[i] M[i] = True, and 18287 { undef otherwise 18288 18289Optimization Hint 18290^^^^^^^^^^^^^^^^^ 18291 18292Some targets, such as AVX512, do not support the %evl parameter in hardware. 18293The use of an effective %evl is discouraged for those targets. The function 18294``TargetTransformInfo::hasActiveVectorLength()`` returns true when the target 18295has native support for %evl. 18296 18297.. _int_vp_select: 18298 18299'``llvm.vp.select.*``' Intrinsics 18300^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18301 18302Syntax: 18303""""""" 18304This is an overloaded intrinsic. 18305 18306:: 18307 18308 declare <16 x i32> @llvm.vp.select.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <evl>) 18309 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>) 18310 18311Overview: 18312""""""""" 18313 18314The '``llvm.vp.select``' intrinsic is used to choose one value based on a 18315condition vector, without IR-level branching. 18316 18317Arguments: 18318"""""""""" 18319 18320The first operand is a vector of ``i1`` and indicates the condition. The 18321second operand is the value that is selected where the condition vector is 18322true. The third operand is the value that is selected where the condition 18323vector is false. The vectors must be of the same size. The fourth operand is 18324the explicit vector length. 18325 18326#. The optional ``fast-math flags`` marker indicates that the select has one or 18327 more :ref:`fast-math flags <fastmath>`. These are optimization hints to 18328 enable otherwise unsafe floating-point optimizations. Fast-math flags are 18329 only valid for selects that return a floating-point scalar or vector type, 18330 or an array (nested to any depth) of floating-point scalar or vector types. 18331 18332Semantics: 18333"""""""""" 18334 18335The intrinsic selects lanes from the second and third operand depending on a 18336condition vector. 18337 18338All result lanes at positions greater or equal than ``%evl`` are undefined. 18339For all lanes below ``%evl`` where the condition vector is true the lane is 18340taken from the second operand. Otherwise, the lane is taken from the third 18341operand. 18342 18343Example: 18344"""""""" 18345 18346.. code-block:: llvm 18347 18348 %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) 18349 18350 ;;; Expansion. 18351 ;; Any result is legal on lanes at and above %evl. 18352 %also.r = select <4 x i1> %cond, <4 x i32> %on_true, <4 x i32> %on_false 18353 18354 18355.. _int_vp_merge: 18356 18357'``llvm.vp.merge.*``' Intrinsics 18358^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18359 18360Syntax: 18361""""""" 18362This is an overloaded intrinsic. 18363 18364:: 18365 18366 declare <16 x i32> @llvm.vp.merge.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <pivot>) 18367 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>) 18368 18369Overview: 18370""""""""" 18371 18372The '``llvm.vp.merge``' intrinsic is used to choose one value based on a 18373condition vector and an index operand, without IR-level branching. 18374 18375Arguments: 18376"""""""""" 18377 18378The first operand is a vector of ``i1`` and indicates the condition. The 18379second operand is the value that is merged where the condition vector is true. 18380The third operand is the value that is selected where the condition vector is 18381false or the lane position is greater equal than the pivot. The fourth operand 18382is the pivot. 18383 18384#. The optional ``fast-math flags`` marker indicates that the merge has one or 18385 more :ref:`fast-math flags <fastmath>`. These are optimization hints to 18386 enable otherwise unsafe floating-point optimizations. Fast-math flags are 18387 only valid for merges that return a floating-point scalar or vector type, 18388 or an array (nested to any depth) of floating-point scalar or vector types. 18389 18390Semantics: 18391"""""""""" 18392 18393The intrinsic selects lanes from the second and third operand depending on a 18394condition vector and pivot value. 18395 18396For all lanes where the condition vector is true and the lane position is less 18397than ``%pivot`` the lane is taken from the second operand. Otherwise, the lane 18398is taken from the third operand. 18399 18400Example: 18401"""""""" 18402 18403.. code-block:: llvm 18404 18405 %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) 18406 18407 ;;; Expansion. 18408 ;; Lanes at and above %pivot are taken from %on_false 18409 %atfirst = insertelement <4 x i32> undef, i32 %pivot, i32 0 18410 %splat = shufflevector <4 x i32> %atfirst, <4 x i32> poison, <4 x i32> zeroinitializer 18411 %pivotmask = icmp ult <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32> %splat 18412 %mergemask = and <4 x i1> %cond, <4 x i1> %pivotmask 18413 %also.r = select <4 x i1> %mergemask, <4 x i32> %on_true, <4 x i32> %on_false 18414 18415 18416 18417.. _int_vp_add: 18418 18419'``llvm.vp.add.*``' Intrinsics 18420^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18421 18422Syntax: 18423""""""" 18424This is an overloaded intrinsic. 18425 18426:: 18427 18428 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>) 18429 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>) 18430 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>) 18431 18432Overview: 18433""""""""" 18434 18435Predicated integer addition of two vectors of integers. 18436 18437 18438Arguments: 18439"""""""""" 18440 18441The first two operands and the result have the same vector of integer type. The 18442third operand is the vector mask and has the same number of elements as the 18443result vector type. The fourth operand is the explicit vector length of the 18444operation. 18445 18446Semantics: 18447"""""""""" 18448 18449The '``llvm.vp.add``' intrinsic performs integer addition (:ref:`add <i_add>`) 18450of the first and second vector operand on each enabled lane. The result on 18451disabled lanes is a :ref:`poison value <poisonvalues>`. 18452 18453Examples: 18454""""""""" 18455 18456.. code-block:: llvm 18457 18458 %r = call <4 x i32> @llvm.vp.add.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18459 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18460 18461 %t = add <4 x i32> %a, %b 18462 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 18463 18464.. _int_vp_sub: 18465 18466'``llvm.vp.sub.*``' Intrinsics 18467^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18468 18469Syntax: 18470""""""" 18471This is an overloaded intrinsic. 18472 18473:: 18474 18475 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>) 18476 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>) 18477 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>) 18478 18479Overview: 18480""""""""" 18481 18482Predicated integer subtraction of two vectors of integers. 18483 18484 18485Arguments: 18486"""""""""" 18487 18488The first two operands and the result have the same vector of integer type. The 18489third operand is the vector mask and has the same number of elements as the 18490result vector type. The fourth operand is the explicit vector length of the 18491operation. 18492 18493Semantics: 18494"""""""""" 18495 18496The '``llvm.vp.sub``' intrinsic performs integer subtraction 18497(:ref:`sub <i_sub>`) of the first and second vector operand on each enabled 18498lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 18499 18500Examples: 18501""""""""" 18502 18503.. code-block:: llvm 18504 18505 %r = call <4 x i32> @llvm.vp.sub.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18506 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18507 18508 %t = sub <4 x i32> %a, %b 18509 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 18510 18511 18512 18513.. _int_vp_mul: 18514 18515'``llvm.vp.mul.*``' Intrinsics 18516^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18517 18518Syntax: 18519""""""" 18520This is an overloaded intrinsic. 18521 18522:: 18523 18524 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>) 18525 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>) 18526 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>) 18527 18528Overview: 18529""""""""" 18530 18531Predicated integer multiplication of two vectors of integers. 18532 18533 18534Arguments: 18535"""""""""" 18536 18537The first two operands and the result have the same vector of integer type. The 18538third operand is the vector mask and has the same number of elements as the 18539result vector type. The fourth operand is the explicit vector length of the 18540operation. 18541 18542Semantics: 18543"""""""""" 18544The '``llvm.vp.mul``' intrinsic performs integer multiplication 18545(:ref:`mul <i_mul>`) of the first and second vector operand on each enabled 18546lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 18547 18548Examples: 18549""""""""" 18550 18551.. code-block:: llvm 18552 18553 %r = call <4 x i32> @llvm.vp.mul.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18554 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18555 18556 %t = mul <4 x i32> %a, %b 18557 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 18558 18559 18560.. _int_vp_sdiv: 18561 18562'``llvm.vp.sdiv.*``' Intrinsics 18563^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18564 18565Syntax: 18566""""""" 18567This is an overloaded intrinsic. 18568 18569:: 18570 18571 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>) 18572 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>) 18573 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>) 18574 18575Overview: 18576""""""""" 18577 18578Predicated, signed division of two vectors of integers. 18579 18580 18581Arguments: 18582"""""""""" 18583 18584The first two operands and the result have the same vector of integer type. The 18585third operand is the vector mask and has the same number of elements as the 18586result vector type. The fourth operand is the explicit vector length of the 18587operation. 18588 18589Semantics: 18590"""""""""" 18591 18592The '``llvm.vp.sdiv``' intrinsic performs signed division (:ref:`sdiv <i_sdiv>`) 18593of the first and second vector operand on each enabled lane. The result on 18594disabled lanes is a :ref:`poison value <poisonvalues>`. 18595 18596Examples: 18597""""""""" 18598 18599.. code-block:: llvm 18600 18601 %r = call <4 x i32> @llvm.vp.sdiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18602 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18603 18604 %t = sdiv <4 x i32> %a, %b 18605 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 18606 18607 18608.. _int_vp_udiv: 18609 18610'``llvm.vp.udiv.*``' Intrinsics 18611^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18612 18613Syntax: 18614""""""" 18615This is an overloaded intrinsic. 18616 18617:: 18618 18619 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>) 18620 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>) 18621 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>) 18622 18623Overview: 18624""""""""" 18625 18626Predicated, unsigned division of two vectors of integers. 18627 18628 18629Arguments: 18630"""""""""" 18631 18632The 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. 18633 18634Semantics: 18635"""""""""" 18636 18637The '``llvm.vp.udiv``' intrinsic performs unsigned division 18638(:ref:`udiv <i_udiv>`) of the first and second vector operand on each enabled 18639lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 18640 18641Examples: 18642""""""""" 18643 18644.. code-block:: llvm 18645 18646 %r = call <4 x i32> @llvm.vp.udiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18647 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18648 18649 %t = udiv <4 x i32> %a, %b 18650 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 18651 18652 18653 18654.. _int_vp_srem: 18655 18656'``llvm.vp.srem.*``' Intrinsics 18657^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18658 18659Syntax: 18660""""""" 18661This is an overloaded intrinsic. 18662 18663:: 18664 18665 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>) 18666 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>) 18667 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>) 18668 18669Overview: 18670""""""""" 18671 18672Predicated computations of the signed remainder of two integer vectors. 18673 18674 18675Arguments: 18676"""""""""" 18677 18678The first two operands and the result have the same vector of integer type. The 18679third operand is the vector mask and has the same number of elements as the 18680result vector type. The fourth operand is the explicit vector length of the 18681operation. 18682 18683Semantics: 18684"""""""""" 18685 18686The '``llvm.vp.srem``' intrinsic computes the remainder of the signed division 18687(:ref:`srem <i_srem>`) of the first and second vector operand on each enabled 18688lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 18689 18690Examples: 18691""""""""" 18692 18693.. code-block:: llvm 18694 18695 %r = call <4 x i32> @llvm.vp.srem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18696 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18697 18698 %t = srem <4 x i32> %a, %b 18699 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 18700 18701 18702 18703.. _int_vp_urem: 18704 18705'``llvm.vp.urem.*``' Intrinsics 18706^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18707 18708Syntax: 18709""""""" 18710This is an overloaded intrinsic. 18711 18712:: 18713 18714 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>) 18715 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>) 18716 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>) 18717 18718Overview: 18719""""""""" 18720 18721Predicated computation of the unsigned remainder of two integer vectors. 18722 18723 18724Arguments: 18725"""""""""" 18726 18727The first two operands and the result have the same vector of integer type. The 18728third operand is the vector mask and has the same number of elements as the 18729result vector type. The fourth operand is the explicit vector length of the 18730operation. 18731 18732Semantics: 18733"""""""""" 18734 18735The '``llvm.vp.urem``' intrinsic computes the remainder of the unsigned division 18736(:ref:`urem <i_urem>`) of the first and second vector operand on each enabled 18737lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 18738 18739Examples: 18740""""""""" 18741 18742.. code-block:: llvm 18743 18744 %r = call <4 x i32> @llvm.vp.urem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18745 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18746 18747 %t = urem <4 x i32> %a, %b 18748 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 18749 18750 18751.. _int_vp_ashr: 18752 18753'``llvm.vp.ashr.*``' Intrinsics 18754^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18755 18756Syntax: 18757""""""" 18758This is an overloaded intrinsic. 18759 18760:: 18761 18762 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>) 18763 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>) 18764 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>) 18765 18766Overview: 18767""""""""" 18768 18769Vector-predicated arithmetic right-shift. 18770 18771 18772Arguments: 18773"""""""""" 18774 18775The first two operands and the result have the same vector of integer type. The 18776third operand is the vector mask and has the same number of elements as the 18777result vector type. The fourth operand is the explicit vector length of the 18778operation. 18779 18780Semantics: 18781"""""""""" 18782 18783The '``llvm.vp.ashr``' intrinsic computes the arithmetic right shift 18784(:ref:`ashr <i_ashr>`) of the first operand by the second operand on each 18785enabled lane. The result on disabled lanes is a 18786:ref:`poison value <poisonvalues>`. 18787 18788Examples: 18789""""""""" 18790 18791.. code-block:: llvm 18792 18793 %r = call <4 x i32> @llvm.vp.ashr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18794 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18795 18796 %t = ashr <4 x i32> %a, %b 18797 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 18798 18799 18800.. _int_vp_lshr: 18801 18802 18803'``llvm.vp.lshr.*``' Intrinsics 18804^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18805 18806Syntax: 18807""""""" 18808This is an overloaded intrinsic. 18809 18810:: 18811 18812 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>) 18813 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>) 18814 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>) 18815 18816Overview: 18817""""""""" 18818 18819Vector-predicated logical right-shift. 18820 18821 18822Arguments: 18823"""""""""" 18824 18825The first two operands and the result have the same vector of integer type. The 18826third operand is the vector mask and has the same number of elements as the 18827result vector type. The fourth operand is the explicit vector length of the 18828operation. 18829 18830Semantics: 18831"""""""""" 18832 18833The '``llvm.vp.lshr``' intrinsic computes the logical right shift 18834(:ref:`lshr <i_lshr>`) of the first operand by the second operand on each 18835enabled lane. The result on disabled lanes is a 18836:ref:`poison value <poisonvalues>`. 18837 18838Examples: 18839""""""""" 18840 18841.. code-block:: llvm 18842 18843 %r = call <4 x i32> @llvm.vp.lshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18844 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18845 18846 %t = lshr <4 x i32> %a, %b 18847 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 18848 18849 18850.. _int_vp_shl: 18851 18852'``llvm.vp.shl.*``' Intrinsics 18853^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18854 18855Syntax: 18856""""""" 18857This is an overloaded intrinsic. 18858 18859:: 18860 18861 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>) 18862 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>) 18863 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>) 18864 18865Overview: 18866""""""""" 18867 18868Vector-predicated left shift. 18869 18870 18871Arguments: 18872"""""""""" 18873 18874The first two operands and the result have the same vector of integer type. The 18875third operand is the vector mask and has the same number of elements as the 18876result vector type. The fourth operand is the explicit vector length of the 18877operation. 18878 18879Semantics: 18880"""""""""" 18881 18882The '``llvm.vp.shl``' intrinsic computes the left shift (:ref:`shl <i_shl>`) of 18883the first operand by the second operand on each enabled lane. The result on 18884disabled lanes is a :ref:`poison value <poisonvalues>`. 18885 18886Examples: 18887""""""""" 18888 18889.. code-block:: llvm 18890 18891 %r = call <4 x i32> @llvm.vp.shl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18892 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18893 18894 %t = shl <4 x i32> %a, %b 18895 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 18896 18897 18898.. _int_vp_or: 18899 18900'``llvm.vp.or.*``' Intrinsics 18901^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18902 18903Syntax: 18904""""""" 18905This is an overloaded intrinsic. 18906 18907:: 18908 18909 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>) 18910 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>) 18911 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>) 18912 18913Overview: 18914""""""""" 18915 18916Vector-predicated or. 18917 18918 18919Arguments: 18920"""""""""" 18921 18922The first two operands and the result have the same vector of integer type. The 18923third operand is the vector mask and has the same number of elements as the 18924result vector type. The fourth operand is the explicit vector length of the 18925operation. 18926 18927Semantics: 18928"""""""""" 18929 18930The '``llvm.vp.or``' intrinsic performs a bitwise or (:ref:`or <i_or>`) of the 18931first two operands on each enabled lane. The result on disabled lanes is 18932a :ref:`poison value <poisonvalues>`. 18933 18934Examples: 18935""""""""" 18936 18937.. code-block:: llvm 18938 18939 %r = call <4 x i32> @llvm.vp.or.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18940 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18941 18942 %t = or <4 x i32> %a, %b 18943 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 18944 18945 18946.. _int_vp_and: 18947 18948'``llvm.vp.and.*``' Intrinsics 18949^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18950 18951Syntax: 18952""""""" 18953This is an overloaded intrinsic. 18954 18955:: 18956 18957 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>) 18958 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>) 18959 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>) 18960 18961Overview: 18962""""""""" 18963 18964Vector-predicated and. 18965 18966 18967Arguments: 18968"""""""""" 18969 18970The first two operands and the result have the same vector of integer type. The 18971third operand is the vector mask and has the same number of elements as the 18972result vector type. The fourth operand is the explicit vector length of the 18973operation. 18974 18975Semantics: 18976"""""""""" 18977 18978The '``llvm.vp.and``' intrinsic performs a bitwise and (:ref:`and <i_or>`) of 18979the first two operands on each enabled lane. The result on disabled lanes is 18980a :ref:`poison value <poisonvalues>`. 18981 18982Examples: 18983""""""""" 18984 18985.. code-block:: llvm 18986 18987 %r = call <4 x i32> @llvm.vp.and.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18988 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18989 18990 %t = and <4 x i32> %a, %b 18991 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 18992 18993 18994.. _int_vp_xor: 18995 18996'``llvm.vp.xor.*``' Intrinsics 18997^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18998 18999Syntax: 19000""""""" 19001This is an overloaded intrinsic. 19002 19003:: 19004 19005 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>) 19006 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>) 19007 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>) 19008 19009Overview: 19010""""""""" 19011 19012Vector-predicated, bitwise xor. 19013 19014 19015Arguments: 19016"""""""""" 19017 19018The first two operands and the result have the same vector of integer type. The 19019third operand is the vector mask and has the same number of elements as the 19020result vector type. The fourth operand is the explicit vector length of the 19021operation. 19022 19023Semantics: 19024"""""""""" 19025 19026The '``llvm.vp.xor``' intrinsic performs a bitwise xor (:ref:`xor <i_xor>`) of 19027the first two operands on each enabled lane. 19028The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 19029 19030Examples: 19031""""""""" 19032 19033.. code-block:: llvm 19034 19035 %r = call <4 x i32> @llvm.vp.xor.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 19036 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19037 19038 %t = xor <4 x i32> %a, %b 19039 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 19040 19041.. _int_vp_abs: 19042 19043'``llvm.vp.abs.*``' Intrinsics 19044^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19045 19046Syntax: 19047""""""" 19048This is an overloaded intrinsic. 19049 19050:: 19051 19052 declare <16 x i32> @llvm.vp.abs.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>, i1 <is_int_min_poison>) 19053 declare <vscale x 4 x i32> @llvm.vp.abs.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>, i1 <is_int_min_poison>) 19054 declare <256 x i64> @llvm.vp.abs.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>, i1 <is_int_min_poison>) 19055 19056Overview: 19057""""""""" 19058 19059Predicated abs of a vector of integers. 19060 19061 19062Arguments: 19063"""""""""" 19064 19065The first operand and the result have the same vector of integer type. The 19066second operand is the vector mask and has the same number of elements as the 19067result vector type. The third operand is the explicit vector length of the 19068operation. The fourth argument must be a constant and is a flag to indicate 19069whether the result value of the '``llvm.vp.abs``' intrinsic is a 19070:ref:`poison value <poisonvalues>` if the argument is statically or dynamically 19071an ``INT_MIN`` value. 19072 19073Semantics: 19074"""""""""" 19075 19076The '``llvm.vp.abs``' intrinsic performs abs (:ref:`abs <int_abs>`) of the first operand on each 19077enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 19078 19079Examples: 19080""""""""" 19081 19082.. code-block:: llvm 19083 19084 %r = call <4 x i32> @llvm.vp.abs.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl, i1 false) 19085 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19086 19087 %t = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %a, i1 false) 19088 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 19089 19090 19091 19092.. _int_vp_smax: 19093 19094'``llvm.vp.smax.*``' Intrinsics 19095^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19096 19097Syntax: 19098""""""" 19099This is an overloaded intrinsic. 19100 19101:: 19102 19103 declare <16 x i32> @llvm.vp.smax.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 19104 declare <vscale x 4 x i32> @llvm.vp.smax.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 19105 declare <256 x i64> @llvm.vp.smax.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 19106 19107Overview: 19108""""""""" 19109 19110Predicated integer signed maximum of two vectors of integers. 19111 19112 19113Arguments: 19114"""""""""" 19115 19116The first two operands and the result have the same vector of integer type. The 19117third operand is the vector mask and has the same number of elements as the 19118result vector type. The fourth operand is the explicit vector length of the 19119operation. 19120 19121Semantics: 19122"""""""""" 19123 19124The '``llvm.vp.smax``' intrinsic performs integer signed maximum (:ref:`smax <int_smax>`) 19125of the first and second vector operand on each enabled lane. The result on 19126disabled lanes is a :ref:`poison value <poisonvalues>`. 19127 19128Examples: 19129""""""""" 19130 19131.. code-block:: llvm 19132 19133 %r = call <4 x i32> @llvm.vp.smax.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 19134 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19135 19136 %t = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> %b) 19137 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 19138 19139 19140.. _int_vp_smin: 19141 19142'``llvm.vp.smin.*``' Intrinsics 19143^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19144 19145Syntax: 19146""""""" 19147This is an overloaded intrinsic. 19148 19149:: 19150 19151 declare <16 x i32> @llvm.vp.smin.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 19152 declare <vscale x 4 x i32> @llvm.vp.smin.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 19153 declare <256 x i64> @llvm.vp.smin.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 19154 19155Overview: 19156""""""""" 19157 19158Predicated integer signed minimum of two vectors of integers. 19159 19160 19161Arguments: 19162"""""""""" 19163 19164The first two operands and the result have the same vector of integer type. The 19165third operand is the vector mask and has the same number of elements as the 19166result vector type. The fourth operand is the explicit vector length of the 19167operation. 19168 19169Semantics: 19170"""""""""" 19171 19172The '``llvm.vp.smin``' intrinsic performs integer signed minimum (:ref:`smin <int_smin>`) 19173of the first and second vector operand on each enabled lane. The result on 19174disabled lanes is a :ref:`poison value <poisonvalues>`. 19175 19176Examples: 19177""""""""" 19178 19179.. code-block:: llvm 19180 19181 %r = call <4 x i32> @llvm.vp.smin.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 19182 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19183 19184 %t = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> %b) 19185 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 19186 19187 19188.. _int_vp_umax: 19189 19190'``llvm.vp.umax.*``' Intrinsics 19191^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19192 19193Syntax: 19194""""""" 19195This is an overloaded intrinsic. 19196 19197:: 19198 19199 declare <16 x i32> @llvm.vp.umax.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 19200 declare <vscale x 4 x i32> @llvm.vp.umax.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 19201 declare <256 x i64> @llvm.vp.umax.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 19202 19203Overview: 19204""""""""" 19205 19206Predicated integer unsigned maximum of two vectors of integers. 19207 19208 19209Arguments: 19210"""""""""" 19211 19212The first two operands and the result have the same vector of integer type. The 19213third operand is the vector mask and has the same number of elements as the 19214result vector type. The fourth operand is the explicit vector length of the 19215operation. 19216 19217Semantics: 19218"""""""""" 19219 19220The '``llvm.vp.umax``' intrinsic performs integer unsigned maximum (:ref:`umax <int_umax>`) 19221of the first and second vector operand on each enabled lane. The result on 19222disabled lanes is a :ref:`poison value <poisonvalues>`. 19223 19224Examples: 19225""""""""" 19226 19227.. code-block:: llvm 19228 19229 %r = call <4 x i32> @llvm.vp.umax.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 19230 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19231 19232 %t = call <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> %b) 19233 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 19234 19235 19236.. _int_vp_umin: 19237 19238'``llvm.vp.umin.*``' Intrinsics 19239^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19240 19241Syntax: 19242""""""" 19243This is an overloaded intrinsic. 19244 19245:: 19246 19247 declare <16 x i32> @llvm.vp.umin.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 19248 declare <vscale x 4 x i32> @llvm.vp.umin.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 19249 declare <256 x i64> @llvm.vp.umin.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 19250 19251Overview: 19252""""""""" 19253 19254Predicated integer unsigned minimum of two vectors of integers. 19255 19256 19257Arguments: 19258"""""""""" 19259 19260The first two operands and the result have the same vector of integer type. The 19261third operand is the vector mask and has the same number of elements as the 19262result vector type. The fourth operand is the explicit vector length of the 19263operation. 19264 19265Semantics: 19266"""""""""" 19267 19268The '``llvm.vp.umin``' intrinsic performs integer unsigned minimum (:ref:`umin <int_umin>`) 19269of the first and second vector operand on each enabled lane. The result on 19270disabled lanes is a :ref:`poison value <poisonvalues>`. 19271 19272Examples: 19273""""""""" 19274 19275.. code-block:: llvm 19276 19277 %r = call <4 x i32> @llvm.vp.umin.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 19278 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19279 19280 %t = call <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> %b) 19281 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 19282 19283 19284.. _int_vp_copysign: 19285 19286'``llvm.vp.copysign.*``' Intrinsics 19287^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19288 19289Syntax: 19290""""""" 19291This is an overloaded intrinsic. 19292 19293:: 19294 19295 declare <16 x float> @llvm.vp.copysign.v16f32 (<16 x float> <mag_op>, <16 x float> <sign_op>, <16 x i1> <mask>, i32 <vector_length>) 19296 declare <vscale x 4 x float> @llvm.vp.copysign.nxv4f32 (<vscale x 4 x float> <mag_op>, <vscale x 4 x float> <sign_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 19297 declare <256 x double> @llvm.vp.copysign.v256f64 (<256 x double> <mag_op>, <256 x double> <sign_op>, <256 x i1> <mask>, i32 <vector_length>) 19298 19299Overview: 19300""""""""" 19301 19302Predicated floating-point copysign of two vectors of floating-point values. 19303 19304 19305Arguments: 19306"""""""""" 19307 19308The first two operands and the result have the same vector of floating-point type. The 19309third operand is the vector mask and has the same number of elements as the 19310result vector type. The fourth operand is the explicit vector length of the 19311operation. 19312 19313Semantics: 19314"""""""""" 19315 19316The '``llvm.vp.copysign``' intrinsic performs floating-point copysign (:ref:`copysign <int_copysign>`) 19317of the first and second vector operand on each enabled lane. The result on 19318disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is 19319performed in the default floating-point environment. 19320 19321Examples: 19322""""""""" 19323 19324.. code-block:: llvm 19325 19326 %r = call <4 x float> @llvm.vp.copysign.v4f32(<4 x float> %mag, <4 x float> %sign, <4 x i1> %mask, i32 %evl) 19327 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19328 19329 %t = call <4 x float> @llvm.copysign.v4f32(<4 x float> %mag, <4 x float> %sign) 19330 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19331 19332 19333.. _int_vp_minnum: 19334 19335'``llvm.vp.minnum.*``' Intrinsics 19336^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19337 19338Syntax: 19339""""""" 19340This is an overloaded intrinsic. 19341 19342:: 19343 19344 declare <16 x float> @llvm.vp.minnum.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 19345 declare <vscale x 4 x float> @llvm.vp.minnum.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 19346 declare <256 x double> @llvm.vp.minnum.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 19347 19348Overview: 19349""""""""" 19350 19351Predicated floating-point IEEE-754 minNum of two vectors of floating-point values. 19352 19353 19354Arguments: 19355"""""""""" 19356 19357The first two operands and the result have the same vector of floating-point type. The 19358third operand is the vector mask and has the same number of elements as the 19359result vector type. The fourth operand is the explicit vector length of the 19360operation. 19361 19362Semantics: 19363"""""""""" 19364 19365The '``llvm.vp.minnum``' intrinsic performs floating-point minimum (:ref:`minnum <i_minnum>`) 19366of the first and second vector operand on each enabled lane. The result on 19367disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is 19368performed in the default floating-point environment. 19369 19370Examples: 19371""""""""" 19372 19373.. code-block:: llvm 19374 19375 %r = call <4 x float> @llvm.vp.minnum.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 19376 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19377 19378 %t = call <4 x float> @llvm.minnum.v4f32(<4 x float> %a, <4 x float> %b) 19379 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19380 19381 19382.. _int_vp_maxnum: 19383 19384'``llvm.vp.maxnum.*``' Intrinsics 19385^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19386 19387Syntax: 19388""""""" 19389This is an overloaded intrinsic. 19390 19391:: 19392 19393 declare <16 x float> @llvm.vp.maxnum.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 19394 declare <vscale x 4 x float> @llvm.vp.maxnum.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 19395 declare <256 x double> @llvm.vp.maxnum.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 19396 19397Overview: 19398""""""""" 19399 19400Predicated floating-point IEEE-754 maxNum of two vectors of floating-point values. 19401 19402 19403Arguments: 19404"""""""""" 19405 19406The first two operands and the result have the same vector of floating-point type. The 19407third operand is the vector mask and has the same number of elements as the 19408result vector type. The fourth operand is the explicit vector length of the 19409operation. 19410 19411Semantics: 19412"""""""""" 19413 19414The '``llvm.vp.maxnum``' intrinsic performs floating-point maximum (:ref:`maxnum <i_maxnum>`) 19415of the first and second vector operand on each enabled lane. The result on 19416disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is 19417performed in the default floating-point environment. 19418 19419Examples: 19420""""""""" 19421 19422.. code-block:: llvm 19423 19424 %r = call <4 x float> @llvm.vp.maxnum.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 19425 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19426 19427 %t = call <4 x float> @llvm.maxnum.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 19428 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19429 19430 19431.. _int_vp_fadd: 19432 19433'``llvm.vp.fadd.*``' Intrinsics 19434^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19435 19436Syntax: 19437""""""" 19438This is an overloaded intrinsic. 19439 19440:: 19441 19442 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>) 19443 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>) 19444 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>) 19445 19446Overview: 19447""""""""" 19448 19449Predicated floating-point addition of two vectors of floating-point values. 19450 19451 19452Arguments: 19453"""""""""" 19454 19455The first two operands and the result have the same vector of floating-point type. The 19456third operand is the vector mask and has the same number of elements as the 19457result vector type. The fourth operand is the explicit vector length of the 19458operation. 19459 19460Semantics: 19461"""""""""" 19462 19463The '``llvm.vp.fadd``' intrinsic performs floating-point addition (:ref:`fadd <i_fadd>`) 19464of the first and second vector operand on each enabled lane. The result on 19465disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is 19466performed in the default floating-point environment. 19467 19468Examples: 19469""""""""" 19470 19471.. code-block:: llvm 19472 19473 %r = call <4 x float> @llvm.vp.fadd.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 19474 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19475 19476 %t = fadd <4 x float> %a, %b 19477 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19478 19479 19480.. _int_vp_fsub: 19481 19482'``llvm.vp.fsub.*``' Intrinsics 19483^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19484 19485Syntax: 19486""""""" 19487This is an overloaded intrinsic. 19488 19489:: 19490 19491 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>) 19492 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>) 19493 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>) 19494 19495Overview: 19496""""""""" 19497 19498Predicated floating-point subtraction of two vectors of floating-point values. 19499 19500 19501Arguments: 19502"""""""""" 19503 19504The first two operands and the result have the same vector of floating-point type. The 19505third operand is the vector mask and has the same number of elements as the 19506result vector type. The fourth operand is the explicit vector length of the 19507operation. 19508 19509Semantics: 19510"""""""""" 19511 19512The '``llvm.vp.fsub``' intrinsic performs floating-point subtraction (:ref:`fsub <i_fsub>`) 19513of the first and second vector operand on each enabled lane. The result on 19514disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is 19515performed in the default floating-point environment. 19516 19517Examples: 19518""""""""" 19519 19520.. code-block:: llvm 19521 19522 %r = call <4 x float> @llvm.vp.fsub.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 19523 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19524 19525 %t = fsub <4 x float> %a, %b 19526 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19527 19528 19529.. _int_vp_fmul: 19530 19531'``llvm.vp.fmul.*``' Intrinsics 19532^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19533 19534Syntax: 19535""""""" 19536This is an overloaded intrinsic. 19537 19538:: 19539 19540 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>) 19541 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>) 19542 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>) 19543 19544Overview: 19545""""""""" 19546 19547Predicated floating-point multiplication of two vectors of floating-point values. 19548 19549 19550Arguments: 19551"""""""""" 19552 19553The first two operands and the result have the same vector of floating-point type. The 19554third operand is the vector mask and has the same number of elements as the 19555result vector type. The fourth operand is the explicit vector length of the 19556operation. 19557 19558Semantics: 19559"""""""""" 19560 19561The '``llvm.vp.fmul``' intrinsic performs floating-point multiplication (:ref:`fmul <i_fmul>`) 19562of the first and second vector operand on each enabled lane. The result on 19563disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is 19564performed in the default floating-point environment. 19565 19566Examples: 19567""""""""" 19568 19569.. code-block:: llvm 19570 19571 %r = call <4 x float> @llvm.vp.fmul.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 19572 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19573 19574 %t = fmul <4 x float> %a, %b 19575 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19576 19577 19578.. _int_vp_fdiv: 19579 19580'``llvm.vp.fdiv.*``' Intrinsics 19581^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19582 19583Syntax: 19584""""""" 19585This is an overloaded intrinsic. 19586 19587:: 19588 19589 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>) 19590 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>) 19591 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>) 19592 19593Overview: 19594""""""""" 19595 19596Predicated floating-point division of two vectors of floating-point values. 19597 19598 19599Arguments: 19600"""""""""" 19601 19602The first two operands and the result have the same vector of floating-point type. The 19603third operand is the vector mask and has the same number of elements as the 19604result vector type. The fourth operand is the explicit vector length of the 19605operation. 19606 19607Semantics: 19608"""""""""" 19609 19610The '``llvm.vp.fdiv``' intrinsic performs floating-point division (:ref:`fdiv <i_fdiv>`) 19611of the first and second vector operand on each enabled lane. The result on 19612disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is 19613performed in the default floating-point environment. 19614 19615Examples: 19616""""""""" 19617 19618.. code-block:: llvm 19619 19620 %r = call <4 x float> @llvm.vp.fdiv.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 19621 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19622 19623 %t = fdiv <4 x float> %a, %b 19624 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19625 19626 19627.. _int_vp_frem: 19628 19629'``llvm.vp.frem.*``' Intrinsics 19630^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19631 19632Syntax: 19633""""""" 19634This is an overloaded intrinsic. 19635 19636:: 19637 19638 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>) 19639 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>) 19640 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>) 19641 19642Overview: 19643""""""""" 19644 19645Predicated floating-point remainder of two vectors of floating-point values. 19646 19647 19648Arguments: 19649"""""""""" 19650 19651The first two operands and the result have the same vector of floating-point type. The 19652third operand is the vector mask and has the same number of elements as the 19653result vector type. The fourth operand is the explicit vector length of the 19654operation. 19655 19656Semantics: 19657"""""""""" 19658 19659The '``llvm.vp.frem``' intrinsic performs floating-point remainder (:ref:`frem <i_frem>`) 19660of the first and second vector operand on each enabled lane. The result on 19661disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is 19662performed in the default floating-point environment. 19663 19664Examples: 19665""""""""" 19666 19667.. code-block:: llvm 19668 19669 %r = call <4 x float> @llvm.vp.frem.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 19670 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19671 19672 %t = frem <4 x float> %a, %b 19673 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19674 19675 19676.. _int_vp_fneg: 19677 19678'``llvm.vp.fneg.*``' Intrinsics 19679^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19680 19681Syntax: 19682""""""" 19683This is an overloaded intrinsic. 19684 19685:: 19686 19687 declare <16 x float> @llvm.vp.fneg.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 19688 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>) 19689 declare <256 x double> @llvm.vp.fneg.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 19690 19691Overview: 19692""""""""" 19693 19694Predicated floating-point negation of a vector of floating-point values. 19695 19696 19697Arguments: 19698"""""""""" 19699 19700The first operand and the result have the same vector of floating-point type. 19701The second operand is the vector mask and has the same number of elements as the 19702result vector type. The third operand is the explicit vector length of the 19703operation. 19704 19705Semantics: 19706"""""""""" 19707 19708The '``llvm.vp.fneg``' intrinsic performs floating-point negation (:ref:`fneg <i_fneg>`) 19709of the first vector operand on each enabled lane. The result on disabled lanes 19710is a :ref:`poison value <poisonvalues>`. 19711 19712Examples: 19713""""""""" 19714 19715.. code-block:: llvm 19716 19717 %r = call <4 x float> @llvm.vp.fneg.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 19718 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19719 19720 %t = fneg <4 x float> %a 19721 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19722 19723 19724.. _int_vp_fabs: 19725 19726'``llvm.vp.fabs.*``' Intrinsics 19727^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19728 19729Syntax: 19730""""""" 19731This is an overloaded intrinsic. 19732 19733:: 19734 19735 declare <16 x float> @llvm.vp.fabs.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 19736 declare <vscale x 4 x float> @llvm.vp.fabs.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 19737 declare <256 x double> @llvm.vp.fabs.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 19738 19739Overview: 19740""""""""" 19741 19742Predicated floating-point absolute value of a vector of floating-point values. 19743 19744 19745Arguments: 19746"""""""""" 19747 19748The first operand and the result have the same vector of floating-point type. 19749The second operand is the vector mask and has the same number of elements as the 19750result vector type. The third operand is the explicit vector length of the 19751operation. 19752 19753Semantics: 19754"""""""""" 19755 19756The '``llvm.vp.fabs``' intrinsic performs floating-point absolute value 19757(:ref:`fabs <int_fabs>`) of the first vector operand on each enabled lane. The 19758result on disabled lanes is a :ref:`poison value <poisonvalues>`. 19759 19760Examples: 19761""""""""" 19762 19763.. code-block:: llvm 19764 19765 %r = call <4 x float> @llvm.vp.fabs.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 19766 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19767 19768 %t = call <4 x float> @llvm.fabs.v4f32(<4 x float> %a) 19769 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19770 19771 19772.. _int_vp_sqrt: 19773 19774'``llvm.vp.sqrt.*``' Intrinsics 19775^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19776 19777Syntax: 19778""""""" 19779This is an overloaded intrinsic. 19780 19781:: 19782 19783 declare <16 x float> @llvm.vp.sqrt.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 19784 declare <vscale x 4 x float> @llvm.vp.sqrt.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 19785 declare <256 x double> @llvm.vp.sqrt.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 19786 19787Overview: 19788""""""""" 19789 19790Predicated floating-point square root of a vector of floating-point values. 19791 19792 19793Arguments: 19794"""""""""" 19795 19796The first operand and the result have the same vector of floating-point type. 19797The second operand is the vector mask and has the same number of elements as the 19798result vector type. The third operand is the explicit vector length of the 19799operation. 19800 19801Semantics: 19802"""""""""" 19803 19804The '``llvm.vp.sqrt``' intrinsic performs floating-point square root (:ref:`sqrt <int_sqrt>`) of 19805the first vector operand on each enabled lane. The result on disabled lanes is 19806a :ref:`poison value <poisonvalues>`. The operation is performed in the default 19807floating-point environment. 19808 19809Examples: 19810""""""""" 19811 19812.. code-block:: llvm 19813 19814 %r = call <4 x float> @llvm.vp.sqrt.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 19815 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19816 19817 %t = call <4 x float> @llvm.sqrt.v4f32(<4 x float> %a) 19818 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19819 19820 19821.. _int_vp_fma: 19822 19823'``llvm.vp.fma.*``' Intrinsics 19824^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19825 19826Syntax: 19827""""""" 19828This is an overloaded intrinsic. 19829 19830:: 19831 19832 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>) 19833 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>) 19834 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>) 19835 19836Overview: 19837""""""""" 19838 19839Predicated floating-point fused multiply-add of two vectors of floating-point values. 19840 19841 19842Arguments: 19843"""""""""" 19844 19845The first three operands and the result have the same vector of floating-point type. The 19846fourth operand is the vector mask and has the same number of elements as the 19847result vector type. The fifth operand is the explicit vector length of the 19848operation. 19849 19850Semantics: 19851"""""""""" 19852 19853The '``llvm.vp.fma``' intrinsic performs floating-point fused multiply-add (:ref:`llvm.fma <int_fma>`) 19854of the first, second, and third vector operand on each enabled lane. The result on 19855disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is 19856performed in the default floating-point environment. 19857 19858Examples: 19859""""""""" 19860 19861.. code-block:: llvm 19862 19863 %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) 19864 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19865 19866 %t = call <4 x float> @llvm.fma(<4 x float> %a, <4 x float> %b, <4 x float> %c) 19867 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19868 19869 19870.. _int_vp_fmuladd: 19871 19872'``llvm.vp.fmuladd.*``' Intrinsics 19873^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19874 19875Syntax: 19876""""""" 19877This is an overloaded intrinsic. 19878 19879:: 19880 19881 declare <16 x float> @llvm.vp.fmuladd.v16f32 (<16 x float> <left_op>, <16 x float> <middle_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 19882 declare <vscale x 4 x float> @llvm.vp.fmuladd.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <middle_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 19883 declare <256 x double> @llvm.vp.fmuladd.v256f64 (<256 x double> <left_op>, <256 x double> <middle_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 19884 19885Overview: 19886""""""""" 19887 19888Predicated floating-point multiply-add of two vectors of floating-point values 19889that can be fused if code generator determines that (a) the target instruction 19890set has support for a fused operation, and (b) that the fused operation is more 19891efficient than the equivalent, separate pair of mul and add instructions. 19892 19893Arguments: 19894"""""""""" 19895 19896The first three operands and the result have the same vector of floating-point 19897type. The fourth operand is the vector mask and has the same number of elements 19898as the result vector type. The fifth operand is the explicit vector length of 19899the operation. 19900 19901Semantics: 19902"""""""""" 19903 19904The '``llvm.vp.fmuladd``' intrinsic performs floating-point multiply-add (:ref:`llvm.fuladd <int_fmuladd>`) 19905of the first, second, and third vector operand on each enabled lane. The result 19906on disabled lanes is a :ref:`poison value <poisonvalues>`. The operation is 19907performed in the default floating-point environment. 19908 19909Examples: 19910""""""""" 19911 19912.. code-block:: llvm 19913 19914 %r = call <4 x float> @llvm.vp.fmuladd.v4f32(<4 x float> %a, <4 x float> %b, <4 x float> %c, <4 x i1> %mask, i32 %evl) 19915 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19916 19917 %t = call <4 x float> @llvm.fmuladd(<4 x float> %a, <4 x float> %b, <4 x float> %c) 19918 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 19919 19920 19921.. _int_vp_reduce_add: 19922 19923'``llvm.vp.reduce.add.*``' Intrinsics 19924^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19925 19926Syntax: 19927""""""" 19928This is an overloaded intrinsic. 19929 19930:: 19931 19932 declare i32 @llvm.vp.reduce.add.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19933 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>) 19934 19935Overview: 19936""""""""" 19937 19938Predicated integer ``ADD`` reduction of a vector and a scalar starting value, 19939returning the result as a scalar. 19940 19941Arguments: 19942"""""""""" 19943 19944The first operand is the start value of the reduction, which must be a scalar 19945integer type equal to the result type. The second operand is the vector on 19946which the reduction is performed and must be a vector of integer values whose 19947element type is the result/start type. The third operand is the vector mask and 19948is a vector of boolean values with the same number of elements as the vector 19949operand. The fourth operand is the explicit vector length of the operation. 19950 19951Semantics: 19952"""""""""" 19953 19954The '``llvm.vp.reduce.add``' intrinsic performs the integer ``ADD`` reduction 19955(:ref:`llvm.vector.reduce.add <int_vector_reduce_add>`) of the vector operand 19956``val`` on each enabled lane, adding it to the scalar ``start_value``. Disabled 19957lanes are treated as containing the neutral value ``0`` (i.e. having no effect 19958on the reduction operation). If the vector length is zero, the result is equal 19959to ``start_value``. 19960 19961To ignore the start value, the neutral value can be used. 19962 19963Examples: 19964""""""""" 19965 19966.. code-block:: llvm 19967 19968 %r = call i32 @llvm.vp.reduce.add.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19969 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19970 ; are treated as though %mask were false for those lanes. 19971 19972 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> zeroinitializer 19973 %reduction = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %masked.a) 19974 %also.r = add i32 %reduction, %start 19975 19976 19977.. _int_vp_reduce_fadd: 19978 19979'``llvm.vp.reduce.fadd.*``' Intrinsics 19980^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19981 19982Syntax: 19983""""""" 19984This is an overloaded intrinsic. 19985 19986:: 19987 19988 declare float @llvm.vp.reduce.fadd.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>) 19989 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>) 19990 19991Overview: 19992""""""""" 19993 19994Predicated floating-point ``ADD`` reduction of a vector and a scalar starting 19995value, returning the result as a scalar. 19996 19997Arguments: 19998"""""""""" 19999 20000The first operand is the start value of the reduction, which must be a scalar 20001floating-point type equal to the result type. The second operand is the vector 20002on which the reduction is performed and must be a vector of floating-point 20003values whose element type is the result/start type. The third operand is the 20004vector mask and is a vector of boolean values with the same number of elements 20005as the vector operand. The fourth operand is the explicit vector length of the 20006operation. 20007 20008Semantics: 20009"""""""""" 20010 20011The '``llvm.vp.reduce.fadd``' intrinsic performs the floating-point ``ADD`` 20012reduction (:ref:`llvm.vector.reduce.fadd <int_vector_reduce_fadd>`) of the 20013vector operand ``val`` on each enabled lane, adding it to the scalar 20014``start_value``. Disabled lanes are treated as containing the neutral value 20015``-0.0`` (i.e. having no effect on the reduction operation). If no lanes are 20016enabled, the resulting value will be equal to ``start_value``. 20017 20018To ignore the start value, the neutral value can be used. 20019 20020See the unpredicated version (:ref:`llvm.vector.reduce.fadd 20021<int_vector_reduce_fadd>`) for more detail on the semantics of the reduction. 20022 20023Examples: 20024""""""""" 20025 20026.. code-block:: llvm 20027 20028 %r = call float @llvm.vp.reduce.fadd.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl) 20029 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 20030 ; are treated as though %mask were false for those lanes. 20031 20032 %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> 20033 %also.r = call float @llvm.vector.reduce.fadd.v4f32(float %start, <4 x float> %masked.a) 20034 20035 20036.. _int_vp_reduce_mul: 20037 20038'``llvm.vp.reduce.mul.*``' Intrinsics 20039^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20040 20041Syntax: 20042""""""" 20043This is an overloaded intrinsic. 20044 20045:: 20046 20047 declare i32 @llvm.vp.reduce.mul.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 20048 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>) 20049 20050Overview: 20051""""""""" 20052 20053Predicated integer ``MUL`` reduction of a vector and a scalar starting value, 20054returning the result as a scalar. 20055 20056 20057Arguments: 20058"""""""""" 20059 20060The first operand is the start value of the reduction, which must be a scalar 20061integer type equal to the result type. The second operand is the vector on 20062which the reduction is performed and must be a vector of integer values whose 20063element type is the result/start type. The third operand is the vector mask and 20064is a vector of boolean values with the same number of elements as the vector 20065operand. The fourth operand is the explicit vector length of the operation. 20066 20067Semantics: 20068"""""""""" 20069 20070The '``llvm.vp.reduce.mul``' intrinsic performs the integer ``MUL`` reduction 20071(:ref:`llvm.vector.reduce.mul <int_vector_reduce_mul>`) of the vector operand ``val`` 20072on each enabled lane, multiplying it by the scalar ``start_value``. Disabled 20073lanes are treated as containing the neutral value ``1`` (i.e. having no effect 20074on the reduction operation). If the vector length is zero, the result is the 20075start value. 20076 20077To ignore the start value, the neutral value can be used. 20078 20079Examples: 20080""""""""" 20081 20082.. code-block:: llvm 20083 20084 %r = call i32 @llvm.vp.reduce.mul.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 20085 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 20086 ; are treated as though %mask were false for those lanes. 20087 20088 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 1, i32 1, i32 1, i32 1> 20089 %reduction = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %masked.a) 20090 %also.r = mul i32 %reduction, %start 20091 20092.. _int_vp_reduce_fmul: 20093 20094'``llvm.vp.reduce.fmul.*``' Intrinsics 20095^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20096 20097Syntax: 20098""""""" 20099This is an overloaded intrinsic. 20100 20101:: 20102 20103 declare float @llvm.vp.reduce.fmul.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>) 20104 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>) 20105 20106Overview: 20107""""""""" 20108 20109Predicated floating-point ``MUL`` reduction of a vector and a scalar starting 20110value, returning the result as a scalar. 20111 20112 20113Arguments: 20114"""""""""" 20115 20116The first operand is the start value of the reduction, which must be a scalar 20117floating-point type equal to the result type. The second operand is the vector 20118on which the reduction is performed and must be a vector of floating-point 20119values whose element type is the result/start type. The third operand is the 20120vector mask and is a vector of boolean values with the same number of elements 20121as the vector operand. The fourth operand is the explicit vector length of the 20122operation. 20123 20124Semantics: 20125"""""""""" 20126 20127The '``llvm.vp.reduce.fmul``' intrinsic performs the floating-point ``MUL`` 20128reduction (:ref:`llvm.vector.reduce.fmul <int_vector_reduce_fmul>`) of the 20129vector operand ``val`` on each enabled lane, multiplying it by the scalar 20130`start_value``. Disabled lanes are treated as containing the neutral value 20131``1.0`` (i.e. having no effect on the reduction operation). If no lanes are 20132enabled, the resulting value will be equal to the starting value. 20133 20134To ignore the start value, the neutral value can be used. 20135 20136See the unpredicated version (:ref:`llvm.vector.reduce.fmul 20137<int_vector_reduce_fmul>`) for more detail on the semantics. 20138 20139Examples: 20140""""""""" 20141 20142.. code-block:: llvm 20143 20144 %r = call float @llvm.vp.reduce.fmul.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl) 20145 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 20146 ; are treated as though %mask were false for those lanes. 20147 20148 %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> 20149 %also.r = call float @llvm.vector.reduce.fmul.v4f32(float %start, <4 x float> %masked.a) 20150 20151 20152.. _int_vp_reduce_and: 20153 20154'``llvm.vp.reduce.and.*``' Intrinsics 20155^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20156 20157Syntax: 20158""""""" 20159This is an overloaded intrinsic. 20160 20161:: 20162 20163 declare i32 @llvm.vp.reduce.and.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 20164 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>) 20165 20166Overview: 20167""""""""" 20168 20169Predicated integer ``AND`` reduction of a vector and a scalar starting value, 20170returning the result as a scalar. 20171 20172 20173Arguments: 20174"""""""""" 20175 20176The first operand is the start value of the reduction, which must be a scalar 20177integer type equal to the result type. The second operand is the vector on 20178which the reduction is performed and must be a vector of integer values whose 20179element type is the result/start type. The third operand is the vector mask and 20180is a vector of boolean values with the same number of elements as the vector 20181operand. The fourth operand is the explicit vector length of the operation. 20182 20183Semantics: 20184"""""""""" 20185 20186The '``llvm.vp.reduce.and``' intrinsic performs the integer ``AND`` reduction 20187(:ref:`llvm.vector.reduce.and <int_vector_reduce_and>`) of the vector operand 20188``val`` on each enabled lane, performing an '``and``' of that with with the 20189scalar ``start_value``. Disabled lanes are treated as containing the neutral 20190value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction 20191operation). If the vector length is zero, the result is the start value. 20192 20193To ignore the start value, the neutral value can be used. 20194 20195Examples: 20196""""""""" 20197 20198.. code-block:: llvm 20199 20200 %r = call i32 @llvm.vp.reduce.and.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 20201 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 20202 ; are treated as though %mask were false for those lanes. 20203 20204 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1> 20205 %reduction = call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %masked.a) 20206 %also.r = and i32 %reduction, %start 20207 20208 20209.. _int_vp_reduce_or: 20210 20211'``llvm.vp.reduce.or.*``' Intrinsics 20212^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20213 20214Syntax: 20215""""""" 20216This is an overloaded intrinsic. 20217 20218:: 20219 20220 declare i32 @llvm.vp.reduce.or.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 20221 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>) 20222 20223Overview: 20224""""""""" 20225 20226Predicated integer ``OR`` reduction of a vector and a scalar starting value, 20227returning the result as a scalar. 20228 20229 20230Arguments: 20231"""""""""" 20232 20233The first operand is the start value of the reduction, which must be a scalar 20234integer type equal to the result type. The second operand is the vector on 20235which the reduction is performed and must be a vector of integer values whose 20236element type is the result/start type. The third operand is the vector mask and 20237is a vector of boolean values with the same number of elements as the vector 20238operand. The fourth operand is the explicit vector length of the operation. 20239 20240Semantics: 20241"""""""""" 20242 20243The '``llvm.vp.reduce.or``' intrinsic performs the integer ``OR`` reduction 20244(:ref:`llvm.vector.reduce.or <int_vector_reduce_or>`) of the vector operand 20245``val`` on each enabled lane, performing an '``or``' of that with the scalar 20246``start_value``. Disabled lanes are treated as containing the neutral value 20247``0`` (i.e. having no effect on the reduction operation). If the vector length 20248is zero, the result is the start value. 20249 20250To ignore the start value, the neutral value can be used. 20251 20252Examples: 20253""""""""" 20254 20255.. code-block:: llvm 20256 20257 %r = call i32 @llvm.vp.reduce.or.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 20258 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 20259 ; are treated as though %mask were false for those lanes. 20260 20261 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0> 20262 %reduction = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %masked.a) 20263 %also.r = or i32 %reduction, %start 20264 20265.. _int_vp_reduce_xor: 20266 20267'``llvm.vp.reduce.xor.*``' Intrinsics 20268^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20269 20270Syntax: 20271""""""" 20272This is an overloaded intrinsic. 20273 20274:: 20275 20276 declare i32 @llvm.vp.reduce.xor.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 20277 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>) 20278 20279Overview: 20280""""""""" 20281 20282Predicated integer ``XOR`` reduction of a vector and a scalar starting value, 20283returning the result as a scalar. 20284 20285 20286Arguments: 20287"""""""""" 20288 20289The first operand is the start value of the reduction, which must be a scalar 20290integer type equal to the result type. The second operand is the vector on 20291which the reduction is performed and must be a vector of integer values whose 20292element type is the result/start type. The third operand is the vector mask and 20293is a vector of boolean values with the same number of elements as the vector 20294operand. The fourth operand is the explicit vector length of the operation. 20295 20296Semantics: 20297"""""""""" 20298 20299The '``llvm.vp.reduce.xor``' intrinsic performs the integer ``XOR`` reduction 20300(:ref:`llvm.vector.reduce.xor <int_vector_reduce_xor>`) of the vector operand 20301``val`` on each enabled lane, performing an '``xor``' of that with the scalar 20302``start_value``. Disabled lanes are treated as containing the neutral value 20303``0`` (i.e. having no effect on the reduction operation). If the vector length 20304is zero, the result is the start value. 20305 20306To ignore the start value, the neutral value can be used. 20307 20308Examples: 20309""""""""" 20310 20311.. code-block:: llvm 20312 20313 %r = call i32 @llvm.vp.reduce.xor.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 20314 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 20315 ; are treated as though %mask were false for those lanes. 20316 20317 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0> 20318 %reduction = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %masked.a) 20319 %also.r = xor i32 %reduction, %start 20320 20321 20322.. _int_vp_reduce_smax: 20323 20324'``llvm.vp.reduce.smax.*``' Intrinsics 20325^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20326 20327Syntax: 20328""""""" 20329This is an overloaded intrinsic. 20330 20331:: 20332 20333 declare i32 @llvm.vp.reduce.smax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 20334 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>) 20335 20336Overview: 20337""""""""" 20338 20339Predicated signed-integer ``MAX`` reduction of a vector and a scalar starting 20340value, returning the result as a scalar. 20341 20342 20343Arguments: 20344"""""""""" 20345 20346The first operand is the start value of the reduction, which must be a scalar 20347integer type equal to the result type. The second operand is the vector on 20348which the reduction is performed and must be a vector of integer values whose 20349element type is the result/start type. The third operand is the vector mask and 20350is a vector of boolean values with the same number of elements as the vector 20351operand. The fourth operand is the explicit vector length of the operation. 20352 20353Semantics: 20354"""""""""" 20355 20356The '``llvm.vp.reduce.smax``' intrinsic performs the signed-integer ``MAX`` 20357reduction (:ref:`llvm.vector.reduce.smax <int_vector_reduce_smax>`) of the 20358vector operand ``val`` on each enabled lane, and taking the maximum of that and 20359the scalar ``start_value``. Disabled lanes are treated as containing the 20360neutral value ``INT_MIN`` (i.e. having no effect on the reduction operation). 20361If the vector length is zero, the result is the start value. 20362 20363To ignore the start value, the neutral value can be used. 20364 20365Examples: 20366""""""""" 20367 20368.. code-block:: llvm 20369 20370 %r = call i8 @llvm.vp.reduce.smax.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl) 20371 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 20372 ; are treated as though %mask were false for those lanes. 20373 20374 %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 -128, i8 -128, i8 -128, i8 -128> 20375 %reduction = call i8 @llvm.vector.reduce.smax.v4i8(<4 x i8> %masked.a) 20376 %also.r = call i8 @llvm.smax.i8(i8 %reduction, i8 %start) 20377 20378 20379.. _int_vp_reduce_smin: 20380 20381'``llvm.vp.reduce.smin.*``' Intrinsics 20382^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20383 20384Syntax: 20385""""""" 20386This is an overloaded intrinsic. 20387 20388:: 20389 20390 declare i32 @llvm.vp.reduce.smin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 20391 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>) 20392 20393Overview: 20394""""""""" 20395 20396Predicated signed-integer ``MIN`` reduction of a vector and a scalar starting 20397value, returning the result as a scalar. 20398 20399 20400Arguments: 20401"""""""""" 20402 20403The first operand is the start value of the reduction, which must be a scalar 20404integer type equal to the result type. The second operand is the vector on 20405which the reduction is performed and must be a vector of integer values whose 20406element type is the result/start type. The third operand is the vector mask and 20407is a vector of boolean values with the same number of elements as the vector 20408operand. The fourth operand is the explicit vector length of the operation. 20409 20410Semantics: 20411"""""""""" 20412 20413The '``llvm.vp.reduce.smin``' intrinsic performs the signed-integer ``MIN`` 20414reduction (:ref:`llvm.vector.reduce.smin <int_vector_reduce_smin>`) of the 20415vector operand ``val`` on each enabled lane, and taking the minimum of that and 20416the scalar ``start_value``. Disabled lanes are treated as containing the 20417neutral value ``INT_MAX`` (i.e. having no effect on the reduction operation). 20418If the vector length is zero, the result is the start value. 20419 20420To ignore the start value, the neutral value can be used. 20421 20422Examples: 20423""""""""" 20424 20425.. code-block:: llvm 20426 20427 %r = call i8 @llvm.vp.reduce.smin.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl) 20428 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 20429 ; are treated as though %mask were false for those lanes. 20430 20431 %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 127, i8 127, i8 127, i8 127> 20432 %reduction = call i8 @llvm.vector.reduce.smin.v4i8(<4 x i8> %masked.a) 20433 %also.r = call i8 @llvm.smin.i8(i8 %reduction, i8 %start) 20434 20435 20436.. _int_vp_reduce_umax: 20437 20438'``llvm.vp.reduce.umax.*``' Intrinsics 20439^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20440 20441Syntax: 20442""""""" 20443This is an overloaded intrinsic. 20444 20445:: 20446 20447 declare i32 @llvm.vp.reduce.umax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 20448 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>) 20449 20450Overview: 20451""""""""" 20452 20453Predicated unsigned-integer ``MAX`` reduction of a vector and a scalar starting 20454value, returning the result as a scalar. 20455 20456 20457Arguments: 20458"""""""""" 20459 20460The first operand is the start value of the reduction, which must be a scalar 20461integer type equal to the result type. The second operand is the vector on 20462which the reduction is performed and must be a vector of integer values whose 20463element type is the result/start type. The third operand is the vector mask and 20464is a vector of boolean values with the same number of elements as the vector 20465operand. The fourth operand is the explicit vector length of the operation. 20466 20467Semantics: 20468"""""""""" 20469 20470The '``llvm.vp.reduce.umax``' intrinsic performs the unsigned-integer ``MAX`` 20471reduction (:ref:`llvm.vector.reduce.umax <int_vector_reduce_umax>`) of the 20472vector operand ``val`` on each enabled lane, and taking the maximum of that and 20473the scalar ``start_value``. Disabled lanes are treated as containing the 20474neutral value ``0`` (i.e. having no effect on the reduction operation). If the 20475vector length is zero, the result is the start value. 20476 20477To ignore the start value, the neutral value can be used. 20478 20479Examples: 20480""""""""" 20481 20482.. code-block:: llvm 20483 20484 %r = call i32 @llvm.vp.reduce.umax.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 20485 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 20486 ; are treated as though %mask were false for those lanes. 20487 20488 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0> 20489 %reduction = call i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %masked.a) 20490 %also.r = call i32 @llvm.umax.i32(i32 %reduction, i32 %start) 20491 20492 20493.. _int_vp_reduce_umin: 20494 20495'``llvm.vp.reduce.umin.*``' Intrinsics 20496^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20497 20498Syntax: 20499""""""" 20500This is an overloaded intrinsic. 20501 20502:: 20503 20504 declare i32 @llvm.vp.reduce.umin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 20505 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>) 20506 20507Overview: 20508""""""""" 20509 20510Predicated unsigned-integer ``MIN`` reduction of a vector and a scalar starting 20511value, returning the result as a scalar. 20512 20513 20514Arguments: 20515"""""""""" 20516 20517The first operand is the start value of the reduction, which must be a scalar 20518integer type equal to the result type. The second operand is the vector on 20519which the reduction is performed and must be a vector of integer values whose 20520element type is the result/start type. The third operand is the vector mask and 20521is a vector of boolean values with the same number of elements as the vector 20522operand. The fourth operand is the explicit vector length of the operation. 20523 20524Semantics: 20525"""""""""" 20526 20527The '``llvm.vp.reduce.umin``' intrinsic performs the unsigned-integer ``MIN`` 20528reduction (:ref:`llvm.vector.reduce.umin <int_vector_reduce_umin>`) of the 20529vector operand ``val`` on each enabled lane, taking the minimum of that and the 20530scalar ``start_value``. Disabled lanes are treated as containing the neutral 20531value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction 20532operation). If the vector length is zero, the result is the start value. 20533 20534To ignore the start value, the neutral value can be used. 20535 20536Examples: 20537""""""""" 20538 20539.. code-block:: llvm 20540 20541 %r = call i32 @llvm.vp.reduce.umin.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 20542 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 20543 ; are treated as though %mask were false for those lanes. 20544 20545 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1> 20546 %reduction = call i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %masked.a) 20547 %also.r = call i32 @llvm.umin.i32(i32 %reduction, i32 %start) 20548 20549 20550.. _int_vp_reduce_fmax: 20551 20552'``llvm.vp.reduce.fmax.*``' Intrinsics 20553^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20554 20555Syntax: 20556""""""" 20557This is an overloaded intrinsic. 20558 20559:: 20560 20561 declare float @llvm.vp.reduce.fmax.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>) 20562 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>) 20563 20564Overview: 20565""""""""" 20566 20567Predicated floating-point ``MAX`` reduction of a vector and a scalar starting 20568value, returning the result as a scalar. 20569 20570 20571Arguments: 20572"""""""""" 20573 20574The first operand is the start value of the reduction, which must be a scalar 20575floating-point type equal to the result type. The second operand is the vector 20576on which the reduction is performed and must be a vector of floating-point 20577values whose element type is the result/start type. The third operand is the 20578vector mask and is a vector of boolean values with the same number of elements 20579as the vector operand. The fourth operand is the explicit vector length of the 20580operation. 20581 20582Semantics: 20583"""""""""" 20584 20585The '``llvm.vp.reduce.fmax``' intrinsic performs the floating-point ``MAX`` 20586reduction (:ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>`) of the 20587vector operand ``val`` on each enabled lane, taking the maximum of that and the 20588scalar ``start_value``. Disabled lanes are treated as containing the neutral 20589value (i.e. having no effect on the reduction operation). If the vector length 20590is zero, the result is the start value. 20591 20592The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no 20593flags are set, the neutral value is ``-QNAN``. If ``nnan`` and ``ninf`` are 20594both set, then the neutral value is the smallest floating-point value for the 20595result type. If only ``nnan`` is set then the neutral value is ``-Infinity``. 20596 20597This instruction has the same comparison semantics as the 20598:ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>` intrinsic (and thus the 20599'``llvm.maxnum.*``' intrinsic). That is, the result will always be a number 20600unless all elements of the vector and the starting value are ``NaN``. For a 20601vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and 20602``-0.0`` elements, the sign of the result is unspecified. 20603 20604To ignore the start value, the neutral value can be used. 20605 20606Examples: 20607""""""""" 20608 20609.. code-block:: llvm 20610 20611 %r = call float @llvm.vp.reduce.fmax.v4f32(float %float, <4 x float> %a, <4 x i1> %mask, i32 %evl) 20612 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 20613 ; are treated as though %mask were false for those lanes. 20614 20615 %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN> 20616 %reduction = call float @llvm.vector.reduce.fmax.v4f32(<4 x float> %masked.a) 20617 %also.r = call float @llvm.maxnum.f32(float %reduction, float %start) 20618 20619 20620.. _int_vp_reduce_fmin: 20621 20622'``llvm.vp.reduce.fmin.*``' Intrinsics 20623^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20624 20625Syntax: 20626""""""" 20627This is an overloaded intrinsic. 20628 20629:: 20630 20631 declare float @llvm.vp.reduce.fmin.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>) 20632 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>) 20633 20634Overview: 20635""""""""" 20636 20637Predicated floating-point ``MIN`` reduction of a vector and a scalar starting 20638value, returning the result as a scalar. 20639 20640 20641Arguments: 20642"""""""""" 20643 20644The first operand is the start value of the reduction, which must be a scalar 20645floating-point type equal to the result type. The second operand is the vector 20646on which the reduction is performed and must be a vector of floating-point 20647values whose element type is the result/start type. The third operand is the 20648vector mask and is a vector of boolean values with the same number of elements 20649as the vector operand. The fourth operand is the explicit vector length of the 20650operation. 20651 20652Semantics: 20653"""""""""" 20654 20655The '``llvm.vp.reduce.fmin``' intrinsic performs the floating-point ``MIN`` 20656reduction (:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>`) of the 20657vector operand ``val`` on each enabled lane, taking the minimum of that and the 20658scalar ``start_value``. Disabled lanes are treated as containing the neutral 20659value (i.e. having no effect on the reduction operation). If the vector length 20660is zero, the result is the start value. 20661 20662The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no 20663flags are set, the neutral value is ``+QNAN``. If ``nnan`` and ``ninf`` are 20664both set, then the neutral value is the largest floating-point value for the 20665result type. If only ``nnan`` is set then the neutral value is ``+Infinity``. 20666 20667This instruction has the same comparison semantics as the 20668:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>` intrinsic (and thus the 20669'``llvm.minnum.*``' intrinsic). That is, the result will always be a number 20670unless all elements of the vector and the starting value are ``NaN``. For a 20671vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and 20672``-0.0`` elements, the sign of the result is unspecified. 20673 20674To ignore the start value, the neutral value can be used. 20675 20676Examples: 20677""""""""" 20678 20679.. code-block:: llvm 20680 20681 %r = call float @llvm.vp.reduce.fmin.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl) 20682 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 20683 ; are treated as though %mask were false for those lanes. 20684 20685 %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN> 20686 %reduction = call float @llvm.vector.reduce.fmin.v4f32(<4 x float> %masked.a) 20687 %also.r = call float @llvm.minnum.f32(float %reduction, float %start) 20688 20689 20690.. _int_get_active_lane_mask: 20691 20692'``llvm.get.active.lane.mask.*``' Intrinsics 20693^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20694 20695Syntax: 20696""""""" 20697This is an overloaded intrinsic. 20698 20699:: 20700 20701 declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %base, i32 %n) 20702 declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 %base, i64 %n) 20703 declare <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 %base, i64 %n) 20704 declare <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 %base, i64 %n) 20705 20706 20707Overview: 20708""""""""" 20709 20710Create a mask representing active and inactive vector lanes. 20711 20712 20713Arguments: 20714"""""""""" 20715 20716Both operands have the same scalar integer type. The result is a vector with 20717the i1 element type. 20718 20719Semantics: 20720"""""""""" 20721 20722The '``llvm.get.active.lane.mask.*``' intrinsics are semantically equivalent 20723to: 20724 20725:: 20726 20727 %m[i] = icmp ult (%base + i), %n 20728 20729where ``%m`` is a vector (mask) of active/inactive lanes with its elements 20730indexed by ``i``, and ``%base``, ``%n`` are the two arguments to 20731``llvm.get.active.lane.mask.*``, ``%icmp`` is an integer compare and ``ult`` 20732the unsigned less-than comparison operator. Overflow cannot occur in 20733``(%base + i)`` and its comparison against ``%n`` as it is performed in integer 20734numbers and not in machine numbers. If ``%n`` is ``0``, then the result is a 20735poison value. The above is equivalent to: 20736 20737:: 20738 20739 %m = @llvm.get.active.lane.mask(%base, %n) 20740 20741This can, for example, be emitted by the loop vectorizer in which case 20742``%base`` is the first element of the vector induction variable (VIV) and 20743``%n`` is the loop tripcount. Thus, these intrinsics perform an element-wise 20744less than comparison of VIV with the loop tripcount, producing a mask of 20745true/false values representing active/inactive vector lanes, except if the VIV 20746overflows in which case they return false in the lanes where the VIV overflows. 20747The arguments are scalar types to accommodate scalable vector types, for which 20748it is unknown what the type of the step vector needs to be that enumerate its 20749lanes without overflow. 20750 20751This mask ``%m`` can e.g. be used in masked load/store instructions. These 20752intrinsics provide a hint to the backend. I.e., for a vector loop, the 20753back-edge taken count of the original scalar loop is explicit as the second 20754argument. 20755 20756 20757Examples: 20758""""""""" 20759 20760.. code-block:: llvm 20761 20762 %active.lane.mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 %elem0, i64 429) 20763 %wide.masked.load = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %3, i32 4, <4 x i1> %active.lane.mask, <4 x i32> poison) 20764 20765 20766.. _int_experimental_vp_splice: 20767 20768'``llvm.experimental.vp.splice``' Intrinsic 20769^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20770 20771Syntax: 20772""""""" 20773This is an overloaded intrinsic. 20774 20775:: 20776 20777 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) 20778 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) 20779 20780Overview: 20781""""""""" 20782 20783The '``llvm.experimental.vp.splice.*``' intrinsic is the vector length 20784predicated version of the '``llvm.experimental.vector.splice.*``' intrinsic. 20785 20786Arguments: 20787"""""""""" 20788 20789The result and the first two arguments ``vec1`` and ``vec2`` are vectors with 20790the same type. The third argument ``imm`` is an immediate signed integer that 20791indicates the offset index. The fourth argument ``mask`` is a vector mask and 20792has the same number of elements as the result. The last two arguments ``evl1`` 20793and ``evl2`` are unsigned integers indicating the explicit vector lengths of 20794``vec1`` and ``vec2`` respectively. ``imm``, ``evl1`` and ``evl2`` should 20795respect the following constraints: ``-evl1 <= imm < evl1``, ``0 <= evl1 <= VL`` 20796and ``0 <= evl2 <= VL``, where ``VL`` is the runtime vector factor. If these 20797constraints are not satisfied the intrinsic has undefined behaviour. 20798 20799Semantics: 20800"""""""""" 20801 20802Effectively, this intrinsic concatenates ``vec1[0..evl1-1]`` and 20803``vec2[0..evl2-1]`` and creates the result vector by selecting the elements in a 20804window of size ``evl2``, starting at index ``imm`` (for a positive immediate) of 20805the concatenated vector. Elements in the result vector beyond ``evl2`` are 20806``undef``. If ``imm`` is negative the starting index is ``evl1 + imm``. The result 20807vector of active vector length ``evl2`` contains ``evl1 - imm`` (``-imm`` for 20808negative ``imm``) elements from indices ``[imm..evl1 - 1]`` 20809(``[evl1 + imm..evl1 -1]`` for negative ``imm``) of ``vec1`` followed by the 20810first ``evl2 - (evl1 - imm)`` (``evl2 + imm`` for negative ``imm``) elements of 20811``vec2``. If ``evl1 - imm`` (``-imm``) >= ``evl2``, only the first ``evl2`` 20812elements are considered and the remaining are ``undef``. The lanes in the result 20813vector disabled by ``mask`` are ``poison``. 20814 20815Examples: 20816""""""""" 20817 20818.. code-block:: text 20819 20820 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, 1, 2, 3) ==> <B, E, F, poison> ; index 20821 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, -2, 3, 2) ==> <B, C, poison, poison> ; trailing elements 20822 20823 20824.. _int_vp_load: 20825 20826'``llvm.vp.load``' Intrinsic 20827^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20828 20829Syntax: 20830""""""" 20831This is an overloaded intrinsic. 20832 20833:: 20834 20835 declare <4 x float> @llvm.vp.load.v4f32.p0(ptr %ptr, <4 x i1> %mask, i32 %evl) 20836 declare <vscale x 2 x i16> @llvm.vp.load.nxv2i16.p0(ptr %ptr, <vscale x 2 x i1> %mask, i32 %evl) 20837 declare <8 x float> @llvm.vp.load.v8f32.p1(ptr addrspace(1) %ptr, <8 x i1> %mask, i32 %evl) 20838 declare <vscale x 1 x i64> @llvm.vp.load.nxv1i64.p6(ptr addrspace(6) %ptr, <vscale x 1 x i1> %mask, i32 %evl) 20839 20840Overview: 20841""""""""" 20842 20843The '``llvm.vp.load.*``' intrinsic is the vector length predicated version of 20844the :ref:`llvm.masked.load <int_mload>` intrinsic. 20845 20846Arguments: 20847"""""""""" 20848 20849The first operand is the base pointer for the load. The second operand is a 20850vector of boolean values with the same number of elements as the return type. 20851The third is the explicit vector length of the operation. The return type and 20852underlying type of the base pointer are the same vector types. 20853 20854The :ref:`align <attr_align>` parameter attribute can be provided for the first 20855operand. 20856 20857Semantics: 20858"""""""""" 20859 20860The '``llvm.vp.load``' intrinsic reads a vector from memory in the same way as 20861the '``llvm.masked.load``' intrinsic, where the mask is taken from the 20862combination of the '``mask``' and '``evl``' operands in the usual VP way. 20863Certain '``llvm.masked.load``' operands do not have corresponding operands in 20864'``llvm.vp.load``': the '``passthru``' operand is implicitly ``poison``; the 20865'``alignment``' operand is taken as the ``align`` parameter attribute, if 20866provided. The default alignment is taken as the ABI alignment of the return 20867type as specified by the :ref:`datalayout string<langref_datalayout>`. 20868 20869Examples: 20870""""""""" 20871 20872.. code-block:: text 20873 20874 %r = call <8 x i8> @llvm.vp.load.v8i8.p0(ptr align 2 %ptr, <8 x i1> %mask, i32 %evl) 20875 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20876 20877 %also.r = call <8 x i8> @llvm.masked.load.v8i8.p0(ptr %ptr, i32 2, <8 x i1> %mask, <8 x i8> poison) 20878 20879 20880.. _int_vp_store: 20881 20882'``llvm.vp.store``' Intrinsic 20883^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20884 20885Syntax: 20886""""""" 20887This is an overloaded intrinsic. 20888 20889:: 20890 20891 declare void @llvm.vp.store.v4f32.p0(<4 x float> %val, ptr %ptr, <4 x i1> %mask, i32 %evl) 20892 declare void @llvm.vp.store.nxv2i16.p0(<vscale x 2 x i16> %val, ptr %ptr, <vscale x 2 x i1> %mask, i32 %evl) 20893 declare void @llvm.vp.store.v8f32.p1(<8 x float> %val, ptr addrspace(1) %ptr, <8 x i1> %mask, i32 %evl) 20894 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) 20895 20896Overview: 20897""""""""" 20898 20899The '``llvm.vp.store.*``' intrinsic is the vector length predicated version of 20900the :ref:`llvm.masked.store <int_mstore>` intrinsic. 20901 20902Arguments: 20903"""""""""" 20904 20905The first operand is the vector value to be written to memory. The second 20906operand is the base pointer for the store. It has the same underlying type as 20907the value operand. The third operand is a vector of boolean values with the 20908same number of elements as the return type. The fourth is the explicit vector 20909length of the operation. 20910 20911The :ref:`align <attr_align>` parameter attribute can be provided for the 20912second operand. 20913 20914Semantics: 20915"""""""""" 20916 20917The '``llvm.vp.store``' intrinsic reads a vector from memory in the same way as 20918the '``llvm.masked.store``' intrinsic, where the mask is taken from the 20919combination of the '``mask``' and '``evl``' operands in the usual VP way. The 20920alignment of the operation (corresponding to the '``alignment``' operand of 20921'``llvm.masked.store``') is specified by the ``align`` parameter attribute (see 20922above). If it is not provided then the ABI alignment of the type of the 20923'``value``' operand as specified by the :ref:`datalayout 20924string<langref_datalayout>` is used instead. 20925 20926Examples: 20927""""""""" 20928 20929.. code-block:: text 20930 20931 call void @llvm.vp.store.v8i8.p0(<8 x i8> %val, ptr align 4 %ptr, <8 x i1> %mask, i32 %evl) 20932 ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below. 20933 20934 call void @llvm.masked.store.v8i8.p0(<8 x i8> %val, ptr %ptr, i32 4, <8 x i1> %mask) 20935 20936 20937.. _int_experimental_vp_strided_load: 20938 20939'``llvm.experimental.vp.strided.load``' Intrinsic 20940^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20941 20942Syntax: 20943""""""" 20944This is an overloaded intrinsic. 20945 20946:: 20947 20948 declare <4 x float> @llvm.experimental.vp.strided.load.v4f32.i64(ptr %ptr, i64 %stride, <4 x i1> %mask, i32 %evl) 20949 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) 20950 20951Overview: 20952""""""""" 20953 20954The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, scalar values from 20955memory locations evenly spaced apart by '``stride``' number of bytes, starting from '``ptr``'. 20956 20957Arguments: 20958"""""""""" 20959 20960The first operand is the base pointer for the load. The second operand is the stride 20961value expressed in bytes. The third operand is a vector of boolean values 20962with the same number of elements as the return type. The fourth is the explicit 20963vector length of the operation. The base pointer underlying type matches the type of the scalar 20964elements of the return operand. 20965 20966The :ref:`align <attr_align>` parameter attribute can be provided for the first 20967operand. 20968 20969Semantics: 20970"""""""""" 20971 20972The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, multiple scalar 20973values from memory in the same way as the :ref:`llvm.vp.gather <int_vp_gather>` intrinsic, 20974where the vector of pointers is in the form: 20975 20976 ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``, 20977 20978with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed 20979integer and all arithmetic occurring in the pointer type. 20980 20981Examples: 20982""""""""" 20983 20984.. code-block:: text 20985 20986 %r = call <8 x i64> @llvm.experimental.vp.strided.load.v8i64.i64(i64* %ptr, i64 %stride, <8 x i64> %mask, i32 %evl) 20987 ;; The operation can also be expressed like this: 20988 20989 %addr = bitcast i64* %ptr to i8* 20990 ;; Create a vector of pointers %addrs in the form: 20991 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...> 20992 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* > 20993 %also.r = call <8 x i64> @llvm.vp.gather.v8i64.v8p0i64(<8 x i64* > %ptrs, <8 x i64> %mask, i32 %evl) 20994 20995 20996.. _int_experimental_vp_strided_store: 20997 20998'``llvm.experimental.vp.strided.store``' Intrinsic 20999^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21000 21001Syntax: 21002""""""" 21003This is an overloaded intrinsic. 21004 21005:: 21006 21007 declare void @llvm.experimental.vp.strided.store.v4f32.i64(<4 x float> %val, ptr %ptr, i64 %stride, <4 x i1> %mask, i32 %evl) 21008 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) 21009 21010Overview: 21011""""""""" 21012 21013The '``@llvm.experimental.vp.strided.store``' intrinsic stores the elements of 21014'``val``' into memory locations evenly spaced apart by '``stride``' number of 21015bytes, starting from '``ptr``'. 21016 21017Arguments: 21018"""""""""" 21019 21020The first operand is the vector value to be written to memory. The second 21021operand is the base pointer for the store. Its underlying type matches the 21022scalar element type of the value operand. The third operand is the stride value 21023expressed in bytes. The fourth operand is a vector of boolean values with the 21024same number of elements as the return type. The fifth is the explicit vector 21025length of the operation. 21026 21027The :ref:`align <attr_align>` parameter attribute can be provided for the 21028second operand. 21029 21030Semantics: 21031"""""""""" 21032 21033The '``llvm.experimental.vp.strided.store``' intrinsic stores the elements of 21034'``val``' in the same way as the :ref:`llvm.vp.scatter <int_vp_scatter>` intrinsic, 21035where the vector of pointers is in the form: 21036 21037 ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``, 21038 21039with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed 21040integer and all arithmetic occurring in the pointer type. 21041 21042Examples: 21043""""""""" 21044 21045.. code-block:: text 21046 21047 call void @llvm.experimental.vp.strided.store.v8i64.i64(<8 x i64> %val, i64* %ptr, i64 %stride, <8 x i1> %mask, i32 %evl) 21048 ;; The operation can also be expressed like this: 21049 21050 %addr = bitcast i64* %ptr to i8* 21051 ;; Create a vector of pointers %addrs in the form: 21052 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...> 21053 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* > 21054 call void @llvm.vp.scatter.v8i64.v8p0i64(<8 x i64> %val, <8 x i64*> %ptrs, <8 x i1> %mask, i32 %evl) 21055 21056 21057.. _int_vp_gather: 21058 21059'``llvm.vp.gather``' Intrinsic 21060^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21061 21062Syntax: 21063""""""" 21064This is an overloaded intrinsic. 21065 21066:: 21067 21068 declare <4 x double> @llvm.vp.gather.v4f64.v4p0(<4 x ptr> %ptrs, <4 x i1> %mask, i32 %evl) 21069 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) 21070 declare <2 x float> @llvm.vp.gather.v2f32.v2p2(<2 x ptr addrspace(2)> %ptrs, <2 x i1> %mask, i32 %evl) 21071 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) 21072 21073Overview: 21074""""""""" 21075 21076The '``llvm.vp.gather.*``' intrinsic is the vector length predicated version of 21077the :ref:`llvm.masked.gather <int_mgather>` intrinsic. 21078 21079Arguments: 21080"""""""""" 21081 21082The first operand is a vector of pointers which holds all memory addresses to 21083read. The second operand is a vector of boolean values with the same number of 21084elements as the return type. The third is the explicit vector length of the 21085operation. The return type and underlying type of the vector of pointers are 21086the same vector types. 21087 21088The :ref:`align <attr_align>` parameter attribute can be provided for the first 21089operand. 21090 21091Semantics: 21092"""""""""" 21093 21094The '``llvm.vp.gather``' intrinsic reads multiple scalar values from memory in 21095the same way as the '``llvm.masked.gather``' intrinsic, where the mask is taken 21096from the combination of the '``mask``' and '``evl``' operands in the usual VP 21097way. Certain '``llvm.masked.gather``' operands do not have corresponding 21098operands in '``llvm.vp.gather``': the '``passthru``' operand is implicitly 21099``poison``; the '``alignment``' operand is taken as the ``align`` parameter, if 21100provided. The default alignment is taken as the ABI alignment of the source 21101addresses as specified by the :ref:`datalayout string<langref_datalayout>`. 21102 21103Examples: 21104""""""""" 21105 21106.. code-block:: text 21107 21108 %r = call <8 x i8> @llvm.vp.gather.v8i8.v8p0(<8 x ptr> align 8 %ptrs, <8 x i1> %mask, i32 %evl) 21109 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21110 21111 %also.r = call <8 x i8> @llvm.masked.gather.v8i8.v8p0(<8 x ptr> %ptrs, i32 8, <8 x i1> %mask, <8 x i8> poison) 21112 21113 21114.. _int_vp_scatter: 21115 21116'``llvm.vp.scatter``' Intrinsic 21117^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21118 21119Syntax: 21120""""""" 21121This is an overloaded intrinsic. 21122 21123:: 21124 21125 declare void @llvm.vp.scatter.v4f64.v4p0(<4 x double> %val, <4 x ptr> %ptrs, <4 x i1> %mask, i32 %evl) 21126 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) 21127 declare void @llvm.vp.scatter.v2f32.v2p2(<2 x float> %val, <2 x ptr addrspace(2)> %ptrs, <2 x i1> %mask, i32 %evl) 21128 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) 21129 21130Overview: 21131""""""""" 21132 21133The '``llvm.vp.scatter.*``' intrinsic is the vector length predicated version of 21134the :ref:`llvm.masked.scatter <int_mscatter>` intrinsic. 21135 21136Arguments: 21137"""""""""" 21138 21139The first operand is a vector value to be written to memory. The second operand 21140is a vector of pointers, pointing to where the value elements should be stored. 21141The third operand is a vector of boolean values with the same number of 21142elements as the return type. The fourth is the explicit vector length of the 21143operation. 21144 21145The :ref:`align <attr_align>` parameter attribute can be provided for the 21146second operand. 21147 21148Semantics: 21149"""""""""" 21150 21151The '``llvm.vp.scatter``' intrinsic writes multiple scalar values to memory in 21152the same way as the '``llvm.masked.scatter``' intrinsic, where the mask is 21153taken from the combination of the '``mask``' and '``evl``' operands in the 21154usual VP way. The '``alignment``' operand of the '``llvm.masked.scatter``' does 21155not have a corresponding operand in '``llvm.vp.scatter``': it is instead 21156provided via the optional ``align`` parameter attribute on the 21157vector-of-pointers operand. Otherwise it is taken as the ABI alignment of the 21158destination addresses as specified by the :ref:`datalayout 21159string<langref_datalayout>`. 21160 21161Examples: 21162""""""""" 21163 21164.. code-block:: text 21165 21166 call void @llvm.vp.scatter.v8i8.v8p0(<8 x i8> %val, <8 x ptr> align 1 %ptrs, <8 x i1> %mask, i32 %evl) 21167 ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below. 21168 21169 call void @llvm.masked.scatter.v8i8.v8p0(<8 x i8> %val, <8 x ptr> %ptrs, i32 1, <8 x i1> %mask) 21170 21171 21172.. _int_vp_trunc: 21173 21174'``llvm.vp.trunc.*``' Intrinsics 21175^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21176 21177Syntax: 21178""""""" 21179This is an overloaded intrinsic. 21180 21181:: 21182 21183 declare <16 x i16> @llvm.vp.trunc.v16i16.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 21184 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>) 21185 21186Overview: 21187""""""""" 21188 21189The '``llvm.vp.trunc``' intrinsic truncates its first operand to the return 21190type. The operation has a mask and an explicit vector length parameter. 21191 21192 21193Arguments: 21194"""""""""" 21195 21196The '``llvm.vp.trunc``' intrinsic takes a value to cast as its first operand. 21197The return type is the type to cast the value to. Both types must be vector of 21198:ref:`integer <t_integer>` type. The bit size of the value must be larger than 21199the bit size of the return type. The second operand is the vector mask. The 21200return type, the value to cast, and the vector mask have the same number of 21201elements. The third operand is the explicit vector length of the operation. 21202 21203Semantics: 21204"""""""""" 21205 21206The '``llvm.vp.trunc``' intrinsic truncates the high order bits in value and 21207converts the remaining bits to return type. Since the source size must be larger 21208than the destination size, '``llvm.vp.trunc``' cannot be a *no-op cast*. It will 21209always truncate bits. The conversion is performed on lane positions below the 21210explicit vector length and where the vector mask is true. Masked-off lanes are 21211``poison``. 21212 21213Examples: 21214""""""""" 21215 21216.. code-block:: llvm 21217 21218 %r = call <4 x i16> @llvm.vp.trunc.v4i16.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 21219 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21220 21221 %t = trunc <4 x i32> %a to <4 x i16> 21222 %also.r = select <4 x i1> %mask, <4 x i16> %t, <4 x i16> poison 21223 21224 21225.. _int_vp_zext: 21226 21227'``llvm.vp.zext.*``' Intrinsics 21228^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21229 21230Syntax: 21231""""""" 21232This is an overloaded intrinsic. 21233 21234:: 21235 21236 declare <16 x i32> @llvm.vp.zext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>) 21237 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>) 21238 21239Overview: 21240""""""""" 21241 21242The '``llvm.vp.zext``' intrinsic zero extends its first operand to the return 21243type. The operation has a mask and an explicit vector length parameter. 21244 21245 21246Arguments: 21247"""""""""" 21248 21249The '``llvm.vp.zext``' intrinsic takes a value to cast as its first operand. 21250The return type is the type to cast the value to. Both types must be vectors of 21251:ref:`integer <t_integer>` type. The bit size of the value must be smaller than 21252the bit size of the return type. The second operand is the vector mask. The 21253return type, the value to cast, and the vector mask have the same number of 21254elements. The third operand is the explicit vector length of the operation. 21255 21256Semantics: 21257"""""""""" 21258 21259The '``llvm.vp.zext``' intrinsic fill the high order bits of the value with zero 21260bits until it reaches the size of the return type. When zero extending from i1, 21261the result will always be either 0 or 1. The conversion is performed on lane 21262positions below the explicit vector length and where the vector mask is true. 21263Masked-off lanes are ``poison``. 21264 21265Examples: 21266""""""""" 21267 21268.. code-block:: llvm 21269 21270 %r = call <4 x i32> @llvm.vp.zext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl) 21271 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21272 21273 %t = zext <4 x i16> %a to <4 x i32> 21274 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 21275 21276 21277.. _int_vp_sext: 21278 21279'``llvm.vp.sext.*``' Intrinsics 21280^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21281 21282Syntax: 21283""""""" 21284This is an overloaded intrinsic. 21285 21286:: 21287 21288 declare <16 x i32> @llvm.vp.sext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>) 21289 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>) 21290 21291Overview: 21292""""""""" 21293 21294The '``llvm.vp.sext``' intrinsic sign extends its first operand to the return 21295type. The operation has a mask and an explicit vector length parameter. 21296 21297 21298Arguments: 21299"""""""""" 21300 21301The '``llvm.vp.sext``' intrinsic takes a value to cast as its first operand. 21302The return type is the type to cast the value to. Both types must be vectors of 21303:ref:`integer <t_integer>` type. The bit size of the value must be smaller than 21304the bit size of the return type. The second operand is the vector mask. The 21305return type, the value to cast, and the vector mask have the same number of 21306elements. The third operand is the explicit vector length of the operation. 21307 21308Semantics: 21309"""""""""" 21310 21311The '``llvm.vp.sext``' intrinsic performs a sign extension by copying the sign 21312bit (highest order bit) of the value until it reaches the size of the return 21313type. When sign extending from i1, the result will always be either -1 or 0. 21314The conversion is performed on lane positions below the explicit vector length 21315and where the vector mask is true. Masked-off lanes are ``poison``. 21316 21317Examples: 21318""""""""" 21319 21320.. code-block:: llvm 21321 21322 %r = call <4 x i32> @llvm.vp.sext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl) 21323 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21324 21325 %t = sext <4 x i16> %a to <4 x i32> 21326 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 21327 21328 21329.. _int_vp_fptrunc: 21330 21331'``llvm.vp.fptrunc.*``' Intrinsics 21332^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21333 21334Syntax: 21335""""""" 21336This is an overloaded intrinsic. 21337 21338:: 21339 21340 declare <16 x float> @llvm.vp.fptrunc.v16f32.v16f64 (<16 x double> <op>, <16 x i1> <mask>, i32 <vector_length>) 21341 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>) 21342 21343Overview: 21344""""""""" 21345 21346The '``llvm.vp.fptrunc``' intrinsic truncates its first operand to the return 21347type. The operation has a mask and an explicit vector length parameter. 21348 21349 21350Arguments: 21351"""""""""" 21352 21353The '``llvm.vp.fptrunc``' intrinsic takes a value to cast as its first operand. 21354The return type is the type to cast the value to. Both types must be vector of 21355:ref:`floating-point <t_floating>` type. The bit size of the value must be 21356larger than the bit size of the return type. This implies that 21357'``llvm.vp.fptrunc``' cannot be used to make a *no-op cast*. The second operand 21358is the vector mask. The return type, the value to cast, and the vector mask have 21359the same number of elements. The third operand is the explicit vector length of 21360the operation. 21361 21362Semantics: 21363"""""""""" 21364 21365The '``llvm.vp.fptrunc``' intrinsic casts a ``value`` from a larger 21366:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point 21367<t_floating>` type. 21368This instruction is assumed to execute in the default :ref:`floating-point 21369environment <floatenv>`. The conversion is performed on lane positions below the 21370explicit vector length and where the vector mask is true. Masked-off lanes are 21371``poison``. 21372 21373Examples: 21374""""""""" 21375 21376.. code-block:: llvm 21377 21378 %r = call <4 x float> @llvm.vp.fptrunc.v4f32.v4f64(<4 x double> %a, <4 x i1> %mask, i32 %evl) 21379 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21380 21381 %t = fptrunc <4 x double> %a to <4 x float> 21382 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 21383 21384 21385.. _int_vp_fpext: 21386 21387'``llvm.vp.fpext.*``' Intrinsics 21388^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21389 21390Syntax: 21391""""""" 21392This is an overloaded intrinsic. 21393 21394:: 21395 21396 declare <16 x double> @llvm.vp.fpext.v16f64.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 21397 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>) 21398 21399Overview: 21400""""""""" 21401 21402The '``llvm.vp.fpext``' intrinsic extends its first operand to the return 21403type. The operation has a mask and an explicit vector length parameter. 21404 21405 21406Arguments: 21407"""""""""" 21408 21409The '``llvm.vp.fpext``' intrinsic takes a value to cast as its first operand. 21410The return type is the type to cast the value to. Both types must be vector of 21411:ref:`floating-point <t_floating>` type. The bit size of the value must be 21412smaller than the bit size of the return type. This implies that 21413'``llvm.vp.fpext``' cannot be used to make a *no-op cast*. The second operand 21414is the vector mask. The return type, the value to cast, and the vector mask have 21415the same number of elements. The third operand is the explicit vector length of 21416the operation. 21417 21418Semantics: 21419"""""""""" 21420 21421The '``llvm.vp.fpext``' intrinsic extends the ``value`` from a smaller 21422:ref:`floating-point <t_floating>` type to a larger :ref:`floating-point 21423<t_floating>` type. The '``llvm.vp.fpext``' cannot be used to make a 21424*no-op cast* because it always changes bits. Use ``bitcast`` to make a 21425*no-op cast* for a floating-point cast. 21426The conversion is performed on lane positions below the explicit vector length 21427and where the vector mask is true. Masked-off lanes are ``poison``. 21428 21429Examples: 21430""""""""" 21431 21432.. code-block:: llvm 21433 21434 %r = call <4 x double> @llvm.vp.fpext.v4f64.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 21435 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21436 21437 %t = fpext <4 x float> %a to <4 x double> 21438 %also.r = select <4 x i1> %mask, <4 x double> %t, <4 x double> poison 21439 21440 21441.. _int_vp_fptoui: 21442 21443'``llvm.vp.fptoui.*``' Intrinsics 21444^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21445 21446Syntax: 21447""""""" 21448This is an overloaded intrinsic. 21449 21450:: 21451 21452 declare <16 x i32> @llvm.vp.fptoui.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 21453 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>) 21454 declare <256 x i64> @llvm.vp.fptoui.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 21455 21456Overview: 21457""""""""" 21458 21459The '``llvm.vp.fptoui``' intrinsic converts the :ref:`floating-point 21460<t_floating>` operand to the unsigned integer return type. 21461The operation has a mask and an explicit vector length parameter. 21462 21463 21464Arguments: 21465"""""""""" 21466 21467The '``llvm.vp.fptoui``' intrinsic takes a value to cast as its first operand. 21468The value to cast must be a vector of :ref:`floating-point <t_floating>` type. 21469The return type is the type to cast the value to. The return type must be 21470vector of :ref:`integer <t_integer>` type. The second operand is the vector 21471mask. The return type, the value to cast, and the vector mask have the same 21472number of elements. The third operand is the explicit vector length of the 21473operation. 21474 21475Semantics: 21476"""""""""" 21477 21478The '``llvm.vp.fptoui``' intrinsic converts its :ref:`floating-point 21479<t_floating>` operand into the nearest (rounding towards zero) unsigned integer 21480value where the lane position is below the explicit vector length and the 21481vector mask is true. Masked-off lanes are ``poison``. On enabled lanes where 21482conversion takes place and the value cannot fit in the return type, the result 21483on that lane is a :ref:`poison value <poisonvalues>`. 21484 21485Examples: 21486""""""""" 21487 21488.. code-block:: llvm 21489 21490 %r = call <4 x i32> @llvm.vp.fptoui.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 21491 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21492 21493 %t = fptoui <4 x float> %a to <4 x i32> 21494 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 21495 21496 21497.. _int_vp_fptosi: 21498 21499'``llvm.vp.fptosi.*``' Intrinsics 21500^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21501 21502Syntax: 21503""""""" 21504This is an overloaded intrinsic. 21505 21506:: 21507 21508 declare <16 x i32> @llvm.vp.fptosi.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 21509 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>) 21510 declare <256 x i64> @llvm.vp.fptosi.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 21511 21512Overview: 21513""""""""" 21514 21515The '``llvm.vp.fptosi``' intrinsic converts the :ref:`floating-point 21516<t_floating>` operand to the signed integer return type. 21517The operation has a mask and an explicit vector length parameter. 21518 21519 21520Arguments: 21521"""""""""" 21522 21523The '``llvm.vp.fptosi``' intrinsic takes a value to cast as its first operand. 21524The value to cast must be a vector of :ref:`floating-point <t_floating>` type. 21525The return type is the type to cast the value to. The return type must be 21526vector of :ref:`integer <t_integer>` type. The second operand is the vector 21527mask. The return type, the value to cast, and the vector mask have the same 21528number of elements. The third operand is the explicit vector length of the 21529operation. 21530 21531Semantics: 21532"""""""""" 21533 21534The '``llvm.vp.fptosi``' intrinsic converts its :ref:`floating-point 21535<t_floating>` operand into the nearest (rounding towards zero) signed integer 21536value where the lane position is below the explicit vector length and the 21537vector mask is true. Masked-off lanes are ``poison``. On enabled lanes where 21538conversion takes place and the value cannot fit in the return type, the result 21539on that lane is a :ref:`poison value <poisonvalues>`. 21540 21541Examples: 21542""""""""" 21543 21544.. code-block:: llvm 21545 21546 %r = call <4 x i32> @llvm.vp.fptosi.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 21547 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21548 21549 %t = fptosi <4 x float> %a to <4 x i32> 21550 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 21551 21552 21553.. _int_vp_uitofp: 21554 21555'``llvm.vp.uitofp.*``' Intrinsics 21556^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21557 21558Syntax: 21559""""""" 21560This is an overloaded intrinsic. 21561 21562:: 21563 21564 declare <16 x float> @llvm.vp.uitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 21565 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>) 21566 declare <256 x double> @llvm.vp.uitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>) 21567 21568Overview: 21569""""""""" 21570 21571The '``llvm.vp.uitofp``' intrinsic converts its unsigned integer operand to the 21572:ref:`floating-point <t_floating>` return type. The operation has a mask and 21573an explicit vector length parameter. 21574 21575 21576Arguments: 21577"""""""""" 21578 21579The '``llvm.vp.uitofp``' intrinsic takes a value to cast as its first operand. 21580The value to cast must be vector of :ref:`integer <t_integer>` type. The 21581return type is the type to cast the value to. The return type must be a vector 21582of :ref:`floating-point <t_floating>` type. The second operand is the vector 21583mask. The return type, the value to cast, and the vector mask have the same 21584number of elements. The third operand is the explicit vector length of the 21585operation. 21586 21587Semantics: 21588"""""""""" 21589 21590The '``llvm.vp.uitofp``' intrinsic interprets its first operand as an unsigned 21591integer quantity and converts it to the corresponding floating-point value. If 21592the value cannot be exactly represented, it is rounded using the default 21593rounding mode. The conversion is performed on lane positions below the 21594explicit vector length and where the vector mask is true. Masked-off lanes are 21595``poison``. 21596 21597Examples: 21598""""""""" 21599 21600.. code-block:: llvm 21601 21602 %r = call <4 x float> @llvm.vp.uitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 21603 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21604 21605 %t = uitofp <4 x i32> %a to <4 x float> 21606 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 21607 21608 21609.. _int_vp_sitofp: 21610 21611'``llvm.vp.sitofp.*``' Intrinsics 21612^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21613 21614Syntax: 21615""""""" 21616This is an overloaded intrinsic. 21617 21618:: 21619 21620 declare <16 x float> @llvm.vp.sitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 21621 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>) 21622 declare <256 x double> @llvm.vp.sitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>) 21623 21624Overview: 21625""""""""" 21626 21627The '``llvm.vp.sitofp``' intrinsic converts its signed integer operand to the 21628:ref:`floating-point <t_floating>` return type. The operation has a mask and 21629an explicit vector length parameter. 21630 21631 21632Arguments: 21633"""""""""" 21634 21635The '``llvm.vp.sitofp``' intrinsic takes a value to cast as its first operand. 21636The value to cast must be vector of :ref:`integer <t_integer>` type. The 21637return type is the type to cast the value to. The return type must be a vector 21638of :ref:`floating-point <t_floating>` type. The second operand is the vector 21639mask. The return type, the value to cast, and the vector mask have the same 21640number of elements. The third operand is the explicit vector length of the 21641operation. 21642 21643Semantics: 21644"""""""""" 21645 21646The '``llvm.vp.sitofp``' intrinsic interprets its first operand as a signed 21647integer quantity and converts it to the corresponding floating-point value. If 21648the value cannot be exactly represented, it is rounded using the default 21649rounding mode. The conversion is performed on lane positions below the 21650explicit vector length and where the vector mask is true. Masked-off lanes are 21651``poison``. 21652 21653Examples: 21654""""""""" 21655 21656.. code-block:: llvm 21657 21658 %r = call <4 x float> @llvm.vp.sitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 21659 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21660 21661 %t = sitofp <4 x i32> %a to <4 x float> 21662 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 21663 21664 21665.. _int_vp_ptrtoint: 21666 21667'``llvm.vp.ptrtoint.*``' Intrinsics 21668^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21669 21670Syntax: 21671""""""" 21672This is an overloaded intrinsic. 21673 21674:: 21675 21676 declare <16 x i8> @llvm.vp.ptrtoint.v16i8.v16p0(<16 x ptr> <op>, <16 x i1> <mask>, i32 <vector_length>) 21677 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>) 21678 declare <256 x i64> @llvm.vp.ptrtoint.v16i64.v16p0(<256 x ptr> <op>, <256 x i1> <mask>, i32 <vector_length>) 21679 21680Overview: 21681""""""""" 21682 21683The '``llvm.vp.ptrtoint``' intrinsic converts its pointer to the integer return 21684type. The operation has a mask and an explicit vector length parameter. 21685 21686 21687Arguments: 21688"""""""""" 21689 21690The '``llvm.vp.ptrtoint``' intrinsic takes a value to cast as its first operand 21691, which must be a vector of pointers, and a type to cast it to return type, 21692which must be a vector of :ref:`integer <t_integer>` type. 21693The second operand is the vector mask. The return type, the value to cast, and 21694the vector mask have the same number of elements. 21695The third operand is the explicit vector length of the operation. 21696 21697Semantics: 21698"""""""""" 21699 21700The '``llvm.vp.ptrtoint``' intrinsic converts value to return type by 21701interpreting the pointer value as an integer and either truncating or zero 21702extending that value to the size of the integer type. 21703If ``value`` is smaller than return type, then a zero extension is done. If 21704``value`` is larger than return type, then a truncation is done. If they are 21705the same size, then nothing is done (*no-op cast*) other than a type 21706change. 21707The conversion is performed on lane positions below the explicit vector length 21708and where the vector mask is true. Masked-off lanes are ``poison``. 21709 21710Examples: 21711""""""""" 21712 21713.. code-block:: llvm 21714 21715 %r = call <4 x i8> @llvm.vp.ptrtoint.v4i8.v4p0i32(<4 x ptr> %a, <4 x i1> %mask, i32 %evl) 21716 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21717 21718 %t = ptrtoint <4 x ptr> %a to <4 x i8> 21719 %also.r = select <4 x i1> %mask, <4 x i8> %t, <4 x i8> poison 21720 21721 21722.. _int_vp_inttoptr: 21723 21724'``llvm.vp.inttoptr.*``' Intrinsics 21725^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21726 21727Syntax: 21728""""""" 21729This is an overloaded intrinsic. 21730 21731:: 21732 21733 declare <16 x ptr> @llvm.vp.inttoptr.v16p0.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 21734 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>) 21735 declare <256 x ptr> @llvm.vp.inttoptr.v256p0.v256i32 (<256 x i32> <op>, <256 x i1> <mask>, i32 <vector_length>) 21736 21737Overview: 21738""""""""" 21739 21740The '``llvm.vp.inttoptr``' intrinsic converts its integer value to the point 21741return type. The operation has a mask and an explicit vector length parameter. 21742 21743 21744Arguments: 21745"""""""""" 21746 21747The '``llvm.vp.inttoptr``' intrinsic takes a value to cast as its first operand 21748, which must be a vector of :ref:`integer <t_integer>` type, and a type to cast 21749it to return type, which must be a vector of pointers type. 21750The second operand is the vector mask. The return type, the value to cast, and 21751the vector mask have the same number of elements. 21752The third operand is the explicit vector length of the operation. 21753 21754Semantics: 21755"""""""""" 21756 21757The '``llvm.vp.inttoptr``' intrinsic converts ``value`` to return type by 21758applying either a zero extension or a truncation depending on the size of the 21759integer ``value``. If ``value`` is larger than the size of a pointer, then a 21760truncation is done. If ``value`` is smaller than the size of a pointer, then a 21761zero extension is done. If they are the same size, nothing is done (*no-op cast*). 21762The conversion is performed on lane positions below the explicit vector length 21763and where the vector mask is true. Masked-off lanes are ``poison``. 21764 21765Examples: 21766""""""""" 21767 21768.. code-block:: llvm 21769 21770 %r = call <4 x ptr> @llvm.vp.inttoptr.v4p0i32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 21771 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21772 21773 %t = inttoptr <4 x i32> %a to <4 x ptr> 21774 %also.r = select <4 x i1> %mask, <4 x ptr> %t, <4 x ptr> poison 21775 21776 21777.. _int_vp_fcmp: 21778 21779'``llvm.vp.fcmp.*``' Intrinsics 21780^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21781 21782Syntax: 21783""""""" 21784This is an overloaded intrinsic. 21785 21786:: 21787 21788 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>) 21789 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>) 21790 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>) 21791 21792Overview: 21793""""""""" 21794 21795The '``llvm.vp.fcmp``' intrinsic returns a vector of boolean values based on 21796the comparison of its operands. The operation has a mask and an explicit vector 21797length parameter. 21798 21799 21800Arguments: 21801"""""""""" 21802 21803The '``llvm.vp.fcmp``' intrinsic takes the two values to compare as its first 21804and second operands. These two values must be vectors of :ref:`floating-point 21805<t_floating>` types. 21806The return type is the result of the comparison. The return type must be a 21807vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask. 21808The return type, the values to compare, and the vector mask have the same 21809number of elements. The third operand is the condition code indicating the kind 21810of comparison to perform. It must be a metadata string with :ref:`one of the 21811supported floating-point condition code values <fcmp_md_cc>`. The fifth operand 21812is the explicit vector length of the operation. 21813 21814Semantics: 21815"""""""""" 21816 21817The '``llvm.vp.fcmp``' compares its first two operands according to the 21818condition code given as the third operand. The operands are compared element by 21819element on each enabled lane, where the the semantics of the comparison are 21820defined :ref:`according to the condition code <fcmp_md_cc_sem>`. Masked-off 21821lanes are ``poison``. 21822 21823Examples: 21824""""""""" 21825 21826.. code-block:: llvm 21827 21828 %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) 21829 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21830 21831 %t = fcmp oeq <4 x float> %a, %b 21832 %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> poison 21833 21834 21835.. _int_vp_icmp: 21836 21837'``llvm.vp.icmp.*``' Intrinsics 21838^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21839 21840Syntax: 21841""""""" 21842This is an overloaded intrinsic. 21843 21844:: 21845 21846 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>) 21847 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>) 21848 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>) 21849 21850Overview: 21851""""""""" 21852 21853The '``llvm.vp.icmp``' intrinsic returns a vector of boolean values based on 21854the comparison of its operands. The operation has a mask and an explicit vector 21855length parameter. 21856 21857 21858Arguments: 21859"""""""""" 21860 21861The '``llvm.vp.icmp``' intrinsic takes the two values to compare as its first 21862and second operands. These two values must be vectors of :ref:`integer 21863<t_integer>` types. 21864The return type is the result of the comparison. The return type must be a 21865vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask. 21866The return type, the values to compare, and the vector mask have the same 21867number of elements. The third operand is the condition code indicating the kind 21868of comparison to perform. It must be a metadata string with :ref:`one of the 21869supported integer condition code values <icmp_md_cc>`. The fifth operand is the 21870explicit vector length of the operation. 21871 21872Semantics: 21873"""""""""" 21874 21875The '``llvm.vp.icmp``' compares its first two operands according to the 21876condition code given as the third operand. The operands are compared element by 21877element on each enabled lane, where the the semantics of the comparison are 21878defined :ref:`according to the condition code <icmp_md_cc_sem>`. Masked-off 21879lanes are ``poison``. 21880 21881Examples: 21882""""""""" 21883 21884.. code-block:: llvm 21885 21886 %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) 21887 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21888 21889 %t = icmp ne <4 x i32> %a, %b 21890 %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> poison 21891 21892.. _int_vp_ceil: 21893 21894'``llvm.vp.ceil.*``' Intrinsics 21895^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21896 21897Syntax: 21898""""""" 21899This is an overloaded intrinsic. 21900 21901:: 21902 21903 declare <16 x float> @llvm.vp.ceil.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 21904 declare <vscale x 4 x float> @llvm.vp.ceil.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 21905 declare <256 x double> @llvm.vp.ceil.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 21906 21907Overview: 21908""""""""" 21909 21910Predicated floating-point ceiling of a vector of floating-point values. 21911 21912 21913Arguments: 21914"""""""""" 21915 21916The first operand and the result have the same vector of floating-point type. 21917The second operand is the vector mask and has the same number of elements as the 21918result vector type. The third operand is the explicit vector length of the 21919operation. 21920 21921Semantics: 21922"""""""""" 21923 21924The '``llvm.vp.ceil``' intrinsic performs floating-point ceiling 21925(:ref:`ceil <int_ceil>`) of the first vector operand on each enabled lane. The 21926result on disabled lanes is a :ref:`poison value <poisonvalues>`. 21927 21928Examples: 21929""""""""" 21930 21931.. code-block:: llvm 21932 21933 %r = call <4 x float> @llvm.vp.ceil.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 21934 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21935 21936 %t = call <4 x float> @llvm.ceil.v4f32(<4 x float> %a) 21937 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 21938 21939.. _int_vp_floor: 21940 21941'``llvm.vp.floor.*``' Intrinsics 21942^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21943 21944Syntax: 21945""""""" 21946This is an overloaded intrinsic. 21947 21948:: 21949 21950 declare <16 x float> @llvm.vp.floor.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 21951 declare <vscale x 4 x float> @llvm.vp.floor.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 21952 declare <256 x double> @llvm.vp.floor.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 21953 21954Overview: 21955""""""""" 21956 21957Predicated floating-point floor of a vector of floating-point values. 21958 21959 21960Arguments: 21961"""""""""" 21962 21963The first operand and the result have the same vector of floating-point type. 21964The second operand is the vector mask and has the same number of elements as the 21965result vector type. The third operand is the explicit vector length of the 21966operation. 21967 21968Semantics: 21969"""""""""" 21970 21971The '``llvm.vp.floor``' intrinsic performs floating-point floor 21972(:ref:`floor <int_floor>`) of the first vector operand on each enabled lane. 21973The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 21974 21975Examples: 21976""""""""" 21977 21978.. code-block:: llvm 21979 21980 %r = call <4 x float> @llvm.vp.floor.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 21981 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 21982 21983 %t = call <4 x float> @llvm.floor.v4f32(<4 x float> %a) 21984 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 21985 21986.. _int_vp_rint: 21987 21988'``llvm.vp.rint.*``' Intrinsics 21989^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21990 21991Syntax: 21992""""""" 21993This is an overloaded intrinsic. 21994 21995:: 21996 21997 declare <16 x float> @llvm.vp.rint.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 21998 declare <vscale x 4 x float> @llvm.vp.rint.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 21999 declare <256 x double> @llvm.vp.rint.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 22000 22001Overview: 22002""""""""" 22003 22004Predicated floating-point rint of a vector of floating-point values. 22005 22006 22007Arguments: 22008"""""""""" 22009 22010The first operand and the result have the same vector of floating-point type. 22011The second operand is the vector mask and has the same number of elements as the 22012result vector type. The third operand is the explicit vector length of the 22013operation. 22014 22015Semantics: 22016"""""""""" 22017 22018The '``llvm.vp.rint``' intrinsic performs floating-point rint 22019(:ref:`rint <int_rint>`) of the first vector operand on each enabled lane. 22020The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 22021 22022Examples: 22023""""""""" 22024 22025.. code-block:: llvm 22026 22027 %r = call <4 x float> @llvm.vp.rint.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 22028 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 22029 22030 %t = call <4 x float> @llvm.rint.v4f32(<4 x float> %a) 22031 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 22032 22033.. _int_vp_nearbyint: 22034 22035'``llvm.vp.nearbyint.*``' Intrinsics 22036^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22037 22038Syntax: 22039""""""" 22040This is an overloaded intrinsic. 22041 22042:: 22043 22044 declare <16 x float> @llvm.vp.nearbyint.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 22045 declare <vscale x 4 x float> @llvm.vp.nearbyint.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 22046 declare <256 x double> @llvm.vp.nearbyint.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 22047 22048Overview: 22049""""""""" 22050 22051Predicated floating-point nearbyint of a vector of floating-point values. 22052 22053 22054Arguments: 22055"""""""""" 22056 22057The first operand and the result have the same vector of floating-point type. 22058The second operand is the vector mask and has the same number of elements as the 22059result vector type. The third operand is the explicit vector length of the 22060operation. 22061 22062Semantics: 22063"""""""""" 22064 22065The '``llvm.vp.nearbyint``' intrinsic performs floating-point nearbyint 22066(:ref:`nearbyint <int_nearbyint>`) of the first vector operand on each enabled lane. 22067The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 22068 22069Examples: 22070""""""""" 22071 22072.. code-block:: llvm 22073 22074 %r = call <4 x float> @llvm.vp.nearbyint.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 22075 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 22076 22077 %t = call <4 x float> @llvm.nearbyint.v4f32(<4 x float> %a) 22078 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 22079 22080.. _int_vp_round: 22081 22082'``llvm.vp.round.*``' Intrinsics 22083^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22084 22085Syntax: 22086""""""" 22087This is an overloaded intrinsic. 22088 22089:: 22090 22091 declare <16 x float> @llvm.vp.round.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 22092 declare <vscale x 4 x float> @llvm.vp.round.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 22093 declare <256 x double> @llvm.vp.round.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 22094 22095Overview: 22096""""""""" 22097 22098Predicated floating-point round of a vector of floating-point values. 22099 22100 22101Arguments: 22102"""""""""" 22103 22104The first operand and the result have the same vector of floating-point type. 22105The second operand is the vector mask and has the same number of elements as the 22106result vector type. The third operand is the explicit vector length of the 22107operation. 22108 22109Semantics: 22110"""""""""" 22111 22112The '``llvm.vp.round``' intrinsic performs floating-point round 22113(:ref:`round <int_round>`) of the first vector operand on each enabled lane. 22114The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 22115 22116Examples: 22117""""""""" 22118 22119.. code-block:: llvm 22120 22121 %r = call <4 x float> @llvm.vp.round.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 22122 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 22123 22124 %t = call <4 x float> @llvm.round.v4f32(<4 x float> %a) 22125 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 22126 22127.. _int_vp_roundeven: 22128 22129'``llvm.vp.roundeven.*``' Intrinsics 22130^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22131 22132Syntax: 22133""""""" 22134This is an overloaded intrinsic. 22135 22136:: 22137 22138 declare <16 x float> @llvm.vp.roundeven.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 22139 declare <vscale x 4 x float> @llvm.vp.roundeven.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 22140 declare <256 x double> @llvm.vp.roundeven.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 22141 22142Overview: 22143""""""""" 22144 22145Predicated floating-point roundeven of a vector of floating-point values. 22146 22147 22148Arguments: 22149"""""""""" 22150 22151The first operand and the result have the same vector of floating-point type. 22152The second operand is the vector mask and has the same number of elements as the 22153result vector type. The third operand is the explicit vector length of the 22154operation. 22155 22156Semantics: 22157"""""""""" 22158 22159The '``llvm.vp.roundeven``' intrinsic performs floating-point roundeven 22160(:ref:`roundeven <int_roundeven>`) of the first vector operand on each enabled 22161lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 22162 22163Examples: 22164""""""""" 22165 22166.. code-block:: llvm 22167 22168 %r = call <4 x float> @llvm.vp.roundeven.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 22169 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 22170 22171 %t = call <4 x float> @llvm.roundeven.v4f32(<4 x float> %a) 22172 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 22173 22174.. _int_vp_roundtozero: 22175 22176'``llvm.vp.roundtozero.*``' Intrinsics 22177^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22178 22179Syntax: 22180""""""" 22181This is an overloaded intrinsic. 22182 22183:: 22184 22185 declare <16 x float> @llvm.vp.roundtozero.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 22186 declare <vscale x 4 x float> @llvm.vp.roundtozero.nxv4f32 (<vscale x 4 x float> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 22187 declare <256 x double> @llvm.vp.roundtozero.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 22188 22189Overview: 22190""""""""" 22191 22192Predicated floating-point round-to-zero of a vector of floating-point values. 22193 22194 22195Arguments: 22196"""""""""" 22197 22198The first operand and the result have the same vector of floating-point type. 22199The second operand is the vector mask and has the same number of elements as the 22200result vector type. The third operand is the explicit vector length of the 22201operation. 22202 22203Semantics: 22204"""""""""" 22205 22206The '``llvm.vp.roundtozero``' intrinsic performs floating-point roundeven 22207(:ref:`llvm.trunc <int_llvm_trunc>`) of the first vector operand on each enabled lane. The 22208result on disabled lanes is a :ref:`poison value <poisonvalues>`. 22209 22210Examples: 22211""""""""" 22212 22213.. code-block:: llvm 22214 22215 %r = call <4 x float> @llvm.vp.roundtozero.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 22216 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 22217 22218 %t = call <4 x float> @llvm.trunc.v4f32(<4 x float> %a) 22219 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> poison 22220 22221.. _int_vp_bitreverse: 22222 22223'``llvm.vp.bitreverse.*``' Intrinsics 22224^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22225 22226Syntax: 22227""""""" 22228This is an overloaded intrinsic. 22229 22230:: 22231 22232 declare <16 x i32> @llvm.vp.bitreverse.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 22233 declare <vscale x 4 x i32> @llvm.vp.bitreverse.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 22234 declare <256 x i64> @llvm.vp.bitreverse.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>) 22235 22236Overview: 22237""""""""" 22238 22239Predicated bitreverse of a vector of integers. 22240 22241 22242Arguments: 22243"""""""""" 22244 22245The first operand and the result have the same vector of integer type. The 22246second operand is the vector mask and has the same number of elements as the 22247result vector type. The third operand is the explicit vector length of the 22248operation. 22249 22250Semantics: 22251"""""""""" 22252 22253The '``llvm.vp.bitreverse``' intrinsic performs bitreverse (:ref:`bitreverse <int_bitreverse>`) of the first operand on each 22254enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 22255 22256Examples: 22257""""""""" 22258 22259.. code-block:: llvm 22260 22261 %r = call <4 x i32> @llvm.vp.bitreverse.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 22262 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 22263 22264 %t = call <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> %a) 22265 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 22266 22267 22268.. _int_vp_bswap: 22269 22270'``llvm.vp.bswap.*``' Intrinsics 22271^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22272 22273Syntax: 22274""""""" 22275This is an overloaded intrinsic. 22276 22277:: 22278 22279 declare <16 x i32> @llvm.vp.bswap.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 22280 declare <vscale x 4 x i32> @llvm.vp.bswap.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 22281 declare <256 x i64> @llvm.vp.bswap.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>) 22282 22283Overview: 22284""""""""" 22285 22286Predicated bswap of a vector of integers. 22287 22288 22289Arguments: 22290"""""""""" 22291 22292The first operand and the result have the same vector of integer type. The 22293second operand is the vector mask and has the same number of elements as the 22294result vector type. The third operand is the explicit vector length of the 22295operation. 22296 22297Semantics: 22298"""""""""" 22299 22300The '``llvm.vp.bswap``' intrinsic performs bswap (:ref:`bswap <int_bswap>`) of the first operand on each 22301enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 22302 22303Examples: 22304""""""""" 22305 22306.. code-block:: llvm 22307 22308 %r = call <4 x i32> @llvm.vp.bswap.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 22309 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 22310 22311 %t = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a) 22312 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 22313 22314 22315.. _int_vp_ctpop: 22316 22317'``llvm.vp.ctpop.*``' Intrinsics 22318^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22319 22320Syntax: 22321""""""" 22322This is an overloaded intrinsic. 22323 22324:: 22325 22326 declare <16 x i32> @llvm.vp.ctpop.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 22327 declare <vscale x 4 x i32> @llvm.vp.ctpop.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 22328 declare <256 x i64> @llvm.vp.ctpop.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>) 22329 22330Overview: 22331""""""""" 22332 22333Predicated ctpop of a vector of integers. 22334 22335 22336Arguments: 22337"""""""""" 22338 22339The first operand and the result have the same vector of integer type. The 22340second operand is the vector mask and has the same number of elements as the 22341result vector type. The third operand is the explicit vector length of the 22342operation. 22343 22344Semantics: 22345"""""""""" 22346 22347The '``llvm.vp.ctpop``' intrinsic performs ctpop (:ref:`ctpop <int_ctpop>`) of the first operand on each 22348enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 22349 22350Examples: 22351""""""""" 22352 22353.. code-block:: llvm 22354 22355 %r = call <4 x i32> @llvm.vp.ctpop.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 22356 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 22357 22358 %t = call <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %a) 22359 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 22360 22361 22362.. _int_vp_ctlz: 22363 22364'``llvm.vp.ctlz.*``' Intrinsics 22365^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22366 22367Syntax: 22368""""""" 22369This is an overloaded intrinsic. 22370 22371:: 22372 22373 declare <16 x i32> @llvm.vp.ctlz.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>) 22374 declare <vscale x 4 x i32> @llvm.vp.ctlz.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>) 22375 declare <256 x i64> @llvm.vp.ctlz.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>) 22376 22377Overview: 22378""""""""" 22379 22380Predicated ctlz of a vector of integers. 22381 22382 22383Arguments: 22384"""""""""" 22385 22386The first operand and the result have the same vector of integer type. The 22387second operand is the vector mask and has the same number of elements as the 22388result vector type. The third operand is the explicit vector length of the 22389operation. 22390 22391Semantics: 22392"""""""""" 22393 22394The '``llvm.vp.ctlz``' intrinsic performs ctlz (:ref:`ctlz <int_ctlz>`) of the first operand on each 22395enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 22396 22397Examples: 22398""""""""" 22399 22400.. code-block:: llvm 22401 22402 %r = call <4 x i32> @llvm.vp.ctlz.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl, i1 false) 22403 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 22404 22405 %t = call <4 x i32> @llvm.ctlz.v4i32(<4 x i32> %a, i1 false) 22406 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 22407 22408 22409.. _int_vp_cttz: 22410 22411'``llvm.vp.cttz.*``' Intrinsics 22412^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22413 22414Syntax: 22415""""""" 22416This is an overloaded intrinsic. 22417 22418:: 22419 22420 declare <16 x i32> @llvm.vp.cttz.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>) 22421 declare <vscale x 4 x i32> @llvm.vp.cttz.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>) 22422 declare <256 x i64> @llvm.vp.cttz.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>, i1 <is_zero_poison>) 22423 22424Overview: 22425""""""""" 22426 22427Predicated cttz of a vector of integers. 22428 22429 22430Arguments: 22431"""""""""" 22432 22433The first operand and the result have the same vector of integer type. The 22434second operand is the vector mask and has the same number of elements as the 22435result vector type. The third operand is the explicit vector length of the 22436operation. 22437 22438Semantics: 22439"""""""""" 22440 22441The '``llvm.vp.cttz``' intrinsic performs cttz (:ref:`cttz <int_cttz>`) of the first operand on each 22442enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 22443 22444Examples: 22445""""""""" 22446 22447.. code-block:: llvm 22448 22449 %r = call <4 x i32> @llvm.vp.cttz.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl, i1 false) 22450 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 22451 22452 %t = call <4 x i32> @llvm.cttz.v4i32(<4 x i32> %a, i1 false) 22453 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 22454 22455 22456.. _int_vp_fshl: 22457 22458'``llvm.vp.fshl.*``' Intrinsics 22459^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22460 22461Syntax: 22462""""""" 22463This is an overloaded intrinsic. 22464 22465:: 22466 22467 declare <16 x i32> @llvm.vp.fshl.v16i32 (<16 x i32> <left_op>, <16 x i32> <middle_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 22468 declare <vscale x 4 x i32> @llvm.vp.fshl.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <middle_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 22469 declare <256 x i64> @llvm.vp.fshl.v256i64 (<256 x i64> <left_op>, <256 x i64> <middle_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 22470 22471Overview: 22472""""""""" 22473 22474Predicated fshl of three vectors of integers. 22475 22476 22477Arguments: 22478"""""""""" 22479 22480The first three operand and the result have the same vector of integer type. The 22481fourth operand is the vector mask and has the same number of elements as the 22482result vector type. The fifth operand is the explicit vector length of the 22483operation. 22484 22485Semantics: 22486"""""""""" 22487 22488The '``llvm.vp.fshl``' intrinsic performs fshl (:ref:`fshl <int_fshl>`) of the first, second, and third 22489vector operand on each enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 22490 22491 22492Examples: 22493""""""""" 22494 22495.. code-block:: llvm 22496 22497 %r = call <4 x i32> @llvm.vp.fshl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c, <4 x i1> %mask, i32 %evl) 22498 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 22499 22500 %t = call <4 x i32> @llvm.fshl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) 22501 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 22502 22503 22504'``llvm.vp.fshr.*``' Intrinsics 22505^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22506 22507Syntax: 22508""""""" 22509This is an overloaded intrinsic. 22510 22511:: 22512 22513 declare <16 x i32> @llvm.vp.fshr.v16i32 (<16 x i32> <left_op>, <16 x i32> <middle_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 22514 declare <vscale x 4 x i32> @llvm.vp.fshr.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <middle_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 22515 declare <256 x i64> @llvm.vp.fshr.v256i64 (<256 x i64> <left_op>, <256 x i64> <middle_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 22516 22517Overview: 22518""""""""" 22519 22520Predicated fshr of three vectors of integers. 22521 22522 22523Arguments: 22524"""""""""" 22525 22526The first three operand and the result have the same vector of integer type. The 22527fourth operand is the vector mask and has the same number of elements as the 22528result vector type. The fifth operand is the explicit vector length of the 22529operation. 22530 22531Semantics: 22532"""""""""" 22533 22534The '``llvm.vp.fshr``' intrinsic performs fshr (:ref:`fshr <int_fshr>`) of the first, second, and third 22535vector operand on each enabled lane. The result on disabled lanes is a :ref:`poison value <poisonvalues>`. 22536 22537 22538Examples: 22539""""""""" 22540 22541.. code-block:: llvm 22542 22543 %r = call <4 x i32> @llvm.vp.fshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c, <4 x i1> %mask, i32 %evl) 22544 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 22545 22546 %t = call <4 x i32> @llvm.fshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) 22547 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> poison 22548 22549 22550.. _int_mload_mstore: 22551 22552Masked Vector Load and Store Intrinsics 22553--------------------------------------- 22554 22555LLVM 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. 22556 22557.. _int_mload: 22558 22559'``llvm.masked.load.*``' Intrinsics 22560^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22561 22562Syntax: 22563""""""" 22564This is an overloaded intrinsic. The loaded data is a vector of any integer, floating-point or pointer data type. 22565 22566:: 22567 22568 declare <16 x float> @llvm.masked.load.v16f32.p0(ptr <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>) 22569 declare <2 x double> @llvm.masked.load.v2f64.p0(ptr <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>) 22570 ;; The data is a vector of pointers 22571 declare <8 x ptr> @llvm.masked.load.v8p0.p0(ptr <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x ptr> <passthru>) 22572 22573Overview: 22574""""""""" 22575 22576Reads 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. 22577 22578 22579Arguments: 22580"""""""""" 22581 22582The 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. 22583 22584Semantics: 22585"""""""""" 22586 22587The '``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. 22588The 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. 22589 22590 22591:: 22592 22593 %res = call <16 x float> @llvm.masked.load.v16f32.p0(ptr %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru) 22594 22595 ;; The result of the two following instructions is identical aside from potential memory access exception 22596 %loadlal = load <16 x float>, ptr %ptr, align 4 22597 %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru 22598 22599.. _int_mstore: 22600 22601'``llvm.masked.store.*``' Intrinsics 22602^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22603 22604Syntax: 22605""""""" 22606This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type. 22607 22608:: 22609 22610 declare void @llvm.masked.store.v8i32.p0 (<8 x i32> <value>, ptr <ptr>, i32 <alignment>, <8 x i1> <mask>) 22611 declare void @llvm.masked.store.v16f32.p0(<16 x float> <value>, ptr <ptr>, i32 <alignment>, <16 x i1> <mask>) 22612 ;; The data is a vector of pointers 22613 declare void @llvm.masked.store.v8p0.p0 (<8 x ptr> <value>, ptr <ptr>, i32 <alignment>, <8 x i1> <mask>) 22614 22615Overview: 22616""""""""" 22617 22618Writes 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. 22619 22620Arguments: 22621"""""""""" 22622 22623The 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. 22624 22625 22626Semantics: 22627"""""""""" 22628 22629The '``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. 22630The 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. 22631 22632:: 22633 22634 call void @llvm.masked.store.v16f32.p0(<16 x float> %value, ptr %ptr, i32 4, <16 x i1> %mask) 22635 22636 ;; The result of the following instructions is identical aside from potential data races and memory access exceptions 22637 %oldval = load <16 x float>, ptr %ptr, align 4 22638 %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval 22639 store <16 x float> %res, ptr %ptr, align 4 22640 22641 22642Masked Vector Gather and Scatter Intrinsics 22643------------------------------------------- 22644 22645LLVM 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. 22646 22647.. _int_mgather: 22648 22649'``llvm.masked.gather.*``' Intrinsics 22650^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22651 22652Syntax: 22653""""""" 22654This 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. 22655 22656:: 22657 22658 declare <16 x float> @llvm.masked.gather.v16f32.v16p0(<16 x ptr> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>) 22659 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>) 22660 declare <8 x ptr> @llvm.masked.gather.v8p0.v8p0(<8 x ptr> <ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x ptr> <passthru>) 22661 22662Overview: 22663""""""""" 22664 22665Reads 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. 22666 22667 22668Arguments: 22669"""""""""" 22670 22671The 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. 22672 22673Semantics: 22674"""""""""" 22675 22676The '``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. 22677The 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. 22678 22679 22680:: 22681 22682 %res = call <4 x double> @llvm.masked.gather.v4f64.v4p0(<4 x ptr> %ptrs, i32 8, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x double> poison) 22683 22684 ;; The gather with all-true mask is equivalent to the following instruction sequence 22685 %ptr0 = extractelement <4 x ptr> %ptrs, i32 0 22686 %ptr1 = extractelement <4 x ptr> %ptrs, i32 1 22687 %ptr2 = extractelement <4 x ptr> %ptrs, i32 2 22688 %ptr3 = extractelement <4 x ptr> %ptrs, i32 3 22689 22690 %val0 = load double, ptr %ptr0, align 8 22691 %val1 = load double, ptr %ptr1, align 8 22692 %val2 = load double, ptr %ptr2, align 8 22693 %val3 = load double, ptr %ptr3, align 8 22694 22695 %vec0 = insertelement <4 x double> poison, %val0, 0 22696 %vec01 = insertelement <4 x double> %vec0, %val1, 1 22697 %vec012 = insertelement <4 x double> %vec01, %val2, 2 22698 %vec0123 = insertelement <4 x double> %vec012, %val3, 3 22699 22700.. _int_mscatter: 22701 22702'``llvm.masked.scatter.*``' Intrinsics 22703^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22704 22705Syntax: 22706""""""" 22707This 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. 22708 22709:: 22710 22711 declare void @llvm.masked.scatter.v8i32.v8p0 (<8 x i32> <value>, <8 x ptr> <ptrs>, i32 <alignment>, <8 x i1> <mask>) 22712 declare void @llvm.masked.scatter.v16f32.v16p1(<16 x float> <value>, <16 x ptr addrspace(1)> <ptrs>, i32 <alignment>, <16 x i1> <mask>) 22713 declare void @llvm.masked.scatter.v4p0.v4p0 (<4 x ptr> <value>, <4 x ptr> <ptrs>, i32 <alignment>, <4 x i1> <mask>) 22714 22715Overview: 22716""""""""" 22717 22718Writes 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. 22719 22720Arguments: 22721"""""""""" 22722 22723The 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. 22724 22725Semantics: 22726"""""""""" 22727 22728The '``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. 22729 22730:: 22731 22732 ;; This instruction unconditionally stores data vector in multiple addresses 22733 call @llvm.masked.scatter.v8i32.v8p0(<8 x i32> %value, <8 x ptr> %ptrs, i32 4, <8 x i1> <true, true, .. true>) 22734 22735 ;; It is equivalent to a list of scalar stores 22736 %val0 = extractelement <8 x i32> %value, i32 0 22737 %val1 = extractelement <8 x i32> %value, i32 1 22738 .. 22739 %val7 = extractelement <8 x i32> %value, i32 7 22740 %ptr0 = extractelement <8 x ptr> %ptrs, i32 0 22741 %ptr1 = extractelement <8 x ptr> %ptrs, i32 1 22742 .. 22743 %ptr7 = extractelement <8 x ptr> %ptrs, i32 7 22744 ;; Note: the order of the following stores is important when they overlap: 22745 store i32 %val0, ptr %ptr0, align 4 22746 store i32 %val1, ptr %ptr1, align 4 22747 .. 22748 store i32 %val7, ptr %ptr7, align 4 22749 22750 22751Masked Vector Expanding Load and Compressing Store Intrinsics 22752------------------------------------------------------------- 22753 22754LLVM 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>`. 22755 22756.. _int_expandload: 22757 22758'``llvm.masked.expandload.*``' Intrinsics 22759^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22760 22761Syntax: 22762""""""" 22763This 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. 22764 22765:: 22766 22767 declare <16 x float> @llvm.masked.expandload.v16f32 (ptr <ptr>, <16 x i1> <mask>, <16 x float> <passthru>) 22768 declare <2 x i64> @llvm.masked.expandload.v2i64 (ptr <ptr>, <2 x i1> <mask>, <2 x i64> <passthru>) 22769 22770Overview: 22771""""""""" 22772 22773Reads 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. 22774 22775 22776Arguments: 22777"""""""""" 22778 22779The 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. 22780 22781Semantics: 22782"""""""""" 22783 22784The '``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: 22785 22786.. code-block:: c 22787 22788 // In this loop we load from B and spread the elements into array A. 22789 double *A, B; int *C; 22790 for (int i = 0; i < size; ++i) { 22791 if (C[i] != 0) 22792 A[i] = B[j++]; 22793 } 22794 22795 22796.. code-block:: llvm 22797 22798 ; Load several elements from array B and expand them in a vector. 22799 ; The number of loaded elements is equal to the number of '1' elements in the Mask. 22800 %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(ptr %Bptr, <8 x i1> %Mask, <8 x double> poison) 22801 ; Store the result in A 22802 call void @llvm.masked.store.v8f64.p0(<8 x double> %Tmp, ptr %Aptr, i32 8, <8 x i1> %Mask) 22803 22804 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask. 22805 %MaskI = bitcast <8 x i1> %Mask to i8 22806 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI) 22807 %MaskI64 = zext i8 %MaskIPopcnt to i64 22808 %BNextInd = add i64 %BInd, %MaskI64 22809 22810 22811Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles. 22812If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load. 22813 22814.. _int_compressstore: 22815 22816'``llvm.masked.compressstore.*``' Intrinsics 22817^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22818 22819Syntax: 22820""""""" 22821This 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. 22822 22823:: 22824 22825 declare void @llvm.masked.compressstore.v8i32 (<8 x i32> <value>, ptr <ptr>, <8 x i1> <mask>) 22826 declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, ptr <ptr>, <16 x i1> <mask>) 22827 22828Overview: 22829""""""""" 22830 22831Selects 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. 22832 22833Arguments: 22834"""""""""" 22835 22836The 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. 22837 22838 22839Semantics: 22840"""""""""" 22841 22842The '``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: 22843 22844.. code-block:: c 22845 22846 // In this loop we load elements from A and store them consecutively in B 22847 double *A, B; int *C; 22848 for (int i = 0; i < size; ++i) { 22849 if (C[i] != 0) 22850 B[j++] = A[i] 22851 } 22852 22853 22854.. code-block:: llvm 22855 22856 ; Load elements from A. 22857 %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0(ptr %Aptr, i32 8, <8 x i1> %Mask, <8 x double> poison) 22858 ; Store all selected elements consecutively in array B 22859 call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, ptr %Bptr, <8 x i1> %Mask) 22860 22861 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask. 22862 %MaskI = bitcast <8 x i1> %Mask to i8 22863 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI) 22864 %MaskI64 = zext i8 %MaskIPopcnt to i64 22865 %BNextInd = add i64 %BInd, %MaskI64 22866 22867 22868Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations. 22869 22870 22871Memory Use Markers 22872------------------ 22873 22874This class of intrinsics provides information about the 22875:ref:`lifetime of memory objects <objectlifetime>` and ranges where variables 22876are immutable. 22877 22878.. _int_lifestart: 22879 22880'``llvm.lifetime.start``' Intrinsic 22881^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22882 22883Syntax: 22884""""""" 22885 22886:: 22887 22888 declare void @llvm.lifetime.start(i64 <size>, ptr nocapture <ptr>) 22889 22890Overview: 22891""""""""" 22892 22893The '``llvm.lifetime.start``' intrinsic specifies the start of a memory 22894object's lifetime. 22895 22896Arguments: 22897"""""""""" 22898 22899The first argument is a constant integer representing the size of the 22900object, or -1 if it is variable sized. The second argument is a pointer 22901to the object. 22902 22903Semantics: 22904"""""""""" 22905 22906If ``ptr`` is a stack-allocated object and it points to the first byte of 22907the object, the object is initially marked as dead. 22908``ptr`` is conservatively considered as a non-stack-allocated object if 22909the stack coloring algorithm that is used in the optimization pipeline cannot 22910conclude that ``ptr`` is a stack-allocated object. 22911 22912After '``llvm.lifetime.start``', the stack object that ``ptr`` points is marked 22913as alive and has an uninitialized value. 22914The stack object is marked as dead when either 22915:ref:`llvm.lifetime.end <int_lifeend>` to the alloca is executed or the 22916function returns. 22917 22918After :ref:`llvm.lifetime.end <int_lifeend>` is called, 22919'``llvm.lifetime.start``' on the stack object can be called again. 22920The second '``llvm.lifetime.start``' call marks the object as alive, but it 22921does not change the address of the object. 22922 22923If ``ptr`` is a non-stack-allocated object, it does not point to the first 22924byte of the object or it is a stack object that is already alive, it simply 22925fills all bytes of the object with ``poison``. 22926 22927 22928.. _int_lifeend: 22929 22930'``llvm.lifetime.end``' Intrinsic 22931^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22932 22933Syntax: 22934""""""" 22935 22936:: 22937 22938 declare void @llvm.lifetime.end(i64 <size>, ptr nocapture <ptr>) 22939 22940Overview: 22941""""""""" 22942 22943The '``llvm.lifetime.end``' intrinsic specifies the end of a memory object's 22944lifetime. 22945 22946Arguments: 22947"""""""""" 22948 22949The first argument is a constant integer representing the size of the 22950object, or -1 if it is variable sized. The second argument is a pointer 22951to the object. 22952 22953Semantics: 22954"""""""""" 22955 22956If ``ptr`` is a stack-allocated object and it points to the first byte of the 22957object, the object is dead. 22958``ptr`` is conservatively considered as a non-stack-allocated object if 22959the stack coloring algorithm that is used in the optimization pipeline cannot 22960conclude that ``ptr`` is a stack-allocated object. 22961 22962Calling ``llvm.lifetime.end`` on an already dead alloca is no-op. 22963 22964If ``ptr`` is a non-stack-allocated object or it does not point to the first 22965byte of the object, it is equivalent to simply filling all bytes of the object 22966with ``poison``. 22967 22968 22969'``llvm.invariant.start``' Intrinsic 22970^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22971 22972Syntax: 22973""""""" 22974This is an overloaded intrinsic. The memory object can belong to any address space. 22975 22976:: 22977 22978 declare ptr @llvm.invariant.start.p0(i64 <size>, ptr nocapture <ptr>) 22979 22980Overview: 22981""""""""" 22982 22983The '``llvm.invariant.start``' intrinsic specifies that the contents of 22984a memory object will not change. 22985 22986Arguments: 22987"""""""""" 22988 22989The first argument is a constant integer representing the size of the 22990object, or -1 if it is variable sized. The second argument is a pointer 22991to the object. 22992 22993Semantics: 22994"""""""""" 22995 22996This intrinsic indicates that until an ``llvm.invariant.end`` that uses 22997the return value, the referenced memory location is constant and 22998unchanging. 22999 23000'``llvm.invariant.end``' Intrinsic 23001^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23002 23003Syntax: 23004""""""" 23005This is an overloaded intrinsic. The memory object can belong to any address space. 23006 23007:: 23008 23009 declare void @llvm.invariant.end.p0(ptr <start>, i64 <size>, ptr nocapture <ptr>) 23010 23011Overview: 23012""""""""" 23013 23014The '``llvm.invariant.end``' intrinsic specifies that the contents of a 23015memory object are mutable. 23016 23017Arguments: 23018"""""""""" 23019 23020The first argument is the matching ``llvm.invariant.start`` intrinsic. 23021The second argument is a constant integer representing the size of the 23022object, or -1 if it is variable sized and the third argument is a 23023pointer to the object. 23024 23025Semantics: 23026"""""""""" 23027 23028This intrinsic indicates that the memory is mutable again. 23029 23030'``llvm.launder.invariant.group``' Intrinsic 23031^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23032 23033Syntax: 23034""""""" 23035This is an overloaded intrinsic. The memory object can belong to any address 23036space. The returned pointer must belong to the same address space as the 23037argument. 23038 23039:: 23040 23041 declare ptr @llvm.launder.invariant.group.p0(ptr <ptr>) 23042 23043Overview: 23044""""""""" 23045 23046The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant 23047established by ``invariant.group`` metadata no longer holds, to obtain a new 23048pointer value that carries fresh invariant group information. It is an 23049experimental intrinsic, which means that its semantics might change in the 23050future. 23051 23052 23053Arguments: 23054"""""""""" 23055 23056The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer 23057to the memory. 23058 23059Semantics: 23060"""""""""" 23061 23062Returns another pointer that aliases its argument but which is considered different 23063for the purposes of ``load``/``store`` ``invariant.group`` metadata. 23064It does not read any accessible memory and the execution can be speculated. 23065 23066'``llvm.strip.invariant.group``' Intrinsic 23067^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23068 23069Syntax: 23070""""""" 23071This is an overloaded intrinsic. The memory object can belong to any address 23072space. The returned pointer must belong to the same address space as the 23073argument. 23074 23075:: 23076 23077 declare ptr @llvm.strip.invariant.group.p0(ptr <ptr>) 23078 23079Overview: 23080""""""""" 23081 23082The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant 23083established by ``invariant.group`` metadata no longer holds, to obtain a new pointer 23084value that does not carry the invariant information. It is an experimental 23085intrinsic, which means that its semantics might change in the future. 23086 23087 23088Arguments: 23089"""""""""" 23090 23091The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer 23092to the memory. 23093 23094Semantics: 23095"""""""""" 23096 23097Returns another pointer that aliases its argument but which has no associated 23098``invariant.group`` metadata. 23099It does not read any memory and can be speculated. 23100 23101 23102 23103.. _constrainedfp: 23104 23105Constrained Floating-Point Intrinsics 23106------------------------------------- 23107 23108These intrinsics are used to provide special handling of floating-point 23109operations when specific rounding mode or floating-point exception behavior is 23110required. By default, LLVM optimization passes assume that the rounding mode is 23111round-to-nearest and that floating-point exceptions will not be monitored. 23112Constrained FP intrinsics are used to support non-default rounding modes and 23113accurately preserve exception behavior without compromising LLVM's ability to 23114optimize FP code when the default behavior is used. 23115 23116If any FP operation in a function is constrained then they all must be 23117constrained. This is required for correct LLVM IR. Optimizations that 23118move code around can create miscompiles if mixing of constrained and normal 23119operations is done. The correct way to mix constrained and less constrained 23120operations is to use the rounding mode and exception handling metadata to 23121mark constrained intrinsics as having LLVM's default behavior. 23122 23123Each of these intrinsics corresponds to a normal floating-point operation. The 23124data arguments and the return value are the same as the corresponding FP 23125operation. 23126 23127The rounding mode argument is a metadata string specifying what 23128assumptions, if any, the optimizer can make when transforming constant 23129values. Some constrained FP intrinsics omit this argument. If required 23130by the intrinsic, this argument must be one of the following strings: 23131 23132:: 23133 23134 "round.dynamic" 23135 "round.tonearest" 23136 "round.downward" 23137 "round.upward" 23138 "round.towardzero" 23139 "round.tonearestaway" 23140 23141If this argument is "round.dynamic" optimization passes must assume that the 23142rounding mode is unknown and may change at runtime. No transformations that 23143depend on rounding mode may be performed in this case. 23144 23145The other possible values for the rounding mode argument correspond to the 23146similarly named IEEE rounding modes. If the argument is any of these values 23147optimization passes may perform transformations as long as they are consistent 23148with the specified rounding mode. 23149 23150For example, 'x-0'->'x' is not a valid transformation if the rounding mode is 23151"round.downward" or "round.dynamic" because if the value of 'x' is +0 then 23152'x-0' should evaluate to '-0' when rounding downward. However, this 23153transformation is legal for all other rounding modes. 23154 23155For values other than "round.dynamic" optimization passes may assume that the 23156actual runtime rounding mode (as defined in a target-specific manner) matches 23157the specified rounding mode, but this is not guaranteed. Using a specific 23158non-dynamic rounding mode which does not match the actual rounding mode at 23159runtime results in undefined behavior. 23160 23161The exception behavior argument is a metadata string describing the floating 23162point exception semantics that required for the intrinsic. This argument 23163must be one of the following strings: 23164 23165:: 23166 23167 "fpexcept.ignore" 23168 "fpexcept.maytrap" 23169 "fpexcept.strict" 23170 23171If this argument is "fpexcept.ignore" optimization passes may assume that the 23172exception status flags will not be read and that floating-point exceptions will 23173be masked. This allows transformations to be performed that may change the 23174exception semantics of the original code. For example, FP operations may be 23175speculatively executed in this case whereas they must not be for either of the 23176other possible values of this argument. 23177 23178If the exception behavior argument is "fpexcept.maytrap" optimization passes 23179must avoid transformations that may raise exceptions that would not have been 23180raised by the original code (such as speculatively executing FP operations), but 23181passes are not required to preserve all exceptions that are implied by the 23182original code. For example, exceptions may be potentially hidden by constant 23183folding. 23184 23185If the exception behavior argument is "fpexcept.strict" all transformations must 23186strictly preserve the floating-point exception semantics of the original code. 23187Any FP exception that would have been raised by the original code must be raised 23188by the transformed code, and the transformed code must not raise any FP 23189exceptions that would not have been raised by the original code. This is the 23190exception behavior argument that will be used if the code being compiled reads 23191the FP exception status flags, but this mode can also be used with code that 23192unmasks FP exceptions. 23193 23194The number and order of floating-point exceptions is NOT guaranteed. For 23195example, a series of FP operations that each may raise exceptions may be 23196vectorized into a single instruction that raises each unique exception a single 23197time. 23198 23199Proper :ref:`function attributes <fnattrs>` usage is required for the 23200constrained intrinsics to function correctly. 23201 23202All function *calls* done in a function that uses constrained floating 23203point intrinsics must have the ``strictfp`` attribute. 23204 23205All function *definitions* that use constrained floating point intrinsics 23206must have the ``strictfp`` attribute. 23207 23208'``llvm.experimental.constrained.fadd``' Intrinsic 23209^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23210 23211Syntax: 23212""""""" 23213 23214:: 23215 23216 declare <type> 23217 @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>, 23218 metadata <rounding mode>, 23219 metadata <exception behavior>) 23220 23221Overview: 23222""""""""" 23223 23224The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its 23225two operands. 23226 23227 23228Arguments: 23229"""""""""" 23230 23231The first two arguments to the '``llvm.experimental.constrained.fadd``' 23232intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 23233of floating-point values. Both arguments must have identical types. 23234 23235The third and fourth arguments specify the rounding mode and exception 23236behavior as described above. 23237 23238Semantics: 23239"""""""""" 23240 23241The value produced is the floating-point sum of the two value operands and has 23242the same type as the operands. 23243 23244 23245'``llvm.experimental.constrained.fsub``' Intrinsic 23246^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23247 23248Syntax: 23249""""""" 23250 23251:: 23252 23253 declare <type> 23254 @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>, 23255 metadata <rounding mode>, 23256 metadata <exception behavior>) 23257 23258Overview: 23259""""""""" 23260 23261The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference 23262of its two operands. 23263 23264 23265Arguments: 23266"""""""""" 23267 23268The first two arguments to the '``llvm.experimental.constrained.fsub``' 23269intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 23270of floating-point values. Both arguments must have identical types. 23271 23272The third and fourth arguments specify the rounding mode and exception 23273behavior as described above. 23274 23275Semantics: 23276"""""""""" 23277 23278The value produced is the floating-point difference of the two value operands 23279and has the same type as the operands. 23280 23281 23282'``llvm.experimental.constrained.fmul``' Intrinsic 23283^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23284 23285Syntax: 23286""""""" 23287 23288:: 23289 23290 declare <type> 23291 @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>, 23292 metadata <rounding mode>, 23293 metadata <exception behavior>) 23294 23295Overview: 23296""""""""" 23297 23298The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of 23299its two operands. 23300 23301 23302Arguments: 23303"""""""""" 23304 23305The first two arguments to the '``llvm.experimental.constrained.fmul``' 23306intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 23307of floating-point values. Both arguments must have identical types. 23308 23309The third and fourth arguments specify the rounding mode and exception 23310behavior as described above. 23311 23312Semantics: 23313"""""""""" 23314 23315The value produced is the floating-point product of the two value operands and 23316has the same type as the operands. 23317 23318 23319'``llvm.experimental.constrained.fdiv``' Intrinsic 23320^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23321 23322Syntax: 23323""""""" 23324 23325:: 23326 23327 declare <type> 23328 @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>, 23329 metadata <rounding mode>, 23330 metadata <exception behavior>) 23331 23332Overview: 23333""""""""" 23334 23335The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of 23336its two operands. 23337 23338 23339Arguments: 23340"""""""""" 23341 23342The first two arguments to the '``llvm.experimental.constrained.fdiv``' 23343intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 23344of floating-point values. Both arguments must have identical types. 23345 23346The third and fourth arguments specify the rounding mode and exception 23347behavior as described above. 23348 23349Semantics: 23350"""""""""" 23351 23352The value produced is the floating-point quotient of the two value operands and 23353has the same type as the operands. 23354 23355 23356'``llvm.experimental.constrained.frem``' Intrinsic 23357^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23358 23359Syntax: 23360""""""" 23361 23362:: 23363 23364 declare <type> 23365 @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>, 23366 metadata <rounding mode>, 23367 metadata <exception behavior>) 23368 23369Overview: 23370""""""""" 23371 23372The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder 23373from the division of its two operands. 23374 23375 23376Arguments: 23377"""""""""" 23378 23379The first two arguments to the '``llvm.experimental.constrained.frem``' 23380intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 23381of floating-point values. Both arguments must have identical types. 23382 23383The third and fourth arguments specify the rounding mode and exception 23384behavior as described above. The rounding mode argument has no effect, since 23385the result of frem is never rounded, but the argument is included for 23386consistency with the other constrained floating-point intrinsics. 23387 23388Semantics: 23389"""""""""" 23390 23391The value produced is the floating-point remainder from the division of the two 23392value operands and has the same type as the operands. The remainder has the 23393same sign as the dividend. 23394 23395'``llvm.experimental.constrained.fma``' Intrinsic 23396^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23397 23398Syntax: 23399""""""" 23400 23401:: 23402 23403 declare <type> 23404 @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>, 23405 metadata <rounding mode>, 23406 metadata <exception behavior>) 23407 23408Overview: 23409""""""""" 23410 23411The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a 23412fused-multiply-add operation on its operands. 23413 23414Arguments: 23415"""""""""" 23416 23417The first three arguments to the '``llvm.experimental.constrained.fma``' 23418intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector 23419<t_vector>` of floating-point values. All arguments must have identical types. 23420 23421The fourth and fifth arguments specify the rounding mode and exception behavior 23422as described above. 23423 23424Semantics: 23425"""""""""" 23426 23427The result produced is the product of the first two operands added to the third 23428operand computed with infinite precision, and then rounded to the target 23429precision. 23430 23431'``llvm.experimental.constrained.fptoui``' Intrinsic 23432^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23433 23434Syntax: 23435""""""" 23436 23437:: 23438 23439 declare <ty2> 23440 @llvm.experimental.constrained.fptoui(<type> <value>, 23441 metadata <exception behavior>) 23442 23443Overview: 23444""""""""" 23445 23446The '``llvm.experimental.constrained.fptoui``' intrinsic converts a 23447floating-point ``value`` to its unsigned integer equivalent of type ``ty2``. 23448 23449Arguments: 23450"""""""""" 23451 23452The first argument to the '``llvm.experimental.constrained.fptoui``' 23453intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 23454<t_vector>` of floating point values. 23455 23456The second argument specifies the exception behavior as described above. 23457 23458Semantics: 23459"""""""""" 23460 23461The result produced is an unsigned integer converted from the floating 23462point operand. The value is truncated, so it is rounded towards zero. 23463 23464'``llvm.experimental.constrained.fptosi``' Intrinsic 23465^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23466 23467Syntax: 23468""""""" 23469 23470:: 23471 23472 declare <ty2> 23473 @llvm.experimental.constrained.fptosi(<type> <value>, 23474 metadata <exception behavior>) 23475 23476Overview: 23477""""""""" 23478 23479The '``llvm.experimental.constrained.fptosi``' intrinsic converts 23480:ref:`floating-point <t_floating>` ``value`` to type ``ty2``. 23481 23482Arguments: 23483"""""""""" 23484 23485The first argument to the '``llvm.experimental.constrained.fptosi``' 23486intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 23487<t_vector>` of floating point values. 23488 23489The second argument specifies the exception behavior as described above. 23490 23491Semantics: 23492"""""""""" 23493 23494The result produced is a signed integer converted from the floating 23495point operand. The value is truncated, so it is rounded towards zero. 23496 23497'``llvm.experimental.constrained.uitofp``' Intrinsic 23498^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23499 23500Syntax: 23501""""""" 23502 23503:: 23504 23505 declare <ty2> 23506 @llvm.experimental.constrained.uitofp(<type> <value>, 23507 metadata <rounding mode>, 23508 metadata <exception behavior>) 23509 23510Overview: 23511""""""""" 23512 23513The '``llvm.experimental.constrained.uitofp``' intrinsic converts an 23514unsigned integer ``value`` to a floating-point of type ``ty2``. 23515 23516Arguments: 23517"""""""""" 23518 23519The first argument to the '``llvm.experimental.constrained.uitofp``' 23520intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector 23521<t_vector>` of integer values. 23522 23523The second and third arguments specify the rounding mode and exception 23524behavior as described above. 23525 23526Semantics: 23527"""""""""" 23528 23529An inexact floating-point exception will be raised if rounding is required. 23530Any result produced is a floating point value converted from the input 23531integer operand. 23532 23533'``llvm.experimental.constrained.sitofp``' Intrinsic 23534^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23535 23536Syntax: 23537""""""" 23538 23539:: 23540 23541 declare <ty2> 23542 @llvm.experimental.constrained.sitofp(<type> <value>, 23543 metadata <rounding mode>, 23544 metadata <exception behavior>) 23545 23546Overview: 23547""""""""" 23548 23549The '``llvm.experimental.constrained.sitofp``' intrinsic converts a 23550signed integer ``value`` to a floating-point of type ``ty2``. 23551 23552Arguments: 23553"""""""""" 23554 23555The first argument to the '``llvm.experimental.constrained.sitofp``' 23556intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector 23557<t_vector>` of integer values. 23558 23559The second and third arguments specify the rounding mode and exception 23560behavior as described above. 23561 23562Semantics: 23563"""""""""" 23564 23565An inexact floating-point exception will be raised if rounding is required. 23566Any result produced is a floating point value converted from the input 23567integer operand. 23568 23569'``llvm.experimental.constrained.fptrunc``' Intrinsic 23570^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23571 23572Syntax: 23573""""""" 23574 23575:: 23576 23577 declare <ty2> 23578 @llvm.experimental.constrained.fptrunc(<type> <value>, 23579 metadata <rounding mode>, 23580 metadata <exception behavior>) 23581 23582Overview: 23583""""""""" 23584 23585The '``llvm.experimental.constrained.fptrunc``' intrinsic truncates ``value`` 23586to type ``ty2``. 23587 23588Arguments: 23589"""""""""" 23590 23591The first argument to the '``llvm.experimental.constrained.fptrunc``' 23592intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 23593<t_vector>` of floating point values. This argument must be larger in size 23594than the result. 23595 23596The second and third arguments specify the rounding mode and exception 23597behavior as described above. 23598 23599Semantics: 23600"""""""""" 23601 23602The result produced is a floating point value truncated to be smaller in size 23603than the operand. 23604 23605'``llvm.experimental.constrained.fpext``' Intrinsic 23606^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23607 23608Syntax: 23609""""""" 23610 23611:: 23612 23613 declare <ty2> 23614 @llvm.experimental.constrained.fpext(<type> <value>, 23615 metadata <exception behavior>) 23616 23617Overview: 23618""""""""" 23619 23620The '``llvm.experimental.constrained.fpext``' intrinsic extends a 23621floating-point ``value`` to a larger floating-point value. 23622 23623Arguments: 23624"""""""""" 23625 23626The first argument to the '``llvm.experimental.constrained.fpext``' 23627intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 23628<t_vector>` of floating point values. This argument must be smaller in size 23629than the result. 23630 23631The second argument specifies the exception behavior as described above. 23632 23633Semantics: 23634"""""""""" 23635 23636The result produced is a floating point value extended to be larger in size 23637than the operand. All restrictions that apply to the fpext instruction also 23638apply to this intrinsic. 23639 23640'``llvm.experimental.constrained.fcmp``' and '``llvm.experimental.constrained.fcmps``' Intrinsics 23641^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23642 23643Syntax: 23644""""""" 23645 23646:: 23647 23648 declare <ty2> 23649 @llvm.experimental.constrained.fcmp(<type> <op1>, <type> <op2>, 23650 metadata <condition code>, 23651 metadata <exception behavior>) 23652 declare <ty2> 23653 @llvm.experimental.constrained.fcmps(<type> <op1>, <type> <op2>, 23654 metadata <condition code>, 23655 metadata <exception behavior>) 23656 23657Overview: 23658""""""""" 23659 23660The '``llvm.experimental.constrained.fcmp``' and 23661'``llvm.experimental.constrained.fcmps``' intrinsics return a boolean 23662value or vector of boolean values based on comparison of its operands. 23663 23664If the operands are floating-point scalars, then the result type is a 23665boolean (:ref:`i1 <t_integer>`). 23666 23667If the operands are floating-point vectors, then the result type is a 23668vector of boolean with the same number of elements as the operands being 23669compared. 23670 23671The '``llvm.experimental.constrained.fcmp``' intrinsic performs a quiet 23672comparison operation while the '``llvm.experimental.constrained.fcmps``' 23673intrinsic performs a signaling comparison operation. 23674 23675Arguments: 23676"""""""""" 23677 23678The first two arguments to the '``llvm.experimental.constrained.fcmp``' 23679and '``llvm.experimental.constrained.fcmps``' intrinsics must be 23680:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 23681of floating-point values. Both arguments must have identical types. 23682 23683The third argument is the condition code indicating the kind of comparison 23684to perform. It must be a metadata string with one of the following values: 23685 23686.. _fcmp_md_cc: 23687 23688- "``oeq``": ordered and equal 23689- "``ogt``": ordered and greater than 23690- "``oge``": ordered and greater than or equal 23691- "``olt``": ordered and less than 23692- "``ole``": ordered and less than or equal 23693- "``one``": ordered and not equal 23694- "``ord``": ordered (no nans) 23695- "``ueq``": unordered or equal 23696- "``ugt``": unordered or greater than 23697- "``uge``": unordered or greater than or equal 23698- "``ult``": unordered or less than 23699- "``ule``": unordered or less than or equal 23700- "``une``": unordered or not equal 23701- "``uno``": unordered (either nans) 23702 23703*Ordered* means that neither operand is a NAN while *unordered* means 23704that either operand may be a NAN. 23705 23706The fourth argument specifies the exception behavior as described above. 23707 23708Semantics: 23709"""""""""" 23710 23711``op1`` and ``op2`` are compared according to the condition code given 23712as the third argument. If the operands are vectors, then the 23713vectors are compared element by element. Each comparison performed 23714always yields an :ref:`i1 <t_integer>` result, as follows: 23715 23716.. _fcmp_md_cc_sem: 23717 23718- "``oeq``": yields ``true`` if both operands are not a NAN and ``op1`` 23719 is equal to ``op2``. 23720- "``ogt``": yields ``true`` if both operands are not a NAN and ``op1`` 23721 is greater than ``op2``. 23722- "``oge``": yields ``true`` if both operands are not a NAN and ``op1`` 23723 is greater than or equal to ``op2``. 23724- "``olt``": yields ``true`` if both operands are not a NAN and ``op1`` 23725 is less than ``op2``. 23726- "``ole``": yields ``true`` if both operands are not a NAN and ``op1`` 23727 is less than or equal to ``op2``. 23728- "``one``": yields ``true`` if both operands are not a NAN and ``op1`` 23729 is not equal to ``op2``. 23730- "``ord``": yields ``true`` if both operands are not a NAN. 23731- "``ueq``": yields ``true`` if either operand is a NAN or ``op1`` is 23732 equal to ``op2``. 23733- "``ugt``": yields ``true`` if either operand is a NAN or ``op1`` is 23734 greater than ``op2``. 23735- "``uge``": yields ``true`` if either operand is a NAN or ``op1`` is 23736 greater than or equal to ``op2``. 23737- "``ult``": yields ``true`` if either operand is a NAN or ``op1`` is 23738 less than ``op2``. 23739- "``ule``": yields ``true`` if either operand is a NAN or ``op1`` is 23740 less than or equal to ``op2``. 23741- "``une``": yields ``true`` if either operand is a NAN or ``op1`` is 23742 not equal to ``op2``. 23743- "``uno``": yields ``true`` if either operand is a NAN. 23744 23745The quiet comparison operation performed by 23746'``llvm.experimental.constrained.fcmp``' will only raise an exception 23747if either operand is a SNAN. The signaling comparison operation 23748performed by '``llvm.experimental.constrained.fcmps``' will raise an 23749exception if either operand is a NAN (QNAN or SNAN). Such an exception 23750does not preclude a result being produced (e.g. exception might only 23751set a flag), therefore the distinction between ordered and unordered 23752comparisons is also relevant for the 23753'``llvm.experimental.constrained.fcmps``' intrinsic. 23754 23755'``llvm.experimental.constrained.fmuladd``' Intrinsic 23756^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23757 23758Syntax: 23759""""""" 23760 23761:: 23762 23763 declare <type> 23764 @llvm.experimental.constrained.fmuladd(<type> <op1>, <type> <op2>, 23765 <type> <op3>, 23766 metadata <rounding mode>, 23767 metadata <exception behavior>) 23768 23769Overview: 23770""""""""" 23771 23772The '``llvm.experimental.constrained.fmuladd``' intrinsic represents 23773multiply-add expressions that can be fused if the code generator determines 23774that (a) the target instruction set has support for a fused operation, 23775and (b) that the fused operation is more efficient than the equivalent, 23776separate pair of mul and add instructions. 23777 23778Arguments: 23779"""""""""" 23780 23781The first three arguments to the '``llvm.experimental.constrained.fmuladd``' 23782intrinsic must be floating-point or vector of floating-point values. 23783All three arguments must have identical types. 23784 23785The fourth and fifth arguments specify the rounding mode and exception behavior 23786as described above. 23787 23788Semantics: 23789"""""""""" 23790 23791The expression: 23792 23793:: 23794 23795 %0 = call float @llvm.experimental.constrained.fmuladd.f32(%a, %b, %c, 23796 metadata <rounding mode>, 23797 metadata <exception behavior>) 23798 23799is equivalent to the expression: 23800 23801:: 23802 23803 %0 = call float @llvm.experimental.constrained.fmul.f32(%a, %b, 23804 metadata <rounding mode>, 23805 metadata <exception behavior>) 23806 %1 = call float @llvm.experimental.constrained.fadd.f32(%0, %c, 23807 metadata <rounding mode>, 23808 metadata <exception behavior>) 23809 23810except that it is unspecified whether rounding will be performed between the 23811multiplication and addition steps. Fusion is not guaranteed, even if the target 23812platform supports it. 23813If a fused multiply-add is required, the corresponding 23814:ref:`llvm.experimental.constrained.fma <int_fma>` intrinsic function should be 23815used instead. 23816This never sets errno, just as '``llvm.experimental.constrained.fma.*``'. 23817 23818Constrained libm-equivalent Intrinsics 23819-------------------------------------- 23820 23821In addition to the basic floating-point operations for which constrained 23822intrinsics are described above, there are constrained versions of various 23823operations which provide equivalent behavior to a corresponding libm function. 23824These intrinsics allow the precise behavior of these operations with respect to 23825rounding mode and exception behavior to be controlled. 23826 23827As with the basic constrained floating-point intrinsics, the rounding mode 23828and exception behavior arguments only control the behavior of the optimizer. 23829They do not change the runtime floating-point environment. 23830 23831 23832'``llvm.experimental.constrained.sqrt``' Intrinsic 23833^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23834 23835Syntax: 23836""""""" 23837 23838:: 23839 23840 declare <type> 23841 @llvm.experimental.constrained.sqrt(<type> <op1>, 23842 metadata <rounding mode>, 23843 metadata <exception behavior>) 23844 23845Overview: 23846""""""""" 23847 23848The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root 23849of the specified value, returning the same value as the libm '``sqrt``' 23850functions would, but without setting ``errno``. 23851 23852Arguments: 23853"""""""""" 23854 23855The first argument and the return type are floating-point numbers of the same 23856type. 23857 23858The second and third arguments specify the rounding mode and exception 23859behavior as described above. 23860 23861Semantics: 23862"""""""""" 23863 23864This function returns the nonnegative square root of the specified value. 23865If the value is less than negative zero, a floating-point exception occurs 23866and the return value is architecture specific. 23867 23868 23869'``llvm.experimental.constrained.pow``' Intrinsic 23870^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23871 23872Syntax: 23873""""""" 23874 23875:: 23876 23877 declare <type> 23878 @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>, 23879 metadata <rounding mode>, 23880 metadata <exception behavior>) 23881 23882Overview: 23883""""""""" 23884 23885The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand 23886raised to the (positive or negative) power specified by the second operand. 23887 23888Arguments: 23889"""""""""" 23890 23891The first two arguments and the return value are floating-point numbers of the 23892same type. The second argument specifies the power to which the first argument 23893should be raised. 23894 23895The third and fourth arguments specify the rounding mode and exception 23896behavior as described above. 23897 23898Semantics: 23899"""""""""" 23900 23901This function returns the first value raised to the second power, 23902returning the same values as the libm ``pow`` functions would, and 23903handles error conditions in the same way. 23904 23905 23906'``llvm.experimental.constrained.powi``' Intrinsic 23907^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23908 23909Syntax: 23910""""""" 23911 23912:: 23913 23914 declare <type> 23915 @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>, 23916 metadata <rounding mode>, 23917 metadata <exception behavior>) 23918 23919Overview: 23920""""""""" 23921 23922The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand 23923raised to the (positive or negative) power specified by the second operand. The 23924order of evaluation of multiplications is not defined. When a vector of 23925floating-point type is used, the second argument remains a scalar integer value. 23926 23927 23928Arguments: 23929"""""""""" 23930 23931The first argument and the return value are floating-point numbers of the same 23932type. The second argument is a 32-bit signed integer specifying the power to 23933which the first argument should be raised. 23934 23935The third and fourth arguments specify the rounding mode and exception 23936behavior as described above. 23937 23938Semantics: 23939"""""""""" 23940 23941This function returns the first value raised to the second power with an 23942unspecified sequence of rounding operations. 23943 23944 23945'``llvm.experimental.constrained.sin``' Intrinsic 23946^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23947 23948Syntax: 23949""""""" 23950 23951:: 23952 23953 declare <type> 23954 @llvm.experimental.constrained.sin(<type> <op1>, 23955 metadata <rounding mode>, 23956 metadata <exception behavior>) 23957 23958Overview: 23959""""""""" 23960 23961The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the 23962first operand. 23963 23964Arguments: 23965"""""""""" 23966 23967The first argument and the return type are floating-point numbers of the same 23968type. 23969 23970The second and third arguments specify the rounding mode and exception 23971behavior as described above. 23972 23973Semantics: 23974"""""""""" 23975 23976This function returns the sine of the specified operand, returning the 23977same values as the libm ``sin`` functions would, and handles error 23978conditions in the same way. 23979 23980 23981'``llvm.experimental.constrained.cos``' Intrinsic 23982^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23983 23984Syntax: 23985""""""" 23986 23987:: 23988 23989 declare <type> 23990 @llvm.experimental.constrained.cos(<type> <op1>, 23991 metadata <rounding mode>, 23992 metadata <exception behavior>) 23993 23994Overview: 23995""""""""" 23996 23997The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the 23998first operand. 23999 24000Arguments: 24001"""""""""" 24002 24003The first argument and the return type are floating-point numbers of the same 24004type. 24005 24006The second and third arguments specify the rounding mode and exception 24007behavior as described above. 24008 24009Semantics: 24010"""""""""" 24011 24012This function returns the cosine of the specified operand, returning the 24013same values as the libm ``cos`` functions would, and handles error 24014conditions in the same way. 24015 24016 24017'``llvm.experimental.constrained.exp``' Intrinsic 24018^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24019 24020Syntax: 24021""""""" 24022 24023:: 24024 24025 declare <type> 24026 @llvm.experimental.constrained.exp(<type> <op1>, 24027 metadata <rounding mode>, 24028 metadata <exception behavior>) 24029 24030Overview: 24031""""""""" 24032 24033The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e 24034exponential of the specified value. 24035 24036Arguments: 24037"""""""""" 24038 24039The first argument and the return value are floating-point numbers of the same 24040type. 24041 24042The second and third arguments specify the rounding mode and exception 24043behavior as described above. 24044 24045Semantics: 24046"""""""""" 24047 24048This function returns the same values as the libm ``exp`` functions 24049would, and handles error conditions in the same way. 24050 24051 24052'``llvm.experimental.constrained.exp2``' Intrinsic 24053^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24054 24055Syntax: 24056""""""" 24057 24058:: 24059 24060 declare <type> 24061 @llvm.experimental.constrained.exp2(<type> <op1>, 24062 metadata <rounding mode>, 24063 metadata <exception behavior>) 24064 24065Overview: 24066""""""""" 24067 24068The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2 24069exponential of the specified value. 24070 24071 24072Arguments: 24073"""""""""" 24074 24075The first argument and the return value are floating-point numbers of the same 24076type. 24077 24078The second and third arguments specify the rounding mode and exception 24079behavior as described above. 24080 24081Semantics: 24082"""""""""" 24083 24084This function returns the same values as the libm ``exp2`` functions 24085would, and handles error conditions in the same way. 24086 24087 24088'``llvm.experimental.constrained.log``' Intrinsic 24089^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24090 24091Syntax: 24092""""""" 24093 24094:: 24095 24096 declare <type> 24097 @llvm.experimental.constrained.log(<type> <op1>, 24098 metadata <rounding mode>, 24099 metadata <exception behavior>) 24100 24101Overview: 24102""""""""" 24103 24104The '``llvm.experimental.constrained.log``' intrinsic computes the base-e 24105logarithm of the specified value. 24106 24107Arguments: 24108"""""""""" 24109 24110The first argument and the return value are floating-point numbers of the same 24111type. 24112 24113The second and third arguments specify the rounding mode and exception 24114behavior as described above. 24115 24116 24117Semantics: 24118"""""""""" 24119 24120This function returns the same values as the libm ``log`` functions 24121would, and handles error conditions in the same way. 24122 24123 24124'``llvm.experimental.constrained.log10``' Intrinsic 24125^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24126 24127Syntax: 24128""""""" 24129 24130:: 24131 24132 declare <type> 24133 @llvm.experimental.constrained.log10(<type> <op1>, 24134 metadata <rounding mode>, 24135 metadata <exception behavior>) 24136 24137Overview: 24138""""""""" 24139 24140The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10 24141logarithm of the specified value. 24142 24143Arguments: 24144"""""""""" 24145 24146The first argument and the return value are floating-point numbers of the same 24147type. 24148 24149The second and third arguments specify the rounding mode and exception 24150behavior as described above. 24151 24152Semantics: 24153"""""""""" 24154 24155This function returns the same values as the libm ``log10`` functions 24156would, and handles error conditions in the same way. 24157 24158 24159'``llvm.experimental.constrained.log2``' Intrinsic 24160^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24161 24162Syntax: 24163""""""" 24164 24165:: 24166 24167 declare <type> 24168 @llvm.experimental.constrained.log2(<type> <op1>, 24169 metadata <rounding mode>, 24170 metadata <exception behavior>) 24171 24172Overview: 24173""""""""" 24174 24175The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2 24176logarithm of the specified value. 24177 24178Arguments: 24179"""""""""" 24180 24181The first argument and the return value are floating-point numbers of the same 24182type. 24183 24184The second and third arguments specify the rounding mode and exception 24185behavior as described above. 24186 24187Semantics: 24188"""""""""" 24189 24190This function returns the same values as the libm ``log2`` functions 24191would, and handles error conditions in the same way. 24192 24193 24194'``llvm.experimental.constrained.rint``' Intrinsic 24195^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24196 24197Syntax: 24198""""""" 24199 24200:: 24201 24202 declare <type> 24203 @llvm.experimental.constrained.rint(<type> <op1>, 24204 metadata <rounding mode>, 24205 metadata <exception behavior>) 24206 24207Overview: 24208""""""""" 24209 24210The '``llvm.experimental.constrained.rint``' intrinsic returns the first 24211operand rounded to the nearest integer. It may raise an inexact floating-point 24212exception if the operand is not an integer. 24213 24214Arguments: 24215"""""""""" 24216 24217The first argument and the return value are floating-point numbers of the same 24218type. 24219 24220The second and third arguments specify the rounding mode and exception 24221behavior as described above. 24222 24223Semantics: 24224"""""""""" 24225 24226This function returns the same values as the libm ``rint`` functions 24227would, and handles error conditions in the same way. The rounding mode is 24228described, not determined, by the rounding mode argument. The actual rounding 24229mode is determined by the runtime floating-point environment. The rounding 24230mode argument is only intended as information to the compiler. 24231 24232 24233'``llvm.experimental.constrained.lrint``' Intrinsic 24234^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24235 24236Syntax: 24237""""""" 24238 24239:: 24240 24241 declare <inttype> 24242 @llvm.experimental.constrained.lrint(<fptype> <op1>, 24243 metadata <rounding mode>, 24244 metadata <exception behavior>) 24245 24246Overview: 24247""""""""" 24248 24249The '``llvm.experimental.constrained.lrint``' intrinsic returns the first 24250operand rounded to the nearest integer. An inexact floating-point exception 24251will be raised if the operand is not an integer. An invalid exception is 24252raised if the result is too large to fit into a supported integer type, 24253and in this case the result is undefined. 24254 24255Arguments: 24256"""""""""" 24257 24258The first argument is a floating-point number. The return value is an 24259integer type. Not all types are supported on all targets. The supported 24260types are the same as the ``llvm.lrint`` intrinsic and the ``lrint`` 24261libm functions. 24262 24263The second and third arguments specify the rounding mode and exception 24264behavior as described above. 24265 24266Semantics: 24267"""""""""" 24268 24269This function returns the same values as the libm ``lrint`` functions 24270would, and handles error conditions in the same way. 24271 24272The rounding mode is described, not determined, by the rounding mode 24273argument. The actual rounding mode is determined by the runtime floating-point 24274environment. The rounding mode argument is only intended as information 24275to the compiler. 24276 24277If the runtime floating-point environment is using the default rounding mode 24278then the results will be the same as the llvm.lrint intrinsic. 24279 24280 24281'``llvm.experimental.constrained.llrint``' Intrinsic 24282^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24283 24284Syntax: 24285""""""" 24286 24287:: 24288 24289 declare <inttype> 24290 @llvm.experimental.constrained.llrint(<fptype> <op1>, 24291 metadata <rounding mode>, 24292 metadata <exception behavior>) 24293 24294Overview: 24295""""""""" 24296 24297The '``llvm.experimental.constrained.llrint``' intrinsic returns the first 24298operand rounded to the nearest integer. An inexact floating-point exception 24299will be raised if the operand is not an integer. An invalid exception is 24300raised if the result is too large to fit into a supported integer type, 24301and in this case the result is undefined. 24302 24303Arguments: 24304"""""""""" 24305 24306The first argument is a floating-point number. The return value is an 24307integer type. Not all types are supported on all targets. The supported 24308types are the same as the ``llvm.llrint`` intrinsic and the ``llrint`` 24309libm functions. 24310 24311The second and third arguments specify the rounding mode and exception 24312behavior as described above. 24313 24314Semantics: 24315"""""""""" 24316 24317This function returns the same values as the libm ``llrint`` functions 24318would, and handles error conditions in the same way. 24319 24320The rounding mode is described, not determined, by the rounding mode 24321argument. The actual rounding mode is determined by the runtime floating-point 24322environment. The rounding mode argument is only intended as information 24323to the compiler. 24324 24325If the runtime floating-point environment is using the default rounding mode 24326then the results will be the same as the llvm.llrint intrinsic. 24327 24328 24329'``llvm.experimental.constrained.nearbyint``' Intrinsic 24330^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24331 24332Syntax: 24333""""""" 24334 24335:: 24336 24337 declare <type> 24338 @llvm.experimental.constrained.nearbyint(<type> <op1>, 24339 metadata <rounding mode>, 24340 metadata <exception behavior>) 24341 24342Overview: 24343""""""""" 24344 24345The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first 24346operand rounded to the nearest integer. It will not raise an inexact 24347floating-point exception if the operand is not an integer. 24348 24349 24350Arguments: 24351"""""""""" 24352 24353The first argument and the return value are floating-point numbers of the same 24354type. 24355 24356The second and third arguments specify the rounding mode and exception 24357behavior as described above. 24358 24359Semantics: 24360"""""""""" 24361 24362This function returns the same values as the libm ``nearbyint`` functions 24363would, and handles error conditions in the same way. The rounding mode is 24364described, not determined, by the rounding mode argument. The actual rounding 24365mode is determined by the runtime floating-point environment. The rounding 24366mode argument is only intended as information to the compiler. 24367 24368 24369'``llvm.experimental.constrained.maxnum``' Intrinsic 24370^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24371 24372Syntax: 24373""""""" 24374 24375:: 24376 24377 declare <type> 24378 @llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2> 24379 metadata <exception behavior>) 24380 24381Overview: 24382""""""""" 24383 24384The '``llvm.experimental.constrained.maxnum``' intrinsic returns the maximum 24385of the two arguments. 24386 24387Arguments: 24388"""""""""" 24389 24390The first two arguments and the return value are floating-point numbers 24391of the same type. 24392 24393The third argument specifies the exception behavior as described above. 24394 24395Semantics: 24396"""""""""" 24397 24398This function follows the IEEE-754 semantics for maxNum. 24399 24400 24401'``llvm.experimental.constrained.minnum``' Intrinsic 24402^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24403 24404Syntax: 24405""""""" 24406 24407:: 24408 24409 declare <type> 24410 @llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2> 24411 metadata <exception behavior>) 24412 24413Overview: 24414""""""""" 24415 24416The '``llvm.experimental.constrained.minnum``' intrinsic returns the minimum 24417of the two arguments. 24418 24419Arguments: 24420"""""""""" 24421 24422The first two arguments and the return value are floating-point numbers 24423of the same type. 24424 24425The third argument specifies the exception behavior as described above. 24426 24427Semantics: 24428"""""""""" 24429 24430This function follows the IEEE-754 semantics for minNum. 24431 24432 24433'``llvm.experimental.constrained.maximum``' Intrinsic 24434^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24435 24436Syntax: 24437""""""" 24438 24439:: 24440 24441 declare <type> 24442 @llvm.experimental.constrained.maximum(<type> <op1>, <type> <op2> 24443 metadata <exception behavior>) 24444 24445Overview: 24446""""""""" 24447 24448The '``llvm.experimental.constrained.maximum``' intrinsic returns the maximum 24449of the two arguments, propagating NaNs and treating -0.0 as less than +0.0. 24450 24451Arguments: 24452"""""""""" 24453 24454The first two arguments and the return value are floating-point numbers 24455of the same type. 24456 24457The third argument specifies the exception behavior as described above. 24458 24459Semantics: 24460"""""""""" 24461 24462This function follows semantics specified in the draft of IEEE 754-2018. 24463 24464 24465'``llvm.experimental.constrained.minimum``' Intrinsic 24466^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24467 24468Syntax: 24469""""""" 24470 24471:: 24472 24473 declare <type> 24474 @llvm.experimental.constrained.minimum(<type> <op1>, <type> <op2> 24475 metadata <exception behavior>) 24476 24477Overview: 24478""""""""" 24479 24480The '``llvm.experimental.constrained.minimum``' intrinsic returns the minimum 24481of the two arguments, propagating NaNs and treating -0.0 as less than +0.0. 24482 24483Arguments: 24484"""""""""" 24485 24486The first two arguments and the return value are floating-point numbers 24487of the same type. 24488 24489The third argument specifies the exception behavior as described above. 24490 24491Semantics: 24492"""""""""" 24493 24494This function follows semantics specified in the draft of IEEE 754-2018. 24495 24496 24497'``llvm.experimental.constrained.ceil``' Intrinsic 24498^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24499 24500Syntax: 24501""""""" 24502 24503:: 24504 24505 declare <type> 24506 @llvm.experimental.constrained.ceil(<type> <op1>, 24507 metadata <exception behavior>) 24508 24509Overview: 24510""""""""" 24511 24512The '``llvm.experimental.constrained.ceil``' intrinsic returns the ceiling of the 24513first operand. 24514 24515Arguments: 24516"""""""""" 24517 24518The first argument and the return value are floating-point numbers of the same 24519type. 24520 24521The second argument specifies the exception behavior as described above. 24522 24523Semantics: 24524"""""""""" 24525 24526This function returns the same values as the libm ``ceil`` functions 24527would and handles error conditions in the same way. 24528 24529 24530'``llvm.experimental.constrained.floor``' Intrinsic 24531^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24532 24533Syntax: 24534""""""" 24535 24536:: 24537 24538 declare <type> 24539 @llvm.experimental.constrained.floor(<type> <op1>, 24540 metadata <exception behavior>) 24541 24542Overview: 24543""""""""" 24544 24545The '``llvm.experimental.constrained.floor``' intrinsic returns the floor of the 24546first operand. 24547 24548Arguments: 24549"""""""""" 24550 24551The first argument and the return value are floating-point numbers of the same 24552type. 24553 24554The second argument specifies the exception behavior as described above. 24555 24556Semantics: 24557"""""""""" 24558 24559This function returns the same values as the libm ``floor`` functions 24560would and handles error conditions in the same way. 24561 24562 24563'``llvm.experimental.constrained.round``' Intrinsic 24564^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24565 24566Syntax: 24567""""""" 24568 24569:: 24570 24571 declare <type> 24572 @llvm.experimental.constrained.round(<type> <op1>, 24573 metadata <exception behavior>) 24574 24575Overview: 24576""""""""" 24577 24578The '``llvm.experimental.constrained.round``' intrinsic returns the first 24579operand rounded to the nearest integer. 24580 24581Arguments: 24582"""""""""" 24583 24584The first argument and the return value are floating-point numbers of the same 24585type. 24586 24587The second argument specifies the exception behavior as described above. 24588 24589Semantics: 24590"""""""""" 24591 24592This function returns the same values as the libm ``round`` functions 24593would and handles error conditions in the same way. 24594 24595 24596'``llvm.experimental.constrained.roundeven``' Intrinsic 24597^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24598 24599Syntax: 24600""""""" 24601 24602:: 24603 24604 declare <type> 24605 @llvm.experimental.constrained.roundeven(<type> <op1>, 24606 metadata <exception behavior>) 24607 24608Overview: 24609""""""""" 24610 24611The '``llvm.experimental.constrained.roundeven``' intrinsic returns the first 24612operand rounded to the nearest integer in floating-point format, rounding 24613halfway cases to even (that is, to the nearest value that is an even integer), 24614regardless of the current rounding direction. 24615 24616Arguments: 24617"""""""""" 24618 24619The first argument and the return value are floating-point numbers of the same 24620type. 24621 24622The second argument specifies the exception behavior as described above. 24623 24624Semantics: 24625"""""""""" 24626 24627This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It 24628also behaves in the same way as C standard function ``roundeven`` and can signal 24629the invalid operation exception for a SNAN operand. 24630 24631 24632'``llvm.experimental.constrained.lround``' Intrinsic 24633^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24634 24635Syntax: 24636""""""" 24637 24638:: 24639 24640 declare <inttype> 24641 @llvm.experimental.constrained.lround(<fptype> <op1>, 24642 metadata <exception behavior>) 24643 24644Overview: 24645""""""""" 24646 24647The '``llvm.experimental.constrained.lround``' intrinsic returns the first 24648operand rounded to the nearest integer with ties away from zero. It will 24649raise an inexact floating-point exception if the operand is not an integer. 24650An invalid exception is raised if the result is too large to fit into a 24651supported integer type, and in this case the result is undefined. 24652 24653Arguments: 24654"""""""""" 24655 24656The first argument is a floating-point number. The return value is an 24657integer type. Not all types are supported on all targets. The supported 24658types are the same as the ``llvm.lround`` intrinsic and the ``lround`` 24659libm functions. 24660 24661The second argument specifies the exception behavior as described above. 24662 24663Semantics: 24664"""""""""" 24665 24666This function returns the same values as the libm ``lround`` functions 24667would and handles error conditions in the same way. 24668 24669 24670'``llvm.experimental.constrained.llround``' Intrinsic 24671^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24672 24673Syntax: 24674""""""" 24675 24676:: 24677 24678 declare <inttype> 24679 @llvm.experimental.constrained.llround(<fptype> <op1>, 24680 metadata <exception behavior>) 24681 24682Overview: 24683""""""""" 24684 24685The '``llvm.experimental.constrained.llround``' intrinsic returns the first 24686operand rounded to the nearest integer with ties away from zero. It will 24687raise an inexact floating-point exception if the operand is not an integer. 24688An invalid exception is raised if the result is too large to fit into a 24689supported integer type, and in this case the result is undefined. 24690 24691Arguments: 24692"""""""""" 24693 24694The first argument is a floating-point number. The return value is an 24695integer type. Not all types are supported on all targets. The supported 24696types are the same as the ``llvm.llround`` intrinsic and the ``llround`` 24697libm functions. 24698 24699The second argument specifies the exception behavior as described above. 24700 24701Semantics: 24702"""""""""" 24703 24704This function returns the same values as the libm ``llround`` functions 24705would and handles error conditions in the same way. 24706 24707 24708'``llvm.experimental.constrained.trunc``' Intrinsic 24709^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24710 24711Syntax: 24712""""""" 24713 24714:: 24715 24716 declare <type> 24717 @llvm.experimental.constrained.trunc(<type> <op1>, 24718 metadata <exception behavior>) 24719 24720Overview: 24721""""""""" 24722 24723The '``llvm.experimental.constrained.trunc``' intrinsic returns the first 24724operand rounded to the nearest integer not larger in magnitude than the 24725operand. 24726 24727Arguments: 24728"""""""""" 24729 24730The first argument and the return value are floating-point numbers of the same 24731type. 24732 24733The second argument specifies the exception behavior as described above. 24734 24735Semantics: 24736"""""""""" 24737 24738This function returns the same values as the libm ``trunc`` functions 24739would and handles error conditions in the same way. 24740 24741.. _int_experimental_noalias_scope_decl: 24742 24743'``llvm.experimental.noalias.scope.decl``' Intrinsic 24744^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24745 24746Syntax: 24747""""""" 24748 24749 24750:: 24751 24752 declare void @llvm.experimental.noalias.scope.decl(metadata !id.scope.list) 24753 24754Overview: 24755""""""""" 24756 24757The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a 24758noalias scope is declared. When the intrinsic is duplicated, a decision must 24759also be made about the scope: depending on the reason of the duplication, 24760the scope might need to be duplicated as well. 24761 24762 24763Arguments: 24764"""""""""" 24765 24766The ``!id.scope.list`` argument is metadata that is a list of ``noalias`` 24767metadata references. The format is identical to that required for ``noalias`` 24768metadata. This list must have exactly one element. 24769 24770Semantics: 24771"""""""""" 24772 24773The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a 24774noalias scope is declared. When the intrinsic is duplicated, a decision must 24775also be made about the scope: depending on the reason of the duplication, 24776the scope might need to be duplicated as well. 24777 24778For example, when the intrinsic is used inside a loop body, and that loop is 24779unrolled, the associated noalias scope must also be duplicated. Otherwise, the 24780noalias property it signifies would spill across loop iterations, whereas it 24781was only valid within a single iteration. 24782 24783.. code-block:: llvm 24784 24785 ; This examples shows two possible positions for noalias.decl and how they impact the semantics: 24786 ; If it is outside the loop (Version 1), then %a and %b are noalias across *all* iterations. 24787 ; If it is inside the loop (Version 2), then %a and %b are noalias only within *one* iteration. 24788 declare void @decl_in_loop(ptr %a.base, ptr %b.base) { 24789 entry: 24790 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 1: noalias decl outside loop 24791 br label %loop 24792 24793 loop: 24794 %a = phi ptr [ %a.base, %entry ], [ %a.inc, %loop ] 24795 %b = phi ptr [ %b.base, %entry ], [ %b.inc, %loop ] 24796 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 2: noalias decl inside loop 24797 %val = load i8, ptr %a, !alias.scope !2 24798 store i8 %val, ptr %b, !noalias !2 24799 %a.inc = getelementptr inbounds i8, ptr %a, i64 1 24800 %b.inc = getelementptr inbounds i8, ptr %b, i64 1 24801 %cond = call i1 @cond() 24802 br i1 %cond, label %loop, label %exit 24803 24804 exit: 24805 ret void 24806 } 24807 24808 !0 = !{!0} ; domain 24809 !1 = !{!1, !0} ; scope 24810 !2 = !{!1} ; scope list 24811 24812Multiple calls to `@llvm.experimental.noalias.scope.decl` for the same scope 24813are possible, but one should never dominate another. Violations are pointed out 24814by the verifier as they indicate a problem in either a transformation pass or 24815the input. 24816 24817 24818Floating Point Environment Manipulation intrinsics 24819-------------------------------------------------- 24820 24821These functions read or write floating point environment, such as rounding 24822mode or state of floating point exceptions. Altering the floating point 24823environment requires special care. See :ref:`Floating Point Environment <floatenv>`. 24824 24825'``llvm.get.rounding``' Intrinsic 24826^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24827 24828Syntax: 24829""""""" 24830 24831:: 24832 24833 declare i32 @llvm.get.rounding() 24834 24835Overview: 24836""""""""" 24837 24838The '``llvm.get.rounding``' intrinsic reads the current rounding mode. 24839 24840Semantics: 24841"""""""""" 24842 24843The '``llvm.get.rounding``' intrinsic returns the current rounding mode. 24844Encoding of the returned values is same as the result of ``FLT_ROUNDS``, 24845specified by C standard: 24846 24847:: 24848 24849 0 - toward zero 24850 1 - to nearest, ties to even 24851 2 - toward positive infinity 24852 3 - toward negative infinity 24853 4 - to nearest, ties away from zero 24854 24855Other values may be used to represent additional rounding modes, supported by a 24856target. These values are target-specific. 24857 24858'``llvm.set.rounding``' Intrinsic 24859^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24860 24861Syntax: 24862""""""" 24863 24864:: 24865 24866 declare void @llvm.set.rounding(i32 <val>) 24867 24868Overview: 24869""""""""" 24870 24871The '``llvm.set.rounding``' intrinsic sets current rounding mode. 24872 24873Arguments: 24874"""""""""" 24875 24876The argument is the required rounding mode. Encoding of rounding mode is 24877the same as used by '``llvm.get.rounding``'. 24878 24879Semantics: 24880"""""""""" 24881 24882The '``llvm.set.rounding``' intrinsic sets the current rounding mode. It is 24883similar to C library function 'fesetround', however this intrinsic does not 24884return any value and uses platform-independent representation of IEEE rounding 24885modes. 24886 24887 24888Floating-Point Test Intrinsics 24889------------------------------ 24890 24891These functions get properties of floating-point values. 24892 24893 24894'``llvm.is.fpclass``' Intrinsic 24895^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24896 24897Syntax: 24898""""""" 24899 24900:: 24901 24902 declare i1 @llvm.is.fpclass(<fptype> <op>, i32 <test>) 24903 declare <N x i1> @llvm.is.fpclass(<vector-fptype> <op>, i32 <test>) 24904 24905Overview: 24906""""""""" 24907 24908The '``llvm.is.fpclass``' intrinsic returns a boolean value or vector of boolean 24909values depending on whether the first argument satisfies the test specified by 24910the second argument. 24911 24912If the first argument is a floating-point scalar, then the result type is a 24913boolean (:ref:`i1 <t_integer>`). 24914 24915If the first argument is a floating-point vector, then the result type is a 24916vector of boolean with the same number of elements as the first argument. 24917 24918Arguments: 24919"""""""""" 24920 24921The first argument to the '``llvm.is.fpclass``' intrinsic must be 24922:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 24923of floating-point values. 24924 24925The second argument specifies, which tests to perform. It must be a compile-time 24926integer constant, each bit in which specifies floating-point class: 24927 24928+-------+----------------------+ 24929| Bit # | floating-point class | 24930+=======+======================+ 24931| 0 | Signaling NaN | 24932+-------+----------------------+ 24933| 1 | Quiet NaN | 24934+-------+----------------------+ 24935| 2 | Negative infinity | 24936+-------+----------------------+ 24937| 3 | Negative normal | 24938+-------+----------------------+ 24939| 4 | Negative subnormal | 24940+-------+----------------------+ 24941| 5 | Negative zero | 24942+-------+----------------------+ 24943| 6 | Positive zero | 24944+-------+----------------------+ 24945| 7 | Positive subnormal | 24946+-------+----------------------+ 24947| 8 | Positive normal | 24948+-------+----------------------+ 24949| 9 | Positive infinity | 24950+-------+----------------------+ 24951 24952Semantics: 24953"""""""""" 24954 24955The function checks if ``op`` belongs to any of the floating-point classes 24956specified by ``test``. If ``op`` is a vector, then the check is made element by 24957element. Each check yields an :ref:`i1 <t_integer>` result, which is ``true``, 24958if the element value satisfies the specified test. The argument ``test`` is a 24959bit mask where each bit specifies floating-point class to test. For example, the 24960value 0x108 makes test for normal value, - bits 3 and 8 in it are set, which 24961means that the function returns ``true`` if ``op`` is a positive or negative 24962normal value. The function never raises floating-point exceptions. 24963 24964 24965General Intrinsics 24966------------------ 24967 24968This class of intrinsics is designed to be generic and has no specific 24969purpose. 24970 24971'``llvm.var.annotation``' Intrinsic 24972^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24973 24974Syntax: 24975""""""" 24976 24977:: 24978 24979 declare void @llvm.var.annotation(ptr <val>, ptr <str>, ptr <str>, i32 <int>) 24980 24981Overview: 24982""""""""" 24983 24984The '``llvm.var.annotation``' intrinsic. 24985 24986Arguments: 24987"""""""""" 24988 24989The first argument is a pointer to a value, the second is a pointer to a 24990global string, the third is a pointer to a global string which is the 24991source file name, and the last argument is the line number. 24992 24993Semantics: 24994"""""""""" 24995 24996This intrinsic allows annotation of local variables with arbitrary 24997strings. This can be useful for special purpose optimizations that want 24998to look for these annotations. These have no other defined use; they are 24999ignored by code generation and optimization. 25000 25001'``llvm.ptr.annotation.*``' Intrinsic 25002^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25003 25004Syntax: 25005""""""" 25006 25007This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a 25008pointer to an integer of any width. *NOTE* you must specify an address space for 25009the pointer. The identifier for the default address space is the integer 25010'``0``'. 25011 25012:: 25013 25014 declare ptr @llvm.ptr.annotation.p0(ptr <val>, ptr <str>, ptr <str>, i32 <int>) 25015 declare ptr @llvm.ptr.annotation.p1(ptr addrspace(1) <val>, ptr <str>, ptr <str>, i32 <int>) 25016 25017Overview: 25018""""""""" 25019 25020The '``llvm.ptr.annotation``' intrinsic. 25021 25022Arguments: 25023"""""""""" 25024 25025The first argument is a pointer to an integer value of arbitrary bitwidth 25026(result of some expression), the second is a pointer to a global string, the 25027third is a pointer to a global string which is the source file name, and the 25028last argument is the line number. It returns the value of the first argument. 25029 25030Semantics: 25031"""""""""" 25032 25033This intrinsic allows annotation of a pointer to an integer with arbitrary 25034strings. This can be useful for special purpose optimizations that want to look 25035for these annotations. These have no other defined use; transformations preserve 25036annotations on a best-effort basis but are allowed to replace the intrinsic with 25037its first argument without breaking semantics and the intrinsic is completely 25038dropped during instruction selection. 25039 25040'``llvm.annotation.*``' Intrinsic 25041^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25042 25043Syntax: 25044""""""" 25045 25046This is an overloaded intrinsic. You can use '``llvm.annotation``' on 25047any integer bit width. 25048 25049:: 25050 25051 declare i8 @llvm.annotation.i8(i8 <val>, ptr <str>, ptr <str>, i32 <int>) 25052 declare i16 @llvm.annotation.i16(i16 <val>, ptr <str>, ptr <str>, i32 <int>) 25053 declare i32 @llvm.annotation.i32(i32 <val>, ptr <str>, ptr <str>, i32 <int>) 25054 declare i64 @llvm.annotation.i64(i64 <val>, ptr <str>, ptr <str>, i32 <int>) 25055 declare i256 @llvm.annotation.i256(i256 <val>, ptr <str>, ptr <str>, i32 <int>) 25056 25057Overview: 25058""""""""" 25059 25060The '``llvm.annotation``' intrinsic. 25061 25062Arguments: 25063"""""""""" 25064 25065The first argument is an integer value (result of some expression), the 25066second is a pointer to a global string, the third is a pointer to a 25067global string which is the source file name, and the last argument is 25068the line number. It returns the value of the first argument. 25069 25070Semantics: 25071"""""""""" 25072 25073This intrinsic allows annotations to be put on arbitrary expressions with 25074arbitrary strings. This can be useful for special purpose optimizations that 25075want to look for these annotations. These have no other defined use; 25076transformations preserve annotations on a best-effort basis but are allowed to 25077replace the intrinsic with its first argument without breaking semantics and the 25078intrinsic is completely dropped during instruction selection. 25079 25080'``llvm.codeview.annotation``' Intrinsic 25081^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25082 25083Syntax: 25084""""""" 25085 25086This annotation emits a label at its program point and an associated 25087``S_ANNOTATION`` codeview record with some additional string metadata. This is 25088used to implement MSVC's ``__annotation`` intrinsic. It is marked 25089``noduplicate``, so calls to this intrinsic prevent inlining and should be 25090considered expensive. 25091 25092:: 25093 25094 declare void @llvm.codeview.annotation(metadata) 25095 25096Arguments: 25097"""""""""" 25098 25099The argument should be an MDTuple containing any number of MDStrings. 25100 25101'``llvm.trap``' Intrinsic 25102^^^^^^^^^^^^^^^^^^^^^^^^^ 25103 25104Syntax: 25105""""""" 25106 25107:: 25108 25109 declare void @llvm.trap() cold noreturn nounwind 25110 25111Overview: 25112""""""""" 25113 25114The '``llvm.trap``' intrinsic. 25115 25116Arguments: 25117"""""""""" 25118 25119None. 25120 25121Semantics: 25122"""""""""" 25123 25124This intrinsic is lowered to the target dependent trap instruction. If 25125the target does not have a trap instruction, this intrinsic will be 25126lowered to a call of the ``abort()`` function. 25127 25128'``llvm.debugtrap``' Intrinsic 25129^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25130 25131Syntax: 25132""""""" 25133 25134:: 25135 25136 declare void @llvm.debugtrap() nounwind 25137 25138Overview: 25139""""""""" 25140 25141The '``llvm.debugtrap``' intrinsic. 25142 25143Arguments: 25144"""""""""" 25145 25146None. 25147 25148Semantics: 25149"""""""""" 25150 25151This intrinsic is lowered to code which is intended to cause an 25152execution trap with the intention of requesting the attention of a 25153debugger. 25154 25155'``llvm.ubsantrap``' Intrinsic 25156^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25157 25158Syntax: 25159""""""" 25160 25161:: 25162 25163 declare void @llvm.ubsantrap(i8 immarg) cold noreturn nounwind 25164 25165Overview: 25166""""""""" 25167 25168The '``llvm.ubsantrap``' intrinsic. 25169 25170Arguments: 25171"""""""""" 25172 25173An integer describing the kind of failure detected. 25174 25175Semantics: 25176"""""""""" 25177 25178This intrinsic is lowered to code which is intended to cause an execution trap, 25179embedding the argument into encoding of that trap somehow to discriminate 25180crashes if possible. 25181 25182Equivalent to ``@llvm.trap`` for targets that do not support this behaviour. 25183 25184'``llvm.stackprotector``' Intrinsic 25185^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25186 25187Syntax: 25188""""""" 25189 25190:: 25191 25192 declare void @llvm.stackprotector(ptr <guard>, ptr <slot>) 25193 25194Overview: 25195""""""""" 25196 25197The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it 25198onto the stack at ``slot``. The stack slot is adjusted to ensure that it 25199is placed on the stack before local variables. 25200 25201Arguments: 25202"""""""""" 25203 25204The ``llvm.stackprotector`` intrinsic requires two pointer arguments. 25205The first argument is the value loaded from the stack guard 25206``@__stack_chk_guard``. The second variable is an ``alloca`` that has 25207enough space to hold the value of the guard. 25208 25209Semantics: 25210"""""""""" 25211 25212This intrinsic causes the prologue/epilogue inserter to force the position of 25213the ``AllocaInst`` stack slot to be before local variables on the stack. This is 25214to ensure that if a local variable on the stack is overwritten, it will destroy 25215the value of the guard. When the function exits, the guard on the stack is 25216checked against the original guard by ``llvm.stackprotectorcheck``. If they are 25217different, then ``llvm.stackprotectorcheck`` causes the program to abort by 25218calling the ``__stack_chk_fail()`` function. 25219 25220'``llvm.stackguard``' Intrinsic 25221^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25222 25223Syntax: 25224""""""" 25225 25226:: 25227 25228 declare ptr @llvm.stackguard() 25229 25230Overview: 25231""""""""" 25232 25233The ``llvm.stackguard`` intrinsic returns the system stack guard value. 25234 25235It should not be generated by frontends, since it is only for internal usage. 25236The reason why we create this intrinsic is that we still support IR form Stack 25237Protector in FastISel. 25238 25239Arguments: 25240"""""""""" 25241 25242None. 25243 25244Semantics: 25245"""""""""" 25246 25247On some platforms, the value returned by this intrinsic remains unchanged 25248between loads in the same thread. On other platforms, it returns the same 25249global variable value, if any, e.g. ``@__stack_chk_guard``. 25250 25251Currently some platforms have IR-level customized stack guard loading (e.g. 25252X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be 25253in the future. 25254 25255'``llvm.objectsize``' Intrinsic 25256^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25257 25258Syntax: 25259""""""" 25260 25261:: 25262 25263 declare i32 @llvm.objectsize.i32(ptr <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>) 25264 declare i64 @llvm.objectsize.i64(ptr <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>) 25265 25266Overview: 25267""""""""" 25268 25269The ``llvm.objectsize`` intrinsic is designed to provide information to the 25270optimizer to determine whether a) an operation (like memcpy) will overflow a 25271buffer that corresponds to an object, or b) that a runtime check for overflow 25272isn't necessary. An object in this context means an allocation of a specific 25273class, structure, array, or other object. 25274 25275Arguments: 25276"""""""""" 25277 25278The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a 25279pointer to or into the ``object``. The second argument determines whether 25280``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size is 25281unknown. The third argument controls how ``llvm.objectsize`` acts when ``null`` 25282in address space 0 is used as its pointer argument. If it's ``false``, 25283``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if 25284the ``null`` is in a non-zero address space or if ``true`` is given for the 25285third argument of ``llvm.objectsize``, we assume its size is unknown. The fourth 25286argument to ``llvm.objectsize`` determines if the value should be evaluated at 25287runtime. 25288 25289The second, third, and fourth arguments only accept constants. 25290 25291Semantics: 25292"""""""""" 25293 25294The ``llvm.objectsize`` intrinsic is lowered to a value representing the size of 25295the object concerned. If the size cannot be determined, ``llvm.objectsize`` 25296returns ``i32/i64 -1 or 0`` (depending on the ``min`` argument). 25297 25298'``llvm.expect``' Intrinsic 25299^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25300 25301Syntax: 25302""""""" 25303 25304This is an overloaded intrinsic. You can use ``llvm.expect`` on any 25305integer bit width. 25306 25307:: 25308 25309 declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>) 25310 declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>) 25311 declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>) 25312 25313Overview: 25314""""""""" 25315 25316The ``llvm.expect`` intrinsic provides information about expected (the 25317most probable) value of ``val``, which can be used by optimizers. 25318 25319Arguments: 25320"""""""""" 25321 25322The ``llvm.expect`` intrinsic takes two arguments. The first argument is 25323a value. The second argument is an expected value. 25324 25325Semantics: 25326"""""""""" 25327 25328This intrinsic is lowered to the ``val``. 25329 25330'``llvm.expect.with.probability``' Intrinsic 25331^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25332 25333Syntax: 25334""""""" 25335 25336This intrinsic is similar to ``llvm.expect``. This is an overloaded intrinsic. 25337You can use ``llvm.expect.with.probability`` on any integer bit width. 25338 25339:: 25340 25341 declare i1 @llvm.expect.with.probability.i1(i1 <val>, i1 <expected_val>, double <prob>) 25342 declare i32 @llvm.expect.with.probability.i32(i32 <val>, i32 <expected_val>, double <prob>) 25343 declare i64 @llvm.expect.with.probability.i64(i64 <val>, i64 <expected_val>, double <prob>) 25344 25345Overview: 25346""""""""" 25347 25348The ``llvm.expect.with.probability`` intrinsic provides information about 25349expected value of ``val`` with probability(or confidence) ``prob``, which can 25350be used by optimizers. 25351 25352Arguments: 25353"""""""""" 25354 25355The ``llvm.expect.with.probability`` intrinsic takes three arguments. The first 25356argument is a value. The second argument is an expected value. The third 25357argument is a probability. 25358 25359Semantics: 25360"""""""""" 25361 25362This intrinsic is lowered to the ``val``. 25363 25364.. _int_assume: 25365 25366'``llvm.assume``' Intrinsic 25367^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25368 25369Syntax: 25370""""""" 25371 25372:: 25373 25374 declare void @llvm.assume(i1 %cond) 25375 25376Overview: 25377""""""""" 25378 25379The ``llvm.assume`` allows the optimizer to assume that the provided 25380condition is true. This information can then be used in simplifying other parts 25381of the code. 25382 25383More complex assumptions can be encoded as 25384:ref:`assume operand bundles <assume_opbundles>`. 25385 25386Arguments: 25387"""""""""" 25388 25389The argument of the call is the condition which the optimizer may assume is 25390always true. 25391 25392Semantics: 25393"""""""""" 25394 25395The intrinsic allows the optimizer to assume that the provided condition is 25396always true whenever the control flow reaches the intrinsic call. No code is 25397generated for this intrinsic, and instructions that contribute only to the 25398provided condition are not used for code generation. If the condition is 25399violated during execution, the behavior is undefined. 25400 25401Note that the optimizer might limit the transformations performed on values 25402used by the ``llvm.assume`` intrinsic in order to preserve the instructions 25403only used to form the intrinsic's input argument. This might prove undesirable 25404if the extra information provided by the ``llvm.assume`` intrinsic does not cause 25405sufficient overall improvement in code quality. For this reason, 25406``llvm.assume`` should not be used to document basic mathematical invariants 25407that the optimizer can otherwise deduce or facts that are of little use to the 25408optimizer. 25409 25410.. _int_ssa_copy: 25411 25412'``llvm.ssa.copy``' Intrinsic 25413^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25414 25415Syntax: 25416""""""" 25417 25418:: 25419 25420 declare type @llvm.ssa.copy(type %operand) returned(1) readnone 25421 25422Arguments: 25423"""""""""" 25424 25425The first argument is an operand which is used as the returned value. 25426 25427Overview: 25428"""""""""" 25429 25430The ``llvm.ssa.copy`` intrinsic can be used to attach information to 25431operations by copying them and giving them new names. For example, 25432the PredicateInfo utility uses it to build Extended SSA form, and 25433attach various forms of information to operands that dominate specific 25434uses. It is not meant for general use, only for building temporary 25435renaming forms that require value splits at certain points. 25436 25437.. _type.test: 25438 25439'``llvm.type.test``' Intrinsic 25440^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25441 25442Syntax: 25443""""""" 25444 25445:: 25446 25447 declare i1 @llvm.type.test(ptr %ptr, metadata %type) nounwind readnone 25448 25449 25450Arguments: 25451"""""""""" 25452 25453The first argument is a pointer to be tested. The second argument is a 25454metadata object representing a :doc:`type identifier <TypeMetadata>`. 25455 25456Overview: 25457""""""""" 25458 25459The ``llvm.type.test`` intrinsic tests whether the given pointer is associated 25460with the given type identifier. 25461 25462.. _type.checked.load: 25463 25464'``llvm.type.checked.load``' Intrinsic 25465^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25466 25467Syntax: 25468""""""" 25469 25470:: 25471 25472 declare {ptr, i1} @llvm.type.checked.load(ptr %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly 25473 25474 25475Arguments: 25476"""""""""" 25477 25478The first argument is a pointer from which to load a function pointer. The 25479second argument is the byte offset from which to load the function pointer. The 25480third argument is a metadata object representing a :doc:`type identifier 25481<TypeMetadata>`. 25482 25483Overview: 25484""""""""" 25485 25486The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a 25487virtual table pointer using type metadata. This intrinsic is used to implement 25488control flow integrity in conjunction with virtual call optimization. The 25489virtual call optimization pass will optimize away ``llvm.type.checked.load`` 25490intrinsics associated with devirtualized calls, thereby removing the type 25491check in cases where it is not needed to enforce the control flow integrity 25492constraint. 25493 25494If the given pointer is associated with a type metadata identifier, this 25495function returns true as the second element of its return value. (Note that 25496the function may also return true if the given pointer is not associated 25497with a type metadata identifier.) If the function's return value's second 25498element is true, the following rules apply to the first element: 25499 25500- If the given pointer is associated with the given type metadata identifier, 25501 it is the function pointer loaded from the given byte offset from the given 25502 pointer. 25503 25504- If the given pointer is not associated with the given type metadata 25505 identifier, it is one of the following (the choice of which is unspecified): 25506 25507 1. The function pointer that would have been loaded from an arbitrarily chosen 25508 (through an unspecified mechanism) pointer associated with the type 25509 metadata. 25510 25511 2. If the function has a non-void return type, a pointer to a function that 25512 returns an unspecified value without causing side effects. 25513 25514If the function's return value's second element is false, the value of the 25515first element is undefined. 25516 25517 25518'``llvm.arithmetic.fence``' Intrinsic 25519^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25520 25521Syntax: 25522""""""" 25523 25524:: 25525 25526 declare <type> 25527 @llvm.arithmetic.fence(<type> <op>) 25528 25529Overview: 25530""""""""" 25531 25532The purpose of the ``llvm.arithmetic.fence`` intrinsic 25533is to prevent the optimizer from performing fast-math optimizations, 25534particularly reassociation, 25535between the argument and the expression that contains the argument. 25536It can be used to preserve the parentheses in the source language. 25537 25538Arguments: 25539"""""""""" 25540 25541The ``llvm.arithmetic.fence`` intrinsic takes only one argument. 25542The argument and the return value are floating-point numbers, 25543or vector floating-point numbers, of the same type. 25544 25545Semantics: 25546"""""""""" 25547 25548This intrinsic returns the value of its operand. The optimizer can optimize 25549the argument, but the optimizer cannot hoist any component of the operand 25550to the containing context, and the optimizer cannot move the calculation of 25551any expression in the containing context into the operand. 25552 25553 25554'``llvm.donothing``' Intrinsic 25555^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25556 25557Syntax: 25558""""""" 25559 25560:: 25561 25562 declare void @llvm.donothing() nounwind readnone 25563 25564Overview: 25565""""""""" 25566 25567The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only 25568three intrinsics (besides ``llvm.experimental.patchpoint`` and 25569``llvm.experimental.gc.statepoint``) that can be called with an invoke 25570instruction. 25571 25572Arguments: 25573"""""""""" 25574 25575None. 25576 25577Semantics: 25578"""""""""" 25579 25580This intrinsic does nothing, and it's removed by optimizers and ignored 25581by codegen. 25582 25583'``llvm.experimental.deoptimize``' Intrinsic 25584^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25585 25586Syntax: 25587""""""" 25588 25589:: 25590 25591 declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ] 25592 25593Overview: 25594""""""""" 25595 25596This intrinsic, together with :ref:`deoptimization operand bundles 25597<deopt_opbundles>`, allow frontends to express transfer of control and 25598frame-local state from the currently executing (typically more specialized, 25599hence faster) version of a function into another (typically more generic, hence 25600slower) version. 25601 25602In languages with a fully integrated managed runtime like Java and JavaScript 25603this intrinsic can be used to implement "uncommon trap" or "side exit" like 25604functionality. In unmanaged languages like C and C++, this intrinsic can be 25605used to represent the slow paths of specialized functions. 25606 25607 25608Arguments: 25609"""""""""" 25610 25611The intrinsic takes an arbitrary number of arguments, whose meaning is 25612decided by the :ref:`lowering strategy<deoptimize_lowering>`. 25613 25614Semantics: 25615"""""""""" 25616 25617The ``@llvm.experimental.deoptimize`` intrinsic executes an attached 25618deoptimization continuation (denoted using a :ref:`deoptimization 25619operand bundle <deopt_opbundles>`) and returns the value returned by 25620the deoptimization continuation. Defining the semantic properties of 25621the continuation itself is out of scope of the language reference -- 25622as far as LLVM is concerned, the deoptimization continuation can 25623invoke arbitrary side effects, including reading from and writing to 25624the entire heap. 25625 25626Deoptimization continuations expressed using ``"deopt"`` operand bundles always 25627continue execution to the end of the physical frame containing them, so all 25628calls to ``@llvm.experimental.deoptimize`` must be in "tail position": 25629 25630 - ``@llvm.experimental.deoptimize`` cannot be invoked. 25631 - The call must immediately precede a :ref:`ret <i_ret>` instruction. 25632 - The ``ret`` instruction must return the value produced by the 25633 ``@llvm.experimental.deoptimize`` call if there is one, or void. 25634 25635Note that the above restrictions imply that the return type for a call to 25636``@llvm.experimental.deoptimize`` will match the return type of its immediate 25637caller. 25638 25639The inliner composes the ``"deopt"`` continuations of the caller into the 25640``"deopt"`` continuations present in the inlinee, and also updates calls to this 25641intrinsic to return directly from the frame of the function it inlined into. 25642 25643All declarations of ``@llvm.experimental.deoptimize`` must share the 25644same calling convention. 25645 25646.. _deoptimize_lowering: 25647 25648Lowering: 25649""""""""" 25650 25651Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the 25652symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to 25653ensure that this symbol is defined). The call arguments to 25654``@llvm.experimental.deoptimize`` are lowered as if they were formal 25655arguments of the specified types, and not as varargs. 25656 25657 25658'``llvm.experimental.guard``' Intrinsic 25659^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25660 25661Syntax: 25662""""""" 25663 25664:: 25665 25666 declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ] 25667 25668Overview: 25669""""""""" 25670 25671This intrinsic, together with :ref:`deoptimization operand bundles 25672<deopt_opbundles>`, allows frontends to express guards or checks on 25673optimistic assumptions made during compilation. The semantics of 25674``@llvm.experimental.guard`` is defined in terms of 25675``@llvm.experimental.deoptimize`` -- its body is defined to be 25676equivalent to: 25677 25678.. code-block:: text 25679 25680 define void @llvm.experimental.guard(i1 %pred, <args...>) { 25681 %realPred = and i1 %pred, undef 25682 br i1 %realPred, label %continue, label %leave [, !make.implicit !{}] 25683 25684 leave: 25685 call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ] 25686 ret void 25687 25688 continue: 25689 ret void 25690 } 25691 25692 25693with the optional ``[, !make.implicit !{}]`` present if and only if it 25694is present on the call site. For more details on ``!make.implicit``, 25695see :doc:`FaultMaps`. 25696 25697In words, ``@llvm.experimental.guard`` executes the attached 25698``"deopt"`` continuation if (but **not** only if) its first argument 25699is ``false``. Since the optimizer is allowed to replace the ``undef`` 25700with an arbitrary value, it can optimize guard to fail "spuriously", 25701i.e. without the original condition being false (hence the "not only 25702if"); and this allows for "check widening" type optimizations. 25703 25704``@llvm.experimental.guard`` cannot be invoked. 25705 25706After ``@llvm.experimental.guard`` was first added, a more general 25707formulation was found in ``@llvm.experimental.widenable.condition``. 25708Support for ``@llvm.experimental.guard`` is slowly being rephrased in 25709terms of this alternate. 25710 25711'``llvm.experimental.widenable.condition``' Intrinsic 25712^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25713 25714Syntax: 25715""""""" 25716 25717:: 25718 25719 declare i1 @llvm.experimental.widenable.condition() 25720 25721Overview: 25722""""""""" 25723 25724This intrinsic represents a "widenable condition" which is 25725boolean expressions with the following property: whether this 25726expression is `true` or `false`, the program is correct and 25727well-defined. 25728 25729Together with :ref:`deoptimization operand bundles <deopt_opbundles>`, 25730``@llvm.experimental.widenable.condition`` allows frontends to 25731express guards or checks on optimistic assumptions made during 25732compilation and represent them as branch instructions on special 25733conditions. 25734 25735While this may appear similar in semantics to `undef`, it is very 25736different in that an invocation produces a particular, singular 25737value. It is also intended to be lowered late, and remain available 25738for specific optimizations and transforms that can benefit from its 25739special properties. 25740 25741Arguments: 25742"""""""""" 25743 25744None. 25745 25746Semantics: 25747"""""""""" 25748 25749The intrinsic ``@llvm.experimental.widenable.condition()`` 25750returns either `true` or `false`. For each evaluation of a call 25751to this intrinsic, the program must be valid and correct both if 25752it returns `true` and if it returns `false`. This allows 25753transformation passes to replace evaluations of this intrinsic 25754with either value whenever one is beneficial. 25755 25756When used in a branch condition, it allows us to choose between 25757two alternative correct solutions for the same problem, like 25758in example below: 25759 25760.. code-block:: text 25761 25762 %cond = call i1 @llvm.experimental.widenable.condition() 25763 br i1 %cond, label %solution_1, label %solution_2 25764 25765 label %fast_path: 25766 ; Apply memory-consuming but fast solution for a task. 25767 25768 label %slow_path: 25769 ; Cheap in memory but slow solution. 25770 25771Whether the result of intrinsic's call is `true` or `false`, 25772it should be correct to pick either solution. We can switch 25773between them by replacing the result of 25774``@llvm.experimental.widenable.condition`` with different 25775`i1` expressions. 25776 25777This is how it can be used to represent guards as widenable branches: 25778 25779.. code-block:: text 25780 25781 block: 25782 ; Unguarded instructions 25783 call void @llvm.experimental.guard(i1 %cond, <args...>) ["deopt"(<deopt_args...>)] 25784 ; Guarded instructions 25785 25786Can be expressed in an alternative equivalent form of explicit branch using 25787``@llvm.experimental.widenable.condition``: 25788 25789.. code-block:: text 25790 25791 block: 25792 ; Unguarded instructions 25793 %widenable_condition = call i1 @llvm.experimental.widenable.condition() 25794 %guard_condition = and i1 %cond, %widenable_condition 25795 br i1 %guard_condition, label %guarded, label %deopt 25796 25797 guarded: 25798 ; Guarded instructions 25799 25800 deopt: 25801 call type @llvm.experimental.deoptimize(<args...>) [ "deopt"(<deopt_args...>) ] 25802 25803So the block `guarded` is only reachable when `%cond` is `true`, 25804and it should be valid to go to the block `deopt` whenever `%cond` 25805is `true` or `false`. 25806 25807``@llvm.experimental.widenable.condition`` will never throw, thus 25808it cannot be invoked. 25809 25810Guard widening: 25811""""""""""""""" 25812 25813When ``@llvm.experimental.widenable.condition()`` is used in 25814condition of a guard represented as explicit branch, it is 25815legal to widen the guard's condition with any additional 25816conditions. 25817 25818Guard widening looks like replacement of 25819 25820.. code-block:: text 25821 25822 %widenable_cond = call i1 @llvm.experimental.widenable.condition() 25823 %guard_cond = and i1 %cond, %widenable_cond 25824 br i1 %guard_cond, label %guarded, label %deopt 25825 25826with 25827 25828.. code-block:: text 25829 25830 %widenable_cond = call i1 @llvm.experimental.widenable.condition() 25831 %new_cond = and i1 %any_other_cond, %widenable_cond 25832 %new_guard_cond = and i1 %cond, %new_cond 25833 br i1 %new_guard_cond, label %guarded, label %deopt 25834 25835for this branch. Here `%any_other_cond` is an arbitrarily chosen 25836well-defined `i1` value. By making guard widening, we may 25837impose stricter conditions on `guarded` block and bail to the 25838deopt when the new condition is not met. 25839 25840Lowering: 25841""""""""" 25842 25843Default lowering strategy is replacing the result of 25844call of ``@llvm.experimental.widenable.condition`` with 25845constant `true`. However it is always correct to replace 25846it with any other `i1` value. Any pass can 25847freely do it if it can benefit from non-default lowering. 25848 25849 25850'``llvm.load.relative``' Intrinsic 25851^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25852 25853Syntax: 25854""""""" 25855 25856:: 25857 25858 declare ptr @llvm.load.relative.iN(ptr %ptr, iN %offset) argmemonly nounwind readonly 25859 25860Overview: 25861""""""""" 25862 25863This intrinsic loads a 32-bit value from the address ``%ptr + %offset``, 25864adds ``%ptr`` to that value and returns it. The constant folder specifically 25865recognizes the form of this intrinsic and the constant initializers it may 25866load from; if a loaded constant initializer is known to have the form 25867``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``. 25868 25869LLVM provides that the calculation of such a constant initializer will 25870not overflow at link time under the medium code model if ``x`` is an 25871``unnamed_addr`` function. However, it does not provide this guarantee for 25872a constant initializer folded into a function body. This intrinsic can be 25873used to avoid the possibility of overflows when loading from such a constant. 25874 25875.. _llvm_sideeffect: 25876 25877'``llvm.sideeffect``' Intrinsic 25878^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25879 25880Syntax: 25881""""""" 25882 25883:: 25884 25885 declare void @llvm.sideeffect() inaccessiblememonly nounwind willreturn 25886 25887Overview: 25888""""""""" 25889 25890The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers 25891treat it as having side effects, so it can be inserted into a loop to 25892indicate that the loop shouldn't be assumed to terminate (which could 25893potentially lead to the loop being optimized away entirely), even if it's 25894an infinite loop with no other side effects. 25895 25896Arguments: 25897"""""""""" 25898 25899None. 25900 25901Semantics: 25902"""""""""" 25903 25904This intrinsic actually does nothing, but optimizers must assume that it 25905has externally observable side effects. 25906 25907'``llvm.is.constant.*``' Intrinsic 25908^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25909 25910Syntax: 25911""""""" 25912 25913This is an overloaded intrinsic. You can use llvm.is.constant with any argument type. 25914 25915:: 25916 25917 declare i1 @llvm.is.constant.i32(i32 %operand) nounwind readnone 25918 declare i1 @llvm.is.constant.f32(float %operand) nounwind readnone 25919 declare i1 @llvm.is.constant.TYPENAME(TYPE %operand) nounwind readnone 25920 25921Overview: 25922""""""""" 25923 25924The '``llvm.is.constant``' intrinsic will return true if the argument 25925is known to be a manifest compile-time constant. It is guaranteed to 25926fold to either true or false before generating machine code. 25927 25928Semantics: 25929"""""""""" 25930 25931This intrinsic generates no code. If its argument is known to be a 25932manifest compile-time constant value, then the intrinsic will be 25933converted to a constant true value. Otherwise, it will be converted to 25934a constant false value. 25935 25936In particular, note that if the argument is a constant expression 25937which refers to a global (the address of which _is_ a constant, but 25938not manifest during the compile), then the intrinsic evaluates to 25939false. 25940 25941The result also intentionally depends on the result of optimization 25942passes -- e.g., the result can change depending on whether a 25943function gets inlined or not. A function's parameters are 25944obviously not constant. However, a call like 25945``llvm.is.constant.i32(i32 %param)`` *can* return true after the 25946function is inlined, if the value passed to the function parameter was 25947a constant. 25948 25949On the other hand, if constant folding is not run, it will never 25950evaluate to true, even in simple cases. 25951 25952.. _int_ptrmask: 25953 25954'``llvm.ptrmask``' Intrinsic 25955^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25956 25957Syntax: 25958""""""" 25959 25960:: 25961 25962 declare ptrty llvm.ptrmask(ptrty %ptr, intty %mask) readnone speculatable 25963 25964Arguments: 25965"""""""""" 25966 25967The first argument is a pointer. The second argument is an integer. 25968 25969Overview: 25970"""""""""" 25971 25972The ``llvm.ptrmask`` intrinsic masks out bits of the pointer according to a mask. 25973This allows stripping data from tagged pointers without converting them to an 25974integer (ptrtoint/inttoptr). As a consequence, we can preserve more information 25975to facilitate alias analysis and underlying-object detection. 25976 25977Semantics: 25978"""""""""" 25979 25980The result of ``ptrmask(ptr, mask)`` is equivalent to 25981``getelementptr ptr, (ptrtoint(ptr) & mask) - ptrtoint(ptr)``. Both the returned 25982pointer and the first argument are based on the same underlying object (for more 25983information on the *based on* terminology see 25984:ref:`the pointer aliasing rules <pointeraliasing>`). If the bitwidth of the 25985mask argument does not match the pointer size of the target, the mask is 25986zero-extended or truncated accordingly. 25987 25988.. _int_threadlocal_address: 25989 25990'``llvm.threadlocal.address``' Intrinsic 25991^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 25992 25993Syntax: 25994""""""" 25995 25996:: 25997 25998 declare ptr @llvm.threadlocal.address(ptr) nounwind readnone willreturn 25999 26000Arguments: 26001"""""""""" 26002 26003The first argument is a pointer, which refers to a thread local global. 26004 26005Semantics: 26006"""""""""" 26007 26008The address of a thread local global is not a constant, since it depends on 26009the calling thread. The `llvm.threadlocal.address` intrinsic returns the 26010address of the given thread local global in the calling thread. 26011 26012.. _int_vscale: 26013 26014'``llvm.vscale``' Intrinsic 26015^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26016 26017Syntax: 26018""""""" 26019 26020:: 26021 26022 declare i32 llvm.vscale.i32() 26023 declare i64 llvm.vscale.i64() 26024 26025Overview: 26026""""""""" 26027 26028The ``llvm.vscale`` intrinsic returns the value for ``vscale`` in scalable 26029vectors such as ``<vscale x 16 x i8>``. 26030 26031Semantics: 26032"""""""""" 26033 26034``vscale`` is a positive value that is constant throughout program 26035execution, but is unknown at compile time. 26036If the result value does not fit in the result type, then the result is 26037a :ref:`poison value <poisonvalues>`. 26038 26039 26040Stack Map Intrinsics 26041-------------------- 26042 26043LLVM provides experimental intrinsics to support runtime patching 26044mechanisms commonly desired in dynamic language JITs. These intrinsics 26045are described in :doc:`StackMaps`. 26046 26047Element Wise Atomic Memory Intrinsics 26048------------------------------------- 26049 26050These intrinsics are similar to the standard library memory intrinsics except 26051that they perform memory transfer as a sequence of atomic memory accesses. 26052 26053.. _int_memcpy_element_unordered_atomic: 26054 26055'``llvm.memcpy.element.unordered.atomic``' Intrinsic 26056^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26057 26058Syntax: 26059""""""" 26060 26061This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on 26062any integer bit width and for different address spaces. Not all targets 26063support all bit widths however. 26064 26065:: 26066 26067 declare void @llvm.memcpy.element.unordered.atomic.p0.p0.i32(ptr <dest>, 26068 ptr <src>, 26069 i32 <len>, 26070 i32 <element_size>) 26071 declare void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr <dest>, 26072 ptr <src>, 26073 i64 <len>, 26074 i32 <element_size>) 26075 26076Overview: 26077""""""""" 26078 26079The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the 26080'``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated 26081as arrays with elements that are exactly ``element_size`` bytes, and the copy between 26082buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations 26083that are a positive integer multiple of the ``element_size`` in size. 26084 26085Arguments: 26086"""""""""" 26087 26088The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>` 26089intrinsic, with the added constraint that ``len`` is required to be a positive integer 26090multiple of the ``element_size``. If ``len`` is not a positive integer multiple of 26091``element_size``, then the behaviour of the intrinsic is undefined. 26092 26093``element_size`` must be a compile-time constant positive power of two no greater than 26094target-specific atomic access size limit. 26095 26096For each of the input pointers ``align`` parameter attribute must be specified. It 26097must be a power of two no less than the ``element_size``. Caller guarantees that 26098both the source and destination pointers are aligned to that boundary. 26099 26100Semantics: 26101"""""""""" 26102 26103The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of 26104memory from the source location to the destination location. These locations are not 26105allowed to overlap. The memory copy is performed as a sequence of load/store operations 26106where each access is guaranteed to be a multiple of ``element_size`` bytes wide and 26107aligned at an ``element_size`` boundary. 26108 26109The order of the copy is unspecified. The same value may be read from the source 26110buffer many times, but only one write is issued to the destination buffer per 26111element. It is well defined to have concurrent reads and writes to both source and 26112destination provided those reads and writes are unordered atomic when specified. 26113 26114This intrinsic does not provide any additional ordering guarantees over those 26115provided by a set of unordered loads from the source location and stores to the 26116destination. 26117 26118Lowering: 26119""""""""" 26120 26121In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is 26122lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*' 26123is replaced with an actual element size. See :ref:`RewriteStatepointsForGC intrinsic 26124lowering <RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific 26125lowering. 26126 26127Optimizer is allowed to inline memory copy when it's profitable to do so. 26128 26129'``llvm.memmove.element.unordered.atomic``' Intrinsic 26130^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26131 26132Syntax: 26133""""""" 26134 26135This is an overloaded intrinsic. You can use 26136``llvm.memmove.element.unordered.atomic`` on any integer bit width and for 26137different address spaces. Not all targets support all bit widths however. 26138 26139:: 26140 26141 declare void @llvm.memmove.element.unordered.atomic.p0.p0.i32(ptr <dest>, 26142 ptr <src>, 26143 i32 <len>, 26144 i32 <element_size>) 26145 declare void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr <dest>, 26146 ptr <src>, 26147 i64 <len>, 26148 i32 <element_size>) 26149 26150Overview: 26151""""""""" 26152 26153The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization 26154of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and 26155``src`` are treated as arrays with elements that are exactly ``element_size`` 26156bytes, and the copy between buffers uses a sequence of 26157:ref:`unordered atomic <ordering>` load/store operations that are a positive 26158integer multiple of the ``element_size`` in size. 26159 26160Arguments: 26161"""""""""" 26162 26163The first three arguments are the same as they are in the 26164:ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that 26165``len`` is required to be a positive integer multiple of the ``element_size``. 26166If ``len`` is not a positive integer multiple of ``element_size``, then the 26167behaviour of the intrinsic is undefined. 26168 26169``element_size`` must be a compile-time constant positive power of two no 26170greater than a target-specific atomic access size limit. 26171 26172For each of the input pointers the ``align`` parameter attribute must be 26173specified. It must be a power of two no less than the ``element_size``. Caller 26174guarantees that both the source and destination pointers are aligned to that 26175boundary. 26176 26177Semantics: 26178"""""""""" 26179 26180The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes 26181of memory from the source location to the destination location. These locations 26182are allowed to overlap. The memory copy is performed as a sequence of load/store 26183operations where each access is guaranteed to be a multiple of ``element_size`` 26184bytes wide and aligned at an ``element_size`` boundary. 26185 26186The order of the copy is unspecified. The same value may be read from the source 26187buffer many times, but only one write is issued to the destination buffer per 26188element. It is well defined to have concurrent reads and writes to both source 26189and destination provided those reads and writes are unordered atomic when 26190specified. 26191 26192This intrinsic does not provide any additional ordering guarantees over those 26193provided by a set of unordered loads from the source location and stores to the 26194destination. 26195 26196Lowering: 26197""""""""" 26198 26199In the most general case call to the 26200'``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol 26201``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an 26202actual element size. See :ref:`RewriteStatepointsForGC intrinsic lowering 26203<RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific 26204lowering. 26205 26206The optimizer is allowed to inline the memory copy when it's profitable to do so. 26207 26208.. _int_memset_element_unordered_atomic: 26209 26210'``llvm.memset.element.unordered.atomic``' Intrinsic 26211^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26212 26213Syntax: 26214""""""" 26215 26216This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on 26217any integer bit width and for different address spaces. Not all targets 26218support all bit widths however. 26219 26220:: 26221 26222 declare void @llvm.memset.element.unordered.atomic.p0.i32(ptr <dest>, 26223 i8 <value>, 26224 i32 <len>, 26225 i32 <element_size>) 26226 declare void @llvm.memset.element.unordered.atomic.p0.i64(ptr <dest>, 26227 i8 <value>, 26228 i64 <len>, 26229 i32 <element_size>) 26230 26231Overview: 26232""""""""" 26233 26234The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the 26235'``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array 26236with elements that are exactly ``element_size`` bytes, and the assignment to that array 26237uses uses a sequence of :ref:`unordered atomic <ordering>` store operations 26238that are a positive integer multiple of the ``element_size`` in size. 26239 26240Arguments: 26241"""""""""" 26242 26243The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>` 26244intrinsic, with the added constraint that ``len`` is required to be a positive integer 26245multiple of the ``element_size``. If ``len`` is not a positive integer multiple of 26246``element_size``, then the behaviour of the intrinsic is undefined. 26247 26248``element_size`` must be a compile-time constant positive power of two no greater than 26249target-specific atomic access size limit. 26250 26251The ``dest`` input pointer must have the ``align`` parameter attribute specified. It 26252must be a power of two no less than the ``element_size``. Caller guarantees that 26253the destination pointer is aligned to that boundary. 26254 26255Semantics: 26256"""""""""" 26257 26258The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of 26259memory starting at the destination location to the given ``value``. The memory is 26260set with a sequence of store operations where each access is guaranteed to be a 26261multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary. 26262 26263The order of the assignment is unspecified. Only one write is issued to the 26264destination buffer per element. It is well defined to have concurrent reads and 26265writes to the destination provided those reads and writes are unordered atomic 26266when specified. 26267 26268This intrinsic does not provide any additional ordering guarantees over those 26269provided by a set of unordered stores to the destination. 26270 26271Lowering: 26272""""""""" 26273 26274In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is 26275lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*' 26276is replaced with an actual element size. 26277 26278The optimizer is allowed to inline the memory assignment when it's profitable to do so. 26279 26280Objective-C ARC Runtime Intrinsics 26281---------------------------------- 26282 26283LLVM provides intrinsics that lower to Objective-C ARC runtime entry points. 26284LLVM is aware of the semantics of these functions, and optimizes based on that 26285knowledge. You can read more about the details of Objective-C ARC `here 26286<https://clang.llvm.org/docs/AutomaticReferenceCounting.html>`_. 26287 26288'``llvm.objc.autorelease``' Intrinsic 26289^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26290 26291Syntax: 26292""""""" 26293:: 26294 26295 declare ptr @llvm.objc.autorelease(ptr) 26296 26297Lowering: 26298""""""""" 26299 26300Lowers to a call to `objc_autorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autorelease>`_. 26301 26302'``llvm.objc.autoreleasePoolPop``' Intrinsic 26303^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26304 26305Syntax: 26306""""""" 26307:: 26308 26309 declare void @llvm.objc.autoreleasePoolPop(ptr) 26310 26311Lowering: 26312""""""""" 26313 26314Lowers to a call to `objc_autoreleasePoolPop <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpop-void-pool>`_. 26315 26316'``llvm.objc.autoreleasePoolPush``' Intrinsic 26317^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26318 26319Syntax: 26320""""""" 26321:: 26322 26323 declare ptr @llvm.objc.autoreleasePoolPush() 26324 26325Lowering: 26326""""""""" 26327 26328Lowers to a call to `objc_autoreleasePoolPush <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpush-void>`_. 26329 26330'``llvm.objc.autoreleaseReturnValue``' Intrinsic 26331^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26332 26333Syntax: 26334""""""" 26335:: 26336 26337 declare ptr @llvm.objc.autoreleaseReturnValue(ptr) 26338 26339Lowering: 26340""""""""" 26341 26342Lowers to a call to `objc_autoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue>`_. 26343 26344'``llvm.objc.copyWeak``' Intrinsic 26345^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26346 26347Syntax: 26348""""""" 26349:: 26350 26351 declare void @llvm.objc.copyWeak(ptr, ptr) 26352 26353Lowering: 26354""""""""" 26355 26356Lowers to a call to `objc_copyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-copyweak-id-dest-id-src>`_. 26357 26358'``llvm.objc.destroyWeak``' Intrinsic 26359^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26360 26361Syntax: 26362""""""" 26363:: 26364 26365 declare void @llvm.objc.destroyWeak(ptr) 26366 26367Lowering: 26368""""""""" 26369 26370Lowers to a call to `objc_destroyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-destroyweak-id-object>`_. 26371 26372'``llvm.objc.initWeak``' Intrinsic 26373^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26374 26375Syntax: 26376""""""" 26377:: 26378 26379 declare ptr @llvm.objc.initWeak(ptr, ptr) 26380 26381Lowering: 26382""""""""" 26383 26384Lowers to a call to `objc_initWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-initweak>`_. 26385 26386'``llvm.objc.loadWeak``' Intrinsic 26387^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26388 26389Syntax: 26390""""""" 26391:: 26392 26393 declare ptr @llvm.objc.loadWeak(ptr) 26394 26395Lowering: 26396""""""""" 26397 26398Lowers to a call to `objc_loadWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweak>`_. 26399 26400'``llvm.objc.loadWeakRetained``' Intrinsic 26401^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26402 26403Syntax: 26404""""""" 26405:: 26406 26407 declare ptr @llvm.objc.loadWeakRetained(ptr) 26408 26409Lowering: 26410""""""""" 26411 26412Lowers to a call to `objc_loadWeakRetained <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweakretained>`_. 26413 26414'``llvm.objc.moveWeak``' Intrinsic 26415^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26416 26417Syntax: 26418""""""" 26419:: 26420 26421 declare void @llvm.objc.moveWeak(ptr, ptr) 26422 26423Lowering: 26424""""""""" 26425 26426Lowers to a call to `objc_moveWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-moveweak-id-dest-id-src>`_. 26427 26428'``llvm.objc.release``' Intrinsic 26429^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26430 26431Syntax: 26432""""""" 26433:: 26434 26435 declare void @llvm.objc.release(ptr) 26436 26437Lowering: 26438""""""""" 26439 26440Lowers to a call to `objc_release <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-release-id-value>`_. 26441 26442'``llvm.objc.retain``' Intrinsic 26443^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26444 26445Syntax: 26446""""""" 26447:: 26448 26449 declare ptr @llvm.objc.retain(ptr) 26450 26451Lowering: 26452""""""""" 26453 26454Lowers to a call to `objc_retain <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>`_. 26455 26456'``llvm.objc.retainAutorelease``' Intrinsic 26457^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26458 26459Syntax: 26460""""""" 26461:: 26462 26463 declare ptr @llvm.objc.retainAutorelease(ptr) 26464 26465Lowering: 26466""""""""" 26467 26468Lowers to a call to `objc_retainAutorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautorelease>`_. 26469 26470'``llvm.objc.retainAutoreleaseReturnValue``' Intrinsic 26471^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26472 26473Syntax: 26474""""""" 26475:: 26476 26477 declare ptr @llvm.objc.retainAutoreleaseReturnValue(ptr) 26478 26479Lowering: 26480""""""""" 26481 26482Lowers to a call to `objc_retainAutoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasereturnvalue>`_. 26483 26484'``llvm.objc.retainAutoreleasedReturnValue``' Intrinsic 26485^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26486 26487Syntax: 26488""""""" 26489:: 26490 26491 declare ptr @llvm.objc.retainAutoreleasedReturnValue(ptr) 26492 26493Lowering: 26494""""""""" 26495 26496Lowers to a call to `objc_retainAutoreleasedReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasedreturnvalue>`_. 26497 26498'``llvm.objc.retainBlock``' Intrinsic 26499^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26500 26501Syntax: 26502""""""" 26503:: 26504 26505 declare ptr @llvm.objc.retainBlock(ptr) 26506 26507Lowering: 26508""""""""" 26509 26510Lowers to a call to `objc_retainBlock <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainblock>`_. 26511 26512'``llvm.objc.storeStrong``' Intrinsic 26513^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26514 26515Syntax: 26516""""""" 26517:: 26518 26519 declare void @llvm.objc.storeStrong(ptr, ptr) 26520 26521Lowering: 26522""""""""" 26523 26524Lowers to a call to `objc_storeStrong <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-storestrong-id-object-id-value>`_. 26525 26526'``llvm.objc.storeWeak``' Intrinsic 26527^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26528 26529Syntax: 26530""""""" 26531:: 26532 26533 declare ptr @llvm.objc.storeWeak(ptr, ptr) 26534 26535Lowering: 26536""""""""" 26537 26538Lowers to a call to `objc_storeWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-storeweak>`_. 26539 26540Preserving Debug Information Intrinsics 26541^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26542 26543These intrinsics are used to carry certain debuginfo together with 26544IR-level operations. For example, it may be desirable to 26545know the structure/union name and the original user-level field 26546indices. Such information got lost in IR GetElementPtr instruction 26547since the IR types are different from debugInfo types and unions 26548are converted to structs in IR. 26549 26550'``llvm.preserve.array.access.index``' Intrinsic 26551^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26552 26553Syntax: 26554""""""" 26555:: 26556 26557 declare <ret_type> 26558 @llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons(<type> base, 26559 i32 dim, 26560 i32 index) 26561 26562Overview: 26563""""""""" 26564 26565The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address 26566based on array base ``base``, array dimension ``dim`` and the last access index ``index`` 26567into the array. The return type ``ret_type`` is a pointer type to the array element. 26568The array ``dim`` and ``index`` are preserved which is more robust than 26569getelementptr instruction which may be subject to compiler transformation. 26570The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 26571to provide array or pointer debuginfo type. 26572The metadata is a ``DICompositeType`` or ``DIDerivedType`` representing the 26573debuginfo version of ``type``. 26574 26575Arguments: 26576"""""""""" 26577 26578The ``base`` is the array base address. The ``dim`` is the array dimension. 26579The ``base`` is a pointer if ``dim`` equals 0. 26580The ``index`` is the last access index into the array or pointer. 26581 26582The ``base`` argument must be annotated with an :ref:`elementtype 26583<attr_elementtype>` attribute at the call-site. This attribute specifies the 26584getelementptr element type. 26585 26586Semantics: 26587"""""""""" 26588 26589The '``llvm.preserve.array.access.index``' intrinsic produces the same result 26590as a getelementptr with base ``base`` and access operands ``{dim's 0's, index}``. 26591 26592'``llvm.preserve.union.access.index``' Intrinsic 26593^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26594 26595Syntax: 26596""""""" 26597:: 26598 26599 declare <type> 26600 @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(<type> base, 26601 i32 di_index) 26602 26603Overview: 26604""""""""" 26605 26606The '``llvm.preserve.union.access.index``' intrinsic carries the debuginfo field index 26607``di_index`` and returns the ``base`` address. 26608The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 26609to provide union debuginfo type. 26610The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``. 26611The return type ``type`` is the same as the ``base`` type. 26612 26613Arguments: 26614"""""""""" 26615 26616The ``base`` is the union base address. The ``di_index`` is the field index in debuginfo. 26617 26618Semantics: 26619"""""""""" 26620 26621The '``llvm.preserve.union.access.index``' intrinsic returns the ``base`` address. 26622 26623'``llvm.preserve.struct.access.index``' Intrinsic 26624^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26625 26626Syntax: 26627""""""" 26628:: 26629 26630 declare <ret_type> 26631 @llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s(<type> base, 26632 i32 gep_index, 26633 i32 di_index) 26634 26635Overview: 26636""""""""" 26637 26638The '``llvm.preserve.struct.access.index``' intrinsic returns the getelementptr address 26639based on struct base ``base`` and IR struct member index ``gep_index``. 26640The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 26641to provide struct debuginfo type. 26642The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``. 26643The return type ``ret_type`` is a pointer type to the structure member. 26644 26645Arguments: 26646"""""""""" 26647 26648The ``base`` is the structure base address. The ``gep_index`` is the struct member index 26649based on IR structures. The ``di_index`` is the struct member index based on debuginfo. 26650 26651The ``base`` argument must be annotated with an :ref:`elementtype 26652<attr_elementtype>` attribute at the call-site. This attribute specifies the 26653getelementptr element type. 26654 26655Semantics: 26656"""""""""" 26657 26658The '``llvm.preserve.struct.access.index``' intrinsic produces the same result 26659as a getelementptr with base ``base`` and access operands ``{0, gep_index}``. 26660 26661'``llvm.fptrunc.round``' Intrinsic 26662^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26663 26664Syntax: 26665""""""" 26666 26667:: 26668 26669 declare <ty2> 26670 @llvm.fptrunc.round(<type> <value>, metadata <rounding mode>) 26671 26672Overview: 26673""""""""" 26674 26675The '``llvm.fptrunc.round``' intrinsic truncates 26676:ref:`floating-point <t_floating>` ``value`` to type ``ty2`` 26677with a specified rounding mode. 26678 26679Arguments: 26680"""""""""" 26681 26682The '``llvm.fptrunc.round``' intrinsic takes a :ref:`floating-point 26683<t_floating>` value to cast and a :ref:`floating-point <t_floating>` type 26684to cast it to. This argument must be larger in size than the result. 26685 26686The second argument specifies the rounding mode as described in the constrained 26687intrinsics section. 26688For this intrinsic, the "round.dynamic" mode is not supported. 26689 26690Semantics: 26691"""""""""" 26692 26693The '``llvm.fptrunc.round``' intrinsic casts a ``value`` from a larger 26694:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point 26695<t_floating>` type. 26696This intrinsic is assumed to execute in the default :ref:`floating-point 26697environment <floatenv>` *except* for the rounding mode. 26698This intrinsic is not supported on all targets. Some targets may not support 26699all rounding modes. 26700