1============================== 2LLVM Language Reference Manual 3============================== 4 5.. contents:: 6 :local: 7 :depth: 4 8 9Abstract 10======== 11 12This document is a reference manual for the LLVM assembly language. LLVM 13is a Static Single Assignment (SSA) based representation that provides 14type safety, low-level operations, flexibility, and the capability of 15representing 'all' high-level languages cleanly. It is the common code 16representation used throughout all phases of the LLVM compilation 17strategy. 18 19Introduction 20============ 21 22The LLVM code representation is designed to be used in three different 23forms: as an in-memory compiler IR, as an on-disk bitcode representation 24(suitable for fast loading by a Just-In-Time compiler), and as a human 25readable assembly language representation. This allows LLVM to provide a 26powerful intermediate representation for efficient compiler 27transformations and analysis, while providing a natural means to debug 28and visualize the transformations. The three different forms of LLVM are 29all equivalent. This document describes the human readable 30representation and notation. 31 32The LLVM representation aims to be light-weight and low-level while 33being expressive, typed, and extensible at the same time. It aims to be 34a "universal IR" of sorts, by being at a low enough level that 35high-level ideas may be cleanly mapped to it (similar to how 36microprocessors are "universal IR's", allowing many source languages to 37be mapped to them). By providing type information, LLVM can be used as 38the target of optimizations: for example, through pointer analysis, it 39can be proven that a C automatic variable is never accessed outside of 40the current function, allowing it to be promoted to a simple SSA value 41instead of a memory location. 42 43.. _wellformed: 44 45Well-Formedness 46--------------- 47 48It is important to note that this document describes 'well formed' LLVM 49assembly language. There is a difference between what the parser accepts 50and what is considered 'well formed'. For example, the following 51instruction is syntactically okay, but not well formed: 52 53.. code-block:: llvm 54 55 %x = add i32 1, %x 56 57because the definition of ``%x`` does not dominate all of its uses. The 58LLVM infrastructure provides a verification pass that may be used to 59verify that an LLVM module is well formed. This pass is automatically 60run by the parser after parsing input assembly and by the optimizer 61before it outputs bitcode. The violations pointed out by the verifier 62pass indicate bugs in transformation passes or input to the parser. 63 64.. _identifiers: 65 66Identifiers 67=========== 68 69LLVM identifiers come in two basic types: global and local. Global 70identifiers (functions, global variables) begin with the ``'@'`` 71character. Local identifiers (register names, types) begin with the 72``'%'`` character. Additionally, there are three different formats for 73identifiers, for different purposes: 74 75#. Named values are represented as a string of characters with their 76 prefix. For example, ``%foo``, ``@DivisionByZero``, 77 ``%a.really.long.identifier``. The actual regular expression used is 78 '``[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*``'. Identifiers that require other 79 characters in their names can be surrounded with quotes. Special 80 characters may be escaped using ``"\xx"`` where ``xx`` is the ASCII 81 code for the character in hexadecimal. In this way, any character can 82 be used in a name value, even quotes themselves. The ``"\01"`` prefix 83 can be used on global values to suppress mangling. 84#. Unnamed values are represented as an unsigned numeric value with 85 their prefix. For example, ``%12``, ``@2``, ``%44``. 86#. Constants, which are described in the section Constants_ below. 87 88LLVM requires that values start with a prefix for two reasons: Compilers 89don't need to worry about name clashes with reserved words, and the set 90of reserved words may be expanded in the future without penalty. 91Additionally, unnamed identifiers allow a compiler to quickly come up 92with a temporary variable without having to avoid symbol table 93conflicts. 94 95Reserved words in LLVM are very similar to reserved words in other 96languages. There are keywords for different opcodes ('``add``', 97'``bitcast``', '``ret``', etc...), for primitive type names ('``void``', 98'``i32``', etc...), and others. These reserved words cannot conflict 99with variable names, because none of them start with a prefix character 100(``'%'`` or ``'@'``). 101 102Here is an example of LLVM code to multiply the integer variable 103'``%X``' by 8: 104 105The easy way: 106 107.. code-block:: llvm 108 109 %result = mul i32 %X, 8 110 111After strength reduction: 112 113.. code-block:: llvm 114 115 %result = shl i32 %X, 3 116 117And the hard way: 118 119.. code-block:: llvm 120 121 %0 = add i32 %X, %X ; yields i32:%0 122 %1 = add i32 %0, %0 ; yields i32:%1 123 %result = add i32 %1, %1 124 125This last way of multiplying ``%X`` by 8 illustrates several important 126lexical features of LLVM: 127 128#. Comments are delimited with a '``;``' and go until the end of line. 129#. Unnamed temporaries are created when the result of a computation is 130 not assigned to a named value. 131#. Unnamed temporaries are numbered sequentially (using a per-function 132 incrementing counter, starting with 0). Note that basic blocks and unnamed 133 function parameters are included in this numbering. For example, if the 134 entry basic block is not given a label name and all function parameters are 135 named, then it will get number 0. 136 137It also shows a convention that we follow in this document. When 138demonstrating instructions, we will follow an instruction with a comment 139that defines the type and name of value produced. 140 141High Level Structure 142==================== 143 144Module Structure 145---------------- 146 147LLVM programs are composed of ``Module``'s, each of which is a 148translation unit of the input programs. Each module consists of 149functions, global variables, and symbol table entries. Modules may be 150combined together with the LLVM linker, which merges function (and 151global variable) definitions, resolves forward declarations, and merges 152symbol table entries. Here is an example of the "hello world" module: 153 154.. code-block:: llvm 155 156 ; Declare the string constant as a global constant. 157 @.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00" 158 159 ; External declaration of the puts function 160 declare i32 @puts(i8* nocapture) nounwind 161 162 ; Definition of main function 163 define i32 @main() { ; i32()* 164 ; Convert [13 x i8]* to i8*... 165 %cast210 = getelementptr [13 x i8], [13 x i8]* @.str, i64 0, i64 0 166 167 ; Call puts function to write out the string to stdout. 168 call i32 @puts(i8* %cast210) 169 ret i32 0 170 } 171 172 ; Named metadata 173 !0 = !{i32 42, null, !"string"} 174 !foo = !{!0} 175 176This example is made up of a :ref:`global variable <globalvars>` named 177"``.str``", an external declaration of the "``puts``" function, a 178:ref:`function definition <functionstructure>` for "``main``" and 179:ref:`named metadata <namedmetadatastructure>` "``foo``". 180 181In general, a module is made up of a list of global values (where both 182functions and global variables are global values). Global values are 183represented by a pointer to a memory location (in this case, a pointer 184to an array of char, and a pointer to a function), and have one of the 185following :ref:`linkage types <linkage>`. 186 187.. _linkage: 188 189Linkage Types 190------------- 191 192All Global Variables and Functions have one of the following types of 193linkage: 194 195``private`` 196 Global values with "``private``" linkage are only directly 197 accessible by objects in the current module. In particular, linking 198 code into a module with a private global value may cause the 199 private to be renamed as necessary to avoid collisions. Because the 200 symbol is private to the module, all references can be updated. This 201 doesn't show up in any symbol table in the object file. 202``internal`` 203 Similar to private, but the value shows as a local symbol 204 (``STB_LOCAL`` in the case of ELF) in the object file. This 205 corresponds to the notion of the '``static``' keyword in C. 206``available_externally`` 207 Globals with "``available_externally``" linkage are never emitted into 208 the object file corresponding to the LLVM module. From the linker's 209 perspective, an ``available_externally`` global is equivalent to 210 an external declaration. They exist to allow inlining and other 211 optimizations to take place given knowledge of the definition of the 212 global, which is known to be somewhere outside the module. Globals 213 with ``available_externally`` linkage are allowed to be discarded at 214 will, and allow inlining and other optimizations. This linkage type is 215 only allowed on definitions, not declarations. 216``linkonce`` 217 Globals with "``linkonce``" linkage are merged with other globals of 218 the same name when linkage occurs. This can be used to implement 219 some forms of inline functions, templates, or other code which must 220 be generated in each translation unit that uses it, but where the 221 body may be overridden with a more definitive definition later. 222 Unreferenced ``linkonce`` globals are allowed to be discarded. Note 223 that ``linkonce`` linkage does not actually allow the optimizer to 224 inline the body of this function into callers because it doesn't 225 know if this definition of the function is the definitive definition 226 within the program or whether it will be overridden by a stronger 227 definition. To enable inlining and other optimizations, use 228 "``linkonce_odr``" linkage. 229``weak`` 230 "``weak``" linkage has the same merging semantics as ``linkonce`` 231 linkage, except that unreferenced globals with ``weak`` linkage may 232 not be discarded. This is used for globals that are declared "weak" 233 in C source code. 234``common`` 235 "``common``" linkage is most similar to "``weak``" linkage, but they 236 are used for tentative definitions in C, such as "``int X;``" at 237 global scope. Symbols with "``common``" linkage are merged in the 238 same way as ``weak symbols``, and they may not be deleted if 239 unreferenced. ``common`` symbols may not have an explicit section, 240 must have a zero initializer, and may not be marked 241 ':ref:`constant <globalvars>`'. Functions and aliases may not have 242 common linkage. 243 244.. _linkage_appending: 245 246``appending`` 247 "``appending``" linkage may only be applied to global variables of 248 pointer to array type. When two global variables with appending 249 linkage are linked together, the two global arrays are appended 250 together. This is the LLVM, typesafe, equivalent of having the 251 system linker append together "sections" with identical names when 252 .o files are linked. 253 254 Unfortunately this doesn't correspond to any feature in .o files, so it 255 can only be used for variables like ``llvm.global_ctors`` which llvm 256 interprets specially. 257 258``extern_weak`` 259 The semantics of this linkage follow the ELF object file model: the 260 symbol is weak until linked, if not linked, the symbol becomes null 261 instead of being an undefined reference. 262``linkonce_odr``, ``weak_odr`` 263 Some languages allow differing globals to be merged, such as two 264 functions with different semantics. Other languages, such as 265 ``C++``, ensure that only equivalent globals are ever merged (the 266 "one definition rule" --- "ODR"). Such languages can use the 267 ``linkonce_odr`` and ``weak_odr`` linkage types to indicate that the 268 global will only be merged with equivalent globals. These linkage 269 types are otherwise the same as their non-``odr`` versions. 270``external`` 271 If none of the above identifiers are used, the global is externally 272 visible, meaning that it participates in linkage and can be used to 273 resolve external symbol references. 274 275It is illegal for a global variable or function *declaration* to have any 276linkage type other than ``external`` or ``extern_weak``. 277 278.. _callingconv: 279 280Calling Conventions 281------------------- 282 283LLVM :ref:`functions <functionstructure>`, :ref:`calls <i_call>` and 284:ref:`invokes <i_invoke>` can all have an optional calling convention 285specified for the call. The calling convention of any pair of dynamic 286caller/callee must match, or the behavior of the program is undefined. 287The following calling conventions are supported by LLVM, and more may be 288added in the future: 289 290"``ccc``" - The C calling convention 291 This calling convention (the default if no other calling convention 292 is specified) matches the target C calling conventions. This calling 293 convention supports varargs function calls and tolerates some 294 mismatch in the declared prototype and implemented declaration of 295 the function (as does normal C). 296"``fastcc``" - The fast calling convention 297 This calling convention attempts to make calls as fast as possible 298 (e.g. by passing things in registers). This calling convention 299 allows the target to use whatever tricks it wants to produce fast 300 code for the target, without having to conform to an externally 301 specified ABI (Application Binary Interface). `Tail calls can only 302 be optimized when this, the tailcc, the GHC or the HiPE convention is 303 used. <CodeGenerator.html#tail-call-optimization>`_ This calling 304 convention does not support varargs and requires the prototype of all 305 callees to exactly match the prototype of the function definition. 306"``coldcc``" - The cold calling convention 307 This calling convention attempts to make code in the caller as 308 efficient as possible under the assumption that the call is not 309 commonly executed. As such, these calls often preserve all registers 310 so that the call does not break any live ranges in the caller side. 311 This calling convention does not support varargs and requires the 312 prototype of all callees to exactly match the prototype of the 313 function definition. Furthermore the inliner doesn't consider such function 314 calls for inlining. 315"``cc 10``" - GHC convention 316 This calling convention has been implemented specifically for use by 317 the `Glasgow Haskell Compiler (GHC) <http://www.haskell.org/ghc>`_. 318 It passes everything in registers, going to extremes to achieve this 319 by disabling callee save registers. This calling convention should 320 not be used lightly but only for specific situations such as an 321 alternative to the *register pinning* performance technique often 322 used when implementing functional programming languages. At the 323 moment only X86 supports this convention and it has the following 324 limitations: 325 326 - On *X86-32* only supports up to 4 bit type parameters. No 327 floating-point types are supported. 328 - On *X86-64* only supports up to 10 bit type parameters and 6 329 floating-point parameters. 330 331 This calling convention supports `tail call 332 optimization <CodeGenerator.html#tail-call-optimization>`_ but requires 333 both the caller and callee are using it. 334"``cc 11``" - The HiPE calling convention 335 This calling convention has been implemented specifically for use by 336 the `High-Performance Erlang 337 (HiPE) <http://www.it.uu.se/research/group/hipe/>`_ compiler, *the* 338 native code compiler of the `Ericsson's Open Source Erlang/OTP 339 system <http://www.erlang.org/download.shtml>`_. It uses more 340 registers for argument passing than the ordinary C calling 341 convention and defines no callee-saved registers. The calling 342 convention properly supports `tail call 343 optimization <CodeGenerator.html#tail-call-optimization>`_ but requires 344 that both the caller and the callee use it. It uses a *register pinning* 345 mechanism, similar to GHC's convention, for keeping frequently 346 accessed runtime components pinned to specific hardware registers. 347 At the moment only X86 supports this convention (both 32 and 64 348 bit). 349"``webkit_jscc``" - WebKit's JavaScript calling convention 350 This calling convention has been implemented for `WebKit FTL JIT 351 <https://trac.webkit.org/wiki/FTLJIT>`_. It passes arguments on the 352 stack right to left (as cdecl does), and returns a value in the 353 platform's customary return register. 354"``anyregcc``" - Dynamic calling convention for code patching 355 This is a special convention that supports patching an arbitrary code 356 sequence in place of a call site. This convention forces the call 357 arguments into registers but allows them to be dynamically 358 allocated. This can currently only be used with calls to 359 llvm.experimental.patchpoint because only this intrinsic records 360 the location of its arguments in a side table. See :doc:`StackMaps`. 361"``preserve_mostcc``" - The `PreserveMost` calling convention 362 This calling convention attempts to make the code in the caller as 363 unintrusive as possible. This convention behaves identically to the `C` 364 calling convention on how arguments and return values are passed, but it 365 uses a different set of caller/callee-saved registers. This alleviates the 366 burden of saving and recovering a large register set before and after the 367 call in the caller. If the arguments are passed in callee-saved registers, 368 then they will be preserved by the callee across the call. This doesn't 369 apply for values returned in callee-saved registers. 370 371 - On X86-64 the callee preserves all general purpose registers, except for 372 R11. R11 can be used as a scratch register. Floating-point registers 373 (XMMs/YMMs) are not preserved and need to be saved by the caller. 374 375 The idea behind this convention is to support calls to runtime functions 376 that have a hot path and a cold path. The hot path is usually a small piece 377 of code that doesn't use many registers. The cold path might need to call out to 378 another function and therefore only needs to preserve the caller-saved 379 registers, which haven't already been saved by the caller. The 380 `PreserveMost` calling convention is very similar to the `cold` calling 381 convention in terms of caller/callee-saved registers, but they are used for 382 different types of function calls. `coldcc` is for function calls that are 383 rarely executed, whereas `preserve_mostcc` function calls are intended to be 384 on the hot path and definitely executed a lot. Furthermore `preserve_mostcc` 385 doesn't prevent the inliner from inlining the function call. 386 387 This calling convention will be used by a future version of the ObjectiveC 388 runtime and should therefore still be considered experimental at this time. 389 Although this convention was created to optimize certain runtime calls to 390 the ObjectiveC runtime, it is not limited to this runtime and might be used 391 by other runtimes in the future too. The current implementation only 392 supports X86-64, but the intention is to support more architectures in the 393 future. 394"``preserve_allcc``" - The `PreserveAll` calling convention 395 This calling convention attempts to make the code in the caller even less 396 intrusive than the `PreserveMost` calling convention. This calling 397 convention also behaves identical to the `C` calling convention on how 398 arguments and return values are passed, but it uses a different set of 399 caller/callee-saved registers. This removes the burden of saving and 400 recovering a large register set before and after the call in the caller. If 401 the arguments are passed in callee-saved registers, then they will be 402 preserved by the callee across the call. This doesn't apply for values 403 returned in callee-saved registers. 404 405 - On X86-64 the callee preserves all general purpose registers, except for 406 R11. R11 can be used as a scratch register. Furthermore it also preserves 407 all floating-point registers (XMMs/YMMs). 408 409 The idea behind this convention is to support calls to runtime functions 410 that don't need to call out to any other functions. 411 412 This calling convention, like the `PreserveMost` calling convention, will be 413 used by a future version of the ObjectiveC runtime and should be considered 414 experimental at this time. 415"``cxx_fast_tlscc``" - The `CXX_FAST_TLS` calling convention for access functions 416 Clang generates an access function to access C++-style TLS. The access 417 function generally has an entry block, an exit block and an initialization 418 block that is run at the first time. The entry and exit blocks can access 419 a few TLS IR variables, each access will be lowered to a platform-specific 420 sequence. 421 422 This calling convention aims to minimize overhead in the caller by 423 preserving as many registers as possible (all the registers that are 424 preserved on the fast path, composed of the entry and exit blocks). 425 426 This calling convention behaves identical to the `C` calling convention on 427 how arguments and return values are passed, but it uses a different set of 428 caller/callee-saved registers. 429 430 Given that each platform has its own lowering sequence, hence its own set 431 of preserved registers, we can't use the existing `PreserveMost`. 432 433 - On X86-64 the callee preserves all general purpose registers, except for 434 RDI and RAX. 435"``tailcc``" - Tail callable calling convention 436 This calling convention ensures that calls in tail position will always be 437 tail call optimized. This calling convention is equivalent to fastcc, 438 except for an additional guarantee that tail calls will be produced 439 whenever possible. `Tail calls can only be optimized when this, the fastcc, 440 the GHC or the HiPE convention is used. <CodeGenerator.html#tail-call-optimization>`_ 441 This calling convention does not support varargs and requires the prototype of 442 all callees to exactly match the prototype of the function definition. 443"``swiftcc``" - This calling convention is used for Swift language. 444 - On X86-64 RCX and R8 are available for additional integer returns, and 445 XMM2 and XMM3 are available for additional FP/vector returns. 446 - On iOS platforms, we use AAPCS-VFP calling convention. 447"``swifttailcc``" 448 This calling convention is like ``swiftcc`` in most respects, but also the 449 callee pops the argument area of the stack so that mandatory tail calls are 450 possible as in ``tailcc``. 451"``cfguard_checkcc``" - Windows Control Flow Guard (Check mechanism) 452 This calling convention is used for the Control Flow Guard check function, 453 calls to which can be inserted before indirect calls to check that the call 454 target is a valid function address. The check function has no return value, 455 but it will trigger an OS-level error if the address is not a valid target. 456 The set of registers preserved by the check function, and the register 457 containing the target address are architecture-specific. 458 459 - On X86 the target address is passed in ECX. 460 - On ARM the target address is passed in R0. 461 - On AArch64 the target address is passed in X15. 462"``cc <n>``" - Numbered convention 463 Any calling convention may be specified by number, allowing 464 target-specific calling conventions to be used. Target specific 465 calling conventions start at 64. 466 467More calling conventions can be added/defined on an as-needed basis, to 468support Pascal conventions or any other well-known target-independent 469convention. 470 471.. _visibilitystyles: 472 473Visibility Styles 474----------------- 475 476All Global Variables and Functions have one of the following visibility 477styles: 478 479"``default``" - Default style 480 On targets that use the ELF object file format, default visibility 481 means that the declaration is visible to other modules and, in 482 shared libraries, means that the declared entity may be overridden. 483 On Darwin, default visibility means that the declaration is visible 484 to other modules. 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 "``dllexport``" causes the compiler to provide a global pointer to a pointer 516 in a DLL, so that it can be referenced with the ``dllimport`` attribute. On 517 Microsoft Windows targets, the pointer name is formed by combining 518 ``__imp_`` and the function or variable name. Since this storage class 519 exists for defining a dll interface, the compiler, assembler and linker know 520 it is externally referenced and must refrain from deleting the symbol. 521 522.. _tls_model: 523 524Thread Local Storage Models 525--------------------------- 526 527A variable may be defined as ``thread_local``, which means that it will 528not be shared by threads (each thread will have a separated copy of the 529variable). Not all targets support thread-local variables. Optionally, a 530TLS model may be specified: 531 532``localdynamic`` 533 For variables that are only used within the current shared library. 534``initialexec`` 535 For variables in modules that will not be loaded dynamically. 536``localexec`` 537 For variables defined in the executable and only used within it. 538 539If no explicit model is given, the "general dynamic" model is used. 540 541The models correspond to the ELF TLS models; see `ELF Handling For 542Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for 543more information on under which circumstances the different models may 544be used. The target may choose a different TLS model if the specified 545model is not supported, or if a better choice of model can be made. 546 547A model can also be specified in an alias, but then it only governs how 548the alias is accessed. It will not have any effect in the aliasee. 549 550For platforms without linker support of ELF TLS model, the -femulated-tls 551flag can be used to generate GCC compatible emulated TLS code. 552 553.. _runtime_preemption_model: 554 555Runtime Preemption Specifiers 556----------------------------- 557 558Global variables, functions and aliases may have an optional runtime preemption 559specifier. If a preemption specifier isn't given explicitly, then a 560symbol is assumed to be ``dso_preemptable``. 561 562``dso_preemptable`` 563 Indicates that the function or variable may be replaced by a symbol from 564 outside the linkage unit at runtime. 565 566``dso_local`` 567 The compiler may assume that a function or variable marked as ``dso_local`` 568 will resolve to a symbol within the same linkage unit. Direct access will 569 be generated even if the definition is not within this compilation unit. 570 571.. _namedtypes: 572 573Structure Types 574--------------- 575 576LLVM IR allows you to specify both "identified" and "literal" :ref:`structure 577types <t_struct>`. Literal types are uniqued structurally, but identified types 578are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used 579to forward declare a type that is not yet available. 580 581An example of an identified structure specification is: 582 583.. code-block:: llvm 584 585 %mytype = type { %mytype*, i32 } 586 587Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only 588literal types are uniqued in recent versions of LLVM. 589 590.. _nointptrtype: 591 592Non-Integral Pointer Type 593------------------------- 594 595Note: non-integral pointer types are a work in progress, and they should be 596considered experimental at this time. 597 598LLVM IR optionally allows the frontend to denote pointers in certain address 599spaces as "non-integral" via the :ref:`datalayout string<langref_datalayout>`. 600Non-integral pointer types represent pointers that have an *unspecified* bitwise 601representation; that is, the integral representation may be target dependent or 602unstable (not backed by a fixed integer). 603 604``inttoptr`` and ``ptrtoint`` instructions have the same semantics as for 605integral (i.e. normal) pointers in that they convert integers to and from 606corresponding pointer types, but there are additional implications to be 607aware of. Because the bit-representation of a non-integral pointer may 608not be stable, two identical casts of the same operand may or may not 609return the same value. Said differently, the conversion to or from the 610non-integral type depends on environmental state in an implementation 611defined manner. 612 613If the frontend wishes to observe a *particular* value following a cast, the 614generated IR must fence with the underlying environment in an implementation 615defined manner. (In practice, this tends to require ``noinline`` routines for 616such operations.) 617 618From the perspective of the optimizer, ``inttoptr`` and ``ptrtoint`` for 619non-integral types are analogous to ones on integral types with one 620key exception: the optimizer may not, in general, insert new dynamic 621occurrences of such casts. If a new cast is inserted, the optimizer would 622need to either ensure that a) all possible values are valid, or b) 623appropriate fencing is inserted. Since the appropriate fencing is 624implementation defined, the optimizer can't do the latter. The former is 625challenging as many commonly expected properties, such as 626``ptrtoint(v)-ptrtoint(v) == 0``, don't hold for non-integral types. 627 628.. _globalvars: 629 630Global Variables 631---------------- 632 633Global variables define regions of memory allocated at compilation time 634instead of run-time. 635 636Global variable definitions must be initialized. 637 638Global variables in other translation units can also be declared, in which 639case they don't have an initializer. 640 641Global variables can optionally specify a :ref:`linkage type <linkage>`. 642 643Either global variable definitions or declarations may have an explicit section 644to be placed in and may have an optional explicit alignment specified. If there 645is a mismatch between the explicit or inferred section information for the 646variable declaration and its definition the resulting behavior is undefined. 647 648A variable may be defined as a global ``constant``, which indicates that 649the contents of the variable will **never** be modified (enabling better 650optimization, allowing the global data to be placed in the read-only 651section of an executable, etc). Note that variables that need runtime 652initialization cannot be marked ``constant`` as there is a store to the 653variable. 654 655LLVM explicitly allows *declarations* of global variables to be marked 656constant, even if the final definition of the global is not. This 657capability can be used to enable slightly better optimization of the 658program, but requires the language definition to guarantee that 659optimizations based on the 'constantness' are valid for the translation 660units that do not include the definition. 661 662As SSA values, global variables define pointer values that are in scope 663(i.e. they dominate) all basic blocks in the program. Global variables 664always define a pointer to their "content" type because they describe a 665region of memory, and all memory objects in LLVM are accessed through 666pointers. 667 668Global variables can be marked with ``unnamed_addr`` which indicates 669that the address is not significant, only the content. Constants marked 670like this can be merged with other constants if they have the same 671initializer. Note that a constant with significant address *can* be 672merged with a ``unnamed_addr`` constant, the result being a constant 673whose address is significant. 674 675If the ``local_unnamed_addr`` attribute is given, the address is known to 676not be significant within the module. 677 678A global variable may be declared to reside in a target-specific 679numbered address space. For targets that support them, address spaces 680may affect how optimizations are performed and/or what target 681instructions are used to access the variable. The default address space 682is zero. The address space qualifier must precede any other attributes. 683 684LLVM allows an explicit section to be specified for globals. If the 685target supports it, it will emit globals to the section specified. 686Additionally, the global can placed in a comdat if the target has the necessary 687support. 688 689External declarations may have an explicit section specified. Section 690information is retained in LLVM IR for targets that make use of this 691information. Attaching section information to an external declaration is an 692assertion that its definition is located in the specified section. If the 693definition is located in a different section, the behavior is undefined. 694 695By default, global initializers are optimized by assuming that global 696variables defined within the module are not modified from their 697initial values before the start of the global initializer. This is 698true even for variables potentially accessible from outside the 699module, including those with external linkage or appearing in 700``@llvm.used`` or dllexported variables. This assumption may be suppressed 701by marking the variable with ``externally_initialized``. 702 703An explicit alignment may be specified for a global, which must be a 704power of 2. If not present, or if the alignment is set to zero, the 705alignment of the global is set by the target to whatever it feels 706convenient. If an explicit alignment is specified, the global is forced 707to have exactly that alignment. Targets and optimizers are not allowed 708to over-align the global if the global has an assigned section. In this 709case, the extra alignment could be observable: for example, code could 710assume that the globals are densely packed in their section and try to 711iterate over them as an array, alignment padding would break this 712iteration. The maximum alignment is ``1 << 32``. 713 714For global variables declarations, as well as definitions that may be 715replaced at link time (``linkonce``, ``weak``, ``extern_weak`` and ``common`` 716linkage types), LLVM makes no assumptions about the allocation size of the 717variables, except that they may not overlap. The alignment of a global variable 718declaration or replaceable definition must not be greater than the alignment of 719the definition it resolves to. 720 721Globals can also have a :ref:`DLL storage class <dllstorageclass>`, 722an optional :ref:`runtime preemption specifier <runtime_preemption_model>`, 723an optional :ref:`global attributes <glattrs>` and 724an optional list of attached :ref:`metadata <metadata>`. 725 726Variables and aliases can have a 727:ref:`Thread Local Storage Model <tls_model>`. 728 729:ref:`Scalable vectors <t_vector>` cannot be global variables or members of 730arrays because their size is unknown at compile time. They are allowed in 731structs to facilitate intrinsics returning multiple values. Structs containing 732scalable vectors cannot be used in loads, stores, allocas, or GEPs. 733 734Syntax:: 735 736 @<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility] 737 [DLLStorageClass] [ThreadLocal] 738 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] 739 [ExternallyInitialized] 740 <global | constant> <Type> [<InitializerConstant>] 741 [, section "name"] [, partition "name"] 742 [, comdat [($name)]] [, align <Alignment>] 743 (, !name !N)* 744 745For example, the following defines a global in a numbered address space 746with an initializer, section, and alignment: 747 748.. code-block:: llvm 749 750 @G = addrspace(5) constant float 1.0, section "foo", align 4 751 752The following example just declares a global variable 753 754.. code-block:: llvm 755 756 @G = external global i32 757 758The following example defines a thread-local global with the 759``initialexec`` TLS model: 760 761.. code-block:: llvm 762 763 @G = thread_local(initialexec) global i32 0, align 4 764 765.. _functionstructure: 766 767Functions 768--------- 769 770LLVM function definitions consist of the "``define``" keyword, an 771optional :ref:`linkage type <linkage>`, an optional :ref:`runtime preemption 772specifier <runtime_preemption_model>`, an optional :ref:`visibility 773style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, 774an optional :ref:`calling convention <callingconv>`, 775an optional ``unnamed_addr`` attribute, a return type, an optional 776:ref:`parameter attribute <paramattrs>` for the return type, a function 777name, a (possibly empty) argument list (each with optional :ref:`parameter 778attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`, 779an optional address space, an optional section, an optional alignment, 780an optional :ref:`comdat <langref_comdats>`, 781an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`, 782an optional :ref:`prologue <prologuedata>`, 783an optional :ref:`personality <personalityfn>`, 784an optional list of attached :ref:`metadata <metadata>`, 785an opening curly brace, a list of basic blocks, and a closing curly brace. 786 787LLVM function declarations consist of the "``declare``" keyword, an 788optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style 789<visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an 790optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr`` 791or ``local_unnamed_addr`` attribute, an optional address space, a return type, 792an optional :ref:`parameter attribute <paramattrs>` for the return type, a function name, a possibly 793empty list of arguments, an optional alignment, an optional :ref:`garbage 794collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional 795:ref:`prologue <prologuedata>`. 796 797A function definition contains a list of basic blocks, forming the CFG (Control 798Flow Graph) for the function. Each basic block may optionally start with a label 799(giving the basic block a symbol table entry), contains a list of instructions, 800and ends with a :ref:`terminator <terminators>` instruction (such as a branch or 801function return). If an explicit label name is not provided, a block is assigned 802an implicit numbered label, using the next value from the same counter as used 803for unnamed temporaries (:ref:`see above<identifiers>`). For example, if a 804function entry block does not have an explicit label, it will be assigned label 805"%0", then the first unnamed temporary in that block will be "%1", etc. If a 806numeric label is explicitly specified, it must match the numeric label that 807would be used implicitly. 808 809The first basic block in a function is special in two ways: it is 810immediately executed on entrance to the function, and it is not allowed 811to have predecessor basic blocks (i.e. there can not be any branches to 812the entry block of a function). Because the block can have no 813predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`. 814 815LLVM allows an explicit section to be specified for functions. If the 816target supports it, it will emit functions to the section specified. 817Additionally, the function can be placed in a COMDAT. 818 819An explicit alignment may be specified for a function. If not present, 820or if the alignment is set to zero, the alignment of the function is set 821by the target to whatever it feels convenient. If an explicit alignment 822is specified, the function is forced to have at least that much 823alignment. All alignments must be a power of 2. 824 825If the ``unnamed_addr`` attribute is given, the address is known to not 826be significant and two identical functions can be merged. 827 828If the ``local_unnamed_addr`` attribute is given, the address is known to 829not be significant within the module. 830 831If an explicit address space is not given, it will default to the program 832address space from the :ref:`datalayout string<langref_datalayout>`. 833 834Syntax:: 835 836 define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass] 837 [cconv] [ret attrs] 838 <ResultType> @<FunctionName> ([argument list]) 839 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs] 840 [section "name"] [partition "name"] [comdat [($name)]] [align N] 841 [gc] [prefix Constant] [prologue Constant] [personality Constant] 842 (!name !N)* { ... } 843 844The argument list is a comma separated sequence of arguments where each 845argument is of the following form: 846 847Syntax:: 848 849 <type> [parameter Attrs] [name] 850 851 852.. _langref_aliases: 853 854Aliases 855------- 856 857Aliases, unlike function or variables, don't create any new data. They 858are just a new symbol and metadata for an existing position. 859 860Aliases have a name and an aliasee that is either a global value or a 861constant expression. 862 863Aliases may have an optional :ref:`linkage type <linkage>`, an optional 864:ref:`runtime preemption specifier <runtime_preemption_model>`, an optional 865:ref:`visibility style <visibility>`, an optional :ref:`DLL storage class 866<dllstorageclass>` and an optional :ref:`tls model <tls_model>`. 867 868Syntax:: 869 870 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee> 871 [, partition "name"] 872 873The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``, 874``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers 875might not correctly handle dropping a weak symbol that is aliased. 876 877Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as 878the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point 879to the same content. 880 881If the ``local_unnamed_addr`` attribute is given, the address is known to 882not be significant within the module. 883 884Since aliases are only a second name, some restrictions apply, of which 885some can only be checked when producing an object file: 886 887* The expression defining the aliasee must be computable at assembly 888 time. Since it is just a name, no relocations can be used. 889 890* No alias in the expression can be weak as the possibility of the 891 intermediate alias being overridden cannot be represented in an 892 object file. 893 894* No global value in the expression can be a declaration, since that 895 would require a relocation, which is not possible. 896 897* If either the alias or the aliasee may be replaced by a symbol outside the 898 module at link time or runtime, any optimization cannot replace the alias with 899 the aliasee, since the behavior may be different. The alias may be used as a 900 name guaranteed to point to the content in the current module. 901 902.. _langref_ifunc: 903 904IFuncs 905------- 906 907IFuncs, like as aliases, don't create any new data or func. They are just a new 908symbol that dynamic linker resolves at runtime by calling a resolver function. 909 910IFuncs have a name and a resolver that is a function called by dynamic linker 911that returns address of another function associated with the name. 912 913IFunc may have an optional :ref:`linkage type <linkage>` and an optional 914:ref:`visibility style <visibility>`. 915 916Syntax:: 917 918 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver> 919 [, partition "name"] 920 921 922.. _langref_comdats: 923 924Comdats 925------- 926 927Comdat IR provides access to object file COMDAT/section group functionality 928which represents interrelated sections. 929 930Comdats have a name which represents the COMDAT key and a selection kind to 931provide input on how the linker deduplicates comdats with the same key in two 932different object files. A comdat must be included or omitted as a unit. 933Discarding the whole comdat is allowed but discarding a subset is not. 934 935A global object may be a member of at most one comdat. Aliases are placed in the 936same COMDAT that their aliasee computes to, if any. 937 938Syntax:: 939 940 $<Name> = comdat SelectionKind 941 942For selection kinds other than ``nodeduplicate``, only one of the duplicate 943comdats may be retained by the linker and the members of the remaining comdats 944must be discarded. The following selection kinds are supported: 945 946``any`` 947 The linker may choose any COMDAT key, the choice is arbitrary. 948``exactmatch`` 949 The linker may choose any COMDAT key but the sections must contain the 950 same data. 951``largest`` 952 The linker will choose the section containing the largest COMDAT key. 953``nodeduplicate`` 954 No deduplication is performed. 955``samesize`` 956 The linker may choose any COMDAT key but the sections must contain the 957 same amount of data. 958 959- XCOFF and Mach-O don't support COMDATs. 960- COFF supports all selection kinds. Non-``nodeduplicate`` selection kinds need 961 a non-local linkage COMDAT symbol. 962- ELF supports ``any`` and ``nodeduplicate``. 963- WebAssembly only supports ``any``. 964 965Here is an example of a COFF COMDAT where a function will only be selected if 966the COMDAT key's section is the largest: 967 968.. code-block:: text 969 970 $foo = comdat largest 971 @foo = global i32 2, comdat($foo) 972 973 define void @bar() comdat($foo) { 974 ret void 975 } 976 977In a COFF object file, this will create a COMDAT section with selection kind 978``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol 979and another COMDAT section with selection kind 980``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT 981section and contains the contents of the ``@bar`` symbol. 982 983As a syntactic sugar the ``$name`` can be omitted if the name is the same as 984the global name: 985 986.. code-block:: llvm 987 988 $foo = comdat any 989 @foo = global i32 2, comdat 990 @bar = global i32 3, comdat($foo) 991 992There are some restrictions on the properties of the global object. 993It, or an alias to it, must have the same name as the COMDAT group when 994targeting COFF. 995The contents and size of this object may be used during link-time to determine 996which COMDAT groups get selected depending on the selection kind. 997Because the name of the object must match the name of the COMDAT group, the 998linkage of the global object must not be local; local symbols can get renamed 999if a collision occurs in the symbol table. 1000 1001The combined use of COMDATS and section attributes may yield surprising results. 1002For example: 1003 1004.. code-block:: llvm 1005 1006 $foo = comdat any 1007 $bar = comdat any 1008 @g1 = global i32 42, section "sec", comdat($foo) 1009 @g2 = global i32 42, section "sec", comdat($bar) 1010 1011From the object file perspective, this requires the creation of two sections 1012with the same name. This is necessary because both globals belong to different 1013COMDAT groups and COMDATs, at the object file level, are represented by 1014sections. 1015 1016Note that certain IR constructs like global variables and functions may 1017create COMDATs in the object file in addition to any which are specified using 1018COMDAT IR. This arises when the code generator is configured to emit globals 1019in individual sections (e.g. when `-data-sections` or `-function-sections` 1020is supplied to `llc`). 1021 1022.. _namedmetadatastructure: 1023 1024Named Metadata 1025-------------- 1026 1027Named metadata is a collection of metadata. :ref:`Metadata 1028nodes <metadata>` (but not metadata strings) are the only valid 1029operands for a named metadata. 1030 1031#. Named metadata are represented as a string of characters with the 1032 metadata prefix. The rules for metadata names are the same as for 1033 identifiers, but quoted names are not allowed. ``"\xx"`` type escapes 1034 are still valid, which allows any character to be part of a name. 1035 1036Syntax:: 1037 1038 ; Some unnamed metadata nodes, which are referenced by the named metadata. 1039 !0 = !{!"zero"} 1040 !1 = !{!"one"} 1041 !2 = !{!"two"} 1042 ; A named metadata. 1043 !name = !{!0, !1, !2} 1044 1045.. _paramattrs: 1046 1047Parameter Attributes 1048-------------------- 1049 1050The return type and each parameter of a function type may have a set of 1051*parameter attributes* associated with them. Parameter attributes are 1052used to communicate additional information about the result or 1053parameters of a function. Parameter attributes are considered to be part 1054of the function, not of the function type, so functions with different 1055parameter attributes can have the same function type. 1056 1057Parameter attributes are simple keywords that follow the type specified. 1058If multiple parameter attributes are needed, they are space separated. 1059For example: 1060 1061.. code-block:: llvm 1062 1063 declare i32 @printf(i8* noalias nocapture, ...) 1064 declare i32 @atoi(i8 zeroext) 1065 declare signext i8 @returns_signed_char() 1066 1067Note that any attributes for the function result (``nounwind``, 1068``readonly``) come immediately after the argument list. 1069 1070Currently, only the following parameter attributes are defined: 1071 1072``zeroext`` 1073 This indicates to the code generator that the parameter or return 1074 value should be zero-extended to the extent required by the target's 1075 ABI by the caller (for a parameter) or the callee (for a return value). 1076``signext`` 1077 This indicates to the code generator that the parameter or return 1078 value should be sign-extended to the extent required by the target's 1079 ABI (which is usually 32-bits) by the caller (for a parameter) or 1080 the callee (for a return value). 1081``inreg`` 1082 This indicates that this parameter or return value should be treated 1083 in a special target-dependent fashion while emitting code for 1084 a function call or return (usually, by putting it in a register as 1085 opposed to memory, though some targets use it to distinguish between 1086 two different kinds of registers). Use of this attribute is 1087 target-specific. 1088``byval(<ty>)`` 1089 This indicates that the pointer parameter should really be passed by 1090 value to the function. The attribute implies that a hidden copy of 1091 the pointee is made between the caller and the callee, so the callee 1092 is unable to modify the value in the caller. This attribute is only 1093 valid on LLVM pointer arguments. It is generally used to pass 1094 structs and arrays by value, but is also valid on pointers to 1095 scalars. The copy is considered to belong to the caller not the 1096 callee (for example, ``readonly`` functions should not write to 1097 ``byval`` parameters). This is not a valid attribute for return 1098 values. 1099 1100 The byval type argument indicates the in-memory value type, and 1101 must be the same as the pointee type of the argument. 1102 1103 The byval attribute also supports specifying an alignment with the 1104 align attribute. It indicates the alignment of the stack slot to 1105 form and the known alignment of the pointer specified to the call 1106 site. If the alignment is not specified, then the code generator 1107 makes a target-specific assumption. 1108 1109.. _attr_byref: 1110 1111``byref(<ty>)`` 1112 1113 The ``byref`` argument attribute allows specifying the pointee 1114 memory type of an argument. This is similar to ``byval``, but does 1115 not imply a copy is made anywhere, or that the argument is passed 1116 on the stack. This implies the pointer is dereferenceable up to 1117 the storage size of the type. 1118 1119 It is not generally permissible to introduce a write to an 1120 ``byref`` pointer. The pointer may have any address space and may 1121 be read only. 1122 1123 This is not a valid attribute for return values. 1124 1125 The alignment for an ``byref`` parameter can be explicitly 1126 specified by combining it with the ``align`` attribute, similar to 1127 ``byval``. If the alignment is not specified, then the code generator 1128 makes a target-specific assumption. 1129 1130 This is intended for representing ABI constraints, and is not 1131 intended to be inferred for optimization use. 1132 1133.. _attr_preallocated: 1134 1135``preallocated(<ty>)`` 1136 This indicates that the pointer parameter should really be passed by 1137 value to the function, and that the pointer parameter's pointee has 1138 already been initialized before the call instruction. This attribute 1139 is only valid on LLVM pointer arguments. The argument must be the value 1140 returned by the appropriate 1141 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` on non 1142 ``musttail`` calls, or the corresponding caller parameter in ``musttail`` 1143 calls, although it is ignored during codegen. 1144 1145 A non ``musttail`` function call with a ``preallocated`` attribute in 1146 any parameter must have a ``"preallocated"`` operand bundle. A ``musttail`` 1147 function call cannot have a ``"preallocated"`` operand bundle. 1148 1149 The preallocated attribute requires a type argument, which must be 1150 the same as the pointee type of the argument. 1151 1152 The preallocated attribute also supports specifying an alignment with the 1153 align attribute. It indicates the alignment of the stack slot to 1154 form and the known alignment of the pointer specified to the call 1155 site. If the alignment is not specified, then the code generator 1156 makes a target-specific assumption. 1157 1158.. _attr_inalloca: 1159 1160``inalloca(<ty>)`` 1161 1162 The ``inalloca`` argument attribute allows the caller to take the 1163 address of outgoing stack arguments. An ``inalloca`` argument must 1164 be a pointer to stack memory produced by an ``alloca`` instruction. 1165 The alloca, or argument allocation, must also be tagged with the 1166 inalloca keyword. Only the last argument may have the ``inalloca`` 1167 attribute, and that argument is guaranteed to be passed in memory. 1168 1169 An argument allocation may be used by a call at most once because 1170 the call may deallocate it. The ``inalloca`` attribute cannot be 1171 used in conjunction with other attributes that affect argument 1172 storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The 1173 ``inalloca`` attribute also disables LLVM's implicit lowering of 1174 large aggregate return values, which means that frontend authors 1175 must lower them with ``sret`` pointers. 1176 1177 When the call site is reached, the argument allocation must have 1178 been the most recent stack allocation that is still live, or the 1179 behavior is undefined. It is possible to allocate additional stack 1180 space after an argument allocation and before its call site, but it 1181 must be cleared off with :ref:`llvm.stackrestore 1182 <int_stackrestore>`. 1183 1184 The inalloca attribute requires a type argument, which must be the 1185 same as the pointee type of the argument. 1186 1187 See :doc:`InAlloca` for more information on how to use this 1188 attribute. 1189 1190``sret(<ty>)`` 1191 This indicates that the pointer parameter specifies the address of a 1192 structure that is the return value of the function in the source 1193 program. This pointer must be guaranteed by the caller to be valid: 1194 loads and stores to the structure may be assumed by the callee not 1195 to trap and to be properly aligned. This is not a valid attribute 1196 for return values. 1197 1198 The sret type argument specifies the in memory type, which must be 1199 the same as the pointee type of the argument. 1200 1201.. _attr_elementtype: 1202 1203``elementtype(<ty>)`` 1204 1205 The ``elementtype`` argument attribute can be used to specify a pointer 1206 element type in a way that is compatible with `opaque pointers 1207 <OpaquePointers.html>`__. 1208 1209 The ``elementtype`` attribute by itself does not carry any specific 1210 semantics. However, certain intrinsics may require this attribute to be 1211 present and assign it particular semantics. This will be documented on 1212 individual intrinsics. 1213 1214 The attribute may only be applied to pointer typed arguments of intrinsic 1215 calls. It cannot be applied to non-intrinsic calls, and cannot be applied 1216 to parameters on function declarations. For non-opaque pointers, the type 1217 passed to ``elementtype`` must match the pointer element type. 1218 1219.. _attr_align: 1220 1221``align <n>`` or ``align(<n>)`` 1222 This indicates that the pointer value or vector of pointers has the 1223 specified alignment. If applied to a vector of pointers, *all* pointers 1224 (elements) have the specified alignment. If the pointer value does not have 1225 the specified alignment, :ref:`poison value <poisonvalues>` is returned or 1226 passed instead. The ``align`` attribute should be combined with the 1227 ``noundef`` attribute to ensure a pointer is aligned, or otherwise the 1228 behavior is undefined. Note that ``align 1`` has no effect on non-byval, 1229 non-preallocated arguments. 1230 1231 Note that this attribute has additional semantics when combined with the 1232 ``byval`` or ``preallocated`` attribute, which are documented there. 1233 1234.. _noalias: 1235 1236``noalias`` 1237 This indicates that memory locations accessed via pointer values 1238 :ref:`based <pointeraliasing>` on the argument or return value are not also 1239 accessed, during the execution of the function, via pointer values not 1240 *based* on the argument or return value. This guarantee only holds for 1241 memory locations that are *modified*, by any means, during the execution of 1242 the function. The attribute on a return value also has additional semantics 1243 described below. The caller shares the responsibility with the callee for 1244 ensuring that these requirements are met. For further details, please see 1245 the discussion of the NoAlias response in :ref:`alias analysis <Must, May, 1246 or No>`. 1247 1248 Note that this definition of ``noalias`` is intentionally similar 1249 to the definition of ``restrict`` in C99 for function arguments. 1250 1251 For function return values, C99's ``restrict`` is not meaningful, 1252 while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias`` 1253 attribute on return values are stronger than the semantics of the attribute 1254 when used on function arguments. On function return values, the ``noalias`` 1255 attribute indicates that the function acts like a system memory allocation 1256 function, returning a pointer to allocated storage disjoint from the 1257 storage for any other object accessible to the caller. 1258 1259.. _nocapture: 1260 1261``nocapture`` 1262 This indicates that the callee does not :ref:`capture <pointercapture>` the 1263 pointer. This is not a valid attribute for return values. 1264 This attribute applies only to the particular copy of the pointer passed in 1265 this argument. A caller could pass two copies of the same pointer with one 1266 being annotated nocapture and the other not, and the callee could validly 1267 capture through the non annotated parameter. 1268 1269.. code-block:: llvm 1270 1271 define void @f(i8* nocapture %a, i8* %b) { 1272 ; (capture %b) 1273 } 1274 1275 call void @f(i8* @glb, i8* @glb) ; well-defined 1276 1277``nofree`` 1278 This indicates that callee does not free the pointer argument. This is not 1279 a valid attribute for return values. 1280 1281.. _nest: 1282 1283``nest`` 1284 This indicates that the pointer parameter can be excised using the 1285 :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid 1286 attribute for return values and can only be applied to one parameter. 1287 1288``returned`` 1289 This indicates that the function always returns the argument as its return 1290 value. This is a hint to the optimizer and code generator used when 1291 generating the caller, allowing value propagation, tail call optimization, 1292 and omission of register saves and restores in some cases; it is not 1293 checked or enforced when generating the callee. The parameter and the 1294 function return type must be valid operands for the 1295 :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for 1296 return values and can only be applied to one parameter. 1297 1298``nonnull`` 1299 This indicates that the parameter or return pointer is not null. This 1300 attribute may only be applied to pointer typed parameters. This is not 1301 checked or enforced by LLVM; if the parameter or return pointer is null, 1302 :ref:`poison value <poisonvalues>` is returned or passed instead. 1303 The ``nonnull`` attribute should be combined with the ``noundef`` attribute 1304 to ensure a pointer is not null or otherwise the behavior is undefined. 1305 1306``dereferenceable(<n>)`` 1307 This indicates that the parameter or return pointer is dereferenceable. This 1308 attribute may only be applied to pointer typed parameters. A pointer that 1309 is dereferenceable can be loaded from speculatively without a risk of 1310 trapping. The number of bytes known to be dereferenceable must be provided 1311 in parentheses. It is legal for the number of bytes to be less than the 1312 size of the pointee type. The ``nonnull`` attribute does not imply 1313 dereferenceability (consider a pointer to one element past the end of an 1314 array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in 1315 ``addrspace(0)`` (which is the default address space), except if the 1316 ``null_pointer_is_valid`` function attribute is present. 1317 ``n`` should be a positive number. The pointer should be well defined, 1318 otherwise it is undefined behavior. This means ``dereferenceable(<n>)`` 1319 implies ``noundef``. 1320 1321``dereferenceable_or_null(<n>)`` 1322 This indicates that the parameter or return value isn't both 1323 non-null and non-dereferenceable (up to ``<n>`` bytes) at the same 1324 time. All non-null pointers tagged with 1325 ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``. 1326 For address space 0 ``dereferenceable_or_null(<n>)`` implies that 1327 a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``, 1328 and in other address spaces ``dereferenceable_or_null(<n>)`` 1329 implies that a pointer is at least one of ``dereferenceable(<n>)`` 1330 or ``null`` (i.e. it may be both ``null`` and 1331 ``dereferenceable(<n>)``). This attribute may only be applied to 1332 pointer typed parameters. 1333 1334``swiftself`` 1335 This indicates that the parameter is the self/context parameter. This is not 1336 a valid attribute for return values and can only be applied to one 1337 parameter. 1338 1339``swiftasync`` 1340 This indicates that the parameter is the asynchronous context parameter and 1341 triggers the creation of a target-specific extended frame record to store 1342 this pointer. This is not a valid attribute for return values and can only 1343 be applied to one parameter. 1344 1345``swifterror`` 1346 This attribute is motivated to model and optimize Swift error handling. It 1347 can be applied to a parameter with pointer to pointer type or a 1348 pointer-sized alloca. At the call site, the actual argument that corresponds 1349 to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or 1350 the ``swifterror`` parameter of the caller. A ``swifterror`` value (either 1351 the parameter or the alloca) can only be loaded and stored from, or used as 1352 a ``swifterror`` argument. This is not a valid attribute for return values 1353 and can only be applied to one parameter. 1354 1355 These constraints allow the calling convention to optimize access to 1356 ``swifterror`` variables by associating them with a specific register at 1357 call boundaries rather than placing them in memory. Since this does change 1358 the calling convention, a function which uses the ``swifterror`` attribute 1359 on a parameter is not ABI-compatible with one which does not. 1360 1361 These constraints also allow LLVM to assume that a ``swifterror`` argument 1362 does not alias any other memory visible within a function and that a 1363 ``swifterror`` alloca passed as an argument does not escape. 1364 1365``immarg`` 1366 This indicates the parameter is required to be an immediate 1367 value. This must be a trivial immediate integer or floating-point 1368 constant. Undef or constant expressions are not valid. This is 1369 only valid on intrinsic declarations and cannot be applied to a 1370 call site or arbitrary function. 1371 1372``noundef`` 1373 This attribute applies to parameters and return values. If the value 1374 representation contains any undefined or poison bits, the behavior is 1375 undefined. Note that this does not refer to padding introduced by the 1376 type's storage representation. 1377 1378``alignstack(<n>)`` 1379 This indicates the alignment that should be considered by the backend when 1380 assigning this parameter to a stack slot during calling convention 1381 lowering. The enforcement of the specified alignment is target-dependent, 1382 as target-specific calling convention rules may override this value. This 1383 attribute serves the purpose of carrying language specific alignment 1384 information that is not mapped to base types in the backend (for example, 1385 over-alignment specification through language attributes). 1386 1387``allocalign`` 1388 The function parameter marked with this attribute is is the alignment in bytes of the 1389 newly allocated block returned by this function. The returned value must either have 1390 the specified alignment or be the null pointer. The return value MAY be more aligned 1391 than the requested alignment, but not less aligned. Invalid (e.g. non-power-of-2) 1392 alignments are permitted for the allocalign parameter, so long as the returned pointer 1393 is null. This attribute may only be applied to integer parameters. 1394 1395.. _gc: 1396 1397Garbage Collector Strategy Names 1398-------------------------------- 1399 1400Each function may specify a garbage collector strategy name, which is simply a 1401string: 1402 1403.. code-block:: llvm 1404 1405 define void @f() gc "name" { ... } 1406 1407The supported values of *name* includes those :ref:`built in to LLVM 1408<builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC 1409strategy will cause the compiler to alter its output in order to support the 1410named garbage collection algorithm. Note that LLVM itself does not contain a 1411garbage collector, this functionality is restricted to generating machine code 1412which can interoperate with a collector provided externally. 1413 1414.. _prefixdata: 1415 1416Prefix Data 1417----------- 1418 1419Prefix data is data associated with a function which the code 1420generator will emit immediately before the function's entrypoint. 1421The purpose of this feature is to allow frontends to associate 1422language-specific runtime metadata with specific functions and make it 1423available through the function pointer while still allowing the 1424function pointer to be called. 1425 1426To access the data for a given function, a program may bitcast the 1427function pointer to a pointer to the constant's type and dereference 1428index -1. This implies that the IR symbol points just past the end of 1429the prefix data. For instance, take the example of a function annotated 1430with a single ``i32``, 1431 1432.. code-block:: llvm 1433 1434 define void @f() prefix i32 123 { ... } 1435 1436The prefix data can be referenced as, 1437 1438.. code-block:: llvm 1439 1440 %0 = bitcast void* () @f to i32* 1441 %a = getelementptr inbounds i32, i32* %0, i32 -1 1442 %b = load i32, i32* %a 1443 1444Prefix data is laid out as if it were an initializer for a global variable 1445of the prefix data's type. The function will be placed such that the 1446beginning of the prefix data is aligned. This means that if the size 1447of the prefix data is not a multiple of the alignment size, the 1448function's entrypoint will not be aligned. If alignment of the 1449function's entrypoint is desired, padding must be added to the prefix 1450data. 1451 1452A function may have prefix data but no body. This has similar semantics 1453to the ``available_externally`` linkage in that the data may be used by the 1454optimizers but will not be emitted in the object file. 1455 1456.. _prologuedata: 1457 1458Prologue Data 1459------------- 1460 1461The ``prologue`` attribute allows arbitrary code (encoded as bytes) to 1462be inserted prior to the function body. This can be used for enabling 1463function hot-patching and instrumentation. 1464 1465To maintain the semantics of ordinary function calls, the prologue data must 1466have a particular format. Specifically, it must begin with a sequence of 1467bytes which decode to a sequence of machine instructions, valid for the 1468module's target, which transfer control to the point immediately succeeding 1469the prologue data, without performing any other visible action. This allows 1470the inliner and other passes to reason about the semantics of the function 1471definition without needing to reason about the prologue data. Obviously this 1472makes the format of the prologue data highly target dependent. 1473 1474A trivial example of valid prologue data for the x86 architecture is ``i8 144``, 1475which encodes the ``nop`` instruction: 1476 1477.. code-block:: text 1478 1479 define void @f() prologue i8 144 { ... } 1480 1481Generally prologue data can be formed by encoding a relative branch instruction 1482which skips the metadata, as in this example of valid prologue data for the 1483x86_64 architecture, where the first two bytes encode ``jmp .+10``: 1484 1485.. code-block:: text 1486 1487 %0 = type <{ i8, i8, i8* }> 1488 1489 define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... } 1490 1491A function may have prologue data but no body. This has similar semantics 1492to the ``available_externally`` linkage in that the data may be used by the 1493optimizers but will not be emitted in the object file. 1494 1495.. _personalityfn: 1496 1497Personality Function 1498-------------------- 1499 1500The ``personality`` attribute permits functions to specify what function 1501to use for exception handling. 1502 1503.. _attrgrp: 1504 1505Attribute Groups 1506---------------- 1507 1508Attribute groups are groups of attributes that are referenced by objects within 1509the IR. They are important for keeping ``.ll`` files readable, because a lot of 1510functions will use the same set of attributes. In the degenerative case of a 1511``.ll`` file that corresponds to a single ``.c`` file, the single attribute 1512group will capture the important command line flags used to build that file. 1513 1514An attribute group is a module-level object. To use an attribute group, an 1515object references the attribute group's ID (e.g. ``#37``). An object may refer 1516to more than one attribute group. In that situation, the attributes from the 1517different groups are merged. 1518 1519Here is an example of attribute groups for a function that should always be 1520inlined, has a stack alignment of 4, and which shouldn't use SSE instructions: 1521 1522.. code-block:: llvm 1523 1524 ; Target-independent attributes: 1525 attributes #0 = { alwaysinline alignstack=4 } 1526 1527 ; Target-dependent attributes: 1528 attributes #1 = { "no-sse" } 1529 1530 ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse". 1531 define void @f() #0 #1 { ... } 1532 1533.. _fnattrs: 1534 1535Function Attributes 1536------------------- 1537 1538Function attributes are set to communicate additional information about 1539a function. Function attributes are considered to be part of the 1540function, not of the function type, so functions with different function 1541attributes can have the same function type. 1542 1543Function attributes are simple keywords that follow the type specified. 1544If multiple attributes are needed, they are space separated. For 1545example: 1546 1547.. code-block:: llvm 1548 1549 define void @f() noinline { ... } 1550 define void @f() alwaysinline { ... } 1551 define void @f() alwaysinline optsize { ... } 1552 define void @f() optsize { ... } 1553 1554``alignstack(<n>)`` 1555 This attribute indicates that, when emitting the prologue and 1556 epilogue, the backend should forcibly align the stack pointer. 1557 Specify the desired alignment, which must be a power of two, in 1558 parentheses. 1559``allocsize(<EltSizeParam>[, <NumEltsParam>])`` 1560 This attribute indicates that the annotated function will always return at 1561 least a given number of bytes (or null). Its arguments are zero-indexed 1562 parameter numbers; if one argument is provided, then it's assumed that at 1563 least ``CallSite.Args[EltSizeParam]`` bytes will be available at the 1564 returned pointer. If two are provided, then it's assumed that 1565 ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are 1566 available. The referenced parameters must be integer types. No assumptions 1567 are made about the contents of the returned block of memory. 1568``alwaysinline`` 1569 This attribute indicates that the inliner should attempt to inline 1570 this function into callers whenever possible, ignoring any active 1571 inlining size threshold for this caller. 1572``builtin`` 1573 This indicates that the callee function at a call site should be 1574 recognized as a built-in function, even though the function's declaration 1575 uses the ``nobuiltin`` attribute. This is only valid at call sites for 1576 direct calls to functions that are declared with the ``nobuiltin`` 1577 attribute. 1578``cold`` 1579 This attribute indicates that this function is rarely called. When 1580 computing edge weights, basic blocks post-dominated by a cold 1581 function call are also considered to be cold; and, thus, given low 1582 weight. 1583``convergent`` 1584 In some parallel execution models, there exist operations that cannot be 1585 made control-dependent on any additional values. We call such operations 1586 ``convergent``, and mark them with this attribute. 1587 1588 The ``convergent`` attribute may appear on functions or call/invoke 1589 instructions. When it appears on a function, it indicates that calls to 1590 this function should not be made control-dependent on additional values. 1591 For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so 1592 calls to this intrinsic cannot be made control-dependent on additional 1593 values. 1594 1595 When it appears on a call/invoke, the ``convergent`` attribute indicates 1596 that we should treat the call as though we're calling a convergent 1597 function. This is particularly useful on indirect calls; without this we 1598 may treat such calls as though the target is non-convergent. 1599 1600 The optimizer may remove the ``convergent`` attribute on functions when it 1601 can prove that the function does not execute any convergent operations. 1602 Similarly, the optimizer may remove ``convergent`` on calls/invokes when it 1603 can prove that the call/invoke cannot call a convergent function. 1604``disable_sanitizer_instrumentation`` 1605 When instrumenting code with sanitizers, it can be important to skip certain 1606 functions to ensure no instrumentation is applied to them. 1607 1608 This attribute is not always similar to absent ``sanitize_<name>`` 1609 attributes: depending on the specific sanitizer, code can be inserted into 1610 functions regardless of the ``sanitize_<name>`` attribute to prevent false 1611 positive reports. 1612 1613 ``disable_sanitizer_instrumentation`` disables all kinds of instrumentation, 1614 taking precedence over the ``sanitize_<name>`` attributes and other compiler 1615 flags. 1616``"dontcall-error"`` 1617 This attribute denotes that an error diagnostic should be emitted when a 1618 call of a function with this attribute is not eliminated via optimization. 1619 Front ends can provide optional ``srcloc`` metadata nodes on call sites of 1620 such callees to attach information about where in the source language such a 1621 call came from. A string value can be provided as a note. 1622``"dontcall-warn"`` 1623 This attribute denotes that a warning diagnostic should be emitted when a 1624 call of a function with this attribute is not eliminated via optimization. 1625 Front ends can provide optional ``srcloc`` metadata nodes on call sites of 1626 such callees to attach information about where in the source language such a 1627 call came from. A string value can be provided as a note. 1628``"frame-pointer"`` 1629 This attribute tells the code generator whether the function 1630 should keep the frame pointer. The code generator may emit the frame pointer 1631 even if this attribute says the frame pointer can be eliminated. 1632 The allowed string values are: 1633 1634 * ``"none"`` (default) - the frame pointer can be eliminated. 1635 * ``"non-leaf"`` - the frame pointer should be kept if the function calls 1636 other functions. 1637 * ``"all"`` - the frame pointer should be kept. 1638``hot`` 1639 This attribute indicates that this function is a hot spot of the program 1640 execution. The function will be optimized more aggressively and will be 1641 placed into special subsection of the text section to improving locality. 1642 1643 When profile feedback is enabled, this attribute has the precedence over 1644 the profile information. By marking a function ``hot``, users can work 1645 around the cases where the training input does not have good coverage 1646 on all the hot functions. 1647``inaccessiblememonly`` 1648 This attribute indicates that the function may only access memory that 1649 is not accessible by the module being compiled before return from the 1650 function. This is a weaker form of ``readnone``. If the function reads 1651 or writes other memory, the behavior is undefined. 1652 1653 For clarity, note that such functions are allowed to return new memory 1654 which is ``noalias`` with respect to memory already accessible from 1655 the module. That is, a function can be both ``inaccessiblememonly`` and 1656 have a ``noalias`` return which introduces a new, potentially initialized, 1657 allocation. 1658``inaccessiblemem_or_argmemonly`` 1659 This attribute indicates that the function may only access memory that is 1660 either not accessible by the module being compiled, or is pointed to 1661 by its pointer arguments. This is a weaker form of ``argmemonly``. If the 1662 function reads or writes other memory, the behavior is undefined. 1663``inlinehint`` 1664 This attribute indicates that the source code contained a hint that 1665 inlining this function is desirable (such as the "inline" keyword in 1666 C/C++). It is just a hint; it imposes no requirements on the 1667 inliner. 1668``jumptable`` 1669 This attribute indicates that the function should be added to a 1670 jump-instruction table at code-generation time, and that all address-taken 1671 references to this function should be replaced with a reference to the 1672 appropriate jump-instruction-table function pointer. Note that this creates 1673 a new pointer for the original function, which means that code that depends 1674 on function-pointer identity can break. So, any function annotated with 1675 ``jumptable`` must also be ``unnamed_addr``. 1676``minsize`` 1677 This attribute suggests that optimization passes and code generator 1678 passes make choices that keep the code size of this function as small 1679 as possible and perform optimizations that may sacrifice runtime 1680 performance in order to minimize the size of the generated code. 1681``naked`` 1682 This attribute disables prologue / epilogue emission for the 1683 function. This can have very system-specific consequences. 1684``"no-inline-line-tables"`` 1685 When this attribute is set to true, the inliner discards source locations 1686 when inlining code and instead uses the source location of the call site. 1687 Breakpoints set on code that was inlined into the current function will 1688 not fire during the execution of the inlined call sites. If the debugger 1689 stops inside an inlined call site, it will appear to be stopped at the 1690 outermost inlined call site. 1691``no-jump-tables`` 1692 When this attribute is set to true, the jump tables and lookup tables that 1693 can be generated from a switch case lowering are disabled. 1694``nobuiltin`` 1695 This indicates that the callee function at a call site is not recognized as 1696 a built-in function. LLVM will retain the original call and not replace it 1697 with equivalent code based on the semantics of the built-in function, unless 1698 the call site uses the ``builtin`` attribute. This is valid at call sites 1699 and on function declarations and definitions. 1700``noduplicate`` 1701 This attribute indicates that calls to the function cannot be 1702 duplicated. A call to a ``noduplicate`` function may be moved 1703 within its parent function, but may not be duplicated within 1704 its parent function. 1705 1706 A function containing a ``noduplicate`` call may still 1707 be an inlining candidate, provided that the call is not 1708 duplicated by inlining. That implies that the function has 1709 internal linkage and only has one call site, so the original 1710 call is dead after inlining. 1711``nofree`` 1712 This function attribute indicates that the function does not, directly or 1713 transitively, call a memory-deallocation function (``free``, for example) 1714 on a memory allocation which existed before the call. 1715 1716 As a result, uncaptured pointers that are known to be dereferenceable 1717 prior to a call to a function with the ``nofree`` attribute are still 1718 known to be dereferenceable after the call. The capturing condition is 1719 necessary in environments where the function might communicate the 1720 pointer to another thread which then deallocates the memory. Alternatively, 1721 ``nosync`` would ensure such communication cannot happen and even captured 1722 pointers cannot be freed by the function. 1723 1724 A ``nofree`` function is explicitly allowed to free memory which it 1725 allocated or (if not ``nosync``) arrange for another thread to free 1726 memory on it's behalf. As a result, perhaps surprisingly, a ``nofree`` 1727 function can return a pointer to a previously deallocated memory object. 1728``noimplicitfloat`` 1729 Disallows implicit floating-point code. This inhibits optimizations that 1730 use floating-point code and floating-point/SIMD/vector registers for 1731 operations that are not nominally floating-point. LLVM instructions that 1732 perform floating-point operations or require access to floating-point 1733 registers may still cause floating-point code to be generated. 1734``noinline`` 1735 This attribute indicates that the inliner should never inline this 1736 function in any situation. This attribute may not be used together 1737 with the ``alwaysinline`` attribute. 1738``nomerge`` 1739 This attribute indicates that calls to this function should never be merged 1740 during optimization. For example, it will prevent tail merging otherwise 1741 identical code sequences that raise an exception or terminate the program. 1742 Tail merging normally reduces the precision of source location information, 1743 making stack traces less useful for debugging. This attribute gives the 1744 user control over the tradeoff between code size and debug information 1745 precision. 1746``nonlazybind`` 1747 This attribute suppresses lazy symbol binding for the function. This 1748 may make calls to the function faster, at the cost of extra program 1749 startup time if the function is not called during program startup. 1750``noprofile`` 1751 This function attribute prevents instrumentation based profiling, used for 1752 coverage or profile based optimization, from being added to a function, 1753 even when inlined. 1754``noredzone`` 1755 This attribute indicates that the code generator should not use a 1756 red zone, even if the target-specific ABI normally permits it. 1757``indirect-tls-seg-refs`` 1758 This attribute indicates that the code generator should not use 1759 direct TLS access through segment registers, even if the 1760 target-specific ABI normally permits it. 1761``noreturn`` 1762 This function attribute indicates that the function never returns 1763 normally, hence through a return instruction. This produces undefined 1764 behavior at runtime if the function ever does dynamically return. Annotated 1765 functions may still raise an exception, i.a., ``nounwind`` is not implied. 1766``norecurse`` 1767 This function attribute indicates that the function does not call itself 1768 either directly or indirectly down any possible call path. This produces 1769 undefined behavior at runtime if the function ever does recurse. 1770 1771.. _langref_willreturn: 1772 1773``willreturn`` 1774 This function attribute indicates that a call of this function will 1775 either exhibit undefined behavior or comes back and continues execution 1776 at a point in the existing call stack that includes the current invocation. 1777 Annotated functions may still raise an exception, i.a., ``nounwind`` is not implied. 1778 If an invocation of an annotated function does not return control back 1779 to a point in the call stack, the behavior is undefined. 1780``nosync`` 1781 This function attribute indicates that the function does not communicate 1782 (synchronize) with another thread through memory or other well-defined means. 1783 Synchronization is considered possible in the presence of `atomic` accesses 1784 that enforce an order, thus not "unordered" and "monotonic", `volatile` accesses, 1785 as well as `convergent` function calls. Note that through `convergent` function calls 1786 non-memory communication, e.g., cross-lane operations, are possible and are also 1787 considered synchronization. However `convergent` does not contradict `nosync`. 1788 If an annotated function does ever synchronize with another thread, 1789 the behavior is undefined. 1790``nounwind`` 1791 This function attribute indicates that the function never raises an 1792 exception. If the function does raise an exception, its runtime 1793 behavior is undefined. However, functions marked nounwind may still 1794 trap or generate asynchronous exceptions. Exception handling schemes 1795 that are recognized by LLVM to handle asynchronous exceptions, such 1796 as SEH, will still provide their implementation defined semantics. 1797``nosanitize_bounds`` 1798 This attribute indicates that bounds checking sanitizer instrumentation 1799 is disabled for this function. 1800``nosanitize_coverage`` 1801 This attribute indicates that SanitizerCoverage instrumentation is disabled 1802 for this function. 1803``null_pointer_is_valid`` 1804 If ``null_pointer_is_valid`` is set, then the ``null`` address 1805 in address-space 0 is considered to be a valid address for memory loads and 1806 stores. Any analysis or optimization should not treat dereferencing a 1807 pointer to ``null`` as undefined behavior in this function. 1808 Note: Comparing address of a global variable to ``null`` may still 1809 evaluate to false because of a limitation in querying this attribute inside 1810 constant expressions. 1811``optforfuzzing`` 1812 This attribute indicates that this function should be optimized 1813 for maximum fuzzing signal. 1814``optnone`` 1815 This function attribute indicates that most optimization passes will skip 1816 this function, with the exception of interprocedural optimization passes. 1817 Code generation defaults to the "fast" instruction selector. 1818 This attribute cannot be used together with the ``alwaysinline`` 1819 attribute; this attribute is also incompatible 1820 with the ``minsize`` attribute and the ``optsize`` attribute. 1821 1822 This attribute requires the ``noinline`` attribute to be specified on 1823 the function as well, so the function is never inlined into any caller. 1824 Only functions with the ``alwaysinline`` attribute are valid 1825 candidates for inlining into the body of this function. 1826``optsize`` 1827 This attribute suggests that optimization passes and code generator 1828 passes make choices that keep the code size of this function low, 1829 and otherwise do optimizations specifically to reduce code size as 1830 long as they do not significantly impact runtime performance. 1831``"patchable-function"`` 1832 This attribute tells the code generator that the code 1833 generated for this function needs to follow certain conventions that 1834 make it possible for a runtime function to patch over it later. 1835 The exact effect of this attribute depends on its string value, 1836 for which there currently is one legal possibility: 1837 1838 * ``"prologue-short-redirect"`` - This style of patchable 1839 function is intended to support patching a function prologue to 1840 redirect control away from the function in a thread safe 1841 manner. It guarantees that the first instruction of the 1842 function will be large enough to accommodate a short jump 1843 instruction, and will be sufficiently aligned to allow being 1844 fully changed via an atomic compare-and-swap instruction. 1845 While the first requirement can be satisfied by inserting large 1846 enough NOP, LLVM can and will try to re-purpose an existing 1847 instruction (i.e. one that would have to be emitted anyway) as 1848 the patchable instruction larger than a short jump. 1849 1850 ``"prologue-short-redirect"`` is currently only supported on 1851 x86-64. 1852 1853 This attribute by itself does not imply restrictions on 1854 inter-procedural optimizations. All of the semantic effects the 1855 patching may have to be separately conveyed via the linkage type. 1856``"probe-stack"`` 1857 This attribute indicates that the function will trigger a guard region 1858 in the end of the stack. It ensures that accesses to the stack must be 1859 no further apart than the size of the guard region to a previous 1860 access of the stack. It takes one required string value, the name of 1861 the stack probing function that will be called. 1862 1863 If a function that has a ``"probe-stack"`` attribute is inlined into 1864 a function with another ``"probe-stack"`` attribute, the resulting 1865 function has the ``"probe-stack"`` attribute of the caller. If a 1866 function that has a ``"probe-stack"`` attribute is inlined into a 1867 function that has no ``"probe-stack"`` attribute at all, the resulting 1868 function has the ``"probe-stack"`` attribute of the callee. 1869``readnone`` 1870 On a function, this attribute indicates that the function computes its 1871 result (or decides to unwind an exception) based strictly on its arguments, 1872 without dereferencing any pointer arguments or otherwise accessing 1873 any mutable state (e.g. memory, control registers, etc) visible outside the 1874 ``readnone`` function. It does not write through any pointer arguments 1875 (including ``byval`` arguments) and never changes any state visible to 1876 callers. This means while it cannot unwind exceptions by calling the ``C++`` 1877 exception throwing methods (since they write to memory), there may be 1878 non-``C++`` mechanisms that throw exceptions without writing to LLVM visible 1879 memory. 1880 1881 On an argument, this attribute indicates that the function does not 1882 dereference that pointer argument, even though it may read or write the 1883 memory that the pointer points to if accessed through other pointers. 1884 1885 If a readnone function reads or writes memory visible outside the function, 1886 or has other side-effects, the behavior is undefined. If a 1887 function reads from or writes to a readnone pointer argument, the behavior 1888 is undefined. 1889``readonly`` 1890 On a function, this attribute indicates that the function does not write 1891 through any pointer arguments (including ``byval`` arguments) or otherwise 1892 modify any state (e.g. memory, control registers, etc) visible outside the 1893 ``readonly`` function. It may dereference pointer arguments and read 1894 state that may be set in the caller. A readonly function always 1895 returns the same value (or unwinds an exception identically) when 1896 called with the same set of arguments and global state. This means while it 1897 cannot unwind exceptions by calling the ``C++`` exception throwing methods 1898 (since they write to memory), there may be non-``C++`` mechanisms that throw 1899 exceptions without writing to LLVM visible memory. 1900 1901 On an argument, this attribute indicates that the function does not write 1902 through this pointer argument, even though it may write to the memory that 1903 the pointer points to. 1904 1905 If a readonly function writes memory visible outside the function, or has 1906 other side-effects, the behavior is undefined. If a function writes to a 1907 readonly pointer argument, the behavior is undefined. 1908``"stack-probe-size"`` 1909 This attribute controls the behavior of stack probes: either 1910 the ``"probe-stack"`` attribute, or ABI-required stack probes, if any. 1911 It defines the size of the guard region. It ensures that if the function 1912 may use more stack space than the size of the guard region, stack probing 1913 sequence will be emitted. It takes one required integer value, which 1914 is 4096 by default. 1915 1916 If a function that has a ``"stack-probe-size"`` attribute is inlined into 1917 a function with another ``"stack-probe-size"`` attribute, the resulting 1918 function has the ``"stack-probe-size"`` attribute that has the lower 1919 numeric value. If a function that has a ``"stack-probe-size"`` attribute is 1920 inlined into a function that has no ``"stack-probe-size"`` attribute 1921 at all, the resulting function has the ``"stack-probe-size"`` attribute 1922 of the callee. 1923``"no-stack-arg-probe"`` 1924 This attribute disables ABI-required stack probes, if any. 1925``writeonly`` 1926 On a function, this attribute indicates that the function may write to but 1927 does not read from memory visible outside the ``writeonly`` function. 1928 1929 On an argument, this attribute indicates that the function may write to but 1930 does not read through this pointer argument (even though it may read from 1931 the memory that the pointer points to). 1932 1933 If a writeonly function reads memory visible outside the function or has 1934 other side-effects, the behavior is undefined. If a function reads 1935 from a writeonly pointer argument, the behavior is undefined. 1936``argmemonly`` 1937 This attribute indicates that the only memory accesses inside function are 1938 loads and stores from objects pointed to by its pointer-typed arguments, 1939 with arbitrary offsets. Or in other words, all memory operations in the 1940 function can refer to memory only using pointers based on its function 1941 arguments. 1942 1943 Note that ``argmemonly`` can be used together with ``readonly`` attribute 1944 in order to specify that function reads only from its arguments. 1945 1946 If an argmemonly function reads or writes memory other than the pointer 1947 arguments, or has other side-effects, the behavior is undefined. 1948``returns_twice`` 1949 This attribute indicates that this function can return twice. The C 1950 ``setjmp`` is an example of such a function. The compiler disables 1951 some optimizations (like tail calls) in the caller of these 1952 functions. 1953``safestack`` 1954 This attribute indicates that 1955 `SafeStack <https://clang.llvm.org/docs/SafeStack.html>`_ 1956 protection is enabled for this function. 1957 1958 If a function that has a ``safestack`` attribute is inlined into a 1959 function that doesn't have a ``safestack`` attribute or which has an 1960 ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting 1961 function will have a ``safestack`` attribute. 1962``sanitize_address`` 1963 This attribute indicates that AddressSanitizer checks 1964 (dynamic address safety analysis) are enabled for this function. 1965``sanitize_memory`` 1966 This attribute indicates that MemorySanitizer checks (dynamic detection 1967 of accesses to uninitialized memory) are enabled for this function. 1968``sanitize_thread`` 1969 This attribute indicates that ThreadSanitizer checks 1970 (dynamic thread safety analysis) are enabled for this function. 1971``sanitize_hwaddress`` 1972 This attribute indicates that HWAddressSanitizer checks 1973 (dynamic address safety analysis based on tagged pointers) are enabled for 1974 this function. 1975``sanitize_memtag`` 1976 This attribute indicates that MemTagSanitizer checks 1977 (dynamic address safety analysis based on Armv8 MTE) are enabled for 1978 this function. 1979``speculative_load_hardening`` 1980 This attribute indicates that 1981 `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_ 1982 should be enabled for the function body. 1983 1984 Speculative Load Hardening is a best-effort mitigation against 1985 information leak attacks that make use of control flow 1986 miss-speculation - specifically miss-speculation of whether a branch 1987 is taken or not. Typically vulnerabilities enabling such attacks are 1988 classified as "Spectre variant #1". Notably, this does not attempt to 1989 mitigate against miss-speculation of branch target, classified as 1990 "Spectre variant #2" vulnerabilities. 1991 1992 When inlining, the attribute is sticky. Inlining a function that carries 1993 this attribute will cause the caller to gain the attribute. This is intended 1994 to provide a maximally conservative model where the code in a function 1995 annotated with this attribute will always (even after inlining) end up 1996 hardened. 1997``speculatable`` 1998 This function attribute indicates that the function does not have any 1999 effects besides calculating its result and does not have undefined behavior. 2000 Note that ``speculatable`` is not enough to conclude that along any 2001 particular execution path the number of calls to this function will not be 2002 externally observable. This attribute is only valid on functions 2003 and declarations, not on individual call sites. If a function is 2004 incorrectly marked as speculatable and really does exhibit 2005 undefined behavior, the undefined behavior may be observed even 2006 if the call site is dead code. 2007 2008``ssp`` 2009 This attribute indicates that the function should emit a stack 2010 smashing protector. It is in the form of a "canary" --- a random value 2011 placed on the stack before the local variables that's checked upon 2012 return from the function to see if it has been overwritten. A 2013 heuristic is used to determine if a function needs stack protectors 2014 or not. The heuristic used will enable protectors for functions with: 2015 2016 - Character arrays larger than ``ssp-buffer-size`` (default 8). 2017 - Aggregates containing character arrays larger than ``ssp-buffer-size``. 2018 - Calls to alloca() with variable sizes or constant sizes greater than 2019 ``ssp-buffer-size``. 2020 2021 Variables that are identified as requiring a protector will be arranged 2022 on the stack such that they are adjacent to the stack protector guard. 2023 2024 If a function with an ``ssp`` attribute is inlined into a calling function, 2025 the attribute is not carried over to the calling function. 2026 2027``sspstrong`` 2028 This attribute indicates that the function should emit a stack smashing 2029 protector. This attribute causes a strong heuristic to be used when 2030 determining if a function needs stack protectors. The strong heuristic 2031 will enable protectors for functions with: 2032 2033 - Arrays of any size and type 2034 - Aggregates containing an array of any size and type. 2035 - Calls to alloca(). 2036 - Local variables that have had their address taken. 2037 2038 Variables that are identified as requiring a protector will be arranged 2039 on the stack such that they are adjacent to the stack protector guard. 2040 The specific layout rules are: 2041 2042 #. Large arrays and structures containing large arrays 2043 (``>= ssp-buffer-size``) are closest to the stack protector. 2044 #. Small arrays and structures containing small arrays 2045 (``< ssp-buffer-size``) are 2nd closest to the protector. 2046 #. Variables that have had their address taken are 3rd closest to the 2047 protector. 2048 2049 This overrides the ``ssp`` function attribute. 2050 2051 If a function with an ``sspstrong`` attribute is inlined into a calling 2052 function which has an ``ssp`` attribute, the calling function's attribute 2053 will be upgraded to ``sspstrong``. 2054 2055``sspreq`` 2056 This attribute indicates that the function should *always* emit a stack 2057 smashing protector. This overrides the ``ssp`` and ``sspstrong`` function 2058 attributes. 2059 2060 Variables that are identified as requiring a protector will be arranged 2061 on the stack such that they are adjacent to the stack protector guard. 2062 The specific layout rules are: 2063 2064 #. Large arrays and structures containing large arrays 2065 (``>= ssp-buffer-size``) are closest to the stack protector. 2066 #. Small arrays and structures containing small arrays 2067 (``< ssp-buffer-size``) are 2nd closest to the protector. 2068 #. Variables that have had their address taken are 3rd closest to the 2069 protector. 2070 2071 If a function with an ``sspreq`` attribute is inlined into a calling 2072 function which has an ``ssp`` or ``sspstrong`` attribute, the calling 2073 function's attribute will be upgraded to ``sspreq``. 2074 2075``strictfp`` 2076 This attribute indicates that the function was called from a scope that 2077 requires strict floating-point semantics. LLVM will not attempt any 2078 optimizations that require assumptions about the floating-point rounding 2079 mode or that might alter the state of floating-point status flags that 2080 might otherwise be set or cleared by calling this function. LLVM will 2081 not introduce any new floating-point instructions that may trap. 2082 2083``"denormal-fp-math"`` 2084 This indicates the denormal (subnormal) handling that may be 2085 assumed for the default floating-point environment. This is a 2086 comma separated pair. The elements may be one of ``"ieee"``, 2087 ``"preserve-sign"``, or ``"positive-zero"``. The first entry 2088 indicates the flushing mode for the result of floating point 2089 operations. The second indicates the handling of denormal inputs 2090 to floating point instructions. For compatibility with older 2091 bitcode, if the second value is omitted, both input and output 2092 modes will assume the same mode. 2093 2094 If this is attribute is not specified, the default is 2095 ``"ieee,ieee"``. 2096 2097 If the output mode is ``"preserve-sign"``, or ``"positive-zero"``, 2098 denormal outputs may be flushed to zero by standard floating-point 2099 operations. It is not mandated that flushing to zero occurs, but if 2100 a denormal output is flushed to zero, it must respect the sign 2101 mode. Not all targets support all modes. While this indicates the 2102 expected floating point mode the function will be executed with, 2103 this does not make any attempt to ensure the mode is 2104 consistent. User or platform code is expected to set the floating 2105 point mode appropriately before function entry. 2106 2107 If the input mode is ``"preserve-sign"``, or ``"positive-zero"``, a 2108 floating-point operation must treat any input denormal value as 2109 zero. In some situations, if an instruction does not respect this 2110 mode, the input may need to be converted to 0 as if by 2111 ``@llvm.canonicalize`` during lowering for correctness. 2112 2113``"denormal-fp-math-f32"`` 2114 Same as ``"denormal-fp-math"``, but only controls the behavior of 2115 the 32-bit float type (or vectors of 32-bit floats). If both are 2116 are present, this overrides ``"denormal-fp-math"``. Not all targets 2117 support separately setting the denormal mode per type, and no 2118 attempt is made to diagnose unsupported uses. Currently this 2119 attribute is respected by the AMDGPU and NVPTX backends. 2120 2121``"thunk"`` 2122 This attribute indicates that the function will delegate to some other 2123 function with a tail call. The prototype of a thunk should not be used for 2124 optimization purposes. The caller is expected to cast the thunk prototype to 2125 match the thunk target prototype. 2126 2127``"tls-load-hoist"`` 2128 This attribute indicates that the function will try to reduce redundant 2129 tls address calculation by hoisting tls variable. 2130 2131``uwtable[(sync|async)]`` 2132 This attribute indicates that the ABI being targeted requires that 2133 an unwind table entry be produced for this function even if we can 2134 show that no exceptions passes by it. This is normally the case for 2135 the ELF x86-64 abi, but it can be disabled for some compilation 2136 units. The optional parameter describes what kind of unwind tables 2137 to generate: ``sync`` for normal unwind tables, ``async`` for asynchronous 2138 (instruction precise) unwind tables. Without the parameter, the attribute 2139 ``uwtable`` is equivalent to ``uwtable(async)``. 2140``nocf_check`` 2141 This attribute indicates that no control-flow check will be performed on 2142 the attributed entity. It disables -fcf-protection=<> for a specific 2143 entity to fine grain the HW control flow protection mechanism. The flag 2144 is target independent and currently appertains to a function or function 2145 pointer. 2146``shadowcallstack`` 2147 This attribute indicates that the ShadowCallStack checks are enabled for 2148 the function. The instrumentation checks that the return address for the 2149 function has not changed between the function prolog and epilog. It is 2150 currently x86_64-specific. 2151 2152.. _langref_mustprogress: 2153 2154``mustprogress`` 2155 This attribute indicates that the function is required to return, unwind, 2156 or interact with the environment in an observable way e.g. via a volatile 2157 memory access, I/O, or other synchronization. The ``mustprogress`` 2158 attribute is intended to model the requirements of the first section of 2159 [intro.progress] of the C++ Standard. As a consequence, a loop in a 2160 function with the `mustprogress` attribute can be assumed to terminate if 2161 it does not interact with the environment in an observable way, and 2162 terminating loops without side-effects can be removed. If a `mustprogress` 2163 function does not satisfy this contract, the behavior is undefined. This 2164 attribute does not apply transitively to callees, but does apply to call 2165 sites within the function. Note that `willreturn` implies `mustprogress`. 2166``"warn-stack-size"="<threshold>"`` 2167 This attribute sets a threshold to emit diagnostics once the frame size is 2168 known should the frame size exceed the specified value. It takes one 2169 required integer value, which should be a non-negative integer, and less 2170 than `UINT_MAX`. It's unspecified which threshold will be used when 2171 duplicate definitions are linked together with differing values. 2172``vscale_range(<min>[, <max>])`` 2173 This attribute indicates the minimum and maximum vscale value for the given 2174 function. The min must be greater than 0. A maximum value of 0 means 2175 unbounded. If the optional max value is omitted then max is set to the 2176 value of min. If the attribute is not present, no assumptions are made 2177 about the range of vscale. 2178 2179Call Site Attributes 2180---------------------- 2181 2182In addition to function attributes the following call site only 2183attributes are supported: 2184 2185``vector-function-abi-variant`` 2186 This attribute can be attached to a :ref:`call <i_call>` to list 2187 the vector functions associated to the function. Notice that the 2188 attribute cannot be attached to a :ref:`invoke <i_invoke>` or a 2189 :ref:`callbr <i_callbr>` instruction. The attribute consists of a 2190 comma separated list of mangled names. The order of the list does 2191 not imply preference (it is logically a set). The compiler is free 2192 to pick any listed vector function of its choosing. 2193 2194 The syntax for the mangled names is as follows::: 2195 2196 _ZGV<isa><mask><vlen><parameters>_<scalar_name>[(<vector_redirection>)] 2197 2198 When present, the attribute informs the compiler that the function 2199 ``<scalar_name>`` has a corresponding vector variant that can be 2200 used to perform the concurrent invocation of ``<scalar_name>`` on 2201 vectors. The shape of the vector function is described by the 2202 tokens between the prefix ``_ZGV`` and the ``<scalar_name>`` 2203 token. The standard name of the vector function is 2204 ``_ZGV<isa><mask><vlen><parameters>_<scalar_name>``. When present, 2205 the optional token ``(<vector_redirection>)`` informs the compiler 2206 that a custom name is provided in addition to the standard one 2207 (custom names can be provided for example via the use of ``declare 2208 variant`` in OpenMP 5.0). The declaration of the variant must be 2209 present in the IR Module. The signature of the vector variant is 2210 determined by the rules of the Vector Function ABI (VFABI) 2211 specifications of the target. For Arm and X86, the VFABI can be 2212 found at https://github.com/ARM-software/abi-aa and 2213 https://software.intel.com/content/www/us/en/develop/download/vector-simd-function-abi.html, 2214 respectively. 2215 2216 For X86 and Arm targets, the values of the tokens in the standard 2217 name are those that are defined in the VFABI. LLVM has an internal 2218 ``<isa>`` token that can be used to create scalar-to-vector 2219 mappings for functions that are not directly associated to any of 2220 the target ISAs (for example, some of the mappings stored in the 2221 TargetLibraryInfo). Valid values for the ``<isa>`` token are::: 2222 2223 <isa>:= b | c | d | e -> X86 SSE, AVX, AVX2, AVX512 2224 | n | s -> Armv8 Advanced SIMD, SVE 2225 | __LLVM__ -> Internal LLVM Vector ISA 2226 2227 For all targets currently supported (x86, Arm and Internal LLVM), 2228 the remaining tokens can have the following values::: 2229 2230 <mask>:= M | N -> mask | no mask 2231 2232 <vlen>:= number -> number of lanes 2233 | x -> VLA (Vector Length Agnostic) 2234 2235 <parameters>:= v -> vector 2236 | l | l <number> -> linear 2237 | R | R <number> -> linear with ref modifier 2238 | L | L <number> -> linear with val modifier 2239 | U | U <number> -> linear with uval modifier 2240 | ls <pos> -> runtime linear 2241 | Rs <pos> -> runtime linear with ref modifier 2242 | Ls <pos> -> runtime linear with val modifier 2243 | Us <pos> -> runtime linear with uval modifier 2244 | u -> uniform 2245 2246 <scalar_name>:= name of the scalar function 2247 2248 <vector_redirection>:= optional, custom name of the vector function 2249 2250``preallocated(<ty>)`` 2251 This attribute is required on calls to ``llvm.call.preallocated.arg`` 2252 and cannot be used on any other call. See 2253 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` for more 2254 details. 2255 2256.. _glattrs: 2257 2258Global Attributes 2259----------------- 2260 2261Attributes may be set to communicate additional information about a global variable. 2262Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable 2263are grouped into a single :ref:`attribute group <attrgrp>`. 2264 2265.. _opbundles: 2266 2267Operand Bundles 2268--------------- 2269 2270Operand bundles are tagged sets of SSA values that can be associated 2271with certain LLVM instructions (currently only ``call`` s and 2272``invoke`` s). In a way they are like metadata, but dropping them is 2273incorrect and will change program semantics. 2274 2275Syntax:: 2276 2277 operand bundle set ::= '[' operand bundle (, operand bundle )* ']' 2278 operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')' 2279 bundle operand ::= SSA value 2280 tag ::= string constant 2281 2282Operand bundles are **not** part of a function's signature, and a 2283given function may be called from multiple places with different kinds 2284of operand bundles. This reflects the fact that the operand bundles 2285are conceptually a part of the ``call`` (or ``invoke``), not the 2286callee being dispatched to. 2287 2288Operand bundles are a generic mechanism intended to support 2289runtime-introspection-like functionality for managed languages. While 2290the exact semantics of an operand bundle depend on the bundle tag, 2291there are certain limitations to how much the presence of an operand 2292bundle can influence the semantics of a program. These restrictions 2293are described as the semantics of an "unknown" operand bundle. As 2294long as the behavior of an operand bundle is describable within these 2295restrictions, LLVM does not need to have special knowledge of the 2296operand bundle to not miscompile programs containing it. 2297 2298- The bundle operands for an unknown operand bundle escape in unknown 2299 ways before control is transferred to the callee or invokee. 2300- Calls and invokes with operand bundles have unknown read / write 2301 effect on the heap on entry and exit (even if the call target is 2302 ``readnone`` or ``readonly``), unless they're overridden with 2303 callsite specific attributes. 2304- An operand bundle at a call site cannot change the implementation 2305 of the called function. Inter-procedural optimizations work as 2306 usual as long as they take into account the first two properties. 2307 2308More specific types of operand bundles are described below. 2309 2310.. _deopt_opbundles: 2311 2312Deoptimization Operand Bundles 2313^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2314 2315Deoptimization operand bundles are characterized by the ``"deopt"`` 2316operand bundle tag. These operand bundles represent an alternate 2317"safe" continuation for the call site they're attached to, and can be 2318used by a suitable runtime to deoptimize the compiled frame at the 2319specified call site. There can be at most one ``"deopt"`` operand 2320bundle attached to a call site. Exact details of deoptimization is 2321out of scope for the language reference, but it usually involves 2322rewriting a compiled frame into a set of interpreted frames. 2323 2324From the compiler's perspective, deoptimization operand bundles make 2325the call sites they're attached to at least ``readonly``. They read 2326through all of their pointer typed operands (even if they're not 2327otherwise escaped) and the entire visible heap. Deoptimization 2328operand bundles do not capture their operands except during 2329deoptimization, in which case control will not be returned to the 2330compiled frame. 2331 2332The inliner knows how to inline through calls that have deoptimization 2333operand bundles. Just like inlining through a normal call site 2334involves composing the normal and exceptional continuations, inlining 2335through a call site with a deoptimization operand bundle needs to 2336appropriately compose the "safe" deoptimization continuation. The 2337inliner does this by prepending the parent's deoptimization 2338continuation to every deoptimization continuation in the inlined body. 2339E.g. inlining ``@f`` into ``@g`` in the following example 2340 2341.. code-block:: llvm 2342 2343 define void @f() { 2344 call void @x() ;; no deopt state 2345 call void @y() [ "deopt"(i32 10) ] 2346 call void @y() [ "deopt"(i32 10), "unknown"(i8* null) ] 2347 ret void 2348 } 2349 2350 define void @g() { 2351 call void @f() [ "deopt"(i32 20) ] 2352 ret void 2353 } 2354 2355will result in 2356 2357.. code-block:: llvm 2358 2359 define void @g() { 2360 call void @x() ;; still no deopt state 2361 call void @y() [ "deopt"(i32 20, i32 10) ] 2362 call void @y() [ "deopt"(i32 20, i32 10), "unknown"(i8* null) ] 2363 ret void 2364 } 2365 2366It is the frontend's responsibility to structure or encode the 2367deoptimization state in a way that syntactically prepending the 2368caller's deoptimization state to the callee's deoptimization state is 2369semantically equivalent to composing the caller's deoptimization 2370continuation after the callee's deoptimization continuation. 2371 2372.. _ob_funclet: 2373 2374Funclet Operand Bundles 2375^^^^^^^^^^^^^^^^^^^^^^^ 2376 2377Funclet operand bundles are characterized by the ``"funclet"`` 2378operand bundle tag. These operand bundles indicate that a call site 2379is within a particular funclet. There can be at most one 2380``"funclet"`` operand bundle attached to a call site and it must have 2381exactly one bundle operand. 2382 2383If any funclet EH pads have been "entered" but not "exited" (per the 2384`description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_), 2385it is undefined behavior to execute a ``call`` or ``invoke`` which: 2386 2387* does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind 2388 intrinsic, or 2389* has a ``"funclet"`` bundle whose operand is not the most-recently-entered 2390 not-yet-exited funclet EH pad. 2391 2392Similarly, if no funclet EH pads have been entered-but-not-yet-exited, 2393executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior. 2394 2395GC Transition Operand Bundles 2396^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2397 2398GC transition operand bundles are characterized by the 2399``"gc-transition"`` operand bundle tag. These operand bundles mark a 2400call as a transition between a function with one GC strategy to a 2401function with a different GC strategy. If coordinating the transition 2402between GC strategies requires additional code generation at the call 2403site, these bundles may contain any values that are needed by the 2404generated code. For more details, see :ref:`GC Transitions 2405<gc_transition_args>`. 2406 2407The bundle contain an arbitrary list of Values which need to be passed 2408to GC transition code. They will be lowered and passed as operands to 2409the appropriate GC_TRANSITION nodes in the selection DAG. It is assumed 2410that these arguments must be available before and after (but not 2411necessarily during) the execution of the callee. 2412 2413.. _assume_opbundles: 2414 2415Assume Operand Bundles 2416^^^^^^^^^^^^^^^^^^^^^^ 2417 2418Operand bundles on an :ref:`llvm.assume <int_assume>` allows representing 2419assumptions that a :ref:`parameter attribute <paramattrs>` or a 2420:ref:`function attribute <fnattrs>` holds for a certain value at a certain 2421location. Operand bundles enable assumptions that are either hard or impossible 2422to represent as a boolean argument of an :ref:`llvm.assume <int_assume>`. 2423 2424An assume operand bundle has the form: 2425 2426:: 2427 2428 "<tag>"([ <holds for value> [, <attribute argument>] ]) 2429 2430* The tag of the operand bundle is usually the name of attribute that can be 2431 assumed to hold. It can also be `ignore`, this tag doesn't contain any 2432 information and should be ignored. 2433* The first argument if present is the value for which the attribute hold. 2434* The second argument if present is an argument of the attribute. 2435 2436If there are no arguments the attribute is a property of the call location. 2437 2438For example: 2439 2440.. code-block:: llvm 2441 2442 call void @llvm.assume(i1 true) ["align"(i32* %val, i32 8)] 2443 2444allows the optimizer to assume that at location of call to 2445:ref:`llvm.assume <int_assume>` ``%val`` has an alignment of at least 8. 2446 2447.. code-block:: llvm 2448 2449 call void @llvm.assume(i1 %cond) ["cold"(), "nonnull"(i64* %val)] 2450 2451allows the optimizer to assume that the :ref:`llvm.assume <int_assume>` 2452call location is cold and that ``%val`` may not be null. 2453 2454Just like for the argument of :ref:`llvm.assume <int_assume>`, if any of the 2455provided guarantees are violated at runtime the behavior is undefined. 2456 2457While attributes expect constant arguments, assume operand bundles may be 2458provided a dynamic value, for example: 2459 2460.. code-block:: llvm 2461 2462 call void @llvm.assume(i1 true) ["align"(i32* %val, i32 %align)] 2463 2464If the operand bundle value violates any requirements on the attribute value, 2465the behavior is undefined, unless one of the following exceptions applies: 2466 2467* ``"assume"`` operand bundles may specify a non-power-of-two alignment 2468 (including a zero alignment). If this is the case, then the pointer value 2469 must be a null pointer, otherwise the behavior is undefined. 2470 2471Even if the assumed property can be encoded as a boolean value, like 2472``nonnull``, using operand bundles to express the property can still have 2473benefits: 2474 2475* Attributes that can be expressed via operand bundles are directly the 2476 property that the optimizer uses and cares about. Encoding attributes as 2477 operand bundles removes the need for an instruction sequence that represents 2478 the property (e.g., `icmp ne i32* %p, null` for `nonnull`) and for the 2479 optimizer to deduce the property from that instruction sequence. 2480* Expressing the property using operand bundles makes it easy to identify the 2481 use of the value as a use in an :ref:`llvm.assume <int_assume>`. This then 2482 simplifies and improves heuristics, e.g., for use "use-sensitive" 2483 optimizations. 2484 2485.. _ob_preallocated: 2486 2487Preallocated Operand Bundles 2488^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2489 2490Preallocated operand bundles are characterized by the ``"preallocated"`` 2491operand bundle tag. These operand bundles allow separation of the allocation 2492of the call argument memory from the call site. This is necessary to pass 2493non-trivially copyable objects by value in a way that is compatible with MSVC 2494on some targets. There can be at most one ``"preallocated"`` operand bundle 2495attached to a call site and it must have exactly one bundle operand, which is 2496a token generated by ``@llvm.call.preallocated.setup``. A call with this 2497operand bundle should not adjust the stack before entering the function, as 2498that will have been done by one of the ``@llvm.call.preallocated.*`` intrinsics. 2499 2500.. code-block:: llvm 2501 2502 %foo = type { i64, i32 } 2503 2504 ... 2505 2506 %t = call token @llvm.call.preallocated.setup(i32 1) 2507 %a = call i8* @llvm.call.preallocated.arg(token %t, i32 0) preallocated(%foo) 2508 %b = bitcast i8* %a to %foo* 2509 ; initialize %b 2510 call void @bar(i32 42, %foo* preallocated(%foo) %b) ["preallocated"(token %t)] 2511 2512.. _ob_gc_live: 2513 2514GC Live Operand Bundles 2515^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2516 2517A "gc-live" operand bundle is only valid on a :ref:`gc.statepoint <gc_statepoint>` 2518intrinsic. The operand bundle must contain every pointer to a garbage collected 2519object which potentially needs to be updated by the garbage collector. 2520 2521When lowered, any relocated value will be recorded in the corresponding 2522:ref:`stackmap entry <statepoint-stackmap-format>`. See the intrinsic description 2523for further details. 2524 2525ObjC ARC Attached Call Operand Bundles 2526^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2527 2528A ``"clang.arc.attachedcall"`` operand bundle on a call indicates the call is 2529implicitly followed by a marker instruction and a call to an ObjC runtime 2530function that uses the result of the call. The operand bundle takes a mandatory 2531pointer to the runtime function (``@objc_retainAutoreleasedReturnValue`` or 2532``@objc_unsafeClaimAutoreleasedReturnValue``). 2533The return value of a call with this bundle is used by a call to 2534``@llvm.objc.clang.arc.noop.use`` unless the called function's return type is 2535void, in which case the operand bundle is ignored. 2536 2537.. code-block:: llvm 2538 2539 ; The marker instruction and a runtime function call are inserted after the call 2540 ; to @foo. 2541 call i8* @foo() [ "clang.arc.attachedcall"(i8* (i8*)* @objc_retainAutoreleasedReturnValue) ] 2542 call i8* @foo() [ "clang.arc.attachedcall"(i8* (i8*)* @objc_unsafeClaimAutoreleasedReturnValue) ] 2543 2544The operand bundle is needed to ensure the call is immediately followed by the 2545marker instruction and the ObjC runtime call in the final output. 2546 2547.. _ob_ptrauth: 2548 2549Pointer Authentication Operand Bundles 2550^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2551 2552Pointer Authentication operand bundles are characterized by the 2553``"ptrauth"`` operand bundle tag. They are described in the 2554`Pointer Authentication <PointerAuth.html#operand-bundle>`__ document. 2555 2556.. _moduleasm: 2557 2558Module-Level Inline Assembly 2559---------------------------- 2560 2561Modules may contain "module-level inline asm" blocks, which corresponds 2562to the GCC "file scope inline asm" blocks. These blocks are internally 2563concatenated by LLVM and treated as a single unit, but may be separated 2564in the ``.ll`` file if desired. The syntax is very simple: 2565 2566.. code-block:: llvm 2567 2568 module asm "inline asm code goes here" 2569 module asm "more can go here" 2570 2571The strings can contain any character by escaping non-printable 2572characters. The escape sequence used is simply "\\xx" where "xx" is the 2573two digit hex code for the number. 2574 2575Note that the assembly string *must* be parseable by LLVM's integrated assembler 2576(unless it is disabled), even when emitting a ``.s`` file. 2577 2578.. _langref_datalayout: 2579 2580Data Layout 2581----------- 2582 2583A module may specify a target specific data layout string that specifies 2584how data is to be laid out in memory. The syntax for the data layout is 2585simply: 2586 2587.. code-block:: llvm 2588 2589 target datalayout = "layout specification" 2590 2591The *layout specification* consists of a list of specifications 2592separated by the minus sign character ('-'). Each specification starts 2593with a letter and may include other information after the letter to 2594define some aspect of the data layout. The specifications accepted are 2595as follows: 2596 2597``E`` 2598 Specifies that the target lays out data in big-endian form. That is, 2599 the bits with the most significance have the lowest address 2600 location. 2601``e`` 2602 Specifies that the target lays out data in little-endian form. That 2603 is, the bits with the least significance have the lowest address 2604 location. 2605``S<size>`` 2606 Specifies the natural alignment of the stack in bits. Alignment 2607 promotion of stack variables is limited to the natural stack 2608 alignment to avoid dynamic stack realignment. The stack alignment 2609 must be a multiple of 8-bits. If omitted, the natural stack 2610 alignment defaults to "unspecified", which does not prevent any 2611 alignment promotions. 2612``P<address space>`` 2613 Specifies the address space that corresponds to program memory. 2614 Harvard architectures can use this to specify what space LLVM 2615 should place things such as functions into. If omitted, the 2616 program memory space defaults to the default address space of 0, 2617 which corresponds to a Von Neumann architecture that has code 2618 and data in the same space. 2619``G<address space>`` 2620 Specifies the address space to be used by default when creating global 2621 variables. If omitted, the globals address space defaults to the default 2622 address space 0. 2623 Note: variable declarations without an address space are always created in 2624 address space 0, this property only affects the default value to be used 2625 when creating globals without additional contextual information (e.g. in 2626 LLVM passes). 2627``A<address space>`` 2628 Specifies the address space of objects created by '``alloca``'. 2629 Defaults to the default address space of 0. 2630``p[n]:<size>:<abi>[:<pref>][:<idx>]`` 2631 This specifies the *size* of a pointer and its ``<abi>`` and 2632 ``<pref>``\erred alignments for address space ``n``. ``<pref>`` is optional 2633 and defaults to ``<abi>``. The fourth parameter ``<idx>`` is the size of the 2634 index that used for address calculation. If not 2635 specified, the default index size is equal to the pointer size. All sizes 2636 are in bits. The address space, ``n``, is optional, and if not specified, 2637 denotes the default address space 0. The value of ``n`` must be 2638 in the range [1,2^23). 2639``i<size>:<abi>[:<pref>]`` 2640 This specifies the alignment for an integer type of a given bit 2641 ``<size>``. The value of ``<size>`` must be in the range [1,2^23). 2642 ``<pref>`` is optional and defaults to ``<abi>``. 2643``v<size>:<abi>[:<pref>]`` 2644 This specifies the alignment for a vector type of a given bit 2645 ``<size>``. The value of ``<size>`` must be in the range [1,2^23). 2646 ``<pref>`` is optional and defaults to ``<abi>``. 2647``f<size>:<abi>[:<pref>]`` 2648 This specifies the alignment for a floating-point type of a given bit 2649 ``<size>``. Only values of ``<size>`` that are supported by the target 2650 will work. 32 (float) and 64 (double) are supported on all targets; 80 2651 or 128 (different flavors of long double) are also supported on some 2652 targets. The value of ``<size>`` must be in the range [1,2^23). 2653 ``<pref>`` is optional and defaults to ``<abi>``. 2654``a:<abi>[:<pref>]`` 2655 This specifies the alignment for an object of aggregate type. 2656 ``<pref>`` is optional and defaults to ``<abi>``. 2657``F<type><abi>`` 2658 This specifies the alignment for function pointers. 2659 The options for ``<type>`` are: 2660 2661 * ``i``: The alignment of function pointers is independent of the alignment 2662 of functions, and is a multiple of ``<abi>``. 2663 * ``n``: The alignment of function pointers is a multiple of the explicit 2664 alignment specified on the function, and is a multiple of ``<abi>``. 2665``m:<mangling>`` 2666 If present, specifies that llvm names are mangled in the output. Symbols 2667 prefixed with the mangling escape character ``\01`` are passed through 2668 directly to the assembler without the escape character. The mangling style 2669 options are 2670 2671 * ``e``: ELF mangling: Private symbols get a ``.L`` prefix. 2672 * ``l``: GOFF mangling: Private symbols get a ``@`` prefix. 2673 * ``m``: Mips mangling: Private symbols get a ``$`` prefix. 2674 * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other 2675 symbols get a ``_`` prefix. 2676 * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix. 2677 Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``, 2678 ``__fastcall``, and ``__vectorcall`` have custom mangling that appends 2679 ``@N`` where N is the number of bytes used to pass parameters. C++ symbols 2680 starting with ``?`` are not mangled in any way. 2681 * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C 2682 symbols do not receive a ``_`` prefix. 2683 * ``a``: XCOFF mangling: Private symbols get a ``L..`` prefix. 2684``n<size1>:<size2>:<size3>...`` 2685 This specifies a set of native integer widths for the target CPU in 2686 bits. For example, it might contain ``n32`` for 32-bit PowerPC, 2687 ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of 2688 this set are considered to support most general arithmetic operations 2689 efficiently. 2690``ni:<address space0>:<address space1>:<address space2>...`` 2691 This specifies pointer types with the specified address spaces 2692 as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0`` 2693 address space cannot be specified as non-integral. 2694 2695On every specification that takes a ``<abi>:<pref>``, specifying the 2696``<pref>`` alignment is optional. If omitted, the preceding ``:`` 2697should be omitted too and ``<pref>`` will be equal to ``<abi>``. 2698 2699When constructing the data layout for a given target, LLVM starts with a 2700default set of specifications which are then (possibly) overridden by 2701the specifications in the ``datalayout`` keyword. The default 2702specifications are given in this list: 2703 2704- ``e`` - little endian 2705- ``p:64:64:64`` - 64-bit pointers with 64-bit alignment. 2706- ``p[n]:64:64:64`` - Other address spaces are assumed to be the 2707 same as the default address space. 2708- ``S0`` - natural stack alignment is unspecified 2709- ``i1:8:8`` - i1 is 8-bit (byte) aligned 2710- ``i8:8:8`` - i8 is 8-bit (byte) aligned 2711- ``i16:16:16`` - i16 is 16-bit aligned 2712- ``i32:32:32`` - i32 is 32-bit aligned 2713- ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred 2714 alignment of 64-bits 2715- ``f16:16:16`` - half is 16-bit aligned 2716- ``f32:32:32`` - float is 32-bit aligned 2717- ``f64:64:64`` - double is 64-bit aligned 2718- ``f128:128:128`` - quad is 128-bit aligned 2719- ``v64:64:64`` - 64-bit vector is 64-bit aligned 2720- ``v128:128:128`` - 128-bit vector is 128-bit aligned 2721- ``a:0:64`` - aggregates are 64-bit aligned 2722 2723When LLVM is determining the alignment for a given type, it uses the 2724following rules: 2725 2726#. If the type sought is an exact match for one of the specifications, 2727 that specification is used. 2728#. If no match is found, and the type sought is an integer type, then 2729 the smallest integer type that is larger than the bitwidth of the 2730 sought type is used. If none of the specifications are larger than 2731 the bitwidth then the largest integer type is used. For example, 2732 given the default specifications above, the i7 type will use the 2733 alignment of i8 (next largest) while both i65 and i256 will use the 2734 alignment of i64 (largest specified). 2735 2736The function of the data layout string may not be what you expect. 2737Notably, this is not a specification from the frontend of what alignment 2738the code generator should use. 2739 2740Instead, if specified, the target data layout is required to match what 2741the ultimate *code generator* expects. This string is used by the 2742mid-level optimizers to improve code, and this only works if it matches 2743what the ultimate code generator uses. There is no way to generate IR 2744that does not embed this target-specific detail into the IR. If you 2745don't specify the string, the default specifications will be used to 2746generate a Data Layout and the optimization phases will operate 2747accordingly and introduce target specificity into the IR with respect to 2748these default specifications. 2749 2750.. _langref_triple: 2751 2752Target Triple 2753------------- 2754 2755A module may specify a target triple string that describes the target 2756host. The syntax for the target triple is simply: 2757 2758.. code-block:: llvm 2759 2760 target triple = "x86_64-apple-macosx10.7.0" 2761 2762The *target triple* string consists of a series of identifiers delimited 2763by the minus sign character ('-'). The canonical forms are: 2764 2765:: 2766 2767 ARCHITECTURE-VENDOR-OPERATING_SYSTEM 2768 ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT 2769 2770This information is passed along to the backend so that it generates 2771code for the proper architecture. It's possible to override this on the 2772command line with the ``-mtriple`` command line option. 2773 2774.. _objectlifetime: 2775 2776Object Lifetime 2777---------------------- 2778 2779A memory object, or simply object, is a region of a memory space that is 2780reserved by a memory allocation such as :ref:`alloca <i_alloca>`, heap 2781allocation calls, and global variable definitions. 2782Once it is allocated, the bytes stored in the region can only be read or written 2783through a pointer that is :ref:`based on <pointeraliasing>` the allocation 2784value. 2785If a pointer that is not based on the object tries to read or write to the 2786object, it is undefined behavior. 2787 2788A lifetime of a memory object is a property that decides its accessibility. 2789Unless stated otherwise, a memory object is alive since its allocation, and 2790dead after its deallocation. 2791It is undefined behavior to access a memory object that isn't alive, but 2792operations that don't dereference it such as 2793:ref:`getelementptr <i_getelementptr>`, :ref:`ptrtoint <i_ptrtoint>` and 2794:ref:`icmp <i_icmp>` return a valid result. 2795This explains code motion of these instructions across operations that 2796impact the object's lifetime. 2797A stack object's lifetime can be explicitly specified using 2798:ref:`llvm.lifetime.start <int_lifestart>` and 2799:ref:`llvm.lifetime.end <int_lifeend>` intrinsic function calls. 2800 2801.. _pointeraliasing: 2802 2803Pointer Aliasing Rules 2804---------------------- 2805 2806Any memory access must be done through a pointer value associated with 2807an address range of the memory access, otherwise the behavior is 2808undefined. Pointer values are associated with address ranges according 2809to the following rules: 2810 2811- A pointer value is associated with the addresses associated with any 2812 value it is *based* on. 2813- An address of a global variable is associated with the address range 2814 of the variable's storage. 2815- The result value of an allocation instruction is associated with the 2816 address range of the allocated storage. 2817- A null pointer in the default address-space is associated with no 2818 address. 2819- An :ref:`undef value <undefvalues>` in *any* address-space is 2820 associated with no address. 2821- An integer constant other than zero or a pointer value returned from 2822 a function not defined within LLVM may be associated with address 2823 ranges allocated through mechanisms other than those provided by 2824 LLVM. Such ranges shall not overlap with any ranges of addresses 2825 allocated by mechanisms provided by LLVM. 2826 2827A pointer value is *based* on another pointer value according to the 2828following rules: 2829 2830- A pointer value formed from a scalar ``getelementptr`` operation is *based* on 2831 the pointer-typed operand of the ``getelementptr``. 2832- The pointer in lane *l* of the result of a vector ``getelementptr`` operation 2833 is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand 2834 of the ``getelementptr``. 2835- The result value of a ``bitcast`` is *based* on the operand of the 2836 ``bitcast``. 2837- A pointer value formed by an ``inttoptr`` is *based* on all pointer 2838 values that contribute (directly or indirectly) to the computation of 2839 the pointer's value. 2840- The "*based* on" relationship is transitive. 2841 2842Note that this definition of *"based"* is intentionally similar to the 2843definition of *"based"* in C99, though it is slightly weaker. 2844 2845LLVM IR does not associate types with memory. The result type of a 2846``load`` merely indicates the size and alignment of the memory from 2847which to load, as well as the interpretation of the value. The first 2848operand type of a ``store`` similarly only indicates the size and 2849alignment of the store. 2850 2851Consequently, type-based alias analysis, aka TBAA, aka 2852``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR. 2853:ref:`Metadata <metadata>` may be used to encode additional information 2854which specialized optimization passes may use to implement type-based 2855alias analysis. 2856 2857.. _pointercapture: 2858 2859Pointer Capture 2860--------------- 2861 2862Given a function call and a pointer that is passed as an argument or stored in 2863the memory before the call, a pointer is *captured* by the call if it makes a 2864copy of any part of the pointer that outlives the call. 2865To be precise, a pointer is captured if one or more of the following conditions 2866hold: 2867 28681. The call stores any bit of the pointer carrying information into a place, 2869 and the stored bits can be read from the place by the caller after this call 2870 exits. 2871 2872.. code-block:: llvm 2873 2874 @glb = global i8* null 2875 @glb2 = global i8* null 2876 @glb3 = global i8* null 2877 @glbi = global i32 0 2878 2879 define i8* @f(i8* %a, i8* %b, i8* %c, i8* %d, i8* %e) { 2880 store i8* %a, i8** @glb ; %a is captured by this call 2881 2882 store i8* %b, i8** @glb2 ; %b isn't captured because the stored value is overwritten by the store below 2883 store i8* null, i8** @glb2 2884 2885 store i8* %c, i8** @glb3 2886 call void @g() ; If @g makes a copy of %c that outlives this call (@f), %c is captured 2887 store i8* null, i8** @glb3 2888 2889 %i = ptrtoint i8* %d to i64 2890 %j = trunc i64 %i to i32 2891 store i32 %j, i32* @glbi ; %d is captured 2892 2893 ret i8* %e ; %e is captured 2894 } 2895 28962. The call stores any bit of the pointer carrying information into a place, 2897 and the stored bits can be safely read from the place by another thread via 2898 synchronization. 2899 2900.. code-block:: llvm 2901 2902 @lock = global i1 true 2903 2904 define void @f(i8* %a) { 2905 store i8* %a, i8** @glb 2906 store atomic i1 false, i1* @lock release ; %a is captured because another thread can safely read @glb 2907 store i8* null, i8** @glb 2908 ret void 2909 } 2910 29113. The call's behavior depends on any bit of the pointer carrying information. 2912 2913.. code-block:: llvm 2914 2915 @glb = global i8 0 2916 2917 define void @f(i8* %a) { 2918 %c = icmp eq i8* %a, @glb 2919 br i1 %c, label %BB_EXIT, label %BB_CONTINUE ; escapes %a 2920 BB_EXIT: 2921 call void @exit() 2922 unreachable 2923 BB_CONTINUE: 2924 ret void 2925 } 2926 29274. The pointer is used in a volatile access as its address. 2928 2929 2930.. _volatile: 2931 2932Volatile Memory Accesses 2933------------------------ 2934 2935Certain memory accesses, such as :ref:`load <i_load>`'s, 2936:ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be 2937marked ``volatile``. The optimizers must not change the number of 2938volatile operations or change their order of execution relative to other 2939volatile operations. The optimizers *may* change the order of volatile 2940operations relative to non-volatile operations. This is not Java's 2941"volatile" and has no cross-thread synchronization behavior. 2942 2943A volatile load or store may have additional target-specific semantics. 2944Any volatile operation can have side effects, and any volatile operation 2945can read and/or modify state which is not accessible via a regular load 2946or store in this module. Volatile operations may use addresses which do 2947not point to memory (like MMIO registers). This means the compiler may 2948not use a volatile operation to prove a non-volatile access to that 2949address has defined behavior. 2950 2951The allowed side-effects for volatile accesses are limited. If a 2952non-volatile store to a given address would be legal, a volatile 2953operation may modify the memory at that address. A volatile operation 2954may not modify any other memory accessible by the module being compiled. 2955A volatile operation may not call any code in the current module. 2956 2957The compiler may assume execution will continue after a volatile operation, 2958so operations which modify memory or may have undefined behavior can be 2959hoisted past a volatile operation. 2960 2961As an exception to the preceding rule, the compiler may not assume execution 2962will continue after a volatile store operation. This restriction is necessary 2963to support the somewhat common pattern in C of intentionally storing to an 2964invalid pointer to crash the program. In the future, it might make sense to 2965allow frontends to control this behavior. 2966 2967IR-level volatile loads and stores cannot safely be optimized into llvm.memcpy 2968or llvm.memmove intrinsics even when those intrinsics are flagged volatile. 2969Likewise, the backend should never split or merge target-legal volatile 2970load/store instructions. Similarly, IR-level volatile loads and stores cannot 2971change from integer to floating-point or vice versa. 2972 2973.. admonition:: Rationale 2974 2975 Platforms may rely on volatile loads and stores of natively supported 2976 data width to be executed as single instruction. For example, in C 2977 this holds for an l-value of volatile primitive type with native 2978 hardware support, but not necessarily for aggregate types. The 2979 frontend upholds these expectations, which are intentionally 2980 unspecified in the IR. The rules above ensure that IR transformations 2981 do not violate the frontend's contract with the language. 2982 2983.. _memmodel: 2984 2985Memory Model for Concurrent Operations 2986-------------------------------------- 2987 2988The LLVM IR does not define any way to start parallel threads of 2989execution or to register signal handlers. Nonetheless, there are 2990platform-specific ways to create them, and we define LLVM IR's behavior 2991in their presence. This model is inspired by the C++0x memory model. 2992 2993For a more informal introduction to this model, see the :doc:`Atomics`. 2994 2995We define a *happens-before* partial order as the least partial order 2996that 2997 2998- Is a superset of single-thread program order, and 2999- When a *synchronizes-with* ``b``, includes an edge from ``a`` to 3000 ``b``. *Synchronizes-with* pairs are introduced by platform-specific 3001 techniques, like pthread locks, thread creation, thread joining, 3002 etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering 3003 Constraints <ordering>`). 3004 3005Note that program order does not introduce *happens-before* edges 3006between a thread and signals executing inside that thread. 3007 3008Every (defined) read operation (load instructions, memcpy, atomic 3009loads/read-modify-writes, etc.) R reads a series of bytes written by 3010(defined) write operations (store instructions, atomic 3011stores/read-modify-writes, memcpy, etc.). For the purposes of this 3012section, initialized globals are considered to have a write of the 3013initializer which is atomic and happens before any other read or write 3014of the memory in question. For each byte of a read R, R\ :sub:`byte` 3015may see any write to the same byte, except: 3016 3017- If write\ :sub:`1` happens before write\ :sub:`2`, and 3018 write\ :sub:`2` happens before R\ :sub:`byte`, then 3019 R\ :sub:`byte` does not see write\ :sub:`1`. 3020- If R\ :sub:`byte` happens before write\ :sub:`3`, then 3021 R\ :sub:`byte` does not see write\ :sub:`3`. 3022 3023Given that definition, R\ :sub:`byte` is defined as follows: 3024 3025- If R is volatile, the result is target-dependent. (Volatile is 3026 supposed to give guarantees which can support ``sig_atomic_t`` in 3027 C/C++, and may be used for accesses to addresses that do not behave 3028 like normal memory. It does not generally provide cross-thread 3029 synchronization.) 3030- Otherwise, if there is no write to the same byte that happens before 3031 R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte. 3032- Otherwise, if R\ :sub:`byte` may see exactly one write, 3033 R\ :sub:`byte` returns the value written by that write. 3034- Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may 3035 see are atomic, it chooses one of the values written. See the :ref:`Atomic 3036 Memory Ordering Constraints <ordering>` section for additional 3037 constraints on how the choice is made. 3038- Otherwise R\ :sub:`byte` returns ``undef``. 3039 3040R returns the value composed of the series of bytes it read. This 3041implies that some bytes within the value may be ``undef`` **without** 3042the entire value being ``undef``. Note that this only defines the 3043semantics of the operation; it doesn't mean that targets will emit more 3044than one instruction to read the series of bytes. 3045 3046Note that in cases where none of the atomic intrinsics are used, this 3047model places only one restriction on IR transformations on top of what 3048is required for single-threaded execution: introducing a store to a byte 3049which might not otherwise be stored is not allowed in general. 3050(Specifically, in the case where another thread might write to and read 3051from an address, introducing a store can change a load that may see 3052exactly one write into a load that may see multiple writes.) 3053 3054.. _ordering: 3055 3056Atomic Memory Ordering Constraints 3057---------------------------------- 3058 3059Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`, 3060:ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`, 3061:ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take 3062ordering parameters that determine which other atomic instructions on 3063the same address they *synchronize with*. These semantics are borrowed 3064from Java and C++0x, but are somewhat more colloquial. If these 3065descriptions aren't precise enough, check those specs (see spec 3066references in the :doc:`atomics guide <Atomics>`). 3067:ref:`fence <i_fence>` instructions treat these orderings somewhat 3068differently since they don't take an address. See that instruction's 3069documentation for details. 3070 3071For a simpler introduction to the ordering constraints, see the 3072:doc:`Atomics`. 3073 3074``unordered`` 3075 The set of values that can be read is governed by the happens-before 3076 partial order. A value cannot be read unless some operation wrote 3077 it. This is intended to provide a guarantee strong enough to model 3078 Java's non-volatile shared variables. This ordering cannot be 3079 specified for read-modify-write operations; it is not strong enough 3080 to make them atomic in any interesting way. 3081``monotonic`` 3082 In addition to the guarantees of ``unordered``, there is a single 3083 total order for modifications by ``monotonic`` operations on each 3084 address. All modification orders must be compatible with the 3085 happens-before order. There is no guarantee that the modification 3086 orders can be combined to a global total order for the whole program 3087 (and this often will not be possible). The read in an atomic 3088 read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and 3089 :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification 3090 order immediately before the value it writes. If one atomic read 3091 happens before another atomic read of the same address, the later 3092 read must see the same value or a later value in the address's 3093 modification order. This disallows reordering of ``monotonic`` (or 3094 stronger) operations on the same address. If an address is written 3095 ``monotonic``-ally by one thread, and other threads ``monotonic``-ally 3096 read that address repeatedly, the other threads must eventually see 3097 the write. This corresponds to the C++0x/C1x 3098 ``memory_order_relaxed``. 3099``acquire`` 3100 In addition to the guarantees of ``monotonic``, a 3101 *synchronizes-with* edge may be formed with a ``release`` operation. 3102 This is intended to model C++'s ``memory_order_acquire``. 3103``release`` 3104 In addition to the guarantees of ``monotonic``, if this operation 3105 writes a value which is subsequently read by an ``acquire`` 3106 operation, it *synchronizes-with* that operation. (This isn't a 3107 complete description; see the C++0x definition of a release 3108 sequence.) This corresponds to the C++0x/C1x 3109 ``memory_order_release``. 3110``acq_rel`` (acquire+release) 3111 Acts as both an ``acquire`` and ``release`` operation on its 3112 address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``. 3113``seq_cst`` (sequentially consistent) 3114 In addition to the guarantees of ``acq_rel`` (``acquire`` for an 3115 operation that only reads, ``release`` for an operation that only 3116 writes), there is a global total order on all 3117 sequentially-consistent operations on all addresses, which is 3118 consistent with the *happens-before* partial order and with the 3119 modification orders of all the affected addresses. Each 3120 sequentially-consistent read sees the last preceding write to the 3121 same address in this global order. This corresponds to the C++0x/C1x 3122 ``memory_order_seq_cst`` and Java volatile. 3123 3124.. _syncscope: 3125 3126If an atomic operation is marked ``syncscope("singlethread")``, it only 3127*synchronizes with* and only participates in the seq\_cst total orderings of 3128other operations running in the same thread (for example, in signal handlers). 3129 3130If an atomic operation is marked ``syncscope("<target-scope>")``, where 3131``<target-scope>`` is a target specific synchronization scope, then it is target 3132dependent if it *synchronizes with* and participates in the seq\_cst total 3133orderings of other operations. 3134 3135Otherwise, an atomic operation that is not marked ``syncscope("singlethread")`` 3136or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the 3137seq\_cst total orderings of other operations that are not marked 3138``syncscope("singlethread")`` or ``syncscope("<target-scope>")``. 3139 3140.. _floatenv: 3141 3142Floating-Point Environment 3143-------------------------- 3144 3145The default LLVM floating-point environment assumes that floating-point 3146instructions do not have side effects. Results assume the round-to-nearest 3147rounding mode. No floating-point exception state is maintained in this 3148environment. Therefore, there is no attempt to create or preserve invalid 3149operation (SNaN) or division-by-zero exceptions. 3150 3151The benefit of this exception-free assumption is that floating-point 3152operations may be speculated freely without any other fast-math relaxations 3153to the floating-point model. 3154 3155Code that requires different behavior than this should use the 3156:ref:`Constrained Floating-Point Intrinsics <constrainedfp>`. 3157 3158.. _fastmath: 3159 3160Fast-Math Flags 3161--------------- 3162 3163LLVM IR floating-point operations (:ref:`fneg <i_fneg>`, :ref:`fadd <i_fadd>`, 3164:ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`, 3165:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`), :ref:`phi <i_phi>`, 3166:ref:`select <i_select>` and :ref:`call <i_call>` 3167may use the following flags to enable otherwise unsafe 3168floating-point transformations. 3169 3170``nnan`` 3171 No NaNs - Allow optimizations to assume the arguments and result are not 3172 NaN. If an argument is a nan, or the result would be a nan, it produces 3173 a :ref:`poison value <poisonvalues>` instead. 3174 3175``ninf`` 3176 No Infs - Allow optimizations to assume the arguments and result are not 3177 +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it 3178 produces a :ref:`poison value <poisonvalues>` instead. 3179 3180``nsz`` 3181 No Signed Zeros - Allow optimizations to treat the sign of a zero 3182 argument or result as insignificant. This does not imply that -0.0 3183 is poison and/or guaranteed to not exist in the operation. 3184 3185``arcp`` 3186 Allow Reciprocal - Allow optimizations to use the reciprocal of an 3187 argument rather than perform division. 3188 3189``contract`` 3190 Allow floating-point contraction (e.g. fusing a multiply followed by an 3191 addition into a fused multiply-and-add). This does not enable reassociating 3192 to form arbitrary contractions. For example, ``(a*b) + (c*d) + e`` can not 3193 be transformed into ``(a*b) + ((c*d) + e)`` to create two fma operations. 3194 3195``afn`` 3196 Approximate functions - Allow substitution of approximate calculations for 3197 functions (sin, log, sqrt, etc). See floating-point intrinsic definitions 3198 for places where this can apply to LLVM's intrinsic math functions. 3199 3200``reassoc`` 3201 Allow reassociation transformations for floating-point instructions. 3202 This may dramatically change results in floating-point. 3203 3204``fast`` 3205 This flag implies all of the others. 3206 3207.. _uselistorder: 3208 3209Use-list Order Directives 3210------------------------- 3211 3212Use-list directives encode the in-memory order of each use-list, allowing the 3213order to be recreated. ``<order-indexes>`` is a comma-separated list of 3214indexes that are assigned to the referenced value's uses. The referenced 3215value's use-list is immediately sorted by these indexes. 3216 3217Use-list directives may appear at function scope or global scope. They are not 3218instructions, and have no effect on the semantics of the IR. When they're at 3219function scope, they must appear after the terminator of the final basic block. 3220 3221If basic blocks have their address taken via ``blockaddress()`` expressions, 3222``uselistorder_bb`` can be used to reorder their use-lists from outside their 3223function's scope. 3224 3225:Syntax: 3226 3227:: 3228 3229 uselistorder <ty> <value>, { <order-indexes> } 3230 uselistorder_bb @function, %block { <order-indexes> } 3231 3232:Examples: 3233 3234:: 3235 3236 define void @foo(i32 %arg1, i32 %arg2) { 3237 entry: 3238 ; ... instructions ... 3239 bb: 3240 ; ... instructions ... 3241 3242 ; At function scope. 3243 uselistorder i32 %arg1, { 1, 0, 2 } 3244 uselistorder label %bb, { 1, 0 } 3245 } 3246 3247 ; At global scope. 3248 uselistorder i32* @global, { 1, 2, 0 } 3249 uselistorder i32 7, { 1, 0 } 3250 uselistorder i32 (i32) @bar, { 1, 0 } 3251 uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 } 3252 3253.. _source_filename: 3254 3255Source Filename 3256--------------- 3257 3258The *source filename* string is set to the original module identifier, 3259which will be the name of the compiled source file when compiling from 3260source through the clang front end, for example. It is then preserved through 3261the IR and bitcode. 3262 3263This is currently necessary to generate a consistent unique global 3264identifier for local functions used in profile data, which prepends the 3265source file name to the local function name. 3266 3267The syntax for the source file name is simply: 3268 3269.. code-block:: text 3270 3271 source_filename = "/path/to/source.c" 3272 3273.. _typesystem: 3274 3275Type System 3276=========== 3277 3278The LLVM type system is one of the most important features of the 3279intermediate representation. Being typed enables a number of 3280optimizations to be performed on the intermediate representation 3281directly, without having to do extra analyses on the side before the 3282transformation. A strong type system makes it easier to read the 3283generated code and enables novel analyses and transformations that are 3284not feasible to perform on normal three address code representations. 3285 3286.. _t_void: 3287 3288Void Type 3289--------- 3290 3291:Overview: 3292 3293 3294The void type does not represent any value and has no size. 3295 3296:Syntax: 3297 3298 3299:: 3300 3301 void 3302 3303 3304.. _t_function: 3305 3306Function Type 3307------------- 3308 3309:Overview: 3310 3311 3312The function type can be thought of as a function signature. It consists of a 3313return type and a list of formal parameter types. The return type of a function 3314type is a void type or first class type --- except for :ref:`label <t_label>` 3315and :ref:`metadata <t_metadata>` types. 3316 3317:Syntax: 3318 3319:: 3320 3321 <returntype> (<parameter list>) 3322 3323...where '``<parameter list>``' is a comma-separated list of type 3324specifiers. Optionally, the parameter list may include a type ``...``, which 3325indicates that the function takes a variable number of arguments. Variable 3326argument functions can access their arguments with the :ref:`variable argument 3327handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type 3328except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`. 3329 3330:Examples: 3331 3332+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3333| ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` | 3334+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3335| ``float (i16, i32 *) *`` | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``. | 3336+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3337| ``i32 (i8*, ...)`` | A vararg function that takes at least one :ref:`pointer <t_pointer>` to ``i8`` (char in C), which returns an integer. This is the signature for ``printf`` in LLVM. | 3338+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3339| ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values | 3340+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3341 3342.. _t_firstclass: 3343 3344First Class Types 3345----------------- 3346 3347The :ref:`first class <t_firstclass>` types are perhaps the most important. 3348Values of these types are the only ones which can be produced by 3349instructions. 3350 3351.. _t_single_value: 3352 3353Single Value Types 3354^^^^^^^^^^^^^^^^^^ 3355 3356These are the types that are valid in registers from CodeGen's perspective. 3357 3358.. _t_integer: 3359 3360Integer Type 3361"""""""""""" 3362 3363:Overview: 3364 3365The integer type is a very simple type that simply specifies an 3366arbitrary bit width for the integer type desired. Any bit width from 1 3367bit to 2\ :sup:`23`\ (about 8 million) can be specified. 3368 3369:Syntax: 3370 3371:: 3372 3373 iN 3374 3375The number of bits the integer will occupy is specified by the ``N`` 3376value. 3377 3378Examples: 3379********* 3380 3381+----------------+------------------------------------------------+ 3382| ``i1`` | a single-bit integer. | 3383+----------------+------------------------------------------------+ 3384| ``i32`` | a 32-bit integer. | 3385+----------------+------------------------------------------------+ 3386| ``i1942652`` | a really big integer of over 1 million bits. | 3387+----------------+------------------------------------------------+ 3388 3389.. _t_floating: 3390 3391Floating-Point Types 3392"""""""""""""""""""" 3393 3394.. list-table:: 3395 :header-rows: 1 3396 3397 * - Type 3398 - Description 3399 3400 * - ``half`` 3401 - 16-bit floating-point value 3402 3403 * - ``bfloat`` 3404 - 16-bit "brain" floating-point value (7-bit significand). Provides the 3405 same number of exponent bits as ``float``, so that it matches its dynamic 3406 range, but with greatly reduced precision. Used in Intel's AVX-512 BF16 3407 extensions and Arm's ARMv8.6-A extensions, among others. 3408 3409 * - ``float`` 3410 - 32-bit floating-point value 3411 3412 * - ``double`` 3413 - 64-bit floating-point value 3414 3415 * - ``fp128`` 3416 - 128-bit floating-point value (113-bit significand) 3417 3418 * - ``x86_fp80`` 3419 - 80-bit floating-point value (X87) 3420 3421 * - ``ppc_fp128`` 3422 - 128-bit floating-point value (two 64-bits) 3423 3424The binary format of half, float, double, and fp128 correspond to the 3425IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128 3426respectively. 3427 3428X86_amx Type 3429"""""""""""" 3430 3431:Overview: 3432 3433The x86_amx type represents a value held in an AMX tile register on an x86 3434machine. The operations allowed on it are quite limited. Only few intrinsics 3435are allowed: stride load and store, zero and dot product. No instruction is 3436allowed for this type. There are no arguments, arrays, pointers, vectors 3437or constants of this type. 3438 3439:Syntax: 3440 3441:: 3442 3443 x86_amx 3444 3445 3446X86_mmx Type 3447"""""""""""" 3448 3449:Overview: 3450 3451The x86_mmx type represents a value held in an MMX register on an x86 3452machine. The operations allowed on it are quite limited: parameters and 3453return values, load and store, and bitcast. User-specified MMX 3454instructions are represented as intrinsic or asm calls with arguments 3455and/or results of this type. There are no arrays, vectors or constants 3456of this type. 3457 3458:Syntax: 3459 3460:: 3461 3462 x86_mmx 3463 3464 3465.. _t_pointer: 3466 3467Pointer Type 3468"""""""""""" 3469 3470:Overview: 3471 3472The pointer type is used to specify memory locations. Pointers are 3473commonly used to reference objects in memory. 3474 3475Pointer types may have an optional address space attribute defining the 3476numbered address space where the pointed-to object resides. The default 3477address space is number zero. The semantics of non-zero address spaces 3478are target-specific. 3479 3480Note that LLVM does not permit pointers to void (``void*``) nor does it 3481permit pointers to labels (``label*``). Use ``i8*`` instead. 3482 3483LLVM is in the process of transitioning to 3484`opaque pointers <OpaquePointers.html#opaque-pointers>`_. 3485Opaque pointers do not have a pointee type. Rather, instructions 3486interacting through pointers specify the type of the underlying memory 3487they are interacting with. Opaque pointers are still in the process of 3488being worked on and are not complete. 3489 3490:Syntax: 3491 3492:: 3493 3494 <type> * 3495 ptr 3496 3497:Examples: 3498 3499+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3500| ``[4 x i32]*`` | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values. | 3501+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3502| ``i32 (i32*) *`` | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. | 3503+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3504| ``i32 addrspace(5)*`` | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space 5. | 3505+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3506| ``ptr`` | An opaque pointer type to a value that resides in address space 0. | 3507+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3508| ``ptr addrspace(5)`` | An opaque pointer type to a value that resides in address space 5. | 3509+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3510 3511.. _t_vector: 3512 3513Vector Type 3514""""""""""" 3515 3516:Overview: 3517 3518A vector type is a simple derived type that represents a vector of 3519elements. Vector types are used when multiple primitive data are 3520operated in parallel using a single instruction (SIMD). A vector type 3521requires a size (number of elements), an underlying primitive data type, 3522and a scalable property to represent vectors where the exact hardware 3523vector length is unknown at compile time. Vector types are considered 3524:ref:`first class <t_firstclass>`. 3525 3526:Memory Layout: 3527 3528In general vector elements are laid out in memory in the same way as 3529:ref:`array types <t_array>`. Such an analogy works fine as long as the vector 3530elements are byte sized. However, when the elements of the vector aren't byte 3531sized it gets a bit more complicated. One way to describe the layout is by 3532describing what happens when a vector such as <N x iM> is bitcasted to an 3533integer type with N*M bits, and then following the rules for storing such an 3534integer to memory. 3535 3536A bitcast from a vector type to a scalar integer type will see the elements 3537being packed together (without padding). The order in which elements are 3538inserted in the integer depends on endianess. For little endian element zero 3539is put in the least significant bits of the integer, and for big endian 3540element zero is put in the most significant bits. 3541 3542Using a vector such as ``<i4 1, i4 2, i4 3, i4 5>`` as an example, together 3543with the analogy that we can replace a vector store by a bitcast followed by 3544an integer store, we get this for big endian: 3545 3546.. code-block:: llvm 3547 3548 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16 3549 3550 ; Bitcasting from a vector to an integral type can be seen as 3551 ; concatenating the values: 3552 ; %val now has the hexadecimal value 0x1235. 3553 3554 store i16 %val, i16* %ptr 3555 3556 ; In memory the content will be (8-bit addressing): 3557 ; 3558 ; [%ptr + 0]: 00010010 (0x12) 3559 ; [%ptr + 1]: 00110101 (0x35) 3560 3561The same example for little endian: 3562 3563.. code-block:: llvm 3564 3565 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16 3566 3567 ; Bitcasting from a vector to an integral type can be seen as 3568 ; concatenating the values: 3569 ; %val now has the hexadecimal value 0x5321. 3570 3571 store i16 %val, i16* %ptr 3572 3573 ; In memory the content will be (8-bit addressing): 3574 ; 3575 ; [%ptr + 0]: 01010011 (0x53) 3576 ; [%ptr + 1]: 00100001 (0x21) 3577 3578When ``<N*M>`` isn't evenly divisible by the byte size the exact memory layout 3579is unspecified (just like it is for an integral type of the same size). This 3580is because different targets could put the padding at different positions when 3581the type size is smaller than the type's store size. 3582 3583:Syntax: 3584 3585:: 3586 3587 < <# elements> x <elementtype> > ; Fixed-length vector 3588 < vscale x <# elements> x <elementtype> > ; Scalable vector 3589 3590The number of elements is a constant integer value larger than 0; 3591elementtype may be any integer, floating-point or pointer type. Vectors 3592of size zero are not allowed. For scalable vectors, the total number of 3593elements is a constant multiple (called vscale) of the specified number 3594of elements; vscale is a positive integer that is unknown at compile time 3595and the same hardware-dependent constant for all scalable vectors at run 3596time. The size of a specific scalable vector type is thus constant within 3597IR, even if the exact size in bytes cannot be determined until run time. 3598 3599:Examples: 3600 3601+------------------------+----------------------------------------------------+ 3602| ``<4 x i32>`` | Vector of 4 32-bit integer values. | 3603+------------------------+----------------------------------------------------+ 3604| ``<8 x float>`` | Vector of 8 32-bit floating-point values. | 3605+------------------------+----------------------------------------------------+ 3606| ``<2 x i64>`` | Vector of 2 64-bit integer values. | 3607+------------------------+----------------------------------------------------+ 3608| ``<4 x i64*>`` | Vector of 4 pointers to 64-bit integer values. | 3609+------------------------+----------------------------------------------------+ 3610| ``<vscale x 4 x i32>`` | Vector with a multiple of 4 32-bit integer values. | 3611+------------------------+----------------------------------------------------+ 3612 3613.. _t_label: 3614 3615Label Type 3616^^^^^^^^^^ 3617 3618:Overview: 3619 3620The label type represents code labels. 3621 3622:Syntax: 3623 3624:: 3625 3626 label 3627 3628.. _t_token: 3629 3630Token Type 3631^^^^^^^^^^ 3632 3633:Overview: 3634 3635The token type is used when a value is associated with an instruction 3636but all uses of the value must not attempt to introspect or obscure it. 3637As such, it is not appropriate to have a :ref:`phi <i_phi>` or 3638:ref:`select <i_select>` of type token. 3639 3640:Syntax: 3641 3642:: 3643 3644 token 3645 3646 3647 3648.. _t_metadata: 3649 3650Metadata Type 3651^^^^^^^^^^^^^ 3652 3653:Overview: 3654 3655The metadata type represents embedded metadata. No derived types may be 3656created from metadata except for :ref:`function <t_function>` arguments. 3657 3658:Syntax: 3659 3660:: 3661 3662 metadata 3663 3664.. _t_aggregate: 3665 3666Aggregate Types 3667^^^^^^^^^^^^^^^ 3668 3669Aggregate Types are a subset of derived types that can contain multiple 3670member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are 3671aggregate types. :ref:`Vectors <t_vector>` are not considered to be 3672aggregate types. 3673 3674.. _t_array: 3675 3676Array Type 3677"""""""""" 3678 3679:Overview: 3680 3681The array type is a very simple derived type that arranges elements 3682sequentially in memory. The array type requires a size (number of 3683elements) and an underlying data type. 3684 3685:Syntax: 3686 3687:: 3688 3689 [<# elements> x <elementtype>] 3690 3691The number of elements is a constant integer value; ``elementtype`` may 3692be any type with a size. 3693 3694:Examples: 3695 3696+------------------+--------------------------------------+ 3697| ``[40 x i32]`` | Array of 40 32-bit integer values. | 3698+------------------+--------------------------------------+ 3699| ``[41 x i32]`` | Array of 41 32-bit integer values. | 3700+------------------+--------------------------------------+ 3701| ``[4 x i8]`` | Array of 4 8-bit integer values. | 3702+------------------+--------------------------------------+ 3703 3704Here are some examples of multidimensional arrays: 3705 3706+-----------------------------+----------------------------------------------------------+ 3707| ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. | 3708+-----------------------------+----------------------------------------------------------+ 3709| ``[12 x [10 x float]]`` | 12x10 array of single precision floating-point values. | 3710+-----------------------------+----------------------------------------------------------+ 3711| ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. | 3712+-----------------------------+----------------------------------------------------------+ 3713 3714There is no restriction on indexing beyond the end of the array implied 3715by a static type (though there are restrictions on indexing beyond the 3716bounds of an allocated object in some cases). This means that 3717single-dimension 'variable sized array' addressing can be implemented in 3718LLVM with a zero length array type. An implementation of 'pascal style 3719arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for 3720example. 3721 3722.. _t_struct: 3723 3724Structure Type 3725"""""""""""""" 3726 3727:Overview: 3728 3729The structure type is used to represent a collection of data members 3730together in memory. The elements of a structure may be any type that has 3731a size. 3732 3733Structures in memory are accessed using '``load``' and '``store``' by 3734getting a pointer to a field with the '``getelementptr``' instruction. 3735Structures in registers are accessed using the '``extractvalue``' and 3736'``insertvalue``' instructions. 3737 3738Structures may optionally be "packed" structures, which indicate that 3739the alignment of the struct is one byte, and that there is no padding 3740between the elements. In non-packed structs, padding between field types 3741is inserted as defined by the DataLayout string in the module, which is 3742required to match what the underlying code generator expects. 3743 3744Structures can either be "literal" or "identified". A literal structure 3745is defined inline with other types (e.g. ``{i32, i32}*``) whereas 3746identified types are always defined at the top level with a name. 3747Literal types are uniqued by their contents and can never be recursive 3748or opaque since there is no way to write one. Identified types can be 3749recursive, can be opaqued, and are never uniqued. 3750 3751:Syntax: 3752 3753:: 3754 3755 %T1 = type { <type list> } ; Identified normal struct type 3756 %T2 = type <{ <type list> }> ; Identified packed struct type 3757 3758:Examples: 3759 3760+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3761| ``{ i32, i32, i32 }`` | A triple of three ``i32`` values | 3762+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3763| ``{ float, i32 (i32) * }`` | A pair, where the first element is a ``float`` and the second element is a :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32``, returning an ``i32``. | 3764+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3765| ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. | 3766+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3767 3768.. _t_opaque: 3769 3770Opaque Structure Types 3771"""""""""""""""""""""" 3772 3773:Overview: 3774 3775Opaque structure types are used to represent structure types that 3776do not have a body specified. This corresponds (for example) to the C 3777notion of a forward declared structure. They can be named (``%X``) or 3778unnamed (``%52``). 3779 3780:Syntax: 3781 3782:: 3783 3784 %X = type opaque 3785 %52 = type opaque 3786 3787:Examples: 3788 3789+--------------+-------------------+ 3790| ``opaque`` | An opaque type. | 3791+--------------+-------------------+ 3792 3793.. _constants: 3794 3795Constants 3796========= 3797 3798LLVM has several different basic types of constants. This section 3799describes them all and their syntax. 3800 3801Simple Constants 3802---------------- 3803 3804**Boolean constants** 3805 The two strings '``true``' and '``false``' are both valid constants 3806 of the ``i1`` type. 3807**Integer constants** 3808 Standard integers (such as '4') are constants of the 3809 :ref:`integer <t_integer>` type. Negative numbers may be used with 3810 integer types. 3811**Floating-point constants** 3812 Floating-point constants use standard decimal notation (e.g. 3813 123.421), exponential notation (e.g. 1.23421e+2), or a more precise 3814 hexadecimal notation (see below). The assembler requires the exact 3815 decimal value of a floating-point constant. For example, the 3816 assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating 3817 decimal in binary. Floating-point constants must have a 3818 :ref:`floating-point <t_floating>` type. 3819**Null pointer constants** 3820 The identifier '``null``' is recognized as a null pointer constant 3821 and must be of :ref:`pointer type <t_pointer>`. 3822**Token constants** 3823 The identifier '``none``' is recognized as an empty token constant 3824 and must be of :ref:`token type <t_token>`. 3825 3826The one non-intuitive notation for constants is the hexadecimal form of 3827floating-point constants. For example, the form 3828'``double 0x432ff973cafa8000``' is equivalent to (but harder to read 3829than) '``double 4.5e+15``'. The only time hexadecimal floating-point 3830constants are required (and the only time that they are generated by the 3831disassembler) is when a floating-point constant must be emitted but it 3832cannot be represented as a decimal floating-point number in a reasonable 3833number of digits. For example, NaN's, infinities, and other special 3834values are represented in their IEEE hexadecimal format so that assembly 3835and disassembly do not cause any bits to change in the constants. 3836 3837When using the hexadecimal form, constants of types bfloat, half, float, and 3838double are represented using the 16-digit form shown above (which matches the 3839IEEE754 representation for double); bfloat, half and float values must, however, 3840be exactly representable as bfloat, IEEE 754 half, and IEEE 754 single 3841precision respectively. Hexadecimal format is always used for long double, and 3842there are three forms of long double. The 80-bit format used by x86 is 3843represented as ``0xK`` followed by 20 hexadecimal digits. The 128-bit format 3844used by PowerPC (two adjacent doubles) is represented by ``0xM`` followed by 32 3845hexadecimal digits. The IEEE 128-bit format is represented by ``0xL`` followed 3846by 32 hexadecimal digits. Long doubles will only work if they match the long 3847double format on your target. The IEEE 16-bit format (half precision) is 3848represented by ``0xH`` followed by 4 hexadecimal digits. The bfloat 16-bit 3849format is represented by ``0xR`` followed by 4 hexadecimal digits. All 3850hexadecimal formats are big-endian (sign bit at the left). 3851 3852There are no constants of type x86_mmx and x86_amx. 3853 3854.. _complexconstants: 3855 3856Complex Constants 3857----------------- 3858 3859Complex constants are a (potentially recursive) combination of simple 3860constants and smaller complex constants. 3861 3862**Structure constants** 3863 Structure constants are represented with notation similar to 3864 structure type definitions (a comma separated list of elements, 3865 surrounded by braces (``{}``)). For example: 3866 "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as 3867 "``@G = external global i32``". Structure constants must have 3868 :ref:`structure type <t_struct>`, and the number and types of elements 3869 must match those specified by the type. 3870**Array constants** 3871 Array constants are represented with notation similar to array type 3872 definitions (a comma separated list of elements, surrounded by 3873 square brackets (``[]``)). For example: 3874 "``[ i32 42, i32 11, i32 74 ]``". Array constants must have 3875 :ref:`array type <t_array>`, and the number and types of elements must 3876 match those specified by the type. As a special case, character array 3877 constants may also be represented as a double-quoted string using the ``c`` 3878 prefix. For example: "``c"Hello World\0A\00"``". 3879**Vector constants** 3880 Vector constants are represented with notation similar to vector 3881 type definitions (a comma separated list of elements, surrounded by 3882 less-than/greater-than's (``<>``)). For example: 3883 "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants 3884 must have :ref:`vector type <t_vector>`, and the number and types of 3885 elements must match those specified by the type. 3886**Zero initialization** 3887 The string '``zeroinitializer``' can be used to zero initialize a 3888 value to zero of *any* type, including scalar and 3889 :ref:`aggregate <t_aggregate>` types. This is often used to avoid 3890 having to print large zero initializers (e.g. for large arrays) and 3891 is always exactly equivalent to using explicit zero initializers. 3892**Metadata node** 3893 A metadata node is a constant tuple without types. For example: 3894 "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values, 3895 for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``". 3896 Unlike other typed constants that are meant to be interpreted as part of 3897 the instruction stream, metadata is a place to attach additional 3898 information such as debug info. 3899 3900Global Variable and Function Addresses 3901-------------------------------------- 3902 3903The addresses of :ref:`global variables <globalvars>` and 3904:ref:`functions <functionstructure>` are always implicitly valid 3905(link-time) constants. These constants are explicitly referenced when 3906the :ref:`identifier for the global <identifiers>` is used and always have 3907:ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM 3908file: 3909 3910.. code-block:: llvm 3911 3912 @X = global i32 17 3913 @Y = global i32 42 3914 @Z = global [2 x i32*] [ i32* @X, i32* @Y ] 3915 3916.. _undefvalues: 3917 3918Undefined Values 3919---------------- 3920 3921The string '``undef``' can be used anywhere a constant is expected, and 3922indicates that the user of the value may receive an unspecified 3923bit-pattern. Undefined values may be of any type (other than '``label``' 3924or '``void``') and be used anywhere a constant is permitted. 3925 3926.. note:: 3927 3928 A '``poison``' value (decribed in the next section) should be used instead of 3929 '``undef``' whenever possible. Poison values are stronger than undef, and 3930 enable more optimizations. Just the existence of '``undef``' blocks certain 3931 optimizations (see the examples below). 3932 3933Undefined values are useful because they indicate to the compiler that 3934the program is well defined no matter what value is used. This gives the 3935compiler more freedom to optimize. Here are some examples of 3936(potentially surprising) transformations that are valid (in pseudo IR): 3937 3938.. code-block:: llvm 3939 3940 %A = add %X, undef 3941 %B = sub %X, undef 3942 %C = xor %X, undef 3943 Safe: 3944 %A = undef 3945 %B = undef 3946 %C = undef 3947 3948This is safe because all of the output bits are affected by the undef 3949bits. Any output bit can have a zero or one depending on the input bits. 3950 3951.. code-block:: llvm 3952 3953 %A = or %X, undef 3954 %B = and %X, undef 3955 Safe: 3956 %A = -1 3957 %B = 0 3958 Safe: 3959 %A = %X ;; By choosing undef as 0 3960 %B = %X ;; By choosing undef as -1 3961 Unsafe: 3962 %A = undef 3963 %B = undef 3964 3965These logical operations have bits that are not always affected by the 3966input. For example, if ``%X`` has a zero bit, then the output of the 3967'``and``' operation will always be a zero for that bit, no matter what 3968the corresponding bit from the '``undef``' is. As such, it is unsafe to 3969optimize or assume that the result of the '``and``' is '``undef``'. 3970However, it is safe to assume that all bits of the '``undef``' could be 39710, and optimize the '``and``' to 0. Likewise, it is safe to assume that 3972all the bits of the '``undef``' operand to the '``or``' could be set, 3973allowing the '``or``' to be folded to -1. 3974 3975.. code-block:: llvm 3976 3977 %A = select undef, %X, %Y 3978 %B = select undef, 42, %Y 3979 %C = select %X, %Y, undef 3980 Safe: 3981 %A = %X (or %Y) 3982 %B = 42 (or %Y) 3983 %C = %Y (if %Y is provably not poison; unsafe otherwise) 3984 Unsafe: 3985 %A = undef 3986 %B = undef 3987 %C = undef 3988 3989This set of examples shows that undefined '``select``' (and conditional 3990branch) conditions can go *either way*, but they have to come from one 3991of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were 3992both known to have a clear low bit, then ``%A`` would have to have a 3993cleared low bit. However, in the ``%C`` example, the optimizer is 3994allowed to assume that the '``undef``' operand could be the same as 3995``%Y`` if ``%Y`` is provably not '``poison``', allowing the whole '``select``' 3996to be eliminated. This is because '``poison``' is stronger than '``undef``'. 3997 3998.. code-block:: llvm 3999 4000 %A = xor undef, undef 4001 4002 %B = undef 4003 %C = xor %B, %B 4004 4005 %D = undef 4006 %E = icmp slt %D, 4 4007 %F = icmp gte %D, 4 4008 4009 Safe: 4010 %A = undef 4011 %B = undef 4012 %C = undef 4013 %D = undef 4014 %E = undef 4015 %F = undef 4016 4017This example points out that two '``undef``' operands are not 4018necessarily the same. This can be surprising to people (and also matches 4019C semantics) where they assume that "``X^X``" is always zero, even if 4020``X`` is undefined. This isn't true for a number of reasons, but the 4021short answer is that an '``undef``' "variable" can arbitrarily change 4022its value over its "live range". This is true because the variable 4023doesn't actually *have a live range*. Instead, the value is logically 4024read from arbitrary registers that happen to be around when needed, so 4025the value is not necessarily consistent over time. In fact, ``%A`` and 4026``%C`` need to have the same semantics or the core LLVM "replace all 4027uses with" concept would not hold. 4028 4029To ensure all uses of a given register observe the same value (even if 4030'``undef``'), the :ref:`freeze instruction <i_freeze>` can be used. 4031 4032.. code-block:: llvm 4033 4034 %A = sdiv undef, %X 4035 %B = sdiv %X, undef 4036 Safe: 4037 %A = 0 4038 b: unreachable 4039 4040These examples show the crucial difference between an *undefined value* 4041and *undefined behavior*. An undefined value (like '``undef``') is 4042allowed to have an arbitrary bit-pattern. This means that the ``%A`` 4043operation can be constant folded to '``0``', because the '``undef``' 4044could be zero, and zero divided by any value is zero. 4045However, in the second example, we can make a more aggressive 4046assumption: because the ``undef`` is allowed to be an arbitrary value, 4047we are allowed to assume that it could be zero. Since a divide by zero 4048has *undefined behavior*, we are allowed to assume that the operation 4049does not execute at all. This allows us to delete the divide and all 4050code after it. Because the undefined operation "can't happen", the 4051optimizer can assume that it occurs in dead code. 4052 4053.. code-block:: text 4054 4055 a: store undef -> %X 4056 b: store %X -> undef 4057 Safe: 4058 a: <deleted> (if the stored value in %X is provably not poison) 4059 b: unreachable 4060 4061A store *of* an undefined value can be assumed to not have any effect; 4062we can assume that the value is overwritten with bits that happen to 4063match what was already there. This argument is only valid if the stored value 4064is provably not ``poison``. However, a store *to* an undefined 4065location could clobber arbitrary memory, therefore, it has undefined 4066behavior. 4067 4068Branching on an undefined value is undefined behavior. 4069This explains optimizations that depend on branch conditions to construct 4070predicates, such as Correlated Value Propagation and Global Value Numbering. 4071In case of switch instruction, the branch condition should be frozen, otherwise 4072it is undefined behavior. 4073 4074.. code-block:: llvm 4075 4076 Unsafe: 4077 br undef, BB1, BB2 ; UB 4078 4079 %X = and i32 undef, 255 4080 switch %X, label %ret [ .. ] ; UB 4081 4082 store undef, i8* %ptr 4083 %X = load i8* %ptr ; %X is undef 4084 switch i8 %X, label %ret [ .. ] ; UB 4085 4086 Safe: 4087 %X = or i8 undef, 255 ; always 255 4088 switch i8 %X, label %ret [ .. ] ; Well-defined 4089 4090 %X = freeze i1 undef 4091 br %X, BB1, BB2 ; Well-defined (non-deterministic jump) 4092 4093 4094 4095.. _poisonvalues: 4096 4097Poison Values 4098------------- 4099 4100A poison value is a result of an erroneous operation. 4101In order to facilitate speculative execution, many instructions do not 4102invoke immediate undefined behavior when provided with illegal operands, 4103and return a poison value instead. 4104The string '``poison``' can be used anywhere a constant is expected, and 4105operations such as :ref:`add <i_add>` with the ``nsw`` flag can produce 4106a poison value. 4107 4108Most instructions return '``poison``' when one of their arguments is 4109'``poison``'. A notable exception is the :ref:`select instruction <i_select>`. 4110Propagation of poison can be stopped with the 4111:ref:`freeze instruction <i_freeze>`. 4112 4113It is correct to replace a poison value with an 4114:ref:`undef value <undefvalues>` or any value of the type. 4115 4116This means that immediate undefined behavior occurs if a poison value is 4117used as an instruction operand that has any values that trigger undefined 4118behavior. Notably this includes (but is not limited to): 4119 4120- The pointer operand of a :ref:`load <i_load>`, :ref:`store <i_store>` or 4121 any other pointer dereferencing instruction (independent of address 4122 space). 4123- The divisor operand of a ``udiv``, ``sdiv``, ``urem`` or ``srem`` 4124 instruction. 4125- The condition operand of a :ref:`br <i_br>` instruction. 4126- The callee operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 4127 instruction. 4128- The parameter operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 4129 instruction, when the function or invoking call site has a ``noundef`` 4130 attribute in the corresponding position. 4131- The operand of a :ref:`ret <i_ret>` instruction if the function or invoking 4132 call site has a `noundef` attribute in the return value position. 4133 4134Here are some examples: 4135 4136.. code-block:: llvm 4137 4138 entry: 4139 %poison = sub nuw i32 0, 1 ; Results in a poison value. 4140 %poison2 = sub i32 poison, 1 ; Also results in a poison value. 4141 %still_poison = and i32 %poison, 0 ; 0, but also poison. 4142 %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison 4143 store i32 0, i32* %poison_yet_again ; Undefined behavior due to 4144 ; store to poison. 4145 4146 store i32 %poison, i32* @g ; Poison value stored to memory. 4147 %poison3 = load i32, i32* @g ; Poison value loaded back from memory. 4148 4149 %narrowaddr = bitcast i32* @g to i16* 4150 %wideaddr = bitcast i32* @g to i64* 4151 %poison4 = load i16, i16* %narrowaddr ; Returns a poison value. 4152 %poison5 = load i64, i64* %wideaddr ; Returns a poison value. 4153 4154 %cmp = icmp slt i32 %poison, 0 ; Returns a poison value. 4155 br i1 %cmp, label %end, label %end ; undefined behavior 4156 4157 end: 4158 4159.. _welldefinedvalues: 4160 4161Well-Defined Values 4162------------------- 4163 4164Given a program execution, a value is *well defined* if the value does not 4165have an undef bit and is not poison in the execution. 4166An aggregate value or vector is well defined if its elements are well defined. 4167The padding of an aggregate isn't considered, since it isn't visible 4168without storing it into memory and loading it with a different type. 4169 4170A constant of a :ref:`single value <t_single_value>`, non-vector type is well 4171defined if it is neither '``undef``' constant nor '``poison``' constant. 4172The result of :ref:`freeze instruction <i_freeze>` is well defined regardless 4173of its operand. 4174 4175.. _blockaddress: 4176 4177Addresses of Basic Blocks 4178------------------------- 4179 4180``blockaddress(@function, %block)`` 4181 4182The '``blockaddress``' constant computes the address of the specified 4183basic block in the specified function. 4184 4185It always has an ``i8 addrspace(P)*`` type, where ``P`` is the address space 4186of the function containing ``%block`` (usually ``addrspace(0)``). 4187 4188Taking the address of the entry block is illegal. 4189 4190This value only has defined behavior when used as an operand to the 4191':ref:`indirectbr <i_indirectbr>`' or ':ref:`callbr <i_callbr>`'instruction, or 4192for comparisons against null. Pointer equality tests between labels addresses 4193results in undefined behavior --- though, again, comparison against null is ok, 4194and no label is equal to the null pointer. This may be passed around as an 4195opaque pointer sized value as long as the bits are not inspected. This 4196allows ``ptrtoint`` and arithmetic to be performed on these values so 4197long as the original value is reconstituted before the ``indirectbr`` or 4198``callbr`` instruction. 4199 4200Finally, some targets may provide defined semantics when using the value 4201as the operand to an inline assembly, but that is target specific. 4202 4203.. _dso_local_equivalent: 4204 4205DSO Local Equivalent 4206-------------------- 4207 4208``dso_local_equivalent @func`` 4209 4210A '``dso_local_equivalent``' constant represents a function which is 4211functionally equivalent to a given function, but is always defined in the 4212current linkage unit. The resulting pointer has the same type as the underlying 4213function. The resulting pointer is permitted, but not required, to be different 4214from a pointer to the function, and it may have different values in different 4215translation units. 4216 4217The target function may not have ``extern_weak`` linkage. 4218 4219``dso_local_equivalent`` can be implemented as such: 4220 4221- If the function has local linkage, hidden visibility, or is 4222 ``dso_local``, ``dso_local_equivalent`` can be implemented as simply a pointer 4223 to the function. 4224- ``dso_local_equivalent`` can be implemented with a stub that tail-calls the 4225 function. Many targets support relocations that resolve at link time to either 4226 a function or a stub for it, depending on if the function is defined within the 4227 linkage unit; LLVM will use this when available. (This is commonly called a 4228 "PLT stub".) On other targets, the stub may need to be emitted explicitly. 4229 4230This can be used wherever a ``dso_local`` instance of a function is needed without 4231needing to explicitly make the original function ``dso_local``. An instance where 4232this can be used is for static offset calculations between a function and some other 4233``dso_local`` symbol. This is especially useful for the Relative VTables C++ ABI, 4234where dynamic relocations for function pointers in VTables can be replaced with 4235static relocations for offsets between the VTable and virtual functions which 4236may not be ``dso_local``. 4237 4238This is currently only supported for ELF binary formats. 4239 4240.. _no_cfi: 4241 4242No CFI 4243------ 4244 4245``no_cfi @func`` 4246 4247With `Control-Flow Integrity (CFI) 4248<https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, a '``no_cfi``' 4249constant represents a function reference that does not get replaced with a 4250reference to the CFI jump table in the ``LowerTypeTests`` pass. These constants 4251may be useful in low-level programs, such as operating system kernels, which 4252need to refer to the actual function body. 4253 4254.. _constantexprs: 4255 4256Constant Expressions 4257-------------------- 4258 4259Constant expressions are used to allow expressions involving other 4260constants to be used as constants. Constant expressions may be of any 4261:ref:`first class <t_firstclass>` type and may involve any LLVM operation 4262that does not have side effects (e.g. load and call are not supported). 4263The following is the syntax for constant expressions: 4264 4265``trunc (CST to TYPE)`` 4266 Perform the :ref:`trunc operation <i_trunc>` on constants. 4267``zext (CST to TYPE)`` 4268 Perform the :ref:`zext operation <i_zext>` on constants. 4269``sext (CST to TYPE)`` 4270 Perform the :ref:`sext operation <i_sext>` on constants. 4271``fptrunc (CST to TYPE)`` 4272 Truncate a floating-point constant to another floating-point type. 4273 The size of CST must be larger than the size of TYPE. Both types 4274 must be floating-point. 4275``fpext (CST to TYPE)`` 4276 Floating-point extend a constant to another type. The size of CST 4277 must be smaller or equal to the size of TYPE. Both types must be 4278 floating-point. 4279``fptoui (CST to TYPE)`` 4280 Convert a floating-point constant to the corresponding unsigned 4281 integer constant. TYPE must be a scalar or vector integer type. CST 4282 must be of scalar or vector floating-point type. Both CST and TYPE 4283 must be scalars, or vectors of the same number of elements. If the 4284 value won't fit in the integer type, the result is a 4285 :ref:`poison value <poisonvalues>`. 4286``fptosi (CST to TYPE)`` 4287 Convert a floating-point constant to the corresponding signed 4288 integer constant. TYPE must be a scalar or vector integer type. CST 4289 must be of scalar or vector floating-point type. Both CST and TYPE 4290 must be scalars, or vectors of the same number of elements. If the 4291 value won't fit in the integer type, the result is a 4292 :ref:`poison value <poisonvalues>`. 4293``uitofp (CST to TYPE)`` 4294 Convert an unsigned integer constant to the corresponding 4295 floating-point constant. TYPE must be a scalar or vector floating-point 4296 type. CST must be of scalar or vector integer type. Both CST and TYPE must 4297 be scalars, or vectors of the same number of elements. 4298``sitofp (CST to TYPE)`` 4299 Convert a signed integer constant to the corresponding floating-point 4300 constant. TYPE must be a scalar or vector floating-point type. 4301 CST must be of scalar or vector integer type. Both CST and TYPE must 4302 be scalars, or vectors of the same number of elements. 4303``ptrtoint (CST to TYPE)`` 4304 Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants. 4305``inttoptr (CST to TYPE)`` 4306 Perform the :ref:`inttoptr operation <i_inttoptr>` on constants. 4307 This one is *really* dangerous! 4308``bitcast (CST to TYPE)`` 4309 Convert a constant, CST, to another TYPE. 4310 The constraints of the operands are the same as those for the 4311 :ref:`bitcast instruction <i_bitcast>`. 4312``addrspacecast (CST to TYPE)`` 4313 Convert a constant pointer or constant vector of pointer, CST, to another 4314 TYPE in a different address space. The constraints of the operands are the 4315 same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`. 4316``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)`` 4317 Perform the :ref:`getelementptr operation <i_getelementptr>` on 4318 constants. As with the :ref:`getelementptr <i_getelementptr>` 4319 instruction, the index list may have one or more indexes, which are 4320 required to make sense for the type of "pointer to TY". 4321``select (COND, VAL1, VAL2)`` 4322 Perform the :ref:`select operation <i_select>` on constants. 4323``icmp COND (VAL1, VAL2)`` 4324 Perform the :ref:`icmp operation <i_icmp>` on constants. 4325``fcmp COND (VAL1, VAL2)`` 4326 Perform the :ref:`fcmp operation <i_fcmp>` on constants. 4327``extractelement (VAL, IDX)`` 4328 Perform the :ref:`extractelement operation <i_extractelement>` on 4329 constants. 4330``insertelement (VAL, ELT, IDX)`` 4331 Perform the :ref:`insertelement operation <i_insertelement>` on 4332 constants. 4333``shufflevector (VEC1, VEC2, IDXMASK)`` 4334 Perform the :ref:`shufflevector operation <i_shufflevector>` on 4335 constants. 4336``extractvalue (VAL, IDX0, IDX1, ...)`` 4337 Perform the :ref:`extractvalue operation <i_extractvalue>` on 4338 constants. The index list is interpreted in a similar manner as 4339 indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At 4340 least one index value must be specified. 4341``insertvalue (VAL, ELT, IDX0, IDX1, ...)`` 4342 Perform the :ref:`insertvalue operation <i_insertvalue>` on constants. 4343 The index list is interpreted in a similar manner as indices in a 4344 ':ref:`getelementptr <i_getelementptr>`' operation. At least one index 4345 value must be specified. 4346``OPCODE (LHS, RHS)`` 4347 Perform the specified operation of the LHS and RHS constants. OPCODE 4348 may be any of the :ref:`binary <binaryops>` or :ref:`bitwise 4349 binary <bitwiseops>` operations. The constraints on operands are 4350 the same as those for the corresponding instruction (e.g. no bitwise 4351 operations on floating-point values are allowed). 4352 4353Other Values 4354============ 4355 4356.. _inlineasmexprs: 4357 4358Inline Assembler Expressions 4359---------------------------- 4360 4361LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level 4362Inline Assembly <moduleasm>`) through the use of a special value. This value 4363represents the inline assembler as a template string (containing the 4364instructions to emit), a list of operand constraints (stored as a string), a 4365flag that indicates whether or not the inline asm expression has side effects, 4366and a flag indicating whether the function containing the asm needs to align its 4367stack conservatively. 4368 4369The template string supports argument substitution of the operands using "``$``" 4370followed by a number, to indicate substitution of the given register/memory 4371location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also 4372be used, where ``MODIFIER`` is a target-specific annotation for how to print the 4373operand (See :ref:`inline-asm-modifiers`). 4374 4375A literal "``$``" may be included by using "``$$``" in the template. To include 4376other special characters into the output, the usual "``\XX``" escapes may be 4377used, just as in other strings. Note that after template substitution, the 4378resulting assembly string is parsed by LLVM's integrated assembler unless it is 4379disabled -- even when emitting a ``.s`` file -- and thus must contain assembly 4380syntax known to LLVM. 4381 4382LLVM also supports a few more substitutions useful for writing inline assembly: 4383 4384- ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob. 4385 This substitution is useful when declaring a local label. Many standard 4386 compiler optimizations, such as inlining, may duplicate an inline asm blob. 4387 Adding a blob-unique identifier ensures that the two labels will not conflict 4388 during assembly. This is used to implement `GCC's %= special format 4389 string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_. 4390- ``${:comment}``: Expands to the comment character of the current target's 4391 assembly dialect. This is usually ``#``, but many targets use other strings, 4392 such as ``;``, ``//``, or ``!``. 4393- ``${:private}``: Expands to the assembler private label prefix. Labels with 4394 this prefix will not appear in the symbol table of the assembled object. 4395 Typically the prefix is ``L``, but targets may use other strings. ``.L`` is 4396 relatively popular. 4397 4398LLVM's support for inline asm is modeled closely on the requirements of Clang's 4399GCC-compatible inline-asm support. Thus, the feature-set and the constraint and 4400modifier codes listed here are similar or identical to those in GCC's inline asm 4401support. However, to be clear, the syntax of the template and constraint strings 4402described here is *not* the same as the syntax accepted by GCC and Clang, and, 4403while most constraint letters are passed through as-is by Clang, some get 4404translated to other codes when converting from the C source to the LLVM 4405assembly. 4406 4407An example inline assembler expression is: 4408 4409.. code-block:: llvm 4410 4411 i32 (i32) asm "bswap $0", "=r,r" 4412 4413Inline assembler expressions may **only** be used as the callee operand 4414of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction. 4415Thus, typically we have: 4416 4417.. code-block:: llvm 4418 4419 %X = call i32 asm "bswap $0", "=r,r"(i32 %Y) 4420 4421Inline asms with side effects not visible in the constraint list must be 4422marked as having side effects. This is done through the use of the 4423'``sideeffect``' keyword, like so: 4424 4425.. code-block:: llvm 4426 4427 call void asm sideeffect "eieio", ""() 4428 4429In some cases inline asms will contain code that will not work unless 4430the stack is aligned in some way, such as calls or SSE instructions on 4431x86, yet will not contain code that does that alignment within the asm. 4432The compiler should make conservative assumptions about what the asm 4433might contain and should generate its usual stack alignment code in the 4434prologue if the '``alignstack``' keyword is present: 4435 4436.. code-block:: llvm 4437 4438 call void asm alignstack "eieio", ""() 4439 4440Inline asms also support using non-standard assembly dialects. The 4441assumed dialect is ATT. When the '``inteldialect``' keyword is present, 4442the inline asm is using the Intel dialect. Currently, ATT and Intel are 4443the only supported dialects. An example is: 4444 4445.. code-block:: llvm 4446 4447 call void asm inteldialect "eieio", ""() 4448 4449In the case that the inline asm might unwind the stack, 4450the '``unwind``' keyword must be used, so that the compiler emits 4451unwinding information: 4452 4453.. code-block:: llvm 4454 4455 call void asm unwind "call func", ""() 4456 4457If the inline asm unwinds the stack and isn't marked with 4458the '``unwind``' keyword, the behavior is undefined. 4459 4460If multiple keywords appear, the '``sideeffect``' keyword must come 4461first, the '``alignstack``' keyword second, the '``inteldialect``' keyword 4462third and the '``unwind``' keyword last. 4463 4464Inline Asm Constraint String 4465^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4466 4467The constraint list is a comma-separated string, each element containing one or 4468more constraint codes. 4469 4470For each element in the constraint list an appropriate register or memory 4471operand will be chosen, and it will be made available to assembly template 4472string expansion as ``$0`` for the first constraint in the list, ``$1`` for the 4473second, etc. 4474 4475There are three different types of constraints, which are distinguished by a 4476prefix symbol in front of the constraint code: Output, Input, and Clobber. The 4477constraints must always be given in that order: outputs first, then inputs, then 4478clobbers. They cannot be intermingled. 4479 4480There are also three different categories of constraint codes: 4481 4482- Register constraint. This is either a register class, or a fixed physical 4483 register. This kind of constraint will allocate a register, and if necessary, 4484 bitcast the argument or result to the appropriate type. 4485- Memory constraint. This kind of constraint is for use with an instruction 4486 taking a memory operand. Different constraints allow for different addressing 4487 modes used by the target. 4488- Immediate value constraint. This kind of constraint is for an integer or other 4489 immediate value which can be rendered directly into an instruction. The 4490 various target-specific constraints allow the selection of a value in the 4491 proper range for the instruction you wish to use it with. 4492 4493Output constraints 4494"""""""""""""""""" 4495 4496Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This 4497indicates that the assembly will write to this operand, and the operand will 4498then be made available as a return value of the ``asm`` expression. Output 4499constraints do not consume an argument from the call instruction. (Except, see 4500below about indirect outputs). 4501 4502Normally, it is expected that no output locations are written to by the assembly 4503expression until *all* of the inputs have been read. As such, LLVM may assign 4504the same register to an output and an input. If this is not safe (e.g. if the 4505assembly contains two instructions, where the first writes to one output, and 4506the second reads an input and writes to a second output), then the "``&``" 4507modifier must be used (e.g. "``=&r``") to specify that the output is an 4508"early-clobber" output. Marking an output as "early-clobber" ensures that LLVM 4509will not use the same register for any inputs (other than an input tied to this 4510output). 4511 4512Input constraints 4513""""""""""""""""" 4514 4515Input constraints do not have a prefix -- just the constraint codes. Each input 4516constraint will consume one argument from the call instruction. It is not 4517permitted for the asm to write to any input register or memory location (unless 4518that input is tied to an output). Note also that multiple inputs may all be 4519assigned to the same register, if LLVM can determine that they necessarily all 4520contain the same value. 4521 4522Instead of providing a Constraint Code, input constraints may also "tie" 4523themselves to an output constraint, by providing an integer as the constraint 4524string. Tied inputs still consume an argument from the call instruction, and 4525take up a position in the asm template numbering as is usual -- they will simply 4526be constrained to always use the same register as the output they've been tied 4527to. For example, a constraint string of "``=r,0``" says to assign a register for 4528output, and use that register as an input as well (it being the 0'th 4529constraint). 4530 4531It is permitted to tie an input to an "early-clobber" output. In that case, no 4532*other* input may share the same register as the input tied to the early-clobber 4533(even when the other input has the same value). 4534 4535You may only tie an input to an output which has a register constraint, not a 4536memory constraint. Only a single input may be tied to an output. 4537 4538There is also an "interesting" feature which deserves a bit of explanation: if a 4539register class constraint allocates a register which is too small for the value 4540type operand provided as input, the input value will be split into multiple 4541registers, and all of them passed to the inline asm. 4542 4543However, this feature is often not as useful as you might think. 4544 4545Firstly, the registers are *not* guaranteed to be consecutive. So, on those 4546architectures that have instructions which operate on multiple consecutive 4547instructions, this is not an appropriate way to support them. (e.g. the 32-bit 4548SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The 4549hardware then loads into both the named register, and the next register. This 4550feature of inline asm would not be useful to support that.) 4551 4552A few of the targets provide a template string modifier allowing explicit access 4553to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and 4554``D``). On such an architecture, you can actually access the second allocated 4555register (yet, still, not any subsequent ones). But, in that case, you're still 4556probably better off simply splitting the value into two separate operands, for 4557clarity. (e.g. see the description of the ``A`` constraint on X86, which, 4558despite existing only for use with this feature, is not really a good idea to 4559use) 4560 4561Indirect inputs and outputs 4562""""""""""""""""""""""""""" 4563 4564Indirect output or input constraints can be specified by the "``*``" modifier 4565(which goes after the "``=``" in case of an output). This indicates that the asm 4566will write to or read from the contents of an *address* provided as an input 4567argument. (Note that in this way, indirect outputs act more like an *input* than 4568an output: just like an input, they consume an argument of the call expression, 4569rather than producing a return value. An indirect output constraint is an 4570"output" only in that the asm is expected to write to the contents of the input 4571memory location, instead of just read from it). 4572 4573This is most typically used for memory constraint, e.g. "``=*m``", to pass the 4574address of a variable as a value. 4575 4576It is also possible to use an indirect *register* constraint, but only on output 4577(e.g. "``=*r``"). This will cause LLVM to allocate a register for an output 4578value normally, and then, separately emit a store to the address provided as 4579input, after the provided inline asm. (It's not clear what value this 4580functionality provides, compared to writing the store explicitly after the asm 4581statement, and it can only produce worse code, since it bypasses many 4582optimization passes. I would recommend not using it.) 4583 4584Call arguments for indirect constraints must have pointer type and must specify 4585the :ref:`elementtype <attr_elementtype>` attribute to indicate the pointer 4586element type. 4587 4588Clobber constraints 4589""""""""""""""""""" 4590 4591A clobber constraint is indicated by a "``~``" prefix. A clobber does not 4592consume an input operand, nor generate an output. Clobbers cannot use any of the 4593general constraint code letters -- they may use only explicit register 4594constraints, e.g. "``~{eax}``". The one exception is that a clobber string of 4595"``~{memory}``" indicates that the assembly writes to arbitrary undeclared 4596memory locations -- not only the memory pointed to by a declared indirect 4597output. 4598 4599Note that clobbering named registers that are also present in output 4600constraints is not legal. 4601 4602 4603Constraint Codes 4604"""""""""""""""" 4605After a potential prefix comes constraint code, or codes. 4606 4607A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character 4608followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``" 4609(e.g. "``{eax}``"). 4610 4611The one and two letter constraint codes are typically chosen to be the same as 4612GCC's constraint codes. 4613 4614A single constraint may include one or more than constraint code in it, leaving 4615it up to LLVM to choose which one to use. This is included mainly for 4616compatibility with the translation of GCC inline asm coming from clang. 4617 4618There are two ways to specify alternatives, and either or both may be used in an 4619inline asm constraint list: 4620 46211) Append the codes to each other, making a constraint code set. E.g. "``im``" 4622 or "``{eax}m``". This means "choose any of the options in the set". The 4623 choice of constraint is made independently for each constraint in the 4624 constraint list. 4625 46262) Use "``|``" between constraint code sets, creating alternatives. Every 4627 constraint in the constraint list must have the same number of alternative 4628 sets. With this syntax, the same alternative in *all* of the items in the 4629 constraint list will be chosen together. 4630 4631Putting those together, you might have a two operand constraint string like 4632``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then 4633operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1 4634may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m. 4635 4636However, the use of either of the alternatives features is *NOT* recommended, as 4637LLVM is not able to make an intelligent choice about which one to use. (At the 4638point it currently needs to choose, not enough information is available to do so 4639in a smart way.) Thus, it simply tries to make a choice that's most likely to 4640compile, not one that will be optimal performance. (e.g., given "``rm``", it'll 4641always choose to use memory, not registers). And, if given multiple registers, 4642or multiple register classes, it will simply choose the first one. (In fact, it 4643doesn't currently even ensure explicitly specified physical registers are 4644unique, so specifying multiple physical registers as alternatives, like 4645``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was 4646intended.) 4647 4648Supported Constraint Code List 4649"""""""""""""""""""""""""""""" 4650 4651The constraint codes are, in general, expected to behave the same way they do in 4652GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C 4653inline asm code which was supported by GCC. A mismatch in behavior between LLVM 4654and GCC likely indicates a bug in LLVM. 4655 4656Some constraint codes are typically supported by all targets: 4657 4658- ``r``: A register in the target's general purpose register class. 4659- ``m``: A memory address operand. It is target-specific what addressing modes 4660 are supported, typical examples are register, or register + register offset, 4661 or register + immediate offset (of some target-specific size). 4662- ``p``: An address operand. Similar to ``m``, but used by "load address" 4663 type instructions without touching memory. 4664- ``i``: An integer constant (of target-specific width). Allows either a simple 4665 immediate, or a relocatable value. 4666- ``n``: An integer constant -- *not* including relocatable values. 4667- ``s``: An integer constant, but allowing *only* relocatable values. 4668- ``X``: Allows an operand of any kind, no constraint whatsoever. Typically 4669 useful to pass a label for an asm branch or call. 4670 4671 .. FIXME: but that surely isn't actually okay to jump out of an asm 4672 block without telling llvm about the control transfer???) 4673 4674- ``{register-name}``: Requires exactly the named physical register. 4675 4676Other constraints are target-specific: 4677 4678AArch64: 4679 4680- ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate. 4681- ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction, 4682 i.e. 0 to 4095 with optional shift by 12. 4683- ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or 4684 ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12. 4685- ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a 4686 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register. 4687- ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a 4688 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register. 4689- ``M``: An immediate integer for use with the ``MOV`` assembly alias on a 4690 32-bit register. This is a superset of ``K``: in addition to the bitmask 4691 immediate, also allows immediate integers which can be loaded with a single 4692 ``MOVZ`` or ``MOVL`` instruction. 4693- ``N``: An immediate integer for use with the ``MOV`` assembly alias on a 4694 64-bit register. This is a superset of ``L``. 4695- ``Q``: Memory address operand must be in a single register (no 4696 offsets). (However, LLVM currently does this for the ``m`` constraint as 4697 well.) 4698- ``r``: A 32 or 64-bit integer register (W* or X*). 4699- ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register. 4700- ``x``: Like w, but restricted to registers 0 to 15 inclusive. 4701- ``y``: Like w, but restricted to SVE vector registers Z0 to Z7 inclusive. 4702- ``Upl``: One of the low eight SVE predicate registers (P0 to P7) 4703- ``Upa``: Any of the SVE predicate registers (P0 to P15) 4704 4705AMDGPU: 4706 4707- ``r``: A 32 or 64-bit integer register. 4708- ``[0-9]v``: The 32-bit VGPR register, number 0-9. 4709- ``[0-9]s``: The 32-bit SGPR register, number 0-9. 4710- ``[0-9]a``: The 32-bit AGPR register, number 0-9. 4711- ``I``: An integer inline constant in the range from -16 to 64. 4712- ``J``: A 16-bit signed integer constant. 4713- ``A``: An integer or a floating-point inline constant. 4714- ``B``: A 32-bit signed integer constant. 4715- ``C``: A 32-bit unsigned integer constant or an integer inline constant in the range from -16 to 64. 4716- ``DA``: A 64-bit constant that can be split into two "A" constants. 4717- ``DB``: A 64-bit constant that can be split into two "B" constants. 4718 4719All ARM modes: 4720 4721- ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address 4722 operand. Treated the same as operand ``m``, at the moment. 4723- ``Te``: An even general-purpose 32-bit integer register: ``r0,r2,...,r12,r14`` 4724- ``To``: An odd general-purpose 32-bit integer register: ``r1,r3,...,r11`` 4725 4726ARM and ARM's Thumb2 mode: 4727 4728- ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``) 4729- ``I``: An immediate integer valid for a data-processing instruction. 4730- ``J``: An immediate integer between -4095 and 4095. 4731- ``K``: An immediate integer whose bitwise inverse is valid for a 4732 data-processing instruction. (Can be used with template modifier "``B``" to 4733 print the inverted value). 4734- ``L``: An immediate integer whose negation is valid for a data-processing 4735 instruction. (Can be used with template modifier "``n``" to print the negated 4736 value). 4737- ``M``: A power of two or an integer between 0 and 32. 4738- ``N``: Invalid immediate constraint. 4739- ``O``: Invalid immediate constraint. 4740- ``r``: A general-purpose 32-bit integer register (``r0-r15``). 4741- ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same 4742 as ``r``. 4743- ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode, 4744 invalid. 4745- ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4746 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively. 4747- ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4748 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively. 4749- ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4750 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively. 4751 4752ARM's Thumb1 mode: 4753 4754- ``I``: An immediate integer between 0 and 255. 4755- ``J``: An immediate integer between -255 and -1. 4756- ``K``: An immediate integer between 0 and 255, with optional left-shift by 4757 some amount. 4758- ``L``: An immediate integer between -7 and 7. 4759- ``M``: An immediate integer which is a multiple of 4 between 0 and 1020. 4760- ``N``: An immediate integer between 0 and 31. 4761- ``O``: An immediate integer which is a multiple of 4 between -508 and 508. 4762- ``r``: A low 32-bit GPR register (``r0-r7``). 4763- ``l``: A low 32-bit GPR register (``r0-r7``). 4764- ``h``: A high GPR register (``r0-r7``). 4765- ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4766 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively. 4767- ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4768 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively. 4769- ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4770 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively. 4771 4772 4773Hexagon: 4774 4775- ``o``, ``v``: A memory address operand, treated the same as constraint ``m``, 4776 at the moment. 4777- ``r``: A 32 or 64-bit register. 4778 4779MSP430: 4780 4781- ``r``: An 8 or 16-bit register. 4782 4783MIPS: 4784 4785- ``I``: An immediate signed 16-bit integer. 4786- ``J``: An immediate integer zero. 4787- ``K``: An immediate unsigned 16-bit integer. 4788- ``L``: An immediate 32-bit integer, where the lower 16 bits are 0. 4789- ``N``: An immediate integer between -65535 and -1. 4790- ``O``: An immediate signed 15-bit integer. 4791- ``P``: An immediate integer between 1 and 65535. 4792- ``m``: A memory address operand. In MIPS-SE mode, allows a base address 4793 register plus 16-bit immediate offset. In MIPS mode, just a base register. 4794- ``R``: A memory address operand. In MIPS-SE mode, allows a base address 4795 register plus a 9-bit signed offset. In MIPS mode, the same as constraint 4796 ``m``. 4797- ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or 4798 ``sc`` instruction on the given subtarget (details vary). 4799- ``r``, ``d``, ``y``: A 32 or 64-bit GPR register. 4800- ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register 4801 (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w`` 4802 argument modifier for compatibility with GCC. 4803- ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always 4804 ``25``). 4805- ``l``: The ``lo`` register, 32 or 64-bit. 4806- ``x``: Invalid. 4807 4808NVPTX: 4809 4810- ``b``: A 1-bit integer register. 4811- ``c`` or ``h``: A 16-bit integer register. 4812- ``r``: A 32-bit integer register. 4813- ``l`` or ``N``: A 64-bit integer register. 4814- ``f``: A 32-bit float register. 4815- ``d``: A 64-bit float register. 4816 4817 4818PowerPC: 4819 4820- ``I``: An immediate signed 16-bit integer. 4821- ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits. 4822- ``K``: An immediate unsigned 16-bit integer. 4823- ``L``: An immediate signed 16-bit integer, shifted left 16 bits. 4824- ``M``: An immediate integer greater than 31. 4825- ``N``: An immediate integer that is an exact power of 2. 4826- ``O``: The immediate integer constant 0. 4827- ``P``: An immediate integer constant whose negation is a signed 16-bit 4828 constant. 4829- ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently 4830 treated the same as ``m``. 4831- ``r``: A 32 or 64-bit integer register. 4832- ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is: 4833 ``R1-R31``). 4834- ``f``: A 32 or 64-bit float register (``F0-F31``), 4835- ``v``: For ``4 x f32`` or ``4 x f64`` types, a 128-bit altivec vector 4836 register (``V0-V31``). 4837 4838- ``y``: Condition register (``CR0-CR7``). 4839- ``wc``: An individual CR bit in a CR register. 4840- ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX 4841 register set (overlapping both the floating-point and vector register files). 4842- ``ws``: A 32 or 64-bit floating-point register, from the full VSX register 4843 set. 4844 4845RISC-V: 4846 4847- ``A``: An address operand (using a general-purpose register, without an 4848 offset). 4849- ``I``: A 12-bit signed integer immediate operand. 4850- ``J``: A zero integer immediate operand. 4851- ``K``: A 5-bit unsigned integer immediate operand. 4852- ``f``: A 32- or 64-bit floating-point register (requires F or D extension). 4853- ``r``: A 32- or 64-bit general-purpose register (depending on the platform 4854 ``XLEN``). 4855- ``vr``: A vector register. (requires V extension). 4856- ``vm``: A vector register for masking operand. (requires V extension). 4857 4858Sparc: 4859 4860- ``I``: An immediate 13-bit signed integer. 4861- ``r``: A 32-bit integer register. 4862- ``f``: Any floating-point register on SparcV8, or a floating-point 4863 register in the "low" half of the registers on SparcV9. 4864- ``e``: Any floating-point register. (Same as ``f`` on SparcV8.) 4865 4866SystemZ: 4867 4868- ``I``: An immediate unsigned 8-bit integer. 4869- ``J``: An immediate unsigned 12-bit integer. 4870- ``K``: An immediate signed 16-bit integer. 4871- ``L``: An immediate signed 20-bit integer. 4872- ``M``: An immediate integer 0x7fffffff. 4873- ``Q``: A memory address operand with a base address and a 12-bit immediate 4874 unsigned displacement. 4875- ``R``: A memory address operand with a base address, a 12-bit immediate 4876 unsigned displacement, and an index register. 4877- ``S``: A memory address operand with a base address and a 20-bit immediate 4878 signed displacement. 4879- ``T``: A memory address operand with a base address, a 20-bit immediate 4880 signed displacement, and an index register. 4881- ``r`` or ``d``: A 32, 64, or 128-bit integer register. 4882- ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an 4883 address context evaluates as zero). 4884- ``h``: A 32-bit value in the high part of a 64bit data register 4885 (LLVM-specific) 4886- ``f``: A 32, 64, or 128-bit floating-point register. 4887 4888X86: 4889 4890- ``I``: An immediate integer between 0 and 31. 4891- ``J``: An immediate integer between 0 and 64. 4892- ``K``: An immediate signed 8-bit integer. 4893- ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only) 4894 0xffffffff. 4895- ``M``: An immediate integer between 0 and 3. 4896- ``N``: An immediate unsigned 8-bit integer. 4897- ``O``: An immediate integer between 0 and 127. 4898- ``e``: An immediate 32-bit signed integer. 4899- ``Z``: An immediate 32-bit unsigned integer. 4900- ``o``, ``v``: Treated the same as ``m``, at the moment. 4901- ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit 4902 ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d`` 4903 registers, and on X86-64, it is all of the integer registers. 4904- ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit 4905 ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers. 4906- ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register. 4907- ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has 4908 existed since i386, and can be accessed without the REX prefix. 4909- ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register. 4910- ``y``: A 64-bit MMX register, if MMX is enabled. 4911- ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector 4912 operand in a SSE register. If AVX is also enabled, can also be a 256-bit 4913 vector operand in an AVX register. If AVX-512 is also enabled, can also be a 4914 512-bit vector operand in an AVX512 register, Otherwise, an error. 4915- ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error. 4916- ``A``: Special case: allocates EAX first, then EDX, for a single operand (in 4917 32-bit mode, a 64-bit integer operand will get split into two registers). It 4918 is not recommended to use this constraint, as in 64-bit mode, the 64-bit 4919 operand will get allocated only to RAX -- if two 32-bit operands are needed, 4920 you're better off splitting it yourself, before passing it to the asm 4921 statement. 4922 4923XCore: 4924 4925- ``r``: A 32-bit integer register. 4926 4927 4928.. _inline-asm-modifiers: 4929 4930Asm template argument modifiers 4931^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4932 4933In the asm template string, modifiers can be used on the operand reference, like 4934"``${0:n}``". 4935 4936The modifiers are, in general, expected to behave the same way they do in 4937GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C 4938inline asm code which was supported by GCC. A mismatch in behavior between LLVM 4939and GCC likely indicates a bug in LLVM. 4940 4941Target-independent: 4942 4943- ``c``: Print an immediate integer constant unadorned, without 4944 the target-specific immediate punctuation (e.g. no ``$`` prefix). 4945- ``n``: Negate and print immediate integer constant unadorned, without the 4946 target-specific immediate punctuation (e.g. no ``$`` prefix). 4947- ``l``: Print as an unadorned label, without the target-specific label 4948 punctuation (e.g. no ``$`` prefix). 4949 4950AArch64: 4951 4952- ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g., 4953 instead of ``x30``, print ``w30``. 4954- ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow). 4955- ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a 4956 ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of 4957 ``v*``. 4958 4959AMDGPU: 4960 4961- ``r``: No effect. 4962 4963ARM: 4964 4965- ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a 4966 register). 4967- ``P``: No effect. 4968- ``q``: No effect. 4969- ``y``: Print a VFP single-precision register as an indexed double (e.g. print 4970 as ``d4[1]`` instead of ``s9``) 4971- ``B``: Bitwise invert and print an immediate integer constant without ``#`` 4972 prefix. 4973- ``L``: Print the low 16-bits of an immediate integer constant. 4974- ``M``: Print as a register set suitable for ldm/stm. Also prints *all* 4975 register operands subsequent to the specified one (!), so use carefully. 4976- ``Q``: Print the low-order register of a register-pair, or the low-order 4977 register of a two-register operand. 4978- ``R``: Print the high-order register of a register-pair, or the high-order 4979 register of a two-register operand. 4980- ``H``: Print the second register of a register-pair. (On a big-endian system, 4981 ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent 4982 to ``R``.) 4983 4984 .. FIXME: H doesn't currently support printing the second register 4985 of a two-register operand. 4986 4987- ``e``: Print the low doubleword register of a NEON quad register. 4988- ``f``: Print the high doubleword register of a NEON quad register. 4989- ``m``: Print the base register of a memory operand without the ``[`` and ``]`` 4990 adornment. 4991 4992Hexagon: 4993 4994- ``L``: Print the second register of a two-register operand. Requires that it 4995 has been allocated consecutively to the first. 4996 4997 .. FIXME: why is it restricted to consecutive ones? And there's 4998 nothing that ensures that happens, is there? 4999 5000- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise 5001 nothing. Used to print 'addi' vs 'add' instructions. 5002 5003MSP430: 5004 5005No additional modifiers. 5006 5007MIPS: 5008 5009- ``X``: Print an immediate integer as hexadecimal 5010- ``x``: Print the low 16 bits of an immediate integer as hexadecimal. 5011- ``d``: Print an immediate integer as decimal. 5012- ``m``: Subtract one and print an immediate integer as decimal. 5013- ``z``: Print $0 if an immediate zero, otherwise print normally. 5014- ``L``: Print the low-order register of a two-register operand, or prints the 5015 address of the low-order word of a double-word memory operand. 5016 5017 .. FIXME: L seems to be missing memory operand support. 5018 5019- ``M``: Print the high-order register of a two-register operand, or prints the 5020 address of the high-order word of a double-word memory operand. 5021 5022 .. FIXME: M seems to be missing memory operand support. 5023 5024- ``D``: Print the second register of a two-register operand, or prints the 5025 second word of a double-word memory operand. (On a big-endian system, ``D`` is 5026 equivalent to ``L``, and on little-endian system, ``D`` is equivalent to 5027 ``M``.) 5028- ``w``: No effect. Provided for compatibility with GCC which requires this 5029 modifier in order to print MSA registers (``W0-W31``) with the ``f`` 5030 constraint. 5031 5032NVPTX: 5033 5034- ``r``: No effect. 5035 5036PowerPC: 5037 5038- ``L``: Print the second register of a two-register operand. Requires that it 5039 has been allocated consecutively to the first. 5040 5041 .. FIXME: why is it restricted to consecutive ones? And there's 5042 nothing that ensures that happens, is there? 5043 5044- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise 5045 nothing. Used to print 'addi' vs 'add' instructions. 5046- ``y``: For a memory operand, prints formatter for a two-register X-form 5047 instruction. (Currently always prints ``r0,OPERAND``). 5048- ``U``: Prints 'u' if the memory operand is an update form, and nothing 5049 otherwise. (NOTE: LLVM does not support update form, so this will currently 5050 always print nothing) 5051- ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does 5052 not support indexed form, so this will currently always print nothing) 5053 5054RISC-V: 5055 5056- ``i``: Print the letter 'i' if the operand is not a register, otherwise print 5057 nothing. Used to print 'addi' vs 'add' instructions, etc. 5058- ``z``: Print the register ``zero`` if an immediate zero, otherwise print 5059 normally. 5060 5061Sparc: 5062 5063- ``r``: No effect. 5064 5065SystemZ: 5066 5067SystemZ implements only ``n``, and does *not* support any of the other 5068target-independent modifiers. 5069 5070X86: 5071 5072- ``c``: Print an unadorned integer or symbol name. (The latter is 5073 target-specific behavior for this typically target-independent modifier). 5074- ``A``: Print a register name with a '``*``' before it. 5075- ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory 5076 operand. 5077- ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a 5078 memory operand. 5079- ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory 5080 operand. 5081- ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory 5082 operand. 5083- ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are 5084 available, otherwise the 32-bit register name; do nothing on a memory operand. 5085- ``n``: Negate and print an unadorned integer, or, for operands other than an 5086 immediate integer (e.g. a relocatable symbol expression), print a '-' before 5087 the operand. (The behavior for relocatable symbol expressions is a 5088 target-specific behavior for this typically target-independent modifier) 5089- ``H``: Print a memory reference with additional offset +8. 5090- ``P``: Print a memory reference used as the argument of a call instruction or 5091 used with explicit base reg and index reg as its offset. So it can not use 5092 additional regs to present the memory reference. (E.g. omit ``(rip)``, even 5093 though it's PC-relative.) 5094 5095XCore: 5096 5097No additional modifiers. 5098 5099 5100Inline Asm Metadata 5101^^^^^^^^^^^^^^^^^^^ 5102 5103The call instructions that wrap inline asm nodes may have a 5104"``!srcloc``" MDNode attached to it that contains a list of constant 5105integers. If present, the code generator will use the integer as the 5106location cookie value when report errors through the ``LLVMContext`` 5107error reporting mechanisms. This allows a front-end to correlate backend 5108errors that occur with inline asm back to the source code that produced 5109it. For example: 5110 5111.. code-block:: llvm 5112 5113 call void asm sideeffect "something bad", ""(), !srcloc !42 5114 ... 5115 !42 = !{ i32 1234567 } 5116 5117It is up to the front-end to make sense of the magic numbers it places 5118in the IR. If the MDNode contains multiple constants, the code generator 5119will use the one that corresponds to the line of the asm that the error 5120occurs on. 5121 5122.. _metadata: 5123 5124Metadata 5125======== 5126 5127LLVM IR allows metadata to be attached to instructions and global objects in the 5128program that can convey extra information about the code to the optimizers and 5129code generator. One example application of metadata is source-level 5130debug information. There are two metadata primitives: strings and nodes. 5131 5132Metadata does not have a type, and is not a value. If referenced from a 5133``call`` instruction, it uses the ``metadata`` type. 5134 5135All metadata are identified in syntax by an exclamation point ('``!``'). 5136 5137.. _metadata-string: 5138 5139Metadata Nodes and Metadata Strings 5140----------------------------------- 5141 5142A metadata string is a string surrounded by double quotes. It can 5143contain any character by escaping non-printable characters with 5144"``\xx``" where "``xx``" is the two digit hex code. For example: 5145"``!"test\00"``". 5146 5147Metadata nodes are represented with notation similar to structure 5148constants (a comma separated list of elements, surrounded by braces and 5149preceded by an exclamation point). Metadata nodes can have any values as 5150their operand. For example: 5151 5152.. code-block:: llvm 5153 5154 !{ !"test\00", i32 10} 5155 5156Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example: 5157 5158.. code-block:: text 5159 5160 !0 = distinct !{!"test\00", i32 10} 5161 5162``distinct`` nodes are useful when nodes shouldn't be merged based on their 5163content. They can also occur when transformations cause uniquing collisions 5164when metadata operands change. 5165 5166A :ref:`named metadata <namedmetadatastructure>` is a collection of 5167metadata nodes, which can be looked up in the module symbol table. For 5168example: 5169 5170.. code-block:: llvm 5171 5172 !foo = !{!4, !3} 5173 5174Metadata can be used as function arguments. Here the ``llvm.dbg.value`` 5175intrinsic is using three metadata arguments: 5176 5177.. code-block:: llvm 5178 5179 call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26) 5180 5181Metadata can be attached to an instruction. Here metadata ``!21`` is attached 5182to the ``add`` instruction using the ``!dbg`` identifier: 5183 5184.. code-block:: llvm 5185 5186 %indvar.next = add i64 %indvar, 1, !dbg !21 5187 5188Instructions may not have multiple metadata attachments with the same 5189identifier. 5190 5191Metadata can also be attached to a function or a global variable. Here metadata 5192``!22`` is attached to the ``f1`` and ``f2`` functions, and the globals ``g1`` 5193and ``g2`` using the ``!dbg`` identifier: 5194 5195.. code-block:: llvm 5196 5197 declare !dbg !22 void @f1() 5198 define void @f2() !dbg !22 { 5199 ret void 5200 } 5201 5202 @g1 = global i32 0, !dbg !22 5203 @g2 = external global i32, !dbg !22 5204 5205Unlike instructions, global objects (functions and global variables) may have 5206multiple metadata attachments with the same identifier. 5207 5208A transformation is required to drop any metadata attachment that it does not 5209know or know it can't preserve. Currently there is an exception for metadata 5210attachment to globals for ``!type`` and ``!absolute_symbol`` which can't be 5211unconditionally dropped unless the global is itself deleted. 5212 5213Metadata attached to a module using named metadata may not be dropped, with 5214the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``). 5215 5216More information about specific metadata nodes recognized by the 5217optimizers and code generator is found below. 5218 5219.. _specialized-metadata: 5220 5221Specialized Metadata Nodes 5222^^^^^^^^^^^^^^^^^^^^^^^^^^ 5223 5224Specialized metadata nodes are custom data structures in metadata (as opposed 5225to generic tuples). Their fields are labelled, and can be specified in any 5226order. 5227 5228These aren't inherently debug info centric, but currently all the specialized 5229metadata nodes are related to debug info. 5230 5231.. _DICompileUnit: 5232 5233DICompileUnit 5234""""""""""""" 5235 5236``DICompileUnit`` nodes represent a compile unit. The ``enums:``, 5237``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples 5238containing the debug info to be emitted along with the compile unit, regardless 5239of code optimizations (some nodes are only emitted if there are references to 5240them from instructions). The ``debugInfoForProfiling:`` field is a boolean 5241indicating whether or not line-table discriminators are updated to provide 5242more-accurate debug info for profiling results. 5243 5244.. code-block:: text 5245 5246 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", 5247 isOptimized: true, flags: "-O2", runtimeVersion: 2, 5248 splitDebugFilename: "abc.debug", emissionKind: FullDebug, 5249 enums: !2, retainedTypes: !3, globals: !4, imports: !5, 5250 macros: !6, dwoId: 0x0abcd) 5251 5252Compile unit descriptors provide the root scope for objects declared in a 5253specific compilation unit. File descriptors are defined using this scope. These 5254descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep 5255track of global variables, type information, and imported entities (declarations 5256and namespaces). 5257 5258.. _DIFile: 5259 5260DIFile 5261"""""" 5262 5263``DIFile`` nodes represent files. The ``filename:`` can include slashes. 5264 5265.. code-block:: none 5266 5267 !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir", 5268 checksumkind: CSK_MD5, 5269 checksum: "000102030405060708090a0b0c0d0e0f") 5270 5271Files are sometimes used in ``scope:`` fields, and are the only valid target 5272for ``file:`` fields. 5273Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1, CSK_SHA256} 5274 5275.. _DIBasicType: 5276 5277DIBasicType 5278""""""""""" 5279 5280``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and 5281``float``. ``tag:`` defaults to ``DW_TAG_base_type``. 5282 5283.. code-block:: text 5284 5285 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8, 5286 encoding: DW_ATE_unsigned_char) 5287 !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)") 5288 5289The ``encoding:`` describes the details of the type. Usually it's one of the 5290following: 5291 5292.. code-block:: text 5293 5294 DW_ATE_address = 1 5295 DW_ATE_boolean = 2 5296 DW_ATE_float = 4 5297 DW_ATE_signed = 5 5298 DW_ATE_signed_char = 6 5299 DW_ATE_unsigned = 7 5300 DW_ATE_unsigned_char = 8 5301 5302.. _DISubroutineType: 5303 5304DISubroutineType 5305"""""""""""""""" 5306 5307``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field 5308refers to a tuple; the first operand is the return type, while the rest are the 5309types of the formal arguments in order. If the first operand is ``null``, that 5310represents a function with no return value (such as ``void foo() {}`` in C++). 5311 5312.. code-block:: text 5313 5314 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed) 5315 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char) 5316 !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char) 5317 5318.. _DIDerivedType: 5319 5320DIDerivedType 5321""""""""""""" 5322 5323``DIDerivedType`` nodes represent types derived from other types, such as 5324qualified types. 5325 5326.. code-block:: text 5327 5328 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8, 5329 encoding: DW_ATE_unsigned_char) 5330 !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32, 5331 align: 32) 5332 5333The following ``tag:`` values are valid: 5334 5335.. code-block:: text 5336 5337 DW_TAG_member = 13 5338 DW_TAG_pointer_type = 15 5339 DW_TAG_reference_type = 16 5340 DW_TAG_typedef = 22 5341 DW_TAG_inheritance = 28 5342 DW_TAG_ptr_to_member_type = 31 5343 DW_TAG_const_type = 38 5344 DW_TAG_friend = 42 5345 DW_TAG_volatile_type = 53 5346 DW_TAG_restrict_type = 55 5347 DW_TAG_atomic_type = 71 5348 DW_TAG_immutable_type = 75 5349 5350.. _DIDerivedTypeMember: 5351 5352``DW_TAG_member`` is used to define a member of a :ref:`composite type 5353<DICompositeType>`. The type of the member is the ``baseType:``. The 5354``offset:`` is the member's bit offset. If the composite type has an ODR 5355``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is 5356uniqued based only on its ``name:`` and ``scope:``. 5357 5358``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:`` 5359field of :ref:`composite types <DICompositeType>` to describe parents and 5360friends. 5361 5362``DW_TAG_typedef`` is used to provide a name for the ``baseType:``. 5363 5364``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``, 5365``DW_TAG_volatile_type``, ``DW_TAG_restrict_type``, ``DW_TAG_atomic_type`` and 5366``DW_TAG_immutable_type`` are used to qualify the ``baseType:``. 5367 5368Note that the ``void *`` type is expressed as a type derived from NULL. 5369 5370.. _DICompositeType: 5371 5372DICompositeType 5373""""""""""""""" 5374 5375``DICompositeType`` nodes represent types composed of other types, like 5376structures and unions. ``elements:`` points to a tuple of the composed types. 5377 5378If the source language supports ODR, the ``identifier:`` field gives the unique 5379identifier used for type merging between modules. When specified, 5380:ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member 5381derived types <DIDerivedTypeMember>` that reference the ODR-type in their 5382``scope:`` change uniquing rules. 5383 5384For a given ``identifier:``, there should only be a single composite type that 5385does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules 5386together will unique such definitions at parse time via the ``identifier:`` 5387field, even if the nodes are ``distinct``. 5388 5389.. code-block:: text 5390 5391 !0 = !DIEnumerator(name: "SixKind", value: 7) 5392 !1 = !DIEnumerator(name: "SevenKind", value: 7) 5393 !2 = !DIEnumerator(name: "NegEightKind", value: -8) 5394 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12, 5395 line: 2, size: 32, align: 32, identifier: "_M4Enum", 5396 elements: !{!0, !1, !2}) 5397 5398The following ``tag:`` values are valid: 5399 5400.. code-block:: text 5401 5402 DW_TAG_array_type = 1 5403 DW_TAG_class_type = 2 5404 DW_TAG_enumeration_type = 4 5405 DW_TAG_structure_type = 19 5406 DW_TAG_union_type = 23 5407 5408For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange 5409descriptors <DISubrange>`, each representing the range of subscripts at that 5410level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an 5411array type is a native packed vector. The optional ``dataLocation`` is a 5412DIExpression that describes how to get from an object's address to the actual 5413raw data, if they aren't equivalent. This is only supported for array types, 5414particularly to describe Fortran arrays, which have an array descriptor in 5415addition to the array data. Alternatively it can also be DIVariable which 5416has the address of the actual raw data. The Fortran language supports pointer 5417arrays which can be attached to actual arrays, this attachment between pointer 5418and pointee is called association. The optional ``associated`` is a 5419DIExpression that describes whether the pointer array is currently associated. 5420The optional ``allocated`` is a DIExpression that describes whether the 5421allocatable array is currently allocated. The optional ``rank`` is a 5422DIExpression that describes the rank (number of dimensions) of fortran assumed 5423rank array (rank is known at runtime). 5424 5425For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator 5426descriptors <DIEnumerator>`, each representing the definition of an enumeration 5427value for the set. All enumeration type descriptors are collected in the 5428``enums:`` field of the :ref:`compile unit <DICompileUnit>`. 5429 5430For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and 5431``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types 5432<DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or 5433``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with 5434``isDefinition: false``. 5435 5436.. _DISubrange: 5437 5438DISubrange 5439"""""""""" 5440 5441``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of 5442:ref:`DICompositeType`. 5443 5444- ``count: -1`` indicates an empty array. 5445- ``count: !10`` describes the count with a :ref:`DILocalVariable`. 5446- ``count: !12`` describes the count with a :ref:`DIGlobalVariable`. 5447 5448.. code-block:: text 5449 5450 !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0 5451 !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1 5452 !2 = !DISubrange(count: -1) ; empty array. 5453 5454 ; Scopes used in rest of example 5455 !6 = !DIFile(filename: "vla.c", directory: "/path/to/file") 5456 !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6) 5457 !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5) 5458 5459 ; Use of local variable as count value 5460 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 5461 !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9) 5462 !11 = !DISubrange(count: !10, lowerBound: 0) 5463 5464 ; Use of global variable as count value 5465 !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9) 5466 !13 = !DISubrange(count: !12, lowerBound: 0) 5467 5468.. _DIEnumerator: 5469 5470DIEnumerator 5471"""""""""""" 5472 5473``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type`` 5474variants of :ref:`DICompositeType`. 5475 5476.. code-block:: text 5477 5478 !0 = !DIEnumerator(name: "SixKind", value: 7) 5479 !1 = !DIEnumerator(name: "SevenKind", value: 7) 5480 !2 = !DIEnumerator(name: "NegEightKind", value: -8) 5481 5482DITemplateTypeParameter 5483""""""""""""""""""""""" 5484 5485``DITemplateTypeParameter`` nodes represent type parameters to generic source 5486language constructs. They are used (optionally) in :ref:`DICompositeType` and 5487:ref:`DISubprogram` ``templateParams:`` fields. 5488 5489.. code-block:: text 5490 5491 !0 = !DITemplateTypeParameter(name: "Ty", type: !1) 5492 5493DITemplateValueParameter 5494"""""""""""""""""""""""" 5495 5496``DITemplateValueParameter`` nodes represent value parameters to generic source 5497language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``, 5498but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or 5499``DW_TAG_GNU_template_param_pack``. They are used (optionally) in 5500:ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields. 5501 5502.. code-block:: text 5503 5504 !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7) 5505 5506DINamespace 5507""""""""""" 5508 5509``DINamespace`` nodes represent namespaces in the source language. 5510 5511.. code-block:: text 5512 5513 !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7) 5514 5515.. _DIGlobalVariable: 5516 5517DIGlobalVariable 5518"""""""""""""""" 5519 5520``DIGlobalVariable`` nodes represent global variables in the source language. 5521 5522.. code-block:: text 5523 5524 @foo = global i32, !dbg !0 5525 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 5526 !1 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !2, 5527 file: !3, line: 7, type: !4, isLocal: true, 5528 isDefinition: false, declaration: !5) 5529 5530 5531DIGlobalVariableExpression 5532"""""""""""""""""""""""""" 5533 5534``DIGlobalVariableExpression`` nodes tie a :ref:`DIGlobalVariable` together 5535with a :ref:`DIExpression`. 5536 5537.. code-block:: text 5538 5539 @lower = global i32, !dbg !0 5540 @upper = global i32, !dbg !1 5541 !0 = !DIGlobalVariableExpression( 5542 var: !2, 5543 expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32) 5544 ) 5545 !1 = !DIGlobalVariableExpression( 5546 var: !2, 5547 expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32) 5548 ) 5549 !2 = !DIGlobalVariable(name: "split64", linkageName: "split64", scope: !3, 5550 file: !4, line: 8, type: !5, declaration: !6) 5551 5552All global variable expressions should be referenced by the `globals:` field of 5553a :ref:`compile unit <DICompileUnit>`. 5554 5555.. _DISubprogram: 5556 5557DISubprogram 5558"""""""""""" 5559 5560``DISubprogram`` nodes represent functions from the source language. A distinct 5561``DISubprogram`` may be attached to a function definition using ``!dbg`` 5562metadata. A unique ``DISubprogram`` may be attached to a function declaration 5563used for call site debug info. The ``retainedNodes:`` field is a list of 5564:ref:`variables <DILocalVariable>` and :ref:`labels <DILabel>` that must be 5565retained, even if their IR counterparts are optimized out of the IR. The 5566``type:`` field must point at an :ref:`DISubroutineType`. 5567 5568.. _DISubprogramDeclaration: 5569 5570When ``isDefinition: false``, subprograms describe a declaration in the type 5571tree as opposed to a definition of a function. If the scope is a composite 5572type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``, 5573then the subprogram declaration is uniqued based only on its ``linkageName:`` 5574and ``scope:``. 5575 5576.. code-block:: text 5577 5578 define void @_Z3foov() !dbg !0 { 5579 ... 5580 } 5581 5582 !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1, 5583 file: !2, line: 7, type: !3, isLocal: true, 5584 isDefinition: true, scopeLine: 8, 5585 containingType: !4, 5586 virtuality: DW_VIRTUALITY_pure_virtual, 5587 virtualIndex: 10, flags: DIFlagPrototyped, 5588 isOptimized: true, unit: !5, templateParams: !6, 5589 declaration: !7, retainedNodes: !8, 5590 thrownTypes: !9) 5591 5592.. _DILexicalBlock: 5593 5594DILexicalBlock 5595"""""""""""""" 5596 5597``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram 5598<DISubprogram>`. The line number and column numbers are used to distinguish 5599two lexical blocks at same depth. They are valid targets for ``scope:`` 5600fields. 5601 5602.. code-block:: text 5603 5604 !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35) 5605 5606Usually lexical blocks are ``distinct`` to prevent node merging based on 5607operands. 5608 5609.. _DILexicalBlockFile: 5610 5611DILexicalBlockFile 5612"""""""""""""""""" 5613 5614``DILexicalBlockFile`` nodes are used to discriminate between sections of a 5615:ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to 5616indicate textual inclusion, or the ``discriminator:`` field can be used to 5617discriminate between control flow within a single block in the source language. 5618 5619.. code-block:: text 5620 5621 !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35) 5622 !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0) 5623 !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1) 5624 5625.. _DILocation: 5626 5627DILocation 5628"""""""""" 5629 5630``DILocation`` nodes represent source debug locations. The ``scope:`` field is 5631mandatory, and points at an :ref:`DILexicalBlockFile`, an 5632:ref:`DILexicalBlock`, or an :ref:`DISubprogram`. 5633 5634.. code-block:: text 5635 5636 !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2) 5637 5638.. _DILocalVariable: 5639 5640DILocalVariable 5641""""""""""""""" 5642 5643``DILocalVariable`` nodes represent local variables in the source language. If 5644the ``arg:`` field is set to non-zero, then this variable is a subprogram 5645parameter, and it will be included in the ``retainedNodes:`` field of its 5646:ref:`DISubprogram`. 5647 5648.. code-block:: text 5649 5650 !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7, 5651 type: !3, flags: DIFlagArtificial) 5652 !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7, 5653 type: !3) 5654 !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3) 5655 5656.. _DIExpression: 5657 5658DIExpression 5659"""""""""""" 5660 5661``DIExpression`` nodes represent expressions that are inspired by the DWARF 5662expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>` 5663(such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the 5664referenced LLVM variable relates to the source language variable. Debug 5665intrinsics are interpreted left-to-right: start by pushing the value/address 5666operand of the intrinsic onto a stack, then repeatedly push and evaluate 5667opcodes from the DIExpression until the final variable description is produced. 5668 5669The current supported opcode vocabulary is limited: 5670 5671- ``DW_OP_deref`` dereferences the top of the expression stack. 5672- ``DW_OP_plus`` pops the last two entries from the expression stack, adds 5673 them together and appends the result to the expression stack. 5674- ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts 5675 the last entry from the second last entry and appends the result to the 5676 expression stack. 5677- ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression. 5678- ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8`` 5679 here, respectively) of the variable fragment from the working expression. Note 5680 that contrary to DW_OP_bit_piece, the offset is describing the location 5681 within the described source variable. 5682- ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding 5683 (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the 5684 expression stack is to be converted. Maps into a ``DW_OP_convert`` operation 5685 that references a base type constructed from the supplied values. 5686- ``DW_OP_LLVM_tag_offset, tag_offset`` specifies that a memory tag should be 5687 optionally applied to the pointer. The memory tag is derived from the 5688 given tag offset in an implementation-defined manner. 5689- ``DW_OP_swap`` swaps top two stack entries. 5690- ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top 5691 of the stack is treated as an address. The second stack entry is treated as an 5692 address space identifier. 5693- ``DW_OP_stack_value`` marks a constant value. 5694- ``DW_OP_LLVM_entry_value, N`` may only appear in MIR and at the 5695 beginning of a ``DIExpression``. In DWARF a ``DBG_VALUE`` 5696 instruction binding a ``DIExpression(DW_OP_LLVM_entry_value`` to a 5697 register is lowered to a ``DW_OP_entry_value [reg]``, pushing the 5698 value the register had upon function entry onto the stack. The next 5699 ``(N - 1)`` operations will be part of the ``DW_OP_entry_value`` 5700 block argument. For example, ``!DIExpression(DW_OP_LLVM_entry_value, 5701 1, DW_OP_plus_uconst, 123, DW_OP_stack_value)`` specifies an 5702 expression where the entry value of the debug value instruction's 5703 value/address operand is pushed to the stack, and is added 5704 with 123. Due to framework limitations ``N`` can currently only 5705 be 1. 5706 5707 The operation is introduced by the ``LiveDebugValues`` pass, which 5708 applies it only to function parameters that are unmodified 5709 throughout the function. Support is limited to simple register 5710 location descriptions, or as indirect locations (e.g., when a struct 5711 is passed-by-value to a callee via a pointer to a temporary copy 5712 made in the caller). The entry value op is also introduced by the 5713 ``AsmPrinter`` pass when a call site parameter value 5714 (``DW_AT_call_site_parameter_value``) is represented as entry value 5715 of the parameter. 5716- ``DW_OP_LLVM_arg, N`` is used in debug intrinsics that refer to more than one 5717 value, such as one that calculates the sum of two registers. This is always 5718 used in combination with an ordered list of values, such that 5719 ``DW_OP_LLVM_arg, N`` refers to the ``N``th element in that list. For 5720 example, ``!DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus, 5721 DW_OP_stack_value)`` used with the list ``(%reg1, %reg2)`` would evaluate to 5722 ``%reg1 - reg2``. This list of values should be provided by the containing 5723 intrinsic/instruction. 5724- ``DW_OP_breg`` (or ``DW_OP_bregx``) represents a content on the provided 5725 signed offset of the specified register. The opcode is only generated by the 5726 ``AsmPrinter`` pass to describe call site parameter value which requires an 5727 expression over two registers. 5728- ``DW_OP_push_object_address`` pushes the address of the object which can then 5729 serve as a descriptor in subsequent calculation. This opcode can be used to 5730 calculate bounds of fortran allocatable array which has array descriptors. 5731- ``DW_OP_over`` duplicates the entry currently second in the stack at the top 5732 of the stack. This opcode can be used to calculate bounds of fortran assumed 5733 rank array which has rank known at run time and current dimension number is 5734 implicitly first element of the stack. 5735- ``DW_OP_LLVM_implicit_pointer`` It specifies the dereferenced value. It can 5736 be used to represent pointer variables which are optimized out but the value 5737 it points to is known. This operator is required as it is different than DWARF 5738 operator DW_OP_implicit_pointer in representation and specification (number 5739 and types of operands) and later can not be used as multiple level. 5740 5741.. code-block:: text 5742 5743 IR for "*ptr = 4;" 5744 -------------- 5745 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !20) 5746 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5, 5747 type: !18) 5748 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64) 5749 !19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 5750 !20 = !DIExpression(DW_OP_LLVM_implicit_pointer)) 5751 5752 IR for "**ptr = 4;" 5753 -------------- 5754 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !21) 5755 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5, 5756 type: !18) 5757 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64) 5758 !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64) 5759 !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 5760 !21 = !DIExpression(DW_OP_LLVM_implicit_pointer, 5761 DW_OP_LLVM_implicit_pointer)) 5762 5763DWARF specifies three kinds of simple location descriptions: Register, memory, 5764and implicit location descriptions. Note that a location description is 5765defined over certain ranges of a program, i.e the location of a variable may 5766change over the course of the program. Register and memory location 5767descriptions describe the *concrete location* of a source variable (in the 5768sense that a debugger might modify its value), whereas *implicit locations* 5769describe merely the actual *value* of a source variable which might not exist 5770in registers or in memory (see ``DW_OP_stack_value``). 5771 5772A ``llvm.dbg.addr`` or ``llvm.dbg.declare`` intrinsic describes an indirect 5773value (the address) of a source variable. The first operand of the intrinsic 5774must be an address of some kind. A DIExpression attached to the intrinsic 5775refines this address to produce a concrete location for the source variable. 5776 5777A ``llvm.dbg.value`` intrinsic describes the direct value of a source variable. 5778The first operand of the intrinsic may be a direct or indirect value. A 5779DIExpression attached to the intrinsic refines the first operand to produce a 5780direct value. For example, if the first operand is an indirect value, it may be 5781necessary to insert ``DW_OP_deref`` into the DIExpression in order to produce a 5782valid debug intrinsic. 5783 5784.. note:: 5785 5786 A DIExpression is interpreted in the same way regardless of which kind of 5787 debug intrinsic it's attached to. 5788 5789.. code-block:: text 5790 5791 !0 = !DIExpression(DW_OP_deref) 5792 !1 = !DIExpression(DW_OP_plus_uconst, 3) 5793 !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus) 5794 !2 = !DIExpression(DW_OP_bit_piece, 3, 7) 5795 !3 = !DIExpression(DW_OP_deref, DW_OP_constu, 3, DW_OP_plus, DW_OP_LLVM_fragment, 3, 7) 5796 !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef) 5797 !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value) 5798 5799DIArgList 5800"""""""""""" 5801 5802``DIArgList`` nodes hold a list of constant or SSA value references. These are 5803used in :ref:`debug intrinsics<dbg_intrinsics>` (currently only in 5804``llvm.dbg.value``) in combination with a ``DIExpression`` that uses the 5805``DW_OP_LLVM_arg`` operator. Because a DIArgList may refer to local values 5806within a function, it must only be used as a function argument, must always be 5807inlined, and cannot appear in named metadata. 5808 5809.. code-block:: text 5810 5811 llvm.dbg.value(metadata !DIArgList(i32 %a, i32 %b), 5812 metadata !16, 5813 metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus)) 5814 5815DIFlags 5816""""""""""""""" 5817 5818These flags encode various properties of DINodes. 5819 5820The `ExportSymbols` flag marks a class, struct or union whose members 5821may be referenced as if they were defined in the containing class or 5822union. This flag is used to decide whether the DW_AT_export_symbols can 5823be used for the structure type. 5824 5825DIObjCProperty 5826"""""""""""""" 5827 5828``DIObjCProperty`` nodes represent Objective-C property nodes. 5829 5830.. code-block:: text 5831 5832 !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo", 5833 getter: "getFoo", attributes: 7, type: !2) 5834 5835DIImportedEntity 5836"""""""""""""""" 5837 5838``DIImportedEntity`` nodes represent entities (such as modules) imported into a 5839compile unit. The ``elements`` field is a list of renamed entities (such as 5840variables and subprograms) in the imported entity (such as module). 5841 5842.. code-block:: text 5843 5844 !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0, 5845 entity: !1, line: 7, elements: !3) 5846 !3 = !{!4} 5847 !4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "bar", scope: !0, 5848 entity: !5, line: 7) 5849 5850DIMacro 5851""""""" 5852 5853``DIMacro`` nodes represent definition or undefinition of a macro identifiers. 5854The ``name:`` field is the macro identifier, followed by macro parameters when 5855defining a function-like macro, and the ``value`` field is the token-string 5856used to expand the macro identifier. 5857 5858.. code-block:: text 5859 5860 !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)", 5861 value: "((x) + 1)") 5862 !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo") 5863 5864DIMacroFile 5865""""""""""" 5866 5867``DIMacroFile`` nodes represent inclusion of source files. 5868The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that 5869appear in the included source file. 5870 5871.. code-block:: text 5872 5873 !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2, 5874 nodes: !3) 5875 5876.. _DILabel: 5877 5878DILabel 5879""""""" 5880 5881``DILabel`` nodes represent labels within a :ref:`DISubprogram`. All fields of 5882a ``DILabel`` are mandatory. The ``scope:`` field must be one of either a 5883:ref:`DILexicalBlockFile`, a :ref:`DILexicalBlock`, or a :ref:`DISubprogram`. 5884The ``name:`` field is the label identifier. The ``file:`` field is the 5885:ref:`DIFile` the label is present in. The ``line:`` field is the source line 5886within the file where the label is declared. 5887 5888.. code-block:: text 5889 5890 !2 = !DILabel(scope: !0, name: "foo", file: !1, line: 7) 5891 5892'``tbaa``' Metadata 5893^^^^^^^^^^^^^^^^^^^ 5894 5895In LLVM IR, memory does not have types, so LLVM's own type system is not 5896suitable for doing type based alias analysis (TBAA). Instead, metadata is 5897added to the IR to describe a type system of a higher level language. This 5898can be used to implement C/C++ strict type aliasing rules, but it can also 5899be used to implement custom alias analysis behavior for other languages. 5900 5901This description of LLVM's TBAA system is broken into two parts: 5902:ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and 5903:ref:`Representation<tbaa_node_representation>` talks about the metadata 5904encoding of various entities. 5905 5906It is always possible to trace any TBAA node to a "root" TBAA node (details 5907in the :ref:`Representation<tbaa_node_representation>` section). TBAA 5908nodes with different roots have an unknown aliasing relationship, and LLVM 5909conservatively infers ``MayAlias`` between them. The rules mentioned in 5910this section only pertain to TBAA nodes living under the same root. 5911 5912.. _tbaa_node_semantics: 5913 5914Semantics 5915""""""""" 5916 5917The TBAA metadata system, referred to as "struct path TBAA" (not to be 5918confused with ``tbaa.struct``), consists of the following high level 5919concepts: *Type Descriptors*, further subdivided into scalar type 5920descriptors and struct type descriptors; and *Access Tags*. 5921 5922**Type descriptors** describe the type system of the higher level language 5923being compiled. **Scalar type descriptors** describe types that do not 5924contain other types. Each scalar type has a parent type, which must also 5925be a scalar type or the TBAA root. Via this parent relation, scalar types 5926within a TBAA root form a tree. **Struct type descriptors** denote types 5927that contain a sequence of other type descriptors, at known offsets. These 5928contained type descriptors can either be struct type descriptors themselves 5929or scalar type descriptors. 5930 5931**Access tags** are metadata nodes attached to load and store instructions. 5932Access tags use type descriptors to describe the *location* being accessed 5933in terms of the type system of the higher level language. Access tags are 5934tuples consisting of a base type, an access type and an offset. The base 5935type is a scalar type descriptor or a struct type descriptor, the access 5936type is a scalar type descriptor, and the offset is a constant integer. 5937 5938The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two 5939things: 5940 5941 * If ``BaseTy`` is a struct type, the tag describes a memory access (load 5942 or store) of a value of type ``AccessTy`` contained in the struct type 5943 ``BaseTy`` at offset ``Offset``. 5944 5945 * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and 5946 ``AccessTy`` must be the same; and the access tag describes a scalar 5947 access with scalar type ``AccessTy``. 5948 5949We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)`` 5950tuples this way: 5951 5952 * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is 5953 ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as 5954 described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is 5955 undefined if ``Offset`` is non-zero. 5956 5957 * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)`` 5958 is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in 5959 ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted 5960 to be relative within that inner type. 5961 5962A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)`` 5963aliases a memory access with an access tag ``(BaseTy2, AccessTy2, 5964Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2, 5965Offset2)`` via the ``Parent`` relation or vice versa. 5966 5967As a concrete example, the type descriptor graph for the following program 5968 5969.. code-block:: c 5970 5971 struct Inner { 5972 int i; // offset 0 5973 float f; // offset 4 5974 }; 5975 5976 struct Outer { 5977 float f; // offset 0 5978 double d; // offset 4 5979 struct Inner inner_a; // offset 12 5980 }; 5981 5982 void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) { 5983 outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0) 5984 outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12) 5985 outer->inner_a.f = 0.0; // tag2: (OuterStructTy, FloatScalarTy, 16) 5986 *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0) 5987 } 5988 5989is (note that in C and C++, ``char`` can be used to access any arbitrary 5990type): 5991 5992.. code-block:: text 5993 5994 Root = "TBAA Root" 5995 CharScalarTy = ("char", Root, 0) 5996 FloatScalarTy = ("float", CharScalarTy, 0) 5997 DoubleScalarTy = ("double", CharScalarTy, 0) 5998 IntScalarTy = ("int", CharScalarTy, 0) 5999 InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)} 6000 OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4), 6001 (InnerStructTy, 12)} 6002 6003 6004with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy, 60050)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and 6006``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``. 6007 6008.. _tbaa_node_representation: 6009 6010Representation 6011"""""""""""""" 6012 6013The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or 6014with exactly one ``MDString`` operand. 6015 6016Scalar type descriptors are represented as an ``MDNode`` s with two 6017operands. The first operand is an ``MDString`` denoting the name of the 6018struct type. LLVM does not assign meaning to the value of this operand, it 6019only cares about it being an ``MDString``. The second operand is an 6020``MDNode`` which points to the parent for said scalar type descriptor, 6021which is either another scalar type descriptor or the TBAA root. Scalar 6022type descriptors can have an optional third argument, but that must be the 6023constant integer zero. 6024 6025Struct type descriptors are represented as ``MDNode`` s with an odd number 6026of operands greater than 1. The first operand is an ``MDString`` denoting 6027the name of the struct type. Like in scalar type descriptors the actual 6028value of this name operand is irrelevant to LLVM. After the name operand, 6029the struct type descriptors have a sequence of alternating ``MDNode`` and 6030``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand, 6031an ``MDNode``, denotes a contained field, and the 2N th operand, a 6032``ConstantInt``, is the offset of the said contained field. The offsets 6033must be in non-decreasing order. 6034 6035Access tags are represented as ``MDNode`` s with either 3 or 4 operands. 6036The first operand is an ``MDNode`` pointing to the node representing the 6037base type. The second operand is an ``MDNode`` pointing to the node 6038representing the access type. The third operand is a ``ConstantInt`` that 6039states the offset of the access. If a fourth field is present, it must be 6040a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states 6041that the location being accessed is "constant" (meaning 6042``pointsToConstantMemory`` should return true; see `other useful 6043AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of 6044the access type and the base type of an access tag must be the same, and 6045that is the TBAA root of the access tag. 6046 6047'``tbaa.struct``' Metadata 6048^^^^^^^^^^^^^^^^^^^^^^^^^^ 6049 6050The :ref:`llvm.memcpy <int_memcpy>` is often used to implement 6051aggregate assignment operations in C and similar languages, however it 6052is defined to copy a contiguous region of memory, which is more than 6053strictly necessary for aggregate types which contain holes due to 6054padding. Also, it doesn't contain any TBAA information about the fields 6055of the aggregate. 6056 6057``!tbaa.struct`` metadata can describe which memory subregions in a 6058memcpy are padding and what the TBAA tags of the struct are. 6059 6060The current metadata format is very simple. ``!tbaa.struct`` metadata 6061nodes are a list of operands which are in conceptual groups of three. 6062For each group of three, the first operand gives the byte offset of a 6063field in bytes, the second gives its size in bytes, and the third gives 6064its tbaa tag. e.g.: 6065 6066.. code-block:: llvm 6067 6068 !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 } 6069 6070This describes a struct with two fields. The first is at offset 0 bytes 6071with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes 6072and has size 4 bytes and has tbaa tag !2. 6073 6074Note that the fields need not be contiguous. In this example, there is a 60754 byte gap between the two fields. This gap represents padding which 6076does not carry useful data and need not be preserved. 6077 6078'``noalias``' and '``alias.scope``' Metadata 6079^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6080 6081``noalias`` and ``alias.scope`` metadata provide the ability to specify generic 6082noalias memory-access sets. This means that some collection of memory access 6083instructions (loads, stores, memory-accessing calls, etc.) that carry 6084``noalias`` metadata can specifically be specified not to alias with some other 6085collection of memory access instructions that carry ``alias.scope`` metadata. 6086Each type of metadata specifies a list of scopes where each scope has an id and 6087a domain. 6088 6089When evaluating an aliasing query, if for some domain, the set 6090of scopes with that domain in one instruction's ``alias.scope`` list is a 6091subset of (or equal to) the set of scopes for that domain in another 6092instruction's ``noalias`` list, then the two memory accesses are assumed not to 6093alias. 6094 6095Because scopes in one domain don't affect scopes in other domains, separate 6096domains can be used to compose multiple independent noalias sets. This is 6097used for example during inlining. As the noalias function parameters are 6098turned into noalias scope metadata, a new domain is used every time the 6099function is inlined. 6100 6101The metadata identifying each domain is itself a list containing one or two 6102entries. The first entry is the name of the domain. Note that if the name is a 6103string then it can be combined across functions and translation units. A 6104self-reference can be used to create globally unique domain names. A 6105descriptive string may optionally be provided as a second list entry. 6106 6107The metadata identifying each scope is also itself a list containing two or 6108three entries. The first entry is the name of the scope. Note that if the name 6109is a string then it can be combined across functions and translation units. A 6110self-reference can be used to create globally unique scope names. A metadata 6111reference to the scope's domain is the second entry. A descriptive string may 6112optionally be provided as a third list entry. 6113 6114For example, 6115 6116.. code-block:: llvm 6117 6118 ; Two scope domains: 6119 !0 = !{!0} 6120 !1 = !{!1} 6121 6122 ; Some scopes in these domains: 6123 !2 = !{!2, !0} 6124 !3 = !{!3, !0} 6125 !4 = !{!4, !1} 6126 6127 ; Some scope lists: 6128 !5 = !{!4} ; A list containing only scope !4 6129 !6 = !{!4, !3, !2} 6130 !7 = !{!3} 6131 6132 ; These two instructions don't alias: 6133 %0 = load float, float* %c, align 4, !alias.scope !5 6134 store float %0, float* %arrayidx.i, align 4, !noalias !5 6135 6136 ; These two instructions also don't alias (for domain !1, the set of scopes 6137 ; in the !alias.scope equals that in the !noalias list): 6138 %2 = load float, float* %c, align 4, !alias.scope !5 6139 store float %2, float* %arrayidx.i2, align 4, !noalias !6 6140 6141 ; These two instructions may alias (for domain !0, the set of scopes in 6142 ; the !noalias list is not a superset of, or equal to, the scopes in the 6143 ; !alias.scope list): 6144 %2 = load float, float* %c, align 4, !alias.scope !6 6145 store float %0, float* %arrayidx.i, align 4, !noalias !7 6146 6147'``fpmath``' Metadata 6148^^^^^^^^^^^^^^^^^^^^^ 6149 6150``fpmath`` metadata may be attached to any instruction of floating-point 6151type. It can be used to express the maximum acceptable error in the 6152result of that instruction, in ULPs, thus potentially allowing the 6153compiler to use a more efficient but less accurate method of computing 6154it. ULP is defined as follows: 6155 6156 If ``x`` is a real number that lies between two finite consecutive 6157 floating-point numbers ``a`` and ``b``, without being equal to one 6158 of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the 6159 distance between the two non-equal finite floating-point numbers 6160 nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``. 6161 6162The metadata node shall consist of a single positive float type number 6163representing the maximum relative error, for example: 6164 6165.. code-block:: llvm 6166 6167 !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs 6168 6169.. _range-metadata: 6170 6171'``range``' Metadata 6172^^^^^^^^^^^^^^^^^^^^ 6173 6174``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of 6175integer types. It expresses the possible ranges the loaded value or the value 6176returned by the called function at this call site is in. If the loaded or 6177returned value is not in the specified range, the behavior is undefined. The 6178ranges are represented with a flattened list of integers. The loaded value or 6179the value returned is known to be in the union of the ranges defined by each 6180consecutive pair. Each pair has the following properties: 6181 6182- The type must match the type loaded by the instruction. 6183- The pair ``a,b`` represents the range ``[a,b)``. 6184- Both ``a`` and ``b`` are constants. 6185- The range is allowed to wrap. 6186- The range should not represent the full or empty set. That is, 6187 ``a!=b``. 6188 6189In addition, the pairs must be in signed order of the lower bound and 6190they must be non-contiguous. 6191 6192Examples: 6193 6194.. code-block:: llvm 6195 6196 %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1 6197 %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1 6198 %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5 6199 %d = invoke i8 @bar() to label %cont 6200 unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5 6201 ... 6202 !0 = !{ i8 0, i8 2 } 6203 !1 = !{ i8 255, i8 2 } 6204 !2 = !{ i8 0, i8 2, i8 3, i8 6 } 6205 !3 = !{ i8 -2, i8 0, i8 3, i8 6 } 6206 6207'``absolute_symbol``' Metadata 6208^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6209 6210``absolute_symbol`` metadata may be attached to a global variable 6211declaration. It marks the declaration as a reference to an absolute symbol, 6212which causes the backend to use absolute relocations for the symbol even 6213in position independent code, and expresses the possible ranges that the 6214global variable's *address* (not its value) is in, in the same format as 6215``range`` metadata, with the extension that the pair ``all-ones,all-ones`` 6216may be used to represent the full set. 6217 6218Example (assuming 64-bit pointers): 6219 6220.. code-block:: llvm 6221 6222 @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256) 6223 @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64) 6224 6225 ... 6226 !0 = !{ i64 0, i64 256 } 6227 !1 = !{ i64 -1, i64 -1 } 6228 6229'``callees``' Metadata 6230^^^^^^^^^^^^^^^^^^^^^^ 6231 6232``callees`` metadata may be attached to indirect call sites. If ``callees`` 6233metadata is attached to a call site, and any callee is not among the set of 6234functions provided by the metadata, the behavior is undefined. The intent of 6235this metadata is to facilitate optimizations such as indirect-call promotion. 6236For example, in the code below, the call instruction may only target the 6237``add`` or ``sub`` functions: 6238 6239.. code-block:: llvm 6240 6241 %result = call i64 %binop(i64 %x, i64 %y), !callees !0 6242 6243 ... 6244 !0 = !{i64 (i64, i64)* @add, i64 (i64, i64)* @sub} 6245 6246'``callback``' Metadata 6247^^^^^^^^^^^^^^^^^^^^^^^ 6248 6249``callback`` metadata may be attached to a function declaration, or definition. 6250(Call sites are excluded only due to the lack of a use case.) For ease of 6251exposition, we'll refer to the function annotated w/ metadata as a broker 6252function. The metadata describes how the arguments of a call to the broker are 6253in turn passed to the callback function specified by the metadata. Thus, the 6254``callback`` metadata provides a partial description of a call site inside the 6255broker function with regards to the arguments of a call to the broker. The only 6256semantic restriction on the broker function itself is that it is not allowed to 6257inspect or modify arguments referenced in the ``callback`` metadata as 6258pass-through to the callback function. 6259 6260The broker is not required to actually invoke the callback function at runtime. 6261However, the assumptions about not inspecting or modifying arguments that would 6262be passed to the specified callback function still hold, even if the callback 6263function is not dynamically invoked. The broker is allowed to invoke the 6264callback function more than once per invocation of the broker. The broker is 6265also allowed to invoke (directly or indirectly) the function passed as a 6266callback through another use. Finally, the broker is also allowed to relay the 6267callback callee invocation to a different thread. 6268 6269The metadata is structured as follows: At the outer level, ``callback`` 6270metadata is a list of ``callback`` encodings. Each encoding starts with a 6271constant ``i64`` which describes the argument position of the callback function 6272in the call to the broker. The following elements, except the last, describe 6273what arguments are passed to the callback function. Each element is again an 6274``i64`` constant identifying the argument of the broker that is passed through, 6275or ``i64 -1`` to indicate an unknown or inspected argument. The order in which 6276they are listed has to be the same in which they are passed to the callback 6277callee. The last element of the encoding is a boolean which specifies how 6278variadic arguments of the broker are handled. If it is true, all variadic 6279arguments of the broker are passed through to the callback function *after* the 6280arguments encoded explicitly before. 6281 6282In the code below, the ``pthread_create`` function is marked as a broker 6283through the ``!callback !1`` metadata. In the example, there is only one 6284callback encoding, namely ``!2``, associated with the broker. This encoding 6285identifies the callback function as the second argument of the broker (``i64 62862``) and the sole argument of the callback function as the third one of the 6287broker function (``i64 3``). 6288 6289.. FIXME why does the llvm-sphinx-docs builder give a highlighting 6290 error if the below is set to highlight as 'llvm', despite that we 6291 have misc.highlighting_failure set? 6292 6293.. code-block:: text 6294 6295 declare !callback !1 dso_local i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*) 6296 6297 ... 6298 !2 = !{i64 2, i64 3, i1 false} 6299 !1 = !{!2} 6300 6301Another example is shown below. The callback callee is the second argument of 6302the ``__kmpc_fork_call`` function (``i64 2``). The callee is given two unknown 6303values (each identified by a ``i64 -1``) and afterwards all 6304variadic arguments that are passed to the ``__kmpc_fork_call`` call (due to the 6305final ``i1 true``). 6306 6307.. FIXME why does the llvm-sphinx-docs builder give a highlighting 6308 error if the below is set to highlight as 'llvm', despite that we 6309 have misc.highlighting_failure set? 6310 6311.. code-block:: text 6312 6313 declare !callback !0 dso_local void @__kmpc_fork_call(%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) 6314 6315 ... 6316 !1 = !{i64 2, i64 -1, i64 -1, i1 true} 6317 !0 = !{!1} 6318 6319 6320'``unpredictable``' Metadata 6321^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6322 6323``unpredictable`` metadata may be attached to any branch or switch 6324instruction. It can be used to express the unpredictability of control 6325flow. Similar to the llvm.expect intrinsic, it may be used to alter 6326optimizations related to compare and branch instructions. The metadata 6327is treated as a boolean value; if it exists, it signals that the branch 6328or switch that it is attached to is completely unpredictable. 6329 6330.. _md_dereferenceable: 6331 6332'``dereferenceable``' Metadata 6333^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6334 6335The existence of the ``!dereferenceable`` metadata on the instruction 6336tells the optimizer that the value loaded is known to be dereferenceable. 6337The number of bytes known to be dereferenceable is specified by the integer 6338value in the metadata node. This is analogous to the ''dereferenceable'' 6339attribute on parameters and return values. 6340 6341.. _md_dereferenceable_or_null: 6342 6343'``dereferenceable_or_null``' Metadata 6344^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6345 6346The existence of the ``!dereferenceable_or_null`` metadata on the 6347instruction tells the optimizer that the value loaded is known to be either 6348dereferenceable or null. 6349The number of bytes known to be dereferenceable is specified by the integer 6350value in the metadata node. This is analogous to the ''dereferenceable_or_null'' 6351attribute on parameters and return values. 6352 6353.. _llvm.loop: 6354 6355'``llvm.loop``' 6356^^^^^^^^^^^^^^^ 6357 6358It is sometimes useful to attach information to loop constructs. Currently, 6359loop metadata is implemented as metadata attached to the branch instruction 6360in the loop latch block. The loop metadata node is a list of 6361other metadata nodes, each representing a property of the loop. Usually, 6362the first item of the property node is a string. For example, the 6363``llvm.loop.unroll.count`` suggests an unroll factor to the loop 6364unroller: 6365 6366.. code-block:: llvm 6367 6368 br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0 6369 ... 6370 !0 = !{!0, !1, !2} 6371 !1 = !{!"llvm.loop.unroll.enable"} 6372 !2 = !{!"llvm.loop.unroll.count", i32 4} 6373 6374For legacy reasons, the first item of a loop metadata node must be a 6375reference to itself. Before the advent of the 'distinct' keyword, this 6376forced the preservation of otherwise identical metadata nodes. Since 6377the loop-metadata node can be attached to multiple nodes, the 'distinct' 6378keyword has become unnecessary. 6379 6380Prior to the property nodes, one or two ``DILocation`` (debug location) 6381nodes can be present in the list. The first, if present, identifies the 6382source-code location where the loop begins. The second, if present, 6383identifies the source-code location where the loop ends. 6384 6385Loop metadata nodes cannot be used as unique identifiers. They are 6386neither persistent for the same loop through transformations nor 6387necessarily unique to just one loop. 6388 6389'``llvm.loop.disable_nonforced``' 6390^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6391 6392This metadata disables all optional loop transformations unless 6393explicitly instructed using other transformation metadata such as 6394``llvm.loop.unroll.enable``. That is, no heuristic will try to determine 6395whether a transformation is profitable. The purpose is to avoid that the 6396loop is transformed to a different loop before an explicitly requested 6397(forced) transformation is applied. For instance, loop fusion can make 6398other transformations impossible. Mandatory loop canonicalizations such 6399as loop rotation are still applied. 6400 6401It is recommended to use this metadata in addition to any llvm.loop.* 6402transformation directive. Also, any loop should have at most one 6403directive applied to it (and a sequence of transformations built using 6404followup-attributes). Otherwise, which transformation will be applied 6405depends on implementation details such as the pass pipeline order. 6406 6407See :ref:`transformation-metadata` for details. 6408 6409'``llvm.loop.vectorize``' and '``llvm.loop.interleave``' 6410^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6411 6412Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are 6413used to control per-loop vectorization and interleaving parameters such as 6414vectorization width and interleave count. These metadata should be used in 6415conjunction with ``llvm.loop`` loop identification metadata. The 6416``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only 6417optimization hints and the optimizer will only interleave and vectorize loops if 6418it believes it is safe to do so. The ``llvm.loop.parallel_accesses`` metadata 6419which contains information about loop-carried memory dependencies can be helpful 6420in determining the safety of these transformations. 6421 6422'``llvm.loop.interleave.count``' Metadata 6423^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6424 6425This metadata suggests an interleave count to the loop interleaver. 6426The first operand is the string ``llvm.loop.interleave.count`` and the 6427second operand is an integer specifying the interleave count. For 6428example: 6429 6430.. code-block:: llvm 6431 6432 !0 = !{!"llvm.loop.interleave.count", i32 4} 6433 6434Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving 6435multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0 6436then the interleave count will be determined automatically. 6437 6438'``llvm.loop.vectorize.enable``' Metadata 6439^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6440 6441This metadata selectively enables or disables vectorization for the loop. The 6442first operand is the string ``llvm.loop.vectorize.enable`` and the second operand 6443is a bit. If the bit operand value is 1 vectorization is enabled. A value of 64440 disables vectorization: 6445 6446.. code-block:: llvm 6447 6448 !0 = !{!"llvm.loop.vectorize.enable", i1 0} 6449 !1 = !{!"llvm.loop.vectorize.enable", i1 1} 6450 6451'``llvm.loop.vectorize.predicate.enable``' Metadata 6452^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6453 6454This metadata selectively enables or disables creating predicated instructions 6455for the loop, which can enable folding of the scalar epilogue loop into the 6456main loop. The first operand is the string 6457``llvm.loop.vectorize.predicate.enable`` and the second operand is a bit. If 6458the bit operand value is 1 vectorization is enabled. A value of 0 disables 6459vectorization: 6460 6461.. code-block:: llvm 6462 6463 !0 = !{!"llvm.loop.vectorize.predicate.enable", i1 0} 6464 !1 = !{!"llvm.loop.vectorize.predicate.enable", i1 1} 6465 6466'``llvm.loop.vectorize.scalable.enable``' Metadata 6467^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6468 6469This metadata selectively enables or disables scalable vectorization for the 6470loop, and only has any effect if vectorization for the loop is already enabled. 6471The first operand is the string ``llvm.loop.vectorize.scalable.enable`` 6472and the second operand is a bit. If the bit operand value is 1 scalable 6473vectorization is enabled, whereas a value of 0 reverts to the default fixed 6474width vectorization: 6475 6476.. code-block:: llvm 6477 6478 !0 = !{!"llvm.loop.vectorize.scalable.enable", i1 0} 6479 !1 = !{!"llvm.loop.vectorize.scalable.enable", i1 1} 6480 6481'``llvm.loop.vectorize.width``' Metadata 6482^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6483 6484This metadata sets the target width of the vectorizer. The first 6485operand is the string ``llvm.loop.vectorize.width`` and the second 6486operand is an integer specifying the width. For example: 6487 6488.. code-block:: llvm 6489 6490 !0 = !{!"llvm.loop.vectorize.width", i32 4} 6491 6492Note that setting ``llvm.loop.vectorize.width`` to 1 disables 6493vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to 64940 or if the loop does not have this metadata the width will be 6495determined automatically. 6496 6497'``llvm.loop.vectorize.followup_vectorized``' Metadata 6498^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6499 6500This metadata defines which loop attributes the vectorized loop will 6501have. See :ref:`transformation-metadata` for details. 6502 6503'``llvm.loop.vectorize.followup_epilogue``' Metadata 6504^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6505 6506This metadata defines which loop attributes the epilogue will have. The 6507epilogue is not vectorized and is executed when either the vectorized 6508loop is not known to preserve semantics (because e.g., it processes two 6509arrays that are found to alias by a runtime check) or for the last 6510iterations that do not fill a complete set of vector lanes. See 6511:ref:`Transformation Metadata <transformation-metadata>` for details. 6512 6513'``llvm.loop.vectorize.followup_all``' Metadata 6514^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6515 6516Attributes in the metadata will be added to both the vectorized and 6517epilogue loop. 6518See :ref:`Transformation Metadata <transformation-metadata>` for details. 6519 6520'``llvm.loop.unroll``' 6521^^^^^^^^^^^^^^^^^^^^^^ 6522 6523Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling 6524optimization hints such as the unroll factor. ``llvm.loop.unroll`` 6525metadata should be used in conjunction with ``llvm.loop`` loop 6526identification metadata. The ``llvm.loop.unroll`` metadata are only 6527optimization hints and the unrolling will only be performed if the 6528optimizer believes it is safe to do so. 6529 6530'``llvm.loop.unroll.count``' Metadata 6531^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6532 6533This metadata suggests an unroll factor to the loop unroller. The 6534first operand is the string ``llvm.loop.unroll.count`` and the second 6535operand is a positive integer specifying the unroll factor. For 6536example: 6537 6538.. code-block:: llvm 6539 6540 !0 = !{!"llvm.loop.unroll.count", i32 4} 6541 6542If the trip count of the loop is less than the unroll count the loop 6543will be partially unrolled. 6544 6545'``llvm.loop.unroll.disable``' Metadata 6546^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6547 6548This metadata disables loop unrolling. The metadata has a single operand 6549which is the string ``llvm.loop.unroll.disable``. For example: 6550 6551.. code-block:: llvm 6552 6553 !0 = !{!"llvm.loop.unroll.disable"} 6554 6555'``llvm.loop.unroll.runtime.disable``' Metadata 6556^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6557 6558This metadata disables runtime loop unrolling. The metadata has a single 6559operand which is the string ``llvm.loop.unroll.runtime.disable``. For example: 6560 6561.. code-block:: llvm 6562 6563 !0 = !{!"llvm.loop.unroll.runtime.disable"} 6564 6565'``llvm.loop.unroll.enable``' Metadata 6566^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6567 6568This metadata suggests that the loop should be fully unrolled if the trip count 6569is known at compile time and partially unrolled if the trip count is not known 6570at compile time. The metadata has a single operand which is the string 6571``llvm.loop.unroll.enable``. For example: 6572 6573.. code-block:: llvm 6574 6575 !0 = !{!"llvm.loop.unroll.enable"} 6576 6577'``llvm.loop.unroll.full``' Metadata 6578^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6579 6580This metadata suggests that the loop should be unrolled fully. The 6581metadata has a single operand which is the string ``llvm.loop.unroll.full``. 6582For example: 6583 6584.. code-block:: llvm 6585 6586 !0 = !{!"llvm.loop.unroll.full"} 6587 6588'``llvm.loop.unroll.followup``' Metadata 6589^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6590 6591This metadata defines which loop attributes the unrolled loop will have. 6592See :ref:`Transformation Metadata <transformation-metadata>` for details. 6593 6594'``llvm.loop.unroll.followup_remainder``' Metadata 6595^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6596 6597This metadata defines which loop attributes the remainder loop after 6598partial/runtime unrolling will have. See 6599:ref:`Transformation Metadata <transformation-metadata>` for details. 6600 6601'``llvm.loop.unroll_and_jam``' 6602^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6603 6604This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata 6605above, but affect the unroll and jam pass. In addition any loop with 6606``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will 6607disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the 6608unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam 6609too.) 6610 6611The metadata for unroll and jam otherwise is the same as for ``unroll``. 6612``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and 6613``llvm.loop.unroll_and_jam.count`` do the same as for unroll. 6614``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints 6615and the normal safety checks will still be performed. 6616 6617'``llvm.loop.unroll_and_jam.count``' Metadata 6618^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6619 6620This metadata suggests an unroll and jam factor to use, similarly to 6621``llvm.loop.unroll.count``. The first operand is the string 6622``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer 6623specifying the unroll factor. For example: 6624 6625.. code-block:: llvm 6626 6627 !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4} 6628 6629If the trip count of the loop is less than the unroll count the loop 6630will be partially unroll and jammed. 6631 6632'``llvm.loop.unroll_and_jam.disable``' Metadata 6633^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6634 6635This metadata disables loop unroll and jamming. The metadata has a single 6636operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example: 6637 6638.. code-block:: llvm 6639 6640 !0 = !{!"llvm.loop.unroll_and_jam.disable"} 6641 6642'``llvm.loop.unroll_and_jam.enable``' Metadata 6643^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6644 6645This metadata suggests that the loop should be fully unroll and jammed if the 6646trip count is known at compile time and partially unrolled if the trip count is 6647not known at compile time. The metadata has a single operand which is the 6648string ``llvm.loop.unroll_and_jam.enable``. For example: 6649 6650.. code-block:: llvm 6651 6652 !0 = !{!"llvm.loop.unroll_and_jam.enable"} 6653 6654'``llvm.loop.unroll_and_jam.followup_outer``' Metadata 6655^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6656 6657This metadata defines which loop attributes the outer unrolled loop will 6658have. See :ref:`Transformation Metadata <transformation-metadata>` for 6659details. 6660 6661'``llvm.loop.unroll_and_jam.followup_inner``' Metadata 6662^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6663 6664This metadata defines which loop attributes the inner jammed loop will 6665have. See :ref:`Transformation Metadata <transformation-metadata>` for 6666details. 6667 6668'``llvm.loop.unroll_and_jam.followup_remainder_outer``' Metadata 6669^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6670 6671This metadata defines which attributes the epilogue of the outer loop 6672will have. This loop is usually unrolled, meaning there is no such 6673loop. This attribute will be ignored in this case. See 6674:ref:`Transformation Metadata <transformation-metadata>` for details. 6675 6676'``llvm.loop.unroll_and_jam.followup_remainder_inner``' Metadata 6677^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6678 6679This metadata defines which attributes the inner loop of the epilogue 6680will have. The outer epilogue will usually be unrolled, meaning there 6681can be multiple inner remainder loops. See 6682:ref:`Transformation Metadata <transformation-metadata>` for details. 6683 6684'``llvm.loop.unroll_and_jam.followup_all``' Metadata 6685^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6686 6687Attributes specified in the metadata is added to all 6688``llvm.loop.unroll_and_jam.*`` loops. See 6689:ref:`Transformation Metadata <transformation-metadata>` for details. 6690 6691'``llvm.loop.licm_versioning.disable``' Metadata 6692^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6693 6694This metadata indicates that the loop should not be versioned for the purpose 6695of enabling loop-invariant code motion (LICM). The metadata has a single operand 6696which is the string ``llvm.loop.licm_versioning.disable``. For example: 6697 6698.. code-block:: llvm 6699 6700 !0 = !{!"llvm.loop.licm_versioning.disable"} 6701 6702'``llvm.loop.distribute.enable``' Metadata 6703^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6704 6705Loop distribution allows splitting a loop into multiple loops. Currently, 6706this is only performed if the entire loop cannot be vectorized due to unsafe 6707memory dependencies. The transformation will attempt to isolate the unsafe 6708dependencies into their own loop. 6709 6710This metadata can be used to selectively enable or disable distribution of the 6711loop. The first operand is the string ``llvm.loop.distribute.enable`` and the 6712second operand is a bit. If the bit operand value is 1 distribution is 6713enabled. A value of 0 disables distribution: 6714 6715.. code-block:: llvm 6716 6717 !0 = !{!"llvm.loop.distribute.enable", i1 0} 6718 !1 = !{!"llvm.loop.distribute.enable", i1 1} 6719 6720This metadata should be used in conjunction with ``llvm.loop`` loop 6721identification metadata. 6722 6723'``llvm.loop.distribute.followup_coincident``' Metadata 6724^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6725 6726This metadata defines which attributes extracted loops with no cyclic 6727dependencies will have (i.e. can be vectorized). See 6728:ref:`Transformation Metadata <transformation-metadata>` for details. 6729 6730'``llvm.loop.distribute.followup_sequential``' Metadata 6731^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6732 6733This metadata defines which attributes the isolated loops with unsafe 6734memory dependencies will have. See 6735:ref:`Transformation Metadata <transformation-metadata>` for details. 6736 6737'``llvm.loop.distribute.followup_fallback``' Metadata 6738^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6739 6740If loop versioning is necessary, this metadata defined the attributes 6741the non-distributed fallback version will have. See 6742:ref:`Transformation Metadata <transformation-metadata>` for details. 6743 6744'``llvm.loop.distribute.followup_all``' Metadata 6745^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6746 6747The attributes in this metadata is added to all followup loops of the 6748loop distribution pass. See 6749:ref:`Transformation Metadata <transformation-metadata>` for details. 6750 6751'``llvm.licm.disable``' Metadata 6752^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6753 6754This metadata indicates that loop-invariant code motion (LICM) should not be 6755performed on this loop. The metadata has a single operand which is the string 6756``llvm.licm.disable``. For example: 6757 6758.. code-block:: llvm 6759 6760 !0 = !{!"llvm.licm.disable"} 6761 6762Note that although it operates per loop it isn't given the llvm.loop prefix 6763as it is not affected by the ``llvm.loop.disable_nonforced`` metadata. 6764 6765'``llvm.access.group``' Metadata 6766^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6767 6768``llvm.access.group`` metadata can be attached to any instruction that 6769potentially accesses memory. It can point to a single distinct metadata 6770node, which we call access group. This node represents all memory access 6771instructions referring to it via ``llvm.access.group``. When an 6772instruction belongs to multiple access groups, it can also point to a 6773list of accesses groups, illustrated by the following example. 6774 6775.. code-block:: llvm 6776 6777 %val = load i32, i32* %arrayidx, !llvm.access.group !0 6778 ... 6779 !0 = !{!1, !2} 6780 !1 = distinct !{} 6781 !2 = distinct !{} 6782 6783It is illegal for the list node to be empty since it might be confused 6784with an access group. 6785 6786The access group metadata node must be 'distinct' to avoid collapsing 6787multiple access groups by content. A access group metadata node must 6788always be empty which can be used to distinguish an access group 6789metadata node from a list of access groups. Being empty avoids the 6790situation that the content must be updated which, because metadata is 6791immutable by design, would required finding and updating all references 6792to the access group node. 6793 6794The access group can be used to refer to a memory access instruction 6795without pointing to it directly (which is not possible in global 6796metadata). Currently, the only metadata making use of it is 6797``llvm.loop.parallel_accesses``. 6798 6799'``llvm.loop.parallel_accesses``' Metadata 6800^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6801 6802The ``llvm.loop.parallel_accesses`` metadata refers to one or more 6803access group metadata nodes (see ``llvm.access.group``). It denotes that 6804no loop-carried memory dependence exist between it and other instructions 6805in the loop with this metadata. 6806 6807Let ``m1`` and ``m2`` be two instructions that both have the 6808``llvm.access.group`` metadata to the access group ``g1``, respectively 6809``g2`` (which might be identical). If a loop contains both access groups 6810in its ``llvm.loop.parallel_accesses`` metadata, then the compiler can 6811assume that there is no dependency between ``m1`` and ``m2`` carried by 6812this loop. Instructions that belong to multiple access groups are 6813considered having this property if at least one of the access groups 6814matches the ``llvm.loop.parallel_accesses`` list. 6815 6816If all memory-accessing instructions in a loop have 6817``llvm.access.group`` metadata that each refer to one of the access 6818groups of a loop's ``llvm.loop.parallel_accesses`` metadata, then the 6819loop has no loop carried memory dependences and is considered to be a 6820parallel loop. 6821 6822Note that if not all memory access instructions belong to an access 6823group referred to by ``llvm.loop.parallel_accesses``, then the loop must 6824not be considered trivially parallel. Additional 6825memory dependence analysis is required to make that determination. As a fail 6826safe mechanism, this causes loops that were originally parallel to be considered 6827sequential (if optimization passes that are unaware of the parallel semantics 6828insert new memory instructions into the loop body). 6829 6830Example of a loop that is considered parallel due to its correct use of 6831both ``llvm.access.group`` and ``llvm.loop.parallel_accesses`` 6832metadata types. 6833 6834.. code-block:: llvm 6835 6836 for.body: 6837 ... 6838 %val0 = load i32, i32* %arrayidx, !llvm.access.group !1 6839 ... 6840 store i32 %val0, i32* %arrayidx1, !llvm.access.group !1 6841 ... 6842 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0 6843 6844 for.end: 6845 ... 6846 !0 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !1}} 6847 !1 = distinct !{} 6848 6849It is also possible to have nested parallel loops: 6850 6851.. code-block:: llvm 6852 6853 outer.for.body: 6854 ... 6855 %val1 = load i32, i32* %arrayidx3, !llvm.access.group !4 6856 ... 6857 br label %inner.for.body 6858 6859 inner.for.body: 6860 ... 6861 %val0 = load i32, i32* %arrayidx1, !llvm.access.group !3 6862 ... 6863 store i32 %val0, i32* %arrayidx2, !llvm.access.group !3 6864 ... 6865 br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1 6866 6867 inner.for.end: 6868 ... 6869 store i32 %val1, i32* %arrayidx4, !llvm.access.group !4 6870 ... 6871 br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2 6872 6873 outer.for.end: ; preds = %for.body 6874 ... 6875 !1 = distinct !{!1, !{!"llvm.loop.parallel_accesses", !3}} ; metadata for the inner loop 6876 !2 = distinct !{!2, !{!"llvm.loop.parallel_accesses", !3, !4}} ; metadata for the outer loop 6877 !3 = distinct !{} ; access group for instructions in the inner loop (which are implicitly contained in outer loop as well) 6878 !4 = distinct !{} ; access group for instructions in the outer, but not the inner loop 6879 6880.. _langref_llvm_loop_mustprogress: 6881 6882'``llvm.loop.mustprogress``' Metadata 6883^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6884 6885The ``llvm.loop.mustprogress`` metadata indicates that this loop is required to 6886terminate, unwind, or interact with the environment in an observable way e.g. 6887via a volatile memory access, I/O, or other synchronization. If such a loop is 6888not found to interact with the environment in an observable way, the loop may 6889be removed. This corresponds to the ``mustprogress`` function attribute. 6890 6891'``irr_loop``' Metadata 6892^^^^^^^^^^^^^^^^^^^^^^^ 6893 6894``irr_loop`` metadata may be attached to the terminator instruction of a basic 6895block that's an irreducible loop header (note that an irreducible loop has more 6896than once header basic blocks.) If ``irr_loop`` metadata is attached to the 6897terminator instruction of a basic block that is not really an irreducible loop 6898header, the behavior is undefined. The intent of this metadata is to improve the 6899accuracy of the block frequency propagation. For example, in the code below, the 6900block ``header0`` may have a loop header weight (relative to the other headers of 6901the irreducible loop) of 100: 6902 6903.. code-block:: llvm 6904 6905 header0: 6906 ... 6907 br i1 %cmp, label %t1, label %t2, !irr_loop !0 6908 6909 ... 6910 !0 = !{"loop_header_weight", i64 100} 6911 6912Irreducible loop header weights are typically based on profile data. 6913 6914.. _md_invariant.group: 6915 6916'``invariant.group``' Metadata 6917^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6918 6919The experimental ``invariant.group`` metadata may be attached to 6920``load``/``store`` instructions referencing a single metadata with no entries. 6921The existence of the ``invariant.group`` metadata on the instruction tells 6922the optimizer that every ``load`` and ``store`` to the same pointer operand 6923can be assumed to load or store the same 6924value (but see the ``llvm.launder.invariant.group`` intrinsic which affects 6925when two pointers are considered the same). Pointers returned by bitcast or 6926getelementptr with only zero indices are considered the same. 6927 6928Examples: 6929 6930.. code-block:: llvm 6931 6932 @unknownPtr = external global i8 6933 ... 6934 %ptr = alloca i8 6935 store i8 42, i8* %ptr, !invariant.group !0 6936 call void @foo(i8* %ptr) 6937 6938 %a = load i8, i8* %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change 6939 call void @foo(i8* %ptr) 6940 6941 %newPtr = call i8* @getPointer(i8* %ptr) 6942 %c = load i8, i8* %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr 6943 6944 %unknownValue = load i8, i8* @unknownPtr 6945 store i8 %unknownValue, i8* %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42 6946 6947 call void @foo(i8* %ptr) 6948 %newPtr2 = call i8* @llvm.launder.invariant.group(i8* %ptr) 6949 %d = load i8, i8* %newPtr2, !invariant.group !0 ; Can't step through launder.invariant.group to get value of %ptr 6950 6951 ... 6952 declare void @foo(i8*) 6953 declare i8* @getPointer(i8*) 6954 declare i8* @llvm.launder.invariant.group(i8*) 6955 6956 !0 = !{} 6957 6958The invariant.group metadata must be dropped when replacing one pointer by 6959another based on aliasing information. This is because invariant.group is tied 6960to the SSA value of the pointer operand. 6961 6962.. code-block:: llvm 6963 6964 %v = load i8, i8* %x, !invariant.group !0 6965 ; if %x mustalias %y then we can replace the above instruction with 6966 %v = load i8, i8* %y 6967 6968Note that this is an experimental feature, which means that its semantics might 6969change in the future. 6970 6971'``type``' Metadata 6972^^^^^^^^^^^^^^^^^^^ 6973 6974See :doc:`TypeMetadata`. 6975 6976'``associated``' Metadata 6977^^^^^^^^^^^^^^^^^^^^^^^^^ 6978 6979The ``associated`` metadata may be attached to a global variable definition with 6980a single argument that references a global object (optionally through an alias). 6981 6982This metadata lowers to the ELF section flag ``SHF_LINK_ORDER`` which prevents 6983discarding of the global variable in linker GC unless the referenced object is 6984also discarded. The linker support for this feature is spotty. For best 6985compatibility, globals carrying this metadata should: 6986 6987- Be in ``@llvm.compiler.used``. 6988- If the referenced global variable is in a comdat, be in the same comdat. 6989 6990``!associated`` can not express many-to-one relationship. A global variable with 6991the metadata should generally not be referenced by a function: the function may 6992be inlined into other functions, leading to more references to the metadata. 6993Ideally we would want to keep metadata alive as long as any inline location is 6994alive, but this many-to-one relationship is not representable. Moreover, if the 6995metadata is retained while the function is discarded, the linker will report an 6996error of a relocation referencing a discarded section. 6997 6998The metadata is often used with an explicit section consisting of valid C 6999identifiers so that the runtime can find the metadata section with 7000linker-defined encapsulation symbols ``__start_<section_name>`` and 7001``__stop_<section_name>``. 7002 7003It does not have any effect on non-ELF targets. 7004 7005Example: 7006 7007.. code-block:: text 7008 7009 $a = comdat any 7010 @a = global i32 1, comdat $a 7011 @b = internal global i32 2, comdat $a, section "abc", !associated !0 7012 !0 = !{i32* @a} 7013 7014 7015'``prof``' Metadata 7016^^^^^^^^^^^^^^^^^^^ 7017 7018The ``prof`` metadata is used to record profile data in the IR. 7019The first operand of the metadata node indicates the profile metadata 7020type. There are currently 3 types: 7021:ref:`branch_weights<prof_node_branch_weights>`, 7022:ref:`function_entry_count<prof_node_function_entry_count>`, and 7023:ref:`VP<prof_node_VP>`. 7024 7025.. _prof_node_branch_weights: 7026 7027branch_weights 7028"""""""""""""" 7029 7030Branch weight metadata attached to a branch, select, switch or call instruction 7031represents the likeliness of the associated branch being taken. 7032For more information, see :doc:`BranchWeightMetadata`. 7033 7034.. _prof_node_function_entry_count: 7035 7036function_entry_count 7037"""""""""""""""""""" 7038 7039Function entry count metadata can be attached to function definitions 7040to record the number of times the function is called. Used with BFI 7041information, it is also used to derive the basic block profile count. 7042For more information, see :doc:`BranchWeightMetadata`. 7043 7044.. _prof_node_VP: 7045 7046VP 7047"" 7048 7049VP (value profile) metadata can be attached to instructions that have 7050value profile information. Currently this is indirect calls (where it 7051records the hottest callees) and calls to memory intrinsics such as memcpy, 7052memmove, and memset (where it records the hottest byte lengths). 7053 7054Each VP metadata node contains "VP" string, then a uint32_t value for the value 7055profiling kind, a uint64_t value for the total number of times the instruction 7056is executed, followed by uint64_t value and execution count pairs. 7057The value profiling kind is 0 for indirect call targets and 1 for memory 7058operations. For indirect call targets, each profile value is a hash 7059of the callee function name, and for memory operations each value is the 7060byte length. 7061 7062Note that the value counts do not need to add up to the total count 7063listed in the third operand (in practice only the top hottest values 7064are tracked and reported). 7065 7066Indirect call example: 7067 7068.. code-block:: llvm 7069 7070 call void %f(), !prof !1 7071 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410} 7072 7073Note that the VP type is 0 (the second operand), which indicates this is 7074an indirect call value profile data. The third operand indicates that the 7075indirect call executed 1600 times. The 4th and 6th operands give the 7076hashes of the 2 hottest target functions' names (this is the same hash used 7077to represent function names in the profile database), and the 5th and 7th 7078operands give the execution count that each of the respective prior target 7079functions was called. 7080 7081.. _md_annotation: 7082 7083'``annotation``' Metadata 7084^^^^^^^^^^^^^^^^^^^^^^^^^ 7085 7086The ``annotation`` metadata can be used to attach a tuple of annotation strings 7087to any instruction. This metadata does not impact the semantics of the program 7088and may only be used to provide additional insight about the program and 7089transformations to users. 7090 7091Example: 7092 7093.. code-block:: text 7094 7095 %a.addr = alloca float*, align 8, !annotation !0 7096 !0 = !{!"auto-init"} 7097 7098Module Flags Metadata 7099===================== 7100 7101Information about the module as a whole is difficult to convey to LLVM's 7102subsystems. The LLVM IR isn't sufficient to transmit this information. 7103The ``llvm.module.flags`` named metadata exists in order to facilitate 7104this. These flags are in the form of key / value pairs --- much like a 7105dictionary --- making it easy for any subsystem who cares about a flag to 7106look it up. 7107 7108The ``llvm.module.flags`` metadata contains a list of metadata triplets. 7109Each triplet has the following form: 7110 7111- The first element is a *behavior* flag, which specifies the behavior 7112 when two (or more) modules are merged together, and it encounters two 7113 (or more) metadata with the same ID. The supported behaviors are 7114 described below. 7115- The second element is a metadata string that is a unique ID for the 7116 metadata. Each module may only have one flag entry for each unique ID (not 7117 including entries with the **Require** behavior). 7118- The third element is the value of the flag. 7119 7120When two (or more) modules are merged together, the resulting 7121``llvm.module.flags`` metadata is the union of the modules' flags. That is, for 7122each unique metadata ID string, there will be exactly one entry in the merged 7123modules ``llvm.module.flags`` metadata table, and the value for that entry will 7124be determined by the merge behavior flag, as described below. The only exception 7125is that entries with the *Require* behavior are always preserved. 7126 7127The following behaviors are supported: 7128 7129.. list-table:: 7130 :header-rows: 1 7131 :widths: 10 90 7132 7133 * - Value 7134 - Behavior 7135 7136 * - 1 7137 - **Error** 7138 Emits an error if two values disagree, otherwise the resulting value 7139 is that of the operands. 7140 7141 * - 2 7142 - **Warning** 7143 Emits a warning if two values disagree. The result value will be the 7144 operand for the flag from the first module being linked, or the max 7145 if the other module uses **Max** (in which case the resulting flag 7146 will be **Max**). 7147 7148 * - 3 7149 - **Require** 7150 Adds a requirement that another module flag be present and have a 7151 specified value after linking is performed. The value must be a 7152 metadata pair, where the first element of the pair is the ID of the 7153 module flag to be restricted, and the second element of the pair is 7154 the value the module flag should be restricted to. This behavior can 7155 be used to restrict the allowable results (via triggering of an 7156 error) of linking IDs with the **Override** behavior. 7157 7158 * - 4 7159 - **Override** 7160 Uses the specified value, regardless of the behavior or value of the 7161 other module. If both modules specify **Override**, but the values 7162 differ, an error will be emitted. 7163 7164 * - 5 7165 - **Append** 7166 Appends the two values, which are required to be metadata nodes. 7167 7168 * - 6 7169 - **AppendUnique** 7170 Appends the two values, which are required to be metadata 7171 nodes. However, duplicate entries in the second list are dropped 7172 during the append operation. 7173 7174 * - 7 7175 - **Max** 7176 Takes the max of the two values, which are required to be integers. 7177 7178It is an error for a particular unique flag ID to have multiple behaviors, 7179except in the case of **Require** (which adds restrictions on another metadata 7180value) or **Override**. 7181 7182An example of module flags: 7183 7184.. code-block:: llvm 7185 7186 !0 = !{ i32 1, !"foo", i32 1 } 7187 !1 = !{ i32 4, !"bar", i32 37 } 7188 !2 = !{ i32 2, !"qux", i32 42 } 7189 !3 = !{ i32 3, !"qux", 7190 !{ 7191 !"foo", i32 1 7192 } 7193 } 7194 !llvm.module.flags = !{ !0, !1, !2, !3 } 7195 7196- Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior 7197 if two or more ``!"foo"`` flags are seen is to emit an error if their 7198 values are not equal. 7199 7200- Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The 7201 behavior if two or more ``!"bar"`` flags are seen is to use the value 7202 '37'. 7203 7204- Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The 7205 behavior if two or more ``!"qux"`` flags are seen is to emit a 7206 warning if their values are not equal. 7207 7208- Metadata ``!3`` has the ID ``!"qux"`` and the value: 7209 7210 :: 7211 7212 !{ !"foo", i32 1 } 7213 7214 The behavior is to emit an error if the ``llvm.module.flags`` does not 7215 contain a flag with the ID ``!"foo"`` that has the value '1' after linking is 7216 performed. 7217 7218Synthesized Functions Module Flags Metadata 7219------------------------------------------- 7220 7221These metadata specify the default attributes synthesized functions should have. 7222These metadata are currently respected by a few instrumentation passes, such as 7223sanitizers. 7224 7225These metadata correspond to a few function attributes with significant code 7226generation behaviors. Function attributes with just optimization purposes 7227should not be listed because the performance impact of these synthesized 7228functions is small. 7229 7230- "frame-pointer": **Max**. The value can be 0, 1, or 2. A synthesized function 7231 will get the "frame-pointer" function attribute, with value being "none", 7232 "non-leaf", or "all", respectively. 7233- "uwtable": **Max**. The value can be 0, 1, or 2. If the value is 1, a synthesized 7234 function will get the ``uwtable(sync)`` function attribute, if the value is 2, 7235 a synthesized function will get the ``uwtable(async)`` function attribute. 7236 7237Objective-C Garbage Collection Module Flags Metadata 7238---------------------------------------------------- 7239 7240On the Mach-O platform, Objective-C stores metadata about garbage 7241collection in a special section called "image info". The metadata 7242consists of a version number and a bitmask specifying what types of 7243garbage collection are supported (if any) by the file. If two or more 7244modules are linked together their garbage collection metadata needs to 7245be merged rather than appended together. 7246 7247The Objective-C garbage collection module flags metadata consists of the 7248following key-value pairs: 7249 7250.. list-table:: 7251 :header-rows: 1 7252 :widths: 30 70 7253 7254 * - Key 7255 - Value 7256 7257 * - ``Objective-C Version`` 7258 - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2. 7259 7260 * - ``Objective-C Image Info Version`` 7261 - **[Required]** --- The version of the image info section. Currently 7262 always 0. 7263 7264 * - ``Objective-C Image Info Section`` 7265 - **[Required]** --- The section to place the metadata. Valid values are 7266 ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and 7267 ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for 7268 Objective-C ABI version 2. 7269 7270 * - ``Objective-C Garbage Collection`` 7271 - **[Required]** --- Specifies whether garbage collection is supported or 7272 not. Valid values are 0, for no garbage collection, and 2, for garbage 7273 collection supported. 7274 7275 * - ``Objective-C GC Only`` 7276 - **[Optional]** --- Specifies that only garbage collection is supported. 7277 If present, its value must be 6. This flag requires that the 7278 ``Objective-C Garbage Collection`` flag have the value 2. 7279 7280Some important flag interactions: 7281 7282- If a module with ``Objective-C Garbage Collection`` set to 0 is 7283 merged with a module with ``Objective-C Garbage Collection`` set to 7284 2, then the resulting module has the 7285 ``Objective-C Garbage Collection`` flag set to 0. 7286- A module with ``Objective-C Garbage Collection`` set to 0 cannot be 7287 merged with a module with ``Objective-C GC Only`` set to 6. 7288 7289C type width Module Flags Metadata 7290---------------------------------- 7291 7292The ARM backend emits a section into each generated object file describing the 7293options that it was compiled with (in a compiler-independent way) to prevent 7294linking incompatible objects, and to allow automatic library selection. Some 7295of these options are not visible at the IR level, namely wchar_t width and enum 7296width. 7297 7298To pass this information to the backend, these options are encoded in module 7299flags metadata, using the following key-value pairs: 7300 7301.. list-table:: 7302 :header-rows: 1 7303 :widths: 30 70 7304 7305 * - Key 7306 - Value 7307 7308 * - short_wchar 7309 - * 0 --- sizeof(wchar_t) == 4 7310 * 1 --- sizeof(wchar_t) == 2 7311 7312 * - short_enum 7313 - * 0 --- Enums are at least as large as an ``int``. 7314 * 1 --- Enums are stored in the smallest integer type which can 7315 represent all of its values. 7316 7317For example, the following metadata section specifies that the module was 7318compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an 7319enum is the smallest type which can represent all of its values:: 7320 7321 !llvm.module.flags = !{!0, !1} 7322 !0 = !{i32 1, !"short_wchar", i32 1} 7323 !1 = !{i32 1, !"short_enum", i32 0} 7324 7325LTO Post-Link Module Flags Metadata 7326----------------------------------- 7327 7328Some optimisations are only when the entire LTO unit is present in the current 7329module. This is represented by the ``LTOPostLink`` module flags metadata, which 7330will be created with a value of ``1`` when LTO linking occurs. 7331 7332Automatic Linker Flags Named Metadata 7333===================================== 7334 7335Some targets support embedding of flags to the linker inside individual object 7336files. Typically this is used in conjunction with language extensions which 7337allow source files to contain linker command line options, and have these 7338automatically be transmitted to the linker via object files. 7339 7340These flags are encoded in the IR using named metadata with the name 7341``!llvm.linker.options``. Each operand is expected to be a metadata node 7342which should be a list of other metadata nodes, each of which should be a 7343list of metadata strings defining linker options. 7344 7345For example, the following metadata section specifies two separate sets of 7346linker options, presumably to link against ``libz`` and the ``Cocoa`` 7347framework:: 7348 7349 !0 = !{ !"-lz" } 7350 !1 = !{ !"-framework", !"Cocoa" } 7351 !llvm.linker.options = !{ !0, !1 } 7352 7353The metadata encoding as lists of lists of options, as opposed to a collapsed 7354list of options, is chosen so that the IR encoding can use multiple option 7355strings to specify e.g., a single library, while still having that specifier be 7356preserved as an atomic element that can be recognized by a target specific 7357assembly writer or object file emitter. 7358 7359Each individual option is required to be either a valid option for the target's 7360linker, or an option that is reserved by the target specific assembly writer or 7361object file emitter. No other aspect of these options is defined by the IR. 7362 7363Dependent Libs Named Metadata 7364============================= 7365 7366Some targets support embedding of strings into object files to indicate 7367a set of libraries to add to the link. Typically this is used in conjunction 7368with language extensions which allow source files to explicitly declare the 7369libraries they depend on, and have these automatically be transmitted to the 7370linker via object files. 7371 7372The list is encoded in the IR using named metadata with the name 7373``!llvm.dependent-libraries``. Each operand is expected to be a metadata node 7374which should contain a single string operand. 7375 7376For example, the following metadata section contains two library specifiers:: 7377 7378 !0 = !{!"a library specifier"} 7379 !1 = !{!"another library specifier"} 7380 !llvm.dependent-libraries = !{ !0, !1 } 7381 7382Each library specifier will be handled independently by the consuming linker. 7383The effect of the library specifiers are defined by the consuming linker. 7384 7385.. _summary: 7386 7387ThinLTO Summary 7388=============== 7389 7390Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_ 7391causes the building of a compact summary of the module that is emitted into 7392the bitcode. The summary is emitted into the LLVM assembly and identified 7393in syntax by a caret ('``^``'). 7394 7395The summary is parsed into a bitcode output, along with the Module 7396IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes 7397of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the 7398summary entries (just as they currently ignore summary entries in a bitcode 7399input file). 7400 7401Eventually, the summary will be parsed into a ModuleSummaryIndex object under 7402the same conditions where summary index is currently built from bitcode. 7403Specifically, tools that test the Thin Link portion of a ThinLTO compile 7404(i.e. llvm-lto and llvm-lto2), or when parsing a combined index 7405for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag 7406(this part is not yet implemented, use llvm-as to create a bitcode object 7407before feeding into thin link tools for now). 7408 7409There are currently 3 types of summary entries in the LLVM assembly: 7410:ref:`module paths<module_path_summary>`, 7411:ref:`global values<gv_summary>`, and 7412:ref:`type identifiers<typeid_summary>`. 7413 7414.. _module_path_summary: 7415 7416Module Path Summary Entry 7417------------------------- 7418 7419Each module path summary entry lists a module containing global values included 7420in the summary. For a single IR module there will be one such entry, but 7421in a combined summary index produced during the thin link, there will be 7422one module path entry per linked module with summary. 7423 7424Example: 7425 7426.. code-block:: text 7427 7428 ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418)) 7429 7430The ``path`` field is a string path to the bitcode file, and the ``hash`` 7431field is the 160-bit SHA-1 hash of the IR bitcode contents, used for 7432incremental builds and caching. 7433 7434.. _gv_summary: 7435 7436Global Value Summary Entry 7437-------------------------- 7438 7439Each global value summary entry corresponds to a global value defined or 7440referenced by a summarized module. 7441 7442Example: 7443 7444.. code-block:: text 7445 7446 ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831 7447 7448For declarations, there will not be a summary list. For definitions, a 7449global value will contain a list of summaries, one per module containing 7450a definition. There can be multiple entries in a combined summary index 7451for symbols with weak linkage. 7452 7453Each ``Summary`` format will depend on whether the global value is a 7454:ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or 7455:ref:`alias<alias_summary>`. 7456 7457.. _function_summary: 7458 7459Function Summary 7460^^^^^^^^^^^^^^^^ 7461 7462If the global value is a function, the ``Summary`` entry will look like: 7463 7464.. code-block:: text 7465 7466 function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Params]?[, Refs]? 7467 7468The ``module`` field includes the summary entry id for the module containing 7469this definition, and the ``flags`` field contains information such as 7470the linkage type, a flag indicating whether it is legal to import the 7471definition, whether it is globally live and whether the linker resolved it 7472to a local definition (the latter two are populated during the thin link). 7473The ``insts`` field contains the number of IR instructions in the function. 7474Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`, 7475:ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`, 7476:ref:`Params<params_summary>`, :ref:`Refs<refs_summary>`. 7477 7478.. _variable_summary: 7479 7480Global Variable Summary 7481^^^^^^^^^^^^^^^^^^^^^^^ 7482 7483If the global value is a variable, the ``Summary`` entry will look like: 7484 7485.. code-block:: text 7486 7487 variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]? 7488 7489The variable entry contains a subset of the fields in a 7490:ref:`function summary <function_summary>`, see the descriptions there. 7491 7492.. _alias_summary: 7493 7494Alias Summary 7495^^^^^^^^^^^^^ 7496 7497If the global value is an alias, the ``Summary`` entry will look like: 7498 7499.. code-block:: text 7500 7501 alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2) 7502 7503The ``module`` and ``flags`` fields are as described for a 7504:ref:`function summary <function_summary>`. The ``aliasee`` field 7505contains a reference to the global value summary entry of the aliasee. 7506 7507.. _funcflags_summary: 7508 7509Function Flags 7510^^^^^^^^^^^^^^ 7511 7512The optional ``FuncFlags`` field looks like: 7513 7514.. code-block:: text 7515 7516 funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0, noUnwind: 1, mayThrow: 0, hasUnknownCall: 0) 7517 7518If unspecified, flags are assumed to hold the conservative ``false`` value of 7519``0``. 7520 7521.. _calls_summary: 7522 7523Calls 7524^^^^^ 7525 7526The optional ``Calls`` field looks like: 7527 7528.. code-block:: text 7529 7530 calls: ((Callee)[, (Callee)]*) 7531 7532where each ``Callee`` looks like: 7533 7534.. code-block:: text 7535 7536 callee: ^1[, hotness: None]?[, relbf: 0]? 7537 7538The ``callee`` refers to the summary entry id of the callee. At most one 7539of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``, 7540``Hot``, and ``Critical``), and ``relbf`` (which holds the integer 7541branch frequency relative to the entry frequency, scaled down by 2^8) 7542may be specified. The defaults are ``Unknown`` and ``0``, respectively. 7543 7544.. _params_summary: 7545 7546Params 7547^^^^^^ 7548 7549The optional ``Params`` is used by ``StackSafety`` and looks like: 7550 7551.. code-block:: text 7552 7553 Params: ((Param)[, (Param)]*) 7554 7555where each ``Param`` describes pointer parameter access inside of the 7556function and looks like: 7557 7558.. code-block:: text 7559 7560 param: 4, offset: [0, 5][, calls: ((Callee)[, (Callee)]*)]? 7561 7562where the first ``param`` is the number of the parameter it describes, 7563``offset`` is the inclusive range of offsets from the pointer parameter to bytes 7564which can be accessed by the function. This range does not include accesses by 7565function calls from ``calls`` list. 7566 7567where each ``Callee`` describes how parameter is forwarded into other 7568functions and looks like: 7569 7570.. code-block:: text 7571 7572 callee: ^3, param: 5, offset: [-3, 3] 7573 7574The ``callee`` refers to the summary entry id of the callee, ``param`` is 7575the number of the callee parameter which points into the callers parameter 7576with offset known to be inside of the ``offset`` range. ``calls`` will be 7577consumed and removed by thin link stage to update ``Param::offset`` so it 7578covers all accesses possible by ``calls``. 7579 7580Pointer parameter without corresponding ``Param`` is considered unsafe and we 7581assume that access with any offset is possible. 7582 7583Example: 7584 7585If we have the following function: 7586 7587.. code-block:: text 7588 7589 define i64 @foo(i64* %0, i32* %1, i8* %2, i8 %3) { 7590 store i32* %1, i32** @x 7591 %5 = getelementptr inbounds i8, i8* %2, i64 5 7592 %6 = load i8, i8* %5 7593 %7 = getelementptr inbounds i8, i8* %2, i8 %3 7594 tail call void @bar(i8 %3, i8* %7) 7595 %8 = load i64, i64* %0 7596 ret i64 %8 7597 } 7598 7599We can expect the record like this: 7600 7601.. code-block:: text 7602 7603 params: ((param: 0, offset: [0, 7]),(param: 2, offset: [5, 5], calls: ((callee: ^3, param: 1, offset: [-128, 127])))) 7604 7605The function may access just 8 bytes of the parameter %0 . ``calls`` is empty, 7606so the parameter is either not used for function calls or ``offset`` already 7607covers all accesses from nested function calls. 7608Parameter %1 escapes, so access is unknown. 7609The function itself can access just a single byte of the parameter %2. Additional 7610access is possible inside of the ``@bar`` or ``^3``. The function adds signed 7611offset to the pointer and passes the result as the argument %1 into ``^3``. 7612This record itself does not tell us how ``^3`` will access the parameter. 7613Parameter %3 is not a pointer. 7614 7615.. _refs_summary: 7616 7617Refs 7618^^^^ 7619 7620The optional ``Refs`` field looks like: 7621 7622.. code-block:: text 7623 7624 refs: ((Ref)[, (Ref)]*) 7625 7626where each ``Ref`` contains a reference to the summary id of the referenced 7627value (e.g. ``^1``). 7628 7629.. _typeidinfo_summary: 7630 7631TypeIdInfo 7632^^^^^^^^^^ 7633 7634The optional ``TypeIdInfo`` field, used for 7635`Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, 7636looks like: 7637 7638.. code-block:: text 7639 7640 typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]? 7641 7642These optional fields have the following forms: 7643 7644TypeTests 7645""""""""" 7646 7647.. code-block:: text 7648 7649 typeTests: (TypeIdRef[, TypeIdRef]*) 7650 7651Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>` 7652by summary id or ``GUID``. 7653 7654TypeTestAssumeVCalls 7655"""""""""""""""""""" 7656 7657.. code-block:: text 7658 7659 typeTestAssumeVCalls: (VFuncId[, VFuncId]*) 7660 7661Where each VFuncId has the format: 7662 7663.. code-block:: text 7664 7665 vFuncId: (TypeIdRef, offset: 16) 7666 7667Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>` 7668by summary id or ``GUID`` preceded by a ``guid:`` tag. 7669 7670TypeCheckedLoadVCalls 7671""""""""""""""""""""" 7672 7673.. code-block:: text 7674 7675 typeCheckedLoadVCalls: (VFuncId[, VFuncId]*) 7676 7677Where each VFuncId has the format described for ``TypeTestAssumeVCalls``. 7678 7679TypeTestAssumeConstVCalls 7680""""""""""""""""""""""""" 7681 7682.. code-block:: text 7683 7684 typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*) 7685 7686Where each ConstVCall has the format: 7687 7688.. code-block:: text 7689 7690 (VFuncId, args: (Arg[, Arg]*)) 7691 7692and where each VFuncId has the format described for ``TypeTestAssumeVCalls``, 7693and each Arg is an integer argument number. 7694 7695TypeCheckedLoadConstVCalls 7696"""""""""""""""""""""""""" 7697 7698.. code-block:: text 7699 7700 typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*) 7701 7702Where each ConstVCall has the format described for 7703``TypeTestAssumeConstVCalls``. 7704 7705.. _typeid_summary: 7706 7707Type ID Summary Entry 7708--------------------- 7709 7710Each type id summary entry corresponds to a type identifier resolution 7711which is generated during the LTO link portion of the compile when building 7712with `Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, 7713so these are only present in a combined summary index. 7714 7715Example: 7716 7717.. code-block:: text 7718 7719 ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778 7720 7721The ``typeTestRes`` gives the type test resolution ``kind`` (which may 7722be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and 7723the ``size-1`` bit width. It is followed by optional flags, which default to 0, 7724and an optional WpdResolutions (whole program devirtualization resolution) 7725field that looks like: 7726 7727.. code-block:: text 7728 7729 wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]* 7730 7731where each entry is a mapping from the given byte offset to the whole-program 7732devirtualization resolution WpdRes, that has one of the following formats: 7733 7734.. code-block:: text 7735 7736 wpdRes: (kind: branchFunnel) 7737 wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi") 7738 wpdRes: (kind: indir) 7739 7740Additionally, each wpdRes has an optional ``resByArg`` field, which 7741describes the resolutions for calls with all constant integer arguments: 7742 7743.. code-block:: text 7744 7745 resByArg: (ResByArg[, ResByArg]*) 7746 7747where ResByArg is: 7748 7749.. code-block:: text 7750 7751 args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0]) 7752 7753Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal`` 7754or ``VirtualConstProp``. The ``info`` field is only used if the kind 7755is ``UniformRetVal`` (indicates the uniform return value), or 7756``UniqueRetVal`` (holds the return value associated with the unique vtable 7757(0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does 7758not support the use of absolute symbols to store constants. 7759 7760.. _intrinsicglobalvariables: 7761 7762Intrinsic Global Variables 7763========================== 7764 7765LLVM has a number of "magic" global variables that contain data that 7766affect code generation or other IR semantics. These are documented here. 7767All globals of this sort should have a section specified as 7768"``llvm.metadata``". This section and all globals that start with 7769"``llvm.``" are reserved for use by LLVM. 7770 7771.. _gv_llvmused: 7772 7773The '``llvm.used``' Global Variable 7774----------------------------------- 7775 7776The ``@llvm.used`` global is an array which has 7777:ref:`appending linkage <linkage_appending>`. This array contains a list of 7778pointers to named global variables, functions and aliases which may optionally 7779have a pointer cast formed of bitcast or getelementptr. For example, a legal 7780use of it is: 7781 7782.. code-block:: llvm 7783 7784 @X = global i8 4 7785 @Y = global i32 123 7786 7787 @llvm.used = appending global [2 x i8*] [ 7788 i8* @X, 7789 i8* bitcast (i32* @Y to i8*) 7790 ], section "llvm.metadata" 7791 7792If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler, 7793and linker are required to treat the symbol as if there is a reference to the 7794symbol that it cannot see (which is why they have to be named). For example, if 7795a variable has internal linkage and no references other than that from the 7796``@llvm.used`` list, it cannot be deleted. This is commonly used to represent 7797references from inline asms and other things the compiler cannot "see", and 7798corresponds to "``attribute((used))``" in GNU C. 7799 7800On some targets, the code generator must emit a directive to the 7801assembler or object file to prevent the assembler and linker from 7802removing the symbol. 7803 7804.. _gv_llvmcompilerused: 7805 7806The '``llvm.compiler.used``' Global Variable 7807-------------------------------------------- 7808 7809The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used`` 7810directive, except that it only prevents the compiler from touching the 7811symbol. On targets that support it, this allows an intelligent linker to 7812optimize references to the symbol without being impeded as it would be 7813by ``@llvm.used``. 7814 7815This is a rare construct that should only be used in rare circumstances, 7816and should not be exposed to source languages. 7817 7818.. _gv_llvmglobalctors: 7819 7820The '``llvm.global_ctors``' Global Variable 7821------------------------------------------- 7822 7823.. code-block:: llvm 7824 7825 %0 = type { i32, void ()*, i8* } 7826 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }] 7827 7828The ``@llvm.global_ctors`` array contains a list of constructor 7829functions, priorities, and an associated global or function. 7830The functions referenced by this array will be called in ascending order 7831of priority (i.e. lowest first) when the module is loaded. The order of 7832functions with the same priority is not defined. 7833 7834If the third field is non-null, and points to a global variable 7835or function, the initializer function will only run if the associated 7836data from the current module is not discarded. 7837On ELF the referenced global variable or function must be in a comdat. 7838 7839.. _llvmglobaldtors: 7840 7841The '``llvm.global_dtors``' Global Variable 7842------------------------------------------- 7843 7844.. code-block:: llvm 7845 7846 %0 = type { i32, void ()*, i8* } 7847 @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }] 7848 7849The ``@llvm.global_dtors`` array contains a list of destructor 7850functions, priorities, and an associated global or function. 7851The functions referenced by this array will be called in descending 7852order of priority (i.e. highest first) when the module is unloaded. The 7853order of functions with the same priority is not defined. 7854 7855If the third field is non-null, and points to a global variable 7856or function, the destructor function will only run if the associated 7857data from the current module is not discarded. 7858On ELF the referenced global variable or function must be in a comdat. 7859 7860Instruction Reference 7861===================== 7862 7863The LLVM instruction set consists of several different classifications 7864of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary 7865instructions <binaryops>`, :ref:`bitwise binary 7866instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and 7867:ref:`other instructions <otherops>`. 7868 7869.. _terminators: 7870 7871Terminator Instructions 7872----------------------- 7873 7874As mentioned :ref:`previously <functionstructure>`, every basic block in a 7875program ends with a "Terminator" instruction, which indicates which 7876block should be executed after the current block is finished. These 7877terminator instructions typically yield a '``void``' value: they produce 7878control flow, not values (the one exception being the 7879':ref:`invoke <i_invoke>`' instruction). 7880 7881The terminator instructions are: ':ref:`ret <i_ret>`', 7882':ref:`br <i_br>`', ':ref:`switch <i_switch>`', 7883':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`', 7884':ref:`callbr <i_callbr>`' 7885':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`', 7886':ref:`catchret <i_catchret>`', 7887':ref:`cleanupret <i_cleanupret>`', 7888and ':ref:`unreachable <i_unreachable>`'. 7889 7890.. _i_ret: 7891 7892'``ret``' Instruction 7893^^^^^^^^^^^^^^^^^^^^^ 7894 7895Syntax: 7896""""""" 7897 7898:: 7899 7900 ret <type> <value> ; Return a value from a non-void function 7901 ret void ; Return from void function 7902 7903Overview: 7904""""""""" 7905 7906The '``ret``' instruction is used to return control flow (and optionally 7907a value) from a function back to the caller. 7908 7909There are two forms of the '``ret``' instruction: one that returns a 7910value and then causes control flow, and one that just causes control 7911flow to occur. 7912 7913Arguments: 7914"""""""""" 7915 7916The '``ret``' instruction optionally accepts a single argument, the 7917return value. The type of the return value must be a ':ref:`first 7918class <t_firstclass>`' type. 7919 7920A function is not :ref:`well formed <wellformed>` if it has a non-void 7921return type and contains a '``ret``' instruction with no return value or 7922a return value with a type that does not match its type, or if it has a 7923void return type and contains a '``ret``' instruction with a return 7924value. 7925 7926Semantics: 7927"""""""""" 7928 7929When the '``ret``' instruction is executed, control flow returns back to 7930the calling function's context. If the caller is a 7931":ref:`call <i_call>`" instruction, execution continues at the 7932instruction after the call. If the caller was an 7933":ref:`invoke <i_invoke>`" instruction, execution continues at the 7934beginning of the "normal" destination block. If the instruction returns 7935a value, that value shall set the call or invoke instruction's return 7936value. 7937 7938Example: 7939"""""""" 7940 7941.. code-block:: llvm 7942 7943 ret i32 5 ; Return an integer value of 5 7944 ret void ; Return from a void function 7945 ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2 7946 7947.. _i_br: 7948 7949'``br``' Instruction 7950^^^^^^^^^^^^^^^^^^^^ 7951 7952Syntax: 7953""""""" 7954 7955:: 7956 7957 br i1 <cond>, label <iftrue>, label <iffalse> 7958 br label <dest> ; Unconditional branch 7959 7960Overview: 7961""""""""" 7962 7963The '``br``' instruction is used to cause control flow to transfer to a 7964different basic block in the current function. There are two forms of 7965this instruction, corresponding to a conditional branch and an 7966unconditional branch. 7967 7968Arguments: 7969"""""""""" 7970 7971The conditional branch form of the '``br``' instruction takes a single 7972'``i1``' value and two '``label``' values. The unconditional form of the 7973'``br``' instruction takes a single '``label``' value as a target. 7974 7975Semantics: 7976"""""""""" 7977 7978Upon execution of a conditional '``br``' instruction, the '``i1``' 7979argument is evaluated. If the value is ``true``, control flows to the 7980'``iftrue``' ``label`` argument. If "cond" is ``false``, control flows 7981to the '``iffalse``' ``label`` argument. 7982If '``cond``' is ``poison`` or ``undef``, this instruction has undefined 7983behavior. 7984 7985Example: 7986"""""""" 7987 7988.. code-block:: llvm 7989 7990 Test: 7991 %cond = icmp eq i32 %a, %b 7992 br i1 %cond, label %IfEqual, label %IfUnequal 7993 IfEqual: 7994 ret i32 1 7995 IfUnequal: 7996 ret i32 0 7997 7998.. _i_switch: 7999 8000'``switch``' Instruction 8001^^^^^^^^^^^^^^^^^^^^^^^^ 8002 8003Syntax: 8004""""""" 8005 8006:: 8007 8008 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] 8009 8010Overview: 8011""""""""" 8012 8013The '``switch``' instruction is used to transfer control flow to one of 8014several different places. It is a generalization of the '``br``' 8015instruction, allowing a branch to occur to one of many possible 8016destinations. 8017 8018Arguments: 8019"""""""""" 8020 8021The '``switch``' instruction uses three parameters: an integer 8022comparison value '``value``', a default '``label``' destination, and an 8023array of pairs of comparison value constants and '``label``'s. The table 8024is not allowed to contain duplicate constant entries. 8025 8026Semantics: 8027"""""""""" 8028 8029The ``switch`` instruction specifies a table of values and destinations. 8030When the '``switch``' instruction is executed, this table is searched 8031for the given value. If the value is found, control flow is transferred 8032to the corresponding destination; otherwise, control flow is transferred 8033to the default destination. 8034If '``value``' is ``poison`` or ``undef``, this instruction has undefined 8035behavior. 8036 8037Implementation: 8038""""""""""""""" 8039 8040Depending on properties of the target machine and the particular 8041``switch`` instruction, this instruction may be code generated in 8042different ways. For example, it could be generated as a series of 8043chained conditional branches or with a lookup table. 8044 8045Example: 8046"""""""" 8047 8048.. code-block:: llvm 8049 8050 ; Emulate a conditional br instruction 8051 %Val = zext i1 %value to i32 8052 switch i32 %Val, label %truedest [ i32 0, label %falsedest ] 8053 8054 ; Emulate an unconditional br instruction 8055 switch i32 0, label %dest [ ] 8056 8057 ; Implement a jump table: 8058 switch i32 %val, label %otherwise [ i32 0, label %onzero 8059 i32 1, label %onone 8060 i32 2, label %ontwo ] 8061 8062.. _i_indirectbr: 8063 8064'``indirectbr``' Instruction 8065^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8066 8067Syntax: 8068""""""" 8069 8070:: 8071 8072 indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ] 8073 8074Overview: 8075""""""""" 8076 8077The '``indirectbr``' instruction implements an indirect branch to a 8078label within the current function, whose address is specified by 8079"``address``". Address must be derived from a 8080:ref:`blockaddress <blockaddress>` constant. 8081 8082Arguments: 8083"""""""""" 8084 8085The '``address``' argument is the address of the label to jump to. The 8086rest of the arguments indicate the full set of possible destinations 8087that the address may point to. Blocks are allowed to occur multiple 8088times in the destination list, though this isn't particularly useful. 8089 8090This destination list is required so that dataflow analysis has an 8091accurate understanding of the CFG. 8092 8093Semantics: 8094"""""""""" 8095 8096Control transfers to the block specified in the address argument. All 8097possible destination blocks must be listed in the label list, otherwise 8098this instruction has undefined behavior. This implies that jumps to 8099labels defined in other functions have undefined behavior as well. 8100If '``address``' is ``poison`` or ``undef``, this instruction has undefined 8101behavior. 8102 8103Implementation: 8104""""""""""""""" 8105 8106This is typically implemented with a jump through a register. 8107 8108Example: 8109"""""""" 8110 8111.. code-block:: llvm 8112 8113 indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ] 8114 8115.. _i_invoke: 8116 8117'``invoke``' Instruction 8118^^^^^^^^^^^^^^^^^^^^^^^^ 8119 8120Syntax: 8121""""""" 8122 8123:: 8124 8125 <result> = invoke [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] 8126 [operand bundles] to label <normal label> unwind label <exception label> 8127 8128Overview: 8129""""""""" 8130 8131The '``invoke``' instruction causes control to transfer to a specified 8132function, with the possibility of control flow transfer to either the 8133'``normal``' label or the '``exception``' label. If the callee function 8134returns with the "``ret``" instruction, control flow will return to the 8135"normal" label. If the callee (or any indirect callees) returns via the 8136":ref:`resume <i_resume>`" instruction or other exception handling 8137mechanism, control is interrupted and continued at the dynamically 8138nearest "exception" label. 8139 8140The '``exception``' label is a `landing 8141pad <ExceptionHandling.html#overview>`_ for the exception. As such, 8142'``exception``' label is required to have the 8143":ref:`landingpad <i_landingpad>`" instruction, which contains the 8144information about the behavior of the program after unwinding happens, 8145as its first non-PHI instruction. The restrictions on the 8146"``landingpad``" instruction's tightly couples it to the "``invoke``" 8147instruction, so that the important information contained within the 8148"``landingpad``" instruction can't be lost through normal code motion. 8149 8150Arguments: 8151"""""""""" 8152 8153This instruction requires several arguments: 8154 8155#. The optional "cconv" marker indicates which :ref:`calling 8156 convention <callingconv>` the call should use. If none is 8157 specified, the call defaults to using C calling conventions. 8158#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 8159 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 8160 are valid here. 8161#. The optional addrspace attribute can be used to indicate the address space 8162 of the called function. If it is not specified, the program address space 8163 from the :ref:`datalayout string<langref_datalayout>` will be used. 8164#. '``ty``': the type of the call instruction itself which is also the 8165 type of the return value. Functions that return no value are marked 8166 ``void``. 8167#. '``fnty``': shall be the signature of the function being invoked. The 8168 argument types must match the types implied by this signature. This 8169 type can be omitted if the function is not varargs. 8170#. '``fnptrval``': An LLVM value containing a pointer to a function to 8171 be invoked. In most cases, this is a direct function invocation, but 8172 indirect ``invoke``'s are just as possible, calling an arbitrary pointer 8173 to function value. 8174#. '``function args``': argument list whose types match the function 8175 signature argument types and parameter attributes. All arguments must 8176 be of :ref:`first class <t_firstclass>` type. If the function signature 8177 indicates the function accepts a variable number of arguments, the 8178 extra arguments can be specified. 8179#. '``normal label``': the label reached when the called function 8180 executes a '``ret``' instruction. 8181#. '``exception label``': the label reached when a callee returns via 8182 the :ref:`resume <i_resume>` instruction or other exception handling 8183 mechanism. 8184#. The optional :ref:`function attributes <fnattrs>` list. 8185#. The optional :ref:`operand bundles <opbundles>` list. 8186 8187Semantics: 8188"""""""""" 8189 8190This instruction is designed to operate as a standard '``call``' 8191instruction in most regards. The primary difference is that it 8192establishes an association with a label, which is used by the runtime 8193library to unwind the stack. 8194 8195This instruction is used in languages with destructors to ensure that 8196proper cleanup is performed in the case of either a ``longjmp`` or a 8197thrown exception. Additionally, this is important for implementation of 8198'``catch``' clauses in high-level languages that support them. 8199 8200For the purposes of the SSA form, the definition of the value returned 8201by the '``invoke``' instruction is deemed to occur on the edge from the 8202current block to the "normal" label. If the callee unwinds then no 8203return value is available. 8204 8205Example: 8206"""""""" 8207 8208.. code-block:: llvm 8209 8210 %retval = invoke i32 @Test(i32 15) to label %Continue 8211 unwind label %TestCleanup ; i32:retval set 8212 %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue 8213 unwind label %TestCleanup ; i32:retval set 8214 8215.. _i_callbr: 8216 8217'``callbr``' Instruction 8218^^^^^^^^^^^^^^^^^^^^^^^^ 8219 8220Syntax: 8221""""""" 8222 8223:: 8224 8225 <result> = callbr [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] 8226 [operand bundles] to label <fallthrough label> [indirect labels] 8227 8228Overview: 8229""""""""" 8230 8231The '``callbr``' instruction causes control to transfer to a specified 8232function, with the possibility of control flow transfer to either the 8233'``fallthrough``' label or one of the '``indirect``' labels. 8234 8235This instruction should only be used to implement the "goto" feature of gcc 8236style inline assembly. Any other usage is an error in the IR verifier. 8237 8238Arguments: 8239"""""""""" 8240 8241This instruction requires several arguments: 8242 8243#. The optional "cconv" marker indicates which :ref:`calling 8244 convention <callingconv>` the call should use. If none is 8245 specified, the call defaults to using C calling conventions. 8246#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 8247 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 8248 are valid here. 8249#. The optional addrspace attribute can be used to indicate the address space 8250 of the called function. If it is not specified, the program address space 8251 from the :ref:`datalayout string<langref_datalayout>` will be used. 8252#. '``ty``': the type of the call instruction itself which is also the 8253 type of the return value. Functions that return no value are marked 8254 ``void``. 8255#. '``fnty``': shall be the signature of the function being called. The 8256 argument types must match the types implied by this signature. This 8257 type can be omitted if the function is not varargs. 8258#. '``fnptrval``': An LLVM value containing a pointer to a function to 8259 be called. In most cases, this is a direct function call, but 8260 other ``callbr``'s are just as possible, calling an arbitrary pointer 8261 to function value. 8262#. '``function args``': argument list whose types match the function 8263 signature argument types and parameter attributes. All arguments must 8264 be of :ref:`first class <t_firstclass>` type. If the function signature 8265 indicates the function accepts a variable number of arguments, the 8266 extra arguments can be specified. 8267#. '``fallthrough label``': the label reached when the inline assembly's 8268 execution exits the bottom. 8269#. '``indirect labels``': the labels reached when a callee transfers control 8270 to a location other than the '``fallthrough label``'. The blockaddress 8271 constant for these should also be in the list of '``function args``'. 8272#. The optional :ref:`function attributes <fnattrs>` list. 8273#. The optional :ref:`operand bundles <opbundles>` list. 8274 8275Semantics: 8276"""""""""" 8277 8278This instruction is designed to operate as a standard '``call``' 8279instruction in most regards. The primary difference is that it 8280establishes an association with additional labels to define where control 8281flow goes after the call. 8282 8283The output values of a '``callbr``' instruction are available only to 8284the '``fallthrough``' block, not to any '``indirect``' blocks(s). 8285 8286The only use of this today is to implement the "goto" feature of gcc inline 8287assembly where additional labels can be provided as locations for the inline 8288assembly to jump to. 8289 8290Example: 8291"""""""" 8292 8293.. code-block:: llvm 8294 8295 ; "asm goto" without output constraints. 8296 callbr void asm "", "r,X"(i32 %x, i8 *blockaddress(@foo, %indirect)) 8297 to label %fallthrough [label %indirect] 8298 8299 ; "asm goto" with output constraints. 8300 <result> = callbr i32 asm "", "=r,r,X"(i32 %x, i8 *blockaddress(@foo, %indirect)) 8301 to label %fallthrough [label %indirect] 8302 8303.. _i_resume: 8304 8305'``resume``' Instruction 8306^^^^^^^^^^^^^^^^^^^^^^^^ 8307 8308Syntax: 8309""""""" 8310 8311:: 8312 8313 resume <type> <value> 8314 8315Overview: 8316""""""""" 8317 8318The '``resume``' instruction is a terminator instruction that has no 8319successors. 8320 8321Arguments: 8322"""""""""" 8323 8324The '``resume``' instruction requires one argument, which must have the 8325same type as the result of any '``landingpad``' instruction in the same 8326function. 8327 8328Semantics: 8329"""""""""" 8330 8331The '``resume``' instruction resumes propagation of an existing 8332(in-flight) exception whose unwinding was interrupted with a 8333:ref:`landingpad <i_landingpad>` instruction. 8334 8335Example: 8336"""""""" 8337 8338.. code-block:: llvm 8339 8340 resume { i8*, i32 } %exn 8341 8342.. _i_catchswitch: 8343 8344'``catchswitch``' Instruction 8345^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8346 8347Syntax: 8348""""""" 8349 8350:: 8351 8352 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller 8353 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default> 8354 8355Overview: 8356""""""""" 8357 8358The '``catchswitch``' instruction is used by `LLVM's exception handling system 8359<ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers 8360that may be executed by the :ref:`EH personality routine <personalityfn>`. 8361 8362Arguments: 8363"""""""""" 8364 8365The ``parent`` argument is the token of the funclet that contains the 8366``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet, 8367this operand may be the token ``none``. 8368 8369The ``default`` argument is the label of another basic block beginning with 8370either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination 8371must be a legal target with respect to the ``parent`` links, as described in 8372the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_. 8373 8374The ``handlers`` are a nonempty list of successor blocks that each begin with a 8375:ref:`catchpad <i_catchpad>` instruction. 8376 8377Semantics: 8378"""""""""" 8379 8380Executing this instruction transfers control to one of the successors in 8381``handlers``, if appropriate, or continues to unwind via the unwind label if 8382present. 8383 8384The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that 8385it must be both the first non-phi instruction and last instruction in the basic 8386block. Therefore, it must be the only non-phi instruction in the block. 8387 8388Example: 8389"""""""" 8390 8391.. code-block:: text 8392 8393 dispatch1: 8394 %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller 8395 dispatch2: 8396 %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup 8397 8398.. _i_catchret: 8399 8400'``catchret``' Instruction 8401^^^^^^^^^^^^^^^^^^^^^^^^^^ 8402 8403Syntax: 8404""""""" 8405 8406:: 8407 8408 catchret from <token> to label <normal> 8409 8410Overview: 8411""""""""" 8412 8413The '``catchret``' instruction is a terminator instruction that has a 8414single successor. 8415 8416 8417Arguments: 8418"""""""""" 8419 8420The first argument to a '``catchret``' indicates which ``catchpad`` it 8421exits. It must be a :ref:`catchpad <i_catchpad>`. 8422The second argument to a '``catchret``' specifies where control will 8423transfer to next. 8424 8425Semantics: 8426"""""""""" 8427 8428The '``catchret``' instruction ends an existing (in-flight) exception whose 8429unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The 8430:ref:`personality function <personalityfn>` gets a chance to execute arbitrary 8431code to, for example, destroy the active exception. Control then transfers to 8432``normal``. 8433 8434The ``token`` argument must be a token produced by a ``catchpad`` instruction. 8435If the specified ``catchpad`` is not the most-recently-entered not-yet-exited 8436funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 8437the ``catchret``'s behavior is undefined. 8438 8439Example: 8440"""""""" 8441 8442.. code-block:: text 8443 8444 catchret from %catch to label %continue 8445 8446.. _i_cleanupret: 8447 8448'``cleanupret``' Instruction 8449^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8450 8451Syntax: 8452""""""" 8453 8454:: 8455 8456 cleanupret from <value> unwind label <continue> 8457 cleanupret from <value> unwind to caller 8458 8459Overview: 8460""""""""" 8461 8462The '``cleanupret``' instruction is a terminator instruction that has 8463an optional successor. 8464 8465 8466Arguments: 8467"""""""""" 8468 8469The '``cleanupret``' instruction requires one argument, which indicates 8470which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`. 8471If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited 8472funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 8473the ``cleanupret``'s behavior is undefined. 8474 8475The '``cleanupret``' instruction also has an optional successor, ``continue``, 8476which must be the label of another basic block beginning with either a 8477``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must 8478be a legal target with respect to the ``parent`` links, as described in the 8479`exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_. 8480 8481Semantics: 8482"""""""""" 8483 8484The '``cleanupret``' instruction indicates to the 8485:ref:`personality function <personalityfn>` that one 8486:ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended. 8487It transfers control to ``continue`` or unwinds out of the function. 8488 8489Example: 8490"""""""" 8491 8492.. code-block:: text 8493 8494 cleanupret from %cleanup unwind to caller 8495 cleanupret from %cleanup unwind label %continue 8496 8497.. _i_unreachable: 8498 8499'``unreachable``' Instruction 8500^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8501 8502Syntax: 8503""""""" 8504 8505:: 8506 8507 unreachable 8508 8509Overview: 8510""""""""" 8511 8512The '``unreachable``' instruction has no defined semantics. This 8513instruction is used to inform the optimizer that a particular portion of 8514the code is not reachable. This can be used to indicate that the code 8515after a no-return function cannot be reached, and other facts. 8516 8517Semantics: 8518"""""""""" 8519 8520The '``unreachable``' instruction has no defined semantics. 8521 8522.. _unaryops: 8523 8524Unary Operations 8525----------------- 8526 8527Unary operators require a single operand, execute an operation on 8528it, and produce a single value. The operand might represent multiple 8529data, as is the case with the :ref:`vector <t_vector>` data type. The 8530result value has the same type as its operand. 8531 8532.. _i_fneg: 8533 8534'``fneg``' Instruction 8535^^^^^^^^^^^^^^^^^^^^^^ 8536 8537Syntax: 8538""""""" 8539 8540:: 8541 8542 <result> = fneg [fast-math flags]* <ty> <op1> ; yields ty:result 8543 8544Overview: 8545""""""""" 8546 8547The '``fneg``' instruction returns the negation of its operand. 8548 8549Arguments: 8550"""""""""" 8551 8552The argument to the '``fneg``' instruction must be a 8553:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8554floating-point values. 8555 8556Semantics: 8557"""""""""" 8558 8559The value produced is a copy of the operand with its sign bit flipped. 8560This instruction can also take any number of :ref:`fast-math 8561flags <fastmath>`, which are optimization hints to enable otherwise 8562unsafe floating-point optimizations: 8563 8564Example: 8565"""""""" 8566 8567.. code-block:: text 8568 8569 <result> = fneg float %val ; yields float:result = -%var 8570 8571.. _binaryops: 8572 8573Binary Operations 8574----------------- 8575 8576Binary operators are used to do most of the computation in a program. 8577They require two operands of the same type, execute an operation on 8578them, and produce a single value. The operands might represent multiple 8579data, as is the case with the :ref:`vector <t_vector>` data type. The 8580result value has the same type as its operands. 8581 8582There are several different binary operators: 8583 8584.. _i_add: 8585 8586'``add``' Instruction 8587^^^^^^^^^^^^^^^^^^^^^ 8588 8589Syntax: 8590""""""" 8591 8592:: 8593 8594 <result> = add <ty> <op1>, <op2> ; yields ty:result 8595 <result> = add nuw <ty> <op1>, <op2> ; yields ty:result 8596 <result> = add nsw <ty> <op1>, <op2> ; yields ty:result 8597 <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result 8598 8599Overview: 8600""""""""" 8601 8602The '``add``' instruction returns the sum of its two operands. 8603 8604Arguments: 8605"""""""""" 8606 8607The two arguments to the '``add``' instruction must be 8608:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8609arguments must have identical types. 8610 8611Semantics: 8612"""""""""" 8613 8614The value produced is the integer sum of the two operands. 8615 8616If the sum has unsigned overflow, the result returned is the 8617mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of 8618the result. 8619 8620Because LLVM integers use a two's complement representation, this 8621instruction is appropriate for both signed and unsigned integers. 8622 8623``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 8624respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 8625result value of the ``add`` is a :ref:`poison value <poisonvalues>` if 8626unsigned and/or signed overflow, respectively, occurs. 8627 8628Example: 8629"""""""" 8630 8631.. code-block:: text 8632 8633 <result> = add i32 4, %var ; yields i32:result = 4 + %var 8634 8635.. _i_fadd: 8636 8637'``fadd``' Instruction 8638^^^^^^^^^^^^^^^^^^^^^^ 8639 8640Syntax: 8641""""""" 8642 8643:: 8644 8645 <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8646 8647Overview: 8648""""""""" 8649 8650The '``fadd``' instruction returns the sum of its two operands. 8651 8652Arguments: 8653"""""""""" 8654 8655The two arguments to the '``fadd``' instruction must be 8656:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8657floating-point values. Both arguments must have identical types. 8658 8659Semantics: 8660"""""""""" 8661 8662The value produced is the floating-point sum of the two operands. 8663This instruction is assumed to execute in the default :ref:`floating-point 8664environment <floatenv>`. 8665This instruction can also take any number of :ref:`fast-math 8666flags <fastmath>`, which are optimization hints to enable otherwise 8667unsafe floating-point optimizations: 8668 8669Example: 8670"""""""" 8671 8672.. code-block:: text 8673 8674 <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var 8675 8676.. _i_sub: 8677 8678'``sub``' Instruction 8679^^^^^^^^^^^^^^^^^^^^^ 8680 8681Syntax: 8682""""""" 8683 8684:: 8685 8686 <result> = sub <ty> <op1>, <op2> ; yields ty:result 8687 <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result 8688 <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result 8689 <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result 8690 8691Overview: 8692""""""""" 8693 8694The '``sub``' instruction returns the difference of its two operands. 8695 8696Note that the '``sub``' instruction is used to represent the '``neg``' 8697instruction present in most other intermediate representations. 8698 8699Arguments: 8700"""""""""" 8701 8702The two arguments to the '``sub``' instruction must be 8703:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8704arguments must have identical types. 8705 8706Semantics: 8707"""""""""" 8708 8709The value produced is the integer difference of the two operands. 8710 8711If the difference has unsigned overflow, the result returned is the 8712mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of 8713the result. 8714 8715Because LLVM integers use a two's complement representation, this 8716instruction is appropriate for both signed and unsigned integers. 8717 8718``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 8719respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 8720result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if 8721unsigned and/or signed overflow, respectively, occurs. 8722 8723Example: 8724"""""""" 8725 8726.. code-block:: text 8727 8728 <result> = sub i32 4, %var ; yields i32:result = 4 - %var 8729 <result> = sub i32 0, %val ; yields i32:result = -%var 8730 8731.. _i_fsub: 8732 8733'``fsub``' Instruction 8734^^^^^^^^^^^^^^^^^^^^^^ 8735 8736Syntax: 8737""""""" 8738 8739:: 8740 8741 <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8742 8743Overview: 8744""""""""" 8745 8746The '``fsub``' instruction returns the difference of its two operands. 8747 8748Arguments: 8749"""""""""" 8750 8751The two arguments to the '``fsub``' instruction must be 8752:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8753floating-point values. Both arguments must have identical types. 8754 8755Semantics: 8756"""""""""" 8757 8758The value produced is the floating-point difference of the two operands. 8759This instruction is assumed to execute in the default :ref:`floating-point 8760environment <floatenv>`. 8761This instruction can also take any number of :ref:`fast-math 8762flags <fastmath>`, which are optimization hints to enable otherwise 8763unsafe floating-point optimizations: 8764 8765Example: 8766"""""""" 8767 8768.. code-block:: text 8769 8770 <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var 8771 <result> = fsub float -0.0, %val ; yields float:result = -%var 8772 8773.. _i_mul: 8774 8775'``mul``' Instruction 8776^^^^^^^^^^^^^^^^^^^^^ 8777 8778Syntax: 8779""""""" 8780 8781:: 8782 8783 <result> = mul <ty> <op1>, <op2> ; yields ty:result 8784 <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result 8785 <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result 8786 <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result 8787 8788Overview: 8789""""""""" 8790 8791The '``mul``' instruction returns the product of its two operands. 8792 8793Arguments: 8794"""""""""" 8795 8796The two arguments to the '``mul``' instruction must be 8797:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8798arguments must have identical types. 8799 8800Semantics: 8801"""""""""" 8802 8803The value produced is the integer product of the two operands. 8804 8805If the result of the multiplication has unsigned overflow, the result 8806returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the 8807bit width of the result. 8808 8809Because LLVM integers use a two's complement representation, and the 8810result is the same width as the operands, this instruction returns the 8811correct result for both signed and unsigned integers. If a full product 8812(e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be 8813sign-extended or zero-extended as appropriate to the width of the full 8814product. 8815 8816``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 8817respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 8818result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if 8819unsigned and/or signed overflow, respectively, occurs. 8820 8821Example: 8822"""""""" 8823 8824.. code-block:: text 8825 8826 <result> = mul i32 4, %var ; yields i32:result = 4 * %var 8827 8828.. _i_fmul: 8829 8830'``fmul``' Instruction 8831^^^^^^^^^^^^^^^^^^^^^^ 8832 8833Syntax: 8834""""""" 8835 8836:: 8837 8838 <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8839 8840Overview: 8841""""""""" 8842 8843The '``fmul``' instruction returns the product of its two operands. 8844 8845Arguments: 8846"""""""""" 8847 8848The two arguments to the '``fmul``' instruction must be 8849:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8850floating-point values. Both arguments must have identical types. 8851 8852Semantics: 8853"""""""""" 8854 8855The value produced is the floating-point product of the two operands. 8856This instruction is assumed to execute in the default :ref:`floating-point 8857environment <floatenv>`. 8858This instruction can also take any number of :ref:`fast-math 8859flags <fastmath>`, which are optimization hints to enable otherwise 8860unsafe floating-point optimizations: 8861 8862Example: 8863"""""""" 8864 8865.. code-block:: text 8866 8867 <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var 8868 8869.. _i_udiv: 8870 8871'``udiv``' Instruction 8872^^^^^^^^^^^^^^^^^^^^^^ 8873 8874Syntax: 8875""""""" 8876 8877:: 8878 8879 <result> = udiv <ty> <op1>, <op2> ; yields ty:result 8880 <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result 8881 8882Overview: 8883""""""""" 8884 8885The '``udiv``' instruction returns the quotient of its two operands. 8886 8887Arguments: 8888"""""""""" 8889 8890The two arguments to the '``udiv``' instruction must be 8891:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8892arguments must have identical types. 8893 8894Semantics: 8895"""""""""" 8896 8897The value produced is the unsigned integer quotient of the two operands. 8898 8899Note that unsigned integer division and signed integer division are 8900distinct operations; for signed integer division, use '``sdiv``'. 8901 8902Division by zero is undefined behavior. For vectors, if any element 8903of the divisor is zero, the operation has undefined behavior. 8904 8905 8906If the ``exact`` keyword is present, the result value of the ``udiv`` is 8907a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as 8908such, "((a udiv exact b) mul b) == a"). 8909 8910Example: 8911"""""""" 8912 8913.. code-block:: text 8914 8915 <result> = udiv i32 4, %var ; yields i32:result = 4 / %var 8916 8917.. _i_sdiv: 8918 8919'``sdiv``' Instruction 8920^^^^^^^^^^^^^^^^^^^^^^ 8921 8922Syntax: 8923""""""" 8924 8925:: 8926 8927 <result> = sdiv <ty> <op1>, <op2> ; yields ty:result 8928 <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result 8929 8930Overview: 8931""""""""" 8932 8933The '``sdiv``' instruction returns the quotient of its two operands. 8934 8935Arguments: 8936"""""""""" 8937 8938The two arguments to the '``sdiv``' instruction must be 8939:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8940arguments must have identical types. 8941 8942Semantics: 8943"""""""""" 8944 8945The value produced is the signed integer quotient of the two operands 8946rounded towards zero. 8947 8948Note that signed integer division and unsigned integer division are 8949distinct operations; for unsigned integer division, use '``udiv``'. 8950 8951Division by zero is undefined behavior. For vectors, if any element 8952of the divisor is zero, the operation has undefined behavior. 8953Overflow also leads to undefined behavior; this is a rare case, but can 8954occur, for example, by doing a 32-bit division of -2147483648 by -1. 8955 8956If the ``exact`` keyword is present, the result value of the ``sdiv`` is 8957a :ref:`poison value <poisonvalues>` if the result would be rounded. 8958 8959Example: 8960"""""""" 8961 8962.. code-block:: text 8963 8964 <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var 8965 8966.. _i_fdiv: 8967 8968'``fdiv``' Instruction 8969^^^^^^^^^^^^^^^^^^^^^^ 8970 8971Syntax: 8972""""""" 8973 8974:: 8975 8976 <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8977 8978Overview: 8979""""""""" 8980 8981The '``fdiv``' instruction returns the quotient of its two operands. 8982 8983Arguments: 8984"""""""""" 8985 8986The two arguments to the '``fdiv``' instruction must be 8987:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8988floating-point values. Both arguments must have identical types. 8989 8990Semantics: 8991"""""""""" 8992 8993The value produced is the floating-point quotient of the two operands. 8994This instruction is assumed to execute in the default :ref:`floating-point 8995environment <floatenv>`. 8996This instruction can also take any number of :ref:`fast-math 8997flags <fastmath>`, which are optimization hints to enable otherwise 8998unsafe floating-point optimizations: 8999 9000Example: 9001"""""""" 9002 9003.. code-block:: text 9004 9005 <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var 9006 9007.. _i_urem: 9008 9009'``urem``' Instruction 9010^^^^^^^^^^^^^^^^^^^^^^ 9011 9012Syntax: 9013""""""" 9014 9015:: 9016 9017 <result> = urem <ty> <op1>, <op2> ; yields ty:result 9018 9019Overview: 9020""""""""" 9021 9022The '``urem``' instruction returns the remainder from the unsigned 9023division of its two arguments. 9024 9025Arguments: 9026"""""""""" 9027 9028The two arguments to the '``urem``' instruction must be 9029:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9030arguments must have identical types. 9031 9032Semantics: 9033"""""""""" 9034 9035This instruction returns the unsigned integer *remainder* of a division. 9036This instruction always performs an unsigned division to get the 9037remainder. 9038 9039Note that unsigned integer remainder and signed integer remainder are 9040distinct operations; for signed integer remainder, use '``srem``'. 9041 9042Taking the remainder of a division by zero is undefined behavior. 9043For vectors, if any element of the divisor is zero, the operation has 9044undefined behavior. 9045 9046Example: 9047"""""""" 9048 9049.. code-block:: text 9050 9051 <result> = urem i32 4, %var ; yields i32:result = 4 % %var 9052 9053.. _i_srem: 9054 9055'``srem``' Instruction 9056^^^^^^^^^^^^^^^^^^^^^^ 9057 9058Syntax: 9059""""""" 9060 9061:: 9062 9063 <result> = srem <ty> <op1>, <op2> ; yields ty:result 9064 9065Overview: 9066""""""""" 9067 9068The '``srem``' instruction returns the remainder from the signed 9069division of its two operands. This instruction can also take 9070:ref:`vector <t_vector>` versions of the values in which case the elements 9071must be integers. 9072 9073Arguments: 9074"""""""""" 9075 9076The two arguments to the '``srem``' instruction must be 9077:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9078arguments must have identical types. 9079 9080Semantics: 9081"""""""""" 9082 9083This instruction returns the *remainder* of a division (where the result 9084is either zero or has the same sign as the dividend, ``op1``), not the 9085*modulo* operator (where the result is either zero or has the same sign 9086as the divisor, ``op2``) of a value. For more information about the 9087difference, see `The Math 9088Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a 9089table of how this is implemented in various languages, please see 9090`Wikipedia: modulo 9091operation <http://en.wikipedia.org/wiki/Modulo_operation>`_. 9092 9093Note that signed integer remainder and unsigned integer remainder are 9094distinct operations; for unsigned integer remainder, use '``urem``'. 9095 9096Taking the remainder of a division by zero is undefined behavior. 9097For vectors, if any element of the divisor is zero, the operation has 9098undefined behavior. 9099Overflow also leads to undefined behavior; this is a rare case, but can 9100occur, for example, by taking the remainder of a 32-bit division of 9101-2147483648 by -1. (The remainder doesn't actually overflow, but this 9102rule lets srem be implemented using instructions that return both the 9103result of the division and the remainder.) 9104 9105Example: 9106"""""""" 9107 9108.. code-block:: text 9109 9110 <result> = srem i32 4, %var ; yields i32:result = 4 % %var 9111 9112.. _i_frem: 9113 9114'``frem``' Instruction 9115^^^^^^^^^^^^^^^^^^^^^^ 9116 9117Syntax: 9118""""""" 9119 9120:: 9121 9122 <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 9123 9124Overview: 9125""""""""" 9126 9127The '``frem``' instruction returns the remainder from the division of 9128its two operands. 9129 9130Arguments: 9131"""""""""" 9132 9133The two arguments to the '``frem``' instruction must be 9134:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 9135floating-point values. Both arguments must have identical types. 9136 9137Semantics: 9138"""""""""" 9139 9140The value produced is the floating-point remainder of the two operands. 9141This is the same output as a libm '``fmod``' function, but without any 9142possibility of setting ``errno``. The remainder has the same sign as the 9143dividend. 9144This instruction is assumed to execute in the default :ref:`floating-point 9145environment <floatenv>`. 9146This instruction can also take any number of :ref:`fast-math 9147flags <fastmath>`, which are optimization hints to enable otherwise 9148unsafe floating-point optimizations: 9149 9150Example: 9151"""""""" 9152 9153.. code-block:: text 9154 9155 <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var 9156 9157.. _bitwiseops: 9158 9159Bitwise Binary Operations 9160------------------------- 9161 9162Bitwise binary operators are used to do various forms of bit-twiddling 9163in a program. They are generally very efficient instructions and can 9164commonly be strength reduced from other instructions. They require two 9165operands of the same type, execute an operation on them, and produce a 9166single value. The resulting value is the same type as its operands. 9167 9168.. _i_shl: 9169 9170'``shl``' Instruction 9171^^^^^^^^^^^^^^^^^^^^^ 9172 9173Syntax: 9174""""""" 9175 9176:: 9177 9178 <result> = shl <ty> <op1>, <op2> ; yields ty:result 9179 <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result 9180 <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result 9181 <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result 9182 9183Overview: 9184""""""""" 9185 9186The '``shl``' instruction returns the first operand shifted to the left 9187a specified number of bits. 9188 9189Arguments: 9190"""""""""" 9191 9192Both arguments to the '``shl``' instruction must be the same 9193:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 9194'``op2``' is treated as an unsigned value. 9195 9196Semantics: 9197"""""""""" 9198 9199The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`, 9200where ``n`` is the width of the result. If ``op2`` is (statically or 9201dynamically) equal to or larger than the number of bits in 9202``op1``, this instruction returns a :ref:`poison value <poisonvalues>`. 9203If the arguments are vectors, each vector element of ``op1`` is shifted 9204by the corresponding shift amount in ``op2``. 9205 9206If the ``nuw`` keyword is present, then the shift produces a poison 9207value if it shifts out any non-zero bits. 9208If the ``nsw`` keyword is present, then the shift produces a poison 9209value if it shifts out any bits that disagree with the resultant sign bit. 9210 9211Example: 9212"""""""" 9213 9214.. code-block:: text 9215 9216 <result> = shl i32 4, %var ; yields i32: 4 << %var 9217 <result> = shl i32 4, 2 ; yields i32: 16 9218 <result> = shl i32 1, 10 ; yields i32: 1024 9219 <result> = shl i32 1, 32 ; undefined 9220 <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4> 9221 9222.. _i_lshr: 9223 9224 9225'``lshr``' Instruction 9226^^^^^^^^^^^^^^^^^^^^^^ 9227 9228Syntax: 9229""""""" 9230 9231:: 9232 9233 <result> = lshr <ty> <op1>, <op2> ; yields ty:result 9234 <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result 9235 9236Overview: 9237""""""""" 9238 9239The '``lshr``' instruction (logical shift right) returns the first 9240operand shifted to the right a specified number of bits with zero fill. 9241 9242Arguments: 9243"""""""""" 9244 9245Both arguments to the '``lshr``' instruction must be the same 9246:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 9247'``op2``' is treated as an unsigned value. 9248 9249Semantics: 9250"""""""""" 9251 9252This instruction always performs a logical shift right operation. The 9253most significant bits of the result will be filled with zero bits after 9254the shift. If ``op2`` is (statically or dynamically) equal to or larger 9255than the number of bits in ``op1``, this instruction returns a :ref:`poison 9256value <poisonvalues>`. If the arguments are vectors, each vector element 9257of ``op1`` is shifted by the corresponding shift amount in ``op2``. 9258 9259If the ``exact`` keyword is present, the result value of the ``lshr`` is 9260a poison value if any of the bits shifted out are non-zero. 9261 9262Example: 9263"""""""" 9264 9265.. code-block:: text 9266 9267 <result> = lshr i32 4, 1 ; yields i32:result = 2 9268 <result> = lshr i32 4, 2 ; yields i32:result = 1 9269 <result> = lshr i8 4, 3 ; yields i8:result = 0 9270 <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F 9271 <result> = lshr i32 1, 32 ; undefined 9272 <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1> 9273 9274.. _i_ashr: 9275 9276'``ashr``' Instruction 9277^^^^^^^^^^^^^^^^^^^^^^ 9278 9279Syntax: 9280""""""" 9281 9282:: 9283 9284 <result> = ashr <ty> <op1>, <op2> ; yields ty:result 9285 <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result 9286 9287Overview: 9288""""""""" 9289 9290The '``ashr``' instruction (arithmetic shift right) returns the first 9291operand shifted to the right a specified number of bits with sign 9292extension. 9293 9294Arguments: 9295"""""""""" 9296 9297Both arguments to the '``ashr``' instruction must be the same 9298:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 9299'``op2``' is treated as an unsigned value. 9300 9301Semantics: 9302"""""""""" 9303 9304This instruction always performs an arithmetic shift right operation, 9305The most significant bits of the result will be filled with the sign bit 9306of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger 9307than the number of bits in ``op1``, this instruction returns a :ref:`poison 9308value <poisonvalues>`. If the arguments are vectors, each vector element 9309of ``op1`` is shifted by the corresponding shift amount in ``op2``. 9310 9311If the ``exact`` keyword is present, the result value of the ``ashr`` is 9312a poison value if any of the bits shifted out are non-zero. 9313 9314Example: 9315"""""""" 9316 9317.. code-block:: text 9318 9319 <result> = ashr i32 4, 1 ; yields i32:result = 2 9320 <result> = ashr i32 4, 2 ; yields i32:result = 1 9321 <result> = ashr i8 4, 3 ; yields i8:result = 0 9322 <result> = ashr i8 -2, 1 ; yields i8:result = -1 9323 <result> = ashr i32 1, 32 ; undefined 9324 <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0> 9325 9326.. _i_and: 9327 9328'``and``' Instruction 9329^^^^^^^^^^^^^^^^^^^^^ 9330 9331Syntax: 9332""""""" 9333 9334:: 9335 9336 <result> = and <ty> <op1>, <op2> ; yields ty:result 9337 9338Overview: 9339""""""""" 9340 9341The '``and``' instruction returns the bitwise logical and of its two 9342operands. 9343 9344Arguments: 9345"""""""""" 9346 9347The two arguments to the '``and``' instruction must be 9348:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9349arguments must have identical types. 9350 9351Semantics: 9352"""""""""" 9353 9354The truth table used for the '``and``' instruction is: 9355 9356+-----+-----+-----+ 9357| In0 | In1 | Out | 9358+-----+-----+-----+ 9359| 0 | 0 | 0 | 9360+-----+-----+-----+ 9361| 0 | 1 | 0 | 9362+-----+-----+-----+ 9363| 1 | 0 | 0 | 9364+-----+-----+-----+ 9365| 1 | 1 | 1 | 9366+-----+-----+-----+ 9367 9368Example: 9369"""""""" 9370 9371.. code-block:: text 9372 9373 <result> = and i32 4, %var ; yields i32:result = 4 & %var 9374 <result> = and i32 15, 40 ; yields i32:result = 8 9375 <result> = and i32 4, 8 ; yields i32:result = 0 9376 9377.. _i_or: 9378 9379'``or``' Instruction 9380^^^^^^^^^^^^^^^^^^^^ 9381 9382Syntax: 9383""""""" 9384 9385:: 9386 9387 <result> = or <ty> <op1>, <op2> ; yields ty:result 9388 9389Overview: 9390""""""""" 9391 9392The '``or``' instruction returns the bitwise logical inclusive or of its 9393two operands. 9394 9395Arguments: 9396"""""""""" 9397 9398The two arguments to the '``or``' instruction must be 9399:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9400arguments must have identical types. 9401 9402Semantics: 9403"""""""""" 9404 9405The truth table used for the '``or``' instruction is: 9406 9407+-----+-----+-----+ 9408| In0 | In1 | Out | 9409+-----+-----+-----+ 9410| 0 | 0 | 0 | 9411+-----+-----+-----+ 9412| 0 | 1 | 1 | 9413+-----+-----+-----+ 9414| 1 | 0 | 1 | 9415+-----+-----+-----+ 9416| 1 | 1 | 1 | 9417+-----+-----+-----+ 9418 9419Example: 9420"""""""" 9421 9422:: 9423 9424 <result> = or i32 4, %var ; yields i32:result = 4 | %var 9425 <result> = or i32 15, 40 ; yields i32:result = 47 9426 <result> = or i32 4, 8 ; yields i32:result = 12 9427 9428.. _i_xor: 9429 9430'``xor``' Instruction 9431^^^^^^^^^^^^^^^^^^^^^ 9432 9433Syntax: 9434""""""" 9435 9436:: 9437 9438 <result> = xor <ty> <op1>, <op2> ; yields ty:result 9439 9440Overview: 9441""""""""" 9442 9443The '``xor``' instruction returns the bitwise logical exclusive or of 9444its two operands. The ``xor`` is used to implement the "one's 9445complement" operation, which is the "~" operator in C. 9446 9447Arguments: 9448"""""""""" 9449 9450The two arguments to the '``xor``' instruction must be 9451:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9452arguments must have identical types. 9453 9454Semantics: 9455"""""""""" 9456 9457The truth table used for the '``xor``' instruction is: 9458 9459+-----+-----+-----+ 9460| In0 | In1 | Out | 9461+-----+-----+-----+ 9462| 0 | 0 | 0 | 9463+-----+-----+-----+ 9464| 0 | 1 | 1 | 9465+-----+-----+-----+ 9466| 1 | 0 | 1 | 9467+-----+-----+-----+ 9468| 1 | 1 | 0 | 9469+-----+-----+-----+ 9470 9471Example: 9472"""""""" 9473 9474.. code-block:: text 9475 9476 <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var 9477 <result> = xor i32 15, 40 ; yields i32:result = 39 9478 <result> = xor i32 4, 8 ; yields i32:result = 12 9479 <result> = xor i32 %V, -1 ; yields i32:result = ~%V 9480 9481Vector Operations 9482----------------- 9483 9484LLVM supports several instructions to represent vector operations in a 9485target-independent manner. These instructions cover the element-access 9486and vector-specific operations needed to process vectors effectively. 9487While LLVM does directly support these vector operations, many 9488sophisticated algorithms will want to use target-specific intrinsics to 9489take full advantage of a specific target. 9490 9491.. _i_extractelement: 9492 9493'``extractelement``' Instruction 9494^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9495 9496Syntax: 9497""""""" 9498 9499:: 9500 9501 <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty> 9502 <result> = extractelement <vscale x n x <ty>> <val>, <ty2> <idx> ; yields <ty> 9503 9504Overview: 9505""""""""" 9506 9507The '``extractelement``' instruction extracts a single scalar element 9508from a vector at a specified index. 9509 9510Arguments: 9511"""""""""" 9512 9513The first operand of an '``extractelement``' instruction is a value of 9514:ref:`vector <t_vector>` type. The second operand is an index indicating 9515the position from which to extract the element. The index may be a 9516variable of any integer type. 9517 9518Semantics: 9519"""""""""" 9520 9521The result is a scalar of the same type as the element type of ``val``. 9522Its value is the value at position ``idx`` of ``val``. If ``idx`` 9523exceeds the length of ``val`` for a fixed-length vector, the result is a 9524:ref:`poison value <poisonvalues>`. For a scalable vector, if the value 9525of ``idx`` exceeds the runtime length of the vector, the result is a 9526:ref:`poison value <poisonvalues>`. 9527 9528Example: 9529"""""""" 9530 9531.. code-block:: text 9532 9533 <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32 9534 9535.. _i_insertelement: 9536 9537'``insertelement``' Instruction 9538^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9539 9540Syntax: 9541""""""" 9542 9543:: 9544 9545 <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>> 9546 <result> = insertelement <vscale x n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <vscale x n x <ty>> 9547 9548Overview: 9549""""""""" 9550 9551The '``insertelement``' instruction inserts a scalar element into a 9552vector at a specified index. 9553 9554Arguments: 9555"""""""""" 9556 9557The first operand of an '``insertelement``' instruction is a value of 9558:ref:`vector <t_vector>` type. The second operand is a scalar value whose 9559type must equal the element type of the first operand. The third operand 9560is an index indicating the position at which to insert the value. The 9561index may be a variable of any integer type. 9562 9563Semantics: 9564"""""""""" 9565 9566The result is a vector of the same type as ``val``. Its element values 9567are those of ``val`` except at position ``idx``, where it gets the value 9568``elt``. If ``idx`` exceeds the length of ``val`` for a fixed-length vector, 9569the result is a :ref:`poison value <poisonvalues>`. For a scalable vector, 9570if the value of ``idx`` exceeds the runtime length of the vector, the result 9571is a :ref:`poison value <poisonvalues>`. 9572 9573Example: 9574"""""""" 9575 9576.. code-block:: text 9577 9578 <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32> 9579 9580.. _i_shufflevector: 9581 9582'``shufflevector``' Instruction 9583^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9584 9585Syntax: 9586""""""" 9587 9588:: 9589 9590 <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>> 9591 <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>> 9592 9593Overview: 9594""""""""" 9595 9596The '``shufflevector``' instruction constructs a permutation of elements 9597from two input vectors, returning a vector with the same element type as 9598the input and length that is the same as the shuffle mask. 9599 9600Arguments: 9601"""""""""" 9602 9603The first two operands of a '``shufflevector``' instruction are vectors 9604with the same type. The third argument is a shuffle mask vector constant 9605whose element type is ``i32``. The mask vector elements must be constant 9606integers or ``undef`` values. The result of the instruction is a vector 9607whose length is the same as the shuffle mask and whose element type is the 9608same as the element type of the first two operands. 9609 9610Semantics: 9611"""""""""" 9612 9613The elements of the two input vectors are numbered from left to right 9614across both of the vectors. For each element of the result vector, the 9615shuffle mask selects an element from one of the input vectors to copy 9616to the result. Non-negative elements in the mask represent an index 9617into the concatenated pair of input vectors. 9618 9619If the shuffle mask is undefined, the result vector is undefined. If 9620the shuffle mask selects an undefined element from one of the input 9621vectors, the resulting element is undefined. An undefined element 9622in the mask vector specifies that the resulting element is undefined. 9623An undefined element in the mask vector prevents a poisoned vector 9624element from propagating. 9625 9626For scalable vectors, the only valid mask values at present are 9627``zeroinitializer`` and ``undef``, since we cannot write all indices as 9628literals for a vector with a length unknown at compile time. 9629 9630Example: 9631"""""""" 9632 9633.. code-block:: text 9634 9635 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2, 9636 <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32> 9637 <result> = shufflevector <4 x i32> %v1, <4 x i32> undef, 9638 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle. 9639 <result> = shufflevector <8 x i32> %v1, <8 x i32> undef, 9640 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> 9641 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2, 9642 <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32> 9643 9644Aggregate Operations 9645-------------------- 9646 9647LLVM supports several instructions for working with 9648:ref:`aggregate <t_aggregate>` values. 9649 9650.. _i_extractvalue: 9651 9652'``extractvalue``' Instruction 9653^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9654 9655Syntax: 9656""""""" 9657 9658:: 9659 9660 <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}* 9661 9662Overview: 9663""""""""" 9664 9665The '``extractvalue``' instruction extracts the value of a member field 9666from an :ref:`aggregate <t_aggregate>` value. 9667 9668Arguments: 9669"""""""""" 9670 9671The first operand of an '``extractvalue``' instruction is a value of 9672:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are 9673constant indices to specify which value to extract in a similar manner 9674as indices in a '``getelementptr``' instruction. 9675 9676The major differences to ``getelementptr`` indexing are: 9677 9678- Since the value being indexed is not a pointer, the first index is 9679 omitted and assumed to be zero. 9680- At least one index must be specified. 9681- Not only struct indices but also array indices must be in bounds. 9682 9683Semantics: 9684"""""""""" 9685 9686The result is the value at the position in the aggregate specified by 9687the index operands. 9688 9689Example: 9690"""""""" 9691 9692.. code-block:: text 9693 9694 <result> = extractvalue {i32, float} %agg, 0 ; yields i32 9695 9696.. _i_insertvalue: 9697 9698'``insertvalue``' Instruction 9699^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9700 9701Syntax: 9702""""""" 9703 9704:: 9705 9706 <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type> 9707 9708Overview: 9709""""""""" 9710 9711The '``insertvalue``' instruction inserts a value into a member field in 9712an :ref:`aggregate <t_aggregate>` value. 9713 9714Arguments: 9715"""""""""" 9716 9717The first operand of an '``insertvalue``' instruction is a value of 9718:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is 9719a first-class value to insert. The following operands are constant 9720indices indicating the position at which to insert the value in a 9721similar manner as indices in a '``extractvalue``' instruction. The value 9722to insert must have the same type as the value identified by the 9723indices. 9724 9725Semantics: 9726"""""""""" 9727 9728The result is an aggregate of the same type as ``val``. Its value is 9729that of ``val`` except that the value at the position specified by the 9730indices is that of ``elt``. 9731 9732Example: 9733"""""""" 9734 9735.. code-block:: llvm 9736 9737 %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef} 9738 %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val} 9739 %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}} 9740 9741.. _memoryops: 9742 9743Memory Access and Addressing Operations 9744--------------------------------------- 9745 9746A key design point of an SSA-based representation is how it represents 9747memory. In LLVM, no memory locations are in SSA form, which makes things 9748very simple. This section describes how to read, write, and allocate 9749memory in LLVM. 9750 9751.. _i_alloca: 9752 9753'``alloca``' Instruction 9754^^^^^^^^^^^^^^^^^^^^^^^^ 9755 9756Syntax: 9757""""""" 9758 9759:: 9760 9761 <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result 9762 9763Overview: 9764""""""""" 9765 9766The '``alloca``' instruction allocates memory on the stack frame of the 9767currently executing function, to be automatically released when this 9768function returns to its caller. If the address space is not explicitly 9769specified, the object is allocated in the alloca address space from the 9770:ref:`datalayout string<langref_datalayout>`. 9771 9772Arguments: 9773"""""""""" 9774 9775The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements`` 9776bytes of memory on the runtime stack, returning a pointer of the 9777appropriate type to the program. If "NumElements" is specified, it is 9778the number of elements allocated, otherwise "NumElements" is defaulted 9779to be one. If a constant alignment is specified, the value result of the 9780allocation is guaranteed to be aligned to at least that boundary. The 9781alignment may not be greater than ``1 << 32``. If not specified, or if 9782zero, the target can choose to align the allocation on any convenient 9783boundary compatible with the type. 9784 9785'``type``' may be any sized type. 9786 9787Semantics: 9788"""""""""" 9789 9790Memory is allocated; a pointer is returned. The allocated memory is 9791uninitialized, and loading from uninitialized memory produces an undefined 9792value. The operation itself is undefined if there is insufficient stack 9793space for the allocation.'``alloca``'d memory is automatically released 9794when the function returns. The '``alloca``' instruction is commonly used 9795to represent automatic variables that must have an address available. When 9796the function returns (either with the ``ret`` or ``resume`` instructions), 9797the memory is reclaimed. Allocating zero bytes is legal, but the returned 9798pointer may not be unique. The order in which memory is allocated (ie., 9799which way the stack grows) is not specified. 9800 9801Note that '``alloca``' outside of the alloca address space from the 9802:ref:`datalayout string<langref_datalayout>` is meaningful only if the 9803target has assigned it a semantics. 9804 9805If the returned pointer is used by :ref:`llvm.lifetime.start <int_lifestart>`, 9806the returned object is initially dead. 9807See :ref:`llvm.lifetime.start <int_lifestart>` and 9808:ref:`llvm.lifetime.end <int_lifeend>` for the precise semantics of 9809lifetime-manipulating intrinsics. 9810 9811Example: 9812"""""""" 9813 9814.. code-block:: llvm 9815 9816 %ptr = alloca i32 ; yields i32*:ptr 9817 %ptr = alloca i32, i32 4 ; yields i32*:ptr 9818 %ptr = alloca i32, i32 4, align 1024 ; yields i32*:ptr 9819 %ptr = alloca i32, align 1024 ; yields i32*:ptr 9820 9821.. _i_load: 9822 9823'``load``' Instruction 9824^^^^^^^^^^^^^^^^^^^^^^ 9825 9826Syntax: 9827""""""" 9828 9829:: 9830 9831 <result> = load [volatile] <ty>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<nontemp_node>][, !invariant.load !<empty_node>][, !invariant.group !<empty_node>][, !nonnull !<empty_node>][, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>][, !align !<align_node>][, !noundef !<empty_node>] 9832 <result> = load atomic [volatile] <ty>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>] 9833 !<nontemp_node> = !{ i32 1 } 9834 !<empty_node> = !{} 9835 !<deref_bytes_node> = !{ i64 <dereferenceable_bytes> } 9836 !<align_node> = !{ i64 <value_alignment> } 9837 9838Overview: 9839""""""""" 9840 9841The '``load``' instruction is used to read from memory. 9842 9843Arguments: 9844"""""""""" 9845 9846The argument to the ``load`` instruction specifies the memory address from which 9847to load. The type specified must be a :ref:`first class <t_firstclass>` type of 9848known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If 9849the ``load`` is marked as ``volatile``, then the optimizer is not allowed to 9850modify the number or order of execution of this ``load`` with other 9851:ref:`volatile operations <volatile>`. 9852 9853If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering 9854<ordering>` and optional ``syncscope("<target-scope>")`` argument. The 9855``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions. 9856Atomic loads produce :ref:`defined <memmodel>` results when they may see 9857multiple atomic stores. The type of the pointee must be an integer, pointer, or 9858floating-point type whose bit width is a power of two greater than or equal to 9859eight and less than or equal to a target-specific size limit. ``align`` must be 9860explicitly specified on atomic loads, and the load has undefined behavior if the 9861alignment is not set to a value which is at least the size in bytes of the 9862pointee. ``!nontemporal`` does not have any defined semantics for atomic loads. 9863 9864The optional constant ``align`` argument specifies the alignment of the 9865operation (that is, the alignment of the memory address). A value of 0 9866or an omitted ``align`` argument means that the operation has the ABI 9867alignment for the target. It is the responsibility of the code emitter 9868to ensure that the alignment information is correct. Overestimating the 9869alignment results in undefined behavior. Underestimating the alignment 9870may produce less efficient code. An alignment of 1 is always safe. The 9871maximum possible alignment is ``1 << 32``. An alignment value higher 9872than the size of the loaded type implies memory up to the alignment 9873value bytes can be safely loaded without trapping in the default 9874address space. Access of the high bytes can interfere with debugging 9875tools, so should not be accessed if the function has the 9876``sanitize_thread`` or ``sanitize_address`` attributes. 9877 9878The optional ``!nontemporal`` metadata must reference a single 9879metadata name ``<nontemp_node>`` corresponding to a metadata node with one 9880``i32`` entry of value 1. The existence of the ``!nontemporal`` 9881metadata on the instruction tells the optimizer and code generator 9882that this load is not expected to be reused in the cache. The code 9883generator may select special instructions to save cache bandwidth, such 9884as the ``MOVNT`` instruction on x86. 9885 9886The optional ``!invariant.load`` metadata must reference a single 9887metadata name ``<empty_node>`` corresponding to a metadata node with no 9888entries. If a load instruction tagged with the ``!invariant.load`` 9889metadata is executed, the memory location referenced by the load has 9890to contain the same value at all points in the program where the 9891memory location is dereferenceable; otherwise, the behavior is 9892undefined. 9893 9894The optional ``!invariant.group`` metadata must reference a single metadata name 9895 ``<empty_node>`` corresponding to a metadata node with no entries. 9896 See ``invariant.group`` metadata :ref:`invariant.group <md_invariant.group>`. 9897 9898The optional ``!nonnull`` metadata must reference a single 9899metadata name ``<empty_node>`` corresponding to a metadata node with no 9900entries. The existence of the ``!nonnull`` metadata on the 9901instruction tells the optimizer that the value loaded is known to 9902never be null. If the value is null at runtime, the behavior is undefined. 9903This is analogous to the ``nonnull`` attribute on parameters and return 9904values. This metadata can only be applied to loads of a pointer type. 9905 9906The optional ``!dereferenceable`` metadata must reference a single metadata 9907name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64`` 9908entry. 9909See ``dereferenceable`` metadata :ref:`dereferenceable <md_dereferenceable>`. 9910 9911The optional ``!dereferenceable_or_null`` metadata must reference a single 9912metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one 9913``i64`` entry. 9914See ``dereferenceable_or_null`` metadata :ref:`dereferenceable_or_null 9915<md_dereferenceable_or_null>`. 9916 9917The optional ``!align`` metadata must reference a single metadata name 9918``<align_node>`` corresponding to a metadata node with one ``i64`` entry. 9919The existence of the ``!align`` metadata on the instruction tells the 9920optimizer that the value loaded is known to be aligned to a boundary specified 9921by the integer value in the metadata node. The alignment must be a power of 2. 9922This is analogous to the ''align'' attribute on parameters and return values. 9923This metadata can only be applied to loads of a pointer type. If the returned 9924value is not appropriately aligned at runtime, the behavior is undefined. 9925 9926The optional ``!noundef`` metadata must reference a single metadata name 9927``<empty_node>`` corresponding to a node with no entries. The existence of 9928``!noundef`` metadata on the instruction tells the optimizer that the value 9929loaded is known to be :ref:`well defined <welldefinedvalues>`. 9930If the value isn't well defined, the behavior is undefined. 9931 9932Semantics: 9933"""""""""" 9934 9935The location of memory pointed to is loaded. If the value being loaded 9936is of scalar type then the number of bytes read does not exceed the 9937minimum number of bytes needed to hold all bits of the type. For 9938example, loading an ``i24`` reads at most three bytes. When loading a 9939value of a type like ``i20`` with a size that is not an integral number 9940of bytes, the result is undefined if the value was not originally 9941written using a store of the same type. 9942If the value being loaded is of aggregate type, the bytes that correspond to 9943padding may be accessed but are ignored, because it is impossible to observe 9944padding from the loaded aggregate value. 9945If ``<pointer>`` is not a well-defined value, the behavior is undefined. 9946 9947Examples: 9948""""""""" 9949 9950.. code-block:: llvm 9951 9952 %ptr = alloca i32 ; yields i32*:ptr 9953 store i32 3, i32* %ptr ; yields void 9954 %val = load i32, i32* %ptr ; yields i32:val = i32 3 9955 9956.. _i_store: 9957 9958'``store``' Instruction 9959^^^^^^^^^^^^^^^^^^^^^^^ 9960 9961Syntax: 9962""""""" 9963 9964:: 9965 9966 store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<nontemp_node>][, !invariant.group !<empty_node>] ; yields void 9967 store atomic [volatile] <ty> <value>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>] ; yields void 9968 !<nontemp_node> = !{ i32 1 } 9969 !<empty_node> = !{} 9970 9971Overview: 9972""""""""" 9973 9974The '``store``' instruction is used to write to memory. 9975 9976Arguments: 9977"""""""""" 9978 9979There are two arguments to the ``store`` instruction: a value to store and an 9980address at which to store it. The type of the ``<pointer>`` operand must be a 9981pointer to the :ref:`first class <t_firstclass>` type of the ``<value>`` 9982operand. If the ``store`` is marked as ``volatile``, then the optimizer is not 9983allowed to modify the number or order of execution of this ``store`` with other 9984:ref:`volatile operations <volatile>`. Only values of :ref:`first class 9985<t_firstclass>` types of known size (i.e. not containing an :ref:`opaque 9986structural type <t_opaque>`) can be stored. 9987 9988If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering 9989<ordering>` and optional ``syncscope("<target-scope>")`` argument. The 9990``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions. 9991Atomic loads produce :ref:`defined <memmodel>` results when they may see 9992multiple atomic stores. The type of the pointee must be an integer, pointer, or 9993floating-point type whose bit width is a power of two greater than or equal to 9994eight and less than or equal to a target-specific size limit. ``align`` must be 9995explicitly specified on atomic stores, and the store has undefined behavior if 9996the alignment is not set to a value which is at least the size in bytes of the 9997pointee. ``!nontemporal`` does not have any defined semantics for atomic stores. 9998 9999The optional constant ``align`` argument specifies the alignment of the 10000operation (that is, the alignment of the memory address). A value of 0 10001or an omitted ``align`` argument means that the operation has the ABI 10002alignment for the target. It is the responsibility of the code emitter 10003to ensure that the alignment information is correct. Overestimating the 10004alignment results in undefined behavior. Underestimating the 10005alignment may produce less efficient code. An alignment of 1 is always 10006safe. The maximum possible alignment is ``1 << 32``. An alignment 10007value higher than the size of the stored type implies memory up to the 10008alignment value bytes can be stored to without trapping in the default 10009address space. Storing to the higher bytes however may result in data 10010races if another thread can access the same address. Introducing a 10011data race is not allowed. Storing to the extra bytes is not allowed 10012even in situations where a data race is known to not exist if the 10013function has the ``sanitize_address`` attribute. 10014 10015The optional ``!nontemporal`` metadata must reference a single metadata 10016name ``<nontemp_node>`` corresponding to a metadata node with one ``i32`` entry 10017of value 1. The existence of the ``!nontemporal`` metadata on the instruction 10018tells the optimizer and code generator that this load is not expected to 10019be reused in the cache. The code generator may select special 10020instructions to save cache bandwidth, such as the ``MOVNT`` instruction on 10021x86. 10022 10023The optional ``!invariant.group`` metadata must reference a 10024single metadata name ``<empty_node>``. See ``invariant.group`` metadata. 10025 10026Semantics: 10027"""""""""" 10028 10029The contents of memory are updated to contain ``<value>`` at the 10030location specified by the ``<pointer>`` operand. If ``<value>`` is 10031of scalar type then the number of bytes written does not exceed the 10032minimum number of bytes needed to hold all bits of the type. For 10033example, storing an ``i24`` writes at most three bytes. When writing a 10034value of a type like ``i20`` with a size that is not an integral number 10035of bytes, it is unspecified what happens to the extra bits that do not 10036belong to the type, but they will typically be overwritten. 10037If ``<value>`` is of aggregate type, padding is filled with 10038:ref:`undef <undefvalues>`. 10039If ``<pointer>`` is not a well-defined value, the behavior is undefined. 10040 10041Example: 10042"""""""" 10043 10044.. code-block:: llvm 10045 10046 %ptr = alloca i32 ; yields i32*:ptr 10047 store i32 3, i32* %ptr ; yields void 10048 %val = load i32, i32* %ptr ; yields i32:val = i32 3 10049 10050.. _i_fence: 10051 10052'``fence``' Instruction 10053^^^^^^^^^^^^^^^^^^^^^^^ 10054 10055Syntax: 10056""""""" 10057 10058:: 10059 10060 fence [syncscope("<target-scope>")] <ordering> ; yields void 10061 10062Overview: 10063""""""""" 10064 10065The '``fence``' instruction is used to introduce happens-before edges 10066between operations. 10067 10068Arguments: 10069"""""""""" 10070 10071'``fence``' instructions take an :ref:`ordering <ordering>` argument which 10072defines what *synchronizes-with* edges they add. They can only be given 10073``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings. 10074 10075Semantics: 10076"""""""""" 10077 10078A fence A which has (at least) ``release`` ordering semantics 10079*synchronizes with* a fence B with (at least) ``acquire`` ordering 10080semantics if and only if there exist atomic operations X and Y, both 10081operating on some atomic object M, such that A is sequenced before X, X 10082modifies M (either directly or through some side effect of a sequence 10083headed by X), Y is sequenced before B, and Y observes M. This provides a 10084*happens-before* dependency between A and B. Rather than an explicit 10085``fence``, one (but not both) of the atomic operations X or Y might 10086provide a ``release`` or ``acquire`` (resp.) ordering constraint and 10087still *synchronize-with* the explicit ``fence`` and establish the 10088*happens-before* edge. 10089 10090A ``fence`` which has ``seq_cst`` ordering, in addition to having both 10091``acquire`` and ``release`` semantics specified above, participates in 10092the global program order of other ``seq_cst`` operations and/or fences. 10093 10094A ``fence`` instruction can also take an optional 10095":ref:`syncscope <syncscope>`" argument. 10096 10097Example: 10098"""""""" 10099 10100.. code-block:: text 10101 10102 fence acquire ; yields void 10103 fence syncscope("singlethread") seq_cst ; yields void 10104 fence syncscope("agent") seq_cst ; yields void 10105 10106.. _i_cmpxchg: 10107 10108'``cmpxchg``' Instruction 10109^^^^^^^^^^^^^^^^^^^^^^^^^ 10110 10111Syntax: 10112""""""" 10113 10114:: 10115 10116 cmpxchg [weak] [volatile] <ty>* <pointer>, <ty> <cmp>, <ty> <new> [syncscope("<target-scope>")] <success ordering> <failure ordering>[, align <alignment>] ; yields { ty, i1 } 10117 10118Overview: 10119""""""""" 10120 10121The '``cmpxchg``' instruction is used to atomically modify memory. It 10122loads a value in memory and compares it to a given value. If they are 10123equal, it tries to store a new value into the memory. 10124 10125Arguments: 10126"""""""""" 10127 10128There are three arguments to the '``cmpxchg``' instruction: an address 10129to operate on, a value to compare to the value currently be at that 10130address, and a new value to place at that address if the compared values 10131are equal. The type of '<cmp>' must be an integer or pointer type whose 10132bit width is a power of two greater than or equal to eight and less 10133than or equal to a target-specific size limit. '<cmp>' and '<new>' must 10134have the same type, and the type of '<pointer>' must be a pointer to 10135that type. If the ``cmpxchg`` is marked as ``volatile``, then the 10136optimizer is not allowed to modify the number or order of execution of 10137this ``cmpxchg`` with other :ref:`volatile operations <volatile>`. 10138 10139The success and failure :ref:`ordering <ordering>` arguments specify how this 10140``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters 10141must be at least ``monotonic``, the failure ordering cannot be either 10142``release`` or ``acq_rel``. 10143 10144A ``cmpxchg`` instruction can also take an optional 10145":ref:`syncscope <syncscope>`" argument. 10146 10147The instruction can take an optional ``align`` attribute. 10148The alignment must be a power of two greater or equal to the size of the 10149`<value>` type. If unspecified, the alignment is assumed to be equal to the 10150size of the '<value>' type. Note that this default alignment assumption is 10151different from the alignment used for the load/store instructions when align 10152isn't specified. 10153 10154The pointer passed into cmpxchg must have alignment greater than or 10155equal to the size in memory of the operand. 10156 10157Semantics: 10158"""""""""" 10159 10160The contents of memory at the location specified by the '``<pointer>``' operand 10161is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is 10162written to the location. The original value at the location is returned, 10163together with a flag indicating success (true) or failure (false). 10164 10165If the cmpxchg operation is marked as ``weak`` then a spurious failure is 10166permitted: the operation may not write ``<new>`` even if the comparison 10167matched. 10168 10169If the cmpxchg operation is strong (the default), the i1 value is 1 if and only 10170if the value loaded equals ``cmp``. 10171 10172A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of 10173identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic 10174load with an ordering parameter determined the second ordering parameter. 10175 10176Example: 10177"""""""" 10178 10179.. code-block:: llvm 10180 10181 entry: 10182 %orig = load atomic i32, i32* %ptr unordered, align 4 ; yields i32 10183 br label %loop 10184 10185 loop: 10186 %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop] 10187 %squared = mul i32 %cmp, %cmp 10188 %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 } 10189 %value_loaded = extractvalue { i32, i1 } %val_success, 0 10190 %success = extractvalue { i32, i1 } %val_success, 1 10191 br i1 %success, label %done, label %loop 10192 10193 done: 10194 ... 10195 10196.. _i_atomicrmw: 10197 10198'``atomicrmw``' Instruction 10199^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10200 10201Syntax: 10202""""""" 10203 10204:: 10205 10206 atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering>[, align <alignment>] ; yields ty 10207 10208Overview: 10209""""""""" 10210 10211The '``atomicrmw``' instruction is used to atomically modify memory. 10212 10213Arguments: 10214"""""""""" 10215 10216There are three arguments to the '``atomicrmw``' instruction: an 10217operation to apply, an address whose value to modify, an argument to the 10218operation. The operation must be one of the following keywords: 10219 10220- xchg 10221- add 10222- sub 10223- and 10224- nand 10225- or 10226- xor 10227- max 10228- min 10229- umax 10230- umin 10231- fadd 10232- fsub 10233 10234For most of these operations, the type of '<value>' must be an integer 10235type whose bit width is a power of two greater than or equal to eight 10236and less than or equal to a target-specific size limit. For xchg, this 10237may also be a floating point type with the same size constraints as 10238integers. For fadd/fsub, this must be a floating point type. The 10239type of the '``<pointer>``' operand must be a pointer to that type. If 10240the ``atomicrmw`` is marked as ``volatile``, then the optimizer is not 10241allowed to modify the number or order of execution of this 10242``atomicrmw`` with other :ref:`volatile operations <volatile>`. 10243 10244The instruction can take an optional ``align`` attribute. 10245The alignment must be a power of two greater or equal to the size of the 10246`<value>` type. If unspecified, the alignment is assumed to be equal to the 10247size of the '<value>' type. Note that this default alignment assumption is 10248different from the alignment used for the load/store instructions when align 10249isn't specified. 10250 10251A ``atomicrmw`` instruction can also take an optional 10252":ref:`syncscope <syncscope>`" argument. 10253 10254Semantics: 10255"""""""""" 10256 10257The contents of memory at the location specified by the '``<pointer>``' 10258operand are atomically read, modified, and written back. The original 10259value at the location is returned. The modification is specified by the 10260operation argument: 10261 10262- xchg: ``*ptr = val`` 10263- add: ``*ptr = *ptr + val`` 10264- sub: ``*ptr = *ptr - val`` 10265- and: ``*ptr = *ptr & val`` 10266- nand: ``*ptr = ~(*ptr & val)`` 10267- or: ``*ptr = *ptr | val`` 10268- xor: ``*ptr = *ptr ^ val`` 10269- max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison) 10270- min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison) 10271- umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned comparison) 10272- umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned comparison) 10273- fadd: ``*ptr = *ptr + val`` (using floating point arithmetic) 10274- fsub: ``*ptr = *ptr - val`` (using floating point arithmetic) 10275 10276Example: 10277"""""""" 10278 10279.. code-block:: llvm 10280 10281 %old = atomicrmw add i32* %ptr, i32 1 acquire ; yields i32 10282 10283.. _i_getelementptr: 10284 10285'``getelementptr``' Instruction 10286^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10287 10288Syntax: 10289""""""" 10290 10291:: 10292 10293 <result> = getelementptr <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}* 10294 <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}* 10295 <result> = getelementptr <ty>, <ptr vector> <ptrval>, [inrange] <vector index type> <idx> 10296 10297Overview: 10298""""""""" 10299 10300The '``getelementptr``' instruction is used to get the address of a 10301subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs 10302address calculation only and does not access memory. The instruction can also 10303be used to calculate a vector of such addresses. 10304 10305Arguments: 10306"""""""""" 10307 10308The first argument is always a type used as the basis for the calculations. 10309The second argument is always a pointer or a vector of pointers, and is the 10310base address to start from. The remaining arguments are indices 10311that indicate which of the elements of the aggregate object are indexed. 10312The interpretation of each index is dependent on the type being indexed 10313into. The first index always indexes the pointer value given as the 10314second argument, the second index indexes a value of the type pointed to 10315(not necessarily the value directly pointed to, since the first index 10316can be non-zero), etc. The first type indexed into must be a pointer 10317value, subsequent types can be arrays, vectors, and structs. Note that 10318subsequent types being indexed into can never be pointers, since that 10319would require loading the pointer before continuing calculation. 10320 10321The type of each index argument depends on the type it is indexing into. 10322When indexing into a (optionally packed) structure, only ``i32`` integer 10323**constants** are allowed (when using a vector of indices they must all 10324be the **same** ``i32`` integer constant). When indexing into an array, 10325pointer or vector, integers of any width are allowed, and they are not 10326required to be constant. These integers are treated as signed values 10327where relevant. 10328 10329For example, let's consider a C code fragment and how it gets compiled 10330to LLVM: 10331 10332.. code-block:: c 10333 10334 struct RT { 10335 char A; 10336 int B[10][20]; 10337 char C; 10338 }; 10339 struct ST { 10340 int X; 10341 double Y; 10342 struct RT Z; 10343 }; 10344 10345 int *foo(struct ST *s) { 10346 return &s[1].Z.B[5][13]; 10347 } 10348 10349The LLVM code generated by Clang is: 10350 10351.. code-block:: llvm 10352 10353 %struct.RT = type { i8, [10 x [20 x i32]], i8 } 10354 %struct.ST = type { i32, double, %struct.RT } 10355 10356 define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp { 10357 entry: 10358 %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13 10359 ret i32* %arrayidx 10360 } 10361 10362Semantics: 10363"""""""""" 10364 10365In the example above, the first index is indexing into the 10366'``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``' 10367= '``{ i32, double, %struct.RT }``' type, a structure. The second index 10368indexes into the third element of the structure, yielding a 10369'``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another 10370structure. The third index indexes into the second element of the 10371structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two 10372dimensions of the array are subscripted into, yielding an '``i32``' 10373type. The '``getelementptr``' instruction returns a pointer to this 10374element, thus computing a value of '``i32*``' type. 10375 10376Note that it is perfectly legal to index partially through a structure, 10377returning a pointer to an inner element. Because of this, the LLVM code 10378for the given testcase is equivalent to: 10379 10380.. code-block:: llvm 10381 10382 define i32* @foo(%struct.ST* %s) { 10383 %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1 ; yields %struct.ST*:%t1 10384 %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2 ; yields %struct.RT*:%t2 10385 %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3 10386 %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4 10387 %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5 10388 ret i32* %t5 10389 } 10390 10391If the ``inbounds`` keyword is present, the result value of the 10392``getelementptr`` is a :ref:`poison value <poisonvalues>` if one of the 10393following rules is violated: 10394 10395* The base pointer has an *in bounds* address of an allocated object, which 10396 means that it points into an allocated object, or to its end. The only 10397 *in bounds* address for a null pointer in the default address-space is the 10398 null pointer itself. 10399* If the type of an index is larger than the pointer index type, the 10400 truncation to the pointer index type preserves the signed value. 10401* The multiplication of an index by the type size does not wrap the pointer 10402 index type in a signed sense (``nsw``). 10403* The successive addition of offsets (without adding the base address) does 10404 not wrap the pointer index type in a signed sense (``nsw``). 10405* The successive addition of the current address, interpreted as an unsigned 10406 number, and an offset, interpreted as a signed number, does not wrap the 10407 unsigned address space and remains *in bounds* of the allocated object. 10408 As a corollary, if the added offset is non-negative, the addition does not 10409 wrap in an unsigned sense (``nuw``). 10410* In cases where the base is a vector of pointers, the ``inbounds`` keyword 10411 applies to each of the computations element-wise. 10412 10413These rules are based on the assumption that no allocated object may cross 10414the unsigned address space boundary, and no allocated object may be larger 10415than half the pointer index type space. 10416 10417If the ``inbounds`` keyword is not present, the offsets are added to the 10418base address with silently-wrapping two's complement arithmetic. If the 10419offsets have a different width from the pointer, they are sign-extended 10420or truncated to the width of the pointer. The result value of the 10421``getelementptr`` may be outside the object pointed to by the base 10422pointer. The result value may not necessarily be used to access memory 10423though, even if it happens to point into allocated storage. See the 10424:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more 10425information. 10426 10427If the ``inrange`` keyword is present before any index, loading from or 10428storing to any pointer derived from the ``getelementptr`` has undefined 10429behavior if the load or store would access memory outside of the bounds of 10430the element selected by the index marked as ``inrange``. The result of a 10431pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations 10432involving memory) involving a pointer derived from a ``getelementptr`` with 10433the ``inrange`` keyword is undefined, with the exception of comparisons 10434in the case where both operands are in the range of the element selected 10435by the ``inrange`` keyword, inclusive of the address one past the end of 10436that element. Note that the ``inrange`` keyword is currently only allowed 10437in constant ``getelementptr`` expressions. 10438 10439The getelementptr instruction is often confusing. For some more insight 10440into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`. 10441 10442Example: 10443"""""""" 10444 10445.. code-block:: llvm 10446 10447 ; yields [12 x i8]*:aptr 10448 %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1 10449 ; yields i8*:vptr 10450 %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1 10451 ; yields i8*:eptr 10452 %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1 10453 ; yields i32*:iptr 10454 %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0 10455 10456Vector of pointers: 10457""""""""""""""""""" 10458 10459The ``getelementptr`` returns a vector of pointers, instead of a single address, 10460when one or more of its arguments is a vector. In such cases, all vector 10461arguments should have the same number of elements, and every scalar argument 10462will be effectively broadcast into a vector during address calculation. 10463 10464.. code-block:: llvm 10465 10466 ; All arguments are vectors: 10467 ; A[i] = ptrs[i] + offsets[i]*sizeof(i8) 10468 %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets 10469 10470 ; Add the same scalar offset to each pointer of a vector: 10471 ; A[i] = ptrs[i] + offset*sizeof(i8) 10472 %A = getelementptr i8, <4 x i8*> %ptrs, i64 %offset 10473 10474 ; Add distinct offsets to the same pointer: 10475 ; A[i] = ptr + offsets[i]*sizeof(i8) 10476 %A = getelementptr i8, i8* %ptr, <4 x i64> %offsets 10477 10478 ; In all cases described above the type of the result is <4 x i8*> 10479 10480The two following instructions are equivalent: 10481 10482.. code-block:: llvm 10483 10484 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1, 10485 <4 x i32> <i32 2, i32 2, i32 2, i32 2>, 10486 <4 x i32> <i32 1, i32 1, i32 1, i32 1>, 10487 <4 x i32> %ind4, 10488 <4 x i64> <i64 13, i64 13, i64 13, i64 13> 10489 10490 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1, 10491 i32 2, i32 1, <4 x i32> %ind4, i64 13 10492 10493Let's look at the C code, where the vector version of ``getelementptr`` 10494makes sense: 10495 10496.. code-block:: c 10497 10498 // Let's assume that we vectorize the following loop: 10499 double *A, *B; int *C; 10500 for (int i = 0; i < size; ++i) { 10501 A[i] = B[C[i]]; 10502 } 10503 10504.. code-block:: llvm 10505 10506 ; get pointers for 8 elements from array B 10507 %ptrs = getelementptr double, double* %B, <8 x i32> %C 10508 ; load 8 elements from array B into A 10509 %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x double*> %ptrs, 10510 i32 8, <8 x i1> %mask, <8 x double> %passthru) 10511 10512Conversion Operations 10513--------------------- 10514 10515The instructions in this category are the conversion instructions 10516(casting) which all take a single operand and a type. They perform 10517various bit conversions on the operand. 10518 10519.. _i_trunc: 10520 10521'``trunc .. to``' Instruction 10522^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10523 10524Syntax: 10525""""""" 10526 10527:: 10528 10529 <result> = trunc <ty> <value> to <ty2> ; yields ty2 10530 10531Overview: 10532""""""""" 10533 10534The '``trunc``' instruction truncates its operand to the type ``ty2``. 10535 10536Arguments: 10537"""""""""" 10538 10539The '``trunc``' instruction takes a value to trunc, and a type to trunc 10540it to. Both types must be of :ref:`integer <t_integer>` types, or vectors 10541of the same number of integers. The bit size of the ``value`` must be 10542larger than the bit size of the destination type, ``ty2``. Equal sized 10543types are not allowed. 10544 10545Semantics: 10546"""""""""" 10547 10548The '``trunc``' instruction truncates the high order bits in ``value`` 10549and converts the remaining bits to ``ty2``. Since the source size must 10550be larger than the destination size, ``trunc`` cannot be a *no-op cast*. 10551It will always truncate bits. 10552 10553Example: 10554"""""""" 10555 10556.. code-block:: llvm 10557 10558 %X = trunc i32 257 to i8 ; yields i8:1 10559 %Y = trunc i32 123 to i1 ; yields i1:true 10560 %Z = trunc i32 122 to i1 ; yields i1:false 10561 %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7> 10562 10563.. _i_zext: 10564 10565'``zext .. to``' Instruction 10566^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10567 10568Syntax: 10569""""""" 10570 10571:: 10572 10573 <result> = zext <ty> <value> to <ty2> ; yields ty2 10574 10575Overview: 10576""""""""" 10577 10578The '``zext``' instruction zero extends its operand to type ``ty2``. 10579 10580Arguments: 10581"""""""""" 10582 10583The '``zext``' instruction takes a value to cast, and a type to cast it 10584to. Both types must be of :ref:`integer <t_integer>` types, or vectors of 10585the same number of integers. The bit size of the ``value`` must be 10586smaller than the bit size of the destination type, ``ty2``. 10587 10588Semantics: 10589"""""""""" 10590 10591The ``zext`` fills the high order bits of the ``value`` with zero bits 10592until it reaches the size of the destination type, ``ty2``. 10593 10594When zero extending from i1, the result will always be either 0 or 1. 10595 10596Example: 10597"""""""" 10598 10599.. code-block:: llvm 10600 10601 %X = zext i32 257 to i64 ; yields i64:257 10602 %Y = zext i1 true to i32 ; yields i32:1 10603 %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7> 10604 10605.. _i_sext: 10606 10607'``sext .. to``' Instruction 10608^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10609 10610Syntax: 10611""""""" 10612 10613:: 10614 10615 <result> = sext <ty> <value> to <ty2> ; yields ty2 10616 10617Overview: 10618""""""""" 10619 10620The '``sext``' sign extends ``value`` to the type ``ty2``. 10621 10622Arguments: 10623"""""""""" 10624 10625The '``sext``' instruction takes a value to cast, and a type to cast it 10626to. Both types must be of :ref:`integer <t_integer>` types, or vectors of 10627the same number of integers. The bit size of the ``value`` must be 10628smaller than the bit size of the destination type, ``ty2``. 10629 10630Semantics: 10631"""""""""" 10632 10633The '``sext``' instruction performs a sign extension by copying the sign 10634bit (highest order bit) of the ``value`` until it reaches the bit size 10635of the type ``ty2``. 10636 10637When sign extending from i1, the extension always results in -1 or 0. 10638 10639Example: 10640"""""""" 10641 10642.. code-block:: llvm 10643 10644 %X = sext i8 -1 to i16 ; yields i16 :65535 10645 %Y = sext i1 true to i32 ; yields i32:-1 10646 %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7> 10647 10648'``fptrunc .. to``' Instruction 10649^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10650 10651Syntax: 10652""""""" 10653 10654:: 10655 10656 <result> = fptrunc <ty> <value> to <ty2> ; yields ty2 10657 10658Overview: 10659""""""""" 10660 10661The '``fptrunc``' instruction truncates ``value`` to type ``ty2``. 10662 10663Arguments: 10664"""""""""" 10665 10666The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>` 10667value to cast and a :ref:`floating-point <t_floating>` type to cast it to. 10668The size of ``value`` must be larger than the size of ``ty2``. This 10669implies that ``fptrunc`` cannot be used to make a *no-op cast*. 10670 10671Semantics: 10672"""""""""" 10673 10674The '``fptrunc``' instruction casts a ``value`` from a larger 10675:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point 10676<t_floating>` type. 10677This instruction is assumed to execute in the default :ref:`floating-point 10678environment <floatenv>`. 10679 10680Example: 10681"""""""" 10682 10683.. code-block:: llvm 10684 10685 %X = fptrunc double 16777217.0 to float ; yields float:16777216.0 10686 %Y = fptrunc double 1.0E+300 to half ; yields half:+infinity 10687 10688'``fpext .. to``' Instruction 10689^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10690 10691Syntax: 10692""""""" 10693 10694:: 10695 10696 <result> = fpext <ty> <value> to <ty2> ; yields ty2 10697 10698Overview: 10699""""""""" 10700 10701The '``fpext``' extends a floating-point ``value`` to a larger floating-point 10702value. 10703 10704Arguments: 10705"""""""""" 10706 10707The '``fpext``' instruction takes a :ref:`floating-point <t_floating>` 10708``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it 10709to. The source type must be smaller than the destination type. 10710 10711Semantics: 10712"""""""""" 10713 10714The '``fpext``' instruction extends the ``value`` from a smaller 10715:ref:`floating-point <t_floating>` type to a larger :ref:`floating-point 10716<t_floating>` type. The ``fpext`` cannot be used to make a 10717*no-op cast* because it always changes bits. Use ``bitcast`` to make a 10718*no-op cast* for a floating-point cast. 10719 10720Example: 10721"""""""" 10722 10723.. code-block:: llvm 10724 10725 %X = fpext float 3.125 to double ; yields double:3.125000e+00 10726 %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000 10727 10728'``fptoui .. to``' Instruction 10729^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10730 10731Syntax: 10732""""""" 10733 10734:: 10735 10736 <result> = fptoui <ty> <value> to <ty2> ; yields ty2 10737 10738Overview: 10739""""""""" 10740 10741The '``fptoui``' converts a floating-point ``value`` to its unsigned 10742integer equivalent of type ``ty2``. 10743 10744Arguments: 10745"""""""""" 10746 10747The '``fptoui``' instruction takes a value to cast, which must be a 10748scalar or vector :ref:`floating-point <t_floating>` value, and a type to 10749cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If 10750``ty`` is a vector floating-point type, ``ty2`` must be a vector integer 10751type with the same number of elements as ``ty`` 10752 10753Semantics: 10754"""""""""" 10755 10756The '``fptoui``' instruction converts its :ref:`floating-point 10757<t_floating>` operand into the nearest (rounding towards zero) 10758unsigned integer value. If the value cannot fit in ``ty2``, the result 10759is a :ref:`poison value <poisonvalues>`. 10760 10761Example: 10762"""""""" 10763 10764.. code-block:: llvm 10765 10766 %X = fptoui double 123.0 to i32 ; yields i32:123 10767 %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1 10768 %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1 10769 10770'``fptosi .. to``' Instruction 10771^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10772 10773Syntax: 10774""""""" 10775 10776:: 10777 10778 <result> = fptosi <ty> <value> to <ty2> ; yields ty2 10779 10780Overview: 10781""""""""" 10782 10783The '``fptosi``' instruction converts :ref:`floating-point <t_floating>` 10784``value`` to type ``ty2``. 10785 10786Arguments: 10787"""""""""" 10788 10789The '``fptosi``' instruction takes a value to cast, which must be a 10790scalar or vector :ref:`floating-point <t_floating>` value, and a type to 10791cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If 10792``ty`` is a vector floating-point type, ``ty2`` must be a vector integer 10793type with the same number of elements as ``ty`` 10794 10795Semantics: 10796"""""""""" 10797 10798The '``fptosi``' instruction converts its :ref:`floating-point 10799<t_floating>` operand into the nearest (rounding towards zero) 10800signed integer value. If the value cannot fit in ``ty2``, the result 10801is a :ref:`poison value <poisonvalues>`. 10802 10803Example: 10804"""""""" 10805 10806.. code-block:: llvm 10807 10808 %X = fptosi double -123.0 to i32 ; yields i32:-123 10809 %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1 10810 %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1 10811 10812'``uitofp .. to``' Instruction 10813^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10814 10815Syntax: 10816""""""" 10817 10818:: 10819 10820 <result> = uitofp <ty> <value> to <ty2> ; yields ty2 10821 10822Overview: 10823""""""""" 10824 10825The '``uitofp``' instruction regards ``value`` as an unsigned integer 10826and converts that value to the ``ty2`` type. 10827 10828Arguments: 10829"""""""""" 10830 10831The '``uitofp``' instruction takes a value to cast, which must be a 10832scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to 10833``ty2``, which must be an :ref:`floating-point <t_floating>` type. If 10834``ty`` is a vector integer type, ``ty2`` must be a vector floating-point 10835type with the same number of elements as ``ty`` 10836 10837Semantics: 10838"""""""""" 10839 10840The '``uitofp``' instruction interprets its operand as an unsigned 10841integer quantity and converts it to the corresponding floating-point 10842value. If the value cannot be exactly represented, it is rounded using 10843the default rounding mode. 10844 10845 10846Example: 10847"""""""" 10848 10849.. code-block:: llvm 10850 10851 %X = uitofp i32 257 to float ; yields float:257.0 10852 %Y = uitofp i8 -1 to double ; yields double:255.0 10853 10854'``sitofp .. to``' Instruction 10855^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10856 10857Syntax: 10858""""""" 10859 10860:: 10861 10862 <result> = sitofp <ty> <value> to <ty2> ; yields ty2 10863 10864Overview: 10865""""""""" 10866 10867The '``sitofp``' instruction regards ``value`` as a signed integer and 10868converts that value to the ``ty2`` type. 10869 10870Arguments: 10871"""""""""" 10872 10873The '``sitofp``' instruction takes a value to cast, which must be a 10874scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to 10875``ty2``, which must be an :ref:`floating-point <t_floating>` type. If 10876``ty`` is a vector integer type, ``ty2`` must be a vector floating-point 10877type with the same number of elements as ``ty`` 10878 10879Semantics: 10880"""""""""" 10881 10882The '``sitofp``' instruction interprets its operand as a signed integer 10883quantity and converts it to the corresponding floating-point value. If the 10884value cannot be exactly represented, it is rounded using the default rounding 10885mode. 10886 10887Example: 10888"""""""" 10889 10890.. code-block:: llvm 10891 10892 %X = sitofp i32 257 to float ; yields float:257.0 10893 %Y = sitofp i8 -1 to double ; yields double:-1.0 10894 10895.. _i_ptrtoint: 10896 10897'``ptrtoint .. to``' Instruction 10898^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10899 10900Syntax: 10901""""""" 10902 10903:: 10904 10905 <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2 10906 10907Overview: 10908""""""""" 10909 10910The '``ptrtoint``' instruction converts the pointer or a vector of 10911pointers ``value`` to the integer (or vector of integers) type ``ty2``. 10912 10913Arguments: 10914"""""""""" 10915 10916The '``ptrtoint``' instruction takes a ``value`` to cast, which must be 10917a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a 10918type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or 10919a vector of integers type. 10920 10921Semantics: 10922"""""""""" 10923 10924The '``ptrtoint``' instruction converts ``value`` to integer type 10925``ty2`` by interpreting the pointer value as an integer and either 10926truncating or zero extending that value to the size of the integer type. 10927If ``value`` is smaller than ``ty2`` then a zero extension is done. If 10928``value`` is larger than ``ty2`` then a truncation is done. If they are 10929the same size, then nothing is done (*no-op cast*) other than a type 10930change. 10931 10932Example: 10933"""""""" 10934 10935.. code-block:: llvm 10936 10937 %X = ptrtoint i32* %P to i8 ; yields truncation on 32-bit architecture 10938 %Y = ptrtoint i32* %P to i64 ; yields zero extension on 32-bit architecture 10939 %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture 10940 10941.. _i_inttoptr: 10942 10943'``inttoptr .. to``' Instruction 10944^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10945 10946Syntax: 10947""""""" 10948 10949:: 10950 10951 <result> = inttoptr <ty> <value> to <ty2>[, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>] ; yields ty2 10952 10953Overview: 10954""""""""" 10955 10956The '``inttoptr``' instruction converts an integer ``value`` to a 10957pointer type, ``ty2``. 10958 10959Arguments: 10960"""""""""" 10961 10962The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to 10963cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>` 10964type. 10965 10966The optional ``!dereferenceable`` metadata must reference a single metadata 10967name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64`` 10968entry. 10969See ``dereferenceable`` metadata. 10970 10971The optional ``!dereferenceable_or_null`` metadata must reference a single 10972metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one 10973``i64`` entry. 10974See ``dereferenceable_or_null`` metadata. 10975 10976Semantics: 10977"""""""""" 10978 10979The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by 10980applying either a zero extension or a truncation depending on the size 10981of the integer ``value``. If ``value`` is larger than the size of a 10982pointer then a truncation is done. If ``value`` is smaller than the size 10983of a pointer then a zero extension is done. If they are the same size, 10984nothing is done (*no-op cast*). 10985 10986Example: 10987"""""""" 10988 10989.. code-block:: llvm 10990 10991 %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture 10992 %Y = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture 10993 %Z = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture 10994 %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers 10995 10996.. _i_bitcast: 10997 10998'``bitcast .. to``' Instruction 10999^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11000 11001Syntax: 11002""""""" 11003 11004:: 11005 11006 <result> = bitcast <ty> <value> to <ty2> ; yields ty2 11007 11008Overview: 11009""""""""" 11010 11011The '``bitcast``' instruction converts ``value`` to type ``ty2`` without 11012changing any bits. 11013 11014Arguments: 11015"""""""""" 11016 11017The '``bitcast``' instruction takes a value to cast, which must be a 11018non-aggregate first class value, and a type to cast it to, which must 11019also be a non-aggregate :ref:`first class <t_firstclass>` type. The 11020bit sizes of ``value`` and the destination type, ``ty2``, must be 11021identical. If the source type is a pointer, the destination type must 11022also be a pointer of the same size. This instruction supports bitwise 11023conversion of vectors to integers and to vectors of other types (as 11024long as they have the same size). 11025 11026Semantics: 11027"""""""""" 11028 11029The '``bitcast``' instruction converts ``value`` to type ``ty2``. It 11030is always a *no-op cast* because no bits change with this 11031conversion. The conversion is done as if the ``value`` had been stored 11032to memory and read back as type ``ty2``. Pointer (or vector of 11033pointers) types may only be converted to other pointer (or vector of 11034pointers) types with the same address space through this instruction. 11035To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>` 11036or :ref:`ptrtoint <i_ptrtoint>` instructions first. 11037 11038There is a caveat for bitcasts involving vector types in relation to 11039endianess. For example ``bitcast <2 x i8> <value> to i16`` puts element zero 11040of the vector in the least significant bits of the i16 for little-endian while 11041element zero ends up in the most significant bits for big-endian. 11042 11043Example: 11044"""""""" 11045 11046.. code-block:: text 11047 11048 %X = bitcast i8 255 to i8 ; yields i8 :-1 11049 %Y = bitcast i32* %x to i16* ; yields i16*:%x 11050 %Z = bitcast <2 x i32> %V to i64; ; yields i64: %V (depends on endianess) 11051 %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*> 11052 11053.. _i_addrspacecast: 11054 11055'``addrspacecast .. to``' Instruction 11056^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11057 11058Syntax: 11059""""""" 11060 11061:: 11062 11063 <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2 11064 11065Overview: 11066""""""""" 11067 11068The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in 11069address space ``n`` to type ``pty2`` in address space ``m``. 11070 11071Arguments: 11072"""""""""" 11073 11074The '``addrspacecast``' instruction takes a pointer or vector of pointer value 11075to cast and a pointer type to cast it to, which must have a different 11076address space. 11077 11078Semantics: 11079"""""""""" 11080 11081The '``addrspacecast``' instruction converts the pointer value 11082``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex 11083value modification, depending on the target and the address space 11084pair. Pointer conversions within the same address space must be 11085performed with the ``bitcast`` instruction. Note that if the address space 11086conversion is legal then both result and operand refer to the same memory 11087location. 11088 11089Example: 11090"""""""" 11091 11092.. code-block:: llvm 11093 11094 %X = addrspacecast i32* %x to i32 addrspace(1)* ; yields i32 addrspace(1)*:%x 11095 %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)* ; yields i64 addrspace(2)*:%y 11096 %Z = addrspacecast <4 x i32*> %z to <4 x float addrspace(3)*> ; yields <4 x float addrspace(3)*>:%z 11097 11098.. _otherops: 11099 11100Other Operations 11101---------------- 11102 11103The instructions in this category are the "miscellaneous" instructions, 11104which defy better classification. 11105 11106.. _i_icmp: 11107 11108'``icmp``' Instruction 11109^^^^^^^^^^^^^^^^^^^^^^ 11110 11111Syntax: 11112""""""" 11113 11114:: 11115 11116 <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result 11117 11118Overview: 11119""""""""" 11120 11121The '``icmp``' instruction returns a boolean value or a vector of 11122boolean values based on comparison of its two integer, integer vector, 11123pointer, or pointer vector operands. 11124 11125Arguments: 11126"""""""""" 11127 11128The '``icmp``' instruction takes three operands. The first operand is 11129the condition code indicating the kind of comparison to perform. It is 11130not a value, just a keyword. The possible condition codes are: 11131 11132.. _icmp_md_cc: 11133 11134#. ``eq``: equal 11135#. ``ne``: not equal 11136#. ``ugt``: unsigned greater than 11137#. ``uge``: unsigned greater or equal 11138#. ``ult``: unsigned less than 11139#. ``ule``: unsigned less or equal 11140#. ``sgt``: signed greater than 11141#. ``sge``: signed greater or equal 11142#. ``slt``: signed less than 11143#. ``sle``: signed less or equal 11144 11145The remaining two arguments must be :ref:`integer <t_integer>` or 11146:ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They 11147must also be identical types. 11148 11149Semantics: 11150"""""""""" 11151 11152The '``icmp``' compares ``op1`` and ``op2`` according to the condition 11153code given as ``cond``. The comparison performed always yields either an 11154:ref:`i1 <t_integer>` or vector of ``i1`` result, as follows: 11155 11156.. _icmp_md_cc_sem: 11157 11158#. ``eq``: yields ``true`` if the operands are equal, ``false`` 11159 otherwise. No sign interpretation is necessary or performed. 11160#. ``ne``: yields ``true`` if the operands are unequal, ``false`` 11161 otherwise. No sign interpretation is necessary or performed. 11162#. ``ugt``: interprets the operands as unsigned values and yields 11163 ``true`` if ``op1`` is greater than ``op2``. 11164#. ``uge``: interprets the operands as unsigned values and yields 11165 ``true`` if ``op1`` is greater than or equal to ``op2``. 11166#. ``ult``: interprets the operands as unsigned values and yields 11167 ``true`` if ``op1`` is less than ``op2``. 11168#. ``ule``: interprets the operands as unsigned values and yields 11169 ``true`` if ``op1`` is less than or equal to ``op2``. 11170#. ``sgt``: interprets the operands as signed values and yields ``true`` 11171 if ``op1`` is greater than ``op2``. 11172#. ``sge``: interprets the operands as signed values and yields ``true`` 11173 if ``op1`` is greater than or equal to ``op2``. 11174#. ``slt``: interprets the operands as signed values and yields ``true`` 11175 if ``op1`` is less than ``op2``. 11176#. ``sle``: interprets the operands as signed values and yields ``true`` 11177 if ``op1`` is less than or equal to ``op2``. 11178 11179If the operands are :ref:`pointer <t_pointer>` typed, the pointer values 11180are compared as if they were integers. 11181 11182If the operands are integer vectors, then they are compared element by 11183element. The result is an ``i1`` vector with the same number of elements 11184as the values being compared. Otherwise, the result is an ``i1``. 11185 11186Example: 11187"""""""" 11188 11189.. code-block:: text 11190 11191 <result> = icmp eq i32 4, 5 ; yields: result=false 11192 <result> = icmp ne float* %X, %X ; yields: result=false 11193 <result> = icmp ult i16 4, 5 ; yields: result=true 11194 <result> = icmp sgt i16 4, 5 ; yields: result=false 11195 <result> = icmp ule i16 -4, 5 ; yields: result=false 11196 <result> = icmp sge i16 4, 5 ; yields: result=false 11197 11198.. _i_fcmp: 11199 11200'``fcmp``' Instruction 11201^^^^^^^^^^^^^^^^^^^^^^ 11202 11203Syntax: 11204""""""" 11205 11206:: 11207 11208 <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result 11209 11210Overview: 11211""""""""" 11212 11213The '``fcmp``' instruction returns a boolean value or vector of boolean 11214values based on comparison of its operands. 11215 11216If the operands are floating-point scalars, then the result type is a 11217boolean (:ref:`i1 <t_integer>`). 11218 11219If the operands are floating-point vectors, then the result type is a 11220vector of boolean with the same number of elements as the operands being 11221compared. 11222 11223Arguments: 11224"""""""""" 11225 11226The '``fcmp``' instruction takes three operands. The first operand is 11227the condition code indicating the kind of comparison to perform. It is 11228not a value, just a keyword. The possible condition codes are: 11229 11230#. ``false``: no comparison, always returns false 11231#. ``oeq``: ordered and equal 11232#. ``ogt``: ordered and greater than 11233#. ``oge``: ordered and greater than or equal 11234#. ``olt``: ordered and less than 11235#. ``ole``: ordered and less than or equal 11236#. ``one``: ordered and not equal 11237#. ``ord``: ordered (no nans) 11238#. ``ueq``: unordered or equal 11239#. ``ugt``: unordered or greater than 11240#. ``uge``: unordered or greater than or equal 11241#. ``ult``: unordered or less than 11242#. ``ule``: unordered or less than or equal 11243#. ``une``: unordered or not equal 11244#. ``uno``: unordered (either nans) 11245#. ``true``: no comparison, always returns true 11246 11247*Ordered* means that neither operand is a QNAN while *unordered* means 11248that either operand may be a QNAN. 11249 11250Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point 11251<t_floating>` type or a :ref:`vector <t_vector>` of floating-point type. 11252They must have identical types. 11253 11254Semantics: 11255"""""""""" 11256 11257The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the 11258condition code given as ``cond``. If the operands are vectors, then the 11259vectors are compared element by element. Each comparison performed 11260always yields an :ref:`i1 <t_integer>` result, as follows: 11261 11262#. ``false``: always yields ``false``, regardless of operands. 11263#. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1`` 11264 is equal to ``op2``. 11265#. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1`` 11266 is greater than ``op2``. 11267#. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1`` 11268 is greater than or equal to ``op2``. 11269#. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1`` 11270 is less than ``op2``. 11271#. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1`` 11272 is less than or equal to ``op2``. 11273#. ``one``: yields ``true`` if both operands are not a QNAN and ``op1`` 11274 is not equal to ``op2``. 11275#. ``ord``: yields ``true`` if both operands are not a QNAN. 11276#. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is 11277 equal to ``op2``. 11278#. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is 11279 greater than ``op2``. 11280#. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is 11281 greater than or equal to ``op2``. 11282#. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is 11283 less than ``op2``. 11284#. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is 11285 less than or equal to ``op2``. 11286#. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is 11287 not equal to ``op2``. 11288#. ``uno``: yields ``true`` if either operand is a QNAN. 11289#. ``true``: always yields ``true``, regardless of operands. 11290 11291The ``fcmp`` instruction can also optionally take any number of 11292:ref:`fast-math flags <fastmath>`, which are optimization hints to enable 11293otherwise unsafe floating-point optimizations. 11294 11295Any set of fast-math flags are legal on an ``fcmp`` instruction, but the 11296only flags that have any effect on its semantics are those that allow 11297assumptions to be made about the values of input arguments; namely 11298``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information. 11299 11300Example: 11301"""""""" 11302 11303.. code-block:: text 11304 11305 <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false 11306 <result> = fcmp one float 4.0, 5.0 ; yields: result=true 11307 <result> = fcmp olt float 4.0, 5.0 ; yields: result=true 11308 <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false 11309 11310.. _i_phi: 11311 11312'``phi``' Instruction 11313^^^^^^^^^^^^^^^^^^^^^ 11314 11315Syntax: 11316""""""" 11317 11318:: 11319 11320 <result> = phi [fast-math-flags] <ty> [ <val0>, <label0>], ... 11321 11322Overview: 11323""""""""" 11324 11325The '``phi``' instruction is used to implement the φ node in the SSA 11326graph representing the function. 11327 11328Arguments: 11329"""""""""" 11330 11331The type of the incoming values is specified with the first type field. 11332After this, the '``phi``' instruction takes a list of pairs as 11333arguments, with one pair for each predecessor basic block of the current 11334block. Only values of :ref:`first class <t_firstclass>` type may be used as 11335the value arguments to the PHI node. Only labels may be used as the 11336label arguments. 11337 11338There must be no non-phi instructions between the start of a basic block 11339and the PHI instructions: i.e. PHI instructions must be first in a basic 11340block. 11341 11342For the purposes of the SSA form, the use of each incoming value is 11343deemed to occur on the edge from the corresponding predecessor block to 11344the current block (but after any definition of an '``invoke``' 11345instruction's return value on the same edge). 11346 11347The optional ``fast-math-flags`` marker indicates that the phi has one 11348or more :ref:`fast-math-flags <fastmath>`. These are optimization hints 11349to enable otherwise unsafe floating-point optimizations. Fast-math-flags 11350are only valid for phis that return a floating-point scalar or vector 11351type, or an array (nested to any depth) of floating-point scalar or vector 11352types. 11353 11354Semantics: 11355"""""""""" 11356 11357At runtime, the '``phi``' instruction logically takes on the value 11358specified by the pair corresponding to the predecessor basic block that 11359executed just prior to the current block. 11360 11361Example: 11362"""""""" 11363 11364.. code-block:: llvm 11365 11366 Loop: ; Infinite loop that counts from 0 on up... 11367 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ] 11368 %nextindvar = add i32 %indvar, 1 11369 br label %Loop 11370 11371.. _i_select: 11372 11373'``select``' Instruction 11374^^^^^^^^^^^^^^^^^^^^^^^^ 11375 11376Syntax: 11377""""""" 11378 11379:: 11380 11381 <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty 11382 11383 selty is either i1 or {<N x i1>} 11384 11385Overview: 11386""""""""" 11387 11388The '``select``' instruction is used to choose one value based on a 11389condition, without IR-level branching. 11390 11391Arguments: 11392"""""""""" 11393 11394The '``select``' instruction requires an 'i1' value or a vector of 'i1' 11395values indicating the condition, and two values of the same :ref:`first 11396class <t_firstclass>` type. 11397 11398#. The optional ``fast-math flags`` marker indicates that the select has one or more 11399 :ref:`fast-math flags <fastmath>`. These are optimization hints to enable 11400 otherwise unsafe floating-point optimizations. Fast-math flags are only valid 11401 for selects that return a floating-point scalar or vector type, or an array 11402 (nested to any depth) of floating-point scalar or vector types. 11403 11404Semantics: 11405"""""""""" 11406 11407If the condition is an i1 and it evaluates to 1, the instruction returns 11408the first value argument; otherwise, it returns the second value 11409argument. 11410 11411If the condition is a vector of i1, then the value arguments must be 11412vectors of the same size, and the selection is done element by element. 11413 11414If the condition is an i1 and the value arguments are vectors of the 11415same size, then an entire vector is selected. 11416 11417Example: 11418"""""""" 11419 11420.. code-block:: llvm 11421 11422 %X = select i1 true, i8 17, i8 42 ; yields i8:17 11423 11424 11425.. _i_freeze: 11426 11427'``freeze``' Instruction 11428^^^^^^^^^^^^^^^^^^^^^^^^ 11429 11430Syntax: 11431""""""" 11432 11433:: 11434 11435 <result> = freeze ty <val> ; yields ty:result 11436 11437Overview: 11438""""""""" 11439 11440The '``freeze``' instruction is used to stop propagation of 11441:ref:`undef <undefvalues>` and :ref:`poison <poisonvalues>` values. 11442 11443Arguments: 11444"""""""""" 11445 11446The '``freeze``' instruction takes a single argument. 11447 11448Semantics: 11449"""""""""" 11450 11451If the argument is ``undef`` or ``poison``, '``freeze``' returns an 11452arbitrary, but fixed, value of type '``ty``'. 11453Otherwise, this instruction is a no-op and returns the input argument. 11454All uses of a value returned by the same '``freeze``' instruction are 11455guaranteed to always observe the same value, while different '``freeze``' 11456instructions may yield different values. 11457 11458While ``undef`` and ``poison`` pointers can be frozen, the result is a 11459non-dereferenceable pointer. See the 11460:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more information. 11461If an aggregate value or vector is frozen, the operand is frozen element-wise. 11462The padding of an aggregate isn't considered, since it isn't visible 11463without storing it into memory and loading it with a different type. 11464 11465 11466Example: 11467"""""""" 11468 11469.. code-block:: text 11470 11471 %w = i32 undef 11472 %x = freeze i32 %w 11473 %y = add i32 %w, %w ; undef 11474 %z = add i32 %x, %x ; even number because all uses of %x observe 11475 ; the same value 11476 %x2 = freeze i32 %w 11477 %cmp = icmp eq i32 %x, %x2 ; can be true or false 11478 11479 ; example with vectors 11480 %v = <2 x i32> <i32 undef, i32 poison> 11481 %a = extractelement <2 x i32> %v, i32 0 ; undef 11482 %b = extractelement <2 x i32> %v, i32 1 ; poison 11483 %add = add i32 %a, %a ; undef 11484 11485 %v.fr = freeze <2 x i32> %v ; element-wise freeze 11486 %d = extractelement <2 x i32> %v.fr, i32 0 ; not undef 11487 %add.f = add i32 %d, %d ; even number 11488 11489 ; branching on frozen value 11490 %poison = add nsw i1 %k, undef ; poison 11491 %c = freeze i1 %poison 11492 br i1 %c, label %foo, label %bar ; non-deterministic branch to %foo or %bar 11493 11494 11495.. _i_call: 11496 11497'``call``' Instruction 11498^^^^^^^^^^^^^^^^^^^^^^ 11499 11500Syntax: 11501""""""" 11502 11503:: 11504 11505 <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] [addrspace(<num>)] 11506 <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] [ operand bundles ] 11507 11508Overview: 11509""""""""" 11510 11511The '``call``' instruction represents a simple function call. 11512 11513Arguments: 11514"""""""""" 11515 11516This instruction requires several arguments: 11517 11518#. The optional ``tail`` and ``musttail`` markers indicate that the optimizers 11519 should perform tail call optimization. The ``tail`` marker is a hint that 11520 `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker 11521 means that the call must be tail call optimized in order for the program to 11522 be correct. The ``musttail`` marker provides these guarantees: 11523 11524 #. The call will not cause unbounded stack growth if it is part of a 11525 recursive cycle in the call graph. 11526 #. Arguments with the :ref:`inalloca <attr_inalloca>` or 11527 :ref:`preallocated <attr_preallocated>` attribute are forwarded in place. 11528 #. If the musttail call appears in a function with the ``"thunk"`` attribute 11529 and the caller and callee both have varargs, than any unprototyped 11530 arguments in register or memory are forwarded to the callee. Similarly, 11531 the return value of the callee is returned to the caller's caller, even 11532 if a void return type is in use. 11533 11534 Both markers imply that the callee does not access allocas from the caller. 11535 The ``tail`` marker additionally implies that the callee does not access 11536 varargs from the caller. Calls marked ``musttail`` must obey the following 11537 additional rules: 11538 11539 - The call must immediately precede a :ref:`ret <i_ret>` instruction, 11540 or a pointer bitcast followed by a ret instruction. 11541 - The ret instruction must return the (possibly bitcasted) value 11542 produced by the call, undef, or void. 11543 - The calling conventions of the caller and callee must match. 11544 - The callee must be varargs iff the caller is varargs. Bitcasting a 11545 non-varargs function to the appropriate varargs type is legal so 11546 long as the non-varargs prefixes obey the other rules. 11547 - The return type must not undergo automatic conversion to an `sret` pointer. 11548 11549 In addition, if the calling convention is not `swifttailcc` or `tailcc`: 11550 11551 - All ABI-impacting function attributes, such as sret, byval, inreg, 11552 returned, and inalloca, must match. 11553 - The caller and callee prototypes must match. Pointer types of parameters 11554 or return types may differ in pointee type, but not in address space. 11555 11556 On the other hand, if the calling convention is `swifttailcc` or `swiftcc`: 11557 11558 - Only these ABI-impacting attributes attributes are allowed: sret, byval, 11559 swiftself, and swiftasync. 11560 - Prototypes are not required to match. 11561 11562 Tail call optimization for calls marked ``tail`` is guaranteed to occur if 11563 the following conditions are met: 11564 11565 - Caller and callee both have the calling convention ``fastcc`` or ``tailcc``. 11566 - The call is in tail position (ret immediately follows call and ret 11567 uses value of call or is void). 11568 - Option ``-tailcallopt`` is enabled, 11569 ``llvm::GuaranteedTailCallOpt`` is ``true``, or the calling convention 11570 is ``tailcc`` 11571 - `Platform-specific constraints are 11572 met. <CodeGenerator.html#tailcallopt>`_ 11573 11574#. The optional ``notail`` marker indicates that the optimizers should not add 11575 ``tail`` or ``musttail`` markers to the call. It is used to prevent tail 11576 call optimization from being performed on the call. 11577 11578#. The optional ``fast-math flags`` marker indicates that the call has one or more 11579 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable 11580 otherwise unsafe floating-point optimizations. Fast-math flags are only valid 11581 for calls that return a floating-point scalar or vector type, or an array 11582 (nested to any depth) of floating-point scalar or vector types. 11583 11584#. The optional "cconv" marker indicates which :ref:`calling 11585 convention <callingconv>` the call should use. If none is 11586 specified, the call defaults to using C calling conventions. The 11587 calling convention of the call must match the calling convention of 11588 the target function, or else the behavior is undefined. 11589#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 11590 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 11591 are valid here. 11592#. The optional addrspace attribute can be used to indicate the address space 11593 of the called function. If it is not specified, the program address space 11594 from the :ref:`datalayout string<langref_datalayout>` will be used. 11595#. '``ty``': the type of the call instruction itself which is also the 11596 type of the return value. Functions that return no value are marked 11597 ``void``. 11598#. '``fnty``': shall be the signature of the function being called. The 11599 argument types must match the types implied by this signature. This 11600 type can be omitted if the function is not varargs. 11601#. '``fnptrval``': An LLVM value containing a pointer to a function to 11602 be called. In most cases, this is a direct function call, but 11603 indirect ``call``'s are just as possible, calling an arbitrary pointer 11604 to function value. 11605#. '``function args``': argument list whose types match the function 11606 signature argument types and parameter attributes. All arguments must 11607 be of :ref:`first class <t_firstclass>` type. If the function signature 11608 indicates the function accepts a variable number of arguments, the 11609 extra arguments can be specified. 11610#. The optional :ref:`function attributes <fnattrs>` list. 11611#. The optional :ref:`operand bundles <opbundles>` list. 11612 11613Semantics: 11614"""""""""" 11615 11616The '``call``' instruction is used to cause control flow to transfer to 11617a specified function, with its incoming arguments bound to the specified 11618values. Upon a '``ret``' instruction in the called function, control 11619flow continues with the instruction after the function call, and the 11620return value of the function is bound to the result argument. 11621 11622Example: 11623"""""""" 11624 11625.. code-block:: llvm 11626 11627 %retval = call i32 @test(i32 %argc) 11628 call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) ; yields i32 11629 %X = tail call i32 @foo() ; yields i32 11630 %Y = tail call fastcc i32 @foo() ; yields i32 11631 call void %foo(i8 signext 97) 11632 11633 %struct.A = type { i32, i8 } 11634 %r = call %struct.A @foo() ; yields { i32, i8 } 11635 %gr = extractvalue %struct.A %r, 0 ; yields i32 11636 %gr1 = extractvalue %struct.A %r, 1 ; yields i8 11637 %Z = call void @foo() noreturn ; indicates that %foo never returns normally 11638 %ZZ = call zeroext i32 @bar() ; Return value is %zero extended 11639 11640llvm treats calls to some functions with names and arguments that match 11641the standard C99 library as being the C99 library functions, and may 11642perform optimizations or generate code for them under that assumption. 11643This is something we'd like to change in the future to provide better 11644support for freestanding environments and non-C-based languages. 11645 11646.. _i_va_arg: 11647 11648'``va_arg``' Instruction 11649^^^^^^^^^^^^^^^^^^^^^^^^ 11650 11651Syntax: 11652""""""" 11653 11654:: 11655 11656 <resultval> = va_arg <va_list*> <arglist>, <argty> 11657 11658Overview: 11659""""""""" 11660 11661The '``va_arg``' instruction is used to access arguments passed through 11662the "variable argument" area of a function call. It is used to implement 11663the ``va_arg`` macro in C. 11664 11665Arguments: 11666"""""""""" 11667 11668This instruction takes a ``va_list*`` value and the type of the 11669argument. It returns a value of the specified argument type and 11670increments the ``va_list`` to point to the next argument. The actual 11671type of ``va_list`` is target specific. 11672 11673Semantics: 11674"""""""""" 11675 11676The '``va_arg``' instruction loads an argument of the specified type 11677from the specified ``va_list`` and causes the ``va_list`` to point to 11678the next argument. For more information, see the variable argument 11679handling :ref:`Intrinsic Functions <int_varargs>`. 11680 11681It is legal for this instruction to be called in a function which does 11682not take a variable number of arguments, for example, the ``vfprintf`` 11683function. 11684 11685``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic 11686function <intrinsics>` because it takes a type as an argument. 11687 11688Example: 11689"""""""" 11690 11691See the :ref:`variable argument processing <int_varargs>` section. 11692 11693Note that the code generator does not yet fully support va\_arg on many 11694targets. Also, it does not currently support va\_arg with aggregate 11695types on any target. 11696 11697.. _i_landingpad: 11698 11699'``landingpad``' Instruction 11700^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11701 11702Syntax: 11703""""""" 11704 11705:: 11706 11707 <resultval> = landingpad <resultty> <clause>+ 11708 <resultval> = landingpad <resultty> cleanup <clause>* 11709 11710 <clause> := catch <type> <value> 11711 <clause> := filter <array constant type> <array constant> 11712 11713Overview: 11714""""""""" 11715 11716The '``landingpad``' instruction is used by `LLVM's exception handling 11717system <ExceptionHandling.html#overview>`_ to specify that a basic block 11718is a landing pad --- one where the exception lands, and corresponds to the 11719code found in the ``catch`` portion of a ``try``/``catch`` sequence. It 11720defines values supplied by the :ref:`personality function <personalityfn>` upon 11721re-entry to the function. The ``resultval`` has the type ``resultty``. 11722 11723Arguments: 11724"""""""""" 11725 11726The optional 11727``cleanup`` flag indicates that the landing pad block is a cleanup. 11728 11729A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and 11730contains the global variable representing the "type" that may be caught 11731or filtered respectively. Unlike the ``catch`` clause, the ``filter`` 11732clause takes an array constant as its argument. Use 11733"``[0 x i8**] undef``" for a filter which cannot throw. The 11734'``landingpad``' instruction must contain *at least* one ``clause`` or 11735the ``cleanup`` flag. 11736 11737Semantics: 11738"""""""""" 11739 11740The '``landingpad``' instruction defines the values which are set by the 11741:ref:`personality function <personalityfn>` upon re-entry to the function, and 11742therefore the "result type" of the ``landingpad`` instruction. As with 11743calling conventions, how the personality function results are 11744represented in LLVM IR is target specific. 11745 11746The clauses are applied in order from top to bottom. If two 11747``landingpad`` instructions are merged together through inlining, the 11748clauses from the calling function are appended to the list of clauses. 11749When the call stack is being unwound due to an exception being thrown, 11750the exception is compared against each ``clause`` in turn. If it doesn't 11751match any of the clauses, and the ``cleanup`` flag is not set, then 11752unwinding continues further up the call stack. 11753 11754The ``landingpad`` instruction has several restrictions: 11755 11756- A landing pad block is a basic block which is the unwind destination 11757 of an '``invoke``' instruction. 11758- A landing pad block must have a '``landingpad``' instruction as its 11759 first non-PHI instruction. 11760- There can be only one '``landingpad``' instruction within the landing 11761 pad block. 11762- A basic block that is not a landing pad block may not include a 11763 '``landingpad``' instruction. 11764 11765Example: 11766"""""""" 11767 11768.. code-block:: llvm 11769 11770 ;; A landing pad which can catch an integer. 11771 %res = landingpad { i8*, i32 } 11772 catch i8** @_ZTIi 11773 ;; A landing pad that is a cleanup. 11774 %res = landingpad { i8*, i32 } 11775 cleanup 11776 ;; A landing pad which can catch an integer and can only throw a double. 11777 %res = landingpad { i8*, i32 } 11778 catch i8** @_ZTIi 11779 filter [1 x i8**] [i8** @_ZTId] 11780 11781.. _i_catchpad: 11782 11783'``catchpad``' Instruction 11784^^^^^^^^^^^^^^^^^^^^^^^^^^ 11785 11786Syntax: 11787""""""" 11788 11789:: 11790 11791 <resultval> = catchpad within <catchswitch> [<args>*] 11792 11793Overview: 11794""""""""" 11795 11796The '``catchpad``' instruction is used by `LLVM's exception handling 11797system <ExceptionHandling.html#overview>`_ to specify that a basic block 11798begins a catch handler --- one where a personality routine attempts to transfer 11799control to catch an exception. 11800 11801Arguments: 11802"""""""""" 11803 11804The ``catchswitch`` operand must always be a token produced by a 11805:ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This 11806ensures that each ``catchpad`` has exactly one predecessor block, and it always 11807terminates in a ``catchswitch``. 11808 11809The ``args`` correspond to whatever information the personality routine 11810requires to know if this is an appropriate handler for the exception. Control 11811will transfer to the ``catchpad`` if this is the first appropriate handler for 11812the exception. 11813 11814The ``resultval`` has the type :ref:`token <t_token>` and is used to match the 11815``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH 11816pads. 11817 11818Semantics: 11819"""""""""" 11820 11821When the call stack is being unwound due to an exception being thrown, the 11822exception is compared against the ``args``. If it doesn't match, control will 11823not reach the ``catchpad`` instruction. The representation of ``args`` is 11824entirely target and personality function-specific. 11825 11826Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad`` 11827instruction must be the first non-phi of its parent basic block. 11828 11829The meaning of the tokens produced and consumed by ``catchpad`` and other "pad" 11830instructions is described in the 11831`Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_. 11832 11833When a ``catchpad`` has been "entered" but not yet "exited" (as 11834described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 11835it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 11836that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`. 11837 11838Example: 11839"""""""" 11840 11841.. code-block:: text 11842 11843 dispatch: 11844 %cs = catchswitch within none [label %handler0] unwind to caller 11845 ;; A catch block which can catch an integer. 11846 handler0: 11847 %tok = catchpad within %cs [i8** @_ZTIi] 11848 11849.. _i_cleanuppad: 11850 11851'``cleanuppad``' Instruction 11852^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11853 11854Syntax: 11855""""""" 11856 11857:: 11858 11859 <resultval> = cleanuppad within <parent> [<args>*] 11860 11861Overview: 11862""""""""" 11863 11864The '``cleanuppad``' instruction is used by `LLVM's exception handling 11865system <ExceptionHandling.html#overview>`_ to specify that a basic block 11866is a cleanup block --- one where a personality routine attempts to 11867transfer control to run cleanup actions. 11868The ``args`` correspond to whatever additional 11869information the :ref:`personality function <personalityfn>` requires to 11870execute the cleanup. 11871The ``resultval`` has the type :ref:`token <t_token>` and is used to 11872match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`. 11873The ``parent`` argument is the token of the funclet that contains the 11874``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet, 11875this operand may be the token ``none``. 11876 11877Arguments: 11878"""""""""" 11879 11880The instruction takes a list of arbitrary values which are interpreted 11881by the :ref:`personality function <personalityfn>`. 11882 11883Semantics: 11884"""""""""" 11885 11886When the call stack is being unwound due to an exception being thrown, 11887the :ref:`personality function <personalityfn>` transfers control to the 11888``cleanuppad`` with the aid of the personality-specific arguments. 11889As with calling conventions, how the personality function results are 11890represented in LLVM IR is target specific. 11891 11892The ``cleanuppad`` instruction has several restrictions: 11893 11894- A cleanup block is a basic block which is the unwind destination of 11895 an exceptional instruction. 11896- A cleanup block must have a '``cleanuppad``' instruction as its 11897 first non-PHI instruction. 11898- There can be only one '``cleanuppad``' instruction within the 11899 cleanup block. 11900- A basic block that is not a cleanup block may not include a 11901 '``cleanuppad``' instruction. 11902 11903When a ``cleanuppad`` has been "entered" but not yet "exited" (as 11904described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 11905it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 11906that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`. 11907 11908Example: 11909"""""""" 11910 11911.. code-block:: text 11912 11913 %tok = cleanuppad within %cs [] 11914 11915.. _intrinsics: 11916 11917Intrinsic Functions 11918=================== 11919 11920LLVM supports the notion of an "intrinsic function". These functions 11921have well known names and semantics and are required to follow certain 11922restrictions. Overall, these intrinsics represent an extension mechanism 11923for the LLVM language that does not require changing all of the 11924transformations in LLVM when adding to the language (or the bitcode 11925reader/writer, the parser, etc...). 11926 11927Intrinsic function names must all start with an "``llvm.``" prefix. This 11928prefix is reserved in LLVM for intrinsic names; thus, function names may 11929not begin with this prefix. Intrinsic functions must always be external 11930functions: you cannot define the body of intrinsic functions. Intrinsic 11931functions may only be used in call or invoke instructions: it is illegal 11932to take the address of an intrinsic function. Additionally, because 11933intrinsic functions are part of the LLVM language, it is required if any 11934are added that they be documented here. 11935 11936Some intrinsic functions can be overloaded, i.e., the intrinsic 11937represents a family of functions that perform the same operation but on 11938different data types. Because LLVM can represent over 8 million 11939different integer types, overloading is used commonly to allow an 11940intrinsic function to operate on any integer type. One or more of the 11941argument types or the result type can be overloaded to accept any 11942integer type. Argument types may also be defined as exactly matching a 11943previous argument's type or the result type. This allows an intrinsic 11944function which accepts multiple arguments, but needs all of them to be 11945of the same type, to only be overloaded with respect to a single 11946argument or the result. 11947 11948Overloaded intrinsics will have the names of its overloaded argument 11949types encoded into its function name, each preceded by a period. Only 11950those types which are overloaded result in a name suffix. Arguments 11951whose type is matched against another type do not. For example, the 11952``llvm.ctpop`` function can take an integer of any width and returns an 11953integer of exactly the same integer width. This leads to a family of 11954functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and 11955``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is 11956overloaded, and only one type suffix is required. Because the argument's 11957type is matched against the return type, it does not require its own 11958name suffix. 11959 11960:ref:`Unnamed types <t_opaque>` are encoded as ``s_s``. Overloaded intrinsics 11961that depend on an unnamed type in one of its overloaded argument types get an 11962additional ``.<number>`` suffix. This allows differentiating intrinsics with 11963different unnamed types as arguments. (For example: 11964``llvm.ssa.copy.p0s_s.2(%42*)``) The number is tracked in the LLVM module and 11965it ensures unique names in the module. While linking together two modules, it is 11966still possible to get a name clash. In that case one of the names will be 11967changed by getting a new number. 11968 11969For target developers who are defining intrinsics for back-end code 11970generation, any intrinsic overloads based solely the distinction between 11971integer or floating point types should not be relied upon for correct 11972code generation. In such cases, the recommended approach for target 11973maintainers when defining intrinsics is to create separate integer and 11974FP intrinsics rather than rely on overloading. For example, if different 11975codegen is required for ``llvm.target.foo(<4 x i32>)`` and 11976``llvm.target.foo(<4 x float>)`` then these should be split into 11977different intrinsics. 11978 11979To learn how to add an intrinsic function, please see the `Extending 11980LLVM Guide <ExtendingLLVM.html>`_. 11981 11982.. _int_varargs: 11983 11984Variable Argument Handling Intrinsics 11985------------------------------------- 11986 11987Variable argument support is defined in LLVM with the 11988:ref:`va_arg <i_va_arg>` instruction and these three intrinsic 11989functions. These functions are related to the similarly named macros 11990defined in the ``<stdarg.h>`` header file. 11991 11992All of these functions operate on arguments that use a target-specific 11993value type "``va_list``". The LLVM assembly language reference manual 11994does not define what this type is, so all transformations should be 11995prepared to handle these functions regardless of the type used. 11996 11997This example shows how the :ref:`va_arg <i_va_arg>` instruction and the 11998variable argument handling intrinsic functions are used. 11999 12000.. code-block:: llvm 12001 12002 ; This struct is different for every platform. For most platforms, 12003 ; it is merely an i8*. 12004 %struct.va_list = type { i8* } 12005 12006 ; For Unix x86_64 platforms, va_list is the following struct: 12007 ; %struct.va_list = type { i32, i32, i8*, i8* } 12008 12009 define i32 @test(i32 %X, ...) { 12010 ; Initialize variable argument processing 12011 %ap = alloca %struct.va_list 12012 %ap2 = bitcast %struct.va_list* %ap to i8* 12013 call void @llvm.va_start(i8* %ap2) 12014 12015 ; Read a single integer argument 12016 %tmp = va_arg i8* %ap2, i32 12017 12018 ; Demonstrate usage of llvm.va_copy and llvm.va_end 12019 %aq = alloca i8* 12020 %aq2 = bitcast i8** %aq to i8* 12021 call void @llvm.va_copy(i8* %aq2, i8* %ap2) 12022 call void @llvm.va_end(i8* %aq2) 12023 12024 ; Stop processing of arguments. 12025 call void @llvm.va_end(i8* %ap2) 12026 ret i32 %tmp 12027 } 12028 12029 declare void @llvm.va_start(i8*) 12030 declare void @llvm.va_copy(i8*, i8*) 12031 declare void @llvm.va_end(i8*) 12032 12033.. _int_va_start: 12034 12035'``llvm.va_start``' Intrinsic 12036^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12037 12038Syntax: 12039""""""" 12040 12041:: 12042 12043 declare void @llvm.va_start(i8* <arglist>) 12044 12045Overview: 12046""""""""" 12047 12048The '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for 12049subsequent use by ``va_arg``. 12050 12051Arguments: 12052"""""""""" 12053 12054The argument is a pointer to a ``va_list`` element to initialize. 12055 12056Semantics: 12057"""""""""" 12058 12059The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro 12060available in C. In a target-dependent way, it initializes the 12061``va_list`` element to which the argument points, so that the next call 12062to ``va_arg`` will produce the first variable argument passed to the 12063function. Unlike the C ``va_start`` macro, this intrinsic does not need 12064to know the last argument of the function as the compiler can figure 12065that out. 12066 12067'``llvm.va_end``' Intrinsic 12068^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12069 12070Syntax: 12071""""""" 12072 12073:: 12074 12075 declare void @llvm.va_end(i8* <arglist>) 12076 12077Overview: 12078""""""""" 12079 12080The '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been 12081initialized previously with ``llvm.va_start`` or ``llvm.va_copy``. 12082 12083Arguments: 12084"""""""""" 12085 12086The argument is a pointer to a ``va_list`` to destroy. 12087 12088Semantics: 12089"""""""""" 12090 12091The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro 12092available in C. In a target-dependent way, it destroys the ``va_list`` 12093element to which the argument points. Calls to 12094:ref:`llvm.va_start <int_va_start>` and 12095:ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to 12096``llvm.va_end``. 12097 12098.. _int_va_copy: 12099 12100'``llvm.va_copy``' Intrinsic 12101^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12102 12103Syntax: 12104""""""" 12105 12106:: 12107 12108 declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>) 12109 12110Overview: 12111""""""""" 12112 12113The '``llvm.va_copy``' intrinsic copies the current argument position 12114from the source argument list to the destination argument list. 12115 12116Arguments: 12117"""""""""" 12118 12119The first argument is a pointer to a ``va_list`` element to initialize. 12120The second argument is a pointer to a ``va_list`` element to copy from. 12121 12122Semantics: 12123"""""""""" 12124 12125The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro 12126available in C. In a target-dependent way, it copies the source 12127``va_list`` element into the destination ``va_list`` element. This 12128intrinsic is necessary because the `` llvm.va_start`` intrinsic may be 12129arbitrarily complex and require, for example, memory allocation. 12130 12131Accurate Garbage Collection Intrinsics 12132-------------------------------------- 12133 12134LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_ 12135(GC) requires the frontend to generate code containing appropriate intrinsic 12136calls and select an appropriate GC strategy which knows how to lower these 12137intrinsics in a manner which is appropriate for the target collector. 12138 12139These intrinsics allow identification of :ref:`GC roots on the 12140stack <int_gcroot>`, as well as garbage collector implementations that 12141require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. 12142Frontends for type-safe garbage collected languages should generate 12143these intrinsics to make use of the LLVM garbage collectors. For more 12144details, see `Garbage Collection with LLVM <GarbageCollection.html>`_. 12145 12146LLVM provides an second experimental set of intrinsics for describing garbage 12147collection safepoints in compiled code. These intrinsics are an alternative 12148to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for 12149:ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The 12150differences in approach are covered in the `Garbage Collection with LLVM 12151<GarbageCollection.html>`_ documentation. The intrinsics themselves are 12152described in :doc:`Statepoints`. 12153 12154.. _int_gcroot: 12155 12156'``llvm.gcroot``' Intrinsic 12157^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12158 12159Syntax: 12160""""""" 12161 12162:: 12163 12164 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata) 12165 12166Overview: 12167""""""""" 12168 12169The '``llvm.gcroot``' intrinsic declares the existence of a GC root to 12170the code generator, and allows some metadata to be associated with it. 12171 12172Arguments: 12173"""""""""" 12174 12175The first argument specifies the address of a stack object that contains 12176the root pointer. The second pointer (which must be either a constant or 12177a global value address) contains the meta-data to be associated with the 12178root. 12179 12180Semantics: 12181"""""""""" 12182 12183At runtime, a call to this intrinsic stores a null pointer into the 12184"ptrloc" location. At compile-time, the code generator generates 12185information to allow the runtime to find the pointer at GC safe points. 12186The '``llvm.gcroot``' intrinsic may only be used in a function which 12187:ref:`specifies a GC algorithm <gc>`. 12188 12189.. _int_gcread: 12190 12191'``llvm.gcread``' Intrinsic 12192^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12193 12194Syntax: 12195""""""" 12196 12197:: 12198 12199 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr) 12200 12201Overview: 12202""""""""" 12203 12204The '``llvm.gcread``' intrinsic identifies reads of references from heap 12205locations, allowing garbage collector implementations that require read 12206barriers. 12207 12208Arguments: 12209"""""""""" 12210 12211The second argument is the address to read from, which should be an 12212address allocated from the garbage collector. The first object is a 12213pointer to the start of the referenced object, if needed by the language 12214runtime (otherwise null). 12215 12216Semantics: 12217"""""""""" 12218 12219The '``llvm.gcread``' intrinsic has the same semantics as a load 12220instruction, but may be replaced with substantially more complex code by 12221the garbage collector runtime, as needed. The '``llvm.gcread``' 12222intrinsic may only be used in a function which :ref:`specifies a GC 12223algorithm <gc>`. 12224 12225.. _int_gcwrite: 12226 12227'``llvm.gcwrite``' Intrinsic 12228^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12229 12230Syntax: 12231""""""" 12232 12233:: 12234 12235 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2) 12236 12237Overview: 12238""""""""" 12239 12240The '``llvm.gcwrite``' intrinsic identifies writes of references to heap 12241locations, allowing garbage collector implementations that require write 12242barriers (such as generational or reference counting collectors). 12243 12244Arguments: 12245"""""""""" 12246 12247The first argument is the reference to store, the second is the start of 12248the object to store it to, and the third is the address of the field of 12249Obj to store to. If the runtime does not require a pointer to the 12250object, Obj may be null. 12251 12252Semantics: 12253"""""""""" 12254 12255The '``llvm.gcwrite``' intrinsic has the same semantics as a store 12256instruction, but may be replaced with substantially more complex code by 12257the garbage collector runtime, as needed. The '``llvm.gcwrite``' 12258intrinsic may only be used in a function which :ref:`specifies a GC 12259algorithm <gc>`. 12260 12261 12262.. _gc_statepoint: 12263 12264'llvm.experimental.gc.statepoint' Intrinsic 12265^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12266 12267Syntax: 12268""""""" 12269 12270:: 12271 12272 declare token 12273 @llvm.experimental.gc.statepoint(i64 <id>, i32 <num patch bytes>, 12274 func_type* elementtype(func_type) <target>, 12275 i64 <#call args>, i64 <flags>, 12276 ... (call parameters), 12277 i64 0, i64 0) 12278 12279Overview: 12280""""""""" 12281 12282The statepoint intrinsic represents a call which is parse-able by the 12283runtime. 12284 12285Operands: 12286""""""""" 12287 12288The 'id' operand is a constant integer that is reported as the ID 12289field in the generated stackmap. LLVM does not interpret this 12290parameter in any way and its meaning is up to the statepoint user to 12291decide. Note that LLVM is free to duplicate code containing 12292statepoint calls, and this may transform IR that had a unique 'id' per 12293lexical call to statepoint to IR that does not. 12294 12295If 'num patch bytes' is non-zero then the call instruction 12296corresponding to the statepoint is not emitted and LLVM emits 'num 12297patch bytes' bytes of nops in its place. LLVM will emit code to 12298prepare the function arguments and retrieve the function return value 12299in accordance to the calling convention; the former before the nop 12300sequence and the latter after the nop sequence. It is expected that 12301the user will patch over the 'num patch bytes' bytes of nops with a 12302calling sequence specific to their runtime before executing the 12303generated machine code. There are no guarantees with respect to the 12304alignment of the nop sequence. Unlike :doc:`StackMaps` statepoints do 12305not have a concept of shadow bytes. Note that semantically the 12306statepoint still represents a call or invoke to 'target', and the nop 12307sequence after patching is expected to represent an operation 12308equivalent to a call or invoke to 'target'. 12309 12310The 'target' operand is the function actually being called. The operand 12311must have an :ref:`elementtype <attr_elementtype>` attribute specifying 12312the function type of the target. The target can be specified as either 12313a symbolic LLVM function, or as an arbitrary Value of pointer type. Note 12314that the function type must match the signature of the callee and the 12315types of the 'call parameters' arguments. 12316 12317The '#call args' operand is the number of arguments to the actual 12318call. It must exactly match the number of arguments passed in the 12319'call parameters' variable length section. 12320 12321The 'flags' operand is used to specify extra information about the 12322statepoint. This is currently only used to mark certain statepoints 12323as GC transitions. This operand is a 64-bit integer with the following 12324layout, where bit 0 is the least significant bit: 12325 12326 +-------+---------------------------------------------------+ 12327 | Bit # | Usage | 12328 +=======+===================================================+ 12329 | 0 | Set if the statepoint is a GC transition, cleared | 12330 | | otherwise. | 12331 +-------+---------------------------------------------------+ 12332 | 1-63 | Reserved for future use; must be cleared. | 12333 +-------+---------------------------------------------------+ 12334 12335The 'call parameters' arguments are simply the arguments which need to 12336be passed to the call target. They will be lowered according to the 12337specified calling convention and otherwise handled like a normal call 12338instruction. The number of arguments must exactly match what is 12339specified in '# call args'. The types must match the signature of 12340'target'. 12341 12342The 'call parameter' attributes must be followed by two 'i64 0' constants. 12343These were originally the length prefixes for 'gc transition parameter' and 12344'deopt parameter' arguments, but the role of these parameter sets have been 12345entirely replaced with the corresponding operand bundles. In a future 12346revision, these now redundant arguments will be removed. 12347 12348Semantics: 12349"""""""""" 12350 12351A statepoint is assumed to read and write all memory. As a result, 12352memory operations can not be reordered past a statepoint. It is 12353illegal to mark a statepoint as being either 'readonly' or 'readnone'. 12354 12355Note that legal IR can not perform any memory operation on a 'gc 12356pointer' argument of the statepoint in a location statically reachable 12357from the statepoint. Instead, the explicitly relocated value (from a 12358``gc.relocate``) must be used. 12359 12360'llvm.experimental.gc.result' Intrinsic 12361^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12362 12363Syntax: 12364""""""" 12365 12366:: 12367 12368 declare type* 12369 @llvm.experimental.gc.result(token %statepoint_token) 12370 12371Overview: 12372""""""""" 12373 12374``gc.result`` extracts the result of the original call instruction 12375which was replaced by the ``gc.statepoint``. The ``gc.result`` 12376intrinsic is actually a family of three intrinsics due to an 12377implementation limitation. Other than the type of the return value, 12378the semantics are the same. 12379 12380Operands: 12381""""""""" 12382 12383The first and only argument is the ``gc.statepoint`` which starts 12384the safepoint sequence of which this ``gc.result`` is a part. 12385Despite the typing of this as a generic token, *only* the value defined 12386by a ``gc.statepoint`` is legal here. 12387 12388Semantics: 12389"""""""""" 12390 12391The ``gc.result`` represents the return value of the call target of 12392the ``statepoint``. The type of the ``gc.result`` must exactly match 12393the type of the target. If the call target returns void, there will 12394be no ``gc.result``. 12395 12396A ``gc.result`` is modeled as a 'readnone' pure function. It has no 12397side effects since it is just a projection of the return value of the 12398previous call represented by the ``gc.statepoint``. 12399 12400'llvm.experimental.gc.relocate' Intrinsic 12401^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12402 12403Syntax: 12404""""""" 12405 12406:: 12407 12408 declare <pointer type> 12409 @llvm.experimental.gc.relocate(token %statepoint_token, 12410 i32 %base_offset, 12411 i32 %pointer_offset) 12412 12413Overview: 12414""""""""" 12415 12416A ``gc.relocate`` returns the potentially relocated value of a pointer 12417at the safepoint. 12418 12419Operands: 12420""""""""" 12421 12422The first argument is the ``gc.statepoint`` which starts the 12423safepoint sequence of which this ``gc.relocation`` is a part. 12424Despite the typing of this as a generic token, *only* the value defined 12425by a ``gc.statepoint`` is legal here. 12426 12427The second and third arguments are both indices into operands of the 12428corresponding statepoint's :ref:`gc-live <ob_gc_live>` operand bundle. 12429 12430The second argument is an index which specifies the allocation for the pointer 12431being relocated. The associated value must be within the object with which the 12432pointer being relocated is associated. The optimizer is free to change *which* 12433interior derived pointer is reported, provided that it does not replace an 12434actual base pointer with another interior derived pointer. Collectors are 12435allowed to rely on the base pointer operand remaining an actual base pointer if 12436so constructed. 12437 12438The third argument is an index which specify the (potentially) derived pointer 12439being relocated. It is legal for this index to be the same as the second 12440argument if-and-only-if a base pointer is being relocated. 12441 12442Semantics: 12443"""""""""" 12444 12445The return value of ``gc.relocate`` is the potentially relocated value 12446of the pointer specified by its arguments. It is unspecified how the 12447value of the returned pointer relates to the argument to the 12448``gc.statepoint`` other than that a) it points to the same source 12449language object with the same offset, and b) the 'based-on' 12450relationship of the newly relocated pointers is a projection of the 12451unrelocated pointers. In particular, the integer value of the pointer 12452returned is unspecified. 12453 12454A ``gc.relocate`` is modeled as a ``readnone`` pure function. It has no 12455side effects since it is just a way to extract information about work 12456done during the actual call modeled by the ``gc.statepoint``. 12457 12458.. _gc.get.pointer.base: 12459 12460'llvm.experimental.gc.get.pointer.base' Intrinsic 12461^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12462 12463Syntax: 12464""""""" 12465 12466:: 12467 12468 declare <pointer type> 12469 @llvm.experimental.gc.get.pointer.base( 12470 <pointer type> readnone nocapture %derived_ptr) 12471 nounwind readnone willreturn 12472 12473Overview: 12474""""""""" 12475 12476``gc.get.pointer.base`` for a derived pointer returns its base pointer. 12477 12478Operands: 12479""""""""" 12480 12481The only argument is a pointer which is based on some object with 12482an unknown offset from the base of said object. 12483 12484Semantics: 12485"""""""""" 12486 12487This intrinsic is used in the abstract machine model for GC to represent 12488the base pointer for an arbitrary derived pointer. 12489 12490This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by 12491replacing all uses of this callsite with the offset of a derived pointer from 12492its base pointer value. The replacement is done as part of the lowering to the 12493explicit statepoint model. 12494 12495The return pointer type must be the same as the type of the parameter. 12496 12497 12498'llvm.experimental.gc.get.pointer.offset' Intrinsic 12499^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12500 12501Syntax: 12502""""""" 12503 12504:: 12505 12506 declare i64 12507 @llvm.experimental.gc.get.pointer.offset( 12508 <pointer type> readnone nocapture %derived_ptr) 12509 nounwind readnone willreturn 12510 12511Overview: 12512""""""""" 12513 12514``gc.get.pointer.offset`` for a derived pointer returns the offset from its 12515base pointer. 12516 12517Operands: 12518""""""""" 12519 12520The only argument is a pointer which is based on some object with 12521an unknown offset from the base of said object. 12522 12523Semantics: 12524"""""""""" 12525 12526This intrinsic is used in the abstract machine model for GC to represent 12527the offset of an arbitrary derived pointer from its base pointer. 12528 12529This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by 12530replacing all uses of this callsite with the offset of a derived pointer from 12531its base pointer value. The replacement is done as part of the lowering to the 12532explicit statepoint model. 12533 12534Basically this call calculates difference between the derived pointer and its 12535base pointer (see :ref:`gc.get.pointer.base`) both ptrtoint casted. But 12536this cast done outside the :ref:`RewriteStatepointsForGC` pass could result 12537in the pointers lost for further lowering from the abstract model to the 12538explicit physical one. 12539 12540Code Generator Intrinsics 12541------------------------- 12542 12543These intrinsics are provided by LLVM to expose special features that 12544may only be implemented with code generator support. 12545 12546'``llvm.returnaddress``' Intrinsic 12547^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12548 12549Syntax: 12550""""""" 12551 12552:: 12553 12554 declare i8* @llvm.returnaddress(i32 <level>) 12555 12556Overview: 12557""""""""" 12558 12559The '``llvm.returnaddress``' intrinsic attempts to compute a 12560target-specific value indicating the return address of the current 12561function or one of its callers. 12562 12563Arguments: 12564"""""""""" 12565 12566The argument to this intrinsic indicates which function to return the 12567address for. Zero indicates the calling function, one indicates its 12568caller, etc. The argument is **required** to be a constant integer 12569value. 12570 12571Semantics: 12572"""""""""" 12573 12574The '``llvm.returnaddress``' intrinsic either returns a pointer 12575indicating the return address of the specified call frame, or zero if it 12576cannot be identified. The value returned by this intrinsic is likely to 12577be incorrect or 0 for arguments other than zero, so it should only be 12578used for debugging purposes. 12579 12580Note that calling this intrinsic does not prevent function inlining or 12581other aggressive transformations, so the value returned may not be that 12582of the obvious source-language caller. 12583 12584'``llvm.addressofreturnaddress``' Intrinsic 12585^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12586 12587Syntax: 12588""""""" 12589 12590:: 12591 12592 declare i8* @llvm.addressofreturnaddress() 12593 12594Overview: 12595""""""""" 12596 12597The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific 12598pointer to the place in the stack frame where the return address of the 12599current function is stored. 12600 12601Semantics: 12602"""""""""" 12603 12604Note that calling this intrinsic does not prevent function inlining or 12605other aggressive transformations, so the value returned may not be that 12606of the obvious source-language caller. 12607 12608This intrinsic is only implemented for x86 and aarch64. 12609 12610'``llvm.sponentry``' Intrinsic 12611^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12612 12613Syntax: 12614""""""" 12615 12616:: 12617 12618 declare i8* @llvm.sponentry() 12619 12620Overview: 12621""""""""" 12622 12623The '``llvm.sponentry``' intrinsic returns the stack pointer value at 12624the entry of the current function calling this intrinsic. 12625 12626Semantics: 12627"""""""""" 12628 12629Note this intrinsic is only verified on AArch64. 12630 12631'``llvm.frameaddress``' Intrinsic 12632^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12633 12634Syntax: 12635""""""" 12636 12637:: 12638 12639 declare i8* @llvm.frameaddress(i32 <level>) 12640 12641Overview: 12642""""""""" 12643 12644The '``llvm.frameaddress``' intrinsic attempts to return the 12645target-specific frame pointer value for the specified stack frame. 12646 12647Arguments: 12648"""""""""" 12649 12650The argument to this intrinsic indicates which function to return the 12651frame pointer for. Zero indicates the calling function, one indicates 12652its caller, etc. The argument is **required** to be a constant integer 12653value. 12654 12655Semantics: 12656"""""""""" 12657 12658The '``llvm.frameaddress``' intrinsic either returns a pointer 12659indicating the frame address of the specified call frame, or zero if it 12660cannot be identified. The value returned by this intrinsic is likely to 12661be incorrect or 0 for arguments other than zero, so it should only be 12662used for debugging purposes. 12663 12664Note that calling this intrinsic does not prevent function inlining or 12665other aggressive transformations, so the value returned may not be that 12666of the obvious source-language caller. 12667 12668'``llvm.swift.async.context.addr``' Intrinsic 12669^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12670 12671Syntax: 12672""""""" 12673 12674:: 12675 12676 declare i8** @llvm.swift.async.context.addr() 12677 12678Overview: 12679""""""""" 12680 12681The '``llvm.swift.async.context.addr``' intrinsic returns a pointer to 12682the part of the extended frame record containing the asynchronous 12683context of a Swift execution. 12684 12685Semantics: 12686"""""""""" 12687 12688If the caller has a ``swiftasync`` parameter, that argument will initially 12689be stored at the returned address. If not, it will be initialized to null. 12690 12691'``llvm.localescape``' and '``llvm.localrecover``' Intrinsics 12692^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12693 12694Syntax: 12695""""""" 12696 12697:: 12698 12699 declare void @llvm.localescape(...) 12700 declare i8* @llvm.localrecover(i8* %func, i8* %fp, i32 %idx) 12701 12702Overview: 12703""""""""" 12704 12705The '``llvm.localescape``' intrinsic escapes offsets of a collection of static 12706allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a 12707live frame pointer to recover the address of the allocation. The offset is 12708computed during frame layout of the caller of ``llvm.localescape``. 12709 12710Arguments: 12711"""""""""" 12712 12713All arguments to '``llvm.localescape``' must be pointers to static allocas or 12714casts of static allocas. Each function can only call '``llvm.localescape``' 12715once, and it can only do so from the entry block. 12716 12717The ``func`` argument to '``llvm.localrecover``' must be a constant 12718bitcasted pointer to a function defined in the current module. The code 12719generator cannot determine the frame allocation offset of functions defined in 12720other modules. 12721 12722The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a 12723call frame that is currently live. The return value of '``llvm.localaddress``' 12724is one way to produce such a value, but various runtimes also expose a suitable 12725pointer in platform-specific ways. 12726 12727The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to 12728'``llvm.localescape``' to recover. It is zero-indexed. 12729 12730Semantics: 12731"""""""""" 12732 12733These intrinsics allow a group of functions to share access to a set of local 12734stack allocations of a one parent function. The parent function may call the 12735'``llvm.localescape``' intrinsic once from the function entry block, and the 12736child functions can use '``llvm.localrecover``' to access the escaped allocas. 12737The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where 12738the escaped allocas are allocated, which would break attempts to use 12739'``llvm.localrecover``'. 12740 12741'``llvm.seh.try.begin``' and '``llvm.seh.try.end``' Intrinsics 12742^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12743 12744Syntax: 12745""""""" 12746 12747:: 12748 12749 declare void @llvm.seh.try.begin() 12750 declare void @llvm.seh.try.end() 12751 12752Overview: 12753""""""""" 12754 12755The '``llvm.seh.try.begin``' and '``llvm.seh.try.end``' intrinsics mark 12756the boundary of a _try region for Windows SEH Asynchrous Exception Handling. 12757 12758Semantics: 12759"""""""""" 12760 12761When a C-function is compiled with Windows SEH Asynchrous Exception option, 12762-feh_asynch (aka MSVC -EHa), these two intrinsics are injected to mark _try 12763boundary and to prevent potential exceptions from being moved across boundary. 12764Any set of operations can then be confined to the region by reading their leaf 12765inputs via volatile loads and writing their root outputs via volatile stores. 12766 12767'``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' Intrinsics 12768^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12769 12770Syntax: 12771""""""" 12772 12773:: 12774 12775 declare void @llvm.seh.scope.begin() 12776 declare void @llvm.seh.scope.end() 12777 12778Overview: 12779""""""""" 12780 12781The '``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' intrinsics mark 12782the boundary of a CPP object lifetime for Windows SEH Asynchrous Exception 12783Handling (MSVC option -EHa). 12784 12785Semantics: 12786"""""""""" 12787 12788LLVM's ordinary exception-handling representation associates EH cleanups and 12789handlers only with ``invoke``s, which normally correspond only to call sites. To 12790support arbitrary faulting instructions, it must be possible to recover the current 12791EH scope for any instruction. Turning every operation in LLVM that could fault 12792into an ``invoke`` of a new, potentially-throwing intrinsic would require adding a 12793large number of intrinsics, impede optimization of those operations, and make 12794compilation slower by introducing many extra basic blocks. These intrinsics can 12795be used instead to mark the region protected by a cleanup, such as for a local 12796C++ object with a non-trivial destructor. ``llvm.seh.scope.begin`` is used to mark 12797the start of the region; it is always called with ``invoke``, with the unwind block 12798being the desired unwind destination for any potentially-throwing instructions 12799within the region. `llvm.seh.scope.end` is used to mark when the scope ends 12800and the EH cleanup is no longer required (e.g. because the destructor is being 12801called). 12802 12803.. _int_read_register: 12804.. _int_read_volatile_register: 12805.. _int_write_register: 12806 12807'``llvm.read_register``', '``llvm.read_volatile_register``', and '``llvm.write_register``' Intrinsics 12808^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12809 12810Syntax: 12811""""""" 12812 12813:: 12814 12815 declare i32 @llvm.read_register.i32(metadata) 12816 declare i64 @llvm.read_register.i64(metadata) 12817 declare i32 @llvm.read_volatile_register.i32(metadata) 12818 declare i64 @llvm.read_volatile_register.i64(metadata) 12819 declare void @llvm.write_register.i32(metadata, i32 @value) 12820 declare void @llvm.write_register.i64(metadata, i64 @value) 12821 !0 = !{!"sp\00"} 12822 12823Overview: 12824""""""""" 12825 12826The '``llvm.read_register``', '``llvm.read_volatile_register``', and 12827'``llvm.write_register``' intrinsics provide access to the named register. 12828The register must be valid on the architecture being compiled to. The type 12829needs to be compatible with the register being read. 12830 12831Semantics: 12832"""""""""" 12833 12834The '``llvm.read_register``' and '``llvm.read_volatile_register``' intrinsics 12835return the current value of the register, where possible. The 12836'``llvm.write_register``' intrinsic sets the current value of the register, 12837where possible. 12838 12839A call to '``llvm.read_volatile_register``' is assumed to have side-effects 12840and possibly return a different value each time (e.g. for a timer register). 12841 12842This is useful to implement named register global variables that need 12843to always be mapped to a specific register, as is common practice on 12844bare-metal programs including OS kernels. 12845 12846The compiler doesn't check for register availability or use of the used 12847register in surrounding code, including inline assembly. Because of that, 12848allocatable registers are not supported. 12849 12850Warning: So far it only works with the stack pointer on selected 12851architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of 12852work is needed to support other registers and even more so, allocatable 12853registers. 12854 12855.. _int_stacksave: 12856 12857'``llvm.stacksave``' Intrinsic 12858^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12859 12860Syntax: 12861""""""" 12862 12863:: 12864 12865 declare i8* @llvm.stacksave() 12866 12867Overview: 12868""""""""" 12869 12870The '``llvm.stacksave``' intrinsic is used to remember the current state 12871of the function stack, for use with 12872:ref:`llvm.stackrestore <int_stackrestore>`. This is useful for 12873implementing language features like scoped automatic variable sized 12874arrays in C99. 12875 12876Semantics: 12877"""""""""" 12878 12879This intrinsic returns an opaque pointer value that can be passed to 12880:ref:`llvm.stackrestore <int_stackrestore>`. When an 12881``llvm.stackrestore`` intrinsic is executed with a value saved from 12882``llvm.stacksave``, it effectively restores the state of the stack to 12883the state it was in when the ``llvm.stacksave`` intrinsic executed. In 12884practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that 12885were allocated after the ``llvm.stacksave`` was executed. 12886 12887.. _int_stackrestore: 12888 12889'``llvm.stackrestore``' Intrinsic 12890^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12891 12892Syntax: 12893""""""" 12894 12895:: 12896 12897 declare void @llvm.stackrestore(i8* %ptr) 12898 12899Overview: 12900""""""""" 12901 12902The '``llvm.stackrestore``' intrinsic is used to restore the state of 12903the function stack to the state it was in when the corresponding 12904:ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is 12905useful for implementing language features like scoped automatic variable 12906sized arrays in C99. 12907 12908Semantics: 12909"""""""""" 12910 12911See the description for :ref:`llvm.stacksave <int_stacksave>`. 12912 12913.. _int_get_dynamic_area_offset: 12914 12915'``llvm.get.dynamic.area.offset``' Intrinsic 12916^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12917 12918Syntax: 12919""""""" 12920 12921:: 12922 12923 declare i32 @llvm.get.dynamic.area.offset.i32() 12924 declare i64 @llvm.get.dynamic.area.offset.i64() 12925 12926Overview: 12927""""""""" 12928 12929 The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to 12930 get the offset from native stack pointer to the address of the most 12931 recent dynamic alloca on the caller's stack. These intrinsics are 12932 intended for use in combination with 12933 :ref:`llvm.stacksave <int_stacksave>` to get a 12934 pointer to the most recent dynamic alloca. This is useful, for example, 12935 for AddressSanitizer's stack unpoisoning routines. 12936 12937Semantics: 12938"""""""""" 12939 12940 These intrinsics return a non-negative integer value that can be used to 12941 get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>` 12942 on the caller's stack. In particular, for targets where stack grows downwards, 12943 adding this offset to the native stack pointer would get the address of the most 12944 recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more 12945 complicated, because subtracting this value from stack pointer would get the address 12946 one past the end of the most recent dynamic alloca. 12947 12948 Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>` 12949 returns just a zero, for others, such as PowerPC and PowerPC64, it returns a 12950 compile-time-known constant value. 12951 12952 The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>` 12953 must match the target's default address space's (address space 0) pointer type. 12954 12955'``llvm.prefetch``' Intrinsic 12956^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12957 12958Syntax: 12959""""""" 12960 12961:: 12962 12963 declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>) 12964 12965Overview: 12966""""""""" 12967 12968The '``llvm.prefetch``' intrinsic is a hint to the code generator to 12969insert a prefetch instruction if supported; otherwise, it is a noop. 12970Prefetches have no effect on the behavior of the program but can change 12971its performance characteristics. 12972 12973Arguments: 12974"""""""""" 12975 12976``address`` is the address to be prefetched, ``rw`` is the specifier 12977determining if the fetch should be for a read (0) or write (1), and 12978``locality`` is a temporal locality specifier ranging from (0) - no 12979locality, to (3) - extremely local keep in cache. The ``cache type`` 12980specifies whether the prefetch is performed on the data (1) or 12981instruction (0) cache. The ``rw``, ``locality`` and ``cache type`` 12982arguments must be constant integers. 12983 12984Semantics: 12985"""""""""" 12986 12987This intrinsic does not modify the behavior of the program. In 12988particular, prefetches cannot trap and do not produce a value. On 12989targets that support this intrinsic, the prefetch can provide hints to 12990the processor cache for better performance. 12991 12992'``llvm.pcmarker``' Intrinsic 12993^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12994 12995Syntax: 12996""""""" 12997 12998:: 12999 13000 declare void @llvm.pcmarker(i32 <id>) 13001 13002Overview: 13003""""""""" 13004 13005The '``llvm.pcmarker``' intrinsic is a method to export a Program 13006Counter (PC) in a region of code to simulators and other tools. The 13007method is target specific, but it is expected that the marker will use 13008exported symbols to transmit the PC of the marker. The marker makes no 13009guarantees that it will remain with any specific instruction after 13010optimizations. It is possible that the presence of a marker will inhibit 13011optimizations. The intended use is to be inserted after optimizations to 13012allow correlations of simulation runs. 13013 13014Arguments: 13015"""""""""" 13016 13017``id`` is a numerical id identifying the marker. 13018 13019Semantics: 13020"""""""""" 13021 13022This intrinsic does not modify the behavior of the program. Backends 13023that do not support this intrinsic may ignore it. 13024 13025'``llvm.readcyclecounter``' Intrinsic 13026^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13027 13028Syntax: 13029""""""" 13030 13031:: 13032 13033 declare i64 @llvm.readcyclecounter() 13034 13035Overview: 13036""""""""" 13037 13038The '``llvm.readcyclecounter``' intrinsic provides access to the cycle 13039counter register (or similar low latency, high accuracy clocks) on those 13040targets that support it. On X86, it should map to RDTSC. On Alpha, it 13041should map to RPCC. As the backing counters overflow quickly (on the 13042order of 9 seconds on alpha), this should only be used for small 13043timings. 13044 13045Semantics: 13046"""""""""" 13047 13048When directly supported, reading the cycle counter should not modify any 13049memory. Implementations are allowed to either return an application 13050specific value or a system wide value. On backends without support, this 13051is lowered to a constant 0. 13052 13053Note that runtime support may be conditional on the privilege-level code is 13054running at and the host platform. 13055 13056'``llvm.clear_cache``' Intrinsic 13057^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13058 13059Syntax: 13060""""""" 13061 13062:: 13063 13064 declare void @llvm.clear_cache(i8*, i8*) 13065 13066Overview: 13067""""""""" 13068 13069The '``llvm.clear_cache``' intrinsic ensures visibility of modifications 13070in the specified range to the execution unit of the processor. On 13071targets with non-unified instruction and data cache, the implementation 13072flushes the instruction cache. 13073 13074Semantics: 13075"""""""""" 13076 13077On platforms with coherent instruction and data caches (e.g. x86), this 13078intrinsic is a nop. On platforms with non-coherent instruction and data 13079cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate 13080instructions or a system call, if cache flushing requires special 13081privileges. 13082 13083The default behavior is to emit a call to ``__clear_cache`` from the run 13084time library. 13085 13086This intrinsic does *not* empty the instruction pipeline. Modifications 13087of the current function are outside the scope of the intrinsic. 13088 13089'``llvm.instrprof.increment``' Intrinsic 13090^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13091 13092Syntax: 13093""""""" 13094 13095:: 13096 13097 declare void @llvm.instrprof.increment(i8* <name>, i64 <hash>, 13098 i32 <num-counters>, i32 <index>) 13099 13100Overview: 13101""""""""" 13102 13103The '``llvm.instrprof.increment``' intrinsic can be emitted by a 13104frontend for use with instrumentation based profiling. These will be 13105lowered by the ``-instrprof`` pass to generate execution counts of a 13106program at runtime. 13107 13108Arguments: 13109"""""""""" 13110 13111The first argument is a pointer to a global variable containing the 13112name of the entity being instrumented. This should generally be the 13113(mangled) function name for a set of counters. 13114 13115The second argument is a hash value that can be used by the consumer 13116of the profile data to detect changes to the instrumented source, and 13117the third is the number of counters associated with ``name``. It is an 13118error if ``hash`` or ``num-counters`` differ between two instances of 13119``instrprof.increment`` that refer to the same name. 13120 13121The last argument refers to which of the counters for ``name`` should 13122be incremented. It should be a value between 0 and ``num-counters``. 13123 13124Semantics: 13125"""""""""" 13126 13127This intrinsic represents an increment of a profiling counter. It will 13128cause the ``-instrprof`` pass to generate the appropriate data 13129structures and the code to increment the appropriate value, in a 13130format that can be written out by a compiler runtime and consumed via 13131the ``llvm-profdata`` tool. 13132 13133'``llvm.instrprof.increment.step``' Intrinsic 13134^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13135 13136Syntax: 13137""""""" 13138 13139:: 13140 13141 declare void @llvm.instrprof.increment.step(i8* <name>, i64 <hash>, 13142 i32 <num-counters>, 13143 i32 <index>, i64 <step>) 13144 13145Overview: 13146""""""""" 13147 13148The '``llvm.instrprof.increment.step``' intrinsic is an extension to 13149the '``llvm.instrprof.increment``' intrinsic with an additional fifth 13150argument to specify the step of the increment. 13151 13152Arguments: 13153"""""""""" 13154The first four arguments are the same as '``llvm.instrprof.increment``' 13155intrinsic. 13156 13157The last argument specifies the value of the increment of the counter variable. 13158 13159Semantics: 13160"""""""""" 13161See description of '``llvm.instrprof.increment``' intrinsic. 13162 13163'``llvm.instrprof.cover``' Intrinsic 13164^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13165 13166Syntax: 13167""""""" 13168 13169:: 13170 13171 declare void @llvm.instrprof.cover(i8* <name>, i64 <hash>, 13172 i32 <num-counters>, i32 <index>) 13173 13174Overview: 13175""""""""" 13176 13177The '``llvm.instrprof.cover``' intrinsic is used to implement coverage 13178instrumentation. 13179 13180Arguments: 13181"""""""""" 13182The arguments are the same as the first four arguments of 13183'``llvm.instrprof.increment``'. 13184 13185Semantics: 13186"""""""""" 13187Similar to the '``llvm.instrprof.increment``' intrinsic, but it stores zero to 13188the profiling variable to signify that the function has been covered. We store 13189zero because this is more efficient on some targets. 13190 13191'``llvm.instrprof.value.profile``' Intrinsic 13192^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13193 13194Syntax: 13195""""""" 13196 13197:: 13198 13199 declare void @llvm.instrprof.value.profile(i8* <name>, i64 <hash>, 13200 i64 <value>, i32 <value_kind>, 13201 i32 <index>) 13202 13203Overview: 13204""""""""" 13205 13206The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a 13207frontend for use with instrumentation based profiling. This will be 13208lowered by the ``-instrprof`` pass to find out the target values, 13209instrumented expressions take in a program at runtime. 13210 13211Arguments: 13212"""""""""" 13213 13214The first argument is a pointer to a global variable containing the 13215name of the entity being instrumented. ``name`` should generally be the 13216(mangled) function name for a set of counters. 13217 13218The second argument is a hash value that can be used by the consumer 13219of the profile data to detect changes to the instrumented source. It 13220is an error if ``hash`` differs between two instances of 13221``llvm.instrprof.*`` that refer to the same name. 13222 13223The third argument is the value of the expression being profiled. The profiled 13224expression's value should be representable as an unsigned 64-bit value. The 13225fourth argument represents the kind of value profiling that is being done. The 13226supported value profiling kinds are enumerated through the 13227``InstrProfValueKind`` type declared in the 13228``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the 13229index of the instrumented expression within ``name``. It should be >= 0. 13230 13231Semantics: 13232"""""""""" 13233 13234This intrinsic represents the point where a call to a runtime routine 13235should be inserted for value profiling of target expressions. ``-instrprof`` 13236pass will generate the appropriate data structures and replace the 13237``llvm.instrprof.value.profile`` intrinsic with the call to the profile 13238runtime library with proper arguments. 13239 13240'``llvm.thread.pointer``' Intrinsic 13241^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13242 13243Syntax: 13244""""""" 13245 13246:: 13247 13248 declare i8* @llvm.thread.pointer() 13249 13250Overview: 13251""""""""" 13252 13253The '``llvm.thread.pointer``' intrinsic returns the value of the thread 13254pointer. 13255 13256Semantics: 13257"""""""""" 13258 13259The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area 13260for the current thread. The exact semantics of this value are target 13261specific: it may point to the start of TLS area, to the end, or somewhere 13262in the middle. Depending on the target, this intrinsic may read a register, 13263call a helper function, read from an alternate memory space, or perform 13264other operations necessary to locate the TLS area. Not all targets support 13265this intrinsic. 13266 13267'``llvm.call.preallocated.setup``' Intrinsic 13268^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13269 13270Syntax: 13271""""""" 13272 13273:: 13274 13275 declare token @llvm.call.preallocated.setup(i32 %num_args) 13276 13277Overview: 13278""""""""" 13279 13280The '``llvm.call.preallocated.setup``' intrinsic returns a token which can 13281be used with a call's ``"preallocated"`` operand bundle to indicate that 13282certain arguments are allocated and initialized before the call. 13283 13284Semantics: 13285"""""""""" 13286 13287The '``llvm.call.preallocated.setup``' intrinsic returns a token which is 13288associated with at most one call. The token can be passed to 13289'``@llvm.call.preallocated.arg``' to get a pointer to get that 13290corresponding argument. The token must be the parameter to a 13291``"preallocated"`` operand bundle for the corresponding call. 13292 13293Nested calls to '``llvm.call.preallocated.setup``' are allowed, but must 13294be properly nested. e.g. 13295 13296:: code-block:: llvm 13297 13298 %t1 = call token @llvm.call.preallocated.setup(i32 0) 13299 %t2 = call token @llvm.call.preallocated.setup(i32 0) 13300 call void foo() ["preallocated"(token %t2)] 13301 call void foo() ["preallocated"(token %t1)] 13302 13303is allowed, but not 13304 13305:: code-block:: llvm 13306 13307 %t1 = call token @llvm.call.preallocated.setup(i32 0) 13308 %t2 = call token @llvm.call.preallocated.setup(i32 0) 13309 call void foo() ["preallocated"(token %t1)] 13310 call void foo() ["preallocated"(token %t2)] 13311 13312.. _int_call_preallocated_arg: 13313 13314'``llvm.call.preallocated.arg``' Intrinsic 13315^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13316 13317Syntax: 13318""""""" 13319 13320:: 13321 13322 declare i8* @llvm.call.preallocated.arg(token %setup_token, i32 %arg_index) 13323 13324Overview: 13325""""""""" 13326 13327The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the 13328corresponding preallocated argument for the preallocated call. 13329 13330Semantics: 13331"""""""""" 13332 13333The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the 13334``%arg_index``th argument with the ``preallocated`` attribute for 13335the call associated with the ``%setup_token``, which must be from 13336'``llvm.call.preallocated.setup``'. 13337 13338A call to '``llvm.call.preallocated.arg``' must have a call site 13339``preallocated`` attribute. The type of the ``preallocated`` attribute must 13340match the type used by the ``preallocated`` attribute of the corresponding 13341argument at the preallocated call. The type is used in the case that an 13342``llvm.call.preallocated.setup`` does not have a corresponding call (e.g. due 13343to DCE), where otherwise we cannot know how large the arguments are. 13344 13345It is undefined behavior if this is called with a token from an 13346'``llvm.call.preallocated.setup``' if another 13347'``llvm.call.preallocated.setup``' has already been called or if the 13348preallocated call corresponding to the '``llvm.call.preallocated.setup``' 13349has already been called. 13350 13351.. _int_call_preallocated_teardown: 13352 13353'``llvm.call.preallocated.teardown``' Intrinsic 13354^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13355 13356Syntax: 13357""""""" 13358 13359:: 13360 13361 declare i8* @llvm.call.preallocated.teardown(token %setup_token) 13362 13363Overview: 13364""""""""" 13365 13366The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack 13367created by a '``llvm.call.preallocated.setup``'. 13368 13369Semantics: 13370"""""""""" 13371 13372The token argument must be a '``llvm.call.preallocated.setup``'. 13373 13374The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack 13375allocated by the corresponding '``llvm.call.preallocated.setup``'. Exactly 13376one of this or the preallocated call must be called to prevent stack leaks. 13377It is undefined behavior to call both a '``llvm.call.preallocated.teardown``' 13378and the preallocated call for a given '``llvm.call.preallocated.setup``'. 13379 13380For example, if the stack is allocated for a preallocated call by a 13381'``llvm.call.preallocated.setup``', then an initializer function called on an 13382allocated argument throws an exception, there should be a 13383'``llvm.call.preallocated.teardown``' in the exception handler to prevent 13384stack leaks. 13385 13386Following the nesting rules in '``llvm.call.preallocated.setup``', nested 13387calls to '``llvm.call.preallocated.setup``' and 13388'``llvm.call.preallocated.teardown``' are allowed but must be properly 13389nested. 13390 13391Example: 13392"""""""" 13393 13394.. code-block:: llvm 13395 13396 %cs = call token @llvm.call.preallocated.setup(i32 1) 13397 %x = call i8* @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32) 13398 %y = bitcast i8* %x to i32* 13399 invoke void @constructor(i32* %y) to label %conta unwind label %contb 13400 conta: 13401 call void @foo1(i32* preallocated(i32) %y) ["preallocated"(token %cs)] 13402 ret void 13403 contb: 13404 %s = catchswitch within none [label %catch] unwind to caller 13405 catch: 13406 %p = catchpad within %s [] 13407 call void @llvm.call.preallocated.teardown(token %cs) 13408 ret void 13409 13410Standard C/C++ Library Intrinsics 13411--------------------------------- 13412 13413LLVM provides intrinsics for a few important standard C/C++ library 13414functions. These intrinsics allow source-language front-ends to pass 13415information about the alignment of the pointer arguments to the code 13416generator, providing opportunity for more efficient code generation. 13417 13418 13419'``llvm.abs.*``' Intrinsic 13420^^^^^^^^^^^^^^^^^^^^^^^^^^ 13421 13422Syntax: 13423""""""" 13424 13425This is an overloaded intrinsic. You can use ``llvm.abs`` on any 13426integer bit width or any vector of integer elements. 13427 13428:: 13429 13430 declare i32 @llvm.abs.i32(i32 <src>, i1 <is_int_min_poison>) 13431 declare <4 x i32> @llvm.abs.v4i32(<4 x i32> <src>, i1 <is_int_min_poison>) 13432 13433Overview: 13434""""""""" 13435 13436The '``llvm.abs``' family of intrinsic functions returns the absolute value 13437of an argument. 13438 13439Arguments: 13440"""""""""" 13441 13442The first argument is the value for which the absolute value is to be returned. 13443This argument may be of any integer type or a vector with integer element type. 13444The return type must match the first argument type. 13445 13446The second argument must be a constant and is a flag to indicate whether the 13447result value of the '``llvm.abs``' intrinsic is a 13448:ref:`poison value <poisonvalues>` if the argument is statically or dynamically 13449an ``INT_MIN`` value. 13450 13451Semantics: 13452"""""""""" 13453 13454The '``llvm.abs``' intrinsic returns the magnitude (always positive) of the 13455argument or each element of a vector argument.". If the argument is ``INT_MIN``, 13456then the result is also ``INT_MIN`` if ``is_int_min_poison == 0`` and 13457``poison`` otherwise. 13458 13459 13460'``llvm.smax.*``' Intrinsic 13461^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13462 13463Syntax: 13464""""""" 13465 13466This is an overloaded intrinsic. You can use ``@llvm.smax`` on any 13467integer bit width or any vector of integer elements. 13468 13469:: 13470 13471 declare i32 @llvm.smax.i32(i32 %a, i32 %b) 13472 declare <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> %b) 13473 13474Overview: 13475""""""""" 13476 13477Return the larger of ``%a`` and ``%b`` comparing the values as signed integers. 13478Vector intrinsics operate on a per-element basis. The larger element of ``%a`` 13479and ``%b`` at a given index is returned for that index. 13480 13481Arguments: 13482"""""""""" 13483 13484The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13485integer element type. The argument types must match each other, and the return 13486type must match the argument type. 13487 13488 13489'``llvm.smin.*``' Intrinsic 13490^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13491 13492Syntax: 13493""""""" 13494 13495This is an overloaded intrinsic. You can use ``@llvm.smin`` on any 13496integer bit width or any vector of integer elements. 13497 13498:: 13499 13500 declare i32 @llvm.smin.i32(i32 %a, i32 %b) 13501 declare <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> %b) 13502 13503Overview: 13504""""""""" 13505 13506Return the smaller of ``%a`` and ``%b`` comparing the values as signed integers. 13507Vector intrinsics operate on a per-element basis. The smaller element of ``%a`` 13508and ``%b`` at a given index is returned for that index. 13509 13510Arguments: 13511"""""""""" 13512 13513The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13514integer element type. The argument types must match each other, and the return 13515type must match the argument type. 13516 13517 13518'``llvm.umax.*``' Intrinsic 13519^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13520 13521Syntax: 13522""""""" 13523 13524This is an overloaded intrinsic. You can use ``@llvm.umax`` on any 13525integer bit width or any vector of integer elements. 13526 13527:: 13528 13529 declare i32 @llvm.umax.i32(i32 %a, i32 %b) 13530 declare <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> %b) 13531 13532Overview: 13533""""""""" 13534 13535Return the larger of ``%a`` and ``%b`` comparing the values as unsigned 13536integers. Vector intrinsics operate on a per-element basis. The larger element 13537of ``%a`` and ``%b`` at a given index is returned for that index. 13538 13539Arguments: 13540"""""""""" 13541 13542The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13543integer element type. The argument types must match each other, and the return 13544type must match the argument type. 13545 13546 13547'``llvm.umin.*``' Intrinsic 13548^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13549 13550Syntax: 13551""""""" 13552 13553This is an overloaded intrinsic. You can use ``@llvm.umin`` on any 13554integer bit width or any vector of integer elements. 13555 13556:: 13557 13558 declare i32 @llvm.umin.i32(i32 %a, i32 %b) 13559 declare <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> %b) 13560 13561Overview: 13562""""""""" 13563 13564Return the smaller of ``%a`` and ``%b`` comparing the values as unsigned 13565integers. Vector intrinsics operate on a per-element basis. The smaller element 13566of ``%a`` and ``%b`` at a given index is returned for that index. 13567 13568Arguments: 13569"""""""""" 13570 13571The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13572integer element type. The argument types must match each other, and the return 13573type must match the argument type. 13574 13575 13576.. _int_memcpy: 13577 13578'``llvm.memcpy``' Intrinsic 13579^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13580 13581Syntax: 13582""""""" 13583 13584This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any 13585integer bit width and for different address spaces. Not all targets 13586support all bit widths however. 13587 13588:: 13589 13590 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 13591 i32 <len>, i1 <isvolatile>) 13592 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 13593 i64 <len>, i1 <isvolatile>) 13594 13595Overview: 13596""""""""" 13597 13598The '``llvm.memcpy.*``' intrinsics copy a block of memory from the 13599source location to the destination location. 13600 13601Note that, unlike the standard libc function, the ``llvm.memcpy.*`` 13602intrinsics do not return a value, takes extra isvolatile 13603arguments and the pointers can be in specified address spaces. 13604 13605Arguments: 13606"""""""""" 13607 13608The first argument is a pointer to the destination, the second is a 13609pointer to the source. The third argument is an integer argument 13610specifying the number of bytes to copy, and the fourth is a 13611boolean indicating a volatile access. 13612 13613The :ref:`align <attr_align>` parameter attribute can be provided 13614for the first and second arguments. 13615 13616If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is 13617a :ref:`volatile operation <volatile>`. The detailed access behavior is not 13618very cleanly specified and it is unwise to depend on it. 13619 13620Semantics: 13621"""""""""" 13622 13623The '``llvm.memcpy.*``' intrinsics copy a block of memory from the source 13624location to the destination location, which must either be equal or 13625non-overlapping. It copies "len" bytes of memory over. If the argument is known 13626to be aligned to some boundary, this can be specified as an attribute on the 13627argument. 13628 13629If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 13630the arguments. 13631If ``<len>`` is not a well-defined value, the behavior is undefined. 13632If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined, 13633otherwise the behavior is undefined. 13634 13635.. _int_memcpy_inline: 13636 13637'``llvm.memcpy.inline``' Intrinsic 13638^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13639 13640Syntax: 13641""""""" 13642 13643This is an overloaded intrinsic. You can use ``llvm.memcpy.inline`` on any 13644integer bit width and for different address spaces. Not all targets 13645support all bit widths however. 13646 13647:: 13648 13649 declare void @llvm.memcpy.inline.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 13650 i32 <len>, i1 <isvolatile>) 13651 declare void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 13652 i64 <len>, i1 <isvolatile>) 13653 13654Overview: 13655""""""""" 13656 13657The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the 13658source location to the destination location and guarantees that no external 13659functions are called. 13660 13661Note that, unlike the standard libc function, the ``llvm.memcpy.inline.*`` 13662intrinsics do not return a value, takes extra isvolatile 13663arguments and the pointers can be in specified address spaces. 13664 13665Arguments: 13666"""""""""" 13667 13668The first argument is a pointer to the destination, the second is a 13669pointer to the source. The third argument is a constant integer argument 13670specifying the number of bytes to copy, and the fourth is a 13671boolean indicating a volatile access. 13672 13673The :ref:`align <attr_align>` parameter attribute can be provided 13674for the first and second arguments. 13675 13676If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy.inline`` call is 13677a :ref:`volatile operation <volatile>`. The detailed access behavior is not 13678very cleanly specified and it is unwise to depend on it. 13679 13680Semantics: 13681"""""""""" 13682 13683The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the 13684source location to the destination location, which are not allowed to 13685overlap. It copies "len" bytes of memory over. If the argument is known 13686to be aligned to some boundary, this can be specified as an attribute on 13687the argument. 13688The behavior of '``llvm.memcpy.inline.*``' is equivalent to the behavior of 13689'``llvm.memcpy.*``', but the generated code is guaranteed not to call any 13690external functions. 13691 13692.. _int_memmove: 13693 13694'``llvm.memmove``' Intrinsic 13695^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13696 13697Syntax: 13698""""""" 13699 13700This is an overloaded intrinsic. You can use llvm.memmove on any integer 13701bit width and for different address space. Not all targets support all 13702bit widths however. 13703 13704:: 13705 13706 declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 13707 i32 <len>, i1 <isvolatile>) 13708 declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 13709 i64 <len>, i1 <isvolatile>) 13710 13711Overview: 13712""""""""" 13713 13714The '``llvm.memmove.*``' intrinsics move a block of memory from the 13715source location to the destination location. It is similar to the 13716'``llvm.memcpy``' intrinsic but allows the two memory locations to 13717overlap. 13718 13719Note that, unlike the standard libc function, the ``llvm.memmove.*`` 13720intrinsics do not return a value, takes an extra isvolatile 13721argument and the pointers can be in specified address spaces. 13722 13723Arguments: 13724"""""""""" 13725 13726The first argument is a pointer to the destination, the second is a 13727pointer to the source. The third argument is an integer argument 13728specifying the number of bytes to copy, and the fourth is a 13729boolean indicating a volatile access. 13730 13731The :ref:`align <attr_align>` parameter attribute can be provided 13732for the first and second arguments. 13733 13734If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call 13735is a :ref:`volatile operation <volatile>`. The detailed access behavior is 13736not very cleanly specified and it is unwise to depend on it. 13737 13738Semantics: 13739"""""""""" 13740 13741The '``llvm.memmove.*``' intrinsics copy a block of memory from the 13742source location to the destination location, which may overlap. It 13743copies "len" bytes of memory over. If the argument is known to be 13744aligned to some boundary, this can be specified as an attribute on 13745the argument. 13746 13747If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 13748the arguments. 13749If ``<len>`` is not a well-defined value, the behavior is undefined. 13750If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined, 13751otherwise the behavior is undefined. 13752 13753.. _int_memset: 13754 13755'``llvm.memset.*``' Intrinsics 13756^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13757 13758Syntax: 13759""""""" 13760 13761This is an overloaded intrinsic. You can use llvm.memset on any integer 13762bit width and for different address spaces. However, not all targets 13763support all bit widths. 13764 13765:: 13766 13767 declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>, 13768 i32 <len>, i1 <isvolatile>) 13769 declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>, 13770 i64 <len>, i1 <isvolatile>) 13771 13772Overview: 13773""""""""" 13774 13775The '``llvm.memset.*``' intrinsics fill a block of memory with a 13776particular byte value. 13777 13778Note that, unlike the standard libc function, the ``llvm.memset`` 13779intrinsic does not return a value and takes an extra volatile 13780argument. Also, the destination can be in an arbitrary address space. 13781 13782Arguments: 13783"""""""""" 13784 13785The first argument is a pointer to the destination to fill, the second 13786is the byte value with which to fill it, the third argument is an 13787integer argument specifying the number of bytes to fill, and the fourth 13788is a boolean indicating a volatile access. 13789 13790The :ref:`align <attr_align>` parameter attribute can be provided 13791for the first arguments. 13792 13793If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is 13794a :ref:`volatile operation <volatile>`. The detailed access behavior is not 13795very cleanly specified and it is unwise to depend on it. 13796 13797Semantics: 13798"""""""""" 13799 13800The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting 13801at the destination location. If the argument is known to be 13802aligned to some boundary, this can be specified as an attribute on 13803the argument. 13804 13805If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 13806the arguments. 13807If ``<len>`` is not a well-defined value, the behavior is undefined. 13808If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined, 13809otherwise the behavior is undefined. 13810 13811'``llvm.sqrt.*``' Intrinsic 13812^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13813 13814Syntax: 13815""""""" 13816 13817This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any 13818floating-point or vector of floating-point type. Not all targets support 13819all types however. 13820 13821:: 13822 13823 declare float @llvm.sqrt.f32(float %Val) 13824 declare double @llvm.sqrt.f64(double %Val) 13825 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val) 13826 declare fp128 @llvm.sqrt.f128(fp128 %Val) 13827 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val) 13828 13829Overview: 13830""""""""" 13831 13832The '``llvm.sqrt``' intrinsics return the square root of the specified value. 13833 13834Arguments: 13835"""""""""" 13836 13837The argument and return value are floating-point numbers of the same type. 13838 13839Semantics: 13840"""""""""" 13841 13842Return the same value as a corresponding libm '``sqrt``' function but without 13843trapping or setting ``errno``. For types specified by IEEE-754, the result 13844matches a conforming libm implementation. 13845 13846When specified with the fast-math-flag 'afn', the result may be approximated 13847using a less accurate calculation. 13848 13849'``llvm.powi.*``' Intrinsic 13850^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13851 13852Syntax: 13853""""""" 13854 13855This is an overloaded intrinsic. You can use ``llvm.powi`` on any 13856floating-point or vector of floating-point type. Not all targets support 13857all types however. 13858 13859Generally, the only supported type for the exponent is the one matching 13860with the C type ``int``. 13861 13862:: 13863 13864 declare float @llvm.powi.f32.i32(float %Val, i32 %power) 13865 declare double @llvm.powi.f64.i16(double %Val, i16 %power) 13866 declare x86_fp80 @llvm.powi.f80.i32(x86_fp80 %Val, i32 %power) 13867 declare fp128 @llvm.powi.f128.i32(fp128 %Val, i32 %power) 13868 declare ppc_fp128 @llvm.powi.ppcf128.i32(ppc_fp128 %Val, i32 %power) 13869 13870Overview: 13871""""""""" 13872 13873The '``llvm.powi.*``' intrinsics return the first operand raised to the 13874specified (positive or negative) power. The order of evaluation of 13875multiplications is not defined. When a vector of floating-point type is 13876used, the second argument remains a scalar integer value. 13877 13878Arguments: 13879"""""""""" 13880 13881The second argument is an integer power, and the first is a value to 13882raise to that power. 13883 13884Semantics: 13885"""""""""" 13886 13887This function returns the first value raised to the second power with an 13888unspecified sequence of rounding operations. 13889 13890'``llvm.sin.*``' Intrinsic 13891^^^^^^^^^^^^^^^^^^^^^^^^^^ 13892 13893Syntax: 13894""""""" 13895 13896This is an overloaded intrinsic. You can use ``llvm.sin`` on any 13897floating-point or vector of floating-point type. Not all targets support 13898all types however. 13899 13900:: 13901 13902 declare float @llvm.sin.f32(float %Val) 13903 declare double @llvm.sin.f64(double %Val) 13904 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val) 13905 declare fp128 @llvm.sin.f128(fp128 %Val) 13906 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val) 13907 13908Overview: 13909""""""""" 13910 13911The '``llvm.sin.*``' intrinsics return the sine of the operand. 13912 13913Arguments: 13914"""""""""" 13915 13916The argument and return value are floating-point numbers of the same type. 13917 13918Semantics: 13919"""""""""" 13920 13921Return the same value as a corresponding libm '``sin``' function but without 13922trapping or setting ``errno``. 13923 13924When specified with the fast-math-flag 'afn', the result may be approximated 13925using a less accurate calculation. 13926 13927'``llvm.cos.*``' Intrinsic 13928^^^^^^^^^^^^^^^^^^^^^^^^^^ 13929 13930Syntax: 13931""""""" 13932 13933This is an overloaded intrinsic. You can use ``llvm.cos`` on any 13934floating-point or vector of floating-point type. Not all targets support 13935all types however. 13936 13937:: 13938 13939 declare float @llvm.cos.f32(float %Val) 13940 declare double @llvm.cos.f64(double %Val) 13941 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val) 13942 declare fp128 @llvm.cos.f128(fp128 %Val) 13943 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val) 13944 13945Overview: 13946""""""""" 13947 13948The '``llvm.cos.*``' intrinsics return the cosine of the operand. 13949 13950Arguments: 13951"""""""""" 13952 13953The argument and return value are floating-point numbers of the same type. 13954 13955Semantics: 13956"""""""""" 13957 13958Return the same value as a corresponding libm '``cos``' function but without 13959trapping or setting ``errno``. 13960 13961When specified with the fast-math-flag 'afn', the result may be approximated 13962using a less accurate calculation. 13963 13964'``llvm.pow.*``' Intrinsic 13965^^^^^^^^^^^^^^^^^^^^^^^^^^ 13966 13967Syntax: 13968""""""" 13969 13970This is an overloaded intrinsic. You can use ``llvm.pow`` on any 13971floating-point or vector of floating-point type. Not all targets support 13972all types however. 13973 13974:: 13975 13976 declare float @llvm.pow.f32(float %Val, float %Power) 13977 declare double @llvm.pow.f64(double %Val, double %Power) 13978 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power) 13979 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power) 13980 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power) 13981 13982Overview: 13983""""""""" 13984 13985The '``llvm.pow.*``' intrinsics return the first operand raised to the 13986specified (positive or negative) power. 13987 13988Arguments: 13989"""""""""" 13990 13991The arguments and return value are floating-point numbers of the same type. 13992 13993Semantics: 13994"""""""""" 13995 13996Return the same value as a corresponding libm '``pow``' function but without 13997trapping or setting ``errno``. 13998 13999When specified with the fast-math-flag 'afn', the result may be approximated 14000using a less accurate calculation. 14001 14002'``llvm.exp.*``' Intrinsic 14003^^^^^^^^^^^^^^^^^^^^^^^^^^ 14004 14005Syntax: 14006""""""" 14007 14008This is an overloaded intrinsic. You can use ``llvm.exp`` on any 14009floating-point or vector of floating-point type. Not all targets support 14010all types however. 14011 14012:: 14013 14014 declare float @llvm.exp.f32(float %Val) 14015 declare double @llvm.exp.f64(double %Val) 14016 declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val) 14017 declare fp128 @llvm.exp.f128(fp128 %Val) 14018 declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val) 14019 14020Overview: 14021""""""""" 14022 14023The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified 14024value. 14025 14026Arguments: 14027"""""""""" 14028 14029The argument and return value are floating-point numbers of the same type. 14030 14031Semantics: 14032"""""""""" 14033 14034Return the same value as a corresponding libm '``exp``' function but without 14035trapping or setting ``errno``. 14036 14037When specified with the fast-math-flag 'afn', the result may be approximated 14038using a less accurate calculation. 14039 14040'``llvm.exp2.*``' Intrinsic 14041^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14042 14043Syntax: 14044""""""" 14045 14046This is an overloaded intrinsic. You can use ``llvm.exp2`` on any 14047floating-point or vector of floating-point type. Not all targets support 14048all types however. 14049 14050:: 14051 14052 declare float @llvm.exp2.f32(float %Val) 14053 declare double @llvm.exp2.f64(double %Val) 14054 declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val) 14055 declare fp128 @llvm.exp2.f128(fp128 %Val) 14056 declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val) 14057 14058Overview: 14059""""""""" 14060 14061The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the 14062specified value. 14063 14064Arguments: 14065"""""""""" 14066 14067The argument and return value are floating-point numbers of the same type. 14068 14069Semantics: 14070"""""""""" 14071 14072Return the same value as a corresponding libm '``exp2``' function but without 14073trapping or setting ``errno``. 14074 14075When specified with the fast-math-flag 'afn', the result may be approximated 14076using a less accurate calculation. 14077 14078'``llvm.log.*``' Intrinsic 14079^^^^^^^^^^^^^^^^^^^^^^^^^^ 14080 14081Syntax: 14082""""""" 14083 14084This is an overloaded intrinsic. You can use ``llvm.log`` on any 14085floating-point or vector of floating-point type. Not all targets support 14086all types however. 14087 14088:: 14089 14090 declare float @llvm.log.f32(float %Val) 14091 declare double @llvm.log.f64(double %Val) 14092 declare x86_fp80 @llvm.log.f80(x86_fp80 %Val) 14093 declare fp128 @llvm.log.f128(fp128 %Val) 14094 declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val) 14095 14096Overview: 14097""""""""" 14098 14099The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified 14100value. 14101 14102Arguments: 14103"""""""""" 14104 14105The argument and return value are floating-point numbers of the same type. 14106 14107Semantics: 14108"""""""""" 14109 14110Return the same value as a corresponding libm '``log``' function but without 14111trapping or setting ``errno``. 14112 14113When specified with the fast-math-flag 'afn', the result may be approximated 14114using a less accurate calculation. 14115 14116'``llvm.log10.*``' Intrinsic 14117^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14118 14119Syntax: 14120""""""" 14121 14122This is an overloaded intrinsic. You can use ``llvm.log10`` on any 14123floating-point or vector of floating-point type. Not all targets support 14124all types however. 14125 14126:: 14127 14128 declare float @llvm.log10.f32(float %Val) 14129 declare double @llvm.log10.f64(double %Val) 14130 declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val) 14131 declare fp128 @llvm.log10.f128(fp128 %Val) 14132 declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val) 14133 14134Overview: 14135""""""""" 14136 14137The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the 14138specified value. 14139 14140Arguments: 14141"""""""""" 14142 14143The argument and return value are floating-point numbers of the same type. 14144 14145Semantics: 14146"""""""""" 14147 14148Return the same value as a corresponding libm '``log10``' function but without 14149trapping or setting ``errno``. 14150 14151When specified with the fast-math-flag 'afn', the result may be approximated 14152using a less accurate calculation. 14153 14154'``llvm.log2.*``' Intrinsic 14155^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14156 14157Syntax: 14158""""""" 14159 14160This is an overloaded intrinsic. You can use ``llvm.log2`` on any 14161floating-point or vector of floating-point type. Not all targets support 14162all types however. 14163 14164:: 14165 14166 declare float @llvm.log2.f32(float %Val) 14167 declare double @llvm.log2.f64(double %Val) 14168 declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val) 14169 declare fp128 @llvm.log2.f128(fp128 %Val) 14170 declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val) 14171 14172Overview: 14173""""""""" 14174 14175The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified 14176value. 14177 14178Arguments: 14179"""""""""" 14180 14181The argument and return value are floating-point numbers of the same type. 14182 14183Semantics: 14184"""""""""" 14185 14186Return the same value as a corresponding libm '``log2``' function but without 14187trapping or setting ``errno``. 14188 14189When specified with the fast-math-flag 'afn', the result may be approximated 14190using a less accurate calculation. 14191 14192.. _int_fma: 14193 14194'``llvm.fma.*``' Intrinsic 14195^^^^^^^^^^^^^^^^^^^^^^^^^^ 14196 14197Syntax: 14198""""""" 14199 14200This is an overloaded intrinsic. You can use ``llvm.fma`` on any 14201floating-point or vector of floating-point type. Not all targets support 14202all types however. 14203 14204:: 14205 14206 declare float @llvm.fma.f32(float %a, float %b, float %c) 14207 declare double @llvm.fma.f64(double %a, double %b, double %c) 14208 declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c) 14209 declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c) 14210 declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c) 14211 14212Overview: 14213""""""""" 14214 14215The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation. 14216 14217Arguments: 14218"""""""""" 14219 14220The arguments and return value are floating-point numbers of the same type. 14221 14222Semantics: 14223"""""""""" 14224 14225Return the same value as a corresponding libm '``fma``' function but without 14226trapping or setting ``errno``. 14227 14228When specified with the fast-math-flag 'afn', the result may be approximated 14229using a less accurate calculation. 14230 14231'``llvm.fabs.*``' Intrinsic 14232^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14233 14234Syntax: 14235""""""" 14236 14237This is an overloaded intrinsic. You can use ``llvm.fabs`` on any 14238floating-point or vector of floating-point type. Not all targets support 14239all types however. 14240 14241:: 14242 14243 declare float @llvm.fabs.f32(float %Val) 14244 declare double @llvm.fabs.f64(double %Val) 14245 declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val) 14246 declare fp128 @llvm.fabs.f128(fp128 %Val) 14247 declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val) 14248 14249Overview: 14250""""""""" 14251 14252The '``llvm.fabs.*``' intrinsics return the absolute value of the 14253operand. 14254 14255Arguments: 14256"""""""""" 14257 14258The argument and return value are floating-point numbers of the same 14259type. 14260 14261Semantics: 14262"""""""""" 14263 14264This function returns the same values as the libm ``fabs`` functions 14265would, and handles error conditions in the same way. 14266 14267'``llvm.minnum.*``' Intrinsic 14268^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14269 14270Syntax: 14271""""""" 14272 14273This is an overloaded intrinsic. You can use ``llvm.minnum`` on any 14274floating-point or vector of floating-point type. Not all targets support 14275all types however. 14276 14277:: 14278 14279 declare float @llvm.minnum.f32(float %Val0, float %Val1) 14280 declare double @llvm.minnum.f64(double %Val0, double %Val1) 14281 declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14282 declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1) 14283 declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14284 14285Overview: 14286""""""""" 14287 14288The '``llvm.minnum.*``' intrinsics return the minimum of the two 14289arguments. 14290 14291 14292Arguments: 14293"""""""""" 14294 14295The arguments and return value are floating-point numbers of the same 14296type. 14297 14298Semantics: 14299"""""""""" 14300 14301Follows the IEEE-754 semantics for minNum, except for handling of 14302signaling NaNs. This match's the behavior of libm's fmin. 14303 14304If either operand is a NaN, returns the other non-NaN operand. Returns 14305NaN only if both operands are NaN. The returned NaN is always 14306quiet. If the operands compare equal, returns a value that compares 14307equal to both operands. This means that fmin(+/-0.0, +/-0.0) could 14308return either -0.0 or 0.0. 14309 14310Unlike the IEEE-754 2008 behavior, this does not distinguish between 14311signaling and quiet NaN inputs. If a target's implementation follows 14312the standard and returns a quiet NaN if either input is a signaling 14313NaN, the intrinsic lowering is responsible for quieting the inputs to 14314correctly return the non-NaN input (e.g. by using the equivalent of 14315``llvm.canonicalize``). 14316 14317 14318'``llvm.maxnum.*``' Intrinsic 14319^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14320 14321Syntax: 14322""""""" 14323 14324This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any 14325floating-point or vector of floating-point type. Not all targets support 14326all types however. 14327 14328:: 14329 14330 declare float @llvm.maxnum.f32(float %Val0, float %Val1) 14331 declare double @llvm.maxnum.f64(double %Val0, double %Val1) 14332 declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14333 declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1) 14334 declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14335 14336Overview: 14337""""""""" 14338 14339The '``llvm.maxnum.*``' intrinsics return the maximum of the two 14340arguments. 14341 14342 14343Arguments: 14344"""""""""" 14345 14346The arguments and return value are floating-point numbers of the same 14347type. 14348 14349Semantics: 14350"""""""""" 14351Follows the IEEE-754 semantics for maxNum except for the handling of 14352signaling NaNs. This matches the behavior of libm's fmax. 14353 14354If either operand is a NaN, returns the other non-NaN operand. Returns 14355NaN only if both operands are NaN. The returned NaN is always 14356quiet. If the operands compare equal, returns a value that compares 14357equal to both operands. This means that fmax(+/-0.0, +/-0.0) could 14358return either -0.0 or 0.0. 14359 14360Unlike the IEEE-754 2008 behavior, this does not distinguish between 14361signaling and quiet NaN inputs. If a target's implementation follows 14362the standard and returns a quiet NaN if either input is a signaling 14363NaN, the intrinsic lowering is responsible for quieting the inputs to 14364correctly return the non-NaN input (e.g. by using the equivalent of 14365``llvm.canonicalize``). 14366 14367'``llvm.minimum.*``' Intrinsic 14368^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14369 14370Syntax: 14371""""""" 14372 14373This is an overloaded intrinsic. You can use ``llvm.minimum`` on any 14374floating-point or vector of floating-point type. Not all targets support 14375all types however. 14376 14377:: 14378 14379 declare float @llvm.minimum.f32(float %Val0, float %Val1) 14380 declare double @llvm.minimum.f64(double %Val0, double %Val1) 14381 declare x86_fp80 @llvm.minimum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14382 declare fp128 @llvm.minimum.f128(fp128 %Val0, fp128 %Val1) 14383 declare ppc_fp128 @llvm.minimum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14384 14385Overview: 14386""""""""" 14387 14388The '``llvm.minimum.*``' intrinsics return the minimum of the two 14389arguments, propagating NaNs and treating -0.0 as less than +0.0. 14390 14391 14392Arguments: 14393"""""""""" 14394 14395The arguments and return value are floating-point numbers of the same 14396type. 14397 14398Semantics: 14399"""""""""" 14400If either operand is a NaN, returns NaN. Otherwise returns the lesser 14401of the two arguments. -0.0 is considered to be less than +0.0 for this 14402intrinsic. Note that these are the semantics specified in the draft of 14403IEEE 754-2018. 14404 14405'``llvm.maximum.*``' Intrinsic 14406^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14407 14408Syntax: 14409""""""" 14410 14411This is an overloaded intrinsic. You can use ``llvm.maximum`` on any 14412floating-point or vector of floating-point type. Not all targets support 14413all types however. 14414 14415:: 14416 14417 declare float @llvm.maximum.f32(float %Val0, float %Val1) 14418 declare double @llvm.maximum.f64(double %Val0, double %Val1) 14419 declare x86_fp80 @llvm.maximum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14420 declare fp128 @llvm.maximum.f128(fp128 %Val0, fp128 %Val1) 14421 declare ppc_fp128 @llvm.maximum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14422 14423Overview: 14424""""""""" 14425 14426The '``llvm.maximum.*``' intrinsics return the maximum of the two 14427arguments, propagating NaNs and treating -0.0 as less than +0.0. 14428 14429 14430Arguments: 14431"""""""""" 14432 14433The arguments and return value are floating-point numbers of the same 14434type. 14435 14436Semantics: 14437"""""""""" 14438If either operand is a NaN, returns NaN. Otherwise returns the greater 14439of the two arguments. -0.0 is considered to be less than +0.0 for this 14440intrinsic. Note that these are the semantics specified in the draft of 14441IEEE 754-2018. 14442 14443'``llvm.copysign.*``' Intrinsic 14444^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14445 14446Syntax: 14447""""""" 14448 14449This is an overloaded intrinsic. You can use ``llvm.copysign`` on any 14450floating-point or vector of floating-point type. Not all targets support 14451all types however. 14452 14453:: 14454 14455 declare float @llvm.copysign.f32(float %Mag, float %Sgn) 14456 declare double @llvm.copysign.f64(double %Mag, double %Sgn) 14457 declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn) 14458 declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn) 14459 declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn) 14460 14461Overview: 14462""""""""" 14463 14464The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the 14465first operand and the sign of the second operand. 14466 14467Arguments: 14468"""""""""" 14469 14470The arguments and return value are floating-point numbers of the same 14471type. 14472 14473Semantics: 14474"""""""""" 14475 14476This function returns the same values as the libm ``copysign`` 14477functions would, and handles error conditions in the same way. 14478 14479'``llvm.floor.*``' Intrinsic 14480^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14481 14482Syntax: 14483""""""" 14484 14485This is an overloaded intrinsic. You can use ``llvm.floor`` on any 14486floating-point or vector of floating-point type. Not all targets support 14487all types however. 14488 14489:: 14490 14491 declare float @llvm.floor.f32(float %Val) 14492 declare double @llvm.floor.f64(double %Val) 14493 declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val) 14494 declare fp128 @llvm.floor.f128(fp128 %Val) 14495 declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val) 14496 14497Overview: 14498""""""""" 14499 14500The '``llvm.floor.*``' intrinsics return the floor of the operand. 14501 14502Arguments: 14503"""""""""" 14504 14505The argument and return value are floating-point numbers of the same 14506type. 14507 14508Semantics: 14509"""""""""" 14510 14511This function returns the same values as the libm ``floor`` functions 14512would, and handles error conditions in the same way. 14513 14514'``llvm.ceil.*``' Intrinsic 14515^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14516 14517Syntax: 14518""""""" 14519 14520This is an overloaded intrinsic. You can use ``llvm.ceil`` on any 14521floating-point or vector of floating-point type. Not all targets support 14522all types however. 14523 14524:: 14525 14526 declare float @llvm.ceil.f32(float %Val) 14527 declare double @llvm.ceil.f64(double %Val) 14528 declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val) 14529 declare fp128 @llvm.ceil.f128(fp128 %Val) 14530 declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val) 14531 14532Overview: 14533""""""""" 14534 14535The '``llvm.ceil.*``' intrinsics return the ceiling of the operand. 14536 14537Arguments: 14538"""""""""" 14539 14540The argument and return value are floating-point numbers of the same 14541type. 14542 14543Semantics: 14544"""""""""" 14545 14546This function returns the same values as the libm ``ceil`` functions 14547would, and handles error conditions in the same way. 14548 14549'``llvm.trunc.*``' Intrinsic 14550^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14551 14552Syntax: 14553""""""" 14554 14555This is an overloaded intrinsic. You can use ``llvm.trunc`` on any 14556floating-point or vector of floating-point type. Not all targets support 14557all types however. 14558 14559:: 14560 14561 declare float @llvm.trunc.f32(float %Val) 14562 declare double @llvm.trunc.f64(double %Val) 14563 declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val) 14564 declare fp128 @llvm.trunc.f128(fp128 %Val) 14565 declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val) 14566 14567Overview: 14568""""""""" 14569 14570The '``llvm.trunc.*``' intrinsics returns the operand rounded to the 14571nearest integer not larger in magnitude than the operand. 14572 14573Arguments: 14574"""""""""" 14575 14576The argument and return value are floating-point numbers of the same 14577type. 14578 14579Semantics: 14580"""""""""" 14581 14582This function returns the same values as the libm ``trunc`` functions 14583would, and handles error conditions in the same way. 14584 14585'``llvm.rint.*``' Intrinsic 14586^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14587 14588Syntax: 14589""""""" 14590 14591This is an overloaded intrinsic. You can use ``llvm.rint`` on any 14592floating-point or vector of floating-point type. Not all targets support 14593all types however. 14594 14595:: 14596 14597 declare float @llvm.rint.f32(float %Val) 14598 declare double @llvm.rint.f64(double %Val) 14599 declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val) 14600 declare fp128 @llvm.rint.f128(fp128 %Val) 14601 declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val) 14602 14603Overview: 14604""""""""" 14605 14606The '``llvm.rint.*``' intrinsics returns the operand rounded to the 14607nearest integer. It may raise an inexact floating-point exception if the 14608operand isn't an integer. 14609 14610Arguments: 14611"""""""""" 14612 14613The argument and return value are floating-point numbers of the same 14614type. 14615 14616Semantics: 14617"""""""""" 14618 14619This function returns the same values as the libm ``rint`` functions 14620would, and handles error conditions in the same way. 14621 14622'``llvm.nearbyint.*``' Intrinsic 14623^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14624 14625Syntax: 14626""""""" 14627 14628This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any 14629floating-point or vector of floating-point type. Not all targets support 14630all types however. 14631 14632:: 14633 14634 declare float @llvm.nearbyint.f32(float %Val) 14635 declare double @llvm.nearbyint.f64(double %Val) 14636 declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val) 14637 declare fp128 @llvm.nearbyint.f128(fp128 %Val) 14638 declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val) 14639 14640Overview: 14641""""""""" 14642 14643The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the 14644nearest integer. 14645 14646Arguments: 14647"""""""""" 14648 14649The argument and return value are floating-point numbers of the same 14650type. 14651 14652Semantics: 14653"""""""""" 14654 14655This function returns the same values as the libm ``nearbyint`` 14656functions would, and handles error conditions in the same way. 14657 14658'``llvm.round.*``' Intrinsic 14659^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14660 14661Syntax: 14662""""""" 14663 14664This is an overloaded intrinsic. You can use ``llvm.round`` on any 14665floating-point or vector of floating-point type. Not all targets support 14666all types however. 14667 14668:: 14669 14670 declare float @llvm.round.f32(float %Val) 14671 declare double @llvm.round.f64(double %Val) 14672 declare x86_fp80 @llvm.round.f80(x86_fp80 %Val) 14673 declare fp128 @llvm.round.f128(fp128 %Val) 14674 declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val) 14675 14676Overview: 14677""""""""" 14678 14679The '``llvm.round.*``' intrinsics returns the operand rounded to the 14680nearest integer. 14681 14682Arguments: 14683"""""""""" 14684 14685The argument and return value are floating-point numbers of the same 14686type. 14687 14688Semantics: 14689"""""""""" 14690 14691This function returns the same values as the libm ``round`` 14692functions would, and handles error conditions in the same way. 14693 14694'``llvm.roundeven.*``' Intrinsic 14695^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14696 14697Syntax: 14698""""""" 14699 14700This is an overloaded intrinsic. You can use ``llvm.roundeven`` on any 14701floating-point or vector of floating-point type. Not all targets support 14702all types however. 14703 14704:: 14705 14706 declare float @llvm.roundeven.f32(float %Val) 14707 declare double @llvm.roundeven.f64(double %Val) 14708 declare x86_fp80 @llvm.roundeven.f80(x86_fp80 %Val) 14709 declare fp128 @llvm.roundeven.f128(fp128 %Val) 14710 declare ppc_fp128 @llvm.roundeven.ppcf128(ppc_fp128 %Val) 14711 14712Overview: 14713""""""""" 14714 14715The '``llvm.roundeven.*``' intrinsics returns the operand rounded to the nearest 14716integer in floating-point format rounding halfway cases to even (that is, to the 14717nearest value that is an even integer). 14718 14719Arguments: 14720"""""""""" 14721 14722The argument and return value are floating-point numbers of the same type. 14723 14724Semantics: 14725"""""""""" 14726 14727This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It 14728also behaves in the same way as C standard function ``roundeven``, except that 14729it does not raise floating point exceptions. 14730 14731 14732'``llvm.lround.*``' Intrinsic 14733^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14734 14735Syntax: 14736""""""" 14737 14738This is an overloaded intrinsic. You can use ``llvm.lround`` on any 14739floating-point type. Not all targets support all types however. 14740 14741:: 14742 14743 declare i32 @llvm.lround.i32.f32(float %Val) 14744 declare i32 @llvm.lround.i32.f64(double %Val) 14745 declare i32 @llvm.lround.i32.f80(float %Val) 14746 declare i32 @llvm.lround.i32.f128(double %Val) 14747 declare i32 @llvm.lround.i32.ppcf128(double %Val) 14748 14749 declare i64 @llvm.lround.i64.f32(float %Val) 14750 declare i64 @llvm.lround.i64.f64(double %Val) 14751 declare i64 @llvm.lround.i64.f80(float %Val) 14752 declare i64 @llvm.lround.i64.f128(double %Val) 14753 declare i64 @llvm.lround.i64.ppcf128(double %Val) 14754 14755Overview: 14756""""""""" 14757 14758The '``llvm.lround.*``' intrinsics return the operand rounded to the nearest 14759integer with ties away from zero. 14760 14761 14762Arguments: 14763"""""""""" 14764 14765The argument is a floating-point number and the return value is an integer 14766type. 14767 14768Semantics: 14769"""""""""" 14770 14771This function returns the same values as the libm ``lround`` 14772functions would, but without setting errno. 14773 14774'``llvm.llround.*``' Intrinsic 14775^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14776 14777Syntax: 14778""""""" 14779 14780This is an overloaded intrinsic. You can use ``llvm.llround`` on any 14781floating-point type. Not all targets support all types however. 14782 14783:: 14784 14785 declare i64 @llvm.lround.i64.f32(float %Val) 14786 declare i64 @llvm.lround.i64.f64(double %Val) 14787 declare i64 @llvm.lround.i64.f80(float %Val) 14788 declare i64 @llvm.lround.i64.f128(double %Val) 14789 declare i64 @llvm.lround.i64.ppcf128(double %Val) 14790 14791Overview: 14792""""""""" 14793 14794The '``llvm.llround.*``' intrinsics return the operand rounded to the nearest 14795integer with ties away from zero. 14796 14797Arguments: 14798"""""""""" 14799 14800The argument is a floating-point number and the return value is an integer 14801type. 14802 14803Semantics: 14804"""""""""" 14805 14806This function returns the same values as the libm ``llround`` 14807functions would, but without setting errno. 14808 14809'``llvm.lrint.*``' Intrinsic 14810^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14811 14812Syntax: 14813""""""" 14814 14815This is an overloaded intrinsic. You can use ``llvm.lrint`` on any 14816floating-point type. Not all targets support all types however. 14817 14818:: 14819 14820 declare i32 @llvm.lrint.i32.f32(float %Val) 14821 declare i32 @llvm.lrint.i32.f64(double %Val) 14822 declare i32 @llvm.lrint.i32.f80(float %Val) 14823 declare i32 @llvm.lrint.i32.f128(double %Val) 14824 declare i32 @llvm.lrint.i32.ppcf128(double %Val) 14825 14826 declare i64 @llvm.lrint.i64.f32(float %Val) 14827 declare i64 @llvm.lrint.i64.f64(double %Val) 14828 declare i64 @llvm.lrint.i64.f80(float %Val) 14829 declare i64 @llvm.lrint.i64.f128(double %Val) 14830 declare i64 @llvm.lrint.i64.ppcf128(double %Val) 14831 14832Overview: 14833""""""""" 14834 14835The '``llvm.lrint.*``' intrinsics return the operand rounded to the nearest 14836integer. 14837 14838 14839Arguments: 14840"""""""""" 14841 14842The argument is a floating-point number and the return value is an integer 14843type. 14844 14845Semantics: 14846"""""""""" 14847 14848This function returns the same values as the libm ``lrint`` 14849functions would, but without setting errno. 14850 14851'``llvm.llrint.*``' Intrinsic 14852^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14853 14854Syntax: 14855""""""" 14856 14857This is an overloaded intrinsic. You can use ``llvm.llrint`` on any 14858floating-point type. Not all targets support all types however. 14859 14860:: 14861 14862 declare i64 @llvm.llrint.i64.f32(float %Val) 14863 declare i64 @llvm.llrint.i64.f64(double %Val) 14864 declare i64 @llvm.llrint.i64.f80(float %Val) 14865 declare i64 @llvm.llrint.i64.f128(double %Val) 14866 declare i64 @llvm.llrint.i64.ppcf128(double %Val) 14867 14868Overview: 14869""""""""" 14870 14871The '``llvm.llrint.*``' intrinsics return the operand rounded to the nearest 14872integer. 14873 14874Arguments: 14875"""""""""" 14876 14877The argument is a floating-point number and the return value is an integer 14878type. 14879 14880Semantics: 14881"""""""""" 14882 14883This function returns the same values as the libm ``llrint`` 14884functions would, but without setting errno. 14885 14886Bit Manipulation Intrinsics 14887--------------------------- 14888 14889LLVM provides intrinsics for a few important bit manipulation 14890operations. These allow efficient code generation for some algorithms. 14891 14892'``llvm.bitreverse.*``' Intrinsics 14893^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14894 14895Syntax: 14896""""""" 14897 14898This is an overloaded intrinsic function. You can use bitreverse on any 14899integer type. 14900 14901:: 14902 14903 declare i16 @llvm.bitreverse.i16(i16 <id>) 14904 declare i32 @llvm.bitreverse.i32(i32 <id>) 14905 declare i64 @llvm.bitreverse.i64(i64 <id>) 14906 declare <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> <id>) 14907 14908Overview: 14909""""""""" 14910 14911The '``llvm.bitreverse``' family of intrinsics is used to reverse the 14912bitpattern of an integer value or vector of integer values; for example 14913``0b10110110`` becomes ``0b01101101``. 14914 14915Semantics: 14916"""""""""" 14917 14918The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit 14919``M`` in the input moved to bit ``N-M`` in the output. The vector 14920intrinsics, such as ``llvm.bitreverse.v4i32``, operate on a per-element 14921basis and the element order is not affected. 14922 14923'``llvm.bswap.*``' Intrinsics 14924^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14925 14926Syntax: 14927""""""" 14928 14929This is an overloaded intrinsic function. You can use bswap on any 14930integer type that is an even number of bytes (i.e. BitWidth % 16 == 0). 14931 14932:: 14933 14934 declare i16 @llvm.bswap.i16(i16 <id>) 14935 declare i32 @llvm.bswap.i32(i32 <id>) 14936 declare i64 @llvm.bswap.i64(i64 <id>) 14937 declare <4 x i32> @llvm.bswap.v4i32(<4 x i32> <id>) 14938 14939Overview: 14940""""""""" 14941 14942The '``llvm.bswap``' family of intrinsics is used to byte swap an integer 14943value or vector of integer values with an even number of bytes (positive 14944multiple of 16 bits). 14945 14946Semantics: 14947"""""""""" 14948 14949The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high 14950and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32`` 14951intrinsic returns an i32 value that has the four bytes of the input i32 14952swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the 14953returned i32 will have its bytes in 3, 2, 1, 0 order. The 14954``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this 14955concept to additional even-byte lengths (6 bytes, 8 bytes and more, 14956respectively). The vector intrinsics, such as ``llvm.bswap.v4i32``, 14957operate on a per-element basis and the element order is not affected. 14958 14959'``llvm.ctpop.*``' Intrinsic 14960^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14961 14962Syntax: 14963""""""" 14964 14965This is an overloaded intrinsic. You can use llvm.ctpop on any integer 14966bit width, or on any vector with integer elements. Not all targets 14967support all bit widths or vector types, however. 14968 14969:: 14970 14971 declare i8 @llvm.ctpop.i8(i8 <src>) 14972 declare i16 @llvm.ctpop.i16(i16 <src>) 14973 declare i32 @llvm.ctpop.i32(i32 <src>) 14974 declare i64 @llvm.ctpop.i64(i64 <src>) 14975 declare i256 @llvm.ctpop.i256(i256 <src>) 14976 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>) 14977 14978Overview: 14979""""""""" 14980 14981The '``llvm.ctpop``' family of intrinsics counts the number of bits set 14982in a value. 14983 14984Arguments: 14985"""""""""" 14986 14987The only argument is the value to be counted. The argument may be of any 14988integer type, or a vector with integer elements. The return type must 14989match the argument type. 14990 14991Semantics: 14992"""""""""" 14993 14994The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within 14995each element of a vector. 14996 14997'``llvm.ctlz.*``' Intrinsic 14998^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14999 15000Syntax: 15001""""""" 15002 15003This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any 15004integer bit width, or any vector whose elements are integers. Not all 15005targets support all bit widths or vector types, however. 15006 15007:: 15008 15009 declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_poison>) 15010 declare <2 x i37> @llvm.ctlz.v2i37(<2 x i37> <src>, i1 <is_zero_poison>) 15011 15012Overview: 15013""""""""" 15014 15015The '``llvm.ctlz``' family of intrinsic functions counts the number of 15016leading zeros in a variable. 15017 15018Arguments: 15019"""""""""" 15020 15021The first argument is the value to be counted. This argument may be of 15022any integer type, or a vector with integer element type. The return 15023type must match the first argument type. 15024 15025The second argument is a constant flag that indicates whether the intrinsic 15026returns a valid result if the first argument is zero. If the first 15027argument is zero and the second argument is true, the result is poison. 15028Historically some architectures did not provide a defined result for zero 15029values as efficiently, and many algorithms are now predicated on avoiding 15030zero-value inputs. 15031 15032Semantics: 15033"""""""""" 15034 15035The '``llvm.ctlz``' intrinsic counts the leading (most significant) 15036zeros in a variable, or within each element of the vector. If 15037``src == 0`` then the result is the size in bits of the type of ``src`` 15038if ``is_zero_poison == 0`` and ``poison`` otherwise. For example, 15039``llvm.ctlz(i32 2) = 30``. 15040 15041'``llvm.cttz.*``' Intrinsic 15042^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15043 15044Syntax: 15045""""""" 15046 15047This is an overloaded intrinsic. You can use ``llvm.cttz`` on any 15048integer bit width, or any vector of integer elements. Not all targets 15049support all bit widths or vector types, however. 15050 15051:: 15052 15053 declare i42 @llvm.cttz.i42 (i42 <src>, i1 <is_zero_poison>) 15054 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_poison>) 15055 15056Overview: 15057""""""""" 15058 15059The '``llvm.cttz``' family of intrinsic functions counts the number of 15060trailing zeros. 15061 15062Arguments: 15063"""""""""" 15064 15065The first argument is the value to be counted. This argument may be of 15066any integer type, or a vector with integer element type. The return 15067type must match the first argument type. 15068 15069The second argument is a constant flag that indicates whether the intrinsic 15070returns a valid result if the first argument is zero. If the first 15071argument is zero and the second argument is true, the result is poison. 15072Historically some architectures did not provide a defined result for zero 15073values as efficiently, and many algorithms are now predicated on avoiding 15074zero-value inputs. 15075 15076Semantics: 15077"""""""""" 15078 15079The '``llvm.cttz``' intrinsic counts the trailing (least significant) 15080zeros in a variable, or within each element of a vector. If ``src == 0`` 15081then the result is the size in bits of the type of ``src`` if 15082``is_zero_poison == 0`` and ``poison`` otherwise. For example, 15083``llvm.cttz(2) = 1``. 15084 15085.. _int_overflow: 15086 15087'``llvm.fshl.*``' Intrinsic 15088^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15089 15090Syntax: 15091""""""" 15092 15093This is an overloaded intrinsic. You can use ``llvm.fshl`` on any 15094integer bit width or any vector of integer elements. Not all targets 15095support all bit widths or vector types, however. 15096 15097:: 15098 15099 declare i8 @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c) 15100 declare i67 @llvm.fshl.i67(i67 %a, i67 %b, i67 %c) 15101 declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) 15102 15103Overview: 15104""""""""" 15105 15106The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left: 15107the first two values are concatenated as { %a : %b } (%a is the most significant 15108bits of the wide value), the combined value is shifted left, and the most 15109significant bits are extracted to produce a result that is the same size as the 15110original arguments. If the first 2 arguments are identical, this is equivalent 15111to a rotate left operation. For vector types, the operation occurs for each 15112element of the vector. The shift argument is treated as an unsigned amount 15113modulo the element size of the arguments. 15114 15115Arguments: 15116"""""""""" 15117 15118The first two arguments are the values to be concatenated. The third 15119argument is the shift amount. The arguments may be any integer type or a 15120vector with integer element type. All arguments and the return value must 15121have the same type. 15122 15123Example: 15124"""""""" 15125 15126.. code-block:: text 15127 15128 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8) 15129 %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15) ; %r = i8: 128 (0b10000000) 15130 %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11) ; %r = i8: 120 (0b01111000) 15131 %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8) ; %r = i8: 0 (0b00000000) 15132 15133'``llvm.fshr.*``' Intrinsic 15134^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15135 15136Syntax: 15137""""""" 15138 15139This is an overloaded intrinsic. You can use ``llvm.fshr`` on any 15140integer bit width or any vector of integer elements. Not all targets 15141support all bit widths or vector types, however. 15142 15143:: 15144 15145 declare i8 @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c) 15146 declare i67 @llvm.fshr.i67(i67 %a, i67 %b, i67 %c) 15147 declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) 15148 15149Overview: 15150""""""""" 15151 15152The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right: 15153the first two values are concatenated as { %a : %b } (%a is the most significant 15154bits of the wide value), the combined value is shifted right, and the least 15155significant bits are extracted to produce a result that is the same size as the 15156original arguments. If the first 2 arguments are identical, this is equivalent 15157to a rotate right operation. For vector types, the operation occurs for each 15158element of the vector. The shift argument is treated as an unsigned amount 15159modulo the element size of the arguments. 15160 15161Arguments: 15162"""""""""" 15163 15164The first two arguments are the values to be concatenated. The third 15165argument is the shift amount. The arguments may be any integer type or a 15166vector with integer element type. All arguments and the return value must 15167have the same type. 15168 15169Example: 15170"""""""" 15171 15172.. code-block:: text 15173 15174 %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8) 15175 %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15) ; %r = i8: 254 (0b11111110) 15176 %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11) ; %r = i8: 225 (0b11100001) 15177 %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8) ; %r = i8: 255 (0b11111111) 15178 15179Arithmetic with Overflow Intrinsics 15180----------------------------------- 15181 15182LLVM provides intrinsics for fast arithmetic overflow checking. 15183 15184Each of these intrinsics returns a two-element struct. The first 15185element of this struct contains the result of the corresponding 15186arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of 15187the result. Therefore, for example, the first element of the struct 15188returned by ``llvm.sadd.with.overflow.i32`` is always the same as the 15189result of a 32-bit ``add`` instruction with the same operands, where 15190the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag. 15191 15192The second element of the result is an ``i1`` that is 1 if the 15193arithmetic operation overflowed and 0 otherwise. An operation 15194overflows if, for any values of its operands ``A`` and ``B`` and for 15195any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is 15196not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is 15197``sext`` for signed overflow and ``zext`` for unsigned overflow, and 15198``op`` is the underlying arithmetic operation. 15199 15200The behavior of these intrinsics is well-defined for all argument 15201values. 15202 15203'``llvm.sadd.with.overflow.*``' Intrinsics 15204^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15205 15206Syntax: 15207""""""" 15208 15209This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow`` 15210on any integer bit width or vectors of integers. 15211 15212:: 15213 15214 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b) 15215 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) 15216 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b) 15217 declare {<4 x i32>, <4 x i1>} @llvm.sadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15218 15219Overview: 15220""""""""" 15221 15222The '``llvm.sadd.with.overflow``' family of intrinsic functions perform 15223a signed addition of the two arguments, and indicate whether an overflow 15224occurred during the signed summation. 15225 15226Arguments: 15227"""""""""" 15228 15229The arguments (%a and %b) and the first element of the result structure 15230may be of integer types of any bit width, but they must have the same 15231bit width. The second element of the result structure must be of type 15232``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 15233addition. 15234 15235Semantics: 15236"""""""""" 15237 15238The '``llvm.sadd.with.overflow``' family of intrinsic functions perform 15239a signed addition of the two variables. They return a structure --- the 15240first element of which is the signed summation, and the second element 15241of which is a bit specifying if the signed summation resulted in an 15242overflow. 15243 15244Examples: 15245""""""""" 15246 15247.. code-block:: llvm 15248 15249 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) 15250 %sum = extractvalue {i32, i1} %res, 0 15251 %obit = extractvalue {i32, i1} %res, 1 15252 br i1 %obit, label %overflow, label %normal 15253 15254'``llvm.uadd.with.overflow.*``' Intrinsics 15255^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15256 15257Syntax: 15258""""""" 15259 15260This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow`` 15261on any integer bit width or vectors of integers. 15262 15263:: 15264 15265 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b) 15266 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) 15267 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b) 15268 declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15269 15270Overview: 15271""""""""" 15272 15273The '``llvm.uadd.with.overflow``' family of intrinsic functions perform 15274an unsigned addition of the two arguments, and indicate whether a carry 15275occurred during the unsigned summation. 15276 15277Arguments: 15278"""""""""" 15279 15280The arguments (%a and %b) and the first element of the result structure 15281may be of integer types of any bit width, but they must have the same 15282bit width. The second element of the result structure must be of type 15283``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 15284addition. 15285 15286Semantics: 15287"""""""""" 15288 15289The '``llvm.uadd.with.overflow``' family of intrinsic functions perform 15290an unsigned addition of the two arguments. They return a structure --- the 15291first element of which is the sum, and the second element of which is a 15292bit specifying if the unsigned summation resulted in a carry. 15293 15294Examples: 15295""""""""" 15296 15297.. code-block:: llvm 15298 15299 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) 15300 %sum = extractvalue {i32, i1} %res, 0 15301 %obit = extractvalue {i32, i1} %res, 1 15302 br i1 %obit, label %carry, label %normal 15303 15304'``llvm.ssub.with.overflow.*``' Intrinsics 15305^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15306 15307Syntax: 15308""""""" 15309 15310This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow`` 15311on any integer bit width or vectors of integers. 15312 15313:: 15314 15315 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b) 15316 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) 15317 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b) 15318 declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15319 15320Overview: 15321""""""""" 15322 15323The '``llvm.ssub.with.overflow``' family of intrinsic functions perform 15324a signed subtraction of the two arguments, and indicate whether an 15325overflow occurred during the signed subtraction. 15326 15327Arguments: 15328"""""""""" 15329 15330The arguments (%a and %b) and the first element of the result structure 15331may be of integer types of any bit width, but they must have the same 15332bit width. The second element of the result structure must be of type 15333``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 15334subtraction. 15335 15336Semantics: 15337"""""""""" 15338 15339The '``llvm.ssub.with.overflow``' family of intrinsic functions perform 15340a signed subtraction of the two arguments. They return a structure --- the 15341first element of which is the subtraction, and the second element of 15342which is a bit specifying if the signed subtraction resulted in an 15343overflow. 15344 15345Examples: 15346""""""""" 15347 15348.. code-block:: llvm 15349 15350 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) 15351 %sum = extractvalue {i32, i1} %res, 0 15352 %obit = extractvalue {i32, i1} %res, 1 15353 br i1 %obit, label %overflow, label %normal 15354 15355'``llvm.usub.with.overflow.*``' Intrinsics 15356^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15357 15358Syntax: 15359""""""" 15360 15361This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow`` 15362on any integer bit width or vectors of integers. 15363 15364:: 15365 15366 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b) 15367 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) 15368 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b) 15369 declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15370 15371Overview: 15372""""""""" 15373 15374The '``llvm.usub.with.overflow``' family of intrinsic functions perform 15375an unsigned subtraction of the two arguments, and indicate whether an 15376overflow occurred during the unsigned subtraction. 15377 15378Arguments: 15379"""""""""" 15380 15381The arguments (%a and %b) and the first element of the result structure 15382may be of integer types of any bit width, but they must have the same 15383bit width. The second element of the result structure must be of type 15384``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 15385subtraction. 15386 15387Semantics: 15388"""""""""" 15389 15390The '``llvm.usub.with.overflow``' family of intrinsic functions perform 15391an unsigned subtraction of the two arguments. They return a structure --- 15392the first element of which is the subtraction, and the second element of 15393which is a bit specifying if the unsigned subtraction resulted in an 15394overflow. 15395 15396Examples: 15397""""""""" 15398 15399.. code-block:: llvm 15400 15401 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) 15402 %sum = extractvalue {i32, i1} %res, 0 15403 %obit = extractvalue {i32, i1} %res, 1 15404 br i1 %obit, label %overflow, label %normal 15405 15406'``llvm.smul.with.overflow.*``' Intrinsics 15407^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15408 15409Syntax: 15410""""""" 15411 15412This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow`` 15413on any integer bit width or vectors of integers. 15414 15415:: 15416 15417 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b) 15418 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) 15419 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b) 15420 declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15421 15422Overview: 15423""""""""" 15424 15425The '``llvm.smul.with.overflow``' family of intrinsic functions perform 15426a signed multiplication of the two arguments, and indicate whether an 15427overflow occurred during the signed multiplication. 15428 15429Arguments: 15430"""""""""" 15431 15432The arguments (%a and %b) and the first element of the result structure 15433may be of integer types of any bit width, but they must have the same 15434bit width. The second element of the result structure must be of type 15435``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 15436multiplication. 15437 15438Semantics: 15439"""""""""" 15440 15441The '``llvm.smul.with.overflow``' family of intrinsic functions perform 15442a signed multiplication of the two arguments. They return a structure --- 15443the first element of which is the multiplication, and the second element 15444of which is a bit specifying if the signed multiplication resulted in an 15445overflow. 15446 15447Examples: 15448""""""""" 15449 15450.. code-block:: llvm 15451 15452 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) 15453 %sum = extractvalue {i32, i1} %res, 0 15454 %obit = extractvalue {i32, i1} %res, 1 15455 br i1 %obit, label %overflow, label %normal 15456 15457'``llvm.umul.with.overflow.*``' Intrinsics 15458^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15459 15460Syntax: 15461""""""" 15462 15463This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow`` 15464on any integer bit width or vectors of integers. 15465 15466:: 15467 15468 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b) 15469 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) 15470 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b) 15471 declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15472 15473Overview: 15474""""""""" 15475 15476The '``llvm.umul.with.overflow``' family of intrinsic functions perform 15477a unsigned multiplication of the two arguments, and indicate whether an 15478overflow occurred during the unsigned multiplication. 15479 15480Arguments: 15481"""""""""" 15482 15483The arguments (%a and %b) and the first element of the result structure 15484may be of integer types of any bit width, but they must have the same 15485bit width. The second element of the result structure must be of type 15486``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 15487multiplication. 15488 15489Semantics: 15490"""""""""" 15491 15492The '``llvm.umul.with.overflow``' family of intrinsic functions perform 15493an unsigned multiplication of the two arguments. They return a structure --- 15494the first element of which is the multiplication, and the second 15495element of which is a bit specifying if the unsigned multiplication 15496resulted in an overflow. 15497 15498Examples: 15499""""""""" 15500 15501.. code-block:: llvm 15502 15503 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) 15504 %sum = extractvalue {i32, i1} %res, 0 15505 %obit = extractvalue {i32, i1} %res, 1 15506 br i1 %obit, label %overflow, label %normal 15507 15508Saturation Arithmetic Intrinsics 15509--------------------------------- 15510 15511Saturation arithmetic is a version of arithmetic in which operations are 15512limited to a fixed range between a minimum and maximum value. If the result of 15513an operation is greater than the maximum value, the result is set (or 15514"clamped") to this maximum. If it is below the minimum, it is clamped to this 15515minimum. 15516 15517 15518'``llvm.sadd.sat.*``' Intrinsics 15519^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15520 15521Syntax 15522""""""" 15523 15524This is an overloaded intrinsic. You can use ``llvm.sadd.sat`` 15525on any integer bit width or vectors of integers. 15526 15527:: 15528 15529 declare i16 @llvm.sadd.sat.i16(i16 %a, i16 %b) 15530 declare i32 @llvm.sadd.sat.i32(i32 %a, i32 %b) 15531 declare i64 @llvm.sadd.sat.i64(i64 %a, i64 %b) 15532 declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15533 15534Overview 15535""""""""" 15536 15537The '``llvm.sadd.sat``' family of intrinsic functions perform signed 15538saturating addition on the 2 arguments. 15539 15540Arguments 15541"""""""""" 15542 15543The arguments (%a and %b) and the result may be of integer types of any bit 15544width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15545values that will undergo signed addition. 15546 15547Semantics: 15548"""""""""" 15549 15550The maximum value this operation can clamp to is the largest signed value 15551representable by the bit width of the arguments. The minimum value is the 15552smallest signed value representable by this bit width. 15553 15554 15555Examples 15556""""""""" 15557 15558.. code-block:: llvm 15559 15560 %res = call i4 @llvm.sadd.sat.i4(i4 1, i4 2) ; %res = 3 15561 %res = call i4 @llvm.sadd.sat.i4(i4 5, i4 6) ; %res = 7 15562 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 2) ; %res = -2 15563 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 -5) ; %res = -8 15564 15565 15566'``llvm.uadd.sat.*``' Intrinsics 15567^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15568 15569Syntax 15570""""""" 15571 15572This is an overloaded intrinsic. You can use ``llvm.uadd.sat`` 15573on any integer bit width or vectors of integers. 15574 15575:: 15576 15577 declare i16 @llvm.uadd.sat.i16(i16 %a, i16 %b) 15578 declare i32 @llvm.uadd.sat.i32(i32 %a, i32 %b) 15579 declare i64 @llvm.uadd.sat.i64(i64 %a, i64 %b) 15580 declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15581 15582Overview 15583""""""""" 15584 15585The '``llvm.uadd.sat``' family of intrinsic functions perform unsigned 15586saturating addition on the 2 arguments. 15587 15588Arguments 15589"""""""""" 15590 15591The arguments (%a and %b) and the result may be of integer types of any bit 15592width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15593values that will undergo unsigned addition. 15594 15595Semantics: 15596"""""""""" 15597 15598The maximum value this operation can clamp to is the largest unsigned value 15599representable by the bit width of the arguments. Because this is an unsigned 15600operation, the result will never saturate towards zero. 15601 15602 15603Examples 15604""""""""" 15605 15606.. code-block:: llvm 15607 15608 %res = call i4 @llvm.uadd.sat.i4(i4 1, i4 2) ; %res = 3 15609 %res = call i4 @llvm.uadd.sat.i4(i4 5, i4 6) ; %res = 11 15610 %res = call i4 @llvm.uadd.sat.i4(i4 8, i4 8) ; %res = 15 15611 15612 15613'``llvm.ssub.sat.*``' Intrinsics 15614^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15615 15616Syntax 15617""""""" 15618 15619This is an overloaded intrinsic. You can use ``llvm.ssub.sat`` 15620on any integer bit width or vectors of integers. 15621 15622:: 15623 15624 declare i16 @llvm.ssub.sat.i16(i16 %a, i16 %b) 15625 declare i32 @llvm.ssub.sat.i32(i32 %a, i32 %b) 15626 declare i64 @llvm.ssub.sat.i64(i64 %a, i64 %b) 15627 declare <4 x i32> @llvm.ssub.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15628 15629Overview 15630""""""""" 15631 15632The '``llvm.ssub.sat``' family of intrinsic functions perform signed 15633saturating subtraction on the 2 arguments. 15634 15635Arguments 15636"""""""""" 15637 15638The arguments (%a and %b) and the result may be of integer types of any bit 15639width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15640values that will undergo signed subtraction. 15641 15642Semantics: 15643"""""""""" 15644 15645The maximum value this operation can clamp to is the largest signed value 15646representable by the bit width of the arguments. The minimum value is the 15647smallest signed value representable by this bit width. 15648 15649 15650Examples 15651""""""""" 15652 15653.. code-block:: llvm 15654 15655 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 1) ; %res = 1 15656 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 6) ; %res = -4 15657 %res = call i4 @llvm.ssub.sat.i4(i4 -4, i4 5) ; %res = -8 15658 %res = call i4 @llvm.ssub.sat.i4(i4 4, i4 -5) ; %res = 7 15659 15660 15661'``llvm.usub.sat.*``' Intrinsics 15662^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15663 15664Syntax 15665""""""" 15666 15667This is an overloaded intrinsic. You can use ``llvm.usub.sat`` 15668on any integer bit width or vectors of integers. 15669 15670:: 15671 15672 declare i16 @llvm.usub.sat.i16(i16 %a, i16 %b) 15673 declare i32 @llvm.usub.sat.i32(i32 %a, i32 %b) 15674 declare i64 @llvm.usub.sat.i64(i64 %a, i64 %b) 15675 declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15676 15677Overview 15678""""""""" 15679 15680The '``llvm.usub.sat``' family of intrinsic functions perform unsigned 15681saturating subtraction on the 2 arguments. 15682 15683Arguments 15684"""""""""" 15685 15686The arguments (%a and %b) and the result may be of integer types of any bit 15687width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15688values that will undergo unsigned subtraction. 15689 15690Semantics: 15691"""""""""" 15692 15693The minimum value this operation can clamp to is 0, which is the smallest 15694unsigned value representable by the bit width of the unsigned arguments. 15695Because this is an unsigned operation, the result will never saturate towards 15696the largest possible value representable by this bit width. 15697 15698 15699Examples 15700""""""""" 15701 15702.. code-block:: llvm 15703 15704 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 1) ; %res = 1 15705 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 6) ; %res = 0 15706 15707 15708'``llvm.sshl.sat.*``' Intrinsics 15709^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15710 15711Syntax 15712""""""" 15713 15714This is an overloaded intrinsic. You can use ``llvm.sshl.sat`` 15715on integers or vectors of integers of any bit width. 15716 15717:: 15718 15719 declare i16 @llvm.sshl.sat.i16(i16 %a, i16 %b) 15720 declare i32 @llvm.sshl.sat.i32(i32 %a, i32 %b) 15721 declare i64 @llvm.sshl.sat.i64(i64 %a, i64 %b) 15722 declare <4 x i32> @llvm.sshl.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15723 15724Overview 15725""""""""" 15726 15727The '``llvm.sshl.sat``' family of intrinsic functions perform signed 15728saturating left shift on the first argument. 15729 15730Arguments 15731"""""""""" 15732 15733The arguments (``%a`` and ``%b``) and the result may be of integer types of any 15734bit width, but they must have the same bit width. ``%a`` is the value to be 15735shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or 15736dynamically) equal to or larger than the integer bit width of the arguments, 15737the result is a :ref:`poison value <poisonvalues>`. If the arguments are 15738vectors, each vector element of ``a`` is shifted by the corresponding shift 15739amount in ``b``. 15740 15741 15742Semantics: 15743"""""""""" 15744 15745The maximum value this operation can clamp to is the largest signed value 15746representable by the bit width of the arguments. The minimum value is the 15747smallest signed value representable by this bit width. 15748 15749 15750Examples 15751""""""""" 15752 15753.. code-block:: llvm 15754 15755 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 1) ; %res = 4 15756 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 2) ; %res = 7 15757 %res = call i4 @llvm.sshl.sat.i4(i4 -5, i4 1) ; %res = -8 15758 %res = call i4 @llvm.sshl.sat.i4(i4 -1, i4 1) ; %res = -2 15759 15760 15761'``llvm.ushl.sat.*``' Intrinsics 15762^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15763 15764Syntax 15765""""""" 15766 15767This is an overloaded intrinsic. You can use ``llvm.ushl.sat`` 15768on integers or vectors of integers of any bit width. 15769 15770:: 15771 15772 declare i16 @llvm.ushl.sat.i16(i16 %a, i16 %b) 15773 declare i32 @llvm.ushl.sat.i32(i32 %a, i32 %b) 15774 declare i64 @llvm.ushl.sat.i64(i64 %a, i64 %b) 15775 declare <4 x i32> @llvm.ushl.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15776 15777Overview 15778""""""""" 15779 15780The '``llvm.ushl.sat``' family of intrinsic functions perform unsigned 15781saturating left shift on the first argument. 15782 15783Arguments 15784"""""""""" 15785 15786The arguments (``%a`` and ``%b``) and the result may be of integer types of any 15787bit width, but they must have the same bit width. ``%a`` is the value to be 15788shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or 15789dynamically) equal to or larger than the integer bit width of the arguments, 15790the result is a :ref:`poison value <poisonvalues>`. If the arguments are 15791vectors, each vector element of ``a`` is shifted by the corresponding shift 15792amount in ``b``. 15793 15794Semantics: 15795"""""""""" 15796 15797The maximum value this operation can clamp to is the largest unsigned value 15798representable by the bit width of the arguments. 15799 15800 15801Examples 15802""""""""" 15803 15804.. code-block:: llvm 15805 15806 %res = call i4 @llvm.ushl.sat.i4(i4 2, i4 1) ; %res = 4 15807 %res = call i4 @llvm.ushl.sat.i4(i4 3, i4 3) ; %res = 15 15808 15809 15810Fixed Point Arithmetic Intrinsics 15811--------------------------------- 15812 15813A fixed point number represents a real data type for a number that has a fixed 15814number of digits after a radix point (equivalent to the decimal point '.'). 15815The number of digits after the radix point is referred as the `scale`. These 15816are useful for representing fractional values to a specific precision. The 15817following intrinsics perform fixed point arithmetic operations on 2 operands 15818of the same scale, specified as the third argument. 15819 15820The ``llvm.*mul.fix`` family of intrinsic functions represents a multiplication 15821of fixed point numbers through scaled integers. Therefore, fixed point 15822multiplication can be represented as 15823 15824.. code-block:: llvm 15825 15826 %result = call i4 @llvm.smul.fix.i4(i4 %a, i4 %b, i32 %scale) 15827 15828 ; Expands to 15829 %a2 = sext i4 %a to i8 15830 %b2 = sext i4 %b to i8 15831 %mul = mul nsw nuw i8 %a, %b 15832 %scale2 = trunc i32 %scale to i8 15833 %r = ashr i8 %mul, i8 %scale2 ; this is for a target rounding down towards negative infinity 15834 %result = trunc i8 %r to i4 15835 15836The ``llvm.*div.fix`` family of intrinsic functions represents a division of 15837fixed point numbers through scaled integers. Fixed point division can be 15838represented as: 15839 15840.. code-block:: llvm 15841 15842 %result call i4 @llvm.sdiv.fix.i4(i4 %a, i4 %b, i32 %scale) 15843 15844 ; Expands to 15845 %a2 = sext i4 %a to i8 15846 %b2 = sext i4 %b to i8 15847 %scale2 = trunc i32 %scale to i8 15848 %a3 = shl i8 %a2, %scale2 15849 %r = sdiv i8 %a3, %b2 ; this is for a target rounding towards zero 15850 %result = trunc i8 %r to i4 15851 15852For each of these functions, if the result cannot be represented exactly with 15853the provided scale, the result is rounded. Rounding is unspecified since 15854preferred rounding may vary for different targets. Rounding is specified 15855through a target hook. Different pipelines should legalize or optimize this 15856using the rounding specified by this hook if it is provided. Operations like 15857constant folding, instruction combining, KnownBits, and ValueTracking should 15858also use this hook, if provided, and not assume the direction of rounding. A 15859rounded result must always be within one unit of precision from the true 15860result. That is, the error between the returned result and the true result must 15861be less than 1/2^(scale). 15862 15863 15864'``llvm.smul.fix.*``' Intrinsics 15865^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15866 15867Syntax 15868""""""" 15869 15870This is an overloaded intrinsic. You can use ``llvm.smul.fix`` 15871on any integer bit width or vectors of integers. 15872 15873:: 15874 15875 declare i16 @llvm.smul.fix.i16(i16 %a, i16 %b, i32 %scale) 15876 declare i32 @llvm.smul.fix.i32(i32 %a, i32 %b, i32 %scale) 15877 declare i64 @llvm.smul.fix.i64(i64 %a, i64 %b, i32 %scale) 15878 declare <4 x i32> @llvm.smul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 15879 15880Overview 15881""""""""" 15882 15883The '``llvm.smul.fix``' family of intrinsic functions perform signed 15884fixed point multiplication on 2 arguments of the same scale. 15885 15886Arguments 15887"""""""""" 15888 15889The arguments (%a and %b) and the result may be of integer types of any bit 15890width, but they must have the same bit width. The arguments may also work with 15891int vectors of the same length and int size. ``%a`` and ``%b`` are the two 15892values that will undergo signed fixed point multiplication. The argument 15893``%scale`` represents the scale of both operands, and must be a constant 15894integer. 15895 15896Semantics: 15897"""""""""" 15898 15899This operation performs fixed point multiplication on the 2 arguments of a 15900specified scale. The result will also be returned in the same scale specified 15901in the third argument. 15902 15903If the result value cannot be precisely represented in the given scale, the 15904value is rounded up or down to the closest representable value. The rounding 15905direction is unspecified. 15906 15907It is undefined behavior if the result value does not fit within the range of 15908the fixed point type. 15909 15910 15911Examples 15912""""""""" 15913 15914.. code-block:: llvm 15915 15916 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 15917 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 15918 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5) 15919 15920 ; The result in the following could be rounded up to -2 or down to -2.5 15921 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25) 15922 15923 15924'``llvm.umul.fix.*``' Intrinsics 15925^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15926 15927Syntax 15928""""""" 15929 15930This is an overloaded intrinsic. You can use ``llvm.umul.fix`` 15931on any integer bit width or vectors of integers. 15932 15933:: 15934 15935 declare i16 @llvm.umul.fix.i16(i16 %a, i16 %b, i32 %scale) 15936 declare i32 @llvm.umul.fix.i32(i32 %a, i32 %b, i32 %scale) 15937 declare i64 @llvm.umul.fix.i64(i64 %a, i64 %b, i32 %scale) 15938 declare <4 x i32> @llvm.umul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 15939 15940Overview 15941""""""""" 15942 15943The '``llvm.umul.fix``' family of intrinsic functions perform unsigned 15944fixed point multiplication on 2 arguments of the same scale. 15945 15946Arguments 15947"""""""""" 15948 15949The arguments (%a and %b) and the result may be of integer types of any bit 15950width, but they must have the same bit width. The arguments may also work with 15951int vectors of the same length and int size. ``%a`` and ``%b`` are the two 15952values that will undergo unsigned fixed point multiplication. The argument 15953``%scale`` represents the scale of both operands, and must be a constant 15954integer. 15955 15956Semantics: 15957"""""""""" 15958 15959This operation performs unsigned fixed point multiplication on the 2 arguments of a 15960specified scale. The result will also be returned in the same scale specified 15961in the third argument. 15962 15963If the result value cannot be precisely represented in the given scale, the 15964value is rounded up or down to the closest representable value. The rounding 15965direction is unspecified. 15966 15967It is undefined behavior if the result value does not fit within the range of 15968the fixed point type. 15969 15970 15971Examples 15972""""""""" 15973 15974.. code-block:: llvm 15975 15976 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 15977 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 15978 15979 ; The result in the following could be rounded down to 3.5 or up to 4 15980 %res = call i4 @llvm.umul.fix.i4(i4 15, i4 1, i32 1) ; %res = 7 (or 8) (7.5 x 0.5 = 3.75) 15981 15982 15983'``llvm.smul.fix.sat.*``' Intrinsics 15984^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15985 15986Syntax 15987""""""" 15988 15989This is an overloaded intrinsic. You can use ``llvm.smul.fix.sat`` 15990on any integer bit width or vectors of integers. 15991 15992:: 15993 15994 declare i16 @llvm.smul.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 15995 declare i32 @llvm.smul.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 15996 declare i64 @llvm.smul.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 15997 declare <4 x i32> @llvm.smul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 15998 15999Overview 16000""""""""" 16001 16002The '``llvm.smul.fix.sat``' family of intrinsic functions perform signed 16003fixed point saturating multiplication on 2 arguments of the same scale. 16004 16005Arguments 16006"""""""""" 16007 16008The arguments (%a and %b) and the result may be of integer types of any bit 16009width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16010values that will undergo signed fixed point multiplication. The argument 16011``%scale`` represents the scale of both operands, and must be a constant 16012integer. 16013 16014Semantics: 16015"""""""""" 16016 16017This operation performs fixed point multiplication on the 2 arguments of a 16018specified scale. The result will also be returned in the same scale specified 16019in the third argument. 16020 16021If the result value cannot be precisely represented in the given scale, the 16022value is rounded up or down to the closest representable value. The rounding 16023direction is unspecified. 16024 16025The maximum value this operation can clamp to is the largest signed value 16026representable by the bit width of the first 2 arguments. The minimum value is the 16027smallest signed value representable by this bit width. 16028 16029 16030Examples 16031""""""""" 16032 16033.. code-block:: llvm 16034 16035 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 16036 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 16037 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5) 16038 16039 ; The result in the following could be rounded up to -2 or down to -2.5 16040 %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) 16041 16042 ; Saturation 16043 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 0) ; %res = 7 16044 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 4, i32 2) ; %res = 7 16045 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 5, i32 2) ; %res = -8 16046 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 -2, i32 1) ; %res = 7 16047 16048 ; Scale can affect the saturation result 16049 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7) 16050 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2) 16051 16052 16053'``llvm.umul.fix.sat.*``' Intrinsics 16054^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16055 16056Syntax 16057""""""" 16058 16059This is an overloaded intrinsic. You can use ``llvm.umul.fix.sat`` 16060on any integer bit width or vectors of integers. 16061 16062:: 16063 16064 declare i16 @llvm.umul.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16065 declare i32 @llvm.umul.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16066 declare i64 @llvm.umul.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16067 declare <4 x i32> @llvm.umul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16068 16069Overview 16070""""""""" 16071 16072The '``llvm.umul.fix.sat``' family of intrinsic functions perform unsigned 16073fixed point saturating multiplication on 2 arguments of the same scale. 16074 16075Arguments 16076"""""""""" 16077 16078The arguments (%a and %b) and the result may be of integer types of any bit 16079width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16080values that will undergo unsigned fixed point multiplication. The argument 16081``%scale`` represents the scale of both operands, and must be a constant 16082integer. 16083 16084Semantics: 16085"""""""""" 16086 16087This operation performs fixed point multiplication on the 2 arguments of a 16088specified scale. The result will also be returned in the same scale specified 16089in the third argument. 16090 16091If the result value cannot be precisely represented in the given scale, the 16092value is rounded up or down to the closest representable value. The rounding 16093direction is unspecified. 16094 16095The maximum value this operation can clamp to is the largest unsigned value 16096representable by the bit width of the first 2 arguments. The minimum value is the 16097smallest unsigned value representable by this bit width (zero). 16098 16099 16100Examples 16101""""""""" 16102 16103.. code-block:: llvm 16104 16105 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 16106 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 16107 16108 ; The result in the following could be rounded down to 2 or up to 2.5 16109 %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) 16110 16111 ; Saturation 16112 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 2, i32 0) ; %res = 15 (8 x 2 -> clamped to 15) 16113 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 8, i32 2) ; %res = 15 (2 x 2 -> clamped to 3.75) 16114 16115 ; Scale can affect the saturation result 16116 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7) 16117 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2) 16118 16119 16120'``llvm.sdiv.fix.*``' Intrinsics 16121^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16122 16123Syntax 16124""""""" 16125 16126This is an overloaded intrinsic. You can use ``llvm.sdiv.fix`` 16127on any integer bit width or vectors of integers. 16128 16129:: 16130 16131 declare i16 @llvm.sdiv.fix.i16(i16 %a, i16 %b, i32 %scale) 16132 declare i32 @llvm.sdiv.fix.i32(i32 %a, i32 %b, i32 %scale) 16133 declare i64 @llvm.sdiv.fix.i64(i64 %a, i64 %b, i32 %scale) 16134 declare <4 x i32> @llvm.sdiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16135 16136Overview 16137""""""""" 16138 16139The '``llvm.sdiv.fix``' family of intrinsic functions perform signed 16140fixed point division on 2 arguments of the same scale. 16141 16142Arguments 16143"""""""""" 16144 16145The arguments (%a and %b) and the result may be of integer types of any bit 16146width, but they must have the same bit width. The arguments may also work with 16147int vectors of the same length and int size. ``%a`` and ``%b`` are the two 16148values that will undergo signed fixed point division. The argument 16149``%scale`` represents the scale of both operands, and must be a constant 16150integer. 16151 16152Semantics: 16153"""""""""" 16154 16155This operation performs fixed point division on the 2 arguments of a 16156specified scale. The result will also be returned in the same scale specified 16157in the third argument. 16158 16159If the result value cannot be precisely represented in the given scale, the 16160value is rounded up or down to the closest representable value. The rounding 16161direction is unspecified. 16162 16163It is undefined behavior if the result value does not fit within the range of 16164the fixed point type, or if the second argument is zero. 16165 16166 16167Examples 16168""""""""" 16169 16170.. code-block:: llvm 16171 16172 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16173 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16174 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5) 16175 16176 ; The result in the following could be rounded up to 1 or down to 0.5 16177 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 16178 16179 16180'``llvm.udiv.fix.*``' Intrinsics 16181^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16182 16183Syntax 16184""""""" 16185 16186This is an overloaded intrinsic. You can use ``llvm.udiv.fix`` 16187on any integer bit width or vectors of integers. 16188 16189:: 16190 16191 declare i16 @llvm.udiv.fix.i16(i16 %a, i16 %b, i32 %scale) 16192 declare i32 @llvm.udiv.fix.i32(i32 %a, i32 %b, i32 %scale) 16193 declare i64 @llvm.udiv.fix.i64(i64 %a, i64 %b, i32 %scale) 16194 declare <4 x i32> @llvm.udiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16195 16196Overview 16197""""""""" 16198 16199The '``llvm.udiv.fix``' family of intrinsic functions perform unsigned 16200fixed point division on 2 arguments of the same scale. 16201 16202Arguments 16203"""""""""" 16204 16205The arguments (%a and %b) and the result may be of integer types of any bit 16206width, but they must have the same bit width. The arguments may also work with 16207int vectors of the same length and int size. ``%a`` and ``%b`` are the two 16208values that will undergo unsigned fixed point division. The argument 16209``%scale`` represents the scale of both operands, and must be a constant 16210integer. 16211 16212Semantics: 16213"""""""""" 16214 16215This operation performs fixed point division on the 2 arguments of a 16216specified scale. The result will also be returned in the same scale specified 16217in the third argument. 16218 16219If the result value cannot be precisely represented in the given scale, the 16220value is rounded up or down to the closest representable value. The rounding 16221direction is unspecified. 16222 16223It is undefined behavior if the result value does not fit within the range of 16224the fixed point type, or if the second argument is zero. 16225 16226 16227Examples 16228""""""""" 16229 16230.. code-block:: llvm 16231 16232 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16233 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16234 %res = call i4 @llvm.udiv.fix.i4(i4 1, i4 -8, i32 4) ; %res = 2 (0.0625 / 0.5 = 0.125) 16235 16236 ; The result in the following could be rounded up to 1 or down to 0.5 16237 %res = call i4 @llvm.udiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 16238 16239 16240'``llvm.sdiv.fix.sat.*``' Intrinsics 16241^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16242 16243Syntax 16244""""""" 16245 16246This is an overloaded intrinsic. You can use ``llvm.sdiv.fix.sat`` 16247on any integer bit width or vectors of integers. 16248 16249:: 16250 16251 declare i16 @llvm.sdiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16252 declare i32 @llvm.sdiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16253 declare i64 @llvm.sdiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16254 declare <4 x i32> @llvm.sdiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16255 16256Overview 16257""""""""" 16258 16259The '``llvm.sdiv.fix.sat``' family of intrinsic functions perform signed 16260fixed point saturating division on 2 arguments of the same scale. 16261 16262Arguments 16263"""""""""" 16264 16265The arguments (%a and %b) and the result may be of integer types of any bit 16266width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16267values that will undergo signed fixed point division. The argument 16268``%scale`` represents the scale of both operands, and must be a constant 16269integer. 16270 16271Semantics: 16272"""""""""" 16273 16274This operation performs fixed point division on the 2 arguments of a 16275specified scale. The result will also be returned in the same scale specified 16276in the third argument. 16277 16278If the result value cannot be precisely represented in the given scale, the 16279value is rounded up or down to the closest representable value. The rounding 16280direction is unspecified. 16281 16282The maximum value this operation can clamp to is the largest signed value 16283representable by the bit width of the first 2 arguments. The minimum value is the 16284smallest signed value representable by this bit width. 16285 16286It is undefined behavior if the second argument is zero. 16287 16288 16289Examples 16290""""""""" 16291 16292.. code-block:: llvm 16293 16294 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16295 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16296 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5) 16297 16298 ; The result in the following could be rounded up to 1 or down to 0.5 16299 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 16300 16301 ; Saturation 16302 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -8, i4 -1, i32 0) ; %res = 7 (-8 / -1 = 8 => 7) 16303 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 4, i4 2, i32 2) ; %res = 7 (1 / 0.5 = 2 => 1.75) 16304 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -4, i4 1, i32 2) ; %res = -8 (-1 / 0.25 = -4 => -2) 16305 16306 16307'``llvm.udiv.fix.sat.*``' Intrinsics 16308^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16309 16310Syntax 16311""""""" 16312 16313This is an overloaded intrinsic. You can use ``llvm.udiv.fix.sat`` 16314on any integer bit width or vectors of integers. 16315 16316:: 16317 16318 declare i16 @llvm.udiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16319 declare i32 @llvm.udiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16320 declare i64 @llvm.udiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16321 declare <4 x i32> @llvm.udiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16322 16323Overview 16324""""""""" 16325 16326The '``llvm.udiv.fix.sat``' family of intrinsic functions perform unsigned 16327fixed point saturating division on 2 arguments of the same scale. 16328 16329Arguments 16330"""""""""" 16331 16332The arguments (%a and %b) and the result may be of integer types of any bit 16333width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16334values that will undergo unsigned fixed point division. The argument 16335``%scale`` represents the scale of both operands, and must be a constant 16336integer. 16337 16338Semantics: 16339"""""""""" 16340 16341This operation performs fixed point division on the 2 arguments of a 16342specified scale. The result will also be returned in the same scale specified 16343in the third argument. 16344 16345If the result value cannot be precisely represented in the given scale, the 16346value is rounded up or down to the closest representable value. The rounding 16347direction is unspecified. 16348 16349The maximum value this operation can clamp to is the largest unsigned value 16350representable by the bit width of the first 2 arguments. The minimum value is the 16351smallest unsigned value representable by this bit width (zero). 16352 16353It is undefined behavior if the second argument is zero. 16354 16355Examples 16356""""""""" 16357 16358.. code-block:: llvm 16359 16360 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16361 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16362 16363 ; The result in the following could be rounded down to 0.5 or up to 1 16364 %res = call i4 @llvm.udiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 1 (or 2) (1.5 / 2 = 0.75) 16365 16366 ; Saturation 16367 %res = call i4 @llvm.udiv.fix.sat.i4(i4 8, i4 2, i32 2) ; %res = 15 (2 / 0.5 = 4 => 3.75) 16368 16369 16370Specialised Arithmetic Intrinsics 16371--------------------------------- 16372 16373.. _i_intr_llvm_canonicalize: 16374 16375'``llvm.canonicalize.*``' Intrinsic 16376^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16377 16378Syntax: 16379""""""" 16380 16381:: 16382 16383 declare float @llvm.canonicalize.f32(float %a) 16384 declare double @llvm.canonicalize.f64(double %b) 16385 16386Overview: 16387""""""""" 16388 16389The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical 16390encoding of a floating-point number. This canonicalization is useful for 16391implementing certain numeric primitives such as frexp. The canonical encoding is 16392defined by IEEE-754-2008 to be: 16393 16394:: 16395 16396 2.1.8 canonical encoding: The preferred encoding of a floating-point 16397 representation in a format. Applied to declets, significands of finite 16398 numbers, infinities, and NaNs, especially in decimal formats. 16399 16400This operation can also be considered equivalent to the IEEE-754-2008 16401conversion of a floating-point value to the same format. NaNs are handled 16402according to section 6.2. 16403 16404Examples of non-canonical encodings: 16405 16406- x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are 16407 converted to a canonical representation per hardware-specific protocol. 16408- Many normal decimal floating-point numbers have non-canonical alternative 16409 encodings. 16410- Some machines, like GPUs or ARMv7 NEON, do not support subnormal values. 16411 These are treated as non-canonical encodings of zero and will be flushed to 16412 a zero of the same sign by this operation. 16413 16414Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with 16415default exception handling must signal an invalid exception, and produce a 16416quiet NaN result. 16417 16418This function should always be implementable as multiplication by 1.0, provided 16419that the compiler does not constant fold the operation. Likewise, division by 164201.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with 16421-0.0 is also sufficient provided that the rounding mode is not -Infinity. 16422 16423``@llvm.canonicalize`` must preserve the equality relation. That is: 16424 16425- ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)`` 16426- ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to 16427 to ``(x == y)`` 16428 16429Additionally, the sign of zero must be conserved: 16430``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0`` 16431 16432The payload bits of a NaN must be conserved, with two exceptions. 16433First, environments which use only a single canonical representation of NaN 16434must perform said canonicalization. Second, SNaNs must be quieted per the 16435usual methods. 16436 16437The canonicalization operation may be optimized away if: 16438 16439- The input is known to be canonical. For example, it was produced by a 16440 floating-point operation that is required by the standard to be canonical. 16441- The result is consumed only by (or fused with) other floating-point 16442 operations. That is, the bits of the floating-point value are not examined. 16443 16444'``llvm.fmuladd.*``' Intrinsic 16445^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16446 16447Syntax: 16448""""""" 16449 16450:: 16451 16452 declare float @llvm.fmuladd.f32(float %a, float %b, float %c) 16453 declare double @llvm.fmuladd.f64(double %a, double %b, double %c) 16454 16455Overview: 16456""""""""" 16457 16458The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add 16459expressions that can be fused if the code generator determines that (a) the 16460target instruction set has support for a fused operation, and (b) that the 16461fused operation is more efficient than the equivalent, separate pair of mul 16462and add instructions. 16463 16464Arguments: 16465"""""""""" 16466 16467The '``llvm.fmuladd.*``' intrinsics each take three arguments: two 16468multiplicands, a and b, and an addend c. 16469 16470Semantics: 16471"""""""""" 16472 16473The expression: 16474 16475:: 16476 16477 %0 = call float @llvm.fmuladd.f32(%a, %b, %c) 16478 16479is equivalent to the expression a \* b + c, except that it is unspecified 16480whether rounding will be performed between the multiplication and addition 16481steps. Fusion is not guaranteed, even if the target platform supports it. 16482If a fused multiply-add is required, the corresponding 16483:ref:`llvm.fma <int_fma>` intrinsic function should be used instead. 16484This never sets errno, just as '``llvm.fma.*``'. 16485 16486Examples: 16487""""""""" 16488 16489.. code-block:: llvm 16490 16491 %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c 16492 16493 16494Hardware-Loop Intrinsics 16495------------------------ 16496 16497LLVM support several intrinsics to mark a loop as a hardware-loop. They are 16498hints to the backend which are required to lower these intrinsics further to target 16499specific instructions, or revert the hardware-loop to a normal loop if target 16500specific restriction are not met and a hardware-loop can't be generated. 16501 16502These intrinsics may be modified in the future and are not intended to be used 16503outside the backend. Thus, front-end and mid-level optimizations should not be 16504generating these intrinsics. 16505 16506 16507'``llvm.set.loop.iterations.*``' Intrinsic 16508^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16509 16510Syntax: 16511""""""" 16512 16513This is an overloaded intrinsic. 16514 16515:: 16516 16517 declare void @llvm.set.loop.iterations.i32(i32) 16518 declare void @llvm.set.loop.iterations.i64(i64) 16519 16520Overview: 16521""""""""" 16522 16523The '``llvm.set.loop.iterations.*``' intrinsics are used to specify the 16524hardware-loop trip count. They are placed in the loop preheader basic block and 16525are marked as ``IntrNoDuplicate`` to avoid optimizers duplicating these 16526instructions. 16527 16528Arguments: 16529"""""""""" 16530 16531The integer operand is the loop trip count of the hardware-loop, and thus 16532not e.g. the loop back-edge taken count. 16533 16534Semantics: 16535"""""""""" 16536 16537The '``llvm.set.loop.iterations.*``' intrinsics do not perform any arithmetic 16538on their operand. It's a hint to the backend that can use this to set up the 16539hardware-loop count with a target specific instruction, usually a move of this 16540value to a special register or a hardware-loop instruction. 16541 16542 16543'``llvm.start.loop.iterations.*``' Intrinsic 16544^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16545 16546Syntax: 16547""""""" 16548 16549This is an overloaded intrinsic. 16550 16551:: 16552 16553 declare i32 @llvm.start.loop.iterations.i32(i32) 16554 declare i64 @llvm.start.loop.iterations.i64(i64) 16555 16556Overview: 16557""""""""" 16558 16559The '``llvm.start.loop.iterations.*``' intrinsics are similar to the 16560'``llvm.set.loop.iterations.*``' intrinsics, used to specify the 16561hardware-loop trip count but also produce a value identical to the input 16562that can be used as the input to the loop. They are placed in the loop 16563preheader basic block and the output is expected to be the input to the 16564phi for the induction variable of the loop, decremented by the 16565'``llvm.loop.decrement.reg.*``'. 16566 16567Arguments: 16568"""""""""" 16569 16570The integer operand is the loop trip count of the hardware-loop, and thus 16571not e.g. the loop back-edge taken count. 16572 16573Semantics: 16574"""""""""" 16575 16576The '``llvm.start.loop.iterations.*``' intrinsics do not perform any arithmetic 16577on their operand. It's a hint to the backend that can use this to set up the 16578hardware-loop count with a target specific instruction, usually a move of this 16579value to a special register or a hardware-loop instruction. 16580 16581'``llvm.test.set.loop.iterations.*``' Intrinsic 16582^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16583 16584Syntax: 16585""""""" 16586 16587This is an overloaded intrinsic. 16588 16589:: 16590 16591 declare i1 @llvm.test.set.loop.iterations.i32(i32) 16592 declare i1 @llvm.test.set.loop.iterations.i64(i64) 16593 16594Overview: 16595""""""""" 16596 16597The '``llvm.test.set.loop.iterations.*``' intrinsics are used to specify the 16598the loop trip count, and also test that the given count is not zero, allowing 16599it to control entry to a while-loop. They are placed in the loop preheader's 16600predecessor basic block, and are marked as ``IntrNoDuplicate`` to avoid 16601optimizers duplicating these instructions. 16602 16603Arguments: 16604"""""""""" 16605 16606The integer operand is the loop trip count of the hardware-loop, and thus 16607not e.g. the loop back-edge taken count. 16608 16609Semantics: 16610"""""""""" 16611 16612The '``llvm.test.set.loop.iterations.*``' intrinsics do not perform any 16613arithmetic on their operand. It's a hint to the backend that can use this to 16614set up the hardware-loop count with a target specific instruction, usually a 16615move of this value to a special register or a hardware-loop instruction. 16616The result is the conditional value of whether the given count is not zero. 16617 16618 16619'``llvm.test.start.loop.iterations.*``' Intrinsic 16620^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16621 16622Syntax: 16623""""""" 16624 16625This is an overloaded intrinsic. 16626 16627:: 16628 16629 declare {i32, i1} @llvm.test.start.loop.iterations.i32(i32) 16630 declare {i64, i1} @llvm.test.start.loop.iterations.i64(i64) 16631 16632Overview: 16633""""""""" 16634 16635The '``llvm.test.start.loop.iterations.*``' intrinsics are similar to the 16636'``llvm.test.set.loop.iterations.*``' and '``llvm.start.loop.iterations.*``' 16637intrinsics, used to specify the hardware-loop trip count, but also produce a 16638value identical to the input that can be used as the input to the loop. The 16639second i1 output controls entry to a while-loop. 16640 16641Arguments: 16642"""""""""" 16643 16644The integer operand is the loop trip count of the hardware-loop, and thus 16645not e.g. the loop back-edge taken count. 16646 16647Semantics: 16648"""""""""" 16649 16650The '``llvm.test.start.loop.iterations.*``' intrinsics do not perform any 16651arithmetic on their operand. It's a hint to the backend that can use this to 16652set up the hardware-loop count with a target specific instruction, usually a 16653move of this value to a special register or a hardware-loop instruction. 16654The result is a pair of the input and a conditional value of whether the 16655given count is not zero. 16656 16657 16658'``llvm.loop.decrement.reg.*``' Intrinsic 16659^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16660 16661Syntax: 16662""""""" 16663 16664This is an overloaded intrinsic. 16665 16666:: 16667 16668 declare i32 @llvm.loop.decrement.reg.i32(i32, i32) 16669 declare i64 @llvm.loop.decrement.reg.i64(i64, i64) 16670 16671Overview: 16672""""""""" 16673 16674The '``llvm.loop.decrement.reg.*``' intrinsics are used to lower the loop 16675iteration counter and return an updated value that will be used in the next 16676loop test check. 16677 16678Arguments: 16679"""""""""" 16680 16681Both arguments must have identical integer types. The first operand is the 16682loop iteration counter. The second operand is the maximum number of elements 16683processed in an iteration. 16684 16685Semantics: 16686"""""""""" 16687 16688The '``llvm.loop.decrement.reg.*``' intrinsics do an integer ``SUB`` of its 16689two operands, which is not allowed to wrap. They return the remaining number of 16690iterations still to be executed, and can be used together with a ``PHI``, 16691``ICMP`` and ``BR`` to control the number of loop iterations executed. Any 16692optimisations are allowed to treat it is a ``SUB``, and it is supported by 16693SCEV, so it's the backends responsibility to handle cases where it may be 16694optimised. These intrinsics are marked as ``IntrNoDuplicate`` to avoid 16695optimizers duplicating these instructions. 16696 16697 16698'``llvm.loop.decrement.*``' Intrinsic 16699^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16700 16701Syntax: 16702""""""" 16703 16704This is an overloaded intrinsic. 16705 16706:: 16707 16708 declare i1 @llvm.loop.decrement.i32(i32) 16709 declare i1 @llvm.loop.decrement.i64(i64) 16710 16711Overview: 16712""""""""" 16713 16714The HardwareLoops pass allows the loop decrement value to be specified with an 16715option. It defaults to a loop decrement value of 1, but it can be an unsigned 16716integer value provided by this option. The '``llvm.loop.decrement.*``' 16717intrinsics decrement the loop iteration counter with this value, and return a 16718false predicate if the loop should exit, and true otherwise. 16719This is emitted if the loop counter is not updated via a ``PHI`` node, which 16720can also be controlled with an option. 16721 16722Arguments: 16723"""""""""" 16724 16725The integer argument is the loop decrement value used to decrement the loop 16726iteration counter. 16727 16728Semantics: 16729"""""""""" 16730 16731The '``llvm.loop.decrement.*``' intrinsics do a ``SUB`` of the loop iteration 16732counter with the given loop decrement value, and return false if the loop 16733should exit, this ``SUB`` is not allowed to wrap. The result is a condition 16734that is used by the conditional branch controlling the loop. 16735 16736 16737Vector Reduction Intrinsics 16738--------------------------- 16739 16740Horizontal reductions of vectors can be expressed using the following 16741intrinsics. Each one takes a vector operand as an input and applies its 16742respective operation across all elements of the vector, returning a single 16743scalar result of the same element type. 16744 16745.. _int_vector_reduce_add: 16746 16747'``llvm.vector.reduce.add.*``' Intrinsic 16748^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16749 16750Syntax: 16751""""""" 16752 16753:: 16754 16755 declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a) 16756 declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a) 16757 16758Overview: 16759""""""""" 16760 16761The '``llvm.vector.reduce.add.*``' intrinsics do an integer ``ADD`` 16762reduction of a vector, returning the result as a scalar. The return type matches 16763the element-type of the vector input. 16764 16765Arguments: 16766"""""""""" 16767The argument to this intrinsic must be a vector of integer values. 16768 16769.. _int_vector_reduce_fadd: 16770 16771'``llvm.vector.reduce.fadd.*``' Intrinsic 16772^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16773 16774Syntax: 16775""""""" 16776 16777:: 16778 16779 declare float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %a) 16780 declare double @llvm.vector.reduce.fadd.v2f64(double %start_value, <2 x double> %a) 16781 16782Overview: 16783""""""""" 16784 16785The '``llvm.vector.reduce.fadd.*``' intrinsics do a floating-point 16786``ADD`` reduction of a vector, returning the result as a scalar. The return type 16787matches the element-type of the vector input. 16788 16789If the intrinsic call has the 'reassoc' flag set, then the reduction will not 16790preserve the associativity of an equivalent scalarized counterpart. Otherwise 16791the reduction will be *sequential*, thus implying that the operation respects 16792the associativity of a scalarized reduction. That is, the reduction begins with 16793the start value and performs an fadd operation with consecutively increasing 16794vector element indices. See the following pseudocode: 16795 16796:: 16797 16798 float sequential_fadd(start_value, input_vector) 16799 result = start_value 16800 for i = 0 to length(input_vector) 16801 result = result + input_vector[i] 16802 return result 16803 16804 16805Arguments: 16806"""""""""" 16807The first argument to this intrinsic is a scalar start value for the reduction. 16808The type of the start value matches the element-type of the vector input. 16809The second argument must be a vector of floating-point values. 16810 16811To ignore the start value, negative zero (``-0.0``) can be used, as it is 16812the neutral value of floating point addition. 16813 16814Examples: 16815""""""""" 16816 16817:: 16818 16819 %unord = call reassoc float @llvm.vector.reduce.fadd.v4f32(float -0.0, <4 x float> %input) ; relaxed reduction 16820 %ord = call float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %input) ; sequential reduction 16821 16822 16823.. _int_vector_reduce_mul: 16824 16825'``llvm.vector.reduce.mul.*``' Intrinsic 16826^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16827 16828Syntax: 16829""""""" 16830 16831:: 16832 16833 declare i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %a) 16834 declare i64 @llvm.vector.reduce.mul.v2i64(<2 x i64> %a) 16835 16836Overview: 16837""""""""" 16838 16839The '``llvm.vector.reduce.mul.*``' intrinsics do an integer ``MUL`` 16840reduction of a vector, returning the result as a scalar. The return type matches 16841the element-type of the vector input. 16842 16843Arguments: 16844"""""""""" 16845The argument to this intrinsic must be a vector of integer values. 16846 16847.. _int_vector_reduce_fmul: 16848 16849'``llvm.vector.reduce.fmul.*``' Intrinsic 16850^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16851 16852Syntax: 16853""""""" 16854 16855:: 16856 16857 declare float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %a) 16858 declare double @llvm.vector.reduce.fmul.v2f64(double %start_value, <2 x double> %a) 16859 16860Overview: 16861""""""""" 16862 16863The '``llvm.vector.reduce.fmul.*``' intrinsics do a floating-point 16864``MUL`` reduction of a vector, returning the result as a scalar. The return type 16865matches the element-type of the vector input. 16866 16867If the intrinsic call has the 'reassoc' flag set, then the reduction will not 16868preserve the associativity of an equivalent scalarized counterpart. Otherwise 16869the reduction will be *sequential*, thus implying that the operation respects 16870the associativity of a scalarized reduction. That is, the reduction begins with 16871the start value and performs an fmul operation with consecutively increasing 16872vector element indices. See the following pseudocode: 16873 16874:: 16875 16876 float sequential_fmul(start_value, input_vector) 16877 result = start_value 16878 for i = 0 to length(input_vector) 16879 result = result * input_vector[i] 16880 return result 16881 16882 16883Arguments: 16884"""""""""" 16885The first argument to this intrinsic is a scalar start value for the reduction. 16886The type of the start value matches the element-type of the vector input. 16887The second argument must be a vector of floating-point values. 16888 16889To ignore the start value, one (``1.0``) can be used, as it is the neutral 16890value of floating point multiplication. 16891 16892Examples: 16893""""""""" 16894 16895:: 16896 16897 %unord = call reassoc float @llvm.vector.reduce.fmul.v4f32(float 1.0, <4 x float> %input) ; relaxed reduction 16898 %ord = call float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %input) ; sequential reduction 16899 16900.. _int_vector_reduce_and: 16901 16902'``llvm.vector.reduce.and.*``' Intrinsic 16903^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16904 16905Syntax: 16906""""""" 16907 16908:: 16909 16910 declare i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %a) 16911 16912Overview: 16913""""""""" 16914 16915The '``llvm.vector.reduce.and.*``' intrinsics do a bitwise ``AND`` 16916reduction of a vector, returning the result as a scalar. The return type matches 16917the element-type of the vector input. 16918 16919Arguments: 16920"""""""""" 16921The argument to this intrinsic must be a vector of integer values. 16922 16923.. _int_vector_reduce_or: 16924 16925'``llvm.vector.reduce.or.*``' Intrinsic 16926^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16927 16928Syntax: 16929""""""" 16930 16931:: 16932 16933 declare i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %a) 16934 16935Overview: 16936""""""""" 16937 16938The '``llvm.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction 16939of a vector, returning the result as a scalar. The return type matches the 16940element-type of the vector input. 16941 16942Arguments: 16943"""""""""" 16944The argument to this intrinsic must be a vector of integer values. 16945 16946.. _int_vector_reduce_xor: 16947 16948'``llvm.vector.reduce.xor.*``' Intrinsic 16949^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16950 16951Syntax: 16952""""""" 16953 16954:: 16955 16956 declare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %a) 16957 16958Overview: 16959""""""""" 16960 16961The '``llvm.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR`` 16962reduction of a vector, returning the result as a scalar. The return type matches 16963the element-type of the vector input. 16964 16965Arguments: 16966"""""""""" 16967The argument to this intrinsic must be a vector of integer values. 16968 16969.. _int_vector_reduce_smax: 16970 16971'``llvm.vector.reduce.smax.*``' Intrinsic 16972^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16973 16974Syntax: 16975""""""" 16976 16977:: 16978 16979 declare i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %a) 16980 16981Overview: 16982""""""""" 16983 16984The '``llvm.vector.reduce.smax.*``' intrinsics do a signed integer 16985``MAX`` reduction of a vector, returning the result as a scalar. The return type 16986matches the element-type of the vector input. 16987 16988Arguments: 16989"""""""""" 16990The argument to this intrinsic must be a vector of integer values. 16991 16992.. _int_vector_reduce_smin: 16993 16994'``llvm.vector.reduce.smin.*``' Intrinsic 16995^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16996 16997Syntax: 16998""""""" 16999 17000:: 17001 17002 declare i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %a) 17003 17004Overview: 17005""""""""" 17006 17007The '``llvm.vector.reduce.smin.*``' intrinsics do a signed integer 17008``MIN`` reduction of a vector, returning the result as a scalar. The return type 17009matches the element-type of the vector input. 17010 17011Arguments: 17012"""""""""" 17013The argument to this intrinsic must be a vector of integer values. 17014 17015.. _int_vector_reduce_umax: 17016 17017'``llvm.vector.reduce.umax.*``' Intrinsic 17018^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17019 17020Syntax: 17021""""""" 17022 17023:: 17024 17025 declare i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %a) 17026 17027Overview: 17028""""""""" 17029 17030The '``llvm.vector.reduce.umax.*``' intrinsics do an unsigned 17031integer ``MAX`` reduction of a vector, returning the result as a scalar. The 17032return type matches the element-type of the vector input. 17033 17034Arguments: 17035"""""""""" 17036The argument to this intrinsic must be a vector of integer values. 17037 17038.. _int_vector_reduce_umin: 17039 17040'``llvm.vector.reduce.umin.*``' Intrinsic 17041^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17042 17043Syntax: 17044""""""" 17045 17046:: 17047 17048 declare i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %a) 17049 17050Overview: 17051""""""""" 17052 17053The '``llvm.vector.reduce.umin.*``' intrinsics do an unsigned 17054integer ``MIN`` reduction of a vector, returning the result as a scalar. The 17055return type matches the element-type of the vector input. 17056 17057Arguments: 17058"""""""""" 17059The argument to this intrinsic must be a vector of integer values. 17060 17061.. _int_vector_reduce_fmax: 17062 17063'``llvm.vector.reduce.fmax.*``' Intrinsic 17064^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17065 17066Syntax: 17067""""""" 17068 17069:: 17070 17071 declare float @llvm.vector.reduce.fmax.v4f32(<4 x float> %a) 17072 declare double @llvm.vector.reduce.fmax.v2f64(<2 x double> %a) 17073 17074Overview: 17075""""""""" 17076 17077The '``llvm.vector.reduce.fmax.*``' intrinsics do a floating-point 17078``MAX`` reduction of a vector, returning the result as a scalar. The return type 17079matches the element-type of the vector input. 17080 17081This instruction has the same comparison semantics as the '``llvm.maxnum.*``' 17082intrinsic. That is, the result will always be a number unless all elements of 17083the vector are NaN. For a vector with maximum element magnitude 0.0 and 17084containing both +0.0 and -0.0 elements, the sign of the result is unspecified. 17085 17086If the intrinsic call has the ``nnan`` fast-math flag, then the operation can 17087assume that NaNs are not present in the input vector. 17088 17089Arguments: 17090"""""""""" 17091The argument to this intrinsic must be a vector of floating-point values. 17092 17093.. _int_vector_reduce_fmin: 17094 17095'``llvm.vector.reduce.fmin.*``' Intrinsic 17096^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17097 17098Syntax: 17099""""""" 17100This is an overloaded intrinsic. 17101 17102:: 17103 17104 declare float @llvm.vector.reduce.fmin.v4f32(<4 x float> %a) 17105 declare double @llvm.vector.reduce.fmin.v2f64(<2 x double> %a) 17106 17107Overview: 17108""""""""" 17109 17110The '``llvm.vector.reduce.fmin.*``' intrinsics do a floating-point 17111``MIN`` reduction of a vector, returning the result as a scalar. The return type 17112matches the element-type of the vector input. 17113 17114This instruction has the same comparison semantics as the '``llvm.minnum.*``' 17115intrinsic. That is, the result will always be a number unless all elements of 17116the vector are NaN. For a vector with minimum element magnitude 0.0 and 17117containing both +0.0 and -0.0 elements, the sign of the result is unspecified. 17118 17119If the intrinsic call has the ``nnan`` fast-math flag, then the operation can 17120assume that NaNs are not present in the input vector. 17121 17122Arguments: 17123"""""""""" 17124The argument to this intrinsic must be a vector of floating-point values. 17125 17126'``llvm.experimental.vector.insert``' Intrinsic 17127^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17128 17129Syntax: 17130""""""" 17131This is an overloaded intrinsic. You can use ``llvm.experimental.vector.insert`` 17132to insert a fixed-width vector into a scalable vector, but not the other way 17133around. 17134 17135:: 17136 17137 declare <vscale x 4 x float> @llvm.experimental.vector.insert.nxv4f32.v4f32(<vscale x 4 x float> %vec, <4 x float> %subvec, i64 %idx) 17138 declare <vscale x 2 x double> @llvm.experimental.vector.insert.nxv2f64.v2f64(<vscale x 2 x double> %vec, <2 x double> %subvec, i64 %idx) 17139 17140Overview: 17141""""""""" 17142 17143The '``llvm.experimental.vector.insert.*``' intrinsics insert a vector into another vector 17144starting from a given index. The return type matches the type of the vector we 17145insert into. Conceptually, this can be used to build a scalable vector out of 17146non-scalable vectors. 17147 17148Arguments: 17149"""""""""" 17150 17151The ``vec`` is the vector which ``subvec`` will be inserted into. 17152The ``subvec`` is the vector that will be inserted. 17153 17154``idx`` represents the starting element number at which ``subvec`` will be 17155inserted. ``idx`` must be a constant multiple of ``subvec``'s known minimum 17156vector length. If ``subvec`` is a scalable vector, ``idx`` is first scaled by 17157the runtime scaling factor of ``subvec``. The elements of ``vec`` starting at 17158``idx`` are overwritten with ``subvec``. Elements ``idx`` through (``idx`` + 17159num_elements(``subvec``) - 1) must be valid ``vec`` indices. If this condition 17160cannot be determined statically but is false at runtime, then the result vector 17161is undefined. 17162 17163 17164'``llvm.experimental.vector.extract``' Intrinsic 17165^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17166 17167Syntax: 17168""""""" 17169This is an overloaded intrinsic. You can use 17170``llvm.experimental.vector.extract`` to extract a fixed-width vector from a 17171scalable vector, but not the other way around. 17172 17173:: 17174 17175 declare <4 x float> @llvm.experimental.vector.extract.v4f32.nxv4f32(<vscale x 4 x float> %vec, i64 %idx) 17176 declare <2 x double> @llvm.experimental.vector.extract.v2f64.nxv2f64(<vscale x 2 x double> %vec, i64 %idx) 17177 17178Overview: 17179""""""""" 17180 17181The '``llvm.experimental.vector.extract.*``' intrinsics extract a vector from 17182within another vector starting from a given index. The return type must be 17183explicitly specified. Conceptually, this can be used to decompose a scalable 17184vector into non-scalable parts. 17185 17186Arguments: 17187"""""""""" 17188 17189The ``vec`` is the vector from which we will extract a subvector. 17190 17191The ``idx`` specifies the starting element number within ``vec`` from which a 17192subvector is extracted. ``idx`` must be a constant multiple of the known-minimum 17193vector length of the result type. If the result type is a scalable vector, 17194``idx`` is first scaled by the result type's runtime scaling factor. Elements 17195``idx`` through (``idx`` + num_elements(result_type) - 1) must be valid vector 17196indices. If this condition cannot be determined statically but is false at 17197runtime, then the result vector is undefined. The ``idx`` parameter must be a 17198vector index constant type (for most targets this will be an integer pointer 17199type). 17200 17201'``llvm.experimental.vector.reverse``' Intrinsic 17202^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17203 17204Syntax: 17205""""""" 17206This is an overloaded intrinsic. 17207 17208:: 17209 17210 declare <2 x i8> @llvm.experimental.vector.reverse.v2i8(<2 x i8> %a) 17211 declare <vscale x 4 x i32> @llvm.experimental.vector.reverse.nxv4i32(<vscale x 4 x i32> %a) 17212 17213Overview: 17214""""""""" 17215 17216The '``llvm.experimental.vector.reverse.*``' intrinsics reverse a vector. 17217The intrinsic takes a single vector and returns a vector of matching type but 17218with the original lane order reversed. These intrinsics work for both fixed 17219and scalable vectors. While this intrinsic is marked as experimental the 17220recommended way to express reverse operations for fixed-width vectors is still 17221to use a shufflevector, as that may allow for more optimization opportunities. 17222 17223Arguments: 17224"""""""""" 17225 17226The argument to this intrinsic must be a vector. 17227 17228'``llvm.experimental.vector.splice``' Intrinsic 17229^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17230 17231Syntax: 17232""""""" 17233This is an overloaded intrinsic. 17234 17235:: 17236 17237 declare <2 x double> @llvm.experimental.vector.splice.v2f64(<2 x double> %vec1, <2 x double> %vec2, i32 %imm) 17238 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) 17239 17240Overview: 17241""""""""" 17242 17243The '``llvm.experimental.vector.splice.*``' intrinsics construct a vector by 17244concatenating elements from the first input vector with elements of the second 17245input vector, returning a vector of the same type as the input vectors. The 17246signed immediate, modulo the number of elements in the vector, is the index 17247into the first vector from which to extract the result value. This means 17248conceptually that for a positive immediate, a vector is extracted from 17249``concat(%vec1, %vec2)`` starting at index ``imm``, whereas for a negative 17250immediate, it extracts ``-imm`` trailing elements from the first vector, and 17251the remaining elements from ``%vec2``. 17252 17253These intrinsics work for both fixed and scalable vectors. While this intrinsic 17254is marked as experimental, the recommended way to express this operation for 17255fixed-width vectors is still to use a shufflevector, as that may allow for more 17256optimization opportunities. 17257 17258For example: 17259 17260.. code-block:: text 17261 17262 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, 1) ==> <B, C, D, E> ; index 17263 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, -3) ==> <B, C, D, E> ; trailing elements 17264 17265 17266Arguments: 17267"""""""""" 17268 17269The first two operands are vectors with the same type. The start index is imm 17270modulo the runtime number of elements in the source vector. For a fixed-width 17271vector <N x eltty>, imm is a signed integer constant in the range 17272-N <= imm < N. For a scalable vector <vscale x N x eltty>, imm is a signed 17273integer constant in the range -X <= imm < X where X=vscale_range_min * N. 17274 17275'``llvm.experimental.stepvector``' Intrinsic 17276^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17277 17278This is an overloaded intrinsic. You can use ``llvm.experimental.stepvector`` 17279to generate a vector whose lane values comprise the linear sequence 17280<0, 1, 2, ...>. It is primarily intended for scalable vectors. 17281 17282:: 17283 17284 declare <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32() 17285 declare <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16() 17286 17287The '``llvm.experimental.stepvector``' intrinsics are used to create vectors 17288of integers whose elements contain a linear sequence of values starting from 0 17289with a step of 1. This experimental intrinsic can only be used for vectors 17290with integer elements that are at least 8 bits in size. If the sequence value 17291exceeds the allowed limit for the element type then the result for that lane is 17292undefined. 17293 17294These intrinsics work for both fixed and scalable vectors. While this intrinsic 17295is marked as experimental, the recommended way to express this operation for 17296fixed-width vectors is still to generate a constant vector instead. 17297 17298 17299Arguments: 17300"""""""""" 17301 17302None. 17303 17304 17305Matrix Intrinsics 17306----------------- 17307 17308Operations on matrixes requiring shape information (like number of rows/columns 17309or the memory layout) can be expressed using the matrix intrinsics. These 17310intrinsics require matrix dimensions to be passed as immediate arguments, and 17311matrixes are passed and returned as vectors. This means that for a ``R`` x 17312``C`` matrix, element ``i`` of column ``j`` is at index ``j * R + i`` in the 17313corresponding vector, with indices starting at 0. Currently column-major layout 17314is assumed. The intrinsics support both integer and floating point matrixes. 17315 17316 17317'``llvm.matrix.transpose.*``' Intrinsic 17318^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17319 17320Syntax: 17321""""""" 17322This is an overloaded intrinsic. 17323 17324:: 17325 17326 declare vectorty @llvm.matrix.transpose.*(vectorty %In, i32 <Rows>, i32 <Cols>) 17327 17328Overview: 17329""""""""" 17330 17331The '``llvm.matrix.transpose.*``' intrinsics treat ``%In`` as a ``<Rows> x 17332<Cols>`` matrix and return the transposed matrix in the result vector. 17333 17334Arguments: 17335"""""""""" 17336 17337The first argument ``%In`` is a vector that corresponds to a ``<Rows> x 17338<Cols>`` matrix. Thus, arguments ``<Rows>`` and ``<Cols>`` correspond to the 17339number of rows and columns, respectively, and must be positive, constant 17340integers. The returned vector must have ``<Rows> * <Cols>`` elements, and have 17341the same float or integer element type as ``%In``. 17342 17343'``llvm.matrix.multiply.*``' Intrinsic 17344^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17345 17346Syntax: 17347""""""" 17348This is an overloaded intrinsic. 17349 17350:: 17351 17352 declare vectorty @llvm.matrix.multiply.*(vectorty %A, vectorty %B, i32 <OuterRows>, i32 <Inner>, i32 <OuterColumns>) 17353 17354Overview: 17355""""""""" 17356 17357The '``llvm.matrix.multiply.*``' intrinsics treat ``%A`` as a ``<OuterRows> x 17358<Inner>`` matrix, ``%B`` as a ``<Inner> x <OuterColumns>`` matrix, and 17359multiplies them. The result matrix is returned in the result vector. 17360 17361Arguments: 17362"""""""""" 17363 17364The first vector argument ``%A`` corresponds to a matrix with ``<OuterRows> * 17365<Inner>`` elements, and the second argument ``%B`` to a matrix with 17366``<Inner> * <OuterColumns>`` elements. Arguments ``<OuterRows>``, 17367``<Inner>`` and ``<OuterColumns>`` must be positive, constant integers. The 17368returned vector must have ``<OuterRows> * <OuterColumns>`` elements. 17369Vectors ``%A``, ``%B``, and the returned vector all have the same float or 17370integer element type. 17371 17372 17373'``llvm.matrix.column.major.load.*``' Intrinsic 17374^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17375 17376Syntax: 17377""""""" 17378This is an overloaded intrinsic. 17379 17380:: 17381 17382 declare vectorty @llvm.matrix.column.major.load.*( 17383 ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>) 17384 17385Overview: 17386""""""""" 17387 17388The '``llvm.matrix.column.major.load.*``' intrinsics load a ``<Rows> x <Cols>`` 17389matrix using a stride of ``%Stride`` to compute the start address of the 17390different columns. The offset is computed using ``%Stride``'s bitwidth. This 17391allows for convenient loading of sub matrixes. If ``<IsVolatile>`` is true, the 17392intrinsic is considered a :ref:`volatile memory access <volatile>`. The result 17393matrix is returned in the result vector. If the ``%Ptr`` argument is known to 17394be aligned to some boundary, this can be specified as an attribute on the 17395argument. 17396 17397Arguments: 17398"""""""""" 17399 17400The first argument ``%Ptr`` is a pointer type to the returned vector type, and 17401corresponds to the start address to load from. The second argument ``%Stride`` 17402is a positive, constant integer with ``%Stride >= <Rows>``. ``%Stride`` is used 17403to compute the column memory addresses. I.e., for a column ``C``, its start 17404memory addresses is calculated with ``%Ptr + C * %Stride``. The third Argument 17405``<IsVolatile>`` is a boolean value. The fourth and fifth arguments, 17406``<Rows>`` and ``<Cols>``, correspond to the number of rows and columns, 17407respectively, and must be positive, constant integers. The returned vector must 17408have ``<Rows> * <Cols>`` elements. 17409 17410The :ref:`align <attr_align>` parameter attribute can be provided for the 17411``%Ptr`` arguments. 17412 17413 17414'``llvm.matrix.column.major.store.*``' Intrinsic 17415^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17416 17417Syntax: 17418""""""" 17419 17420:: 17421 17422 declare void @llvm.matrix.column.major.store.*( 17423 vectorty %In, ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>) 17424 17425Overview: 17426""""""""" 17427 17428The '``llvm.matrix.column.major.store.*``' intrinsics store the ``<Rows> x 17429<Cols>`` matrix in ``%In`` to memory using a stride of ``%Stride`` between 17430columns. The offset is computed using ``%Stride``'s bitwidth. If 17431``<IsVolatile>`` is true, the intrinsic is considered a 17432:ref:`volatile memory access <volatile>`. 17433 17434If the ``%Ptr`` argument is known to be aligned to some boundary, this can be 17435specified as an attribute on the argument. 17436 17437Arguments: 17438"""""""""" 17439 17440The first argument ``%In`` is a vector that corresponds to a ``<Rows> x 17441<Cols>`` matrix to be stored to memory. The second argument ``%Ptr`` is a 17442pointer to the vector type of ``%In``, and is the start address of the matrix 17443in memory. The third argument ``%Stride`` is a positive, constant integer with 17444``%Stride >= <Rows>``. ``%Stride`` is used to compute the column memory 17445addresses. I.e., for a column ``C``, its start memory addresses is calculated 17446with ``%Ptr + C * %Stride``. The fourth argument ``<IsVolatile>`` is a boolean 17447value. The arguments ``<Rows>`` and ``<Cols>`` correspond to the number of rows 17448and columns, respectively, and must be positive, constant integers. 17449 17450The :ref:`align <attr_align>` parameter attribute can be provided 17451for the ``%Ptr`` arguments. 17452 17453 17454Half Precision Floating-Point Intrinsics 17455---------------------------------------- 17456 17457For most target platforms, half precision floating-point is a 17458storage-only format. This means that it is a dense encoding (in memory) 17459but does not support computation in the format. 17460 17461This means that code must first load the half-precision floating-point 17462value as an i16, then convert it to float with 17463:ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can 17464then be performed on the float value (including extending to double 17465etc). To store the value back to memory, it is first converted to float 17466if needed, then converted to i16 with 17467:ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an 17468i16 value. 17469 17470.. _int_convert_to_fp16: 17471 17472'``llvm.convert.to.fp16``' Intrinsic 17473^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17474 17475Syntax: 17476""""""" 17477 17478:: 17479 17480 declare i16 @llvm.convert.to.fp16.f32(float %a) 17481 declare i16 @llvm.convert.to.fp16.f64(double %a) 17482 17483Overview: 17484""""""""" 17485 17486The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a 17487conventional floating-point type to half precision floating-point format. 17488 17489Arguments: 17490"""""""""" 17491 17492The intrinsic function contains single argument - the value to be 17493converted. 17494 17495Semantics: 17496"""""""""" 17497 17498The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a 17499conventional floating-point format to half precision floating-point format. The 17500return value is an ``i16`` which contains the converted number. 17501 17502Examples: 17503""""""""" 17504 17505.. code-block:: llvm 17506 17507 %res = call i16 @llvm.convert.to.fp16.f32(float %a) 17508 store i16 %res, i16* @x, align 2 17509 17510.. _int_convert_from_fp16: 17511 17512'``llvm.convert.from.fp16``' Intrinsic 17513^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17514 17515Syntax: 17516""""""" 17517 17518:: 17519 17520 declare float @llvm.convert.from.fp16.f32(i16 %a) 17521 declare double @llvm.convert.from.fp16.f64(i16 %a) 17522 17523Overview: 17524""""""""" 17525 17526The '``llvm.convert.from.fp16``' intrinsic function performs a 17527conversion from half precision floating-point format to single precision 17528floating-point format. 17529 17530Arguments: 17531"""""""""" 17532 17533The intrinsic function contains single argument - the value to be 17534converted. 17535 17536Semantics: 17537"""""""""" 17538 17539The '``llvm.convert.from.fp16``' intrinsic function performs a 17540conversion from half single precision floating-point format to single 17541precision floating-point format. The input half-float value is 17542represented by an ``i16`` value. 17543 17544Examples: 17545""""""""" 17546 17547.. code-block:: llvm 17548 17549 %a = load i16, i16* @x, align 2 17550 %res = call float @llvm.convert.from.fp16(i16 %a) 17551 17552Saturating floating-point to integer conversions 17553------------------------------------------------ 17554 17555The ``fptoui`` and ``fptosi`` instructions return a 17556:ref:`poison value <poisonvalues>` if the rounded-towards-zero value is not 17557representable by the result type. These intrinsics provide an alternative 17558conversion, which will saturate towards the smallest and largest representable 17559integer values instead. 17560 17561'``llvm.fptoui.sat.*``' Intrinsic 17562^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17563 17564Syntax: 17565""""""" 17566 17567This is an overloaded intrinsic. You can use ``llvm.fptoui.sat`` on any 17568floating-point argument type and any integer result type, or vectors thereof. 17569Not all targets may support all types, however. 17570 17571:: 17572 17573 declare i32 @llvm.fptoui.sat.i32.f32(float %f) 17574 declare i19 @llvm.fptoui.sat.i19.f64(double %f) 17575 declare <4 x i100> @llvm.fptoui.sat.v4i100.v4f128(<4 x fp128> %f) 17576 17577Overview: 17578""""""""" 17579 17580This intrinsic converts the argument into an unsigned integer using saturating 17581semantics. 17582 17583Arguments: 17584"""""""""" 17585 17586The argument may be any floating-point or vector of floating-point type. The 17587return value may be any integer or vector of integer type. The number of vector 17588elements in argument and return must be the same. 17589 17590Semantics: 17591"""""""""" 17592 17593The conversion to integer is performed subject to the following rules: 17594 17595- If the argument is any NaN, zero is returned. 17596- If the argument is smaller than zero (this includes negative infinity), 17597 zero is returned. 17598- If the argument is larger than the largest representable unsigned integer of 17599 the result type (this includes positive infinity), the largest representable 17600 unsigned integer is returned. 17601- Otherwise, the result of rounding the argument towards zero is returned. 17602 17603Example: 17604"""""""" 17605 17606.. code-block:: text 17607 17608 %a = call i8 @llvm.fptoui.sat.i8.f32(float 123.9) ; yields i8: 123 17609 %b = call i8 @llvm.fptoui.sat.i8.f32(float -5.7) ; yields i8: 0 17610 %c = call i8 @llvm.fptoui.sat.i8.f32(float 377.0) ; yields i8: 255 17611 %d = call i8 @llvm.fptoui.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0 17612 17613'``llvm.fptosi.sat.*``' Intrinsic 17614^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17615 17616Syntax: 17617""""""" 17618 17619This is an overloaded intrinsic. You can use ``llvm.fptosi.sat`` on any 17620floating-point argument type and any integer result type, or vectors thereof. 17621Not all targets may support all types, however. 17622 17623:: 17624 17625 declare i32 @llvm.fptosi.sat.i32.f32(float %f) 17626 declare i19 @llvm.fptosi.sat.i19.f64(double %f) 17627 declare <4 x i100> @llvm.fptosi.sat.v4i100.v4f128(<4 x fp128> %f) 17628 17629Overview: 17630""""""""" 17631 17632This intrinsic converts the argument into a signed integer using saturating 17633semantics. 17634 17635Arguments: 17636"""""""""" 17637 17638The argument may be any floating-point or vector of floating-point type. The 17639return value may be any integer or vector of integer type. The number of vector 17640elements in argument and return must be the same. 17641 17642Semantics: 17643"""""""""" 17644 17645The conversion to integer is performed subject to the following rules: 17646 17647- If the argument is any NaN, zero is returned. 17648- If the argument is smaller than the smallest representable signed integer of 17649 the result type (this includes negative infinity), the smallest 17650 representable signed integer is returned. 17651- If the argument is larger than the largest representable signed integer of 17652 the result type (this includes positive infinity), the largest representable 17653 signed integer is returned. 17654- Otherwise, the result of rounding the argument towards zero is returned. 17655 17656Example: 17657"""""""" 17658 17659.. code-block:: text 17660 17661 %a = call i8 @llvm.fptosi.sat.i8.f32(float 23.9) ; yields i8: 23 17662 %b = call i8 @llvm.fptosi.sat.i8.f32(float -130.8) ; yields i8: -128 17663 %c = call i8 @llvm.fptosi.sat.i8.f32(float 999.0) ; yields i8: 127 17664 %d = call i8 @llvm.fptosi.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0 17665 17666.. _dbg_intrinsics: 17667 17668Debugger Intrinsics 17669------------------- 17670 17671The LLVM debugger intrinsics (which all start with ``llvm.dbg.`` 17672prefix), are described in the `LLVM Source Level 17673Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_ 17674document. 17675 17676Exception Handling Intrinsics 17677----------------------------- 17678 17679The LLVM exception handling intrinsics (which all start with 17680``llvm.eh.`` prefix), are described in the `LLVM Exception 17681Handling <ExceptionHandling.html#format-common-intrinsics>`_ document. 17682 17683Pointer Authentication Intrinsics 17684--------------------------------- 17685 17686The LLVM pointer authentication intrinsics (which all start with 17687``llvm.ptrauth.`` prefix), are described in the `Pointer Authentication 17688<PointerAuth.html#intrinsics>`_ document. 17689 17690.. _int_trampoline: 17691 17692Trampoline Intrinsics 17693--------------------- 17694 17695These intrinsics make it possible to excise one parameter, marked with 17696the :ref:`nest <nest>` attribute, from a function. The result is a 17697callable function pointer lacking the nest parameter - the caller does 17698not need to provide a value for it. Instead, the value to use is stored 17699in advance in a "trampoline", a block of memory usually allocated on the 17700stack, which also contains code to splice the nest value into the 17701argument list. This is used to implement the GCC nested function address 17702extension. 17703 17704For example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)`` 17705then the resulting function pointer has signature ``i32 (i32, i32)*``. 17706It can be created as follows: 17707 17708.. code-block:: llvm 17709 17710 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86 17711 %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0 17712 call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval) 17713 %p = call i8* @llvm.adjust.trampoline(i8* %tramp1) 17714 %fp = bitcast i8* %p to i32 (i32, i32)* 17715 17716The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to 17717``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``. 17718 17719.. _int_it: 17720 17721'``llvm.init.trampoline``' Intrinsic 17722^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17723 17724Syntax: 17725""""""" 17726 17727:: 17728 17729 declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>) 17730 17731Overview: 17732""""""""" 17733 17734This fills the memory pointed to by ``tramp`` with executable code, 17735turning it into a trampoline. 17736 17737Arguments: 17738"""""""""" 17739 17740The ``llvm.init.trampoline`` intrinsic takes three arguments, all 17741pointers. The ``tramp`` argument must point to a sufficiently large and 17742sufficiently aligned block of memory; this memory is written to by the 17743intrinsic. Note that the size and the alignment are target-specific - 17744LLVM currently provides no portable way of determining them, so a 17745front-end that generates this intrinsic needs to have some 17746target-specific knowledge. The ``func`` argument must hold a function 17747bitcast to an ``i8*``. 17748 17749Semantics: 17750"""""""""" 17751 17752The block of memory pointed to by ``tramp`` is filled with target 17753dependent code, turning it into a function. Then ``tramp`` needs to be 17754passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can 17755be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new 17756function's signature is the same as that of ``func`` with any arguments 17757marked with the ``nest`` attribute removed. At most one such ``nest`` 17758argument is allowed, and it must be of pointer type. Calling the new 17759function is equivalent to calling ``func`` with the same argument list, 17760but with ``nval`` used for the missing ``nest`` argument. If, after 17761calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is 17762modified, then the effect of any later call to the returned function 17763pointer is undefined. 17764 17765.. _int_at: 17766 17767'``llvm.adjust.trampoline``' Intrinsic 17768^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17769 17770Syntax: 17771""""""" 17772 17773:: 17774 17775 declare i8* @llvm.adjust.trampoline(i8* <tramp>) 17776 17777Overview: 17778""""""""" 17779 17780This performs any required machine-specific adjustment to the address of 17781a trampoline (passed as ``tramp``). 17782 17783Arguments: 17784"""""""""" 17785 17786``tramp`` must point to a block of memory which already has trampoline 17787code filled in by a previous call to 17788:ref:`llvm.init.trampoline <int_it>`. 17789 17790Semantics: 17791"""""""""" 17792 17793On some architectures the address of the code to be executed needs to be 17794different than the address where the trampoline is actually stored. This 17795intrinsic returns the executable address corresponding to ``tramp`` 17796after performing the required machine specific adjustments. The pointer 17797returned can then be :ref:`bitcast and executed <int_trampoline>`. 17798 17799 17800.. _int_vp: 17801 17802Vector Predication Intrinsics 17803----------------------------- 17804VP intrinsics are intended for predicated SIMD/vector code. A typical VP 17805operation takes a vector mask and an explicit vector length parameter as in: 17806 17807:: 17808 17809 <W x T> llvm.vp.<opcode>.*(<W x T> %x, <W x T> %y, <W x i1> %mask, i32 %evl) 17810 17811The vector mask parameter (%mask) always has a vector of `i1` type, for example 17812`<32 x i1>`. The explicit vector length parameter always has the type `i32` and 17813is an unsigned integer value. The explicit vector length parameter (%evl) is in 17814the range: 17815 17816:: 17817 17818 0 <= %evl <= W, where W is the number of vector elements 17819 17820Note that for :ref:`scalable vector types <t_vector>` ``W`` is the runtime 17821length of the vector. 17822 17823The VP intrinsic has undefined behavior if ``%evl > W``. The explicit vector 17824length (%evl) creates a mask, %EVLmask, with all elements ``0 <= i < %evl`` set 17825to True, and all other lanes ``%evl <= i < W`` to False. A new mask %M is 17826calculated with an element-wise AND from %mask and %EVLmask: 17827 17828:: 17829 17830 M = %mask AND %EVLmask 17831 17832A vector operation ``<opcode>`` on vectors ``A`` and ``B`` calculates: 17833 17834:: 17835 17836 A <opcode> B = { A[i] <opcode> B[i] M[i] = True, and 17837 { undef otherwise 17838 17839Optimization Hint 17840^^^^^^^^^^^^^^^^^ 17841 17842Some targets, such as AVX512, do not support the %evl parameter in hardware. 17843The use of an effective %evl is discouraged for those targets. The function 17844``TargetTransformInfo::hasActiveVectorLength()`` returns true when the target 17845has native support for %evl. 17846 17847.. _int_vp_select: 17848 17849'``llvm.vp.select.*``' Intrinsics 17850^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17851 17852Syntax: 17853""""""" 17854This is an overloaded intrinsic. 17855 17856:: 17857 17858 declare <16 x i32> @llvm.vp.select.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <evl>) 17859 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>) 17860 17861Overview: 17862""""""""" 17863 17864The '``llvm.vp.select``' intrinsic is used to choose one value based on a 17865condition vector, without IR-level branching. 17866 17867Arguments: 17868"""""""""" 17869 17870The first operand is a vector of ``i1`` and indicates the condition. The 17871second operand is the value that is selected where the condition vector is 17872true. The third operand is the value that is selected where the condition 17873vector is false. The vectors must be of the same size. The fourth operand is 17874the explicit vector length. 17875 17876#. The optional ``fast-math flags`` marker indicates that the select has one or 17877 more :ref:`fast-math flags <fastmath>`. These are optimization hints to 17878 enable otherwise unsafe floating-point optimizations. Fast-math flags are 17879 only valid for selects that return a floating-point scalar or vector type, 17880 or an array (nested to any depth) of floating-point scalar or vector types. 17881 17882Semantics: 17883"""""""""" 17884 17885The intrinsic selects lanes from the second and third operand depending on a 17886condition vector. 17887 17888All result lanes at positions greater or equal than ``%evl`` are undefined. 17889For all lanes below ``%evl`` where the condition vector is true the lane is 17890taken from the second operand. Otherwise, the lane is taken from the third 17891operand. 17892 17893Example: 17894"""""""" 17895 17896.. code-block:: llvm 17897 17898 %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) 17899 17900 ;;; Expansion. 17901 ;; Any result is legal on lanes at and above %evl. 17902 %also.r = select <4 x i1> %cond, <4 x i32> %on_true, <4 x i32> %on_false 17903 17904 17905.. _int_vp_merge: 17906 17907'``llvm.vp.merge.*``' Intrinsics 17908^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17909 17910Syntax: 17911""""""" 17912This is an overloaded intrinsic. 17913 17914:: 17915 17916 declare <16 x i32> @llvm.vp.merge.v16i32 (<16 x i1> <condition>, <16 x i32> <on_true>, <16 x i32> <on_false>, i32 <pivot>) 17917 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>) 17918 17919Overview: 17920""""""""" 17921 17922The '``llvm.vp.merge``' intrinsic is used to choose one value based on a 17923condition vector and an index operand, without IR-level branching. 17924 17925Arguments: 17926"""""""""" 17927 17928The first operand is a vector of ``i1`` and indicates the condition. The 17929second operand is the value that is merged where the condition vector is true. 17930The third operand is the value that is selected where the condition vector is 17931false or the lane position is greater equal than the pivot. The fourth operand 17932is the pivot. 17933 17934#. The optional ``fast-math flags`` marker indicates that the merge has one or 17935 more :ref:`fast-math flags <fastmath>`. These are optimization hints to 17936 enable otherwise unsafe floating-point optimizations. Fast-math flags are 17937 only valid for merges that return a floating-point scalar or vector type, 17938 or an array (nested to any depth) of floating-point scalar or vector types. 17939 17940Semantics: 17941"""""""""" 17942 17943The intrinsic selects lanes from the second and third operand depending on a 17944condition vector and pivot value. 17945 17946For all lanes where the condition vector is true and the lane position is less 17947than ``%pivot`` the lane is taken from the second operand. Otherwise, the lane 17948is taken from the third operand. 17949 17950Example: 17951"""""""" 17952 17953.. code-block:: llvm 17954 17955 %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) 17956 17957 ;;; Expansion. 17958 ;; Lanes at and above %pivot are taken from %on_false 17959 %atfirst = insertelement <4 x i32> undef, i32 %pivot, i32 0 17960 %splat = shufflevector <4 x i32> %atfirst, <4 x i32> poison, <4 x i32> zeroinitializer 17961 %pivotmask = icmp ult <4 x i32> %splat, <4 x i32> <i32 0, i32 1, i32 2, i32 3> 17962 %mergemask = and <4 x i1> %cond, <4 x i1> %pivotmask 17963 %also.r = select <4 x i1> %mergemask, <4 x i32> %on_true, <4 x i32> %on_false 17964 17965 17966 17967.. _int_vp_add: 17968 17969'``llvm.vp.add.*``' Intrinsics 17970^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17971 17972Syntax: 17973""""""" 17974This is an overloaded intrinsic. 17975 17976:: 17977 17978 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>) 17979 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>) 17980 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>) 17981 17982Overview: 17983""""""""" 17984 17985Predicated integer addition of two vectors of integers. 17986 17987 17988Arguments: 17989"""""""""" 17990 17991The first two operands and the result have the same vector of integer type. The 17992third operand is the vector mask and has the same number of elements as the 17993result vector type. The fourth operand is the explicit vector length of the 17994operation. 17995 17996Semantics: 17997"""""""""" 17998 17999The '``llvm.vp.add``' intrinsic performs integer addition (:ref:`add <i_add>`) 18000of the first and second vector operand on each enabled lane. The result on 18001disabled lanes is undefined. 18002 18003Examples: 18004""""""""" 18005 18006.. code-block:: llvm 18007 18008 %r = call <4 x i32> @llvm.vp.add.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18009 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18010 18011 %t = add <4 x i32> %a, %b 18012 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18013 18014.. _int_vp_sub: 18015 18016'``llvm.vp.sub.*``' Intrinsics 18017^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18018 18019Syntax: 18020""""""" 18021This is an overloaded intrinsic. 18022 18023:: 18024 18025 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>) 18026 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>) 18027 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>) 18028 18029Overview: 18030""""""""" 18031 18032Predicated integer subtraction of two vectors of integers. 18033 18034 18035Arguments: 18036"""""""""" 18037 18038The first two operands and the result have the same vector of integer type. The 18039third operand is the vector mask and has the same number of elements as the 18040result vector type. The fourth operand is the explicit vector length of the 18041operation. 18042 18043Semantics: 18044"""""""""" 18045 18046The '``llvm.vp.sub``' intrinsic performs integer subtraction 18047(:ref:`sub <i_sub>`) of the first and second vector operand on each enabled 18048lane. The result on disabled lanes is undefined. 18049 18050Examples: 18051""""""""" 18052 18053.. code-block:: llvm 18054 18055 %r = call <4 x i32> @llvm.vp.sub.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18056 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18057 18058 %t = sub <4 x i32> %a, %b 18059 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18060 18061 18062 18063.. _int_vp_mul: 18064 18065'``llvm.vp.mul.*``' Intrinsics 18066^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18067 18068Syntax: 18069""""""" 18070This is an overloaded intrinsic. 18071 18072:: 18073 18074 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>) 18075 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>) 18076 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>) 18077 18078Overview: 18079""""""""" 18080 18081Predicated integer multiplication of two vectors of integers. 18082 18083 18084Arguments: 18085"""""""""" 18086 18087The first two operands and the result have the same vector of integer type. The 18088third operand is the vector mask and has the same number of elements as the 18089result vector type. The fourth operand is the explicit vector length of the 18090operation. 18091 18092Semantics: 18093"""""""""" 18094The '``llvm.vp.mul``' intrinsic performs integer multiplication 18095(:ref:`mul <i_mul>`) of the first and second vector operand on each enabled 18096lane. The result on disabled lanes is undefined. 18097 18098Examples: 18099""""""""" 18100 18101.. code-block:: llvm 18102 18103 %r = call <4 x i32> @llvm.vp.mul.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18104 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18105 18106 %t = mul <4 x i32> %a, %b 18107 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18108 18109 18110.. _int_vp_sdiv: 18111 18112'``llvm.vp.sdiv.*``' Intrinsics 18113^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18114 18115Syntax: 18116""""""" 18117This is an overloaded intrinsic. 18118 18119:: 18120 18121 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>) 18122 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>) 18123 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>) 18124 18125Overview: 18126""""""""" 18127 18128Predicated, signed division of two vectors of integers. 18129 18130 18131Arguments: 18132"""""""""" 18133 18134The first two operands and the result have the same vector of integer type. The 18135third operand is the vector mask and has the same number of elements as the 18136result vector type. The fourth operand is the explicit vector length of the 18137operation. 18138 18139Semantics: 18140"""""""""" 18141 18142The '``llvm.vp.sdiv``' intrinsic performs signed division (:ref:`sdiv <i_sdiv>`) 18143of the first and second vector operand on each enabled lane. The result on 18144disabled lanes is undefined. 18145 18146Examples: 18147""""""""" 18148 18149.. code-block:: llvm 18150 18151 %r = call <4 x i32> @llvm.vp.sdiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18152 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18153 18154 %t = sdiv <4 x i32> %a, %b 18155 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18156 18157 18158.. _int_vp_udiv: 18159 18160'``llvm.vp.udiv.*``' Intrinsics 18161^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18162 18163Syntax: 18164""""""" 18165This is an overloaded intrinsic. 18166 18167:: 18168 18169 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>) 18170 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>) 18171 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>) 18172 18173Overview: 18174""""""""" 18175 18176Predicated, unsigned division of two vectors of integers. 18177 18178 18179Arguments: 18180"""""""""" 18181 18182The 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. 18183 18184Semantics: 18185"""""""""" 18186 18187The '``llvm.vp.udiv``' intrinsic performs unsigned division 18188(:ref:`udiv <i_udiv>`) of the first and second vector operand on each enabled 18189lane. The result on disabled lanes is undefined. 18190 18191Examples: 18192""""""""" 18193 18194.. code-block:: llvm 18195 18196 %r = call <4 x i32> @llvm.vp.udiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18197 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18198 18199 %t = udiv <4 x i32> %a, %b 18200 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18201 18202 18203 18204.. _int_vp_srem: 18205 18206'``llvm.vp.srem.*``' Intrinsics 18207^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18208 18209Syntax: 18210""""""" 18211This is an overloaded intrinsic. 18212 18213:: 18214 18215 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>) 18216 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>) 18217 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>) 18218 18219Overview: 18220""""""""" 18221 18222Predicated computations of the signed remainder of two integer vectors. 18223 18224 18225Arguments: 18226"""""""""" 18227 18228The first two operands and the result have the same vector of integer type. The 18229third operand is the vector mask and has the same number of elements as the 18230result vector type. The fourth operand is the explicit vector length of the 18231operation. 18232 18233Semantics: 18234"""""""""" 18235 18236The '``llvm.vp.srem``' intrinsic computes the remainder of the signed division 18237(:ref:`srem <i_srem>`) of the first and second vector operand on each enabled 18238lane. The result on disabled lanes is undefined. 18239 18240Examples: 18241""""""""" 18242 18243.. code-block:: llvm 18244 18245 %r = call <4 x i32> @llvm.vp.srem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18246 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18247 18248 %t = srem <4 x i32> %a, %b 18249 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18250 18251 18252 18253.. _int_vp_urem: 18254 18255'``llvm.vp.urem.*``' Intrinsics 18256^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18257 18258Syntax: 18259""""""" 18260This is an overloaded intrinsic. 18261 18262:: 18263 18264 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>) 18265 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>) 18266 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>) 18267 18268Overview: 18269""""""""" 18270 18271Predicated computation of the unsigned remainder of two integer vectors. 18272 18273 18274Arguments: 18275"""""""""" 18276 18277The first two operands and the result have the same vector of integer type. The 18278third operand is the vector mask and has the same number of elements as the 18279result vector type. The fourth operand is the explicit vector length of the 18280operation. 18281 18282Semantics: 18283"""""""""" 18284 18285The '``llvm.vp.urem``' intrinsic computes the remainder of the unsigned division 18286(:ref:`urem <i_urem>`) of the first and second vector operand on each enabled 18287lane. The result on disabled lanes is undefined. 18288 18289Examples: 18290""""""""" 18291 18292.. code-block:: llvm 18293 18294 %r = call <4 x i32> @llvm.vp.urem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18295 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18296 18297 %t = urem <4 x i32> %a, %b 18298 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18299 18300 18301.. _int_vp_ashr: 18302 18303'``llvm.vp.ashr.*``' Intrinsics 18304^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18305 18306Syntax: 18307""""""" 18308This is an overloaded intrinsic. 18309 18310:: 18311 18312 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>) 18313 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>) 18314 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>) 18315 18316Overview: 18317""""""""" 18318 18319Vector-predicated arithmetic right-shift. 18320 18321 18322Arguments: 18323"""""""""" 18324 18325The first two operands and the result have the same vector of integer type. The 18326third operand is the vector mask and has the same number of elements as the 18327result vector type. The fourth operand is the explicit vector length of the 18328operation. 18329 18330Semantics: 18331"""""""""" 18332 18333The '``llvm.vp.ashr``' intrinsic computes the arithmetic right shift 18334(:ref:`ashr <i_ashr>`) of the first operand by the second operand on each 18335enabled lane. The result on disabled lanes is undefined. 18336 18337Examples: 18338""""""""" 18339 18340.. code-block:: llvm 18341 18342 %r = call <4 x i32> @llvm.vp.ashr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18343 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18344 18345 %t = ashr <4 x i32> %a, %b 18346 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18347 18348 18349.. _int_vp_lshr: 18350 18351 18352'``llvm.vp.lshr.*``' Intrinsics 18353^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18354 18355Syntax: 18356""""""" 18357This is an overloaded intrinsic. 18358 18359:: 18360 18361 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>) 18362 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>) 18363 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>) 18364 18365Overview: 18366""""""""" 18367 18368Vector-predicated logical right-shift. 18369 18370 18371Arguments: 18372"""""""""" 18373 18374The first two operands and the result have the same vector of integer type. The 18375third operand is the vector mask and has the same number of elements as the 18376result vector type. The fourth operand is the explicit vector length of the 18377operation. 18378 18379Semantics: 18380"""""""""" 18381 18382The '``llvm.vp.lshr``' intrinsic computes the logical right shift 18383(:ref:`lshr <i_lshr>`) of the first operand by the second operand on each 18384enabled lane. The result on disabled lanes is undefined. 18385 18386Examples: 18387""""""""" 18388 18389.. code-block:: llvm 18390 18391 %r = call <4 x i32> @llvm.vp.lshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18392 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18393 18394 %t = lshr <4 x i32> %a, %b 18395 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18396 18397 18398.. _int_vp_shl: 18399 18400'``llvm.vp.shl.*``' Intrinsics 18401^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18402 18403Syntax: 18404""""""" 18405This is an overloaded intrinsic. 18406 18407:: 18408 18409 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>) 18410 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>) 18411 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>) 18412 18413Overview: 18414""""""""" 18415 18416Vector-predicated left shift. 18417 18418 18419Arguments: 18420"""""""""" 18421 18422The first two operands and the result have the same vector of integer type. The 18423third operand is the vector mask and has the same number of elements as the 18424result vector type. The fourth operand is the explicit vector length of the 18425operation. 18426 18427Semantics: 18428"""""""""" 18429 18430The '``llvm.vp.shl``' intrinsic computes the left shift (:ref:`shl <i_shl>`) of 18431the first operand by the second operand on each enabled lane. The result on 18432disabled lanes is undefined. 18433 18434Examples: 18435""""""""" 18436 18437.. code-block:: llvm 18438 18439 %r = call <4 x i32> @llvm.vp.shl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18440 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18441 18442 %t = shl <4 x i32> %a, %b 18443 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18444 18445 18446.. _int_vp_or: 18447 18448'``llvm.vp.or.*``' Intrinsics 18449^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18450 18451Syntax: 18452""""""" 18453This is an overloaded intrinsic. 18454 18455:: 18456 18457 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>) 18458 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>) 18459 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>) 18460 18461Overview: 18462""""""""" 18463 18464Vector-predicated or. 18465 18466 18467Arguments: 18468"""""""""" 18469 18470The first two operands and the result have the same vector of integer type. The 18471third operand is the vector mask and has the same number of elements as the 18472result vector type. The fourth operand is the explicit vector length of the 18473operation. 18474 18475Semantics: 18476"""""""""" 18477 18478The '``llvm.vp.or``' intrinsic performs a bitwise or (:ref:`or <i_or>`) of the 18479first two operands on each enabled lane. The result on disabled lanes is 18480undefined. 18481 18482Examples: 18483""""""""" 18484 18485.. code-block:: llvm 18486 18487 %r = call <4 x i32> @llvm.vp.or.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18488 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18489 18490 %t = or <4 x i32> %a, %b 18491 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18492 18493 18494.. _int_vp_and: 18495 18496'``llvm.vp.and.*``' Intrinsics 18497^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18498 18499Syntax: 18500""""""" 18501This is an overloaded intrinsic. 18502 18503:: 18504 18505 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>) 18506 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>) 18507 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>) 18508 18509Overview: 18510""""""""" 18511 18512Vector-predicated and. 18513 18514 18515Arguments: 18516"""""""""" 18517 18518The first two operands and the result have the same vector of integer type. The 18519third operand is the vector mask and has the same number of elements as the 18520result vector type. The fourth operand is the explicit vector length of the 18521operation. 18522 18523Semantics: 18524"""""""""" 18525 18526The '``llvm.vp.and``' intrinsic performs a bitwise and (:ref:`and <i_or>`) of 18527the first two operands on each enabled lane. The result on disabled lanes is 18528undefined. 18529 18530Examples: 18531""""""""" 18532 18533.. code-block:: llvm 18534 18535 %r = call <4 x i32> @llvm.vp.and.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18536 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18537 18538 %t = and <4 x i32> %a, %b 18539 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18540 18541 18542.. _int_vp_xor: 18543 18544'``llvm.vp.xor.*``' Intrinsics 18545^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18546 18547Syntax: 18548""""""" 18549This is an overloaded intrinsic. 18550 18551:: 18552 18553 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>) 18554 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>) 18555 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>) 18556 18557Overview: 18558""""""""" 18559 18560Vector-predicated, bitwise xor. 18561 18562 18563Arguments: 18564"""""""""" 18565 18566The first two operands and the result have the same vector of integer type. The 18567third operand is the vector mask and has the same number of elements as the 18568result vector type. The fourth operand is the explicit vector length of the 18569operation. 18570 18571Semantics: 18572"""""""""" 18573 18574The '``llvm.vp.xor``' intrinsic performs a bitwise xor (:ref:`xor <i_xor>`) of 18575the first two operands on each enabled lane. 18576The result on disabled lanes is undefined. 18577 18578Examples: 18579""""""""" 18580 18581.. code-block:: llvm 18582 18583 %r = call <4 x i32> @llvm.vp.xor.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18584 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18585 18586 %t = xor <4 x i32> %a, %b 18587 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18588 18589 18590.. _int_vp_fadd: 18591 18592'``llvm.vp.fadd.*``' Intrinsics 18593^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18594 18595Syntax: 18596""""""" 18597This is an overloaded intrinsic. 18598 18599:: 18600 18601 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>) 18602 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>) 18603 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>) 18604 18605Overview: 18606""""""""" 18607 18608Predicated floating-point addition of two vectors of floating-point values. 18609 18610 18611Arguments: 18612"""""""""" 18613 18614The first two operands and the result have the same vector of floating-point type. The 18615third operand is the vector mask and has the same number of elements as the 18616result vector type. The fourth operand is the explicit vector length of the 18617operation. 18618 18619Semantics: 18620"""""""""" 18621 18622The '``llvm.vp.fadd``' intrinsic performs floating-point addition (:ref:`fadd <i_fadd>`) 18623of the first and second vector operand on each enabled lane. The result on 18624disabled lanes is undefined. The operation is performed in the default 18625floating-point environment. 18626 18627Examples: 18628""""""""" 18629 18630.. code-block:: llvm 18631 18632 %r = call <4 x float> @llvm.vp.fadd.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18633 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18634 18635 %t = fadd <4 x float> %a, %b 18636 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18637 18638 18639.. _int_vp_fsub: 18640 18641'``llvm.vp.fsub.*``' Intrinsics 18642^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18643 18644Syntax: 18645""""""" 18646This is an overloaded intrinsic. 18647 18648:: 18649 18650 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>) 18651 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>) 18652 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>) 18653 18654Overview: 18655""""""""" 18656 18657Predicated floating-point subtraction of two vectors of floating-point values. 18658 18659 18660Arguments: 18661"""""""""" 18662 18663The first two operands and the result have the same vector of floating-point type. The 18664third operand is the vector mask and has the same number of elements as the 18665result vector type. The fourth operand is the explicit vector length of the 18666operation. 18667 18668Semantics: 18669"""""""""" 18670 18671The '``llvm.vp.fsub``' intrinsic performs floating-point subtraction (:ref:`fsub <i_fsub>`) 18672of the first and second vector operand on each enabled lane. The result on 18673disabled lanes is undefined. The operation is performed in the default 18674floating-point environment. 18675 18676Examples: 18677""""""""" 18678 18679.. code-block:: llvm 18680 18681 %r = call <4 x float> @llvm.vp.fsub.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18682 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18683 18684 %t = fsub <4 x float> %a, %b 18685 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18686 18687 18688.. _int_vp_fmul: 18689 18690'``llvm.vp.fmul.*``' Intrinsics 18691^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18692 18693Syntax: 18694""""""" 18695This is an overloaded intrinsic. 18696 18697:: 18698 18699 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>) 18700 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>) 18701 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>) 18702 18703Overview: 18704""""""""" 18705 18706Predicated floating-point multiplication of two vectors of floating-point values. 18707 18708 18709Arguments: 18710"""""""""" 18711 18712The first two operands and the result have the same vector of floating-point type. The 18713third operand is the vector mask and has the same number of elements as the 18714result vector type. The fourth operand is the explicit vector length of the 18715operation. 18716 18717Semantics: 18718"""""""""" 18719 18720The '``llvm.vp.fmul``' intrinsic performs floating-point multiplication (:ref:`fmul <i_fmul>`) 18721of the first and second vector operand on each enabled lane. The result on 18722disabled lanes is undefined. The operation is performed in the default 18723floating-point environment. 18724 18725Examples: 18726""""""""" 18727 18728.. code-block:: llvm 18729 18730 %r = call <4 x float> @llvm.vp.fmul.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18731 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18732 18733 %t = fmul <4 x float> %a, %b 18734 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18735 18736 18737.. _int_vp_fdiv: 18738 18739'``llvm.vp.fdiv.*``' Intrinsics 18740^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18741 18742Syntax: 18743""""""" 18744This is an overloaded intrinsic. 18745 18746:: 18747 18748 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>) 18749 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>) 18750 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>) 18751 18752Overview: 18753""""""""" 18754 18755Predicated floating-point division of two vectors of floating-point values. 18756 18757 18758Arguments: 18759"""""""""" 18760 18761The first two operands and the result have the same vector of floating-point type. The 18762third operand is the vector mask and has the same number of elements as the 18763result vector type. The fourth operand is the explicit vector length of the 18764operation. 18765 18766Semantics: 18767"""""""""" 18768 18769The '``llvm.vp.fdiv``' intrinsic performs floating-point division (:ref:`fdiv <i_fdiv>`) 18770of the first and second vector operand on each enabled lane. The result on 18771disabled lanes is undefined. The operation is performed in the default 18772floating-point environment. 18773 18774Examples: 18775""""""""" 18776 18777.. code-block:: llvm 18778 18779 %r = call <4 x float> @llvm.vp.fdiv.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18780 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18781 18782 %t = fdiv <4 x float> %a, %b 18783 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18784 18785 18786.. _int_vp_frem: 18787 18788'``llvm.vp.frem.*``' Intrinsics 18789^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18790 18791Syntax: 18792""""""" 18793This is an overloaded intrinsic. 18794 18795:: 18796 18797 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>) 18798 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>) 18799 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>) 18800 18801Overview: 18802""""""""" 18803 18804Predicated floating-point remainder of two vectors of floating-point values. 18805 18806 18807Arguments: 18808"""""""""" 18809 18810The first two operands and the result have the same vector of floating-point type. The 18811third operand is the vector mask and has the same number of elements as the 18812result vector type. The fourth operand is the explicit vector length of the 18813operation. 18814 18815Semantics: 18816"""""""""" 18817 18818The '``llvm.vp.frem``' intrinsic performs floating-point remainder (:ref:`frem <i_frem>`) 18819of the first and second vector operand on each enabled lane. The result on 18820disabled lanes is undefined. The operation is performed in the default 18821floating-point environment. 18822 18823Examples: 18824""""""""" 18825 18826.. code-block:: llvm 18827 18828 %r = call <4 x float> @llvm.vp.frem.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18829 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18830 18831 %t = frem <4 x float> %a, %b 18832 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18833 18834 18835.. _int_vp_fneg: 18836 18837'``llvm.vp.fneg.*``' Intrinsics 18838^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18839 18840Syntax: 18841""""""" 18842This is an overloaded intrinsic. 18843 18844:: 18845 18846 declare <16 x float> @llvm.vp.fneg.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 18847 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>) 18848 declare <256 x double> @llvm.vp.fneg.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 18849 18850Overview: 18851""""""""" 18852 18853Predicated floating-point negation of a vector of floating-point values. 18854 18855 18856Arguments: 18857"""""""""" 18858 18859The first operand and the result have the same vector of floating-point type. 18860The second operand is the vector mask and has the same number of elements as the 18861result vector type. The third operand is the explicit vector length of the 18862operation. 18863 18864Semantics: 18865"""""""""" 18866 18867The '``llvm.vp.fneg``' intrinsic performs floating-point negation (:ref:`fneg <i_fneg>`) 18868of the first vector operand on each enabled lane. The result on disabled lanes 18869is undefined. 18870 18871Examples: 18872""""""""" 18873 18874.. code-block:: llvm 18875 18876 %r = call <4 x float> @llvm.vp.fneg.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 18877 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18878 18879 %t = fneg <4 x float> %a 18880 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18881 18882 18883.. _int_vp_fma: 18884 18885'``llvm.vp.fma.*``' Intrinsics 18886^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18887 18888Syntax: 18889""""""" 18890This is an overloaded intrinsic. 18891 18892:: 18893 18894 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>) 18895 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>) 18896 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>) 18897 18898Overview: 18899""""""""" 18900 18901Predicated floating-point fused multiply-add of two vectors of floating-point values. 18902 18903 18904Arguments: 18905"""""""""" 18906 18907The first three operands and the result have the same vector of floating-point type. The 18908fourth operand is the vector mask and has the same number of elements as the 18909result vector type. The fifth operand is the explicit vector length of the 18910operation. 18911 18912Semantics: 18913"""""""""" 18914 18915The '``llvm.vp.fma``' intrinsic performs floating-point fused multiply-add (:ref:`llvm.fma <int_fma>`) 18916of the first, second, and third vector operand on each enabled lane. The result on 18917disabled lanes is undefined. The operation is performed in the default 18918floating-point environment. 18919 18920Examples: 18921""""""""" 18922 18923.. code-block:: llvm 18924 18925 %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) 18926 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18927 18928 %t = call <4 x float> @llvm.fma(<4 x float> %a, <4 x float> %b, <4 x float> %c) 18929 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18930 18931 18932.. _int_vp_reduce_add: 18933 18934'``llvm.vp.reduce.add.*``' Intrinsics 18935^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18936 18937Syntax: 18938""""""" 18939This is an overloaded intrinsic. 18940 18941:: 18942 18943 declare i32 @llvm.vp.reduce.add.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 18944 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>) 18945 18946Overview: 18947""""""""" 18948 18949Predicated integer ``ADD`` reduction of a vector and a scalar starting value, 18950returning the result as a scalar. 18951 18952Arguments: 18953"""""""""" 18954 18955The first operand is the start value of the reduction, which must be a scalar 18956integer type equal to the result type. The second operand is the vector on 18957which the reduction is performed and must be a vector of integer values whose 18958element type is the result/start type. The third operand is the vector mask and 18959is a vector of boolean values with the same number of elements as the vector 18960operand. The fourth operand is the explicit vector length of the operation. 18961 18962Semantics: 18963"""""""""" 18964 18965The '``llvm.vp.reduce.add``' intrinsic performs the integer ``ADD`` reduction 18966(:ref:`llvm.vector.reduce.add <int_vector_reduce_add>`) of the vector operand 18967``val`` on each enabled lane, adding it to the scalar ``start_value``. Disabled 18968lanes are treated as containing the neutral value ``0`` (i.e. having no effect 18969on the reduction operation). If the vector length is zero, the result is equal 18970to ``start_value``. 18971 18972To ignore the start value, the neutral value can be used. 18973 18974Examples: 18975""""""""" 18976 18977.. code-block:: llvm 18978 18979 %r = call i32 @llvm.vp.reduce.add.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 18980 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 18981 ; are treated as though %mask were false for those lanes. 18982 18983 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> zeroinitializer 18984 %reduction = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %masked.a) 18985 %also.r = add i32 %reduction, %start 18986 18987 18988.. _int_vp_reduce_fadd: 18989 18990'``llvm.vp.reduce.fadd.*``' Intrinsics 18991^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18992 18993Syntax: 18994""""""" 18995This is an overloaded intrinsic. 18996 18997:: 18998 18999 declare float @llvm.vp.reduce.fadd.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>) 19000 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>) 19001 19002Overview: 19003""""""""" 19004 19005Predicated floating-point ``ADD`` reduction of a vector and a scalar starting 19006value, returning the result as a scalar. 19007 19008Arguments: 19009"""""""""" 19010 19011The first operand is the start value of the reduction, which must be a scalar 19012floating-point type equal to the result type. The second operand is the vector 19013on which the reduction is performed and must be a vector of floating-point 19014values whose element type is the result/start type. The third operand is the 19015vector mask and is a vector of boolean values with the same number of elements 19016as the vector operand. The fourth operand is the explicit vector length of the 19017operation. 19018 19019Semantics: 19020"""""""""" 19021 19022The '``llvm.vp.reduce.fadd``' intrinsic performs the floating-point ``ADD`` 19023reduction (:ref:`llvm.vector.reduce.fadd <int_vector_reduce_fadd>`) of the 19024vector operand ``val`` on each enabled lane, adding it to the scalar 19025``start_value``. Disabled lanes are treated as containing the neutral value 19026``-0.0`` (i.e. having no effect on the reduction operation). If no lanes are 19027enabled, the resulting value will be equal to ``start_value``. 19028 19029To ignore the start value, the neutral value can be used. 19030 19031See the unpredicated version (:ref:`llvm.vector.reduce.fadd 19032<int_vector_reduce_fadd>`) for more detail on the semantics of the reduction. 19033 19034Examples: 19035""""""""" 19036 19037.. code-block:: llvm 19038 19039 %r = call float @llvm.vp.reduce.fadd.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl) 19040 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19041 ; are treated as though %mask were false for those lanes. 19042 19043 %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> 19044 %also.r = call float @llvm.vector.reduce.fadd.v4f32(float %start, <4 x float> %masked.a) 19045 19046 19047.. _int_vp_reduce_mul: 19048 19049'``llvm.vp.reduce.mul.*``' Intrinsics 19050^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19051 19052Syntax: 19053""""""" 19054This is an overloaded intrinsic. 19055 19056:: 19057 19058 declare i32 @llvm.vp.reduce.mul.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19059 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>) 19060 19061Overview: 19062""""""""" 19063 19064Predicated integer ``MUL`` reduction of a vector and a scalar starting value, 19065returning the result as a scalar. 19066 19067 19068Arguments: 19069"""""""""" 19070 19071The first operand is the start value of the reduction, which must be a scalar 19072integer type equal to the result type. The second operand is the vector on 19073which the reduction is performed and must be a vector of integer values whose 19074element type is the result/start type. The third operand is the vector mask and 19075is a vector of boolean values with the same number of elements as the vector 19076operand. The fourth operand is the explicit vector length of the operation. 19077 19078Semantics: 19079"""""""""" 19080 19081The '``llvm.vp.reduce.mul``' intrinsic performs the integer ``MUL`` reduction 19082(:ref:`llvm.vector.reduce.mul <int_vector_reduce_mul>`) of the vector operand ``val`` 19083on each enabled lane, multiplying it by the scalar ``start_value``. Disabled 19084lanes are treated as containing the neutral value ``1`` (i.e. having no effect 19085on the reduction operation). If the vector length is zero, the result is the 19086start value. 19087 19088To ignore the start value, the neutral value can be used. 19089 19090Examples: 19091""""""""" 19092 19093.. code-block:: llvm 19094 19095 %r = call i32 @llvm.vp.reduce.mul.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19096 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19097 ; are treated as though %mask were false for those lanes. 19098 19099 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 1, i32 1, i32 1, i32 1> 19100 %reduction = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %masked.a) 19101 %also.r = mul i32 %reduction, %start 19102 19103.. _int_vp_reduce_fmul: 19104 19105'``llvm.vp.reduce.fmul.*``' Intrinsics 19106^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19107 19108Syntax: 19109""""""" 19110This is an overloaded intrinsic. 19111 19112:: 19113 19114 declare float @llvm.vp.reduce.fmul.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, i32 <vector_length>) 19115 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>) 19116 19117Overview: 19118""""""""" 19119 19120Predicated floating-point ``MUL`` reduction of a vector and a scalar starting 19121value, returning the result as a scalar. 19122 19123 19124Arguments: 19125"""""""""" 19126 19127The first operand is the start value of the reduction, which must be a scalar 19128floating-point type equal to the result type. The second operand is the vector 19129on which the reduction is performed and must be a vector of floating-point 19130values whose element type is the result/start type. The third operand is the 19131vector mask and is a vector of boolean values with the same number of elements 19132as the vector operand. The fourth operand is the explicit vector length of the 19133operation. 19134 19135Semantics: 19136"""""""""" 19137 19138The '``llvm.vp.reduce.fmul``' intrinsic performs the floating-point ``MUL`` 19139reduction (:ref:`llvm.vector.reduce.fmul <int_vector_reduce_fmul>`) of the 19140vector operand ``val`` on each enabled lane, multiplying it by the scalar 19141`start_value``. Disabled lanes are treated as containing the neutral value 19142``1.0`` (i.e. having no effect on the reduction operation). If no lanes are 19143enabled, the resulting value will be equal to the starting value. 19144 19145To ignore the start value, the neutral value can be used. 19146 19147See the unpredicated version (:ref:`llvm.vector.reduce.fmul 19148<int_vector_reduce_fmul>`) for more detail on the semantics. 19149 19150Examples: 19151""""""""" 19152 19153.. code-block:: llvm 19154 19155 %r = call float @llvm.vp.reduce.fmul.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl) 19156 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19157 ; are treated as though %mask were false for those lanes. 19158 19159 %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> 19160 %also.r = call float @llvm.vector.reduce.fmul.v4f32(float %start, <4 x float> %masked.a) 19161 19162 19163.. _int_vp_reduce_and: 19164 19165'``llvm.vp.reduce.and.*``' Intrinsics 19166^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19167 19168Syntax: 19169""""""" 19170This is an overloaded intrinsic. 19171 19172:: 19173 19174 declare i32 @llvm.vp.reduce.and.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19175 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>) 19176 19177Overview: 19178""""""""" 19179 19180Predicated integer ``AND`` reduction of a vector and a scalar starting value, 19181returning the result as a scalar. 19182 19183 19184Arguments: 19185"""""""""" 19186 19187The first operand is the start value of the reduction, which must be a scalar 19188integer type equal to the result type. The second operand is the vector on 19189which the reduction is performed and must be a vector of integer values whose 19190element type is the result/start type. The third operand is the vector mask and 19191is a vector of boolean values with the same number of elements as the vector 19192operand. The fourth operand is the explicit vector length of the operation. 19193 19194Semantics: 19195"""""""""" 19196 19197The '``llvm.vp.reduce.and``' intrinsic performs the integer ``AND`` reduction 19198(:ref:`llvm.vector.reduce.and <int_vector_reduce_and>`) of the vector operand 19199``val`` on each enabled lane, performing an '``and``' of that with with the 19200scalar ``start_value``. Disabled lanes are treated as containing the neutral 19201value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction 19202operation). If the vector length is zero, the result is the start value. 19203 19204To ignore the start value, the neutral value can be used. 19205 19206Examples: 19207""""""""" 19208 19209.. code-block:: llvm 19210 19211 %r = call i32 @llvm.vp.reduce.and.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19212 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19213 ; are treated as though %mask were false for those lanes. 19214 19215 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1> 19216 %reduction = call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %masked.a) 19217 %also.r = and i32 %reduction, %start 19218 19219 19220.. _int_vp_reduce_or: 19221 19222'``llvm.vp.reduce.or.*``' Intrinsics 19223^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19224 19225Syntax: 19226""""""" 19227This is an overloaded intrinsic. 19228 19229:: 19230 19231 declare i32 @llvm.vp.reduce.or.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19232 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>) 19233 19234Overview: 19235""""""""" 19236 19237Predicated integer ``OR`` reduction of a vector and a scalar starting value, 19238returning the result as a scalar. 19239 19240 19241Arguments: 19242"""""""""" 19243 19244The first operand is the start value of the reduction, which must be a scalar 19245integer type equal to the result type. The second operand is the vector on 19246which the reduction is performed and must be a vector of integer values whose 19247element type is the result/start type. The third operand is the vector mask and 19248is a vector of boolean values with the same number of elements as the vector 19249operand. The fourth operand is the explicit vector length of the operation. 19250 19251Semantics: 19252"""""""""" 19253 19254The '``llvm.vp.reduce.or``' intrinsic performs the integer ``OR`` reduction 19255(:ref:`llvm.vector.reduce.or <int_vector_reduce_or>`) of the vector operand 19256``val`` on each enabled lane, performing an '``or``' of that with the scalar 19257``start_value``. Disabled lanes are treated as containing the neutral value 19258``0`` (i.e. having no effect on the reduction operation). If the vector length 19259is zero, the result is the start value. 19260 19261To ignore the start value, the neutral value can be used. 19262 19263Examples: 19264""""""""" 19265 19266.. code-block:: llvm 19267 19268 %r = call i32 @llvm.vp.reduce.or.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19269 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19270 ; are treated as though %mask were false for those lanes. 19271 19272 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0> 19273 %reduction = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %masked.a) 19274 %also.r = or i32 %reduction, %start 19275 19276.. _int_vp_reduce_xor: 19277 19278'``llvm.vp.reduce.xor.*``' Intrinsics 19279^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19280 19281Syntax: 19282""""""" 19283This is an overloaded intrinsic. 19284 19285:: 19286 19287 declare i32 @llvm.vp.reduce.xor.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19288 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>) 19289 19290Overview: 19291""""""""" 19292 19293Predicated integer ``XOR`` reduction of a vector and a scalar starting value, 19294returning the result as a scalar. 19295 19296 19297Arguments: 19298"""""""""" 19299 19300The first operand is the start value of the reduction, which must be a scalar 19301integer type equal to the result type. The second operand is the vector on 19302which the reduction is performed and must be a vector of integer values whose 19303element type is the result/start type. The third operand is the vector mask and 19304is a vector of boolean values with the same number of elements as the vector 19305operand. The fourth operand is the explicit vector length of the operation. 19306 19307Semantics: 19308"""""""""" 19309 19310The '``llvm.vp.reduce.xor``' intrinsic performs the integer ``XOR`` reduction 19311(:ref:`llvm.vector.reduce.xor <int_vector_reduce_xor>`) of the vector operand 19312``val`` on each enabled lane, performing an '``xor``' of that with the scalar 19313``start_value``. Disabled lanes are treated as containing the neutral value 19314``0`` (i.e. having no effect on the reduction operation). If the vector length 19315is zero, the result is the start value. 19316 19317To ignore the start value, the neutral value can be used. 19318 19319Examples: 19320""""""""" 19321 19322.. code-block:: llvm 19323 19324 %r = call i32 @llvm.vp.reduce.xor.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19325 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19326 ; are treated as though %mask were false for those lanes. 19327 19328 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0> 19329 %reduction = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %masked.a) 19330 %also.r = xor i32 %reduction, %start 19331 19332 19333.. _int_vp_reduce_smax: 19334 19335'``llvm.vp.reduce.smax.*``' Intrinsics 19336^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19337 19338Syntax: 19339""""""" 19340This is an overloaded intrinsic. 19341 19342:: 19343 19344 declare i32 @llvm.vp.reduce.smax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19345 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>) 19346 19347Overview: 19348""""""""" 19349 19350Predicated signed-integer ``MAX`` reduction of a vector and a scalar starting 19351value, returning the result as a scalar. 19352 19353 19354Arguments: 19355"""""""""" 19356 19357The first operand is the start value of the reduction, which must be a scalar 19358integer type equal to the result type. The second operand is the vector on 19359which the reduction is performed and must be a vector of integer values whose 19360element type is the result/start type. The third operand is the vector mask and 19361is a vector of boolean values with the same number of elements as the vector 19362operand. The fourth operand is the explicit vector length of the operation. 19363 19364Semantics: 19365"""""""""" 19366 19367The '``llvm.vp.reduce.smax``' intrinsic performs the signed-integer ``MAX`` 19368reduction (:ref:`llvm.vector.reduce.smax <int_vector_reduce_smax>`) of the 19369vector operand ``val`` on each enabled lane, and taking the maximum of that and 19370the scalar ``start_value``. Disabled lanes are treated as containing the 19371neutral value ``INT_MIN`` (i.e. having no effect on the reduction operation). 19372If the vector length is zero, the result is the start value. 19373 19374To ignore the start value, the neutral value can be used. 19375 19376Examples: 19377""""""""" 19378 19379.. code-block:: llvm 19380 19381 %r = call i8 @llvm.vp.reduce.smax.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl) 19382 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19383 ; are treated as though %mask were false for those lanes. 19384 19385 %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 -128, i8 -128, i8 -128, i8 -128> 19386 %reduction = call i8 @llvm.vector.reduce.smax.v4i8(<4 x i8> %masked.a) 19387 %also.r = call i8 @llvm.smax.i8(i8 %reduction, i8 %start) 19388 19389 19390.. _int_vp_reduce_smin: 19391 19392'``llvm.vp.reduce.smin.*``' Intrinsics 19393^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19394 19395Syntax: 19396""""""" 19397This is an overloaded intrinsic. 19398 19399:: 19400 19401 declare i32 @llvm.vp.reduce.smin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19402 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>) 19403 19404Overview: 19405""""""""" 19406 19407Predicated signed-integer ``MIN`` reduction of a vector and a scalar starting 19408value, returning the result as a scalar. 19409 19410 19411Arguments: 19412"""""""""" 19413 19414The first operand is the start value of the reduction, which must be a scalar 19415integer type equal to the result type. The second operand is the vector on 19416which the reduction is performed and must be a vector of integer values whose 19417element type is the result/start type. The third operand is the vector mask and 19418is a vector of boolean values with the same number of elements as the vector 19419operand. The fourth operand is the explicit vector length of the operation. 19420 19421Semantics: 19422"""""""""" 19423 19424The '``llvm.vp.reduce.smin``' intrinsic performs the signed-integer ``MIN`` 19425reduction (:ref:`llvm.vector.reduce.smin <int_vector_reduce_smin>`) of the 19426vector operand ``val`` on each enabled lane, and taking the minimum of that and 19427the scalar ``start_value``. Disabled lanes are treated as containing the 19428neutral value ``INT_MAX`` (i.e. having no effect on the reduction operation). 19429If the vector length is zero, the result is the start value. 19430 19431To ignore the start value, the neutral value can be used. 19432 19433Examples: 19434""""""""" 19435 19436.. code-block:: llvm 19437 19438 %r = call i8 @llvm.vp.reduce.smin.v4i8(i8 %start, <4 x i8> %a, <4 x i1> %mask, i32 %evl) 19439 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19440 ; are treated as though %mask were false for those lanes. 19441 19442 %masked.a = select <4 x i1> %mask, <4 x i8> %a, <4 x i8> <i8 127, i8 127, i8 127, i8 127> 19443 %reduction = call i8 @llvm.vector.reduce.smin.v4i8(<4 x i8> %masked.a) 19444 %also.r = call i8 @llvm.smin.i8(i8 %reduction, i8 %start) 19445 19446 19447.. _int_vp_reduce_umax: 19448 19449'``llvm.vp.reduce.umax.*``' Intrinsics 19450^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19451 19452Syntax: 19453""""""" 19454This is an overloaded intrinsic. 19455 19456:: 19457 19458 declare i32 @llvm.vp.reduce.umax.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19459 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>) 19460 19461Overview: 19462""""""""" 19463 19464Predicated unsigned-integer ``MAX`` reduction of a vector and a scalar starting 19465value, returning the result as a scalar. 19466 19467 19468Arguments: 19469"""""""""" 19470 19471The first operand is the start value of the reduction, which must be a scalar 19472integer type equal to the result type. The second operand is the vector on 19473which the reduction is performed and must be a vector of integer values whose 19474element type is the result/start type. The third operand is the vector mask and 19475is a vector of boolean values with the same number of elements as the vector 19476operand. The fourth operand is the explicit vector length of the operation. 19477 19478Semantics: 19479"""""""""" 19480 19481The '``llvm.vp.reduce.umax``' intrinsic performs the unsigned-integer ``MAX`` 19482reduction (:ref:`llvm.vector.reduce.umax <int_vector_reduce_umax>`) of the 19483vector operand ``val`` on each enabled lane, and taking the maximum of that and 19484the scalar ``start_value``. Disabled lanes are treated as containing the 19485neutral value ``0`` (i.e. having no effect on the reduction operation). If the 19486vector length is zero, the result is the start value. 19487 19488To ignore the start value, the neutral value can be used. 19489 19490Examples: 19491""""""""" 19492 19493.. code-block:: llvm 19494 19495 %r = call i32 @llvm.vp.reduce.umax.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19496 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19497 ; are treated as though %mask were false for those lanes. 19498 19499 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 0, i32 0, i32 0, i32 0> 19500 %reduction = call i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %masked.a) 19501 %also.r = call i32 @llvm.umax.i32(i32 %reduction, i32 %start) 19502 19503 19504.. _int_vp_reduce_umin: 19505 19506'``llvm.vp.reduce.umin.*``' Intrinsics 19507^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19508 19509Syntax: 19510""""""" 19511This is an overloaded intrinsic. 19512 19513:: 19514 19515 declare i32 @llvm.vp.reduce.umin.v4i32(i32 <start_value>, <4 x i32> <val>, <4 x i1> <mask>, i32 <vector_length>) 19516 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>) 19517 19518Overview: 19519""""""""" 19520 19521Predicated unsigned-integer ``MIN`` reduction of a vector and a scalar starting 19522value, returning the result as a scalar. 19523 19524 19525Arguments: 19526"""""""""" 19527 19528The first operand is the start value of the reduction, which must be a scalar 19529integer type equal to the result type. The second operand is the vector on 19530which the reduction is performed and must be a vector of integer values whose 19531element type is the result/start type. The third operand is the vector mask and 19532is a vector of boolean values with the same number of elements as the vector 19533operand. The fourth operand is the explicit vector length of the operation. 19534 19535Semantics: 19536"""""""""" 19537 19538The '``llvm.vp.reduce.umin``' intrinsic performs the unsigned-integer ``MIN`` 19539reduction (:ref:`llvm.vector.reduce.umin <int_vector_reduce_umin>`) of the 19540vector operand ``val`` on each enabled lane, taking the minimum of that and the 19541scalar ``start_value``. Disabled lanes are treated as containing the neutral 19542value ``UINT_MAX``, or ``-1`` (i.e. having no effect on the reduction 19543operation). If the vector length is zero, the result is the start value. 19544 19545To ignore the start value, the neutral value can be used. 19546 19547Examples: 19548""""""""" 19549 19550.. code-block:: llvm 19551 19552 %r = call i32 @llvm.vp.reduce.umin.v4i32(i32 %start, <4 x i32> %a, <4 x i1> %mask, i32 %evl) 19553 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19554 ; are treated as though %mask were false for those lanes. 19555 19556 %masked.a = select <4 x i1> %mask, <4 x i32> %a, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1> 19557 %reduction = call i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %masked.a) 19558 %also.r = call i32 @llvm.umin.i32(i32 %reduction, i32 %start) 19559 19560 19561.. _int_vp_reduce_fmax: 19562 19563'``llvm.vp.reduce.fmax.*``' Intrinsics 19564^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19565 19566Syntax: 19567""""""" 19568This is an overloaded intrinsic. 19569 19570:: 19571 19572 declare float @llvm.vp.reduce.fmax.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>) 19573 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>) 19574 19575Overview: 19576""""""""" 19577 19578Predicated floating-point ``MAX`` reduction of a vector and a scalar starting 19579value, returning the result as a scalar. 19580 19581 19582Arguments: 19583"""""""""" 19584 19585The first operand is the start value of the reduction, which must be a scalar 19586floating-point type equal to the result type. The second operand is the vector 19587on which the reduction is performed and must be a vector of floating-point 19588values whose element type is the result/start type. The third operand is the 19589vector mask and is a vector of boolean values with the same number of elements 19590as the vector operand. The fourth operand is the explicit vector length of the 19591operation. 19592 19593Semantics: 19594"""""""""" 19595 19596The '``llvm.vp.reduce.fmax``' intrinsic performs the floating-point ``MAX`` 19597reduction (:ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>`) of the 19598vector operand ``val`` on each enabled lane, taking the maximum of that and the 19599scalar ``start_value``. Disabled lanes are treated as containing the neutral 19600value (i.e. having no effect on the reduction operation). If the vector length 19601is zero, the result is the start value. 19602 19603The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no 19604flags are set, the neutral value is ``-QNAN``. If ``nnan`` and ``ninf`` are 19605both set, then the neutral value is the smallest floating-point value for the 19606result type. If only ``nnan`` is set then the neutral value is ``-Infinity``. 19607 19608This instruction has the same comparison semantics as the 19609:ref:`llvm.vector.reduce.fmax <int_vector_reduce_fmax>` intrinsic (and thus the 19610'``llvm.maxnum.*``' intrinsic). That is, the result will always be a number 19611unless all elements of the vector and the starting value are ``NaN``. For a 19612vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and 19613``-0.0`` elements, the sign of the result is unspecified. 19614 19615To ignore the start value, the neutral value can be used. 19616 19617Examples: 19618""""""""" 19619 19620.. code-block:: llvm 19621 19622 %r = call float @llvm.vp.reduce.fmax.v4f32(float %float, <4 x float> %a, <4 x i1> %mask, i32 %evl) 19623 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19624 ; are treated as though %mask were false for those lanes. 19625 19626 %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN> 19627 %reduction = call float @llvm.vector.reduce.fmax.v4f32(<4 x float> %masked.a) 19628 %also.r = call float @llvm.maxnum.f32(float %reduction, float %start) 19629 19630 19631.. _int_vp_reduce_fmin: 19632 19633'``llvm.vp.reduce.fmin.*``' Intrinsics 19634^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19635 19636Syntax: 19637""""""" 19638This is an overloaded intrinsic. 19639 19640:: 19641 19642 declare float @llvm.vp.reduce.fmin.v4f32(float <start_value>, <4 x float> <val>, <4 x i1> <mask>, float <vector_length>) 19643 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>) 19644 19645Overview: 19646""""""""" 19647 19648Predicated floating-point ``MIN`` reduction of a vector and a scalar starting 19649value, returning the result as a scalar. 19650 19651 19652Arguments: 19653"""""""""" 19654 19655The first operand is the start value of the reduction, which must be a scalar 19656floating-point type equal to the result type. The second operand is the vector 19657on which the reduction is performed and must be a vector of floating-point 19658values whose element type is the result/start type. The third operand is the 19659vector mask and is a vector of boolean values with the same number of elements 19660as the vector operand. The fourth operand is the explicit vector length of the 19661operation. 19662 19663Semantics: 19664"""""""""" 19665 19666The '``llvm.vp.reduce.fmin``' intrinsic performs the floating-point ``MIN`` 19667reduction (:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>`) of the 19668vector operand ``val`` on each enabled lane, taking the minimum of that and the 19669scalar ``start_value``. Disabled lanes are treated as containing the neutral 19670value (i.e. having no effect on the reduction operation). If the vector length 19671is zero, the result is the start value. 19672 19673The neutral value is dependent on the :ref:`fast-math flags <fastmath>`. If no 19674flags are set, the neutral value is ``+QNAN``. If ``nnan`` and ``ninf`` are 19675both set, then the neutral value is the largest floating-point value for the 19676result type. If only ``nnan`` is set then the neutral value is ``+Infinity``. 19677 19678This instruction has the same comparison semantics as the 19679:ref:`llvm.vector.reduce.fmin <int_vector_reduce_fmin>` intrinsic (and thus the 19680'``llvm.minnum.*``' intrinsic). That is, the result will always be a number 19681unless all elements of the vector and the starting value are ``NaN``. For a 19682vector with maximum element magnitude ``0.0`` and containing both ``+0.0`` and 19683``-0.0`` elements, the sign of the result is unspecified. 19684 19685To ignore the start value, the neutral value can be used. 19686 19687Examples: 19688""""""""" 19689 19690.. code-block:: llvm 19691 19692 %r = call float @llvm.vp.reduce.fmin.v4f32(float %start, <4 x float> %a, <4 x i1> %mask, i32 %evl) 19693 ; %r is equivalent to %also.r, where lanes greater than or equal to %evl 19694 ; are treated as though %mask were false for those lanes. 19695 19696 %masked.a = select <4 x i1> %mask, <4 x float> %a, <4 x float> <float QNAN, float QNAN, float QNAN, float QNAN> 19697 %reduction = call float @llvm.vector.reduce.fmin.v4f32(<4 x float> %masked.a) 19698 %also.r = call float @llvm.minnum.f32(float %reduction, float %start) 19699 19700 19701.. _int_get_active_lane_mask: 19702 19703'``llvm.get.active.lane.mask.*``' Intrinsics 19704^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19705 19706Syntax: 19707""""""" 19708This is an overloaded intrinsic. 19709 19710:: 19711 19712 declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %base, i32 %n) 19713 declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 %base, i64 %n) 19714 declare <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 %base, i64 %n) 19715 declare <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 %base, i64 %n) 19716 19717 19718Overview: 19719""""""""" 19720 19721Create a mask representing active and inactive vector lanes. 19722 19723 19724Arguments: 19725"""""""""" 19726 19727Both operands have the same scalar integer type. The result is a vector with 19728the i1 element type. 19729 19730Semantics: 19731"""""""""" 19732 19733The '``llvm.get.active.lane.mask.*``' intrinsics are semantically equivalent 19734to: 19735 19736:: 19737 19738 %m[i] = icmp ult (%base + i), %n 19739 19740where ``%m`` is a vector (mask) of active/inactive lanes with its elements 19741indexed by ``i``, and ``%base``, ``%n`` are the two arguments to 19742``llvm.get.active.lane.mask.*``, ``%icmp`` is an integer compare and ``ult`` 19743the unsigned less-than comparison operator. Overflow cannot occur in 19744``(%base + i)`` and its comparison against ``%n`` as it is performed in integer 19745numbers and not in machine numbers. If ``%n`` is ``0``, then the result is a 19746poison value. The above is equivalent to: 19747 19748:: 19749 19750 %m = @llvm.get.active.lane.mask(%base, %n) 19751 19752This can, for example, be emitted by the loop vectorizer in which case 19753``%base`` is the first element of the vector induction variable (VIV) and 19754``%n`` is the loop tripcount. Thus, these intrinsics perform an element-wise 19755less than comparison of VIV with the loop tripcount, producing a mask of 19756true/false values representing active/inactive vector lanes, except if the VIV 19757overflows in which case they return false in the lanes where the VIV overflows. 19758The arguments are scalar types to accommodate scalable vector types, for which 19759it is unknown what the type of the step vector needs to be that enumerate its 19760lanes without overflow. 19761 19762This mask ``%m`` can e.g. be used in masked load/store instructions. These 19763intrinsics provide a hint to the backend. I.e., for a vector loop, the 19764back-edge taken count of the original scalar loop is explicit as the second 19765argument. 19766 19767 19768Examples: 19769""""""""" 19770 19771.. code-block:: llvm 19772 19773 %active.lane.mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 %elem0, i64 429) 19774 %wide.masked.load = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %3, i32 4, <4 x i1> %active.lane.mask, <4 x i32> undef) 19775 19776 19777.. _int_experimental_vp_splice: 19778 19779'``llvm.experimental.vp.splice``' Intrinsic 19780^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19781 19782Syntax: 19783""""""" 19784This is an overloaded intrinsic. 19785 19786:: 19787 19788 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) 19789 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) 19790 19791Overview: 19792""""""""" 19793 19794The '``llvm.experimental.vp.splice.*``' intrinsic is the vector length 19795predicated version of the '``llvm.experimental.vector.splice.*``' intrinsic. 19796 19797Arguments: 19798"""""""""" 19799 19800The result and the first two arguments ``vec1`` and ``vec2`` are vectors with 19801the same type. The third argument ``imm`` is an immediate signed integer that 19802indicates the offset index. The fourth argument ``mask`` is a vector mask and 19803has the same number of elements as the result. The last two arguments ``evl1`` 19804and ``evl2`` are unsigned integers indicating the explicit vector lengths of 19805``vec1`` and ``vec2`` respectively. ``imm``, ``evl1`` and ``evl2`` should 19806respect the following constraints: ``-evl1 <= imm < evl1``, ``0 <= evl1 <= VL`` 19807and ``0 <= evl2 <= VL``, where ``VL`` is the runtime vector factor. If these 19808constraints are not satisfied the intrinsic has undefined behaviour. 19809 19810Semantics: 19811"""""""""" 19812 19813Effectively, this intrinsic concatenates ``vec1[0..evl1-1]`` and 19814``vec2[0..evl2-1]`` and creates the result vector by selecting the elements in a 19815window of size ``evl2``, starting at index ``imm`` (for a positive immediate) of 19816the concatenated vector. Elements in the result vector beyond ``evl2`` are 19817``undef``. If ``imm`` is negative the starting index is ``evl1 + imm``. The result 19818vector of active vector length ``evl2`` contains ``evl1 - imm`` (``-imm`` for 19819negative ``imm``) elements from indices ``[imm..evl1 - 1]`` 19820(``[evl1 + imm..evl1 -1]`` for negative ``imm``) of ``vec1`` followed by the 19821first ``evl2 - (evl1 - imm)`` (``evl2 + imm`` for negative ``imm``) elements of 19822``vec2``. If ``evl1 - imm`` (``-imm``) >= ``evl2``, only the first ``evl2`` 19823elements are considered and the remaining are ``undef``. The lanes in the result 19824vector disabled by ``mask`` are ``undef``. 19825 19826Examples: 19827""""""""" 19828 19829.. code-block:: text 19830 19831 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, 1, 2, 3) ==> <B, E, F, undef> ; index 19832 llvm.experimental.vp.splice(<A,B,C,D>, <E,F,G,H>, -2, 3, 2) ==> <B, C, undef, undef> ; trailing elements 19833 19834 19835.. _int_vp_load: 19836 19837'``llvm.vp.load``' Intrinsic 19838^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19839 19840Syntax: 19841""""""" 19842This is an overloaded intrinsic. 19843 19844:: 19845 19846 declare <4 x float> @llvm.vp.load.v4f32.p0v4f32(<4 x float>* %ptr, <4 x i1> %mask, i32 %evl) 19847 declare <vscale x 2 x i16> @llvm.vp.load.nxv2i16.p0nxv2i16(<vscale x 2 x i16>* %ptr, <vscale x 2 x i1> %mask, i32 %evl) 19848 declare <8 x float> @llvm.vp.load.v8f32.p1v8f32(<8 x float> addrspace(1)* %ptr, <8 x i1> %mask, i32 %evl) 19849 declare <vscale x 1 x i64> @llvm.vp.load.nxv1i64.p6nxv1i64(<vscale x 1 x i64> addrspace(6)* %ptr, <vscale x 1 x i1> %mask, i32 %evl) 19850 19851Overview: 19852""""""""" 19853 19854The '``llvm.vp.load.*``' intrinsic is the vector length predicated version of 19855the :ref:`llvm.masked.load <int_mload>` intrinsic. 19856 19857Arguments: 19858"""""""""" 19859 19860The first operand is the base pointer for the load. The second operand is a 19861vector of boolean values with the same number of elements as the return type. 19862The third is the explicit vector length of the operation. The return type and 19863underlying type of the base pointer are the same vector types. 19864 19865The :ref:`align <attr_align>` parameter attribute can be provided for the first 19866operand. 19867 19868Semantics: 19869"""""""""" 19870 19871The '``llvm.vp.load``' intrinsic reads a vector from memory in the same way as 19872the '``llvm.masked.load``' intrinsic, where the mask is taken from the 19873combination of the '``mask``' and '``evl``' operands in the usual VP way. 19874Certain '``llvm.masked.load``' operands do not have corresponding operands in 19875'``llvm.vp.load``': the '``passthru``' operand is implicitly ``undef``; the 19876'``alignment``' operand is taken as the ``align`` parameter attribute, if 19877provided. The default alignment is taken as the ABI alignment of the return 19878type as specified by the :ref:`datalayout string<langref_datalayout>`. 19879 19880Examples: 19881""""""""" 19882 19883.. code-block:: text 19884 19885 %r = call <8 x i8> @llvm.vp.load.v8i8.p0v8i8(<8 x i8>* align 2 %ptr, <8 x i1> %mask, i32 %evl) 19886 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 19887 19888 %also.r = call <8 x i8> @llvm.masked.load.v8i8.p0v8i8(<8 x i8>* %ptr, i32 2, <8 x i1> %mask, <8 x i8> undef) 19889 19890 19891.. _int_vp_store: 19892 19893'``llvm.vp.store``' Intrinsic 19894^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19895 19896Syntax: 19897""""""" 19898This is an overloaded intrinsic. 19899 19900:: 19901 19902 declare void @llvm.vp.store.v4f32.p0v4f32(<4 x float> %val, <4 x float>* %ptr, <4 x i1> %mask, i32 %evl) 19903 declare void @llvm.vp.store.nxv2i16.p0nxv2i16(<vscale x 2 x i16> %val, <vscale x 2 x i16>* %ptr, <vscale x 2 x i1> %mask, i32 %evl) 19904 declare void @llvm.vp.store.v8f32.p1v8f32(<8 x float> %val, <8 x float> addrspace(1)* %ptr, <8 x i1> %mask, i32 %evl) 19905 declare void @llvm.vp.store.nxv1i64.p6nxv1i64(<vscale x 1 x i64> %val, <vscale x 1 x i64> addrspace(6)* %ptr, <vscale x 1 x i1> %mask, i32 %evl) 19906 19907Overview: 19908""""""""" 19909 19910The '``llvm.vp.store.*``' intrinsic is the vector length predicated version of 19911the :ref:`llvm.masked.store <int_mstore>` intrinsic. 19912 19913Arguments: 19914"""""""""" 19915 19916The first operand is the vector value to be written to memory. The second 19917operand is the base pointer for the store. It has the same underlying type as 19918the value operand. The third operand is a vector of boolean values with the 19919same number of elements as the return type. The fourth is the explicit vector 19920length of the operation. 19921 19922The :ref:`align <attr_align>` parameter attribute can be provided for the 19923second operand. 19924 19925Semantics: 19926"""""""""" 19927 19928The '``llvm.vp.store``' intrinsic reads a vector from memory in the same way as 19929the '``llvm.masked.store``' intrinsic, where the mask is taken from the 19930combination of the '``mask``' and '``evl``' operands in the usual VP way. The 19931alignment of the operation (corresponding to the '``alignment``' operand of 19932'``llvm.masked.store``') is specified by the ``align`` parameter attribute (see 19933above). If it is not provided then the ABI alignment of the type of the 19934'``value``' operand as specified by the :ref:`datalayout 19935string<langref_datalayout>` is used instead. 19936 19937Examples: 19938""""""""" 19939 19940.. code-block:: text 19941 19942 call void @llvm.vp.store.v8i8.p0v8i8(<8 x i8> %val, <8 x i8>* align 4 %ptr, <8 x i1> %mask, i32 %evl) 19943 ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below. 19944 19945 call void @llvm.masked.store.v8i8.p0v8i8(<8 x i8> %val, <8 x i8>* %ptr, i32 4, <8 x i1> %mask) 19946 19947 19948.. _int_experimental_vp_strided_load: 19949 19950'``llvm.experimental.vp.strided.load``' Intrinsic 19951^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19952 19953Syntax: 19954""""""" 19955This is an overloaded intrinsic. 19956 19957:: 19958 19959 declare <4 x float> @llvm.experimental.vp.strided.load.v4f32.i64(float* %ptr, i64 %stride, <4 x i1> %mask, i32 %evl) 19960 declare <vscale x 2 x i16> @llvm.experimental.vp.strided.load.nxv2i16.i64(i16* %ptr, i64 %stride, <vscale x 2 x i1> %mask, i32 %evl) 19961 19962Overview: 19963""""""""" 19964 19965The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, scalar values from 19966memory locations evenly spaced apart by '``stride``' number of bytes, starting from '``ptr``'. 19967 19968Arguments: 19969"""""""""" 19970 19971The first operand is the base pointer for the load. The second operand is the stride 19972value expressed in bytes. The third operand is a vector of boolean values 19973with the same number of elements as the return type. The fourth is the explicit 19974vector length of the operation. The base pointer underlying type matches the type of the scalar 19975elements of the return operand. 19976 19977The :ref:`align <attr_align>` parameter attribute can be provided for the first 19978operand. 19979 19980Semantics: 19981"""""""""" 19982 19983The '``llvm.experimental.vp.strided.load``' intrinsic loads, into a vector, multiple scalar 19984values from memory in the same way as the :ref:`llvm.vp.gather <int_vp_gather>` intrinsic, 19985where the vector of pointers is in the form: 19986 19987 ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``, 19988 19989with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed 19990integer and all arithmetic occurring in the pointer type. 19991 19992Examples: 19993""""""""" 19994 19995.. code-block:: text 19996 19997 %r = call <8 x i64> @llvm.experimental.vp.strided.load.v8i64.i64(i64* %ptr, i64 %stride, <8 x i64> %mask, i32 %evl) 19998 ;; The operation can also be expressed like this: 19999 20000 %addr = bitcast i64* %ptr to i8* 20001 ;; Create a vector of pointers %addrs in the form: 20002 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...> 20003 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* > 20004 %also.r = call <8 x i64> @llvm.vp.gather.v8i64.v8p0i64(<8 x i64* > %ptrs, <8 x i64> %mask, i32 %evl) 20005 20006 20007.. _int_experimental_vp_strided_store: 20008 20009'``llvm.experimental.vp.strided.store``' Intrinsic 20010^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20011 20012Syntax: 20013""""""" 20014This is an overloaded intrinsic. 20015 20016:: 20017 20018 declare void @llvm.experimental.vp.strided.store.v4f32.i64(<4 x float> %val, float* %ptr, i64 %stride, <4 x i1> %mask, i32 %evl) 20019 declare void @llvm.experimental.vp.strided.store.nxv2i16.i64(<vscale x 2 x i16> %val, i16* %ptr, i64 %stride, <vscale x 2 x i1> %mask, i32 %evl) 20020 20021Overview: 20022""""""""" 20023 20024The '``@llvm.experimental.vp.strided.store``' intrinsic stores the elements of 20025'``val``' into memory locations evenly spaced apart by '``stride``' number of 20026bytes, starting from '``ptr``'. 20027 20028Arguments: 20029"""""""""" 20030 20031The first operand is the vector value to be written to memory. The second 20032operand is the base pointer for the store. Its underlying type matches the 20033scalar element type of the value operand. The third operand is the stride value 20034expressed in bytes. The fourth operand is a vector of boolean values with the 20035same number of elements as the return type. The fifth is the explicit vector 20036length of the operation. 20037 20038The :ref:`align <attr_align>` parameter attribute can be provided for the 20039second operand. 20040 20041Semantics: 20042"""""""""" 20043 20044The '``llvm.experimental.vp.strided.store``' intrinsic stores the elements of 20045'``val``' in the same way as the :ref:`llvm.vp.scatter <int_vp_scatter>` intrinsic, 20046where the vector of pointers is in the form: 20047 20048 ``%ptrs = <%ptr, %ptr + %stride, %ptr + 2 * %stride, ... >``, 20049 20050with '``ptr``' previously casted to a pointer '``i8``', '``stride``' always interpreted as a signed 20051integer and all arithmetic occurring in the pointer type. 20052 20053Examples: 20054""""""""" 20055 20056.. code-block:: text 20057 20058 call void @llvm.experimental.vp.strided.store.v8i64.i64(<8 x i64> %val, i64* %ptr, i64 %stride, <8 x i1> %mask, i32 %evl) 20059 ;; The operation can also be expressed like this: 20060 20061 %addr = bitcast i64* %ptr to i8* 20062 ;; Create a vector of pointers %addrs in the form: 20063 ;; %addrs = <%addr, %addr + %stride, %addr + 2 * %stride, ...> 20064 %ptrs = bitcast <8 x i8* > %addrs to <8 x i64* > 20065 call void @llvm.vp.scatter.v8i64.v8p0i64(<8 x i64> %val, <8 x i64*> %ptrs, <8 x i1> %mask, i32 %evl) 20066 20067 20068.. _int_vp_gather: 20069 20070'``llvm.vp.gather``' Intrinsic 20071^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20072 20073Syntax: 20074""""""" 20075This is an overloaded intrinsic. 20076 20077:: 20078 20079 declare <4 x double> @llvm.vp.gather.v4f64.v4p0f64(<4 x double*> %ptrs, <4 x i1> %mask, i32 %evl) 20080 declare <vscale x 2 x i8> @llvm.vp.gather.nxv2i8.nxv2p0i8(<vscale x 2 x i8*> %ptrs, <vscale x 2 x i1> %mask, i32 %evl) 20081 declare <2 x float> @llvm.vp.gather.v2f32.v2p2f32(<2 x float addrspace(2)*> %ptrs, <2 x i1> %mask, i32 %evl) 20082 declare <vscale x 4 x i32> @llvm.vp.gather.nxv4i32.nxv4p4i32(<vscale x 4 x i32 addrspace(4)*> %ptrs, <vscale x 4 x i1> %mask, i32 %evl) 20083 20084Overview: 20085""""""""" 20086 20087The '``llvm.vp.gather.*``' intrinsic is the vector length predicated version of 20088the :ref:`llvm.masked.gather <int_mgather>` intrinsic. 20089 20090Arguments: 20091"""""""""" 20092 20093The first operand is a vector of pointers which holds all memory addresses to 20094read. The second operand is a vector of boolean values with the same number of 20095elements as the return type. The third is the explicit vector length of the 20096operation. The return type and underlying type of the vector of pointers are 20097the same vector types. 20098 20099The :ref:`align <attr_align>` parameter attribute can be provided for the first 20100operand. 20101 20102Semantics: 20103"""""""""" 20104 20105The '``llvm.vp.gather``' intrinsic reads multiple scalar values from memory in 20106the same way as the '``llvm.masked.gather``' intrinsic, where the mask is taken 20107from the combination of the '``mask``' and '``evl``' operands in the usual VP 20108way. Certain '``llvm.masked.gather``' operands do not have corresponding 20109operands in '``llvm.vp.gather``': the '``passthru``' operand is implicitly 20110``undef``; the '``alignment``' operand is taken as the ``align`` parameter, if 20111provided. The default alignment is taken as the ABI alignment of the source 20112addresses as specified by the :ref:`datalayout string<langref_datalayout>`. 20113 20114Examples: 20115""""""""" 20116 20117.. code-block:: text 20118 20119 %r = call <8 x i8> @llvm.vp.gather.v8i8.v8p0i8(<8 x i8*> align 8 %ptrs, <8 x i1> %mask, i32 %evl) 20120 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20121 20122 %also.r = call <8 x i8> @llvm.masked.gather.v8i8.v8p0i8(<8 x i8*> %ptrs, i32 8, <8 x i1> %mask, <8 x i8> undef) 20123 20124 20125.. _int_vp_scatter: 20126 20127'``llvm.vp.scatter``' Intrinsic 20128^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20129 20130Syntax: 20131""""""" 20132This is an overloaded intrinsic. 20133 20134:: 20135 20136 declare void @llvm.vp.scatter.v4f64.v4p0f64(<4 x double> %val, <4 x double*> %ptrs, <4 x i1> %mask, i32 %evl) 20137 declare void @llvm.vp.scatter.nxv2i8.nxv2p0i8(<vscale x 2 x i8> %val, <vscale x 2 x i8*> %ptrs, <vscale x 2 x i1> %mask, i32 %evl) 20138 declare void @llvm.vp.scatter.v2f32.v2p2f32(<2 x float> %val, <2 x float addrspace(2)*> %ptrs, <2 x i1> %mask, i32 %evl) 20139 declare void @llvm.vp.scatter.nxv4i32.nxv4p4i32(<vscale x 4 x i32> %val, <vscale x 4 x i32 addrspace(4)*> %ptrs, <vscale x 4 x i1> %mask, i32 %evl) 20140 20141Overview: 20142""""""""" 20143 20144The '``llvm.vp.scatter.*``' intrinsic is the vector length predicated version of 20145the :ref:`llvm.masked.scatter <int_mscatter>` intrinsic. 20146 20147Arguments: 20148"""""""""" 20149 20150The first operand is a vector value to be written to memory. The second operand 20151is a vector of pointers, pointing to where the value elements should be stored. 20152The third operand is a vector of boolean values with the same number of 20153elements as the return type. The fourth is the explicit vector length of the 20154operation. 20155 20156The :ref:`align <attr_align>` parameter attribute can be provided for the 20157second operand. 20158 20159Semantics: 20160"""""""""" 20161 20162The '``llvm.vp.scatter``' intrinsic writes multiple scalar values to memory in 20163the same way as the '``llvm.masked.scatter``' intrinsic, where the mask is 20164taken from the combination of the '``mask``' and '``evl``' operands in the 20165usual VP way. The '``alignment``' operand of the '``llvm.masked.scatter``' does 20166not have a corresponding operand in '``llvm.vp.scatter``': it is instead 20167provided via the optional ``align`` parameter attribute on the 20168vector-of-pointers operand. Otherwise it is taken as the ABI alignment of the 20169destination addresses as specified by the :ref:`datalayout 20170string<langref_datalayout>`. 20171 20172Examples: 20173""""""""" 20174 20175.. code-block:: text 20176 20177 call void @llvm.vp.scatter.v8i8.v8p0i8(<8 x i8> %val, <8 x i8*> align 1 %ptrs, <8 x i1> %mask, i32 %evl) 20178 ;; For all lanes below %evl, the call above is lane-wise equivalent to the call below. 20179 20180 call void @llvm.masked.scatter.v8i8.v8p0i8(<8 x i8> %val, <8 x i8*> %ptrs, i32 1, <8 x i1> %mask) 20181 20182 20183.. _int_vp_trunc: 20184 20185'``llvm.vp.trunc.*``' Intrinsics 20186^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20187 20188Syntax: 20189""""""" 20190This is an overloaded intrinsic. 20191 20192:: 20193 20194 declare <16 x i16> @llvm.vp.trunc.v16i16.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 20195 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>) 20196 20197Overview: 20198""""""""" 20199 20200The '``llvm.vp.trunc``' intrinsic truncates its first operand to the return 20201type. The operation has a mask and an explicit vector length parameter. 20202 20203 20204Arguments: 20205"""""""""" 20206 20207The '``llvm.vp.trunc``' intrinsic takes a value to cast as its first operand. 20208The return type is the type to cast the value to. Both types must be vector of 20209:ref:`integer <t_integer>` type. The bit size of the value must be larger than 20210the bit size of the return type. The second operand is the vector mask. The 20211return type, the value to cast, and the vector mask have the same number of 20212elements. The third operand is the explicit vector length of the operation. 20213 20214Semantics: 20215"""""""""" 20216 20217The '``llvm.vp.trunc``' intrinsic truncates the high order bits in value and 20218converts the remaining bits to return type. Since the source size must be larger 20219than the destination size, '``llvm.vp.trunc``' cannot be a *no-op cast*. It will 20220always truncate bits. The conversion is performed on lane positions below the 20221explicit vector length and where the vector mask is true. Masked-off lanes are 20222undefined. 20223 20224Examples: 20225""""""""" 20226 20227.. code-block:: llvm 20228 20229 %r = call <4 x i16> @llvm.vp.trunc.v4i16.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 20230 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20231 20232 %t = trunc <4 x i32> %a to <4 x i16> 20233 %also.r = select <4 x i1> %mask, <4 x i16> %t, <4 x i16> undef 20234 20235 20236.. _int_vp_zext: 20237 20238'``llvm.vp.zext.*``' Intrinsics 20239^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20240 20241Syntax: 20242""""""" 20243This is an overloaded intrinsic. 20244 20245:: 20246 20247 declare <16 x i32> @llvm.vp.zext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>) 20248 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>) 20249 20250Overview: 20251""""""""" 20252 20253The '``llvm.vp.zext``' intrinsic zero extends its first operand to the return 20254type. The operation has a mask and an explicit vector length parameter. 20255 20256 20257Arguments: 20258"""""""""" 20259 20260The '``llvm.vp.zext``' intrinsic takes a value to cast as its first operand. 20261The return type is the type to cast the value to. Both types must be vectors of 20262:ref:`integer <t_integer>` type. The bit size of the value must be smaller than 20263the bit size of the return type. The second operand is the vector mask. The 20264return type, the value to cast, and the vector mask have the same number of 20265elements. The third operand is the explicit vector length of the operation. 20266 20267Semantics: 20268"""""""""" 20269 20270The '``llvm.vp.zext``' intrinsic fill the high order bits of the value with zero 20271bits until it reaches the size of the return type. When zero extending from i1, 20272the result will always be either 0 or 1. The conversion is performed on lane 20273positions below the explicit vector length and where the vector mask is true. 20274Masked-off lanes are undefined. 20275 20276Examples: 20277""""""""" 20278 20279.. code-block:: llvm 20280 20281 %r = call <4 x i32> @llvm.vp.zext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl) 20282 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20283 20284 %t = zext <4 x i16> %a to <4 x i32> 20285 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 20286 20287 20288.. _int_vp_sext: 20289 20290'``llvm.vp.sext.*``' Intrinsics 20291^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20292 20293Syntax: 20294""""""" 20295This is an overloaded intrinsic. 20296 20297:: 20298 20299 declare <16 x i32> @llvm.vp.sext.v16i32.v16i16 (<16 x i16> <op>, <16 x i1> <mask>, i32 <vector_length>) 20300 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>) 20301 20302Overview: 20303""""""""" 20304 20305The '``llvm.vp.sext``' intrinsic sign extends its first operand to the return 20306type. The operation has a mask and an explicit vector length parameter. 20307 20308 20309Arguments: 20310"""""""""" 20311 20312The '``llvm.vp.sext``' intrinsic takes a value to cast as its first operand. 20313The return type is the type to cast the value to. Both types must be vectors of 20314:ref:`integer <t_integer>` type. The bit size of the value must be smaller than 20315the bit size of the return type. The second operand is the vector mask. The 20316return type, the value to cast, and the vector mask have the same number of 20317elements. The third operand is the explicit vector length of the operation. 20318 20319Semantics: 20320"""""""""" 20321 20322The '``llvm.vp.sext``' intrinsic performs a sign extension by copying the sign 20323bit (highest order bit) of the value until it reaches the size of the return 20324type. When zero extending from i1, the result will always be either -1 or 0. 20325The conversion is performed on lane positions below the explicit vector length 20326and where the vector mask is true. Masked-off lanes are undefined. 20327 20328Examples: 20329""""""""" 20330 20331.. code-block:: llvm 20332 20333 %r = call <4 x i32> @llvm.vp.sext.v4i32.v4i16(<4 x i16> %a, <4 x i1> %mask, i32 %evl) 20334 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20335 20336 %t = sext <4 x i16> %a to <4 x i32> 20337 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 20338 20339 20340.. _int_vp_fptrunc: 20341 20342'``llvm.vp.fptrunc.*``' Intrinsics 20343^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20344 20345Syntax: 20346""""""" 20347This is an overloaded intrinsic. 20348 20349:: 20350 20351 declare <16 x float> @llvm.vp.fptrunc.v16f32.v16f64 (<16 x double> <op>, <16 x i1> <mask>, i32 <vector_length>) 20352 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>) 20353 20354Overview: 20355""""""""" 20356 20357The '``llvm.vp.fptrunc``' intrinsic truncates its first operand to the return 20358type. The operation has a mask and an explicit vector length parameter. 20359 20360 20361Arguments: 20362"""""""""" 20363 20364The '``llvm.vp.fptrunc``' intrinsic takes a value to cast as its first operand. 20365The return type is the type to cast the value to. Both types must be vector of 20366:ref:`floating-point <t_floating>` type. The bit size of the value must be 20367larger than the bit size of the return type. This implies that 20368'``llvm.vp.fptrunc``' cannot be used to make a *no-op cast*. The second operand 20369is the vector mask. The return type, the value to cast, and the vector mask have 20370the same number of elements. The third operand is the explicit vector length of 20371the operation. 20372 20373Semantics: 20374"""""""""" 20375 20376The '``llvm.vp.fptrunc``' intrinsic casts a ``value`` from a larger 20377:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point 20378<t_floating>` type. 20379This instruction is assumed to execute in the default :ref:`floating-point 20380environment <floatenv>`. The conversion is performed on lane positions below the 20381explicit vector length and where the vector mask is true. Masked-off lanes are 20382undefined. 20383 20384Examples: 20385""""""""" 20386 20387.. code-block:: llvm 20388 20389 %r = call <4 x float> @llvm.vp.fptrunc.v4f32.v4f64(<4 x double> %a, <4 x i1> %mask, i32 %evl) 20390 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20391 20392 %t = fptrunc <4 x double> %a to <4 x float> 20393 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 20394 20395 20396.. _int_vp_fpext: 20397 20398'``llvm.vp.fpext.*``' Intrinsics 20399^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20400 20401Syntax: 20402""""""" 20403This is an overloaded intrinsic. 20404 20405:: 20406 20407 declare <16 x double> @llvm.vp.fpext.v16f64.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 20408 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>) 20409 20410Overview: 20411""""""""" 20412 20413The '``llvm.vp.fpext``' intrinsic extends its first operand to the return 20414type. The operation has a mask and an explicit vector length parameter. 20415 20416 20417Arguments: 20418"""""""""" 20419 20420The '``llvm.vp.fpext``' intrinsic takes a value to cast as its first operand. 20421The return type is the type to cast the value to. Both types must be vector of 20422:ref:`floating-point <t_floating>` type. The bit size of the value must be 20423smaller than the bit size of the return type. This implies that 20424'``llvm.vp.fpext``' cannot be used to make a *no-op cast*. The second operand 20425is the vector mask. The return type, the value to cast, and the vector mask have 20426the same number of elements. The third operand is the explicit vector length of 20427the operation. 20428 20429Semantics: 20430"""""""""" 20431 20432The '``llvm.vp.fpext``' intrinsic extends the ``value`` from a smaller 20433:ref:`floating-point <t_floating>` type to a larger :ref:`floating-point 20434<t_floating>` type. The '``llvm.vp.fpext``' cannot be used to make a 20435*no-op cast* because it always changes bits. Use ``bitcast`` to make a 20436*no-op cast* for a floating-point cast. 20437The conversion is performed on lane positions below the explicit vector length 20438and where the vector mask is true. Masked-off lanes are undefined. 20439 20440Examples: 20441""""""""" 20442 20443.. code-block:: llvm 20444 20445 %r = call <4 x double> @llvm.vp.fpext.v4f64.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 20446 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20447 20448 %t = fpext <4 x float> %a to <4 x double> 20449 %also.r = select <4 x i1> %mask, <4 x double> %t, <4 x double> undef 20450 20451 20452.. _int_vp_fptoui: 20453 20454'``llvm.vp.fptoui.*``' Intrinsics 20455^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20456 20457Syntax: 20458""""""" 20459This is an overloaded intrinsic. 20460 20461:: 20462 20463 declare <16 x i32> @llvm.vp.fptoui.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 20464 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>) 20465 declare <256 x i64> @llvm.vp.fptoui.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 20466 20467Overview: 20468""""""""" 20469 20470The '``llvm.vp.fptoui``' intrinsic converts the :ref:`floating-point 20471<t_floating>` operand to the unsigned integer return type. 20472The operation has a mask and an explicit vector length parameter. 20473 20474 20475Arguments: 20476"""""""""" 20477 20478The '``llvm.vp.fptoui``' intrinsic takes a value to cast as its first operand. 20479The value to cast must be a vector of :ref:`floating-point <t_floating>` type. 20480The return type is the type to cast the value to. The return type must be 20481vector of :ref:`integer <t_integer>` type. The second operand is the vector 20482mask. The return type, the value to cast, and the vector mask have the same 20483number of elements. The third operand is the explicit vector length of the 20484operation. 20485 20486Semantics: 20487"""""""""" 20488 20489The '``llvm.vp.fptoui``' intrinsic converts its :ref:`floating-point 20490<t_floating>` operand into the nearest (rounding towards zero) unsigned integer 20491value where the lane position is below the explicit vector length and the 20492vector mask is true. Masked-off lanes are undefined. On enabled lanes where 20493conversion takes place and the value cannot fit in the return type, the result 20494on that lane is a :ref:`poison value <poisonvalues>`. 20495 20496Examples: 20497""""""""" 20498 20499.. code-block:: llvm 20500 20501 %r = call <4 x i32> @llvm.vp.fptoui.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 20502 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20503 20504 %t = fptoui <4 x float> %a to <4 x i32> 20505 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 20506 20507 20508.. _int_vp_fptosi: 20509 20510'``llvm.vp.fptosi.*``' Intrinsics 20511^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20512 20513Syntax: 20514""""""" 20515This is an overloaded intrinsic. 20516 20517:: 20518 20519 declare <16 x i32> @llvm.vp.fptosi.v16i32.v16f32 (<16 x float> <op>, <16 x i1> <mask>, i32 <vector_length>) 20520 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>) 20521 declare <256 x i64> @llvm.vp.fptosi.v256i64.v256f64 (<256 x double> <op>, <256 x i1> <mask>, i32 <vector_length>) 20522 20523Overview: 20524""""""""" 20525 20526The '``llvm.vp.fptosi``' intrinsic converts the :ref:`floating-point 20527<t_floating>` operand to the signed integer return type. 20528The operation has a mask and an explicit vector length parameter. 20529 20530 20531Arguments: 20532"""""""""" 20533 20534The '``llvm.vp.fptosi``' intrinsic takes a value to cast as its first operand. 20535The value to cast must be a vector of :ref:`floating-point <t_floating>` type. 20536The return type is the type to cast the value to. The return type must be 20537vector of :ref:`integer <t_integer>` type. The second operand is the vector 20538mask. The return type, the value to cast, and the vector mask have the same 20539number of elements. The third operand is the explicit vector length of the 20540operation. 20541 20542Semantics: 20543"""""""""" 20544 20545The '``llvm.vp.fptosi``' intrinsic converts its :ref:`floating-point 20546<t_floating>` operand into the nearest (rounding towards zero) signed integer 20547value where the lane position is below the explicit vector length and the 20548vector mask is true. Masked-off lanes are undefined. On enabled lanes where 20549conversion takes place and the value cannot fit in the return type, the result 20550on that lane is a :ref:`poison value <poisonvalues>`. 20551 20552Examples: 20553""""""""" 20554 20555.. code-block:: llvm 20556 20557 %r = call <4 x i32> @llvm.vp.fptosi.v4i32.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) 20558 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20559 20560 %t = fptosi <4 x float> %a to <4 x i32> 20561 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 20562 20563 20564.. _int_vp_uitofp: 20565 20566'``llvm.vp.uitofp.*``' Intrinsics 20567^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20568 20569Syntax: 20570""""""" 20571This is an overloaded intrinsic. 20572 20573:: 20574 20575 declare <16 x float> @llvm.vp.uitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 20576 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>) 20577 declare <256 x double> @llvm.vp.uitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>) 20578 20579Overview: 20580""""""""" 20581 20582The '``llvm.vp.uitofp``' intrinsic converts its unsigned integer operand to the 20583:ref:`floating-point <t_floating>` return type. The operation has a mask and 20584an explicit vector length parameter. 20585 20586 20587Arguments: 20588"""""""""" 20589 20590The '``llvm.vp.uitofp``' intrinsic takes a value to cast as its first operand. 20591The value to cast must be vector of :ref:`integer <t_integer>` type. The 20592return type is the type to cast the value to. The return type must be a vector 20593of :ref:`floating-point <t_floating>` type. The second operand is the vector 20594mask. The return type, the value to cast, and the vector mask have the same 20595number of elements. The third operand is the explicit vector length of the 20596operation. 20597 20598Semantics: 20599"""""""""" 20600 20601The '``llvm.vp.uitofp``' intrinsic interprets its first operand as an unsigned 20602integer quantity and converts it to the corresponding floating-point value. If 20603the value cannot be exactly represented, it is rounded using the default 20604rounding mode. The conversion is performed on lane positions below the 20605explicit vector length and where the vector mask is true. Masked-off lanes are 20606undefined. 20607 20608Examples: 20609""""""""" 20610 20611.. code-block:: llvm 20612 20613 %r = call <4 x float> @llvm.vp.uitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 20614 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20615 20616 %t = uitofp <4 x i32> %a to <4 x float> 20617 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 20618 20619 20620.. _int_vp_sitofp: 20621 20622'``llvm.vp.sitofp.*``' Intrinsics 20623^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20624 20625Syntax: 20626""""""" 20627This is an overloaded intrinsic. 20628 20629:: 20630 20631 declare <16 x float> @llvm.vp.sitofp.v16f32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 20632 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>) 20633 declare <256 x double> @llvm.vp.sitofp.v256f64.v256i64 (<256 x i64> <op>, <256 x i1> <mask>, i32 <vector_length>) 20634 20635Overview: 20636""""""""" 20637 20638The '``llvm.vp.sitofp``' intrinsic converts its signed integer operand to the 20639:ref:`floating-point <t_floating>` return type. The operation has a mask and 20640an explicit vector length parameter. 20641 20642 20643Arguments: 20644"""""""""" 20645 20646The '``llvm.vp.sitofp``' intrinsic takes a value to cast as its first operand. 20647The value to cast must be vector of :ref:`integer <t_integer>` type. The 20648return type is the type to cast the value to. The return type must be a vector 20649of :ref:`floating-point <t_floating>` type. The second operand is the vector 20650mask. The return type, the value to cast, and the vector mask have the same 20651number of elements. The third operand is the explicit vector length of the 20652operation. 20653 20654Semantics: 20655"""""""""" 20656 20657The '``llvm.vp.sitofp``' intrinsic interprets its first operand as a signed 20658integer quantity and converts it to the corresponding floating-point value. If 20659the value cannot be exactly represented, it is rounded using the default 20660rounding mode. The conversion is performed on lane positions below the 20661explicit vector length and where the vector mask is true. Masked-off lanes are 20662undefined. 20663 20664Examples: 20665""""""""" 20666 20667.. code-block:: llvm 20668 20669 %r = call <4 x float> @llvm.vp.sitofp.v4f32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 20670 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20671 20672 %t = sitofp <4 x i32> %a to <4 x float> 20673 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 20674 20675 20676.. _int_vp_ptrtoint: 20677 20678'``llvm.vp.ptrtoint.*``' Intrinsics 20679^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20680 20681Syntax: 20682""""""" 20683This is an overloaded intrinsic. 20684 20685:: 20686 20687 declare <16 x i8> @llvm.vp.ptrtoint.v16i8.v16p0i32 (<16 x i32*> <op>, <16 x i1> <mask>, i32 <vector_length>) 20688 declare <vscale x 4 x i8> @llvm.vp.ptrtoint.nxv4i8.nxv4p0i32 (<vscale x 4 x i32*> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 20689 declare <256 x i64> @llvm.vp.ptrtoint.v16i64.v16p0i32 (<256 x i32*> <op>, <256 x i1> <mask>, i32 <vector_length>) 20690 20691Overview: 20692""""""""" 20693 20694The '``llvm.vp.ptrtoint``' intrinsic converts its pointer to the integer return 20695type. The operation has a mask and an explicit vector length parameter. 20696 20697 20698Arguments: 20699"""""""""" 20700 20701The '``llvm.vp.ptrtoint``' intrinsic takes a value to cast as its first operand 20702, which must be a vector of pointers, and a type to cast it to return type, 20703which must be a vector of :ref:`integer <t_integer>` type. 20704The second operand is the vector mask. The return type, the value to cast, and 20705the vector mask have the same number of elements. 20706The third operand is the explicit vector length of the operation. 20707 20708Semantics: 20709"""""""""" 20710 20711The '``llvm.vp.ptrtoint``' intrinsic converts value to return type by 20712interpreting the pointer value as an integer and either truncating or zero 20713extending that value to the size of the integer type. 20714If ``value`` is smaller than return type, then a zero extension is done. If 20715``value`` is larger than return type, then a truncation is done. If they are 20716the same size, then nothing is done (*no-op cast*) other than a type 20717change. 20718The conversion is performed on lane positions below the explicit vector length 20719and where the vector mask is true. Masked-off lanes are undefined. 20720 20721Examples: 20722""""""""" 20723 20724.. code-block:: llvm 20725 20726 %r = call <4 x i8> @llvm.vp.ptrtoint.v4i8.v4p0i32(<4 x i32*> %a, <4 x i1> %mask, i32 %evl) 20727 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20728 20729 %t = ptrtoint <4 x i32*> %a to <4 x i8> 20730 %also.r = select <4 x i1> %mask, <4 x i8> %t, <4 x i8> undef 20731 20732 20733.. _int_vp_inttoptr: 20734 20735'``llvm.vp.inttoptr.*``' Intrinsics 20736^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20737 20738Syntax: 20739""""""" 20740This is an overloaded intrinsic. 20741 20742:: 20743 20744 declare <16 x i32*> @llvm.vp.inttoptr.v16p0i32.v16i32 (<16 x i32> <op>, <16 x i1> <mask>, i32 <vector_length>) 20745 declare <vscale x 4 x i32*> @llvm.vp.inttoptr.nxv4p0i32.nxv4i32 (<vscale x 4 x i32> <op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 20746 declare <256 x i32*> @llvm.vp.inttoptr.v256p0i32.v256i32 (<256 x i32> <op>, <256 x i1> <mask>, i32 <vector_length>) 20747 20748Overview: 20749""""""""" 20750 20751The '``llvm.vp.inttoptr``' intrinsic converts its integer value to the point 20752return type. The operation has a mask and an explicit vector length parameter. 20753 20754 20755Arguments: 20756"""""""""" 20757 20758The '``llvm.vp.inttoptr``' intrinsic takes a value to cast as its first operand 20759, which must be a vector of :ref:`integer <t_integer>` type, and a type to cast 20760it to return type, which must be a vector of pointers type. 20761The second operand is the vector mask. The return type, the value to cast, and 20762the vector mask have the same number of elements. 20763The third operand is the explicit vector length of the operation. 20764 20765Semantics: 20766"""""""""" 20767 20768The '``llvm.vp.inttoptr``' intrinsic converts ``value`` to return type by 20769applying either a zero extension or a truncation depending on the size of the 20770integer ``value``. If ``value`` is larger than the size of a pointer, then a 20771truncation is done. If ``value`` is smaller than the size of a pointer, then a 20772zero extension is done. If they are the same size, nothing is done (*no-op cast*). 20773The conversion is performed on lane positions below the explicit vector length 20774and where the vector mask is true. Masked-off lanes are undefined. 20775 20776Examples: 20777""""""""" 20778 20779.. code-block:: llvm 20780 20781 %r = call <4 x i32*> @llvm.vp.inttoptr.v4p0i32.v4i32(<4 x i32> %a, <4 x i1> %mask, i32 %evl) 20782 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20783 20784 %t = inttoptr <4 x i32> %a to <4 x i32*> 20785 %also.r = select <4 x i1> %mask, <4 x i32*> %t, <4 x i32*> undef 20786 20787 20788.. _int_vp_fcmp: 20789 20790'``llvm.vp.fcmp.*``' Intrinsics 20791^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20792 20793Syntax: 20794""""""" 20795This is an overloaded intrinsic. 20796 20797:: 20798 20799 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>) 20800 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>) 20801 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>) 20802 20803Overview: 20804""""""""" 20805 20806The '``llvm.vp.fcmp``' intrinsic returns a vector of boolean values based on 20807the comparison of its operands. The operation has a mask and an explicit vector 20808length parameter. 20809 20810 20811Arguments: 20812"""""""""" 20813 20814The '``llvm.vp.fcmp``' intrinsic takes the two values to compare as its first 20815and second operands. These two values must be vectors of :ref:`floating-point 20816<t_floating>` types. 20817The return type is the result of the comparison. The return type must be a 20818vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask. 20819The return type, the values to compare, and the vector mask have the same 20820number of elements. The third operand is the condition code indicating the kind 20821of comparison to perform. It must be a metadata string with :ref:`one of the 20822supported floating-point condition code values <fcmp_md_cc>`. The fifth operand 20823is the explicit vector length of the operation. 20824 20825Semantics: 20826"""""""""" 20827 20828The '``llvm.vp.fcmp``' compares its first two operands according to the 20829condition code given as the third operand. The operands are compared element by 20830element on each enabled lane, where the the semantics of the comparison are 20831defined :ref:`according to the condition code <fcmp_md_cc_sem>`. Masked-off 20832lanes are undefined. 20833 20834Examples: 20835""""""""" 20836 20837.. code-block:: llvm 20838 20839 %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) 20840 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20841 20842 %t = fcmp oeq <4 x float> %a, %b 20843 %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> undef 20844 20845 20846.. _int_vp_icmp: 20847 20848'``llvm.vp.icmp.*``' Intrinsics 20849^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20850 20851Syntax: 20852""""""" 20853This is an overloaded intrinsic. 20854 20855:: 20856 20857 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>) 20858 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>) 20859 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>) 20860 20861Overview: 20862""""""""" 20863 20864The '``llvm.vp.icmp``' intrinsic returns a vector of boolean values based on 20865the comparison of its operands. The operation has a mask and an explicit vector 20866length parameter. 20867 20868 20869Arguments: 20870"""""""""" 20871 20872The '``llvm.vp.icmp``' intrinsic takes the two values to compare as its first 20873and second operands. These two values must be vectors of :ref:`integer 20874<t_integer>` types. 20875The return type is the result of the comparison. The return type must be a 20876vector of :ref:`i1 <t_integer>` type. The fourth operand is the vector mask. 20877The return type, the values to compare, and the vector mask have the same 20878number of elements. The third operand is the condition code indicating the kind 20879of comparison to perform. It must be a metadata string with :ref:`one of the 20880supported integer condition code values <icmp_md_cc>`. The fifth operand is the 20881explicit vector length of the operation. 20882 20883Semantics: 20884"""""""""" 20885 20886The '``llvm.vp.icmp``' compares its first two operands according to the 20887condition code given as the third operand. The operands are compared element by 20888element on each enabled lane, where the the semantics of the comparison are 20889defined :ref:`according to the condition code <icmp_md_cc_sem>`. Masked-off 20890lanes are undefined. 20891 20892Examples: 20893""""""""" 20894 20895.. code-block:: llvm 20896 20897 %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) 20898 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 20899 20900 %t = icmp ne <4 x i32> %a, %b 20901 %also.r = select <4 x i1> %mask, <4 x i1> %t, <4 x i1> undef 20902 20903 20904.. _int_mload_mstore: 20905 20906Masked Vector Load and Store Intrinsics 20907--------------------------------------- 20908 20909LLVM 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. 20910 20911.. _int_mload: 20912 20913'``llvm.masked.load.*``' Intrinsics 20914^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20915 20916Syntax: 20917""""""" 20918This is an overloaded intrinsic. The loaded data is a vector of any integer, floating-point or pointer data type. 20919 20920:: 20921 20922 declare <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>) 20923 declare <2 x double> @llvm.masked.load.v2f64.p0v2f64 (<2 x double>* <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>) 20924 ;; The data is a vector of pointers to double 20925 declare <8 x double*> @llvm.masked.load.v8p0f64.p0v8p0f64 (<8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x double*> <passthru>) 20926 ;; The data is a vector of function pointers 20927 declare <8 x i32 ()*> @llvm.masked.load.v8p0f_i32f.p0v8p0f_i32f (<8 x i32 ()*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x i32 ()*> <passthru>) 20928 20929Overview: 20930""""""""" 20931 20932Reads 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. 20933 20934 20935Arguments: 20936"""""""""" 20937 20938The 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. 20939 20940Semantics: 20941"""""""""" 20942 20943The '``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. 20944The 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. 20945 20946 20947:: 20948 20949 %res = call <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru) 20950 20951 ;; The result of the two following instructions is identical aside from potential memory access exception 20952 %loadlal = load <16 x float>, <16 x float>* %ptr, align 4 20953 %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru 20954 20955.. _int_mstore: 20956 20957'``llvm.masked.store.*``' Intrinsics 20958^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20959 20960Syntax: 20961""""""" 20962This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type. 20963 20964:: 20965 20966 declare void @llvm.masked.store.v8i32.p0v8i32 (<8 x i32> <value>, <8 x i32>* <ptr>, i32 <alignment>, <8 x i1> <mask>) 20967 declare void @llvm.masked.store.v16f32.p0v16f32 (<16 x float> <value>, <16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>) 20968 ;; The data is a vector of pointers to double 20969 declare void @llvm.masked.store.v8p0f64.p0v8p0f64 (<8 x double*> <value>, <8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>) 20970 ;; The data is a vector of function pointers 20971 declare void @llvm.masked.store.v4p0f_i32f.p0v4p0f_i32f (<4 x i32 ()*> <value>, <4 x i32 ()*>* <ptr>, i32 <alignment>, <4 x i1> <mask>) 20972 20973Overview: 20974""""""""" 20975 20976Writes 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. 20977 20978Arguments: 20979"""""""""" 20980 20981The 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. 20982 20983 20984Semantics: 20985"""""""""" 20986 20987The '``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. 20988The 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. 20989 20990:: 20991 20992 call void @llvm.masked.store.v16f32.p0v16f32(<16 x float> %value, <16 x float>* %ptr, i32 4, <16 x i1> %mask) 20993 20994 ;; The result of the following instructions is identical aside from potential data races and memory access exceptions 20995 %oldval = load <16 x float>, <16 x float>* %ptr, align 4 20996 %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval 20997 store <16 x float> %res, <16 x float>* %ptr, align 4 20998 20999 21000Masked Vector Gather and Scatter Intrinsics 21001------------------------------------------- 21002 21003LLVM 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. 21004 21005.. _int_mgather: 21006 21007'``llvm.masked.gather.*``' Intrinsics 21008^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21009 21010Syntax: 21011""""""" 21012This 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. 21013 21014:: 21015 21016 declare <16 x float> @llvm.masked.gather.v16f32.v16p0f32 (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>) 21017 declare <2 x double> @llvm.masked.gather.v2f64.v2p1f64 (<2 x double addrspace(1)*> <ptrs>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>) 21018 declare <8 x float*> @llvm.masked.gather.v8p0f32.v8p0p0f32 (<8 x float**> <ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x float*> <passthru>) 21019 21020Overview: 21021""""""""" 21022 21023Reads 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. 21024 21025 21026Arguments: 21027"""""""""" 21028 21029The 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. 21030 21031Semantics: 21032"""""""""" 21033 21034The '``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. 21035The 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. 21036 21037 21038:: 21039 21040 %res = call <4 x double> @llvm.masked.gather.v4f64.v4p0f64 (<4 x double*> %ptrs, i32 8, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x double> undef) 21041 21042 ;; The gather with all-true mask is equivalent to the following instruction sequence 21043 %ptr0 = extractelement <4 x double*> %ptrs, i32 0 21044 %ptr1 = extractelement <4 x double*> %ptrs, i32 1 21045 %ptr2 = extractelement <4 x double*> %ptrs, i32 2 21046 %ptr3 = extractelement <4 x double*> %ptrs, i32 3 21047 21048 %val0 = load double, double* %ptr0, align 8 21049 %val1 = load double, double* %ptr1, align 8 21050 %val2 = load double, double* %ptr2, align 8 21051 %val3 = load double, double* %ptr3, align 8 21052 21053 %vec0 = insertelement <4 x double>undef, %val0, 0 21054 %vec01 = insertelement <4 x double>%vec0, %val1, 1 21055 %vec012 = insertelement <4 x double>%vec01, %val2, 2 21056 %vec0123 = insertelement <4 x double>%vec012, %val3, 3 21057 21058.. _int_mscatter: 21059 21060'``llvm.masked.scatter.*``' Intrinsics 21061^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21062 21063Syntax: 21064""""""" 21065This 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. 21066 21067:: 21068 21069 declare void @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> <value>, <8 x i32*> <ptrs>, i32 <alignment>, <8 x i1> <mask>) 21070 declare void @llvm.masked.scatter.v16f32.v16p1f32 (<16 x float> <value>, <16 x float addrspace(1)*> <ptrs>, i32 <alignment>, <16 x i1> <mask>) 21071 declare void @llvm.masked.scatter.v4p0f64.v4p0p0f64 (<4 x double*> <value>, <4 x double**> <ptrs>, i32 <alignment>, <4 x i1> <mask>) 21072 21073Overview: 21074""""""""" 21075 21076Writes 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. 21077 21078Arguments: 21079"""""""""" 21080 21081The 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. 21082 21083Semantics: 21084"""""""""" 21085 21086The '``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. 21087 21088:: 21089 21090 ;; This instruction unconditionally stores data vector in multiple addresses 21091 call @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> %value, <8 x i32*> %ptrs, i32 4, <8 x i1> <true, true, .. true>) 21092 21093 ;; It is equivalent to a list of scalar stores 21094 %val0 = extractelement <8 x i32> %value, i32 0 21095 %val1 = extractelement <8 x i32> %value, i32 1 21096 .. 21097 %val7 = extractelement <8 x i32> %value, i32 7 21098 %ptr0 = extractelement <8 x i32*> %ptrs, i32 0 21099 %ptr1 = extractelement <8 x i32*> %ptrs, i32 1 21100 .. 21101 %ptr7 = extractelement <8 x i32*> %ptrs, i32 7 21102 ;; Note: the order of the following stores is important when they overlap: 21103 store i32 %val0, i32* %ptr0, align 4 21104 store i32 %val1, i32* %ptr1, align 4 21105 .. 21106 store i32 %val7, i32* %ptr7, align 4 21107 21108 21109Masked Vector Expanding Load and Compressing Store Intrinsics 21110------------------------------------------------------------- 21111 21112LLVM 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>`. 21113 21114.. _int_expandload: 21115 21116'``llvm.masked.expandload.*``' Intrinsics 21117^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21118 21119Syntax: 21120""""""" 21121This 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. 21122 21123:: 21124 21125 declare <16 x float> @llvm.masked.expandload.v16f32 (float* <ptr>, <16 x i1> <mask>, <16 x float> <passthru>) 21126 declare <2 x i64> @llvm.masked.expandload.v2i64 (i64* <ptr>, <2 x i1> <mask>, <2 x i64> <passthru>) 21127 21128Overview: 21129""""""""" 21130 21131Reads 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. 21132 21133 21134Arguments: 21135"""""""""" 21136 21137The 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. 21138 21139Semantics: 21140"""""""""" 21141 21142The '``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: 21143 21144.. code-block:: c 21145 21146 // In this loop we load from B and spread the elements into array A. 21147 double *A, B; int *C; 21148 for (int i = 0; i < size; ++i) { 21149 if (C[i] != 0) 21150 A[i] = B[j++]; 21151 } 21152 21153 21154.. code-block:: llvm 21155 21156 ; Load several elements from array B and expand them in a vector. 21157 ; The number of loaded elements is equal to the number of '1' elements in the Mask. 21158 %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(double* %Bptr, <8 x i1> %Mask, <8 x double> undef) 21159 ; Store the result in A 21160 call void @llvm.masked.store.v8f64.p0v8f64(<8 x double> %Tmp, <8 x double>* %Aptr, i32 8, <8 x i1> %Mask) 21161 21162 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask. 21163 %MaskI = bitcast <8 x i1> %Mask to i8 21164 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI) 21165 %MaskI64 = zext i8 %MaskIPopcnt to i64 21166 %BNextInd = add i64 %BInd, %MaskI64 21167 21168 21169Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles. 21170If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load. 21171 21172.. _int_compressstore: 21173 21174'``llvm.masked.compressstore.*``' Intrinsics 21175^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21176 21177Syntax: 21178""""""" 21179This 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. 21180 21181:: 21182 21183 declare void @llvm.masked.compressstore.v8i32 (<8 x i32> <value>, i32* <ptr>, <8 x i1> <mask>) 21184 declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, float* <ptr>, <16 x i1> <mask>) 21185 21186Overview: 21187""""""""" 21188 21189Selects 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. 21190 21191Arguments: 21192"""""""""" 21193 21194The 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. 21195 21196 21197Semantics: 21198"""""""""" 21199 21200The '``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: 21201 21202.. code-block:: c 21203 21204 // In this loop we load elements from A and store them consecutively in B 21205 double *A, B; int *C; 21206 for (int i = 0; i < size; ++i) { 21207 if (C[i] != 0) 21208 B[j++] = A[i] 21209 } 21210 21211 21212.. code-block:: llvm 21213 21214 ; Load elements from A. 21215 %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0v8f64(<8 x double>* %Aptr, i32 8, <8 x i1> %Mask, <8 x double> undef) 21216 ; Store all selected elements consecutively in array B 21217 call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, double* %Bptr, <8 x i1> %Mask) 21218 21219 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask. 21220 %MaskI = bitcast <8 x i1> %Mask to i8 21221 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI) 21222 %MaskI64 = zext i8 %MaskIPopcnt to i64 21223 %BNextInd = add i64 %BInd, %MaskI64 21224 21225 21226Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations. 21227 21228 21229Memory Use Markers 21230------------------ 21231 21232This class of intrinsics provides information about the 21233:ref:`lifetime of memory objects <objectlifetime>` and ranges where variables 21234are immutable. 21235 21236.. _int_lifestart: 21237 21238'``llvm.lifetime.start``' Intrinsic 21239^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21240 21241Syntax: 21242""""""" 21243 21244:: 21245 21246 declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>) 21247 21248Overview: 21249""""""""" 21250 21251The '``llvm.lifetime.start``' intrinsic specifies the start of a memory 21252object's lifetime. 21253 21254Arguments: 21255"""""""""" 21256 21257The first argument is a constant integer representing the size of the 21258object, or -1 if it is variable sized. The second argument is a pointer 21259to the object. 21260 21261Semantics: 21262"""""""""" 21263 21264If ``ptr`` is a stack-allocated object and it points to the first byte of 21265the object, the object is initially marked as dead. 21266``ptr`` is conservatively considered as a non-stack-allocated object if 21267the stack coloring algorithm that is used in the optimization pipeline cannot 21268conclude that ``ptr`` is a stack-allocated object. 21269 21270After '``llvm.lifetime.start``', the stack object that ``ptr`` points is marked 21271as alive and has an uninitialized value. 21272The stack object is marked as dead when either 21273:ref:`llvm.lifetime.end <int_lifeend>` to the alloca is executed or the 21274function returns. 21275 21276After :ref:`llvm.lifetime.end <int_lifeend>` is called, 21277'``llvm.lifetime.start``' on the stack object can be called again. 21278The second '``llvm.lifetime.start``' call marks the object as alive, but it 21279does not change the address of the object. 21280 21281If ``ptr`` is a non-stack-allocated object, it does not point to the first 21282byte of the object or it is a stack object that is already alive, it simply 21283fills all bytes of the object with ``poison``. 21284 21285 21286.. _int_lifeend: 21287 21288'``llvm.lifetime.end``' Intrinsic 21289^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21290 21291Syntax: 21292""""""" 21293 21294:: 21295 21296 declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>) 21297 21298Overview: 21299""""""""" 21300 21301The '``llvm.lifetime.end``' intrinsic specifies the end of a memory object's 21302lifetime. 21303 21304Arguments: 21305"""""""""" 21306 21307The first argument is a constant integer representing the size of the 21308object, or -1 if it is variable sized. The second argument is a pointer 21309to the object. 21310 21311Semantics: 21312"""""""""" 21313 21314If ``ptr`` is a stack-allocated object and it points to the first byte of the 21315object, the object is dead. 21316``ptr`` is conservatively considered as a non-stack-allocated object if 21317the stack coloring algorithm that is used in the optimization pipeline cannot 21318conclude that ``ptr`` is a stack-allocated object. 21319 21320Calling ``llvm.lifetime.end`` on an already dead alloca is no-op. 21321 21322If ``ptr`` is a non-stack-allocated object or it does not point to the first 21323byte of the object, it is equivalent to simply filling all bytes of the object 21324with ``poison``. 21325 21326 21327'``llvm.invariant.start``' Intrinsic 21328^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21329 21330Syntax: 21331""""""" 21332This is an overloaded intrinsic. The memory object can belong to any address space. 21333 21334:: 21335 21336 declare {}* @llvm.invariant.start.p0i8(i64 <size>, i8* nocapture <ptr>) 21337 21338Overview: 21339""""""""" 21340 21341The '``llvm.invariant.start``' intrinsic specifies that the contents of 21342a memory object will not change. 21343 21344Arguments: 21345"""""""""" 21346 21347The first argument is a constant integer representing the size of the 21348object, or -1 if it is variable sized. The second argument is a pointer 21349to the object. 21350 21351Semantics: 21352"""""""""" 21353 21354This intrinsic indicates that until an ``llvm.invariant.end`` that uses 21355the return value, the referenced memory location is constant and 21356unchanging. 21357 21358'``llvm.invariant.end``' Intrinsic 21359^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21360 21361Syntax: 21362""""""" 21363This is an overloaded intrinsic. The memory object can belong to any address space. 21364 21365:: 21366 21367 declare void @llvm.invariant.end.p0i8({}* <start>, i64 <size>, i8* nocapture <ptr>) 21368 21369Overview: 21370""""""""" 21371 21372The '``llvm.invariant.end``' intrinsic specifies that the contents of a 21373memory object are mutable. 21374 21375Arguments: 21376"""""""""" 21377 21378The first argument is the matching ``llvm.invariant.start`` intrinsic. 21379The second argument is a constant integer representing the size of the 21380object, or -1 if it is variable sized and the third argument is a 21381pointer to the object. 21382 21383Semantics: 21384"""""""""" 21385 21386This intrinsic indicates that the memory is mutable again. 21387 21388'``llvm.launder.invariant.group``' Intrinsic 21389^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21390 21391Syntax: 21392""""""" 21393This is an overloaded intrinsic. The memory object can belong to any address 21394space. The returned pointer must belong to the same address space as the 21395argument. 21396 21397:: 21398 21399 declare i8* @llvm.launder.invariant.group.p0i8(i8* <ptr>) 21400 21401Overview: 21402""""""""" 21403 21404The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant 21405established by ``invariant.group`` metadata no longer holds, to obtain a new 21406pointer value that carries fresh invariant group information. It is an 21407experimental intrinsic, which means that its semantics might change in the 21408future. 21409 21410 21411Arguments: 21412"""""""""" 21413 21414The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer 21415to the memory. 21416 21417Semantics: 21418"""""""""" 21419 21420Returns another pointer that aliases its argument but which is considered different 21421for the purposes of ``load``/``store`` ``invariant.group`` metadata. 21422It does not read any accessible memory and the execution can be speculated. 21423 21424'``llvm.strip.invariant.group``' Intrinsic 21425^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21426 21427Syntax: 21428""""""" 21429This is an overloaded intrinsic. The memory object can belong to any address 21430space. The returned pointer must belong to the same address space as the 21431argument. 21432 21433:: 21434 21435 declare i8* @llvm.strip.invariant.group.p0i8(i8* <ptr>) 21436 21437Overview: 21438""""""""" 21439 21440The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant 21441established by ``invariant.group`` metadata no longer holds, to obtain a new pointer 21442value that does not carry the invariant information. It is an experimental 21443intrinsic, which means that its semantics might change in the future. 21444 21445 21446Arguments: 21447"""""""""" 21448 21449The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer 21450to the memory. 21451 21452Semantics: 21453"""""""""" 21454 21455Returns another pointer that aliases its argument but which has no associated 21456``invariant.group`` metadata. 21457It does not read any memory and can be speculated. 21458 21459 21460 21461.. _constrainedfp: 21462 21463Constrained Floating-Point Intrinsics 21464------------------------------------- 21465 21466These intrinsics are used to provide special handling of floating-point 21467operations when specific rounding mode or floating-point exception behavior is 21468required. By default, LLVM optimization passes assume that the rounding mode is 21469round-to-nearest and that floating-point exceptions will not be monitored. 21470Constrained FP intrinsics are used to support non-default rounding modes and 21471accurately preserve exception behavior without compromising LLVM's ability to 21472optimize FP code when the default behavior is used. 21473 21474If any FP operation in a function is constrained then they all must be 21475constrained. This is required for correct LLVM IR. Optimizations that 21476move code around can create miscompiles if mixing of constrained and normal 21477operations is done. The correct way to mix constrained and less constrained 21478operations is to use the rounding mode and exception handling metadata to 21479mark constrained intrinsics as having LLVM's default behavior. 21480 21481Each of these intrinsics corresponds to a normal floating-point operation. The 21482data arguments and the return value are the same as the corresponding FP 21483operation. 21484 21485The rounding mode argument is a metadata string specifying what 21486assumptions, if any, the optimizer can make when transforming constant 21487values. Some constrained FP intrinsics omit this argument. If required 21488by the intrinsic, this argument must be one of the following strings: 21489 21490:: 21491 21492 "round.dynamic" 21493 "round.tonearest" 21494 "round.downward" 21495 "round.upward" 21496 "round.towardzero" 21497 "round.tonearestaway" 21498 21499If this argument is "round.dynamic" optimization passes must assume that the 21500rounding mode is unknown and may change at runtime. No transformations that 21501depend on rounding mode may be performed in this case. 21502 21503The other possible values for the rounding mode argument correspond to the 21504similarly named IEEE rounding modes. If the argument is any of these values 21505optimization passes may perform transformations as long as they are consistent 21506with the specified rounding mode. 21507 21508For example, 'x-0'->'x' is not a valid transformation if the rounding mode is 21509"round.downward" or "round.dynamic" because if the value of 'x' is +0 then 21510'x-0' should evaluate to '-0' when rounding downward. However, this 21511transformation is legal for all other rounding modes. 21512 21513For values other than "round.dynamic" optimization passes may assume that the 21514actual runtime rounding mode (as defined in a target-specific manner) matches 21515the specified rounding mode, but this is not guaranteed. Using a specific 21516non-dynamic rounding mode which does not match the actual rounding mode at 21517runtime results in undefined behavior. 21518 21519The exception behavior argument is a metadata string describing the floating 21520point exception semantics that required for the intrinsic. This argument 21521must be one of the following strings: 21522 21523:: 21524 21525 "fpexcept.ignore" 21526 "fpexcept.maytrap" 21527 "fpexcept.strict" 21528 21529If this argument is "fpexcept.ignore" optimization passes may assume that the 21530exception status flags will not be read and that floating-point exceptions will 21531be masked. This allows transformations to be performed that may change the 21532exception semantics of the original code. For example, FP operations may be 21533speculatively executed in this case whereas they must not be for either of the 21534other possible values of this argument. 21535 21536If the exception behavior argument is "fpexcept.maytrap" optimization passes 21537must avoid transformations that may raise exceptions that would not have been 21538raised by the original code (such as speculatively executing FP operations), but 21539passes are not required to preserve all exceptions that are implied by the 21540original code. For example, exceptions may be potentially hidden by constant 21541folding. 21542 21543If the exception behavior argument is "fpexcept.strict" all transformations must 21544strictly preserve the floating-point exception semantics of the original code. 21545Any FP exception that would have been raised by the original code must be raised 21546by the transformed code, and the transformed code must not raise any FP 21547exceptions that would not have been raised by the original code. This is the 21548exception behavior argument that will be used if the code being compiled reads 21549the FP exception status flags, but this mode can also be used with code that 21550unmasks FP exceptions. 21551 21552The number and order of floating-point exceptions is NOT guaranteed. For 21553example, a series of FP operations that each may raise exceptions may be 21554vectorized into a single instruction that raises each unique exception a single 21555time. 21556 21557Proper :ref:`function attributes <fnattrs>` usage is required for the 21558constrained intrinsics to function correctly. 21559 21560All function *calls* done in a function that uses constrained floating 21561point intrinsics must have the ``strictfp`` attribute. 21562 21563All function *definitions* that use constrained floating point intrinsics 21564must have the ``strictfp`` attribute. 21565 21566'``llvm.experimental.constrained.fadd``' Intrinsic 21567^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21568 21569Syntax: 21570""""""" 21571 21572:: 21573 21574 declare <type> 21575 @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>, 21576 metadata <rounding mode>, 21577 metadata <exception behavior>) 21578 21579Overview: 21580""""""""" 21581 21582The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its 21583two operands. 21584 21585 21586Arguments: 21587"""""""""" 21588 21589The first two arguments to the '``llvm.experimental.constrained.fadd``' 21590intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 21591of floating-point values. Both arguments must have identical types. 21592 21593The third and fourth arguments specify the rounding mode and exception 21594behavior as described above. 21595 21596Semantics: 21597"""""""""" 21598 21599The value produced is the floating-point sum of the two value operands and has 21600the same type as the operands. 21601 21602 21603'``llvm.experimental.constrained.fsub``' Intrinsic 21604^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21605 21606Syntax: 21607""""""" 21608 21609:: 21610 21611 declare <type> 21612 @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>, 21613 metadata <rounding mode>, 21614 metadata <exception behavior>) 21615 21616Overview: 21617""""""""" 21618 21619The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference 21620of its two operands. 21621 21622 21623Arguments: 21624"""""""""" 21625 21626The first two arguments to the '``llvm.experimental.constrained.fsub``' 21627intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 21628of floating-point values. Both arguments must have identical types. 21629 21630The third and fourth arguments specify the rounding mode and exception 21631behavior as described above. 21632 21633Semantics: 21634"""""""""" 21635 21636The value produced is the floating-point difference of the two value operands 21637and has the same type as the operands. 21638 21639 21640'``llvm.experimental.constrained.fmul``' Intrinsic 21641^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21642 21643Syntax: 21644""""""" 21645 21646:: 21647 21648 declare <type> 21649 @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>, 21650 metadata <rounding mode>, 21651 metadata <exception behavior>) 21652 21653Overview: 21654""""""""" 21655 21656The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of 21657its two operands. 21658 21659 21660Arguments: 21661"""""""""" 21662 21663The first two arguments to the '``llvm.experimental.constrained.fmul``' 21664intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 21665of floating-point values. Both arguments must have identical types. 21666 21667The third and fourth arguments specify the rounding mode and exception 21668behavior as described above. 21669 21670Semantics: 21671"""""""""" 21672 21673The value produced is the floating-point product of the two value operands and 21674has the same type as the operands. 21675 21676 21677'``llvm.experimental.constrained.fdiv``' Intrinsic 21678^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21679 21680Syntax: 21681""""""" 21682 21683:: 21684 21685 declare <type> 21686 @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>, 21687 metadata <rounding mode>, 21688 metadata <exception behavior>) 21689 21690Overview: 21691""""""""" 21692 21693The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of 21694its two operands. 21695 21696 21697Arguments: 21698"""""""""" 21699 21700The first two arguments to the '``llvm.experimental.constrained.fdiv``' 21701intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 21702of floating-point values. Both arguments must have identical types. 21703 21704The third and fourth arguments specify the rounding mode and exception 21705behavior as described above. 21706 21707Semantics: 21708"""""""""" 21709 21710The value produced is the floating-point quotient of the two value operands and 21711has the same type as the operands. 21712 21713 21714'``llvm.experimental.constrained.frem``' Intrinsic 21715^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21716 21717Syntax: 21718""""""" 21719 21720:: 21721 21722 declare <type> 21723 @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>, 21724 metadata <rounding mode>, 21725 metadata <exception behavior>) 21726 21727Overview: 21728""""""""" 21729 21730The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder 21731from the division of its two operands. 21732 21733 21734Arguments: 21735"""""""""" 21736 21737The first two arguments to the '``llvm.experimental.constrained.frem``' 21738intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 21739of floating-point values. Both arguments must have identical types. 21740 21741The third and fourth arguments specify the rounding mode and exception 21742behavior as described above. The rounding mode argument has no effect, since 21743the result of frem is never rounded, but the argument is included for 21744consistency with the other constrained floating-point intrinsics. 21745 21746Semantics: 21747"""""""""" 21748 21749The value produced is the floating-point remainder from the division of the two 21750value operands and has the same type as the operands. The remainder has the 21751same sign as the dividend. 21752 21753'``llvm.experimental.constrained.fma``' Intrinsic 21754^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21755 21756Syntax: 21757""""""" 21758 21759:: 21760 21761 declare <type> 21762 @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>, 21763 metadata <rounding mode>, 21764 metadata <exception behavior>) 21765 21766Overview: 21767""""""""" 21768 21769The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a 21770fused-multiply-add operation on its operands. 21771 21772Arguments: 21773"""""""""" 21774 21775The first three arguments to the '``llvm.experimental.constrained.fma``' 21776intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector 21777<t_vector>` of floating-point values. All arguments must have identical types. 21778 21779The fourth and fifth arguments specify the rounding mode and exception behavior 21780as described above. 21781 21782Semantics: 21783"""""""""" 21784 21785The result produced is the product of the first two operands added to the third 21786operand computed with infinite precision, and then rounded to the target 21787precision. 21788 21789'``llvm.experimental.constrained.fptoui``' Intrinsic 21790^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21791 21792Syntax: 21793""""""" 21794 21795:: 21796 21797 declare <ty2> 21798 @llvm.experimental.constrained.fptoui(<type> <value>, 21799 metadata <exception behavior>) 21800 21801Overview: 21802""""""""" 21803 21804The '``llvm.experimental.constrained.fptoui``' intrinsic converts a 21805floating-point ``value`` to its unsigned integer equivalent of type ``ty2``. 21806 21807Arguments: 21808"""""""""" 21809 21810The first argument to the '``llvm.experimental.constrained.fptoui``' 21811intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 21812<t_vector>` of floating point values. 21813 21814The second argument specifies the exception behavior as described above. 21815 21816Semantics: 21817"""""""""" 21818 21819The result produced is an unsigned integer converted from the floating 21820point operand. The value is truncated, so it is rounded towards zero. 21821 21822'``llvm.experimental.constrained.fptosi``' Intrinsic 21823^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21824 21825Syntax: 21826""""""" 21827 21828:: 21829 21830 declare <ty2> 21831 @llvm.experimental.constrained.fptosi(<type> <value>, 21832 metadata <exception behavior>) 21833 21834Overview: 21835""""""""" 21836 21837The '``llvm.experimental.constrained.fptosi``' intrinsic converts 21838:ref:`floating-point <t_floating>` ``value`` to type ``ty2``. 21839 21840Arguments: 21841"""""""""" 21842 21843The first argument to the '``llvm.experimental.constrained.fptosi``' 21844intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 21845<t_vector>` of floating point values. 21846 21847The second argument specifies the exception behavior as described above. 21848 21849Semantics: 21850"""""""""" 21851 21852The result produced is a signed integer converted from the floating 21853point operand. The value is truncated, so it is rounded towards zero. 21854 21855'``llvm.experimental.constrained.uitofp``' Intrinsic 21856^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21857 21858Syntax: 21859""""""" 21860 21861:: 21862 21863 declare <ty2> 21864 @llvm.experimental.constrained.uitofp(<type> <value>, 21865 metadata <rounding mode>, 21866 metadata <exception behavior>) 21867 21868Overview: 21869""""""""" 21870 21871The '``llvm.experimental.constrained.uitofp``' intrinsic converts an 21872unsigned integer ``value`` to a floating-point of type ``ty2``. 21873 21874Arguments: 21875"""""""""" 21876 21877The first argument to the '``llvm.experimental.constrained.uitofp``' 21878intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector 21879<t_vector>` of integer values. 21880 21881The second and third arguments specify the rounding mode and exception 21882behavior as described above. 21883 21884Semantics: 21885"""""""""" 21886 21887An inexact floating-point exception will be raised if rounding is required. 21888Any result produced is a floating point value converted from the input 21889integer operand. 21890 21891'``llvm.experimental.constrained.sitofp``' Intrinsic 21892^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21893 21894Syntax: 21895""""""" 21896 21897:: 21898 21899 declare <ty2> 21900 @llvm.experimental.constrained.sitofp(<type> <value>, 21901 metadata <rounding mode>, 21902 metadata <exception behavior>) 21903 21904Overview: 21905""""""""" 21906 21907The '``llvm.experimental.constrained.sitofp``' intrinsic converts a 21908signed integer ``value`` to a floating-point of type ``ty2``. 21909 21910Arguments: 21911"""""""""" 21912 21913The first argument to the '``llvm.experimental.constrained.sitofp``' 21914intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector 21915<t_vector>` of integer values. 21916 21917The second and third arguments specify the rounding mode and exception 21918behavior as described above. 21919 21920Semantics: 21921"""""""""" 21922 21923An inexact floating-point exception will be raised if rounding is required. 21924Any result produced is a floating point value converted from the input 21925integer operand. 21926 21927'``llvm.experimental.constrained.fptrunc``' Intrinsic 21928^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21929 21930Syntax: 21931""""""" 21932 21933:: 21934 21935 declare <ty2> 21936 @llvm.experimental.constrained.fptrunc(<type> <value>, 21937 metadata <rounding mode>, 21938 metadata <exception behavior>) 21939 21940Overview: 21941""""""""" 21942 21943The '``llvm.experimental.constrained.fptrunc``' intrinsic truncates ``value`` 21944to type ``ty2``. 21945 21946Arguments: 21947"""""""""" 21948 21949The first argument to the '``llvm.experimental.constrained.fptrunc``' 21950intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 21951<t_vector>` of floating point values. This argument must be larger in size 21952than the result. 21953 21954The second and third arguments specify the rounding mode and exception 21955behavior as described above. 21956 21957Semantics: 21958"""""""""" 21959 21960The result produced is a floating point value truncated to be smaller in size 21961than the operand. 21962 21963'``llvm.experimental.constrained.fpext``' Intrinsic 21964^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21965 21966Syntax: 21967""""""" 21968 21969:: 21970 21971 declare <ty2> 21972 @llvm.experimental.constrained.fpext(<type> <value>, 21973 metadata <exception behavior>) 21974 21975Overview: 21976""""""""" 21977 21978The '``llvm.experimental.constrained.fpext``' intrinsic extends a 21979floating-point ``value`` to a larger floating-point value. 21980 21981Arguments: 21982"""""""""" 21983 21984The first argument to the '``llvm.experimental.constrained.fpext``' 21985intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 21986<t_vector>` of floating point values. This argument must be smaller in size 21987than the result. 21988 21989The second argument specifies the exception behavior as described above. 21990 21991Semantics: 21992"""""""""" 21993 21994The result produced is a floating point value extended to be larger in size 21995than the operand. All restrictions that apply to the fpext instruction also 21996apply to this intrinsic. 21997 21998'``llvm.experimental.constrained.fcmp``' and '``llvm.experimental.constrained.fcmps``' Intrinsics 21999^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22000 22001Syntax: 22002""""""" 22003 22004:: 22005 22006 declare <ty2> 22007 @llvm.experimental.constrained.fcmp(<type> <op1>, <type> <op2>, 22008 metadata <condition code>, 22009 metadata <exception behavior>) 22010 declare <ty2> 22011 @llvm.experimental.constrained.fcmps(<type> <op1>, <type> <op2>, 22012 metadata <condition code>, 22013 metadata <exception behavior>) 22014 22015Overview: 22016""""""""" 22017 22018The '``llvm.experimental.constrained.fcmp``' and 22019'``llvm.experimental.constrained.fcmps``' intrinsics return a boolean 22020value or vector of boolean values based on comparison of its operands. 22021 22022If the operands are floating-point scalars, then the result type is a 22023boolean (:ref:`i1 <t_integer>`). 22024 22025If the operands are floating-point vectors, then the result type is a 22026vector of boolean with the same number of elements as the operands being 22027compared. 22028 22029The '``llvm.experimental.constrained.fcmp``' intrinsic performs a quiet 22030comparison operation while the '``llvm.experimental.constrained.fcmps``' 22031intrinsic performs a signaling comparison operation. 22032 22033Arguments: 22034"""""""""" 22035 22036The first two arguments to the '``llvm.experimental.constrained.fcmp``' 22037and '``llvm.experimental.constrained.fcmps``' intrinsics must be 22038:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 22039of floating-point values. Both arguments must have identical types. 22040 22041The third argument is the condition code indicating the kind of comparison 22042to perform. It must be a metadata string with one of the following values: 22043 22044.. _fcmp_md_cc: 22045 22046- "``oeq``": ordered and equal 22047- "``ogt``": ordered and greater than 22048- "``oge``": ordered and greater than or equal 22049- "``olt``": ordered and less than 22050- "``ole``": ordered and less than or equal 22051- "``one``": ordered and not equal 22052- "``ord``": ordered (no nans) 22053- "``ueq``": unordered or equal 22054- "``ugt``": unordered or greater than 22055- "``uge``": unordered or greater than or equal 22056- "``ult``": unordered or less than 22057- "``ule``": unordered or less than or equal 22058- "``une``": unordered or not equal 22059- "``uno``": unordered (either nans) 22060 22061*Ordered* means that neither operand is a NAN while *unordered* means 22062that either operand may be a NAN. 22063 22064The fourth argument specifies the exception behavior as described above. 22065 22066Semantics: 22067"""""""""" 22068 22069``op1`` and ``op2`` are compared according to the condition code given 22070as the third argument. If the operands are vectors, then the 22071vectors are compared element by element. Each comparison performed 22072always yields an :ref:`i1 <t_integer>` result, as follows: 22073 22074.. _fcmp_md_cc_sem: 22075 22076- "``oeq``": yields ``true`` if both operands are not a NAN and ``op1`` 22077 is equal to ``op2``. 22078- "``ogt``": yields ``true`` if both operands are not a NAN and ``op1`` 22079 is greater than ``op2``. 22080- "``oge``": yields ``true`` if both operands are not a NAN and ``op1`` 22081 is greater than or equal to ``op2``. 22082- "``olt``": yields ``true`` if both operands are not a NAN and ``op1`` 22083 is less than ``op2``. 22084- "``ole``": yields ``true`` if both operands are not a NAN and ``op1`` 22085 is less than or equal to ``op2``. 22086- "``one``": yields ``true`` if both operands are not a NAN and ``op1`` 22087 is not equal to ``op2``. 22088- "``ord``": yields ``true`` if both operands are not a NAN. 22089- "``ueq``": yields ``true`` if either operand is a NAN or ``op1`` is 22090 equal to ``op2``. 22091- "``ugt``": yields ``true`` if either operand is a NAN or ``op1`` is 22092 greater than ``op2``. 22093- "``uge``": yields ``true`` if either operand is a NAN or ``op1`` is 22094 greater than or equal to ``op2``. 22095- "``ult``": yields ``true`` if either operand is a NAN or ``op1`` is 22096 less than ``op2``. 22097- "``ule``": yields ``true`` if either operand is a NAN or ``op1`` is 22098 less than or equal to ``op2``. 22099- "``une``": yields ``true`` if either operand is a NAN or ``op1`` is 22100 not equal to ``op2``. 22101- "``uno``": yields ``true`` if either operand is a NAN. 22102 22103The quiet comparison operation performed by 22104'``llvm.experimental.constrained.fcmp``' will only raise an exception 22105if either operand is a SNAN. The signaling comparison operation 22106performed by '``llvm.experimental.constrained.fcmps``' will raise an 22107exception if either operand is a NAN (QNAN or SNAN). Such an exception 22108does not preclude a result being produced (e.g. exception might only 22109set a flag), therefore the distinction between ordered and unordered 22110comparisons is also relevant for the 22111'``llvm.experimental.constrained.fcmps``' intrinsic. 22112 22113'``llvm.experimental.constrained.fmuladd``' Intrinsic 22114^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22115 22116Syntax: 22117""""""" 22118 22119:: 22120 22121 declare <type> 22122 @llvm.experimental.constrained.fmuladd(<type> <op1>, <type> <op2>, 22123 <type> <op3>, 22124 metadata <rounding mode>, 22125 metadata <exception behavior>) 22126 22127Overview: 22128""""""""" 22129 22130The '``llvm.experimental.constrained.fmuladd``' intrinsic represents 22131multiply-add expressions that can be fused if the code generator determines 22132that (a) the target instruction set has support for a fused operation, 22133and (b) that the fused operation is more efficient than the equivalent, 22134separate pair of mul and add instructions. 22135 22136Arguments: 22137"""""""""" 22138 22139The first three arguments to the '``llvm.experimental.constrained.fmuladd``' 22140intrinsic must be floating-point or vector of floating-point values. 22141All three arguments must have identical types. 22142 22143The fourth and fifth arguments specify the rounding mode and exception behavior 22144as described above. 22145 22146Semantics: 22147"""""""""" 22148 22149The expression: 22150 22151:: 22152 22153 %0 = call float @llvm.experimental.constrained.fmuladd.f32(%a, %b, %c, 22154 metadata <rounding mode>, 22155 metadata <exception behavior>) 22156 22157is equivalent to the expression: 22158 22159:: 22160 22161 %0 = call float @llvm.experimental.constrained.fmul.f32(%a, %b, 22162 metadata <rounding mode>, 22163 metadata <exception behavior>) 22164 %1 = call float @llvm.experimental.constrained.fadd.f32(%0, %c, 22165 metadata <rounding mode>, 22166 metadata <exception behavior>) 22167 22168except that it is unspecified whether rounding will be performed between the 22169multiplication and addition steps. Fusion is not guaranteed, even if the target 22170platform supports it. 22171If a fused multiply-add is required, the corresponding 22172:ref:`llvm.experimental.constrained.fma <int_fma>` intrinsic function should be 22173used instead. 22174This never sets errno, just as '``llvm.experimental.constrained.fma.*``'. 22175 22176Constrained libm-equivalent Intrinsics 22177-------------------------------------- 22178 22179In addition to the basic floating-point operations for which constrained 22180intrinsics are described above, there are constrained versions of various 22181operations which provide equivalent behavior to a corresponding libm function. 22182These intrinsics allow the precise behavior of these operations with respect to 22183rounding mode and exception behavior to be controlled. 22184 22185As with the basic constrained floating-point intrinsics, the rounding mode 22186and exception behavior arguments only control the behavior of the optimizer. 22187They do not change the runtime floating-point environment. 22188 22189 22190'``llvm.experimental.constrained.sqrt``' Intrinsic 22191^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22192 22193Syntax: 22194""""""" 22195 22196:: 22197 22198 declare <type> 22199 @llvm.experimental.constrained.sqrt(<type> <op1>, 22200 metadata <rounding mode>, 22201 metadata <exception behavior>) 22202 22203Overview: 22204""""""""" 22205 22206The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root 22207of the specified value, returning the same value as the libm '``sqrt``' 22208functions would, but without setting ``errno``. 22209 22210Arguments: 22211"""""""""" 22212 22213The first argument and the return type are floating-point numbers of the same 22214type. 22215 22216The second and third arguments specify the rounding mode and exception 22217behavior as described above. 22218 22219Semantics: 22220"""""""""" 22221 22222This function returns the nonnegative square root of the specified value. 22223If the value is less than negative zero, a floating-point exception occurs 22224and the return value is architecture specific. 22225 22226 22227'``llvm.experimental.constrained.pow``' Intrinsic 22228^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22229 22230Syntax: 22231""""""" 22232 22233:: 22234 22235 declare <type> 22236 @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>, 22237 metadata <rounding mode>, 22238 metadata <exception behavior>) 22239 22240Overview: 22241""""""""" 22242 22243The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand 22244raised to the (positive or negative) power specified by the second operand. 22245 22246Arguments: 22247"""""""""" 22248 22249The first two arguments and the return value are floating-point numbers of the 22250same type. The second argument specifies the power to which the first argument 22251should be raised. 22252 22253The third and fourth arguments specify the rounding mode and exception 22254behavior as described above. 22255 22256Semantics: 22257"""""""""" 22258 22259This function returns the first value raised to the second power, 22260returning the same values as the libm ``pow`` functions would, and 22261handles error conditions in the same way. 22262 22263 22264'``llvm.experimental.constrained.powi``' Intrinsic 22265^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22266 22267Syntax: 22268""""""" 22269 22270:: 22271 22272 declare <type> 22273 @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>, 22274 metadata <rounding mode>, 22275 metadata <exception behavior>) 22276 22277Overview: 22278""""""""" 22279 22280The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand 22281raised to the (positive or negative) power specified by the second operand. The 22282order of evaluation of multiplications is not defined. When a vector of 22283floating-point type is used, the second argument remains a scalar integer value. 22284 22285 22286Arguments: 22287"""""""""" 22288 22289The first argument and the return value are floating-point numbers of the same 22290type. The second argument is a 32-bit signed integer specifying the power to 22291which the first argument should be raised. 22292 22293The third and fourth arguments specify the rounding mode and exception 22294behavior as described above. 22295 22296Semantics: 22297"""""""""" 22298 22299This function returns the first value raised to the second power with an 22300unspecified sequence of rounding operations. 22301 22302 22303'``llvm.experimental.constrained.sin``' Intrinsic 22304^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22305 22306Syntax: 22307""""""" 22308 22309:: 22310 22311 declare <type> 22312 @llvm.experimental.constrained.sin(<type> <op1>, 22313 metadata <rounding mode>, 22314 metadata <exception behavior>) 22315 22316Overview: 22317""""""""" 22318 22319The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the 22320first operand. 22321 22322Arguments: 22323"""""""""" 22324 22325The first argument and the return type are floating-point numbers of the same 22326type. 22327 22328The second and third arguments specify the rounding mode and exception 22329behavior as described above. 22330 22331Semantics: 22332"""""""""" 22333 22334This function returns the sine of the specified operand, returning the 22335same values as the libm ``sin`` functions would, and handles error 22336conditions in the same way. 22337 22338 22339'``llvm.experimental.constrained.cos``' Intrinsic 22340^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22341 22342Syntax: 22343""""""" 22344 22345:: 22346 22347 declare <type> 22348 @llvm.experimental.constrained.cos(<type> <op1>, 22349 metadata <rounding mode>, 22350 metadata <exception behavior>) 22351 22352Overview: 22353""""""""" 22354 22355The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the 22356first operand. 22357 22358Arguments: 22359"""""""""" 22360 22361The first argument and the return type are floating-point numbers of the same 22362type. 22363 22364The second and third arguments specify the rounding mode and exception 22365behavior as described above. 22366 22367Semantics: 22368"""""""""" 22369 22370This function returns the cosine of the specified operand, returning the 22371same values as the libm ``cos`` functions would, and handles error 22372conditions in the same way. 22373 22374 22375'``llvm.experimental.constrained.exp``' Intrinsic 22376^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22377 22378Syntax: 22379""""""" 22380 22381:: 22382 22383 declare <type> 22384 @llvm.experimental.constrained.exp(<type> <op1>, 22385 metadata <rounding mode>, 22386 metadata <exception behavior>) 22387 22388Overview: 22389""""""""" 22390 22391The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e 22392exponential of the specified value. 22393 22394Arguments: 22395"""""""""" 22396 22397The first argument and the return value are floating-point numbers of the same 22398type. 22399 22400The second and third arguments specify the rounding mode and exception 22401behavior as described above. 22402 22403Semantics: 22404"""""""""" 22405 22406This function returns the same values as the libm ``exp`` functions 22407would, and handles error conditions in the same way. 22408 22409 22410'``llvm.experimental.constrained.exp2``' Intrinsic 22411^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22412 22413Syntax: 22414""""""" 22415 22416:: 22417 22418 declare <type> 22419 @llvm.experimental.constrained.exp2(<type> <op1>, 22420 metadata <rounding mode>, 22421 metadata <exception behavior>) 22422 22423Overview: 22424""""""""" 22425 22426The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2 22427exponential of the specified value. 22428 22429 22430Arguments: 22431"""""""""" 22432 22433The first argument and the return value are floating-point numbers of the same 22434type. 22435 22436The second and third arguments specify the rounding mode and exception 22437behavior as described above. 22438 22439Semantics: 22440"""""""""" 22441 22442This function returns the same values as the libm ``exp2`` functions 22443would, and handles error conditions in the same way. 22444 22445 22446'``llvm.experimental.constrained.log``' Intrinsic 22447^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22448 22449Syntax: 22450""""""" 22451 22452:: 22453 22454 declare <type> 22455 @llvm.experimental.constrained.log(<type> <op1>, 22456 metadata <rounding mode>, 22457 metadata <exception behavior>) 22458 22459Overview: 22460""""""""" 22461 22462The '``llvm.experimental.constrained.log``' intrinsic computes the base-e 22463logarithm of the specified value. 22464 22465Arguments: 22466"""""""""" 22467 22468The first argument and the return value are floating-point numbers of the same 22469type. 22470 22471The second and third arguments specify the rounding mode and exception 22472behavior as described above. 22473 22474 22475Semantics: 22476"""""""""" 22477 22478This function returns the same values as the libm ``log`` functions 22479would, and handles error conditions in the same way. 22480 22481 22482'``llvm.experimental.constrained.log10``' Intrinsic 22483^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22484 22485Syntax: 22486""""""" 22487 22488:: 22489 22490 declare <type> 22491 @llvm.experimental.constrained.log10(<type> <op1>, 22492 metadata <rounding mode>, 22493 metadata <exception behavior>) 22494 22495Overview: 22496""""""""" 22497 22498The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10 22499logarithm of the specified value. 22500 22501Arguments: 22502"""""""""" 22503 22504The first argument and the return value are floating-point numbers of the same 22505type. 22506 22507The second and third arguments specify the rounding mode and exception 22508behavior as described above. 22509 22510Semantics: 22511"""""""""" 22512 22513This function returns the same values as the libm ``log10`` functions 22514would, and handles error conditions in the same way. 22515 22516 22517'``llvm.experimental.constrained.log2``' Intrinsic 22518^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22519 22520Syntax: 22521""""""" 22522 22523:: 22524 22525 declare <type> 22526 @llvm.experimental.constrained.log2(<type> <op1>, 22527 metadata <rounding mode>, 22528 metadata <exception behavior>) 22529 22530Overview: 22531""""""""" 22532 22533The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2 22534logarithm of the specified value. 22535 22536Arguments: 22537"""""""""" 22538 22539The first argument and the return value are floating-point numbers of the same 22540type. 22541 22542The second and third arguments specify the rounding mode and exception 22543behavior as described above. 22544 22545Semantics: 22546"""""""""" 22547 22548This function returns the same values as the libm ``log2`` functions 22549would, and handles error conditions in the same way. 22550 22551 22552'``llvm.experimental.constrained.rint``' Intrinsic 22553^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22554 22555Syntax: 22556""""""" 22557 22558:: 22559 22560 declare <type> 22561 @llvm.experimental.constrained.rint(<type> <op1>, 22562 metadata <rounding mode>, 22563 metadata <exception behavior>) 22564 22565Overview: 22566""""""""" 22567 22568The '``llvm.experimental.constrained.rint``' intrinsic returns the first 22569operand rounded to the nearest integer. It may raise an inexact floating-point 22570exception if the operand is not an integer. 22571 22572Arguments: 22573"""""""""" 22574 22575The first argument and the return value are floating-point numbers of the same 22576type. 22577 22578The second and third arguments specify the rounding mode and exception 22579behavior as described above. 22580 22581Semantics: 22582"""""""""" 22583 22584This function returns the same values as the libm ``rint`` functions 22585would, and handles error conditions in the same way. The rounding mode is 22586described, not determined, by the rounding mode argument. The actual rounding 22587mode is determined by the runtime floating-point environment. The rounding 22588mode argument is only intended as information to the compiler. 22589 22590 22591'``llvm.experimental.constrained.lrint``' Intrinsic 22592^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22593 22594Syntax: 22595""""""" 22596 22597:: 22598 22599 declare <inttype> 22600 @llvm.experimental.constrained.lrint(<fptype> <op1>, 22601 metadata <rounding mode>, 22602 metadata <exception behavior>) 22603 22604Overview: 22605""""""""" 22606 22607The '``llvm.experimental.constrained.lrint``' intrinsic returns the first 22608operand rounded to the nearest integer. An inexact floating-point exception 22609will be raised if the operand is not an integer. An invalid exception is 22610raised if the result is too large to fit into a supported integer type, 22611and in this case the result is undefined. 22612 22613Arguments: 22614"""""""""" 22615 22616The first argument is a floating-point number. The return value is an 22617integer type. Not all types are supported on all targets. The supported 22618types are the same as the ``llvm.lrint`` intrinsic and the ``lrint`` 22619libm functions. 22620 22621The second and third arguments specify the rounding mode and exception 22622behavior as described above. 22623 22624Semantics: 22625"""""""""" 22626 22627This function returns the same values as the libm ``lrint`` functions 22628would, and handles error conditions in the same way. 22629 22630The rounding mode is described, not determined, by the rounding mode 22631argument. The actual rounding mode is determined by the runtime floating-point 22632environment. The rounding mode argument is only intended as information 22633to the compiler. 22634 22635If the runtime floating-point environment is using the default rounding mode 22636then the results will be the same as the llvm.lrint intrinsic. 22637 22638 22639'``llvm.experimental.constrained.llrint``' Intrinsic 22640^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22641 22642Syntax: 22643""""""" 22644 22645:: 22646 22647 declare <inttype> 22648 @llvm.experimental.constrained.llrint(<fptype> <op1>, 22649 metadata <rounding mode>, 22650 metadata <exception behavior>) 22651 22652Overview: 22653""""""""" 22654 22655The '``llvm.experimental.constrained.llrint``' intrinsic returns the first 22656operand rounded to the nearest integer. An inexact floating-point exception 22657will be raised if the operand is not an integer. An invalid exception is 22658raised if the result is too large to fit into a supported integer type, 22659and in this case the result is undefined. 22660 22661Arguments: 22662"""""""""" 22663 22664The first argument is a floating-point number. The return value is an 22665integer type. Not all types are supported on all targets. The supported 22666types are the same as the ``llvm.llrint`` intrinsic and the ``llrint`` 22667libm functions. 22668 22669The second and third arguments specify the rounding mode and exception 22670behavior as described above. 22671 22672Semantics: 22673"""""""""" 22674 22675This function returns the same values as the libm ``llrint`` functions 22676would, and handles error conditions in the same way. 22677 22678The rounding mode is described, not determined, by the rounding mode 22679argument. The actual rounding mode is determined by the runtime floating-point 22680environment. The rounding mode argument is only intended as information 22681to the compiler. 22682 22683If the runtime floating-point environment is using the default rounding mode 22684then the results will be the same as the llvm.llrint intrinsic. 22685 22686 22687'``llvm.experimental.constrained.nearbyint``' Intrinsic 22688^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22689 22690Syntax: 22691""""""" 22692 22693:: 22694 22695 declare <type> 22696 @llvm.experimental.constrained.nearbyint(<type> <op1>, 22697 metadata <rounding mode>, 22698 metadata <exception behavior>) 22699 22700Overview: 22701""""""""" 22702 22703The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first 22704operand rounded to the nearest integer. It will not raise an inexact 22705floating-point exception if the operand is not an integer. 22706 22707 22708Arguments: 22709"""""""""" 22710 22711The first argument and the return value are floating-point numbers of the same 22712type. 22713 22714The second and third arguments specify the rounding mode and exception 22715behavior as described above. 22716 22717Semantics: 22718"""""""""" 22719 22720This function returns the same values as the libm ``nearbyint`` functions 22721would, and handles error conditions in the same way. The rounding mode is 22722described, not determined, by the rounding mode argument. The actual rounding 22723mode is determined by the runtime floating-point environment. The rounding 22724mode argument is only intended as information to the compiler. 22725 22726 22727'``llvm.experimental.constrained.maxnum``' Intrinsic 22728^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22729 22730Syntax: 22731""""""" 22732 22733:: 22734 22735 declare <type> 22736 @llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2> 22737 metadata <exception behavior>) 22738 22739Overview: 22740""""""""" 22741 22742The '``llvm.experimental.constrained.maxnum``' intrinsic returns the maximum 22743of the two arguments. 22744 22745Arguments: 22746"""""""""" 22747 22748The first two arguments and the return value are floating-point numbers 22749of the same type. 22750 22751The third argument specifies the exception behavior as described above. 22752 22753Semantics: 22754"""""""""" 22755 22756This function follows the IEEE-754 semantics for maxNum. 22757 22758 22759'``llvm.experimental.constrained.minnum``' Intrinsic 22760^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22761 22762Syntax: 22763""""""" 22764 22765:: 22766 22767 declare <type> 22768 @llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2> 22769 metadata <exception behavior>) 22770 22771Overview: 22772""""""""" 22773 22774The '``llvm.experimental.constrained.minnum``' intrinsic returns the minimum 22775of the two arguments. 22776 22777Arguments: 22778"""""""""" 22779 22780The first two arguments and the return value are floating-point numbers 22781of the same type. 22782 22783The third argument specifies the exception behavior as described above. 22784 22785Semantics: 22786"""""""""" 22787 22788This function follows the IEEE-754 semantics for minNum. 22789 22790 22791'``llvm.experimental.constrained.maximum``' Intrinsic 22792^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22793 22794Syntax: 22795""""""" 22796 22797:: 22798 22799 declare <type> 22800 @llvm.experimental.constrained.maximum(<type> <op1>, <type> <op2> 22801 metadata <exception behavior>) 22802 22803Overview: 22804""""""""" 22805 22806The '``llvm.experimental.constrained.maximum``' intrinsic returns the maximum 22807of the two arguments, propagating NaNs and treating -0.0 as less than +0.0. 22808 22809Arguments: 22810"""""""""" 22811 22812The first two arguments and the return value are floating-point numbers 22813of the same type. 22814 22815The third argument specifies the exception behavior as described above. 22816 22817Semantics: 22818"""""""""" 22819 22820This function follows semantics specified in the draft of IEEE 754-2018. 22821 22822 22823'``llvm.experimental.constrained.minimum``' Intrinsic 22824^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22825 22826Syntax: 22827""""""" 22828 22829:: 22830 22831 declare <type> 22832 @llvm.experimental.constrained.minimum(<type> <op1>, <type> <op2> 22833 metadata <exception behavior>) 22834 22835Overview: 22836""""""""" 22837 22838The '``llvm.experimental.constrained.minimum``' intrinsic returns the minimum 22839of the two arguments, propagating NaNs and treating -0.0 as less than +0.0. 22840 22841Arguments: 22842"""""""""" 22843 22844The first two arguments and the return value are floating-point numbers 22845of the same type. 22846 22847The third argument specifies the exception behavior as described above. 22848 22849Semantics: 22850"""""""""" 22851 22852This function follows semantics specified in the draft of IEEE 754-2018. 22853 22854 22855'``llvm.experimental.constrained.ceil``' Intrinsic 22856^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22857 22858Syntax: 22859""""""" 22860 22861:: 22862 22863 declare <type> 22864 @llvm.experimental.constrained.ceil(<type> <op1>, 22865 metadata <exception behavior>) 22866 22867Overview: 22868""""""""" 22869 22870The '``llvm.experimental.constrained.ceil``' intrinsic returns the ceiling of the 22871first operand. 22872 22873Arguments: 22874"""""""""" 22875 22876The first argument and the return value are floating-point numbers of the same 22877type. 22878 22879The second argument specifies the exception behavior as described above. 22880 22881Semantics: 22882"""""""""" 22883 22884This function returns the same values as the libm ``ceil`` functions 22885would and handles error conditions in the same way. 22886 22887 22888'``llvm.experimental.constrained.floor``' Intrinsic 22889^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22890 22891Syntax: 22892""""""" 22893 22894:: 22895 22896 declare <type> 22897 @llvm.experimental.constrained.floor(<type> <op1>, 22898 metadata <exception behavior>) 22899 22900Overview: 22901""""""""" 22902 22903The '``llvm.experimental.constrained.floor``' intrinsic returns the floor of the 22904first operand. 22905 22906Arguments: 22907"""""""""" 22908 22909The first argument and the return value are floating-point numbers of the same 22910type. 22911 22912The second argument specifies the exception behavior as described above. 22913 22914Semantics: 22915"""""""""" 22916 22917This function returns the same values as the libm ``floor`` functions 22918would and handles error conditions in the same way. 22919 22920 22921'``llvm.experimental.constrained.round``' Intrinsic 22922^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22923 22924Syntax: 22925""""""" 22926 22927:: 22928 22929 declare <type> 22930 @llvm.experimental.constrained.round(<type> <op1>, 22931 metadata <exception behavior>) 22932 22933Overview: 22934""""""""" 22935 22936The '``llvm.experimental.constrained.round``' intrinsic returns the first 22937operand rounded to the nearest integer. 22938 22939Arguments: 22940"""""""""" 22941 22942The first argument and the return value are floating-point numbers of the same 22943type. 22944 22945The second argument specifies the exception behavior as described above. 22946 22947Semantics: 22948"""""""""" 22949 22950This function returns the same values as the libm ``round`` functions 22951would and handles error conditions in the same way. 22952 22953 22954'``llvm.experimental.constrained.roundeven``' Intrinsic 22955^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22956 22957Syntax: 22958""""""" 22959 22960:: 22961 22962 declare <type> 22963 @llvm.experimental.constrained.roundeven(<type> <op1>, 22964 metadata <exception behavior>) 22965 22966Overview: 22967""""""""" 22968 22969The '``llvm.experimental.constrained.roundeven``' intrinsic returns the first 22970operand rounded to the nearest integer in floating-point format, rounding 22971halfway cases to even (that is, to the nearest value that is an even integer), 22972regardless of the current rounding direction. 22973 22974Arguments: 22975"""""""""" 22976 22977The first argument and the return value are floating-point numbers of the same 22978type. 22979 22980The second argument specifies the exception behavior as described above. 22981 22982Semantics: 22983"""""""""" 22984 22985This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It 22986also behaves in the same way as C standard function ``roundeven`` and can signal 22987the invalid operation exception for a SNAN operand. 22988 22989 22990'``llvm.experimental.constrained.lround``' Intrinsic 22991^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22992 22993Syntax: 22994""""""" 22995 22996:: 22997 22998 declare <inttype> 22999 @llvm.experimental.constrained.lround(<fptype> <op1>, 23000 metadata <exception behavior>) 23001 23002Overview: 23003""""""""" 23004 23005The '``llvm.experimental.constrained.lround``' intrinsic returns the first 23006operand rounded to the nearest integer with ties away from zero. It will 23007raise an inexact floating-point exception if the operand is not an integer. 23008An invalid exception is raised if the result is too large to fit into a 23009supported integer type, and in this case the result is undefined. 23010 23011Arguments: 23012"""""""""" 23013 23014The first argument is a floating-point number. The return value is an 23015integer type. Not all types are supported on all targets. The supported 23016types are the same as the ``llvm.lround`` intrinsic and the ``lround`` 23017libm functions. 23018 23019The second argument specifies the exception behavior as described above. 23020 23021Semantics: 23022"""""""""" 23023 23024This function returns the same values as the libm ``lround`` functions 23025would and handles error conditions in the same way. 23026 23027 23028'``llvm.experimental.constrained.llround``' Intrinsic 23029^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23030 23031Syntax: 23032""""""" 23033 23034:: 23035 23036 declare <inttype> 23037 @llvm.experimental.constrained.llround(<fptype> <op1>, 23038 metadata <exception behavior>) 23039 23040Overview: 23041""""""""" 23042 23043The '``llvm.experimental.constrained.llround``' intrinsic returns the first 23044operand rounded to the nearest integer with ties away from zero. It will 23045raise an inexact floating-point exception if the operand is not an integer. 23046An invalid exception is raised if the result is too large to fit into a 23047supported integer type, and in this case the result is undefined. 23048 23049Arguments: 23050"""""""""" 23051 23052The first argument is a floating-point number. The return value is an 23053integer type. Not all types are supported on all targets. The supported 23054types are the same as the ``llvm.llround`` intrinsic and the ``llround`` 23055libm functions. 23056 23057The second argument specifies the exception behavior as described above. 23058 23059Semantics: 23060"""""""""" 23061 23062This function returns the same values as the libm ``llround`` functions 23063would and handles error conditions in the same way. 23064 23065 23066'``llvm.experimental.constrained.trunc``' Intrinsic 23067^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23068 23069Syntax: 23070""""""" 23071 23072:: 23073 23074 declare <type> 23075 @llvm.experimental.constrained.trunc(<type> <op1>, 23076 metadata <exception behavior>) 23077 23078Overview: 23079""""""""" 23080 23081The '``llvm.experimental.constrained.trunc``' intrinsic returns the first 23082operand rounded to the nearest integer not larger in magnitude than the 23083operand. 23084 23085Arguments: 23086"""""""""" 23087 23088The first argument and the return value are floating-point numbers of the same 23089type. 23090 23091The second argument specifies the exception behavior as described above. 23092 23093Semantics: 23094"""""""""" 23095 23096This function returns the same values as the libm ``trunc`` functions 23097would and handles error conditions in the same way. 23098 23099.. _int_experimental_noalias_scope_decl: 23100 23101'``llvm.experimental.noalias.scope.decl``' Intrinsic 23102^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23103 23104Syntax: 23105""""""" 23106 23107 23108:: 23109 23110 declare void @llvm.experimental.noalias.scope.decl(metadata !id.scope.list) 23111 23112Overview: 23113""""""""" 23114 23115The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a 23116noalias scope is declared. When the intrinsic is duplicated, a decision must 23117also be made about the scope: depending on the reason of the duplication, 23118the scope might need to be duplicated as well. 23119 23120 23121Arguments: 23122"""""""""" 23123 23124The ``!id.scope.list`` argument is metadata that is a list of ``noalias`` 23125metadata references. The format is identical to that required for ``noalias`` 23126metadata. This list must have exactly one element. 23127 23128Semantics: 23129"""""""""" 23130 23131The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a 23132noalias scope is declared. When the intrinsic is duplicated, a decision must 23133also be made about the scope: depending on the reason of the duplication, 23134the scope might need to be duplicated as well. 23135 23136For example, when the intrinsic is used inside a loop body, and that loop is 23137unrolled, the associated noalias scope must also be duplicated. Otherwise, the 23138noalias property it signifies would spill across loop iterations, whereas it 23139was only valid within a single iteration. 23140 23141.. code-block:: llvm 23142 23143 ; This examples shows two possible positions for noalias.decl and how they impact the semantics: 23144 ; If it is outside the loop (Version 1), then %a and %b are noalias across *all* iterations. 23145 ; If it is inside the loop (Version 2), then %a and %b are noalias only within *one* iteration. 23146 declare void @decl_in_loop(i8* %a.base, i8* %b.base) { 23147 entry: 23148 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 1: noalias decl outside loop 23149 br label %loop 23150 23151 loop: 23152 %a = phi i8* [ %a.base, %entry ], [ %a.inc, %loop ] 23153 %b = phi i8* [ %b.base, %entry ], [ %b.inc, %loop ] 23154 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 2: noalias decl inside loop 23155 %val = load i8, i8* %a, !alias.scope !2 23156 store i8 %val, i8* %b, !noalias !2 23157 %a.inc = getelementptr inbounds i8, i8* %a, i64 1 23158 %b.inc = getelementptr inbounds i8, i8* %b, i64 1 23159 %cond = call i1 @cond() 23160 br i1 %cond, label %loop, label %exit 23161 23162 exit: 23163 ret void 23164 } 23165 23166 !0 = !{!0} ; domain 23167 !1 = !{!1, !0} ; scope 23168 !2 = !{!1} ; scope list 23169 23170Multiple calls to `@llvm.experimental.noalias.scope.decl` for the same scope 23171are possible, but one should never dominate another. Violations are pointed out 23172by the verifier as they indicate a problem in either a transformation pass or 23173the input. 23174 23175 23176Floating Point Environment Manipulation intrinsics 23177-------------------------------------------------- 23178 23179These functions read or write floating point environment, such as rounding 23180mode or state of floating point exceptions. Altering the floating point 23181environment requires special care. See :ref:`Floating Point Environment <floatenv>`. 23182 23183'``llvm.flt.rounds``' Intrinsic 23184^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23185 23186Syntax: 23187""""""" 23188 23189:: 23190 23191 declare i32 @llvm.flt.rounds() 23192 23193Overview: 23194""""""""" 23195 23196The '``llvm.flt.rounds``' intrinsic reads the current rounding mode. 23197 23198Semantics: 23199"""""""""" 23200 23201The '``llvm.flt.rounds``' intrinsic returns the current rounding mode. 23202Encoding of the returned values is same as the result of ``FLT_ROUNDS``, 23203specified by C standard: 23204 23205:: 23206 23207 0 - toward zero 23208 1 - to nearest, ties to even 23209 2 - toward positive infinity 23210 3 - toward negative infinity 23211 4 - to nearest, ties away from zero 23212 23213Other values may be used to represent additional rounding modes, supported by a 23214target. These values are target-specific. 23215 23216 23217'``llvm.set.rounding``' Intrinsic 23218^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23219 23220Syntax: 23221""""""" 23222 23223:: 23224 23225 declare void @llvm.set.rounding(i32 <val>) 23226 23227Overview: 23228""""""""" 23229 23230The '``llvm.set.rounding``' intrinsic sets current rounding mode. 23231 23232Arguments: 23233"""""""""" 23234 23235The argument is the required rounding mode. Encoding of rounding mode is 23236the same as used by '``llvm.flt.rounds``'. 23237 23238Semantics: 23239"""""""""" 23240 23241The '``llvm.set.rounding``' intrinsic sets the current rounding mode. It is 23242similar to C library function 'fesetround', however this intrinsic does not 23243return any value and uses platform-independent representation of IEEE rounding 23244modes. 23245 23246 23247Floating-Point Test Intrinsics 23248------------------------------ 23249 23250These functions get properties of floating-point values. 23251 23252 23253'``llvm.is.fpclass``' Intrinsic 23254^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23255 23256Syntax: 23257""""""" 23258 23259:: 23260 23261 declare i1 @llvm.is.fpclass(<fptype> <op>, i32 <test>) 23262 declare <N x i1> @llvm.is.fpclass(<vector-fptype> <op>, i32 <test>) 23263 23264Overview: 23265""""""""" 23266 23267The '``llvm.is.fpclass``' intrinsic returns a boolean value or vector of boolean 23268values depending on whether the first argument satisfies the test specified by 23269the second argument. 23270 23271If the first argument is a floating-point scalar, then the result type is a 23272boolean (:ref:`i1 <t_integer>`). 23273 23274If the first argument is a floating-point vector, then the result type is a 23275vector of boolean with the same number of elements as the first argument. 23276 23277Arguments: 23278"""""""""" 23279 23280The first argument to the '``llvm.is.fpclass``' intrinsic must be 23281:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 23282of floating-point values. 23283 23284The second argument specifies, which tests to perform. It is an integer value, 23285each bit in which specifies floating-point class: 23286 23287+-------+----------------------+ 23288| Bit # | floating-point class | 23289+=======+======================+ 23290| 0 | Signaling NaN | 23291+-------+----------------------+ 23292| 1 | Quiet NaN | 23293+-------+----------------------+ 23294| 2 | Negative infinity | 23295+-------+----------------------+ 23296| 3 | Negative normal | 23297+-------+----------------------+ 23298| 4 | Negative subnormal | 23299+-------+----------------------+ 23300| 5 | Negative zero | 23301+-------+----------------------+ 23302| 6 | Positive zero | 23303+-------+----------------------+ 23304| 7 | Positive subnormal | 23305+-------+----------------------+ 23306| 8 | Positive normal | 23307+-------+----------------------+ 23308| 9 | Positive infinity | 23309+-------+----------------------+ 23310 23311Semantics: 23312"""""""""" 23313 23314The function checks if ``op`` belongs to any of the floating-point classes 23315specified by ``test``. If ``op`` is a vector, then the check is made element by 23316element. Each check yields an :ref:`i1 <t_integer>` result, which is ``true``, 23317if the element value satisfies the specified test. The argument ``test`` is a 23318bit mask where each bit specifies floating-point class to test. For example, the 23319value 0x108 makes test for normal value, - bits 3 and 8 in it are set, which 23320means that the function returns ``true`` if ``op`` is a positive or negative 23321normal value. The function never raises floating-point exceptions. 23322 23323 23324General Intrinsics 23325------------------ 23326 23327This class of intrinsics is designed to be generic and has no specific 23328purpose. 23329 23330'``llvm.var.annotation``' Intrinsic 23331^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23332 23333Syntax: 23334""""""" 23335 23336:: 23337 23338 declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32 <int>) 23339 23340Overview: 23341""""""""" 23342 23343The '``llvm.var.annotation``' intrinsic. 23344 23345Arguments: 23346"""""""""" 23347 23348The first argument is a pointer to a value, the second is a pointer to a 23349global string, the third is a pointer to a global string which is the 23350source file name, and the last argument is the line number. 23351 23352Semantics: 23353"""""""""" 23354 23355This intrinsic allows annotation of local variables with arbitrary 23356strings. This can be useful for special purpose optimizations that want 23357to look for these annotations. These have no other defined use; they are 23358ignored by code generation and optimization. 23359 23360'``llvm.ptr.annotation.*``' Intrinsic 23361^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23362 23363Syntax: 23364""""""" 23365 23366This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a 23367pointer to an integer of any width. *NOTE* you must specify an address space for 23368the pointer. The identifier for the default address space is the integer 23369'``0``'. 23370 23371:: 23372 23373 declare i8* @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32 <int>) 23374 declare i16* @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32 <int>) 23375 declare i32* @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32 <int>) 23376 declare i64* @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32 <int>) 23377 declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32 <int>) 23378 23379Overview: 23380""""""""" 23381 23382The '``llvm.ptr.annotation``' intrinsic. 23383 23384Arguments: 23385"""""""""" 23386 23387The first argument is a pointer to an integer value of arbitrary bitwidth 23388(result of some expression), the second is a pointer to a global string, the 23389third is a pointer to a global string which is the source file name, and the 23390last argument is the line number. It returns the value of the first argument. 23391 23392Semantics: 23393"""""""""" 23394 23395This intrinsic allows annotation of a pointer to an integer with arbitrary 23396strings. This can be useful for special purpose optimizations that want to look 23397for these annotations. These have no other defined use; they are ignored by code 23398generation and optimization. 23399 23400'``llvm.annotation.*``' Intrinsic 23401^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23402 23403Syntax: 23404""""""" 23405 23406This is an overloaded intrinsic. You can use '``llvm.annotation``' on 23407any integer bit width. 23408 23409:: 23410 23411 declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int>) 23412 declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int>) 23413 declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int>) 23414 declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int>) 23415 declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32 <int>) 23416 23417Overview: 23418""""""""" 23419 23420The '``llvm.annotation``' intrinsic. 23421 23422Arguments: 23423"""""""""" 23424 23425The first argument is an integer value (result of some expression), the 23426second is a pointer to a global string, the third is a pointer to a 23427global string which is the source file name, and the last argument is 23428the line number. It returns the value of the first argument. 23429 23430Semantics: 23431"""""""""" 23432 23433This intrinsic allows annotations to be put on arbitrary expressions 23434with arbitrary strings. This can be useful for special purpose 23435optimizations that want to look for these annotations. These have no 23436other defined use; they are ignored by code generation and optimization. 23437 23438'``llvm.codeview.annotation``' Intrinsic 23439^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23440 23441Syntax: 23442""""""" 23443 23444This annotation emits a label at its program point and an associated 23445``S_ANNOTATION`` codeview record with some additional string metadata. This is 23446used to implement MSVC's ``__annotation`` intrinsic. It is marked 23447``noduplicate``, so calls to this intrinsic prevent inlining and should be 23448considered expensive. 23449 23450:: 23451 23452 declare void @llvm.codeview.annotation(metadata) 23453 23454Arguments: 23455"""""""""" 23456 23457The argument should be an MDTuple containing any number of MDStrings. 23458 23459'``llvm.trap``' Intrinsic 23460^^^^^^^^^^^^^^^^^^^^^^^^^ 23461 23462Syntax: 23463""""""" 23464 23465:: 23466 23467 declare void @llvm.trap() cold noreturn nounwind 23468 23469Overview: 23470""""""""" 23471 23472The '``llvm.trap``' intrinsic. 23473 23474Arguments: 23475"""""""""" 23476 23477None. 23478 23479Semantics: 23480"""""""""" 23481 23482This intrinsic is lowered to the target dependent trap instruction. If 23483the target does not have a trap instruction, this intrinsic will be 23484lowered to a call of the ``abort()`` function. 23485 23486'``llvm.debugtrap``' Intrinsic 23487^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23488 23489Syntax: 23490""""""" 23491 23492:: 23493 23494 declare void @llvm.debugtrap() nounwind 23495 23496Overview: 23497""""""""" 23498 23499The '``llvm.debugtrap``' intrinsic. 23500 23501Arguments: 23502"""""""""" 23503 23504None. 23505 23506Semantics: 23507"""""""""" 23508 23509This intrinsic is lowered to code which is intended to cause an 23510execution trap with the intention of requesting the attention of a 23511debugger. 23512 23513'``llvm.ubsantrap``' Intrinsic 23514^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23515 23516Syntax: 23517""""""" 23518 23519:: 23520 23521 declare void @llvm.ubsantrap(i8 immarg) cold noreturn nounwind 23522 23523Overview: 23524""""""""" 23525 23526The '``llvm.ubsantrap``' intrinsic. 23527 23528Arguments: 23529"""""""""" 23530 23531An integer describing the kind of failure detected. 23532 23533Semantics: 23534"""""""""" 23535 23536This intrinsic is lowered to code which is intended to cause an execution trap, 23537embedding the argument into encoding of that trap somehow to discriminate 23538crashes if possible. 23539 23540Equivalent to ``@llvm.trap`` for targets that do not support this behaviour. 23541 23542'``llvm.stackprotector``' Intrinsic 23543^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23544 23545Syntax: 23546""""""" 23547 23548:: 23549 23550 declare void @llvm.stackprotector(i8* <guard>, i8** <slot>) 23551 23552Overview: 23553""""""""" 23554 23555The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it 23556onto the stack at ``slot``. The stack slot is adjusted to ensure that it 23557is placed on the stack before local variables. 23558 23559Arguments: 23560"""""""""" 23561 23562The ``llvm.stackprotector`` intrinsic requires two pointer arguments. 23563The first argument is the value loaded from the stack guard 23564``@__stack_chk_guard``. The second variable is an ``alloca`` that has 23565enough space to hold the value of the guard. 23566 23567Semantics: 23568"""""""""" 23569 23570This intrinsic causes the prologue/epilogue inserter to force the position of 23571the ``AllocaInst`` stack slot to be before local variables on the stack. This is 23572to ensure that if a local variable on the stack is overwritten, it will destroy 23573the value of the guard. When the function exits, the guard on the stack is 23574checked against the original guard by ``llvm.stackprotectorcheck``. If they are 23575different, then ``llvm.stackprotectorcheck`` causes the program to abort by 23576calling the ``__stack_chk_fail()`` function. 23577 23578'``llvm.stackguard``' Intrinsic 23579^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23580 23581Syntax: 23582""""""" 23583 23584:: 23585 23586 declare i8* @llvm.stackguard() 23587 23588Overview: 23589""""""""" 23590 23591The ``llvm.stackguard`` intrinsic returns the system stack guard value. 23592 23593It should not be generated by frontends, since it is only for internal usage. 23594The reason why we create this intrinsic is that we still support IR form Stack 23595Protector in FastISel. 23596 23597Arguments: 23598"""""""""" 23599 23600None. 23601 23602Semantics: 23603"""""""""" 23604 23605On some platforms, the value returned by this intrinsic remains unchanged 23606between loads in the same thread. On other platforms, it returns the same 23607global variable value, if any, e.g. ``@__stack_chk_guard``. 23608 23609Currently some platforms have IR-level customized stack guard loading (e.g. 23610X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be 23611in the future. 23612 23613'``llvm.objectsize``' Intrinsic 23614^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23615 23616Syntax: 23617""""""" 23618 23619:: 23620 23621 declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>) 23622 declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>) 23623 23624Overview: 23625""""""""" 23626 23627The ``llvm.objectsize`` intrinsic is designed to provide information to the 23628optimizer to determine whether a) an operation (like memcpy) will overflow a 23629buffer that corresponds to an object, or b) that a runtime check for overflow 23630isn't necessary. An object in this context means an allocation of a specific 23631class, structure, array, or other object. 23632 23633Arguments: 23634"""""""""" 23635 23636The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a 23637pointer to or into the ``object``. The second argument determines whether 23638``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size is 23639unknown. The third argument controls how ``llvm.objectsize`` acts when ``null`` 23640in address space 0 is used as its pointer argument. If it's ``false``, 23641``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if 23642the ``null`` is in a non-zero address space or if ``true`` is given for the 23643third argument of ``llvm.objectsize``, we assume its size is unknown. The fourth 23644argument to ``llvm.objectsize`` determines if the value should be evaluated at 23645runtime. 23646 23647The second, third, and fourth arguments only accept constants. 23648 23649Semantics: 23650"""""""""" 23651 23652The ``llvm.objectsize`` intrinsic is lowered to a value representing the size of 23653the object concerned. If the size cannot be determined, ``llvm.objectsize`` 23654returns ``i32/i64 -1 or 0`` (depending on the ``min`` argument). 23655 23656'``llvm.expect``' Intrinsic 23657^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23658 23659Syntax: 23660""""""" 23661 23662This is an overloaded intrinsic. You can use ``llvm.expect`` on any 23663integer bit width. 23664 23665:: 23666 23667 declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>) 23668 declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>) 23669 declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>) 23670 23671Overview: 23672""""""""" 23673 23674The ``llvm.expect`` intrinsic provides information about expected (the 23675most probable) value of ``val``, which can be used by optimizers. 23676 23677Arguments: 23678"""""""""" 23679 23680The ``llvm.expect`` intrinsic takes two arguments. The first argument is 23681a value. The second argument is an expected value. 23682 23683Semantics: 23684"""""""""" 23685 23686This intrinsic is lowered to the ``val``. 23687 23688'``llvm.expect.with.probability``' Intrinsic 23689^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23690 23691Syntax: 23692""""""" 23693 23694This intrinsic is similar to ``llvm.expect``. This is an overloaded intrinsic. 23695You can use ``llvm.expect.with.probability`` on any integer bit width. 23696 23697:: 23698 23699 declare i1 @llvm.expect.with.probability.i1(i1 <val>, i1 <expected_val>, double <prob>) 23700 declare i32 @llvm.expect.with.probability.i32(i32 <val>, i32 <expected_val>, double <prob>) 23701 declare i64 @llvm.expect.with.probability.i64(i64 <val>, i64 <expected_val>, double <prob>) 23702 23703Overview: 23704""""""""" 23705 23706The ``llvm.expect.with.probability`` intrinsic provides information about 23707expected value of ``val`` with probability(or confidence) ``prob``, which can 23708be used by optimizers. 23709 23710Arguments: 23711"""""""""" 23712 23713The ``llvm.expect.with.probability`` intrinsic takes three arguments. The first 23714argument is a value. The second argument is an expected value. The third 23715argument is a probability. 23716 23717Semantics: 23718"""""""""" 23719 23720This intrinsic is lowered to the ``val``. 23721 23722.. _int_assume: 23723 23724'``llvm.assume``' Intrinsic 23725^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23726 23727Syntax: 23728""""""" 23729 23730:: 23731 23732 declare void @llvm.assume(i1 %cond) 23733 23734Overview: 23735""""""""" 23736 23737The ``llvm.assume`` allows the optimizer to assume that the provided 23738condition is true. This information can then be used in simplifying other parts 23739of the code. 23740 23741More complex assumptions can be encoded as 23742:ref:`assume operand bundles <assume_opbundles>`. 23743 23744Arguments: 23745"""""""""" 23746 23747The argument of the call is the condition which the optimizer may assume is 23748always true. 23749 23750Semantics: 23751"""""""""" 23752 23753The intrinsic allows the optimizer to assume that the provided condition is 23754always true whenever the control flow reaches the intrinsic call. No code is 23755generated for this intrinsic, and instructions that contribute only to the 23756provided condition are not used for code generation. If the condition is 23757violated during execution, the behavior is undefined. 23758 23759Note that the optimizer might limit the transformations performed on values 23760used by the ``llvm.assume`` intrinsic in order to preserve the instructions 23761only used to form the intrinsic's input argument. This might prove undesirable 23762if the extra information provided by the ``llvm.assume`` intrinsic does not cause 23763sufficient overall improvement in code quality. For this reason, 23764``llvm.assume`` should not be used to document basic mathematical invariants 23765that the optimizer can otherwise deduce or facts that are of little use to the 23766optimizer. 23767 23768.. _int_ssa_copy: 23769 23770'``llvm.ssa.copy``' Intrinsic 23771^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23772 23773Syntax: 23774""""""" 23775 23776:: 23777 23778 declare type @llvm.ssa.copy(type %operand) returned(1) readnone 23779 23780Arguments: 23781"""""""""" 23782 23783The first argument is an operand which is used as the returned value. 23784 23785Overview: 23786"""""""""" 23787 23788The ``llvm.ssa.copy`` intrinsic can be used to attach information to 23789operations by copying them and giving them new names. For example, 23790the PredicateInfo utility uses it to build Extended SSA form, and 23791attach various forms of information to operands that dominate specific 23792uses. It is not meant for general use, only for building temporary 23793renaming forms that require value splits at certain points. 23794 23795.. _type.test: 23796 23797'``llvm.type.test``' Intrinsic 23798^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23799 23800Syntax: 23801""""""" 23802 23803:: 23804 23805 declare i1 @llvm.type.test(i8* %ptr, metadata %type) nounwind readnone 23806 23807 23808Arguments: 23809"""""""""" 23810 23811The first argument is a pointer to be tested. The second argument is a 23812metadata object representing a :doc:`type identifier <TypeMetadata>`. 23813 23814Overview: 23815""""""""" 23816 23817The ``llvm.type.test`` intrinsic tests whether the given pointer is associated 23818with the given type identifier. 23819 23820.. _type.checked.load: 23821 23822'``llvm.type.checked.load``' Intrinsic 23823^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23824 23825Syntax: 23826""""""" 23827 23828:: 23829 23830 declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly 23831 23832 23833Arguments: 23834"""""""""" 23835 23836The first argument is a pointer from which to load a function pointer. The 23837second argument is the byte offset from which to load the function pointer. The 23838third argument is a metadata object representing a :doc:`type identifier 23839<TypeMetadata>`. 23840 23841Overview: 23842""""""""" 23843 23844The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a 23845virtual table pointer using type metadata. This intrinsic is used to implement 23846control flow integrity in conjunction with virtual call optimization. The 23847virtual call optimization pass will optimize away ``llvm.type.checked.load`` 23848intrinsics associated with devirtualized calls, thereby removing the type 23849check in cases where it is not needed to enforce the control flow integrity 23850constraint. 23851 23852If the given pointer is associated with a type metadata identifier, this 23853function returns true as the second element of its return value. (Note that 23854the function may also return true if the given pointer is not associated 23855with a type metadata identifier.) If the function's return value's second 23856element is true, the following rules apply to the first element: 23857 23858- If the given pointer is associated with the given type metadata identifier, 23859 it is the function pointer loaded from the given byte offset from the given 23860 pointer. 23861 23862- If the given pointer is not associated with the given type metadata 23863 identifier, it is one of the following (the choice of which is unspecified): 23864 23865 1. The function pointer that would have been loaded from an arbitrarily chosen 23866 (through an unspecified mechanism) pointer associated with the type 23867 metadata. 23868 23869 2. If the function has a non-void return type, a pointer to a function that 23870 returns an unspecified value without causing side effects. 23871 23872If the function's return value's second element is false, the value of the 23873first element is undefined. 23874 23875 23876'``llvm.arithmetic.fence``' Intrinsic 23877^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23878 23879Syntax: 23880""""""" 23881 23882:: 23883 23884 declare <type> 23885 @llvm.arithmetic.fence(<type> <op>) 23886 23887Overview: 23888""""""""" 23889 23890The purpose of the ``llvm.arithmetic.fence`` intrinsic 23891is to prevent the optimizer from performing fast-math optimizations, 23892particularly reassociation, 23893between the argument and the expression that contains the argument. 23894It can be used to preserve the parentheses in the source language. 23895 23896Arguments: 23897"""""""""" 23898 23899The ``llvm.arithmetic.fence`` intrinsic takes only one argument. 23900The argument and the return value are floating-point numbers, 23901or vector floating-point numbers, of the same type. 23902 23903Semantics: 23904"""""""""" 23905 23906This intrinsic returns the value of its operand. The optimizer can optimize 23907the argument, but the optimizer cannot hoist any component of the operand 23908to the containing context, and the optimizer cannot move the calculation of 23909any expression in the containing context into the operand. 23910 23911 23912'``llvm.donothing``' Intrinsic 23913^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23914 23915Syntax: 23916""""""" 23917 23918:: 23919 23920 declare void @llvm.donothing() nounwind readnone 23921 23922Overview: 23923""""""""" 23924 23925The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only 23926three intrinsics (besides ``llvm.experimental.patchpoint`` and 23927``llvm.experimental.gc.statepoint``) that can be called with an invoke 23928instruction. 23929 23930Arguments: 23931"""""""""" 23932 23933None. 23934 23935Semantics: 23936"""""""""" 23937 23938This intrinsic does nothing, and it's removed by optimizers and ignored 23939by codegen. 23940 23941'``llvm.experimental.deoptimize``' Intrinsic 23942^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23943 23944Syntax: 23945""""""" 23946 23947:: 23948 23949 declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ] 23950 23951Overview: 23952""""""""" 23953 23954This intrinsic, together with :ref:`deoptimization operand bundles 23955<deopt_opbundles>`, allow frontends to express transfer of control and 23956frame-local state from the currently executing (typically more specialized, 23957hence faster) version of a function into another (typically more generic, hence 23958slower) version. 23959 23960In languages with a fully integrated managed runtime like Java and JavaScript 23961this intrinsic can be used to implement "uncommon trap" or "side exit" like 23962functionality. In unmanaged languages like C and C++, this intrinsic can be 23963used to represent the slow paths of specialized functions. 23964 23965 23966Arguments: 23967"""""""""" 23968 23969The intrinsic takes an arbitrary number of arguments, whose meaning is 23970decided by the :ref:`lowering strategy<deoptimize_lowering>`. 23971 23972Semantics: 23973"""""""""" 23974 23975The ``@llvm.experimental.deoptimize`` intrinsic executes an attached 23976deoptimization continuation (denoted using a :ref:`deoptimization 23977operand bundle <deopt_opbundles>`) and returns the value returned by 23978the deoptimization continuation. Defining the semantic properties of 23979the continuation itself is out of scope of the language reference -- 23980as far as LLVM is concerned, the deoptimization continuation can 23981invoke arbitrary side effects, including reading from and writing to 23982the entire heap. 23983 23984Deoptimization continuations expressed using ``"deopt"`` operand bundles always 23985continue execution to the end of the physical frame containing them, so all 23986calls to ``@llvm.experimental.deoptimize`` must be in "tail position": 23987 23988 - ``@llvm.experimental.deoptimize`` cannot be invoked. 23989 - The call must immediately precede a :ref:`ret <i_ret>` instruction. 23990 - The ``ret`` instruction must return the value produced by the 23991 ``@llvm.experimental.deoptimize`` call if there is one, or void. 23992 23993Note that the above restrictions imply that the return type for a call to 23994``@llvm.experimental.deoptimize`` will match the return type of its immediate 23995caller. 23996 23997The inliner composes the ``"deopt"`` continuations of the caller into the 23998``"deopt"`` continuations present in the inlinee, and also updates calls to this 23999intrinsic to return directly from the frame of the function it inlined into. 24000 24001All declarations of ``@llvm.experimental.deoptimize`` must share the 24002same calling convention. 24003 24004.. _deoptimize_lowering: 24005 24006Lowering: 24007""""""""" 24008 24009Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the 24010symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to 24011ensure that this symbol is defined). The call arguments to 24012``@llvm.experimental.deoptimize`` are lowered as if they were formal 24013arguments of the specified types, and not as varargs. 24014 24015 24016'``llvm.experimental.guard``' Intrinsic 24017^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24018 24019Syntax: 24020""""""" 24021 24022:: 24023 24024 declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ] 24025 24026Overview: 24027""""""""" 24028 24029This intrinsic, together with :ref:`deoptimization operand bundles 24030<deopt_opbundles>`, allows frontends to express guards or checks on 24031optimistic assumptions made during compilation. The semantics of 24032``@llvm.experimental.guard`` is defined in terms of 24033``@llvm.experimental.deoptimize`` -- its body is defined to be 24034equivalent to: 24035 24036.. code-block:: text 24037 24038 define void @llvm.experimental.guard(i1 %pred, <args...>) { 24039 %realPred = and i1 %pred, undef 24040 br i1 %realPred, label %continue, label %leave [, !make.implicit !{}] 24041 24042 leave: 24043 call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ] 24044 ret void 24045 24046 continue: 24047 ret void 24048 } 24049 24050 24051with the optional ``[, !make.implicit !{}]`` present if and only if it 24052is present on the call site. For more details on ``!make.implicit``, 24053see :doc:`FaultMaps`. 24054 24055In words, ``@llvm.experimental.guard`` executes the attached 24056``"deopt"`` continuation if (but **not** only if) its first argument 24057is ``false``. Since the optimizer is allowed to replace the ``undef`` 24058with an arbitrary value, it can optimize guard to fail "spuriously", 24059i.e. without the original condition being false (hence the "not only 24060if"); and this allows for "check widening" type optimizations. 24061 24062``@llvm.experimental.guard`` cannot be invoked. 24063 24064After ``@llvm.experimental.guard`` was first added, a more general 24065formulation was found in ``@llvm.experimental.widenable.condition``. 24066Support for ``@llvm.experimental.guard`` is slowly being rephrased in 24067terms of this alternate. 24068 24069'``llvm.experimental.widenable.condition``' Intrinsic 24070^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24071 24072Syntax: 24073""""""" 24074 24075:: 24076 24077 declare i1 @llvm.experimental.widenable.condition() 24078 24079Overview: 24080""""""""" 24081 24082This intrinsic represents a "widenable condition" which is 24083boolean expressions with the following property: whether this 24084expression is `true` or `false`, the program is correct and 24085well-defined. 24086 24087Together with :ref:`deoptimization operand bundles <deopt_opbundles>`, 24088``@llvm.experimental.widenable.condition`` allows frontends to 24089express guards or checks on optimistic assumptions made during 24090compilation and represent them as branch instructions on special 24091conditions. 24092 24093While this may appear similar in semantics to `undef`, it is very 24094different in that an invocation produces a particular, singular 24095value. It is also intended to be lowered late, and remain available 24096for specific optimizations and transforms that can benefit from its 24097special properties. 24098 24099Arguments: 24100"""""""""" 24101 24102None. 24103 24104Semantics: 24105"""""""""" 24106 24107The intrinsic ``@llvm.experimental.widenable.condition()`` 24108returns either `true` or `false`. For each evaluation of a call 24109to this intrinsic, the program must be valid and correct both if 24110it returns `true` and if it returns `false`. This allows 24111transformation passes to replace evaluations of this intrinsic 24112with either value whenever one is beneficial. 24113 24114When used in a branch condition, it allows us to choose between 24115two alternative correct solutions for the same problem, like 24116in example below: 24117 24118.. code-block:: text 24119 24120 %cond = call i1 @llvm.experimental.widenable.condition() 24121 br i1 %cond, label %solution_1, label %solution_2 24122 24123 label %fast_path: 24124 ; Apply memory-consuming but fast solution for a task. 24125 24126 label %slow_path: 24127 ; Cheap in memory but slow solution. 24128 24129Whether the result of intrinsic's call is `true` or `false`, 24130it should be correct to pick either solution. We can switch 24131between them by replacing the result of 24132``@llvm.experimental.widenable.condition`` with different 24133`i1` expressions. 24134 24135This is how it can be used to represent guards as widenable branches: 24136 24137.. code-block:: text 24138 24139 block: 24140 ; Unguarded instructions 24141 call void @llvm.experimental.guard(i1 %cond, <args...>) ["deopt"(<deopt_args...>)] 24142 ; Guarded instructions 24143 24144Can be expressed in an alternative equivalent form of explicit branch using 24145``@llvm.experimental.widenable.condition``: 24146 24147.. code-block:: text 24148 24149 block: 24150 ; Unguarded instructions 24151 %widenable_condition = call i1 @llvm.experimental.widenable.condition() 24152 %guard_condition = and i1 %cond, %widenable_condition 24153 br i1 %guard_condition, label %guarded, label %deopt 24154 24155 guarded: 24156 ; Guarded instructions 24157 24158 deopt: 24159 call type @llvm.experimental.deoptimize(<args...>) [ "deopt"(<deopt_args...>) ] 24160 24161So the block `guarded` is only reachable when `%cond` is `true`, 24162and it should be valid to go to the block `deopt` whenever `%cond` 24163is `true` or `false`. 24164 24165``@llvm.experimental.widenable.condition`` will never throw, thus 24166it cannot be invoked. 24167 24168Guard widening: 24169""""""""""""""" 24170 24171When ``@llvm.experimental.widenable.condition()`` is used in 24172condition of a guard represented as explicit branch, it is 24173legal to widen the guard's condition with any additional 24174conditions. 24175 24176Guard widening looks like replacement of 24177 24178.. code-block:: text 24179 24180 %widenable_cond = call i1 @llvm.experimental.widenable.condition() 24181 %guard_cond = and i1 %cond, %widenable_cond 24182 br i1 %guard_cond, label %guarded, label %deopt 24183 24184with 24185 24186.. code-block:: text 24187 24188 %widenable_cond = call i1 @llvm.experimental.widenable.condition() 24189 %new_cond = and i1 %any_other_cond, %widenable_cond 24190 %new_guard_cond = and i1 %cond, %new_cond 24191 br i1 %new_guard_cond, label %guarded, label %deopt 24192 24193for this branch. Here `%any_other_cond` is an arbitrarily chosen 24194well-defined `i1` value. By making guard widening, we may 24195impose stricter conditions on `guarded` block and bail to the 24196deopt when the new condition is not met. 24197 24198Lowering: 24199""""""""" 24200 24201Default lowering strategy is replacing the result of 24202call of ``@llvm.experimental.widenable.condition`` with 24203constant `true`. However it is always correct to replace 24204it with any other `i1` value. Any pass can 24205freely do it if it can benefit from non-default lowering. 24206 24207 24208'``llvm.load.relative``' Intrinsic 24209^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24210 24211Syntax: 24212""""""" 24213 24214:: 24215 24216 declare i8* @llvm.load.relative.iN(i8* %ptr, iN %offset) argmemonly nounwind readonly 24217 24218Overview: 24219""""""""" 24220 24221This intrinsic loads a 32-bit value from the address ``%ptr + %offset``, 24222adds ``%ptr`` to that value and returns it. The constant folder specifically 24223recognizes the form of this intrinsic and the constant initializers it may 24224load from; if a loaded constant initializer is known to have the form 24225``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``. 24226 24227LLVM provides that the calculation of such a constant initializer will 24228not overflow at link time under the medium code model if ``x`` is an 24229``unnamed_addr`` function. However, it does not provide this guarantee for 24230a constant initializer folded into a function body. This intrinsic can be 24231used to avoid the possibility of overflows when loading from such a constant. 24232 24233.. _llvm_sideeffect: 24234 24235'``llvm.sideeffect``' Intrinsic 24236^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24237 24238Syntax: 24239""""""" 24240 24241:: 24242 24243 declare void @llvm.sideeffect() inaccessiblememonly nounwind willreturn 24244 24245Overview: 24246""""""""" 24247 24248The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers 24249treat it as having side effects, so it can be inserted into a loop to 24250indicate that the loop shouldn't be assumed to terminate (which could 24251potentially lead to the loop being optimized away entirely), even if it's 24252an infinite loop with no other side effects. 24253 24254Arguments: 24255"""""""""" 24256 24257None. 24258 24259Semantics: 24260"""""""""" 24261 24262This intrinsic actually does nothing, but optimizers must assume that it 24263has externally observable side effects. 24264 24265'``llvm.is.constant.*``' Intrinsic 24266^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24267 24268Syntax: 24269""""""" 24270 24271This is an overloaded intrinsic. You can use llvm.is.constant with any argument type. 24272 24273:: 24274 24275 declare i1 @llvm.is.constant.i32(i32 %operand) nounwind readnone 24276 declare i1 @llvm.is.constant.f32(float %operand) nounwind readnone 24277 declare i1 @llvm.is.constant.TYPENAME(TYPE %operand) nounwind readnone 24278 24279Overview: 24280""""""""" 24281 24282The '``llvm.is.constant``' intrinsic will return true if the argument 24283is known to be a manifest compile-time constant. It is guaranteed to 24284fold to either true or false before generating machine code. 24285 24286Semantics: 24287"""""""""" 24288 24289This intrinsic generates no code. If its argument is known to be a 24290manifest compile-time constant value, then the intrinsic will be 24291converted to a constant true value. Otherwise, it will be converted to 24292a constant false value. 24293 24294In particular, note that if the argument is a constant expression 24295which refers to a global (the address of which _is_ a constant, but 24296not manifest during the compile), then the intrinsic evaluates to 24297false. 24298 24299The result also intentionally depends on the result of optimization 24300passes -- e.g., the result can change depending on whether a 24301function gets inlined or not. A function's parameters are 24302obviously not constant. However, a call like 24303``llvm.is.constant.i32(i32 %param)`` *can* return true after the 24304function is inlined, if the value passed to the function parameter was 24305a constant. 24306 24307On the other hand, if constant folding is not run, it will never 24308evaluate to true, even in simple cases. 24309 24310.. _int_ptrmask: 24311 24312'``llvm.ptrmask``' Intrinsic 24313^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24314 24315Syntax: 24316""""""" 24317 24318:: 24319 24320 declare ptrty llvm.ptrmask(ptrty %ptr, intty %mask) readnone speculatable 24321 24322Arguments: 24323"""""""""" 24324 24325The first argument is a pointer. The second argument is an integer. 24326 24327Overview: 24328"""""""""" 24329 24330The ``llvm.ptrmask`` intrinsic masks out bits of the pointer according to a mask. 24331This allows stripping data from tagged pointers without converting them to an 24332integer (ptrtoint/inttoptr). As a consequence, we can preserve more information 24333to facilitate alias analysis and underlying-object detection. 24334 24335Semantics: 24336"""""""""" 24337 24338The result of ``ptrmask(ptr, mask)`` is equivalent to 24339``getelementptr ptr, (ptrtoint(ptr) & mask) - ptrtoint(ptr)``. Both the returned 24340pointer and the first argument are based on the same underlying object (for more 24341information on the *based on* terminology see 24342:ref:`the pointer aliasing rules <pointeraliasing>`). If the bitwidth of the 24343mask argument does not match the pointer size of the target, the mask is 24344zero-extended or truncated accordingly. 24345 24346.. _int_vscale: 24347 24348'``llvm.vscale``' Intrinsic 24349^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24350 24351Syntax: 24352""""""" 24353 24354:: 24355 24356 declare i32 llvm.vscale.i32() 24357 declare i64 llvm.vscale.i64() 24358 24359Overview: 24360""""""""" 24361 24362The ``llvm.vscale`` intrinsic returns the value for ``vscale`` in scalable 24363vectors such as ``<vscale x 16 x i8>``. 24364 24365Semantics: 24366"""""""""" 24367 24368``vscale`` is a positive value that is constant throughout program 24369execution, but is unknown at compile time. 24370If the result value does not fit in the result type, then the result is 24371a :ref:`poison value <poisonvalues>`. 24372 24373 24374Stack Map Intrinsics 24375-------------------- 24376 24377LLVM provides experimental intrinsics to support runtime patching 24378mechanisms commonly desired in dynamic language JITs. These intrinsics 24379are described in :doc:`StackMaps`. 24380 24381Element Wise Atomic Memory Intrinsics 24382------------------------------------- 24383 24384These intrinsics are similar to the standard library memory intrinsics except 24385that they perform memory transfer as a sequence of atomic memory accesses. 24386 24387.. _int_memcpy_element_unordered_atomic: 24388 24389'``llvm.memcpy.element.unordered.atomic``' Intrinsic 24390^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24391 24392Syntax: 24393""""""" 24394 24395This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on 24396any integer bit width and for different address spaces. Not all targets 24397support all bit widths however. 24398 24399:: 24400 24401 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>, 24402 i8* <src>, 24403 i32 <len>, 24404 i32 <element_size>) 24405 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>, 24406 i8* <src>, 24407 i64 <len>, 24408 i32 <element_size>) 24409 24410Overview: 24411""""""""" 24412 24413The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the 24414'``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated 24415as arrays with elements that are exactly ``element_size`` bytes, and the copy between 24416buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations 24417that are a positive integer multiple of the ``element_size`` in size. 24418 24419Arguments: 24420"""""""""" 24421 24422The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>` 24423intrinsic, with the added constraint that ``len`` is required to be a positive integer 24424multiple of the ``element_size``. If ``len`` is not a positive integer multiple of 24425``element_size``, then the behaviour of the intrinsic is undefined. 24426 24427``element_size`` must be a compile-time constant positive power of two no greater than 24428target-specific atomic access size limit. 24429 24430For each of the input pointers ``align`` parameter attribute must be specified. It 24431must be a power of two no less than the ``element_size``. Caller guarantees that 24432both the source and destination pointers are aligned to that boundary. 24433 24434Semantics: 24435"""""""""" 24436 24437The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of 24438memory from the source location to the destination location. These locations are not 24439allowed to overlap. The memory copy is performed as a sequence of load/store operations 24440where each access is guaranteed to be a multiple of ``element_size`` bytes wide and 24441aligned at an ``element_size`` boundary. 24442 24443The order of the copy is unspecified. The same value may be read from the source 24444buffer many times, but only one write is issued to the destination buffer per 24445element. It is well defined to have concurrent reads and writes to both source and 24446destination provided those reads and writes are unordered atomic when specified. 24447 24448This intrinsic does not provide any additional ordering guarantees over those 24449provided by a set of unordered loads from the source location and stores to the 24450destination. 24451 24452Lowering: 24453""""""""" 24454 24455In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is 24456lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*' 24457is replaced with an actual element size. See :ref:`RewriteStatepointsForGC intrinsic 24458lowering <RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific 24459lowering. 24460 24461Optimizer is allowed to inline memory copy when it's profitable to do so. 24462 24463'``llvm.memmove.element.unordered.atomic``' Intrinsic 24464^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24465 24466Syntax: 24467""""""" 24468 24469This is an overloaded intrinsic. You can use 24470``llvm.memmove.element.unordered.atomic`` on any integer bit width and for 24471different address spaces. Not all targets support all bit widths however. 24472 24473:: 24474 24475 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>, 24476 i8* <src>, 24477 i32 <len>, 24478 i32 <element_size>) 24479 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>, 24480 i8* <src>, 24481 i64 <len>, 24482 i32 <element_size>) 24483 24484Overview: 24485""""""""" 24486 24487The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization 24488of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and 24489``src`` are treated as arrays with elements that are exactly ``element_size`` 24490bytes, and the copy between buffers uses a sequence of 24491:ref:`unordered atomic <ordering>` load/store operations that are a positive 24492integer multiple of the ``element_size`` in size. 24493 24494Arguments: 24495"""""""""" 24496 24497The first three arguments are the same as they are in the 24498:ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that 24499``len`` is required to be a positive integer multiple of the ``element_size``. 24500If ``len`` is not a positive integer multiple of ``element_size``, then the 24501behaviour of the intrinsic is undefined. 24502 24503``element_size`` must be a compile-time constant positive power of two no 24504greater than a target-specific atomic access size limit. 24505 24506For each of the input pointers the ``align`` parameter attribute must be 24507specified. It must be a power of two no less than the ``element_size``. Caller 24508guarantees that both the source and destination pointers are aligned to that 24509boundary. 24510 24511Semantics: 24512"""""""""" 24513 24514The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes 24515of memory from the source location to the destination location. These locations 24516are allowed to overlap. The memory copy is performed as a sequence of load/store 24517operations where each access is guaranteed to be a multiple of ``element_size`` 24518bytes wide and aligned at an ``element_size`` boundary. 24519 24520The order of the copy is unspecified. The same value may be read from the source 24521buffer many times, but only one write is issued to the destination buffer per 24522element. It is well defined to have concurrent reads and writes to both source 24523and destination provided those reads and writes are unordered atomic when 24524specified. 24525 24526This intrinsic does not provide any additional ordering guarantees over those 24527provided by a set of unordered loads from the source location and stores to the 24528destination. 24529 24530Lowering: 24531""""""""" 24532 24533In the most general case call to the 24534'``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol 24535``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an 24536actual element size. See :ref:`RewriteStatepointsForGC intrinsic lowering 24537<RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific 24538lowering. 24539 24540The optimizer is allowed to inline the memory copy when it's profitable to do so. 24541 24542.. _int_memset_element_unordered_atomic: 24543 24544'``llvm.memset.element.unordered.atomic``' Intrinsic 24545^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24546 24547Syntax: 24548""""""" 24549 24550This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on 24551any integer bit width and for different address spaces. Not all targets 24552support all bit widths however. 24553 24554:: 24555 24556 declare void @llvm.memset.element.unordered.atomic.p0i8.i32(i8* <dest>, 24557 i8 <value>, 24558 i32 <len>, 24559 i32 <element_size>) 24560 declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* <dest>, 24561 i8 <value>, 24562 i64 <len>, 24563 i32 <element_size>) 24564 24565Overview: 24566""""""""" 24567 24568The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the 24569'``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array 24570with elements that are exactly ``element_size`` bytes, and the assignment to that array 24571uses uses a sequence of :ref:`unordered atomic <ordering>` store operations 24572that are a positive integer multiple of the ``element_size`` in size. 24573 24574Arguments: 24575"""""""""" 24576 24577The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>` 24578intrinsic, with the added constraint that ``len`` is required to be a positive integer 24579multiple of the ``element_size``. If ``len`` is not a positive integer multiple of 24580``element_size``, then the behaviour of the intrinsic is undefined. 24581 24582``element_size`` must be a compile-time constant positive power of two no greater than 24583target-specific atomic access size limit. 24584 24585The ``dest`` input pointer must have the ``align`` parameter attribute specified. It 24586must be a power of two no less than the ``element_size``. Caller guarantees that 24587the destination pointer is aligned to that boundary. 24588 24589Semantics: 24590"""""""""" 24591 24592The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of 24593memory starting at the destination location to the given ``value``. The memory is 24594set with a sequence of store operations where each access is guaranteed to be a 24595multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary. 24596 24597The order of the assignment is unspecified. Only one write is issued to the 24598destination buffer per element. It is well defined to have concurrent reads and 24599writes to the destination provided those reads and writes are unordered atomic 24600when specified. 24601 24602This intrinsic does not provide any additional ordering guarantees over those 24603provided by a set of unordered stores to the destination. 24604 24605Lowering: 24606""""""""" 24607 24608In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is 24609lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*' 24610is replaced with an actual element size. 24611 24612The optimizer is allowed to inline the memory assignment when it's profitable to do so. 24613 24614Objective-C ARC Runtime Intrinsics 24615---------------------------------- 24616 24617LLVM provides intrinsics that lower to Objective-C ARC runtime entry points. 24618LLVM is aware of the semantics of these functions, and optimizes based on that 24619knowledge. You can read more about the details of Objective-C ARC `here 24620<https://clang.llvm.org/docs/AutomaticReferenceCounting.html>`_. 24621 24622'``llvm.objc.autorelease``' Intrinsic 24623^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24624 24625Syntax: 24626""""""" 24627:: 24628 24629 declare i8* @llvm.objc.autorelease(i8*) 24630 24631Lowering: 24632""""""""" 24633 24634Lowers to a call to `objc_autorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autorelease>`_. 24635 24636'``llvm.objc.autoreleasePoolPop``' Intrinsic 24637^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24638 24639Syntax: 24640""""""" 24641:: 24642 24643 declare void @llvm.objc.autoreleasePoolPop(i8*) 24644 24645Lowering: 24646""""""""" 24647 24648Lowers to a call to `objc_autoreleasePoolPop <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpop-void-pool>`_. 24649 24650'``llvm.objc.autoreleasePoolPush``' Intrinsic 24651^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24652 24653Syntax: 24654""""""" 24655:: 24656 24657 declare i8* @llvm.objc.autoreleasePoolPush() 24658 24659Lowering: 24660""""""""" 24661 24662Lowers to a call to `objc_autoreleasePoolPush <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpush-void>`_. 24663 24664'``llvm.objc.autoreleaseReturnValue``' Intrinsic 24665^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24666 24667Syntax: 24668""""""" 24669:: 24670 24671 declare i8* @llvm.objc.autoreleaseReturnValue(i8*) 24672 24673Lowering: 24674""""""""" 24675 24676Lowers to a call to `objc_autoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue>`_. 24677 24678'``llvm.objc.copyWeak``' Intrinsic 24679^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24680 24681Syntax: 24682""""""" 24683:: 24684 24685 declare void @llvm.objc.copyWeak(i8**, i8**) 24686 24687Lowering: 24688""""""""" 24689 24690Lowers to a call to `objc_copyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-copyweak-id-dest-id-src>`_. 24691 24692'``llvm.objc.destroyWeak``' Intrinsic 24693^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24694 24695Syntax: 24696""""""" 24697:: 24698 24699 declare void @llvm.objc.destroyWeak(i8**) 24700 24701Lowering: 24702""""""""" 24703 24704Lowers to a call to `objc_destroyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-destroyweak-id-object>`_. 24705 24706'``llvm.objc.initWeak``' Intrinsic 24707^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24708 24709Syntax: 24710""""""" 24711:: 24712 24713 declare i8* @llvm.objc.initWeak(i8**, i8*) 24714 24715Lowering: 24716""""""""" 24717 24718Lowers to a call to `objc_initWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-initweak>`_. 24719 24720'``llvm.objc.loadWeak``' Intrinsic 24721^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24722 24723Syntax: 24724""""""" 24725:: 24726 24727 declare i8* @llvm.objc.loadWeak(i8**) 24728 24729Lowering: 24730""""""""" 24731 24732Lowers to a call to `objc_loadWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweak>`_. 24733 24734'``llvm.objc.loadWeakRetained``' Intrinsic 24735^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24736 24737Syntax: 24738""""""" 24739:: 24740 24741 declare i8* @llvm.objc.loadWeakRetained(i8**) 24742 24743Lowering: 24744""""""""" 24745 24746Lowers to a call to `objc_loadWeakRetained <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweakretained>`_. 24747 24748'``llvm.objc.moveWeak``' Intrinsic 24749^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24750 24751Syntax: 24752""""""" 24753:: 24754 24755 declare void @llvm.objc.moveWeak(i8**, i8**) 24756 24757Lowering: 24758""""""""" 24759 24760Lowers to a call to `objc_moveWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-moveweak-id-dest-id-src>`_. 24761 24762'``llvm.objc.release``' Intrinsic 24763^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24764 24765Syntax: 24766""""""" 24767:: 24768 24769 declare void @llvm.objc.release(i8*) 24770 24771Lowering: 24772""""""""" 24773 24774Lowers to a call to `objc_release <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-release-id-value>`_. 24775 24776'``llvm.objc.retain``' Intrinsic 24777^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24778 24779Syntax: 24780""""""" 24781:: 24782 24783 declare i8* @llvm.objc.retain(i8*) 24784 24785Lowering: 24786""""""""" 24787 24788Lowers to a call to `objc_retain <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>`_. 24789 24790'``llvm.objc.retainAutorelease``' Intrinsic 24791^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24792 24793Syntax: 24794""""""" 24795:: 24796 24797 declare i8* @llvm.objc.retainAutorelease(i8*) 24798 24799Lowering: 24800""""""""" 24801 24802Lowers to a call to `objc_retainAutorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautorelease>`_. 24803 24804'``llvm.objc.retainAutoreleaseReturnValue``' Intrinsic 24805^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24806 24807Syntax: 24808""""""" 24809:: 24810 24811 declare i8* @llvm.objc.retainAutoreleaseReturnValue(i8*) 24812 24813Lowering: 24814""""""""" 24815 24816Lowers to a call to `objc_retainAutoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasereturnvalue>`_. 24817 24818'``llvm.objc.retainAutoreleasedReturnValue``' Intrinsic 24819^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24820 24821Syntax: 24822""""""" 24823:: 24824 24825 declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8*) 24826 24827Lowering: 24828""""""""" 24829 24830Lowers to a call to `objc_retainAutoreleasedReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasedreturnvalue>`_. 24831 24832'``llvm.objc.retainBlock``' Intrinsic 24833^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24834 24835Syntax: 24836""""""" 24837:: 24838 24839 declare i8* @llvm.objc.retainBlock(i8*) 24840 24841Lowering: 24842""""""""" 24843 24844Lowers to a call to `objc_retainBlock <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainblock>`_. 24845 24846'``llvm.objc.storeStrong``' Intrinsic 24847^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24848 24849Syntax: 24850""""""" 24851:: 24852 24853 declare void @llvm.objc.storeStrong(i8**, i8*) 24854 24855Lowering: 24856""""""""" 24857 24858Lowers to a call to `objc_storeStrong <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-storestrong-id-object-id-value>`_. 24859 24860'``llvm.objc.storeWeak``' Intrinsic 24861^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24862 24863Syntax: 24864""""""" 24865:: 24866 24867 declare i8* @llvm.objc.storeWeak(i8**, i8*) 24868 24869Lowering: 24870""""""""" 24871 24872Lowers to a call to `objc_storeWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-storeweak>`_. 24873 24874Preserving Debug Information Intrinsics 24875^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24876 24877These intrinsics are used to carry certain debuginfo together with 24878IR-level operations. For example, it may be desirable to 24879know the structure/union name and the original user-level field 24880indices. Such information got lost in IR GetElementPtr instruction 24881since the IR types are different from debugInfo types and unions 24882are converted to structs in IR. 24883 24884'``llvm.preserve.array.access.index``' Intrinsic 24885^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24886 24887Syntax: 24888""""""" 24889:: 24890 24891 declare <ret_type> 24892 @llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons(<type> base, 24893 i32 dim, 24894 i32 index) 24895 24896Overview: 24897""""""""" 24898 24899The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address 24900based on array base ``base``, array dimension ``dim`` and the last access index ``index`` 24901into the array. The return type ``ret_type`` is a pointer type to the array element. 24902The array ``dim`` and ``index`` are preserved which is more robust than 24903getelementptr instruction which may be subject to compiler transformation. 24904The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 24905to provide array or pointer debuginfo type. 24906The metadata is a ``DICompositeType`` or ``DIDerivedType`` representing the 24907debuginfo version of ``type``. 24908 24909Arguments: 24910"""""""""" 24911 24912The ``base`` is the array base address. The ``dim`` is the array dimension. 24913The ``base`` is a pointer if ``dim`` equals 0. 24914The ``index`` is the last access index into the array or pointer. 24915 24916The ``base`` argument must be annotated with an :ref:`elementtype 24917<attr_elementtype>` attribute at the call-site. This attribute specifies the 24918getelementptr element type. 24919 24920Semantics: 24921"""""""""" 24922 24923The '``llvm.preserve.array.access.index``' intrinsic produces the same result 24924as a getelementptr with base ``base`` and access operands ``{dim's 0's, index}``. 24925 24926'``llvm.preserve.union.access.index``' Intrinsic 24927^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24928 24929Syntax: 24930""""""" 24931:: 24932 24933 declare <type> 24934 @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(<type> base, 24935 i32 di_index) 24936 24937Overview: 24938""""""""" 24939 24940The '``llvm.preserve.union.access.index``' intrinsic carries the debuginfo field index 24941``di_index`` and returns the ``base`` address. 24942The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 24943to provide union debuginfo type. 24944The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``. 24945The return type ``type`` is the same as the ``base`` type. 24946 24947Arguments: 24948"""""""""" 24949 24950The ``base`` is the union base address. The ``di_index`` is the field index in debuginfo. 24951 24952Semantics: 24953"""""""""" 24954 24955The '``llvm.preserve.union.access.index``' intrinsic returns the ``base`` address. 24956 24957'``llvm.preserve.struct.access.index``' Intrinsic 24958^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24959 24960Syntax: 24961""""""" 24962:: 24963 24964 declare <ret_type> 24965 @llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s(<type> base, 24966 i32 gep_index, 24967 i32 di_index) 24968 24969Overview: 24970""""""""" 24971 24972The '``llvm.preserve.struct.access.index``' intrinsic returns the getelementptr address 24973based on struct base ``base`` and IR struct member index ``gep_index``. 24974The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 24975to provide struct debuginfo type. 24976The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``. 24977The return type ``ret_type`` is a pointer type to the structure member. 24978 24979Arguments: 24980"""""""""" 24981 24982The ``base`` is the structure base address. The ``gep_index`` is the struct member index 24983based on IR structures. The ``di_index`` is the struct member index based on debuginfo. 24984 24985The ``base`` argument must be annotated with an :ref:`elementtype 24986<attr_elementtype>` attribute at the call-site. This attribute specifies the 24987getelementptr element type. 24988 24989Semantics: 24990"""""""""" 24991 24992The '``llvm.preserve.struct.access.index``' intrinsic produces the same result 24993as a getelementptr with base ``base`` and access operands ``{0, gep_index}``. 24994 24995'``llvm.fptrunc.round``' Intrinsic 24996^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24997 24998Syntax: 24999""""""" 25000 25001:: 25002 25003 declare <ty2> 25004 @llvm.fptrunc.round(<type> <value>, metadata <rounding mode>) 25005 25006Overview: 25007""""""""" 25008 25009The '``llvm.fptrunc.round``' intrinsic truncates 25010:ref:`floating-point <t_floating>` ``value`` to type ``ty2`` 25011with a specified rounding mode. 25012 25013Arguments: 25014"""""""""" 25015 25016The '``llvm.fptrunc.round``' intrinsic takes a :ref:`floating-point 25017<t_floating>` value to cast and a :ref:`floating-point <t_floating>` type 25018to cast it to. This argument must be larger in size than the result. 25019 25020The second argument specifies the rounding mode as described in the constrained 25021intrinsics section. 25022For this intrinsic, the "round.dynamic" mode is not supported. 25023 25024Semantics: 25025"""""""""" 25026 25027The '``llvm.fptrunc.round``' intrinsic casts a ``value`` from a larger 25028:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point 25029<t_floating>` type. 25030This intrinsic is assumed to execute in the default :ref:`floating-point 25031environment <floatenv>` *except* for the rounding mode. 25032This intrinsic is not supported on all targets. Some targets may not support 25033all rounding modes. 25034